Skip to content

PDBx/mmCIF Reader/Topology Reader #2367

@JoaoRodrigues

Description

@JoaoRodrigues

Hi all,

I've been using OpenMM to run simulations for the past couple of years. Unlike other tools, OpenMM does not write a 'topology' file (e.g. .gro, .prmtop) but instead creates a Topology object on the fly when loading structures. Because simulation systems tend to be quite large, I've take to use PDBx/mmCIF files as my default file format for writing structures that I use as topologies.

I'd like to start using MDAnalysis but right now this involves jumping through a bunch of hoops to get my topologies in a format that is parseable. It'd be much easier if I could just load a PDBx/mmCIF file as a topology, specially since it's now the default file format for structures in the PDB.

To this end, I've started working on writing a simple PDBxParser class. I wouldn't mind extending it to a PDBxReader/Writer class but that is not necessarily a priority (specially the writer). Would this be an interesting feature to add in your opinion? See the code here, I modeled the class after PDBParser.

Thanks for the great work with the library so far!

EDIT: Since I cannot label issues, I'm just editing the title of the issue for now to make it clear!

Activity

changed the title [-]PDBx/mmCIF Reader/Topology Reader[/-] [+][Feature][Improvement] PDBx/mmCIF Reader/Topology Reader[/+] on Oct 15, 2019
changed the title [-][Feature][Improvement] PDBx/mmCIF Reader/Topology Reader[/-] [+][Feature][Contrib] PDBx/mmCIF Reader/Topology Reader[/+] on Oct 15, 2019
orbeckst

orbeckst commented on Oct 17, 2019

@orbeckst
Member

Hi @JoaoRodrigues , new formats are a great addition. Can you just create a PR and then we can comment directly on the code, run tests, etc?

changed the title [-][Feature][Contrib] PDBx/mmCIF Reader/Topology Reader[/-] [+]PDBx/mmCIF Reader/Topology Reader[/+] on Oct 17, 2019
JoaoRodrigues

JoaoRodrigues commented on Oct 17, 2019

@JoaoRodrigues
Author

Sounds good. Will do. Thanks!

orbeckst

orbeckst commented on Jul 30, 2020

@orbeckst
Member
orbeckst

orbeckst commented on Jul 30, 2020

@orbeckst
Member

Also, chemfiles reads mmCIF and can be used inside MDAnalysis, see Reading trajectories with chemfiles.

orbeckst

orbeckst commented on Jul 8, 2021

@orbeckst
Member

Note on trying to use chemfiles:

With the 2.0.0b,

u = mda.Universe("1ake.cif.gz", topology_format="chemfiles")

fails with

'CHEMFILES' isn't a valid topology format, nor a coordinate format

I can't just read it with

u = mda.Universe("1ake.cif.gz", format="chemfiles")

either as it gives the same ValueError.

Just trying something stupid with the topology as a PDB also fails

u = mda.Universe("1ake.pdb.gz", "1ake.cif.gz", format="chemfiles")

with

ChemfilesError: can not read file '1ake.cif.gz' at step 0, it does not contain any step.

Conclusion: I couldn't get it to work with chemfiles. Maybe @Luthaf has some ideas but a key problem seems to be that our (EDIT) chemfiles converter do not work for topologies —— ??

Luthaf

Luthaf commented on Jul 8, 2021

@Luthaf
Contributor

I think that topology reading is not registered with MDA, since the chemfiles adapter is implemented as a coordinate reader/writer. Although the conversion from chemfiles to MDA topologies is already implemented, so it should be mostly a question of adding a new ChemfilesParser class. I'll have a look at this next week!

ChemfilesError: can not read file '1ake.cif.gz' at step 0, it does not contain any step.

This is a bit strange and probably a bug, is this 1ake from the wwwPDB?

Luthaf

Luthaf commented on Jul 8, 2021

@Luthaf
Contributor

This is a bit strange and probably a bug, is this 1ake from the wwwPDB?

Ok, I understand this part. The core of the issue is that to relatively different formats want to use the same extension: mmCIF and crystallography CIF. While they both use the same STAR format, they specify data in different ways. Unfortunately, chemfiles is associating the .cif extension with crystallography CIF files, and uses .mmcif for mmCIF.

There is a simple workaround though, since you can specify the format to use manually, with something like

u = mda.Universe("1ake.pdb.gz", "1ake.cif.gz", format="chemfiles", chemfiles_format="mmCIF / GZ")

Unfortunately, this still fails in the case of 1AKE (but should work for other files). I'll fix the 1AKE issue, it should be working in the next patch release.

I would also like to introduce a better format guessing functionality, to decide between mmCIF and crystallography CIF on the fly instead of having the use specify it manually.

9 remaining items

orbeckst

orbeckst commented on May 17, 2022

@orbeckst
Member

The mmCIF/PDBx format would also be needed for alphafold #3377 .

razvanmarinescu

razvanmarinescu commented on Aug 16, 2022

@razvanmarinescu

does anyone have a solution for writing an MDAnalysis universe as PDBx/mmCIF?

joaomcteixeira

joaomcteixeira commented on Aug 16, 2022

@joaomcteixeira
Member

you could use pdb_tocif tool from pdb-tools applied to all PDB files from a trajectory and then pdb_mkensemble to merge them.

razvanmarinescu

razvanmarinescu commented on Aug 16, 2022

@razvanmarinescu

I just tried pdb_tocif, but it screws up the segids. It should have segid of B0, or B1, ... It only keeps the chain (B). See the question marks below:

ATOM   374778 H  HA     ?     B   ? 116   ?    352.061     37.526    138.818      1.000      0.000 ? 116       B HA   1
ATOM   374779 C  CB     ?     B   ? 116   ?    353.637     37.061    140.192      1.000      0.000 ? 116       B CB   1
ATOM   374780 H  HB2    ?     B   ? 116   ?    353.967     36.114    140.621      1.000      0.000 ? 116       B HB2  1
ATOM   374781 H  HB3    ?     B   ? 116   ?    354.280     37.265    139.336      1.000      0.000 ? 116       B HB3  1
ATOM   374782 C  CG     ?     B   ? 116   ?    353.874     38.157    141.231      1.000      0.000 ? 116       B CG   1
JoaoRodrigues

JoaoRodrigues commented on Aug 16, 2022

@JoaoRodrigues
Author

Sorry to cross-post on a different project, but could you share an input file?pdb_tocif is not designed to handle multi-character chain identifiers. Feel free to open an issue in the pdb-tools repo.

marinegor

marinegor commented on May 15, 2024

@marinegor
Contributor

I wonder if it'd be ok to use gemmi library (link) as a dependency to read mmcif and other cif-like formats consistently?

IMO it's one of the best supported crystallography-related libraries, is maintained by ccp4 and globalphasing, and allows very detailed cif parsing and writing.

For example, reading all atom ID and coordinates could be done as simple as:

# read only ATOM groups of chain 

model = gemmi.read_structure('6rz6.cif')[0]
residues = [res for res in model['A'] if res.het_flag == 'A'] # reading non-heteroatom atoms for simplicity
arr = np.array([[at.serial, *at.pos.tolist()] for res in residues for at in res])

ids, xyzs = arr[:, 0].astype(int), arr[:, 1:]

the whole discussion with devs here

hmacdope

hmacdope commented on May 17, 2024

@hmacdope
Member

@marinegor I think @richardjgowers has some ideas in this area

marinegor

marinegor commented on May 20, 2024

@marinegor
Contributor

@richardjgowers could you share them (here, if it's appropriate place, or somewhere on discord)?

richardjgowers

richardjgowers commented on May 23, 2024

@richardjgowers
Member

@marinegor I'd done this at a hackathon: #4303

The problem with this approach is that it doesn't do the "table join" on conect records that mmcif relies on, so you won't get some data (bonds).

I've since done this: https://github.com/OpenFreeEnergy/pdbinf which does do the "table join" to get bonds. It's into rdkit format, but conversion is trivial...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @JoaoRodrigues@orbeckst@razvanmarinescu@joaomcteixeira@Luthaf

      Issue actions

        PDBx/mmCIF Reader/Topology Reader · Issue #2367 · MDAnalysis/mdanalysis