[Biopython-dev] changing PDB file chains
David Cain
davidjosephcain at gmail.com
Mon Jun 17 02:52:12 UTC 2013
Hi, John. Your error is that you're using pdbid[0]["A"], where pdbid is a
string (not an instance of PDB.Structure, as you probably expect it to be).
You seem to have the parent detachment down, you just need to properly
attach to a new chain. Calling waterResidue.add(...) will add a child
object to the residue (which should be an atom:
http://biopython.org/DIST/docs/api/Bio.PDB.Residue-pysrc.html#L73).
Instead, you want to call newChain.add(waterResidue).
Just FYI, looking at how Structures are constructed by
StructureBuilder<http://biopython.org/DIST/docs/api/Bio.PDB.StructureBuilder.StructureBuilder-class.html>
should
help you with the mechanics of modifying the SMRCA hierarchy. That is,
StructureBuilder creates a Structure from scratch- if you understand how a
Structure is built, it should make modifying a Structure trivial!
As far as Aniso records, I don't believe the current implementation of
PDBIO can handle that. You could always modify the source code to fit your
needs, though! (I'm sure others would benefit from your changes).
David Cain
+1 (339) 222 4452
On Sun, Jun 16, 2013 at 4:33 PM, John Berrisford <jmb at ebi.ac.uk> wrote:
> Thanks for the advice****
>
> ** **
>
> Can you help in how to set a chain using the add method?****
>
> ** **
>
> Also the PDBIO writer appears to remove aniso records. Is there anyway to
> stop it doing this?****
>
> ** **
>
> Currently my code is:****
>
> pdbFile = PDBParser().get_structure(pdbid, pdbPath)****
>
> waterChain = pdbFile[0]['W']****
>
> newChain = pdbFile[0]['A']****
>
> waterAtom = pdbFile[0]['W']['W', 1031, ' ']['O']****
>
> waterResidue = pdbFile[0]['W']['W', 1031, ' ']****
>
> print waterChain.id****
>
> print waterResidue.get_parent()****
>
> waterResidue.detach_parent() #this bit seems to work****
>
> print waterResidues.get_parent()****
>
> waterResidue.add(pdbid[0]["A"]) #i’m not sure exactly how to get a
> chainID. ****
>
> print waterResidue.get_parent()****
>
> print waterResidue.id****
>
> ** **
>
> which returns:****
>
> W****
>
> <Chain id=W> #original parent (chain) of the residue. ****
>
> None #detach parent seems to work fine****
>
> Traceback (most recent call last):****
>
> File “water_orig.py", line 53, in <module>****
>
> waterResidue.add(pdbid[0]["A"])****
>
> TypeError: string indices must be integers, not str****
>
> ** **
>
> ** **
>
> My writer commands are:****
>
> pdb_writer = PDBIO()****
>
> pdb_writer.set_structure(pdbFile)****
>
> pdb_writer.save("output_path.pdb")****
>
> ** **
>
> ** **
>
> Regards****
>
> ** **
>
> John****
>
> ** **
>
> *From:* João Rodrigues [mailto:anaryin at gmail.com]
> *Sent:* 14 June 2013 10:50
> *To:* John Berrisford
> *Cc:* David Cain; biopython-dev at lists.open-bio.org
> *Subject:* Re: [Biopython-dev] changing PDB file chains****
>
> ** **
>
> Hi John,****
>
> ** **
>
> Actually, David is absolutely right.. I didn't really think it through.
> You need to move the water atoms to the chain where you want them to be.
> So, if they are in chain A and should be in chain B, you need to detach
> them from chain A (detach_child method on the residue, easier) and
> re-attach it to chain B (add method).****
>
More information about the Biopython-dev
mailing list