From: Dr N. O'B. <no...@ca...> - 2006-03-16 17:56:32
|
Regarding the wrapping of streams, you may find the following interesting: http://embedded.eecs.berkeley.edu/Alumni/pinhong/scriptEDA/pyTypemapFAQ.html#8 It appears to show a way of wrapping them. Regards, Noel On Mar 16 2006, Noel O'Boyle wrote: >I'm not having great luck with this method. > >Attempt 1 Using Read after ReadFile >========= >from openbabel import * > >myfile = "3d.head.sdf" >obConversion = OBConversion() >obConversion.SetInFormat("sdf") > >mymol = OBMol() >obConversion.ReadFile(mymol,myfile) >print mymol.GetMolWt() >print obConversion.Read(mymol) >print "The program segfaults before this line" > >Attempt 2 Using Read after ReadString >========= >from openbabel import * > >myfilestring = open("3d.head.sdf","r").read() >obConversion = OBConversion() >obConversion.SetInFormat("sdf") > >mymol = OBMol() >obConversion.ReadString(mymol,myfilestring) >print mymol.GetMolWt() >print obConversion.Read(mymol) >print "The program aborts before this line" > >>From the python point of view, what is needed is a function that when >repeatedly called, will return additional molecules. This doesn't need >to be in the main openbabel library, but can be in the SWIG wrapper >somewhere. > >Regards, > Noel > >On Wed, 2006-03-15 at 14:18 -0500, Geoffrey Hutchison wrote: >> On Mar 15, 2006, at 5:18 AM, Noel O'Boyle wrote: >> >> > It seems that OBConversion.ReadFile(OBMolecule) just reads in the >> > first >> > molecule, and I cannot see a way of iterating over the molecules. >> >> The OBConversion.Read(OBMol) function should continue to read from >> the same file. However, since Python and Perl have no concept of >> "streams", it's not possible to use OBConversion.Read() to set up the >> input file or string. >> >> So something like this (sorry, I haven't written much Python, so the >> syntax might be off): >> >> import openbabel >> >> mol = openbabel.OBMol() >> conv = openbabel.OBConversion() >> conv.SetInAndOutFormats("sdf", "sdf") >> obConversion.ReadString(mol, "test.sdf") >> >> while (obConversion.Read(mol)) >> ... >> >> >> Cheers, >> -Geoff > > > > ------------------------------------------------------- This SF.Net email > is sponsored by xPML, a groundbreaking scripting language that extends > applications into web and mobile media. Attend the live webcast and join > the prime developer group breaking into this new coding territory! > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 > _______________________________________________ OpenBabel-scripting > mailing list Ope...@li... > https://lists.sourceforge.net/lists/listinfo/openbabel-scripting |