[Biopython] Problem when adding a residue

Lenna Peterson arklenna at gmail.com
Mon Jul 25 13:08:56 UTC 2016


Hi Claudia,

Rather than add the residue directly to the structure, you need to add it
to a chain. So you will want to do something like
`structure[0]["A"].add(...)` (depending on the models/chains in your
structure).

The PDB object in Biopython has 5 hierarchical levels:
Structure
Model
Chain
Residue
Atom

The error occurred because the `PDBIO.save` method expects the child of a
`Structure` object to be a `Model` object, which has the attribute
`serial_num`.

Let me know if you still run into any problems.

Cheers,

Lenna

On Mon, Jul 25, 2016 at 7:26 AM, Claudia Millán Nebot <cmncri at ibmb.csic.es>
wrote:

> Dear all,
>
> I am using Biopython to parse a pdb model extracted from a larger pdb and
> if a condition is met, complete it with some residues from the original pdb
> model. The residue object that I am trying to add was saved when parsing
> the original larger pdb, but when I am trying to add it to the new model I
> am getting this error:
>
>   File
> "/Library/Python/2.7/site-packages/biopython-1.66-py2.7-macosx-10.11-intel.egg/Bio/PDB/PDBIO.py",
> line 187, in save
>
>     fp.write("MODEL      %s\n" % model.serial_num)
>
> AttributeError: 'Residue' object has no attribute 'serial_num'
>
>
> The pdb model that I am completing might have some changes in the chain
> nomenclature, could that be the reason for the error? But apparently is
> raised for something related with the model... so I am not sure what is
> happening.
>
> This is the relevant piece of code where the error happens:
>
>                         if add==True and checkres!=resi.get_full_id()[-1]:
>
>                               ncheckres=checkres[1]
>
>                               print "Adding ncheckres",ncheckres
>
>                               print
> "dictio_template[ncheckres]['residue_object']",dictio_template[ncheckres][
> 'residue_object']
>
>                               checkresobj=dictio_template[ncheckres][
> 'residue_object']
>
>                               #print "resi.serial_num",resi.serial_num()
>
>                               #print
> "list_res[i+1].serial_num",list_res[i+1].serial_num()
>
>                               #print
> "checkresobj.serial_num",checkresobj.serial_num()
>
>                               structure.add(dictio_template[ncheckres][
> 'residue_object'])
>
> Thanks in advance,
>
>
> Claudia
>
> _______________________________________________
> Biopython mailing list  -  Biopython at mailman.open-bio.org
> http://mailman.open-bio.org/mailman/listinfo/biopython
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.open-bio.org/pipermail/biopython/attachments/20160725/f23d62f3/attachment.html>


More information about the Biopython mailing list