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 |
5 |
|
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. |
9 |
|
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 |
***********************************************************************/ |
15 |
|
16 |
#include "mol.hpp" |
17 |
#include "obconversion.hpp" |
18 |
#include "obmolecformat.hpp" |
19 |
|
20 |
using namespace std; |
21 |
namespace OpenBabel |
22 |
{ |
23 |
|
24 |
class AmberPrepFormat : public OBMoleculeFormat |
25 |
{ |
26 |
public: |
27 |
//Register this format type ID |
28 |
AmberPrepFormat() |
29 |
{ |
30 |
OBConversion::RegisterFormat("prep",this); |
31 |
} |
32 |
|
33 |
virtual const char* Description() //required |
34 |
{ |
35 |
return |
36 |
"Amber Prep format\n \ |
37 |
Read Options e.g. -as\n\ |
38 |
s Output single bonds only\n\ |
39 |
b Disable bonding entirely\n\n"; |
40 |
}; |
41 |
|
42 |
virtual const char* SpecificationURL() |
43 |
{return "http://amber.scripps.edu/doc/prep.html";}; |
44 |
|
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() |
48 |
{ |
49 |
return NOTWRITABLE; |
50 |
}; |
51 |
|
52 |
//////////////////////////////////////////////////// |
53 |
/// The "API" interface functions |
54 |
virtual bool ReadMolecule(OBBase* pOb, OBConversion* pConv); |
55 |
}; |
56 |
|
57 |
//Make an instance of the format class |
58 |
AmberPrepFormat theAmberPrepFormat; |
59 |
|
60 |
///////////////////////////////////////////////////////////////// |
61 |
bool AmberPrepFormat::ReadMolecule(OBBase* pOb, OBConversion* pConv) |
62 |
{ |
63 |
|
64 |
OBMol* pmol = dynamic_cast<OBMol*>(pOb); |
65 |
if(pmol==NULL) |
66 |
return false; |
67 |
|
68 |
//Define some references so we can use the old parameter names |
69 |
istream &ifs = *pConv->GetInStream(); |
70 |
OBMol &mol = *pmol; |
71 |
const char* title = pConv->GetTitle(); |
72 |
|
73 |
char buffer[BUFF_SIZE]; |
74 |
string str,str1; |
75 |
OBAtom *atom; |
76 |
OBInternalCoord *coord; |
77 |
vector<string> vs; |
78 |
vector<OBInternalCoord*> internals; |
79 |
|
80 |
mol.BeginModify(); |
81 |
|
82 |
while (ifs.getline(buffer,BUFF_SIZE)) |
83 |
{ |
84 |
tokenize(vs,buffer); |
85 |
if (vs.size() == 10) |
86 |
{ |
87 |
atom = mol.NewAtom(); |
88 |
coord = new OBInternalCoord(); |
89 |
if (mol.NumAtoms() > 1) |
90 |
coord->_a = mol.GetAtom(atoi(vs[4].c_str())); |
91 |
if (mol.NumAtoms() > 2) |
92 |
coord->_b = mol.GetAtom(atoi(vs[5].c_str())); |
93 |
if (mol.NumAtoms() > 3) |
94 |
coord->_c = mol.GetAtom(atoi(vs[6].c_str())); |
95 |
coord->_dst = atof(vs[7].c_str()); |
96 |
coord->_ang = atof(vs[8].c_str()); |
97 |
coord->_tor = atof(vs[9].c_str()); |
98 |
internals.push_back(coord); |
99 |
|
100 |
atom->SetAtomicNum(etab.GetAtomicNum(vs[1].c_str())); |
101 |
|
102 |
if (!ifs.getline(buffer,BUFF_SIZE)) |
103 |
break; |
104 |
tokenize(vs,buffer); |
105 |
} |
106 |
} |
107 |
|
108 |
if (internals.size() > 0) |
109 |
InternalToCartesian(internals,mol); |
110 |
|
111 |
if (!pConv->IsOption("b",OBConversion::INOPTIONS)) |
112 |
mol.ConnectTheDots(); |
113 |
if (!pConv->IsOption("s",OBConversion::INOPTIONS) && !pConv->IsOption("b",OBConversion::INOPTIONS)) |
114 |
mol.PerceiveBondOrders(); |
115 |
|
116 |
mol.EndModify(); |
117 |
mol.SetTitle(title); |
118 |
return(true); |
119 |
} |
120 |
|
121 |
} //namespace OpenBabel |