2

I am trying to load a .crd file from Amber, but this fails because it's not in the format MDAnalysis expect (see error at the end):

topology = 'top.prmtop'
trajectory = 'amberOut.crd'
u = MDAnalysis.Universe(topology, trajectory)

I saw this thread and also this library which I don't want to use if I can read Amber .crd file using MDAnalysis.

Any ideas why it doesn't work? If I load the trajectory in VMD I am using this command (and it works):

vmd -parm7 top.prmtop -crdbox amberOut.crd

Traceback (most recent call last):
  File "analysis.py", line 5, in <module>
    u = MDAnalysis.Universe(topology, trajectory)
  File "/anaconda3/envs/mdaenv/lib/python2.7/site-packages/MDAnalysis/core/universe.py", line 305, in __init__
    self.load_new(coordinatefile, **kwargs)
  File "/anaconda3/envs/mdaenv/lib/python2.7/site-packages/MDAnalysis/core/universe.py", line 535, in load_new
    self.trajectory = reader(filename, **kwargs)
  File "/anaconda3/envs/mdaenv/lib/python2.7/site-packages/MDAnalysis/coordinates/base.py", line 1943, in __init__
    self._read_first_frame()
  File "/anaconda3/envs/mdaenv/lib/python2.7/site-packages/MDAnalysis/coordinates/CRD.py", line 73, in _read_first_frame
    natoms = int(fields[0])
ValueError: invalid literal for int() with base 10: '96.380'
0x90
  • 39,472
  • 36
  • 165
  • 245
  • 2
    Is your "amberOut.crd" a AMBER text format trajectory or a Amber restart file? I am asking because MDAnalysis recognizes files with .crd by default as CHARMM crd structure files. If it is a restart file, try passing the explicit `format` argument to the Universe: `Universe(..., format="INPCRD")`. See also https://github.com/MDAnalysis/mdanalysis/issues/262 – orbeckst Feb 08 '18 at 07:29
  • 1
    By the way, most MDAnalysis developers read the mailing list https://groups.google.com/forum/#!forum/mdnalysis-discussion and the issue tracker https://github.com/MDAnalysis/mdanalysis/issues so you often get an answer there faster. – orbeckst Feb 08 '18 at 07:32
  • @orbeckst I really don't know what is a restart file or output file of Amber. Do you have an example? Or what are the parameters I should use in each case? Pytraj and VMD are able to load it, so I believe it's parameter issues. – 0x90 Feb 08 '18 at 12:02
  • 1
    Did you use the suggestion of orbeckst to pass the format parameter? MDAnalysis detects filetype based on the file extension (the characters after the last dot). Unfortunately, AMBER and CHARMM share some of these extensions and write different files. Therefore you might need to nudge MDAnalysis to use the right parser. – Max Linke Feb 08 '18 at 15:58
  • @MaxLinke I tried that already and didn't work `u = MDAnalysis.Universe(topology, trajectory, format="INPCRD") ` – 0x90 Feb 08 '18 at 20:41
  • Would you mind filing an issue in the MDAnalysis issue tracker https://github.com/MDAnalysis/mdanalysis/issues ? I don't think that S/O is ideal for solving this problem because the next step is going to be that we will ask you to post a file or show part of the CRD file so that we can get a better idea of what is happening here. – orbeckst Feb 09 '18 at 23:20
  • @orbeckst I would do it, but I can't publish the crd and promtop. It's part of classified project (national lab). – 0x90 Feb 09 '18 at 23:21
  • Ok, we can still try to figure out what format of data you have. I just find the S/O comments too limiting to carry out this conversation. I would prefer a discussion on the MDAnalysis issue tracker. You can say that you cannot share the data – that happens often. Once we find a solution we will also post the answer on S/O to close the loop. – orbeckst Feb 11 '18 at 16:20
  • One thing you should try, though, is use `format="TRJ"` in your command: `u = MDAnalysis.Universe("top.prmtop", "amberOut.crd", format="TRJ")`. You used VMD with "crdbox" and this extension *is* recognized by MDAnalysis as a *Amber ASCII trajectory" https://www.mdanalysis.org/docs/documentation_pages/coordinates/TRJ.html#ascii-trajectories. See if this happens to work for you. – orbeckst Feb 11 '18 at 16:22
  • 1
    @orbeckst, `u = MDAnalysis.Universe(topology, trajectory, format="TRJ")` worked I think (at least it could load the data). Few questions: is it still true I should prefer to use Python 2.7? Do you still want me to open an issue? Any suggestion to validate the command I ran worked? – 0x90 Feb 12 '18 at 21:34
  • MDAnalysis fully supports Python 3.4+ and 2.7 – choose whichever version you prefer. If you could load the data then there's a good chance that it worked. Given that the format is ASCII, I would manually compare a few coordinates. If you find discrepancies, raise an issue, please. Now that you confirmed that this works with `format="TRAJ"` I will post it as answer below so that people don't have to go through the comments. – orbeckst Feb 13 '18 at 22:28

1 Answers1

2

Use the format="TRJ" keyword argument for the Universe in your command:

u = MDAnalysis.Universe("top.prmtop", "amberOut.crd", format="TRJ")

You said you used VMD with "crdbox" and the "crdbox" extension is recognized by MDAnalysis as an Amber ASCII trajectory. However, the "crd" extension that you used for your file is already used for CHARMM coordinate files ("CRD" files) and so you need to explicitly specify the trajectory format for the Universe.

(If you give your trajectories the extension "crdbox" or "trj" such as "amberOut.crdbox" or "amberOut.trj" then MDAnalysis will automatically recognize it as an Amber ASCII trajectory. However, you can always override the format detection with the explicit format keyword argument.)

Update: Based on this question, we updated the MDAnalysis docs for the Amber trajectory reader to include a note for how to read Amber "crd" trajectories.

orbeckst
  • 3,189
  • 1
  • 17
  • 14