text: user747: There is already a question on PDB/CIF to MMTF, however what is a robust way to programmatically go between PDB and CIF files?
  For example I can use a python script from this gist that relies on Biopython.
  id="4ckh"
  wget http://www.ebi.ac.uk/pdbe/static/entry/download/$id-assembly-1.cif.gz
  gunzip $id-assembly-1.cif.gz
  python cif2pdb.py $id-assembly-1.cif $id.pdb
  
  This process yields a pdb structure as shown below.
  
  The issues are:
  
  Requires python/Biopython to be installed.
  The output isn't perfectly clean.
  The gist is relatively undeveloped and hasn't got much evidence of testing.
  
  
  user4622: Converting a PDB file to some version of an mmCIF file is always possible provided the PDB file doesn't have any "problems". However grouping identical molecules into the same entity is non-trivial so the Biopython and BioJulia mmCIF writers (which I wrote) do not try and do this, simply assigning new entites for each molecule. These files will also be missing other things like the metadata parts of the mmCIF dictionary not involving the atoms.
  In Biopython:
  from Bio.PDB import PDBParser, MMCIFIO
  p = PDBParser()
  struc = p.get_structure("", "file.pdb")
  io = MMCIFIO()
  io.set_structure(struc)
  io.save("file.cif")
  
  In BioJulia:
  using BioStructures
  struc = read("file.pdb", PDB)
  writemmcif("file.cif", struc)
  
  Going the other way is, however, not always possible. You can run out of atom serials or chain IDs to use in the output PDB file (this is one reason for the switch to mmCIF files in general). The gist you have linked is a way to get round this.
  If this is not a problem for your structure you can invert the above snippets to get a decent PDB file - see the relevant docs. Note that in both cases it will use the auth_seq_id and auth_asym_id fields to get the residue number and chain ID rather than the relabelled label versions. The test suites of Biopython and BioJulia do test these conversions pretty thoroughly.
  There is also pdb-tools if you do not want to install Biopython, though both involve a simple pip install so it's not much difference.
  For some speed benchmarks of various software see here and here.
  
original_text: 747: <p>There is already <a href="https://bioinformatics.stackexchange.com/questions/694/converter-between-pdb-or-mmcif-and-mmtf">a question on PDB/CIF to MMTF</a>, however what is a robust way to programmatically go between PDB and CIF files?</p>
  
  <p>For example I can use a python script from this <a href="https://gist.github.com/sbliven/b7cc2c5305aa3652a75a580ae7c6ce33" rel="nofollow noreferrer">gist</a> that relies on Biopython.</p>
  
  <pre><code>id="4ckh"
  wget http://www.ebi.ac.uk/pdbe/static/entry/download/<span class="math-container">$id-assembly-1.cif.gz
  gunzip $</span>id-assembly-1.cif.gz
  python cif2pdb.py <span class="math-container">$id-assembly-1.cif $</span>id.pdb
  </code></pre>
  
  <p>This process yields a pdb structure as shown below.</p>
  
  <p><img src="https://i.stack.imgur.com/wWiJG.png" alt="A large protein structure"></p>
  
  <p>The issues are:</p>
  
  <ul>
  <li>Requires python/Biopython to be installed.</li>
  <li>The output isn't perfectly clean.</li>
  <li>The gist is relatively undeveloped and hasn't got much evidence of testing.</li>
  </ul>
   4622: <p>Converting a PDB file to some version of an mmCIF file is always possible provided the PDB file doesn't have any "problems". However grouping identical molecules into the same entity is non-trivial so the Biopython and BioJulia mmCIF writers (which I wrote) do not try and do this, simply assigning new entites for each molecule. These files will also be missing other things like the metadata parts of the mmCIF dictionary not involving the atoms.</p>
  
  <p>In Biopython:</p>
  
  <pre class="lang-py prettyprint-override"><code>from Bio.PDB import PDBParser, MMCIFIO
  p = PDBParser()
  struc = p.get_structure("", "file.pdb")
  io = MMCIFIO()
  io.set_structure(struc)
  io.save("file.cif")
  </code></pre>
  
  <p>In BioJulia:</p>
  
  <pre><code>using BioStructures
  struc = read("file.pdb", PDB)
  writemmcif("file.cif", struc)
  </code></pre>
  
  <p>Going the other way is, however, not always possible. You can run out of atom serials or chain IDs to use in the output PDB file (this is one reason for the switch to mmCIF files in general). The gist you have linked is a way to get round this.</p>
  
  <p>If this is not a problem for your structure you can invert the above snippets to get a decent PDB file - see the relevant docs. Note that in both cases it will use the <code>auth_seq_id</code> and <code>auth_asym_id</code> fields to get the residue number and chain ID rather than the relabelled <code>label</code> versions. The test suites of Biopython and BioJulia do test these conversions pretty thoroughly.</p>
  
  <p>There is also <a href="https://github.com/haddocking/pdb-tools" rel="nofollow noreferrer">pdb-tools</a> if you do not want to install Biopython, though both involve a simple <code>pip install</code> so it's not much difference.</p>
  
  <p>For some speed benchmarks of various software see <a href="https://github.com/jgreener64/pdb-benchmarks" rel="nofollow noreferrer">here</a> and <a href="https://github.com/project-gemmi/mmcif-benchmark" rel="nofollow noreferrer">here</a>.</p>
  