Answers.Body: <p>Create a function and run it for each pdb file.</p>
  <pre><code>from Bio.PDB import PDBParser
  
  def print_residues(name, pdb_file, chain_key, out_file):
      parser = PDBParser()
      structure = parser.get_structure(name, pdb_file)
      model = structure[0]
      chain = model[chain_key]
      with open(out_file, 'w') as fp:
          for i in chain.get_residues():
              print(i, file=fp)
  </code></pre>
  <p>Then run the function for all pdb files.</p>
  <pre><code>print_residues('1d8t', '1d8t.pdb', 'C', '1d8t.txt')
  # ...
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-05-27T18:57:11.970Z
Answers.LastActivityDate: 2022-05-27T18:57:11.970Z
Answers.UserDisplayName: Simeon Borko
Body: <p>I'm new to biopython &amp; I'm trying to extract residues from specific chain of each file from a list of 316 pdb files. Eg: <a href="https://www.rcsb.org/structure/1d8t" rel="nofollow noreferrer">1d8t</a> has four chains A, B, C &amp; D of which my interest is to extract just the residues of C chain. As the chain of interest differs for different files, I'm not knowing how to extract specific chain residue from each file and save it separately.</p>
  <pre><code>from Bio import *
  from Bio.PDB.PDBParser import PDBParser
  from Bio.PDB.Polypeptide import PPBuilder
  structure = PDBParser().get_structure('1d8t', '1d8t.pdb')    
  
  
  model = structure[0]
  chain = model['C']
  
  for i in chain.get_residues():
      print(i)
  </code></pre>
  <p>With the above code I was able to extract the residues of C chains not sure how to proceed for multiple files in python.</p>
  
Tags: <python><pdb><parsing>
Title: How to extract residues from specific chain of interest from multiple pdb files?
ThreadText: # How to extract residues from specific chain of interest from multiple pdb files?
  
  (Asked by: username_0 on 2022-05-19)
  
  I'm new to biopython & I'm trying to extract residues from specific chain of each file from a list of 316 pdb files. Eg: [1d8t](https://www.rcsb.org/structure/1d8t) has four chains A, B, C & D of which my interest is to extract just the residues of C chain. As the chain of interest differs for different files, I'm not knowing how to extract specific chain residue from each file and save it separately.
  
  ```
  from Bio import *
  from Bio.PDB.PDBParser import PDBParser
  from Bio.PDB.Polypeptide import PPBuilder
  structure = PDBParser().get_structure('1d8t', '1d8t.pdb')    
  
  model = structure[0]
  chain = model['C']
  
  for i in chain.get_residues():
      print(i)
  
  ```
  
  With the above code I was able to extract the residues of C chains not sure how to proceed for multiple files in python.
  
  **Tags:** python, pdb, parsing
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-05-27. Score: 1
  
  Create a function and run it for each pdb file.
  
  ```
  from Bio.PDB import PDBParser
  
  def print_residues(name, pdb_file, chain_key, out_file):
      parser = PDBParser()
      structure = parser.get_structure(name, pdb_file)
      model = structure[0]
      chain = model[chain_key]
      with open(out_file, 'w') as fp:
          for i in chain.get_residues():
              print(i, file=fp)
  
  ```
  
  Then run the function for all pdb files.
  
  ```
  print_residues('1d8t', '1d8t.pdb', 'C', '1d8t.txt')
  # ...
  
  ```
  
  
  ---
  
  