tcc_python_scripts.file_readers package

Submodules

tcc_python_scripts.file_readers.atom module

Module for reading and writing snapshots from and to LAMMPS (.atom) file formats.

class tcc_python_scripts.file_readers.atom.AtomSnapshot(particle_coordinates=array([], shape=(0, 0), dtype=float64), box=None, species=None, time=0)[source]

Bases: tcc_python_scripts.file_readers.snapshot.Snapshot

Snapshot of a system of particles in LAMMPS (.atom) file format.

Interface defined in parent class Snapshot. Further documentation can be found there.

tcc_python_scripts.file_readers.atom.read(file_name)[source]

Returns a generator that reads one or more snapshots from a .atom file.

Parameters:file_name – Name of .atom file to read.
Returns:A generator object that generates Snapshots.

tcc_python_scripts.file_readers.dynamo module

Module for reading and writing snapshots from and to DynamO (.xml) file formats.

class tcc_python_scripts.file_readers.dynamo.DynamoSnapshot(particle_coordinates=array([], shape=(0, 0), dtype=float64), box=None, species=None, time=0)[source]

Bases: tcc_python_scripts.file_readers.snapshot.Snapshot

Snapshot of a system of particles in DynamO (.xml) file format.

Interface defined in parent class Snapshot. Further documentation can be found there.

exception tcc_python_scripts.file_readers.dynamo.NonadditiveError[source]

Bases: RuntimeError

Error rasied if the given interaction range is a cross-species interaction, so potentially the dynamo file describes a nonadditive potential.

tcc_python_scripts.file_readers.dynamo.read(file_name)[source]

Read a snaphshot from the dynamo file. At the moment only a single frame can be read.

Parameters:file_name – Name of Dynamo file to read.
Returns:A generator object that generates Snapshots.

tcc_python_scripts.file_readers.snapshot module

Module defining interface for reading and writing snapshots in various file formats. A snapshot is an object which holds data about a configuration of particles at a single point in time. A series of snapshots can be used to describe a trajectory in time.

exception tcc_python_scripts.file_readers.snapshot.NoSnapshotError[source]

Bases: RuntimeError

Exception raised when not able to read a snapshot from a file.

class tcc_python_scripts.file_readers.snapshot.Snapshot(particle_coordinates=array([], shape=(0, 0), dtype=float64), box=None, species=None, time=0)[source]

Bases: object

Snapshot of a system of particles. A snapshot is a single configuration of particles at a point in time.

particle_coordinates

particle coordinates (num_particles by dimensionality container)

box

box containing the particles (d by 2 container)

species

labels of the particle species (string or container of strings)

time

time or frame of the snapshot within a trajectory (integer or float)

copy()[source]
Returns:A deep copy of the snapshot.
dimensionality

Dimensionality of configuration space.

Type:Returns
num_particles

Number of particles in snapshot.

Type:Returns
classmethod read_single(path_or_file)[source]

Read a single snapshot from the disk. Example: >>> Snapshot.read_single(‘snapshot.atom’) <snapshot n=10976 t=0> :param cls: derived class defining specific file format :param path_or_file: file stream or path to read snapshot from

Returns:

the snapshot read from disk

Return type:

snapshot

Raises:
  • NoSnapshotError – if could not read from file
  • RuntimeException – if did not recognise file format
classmethod read_trajectory(path_or_file)[source]

A generator that reads snapshots from a file.

Parameters:

path_or_file – file stream or path to read trajectory from

Raises:
  • NoSnapshotError – if file could not be read.
  • RuntimeException – file format is not recognised
write(output_file)[source]

Dump the snapshot to a file.

Parameters:output_file – file or path to write the snapshot to
exception tcc_python_scripts.file_readers.snapshot.SnapshotIncompleteError[source]

Bases: RuntimeError

Exception raised when a snapshot is partially read but not all particles are found or the coordinates cannot be read.

tcc_python_scripts.file_readers.snapshot.stream_safe_open(path_or_file, mode='r')[source]

Context manager for parsers which accept an open file stream or a file path to open.

Parameters:
  • path_or_file – either an open file stream (in which case the context manager does nothing and returns it) or a path (in which case the context manager will open this, return a stream and then clean up)
  • mode – mode to open file in, ‘r’ for read, ‘w’ for write

tcc_python_scripts.file_readers.xyz module

Module for reading and writing snapshots from and to XYZ (.xyz) file formats.

class tcc_python_scripts.file_readers.xyz.XYZSnapshot(particle_coordinates=array([], shape=(0, 0), dtype=float64), box=None, species=None, time=0)[source]

Bases: tcc_python_scripts.file_readers.snapshot.Snapshot

Snapshot of a system of particles in XYZ (.xyz) file format.

Interface defined in parent class Snapshot. Further documentation can be found there.

tcc_python_scripts.file_readers.xyz.read(file_name)[source]

Returns a generator that reads one or more snapshots from an xyz file.

Parameters:file_name – Name of XYZ file to read.
Returns:A generator object that generates Snapshots.
tcc_python_scripts.file_readers.xyz.write(output_filename, particle_coordinates, species=None)[source]

Write a single configuration to the disk.

Parameters:
  • output_filename – The filename to write the coordinates to.
  • particle_coordinates – A list of particle coordinates
  • species – A list of particle species. Defaults all particles to ‘A’ if not provided.
tcc_python_scripts.file_readers.xyz.write_snapshot(output_filename, snapshot_list)[source]

Write one or more snapshots to the disk.

Parameters:
  • output_filename – The filename to write the coordinates to.
  • snapshot_list – A list of XYZSnapshots.