How to quickly and robustly convert between mmCIF and PDB? 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.
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.