mooonpy.molspace.box module

@author: Josh Kemppainen Revision 1.0 June 15, 2025 Michigan Technological University 1400 Townsend Dr. Houghton, MI 49931

@author: Tristan Muzzy Revision 1.1 July 5, 2025

class mooonpy.molspace.box.Box(**kwargs)[source]

Bases: object

Class representing a restricted triclimic simulation box as described in LAMMPS docs. mooonpy uses this geometry internally, and will write tilt factors if any are nonzero https://docs.lammps.org/Howto_triclinic.html

..todo::
  • read in from general triclinic to restricted

frac2pos(frac_x, frac_y, frac_z, h, boxlo) Tuple[float, float, float][source]

Convert fractional (0-1) to cartesian coords for one atom

>>> x = h*frac + x0

where frac is the fractional coordinate, x is the cartesian coordinate vector, and x0 is the origin of the simulation cell in that direction and h is the sparse h matrix, generated by get_box_parameters(m).

Parameters:
  • frac_x (float) – X fractional coordinate

  • frac_y (float) – Y fractional coordinate

  • frac_z (float) – Z fractional coordinate

  • h (List[float]|Tuple[float,float,float,float,float,float]) – Matrix of h as 6 components

  • boxlo (List[float]|Tuple[float,float,float]) – Low box vector

Todo

  • Change docs to use LaTeX

get_lengths() Tuple[float, float, float][source]

Compute box lengths from box edges.

Returns:

lengths of box edges

Return type:

Tuple[float, float, float]

get_transformation_matrix() Tuple[list[float], list[float], list[float], list[float]][source]

Generate transformation matrix to convert to and from fractional or Cartesian coordinates using LAMMPS “sparse matrix” setup.

>>> matrix = [[lx, xy, xz],
>>>           [0 , ly, yz],
>>>           [0 ,  0, lz]]
>>> matrix_index = [[0  , 5, 4],
>>>                 [na , 1, 3],
>>>                 [na ,na, 2]]
>>> h = [lx, ly, lz, yz, xz, xy]
>>> h_inv = matrix^-1 # indexing the same locations
>>> boxlo = [xlo, ylo, zlo]
>>> boxhi = [xhi, yhi, zhi]
Returns:

Tuple corresponding to transformation matrix, inverse matrix, low and high box vectors

Return type:

Tuple[List[float],List[float],List[float],List[float]]

pos2frac(x, y, z, h_inv, boxlo) Tuple[float, float, float][source]

Convert cartesian to fractional coords (0-1) for one atom

>>> frac = h_inv*(x - x0)

where frac is the fractional coordinate, x is the cartesian coordinate, and x0 is the origin of the simulation cell in that direction and h_inv is the sparse inverse matrix of h, generated by get_box_parameters(m).

Parameters:
  • x (float) – X Cartesian coordinate

  • y (float) – Y Cartesian coordinate

  • z (float) – Z Cartesian coordinate

  • h_inv (List[float]|Tuple[float,float,float,float,float,float]) – Inverse matrix of h as 6 components

  • boxlo (List[float]|Tuple[float,float,float]) – Low box vector