79 |
|
return false; |
80 |
|
} |
81 |
|
|
82 |
< |
WriteMDFile(mdMols, numMols, ofs); |
82 |
> |
WriteMDFile(mdMols, numMols, ofs, *pmol, indices); |
83 |
|
|
84 |
|
for(vector<OBMol*>::iterator i = mdMols.begin(); i != mdMols.end(); ++i) |
85 |
|
{ |
87 |
|
} |
88 |
|
|
89 |
|
// |
90 |
– |
WriteINFile(*pmol, *pConv->GetOutStream(), indices); |
90 |
|
|
92 |
– |
|
93 |
– |
|
91 |
|
return(true); |
92 |
|
} |
93 |
|
|
98 |
|
return false; |
99 |
|
} |
100 |
|
|
101 |
< |
//exact graph matching is a NP complete problem, |
101 |
> |
//exact graph matching is a NP complete problem |
102 |
> |
/** @todo using sparse matrix to store the connectivities*/ |
103 |
|
for (unsigned int i =0 ; i < frag1.size(); ++i) |
104 |
|
{ |
105 |
< |
if (strcmp(mol.GetAtom(frag1[i])->GetType(), mol.GetAtom(frag2[i])->GetType()) ) |
105 |
> |
OBAtom* atom1 = mol.GetAtom(frag1[i]); |
106 |
> |
OBAtom* atom2 = mol.GetAtom(frag2[i]); |
107 |
> |
|
108 |
> |
if (atom1->GetAtomicNum() != atom2->GetAtomicNum()) |
109 |
|
{ |
110 |
|
return false; |
111 |
|
} |
121 |
|
} |
122 |
|
}; |
123 |
|
|
124 |
< |
void OOPSEFormat::findAngles(OBMol& mol) |
124 |
< |
{ |
124 |
> |
void OOPSEFormat::findAngles(OBMol& mol) { |
125 |
|
/* |
126 |
|
//if already has data return |
127 |
|
if(mol.HasData(OBGenericDataType::AngleData)) |
160 |
|
angles->SetData(angle); |
161 |
|
} |
162 |
|
*/ |
163 |
< |
} |
164 |
< |
OBMol* OOPSEFormat::createMolFromFragment(OBMol& mol, vector<int>& fragment) |
165 |
< |
{ |
163 |
> |
} |
164 |
> |
|
165 |
> |
OBMol* OOPSEFormat::createMolFromFragment(OBMol& mol, vector<int>& fragment) { |
166 |
> |
|
167 |
|
OBMol* newMol = new OBMol(); |
168 |
|
newMol->ReserveAtoms(fragment.size()); |
169 |
|
newMol->BeginModify(); |
170 |
< |
for(vector<int>::iterator i = fragment.begin(); i != fragment.end(); ++i) |
171 |
< |
{ |
172 |
< |
OBAtom* newAtom = newMol->NewAtom(); |
172 |
< |
*newAtom = *mol.GetAtom(*i); |
170 |
> |
for(vector<int>::iterator i = fragment.begin(); i != fragment.end(); ++i) { |
171 |
> |
OBAtom* newAtom = newMol->NewAtom(); |
172 |
> |
*newAtom = *mol.GetAtom(*i); |
173 |
|
} |
174 |
|
newMol->EndModify(); |
175 |
|
newMol->ConnectTheDots(); |
176 |
|
findAngles(*newMol); |
177 |
|
newMol->FindTorsions(); |
178 |
|
return newMol; |
179 |
< |
} |
180 |
< |
void OOPSEFormat::WriteMDFile(vector<OBMol*> mols, vector<int> numMols, ostream& os) |
181 |
< |
{ |
182 |
< |
std::string identLevel1("\t"); |
183 |
< |
std::string identLevel2("\t\t"); |
179 |
> |
} |
180 |
> |
|
181 |
> |
void OOPSEFormat::WriteMDFile(vector<OBMol*> mols, vector<int> numMols, ostream& os, OBMol& mol, vector<int>& indices) { |
182 |
> |
std::string indentLevel1(" "); |
183 |
> |
std::string indentLevel2(" "); |
184 |
|
std::string molPrefix("MolName"); |
185 |
+ |
unsigned int i; |
186 |
|
const int BUFFLEN = 1024; |
187 |
|
char buffer[BUFFLEN]; |
188 |
|
|
188 |
– |
for(unsigned int i = 0; i < mols.size(); ++i) |
189 |
– |
{ |
190 |
– |
OBMol* pmol = mols[i]; |
191 |
– |
map<OBAtom*, int> atomMap; |
192 |
– |
os << "molecule {\n"; |
193 |
– |
sprintf(buffer, "%d", i); |
194 |
– |
os << identLevel1 << "name = " << "\"" << molPrefix << buffer << "\"" << ";\n"; |
195 |
– |
|
196 |
– |
|
197 |
– |
//atom |
198 |
– |
int ai = 0; |
199 |
– |
FOR_ATOMS_OF_MOL(atom, *pmol ) { |
200 |
– |
os << identLevel1 << "atom[" << ai << "] {\n"; |
201 |
– |
os << identLevel2 << "type = " << "\"" << atom->GetType() << "\"" << ";\n"; |
202 |
– |
os << identLevel1 << "}\n"; |
203 |
– |
atomMap[&(*atom)] = ai++; |
204 |
– |
} |
205 |
– |
os << "\n"; |
206 |
– |
|
207 |
– |
//bond |
208 |
– |
FOR_BONDS_OF_MOL(bond, *pmol ) { |
209 |
– |
os << identLevel1 << "bond {\n"; |
210 |
– |
os << identLevel2 << "members(" << atomMap[bond->GetBeginAtom()] << ", " << atomMap[bond->GetEndAtom()] << ");\n"; |
211 |
– |
os << identLevel1 << "}\n"; |
212 |
– |
} |
213 |
– |
/* |
214 |
– |
//bend |
215 |
– |
OBGenericData* pGenericData = pmol->GetData(OBGenericDataType::AngleData); |
216 |
– |
OBAngleData* pAngleData = dynamic_cast<OBAngleData*>(pGenericData); |
217 |
– |
vector<OBAngle> angles = pAngleData->GetData(); |
218 |
– |
|
219 |
– |
os << identLevel1 << "nBends = " << angles.size() << ";\n"; |
220 |
– |
int bendIndex = 0; |
221 |
– |
for (vector<OBAngle>::iterator ti = angles.begin(); ti != angles.end(); ++ti) |
222 |
– |
{ |
223 |
– |
triple<OBAtom*, OBAtom*, OBAtom*> bendAtoms = ti->getAtoms(); |
224 |
– |
os << identLevel1 << "bend[" << bendIndex++ << "] {\n"; |
225 |
– |
os << identLevel2 << "member(" << atomMap[bendAtoms.first] << ", " << atomMap[bendAtoms.second] << atomMap[bendAtoms.third] <<");\n"; |
226 |
– |
os << identLevel1 << "}\n"; |
227 |
– |
} |
228 |
– |
|
229 |
– |
//torsion |
230 |
– |
pGenericData = pmol->GetData(OBGenericDataType::TorsionData); |
231 |
– |
OBTorsionData* pTorsionData = dynamic_cast<OBTorsionData*>(pGenericData); |
232 |
– |
vector<OBTorsion> torsions = pTorsionData->GetData(); |
233 |
– |
vector<quad<OBAtom*,OBAtom*,OBAtom*,OBAtom*> > torsionArray; |
234 |
– |
for (vector<OBTorsion>::iterator ti = torsions.begin(); ti != torsions.end(); ++ti) |
235 |
– |
{ |
236 |
– |
vector<quad<OBAtom*,OBAtom*,OBAtom*,OBAtom*> > tmpTorsions = ti->getTorsions(); |
237 |
– |
torsionArray.insert(torsionArray.end(), tmpTorsions.begin(), tmpTorsions.end()); |
238 |
– |
} |
239 |
– |
|
240 |
– |
os << identLevel1 << "nTorsions = " << torsionArray.size() << ";\n"; |
241 |
– |
int torsionIndex = 0; |
242 |
– |
for (vector<quad<OBAtom*,OBAtom*,OBAtom*,OBAtom*> >::iterator ti = torsionArray.begin(); ti != torsionArray.end(); ++ti) |
243 |
– |
{ |
244 |
– |
os << identLevel1 << "torsion[" << torsionIndex++ << "] {\n"; |
245 |
– |
os << identLevel2 << "member(" << atomMap[ti->first] << ", " << atomMap[ti->second] <<", " << atomMap[ti->third] <<", " << atomMap[ti->forth] << ");\n"; |
246 |
– |
os << identLevel1 << "}\n"; |
247 |
– |
} |
248 |
– |
*/ |
249 |
– |
os << "}\n"; |
250 |
– |
os << "\n"; |
251 |
– |
|
252 |
– |
} |
253 |
– |
|
254 |
– |
os << "\n"; |
255 |
– |
os << "nComponents = " << mols.size() << ";\n"; |
189 |
|
|
190 |
< |
for(unsigned int i =0; i < mols.size(); ++i) |
191 |
< |
{ |
259 |
< |
os << "component{\n"; |
260 |
< |
sprintf(buffer, "%d", i); |
261 |
< |
os << "type = " << molPrefix << buffer << ";\n"; |
262 |
< |
os << "nMol = " << numMols[i]<< ";\n"; |
263 |
< |
os << "}\n"; |
264 |
< |
} |
265 |
< |
} |
266 |
< |
void OOPSEFormat::WriteINFile(OBMol& mol, ostream& ofs, vector<int>& indices) |
267 |
< |
{ |
268 |
< |
unsigned int i; |
269 |
< |
char buffer[BUFF_SIZE]; |
190 |
> |
os << "<OOPSE version=4>" << endl; |
191 |
> |
os << " <MetaData>" << endl << endl; |
192 |
|
|
193 |
< |
sprintf(buffer,"%d", mol.NumAtoms()); |
194 |
< |
ofs << buffer << endl; |
195 |
< |
//sprintf(buffer,"0;%f, 0, 0; 0, %15.7f, 0; 0, 0, %15.7f;", boxx, boxy, boxz); |
196 |
< |
sprintf(buffer, "0;%f, 0, 0; 0, %15.7f, 0; 0, 0, %15.7f;", 100.0, 100.0, 100.0); |
197 |
< |
ofs << buffer << endl; |
193 |
> |
for(i = 0; i < mols.size(); ++i) { |
194 |
> |
OBMol* pmol = mols[i]; |
195 |
> |
map<OBAtom*, int> atomMap; |
196 |
> |
os << "molecule {\n"; |
197 |
> |
sprintf(buffer, "%d", i); |
198 |
> |
os << indentLevel1 << "name = " << "\"" << molPrefix << buffer << "\"" << ";\n"; |
199 |
> |
|
200 |
> |
|
201 |
> |
//atom |
202 |
> |
int ai = 0; |
203 |
> |
FOR_ATOMS_OF_MOL(atom, *pmol ) { |
204 |
> |
os << indentLevel1 << "atom[" << ai << "] {\n"; |
205 |
> |
os << indentLevel2 << "type = " << "\"" << etab.GetSymbol(atom->GetAtomicNum()) << "\"" << ";\n"; |
206 |
> |
os << indentLevel1 << "}\n"; |
207 |
> |
atomMap[&(*atom)] = ai++; |
208 |
> |
} |
209 |
> |
os << "\n"; |
210 |
> |
|
211 |
> |
//bond |
212 |
> |
FOR_BONDS_OF_MOL(bond, *pmol ) { |
213 |
> |
os << indentLevel1 << "bond {\n"; |
214 |
> |
os << indentLevel2 << "members(" << atomMap[bond->GetBeginAtom()] << ", " << atomMap[bond->GetEndAtom()] << ");\n"; |
215 |
> |
os << indentLevel1 << "}\n"; |
216 |
> |
} |
217 |
> |
/* |
218 |
> |
//bend |
219 |
> |
OBGenericData* pGenericData = pmol->GetData(OBGenericDataType::AngleData); |
220 |
> |
OBAngleData* pAngleData = dynamic_cast<OBAngleData*>(pGenericData); |
221 |
> |
vector<OBAngle> angles = pAngleData->GetData(); |
222 |
> |
|
223 |
> |
os << indentLevel1 << "nBends = " << angles.size() << ";\n"; |
224 |
> |
int bendIndex = 0; |
225 |
> |
for (vector<OBAngle>::iterator ti = angles.begin(); ti != angles.end(); ++ti) |
226 |
> |
{ |
227 |
> |
triple<OBAtom*, OBAtom*, OBAtom*> bendAtoms = ti->getAtoms(); |
228 |
> |
os << indentLevel1 << "bend[" << bendIndex++ << "] {\n"; |
229 |
> |
os << indentLevel2 << "member(" << atomMap[bendAtoms.first] << ", " << atomMap[bendAtoms.second] << atomMap[bendAtoms.third] <<");\n"; |
230 |
> |
os << indentLevel1 << "}\n"; |
231 |
> |
} |
232 |
> |
|
233 |
> |
//torsion |
234 |
> |
pGenericData = pmol->GetData(OBGenericDataType::TorsionData); |
235 |
> |
OBTorsionData* pTorsionData = dynamic_cast<OBTorsionData*>(pGenericData); |
236 |
> |
vector<OBTorsion> torsions = pTorsionData->GetData(); |
237 |
> |
vector<quad<OBAtom*,OBAtom*,OBAtom*,OBAtom*> > torsionArray; |
238 |
> |
for (vector<OBTorsion>::iterator ti = torsions.begin(); ti != torsions.end(); ++ti) |
239 |
> |
{ |
240 |
> |
vector<quad<OBAtom*,OBAtom*,OBAtom*,OBAtom*> > tmpTorsions = ti->getTorsions(); |
241 |
> |
torsionArray.insert(torsionArray.end(), tmpTorsions.begin(), tmpTorsions.end()); |
242 |
> |
} |
243 |
> |
|
244 |
> |
os << indentLevel1 << "nTorsions = " << torsionArray.size() << ";\n"; |
245 |
> |
int torsionIndex = 0; |
246 |
> |
for (vector<quad<OBAtom*,OBAtom*,OBAtom*,OBAtom*> >::iterator ti = torsionArray.begin(); ti != torsionArray.end(); ++ti) |
247 |
> |
{ |
248 |
> |
os << indentLevel1 << "torsion[" << torsionIndex++ << "] {\n"; |
249 |
> |
os << indentLevel2 << "member(" << atomMap[ti->first] << ", " << atomMap[ti->second] <<", " << atomMap[ti->third] <<", " << atomMap[ti->forth] << ");\n"; |
250 |
> |
os << indentLevel1 << "}\n"; |
251 |
> |
} |
252 |
> |
*/ |
253 |
> |
os << "}" << endl; |
254 |
> |
os << endl; |
255 |
> |
|
256 |
> |
} |
257 |
> |
|
258 |
> |
os << endl; |
259 |
|
|
260 |
+ |
|
261 |
+ |
for(i=0; i < mols.size(); ++i) { |
262 |
+ |
os << "component{" << endl; |
263 |
+ |
sprintf(buffer, "%d", i); |
264 |
+ |
os << indentLevel1 << "type = " << molPrefix << buffer << ";" << endl; |
265 |
+ |
os << indentLevel1 << "nMol = " << numMols[i]<< ";" << endl; |
266 |
+ |
os << "}" << endl; |
267 |
+ |
} |
268 |
+ |
|
269 |
+ |
os << " </MetaData>" << endl; |
270 |
+ |
os << " <Snapshot>" << endl; |
271 |
+ |
os << " <FrameData>" << endl; |
272 |
+ |
|
273 |
+ |
sprintf(buffer, " Time: %.10g", 0.0); |
274 |
+ |
|
275 |
+ |
os << buffer << endl; |
276 |
+ |
|
277 |
+ |
sprintf(buffer, " Hmat: {{ %.10g, %.10g, %.10g }, { %.10g, %.10g, %.10g }, { %.10g, %.10g, %.10g }}", 100.0, 0.0, 0.0, 0.0, 100.0, 0.0, 0.0, 0.0, 100.0); |
278 |
+ |
|
279 |
+ |
os << buffer << endl; |
280 |
+ |
os << " </FrameData>" << endl; |
281 |
+ |
os << " <StuntDoubles>" << endl; |
282 |
+ |
|
283 |
|
OBAtom *atom; |
284 |
|
string str,str1; |
285 |
|
|
286 |
< |
for(vector<int>::iterator i = indices.begin();i != indices.end(); ++i) |
287 |
< |
{ |
288 |
< |
atom = mol.GetAtom(*i); |
289 |
< |
sprintf(buffer,"%15s%15.5f%15.5f%15.5f%15.5f%15.5f%15.5f%15.5f%15.5f%15.5f%15.5f%15.5f%15.5f%15.5f", |
284 |
< |
atom->GetType(), |
285 |
< |
atom->GetX(), atom->GetY(), atom->GetZ(), |
286 |
< |
0.0, 0.0, 0.0, |
287 |
< |
0.0, 0.0, 0.0, 0.0, |
288 |
< |
0.0, 0.0, 0.0 |
289 |
< |
); |
290 |
< |
ofs << buffer << endl; |
286 |
> |
for(vector<int>::iterator i = indices.begin();i != indices.end(); ++i) { |
287 |
> |
atom = mol.GetAtom(*i); |
288 |
> |
sprintf(buffer, "%d\tpv\t%18.10g\t%18.10g\t%18.10g\t%14.10g\t%14.10g\t%14.10g", *i - 1, atom->GetX(), atom->GetY(), atom->GetZ(), 0.0, 0.0, 0.0); |
289 |
> |
os << buffer << endl; |
290 |
|
} |
291 |
< |
|
291 |
> |
os << " </StuntDoubles>" << endl; |
292 |
> |
os << " </Snapshot>" << endl; |
293 |
> |
os << "</OOPSE>" << endl; |
294 |
|
} |
295 |
< |
|
295 |
> |
|
296 |
|
} //namespace OpenBabel |
297 |
|
|