Python API¶
Shared conventions (units, frames, indices) are on the
home page. Import name is molsymm (PyPI package
libmolsymm). Failures raise RuntimeError. Numeric results are
C-contiguous float64 ndarrays.
import molsymm
import numpy as np
a = molsymm.analyze(numbers, positions) # -> Analysis
print(a.point_group, a.order)
rms, xyz = a.symmetrize() # input-frame coordinates
out = molsymm.symmetrize(numbers, positions, "C2v", forces=forces)
Analysis-frame helpers (frame_xyz, operations) use the Cotton /
principal-axis frame. Analysis.symmetrize, displacements, reconstruct,
assemble, and module-level symmetrize return the original input frame.
Fragmentation indices are 0-based.
Functions¶
analyze
¶
analyze(numbers: Sequence[int], positions: ArrayLike, primary: float = 0.001) -> Analysis
Detect the point group of a Cartesian geometry.
This is the main entry point. The returned Analysis object carries the
group label and methods such as symmetrize, displacements, and
fragmentation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
numbers
|
sequence of int
|
Atomic numbers, length |
required |
positions
|
array_like
|
Cartesian coordinates, shape |
required |
primary
|
float
|
Geometry tolerance in Å (default |
0.001
|
Returns:
| Type | Description |
|---|---|
Analysis
|
Point-group analysis for this molecule. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
Examples:
>>> a = molsymm.analyze([8, 1, 1], positions)
>>> a.point_group
'C2v'
symmetrize
¶
symmetrize(numbers: Sequence[int], positions: ArrayLike, point_group: str, forces: ArrayLike | None = None, hessian: ArrayLike | None = None, primary: float = 0.001) -> Symmetrized
Project geometry (and optional forces / Hessian) onto a named point group.
One-shot alternative to analyze(...).symmetrize() when you already know
the target group and may also want forces / Hessian projected. Returns a
Symmetrized object; coordinates are in the input frame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
numbers
|
sequence of int
|
Atomic numbers, length |
required |
positions
|
array_like
|
Cartesian coordinates, shape |
required |
point_group
|
str
|
Target point-group label (e.g. |
required |
forces
|
array_like
|
Forces shaped |
None
|
hessian
|
array_like
|
Hessian shaped |
None
|
primary
|
float
|
Geometry tolerance in Å (default |
0.001
|
Returns:
| Type | Description |
|---|---|
Symmetrized
|
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If shapes are incompatible or |
Examples:
>>> out = molsymm.symmetrize(numbers, positions, "C2v", forces=forces)
>>> out.positions.shape
(n, 3)
analyze_zmatrix
¶
analyze_zmatrix(entries: Sequence[ZMatrixRow], primary: float = 0.001) -> Analysis
Build Cartesian coordinates from a Z-matrix and detect the point group.
Same return type and methods as analyze.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entries
|
sequence of ZMatrixRow
|
Rows of length 1, 3, 5, or 7 (see |
required |
primary
|
float
|
Geometry tolerance in Å (default |
0.001
|
Returns:
| Type | Description |
|---|---|
Analysis
|
Point-group analysis of the built geometry. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If a row is malformed or analysis fails. |
Examples:
>>> entries = [(8,), (1, 1, 0.957), (1, 1, 0.957, 2, angle)]
>>> molsymm.analyze_zmatrix(entries).point_group
'C2v'
zmatrix_to_xyz
¶
zmatrix_to_xyz(entries: Sequence[ZMatrixRow]) -> Float64Array
Convert a Z-matrix to Cartesian coordinates without symmetry analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entries
|
sequence of ZMatrixRow
|
Same row forms as |
required |
Returns:
| Type | Description |
|---|---|
ndarray of float64, shape (n, 3)
|
Cartesian positions in ångströms. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If a row is malformed. |
wyckoff_positions
¶
wyckoff_positions(point_group: str) -> list[WyckoffSite]
List special positions of a finite Schönflies group.
wyckoff_plans
¶
wyckoff_plans(point_group: str, composition: Sequence[int] | int) -> list[WyckoffPlan]
Partition a composition (or n_sites) into orbit plans.
wyckoff_plan
¶
wyckoff_plan(point_group: str, site_labels: Sequence[str], atomic_numbers: Sequence[int] = ()) -> WyckoffPlan
Build one plan from explicit site labels.
assemble_from_au
¶
assemble_from_au(point_group: str, numbers: Sequence[int], positions: ArrayLike, site_labels: Sequence[str]) -> Analysis
Expand asymmetric-unit coordinates for the given sites into an Analysis.
Types¶
ZMatrixRow
module-attribute
¶
ZMatrixRow: TypeAlias = tuple[int] | tuple[int, int, float] | tuple[int, int, float, int, float] | tuple[int, int, float, int, float, int, float]
One Z-matrix row (1-based bond/angle/dihedral indices; Å / radians).
Notes
Accepted lengths are 1, 3, 5, or 7:
(Z,)— first atom(Z, bond_to, R)— second atom(Z, bond_to, R, angle_to, angle)— third atom(Z, bond_to, R, angle_to, angle, dihedral_to, dihedral)— later atoms
Classes¶
Analysis
¶
Point-group analysis result for one molecule.
Created by analyze or analyze_zmatrix. Stores the detected (or
selected) point group and the molecule in the analysis frame (COM at the
origin, principal axes). Use the methods below to project the geometry,
build symmetry-reduced finite differences, or recover an asymmetric unit.
Attributes:
| Name | Type | Description |
|---|---|---|
point_group |
str
|
Detected or selected point-group label (e.g. |
order |
int
|
Group order; |
symmetry_number |
int
|
Rotational symmetry number for thermochemistry. |
rmsd |
float
|
RMS change from the last |
subgroups |
list of str
|
Labels accepted by |
Examples:
>>> a = molsymm.analyze(numbers, positions)
>>> a.point_group, a.order
('C2v', 4)
>>> rms, xyz = a.symmetrize()
symmetry_number
instance-attribute
¶
symmetry_number: int
Rotational symmetry number for thermochemistry.
subgroups
instance-attribute
¶
subgroups: list[str]
Named subgroups for select_subgroup / subgroup_assembly.
frame_xyz
property
¶
frame_xyz: Float64Array
Analysis-frame coordinates, shape (n, 3) (COM at origin).
operations
property
¶
operations: list[Float64Array]
Symmetry operation matrices in the analysis frame, each (3, 3).
irrep_names
property
¶
irrep_names: list[str]
Irreducible-representation labels for the current group.
select_subgroup
¶
select_subgroup(name: str) -> None
Replace the current group with a named subgroup (in place).
After this call, point_group, order, operations, and related
fields describe name. Subsequent symmetrize / displacements /
fragmentation use the subgroup.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
A label from |
required |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
symmetrize
¶
symmetrize() -> tuple[float, Float64Array]
Project the geometry onto the totally symmetric subspace.
Updates rmsd. The returned coordinates are in the input frame
(the frame passed to analyze), not frame_xyz.
Returns:
| Name | Type | Description |
|---|---|---|
rms |
float
|
RMS Cartesian change in the analysis frame (also stored in |
xyz |
ndarray of float64, shape (n, 3)
|
Symmetrized positions in the input frame. |
Examples:
>>> a = molsymm.analyze(numbers, positions)
>>> rms, xyz = a.symmetrize()
displacements
¶
displacements(step: float = 0.001) -> DisplacementSet
Build symmetry-reduced ± Cartesian displacements.
Returns unique displacements in the input frame for finite-difference gradients and Hessians.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step
|
float
|
Cartesian step in Å (default |
0.001
|
Returns:
| Type | Description |
|---|---|
DisplacementSet
|
|
fragmentation
¶
fragmentation() -> Fragmentation
Partition the molecule into an asymmetric unit (finite groups).
Returns:
| Type | Description |
|---|---|
Fragmentation
|
Representative atom indices and |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the current group is infinite. |
subgroup_assembly
¶
subgroup_assembly(name: str) -> SubgroupAssembly
Describe how to rebuild the molecule under a lower-symmetry subgroup.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
A label from |
required |
Returns:
| Type | Description |
|---|---|
SubgroupAssembly
|
Atom-index pieces and |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
Symmetrized
¶
Result of the module-level symmetrize function.
Holds the projected geometry in the input frame and optional projected forces / Hessian when those were passed in.
Attributes:
| Name | Type | Description |
|---|---|---|
rmsd |
float
|
RMS change of the geometry projection in the analysis frame. |
DisplacementSet
¶
Symmetry-reduced ± Cartesian displacements from Analysis.displacements.
Evaluate energies or gradients at plus / minus, then call
gradient_from_energies or hessian_from_gradients.
Attributes:
| Name | Type | Description |
|---|---|---|
step |
float
|
Cartesian step size in Å. |
plus
property
¶
plus: list[Float64Array]
+step geometries in the input frame, each shape (n_atoms, 3).
minus
property
¶
minus: list[Float64Array]
-step geometries in the input frame, each shape (n_atoms, 3).
gradient_from_energies
¶
gradient_from_energies(ep: ArrayLike, em: ArrayLike) -> Float64Array
Central-difference gradient from ± energies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ep
|
array_like
|
Energies at |
required |
em
|
array_like
|
Energies at |
required |
Returns:
| Type | Description |
|---|---|
ndarray of float64, shape (3 * n_atoms,)
|
Gradient in the input frame. |
hessian_from_gradients
¶
hessian_from_gradients(gp: Sequence[ArrayLike], gm: Sequence[ArrayLike]) -> Float64Array
Assemble a Hessian from ± gradients.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gp
|
sequence of array_like
|
Gradients at |
required |
gm
|
sequence of array_like
|
Gradients at |
required |
Returns:
| Type | Description |
|---|---|
ndarray of float64, shape (3 * n_atoms, 3 * n_atoms)
|
Hessian in the input frame. |
Fragmentation
¶
Asymmetric unit of a finite point group from Analysis.fragmentation.
representatives are the independent atoms. Pass their coordinates to
reconstruct to generate the full molecule by symmetry.
Attributes:
| Name | Type | Description |
|---|---|---|
representatives |
list of int
|
One 0-based atom index per orbit (lowest index). |
representatives
instance-attribute
¶
representatives: list[int]
One 0-based atom index per orbit (lowest index).
free_axes
property
¶
free_axes: list[list[list[float]]]
Input-frame free axes per representative; empty site lists are falsy.
reconstruct
¶
reconstruct(positions: ArrayLike) -> Float64Array
Rebuild the full geometry from representative coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
array_like
|
Representative coordinates, shape |
required |
Returns:
| Type | Description |
|---|---|
ndarray of float64, shape (n_atoms, 3)
|
Full geometry in the input frame. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the shape does not match |
SubgroupAssembly
¶
Piece lists for assembling under a subgroup from subgroup_assembly.
Attributes:
| Name | Type | Description |
|---|---|---|
subgroup |
str
|
Subgroup label used to build this assembly. |
free_axes
property
¶
free_axes: list[list[list[float]]]
Input-frame free axes in piece order; empty site lists are falsy.
assemble
¶
assemble(pieces: Sequence[ArrayLike]) -> Float64Array
Assemble the full geometry from one coordinate array per piece.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pieces
|
sequence of array_like
|
One array per entry in |
required |
Returns:
| Type | Description |
|---|---|
ndarray of float64, shape (n_atoms, 3)
|
Full geometry in the input frame. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the number or shapes of |
WyckoffSite
¶
One special position of a finite point group (Cotton frame).
WyckoffOrbit
¶
One orbit assignment inside a WyckoffPlan.
WyckoffPlan
¶
Orbit assignment for a composition under a point group.
assemble
¶
assemble(positions: ArrayLike) -> Analysis
Expand one Cotton-frame position per orbit into an Analysis.
Examples¶
Symmetrize geometry, forces, and Hessian¶
forces = np.array(
[
[0.0, 0.0, 0.1],
[0.05, 0.02, -0.05],
[0.0, -0.02, -0.05],
],
dtype=np.float64,
)
hessian = np.eye(9, dtype=np.float64)
out = molsymm.symmetrize(
numbers, positions, "C2v", forces=forces, hessian=hessian, primary=1e-2
)
pos = out.positions
fout = out.forces
hout = out.hessian
Symmetry-reduced finite differences¶
d = a.displacements(step=1e-3)
plus: list[Float64Array] = d.plus
minus: list[Float64Array] = d.minus
assert d.n == len(plus) == len(minus)
g = d.gradient_from_energies([0.0] * d.n, [0.0] * d.n)
h = d.hessian_from_gradients(
[np.zeros(9, dtype=np.float64) for _ in range(d.n)],
[np.zeros(9, dtype=np.float64) for _ in range(d.n)],
)
Asymmetric unit¶
frag = a.fragmentation()
reps: list[int] = frag.representatives
full = frag.reconstruct(positions[reps])
Subgroup assembly¶
asmbl = a.subgroup_assembly("C2v")
pieces: list[Float64Array] = [positions[atoms] for atoms in asmbl.pieces]
rebuilt = asmbl.assemble(pieces)
Constructive Wyckoff geometry¶
sites = molsymm.wyckoff_positions("Oh")
plans = molsymm.wyckoff_plans("Oh", [16, 9, 9, 9, 9, 9, 9])
a = molsymm.assemble_from_au(
"Oh",
[16, 9],
np.array([[0.0, 0.0, 0.0], [0.0, 0.0, 1.56]]),
site_labels=["1a", "6a"],
)
frag = a.fragmentation()