text: user6445: I am trying to obtain the sequence from PDB file, but no output is given when I run the following code :  
  from Bio import SeqIO
  
  with open("1a9l.pdb", "r") as handle:
      for record in SeqIO.parse(handle, "pdb-atom"):
          print(record.seq)
  
  
  user6322: If you are using a conda version of python you can use Pymol module for this, which is actually more robust in some aspects than bio.PDB, although errors may cause segmentation faults. The following:
  import pymol2
  ## paralellisable version.
  with pymol2.PyMOL() as pymol:
      pymol.cmd.fetch('1a9l')
      print(pymol.cmd.get_fastastr('polymer.nucleic'))
  
  Gives me:
  >1a9l_A
  GGGUGACUCCAGAGGUCGAGAGACCGGAGAUAUCACCC
  
  Alternatively, you can use PDBe's API.
  import requests
  
  response = requests.get('https://www.ebi.ac.uk/pdbe/api/pdb/entry/molecules/1a9l').json()['1a9l']
  
  for entity in response:
      if entity['molecule_type'] == 'polyribonucleotide':
          print(entity['sequence'])
  
  Do note that missing 'residues' (residues, small molecules and nucleotides) will cause issues. PDB files do not have missing 'residues', while mmCIF files have a dictionary that does. The API will give you the latter.
  
  user4622: That PDB entry is an RNA molecule, so there is no protein sequence to extract.
  If it extracted the RNA sequence by default here you can see there could be an ambiguity as to whether it was an RNA sequence or a protein sequence, as the alphabets share characters.
  
original_text: 6445: <p>I am trying to obtain the sequence from PDB file, but no output is given when I run the following code :  </p>
  
  <pre><code>from Bio import SeqIO
  
  with open("1a9l.pdb", "r") as handle:
      for record in SeqIO.parse(handle, "pdb-atom"):
          print(record.seq)
  </code></pre>
   6322: <p>If you are using a conda version of python you can use Pymol module for this, which is actually more robust in some aspects than <code>bio.PDB</code>, although errors may cause segmentation faults. The following:</p>
  
  <pre><code>import pymol2
  ## paralellisable version.
  with pymol2.PyMOL() as pymol:
      pymol.cmd.fetch('1a9l')
      print(pymol.cmd.get_fastastr('polymer.nucleic'))
  </code></pre>
  
  <p>Gives me:</p>
  
  <pre><code>&gt;1a9l_A
  GGGUGACUCCAGAGGUCGAGAGACCGGAGAUAUCACCC
  </code></pre>
  
  <p>Alternatively, you can use PDBe's API.</p>
  
  <pre><code>import requests
  
  response = requests.get('https://www.ebi.ac.uk/pdbe/api/pdb/entry/molecules/1a9l').json()['1a9l']
  
  for entity in response:
      if entity['molecule_type'] == 'polyribonucleotide':
          print(entity['sequence'])
  </code></pre>
  
  <p>Do note that missing 'residues' (residues, small molecules and nucleotides) will cause issues. PDB files do not have missing 'residues', while mmCIF files have a dictionary that does. The API will give you the latter.</p>
   4622: <p>That <a href="http://www.rcsb.org/structure/1A9L" rel="nofollow noreferrer">PDB entry</a> is an RNA molecule, so there is no protein sequence to extract.</p>
  
  <p>If it extracted the RNA sequence by default here you can see there could be an ambiguity as to whether it was an RNA sequence or a protein sequence, as the alphabets share characters.</p>
  