Re: [Open Babel] pybel.write() produces truncated pdbqt? (R. K. Belew)
Hi, I suspect that you don't modify the data structure you are iterating over but rather the iterating object. For instance when you iterate over a list and try to change the element, the following will not work (you probably know this): Input: l=[1,2,3] for i in l: i=5 print l Output: [1, 2, 3] I don't know whether Swig copies the data structure or allows you to directly modify the C++ data structure when using the iterator object. Instead, you might try to initialize a new object of the corresponding class and retreive the corresponding atom/residue via the appropriate getter function. You could also try to create an empty molecule and add all atoms to it after modifying them and print the new one. Here is an example how to iterate over all atoms via the corresponding ID: import openbabel as op def get_coordinates(mol): a=op.OBAtom() coordinates=[None]*mol.NumAtoms() for idx in range(1,mol.NumAtoms()+1): a = mol.GetAtom(idx) coordinates[idx-1] = [a.GetX(),a.GetY(),a.GetZ()] return coordinates I just tried to iterate over all residues in one of my molecules but I noticed that mol.NumResidues() returned 0 (might be because I used an XYZ-file that does not store residue information). Are you sure your are actually iterating over all residues and atoms within them? Also, if you have a look at the method you are calling: void OBResidue::SetAtomID(OBAtom *atom, const string id) { for ( unsigned int i = 0 ; i _atoms.size() ; ++i ) if (_atoms[i] == atom) _atomid[i] = id; } This checks for equivalence of pointers, so I guess they are just not equivalent, for whatever reason. Cheers and I hope this helps, Torsten hi all, i'm trying to use a basic `pybel.readfile()` -- modify molecule -- `newmol.write()` pattern, but something is not going right. the specific task is to add unique atom indices to a PDBQT file without them, but that conversion seems to be working fine. but the resulting output PDBQT contains only the REMARKS header from the original file? i'm not able to debug very far because of the Swig wrapper around the OBMol. i'm attaching the routine, and a sample PDBQT file. does anyone see the problem? thanks for any pointers, Rik -- ___ OpenBabel-discuss mailing list OpenBabel-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Re: [Open Babel] pybel.write() produces truncated pdbqt? (R. K. Belew)
update, if anyone is interested: it seems quite clear the bug is in the PDBQT output filter: obabel file1.pdbqt -O file2.pdbqt Segmentation fault: 11 obabel file1.pdbqt -O file2.pdb 1 molecule converted and has nothing particular to do with pybel; pybel is silently eating this fault and generating only partial output before it dies. Rik -- ___ OpenBabel-discuss mailing list OpenBabel-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Re: [Open Babel] pybel.write() produces truncated pdbqt? (R. K. Belew)
thanks Torsten, that was a good idea. but i've done some more testing, and it seems to have nothing to do with my modifications, but with pbmol.write(): if i simply echo back the same pybel Molecule: pbmol = pybel.readfile('pdbqt', pdbqf).next() pathName,basename = os.path.split(pdbqf) ppos = basename.find('.') bakFname = basename[:ppos]+'_2.pdbqt' bakPath = pathName + bakFname pbmol.write('pdbqt',bakPath) this is also truncated! certainly others have used the general `pbmol.write()` method; has anyone ever exercised the `pbmol.write('pdbqt')` format? (is there pybel or openbabel unit TESTING of formats like this?) in any case, i guess i need to dig into `.../ob_src/src/formats/pdbqtformat.cpp` ? or am i still confused? Rik On 8/4/15 6:13 AM, Torsten Sachse wrote: Hi, I suspect that you don't modify the data structure you are iterating over but rather the iterating object. For instance when you iterate over a list and try to change the element, the following will not work (you probably know this): Input: l=[1,2,3] for i in l: i=5 print l Output: [1, 2, 3] I don't know whether Swig copies the data structure or allows you to directly modify the C++ data structure when using the iterator object. Instead, you might try to initialize a new object of the corresponding class and retreive the corresponding atom/residue via the appropriate getter function. You could also try to create an empty molecule and add all atoms to it after modifying them and print the new one. Here is an example how to iterate over all atoms via the corresponding ID: import openbabel as op def get_coordinates(mol): a=op.OBAtom() coordinates=[None]*mol.NumAtoms() for idx in range(1,mol.NumAtoms()+1): a = mol.GetAtom(idx) coordinates[idx-1] = [a.GetX(),a.GetY(),a.GetZ()] return coordinates I just tried to iterate over all residues in one of my molecules but I noticed that mol.NumResidues() returned 0 (might be because I used an XYZ-file that does not store residue information). Are you sure your are actually iterating over all residues and atoms within them? Also, if you have a look at the method you are calling: void OBResidue::SetAtomID(OBAtom *atom, const string id) { for ( unsigned int i = 0 ; i _atoms.size() ; ++i ) if (_atoms[i] == atom) _atomid[i] = id; } This checks for equivalence of pointers, so I guess they are just not equivalent, for whatever reason. Cheers and I hope this helps, Torsten hi all, i'm trying to use a basic `pybel.readfile()` -- modify molecule -- `newmol.write()` pattern, but something is not going right. the specific task is to add unique atom indices to a PDBQT file without them, but that conversion seems to be working fine. but the resulting output PDBQT contains only the REMARKS header from the original file? i'm not able to debug very far because of the Swig wrapper around the OBMol. i'm attaching the routine, and a sample PDBQT file. does anyone see the problem? thanks for any pointers, Rik -- ___ OpenBabel-discuss mailing list OpenBabel-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbabel-discuss . -- ___ OpenBabel-discuss mailing list OpenBabel-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Re: [Open Babel] pybel.write() produces truncated pdbqt? (R. K. Belew)
It seems I can reproduce the segfault on OS X Yosemite, but not on Ubuntu 14.04. -David On Aug 4, 2015, at 8:02 PM, R. K. Belew rbe...@ucsd.edu wrote: update, if anyone is interested: it seems quite clear the bug is in the PDBQT output filter: obabel file1.pdbqt -O file2.pdbqt Segmentation fault: 11 obabel file1.pdbqt -O file2.pdb 1 molecule converted and has nothing particular to do with pybel; pybel is silently eating this fault and generating only partial output before it dies. Rik -- ___ OpenBabel-discuss mailing list OpenBabel-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbabel-discuss -- ___ OpenBabel-discuss mailing list OpenBabel-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbabel-discuss