Skip to content

cell

asext.cell

Classes:

  • AseCell
  • CellTransform

    Tranform the cell and atom properties from old_cell to new_cell orientations.

Functions:

AseCell(array: np.ndarray)

Bases: Cell

Methods:

lower_triangular_form() -> tuple[Cell, np.ndarray]

Rename original function Cell.standard_form(), see https://gitlab.com/ase/ase/-/blob/master/ase/cell.py?ref_type=heads#L333

upper_triangular_form() -> tuple[Cell, np.ndarray]

Rotate axes such that the unit cell is an upper triangular matrix.

CellTransform(old_cell: np.ndarray, new_cell: np.ndarray, pure_rotation: bool = True)

Tranform the cell and atom properties from old_cell to new_cell orientations.

The idea is compute a linear transformation that maps the old cell to the new cell. A = solve(old_cell, new_cell) = old_cell^(-1) new_cell

Generally, this linear transformation A can include rotation R + shear/reshape U (stretching and shearing), i.e., A = R * U.

Therefore, this transformation can be used in two ways: 1. Directly apply A that includes both rotation and shear/stretch. (should avoid using this, since it is not clear how to transform properties like stress/forces) 2. Extract only the rotation part R from A (using polar decomposition), and use it to rotate vectors/tensors, ignoring shear/reshape change. - Extract the closest pure rotation R from A (using polar decomposition) - Use that R to rotate positions, forces, stress, etc.

Parameters:

  • old_cell (ndarray) –

    3x3 matrix represent the old cell.

  • new_cell (ndarray) –

    3x3 matrix represent the new cell.

  • pure_rotation (bool, default: True ) –

    If True, only use the rotation part of the transformation. Defaults to True.

Note
  • np.linalg.solve(A, B) solves AX = B for X. May fail if A is singular (square matrix with a determinant of zero, det(A)=0).
  • Rotation matrix is derived from QR decomposition of the cell, following Prism class

Methods:

Attributes:

old_cell = np.asarray(old_cell, dtype=float) instance-attribute

new_cell = np.asarray(new_cell, dtype=float) instance-attribute

R = _polar_rotation(A) instance-attribute

vectors_forward(vec: np.ndarray) -> np.ndarray

Rotate vectors from the old_cell's orient to the new_cell's orient.

Parameters:

  • vec (ndarray) –

    Nx3 matrix represent the vector properties. (positions, forces, etc. each row is a vector)

Returns:

  • ndarray

    np.ndarray: Rotated vectors.

vectors_backward(vec: np.ndarray) -> np.ndarray

Rotate vectors back from the new_cell to the old_cell. Same as Prism.vector_to_ase

tensor_forward(tensor: np.ndarray) -> np.ndarray

Rotate the tensor from the old_cell's orient to the new_cell's orient. (T' = Rᵀ T R) rotates the tensor into the rotated coordinate system

Parameters:

  • tensor (ndarray) –

    3x3 matrix represent the tensor properties. (e.g., 3x3 stress tensor)

Returns:

  • ndarray

    np.ndarray: Transformed tensor.

tensor_backward(tensor: np.ndarray) -> np.ndarray

Rotate the tensor back from the new_cell to the old_cell. Same as Prism.tensor_to_ase (T = R T' Rᵀ) rotates the tensor back into the original coordinate system

make_upper_triangular_cell(atoms: Atoms, zero_tol: float = 1e-12) -> Atoms

Atoms with a box is an upper triangular matrix is a requirement to run NPT class in ASE. [[ ax, ay, az ] [ 0, by, bz ] [ 0, 0, cz ]]

make_lower_triangular_cell(atoms: Atoms, zero_tol: float = 1e-12) -> Atoms

Converts the cell matrix of atoms into a lower triangular, to be used in LAMMPS: [[ ax, 0, 0 ] [ bx, by, 0 ] [ cx, cy, cz ]]

make_triangular_cell_extxyz(extxyz_file: str, form: str = 'lower') -> None

Make the cell of atoms in extxyz file to be triangular. Args: extxyz_file (str): Path to the extxyz file. form (str): 'upper' or 'lower'. Defaults to 'lower'.

rotate_struct_property(struct: Atoms, new_cell: np.ndarray, wrap: bool = False, custom_vector_props: list[str] | None = None, custom_tensor_props: list[str] | None = None) -> Atoms

Rotate atomic structure and its properties to match a new cell orientation.

Parameters:

  • struct (Atoms) –

    Atoms object.

  • new_cell (ndarray) –

    3x3 matrix represent the new cell.

  • wrap (bool, default: False ) –

    If True, wrap atoms into the new cell.

  • custom_vector_props (list, default: None ) –

    List of vector properties to rotate. This allows to set vector properties with custom names.

  • custom_tensor_props (list, default: None ) –

    List of tensor properties to rotate. This allows to set tensor properties with custom names.

Returns:

  • Atoms

    ase.Atoms: Atoms object with rotated properties.

Note
  • Important note: deepcopy(struct) copies the struct.calc object, but struct.copy() does not.