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.