1
/**********************************************************************
2
Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc.
3
Some portions Copyright (c) 2001-2003 by Geoffrey R. Hutchison
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation version 2 of the License.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
13
***********************************************************************/
24
bool ReadMacroModel(istream &ifs, OBMol &mol,const char *defaultTitle)
27
char buffer[BUFF_SIZE];
29
vector<vector<pair<int,int> > > connections;
31
if (ifs.getline(buffer,BUFF_SIZE))
34
tokenize(vs,buffer," \n");
36
if ( !vs.empty() && vs.size() > 0)
37
sscanf(buffer,"%i%*s",&natoms);
39
if ( !vs.empty() && vs.size() > 1)
43
string s = defaultTitle;
44
mol.SetTitle(defaultTitle);
50
mol.ReserveAtoms(natoms);
51
connections.resize(natoms+1);
53
/***********************************************************************/
55
// Get Type Bonds, BondOrder, X, Y, Z
64
ttab.SetFromType("MMD");
65
for (i = 1; i <= natoms; i++)
67
if (!ifs.getline(buffer,BUFF_SIZE)) break;
71
sscanf(buffer,"%s%d%d%d%d%d%d%d%d%d%d%d%d%lf%lf%lf",
72
temp_type,&end[0],&order[0],&end[1],&order[1],&end[2],&order[2],
73
&end[3], &order[3], &end[4], &order[4], &end[5], &order[5],
77
for ( j = 0 ; j <=5 ; j++ )
79
if ( end[j] > 0 && end[j] > i)
82
tmp.second = order[j];
83
connections[i].push_back(tmp);
87
v.SetX(x); v.SetY(y); v.SetZ(z);
90
string str = temp_type,str1;
91
ttab.SetToType("ATN"); ttab.Translate(str1,str);
92
atom.SetAtomicNum(atoi(str1.c_str()));
93
ttab.SetToType("INT"); ttab.Translate(str1,str);
96
// stuff for optional fields
99
sscanf(&buffer[101],"%lf", &charge);
100
atom.SetPartialCharge(charge);
104
for (i = 1; i <= natoms; i++)
105
for (j = 0; j < (signed)connections[i].size(); j++)
106
mol.AddBond(i, connections[i][j].first, connections[i][j].second);
111
vector<OBEdgeBase*>::iterator bi;
112
for (bond = mol.BeginBond(bi);bond;bond = mol.NextBond(bi))
113
if (bond->GetBO() == 5 && !bond->IsInRing())
116
if ( natoms != (signed)mol.NumAtoms() ) return(false);
121
bool WriteMacroModel(ostream &ofs,OBMol &mol)
123
char buffer[BUFF_SIZE];
124
sprintf(buffer," %5d %6s E = %7.3f KJ/mol",
125
mol.NumAtoms(),mol.GetTitle(),4.184*mol.GetEnergy());
126
ofs << buffer << endl;
131
vector<OBNodeBase*>::iterator i;
132
vector<OBEdgeBase*>::iterator j;
133
ttab.SetFromType("INT");
134
ttab.SetToType("MMD");
136
for (atom = mol.BeginAtom(i);atom;atom = mol.NextAtom(i))
138
if (atom->IsHydrogen())
141
if ((nbr = atom->BeginNbrAtom(j)))
142
if (nbr->IsOxygen()) type = 42;
143
else if (nbr->IsNitrogen()) type = 43;
147
from = atom->GetType();
148
ttab.Translate(to,from);
149
type = atoi((char*)to.c_str());
151
sprintf(buffer,"%4d",type);
153
for (nbr = atom->BeginNbrAtom(j);nbr;nbr = atom->NextNbrAtom(j))
155
sprintf(buffer," %5d %1d",nbr->GetIdx(),(*j)->GetBO());
158
for (k=atom->GetValence();k < 6;k++)
160
sprintf(buffer," %5d %1d",0,0);
164
sprintf(buffer," %11.6f %11.6f %11.6f %5d %5d %8.5f \n",
165
atom->x(), atom->y(),atom->z(),0,0,
166
atom->GetPartialCharge());