1

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.

Community
  • 1
  • 1
Exchhattu
  • 197
  • 3
  • 15

2 Answers2

3

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")
xbello
  • 7,223
  • 3
  • 28
  • 41
0

I solved the problem. Perhaps maynot be smart way. Simple answer or solution is always welcome. For writing PDB for given chain, please follow this thread which is written perfectly - How to extract chains from a PDB file?

In addition, get all the chains using this piece of code

chain_ids = []
struct = self.parser.get_structure("6CHY", "./6CHY.pdb")
chains = struct[0] # I need only X-RAY structures 
for chain in chains:
    chain_ids.append(chain.get_id())

Please append these lines of code in How to extract chains from a PDB file?

Community
  • 1
  • 1
Exchhattu
  • 197
  • 3
  • 15