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 HINFormat : public OBMoleculeFormat
23
class HINFormat : public OBMoleculeFormat
27
26
//Register this format type ID
30
OBConversion::RegisterFormat("hin",this);
29
OBConversion::RegisterFormat("hin",this, "chemical/x-hin");
33
32
virtual const char* Description() //required
35
return "HyperChem HIN format\n\
34
return "HyperChem HIN format\n\
36
35
No comments yet\n";
39
virtual const char* SpecificationURL()
40
{ return "";}; //optional
38
virtual const char* SpecificationURL()
39
{ return "";}; //optional
41
virtual const char* GetMIMEType()
42
{ return "chemical/x-hin";}; //optional
42
44
//*** This section identical for most OBMol conversions ***
43
45
////////////////////////////////////////////////////
44
46
/// The "API" interface functions
45
47
virtual bool ReadMolecule(OBBase* pOb, OBConversion* pConv);
46
48
virtual bool WriteMolecule(OBBase* pOb, OBConversion* pConv);
50
//Make an instance of the format class
51
HINFormat theHINFormat;
53
/////////////////////////////////////////////////////////////////
54
bool HINFormat::ReadMolecule(OBBase* pOb, OBConversion* pConv)
57
OBMol* pmol = dynamic_cast<OBMol*>(pOb);
52
//Make an instance of the format class
53
HINFormat theHINFormat;
55
/////////////////////////////////////////////////////////////////
56
bool HINFormat::ReadMolecule(OBBase* pOb, OBConversion* pConv)
59
OBMol* pmol = pOb->CastAndClear<OBMol>();
61
63
//Define some references so we can use the old parameter names
62
64
istream &ifs = *pConv->GetInStream();
75
77
ifs.getline(buffer, BUFF_SIZE);
76
while (strstr(buffer,"mol") == NULL)
78
while (ifs.good() && strstr(buffer,"mol") == NULL)
78
80
ifs.getline(buffer, BUFF_SIZE);
79
if (ifs.peek() == EOF || !ifs.good())
81
if (ifs.peek() == EOF || !ifs.good())
82
84
ifs.getline(buffer, BUFF_SIZE);
86
return false; // ended early
85
while (strstr(buffer,"endmol") == NULL)
89
while (ifs.good() && strstr(buffer,"endmol") == NULL)
87
91
tokenize(vs,buffer); // Don't really know how long it'll be
88
92
if (vs.size() < 11)
90
ifs.getline(buffer, BUFF_SIZE);
94
ifs.getline(buffer, BUFF_SIZE);
94
98
atom = mol.NewAtom();
95
99
atom->SetAtomicNum(etab.GetAtomicNum(vs[3].c_str()));
100
atom->SetPartialCharge(atof(vs[6].c_str()));
96
101
x = atof((char*)vs[7].c_str());
97
102
y = atof((char*)vs[8].c_str());
98
103
z = atof((char*)vs[9].c_str());
101
106
max = 11 + 2 * atoi((char *)vs[10].c_str());
102
107
for (i = 11; i < max; i+=2)
104
109
switch(((char*)vs[i+1].c_str())[0]) // First char in next token
122
127
mol.AddBond(mol.NumAtoms(), atoi((char *)vs[i].c_str()), bo);
124
129
ifs.getline(buffer, BUFF_SIZE);
127
132
// clean out remaining blank lines
128
133
while(ifs.peek() != EOF && ifs.good() &&
129
(ifs.peek() == '\n' || ifs.peek() == '\r'))
134
(ifs.peek() == '\n' || ifs.peek() == '\r'))
130
135
ifs.getline(buffer,BUFF_SIZE);
134
139
mol.SetTitle(title);
140
mol.SetPartialChargesPerceived();
138
////////////////////////////////////////////////////////////////
140
bool HINFormat::WriteMolecule(OBBase* pOb, OBConversion* pConv)
145
////////////////////////////////////////////////////////////////
147
bool HINFormat::WriteMolecule(OBBase* pOb, OBConversion* pConv)
142
149
OBMol* pmol = dynamic_cast<OBMol*>(pOb);
146
153
//Define some references so we can use the old parameter names
147
154
ostream &ofs = *pConv->GetOutStream();
172
179
atom->GetValence());
174
181
for (bond = atom->BeginBond(j); bond; bond = atom->NextBond(j))
176
183
switch(bond->GetBO())
194
if (bond->IsAromatic())
201
if (bond->IsAromatic())
197
204
snprintf(buffer,BUFF_SIZE, "%d %c ", (bond->GetNbrAtom(atom))->GetIdx(), bond_char);
202
209
ofs << "endmol " << file_num << endl;
206
213
} //namespace OpenBabel