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 "math/matrix3x3.h"
18
#include "obconversion.h"
19
#include "obmolecformat.h"
17
#include <openbabel/obmolecformat.h>
18
#include <openbabel/math/matrix3x3.h>
21
20
using namespace std;
22
21
namespace OpenBabel
25
class CacaoFormat : public OBMoleculeFormat
24
class CacaoFormat : public OBMoleculeFormat
28
27
//Register this format type ID
31
OBConversion::RegisterFormat("caccrt",this);
30
OBConversion::RegisterFormat("caccrt",this);
34
virtual const char* Description() //required
37
"Cacao Cartesian format\n \
38
Read Options e.g. -as\n\
39
s Output single bonds only\n\
40
b Disable bonding entirely\n\n";
43
virtual const char* SpecificationURL()
44
{return "http://www.chembio.uoguelph.ca/oakley/310/cacao/cacao.htm";}; //optional
46
//Flags() can return be any the following combined by | or be omitted if none apply
47
// NOTREADABLE READONEONLY NOTWRITABLE WRITEONEONLY
48
virtual unsigned int Flags()
50
return READONEONLY | WRITEONEONLY;
53
////////////////////////////////////////////////////
54
/// The "API" interface functions
55
virtual bool ReadMolecule(OBBase* pOb, OBConversion* pConv);
56
virtual bool WriteMolecule(OBBase* pOb, OBConversion* pConv);
58
static void SetHilderbrandt(OBMol&,vector<OBInternalCoord*>&);
61
//Make an instance of the format class
62
CacaoFormat theCacaoFormat;
64
/////////////////////////////////////////////////////////////////
65
bool CacaoFormat::ReadMolecule(OBBase* pOb, OBConversion* pConv)
68
OBMol* pmol = dynamic_cast<OBMol*>(pOb);
33
virtual const char* Description() //required
36
"Cacao Cartesian format\n"
37
"Read Options e.g. -as\n"
38
" s Output single bonds only\n"
39
" b Disable bonding entirely\n\n";
42
virtual const char* SpecificationURL()
43
{return "http://www.chembio.uoguelph.ca/oakley/310/cacao/cacao.htm";}; //optional
45
//Flags() can return be any the following combined by | or be omitted if none apply
46
// NOTREADABLE READONEONLY NOTWRITABLE WRITEONEONLY
47
virtual unsigned int Flags()
49
return READONEONLY | WRITEONEONLY;
52
////////////////////////////////////////////////////
53
/// The "API" interface functions
54
virtual bool ReadMolecule(OBBase* pOb, OBConversion* pConv);
55
virtual bool WriteMolecule(OBBase* pOb, OBConversion* pConv);
57
static void SetHilderbrandt(OBMol&,vector<OBInternalCoord*>&);
60
//Make an instance of the format class
61
CacaoFormat theCacaoFormat;
63
/////////////////////////////////////////////////////////////////
64
bool CacaoFormat::ReadMolecule(OBBase* pOb, OBConversion* pConv)
67
OBMol* pmol = pOb->CastAndClear<OBMol>();
72
71
//Define some references so we can use the old parameter names
73
72
istream &ifs = *pConv->GetInStream();
141
141
// clean out remaining blank lines
142
142
while(ifs.peek() != EOF && ifs.good() &&
143
(ifs.peek() == '\n' || ifs.peek() == '\r'))
143
(ifs.peek() == '\n' || ifs.peek() == '\r'))
144
144
ifs.getline(buffer,BUFF_SIZE);
150
////////////////////////////////////////////////////////////////
152
bool CacaoFormat::WriteMolecule(OBBase* pOb, OBConversion* pConv)
150
////////////////////////////////////////////////////////////////
152
bool CacaoFormat::WriteMolecule(OBBase* pOb, OBConversion* pConv)
154
154
OBMol* pmol = dynamic_cast<OBMol*>(pOb);
158
158
//Define some references so we can use the old parameter names
159
159
ostream &ofs = *pConv->GetOutStream();
171
171
if (!mol.HasData(OBGenericDataType::UnitCell))
172
172
ofs << "CELL 1.,1.,1.,90.,90.,90.\n";
175
175
OBUnitCell *uc = (OBUnitCell*)mol.GetData(OBGenericDataType::UnitCell);
176
176
snprintf(buffer, BUFF_SIZE, "CELL %f,%f,%f,%f,%f,%f\n",
177
uc->GetA(), uc->GetB(), uc->GetC(),
178
uc->GetAlpha(), uc->GetBeta(), uc->GetGamma());
177
uc->GetA(), uc->GetB(), uc->GetC(),
178
uc->GetAlpha(), uc->GetBeta(), uc->GetGamma());
182
182
for (atom = mol.BeginAtom(i);atom;atom = mol.NextAtom(i))
184
184
snprintf(buffer,BUFF_SIZE,"%2s %7.4f, %7.4f, %7.4f\n",
185
etab.GetSymbol(atom->GetAtomicNum()),
185
etab.GetSymbol(atom->GetAtomicNum()),
195
//! \todo Make this method bulletproof. Currently it causes segfaults sometimes
196
void CacaoFormat::SetHilderbrandt(OBMol &mol,vector<OBInternalCoord*> &vit)
195
//! \todo Make this method bulletproof. Currently it causes segfaults sometimes
196
void CacaoFormat::SetHilderbrandt(OBMol &mol,vector<OBInternalCoord*> &vit)
198
198
// Roundtrip testing shows that some atoms are NULL
199
199
// which causes segfaults when dereferencing later
200
200
// (e.g. in the last "segment" of this routine)
205
205
dummy2.SetVector(1.0,0.0,0.0);
207
207
OBAtom *atom,*a1,*a2,*ref;
208
vector<OBNodeBase*>::iterator ai;
208
vector<OBAtom*>::iterator ai;
210
210
vit.push_back((OBInternalCoord*)NULL);
211
211
for (atom = mol.BeginAtom(ai);atom;atom = mol.NextAtom(ai))
212
vit.push_back(new OBInternalCoord (atom));
212
vit.push_back(new OBInternalCoord (atom));
214
214
vit[1]->_a = &dummy1;
215
215
vit[1]->_b = &dummy2;
217
217
vit[2]->_b = &dummy1;
218
218
vit[2]->_c = &dummy2;
219
219
if (vit.size() > 3) {
220
vit[3]->_c = &dummy1;
220
vit[3]->_c = &dummy1;
224
224
unsigned int i,j;
225
225
for (i = 2;i <= mol.NumAtoms();i++)
227
227
ref = (OBAtom*)NULL;
228
228
a1 = mol.GetAtom(i);
230
230
for (j = 1;j < i;j++)
232
232
a2 = mol.GetAtom(j);
233
233
r = (a1->GetVector()-a2->GetVector()).length_2();
234
234
if ((r < sum) && (vit[j]->_a != a2) && (vit[j]->_b != a2))
240
240
vit[i]->_a = ref;
243
243
for (i = 3;i <= mol.NumAtoms();i++)
244
vit[i]->_b = vit[vit[i]->_a->GetIdx()]->_a;
244
vit[i]->_b = vit[vit[i]->_a->GetIdx()]->_a;
246
246
for (i = 4;i <= mol.NumAtoms();i++)
248
248
if (vit[i]->_b && vit[i]->_b->GetIdx())
249
vit[i]->_c = vit[vit[i]->_b->GetIdx()]->_b;
249
vit[i]->_c = vit[vit[i]->_b->GetIdx()]->_b;
251
vit[i]->_c = &dummy1;
251
vit[i]->_c = &dummy1;
256
256
for (i = 2;i <= mol.NumAtoms();i++)
258
258
atom = mol.GetAtom(i);
269
269
vit[i]->_dst = (vit[i]->_a->GetVector() - atom->GetVector()).length();
273
//***************************************************************
274
class CacaoInternalFormat : public OBFormat
273
//***************************************************************
274
class CacaoInternalFormat : public OBMoleculeFormat
277
277
//Register this format type ID
278
278
CacaoInternalFormat()
280
OBConversion::RegisterFormat("cacint",this);
280
OBConversion::RegisterFormat("cacint",this);
283
283
virtual const char* Description() //required
286
"Cacao Internal format\n \
286
"Cacao Internal format\n \
287
287
No comments yet\n \
291
291
virtual const char* SpecificationURL(){return
292
"http://www.chembio.uoguelph.ca/oakley/310/cacao/cacao.htm";}; //optional
292
"http://www.chembio.uoguelph.ca/oakley/310/cacao/cacao.htm";}; //optional
294
294
//Flags() can return be any the following combined by | or be omitted if none apply
295
295
// NOTREADABLE READONEONLY NOTWRITABLE WRITEONEONLY
296
296
virtual unsigned int Flags()
298
return NOTREADABLE | WRITEONEONLY;
298
return NOTREADABLE | WRITEONEONLY;
301
301
////////////////////////////////////////////////////
302
302
/// The "API" interface functions
303
303
virtual bool WriteMolecule(OBBase* pOb, OBConversion* pConv);
305
////////////////////////////////////////////////////
306
virtual bool WriteChemObject(OBConversion* pConv)
308
//Retrieve the target OBMol
309
OBBase* pOb = pConv->GetChemObject();
310
OBMol* pmol = dynamic_cast<OBMol*> (pOb);
313
ret=WriteMolecule(pmol,pConv);
319
//Make an instance of the format class
320
CacaoInternalFormat theCacaoInternalFormat;
322
bool CacaoInternalFormat::WriteMolecule(OBBase* pOb, OBConversion* pConv)
306
//Make an instance of the format class
307
CacaoInternalFormat theCacaoInternalFormat;
309
bool CacaoInternalFormat::WriteMolecule(OBBase* pOb, OBConversion* pConv)
324
311
OBMol* pmol = dynamic_cast<OBMol*>(pOb);
328
315
//Define some references so we can use the old parameter names
329
316
ostream &ofs = *pConv->GetOutStream();
352
339
snprintf(buffer, BUFF_SIZE, "0.,0.,0., %s\n",tmptype);
354
341
for (i = 2; i <= mol.NumAtoms(); i++)
356
343
strncpy(tmptype,etab.GetSymbol(mol.GetAtom(i)->GetAtomicNum()), sizeof(tmptype));
357
344
tmptype[sizeof(tmptype) - 1] = '\0';
359
346
if (vit[i]->_tor < 0.0)
360
vit[i]->_tor += 360.0;
347
vit[i]->_tor += 360.0;
361
348
snprintf(buffer, BUFF_SIZE, "%2d,%d,%2s%7.3f,%7.3f,%7.3f",
362
vit[i]->_a->GetIdx(),i,tmptype,
349
vit[i]->_a->GetIdx(),i,tmptype,
366
353
ofs << buffer << endl;
369
356
vector<OBInternalCoord*>::iterator j;
370
357
for (j = vit.begin();j != vit.end();j++)
380
367
} //namespace OpenBabel