NetCDF file reader
For loading particle trajectories stored in binary NetCDF files that follow the
AMBER NetCDF trajectory convention. Files of this kind are written by the
dump netcdf command of LAMMPS, by the NetCDFTrajectory class of the
Atomic Simulation Environment (ASE), by the
Atomistica code, by the AMBER molecular dynamics package and its cpptraj tool,
and by the SimPARTIX particle simulation code. OVITO itself can write files in this format, too.
NetCDF is a self-describing container format: a file consists of named dimensions, variables (multi-dimensional data arrays), and attributes. The AMBER convention prescribes a fixed set of dimension and variable names for trajectory data (see the table below), which OVITO recognizes, while all further per-atom variables found in a file get imported as user-defined particle properties. This makes the format an efficient alternative to text-based formats such as XYZ or LAMMPS dump.
OVITO reads files stored in the classic NetCDF-3 formats (CDF-1, 64-bit offset CDF-2, and CDF-5) as well as in the HDF5-based NetCDF-4 format.
Compressed files (“.gz” suffix) cannot be read directly and must be decompressed first. The file reader identifies a NetCDF file as an AMBER
trajectory by its global attribute Conventions, whose value must be AMBER (the ConventionVersion attribute is not checked).
The trajectory data may reside either in the root group of the file or in a subgroup named AMBER.
Imported data
- Frames
The number of trajectory frames is given by the length of the
framedimension, which must be present in every file. Each entry along this dimension is loaded as one animation frame. Variables with a leadingframedimension hold time-dependent data, while variables without it (e.g. a statictypearray) are shared by all frames.- Particles
The
atomdimension defines the maximum number of particles per frame. Every file must contain a floating-point variable namedcoordinatesorunwrapped_coordinateswith dimensions(frame, atom, spatial)or(atom, spatial), from which the Position particle property is read. If the number of atoms varies from frame to frame, unused trailing entries of thecoordinatesarray should be set to the NetCDF fill value; such entries are discarded by the file reader, and only the actual atoms are imported.All other numeric variables whose first dimension is
atom(orframefollowed byatom) are read as per-particle properties. A variable may have up to two extra trailing dimensions:(atom, N)yields a vector property with N components (e.g.(atom, spatial)for 3-vectors), and(atom, N, M)yields a vector property with N*×*M components, which stores the matrix elements in row-major order. The following NetCDF variable names are automatically mapped to OVITO’s standard particle properties (case-insensitive):NetCDF variable
OVITO particle property
coordinates,unwrapped_coordinatesPositionvelocitiesVelocityforces,forceForceid,identifierParticle Identifiertype,atom_types,element,speciesParticle TypemassMassradiusRadiuscolorColorselectionSelectionc_epotPotential Energyc_kpotKinetic Energyc_cna,patternStructure TypeA variable whose name exactly matches the name of any other standard particle property (e.g.
ChargeorStress Tensor) is mapped to that property as well. The automatic mapping to a standard property requires the number of vector components stored in the file to match the number of components of the OVITO property; otherwise, and for all variables with unrecognized names, a user-defined particle property with the name of the NetCDF variable is created. Dots, slashes, and colons in variable names are replaced with underscores. The data type of a user-defined property is inherited from the NetCDF variable:byte,short/int,int64,float, anddoublevariables are stored as 8-bit, 32-bit, and 64-bit integer, and 32-bit and 64-bit floating-point properties, respectively. Variables of any other NetCDF data type (charstrings, unsigned integer types) are ignored.The particle types read from the
typevariable (or one of its aliases) are numeric IDs. The file reader creates one particle type per distinct numeric ID occurring in the file; the types remain unnamed. If the file contains a Velocity property, the reader also computes the Velocity Magnitude property automatically.- Simulation cell
The simulation cell is constructed from the per-frame variables
cell_lengthsandcell_angles(dimensions(frame, cell_spatial)and(frame, cell_angular)), which specify the three cell edge lengths and the angles \(\alpha\), \(\beta\), \(\gamma\) in degrees. The cell vector \(\mathbf{a}\) is aligned with the Cartesian x-axis and \(\mathbf{b}\) lies in the x-y plane. Two extensions to the AMBER convention are supported: the optional variablecell_origin(written by LAMMPS, ASE, and OVITO) specifies the position of the cell corner, which is placed at the coordinate origin otherwise, and the optional variableshear_dx(written by Atomistica) specifies an additional shear displacement of the \(\mathbf{c}\) vector in the x-y plane.Following the AMBER convention, a cell edge length of zero indicates a non-periodic direction. Directions with non-zero length are treated as periodic. In non-periodic directions, the cell extent is replaced by the extent of the axis-aligned bounding box of the particle coordinates. If the file contains no cell information at all (or all cell lengths are zero), no simulation cell is created unless the option Generate bounding box if needed is enabled.
- Global attributes
Every numeric variable that has the
framedimension as its only dimension (e.g.time) is imported as a global attribute named after the variable, holding the variable’s value for the current frame. This includes, for instance, the thermodynamic quantities written by the LAMMPSdump_modify thermooption. Entries equal to the variable’s NetCDF fill value are skipped, and variables namedSourceFileorSourceFrameare ignored, because these attribute names are reserved by OVITO. The optional global attributetitleof the NetCDF file is made available as the global attributeNetCDF_Title. The global attributesprogram,programVersion, andapplicationare ignored.
Limitations
The reader ignores the
unitsandscale_factorattributes of variables. All values are imported as stored in the file, without unit conversion. Note that LAMMPS, for instance, stores the timestep number in thetimevariable and the timestep size in itsscale_factorattribute; OVITO imports the unscaled timestep number astimeattribute.String-valued per-atom variables (data type
char) are not supported. In particular, chemical element names cannot be read from such variables; particle types must be given as integer IDs.The atomic numbers stored by ASE in a variable named
Zare imported as a user-defined propertyZrather than as particle types. You can map this variable to the Particle Type property via the Edit column mapping dialog if desired.The NetCDF format does not store bonds or other topology information.
Bond generation during import (the Generate bonds option of other readers) is not available for this file reader. Bonds can be generated after import using the Create bonds modifier.
Options
- Generate bounding box if needed
If this option is enabled and the file contains no cell dimensions (all cell edge lengths are zero or the
cell_lengthsvariable is absent), OVITO will generate an axis-aligned bounding box enclosing all particles. This bounding box has open boundary conditions and serves as an approximate simulation cell.- Sort particles by ID
If enabled, OVITO reorders the loaded particles according to the values of the
Particle Identifierproperty, i.e. theidoridentifiervariable of the file. Otherwise the storage order of the file is preserved.- File columns
By default, the mapping of NetCDF variables to OVITO particle properties is performed automatically according to the rules described above (Automatic mapping). Select User-defined mapping to particle properties and click Edit column mapping to override the mapping. The dialog lists all per-atom variables found in the file, and for each one you can choose the OVITO particle property it should be mapped to, or exclude it from the import. Mapping a 3×3 matrix variable with 9 components (e.g. a per-atom virial or stress tensor) to one of OVITO’s symmetric tensor properties with 6 components, such as
Stress Tensor, performs an automatic conversion to Voigt notation by averaging the off-diagonal elements. The same mapping can be specified in Python using thecolumnsparameter (see below).
Python parameters
The file reader accepts the following optional keyword parameters in a call to the import_file() or load() Python functions.
- import_file(location, columns=None, bounding_box=False, sort_particles=False)
- Parameters:
columns (list[str|None]) – An optional list of particle property names, which overrides the automatic mapping of the per-atom NetCDF variables to OVITO particle properties. The list must contain one entry per per-atom variable of the file, in the order in which the variables appear in the file (i.e. the order shown in the Edit column mapping dialog). Use
Noneto skip a variable. A 3×3 matrix variable can be mapped to a symmetric tensor property with six components (e.g.'Stress Tensor'), which converts the values to Voigt notation.bounding_box (bool) – Generate an ad-hoc
SimulationCellas an axis-aligned bounding box around the imported particles when the file contains no cell dimensions.sort_particles (bool) – Makes the file reader reorder the loaded particles before passing them to the pipeline. Sorting is based on the values of the
Particle Identifierproperty loaded from the file.
Added in version 3.17.0: The columns parameter.