nanover.ase.trajectory_logger module

Module containing a trajectory logging class that can be used to output portable trajectory files from an ASE molecular dynamics simulation.

class nanover.ase.trajectory_logger.TrajectoryLogger(atoms: Atoms, filename: str, format: str | None = None, timestamp=True, parallel=True, **kwargs)

Bases: object

Trajectory logging class for use with ASE simulations.

Can be attached to an ASE simulation, resulting in frames being written automatically:

>>> from ase.calculators.emt import EMT
>>> from ase.lattice.cubic import FaceCenteredCubic
>>> atoms = FaceCenteredCubic(directions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]], symbol="Cu", size=(2, 2, 2), pbc=True)
>>> atoms.calc = EMT()
>>> dynamics = Langevin(atoms, timestep=0.5, temperature_K=300, friction=1.0)
>>> with TrajectoryLogger(atoms, 'example.xyz') as logger:
...     dynamics.attach(TrajectoryLogger(atoms, 'example.xyz'), interval=10) # attach an XYZ logger.
Parameters:
  • atoms – ASE Atoms from which to write data.

  • filename – Path to filename to write to.

  • format – Format to use, as supported by ASE. If not specified, derived from filename.

  • timestamp – Whether to append a timestamp to the file name. Use to avoid overwriting the same file if dynamics is reset.

  • parallel – Default is to write on master process only. Set to False to write from all processes.

  • kwargs – Keyword arguments to be passed to the underlying ase.io.write() method.

Note that even if an ASE format supports appending, if that file requires additional data between frames (e.g. headers), then the resulting output may not be valid.

If ASE supports writing directly a file descriptor for the given format, then that will be used for performance, otherwise, the file will be reopened and appended to each frame, which will negatively impact performance.

atoms: Atoms
base_path: str
close()

Closes the current file being written to, if it exists.

format: str
frame_index: int
parallel: bool
reset()

Resets the logger, restarting logging with a new file.

If the logger is set to use timestamps, a new file will be generated with the current time. Otherwise, the file will be overwritten.

..note

This method is used in NanoVer to produce new trajectory files whenever the simulation is reset by the user.

property timestamping: bool

Indicates whether this logger is appending timestamps to the names of any files it produces.

Returns:

True, if appending timestamps, False otherwise.

write()

Writes the current state of the atoms to file.

exception nanover.ase.trajectory_logger.UnsupportedFormatError

Bases: Exception

nanover.ase.trajectory_logger.validate_ase_can_append_filename(filename: str)
Raises:

UnsupportedFormatError – if ase is unable to append the format implied by the file extension

nanover.ase.trajectory_logger.validate_ase_can_append_format(format: str)
Raises:

UnsupportedFormatError – if ase is unable to append the desired format.