Hi,
I found what looks like another gotcha in the Python implementation, so I'm reporting it because it could be useful to somebody else (also because I want to understand if there's something absolutely wrong about what I do).

The following code will result in a segmentation fault when running on the 
attached molecule:
-------------------------------------
import pybel
ob = pybel.ob
pmol = pybel.readfile('pdb', 'taxol.pdb').next()
mol = pmol.OBMol
for a in ob.OBMolAtomIter(mol):
    valence = a.GetValence()
    implicit = a.GetImplicitValence()
    if not (valence == implicit):
        mol.AddHydrogens(a)
-------------------------------------
Basically, the code adds hydrogens *on the fly* to atoms that miss them.
Adding Begin/EndModify() would not prevent the crash.
I suspect it has something to do with the fact that I'm altering the molecule data structure while iterating, and that messes up with the iterator.
In fact, the following code works without errors:
-------------------------------------
import pybel
ob = pybel.ob
pmol = pybel.readfile('pdb', 'taxol.pdb').next()
mol = pmol.OBMol
missing = []
for a in ob.OBMolAtomIter(mol):
    valence = a.GetValence()
    implicit = a.GetImplicitValence()
    if not (valence == implicit):
        missing.append(a)
for a in missing:
    mol.AddHydrogens(a)
-------------------------------------

Now, I understand that a segFault shouldn't happen, but I'm not sure what would be the way to prevent it. Is this a bug or something that nobody should ever do (and it should be added to the documentation)?

Thanks!

S




--
 Stefano Forli, PhD

 Staff Scientist
 Molecular Graphics Laboratory
 Dept. of Integrative Structural
  and Computational Biology, MB-112F
 The Scripps Research Institute
 10550  North Torrey Pines Road
 La Jolla,  CA 92037-1000,  USA.

    tel: +1 (858)784-2055
    fax: +1 (858)784-2860
    email: fo...@scripps.edu
    http://www.scripps.edu/~forli/

Attachment: taxol.pdb
Description: application/aportisdoc

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
OpenBabel-discuss mailing list
OpenBabel-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss

Reply via email to