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

Reply via email to