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