Aurore Vaitinadapoule
Aurore Vaitinadapoule

Reputation: 153

How to add chain id in pdb

By using biopython library, I would like to add chains ids in my pdb file. I'm using

p = PDBParser()
structure=p.get_structure('mypdb',mypdb.pdb)
model=structure[0]
model.child_list=["A","B"]

But I got this error:

Traceback (most recent call last):
  File "../../principal_axis_v3.py", line 319, in <module>
    main()
  File "../../principal_axis_v3.py", line 310, in main
    protA=read_PDB(struct,ch1,s1,e1)
  File "../../principal_axis_v3.py", line 104, in read_PDB
    chain=model[ch]
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Bio/PDB/Entity.py", line 38, in __getitem__
    return self.child_dict[id]
KeyError: 'A'

I tried to changes the keys in th child.dict, butI got another error:

Traceback (most recent call last):
  File "../../principal_axis_v3.py", line 319, in <module>
    main()
  File "../../principal_axis_v3.py", line 310, in main
    protA=read_PDB(struct,ch1,s1,e1)
  File "../../principal_axis_v3.py", line 102, in read_PDB
    model.child_dict.keys=["A","B"]
AttributeError: 'dict' object attribute 'keys' is read-only

How can I add chains ids ?

Upvotes: 2

Views: 2373

Answers (1)

xbello
xbello

Reputation: 7443

Your error is that child_list is not a list with chain IDs, but of Chain objects (Bio.PDB.Chain.Chain). You have to create Chain objects and then add them to the structure. A lame example:

from Bio.PDB.Chain import Chain

my_chain = Chain("C")
model.add(my_chain)

Now you can access the model child_dict:

>>> model.child_dict
{'A': <Chain id=A>, 'C': <Chain id=C>}
>>> model.child_dict["C"]
<Chain id=C>

Upvotes: 1

Related Questions