From: Noel O'B. <bao...@gm...> - 2008-09-17 15:28:28
|
Hello Loris, This problem is due to the PairData object getting destroyed by Python, while the C++ OBMol still wants to keep it. The solution is to use CloneData instead of SetData. In other words, *never* use SetData from Python or any other scripting language. I will update the Python documentation to make this clear. You might find it useful to look at the code of pybel.py to see how I do things there. Noel On 16/09/2008, Loris Moretti <lor...@ch...> wrote: > Hi all, > > I am quite new to OpenBabel I am trying to develop a script in Python with > OpenBabel. The script reads a multiple sdf file, takes a molecule per time and > calculates some properties. It adds the property value and attribute to the > OBMol object with OBPairData and then, it writes out the molecules into a > multiple sdf file with the new field. > > a very simple form of the script: > > ######################################################### > #!/usr/bin/python > > import openbabel > > obConversion = openbabel.OBConversion() > obConversion.SetInAndOutFormats("sdf", "sdf") > > mol = openbabel.OBMol() > > iteratorMol = obConversion.ReadFile(mol, "molecules.sdf") > > while iteratorMol: > > newData = openbabel.OBPairData() > newData.SetAttribute("NEWDATA") > newData.SetValue("blabla") > mol.SetData(newData) > > print obConversion.WriteString(mol) > > iteratorMol = obConversion.Read(mol) > ######################################################### > > The script works for the first molecule of the input file but fails for the > others with a "segmentation fault" error. > I tested it line by line and I saw there is a problem to reuse the OBPairData > object. > > It might be a trivial error of mine but I cannot see it! > It might be an error of the system I use! > > Can anyone help, please. > > Thanks in advance, > loris... > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > OpenBabel-scripting mailing list > Ope...@li... > https://lists.sourceforge.net/lists/listinfo/openbabel-scripting > |