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 (np.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 (np.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 (np.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 np.ndarray) – length of Bravais unit vector a

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

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

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

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

  • gamma (scalar or np.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 (scalar or np.ndarray) – length of Bravais unit vector a

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

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

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

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

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

Returns:

  • a (np.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 (np.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 (np.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)#
Parameters:
  • a_length (scalar or np.ndarray) – length of Bravais unit vector a

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

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

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

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

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

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