Re: pybel.write() produces truncated pdbqt? (R. K. Belew)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: pybel.write() produces truncated pdbqt? (R. K. Belew)

Torsten Sachse
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Reply | Threaded
Open this post in threaded view
|

Re: pybel.write() produces truncated pdbqt? (R. K. Belew)

rikb
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
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
> .
>

------------------------------------------------------------------------------
_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Reply | Threaded
Open this post in threaded view
|

Re: pybel.write() produces truncated pdbqt? (R. K. Belew)

rikb
In reply to this post by Torsten Sachse
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Reply | Threaded
Open this post in threaded view
|

Re: pybel.write() produces truncated pdbqt? (R. K. Belew)

David Hall
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 <[hidden email]> 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
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/openbabel-discuss


------------------------------------------------------------------------------
_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Reply | Threaded
Open this post in threaded view
|

Re: pybel.write() produces truncated pdbqt? (R. K. Belew)

Torsten Sachse
Hi all,

I can confirm that writing the pdbqt file works without problems on several
Linux distributions (including some CentOS, RedHat and Debian Systems and
derivates). Hence, unfortunately, I cannot try to find the location of the bug
as I don't have a MacOS-system available.

It should not be too hard to add some simple debug output to the place where the
output file is written to check where exactly the error happens. Although it's
important to flush the output as shown below [1]. Maybe a programme like
Valgrind could help to find the issue if it's memory related? You could also try
to turn of optimization during the compilation. If it's a matter of trying to
access memory that is already allocated by a different programme, the issue is
more likely to occur with high optimization (at least that's what I experienced
on Linux). It'd still need to be fixed though.

Hope this helps,
Torsten

[1]: Example debug output (in case you don't know):
std::cerr << "Debug: 1" << std::endl << std::flush;

On Tue, 4 Aug 2015, David Hall wrote:

> 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 <[hidden email]> 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
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
>
>

------------------------------------------------------------------------------
_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Reply | Threaded
Open this post in threaded view
|

Re: pybel.write() produces truncated pdbqt? (R. K. Belew)

rikb
thanks very much David and Torsten.  i can also make
this work on (ubuntu 14.04) linux.

that's the good news.  the bad news (for my purposes) is that
the output PDBQT file is considerably perturbed from the original:
user/remark lines dropped, torsion tree traversal order, and
esp. atom numbering.

and given my aversion to all things C++, i'm afraid i'm not
motivated to dig in and find the OSX version of this bug.
he said guiltily(:

thanks again for helping me puzzle this through in any case.

        Rik

On 8/5/15 1:53 AM, Torsten Sachse wrote:

> Hi all,
>
> I can confirm that writing the pdbqt file works without problems on several
> Linux distributions (including some CentOS, RedHat and Debian Systems and
> derivates). Hence, unfortunately, I cannot try to find the location of
> the bug
> as I don't have a MacOS-system available.
>
> It should not be too hard to add some simple debug output to the place
> where the
> output file is written to check where exactly the error happens.
> Although it's
> important to flush the output as shown below [1]. Maybe a programme like
> Valgrind could help to find the issue if it's memory related? You could
> also try
> to turn of optimization during the compilation. If it's a matter of
> trying to
> access memory that is already allocated by a different programme, the
> issue is
> more likely to occur with high optimization (at least that's what I
> experienced
> on Linux). It'd still need to be fixed though.
>
> Hope this helps,
> Torsten
>
> [1]: Example debug output (in case you don't know):
> std::cerr << "Debug: 1" << std::endl << std::flush;
>
> On Tue, 4 Aug 2015, David Hall wrote:
>
>> 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 <[hidden email]> 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
>>> [hidden email]
>>> https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
>>
>>
> .
>

------------------------------------------------------------------------------
_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss