| 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 |
+ |
string str, str1; |
| 189 |
|
|
| 190 |
< |
for(unsigned int i = 0; i < mols.size(); ++i) |
| 191 |
< |
{ |
| 192 |
< |
OBMol* pmol = mols[i]; |
| 193 |
< |
map<OBAtom*, int> atomMap; |
| 194 |
< |
os << "molecule {\n"; |
| 195 |
< |
sprintf(buffer, "%d", i); |
| 194 |
< |
os << identLevel1 << "name = " << "\"" << molPrefix << buffer << "\"" << ";\n"; |
| 190 |
> |
|
| 191 |
> |
os << "<OOPSE version=4>" << endl; |
| 192 |
> |
os << " <MetaData>" << endl << endl; |
| 193 |
> |
|
| 194 |
> |
for(i = 0; i < mols.size(); ++i) { |
| 195 |
> |
OBMol* pmol = mols[i]; |
| 196 |
|
|
| 197 |
< |
|
| 198 |
< |
//atom |
| 199 |
< |
int ai = 0; |
| 200 |
< |
FOR_ATOMS_OF_MOL(atom, *pmol ) { |
| 201 |
< |
os << identLevel1 << "atom[" << ai << "] {\n"; |
| 201 |
< |
os << identLevel2 << "type = " << "\"" << atom->GetType() << "\"" << ";\n"; |
| 202 |
< |
os << identLevel1 << "}\n"; |
| 203 |
< |
atomMap[&(*atom)] = ai++; |
| 204 |
< |
} |
| 197 |
> |
pmol->ConnectTheDots(); |
| 198 |
> |
pmol->PerceiveBondOrders(); |
| 199 |
> |
//pmol->FindSSSR(); |
| 200 |
> |
//pmol->SetAromaticPerceived(); |
| 201 |
> |
//pmol->Kekulize(); |
| 202 |
|
|
| 203 |
< |
//bond |
| 204 |
< |
FOR_BONDS_OF_MOL(bond, *pmol ) { |
| 205 |
< |
os << identLevel1 << "bond {\n"; |
| 206 |
< |
os << identLevel2 << "members(" << atomMap[bond->GetBeginAtom()] << ", " << atomMap[bond->GetEndAtom()] << ");\n"; |
| 207 |
< |
os << identLevel1 << "}\n"; |
| 208 |
< |
} |
| 209 |
< |
/* |
| 210 |
< |
//bend |
| 211 |
< |
OBGenericData* pGenericData = pmol->GetData(OBGenericDataType::AngleData); |
| 212 |
< |
OBAngleData* pAngleData = dynamic_cast<OBAngleData*>(pGenericData); |
| 213 |
< |
vector<OBAngle> angles = pAngleData->GetData(); |
| 214 |
< |
|
| 215 |
< |
os << identLevel1 << "nBends = " << angles.size() << ";\n"; |
| 216 |
< |
int bendIndex = 0; |
| 217 |
< |
for (vector<OBAngle>::iterator ti = angles.begin(); ti != angles.end(); ++ti) |
| 218 |
< |
{ |
| 219 |
< |
triple<OBAtom*, OBAtom*, OBAtom*> bendAtoms = ti->getAtoms(); |
| 220 |
< |
os << identLevel1 << "bend[" << bendIndex++ << "] {\n"; |
| 221 |
< |
os << identLevel2 << "member(" << atomMap[bendAtoms.first] << ", " << atomMap[bendAtoms.second] << atomMap[bendAtoms.third] <<");\n"; |
| 222 |
< |
os << identLevel1 << "}\n"; |
| 223 |
< |
} |
| 224 |
< |
|
| 225 |
< |
//torsion |
| 226 |
< |
pGenericData = pmol->GetData(OBGenericDataType::TorsionData); |
| 227 |
< |
OBTorsionData* pTorsionData = dynamic_cast<OBTorsionData*>(pGenericData); |
| 228 |
< |
vector<OBTorsion> torsions = pTorsionData->GetData(); |
| 229 |
< |
vector<quad<OBAtom*,OBAtom*,OBAtom*,OBAtom*> > torsionArray; |
| 230 |
< |
for (vector<OBTorsion>::iterator ti = torsions.begin(); ti != torsions.end(); ++ti) |
| 203 |
> |
map<OBAtom*, int> atomMap; |
| 204 |
> |
os << "molecule {\n"; |
| 205 |
> |
sprintf(buffer, "%d", i); |
| 206 |
> |
os << indentLevel1 << "name = " << "\"" << molPrefix << buffer << "\"" << ";\n"; |
| 207 |
> |
|
| 208 |
> |
//atom |
| 209 |
> |
int ai = 0; |
| 210 |
> |
FOR_ATOMS_OF_MOL(atom, *pmol ) { |
| 211 |
> |
str = atom->GetType(); |
| 212 |
> |
ttab.SetFromType("INT"); |
| 213 |
> |
ttab.SetToType("INT"); |
| 214 |
> |
ttab.Translate(str1,str); |
| 215 |
> |
os << indentLevel1 << "atom[" << ai << "] {\n"; |
| 216 |
> |
// os << indentLevel2 << "type = " << "\"" << etab.GetSymbol(atom->GetAtomicNum()) << "\"" << ";\n"; |
| 217 |
> |
os << indentLevel2 << "type = " << "\"" << str1 << "\"" << ";\n"; |
| 218 |
> |
os << indentLevel1 << "}\n"; |
| 219 |
> |
atomMap[&(*atom)] = ai++; |
| 220 |
> |
} |
| 221 |
> |
os << "\n"; |
| 222 |
> |
|
| 223 |
> |
//bond |
| 224 |
> |
FOR_BONDS_OF_MOL(bond, *pmol ) { |
| 225 |
> |
os << indentLevel1 << "bond {\n"; |
| 226 |
> |
os << indentLevel2 << "members(" << atomMap[bond->GetBeginAtom()] << ", " << atomMap[bond->GetEndAtom()] << ");\n"; |
| 227 |
> |
os << indentLevel1 << "}\n"; |
| 228 |
> |
} |
| 229 |
> |
/* |
| 230 |
> |
//bend |
| 231 |
> |
OBGenericData* pGenericData = pmol->GetData(OBGenericDataType::AngleData); |
| 232 |
> |
OBAngleData* pAngleData = dynamic_cast<OBAngleData*>(pGenericData); |
| 233 |
> |
vector<OBAngle> angles = pAngleData->GetData(); |
| 234 |
> |
|
| 235 |
> |
os << indentLevel1 << "nBends = " << angles.size() << ";\n"; |
| 236 |
> |
int bendIndex = 0; |
| 237 |
> |
for (vector<OBAngle>::iterator ti = angles.begin(); ti != angles.end(); ++ti) |
| 238 |
|
{ |
| 239 |
< |
vector<quad<OBAtom*,OBAtom*,OBAtom*,OBAtom*> > tmpTorsions = ti->getTorsions(); |
| 240 |
< |
torsionArray.insert(torsionArray.end(), tmpTorsions.begin(), tmpTorsions.end()); |
| 239 |
> |
triple<OBAtom*, OBAtom*, OBAtom*> bendAtoms = ti->getAtoms(); |
| 240 |
> |
os << indentLevel1 << "bend[" << bendIndex++ << "] {\n"; |
| 241 |
> |
os << indentLevel2 << "member(" << atomMap[bendAtoms.first] << ", " << atomMap[bendAtoms.second] << atomMap[bendAtoms.third] <<");\n"; |
| 242 |
> |
os << indentLevel1 << "}\n"; |
| 243 |
|
} |
| 244 |
< |
|
| 245 |
< |
os << identLevel1 << "nTorsions = " << torsionArray.size() << ";\n"; |
| 246 |
< |
int torsionIndex = 0; |
| 247 |
< |
for (vector<quad<OBAtom*,OBAtom*,OBAtom*,OBAtom*> >::iterator ti = torsionArray.begin(); ti != torsionArray.end(); ++ti) |
| 244 |
> |
|
| 245 |
> |
//torsion |
| 246 |
> |
pGenericData = pmol->GetData(OBGenericDataType::TorsionData); |
| 247 |
> |
OBTorsionData* pTorsionData = dynamic_cast<OBTorsionData*>(pGenericData); |
| 248 |
> |
vector<OBTorsion> torsions = pTorsionData->GetData(); |
| 249 |
> |
vector<quad<OBAtom*,OBAtom*,OBAtom*,OBAtom*> > torsionArray; |
| 250 |
> |
for (vector<OBTorsion>::iterator ti = torsions.begin(); ti != torsions.end(); ++ti) |
| 251 |
|
{ |
| 252 |
< |
os << identLevel1 << "torsion[" << torsionIndex++ << "] {\n"; |
| 253 |
< |
os << identLevel2 << "member(" << atomMap[ti->first] << ", " << atomMap[ti->second] <<", " << atomMap[ti->third] <<", " << atomMap[ti->forth] << ");\n"; |
| 245 |
< |
os << identLevel1 << "}\n"; |
| 252 |
> |
vector<quad<OBAtom*,OBAtom*,OBAtom*,OBAtom*> > tmpTorsions = ti->getTorsions(); |
| 253 |
> |
torsionArray.insert(torsionArray.end(), tmpTorsions.begin(), tmpTorsions.end()); |
| 254 |
|
} |
| 255 |
< |
*/ |
| 256 |
< |
os << "}\n"; |
| 255 |
> |
|
| 256 |
> |
os << indentLevel1 << "nTorsions = " << torsionArray.size() << ";\n"; |
| 257 |
> |
int torsionIndex = 0; |
| 258 |
> |
for (vector<quad<OBAtom*,OBAtom*,OBAtom*,OBAtom*> >::iterator ti = torsionArray.begin(); ti != torsionArray.end(); ++ti) |
| 259 |
> |
{ |
| 260 |
> |
os << indentLevel1 << "torsion[" << torsionIndex++ << "] {\n"; |
| 261 |
> |
os << indentLevel2 << "member(" << atomMap[ti->first] << ", " << atomMap[ti->second] <<", " << atomMap[ti->third] <<", " << atomMap[ti->forth] << ");\n"; |
| 262 |
> |
os << indentLevel1 << "}\n"; |
| 263 |
> |
} |
| 264 |
> |
*/ |
| 265 |
> |
os << "}" << endl; |
| 266 |
> |
os << endl; |
| 267 |
> |
|
| 268 |
|
} |
| 269 |
+ |
|
| 270 |
+ |
os << endl; |
| 271 |
|
|
| 251 |
– |
os << "nComponents = " << mols.size() << ";\n"; |
| 272 |
|
|
| 273 |
< |
for(unsigned int i =0; i < mols.size(); ++i) |
| 274 |
< |
{ |
| 275 |
< |
os << "component{\n"; |
| 276 |
< |
sprintf(buffer, "%d", i); |
| 277 |
< |
os << "type = " << molPrefix << buffer << ";\n"; |
| 278 |
< |
os << "nMol = " << numMols[i]<< ";\n"; |
| 259 |
< |
os << "}\n"; |
| 273 |
> |
for(i=0; i < mols.size(); ++i) { |
| 274 |
> |
os << "component{" << endl; |
| 275 |
> |
sprintf(buffer, "%d", i); |
| 276 |
> |
os << indentLevel1 << "type = " << molPrefix << buffer << ";" << endl; |
| 277 |
> |
os << indentLevel1 << "nMol = " << numMols[i]<< ";" << endl; |
| 278 |
> |
os << "}" << endl; |
| 279 |
|
} |
| 261 |
– |
} |
| 262 |
– |
void OOPSEFormat::WriteINFile(OBMol& mol, ostream& ofs, vector<int>& indices) |
| 263 |
– |
{ |
| 264 |
– |
unsigned int i; |
| 265 |
– |
char buffer[BUFF_SIZE]; |
| 280 |
|
|
| 281 |
< |
sprintf(buffer,"%d", mol.NumAtoms()); |
| 282 |
< |
ofs << buffer << endl; |
| 283 |
< |
//sprintf(buffer,"0;%f, 0, 0; 0, %15.7f, 0; 0, 0, %15.7f;", boxx, boxy, boxz); |
| 284 |
< |
sprintf(buffer, "0;%f, 0, 0; 0, %15.7f, 0; 0, 0, %15.7f;", 100.0, 100.0, 100.0); |
| 285 |
< |
ofs << buffer << endl; |
| 281 |
> |
os << " </MetaData>" << endl; |
| 282 |
> |
os << " <Snapshot>" << endl; |
| 283 |
> |
os << " <FrameData>" << endl; |
| 284 |
> |
|
| 285 |
> |
sprintf(buffer, " Time: %.10g", 0.0); |
| 286 |
> |
|
| 287 |
> |
os << buffer << endl; |
| 288 |
|
|
| 289 |
+ |
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); |
| 290 |
+ |
|
| 291 |
+ |
os << buffer << endl; |
| 292 |
+ |
os << " </FrameData>" << endl; |
| 293 |
+ |
os << " <StuntDoubles>" << endl; |
| 294 |
+ |
|
| 295 |
|
OBAtom *atom; |
| 274 |
– |
string str,str1; |
| 296 |
|
|
| 297 |
< |
for(vector<int>::iterator i = indices.begin();i != indices.end(); ++i) |
| 298 |
< |
{ |
| 299 |
< |
atom = mol.GetAtom(*i); |
| 300 |
< |
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", |
| 280 |
< |
atom->GetType(), |
| 281 |
< |
atom->GetX(), atom->GetY(), atom->GetZ(), |
| 282 |
< |
0.0, 0.0, 0.0, |
| 283 |
< |
0.0, 0.0, 0.0, 0.0, |
| 284 |
< |
0.0, 0.0, 0.0 |
| 285 |
< |
); |
| 286 |
< |
ofs << buffer << endl; |
| 297 |
> |
for(vector<int>::iterator i = indices.begin();i != indices.end(); ++i) { |
| 298 |
> |
atom = mol.GetAtom(*i); |
| 299 |
> |
sprintf(buffer, "%10d %7s %18.10g %18.10g %18.10g %13e %13e %13e", *i - 1, "pv", atom->GetX(), atom->GetY(), atom->GetZ(), 0.0, 0.0, 0.0); |
| 300 |
> |
os << buffer << endl; |
| 301 |
|
} |
| 302 |
< |
|
| 302 |
> |
os << " </StuntDoubles>" << endl; |
| 303 |
> |
os << " </Snapshot>" << endl; |
| 304 |
> |
os << "</OOPSE>" << endl; |
| 305 |
|
} |
| 306 |
< |
|
| 306 |
> |
|
| 307 |
|
} //namespace OpenBabel |
| 308 |
|
|