12
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
13
GNU General Public License for more details.
14
14
***********************************************************************/
15
#include <openbabel/babelconfig.h>
17
#include "obconversion.h"
18
#include "obmolecformat.h"
17
#include <openbabel/obmolecformat.h>
20
19
using namespace std;
21
20
namespace OpenBabel
24
class MacroModFormat : public OBMoleculeFormat
23
class MacroModFormat : public OBMoleculeFormat
27
26
//Register this format type ID
30
OBConversion::RegisterFormat("mmd",this, "chemical/x-macromodel-input");
31
OBConversion::RegisterFormat("mmod",this, "chemical/x-macromodel-input");
29
OBConversion::RegisterFormat("mmd",this, "chemical/x-macromodel-input");
30
OBConversion::RegisterFormat("mmod",this, "chemical/x-macromodel-input");
34
33
virtual const char* Description() //required
37
"MacroModel format\n \
36
"MacroModel format\n \
38
37
No comments yet\n";
41
virtual const char* SpecificationURL()
42
{return "";}; //optional
40
virtual const char* SpecificationURL()
41
{return "";}; //optional
44
virtual const char* GetMIMEType()
45
{ return "chemical/x-macromodel-input"; };
43
virtual const char* GetMIMEType()
44
{ return "chemical/x-macromodel-input"; };
47
46
//Flags() can return be any the following combined by | or be omitted if none apply
48
47
// NOTREADABLE READONEONLY NOTWRITABLE WRITEONEONLY
49
48
virtual unsigned int Flags()
54
53
//*** This section identical for most OBMol conversions ***
56
55
/// The "API" interface functions
57
56
virtual bool ReadMolecule(OBBase* pOb, OBConversion* pConv);
58
57
virtual bool WriteMolecule(OBBase* pOb, OBConversion* pConv);
62
//Make an instance of the format class
63
MacroModFormat theMacroModFormat;
65
/////////////////////////////////////////////////////////////////
66
bool MacroModFormat::ReadMolecule(OBBase* pOb, OBConversion* pConv)
69
OBMol* pmol = dynamic_cast<OBMol*>(pOb);
61
//Make an instance of the format class
62
MacroModFormat theMacroModFormat;
64
/////////////////////////////////////////////////////////////////
65
bool MacroModFormat::ReadMolecule(OBBase* pOb, OBConversion* pConv)
68
OBMol* pmol = pOb->CastAndClear<OBMol>();
73
72
//Define some references so we can use the old parameter names
74
73
istream &ifs = *pConv->GetInStream();
81
80
vector<vector<pair<int,int> > > connections;
83
82
if (ifs.getline(buffer,BUFF_SIZE))
86
85
tokenize(vs,buffer," \n");
88
87
if ( !vs.empty() && vs.size() > 0)
89
sscanf(buffer,"%i%*s",&natoms);
88
sscanf(buffer,"%i%*s",&natoms);
94
93
if ( !vs.empty() && vs.size() > 1)
98
97
string s = defaultTitle;
99
98
mol.SetTitle(defaultTitle);
105
104
mol.BeginModify();
106
105
mol.ReserveAtoms(natoms);
160
159
sscanf(&buffer[101],"%lf", &charge);
161
160
atom.SetPartialCharge(charge);
162
161
mol.AddAtom(atom);
165
164
for (i = 1; i <= natoms; i++)
166
for (j = 0; j < (signed)connections[i].size(); j++)
167
mol.AddBond(i, connections[i][j].first, connections[i][j].second);
165
for (j = 0; j < (signed)connections[i].size(); j++)
166
mol.AddBond(i, connections[i][j].first, connections[i][j].second);
172
vector<OBEdgeBase*>::iterator bi;
171
vector<OBBond*>::iterator bi;
173
172
for (bond = mol.BeginBond(bi);bond;bond = mol.NextBond(bi))
174
if (bond->GetBO() == 5 && !bond->IsInRing())
173
if (bond->GetBO() == 5 && !bond->IsInRing())
177
176
if ( natoms != (signed)mol.NumAtoms() )
180
179
// clean out remaining blank lines
181
180
while(ifs.peek() != EOF && ifs.good() &&
182
(ifs.peek() == '\n' || ifs.peek() == '\r'))
181
(ifs.peek() == '\n' || ifs.peek() == '\r'))
183
182
ifs.getline(buffer,BUFF_SIZE);
188
////////////////////////////////////////////////////////////////
190
bool MacroModFormat::WriteMolecule(OBBase* pOb, OBConversion* pConv)
187
////////////////////////////////////////////////////////////////
189
bool MacroModFormat::WriteMolecule(OBBase* pOb, OBConversion* pConv)
192
191
OBMol* pmol = dynamic_cast<OBMol*>(pOb);
196
195
//Define some references so we can use the old parameter names
197
196
ostream &ofs = *pConv->GetOutStream();
206
205
OBAtom *atom,*nbr;
208
vector<OBNodeBase*>::iterator i;
209
vector<OBEdgeBase*>::iterator j;
207
vector<OBAtom*>::iterator i;
208
vector<OBBond*>::iterator j;
210
209
ttab.SetFromType("INT");
211
210
ttab.SetToType("MMD");
213
212
for (atom = mol.BeginAtom(i);atom;atom = mol.NextAtom(i))
215
214
if (atom->IsHydrogen())
218
217
if ((nbr = atom->BeginNbrAtom(j)))
221
else if (nbr->IsNitrogen())
220
else if (nbr->IsNitrogen())
226
225
from = atom->GetType();
227
226
ttab.Translate(to,from);
228
227
type = atoi((char*)to.c_str());
230
229
snprintf(buffer, BUFF_SIZE, "%4d",type);
232
231
for (nbr = atom->BeginNbrAtom(j);nbr;nbr = atom->NextNbrAtom(j))
234
233
snprintf(buffer, BUFF_SIZE, " %5d %1d",nbr->GetIdx(),(*j)->GetBO());
237
236
for (k=atom->GetValence();k < 6;k++)
239
238
snprintf(buffer, BUFF_SIZE," %5d %1d",0,0);
243
242
snprintf(buffer, BUFF_SIZE, " %11.6f %11.6f %11.6f %5d %5d %8.5f \n",
244
243
atom->x(), atom->y(),atom->z(),0,0,
245
244
atom->GetPartialCharge());
252
251
} //namespace OpenBabel