5.7. GRO file format — MDAnalysis.coordinates.GRO
¶
Classes to read and write Gromacs GRO coordinate files; see the notes on the GRO format which includes a conversion routine for the box.
5.7.1. GROWriter format strings¶
The GROWriter class has a .fmt attribute, which is a dictionary of different strings for writing lines in .gro files. These are as follows:
- n_atoms
- For the first line of the gro file, supply the number of atoms in the system. Eg: fmt[‘n_atoms’].format(42)
- xyz
An atom line without velocities. Requires that the ‘resid’, ‘resname’, ‘name’, ‘index’ and ‘pos’ keys be supplied. Eg: fmt[‘xyz’].format(resid=1, resname=’SOL’, name=’OW2’, index=2,
pos=(0.0, 1.0, 2.0))- xyz_v
- As above, but with velocities. Needs an additional keyword ‘vel’.
- box_orthorhombic
- The final line of the gro file which gives box dimensions. Requires the box keyword to be given, which should be the three cartesian dimensions. Eg: fmt[‘box_orthorhombic’].format(box=(10.0, 10.0, 10.0))
- box_triclinic
- As above, but for a non orthorhombic box. Requires the box keyword, but this time as a length 9 vector. This is a flattened version of the (3,3) triclinic vector representation of the unit cell. The rearrangement into the odd gromacs order is done automatically.
-
class
MDAnalysis.coordinates.GRO.
GROReader
(filename, convert_units=None, **kwargs)[source]¶ Reader for the Gromacs GRO structure format.
Changed in version 0.11.0: Frames now 0-based instead of 1-based
-
class
MDAnalysis.coordinates.GRO.
GROWriter
(filename, convert_units=None, **kwargs)[source]¶ GRO Writer that conforms to the Trajectory API.
Note
The precision is hard coded to three decimal places and velocities are not written (yet).
Changed in version 0.11.0: Frames now 0-based instead of 1-based
Changed in version 0.13.0: Now strictly writes positions with 3dp precision and velocities with 4dp Removed the convert_dimensions_to_unitcell method, use Timestep.triclinic_dimensions instead Now now writes velocities where possible
Set up a GROWriter with a precision of 3 decimal places.
Parameters: *filename* – output filename -
fmt
= {'box_orthorhombic': '{box[0]:10.5f}{box[1]:10.5f}{box[2]:10.5f}\n', 'box_triclinic': '{box[0]:10.5f}{box[4]:10.5f}{box[8]:10.5f}{box[1]:10.5f}{box[2]:10.5f}{box[3]:10.5f}{box[5]:10.5f}{box[6]:10.5f}{box[7]:10.5f}\n', 'n_atoms': '{0:5d}\n', 'xyz': '{resid:>5d}{resname:<5.5s}{name:>5.5s}{index:>5d}{pos[0]:8.3f}{pos[1]:8.3f}{pos[2]:8.3f}\n', 'xyz_v': '{resid:>5d}{resname:<5.5s}{name:>5.5s}{index:>5d}{pos[0]:8.3f}{pos[1]:8.3f}{pos[2]:8.3f}{vel[0]:8.4f}{vel[1]:8.4f}{vel[2]:8.4f}\n'}¶ format strings for the GRO file (all include newline); precision of 3 decimal places is hard-coded here.
-
write
(selection, frame=None)[source]¶ Write selection at current trajectory frame to file.
Parameters: selection – MDAnalysis AtomGroup (selection or Universe.atoms) or also Universe
Keywords: - frame
optionally move to frame number frame
The GRO format only allows 5 digits for resid and atom number. If these number become larger than 99,999 then this routine will chop off the leading digits.
Changed in version 0.7.6: resName and atomName are truncated to a maximum of 5 characters
-