Molecule

PyAR uses pyar.Molecule.Molecule as its lightweight geometry container. It stores the atomic symbols, Cartesian coordinates (Angstrom), and a small set of workflow metadata (charge, multiplicity, fragments, energy).

Object Contract

The number of atom symbols must match the number of coordinate rows. Fragment definitions, when provided, must refer to valid atom indices. Invalid geometries fail at construction time with a clear ValueError.

Two molecules can be combined explicitly with pyar.Molecule.Molecule.merged_with(). The + operator remains an equivalent shorthand for existing PyAR workflows.

XYZ IO

  • pyar.Molecule.Molecule.from_xyz() reads an .xyz file into a pyar.Molecule.Molecule.

  • pyar.Molecule.Molecule.mol_to_xyz() writes the current structure out.

Internally, PyAR provides an exception-based parser pyar.Molecule.parse_xyz() and preserves the historical fatal-exit behavior via pyar.Molecule.read_xyz().

Geometry Transforms

PyAR provides both in-place and non-mutating transform styles.

In-place (mutates the object)

  • pyar.Molecule.Molecule.translate()

  • pyar.Molecule.Molecule.rotate_3d()

  • pyar.Molecule.Molecule.align()

rotate_3d rotates around the molecule centroid. align centers the molecule at its center of mass before aligning it with its principal axes. Reading pyar.Molecule.Molecule.moments_of_inertia_tensor does not modify coordinates.

Non-mutating (returns a new object)

  • pyar.Molecule.Molecule.translated()

  • pyar.Molecule.Molecule.rotated_3d()

  • pyar.Molecule.Molecule.aligned()

ASE Interop (Optional)

If ASE is installed, you can convert between PyAR and ASE objects:

  • pyar.Molecule.Molecule.to_ase_atoms()

  • pyar.Molecule.Molecule.from_ase_atoms()