Coverage Report

Created: 2025-11-24 06:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openbabel/src/formats/msmsformat.cpp
Line
Count
Source
1
//
2
// Molekel - Molecular Visualization Program
3
// Copyright (C) 2006, 2007 Swiss National Supercomputing Centre (CSCS)
4
//
5
// This program is free software; you can redistribute it and/or
6
// modify it under the terms of the GNU General Public License
7
// as published by the Free Software Foundation; either version 2
8
// of the License, or (at your option) any later version.
9
10
// This program is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
// GNU General Public License for more details.
14
//
15
// You should have received a copy of the GNU General Public License
16
// along with this program; if not, write to the Free Software
17
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
// MA  02110-1301, USA.
19
//
20
// $Author$
21
// $Date$
22
// $Revision$
23
//
24
25
26
#include <openbabel/mol.h>
27
#include <openbabel/obconversion.h>
28
#include <openbabel/obmolecformat.h>
29
#include <openbabel/mol.h>
30
#include <openbabel/atom.h>
31
#include <openbabel/elements.h>
32
33
34
#include <openbabel/obiter.h>
35
#include <openbabel/data.h>
36
37
#include <iostream>
38
39
using namespace std;
40
41
namespace OpenBabel
42
{
43
44
45
//==============================================================================
46
/// Class to output a molecule in XYZR MSMS input format for further computation
47
/// of Connolly surface.
48
/// Michel Sanner page with info on MSMS:
49
/// http://www.scripps.edu/~sanner/
50
class OBMSMSFormat : public OpenBabel::OBMoleculeFormat
51
{
52
public:
53
    /// Constructor: register 'msms' and "MSMS" format.
54
    OBMSMSFormat()
55
6
    {
56
6
        OpenBabel::OBConversion::RegisterFormat( "msms", this );
57
6
    }
58
59
    /// Return description.
60
    const char* Description() override  // required
61
0
    {
62
0
        return
63
0
        "M.F. Sanner's MSMS input format\n"
64
0
        "Generates input to the MSMS (Michael Sanner Molecular Surface) program to compute solvent surfaces.\n\n"
65
0
        "Write Options, e.g. -xa\n"
66
0
        "  a output atom names\n";
67
0
    }
68
69
    /// Return a specification url, not really a specification since
70
    /// I couldn't find it but close enough.
71
    const char* SpecificationURL() override
72
0
    {
73
0
        return "http://www.scripps.edu/~sanner";
74
0
    }
75
76
    /// Return MIME type, NULL in this case.
77
0
    const char* GetMIMEType() override { return nullptr; }
78
79
      /// Return read/write flag: read only.
80
    unsigned int Flags() override
81
9
    {
82
9
        return WRITEONEONLY | NOTREADABLE;
83
9
    }
84
85
    /// Skip to object: used for multi-object file formats.
86
0
    int SkipObjects(int n, OpenBabel::OBConversion* pConv) override { return 0; }
87
88
    /// Read: always return false.
89
    bool ReadMolecule(OpenBabel::OBBase*, OpenBabel::OBConversion*) override
90
0
    {
91
0
        return false;
92
0
    }
93
94
    /// Write.
95
    bool WriteMolecule(OpenBabel::OBBase*, OpenBabel::OBConversion*) override;
96
};
97
98
//------------------------------------------------------------------------------
99
100
// Global variable used to register MSMS format.
101
OBMSMSFormat msmsFormat__;
102
103
//------------------------------------------------------------------------------
104
105
106
//==============================================================================
107
108
//------------------------------------------------------------------------------
109
bool OBMSMSFormat::WriteMolecule( OBBase* pOb, OBConversion* pConv )
110
0
{
111
0
    OBMol* pmol = dynamic_cast< OBMol* >(pOb);
112
0
    if (pmol == nullptr) return false;
113
114
0
    ostream& os = *pConv->GetOutStream();
115
116
0
    const bool atomNames = pConv->IsOption("a", OBConversion::OUTOPTIONS) != nullptr;
117
118
    // write header ?
119
120
    // iterate through atoms and write <atom x> <atom y> <atom z> <atom radius>
121
    // and optionally <atomic number> in case atomNames == true
122
123
0
    FOR_ATOMS_OF_MOL( a, *pmol )
124
0
    {
125
0
        const double* c = a->GetCoordinate();
126
0
        os << c[ 0 ] << '\t' << c[ 1 ] << '\t' << c[ 2 ] << '\t' <<
127
0
        OBElements::GetVdwRad( a->GetAtomicNum() );
128
0
        if( atomNames ) os << '\t' << a->GetAtomicNum();
129
0
        os << '\n';
130
0
    }
131
0
    os.flush();
132
0
    return true;
133
0
}
134
135
}