File Format Readers and Writers
The gmso.formats module provides readers and writers for common molecular simulation
file formats. All public functions are importable from gmso.formats.
GROMACS
GROMACS coordinate files (.gro) and topology/parameter files (.top, .itp) are supported for both reading and writing.
Read a Gromos87 (GRO) file and return a |
|
Write a |
|
Write a |
read_gro
- gmso.formats.read_gro(filename)[source]
Read a Gromos87 (GRO) file and return a
Topology.The GRO format is a plain-text structure file used by the GROMACS simulation engine. It encodes simulation-box parameters, atom count, residue/atom names, positions, and (optionally) velocities.
- Parameters:
filename (
Union[str,Path]) – Path to the.grofile to read.- Returns:
Topology containing the sites and box parsed from filename.
- Return type:
Notes
GRO files do not specify bonds; the returned topology will have no connections.
Velocities are detected but not parsed.
Only single-frame GRO files are supported.
Residue/resid information is mapped to
site.moleculeandsite.residuebut the original resid integers are rebased to 0-indexed integers.
write_gro
- gmso.formats.write_gro(top, filename, n_decimals=3, shift_coord=False)[source]
Write a
Topologyto a Gromos87 (GRO) file.- Parameters:
- Return type:
Notes
Velocities are not written.
Residue/resid indices cycle back at 99 999 to comply with the fixed-width GRO column format.
write_top
- gmso.formats.write_top(top, filename, top_vars=None, settles_tag=None)[source]
Write a
Topologyto a GROMACS topology (.top) file.- Parameters:
top (
Topology) – Fully typed topology to write.top_vars (
Optional[dict]) – Override the default GROMACS[ defaults ]section values. Keys are GROMACS parameter names (e.g.'nbfunc','comb-rule','gen-pairs','fudgeLJ','fudgeQQ'). Any key not supplied falls back to the value inferred from the topology.settles_tag (
Optional[str]) – When provided, write a[ settles ]section for rigid 3-site water models using the given tag string.
- Returns:
Writes the GROMACS topology file to filename in place.
- Return type:
Notes
This writer is a work in progress and does not yet support the full GROMACS topology spec. See the GROMACS manual at https://manual.gromacs.org/current/reference-manual/topologies/topology-file-formats.html for the complete format description.
GSD
GSD (General Simulation Data) is the native trajectory format for HOOMD-blue.
Output a GSD file (HOOMD default data format). |
write_gsd
- gmso.formats.write_gsd(top, filename, base_units=None, shift_coords=True, write_special_pairs=True)[source]
Output a GSD file (HOOMD default data format).
The GSD binary file format is the native format of HOOMD-blue. It can be used as a starting point for a HOOMD-blue simulation, for trajectory analysis, and for visualisation in various tools.
To write a HOOMD snapshot, see
gmso.external.convert_hoomd.to_hoomd_snapshot()andgmso.external.convert_hoomd.to_gsd_snapshot()- Parameters:
top (
Topology) – Typed topology to write.base_units (
Optional[dict]) – Dictionary of base units to use when writing the GSD snapshot. IfNone, HOOMD-blue default units are used.shift_coords (
bool) – Shift coordinates from(0, L)to(-L/2, L/2)if necessary.write_special_pairs (
bool) – Write special pair information needed to correctly apply the OPLS fudged 1-4 interactions in HOOMD-blue.
- Returns:
Writes the GSD snapshot to filename in place.
- Return type:
Notes
Force field parameters are not stored in the GSD file. You can use GMSO to create the HOOMD force objects. See
gmso.external.convert_hoomd.to_hoomd_forcefield()
XYZ
The plain-text XYZ format stores atomic symbols and Cartesian coordinates.
Read an XYZ file and return a |
|
Write a |
read_xyz
- gmso.formats.read_xyz(filename)[source]
Read an XYZ file and return a
Topology.- Parameters:
filename (
Union[str,Path]) – Path to the.xyzfile to read.- Returns:
Topology containing the sites parsed from filename. No bonds or box information are set; call
update_topology()afterwards if needed.- Return type:
- Raises:
ValueError – If the number of coordinate lines does not match the atom count in the first line of the file.
write_xyz
LAMMPS DATA
LAMMPS data files encode particle positions, topology, and forcefield coefficients.
Write a LAMMPS data file from a |
|
Read a LAMMPS data file and return a |
write_lammpsdata
- gmso.formats.write_lammpsdata(top, filename, atom_style='full', unit_style='real', strict_potentials=False, strict_units=False, lj_cfactorsDict=None)[source]
Write a LAMMPS data file from a
Topology.- Parameters:
top (
Topology) – Typed topology to write.atom_style (
str) – LAMMPS atom style. Supported values:'full','atomic','charge','molecular'.unit_style (
str) – LAMMPS unit system. Supported values:'real','lj','metal','si','cgs','electron','micro','nano'.strict_potentials (
bool) – WhenTrue, raise an error if any potential style is not directly supported instead of attempting an automatic conversion.strict_units (
bool) – WhenTrue, raise an error if parameter units do not match the target unit style instead of converting automatically.lj_cfactorsDict (
Optional[dict]) – Used only whenunit_style='lj'. A dict with any subset of keys'mass','energy','length','charge'that override the default non-dimensionalisation factors (which are derived from the largest values found in the topology).
- Returns:
Writes the LAMMPS data file to filename in place.
- Return type:
Notes
See https://docs.lammps.org/read_data.html for a full description of the LAMMPS data format. Only a subset of atom styles, potential styles, and unit styles are currently supported.
read_lammpsdata
- gmso.formats.read_lammpsdata(filename, atom_style='full', unit_style='real')[source]
Read a LAMMPS data file and return a
Topology.- Parameters:
- Returns:
Typed topology parsed from filename.
- Return type:
Notes
This reader is a work in progress. Currently supported styles:
Atom styles:
'full'Pair potential styles:
'lj'Bond styles:
'harmonic','fene'Angle styles:
'harmonic'Dihedral styles:
'opls'Improper styles:
'harmonic'
MOL2
Tripos MOL2 is a common format for small-molecule structures.
Read a TRIPOS MOL2 file and return a |
|
Write a |
read_mol2
- gmso.formats.read_mol2(filename, site_type='atom', verbose=False)[source]
Read a TRIPOS MOL2 file and return a
Topology.Parses sites, bonds, and box information from a MOL2 file. Forcefield parameters present in the file are not converted.
- Parameters:
- Returns:
Topology containing the sites, bonds, and box from filename.
- Return type:
Notes
Atom positions in MOL2 files are assumed to be in Angstroms.
write_mol2
MCF
Monte Carlo forcefield (MCF) files are used by Cassandra Monte Carlo.
Write a Cassandra Monte Carlo MCF file from a |
write_mcf
- gmso.formats.write_mcf(top, filename)[source]
Write a Cassandra Monte Carlo MCF file from a
Topology.The MCF file encodes the topology of a single molecular species for the Cassandra Monte Carlo engine. The supplied topology should contain a single fully parameterised molecule. One MCF file is required for each unique species in the simulation.
- Parameters:
- Returns:
Writes the MCF file(s) to filename in place.
- Return type:
Notes
Atom indexing in the MCF format begins at 1. See the Cassandra documentation at https://cassandra.nd.edu/index.php/documentation for a complete format description.
JSON
GMSO topologies can be serialized to and from JSON for storage and interoperability.
Write a |
|
Load a |
write_json
- gmso.formats.write_json(top, filename, types=True, update=False, **kwargs)[source]
Write a
Topologyto a JSON file.- Parameters:
top (
Topology) – Topology to serialise.filename (
Union[str,Path]) – Destination file path; must end with.json.types (
bool) – WhenTrue, include potential type information (atom types, bond types, etc.) in the output.update (
bool) – WhenTrue, callupdate_topology()before serialisation.**kwargs – Additional keyword arguments forwarded to
json.dump().
- Returns:
Writes the JSON file to filename in place.
- Return type:
load_json
Format Registry
The format registry provides the decorator-based mechanism for registering new file format readers and writers.
- gmso.formats.formats_registry.LoadersRegistry
alias of <gmso.formats.formats_registry.Registry object>
- gmso.formats.formats_registry.SaversRegistry
alias of <gmso.formats.formats_registry.Registry object>