SimTk/openmm — pull request #461 by swails (2014-05-21 19:26:12+00:00)
Title: Rewrite Amber inpcrd file parsers

This is a rewrite of the Amber inpcrd file parsers. The following improvements are made:

* Existence of box and velocities is autodetected, so `loadBoxVectors` and `loadVelocities` are now unnecessary (and deprecated). [1]
* Amber NetCDF restart files are now supported if scipy is installed, and the file format is auto-detected.
* (Valid) Amber ASCII restarts that do not have spaces between all of their entries are now supported (the format specifies 12-character-width fields, and are on occasion not space-delimited -- this is not uncommon)
* Tests are added for most of the possible inpcrd file formats and layouts (they all pass for me currently)

[1] There is a _tiny_ corner case where velocities and box coordinates may not be autodetected correctly. In systems with only 2 atoms (almost never happens in Amber) where the inpcrd file has either box coordinates (rare in 2-atom systems, which themselves are super rare) or velocities. Then there's no way of "knowing" a priori what the last line is -- velocities or box? However, velocities are typically on the order of -5 to 5 (they are angstroms/picosecond/20.455 in the inpcrd file), and will never reach values of 60+ in even quasi-plausible scenarios. So if any numbers in the last line are this large, it is assigned as box parameters.

At the end of the day, I think that in the 0.000001% of cases where users have an ambiguous 2-atom restart file, this code handles 99% of _those_ cases correctly.

I ported this parser from what I use in ParmEd, and it has been stable for a long time so far.

Notably solved in this PR is the instance where a programmer may specify

```Python
from simtk.openmm import app
inpcrd = app.AmberInpcrdFile('inpcrd', loadBoxVectors=True)
```

if velocities are present in inpcrd (but not requested), the first 6 velocities will be interpreted as the box vectors. This is far more frequent (it happened to me when I first started with OpenMM) than the corner case I described above.