I follow this page How to extract chains from a PDB file? but I am not able to find complete solution of what I want. Here is my question:
without giving particular chain id, I want to extract all the chain ids in the pdb and write these chain ids in seperate pdb file. Could you please tell me how to extract the all chain existed in pdb? For example, if pdb contains two chains, I want to write all two chains seperately.
6CHY - It has two chain A and B. I want to write A chain in 6CHY_A.pdb and B chain in 6CHY_B respectively.
All the chains in the pdb can be retrieved with get_chains
.
pdb = PDBParser().get_structure("6CHY", "6CHY.pdb")
for chain in pdb.get_chains():
# Chain business goes here
Say you need to write each chain to a separate file. Do this:
from Bio.PDB import PDBParser, PDBIO
io = PDBIO()
pdb = PDBParser().get_structure("6CHY", "6CHY.pdb")
for chain in pdb.get_chains():
io.set_structure(chain)
io.save(pdb.get_id() + "_" + chain.get_id() + ".pdb")