1
/**********************************************************************
2
Copyright (C) 2000 by OpenEye Scientific Software, Inc.
3
Some portions Copyright (C) 2001-2005 by Geoffrey R. Hutchison
4
Some portions Copyright (C) 2004 by Chris Morley
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation version 2 of the License.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
14
***********************************************************************/
17
#include "obconversion.h"
23
class TinkerFormat : public OBFormat
26
//Register this format type ID
29
OBConversion::RegisterFormat("txyz",this);
32
virtual const char* Description() //required
35
"Tinker MM2 format\n \
39
virtual const char* SpecificationURL()
40
{return "http://dasher.wustl.edu/tinker/";}; //optional
42
//Flags() can return be any the following combined by | or be omitted if none apply
43
// NOTREADABLE READONEONLY NOTWRITABLE WRITEONEONLY
44
virtual unsigned int Flags()
46
return NOTREADABLE | WRITEONEONLY;
49
//*** This section identical for most OBMol conversions ***
50
////////////////////////////////////////////////////
51
/// The "API" interface functions
52
virtual bool WriteMolecule(OBBase* pOb, OBConversion* pConv);
54
////////////////////////////////////////////////////
55
/// The "Convert" interface functions
56
virtual bool WriteChemObject(OBConversion* pConv)
58
//Retrieve the target OBMol
59
OBBase* pOb = pConv->GetChemObject();
60
OBMol* pmol = dynamic_cast<OBMol*> (pOb);
63
ret=WriteMolecule(pmol,pConv);
65
std::string auditMsg = "OpenBabel::Write molecule ";
66
std::string description(Description());
67
auditMsg += description.substr( 0, description.find('\n') );
68
obErrorLog.ThrowError(__FUNCTION__,
78
//Make an instance of the format class
79
TinkerFormat theTinkerFormat;
81
/////////////////////////////////////////////////////////////////
83
bool TinkerFormat::WriteMolecule(OBBase* pOb, OBConversion* pConv)
85
OBMol* pmol = dynamic_cast<OBMol*>(pOb);
89
//Define some references so we can use the old parameter names
90
ostream &ofs = *pConv->GetOutStream();
94
char buffer[BUFF_SIZE];
96
vector<OBEdgeBase*>::iterator j;
98
sprintf(buffer,"%6d %-20s MM2 parameters",mol.NumAtoms(),mol.GetTitle());
99
ofs << buffer << endl;
101
ttab.SetFromType("INT");
105
for(i = 1;i <= mol.NumAtoms(); i++)
107
atom = mol.GetAtom(i);
108
str = atom->GetType();
109
ttab.SetToType("MM2");
110
ttab.Translate(str1,str);
111
sprintf(buffer,"%6d %2s %12.6f%12.6f%12.6f %5d",
113
etab.GetSymbol(atom->GetAtomicNum()),
117
atoi((char*)str1.c_str()));
120
for (bond = atom->BeginBond(j); bond; bond = atom->NextBond(j))
122
sprintf(buffer,"%6d", (bond->GetNbrAtom(atom))->GetIdx());
132
} //namespace OpenBabel