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.

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.

A large protein structure

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.
  • 1
    $\begingroup$ I can't really address your issues certainly so I thought I would comment rather than answer, but I've had good results using Maxit (sw-tools.rcsb.org) which is produced by the RCSB. At least for submitting to the PDB Maxit is endorsed so I would hope it's robust. $\endgroup$
    – TW93
    Nov 29 '19 at 10:44

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()

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.

  • $\begingroup$ hey @jgreener! Thanks for the clarification! I'm wondering how come MMCIFIO drops metadata and such? Isn't that pretty inconvenient? let's say i need to rename (change the ids of ) certain chains in a structure and nothing else... I'll be losing all the authors' annotation, seq data etc. just by doing io.set_structure(struct), right? Are there any alternatives that you know of? $\endgroup$
    – rtviii
    Jul 16 '21 at 12:42
  • 1
    $\begingroup$ Yes, you would lose that info. The readers and writers focus on parsing the atomic structural data into a unified representation that can be modified and written back out to any file type. Developer focus has gone there rather than on writing a unified representation for the metadata. My recommendation would either be to concatenate the newly generated file onto the old metadata (beware some may be wrong now) or to use the MMCIF2Dict constructor and modify list items (writing that out preserves metadata, again some metadata may now be wrong). $\endgroup$
    – jgreener
    Jul 17 '21 at 15:27
  • $\begingroup$ that's super useful. I have played with MMCIF2Dict before and that'd actually be ideal to preserve and edit the metadata. Any tips for how to write that representation (the dict resultant from MMCIF2Dict) to a .cif file if not through MMCIFIO? $\endgroup$
    – rtviii
    Jul 17 '21 at 23:09
  • 1
    $\begingroup$ You can write a MMCIF2Dict with MMCIFIO, just use io.set_dict(d) rather than set_structure. $\endgroup$
    – jgreener
    Jul 18 '21 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.