MDAnalysis / mdanalysis

MDAnalysis is a Python library to analyze molecular dynamics simulations.
https://mdanalysis.org
Other
1.29k stars 646 forks source link

TOPParser doesn't parse chamber-style parm7 files #2475

Open IAlibay opened 4 years ago

IAlibay commented 4 years ago

Introduction

So this is something that has been brought up in the past in the discussion group (see this post as an example).

Some time back, chamber style parm7 got introduced (I think by Jason Swails?) in AMBER in order to handle charmm topology attributes. These parm7 files some differences in structure (including the very obvious change of the TITLE %FLAG to CTITLE) which makes them current unreadable in MDAnalysis. With the introduction of #2404 this has been made a bit more pressing as the new PRM_UreyBradley datafile is cannot be parsed by our own TOPParser.

Whilst the TOPParser in its current form can probably be easily modified to handle all the new extra flags, a cursory look at the differences seems to indicate that some care/thought will be required in order to avoid bloating an already slow topology parser. Note: Information on chamber-style topologies can be found here.

Expected behavior

Loading any AMBER supported .parm7 file should work.

Actual behavior

Raises a ValueError that the topology does not contain TITLE in the header.

Code to reproduce the behavior

import MDAnalysis as mda
from MDAnalysis.tests.datafiles import PRM_UreyBradley

u = mda.Universe(PRM_UreyBradley)

Currently version of MDAnalysis

IAlibay commented 4 years ago

Having spent far far too long reading .parm7 files, I am more than willing to take this on, however it will need to be prioritised after 0.21 and fixing the netcdf reader/writer (inc. restart reader).

In the meantime, I am pushing a simple PR to give users more information when attempting to read chamber-style files.

tylerjereddy commented 3 years ago

This is causing some pain for one project I know about.

IAlibay commented 3 years ago

@tylerjereddy apologies I never really got a chance to get back to this one.

Not tested but perhaps a quick temporary solution here might be to create a universe using a parmed object and then load the trajectory on top of it?

tylerjereddy commented 3 years ago

Interesting, thanks

IAlibay commented 1 year ago

Since this came up on discord today, using the Parmed Converter as mentioned here https://github.com/MDAnalysis/mdanalysis/issues/2475#issuecomment-725066639 should work here.

This should work:

import MDAnalysis as mda
top = pmd.load_file('topology.prmtop')
mda.Universe(top, 'trajectory.netcdf')
richardjgowers commented 1 year ago

If I can get an example file I can probably fix this

abbielear commented 2 weeks ago

I've been using chamber style parm7s with the parmed workaround mentioned above for a while and previously I've had no issues. However, when I tried to create an average structure as part of the RMSF tutorial I hit a new error which I think is to do with the topology format: TypeError: Encountered unexpected topology attribute of type <class 'MDAnalysis.core.topologyobjects.TopologyGroup'>. I've attached example .parm7 and .nc files and a code snippet to reproduce the error. This is using MDAnalysis v. 2.7.0 with Python 3.11. I'm also happy to create a new issue if that's easier. I've calculated RMSF successfully using pytraj, I was just trying to find an alternative but I thought it might be a useful example. chamber_example.zip