xnn.ffnn.models.amber.Amber#

class xnn.ffnn.models.amber.Amber(ffield, topology, *, cutoff=10.0, switch_width=0.0, charges=None, fudge_lj=None, fudge_qq=None, trainable=(), keep_intermediates=False, auto_impropers=True, constrain_charge=True, use_fast='auto', atomic_energies=None)[source]#

Bases: ClassicalFastPath, InteratomicPotential

The AMBER fixed-topology force field (Cornell et al. 1995 form).

An instance binds a parameter library to one molecular topology; the bonded terms, impropers, exclusions and scaled 1,4 pairs are resolved once, and forward evaluates the energy on any conformation (or batch of conformations) of that system. Forces and stress come from autograd via ForceStressOutput.

Parameters:
  • ffield (AmberLibrary, AmberForceField, str or Path) – The parameter library – a parsed AmberLibrary, a set shipped with xnn ("ff94"), a .frc or native JSON path, or an AmberForceField to share parameters with other models.

  • topology (MolecularTopology, str or Path) – The system’s topology (or a topology JSON path). Its charges are the partial charges unless charges is given; its residues order the impropers (place_impropers()).

  • cutoff (float, optional) – Nonbonded cutoff in Angstrom (the neighbor-list cutoff); by default 10.0. 1,4 pairs are independent of it.

  • switch_width (float, optional) – Width of a quintic switching function taking the nonbonded interactions smoothly to zero at the cutoff; 0.0 (plain truncation) by default.

  • charges (sequence of float, optional) – Per-atom partial charges in e, overriding the topology’s.

  • fudge_lj (float, optional) – Override the library’s 1,4 scaling factors (1/2 and 1/1.2).

  • fudge_qq (float, optional) – Override the library’s 1,4 scaling factors (1/2 and 1/1.2).

  • trainable (sequence of str or "all", optional) – Force-field groups (see AmberForceField) plus the model groups "charge" (per-atom charges) and "atom_ref" (per-element reference energies); "all" unfreezes everything.

  • keep_intermediates (bool, optional) – Stash the intermediate tensors of the last evaluation in self.intermediates. Default False.

  • auto_impropers (bool, optional) – When the topology lists no impropers, place them by the AMBER rules (one per three-connected atom with a matching pattern). Default True. Listed impropers are used as given, resolved by their atom classes in the listed order (or by improper_keys).

  • constrain_charge (bool or float, optional) – Hold the bound system’s total charge when charge trains: True (default) keeps the sum of the initial charges, a number fixes that value in e, False registers no constraint. The charges the model evaluates are the per-atom parameters shifted uniformly onto the constraint.

  • use_fast (bool or "auto", optional) – Evaluate the terms with the fused GPU kernels of classical_kernels (the same numbers to round-off). "auto" (default) and True take them on a CUDA device with Triton, in evaluation and in training; False evaluates every term eagerly. The kernels are differentiable twice (force training, Hessians), and once with a cell gradient (stress); training with a stress loss evaluates every term eagerly.

  • atomic_energies (mapping, optional) – Per-element reference energies in eV, {Z or symbol: E0}, loaded into atom_ref; the offset between the labels’ zero and the force field’s. All zero by default.

Notes

forward returns, besides node_energy / energy / node_features, the partial charges (N,) and one per-structure tensor per term: e_bond, e_angle, e_torsion, e_improper, e_vdw, e_coulomb, e_vdw14, e_coulomb14 and e_ref. Every structure in a batch must have this topology’s atom count and element sequence.

Variables:
  • atom_ref (torch.nn.Embedding) – The per-element reference energies, row Z.

  • species (list of int) – The atomic numbers of the bound topology.

  • impropers (list of tuple) – The improper quadruples in evaluation order (center third).

Parameters:
classmethod from_atoms(structure, ffield='ff94', *, charge=0, bonds=None, charges=None, orders=True, **kwargs)[source]#

Build an AMBER model for a structure, typing it from the library.

Residue templates (the #fragments of the parameter file) assign atom types and partial charges to every atom they match; atoms outside any residue are typed by the per-type SMARTS templates and carry zero charge unless charges is given.

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 (AmberLibrary, AmberForceField, str or Path, optional) – The parameter library (must carry templates); default "ff94".

  • charge (int, optional) – Total charge of the structure (for bond-order perception).

  • bonds (sequence of (int, int), optional) – Known connectivity; bond orders are then perceived, not bonds.

  • charges (sequence of float, optional) – Per-atom partial charges overriding the templates’ (e.g. RESP charges of a small molecule).

  • orders (bool, optional) – With bonds given, False skips the perception of bond orders and formal charges (the residue templates need only the connectivity), which is robust for charged systems and ions.

  • **kwargs – Forwarded to the constructor (cutoff, trainable, …).

Returns:

The model, bound to the derived topology.

Return type:

Amber

property charges: Tensor#

the charge parameters shifted uniformly so that they sum to the constrained total (the parameters themselves without a constraint).

Type:

Tensor

Type:

The per-atom charges the model evaluates

forward(data)[source]#

Evaluate the AMBER 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.

Returns:

node_energy (N,), energy (B,), charges (N,), node_features (N, 1) and the per-structure energy decomposition (see the class docstring).

Return type:

dict of str to Tensor

Raises:

ValueError – If a structure in the batch does not match the bound topology.

export_library()[source]#

Export the current parameters as an AmberLibrary.

The per-atom charges of this model are written into the residue templates of the library wherever the bound topology carries residue positions (every atom of a matched residue), so a refit of charge round-trips through the .frc file.

Returns:

See AmberForceField.export_library().

Return type:

AmberLibrary

property masses: Tensor#

Per-atom masses (u) of the bound topology.

Type:

Tensor

classmethod from_config(cfg)[source]#

Construct an Amber model from a core model config.

Core field: cfg.cutoff. From cfg.extra: library (default ff94) and either topology (a topology JSON path) or types + bonds (+ optional impropers / improper_keys / charges / residues) inline. Optional: switch_width, fudge_lj, fudge_qq (or the AMBER divisors scnb / scee), trainable, constrain_charge and atomic_energies. Alternative spellings are translated by xnn.common.config.translate.

Parameters:

cfg (xnn.common.config.schema.ModelConfig) – The core model config.

Returns:

The model.

Return type:

Amber

Raises:

ValueError – If the topology specification is missing.