xnn.ffnn.models.amoeba.Amoeba#
- class xnn.ffnn.models.amoeba.Amoeba(ffield, topology, *, cutoff=10.0, trainable=(), polarization=None, keep_intermediates=False, atomic_energies=None, ewald=None, ewald_alpha=None, pewald_alpha=None, dewald_alpha=None, ewald_cutoff=None, pme_grid=None, pme_order=5, ppme_order=None, dpme_grid=None, dpme_order=4, vdw_cutoff=None, vdw_taper=None, taper=None, repulsion_cutoff=None, chgtrn_cutoff=None, dispersion_cutoff=None, polar_eps=1e-08, preconditioner='diagonal', precond_cutoff=4.5, mesh_self=False, solver='auto', max_iter=100, predictor=None, predictor_history=6, conserve_charge=True, symmetry_mask=True, use_fast='auto', mixed_precision=False)[source]#
Bases:
InteratomicPotentialThe AMOEBA polarizable multipole force field.
An instance binds a parameter library to one molecular topology; the valence terms, multipole frames, polarization groups and nonbonded scale factors are resolved once, and
forwardevaluates the energy on any conformation (or batch of conformations) of that system. Forces come from autograd viaForceStressOutput.- Parameters:
ffield (AmoebaLibrary, AmoebaForceField, str or Path) – The parameter library: a parsed
AmoebaLibrary, a set shipped with xnn ("amoeba-water-2003","amoebapro13"), a.frc/ Tinker.prm/ JSON path, or anAmoebaForceFieldto share parameters with other models.topology (MolecularTopology, str or Path) – The system’s topology (or a topology JSON path).
cutoff (float, optional) – Neighbor-list cutoff in Angstrom, by default 10.0. For clusters use a value that encloses the whole system (every pair interacts in full); for cells it bounds the real-space cutoffs below.
trainable (sequence of str or "all", optional) – Force-field groups (see
AmoebaForceField) plus the model group"atom_ref";"all"unfreezes everything.polarization (str, optional) –
"mutual"solves the induced dipoles self-consistently,"direct"uses the permanent field only and"none"switches the induction off; by default the library’spolarizationsetting (MUTUALunless the file saysDIRECT).keep_intermediates (bool, optional) – Stash the intermediate tensors of the last evaluation in
self.intermediates.atomic_energies (mapping, optional) – Per-element reference energies in eV loaded into
atom_ref.ewald (bool, optional) – Ewald sums for the electrostatics of periodic cells:
None(default) switches them on for every structure that has a cell,Falsetruncates at the cutoff instead (minimum image). A slab (two periodic axes) is summed on the full cell, which must hold a vacuum gap along the free axis, with the Yeh-Berkowitz correction.ewald_alpha (float, optional) – Ewald coefficients (1/Angstrom) of the permanent multipoles, the induction and HIPPO’s dispersion; the defaults make the screened interaction at the real-space cutoff
1e-8, the induction one equal to the multipole one.pewald_alpha (float, optional) – Ewald coefficients (1/Angstrom) of the permanent multipoles, the induction and HIPPO’s dispersion; the defaults make the screened interaction at the real-space cutoff
1e-8, the induction one equal to the multipole one.dewald_alpha (float, optional) – Ewald coefficients (1/Angstrom) of the permanent multipoles, the induction and HIPPO’s dispersion; the defaults make the screened interaction at the real-space cutoff
1e-8, the induction one equal to the multipole one.ewald_cutoff (float, optional) – Real-space cutoff of the Ewald sums, by default the smaller of 7 Angstrom and
cutoff.pme_grid (sequence of int, optional) – Mesh dimensions of the electrostatic and dispersion particle-mesh sums, by default 1.2 (0.8) points per Angstrom. As in Tinker, every size is rounded up to an even one with prime factors 2, 3 and 5, at least 16 (a requested 27 becomes 30).
dpme_grid (sequence of int, optional) – Mesh dimensions of the electrostatic and dispersion particle-mesh sums, by default 1.2 (0.8) points per Angstrom. As in Tinker, every size is rounded up to an even one with prime factors 2, 3 and 5, at least 16 (a requested 27 becomes 30).
pme_order (int, optional) – B-spline orders of the multipole, induction and dispersion meshes (5, the multipole one, 4).
ppme_order (int, optional) – B-spline orders of the multipole, induction and dispersion meshes (5, the multipole one, 4).
dpme_order (int, optional) – B-spline orders of the multipole, induction and dispersion meshes (5, the multipole one, 4).
vdw_cutoff (float, optional) – Cutoffs of the switched short-range terms, by default
cutoff(the dispersion one is the Ewald real-space cutoff when its sum is on). The van der Waals term acts between the reduced sites, so a pair of sites withinvdw_cutoffcan belong to atoms just beyond it: withcutoffabovevdw_cutoffby twice the largest site displacement (about 0.2 Angstrom for hydrogens reduced to 0.9 of their bond), the neighbor list holds every such pair, as Tinker’s list of the sites does.repulsion_cutoff (float, optional) – Cutoffs of the switched short-range terms, by default
cutoff(the dispersion one is the Ewald real-space cutoff when its sum is on). The van der Waals term acts between the reduced sites, so a pair of sites withinvdw_cutoffcan belong to atoms just beyond it: withcutoffabovevdw_cutoffby twice the largest site displacement (about 0.2 Angstrom for hydrogens reduced to 0.9 of their bond), the neighbor list holds every such pair, as Tinker’s list of the sites does.chgtrn_cutoff (float, optional) – Cutoffs of the switched short-range terms, by default
cutoff(the dispersion one is the Ewald real-space cutoff when its sum is on). The van der Waals term acts between the reduced sites, so a pair of sites withinvdw_cutoffcan belong to atoms just beyond it: withcutoffabovevdw_cutoffby twice the largest site displacement (about 0.2 Angstrom for hydrogens reduced to 0.9 of their bond), the neighbor list holds every such pair, as Tinker’s list of the sites does.dispersion_cutoff (float, optional) – Cutoffs of the switched short-range terms, by default
cutoff(the dispersion one is the Ewald real-space cutoff when its sum is on). The van der Waals term acts between the reduced sites, so a pair of sites withinvdw_cutoffcan belong to atoms just beyond it: withcutoffabovevdw_cutoffby twice the largest site displacement (about 0.2 Angstrom for hydrogens reduced to 0.9 of their bond), the neighbor list holds every such pair, as Tinker’s list of the sites does.vdw_taper (float, optional) – Start of the C2 switch of the van der Waals term, and of every switched term, in Angstrom; by default 0.9 of each cutoff for cells and no switching for molecules.
taper (float, optional) – Start of the C2 switch of the van der Waals term, and of every switched term, in Angstrom; by default 0.9 of each cutoff for cells and no switching for molecules.
mesh_self (bool, optional) – Remove the spurious, position-averaged mesh self-interaction of every multipole from the particle-mesh energy, from the field that polarizes it and from the dispersion sum. Off by default, as in Tinker. On, the mean discretisation error of the self-interaction leaves the energies and the stress.
polar_eps (float, optional) – Convergence of the iterative induced-dipole solve, the rms change per iteration in Debye (
1e-8). The adjoint solve of the forces converges the dipoles of the polar field to the same tolerance.preconditioner (str, optional) – Preconditioner of the iterative solve:
"diagonal"(default, the polarizabilities),"block"(the exact inverse of every molecule’s real-space block, polarization groups for molecules of more than 32 atoms),"neumann"(the diagonal plus a first-order correction from the pairs withinprecond_cutoff) or"block-neumann"(both). The dipoles are converged topolar_epseither way; only the number of iterations changes.precond_cutoff (float, optional) – Pair distance of the Neumann correction, in Angstrom (4.5).
solver (str, optional) –
"auto"(dense for molecules up to a thousand atoms, iterative otherwise),"dense"or"iterative".max_iter (int, optional) – Iteration limit of the solve (100).
predictor (str, optional) – Predict the starting dipoles of the iterative solve from the converged dipoles of the last evaluations (
DipolePredictor:"aspc","gear"or"previous"), for molecular dynamics where each structure follows the last. Used in evaluation mode only; by defaultNone(the MDI engine turns ASPC on). The result agrees with a cold start topolar_eps.predictor_history (int, optional) – Number of past dipole sets the predictor uses (6).
conserve_charge (bool, optional) – Hold the total charge of every molecule at its library value while
chargetrains (a minimum-norm projection of the row charges, registered on the force field), by defaultTrue.symmetry_mask (bool, optional) – Keep the dipole and quadrupole components that the library leaves zero at zero while they train, by default
True. The quadrupoles stay symmetric and traceless in any case, andexport_librarywrites the multipoles the model uses.mixed_precision (bool, optional) – How the fast implementation evaluates the radial ladders of the pair terms in a float32 model:
False(default) in float64, cast afterwards, at the round-off of the float32 reference;Truein float32 throughout, as Tinker9’s mixed precision does, faster, with the energies at the float32 round-off and the forces up to one digit off. No effect on a float64 model.use_fast (bool or str, optional) – The fast path:
Falseruns the reference implementation, the eager composition of the equations (any device, second derivatives);Trueruns the fast implementation, which computes the same numbers to round-off with the same derivatives: the fused GPU kernels of the pair terms, the fields and the induction’s products (amoeba_kernels) and the mesh spreading and interpolation kernels. The pair kernels are differentiable twice (their generated tangents and parameter adjoints,amoeba_tangents), so force losses and parameter gradients train through them; in training the mesh and the solver’s products run eager. In evaluation mode the mesh runs on kernels too, and a second derivative (a Hessian) takes the gradient of their backward pass through the eager stencils. When forces follow, AMOEBA’s fast implementation solves the dipoles of the direct and the polar field together, one set of iterations for both (Tinker’s scheme), so its dipoles and forces agree with the reference’s to the solver tolerance. On a CPU with a C++ compiler the same kernels run as C++ loops (amoeba_cpu)."auto"(default) takes the fast implementation above the measured crossover of the device and the mode (evaluation or training) and the reference otherwise.mixed_precision – How the fast implementation of HIPPO evaluates the radial ladders of the pair terms in a float32 model:
False(default) in float64, cast afterwards, which keeps the float32 numbers at the round-off of the float32 reference;Truein float32 throughout, as Tinker9’s mixed precision does, which is faster, with the energies at the float32 round-off and the forces up to one digit off. No effect on a float64 model or on AMOEBA.
Notes
forwardreturnsnode_energy/energy/node_features, the per-atomcharges(monopoles, charge flux included), theinduced_dipoles(N, 3)in e Angstrom, the moleculardipole(B, 3)in e Angstrom, and one per-structure tensor per term:e_bond,e_angle,e_strbnd,e_urey,e_opbend,e_torsion,e_pitors,e_tortor,e_vdw,e_multipole,e_polar(and for HIPPOe_repulsion,e_dispersion,e_chgtrninstead ofe_vdw), ande_ref.- classmethod from_atoms(structure, ffield='amoeba-water-2003', *, charge=0, bonds=None, orders=True, **kwargs)[source]#
Build a model for a structure, typing it from the library’s templates.
- Parameters:
structure (object) – An
ase.Atoms, a(positions, atomic_numbers)pair, a dict with"pos"/"atomic_numbers", an RDKit molecule or a SMILES string.ffield (AmoebaLibrary, AmoebaForceField, str or Path, optional) – The parameter library (must carry templates or fragments).
charge (int, optional) – Total charge (for bond-order perception).
bonds (sequence of (int, int), optional) – Known connectivity.
orders (bool, optional) – With
bondsgiven,Falseskips bond-order perception.**kwargs – Forwarded to the constructor.
- Returns:
The model bound to the derived topology.
- Return type:
- classmethod from_tinker_xyz(path, ffield, type_map=None, **kwargs)[source]#
Build a model from a Tinker
.xyzfile (types and connectivity).- Parameters:
path (str or Path) – The coordinate file.
ffield (AmoebaLibrary, AmoebaForceField, str or Path) – The parameter library; the file’s integer types must be the library’s type names, or be translated by
type_map.type_map (dict, optional) –
{integer type: type name}.**kwargs – Forwarded to the constructor.
- Returns:
(model, structure)withstructurea dict ofpos,atomic_numbers(andcellwhen the file has one) ready forstructure_to_graph().- Return type:
- plan_pairs(data, plan)[source]#
Refresh the pair list of
planfrom the neighbor list ofdatain place, keeping the rest of the plan: a cheap rebuild while the atoms move continuously (an atom wrapped back into the cell changes the image shifts of its bonded vectors too and needsplan_step()).- Parameters:
data (AtomicGraph) – The batched graph at the current positions, its neighbor list built with
cutoff + skin.plan (StepPlan) – The plan to refresh.
- Returns:
Whether the pairs fitted the plan’s capacity and were copied; the plan is unchanged otherwise.
- Return type:
- refresh_pairs(data, plan, cutoff)[source]#
Refresh the pair list of
planin place at the positions and cell ofdata, one structure, from a half neighbor list ofcutoff(the model’s cutoff plus the skin), without building a graph: the same pairs asplan_pairs(), found once each on the device.- Parameters:
data (AtomicGraph) – The plan’s graph, its positions and cell at the current step.
plan (StepPlan) – The plan to refresh.
cutoff (float) – The radius of the pair list.
- Returns:
Whether the pairs fitted the plan’s capacity and were copied; the plan is unchanged otherwise.
- Return type:
- stage_pairs(data, plan, pairs, single_image=False)[source]#
The unique pairs
(i, k, shift)ofdata, one structure, sorted byi(unique_pairs()), recorded as the pair list of a new plan forplan.update(fresh, bonded=False).planis not touched, so a step can still run on it meanwhile.- Parameters:
data (AtomicGraph) – The plan’s graph, its positions and cell where the pairs were found.
plan (StepPlan) – The plan whose capacity and skin the new one takes.
pairs (tuple of Tensor) – The pairs and their integer image shifts, or those in buffers of the plan’s capacity followed by their number on the device.
single_image (bool, optional) – Every pair has one image within the list’s cutoff (a cell more than twice the cutoff high on every axis), so a bonded pair’s scale factors need no minimum-image test.
- Returns:
The new pair list, or
Nonewhen the pairs exceed the capacity.- Return type:
StepPlan or None
- forward(data, plan=None)[source]#
Evaluate the energy on a (batched) atomic graph.
- Parameters:
data (AtomicGraph) – The batched graph; every structure must be a conformation of the bound topology, with the neighbor list built with this model’s
cutoff.plan (StepPlan, optional) – The host decisions of this structure, from
plan_step(): the evaluation reads them instead of deciding them again, and takes its pairs from the plan instead of the neighbor list. Itstermsselect the terms evaluated (all by default).
- Returns:
See the class notes.
- Return type:
dict of str to Tensor
- Raises:
ValueError – If a structure in the batch does not match the bound topology.
- forms_plan_forces(data, plan)[source]#
Whether an evaluation on
planforms its forces and strain derivative itself (forward_plan_direct()): an inner step (terms="valence") of one periodic structure on the valence kernels of a GPU.- Parameters:
data (AtomicGraph) – The structure.
plan (StepPlan) – Its plan.
- Returns:
Whether
forward_plan_direct()serves the evaluation.- Return type:
- forward_plan_direct(data, plan)[source]#
The valence terms of an inner step (see
forms_plan_forces()) with their forces and strain derivative, formed directly: the kernels’ gradient with respect to the bonded vectors is scattered to the atoms, and the strain derivative is the sum of every vector times its gradient (a bonded vector strains with the cell and the positions).- Parameters:
data (AtomicGraph) – The structure.
plan (StepPlan) – Its plan.
- Returns:
energy,node_energy,forces,virial(the strain derivative(1, 3, 3)) and the valence terms’ totals.- Return type:
dict of str to Tensor
- plan_step(data, skin=0.0, capacity=None)[source]#
Record the host decisions of an evaluation of
datafor later evaluations of the same structure as it moves (seeStepPlan); the recording evaluation itself runs without gradients and leaves the dipole predictor alone.- Parameters:
data (AtomicGraph) – The batched graph, its neighbor list built with
cutoff + skin.skin (float, optional) – The margin of the neighbor list beyond the model’s cutoff in Angstrom, by default 0 (the plan then holds at these positions only).
capacity (int, optional) – The number of pairs the plan holds, padded beyond the unique pairs of the neighbor list; by default exactly those.
- Returns:
The plan, for
forward(data, plan).- Return type:
- Raises:
ValueError – If the neighbor list has more unique pairs than
capacity.
- rewind_predictors()[source]#
Take the dipoles of the last evaluation back out of the predictors that stored them, before the step is evaluated again (see
DipolePredictor.rewind()).- Return type:
None
- refresh_cell(plan, cells, changed=False)[source]#
Bring the cell terms the step plan
plankeeps across evaluations (the mesh influence functions, inverse cells and volumes of every mesh group) to the cellscells(B, 3, 3), in place, so that a recorded step follows a changed cell. Reads the cells on the host, unless the caller found themchanged.
- set_dipole_predictor(kind, history=6)[source]#
Switch the induced-dipole predictor on (
"aspc","gear","previous") or off (Noneor"none"); seeDipolePredictor.
- molecular_polarizability(data)[source]#
Static dipole polarizability of every structure from the induction model.
A uniform field is applied to every polarizable site, the induced dipoles are solved with the mutual-induction matrix of the structure (Thole or density damping included) and summed, column by column, into the
(B, 3, 3)tensor in Angstrom^3. Permanent multipoles and the polarization groups play no role: the induced dipoles see every other induced dipole as in a mutual induction run.- Parameters:
data (AtomicGraph) – The (batched) graph of conformations of the bound topology.
- Returns:
Polarizability tensors
(B, 3, 3).- Return type:
Tensor
- export_library()[source]#
Export the current parameters as an
AmoebaLibrary.- Return type:
- classmethod from_config(cfg)[source]#
Construct the model from a core model config.
Core field:
cfg.cutoff. Fromcfg.extra:libraryand eithertopology(a topology JSON path),tinker_xyz(a Tinker coordinate file) ortypes+bondsinline; optionalpolarization,trainable,atomic_energies.- Parameters:
cfg (xnn.common.config.schema.ModelConfig) – The core model config.
- Returns:
The model.
- Return type: