From: Dr N. O'B. <no...@ca...> - 2006-07-22 07:20:10
|
On Jul 22 2006, Rajarshi Guha wrote: >I'm using the code I got on your website: > >obconversion = OBConversion() >obconversion.SetInFormat("sdf") >obmol = OBMol() > >notatend = obconversion.ReadFile(obmol,"test.sdf") >while notatend: > print obmol.GetMolWt() > print obmol.NumAtoms() > obmol = OBMol() > notatend = obconversion.Read(obmol) > >So this is for iterating over the molecules in a single file. I would >like to do this for multiple files. My question is do I need to make a >new obmol object (using the first 3 lines) for each input file. Or can I >just reuse obconversiona and obmol for each new input file? I don't know the answer to this without checking. It would be reasonable to expect that it is possible. Note that you definitely need to create a new obmol every time or else it reads in the new atoms into the previous obmol (without first wiping it clean - it is more memory efficient to wipe it clean though if you do not need to keep the molecule). You need to test something like the following: obconversion = OBConversion() obconversion.SetInFormat("sdf") obmol = OBMol() for filename in ["file1.sdf", "file2.sdf"]: notatend = obconversion.ReadFile(obmol, filename) while notatend: print obmol.GetMolWt() print obmol.NumAtoms() obmol = OBMol() notatend = obconversion.Read(obmol) Regards, Noel |