| 16 |
|
|
| 17 |
|
#include <openbabel/babelconfig.h> |
| 18 |
|
#include <openbabel/obmolecformat.h> |
| 19 |
+ |
#include <openbabel/obiter.h> |
| 20 |
+ |
#include <openbabel/mol.h> |
| 21 |
+ |
#include <openbabel/chains.h> |
| 22 |
|
#include <fstream> |
| 23 |
|
|
| 24 |
+ |
#include "utils/StringUtils.hpp" |
| 25 |
+ |
|
| 26 |
|
using namespace std; |
| 27 |
|
namespace OpenBabel |
| 28 |
|
{ |
| 60 |
|
|
| 61 |
|
private: |
| 62 |
|
bool AreSameFragments(OBMol& mol, vector<int>& frag1, vector<int>& frag2); |
| 63 |
< |
void findAngles(OBMol& mol); |
| 63 |
> |
//void findAngles(OBMol& mol); |
| 64 |
|
OBMol* createMolFromFragment(OBMol& mol, vector<int>& fragment); |
| 65 |
|
void WriteMDFile(vector<OBMol*> mols, vector<int> numMols, ostream& os, OBMol& mol, vector<int>& indices); |
| 66 |
|
}; |
| 124 |
|
} |
| 125 |
|
|
| 126 |
|
string OutputFileName = pConv->GetInFilename(); |
| 127 |
< |
unsigned int pos = OutputFileName.rfind("."); |
| 128 |
< |
if(pos==string::npos) |
| 124 |
< |
OutputFileName += ".md"; |
| 125 |
< |
else |
| 127 |
> |
size_t pos = OutputFileName.rfind("."); |
| 128 |
> |
if(pos!=string::npos) |
| 129 |
|
OutputFileName = OutputFileName.substr(0, pos) + ".md"; |
| 130 |
+ |
else |
| 131 |
+ |
OutputFileName += ".md"; |
| 132 |
+ |
|
| 133 |
|
ofstream ofs(OutputFileName.c_str()); |
| 134 |
|
if(!ofs) |
| 135 |
|
{ |
| 180 |
|
return (t1.second == t2.second) && ( (t1.first == t2.first && t1.third == t2.third) || (t1.first == t2.third && t1.third == t2.first)); |
| 181 |
|
} |
| 182 |
|
}; |
| 183 |
< |
|
| 184 |
< |
void OOPSEFormat::findAngles(OBMol& mol) { |
| 185 |
< |
/* |
| 183 |
> |
|
| 184 |
> |
/* |
| 185 |
> |
void OOPSEFormat::findAngles(OBMol& mol) { |
| 186 |
> |
|
| 187 |
|
//if already has data return |
| 188 |
|
if(mol.HasData(OBGenericDataType::AngleData)) |
| 189 |
|
return; |
| 220 |
|
angle.SetAtoms(i->first, i->second, i->second); |
| 221 |
|
angles->SetData(angle); |
| 222 |
|
} |
| 223 |
< |
*/ |
| 223 |
> |
|
| 224 |
|
} |
| 225 |
+ |
*/ |
| 226 |
|
|
| 227 |
|
OBMol* OOPSEFormat::createMolFromFragment(OBMol& mol, vector<int>& fragment) { |
| 228 |
|
|
| 229 |
|
OBMol* newMol = new OBMol(); |
| 230 |
+ |
OBChainsParser* chainParser = new OBChainsParser(); |
| 231 |
|
newMol->ReserveAtoms(fragment.size()); |
| 232 |
|
newMol->BeginModify(); |
| 233 |
|
for(vector<int>::iterator i = fragment.begin(); i != fragment.end(); ++i) { |
| 236 |
|
} |
| 237 |
|
newMol->EndModify(); |
| 238 |
|
newMol->ConnectTheDots(); |
| 239 |
< |
findAngles(*newMol); |
| 239 |
> |
newMol->PerceiveBondOrders(); |
| 240 |
> |
newMol->FindAngles(); |
| 241 |
|
newMol->FindTorsions(); |
| 242 |
+ |
//chainParser->PerceiveChains(*newMol, false); |
| 243 |
+ |
|
| 244 |
|
return newMol; |
| 245 |
|
} |
| 246 |
|
|
| 248 |
|
std::string indentLevel1(" "); |
| 249 |
|
std::string indentLevel2(" "); |
| 250 |
|
std::string molPrefix("MolName"); |
| 251 |
+ |
std::string resName; |
| 252 |
|
unsigned int i; |
| 253 |
|
const int BUFFLEN = 1024; |
| 254 |
|
char buffer[BUFFLEN]; |
| 255 |
|
string str, str1; |
| 256 |
+ |
OBAtom *a, *b, *c, *d; |
| 257 |
+ |
OBChainsParser* chainParser = new OBChainsParser(); |
| 258 |
+ |
OBResidue *r; |
| 259 |
+ |
int resKey; |
| 260 |
+ |
char type_name[10]; |
| 261 |
+ |
char *element_name; |
| 262 |
+ |
int res_num; |
| 263 |
|
|
| 264 |
< |
|
| 264 |
> |
std::cerr << "yo\n"; |
| 265 |
|
os << "<OOPSE version=4>" << endl; |
| 266 |
|
os << " <MetaData>" << endl << endl; |
| 267 |
|
|
| 268 |
|
for(i = 0; i < mols.size(); ++i) { |
| 269 |
|
OBMol* pmol = mols[i]; |
| 270 |
< |
|
| 270 |
> |
std::cerr << "yo1\n"; |
| 271 |
|
pmol->ConnectTheDots(); |
| 272 |
|
pmol->PerceiveBondOrders(); |
| 273 |
+ |
chainParser->PerceiveChains(*pmol, false); |
| 274 |
|
//pmol->FindSSSR(); |
| 275 |
|
//pmol->SetAromaticPerceived(); |
| 276 |
|
//pmol->Kekulize(); |
| 280 |
|
sprintf(buffer, "%d", i); |
| 281 |
|
os << indentLevel1 << "name = " << "\"" << molPrefix << buffer << "\"" << ";\n"; |
| 282 |
|
|
| 283 |
+ |
|
| 284 |
|
//atom |
| 285 |
+ |
|
| 286 |
|
int ai = 0; |
| 287 |
+ |
FOR_RESIDUES_OF_MOL(res, *pmol) { |
| 288 |
+ |
|
| 289 |
+ |
std::cerr << "found residue" << res->GetName() << "\n"; |
| 290 |
+ |
} |
| 291 |
+ |
|
| 292 |
+ |
// FOR_RESIDUES_OF_MOL(res, *pmol) { |
| 293 |
+ |
|
| 294 |
+ |
// resName = res->GetName(); |
| 295 |
+ |
// resKey = res->GetResKey(); |
| 296 |
+ |
|
| 297 |
+ |
|
| 298 |
+ |
|
| 299 |
+ |
// std::cerr << "found residue " << resName << "\n"; |
| 300 |
+ |
// std::cerr << " num = " << res->GetNum() << "\n"; |
| 301 |
+ |
// std::cerr << " numAtoms = " << res->GetNumAtoms() << "\n"; |
| 302 |
+ |
// std::cerr << " num = " << res->GetNum() << "\n"; |
| 303 |
+ |
// std::cerr << " chain = " << res->GetChain() << "\n"; |
| 304 |
+ |
// std::cerr << " chainnum = " << res->GetChainNum() << "\n"; |
| 305 |
+ |
// std::cerr << " idx = " << res->GetIdx() << "\n"; |
| 306 |
+ |
// std::cerr << " key = " << res->GetResKey() << "\n"; |
| 307 |
+ |
|
| 308 |
+ |
|
| 309 |
+ |
// FOR_ATOMS_OF_RESIDUE(atom, &*res) { |
| 310 |
+ |
// str = atom->GetType(); |
| 311 |
+ |
// ttab.SetFromType("INT"); |
| 312 |
+ |
// ttab.SetToType("INT"); |
| 313 |
+ |
// ttab.Translate(str1,str); |
| 314 |
+ |
// os << indentLevel1 << "atom[" << ai << "] {\n"; |
| 315 |
+ |
// os << indentLevel2 << "type = " << "\"" << resName << "-" << str1 << "\"" << ";\n"; |
| 316 |
+ |
// os << indentLevel1 << "}\n"; |
| 317 |
+ |
// atomMap[&(*atom)] = ai++; |
| 318 |
+ |
// } |
| 319 |
+ |
// os << "\n"; |
| 320 |
+ |
|
| 321 |
+ |
// } |
| 322 |
+ |
|
| 323 |
+ |
ai = 0; |
| 324 |
|
FOR_ATOMS_OF_MOL(atom, *pmol ) { |
| 325 |
|
str = atom->GetType(); |
| 326 |
< |
ttab.SetFromType("INT"); |
| 327 |
< |
ttab.SetToType("INT"); |
| 328 |
< |
ttab.Translate(str1,str); |
| 329 |
< |
os << indentLevel1 << "atom[" << ai << "] {\n"; |
| 330 |
< |
// os << indentLevel2 << "type = " << "\"" << etab.GetSymbol(atom->GetAtomicNum()) << "\"" << ";\n"; |
| 331 |
< |
os << indentLevel2 << "type = " << "\"" << str1 << "\"" << ";\n"; |
| 332 |
< |
os << indentLevel1 << "}\n"; |
| 326 |
> |
r = atom->GetResidue(); |
| 327 |
> |
|
| 328 |
> |
if (r == NULL) |
| 329 |
> |
resName = "NULL"; |
| 330 |
> |
else |
| 331 |
> |
resName = r->GetName(); |
| 332 |
> |
|
| 333 |
> |
if (resName.compare("NULL") ==0 || resName.compare("LIG") == 0 || resName.compare("UNK") == 0) { |
| 334 |
> |
// Either couldn't find a residue at all or couldn't find a reasonable |
| 335 |
> |
// residue name to use. We'll punt and use OpenBabel's internal atom typing: |
| 336 |
> |
ttab.SetFromType("INT"); |
| 337 |
> |
ttab.SetToType("INT"); |
| 338 |
> |
ttab.Translate(str1,str); |
| 339 |
> |
} else { |
| 340 |
> |
|
| 341 |
> |
|
| 342 |
> |
if (resName.compare("HOH") == 0) { |
| 343 |
> |
// HOH is a special residue name for water, and the standard atom types |
| 344 |
> |
// are OW and HW, so just append W to the string for the atom type: |
| 345 |
> |
ttab.SetFromType("INT"); |
| 346 |
> |
ttab.SetToType("XYZ"); |
| 347 |
> |
ttab.Translate(str1,str); |
| 348 |
> |
str1 += "W"; |
| 349 |
> |
} else { |
| 350 |
> |
|
| 351 |
> |
std::cerr << "found residue " << resName << "\n"; |
| 352 |
> |
|
| 353 |
> |
// If we know what residue we've got, the specific atom name can |
| 354 |
> |
// be used to help specify partial charges. |
| 355 |
> |
|
| 356 |
> |
str = r->GetAtomID(&*atom); |
| 357 |
> |
size_t startpos = str.find_first_not_of(" "); |
| 358 |
> |
size_t endpos = str.find_last_not_of(" "); |
| 359 |
> |
str = str.substr( startpos, endpos-startpos+1 ); |
| 360 |
> |
str1 = resName + "-" + str; |
| 361 |
> |
} |
| 362 |
> |
|
| 363 |
> |
} |
| 364 |
> |
|
| 365 |
> |
// os << indentLevel1 << "atom[" << ai << "] {\n"; |
| 366 |
> |
// os << indentLevel2 << "type = " << "\"" << str1 << "\"" << ";\n"; |
| 367 |
> |
// os << indentLevel1 << "}\n"; |
| 368 |
> |
os << "atom[" << ai << "] { "; |
| 369 |
> |
os << "type = " << "\"" << str1 << "\"" << "; "; |
| 370 |
> |
os << "}\n"; |
| 371 |
|
atomMap[&(*atom)] = ai++; |
| 372 |
|
} |
| 373 |
|
os << "\n"; |
| 374 |
|
|
| 375 |
|
//bond |
| 376 |
|
FOR_BONDS_OF_MOL(bond, *pmol ) { |
| 377 |
< |
os << indentLevel1 << "bond {\n"; |
| 378 |
< |
os << indentLevel2 << "members(" << atomMap[bond->GetBeginAtom()] << ", " << atomMap[bond->GetEndAtom()] << ");\n"; |
| 379 |
< |
os << indentLevel1 << "}\n"; |
| 380 |
< |
} |
| 377 |
> |
// os << indentLevel1 << "bond {\n"; |
| 378 |
> |
// os << indentLevel2 << "members(" << atomMap[bond->GetBeginAtom()] << ", " << atomMap[bond->GetEndAtom()] << ");\n"; |
| 379 |
> |
// os << indentLevel1 << "}\n"; |
| 380 |
> |
os << "bond { "; |
| 381 |
> |
os << "members(" << atomMap[bond->GetBeginAtom()] << ", " << atomMap[bond->GetEndAtom()] << "); "; |
| 382 |
> |
os << "}\n"; |
| 383 |
> |
} |
| 384 |
> |
|
| 385 |
> |
FOR_ANGLES_OF_MOL(angle, *pmol) { |
| 386 |
> |
|
| 387 |
> |
// OpenBabel's getAtoms returns the 3 atom pointer for the |
| 388 |
> |
// angle with the vertex first. These need to be reordered |
| 389 |
> |
// for vertex-second ordering for OOPSE. |
| 390 |
> |
|
| 391 |
> |
b = pmol->GetAtom((*angle)[0] + 1); |
| 392 |
> |
a = pmol->GetAtom((*angle)[1] + 1); |
| 393 |
> |
c = pmol->GetAtom((*angle)[2] + 1); |
| 394 |
> |
|
| 395 |
> |
// os << indentLevel1 << "bend {\n"; |
| 396 |
> |
// os << indentLevel2 << "members(" << atomMap[a] << ", " << atomMap[b] << ", " << atomMap[c] << ");\n"; |
| 397 |
> |
// os << indentLevel1 << "}\n"; |
| 398 |
> |
os << "bend { "; |
| 399 |
> |
os << "members(" << atomMap[a] << ", " << atomMap[b] << ", " << atomMap[c] << "); "; |
| 400 |
> |
os << "}\n"; |
| 401 |
> |
} |
| 402 |
> |
|
| 403 |
> |
FOR_TORSIONS_OF_MOL(torsion, *pmol) { |
| 404 |
> |
|
| 405 |
> |
// OpenBabel's getAtoms returns the 3 atom pointer for the |
| 406 |
> |
// angle with the vertex first. These need to be reordered |
| 407 |
> |
// for vertex-second ordering for OOPSE. |
| 408 |
> |
|
| 409 |
> |
a = pmol->GetAtom((*torsion)[0] + 1); |
| 410 |
> |
b = pmol->GetAtom((*torsion)[1] + 1); |
| 411 |
> |
c = pmol->GetAtom((*torsion)[2] + 1); |
| 412 |
> |
d = pmol->GetAtom((*torsion)[3] + 1); |
| 413 |
> |
|
| 414 |
> |
// os << indentLevel1 << "torsion {\n"; |
| 415 |
> |
// os << indentLevel2 << "members(" << atomMap[a] << ", " << atomMap[b] << ", " << atomMap[c] << ", " << atomMap[d] << ");\n"; |
| 416 |
> |
// os << indentLevel1 << "}\n"; |
| 417 |
> |
|
| 418 |
> |
os << "torsion { "; |
| 419 |
> |
os << "members(" << atomMap[a] << ", " << atomMap[b] << ", " << atomMap[c] << ", " << atomMap[d] << "); "; |
| 420 |
> |
os << "}\n"; |
| 421 |
> |
} |
| 422 |
> |
|
| 423 |
|
/* |
| 424 |
|
//bend |
| 425 |
|
OBGenericData* pGenericData = pmol->GetData(OBGenericDataType::AngleData); |