moleculekit.unitcell module#

moleculekit.unitcell.box_vectors_to_lengths_and_angles(a, b, c)#

Convert box vectors into the lengths and angles defining the box.

Parameters:
  • a (ndarray) – the vector defining the first edge of the periodic box (length 3), or an array of this vector in multiple frames, where a[i,:] gives the length 3 array of vector a in each frame of a simulation

  • b (ndarray) – the vector defining the second edge of the periodic box (length 3), or an array of this vector in multiple frames, where b[i,:] gives the length 3 array of vector a in each frame of a simulation

  • c (ndarray) – the vector defining the third edge of the periodic box (length 3), or an array of this vector in multiple frames, where c[i,:] gives the length 3 array of vector a in each frame of a simulation

Examples

>>> a = np.array([2,0,0], dtype=float)
>>> b = np.array([0,1,0], dtype=float)
>>> c = np.array([0,1,1], dtype=float)
>>> l1, l2, l3, alpha, beta, gamma = box_vectors_to_lengths_and_angles(a, b, c)
>>> (l1 == 2.0) and (l2 == 1.0) and (l3 == np.sqrt(2))
True
>>> np.abs(alpha - 45) < 1e-6
True
>>> np.abs(beta - 90.0) < 1e-6
True
>>> np.abs(gamma - 90.0) < 1e-6
True
Returns:

  • a_length (scalar or numpy.ndarray) – length of Bravais unit vector a

  • b_length (scalar or numpy.ndarray) – length of Bravais unit vector b

  • c_length (scalar or numpy.ndarray) – length of Bravais unit vector c

  • alpha (scalar or numpy.ndarray) – angle between vectors b and c, in degrees.

  • beta (scalar or numpy.ndarray) – angle between vectors c and a, in degrees.

  • gamma (scalar or numpy.ndarray) – angle between vectors a and b, in degrees.

moleculekit.unitcell.lengths_and_angles_to_box_vectors(a_length, b_length, c_length, alpha, beta, gamma, reduced=False)#

Convert from the lengths/angles of the unit cell to the box vectors (Bravais vectors). The angles should be in degrees.

Parameters:
  • a_length (float | ndarray) – length of Bravais unit vector a

  • b_length (float | ndarray) – length of Bravais unit vector b

  • c_length (float | ndarray) – length of Bravais unit vector c

  • alpha (float | ndarray) – angle between vectors b and c, in degrees.

  • beta (float | ndarray) – angle between vectors c and a, in degrees.

  • gamma (float | ndarray) – angle between vectors a and b, in degrees.

  • reduced (bool) – if True, return the box vectors in the reduced form required by OpenMM.

Returns:

  • a (numpy.ndarray) – If the inputs are scalar, the vectors will one dimesninoal (length 3). If the inputs are one dimension, shape=(n_frames, ), then the output will be (n_frames, 3)

  • b (numpy.ndarray) – If the inputs are scalar, the vectors will one dimesninoal (length 3). If the inputs are one dimension, shape=(n_frames, ), then the output will be (n_frames, 3)

  • c (numpy.ndarray) – If the inputs are scalar, the vectors will one dimesninoal (length 3). If the inputs are one dimension, shape=(n_frames, ), then the output will be (n_frames, 3)

Examples

>>> import numpy as np
>>> result = lengths_and_angles_to_box_vectors(1, 1, 1, 90.0, 90.0, 90.0)

Notes

This code is adapted from gyroid, which is licensed under the BSD http://pythonhosted.org/gyroid/_modules/gyroid/unitcell.html

moleculekit.unitcell.lengths_and_angles_to_tilt_factors(a_length, b_length, c_length, alpha, beta, gamma)#

Convert Bravais unit cell lengths and angles to tilt factors.

Computes the box extents (lx, ly, lz) and the tilt factors (xy, xz, yz) used by triclinic simulation boxes from the unit cell edge lengths and angles.

Parameters:
  • a_length (float | ndarray) – length of Bravais unit vector a

  • b_length (float | ndarray) – length of Bravais unit vector b

  • c_length (float | ndarray) – length of Bravais unit vector c

  • alpha (float | ndarray) – angle between vectors b and c, in degrees.

  • beta (float | ndarray) – angle between vectors c and a, in degrees.

  • gamma (float | ndarray) – angle between vectors a and b, in degrees.

Return type:

ndarray

Returns:

  • lx (scalar) – Extent in x direction

  • ly (scalar) – Extent in y direction

  • lz (scalar) – Extent in z direction

  • xy (scalar) – Unit vector b tilt with respect to a

  • xz (scalar) – Unit vector of c tilt with respect to a

  • yz (scalar) – Unit vector of c tilt with respect to b

Examples

>>> import numpy as np
>>> result = lengths_and_angles_to_tilt_factors(1, 1, 1, 90.0, 90.0, 90.0)