API Reference¶
This section contains the complete API reference for all modules in mlfsm.
Core Modules¶
FreezingString (mlfsm.cos)¶
The main driver class that orchestrates string growth, interpolation, and node optimization throughout the FSM calculation.
Freezing String Method driver for reaction pathway construction.
- class mlfsm.cos.FreezingString(reactant, product, nnodes_min=10, interp_method='ric', ninterp=100, stepsize=0.0, raise_on_backtransf_fail=True, output=None)[source]¶
Bases:
objectImplements the Freezing String Method (FSM) for transition state guess generation.
The FSM grows two strings from the reactant and product endpoints toward each other. At each iteration a new frontier node is placed by taking a step along an interpolated path, optimized perpendicular to the local tangent direction, and then frozen. The highest-energy node at convergence serves as the TS guess.
- Parameters:
reactant (ase.Atoms) – Reactant geometry with an attached ASE calculator (optional at construction; required before calling
optimize()).product (ase.Atoms) – Product geometry. Must have the same atom ordering as
reactant.nnodes_min (int, optional) – Nominal number of string nodes used to determine the interpolation step size. The actual node count may differ slightly depending on the path arc length. Default is 10.
interp_method ({"ric", "lst", "cart"}) –
Interpolation scheme used to generate new frontier nodes:
"ric"— redundant internal coordinates (recommended)."lst"— linear synchronous transit."cart"— plain Cartesian linear interpolation.
ninterp (int, optional) – Number of points used to discretize the dense interpolated path from which frontier nodes are selected. Default is 100.
stepsize (float, optional) – If > 0, sets the Cartesian step size (Å) explicitly and ignores
nnodes_min. The step size is measured along the Cartesian arc length of the initial linear interpolation. Default is 0.0 (derive step size fromnnodes_min).raise_on_backtransf_fail (bool, optional) – If
True, raise a RuntimeError if the RIC back transformation fails to converge during interpolation or node growth. Default isTrue.output (FSMOutput | None)
- __init__(reactant, product, nnodes_min=10, interp_method='ric', ninterp=100, stepsize=0.0, raise_on_backtransf_fail=True, output=None)[source]¶
- interpolate(outdir)[source]¶
Generate and write the dense interpolated path between current frontier nodes.
Writes a single XYZ file named
interp_<iteration>.xyztooutdir. Each frame comment line contains the cumulative arc-length value.- Parameters:
outdir (path-like) – Directory in which to write the interpolated path XYZ file.
- Return type:
None
- grow()[source]¶
Grow the string by adding one new frontier node to each end.
Interpolates between the current frontier nodes, selects positions one step-size inward from each end, and appends those nodes to
r_stringandp_stringwithfix=False. Setsself.growing = Falsewhen the two frontiers are within one step-size of each other.- Return type:
None
- optimize(optimizer)[source]¶
Relax all unfixed frontier nodes perpendicular to the local tangent.
Evaluates energies for endpoint nodes that have not yet been computed, then runs the optimizer on every unfixed node. After optimization each node is frozen (
fix=True) so it will not move in subsequent iterations.- Parameters:
optimizer (CartesianOptimizer or InternalsOptimizer) – Optimizer instance whose
calcattribute provides energies and gradients via the ASE calculator interface.- Return type:
None
- write(outdir)[source]¶
Write the current string geometries and relative energies to an XYZ file.
Writes
vfile_<iteration>.xyztooutdir. Frame comment lines contain the cumulative arc-length and relative energy (eV). On the final iteration (growing=False) also writes the total gradient count tongrad.txt.- Parameters:
outdir (path-like) – Directory in which to write output files.
- Return type:
None
Interpolation (mlfsm.interp)¶
Provides Linear, LST, and
RIC interpolation schemes for generating reaction path
nodes between endpoint geometries.
Interpolation methods for constructing paths between endpoint geometries.
- class mlfsm.interp.Interpolate(atoms1, atoms2, ninterp, gtol=0.0001, return_q=False, raise_on_backtransf_fail=True)[source]¶
Bases:
objectAbstract base class for interpolation schemes between molecular geometries.
- Parameters:
atoms1 (ase.Atoms) – Starting (reactant-side) geometry.
atoms2 (ase.Atoms) – Ending (product-side) geometry.
ninterp (int) – Number of discrete frames to generate along the interpolated path.
gtol (float, optional) – Gradient tolerance passed to the L-BFGS-B minimizer (used by
LST). Default is 1e-4.return_q (bool, optional) – If
True, return interpolated internal coordinate vectors instead of Cartesian positions. Only meaningful forRIC. Default isFalse.raise_on_backtransf_fail (bool, optional) – If
True, raise a RuntimeError if the RIC back transformation fails to converge during interpolation or node growth. Only meaningful forRIC. Default isTrue.
- class mlfsm.interp.Linear(atoms1, atoms2, ninterp, gtol=0.0001, return_q=False, raise_on_backtransf_fail=True)[source]¶
Bases:
InterpolateLinear interpolation of Cartesian coordinates.
Generates a reaction path by linearly blending the Cartesian positions of two endpoint geometries:
(1-f)*xyz1 + f*xyz2for f in [0, 1]. Fast but may produce unphysical geometries for large conformational changes.- Parameters:
- class mlfsm.interp.LST(atoms1, atoms2, ninterp, gtol=0.0001, return_q=False, raise_on_backtransf_fail=True)[source]¶
Bases:
InterpolateLinear Synchronous Transit (LST) interpolation.
At each interpolation point f, minimizes the deviation from linearly interpolated pairwise interatomic distances while remaining close to the Cartesian linear blend. Produces more chemically realistic geometries than plain Cartesian interpolation at moderate extra cost.
References
Halgren, T. A.; Lipscomb, W. N. Chem. Phys. Lett. 1977, 49, 225-232.
- Parameters:
- obj(x_c, f, rab, xab)[source]¶
Objective function minimized at each interpolation point.
Computes the weighted sum of squared deviations of pairwise distances from their linearly interpolated target values, plus a small Cartesian restraint to prevent rigid-body drift.
- Parameters:
x_c (NDArray) – Flattened trial Cartesian coordinates.
f (float) – Interpolation parameter in [0, 1].
rab (callable) – Returns linearly interpolated pairwise distances at parameter f.
xab (callable) – Returns linearly interpolated Cartesian coordinates at parameter f.
- Returns:
Scalar objective value.
- Return type:
- class mlfsm.interp.RIC(atoms1, atoms2, ninterp, gtol=0.0001, return_q=False, raise_on_backtransf_fail=True)[source]¶
Bases:
InterpolateRedundant internal coordinate (RIC) interpolation.
Linearly interpolates between the reactant and product geometries in the space of delocalized redundant internal coordinates (bonds, angles, torsions, out-of-plane bends). The interpolated frames are then back-transformed to Cartesian coordinates via iterative application of the Wilson B-matrix. This scheme avoids the unphysical bond compressions that can occur with Cartesian interpolation for large conformational changes.
- Parameters:
- interpolate()[source]¶
Return RIC-interpolated path in Cartesian (or internal) coordinates.
Torsion periodicity wrapping is applied automatically when the interpolation crosses the ±π boundary.
- Returns:
If
return_qisFalse(default): array of shape(ninterp, natoms*3)with flattened Cartesian coordinates. Ifreturn_qisTrue: array of shape(ninterp, n_ics)with internal coordinate values.- Return type:
NDArray[np.float32]
Coordinates (mlfsm.coords)¶
Cartesian and redundant internal coordinate systems used during interpolation and back-transformation to Cartesian coordinates.
Coordinate generation and transformation tools for FSM optimization.
- class mlfsm.coords.Coordinates(atoms1, atoms2=None, verbose=False, raise_on_backtransf_fail=True)[source]¶
Bases:
objectBase class for internal coordinate systems used in FSM.
- qprint(atoms)[source]¶
Print coordinate values in human-readable format for a given ASE atoms object.
- Parameters:
atoms (Atoms)
- Return type:
None
- class mlfsm.coords.Cartesian(atoms1, atoms2=None, verbose=False, raise_on_backtransf_fail=True)[source]¶
Bases:
CoordinatesCartesian coordinate system used for atoms.
- class mlfsm.coords.Redundant(atoms1, atoms2=None, verbose=False, raise_on_backtransf_fail=True)[source]¶
Bases:
CoordinatesRedundant internal coordinate system including bond, angle, torsion, etc.
- checkstre(A, B, eps=1e-08)[source]¶
Check if distance between two atoms is significant (non-zero within tolerance).
Optimization (mlfsm.opt)¶
Node-level optimizers that relax FSM images perpendicular to the current tangent direction using L-BFGS-B with explicit line search.
Optimization routines for FSM nodes.
Contains Cartesian and internal coordinate optimizers using projected gradients and scipy-based minimization. Optimizers are used to refine node geometries along a reaction path subject to constraints imposed by the FSM.
- class mlfsm.opt.Optimizer(calc, method='L-BFGS-B', maxiter=3, maxls=2, dmax=0.3)[source]¶
Bases:
objectBase optimizer class for use with FSM node optimization.
This abstract class provides an interface for optimizer implementations, requiring subclasses to define obj and optimize methods.
- obj(*args, **kwargs)[source]¶
Objective function to be implemented by subclasses.
- Parameters:
- Raises:
NotImplementedError – Always, since this is an abstract method.:
- Return type:
- optimizeobj(*args, **kwargs)[source]¶
Optimization method to be implemented by subclasses.
- Parameters:
- Raises:
NotImplementedError – Always, since this is an abstract method.:
- Return type:
- class mlfsm.opt.CartesianOptimizer(calc, method='L-BFGS-B', maxiter=3, maxls=2, dmax=0.3)[source]¶
Bases:
OptimizerPerforms optimization in Cartesian coordinates using projected gradients.
- obj(xyz, tangent, atoms)[source]¶
Objective function for cartesian coordinate optimization.
Computes energy and projected gradient given a position and tangent vector.
- Parameters:
xyz (ndarray) – Cartesian coordinates.
tangent (ndarray) – Tangent vector in Cartesian space.
atoms (ase.Atoms) – ASE atoms object with calculator.
- Returns:
tuple[float, ndarray]
- Return type:
Energy and projected gradient.
- optimize(atoms, tangent)[source]¶
Run optimization in Cartesian coordinates using user specified method.
- Parameters:
atoms (ASE.Atoms) – ASE atoms object with calculator.
tangent (ndarray) – Tangent vector used for projection.
- Returns:
tuple[ASE.Atoms,float,int,int] (ASE.Atoms with final positions, energy, total function)
evaluations (nfev), and number of optimizer iterations (nit).
- Return type:
- class mlfsm.opt.InternalsOptimizer(calc, method='L-BFGS-B', maxiter=3, maxls=6, dmax=0.05)[source]¶
Bases:
OptimizerPerforms projected optimization in internal coordinates.
NOTE: This optimizer is currently under development and may not work as expected.
- compute_bounds(q)[source]¶
Compute optimization bounds for each internal coordinate.
Bounds are computed based on the coordinate type (e.g., bend, torsion), ensuring constraints appropriate to their periodicity and domain.
- Parameters:
q (ndarray) – Internal coordinate values.
- Returns:
list[tuple[float, float]]
- Return type:
List of bounds for each coordinate.
- obj(q, xyzref, tangent, atoms)[source]¶
Objective function for internal coordinate optimization.
Computes the energy and projected gradient given internal coordinates and a tangent direction.
- Parameters:
q (ndarray) – Internal coordinates.
xyzref (ndarray) – Reference Cartesian coordinates.
tangent (ndarray) – Tangent vector in Cartesian space.
atoms (ASE.Atoms) – ASE atoms object with calculator.
- Returns:
tuple[float, ndarray]
- Return type:
Energy and projected gradient.
- optimize(atoms, tangent)[source]¶
Run optimization in internal coordinates using user specified method.
- Parameters:
atoms (ASE.Atoms) – ASE atoms object with calculator.
tangent (ndarray) – Tangent vector used for projection.
- Returns:
tuple[ASE.Atoms,float,int,int] (ASE.Atoms with final positions, energy, total function)
evaluations (nfev), and number of optimizer iterations (nit).
- Return type:
Geometry Utilities (mlfsm.geom)¶
Low-level vector operations and projection operators used throughout the FSM, including rigid-body alignment and translation/rotation projection.
Geometry utilities for vector operations in FSM-based reaction path methods.
- mlfsm.geom.magnitude(v)[source]¶
Return the magnitude (L2 norm) of a vector with floor for stability.
- mlfsm.geom.calculate_arc_length(string)[source]¶
Compute cumulative arc length along a string of molecular geometries.
- mlfsm.geom.project_trans_rot(a, b)[source]¶
Minimizes distance between structures a and b by minimizing rotation and translation.
- mlfsm.geom.project_trans_rot_fixed(a, b, fixed)[source]¶
Minimizes distance between structures a and b by minimizing rotation and translation.
- mlfsm.geom.generate_inertia_I(X)[source]¶
Compute the moment of inertia tensor for a set of 3D coordinates X.
- mlfsm.geom.generate_project_rt(X)[source]¶
Construct a projection operator that removes rigid translations and rotations from X.
Utilities (mlfsm.utils)¶
Input/output helpers for loading reactant and product geometries and handling fixed-atom constraints.
Utility functions for reading input and checking numeric types.
- mlfsm.utils.load_xyz(reaction_dir)[source]¶
Load reactant and product geometries from a reaction directory.
Reads the first and last frames of
initial.xyzand aligns them by minimizing rigid-body rotation and translation via the Kabsch algorithm.- Parameters:
reaction_dir (path-like) – Directory containing
initial.xyz. The file must have at least two XYZ frames: the reactant (first) and the product (last).- Returns:
reactant (ase.Atoms) – Reactant geometry after alignment.
product (ase.Atoms) – Product geometry after alignment to the reactant.
- Raises:
Exception – If
initial.xyzdoes not exist inreaction_dir.- Return type:
- mlfsm.utils.load_xyz_fixed(reaction_dir, fixed)[source]¶
Load reactant and product geometries with fixed-atom constraints applied.
Reads
initial.xyz, aligns the structures, and attaches an ASEFixAtomsconstraint to both atoms objects so that the specified atoms are held stationary during FSM optimization. Whenfixedis empty the behaviour is identical toload_xyz().- Parameters:
reaction_dir (path-like) – Directory containing
initial.xyz.fixed (NDArray[int]) – Zero-indexed array of atom indices to freeze. Pass an empty array (
np.array([], dtype=int)) to apply no constraints.
- Returns:
- Raises:
Exception – If
initial.xyzdoes not exist inreaction_dir.- Return type: