Hi,
I've been trying to generate molecules programatically in Python when I
found a buggy behavior.
The gist of it is that certain operations destroy the residue information.
Initially I thought it was a format-specific issue, so I've tried
writing Mol2 and PDB files (both formats support residue information).
Then I found out I could trigger this without using OBConversion(),
simply extracting the residue information from an atom.
The attached code shows how to trigger the bug in both ways.
One caveat is that I tested it only with Python, so not sure if it's
triggered by the bindings or it's a different problem.
Also, a while back [1] I reported a behavior that might be related to
this bug.
Thanks,
S
[1] https://sourceforge.net/p/openbabel/mailman/message/32894918/
--
Stefano Forli, PhD
Associate Professor
Dept. of Integrative Structural
and Computational Biology, MB-112A
Scripps Research
10550 North Torrey Pines Road
La Jolla, CA 92037-1000, USA.
tel: +1 (858)784-2055
email: fo...@scripps.edu
https://forlilab.org
from openbabel import openbabel as ob
new_mol = ob.OBMol()
# the following procedure is from pdbformat.cpp
new_mol.BeginModify()
# create atom
new_atom = ob.OBAtom()
new_atom.SetVector(0.1, 0.2, 0.3)
new_atom.SetAtomicNum(6)
# create residue
new_res = new_mol.NewResidue()
new_res.SetChain("Q")
new_res.SetName("RES")
new_res.SetNum(10)
new_res.SetInsertionCode(" ")
# add atom to molecule
new_mol.AddAtom(new_atom)
# add atom to residue and add info
new_res.AddAtom(new_atom)
new_res.SetSerialNum(new_atom, 10)
new_res.SetAtomID(new_atom, "CA")
new_res.SetHetAtom(new_atom, False)
new_atom.SetResidue(new_res)
new_mol.EndModify()
# residue still present
print("\ncheck residue info (1)")
for res in ob.OBResidueIter(new_mol):
print("RES:", res.GetName(), res.GetNum(), res.GetChain())
for a in ob.OBResidueAtomIter(res):
print("ATOM:", a.GetX(), res.GetAtomID(a), res.GetName(), res.GetNum(), res.GetChain())
print('***')
x = new_mol.GetAtom(1)
# either one of the next code blocks kills the residue information (comment to disable)
#
# BUG TRIGGER 1
print("trigger: GetResidue()")
r = x.GetResidue()
#
# BUG TRIGGER 2
# print("trigger: WriteFile()")
# conv = ob.OBConversion()
# conv.SetOutFormat('mol2')
# conv.WriteFile(new_mol, 'test.mol2')
print('***')
print("check residue info (2)")
# test: residue information lost
for res in ob.OBResidueIter(new_mol):
print("RES:", res.GetName(), res.GetNum(), res.GetChain())
for a in ob.OBResidueAtomIter(res):
print("ATOM:", a.GetX(), res.GetAtomID(a), res.GetName(), res.GetNum(), res.GetChain())
_______________________________________________
OpenBabel-discuss mailing list
OpenBabel-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss