# hoomd.write¶

Overview

 Table A delimiter separated value file backend for a Logger. CustomWriter Writer wrapper for hoomd.custom.Action objects. GSD Write simulation trajectories in the GSD format.

Details

class hoomd.write.Table(trigger, logger, output=stdout, header_sep='.', delimiter=' ', pretty=True, max_precision=10, max_header_len=None)

A delimiter separated value file backend for a Logger.

This can serve as a way to output scalar simulation data to standard out. However, this is useable to store simulation scalar data to a file as well.

Note

This only works with scalar and string quantities. If using string quantities, keep in mind that the default space delimiter will make strings with spaces in them will cause read errors if attempting to read the outputed data with a space delimited file reader.

Note

All attributes for this class are static. They cannot be set to new values once created.

Parameters
• trigger (hoomd.trigger.Trigger) – The trigger to determine when to run the Table back end.

• logger (hoomd.logging.Logger) – The logger to query for output. The ‘scalar’ flag must be set on the logger, and the ‘string’ flag is optional.

• output (file-like object , optional) – A file-like object to output the data from, defaults to standard out. The object must have write and flush methods and a mode attribute.

• header_sep (str, optional) – String to use to separate names in the logger’s namespace, defaults to ‘.’. For example, if logging the total energy of an hoomd.md.pair.LJ pair force object, the default header would be md.pair.LJ.energy (assuming that max_header_len is not set).

• delimiter (str, optional) – String used to separate elements in the space delimitated file, defaults to ‘ ‘.

• pretty (bool, optional) – Flags whether to attempt to make output prettier and easier to read, defaults to True. To make the ouput easier to read, the output will compromise on outputted precision for improved readability. In many cases, though the precision will still be high with pretty set to True.

• max_precision (int, optional) – If pretty is not set, then this controls the maximum precision to use when outputing numerical values, defaults to 10.

• max_header_len (int, optional) – If not None (the default), limit the outputted header names to length max_header_len. When not None, names are grabbed from the most specific to the least. For example, if set to 7 the namespace ‘hoomd.md.pair.LJ.energy’ would be set to ‘energy’. Note that at least the most specific part of the namespace will be used regardless of this setting (e.g. if set to 5 in the previous example, ‘energy’ would still be the header).

trigger

The trigger to determine when to run the Table back end.

Type

hoomd.trigger.Trigger

logger

The logger to query for output. The ‘scalar’ flag must be set on the logger, and the ‘string’ flag is optional.

Type

hoomd.logging.Logger

output

A file-like object to output the data from. The object must have write and flush methods and a mode attribute.

Type

file-like object

header_sep

String to use to separate names in the logger’s namespace.’. For example, if logging the total energy of an hoomd.md.pair.LJ pair force object, the default header would be md.pair.LJ.energy (assuming that max_header_len is not set).

Type

str

delimiter

String used to separate elements in the space delimitated file.

Type

str

pretty

Flags whether to attempt to make output prettier and easier to read. To make the ouput easier to read, the output will compromise on outputted precision for improved readability. In many cases, though the precision will still be high with pretty set to True.

Type

bool

max_precision

If pretty is not set, then this controls the maximum precision to use when outputing numerical values, defaults to 10.

Type

int, optional

max_header_len

Limits the outputted header names to length max_header_len when not None. Names are grabbed from the most specific to the least. For example, if set to 7 the namespace ‘hoomd.md.pair.LJ.energy’ would be set to ‘energy’. Note that at least the most specific part of the namespace will be used regardless of this setting (e.g. if set to 5 in the previous example, ‘energy’ would still be the header).

Type

int

min_column_width

The minimum allowed column width.

Type

int

write()

Write out data to self.output.

Writes a row from given hoomd.logging.Logger object data.

class hoomd.write.CustomWriter(action, trigger=1)

Writer wrapper for hoomd.custom.Action objects.

For usage see hoomd.custom.CustomOperation.

class hoomd.write.GSD(filename, trigger, filter=hoomd._hoomd.ParticleFilter, overwrite=False, truncate=False, dynamic=None, log=None)

Write simulation trajectories in the GSD format.

Parameters
• filename (str) – File name to write.

• trigger (hoomd.trigger.Trigger) – Select the timesteps to write.

• filter (hoomd.filter.ParticleFilter) – Select the particles to write, defaults to hoomd.filter.All.

• overwrite (bool) – When True, overwite the file. When False append frames to filename if it exists and create the file if it does not, defaults to False.

• truncate (bool) – When True, truncate the file and write a new frame 0 each time this operation triggers, defaults to False.

• dynamic (list[str]) – Quantity categories to save in every frame, defaults to property.

• log (hoomd.logging.Logger) – A Logger object for GSD logging, defaults to None.

Note

All parameters are also available as instance attributes. Only trigger and log may be modified after construction.

GSD writes a simulation snapshot to the specified file each time it triggers. GSD can store all particle, bond, angle, dihedral, improper, pair, and constraint data fields in every frame of the trajectory. GSD can write trajectories where the number of particles, number of particle types, particle types, diameter, mass, charge, or other quantities change over time. GSD can also store operation-specific state information necessary for restarting simulations and user-defined log quantities.

To reduce file size, GSD does not write properties that are set to defaults. When masses, orientations, angular momenta, etc… are left default for all particles, these fields will not take up any space in the file. Additionally, GSD only writes dynamic quantities to all frames. It writes non-dynamic quantities only the first frame. When reading a GSD file, the data in frame 0 is read when a quantity is missing in frame i, supplying data that is static over the entire trajectory. Set the dynamic parameter to specify dynamic attributes by category. property is always dynamic:

• property

• particles/position

• particles/orientation (only written when values are not the default: [1,0,0,0])

• momentum

• particles/velocity

• particles/angmom (only written when values are not the default: [0,0,0,0])

• particles/image (only written when values are not the default: [0,0,0])

• attribute

• particles/N

• particles/types

• particles/typeid

• particles/mass

• particles/charge

• particles/diameter

• particles/body

• particles/moment_inertia

• topology

• bonds/

• angles/

• dihedrals/

• impropers/

• constraints/

• pairs/

See the GSD documentation and GitHub project for more information on GSD files.

Note

When you use filter_ to select a subset of the whole system, GSD will write out all of the selected particles in ascending tag order and will not write out topology.

Note

All logged data chunks must be present in the first frame in the gsd file to provide the default value. Some (or all) chunks may be omitted on later frames.

Note

In MPI parallel simulations, the callback will be called on all ranks. GSD will write the data returned by the root rank. Return values from all other ranks are ignored (and may be None).

Examples:

static write(state, filename, filter=hoomd._hoomd.ParticleFilter, log=None)

Write the given simulation state out to a GSD file.

Parameters
• state (State) – Simulation state.

• filename (str) – File name to write.

• filter (hoomd.ParticleFilter) – Select the particles to write.

• log (hoomd.logger.Logger) –

Note

The file is always overwritten.