2

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 ?

xbello
  • 7,223
  • 3
  • 28
  • 41

1 Answers1

1

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>
xbello
  • 7,223
  • 3
  • 28
  • 41
  • Thank you. What I want is to change/add the keys of the dictionary. The script you gave is creating new chains and add them to `model.child_dict` . And I got this : `{'A': , ' ': }`. And my chain still has no id. – Aurore Vaitinadapoule Oct 28 '15 at 14:22
  • How are you creating the Chain object? You have to pass the id to the constructor as in `Chain("C")` (note the C). – xbello Oct 28 '15 at 15:20