smc_lammps.reader package

Submodules

smc_lammps.reader.lammps_data module

class smc_lammps.reader.lammps_data.Box(lows: ndarray[tuple[Any, ...], dtype[float32]], highs: ndarray[tuple[Any, ...], dtype[float32]])

Bases: object

A box in some region of space.

__init__(lows: ndarray[tuple[Any, ...], dtype[float32]], highs: ndarray[tuple[Any, ...], dtype[float32]]) None
highs: ndarray[tuple[Any, ...], dtype[float32]]

Upper bounds of the box (x, y, z)

is_in_box(xyz: ndarray[tuple[Any, ...], dtype[float32]]) ndarray[tuple[Any, ...], dtype[bool]]

Checks if the point(s) is/are in the box.

Points on the surface are included.

Parameters:

xyz – Array of 3D point or points (N, 3)

Returns:

True if in the box, False otherwise.

lows: ndarray[tuple[Any, ...], dtype[float32]]

Lower bounds of the box (x, y, z)

smc_lammps.reader.lammps_data.ID_TYPE

LAMMPS id.

smc_lammps.reader.lammps_data.IdArray

An array of LAMMPS ids.

alias of ndarray[tuple[Any, …], dtype[int64]]

class smc_lammps.reader.lammps_data.LammpsData(ids: ndarray[tuple[Any, ...], dtype[int64]], types: ndarray[tuple[Any, ...], dtype[int64]], positions: ndarray[tuple[Any, ...], dtype[float32]])

Bases: object

Stores data from a LAMMPS trajectory file (*.lammpstrj).

__init__(ids: ndarray[tuple[Any, ...], dtype[int64]], types: ndarray[tuple[Any, ...], dtype[int64]], positions: ndarray[tuple[Any, ...], dtype[float32]]) None
combine_by_ids(other: LammpsData) None

Appends the values of other in-place.

Parameters:

other – Second LammpsData instance.

create_box(types: ndarray[tuple[Any, ...], dtype[int64]]) Box

Creates the smallest box containing all atoms of the given types.

Parameters:

types – Types to place in box.

Returns:

Box containing atoms of types.

delete_outside_box(box: Box) LammpsData

Creates a new LammpsData instance with points outside of box removed.

Parameters:

box – Points inside of this box are kept.

Returns:

New LammpsData instance with only the points inside of box.

delete_side_of_plane(plane: Plane, side: Side) None

Filters the arrays by removing points on one side of a plane.

Parameters:
  • plane – Plane used to filter points.

  • side – The side of the plane that will be removed.

classmethod empty()

Creates an empty LammpsData instance.

filter(keep: Callable[[int64, int64, float32], bool] | Callable[[ndarray[tuple[Any, ...], dtype[int64]], ndarray[tuple[Any, ...], dtype[int64]], ndarray[tuple[Any, ...], dtype[float32]]], ndarray[tuple[Any, ...], dtype[bool]]]) None

Filters the arrays, edits in-place.

Parameters:

keep – Filter definition, a function from (id, type, pos) -> bool.

filter_by_types(types: ndarray[tuple[Any, ...], dtype[int64]]) None

Filters the arrays by the type value, edits in-place.

Parameters:

types – Types to keep.

get_position_from_index(index: int) ndarray[tuple[Any, ...], dtype[float32]]

Returns the position(s) at the given index / indices.

Parameters:

index – A LAMMPS atom id.

ids: ndarray[tuple[Any, ...], dtype[int64]]

Array of atom ids.

positions: ndarray[tuple[Any, ...], dtype[float32]]

Array of atom positions, same length as ids.

types: ndarray[tuple[Any, ...], dtype[int64]]

Array of atom types, same length as ids.

class smc_lammps.reader.lammps_data.Plane(point: ndarray[tuple[Any, ...], dtype[float32]], normal: ndarray[tuple[Any, ...], dtype[float32]])

Bases: object

class Side(*values)

Bases: Enum

INSIDE = 1
OUTSIDE = -1
classmethod get_opposite(side: Side) Side
__init__(point: ndarray[tuple[Any, ...], dtype[float32]], normal: ndarray[tuple[Any, ...], dtype[float32]])

point: a point on the plain, normal: normal vector of the plain (always normalized)

distance(point) float
is_on_side(side: Side, points: ndarray[tuple[Any, ...], dtype[float32]]) ndarray[tuple[Any, ...], dtype[bool]]

Checks which side of the plane the given points are on.

Parameters:
  • side – Side to check.

  • points – Array of 3D points.

Returns:

Array of bools, True for every point on side, False for other points.

smc_lammps.reader.lammps_data.TYPE_TYPE

LAMMPS atom type.

smc_lammps.reader.lammps_data.TypeArray

An array of LAMMPS atom types.

alias of ndarray[tuple[Any, …], dtype[int64]]

smc_lammps.reader.lammps_data.get_normal_direction(p1: ndarray[tuple[Any, ...], dtype[float32]], p2: ndarray[tuple[Any, ...], dtype[float32]], p3: ndarray[tuple[Any, ...], dtype[float32]]) ndarray[tuple[Any, ...], dtype[float32]]

Returns the direction normal to the plane constructed by the three given points.

Parameters:
  • p1 – Point 1.

  • p2 – Point 2.

  • p3 – Point 3.

Returns:

A normalized (1, 3) vector representing the normal direction.

smc_lammps.reader.parser module

class smc_lammps.reader.parser.Parser(file: Path, time_it: bool = False, mode: OpenTextMode = 'r')

Bases: object

LAMMPS trajectory file parser.

file

Open LAMMPS trajectory file handle.

time_it

If True, record the time spent parsing in timings.

mode

Custom file mode (e.g. “r+” if you want to edit the file after reaching a certain timestep).

ATOM_FORMAT = 'ITEM: ATOMS id type x y z'

Format of header for atoms section of trajectory file.

exception EndOfLammpsFile

Bases: Exception

Raised when the end of the file has been reached.

__init__(file: Path, time_it: bool = False, mode: OpenTextMode = 'r') None
static get_array(lines: list[str]) ndarray[tuple[Any, ...], dtype[_ScalarT]]

Returns the id, type, x, y, z data for a single timestep.

Parameters:

lines – Lines in the atom section of the LAMMPS trajectory file.

next_step() tuple[int, LammpsData]

Iterates through the file and retrieves the next timestep.

Returns:

Tuple of (timestep, data).

next_step_raw() dict[str, list[str]]

Iterates through the file and retrieves all data for the next timestep.

Returns:

Dictionary which maps the header ('ITEM: .*') to a list of lines under the header.

Raises:

ValueError – Reached the end of the file while parsing.

skip_to_atoms() dict[str, list[str]]

Iterate through the file

Returns:

Dictionary which maps the header ('ITEM: .*') to a list of lines under the header.

Raises:
  • ValueError – Invalid format found, must match Parser.ATOM_FORMAT.

  • self.EndOfLammpsFile – Successfully reached the end of the file.

  • ValueError – Reached the end of the file while parsing.

static split_data(array) LammpsData

Converts array to LammpsData.

Parameters:

array – Array of id, type, x, y, z data.

Returns:

A LammpsData instance for a single timestep.

smc_lammps.reader.util module

smc_lammps.reader.util.get_timer_accumulator(cache)
Usage:
>>> from smc_lammps.reader.util import get_timer_accumulator
>>> # create a global cache
>>> cache = {}
>>> timer_accumulator = get_timer_accumulator(cache)
>>>
>>> @timer_accumulator
... def my_func():
...     # do stuff here
...     pass
...
>>> # call your function
>>> for _ in range(1000):
...    my_func()
>>>
>>> # each element shows the time spent per function
>>> print(len(cache))
1
smc_lammps.reader.util.timer(func)

Decorator that prints the time spent calling a function.