pyscivr.utils module

Utilities for molecular geometries.

Notation:
  • N: number of atoms.

pyscivr.utils.get_geom(xyzstr)[source]

Get the chemical symbols, positions and masses from an XYZ string.

Only the lines of the form symbol x y z whose first token is a chemical symbol in atomic_weights are read. Other lines (e.g. the atom count and the comment line of the XYZ format) are skipped.

Parameters:

xyzstr (str) – Contents of an XYZ file.

Returns:

(symbols, posi, mass), where

  • symbols: (N,) chemical symbols.

  • posi: (N, 3) positions, in the same units as xyzstr.

  • mass: (N,) atomic masses [amu].

Return type:

tuple[list[str], NDArray[np.float64], NDArray[np.float64]]

pyscivr.utils.get_mass_center(posi, mass)[source]

Get the center of mass.

Parameters:
  • posi (ArrayLike) – (N, 3) positions.

  • mass (ArrayLike) – (N,) atomic masses.

Returns:

(3,) center of mass.

Return type:

NDArray[np.float64]

pyscivr.utils.get_inertia(posi, mass)[source]

Get the inertia tensor about the origin.

\[I = \sum_a m_a ((r_a^T r_a) I_3 - r_a r_a^T)\]
Parameters:
  • posi (ArrayLike) – (N, 3) positions.

  • mass (ArrayLike) – (N,) atomic masses.

Returns:

(3, 3) inertia tensor.

Return type:

NDArray[np.float64]

Note

The tensor is computed about the origin. To obtain the inertia tensor about the center of mass, subtract get_mass_center() from posi in advance.