xnn.ffnn.models.gfnff.GFNFF#
- class xnn.ffnn.models.gfnff.GFNFF(atomic_numbers, positions, charge=0, *, cutoff=1.0, cache_dir=None, use_fast='auto', skin=1.0, fixed_lists=False, cell=None)[source]#
Bases:
InteratomicPotentialThe GFN-FF force field of one molecule.
The topology is generated at construction from the given structure; every structure passed to
forwardmust be a conformation of that molecule (same atoms in the same order). The hydrogen- and halogen-bond rows are those of each conformation: candidates withinskinof the distance cuts are kept, each evaluation applies the cuts, and the candidates are regenerated once an atom has moved by more than half the skin. The energy is in eV. It has no unique atomic decomposition (the charges come from a global solve), sonode_energycarries an equal share per atom.- Parameters:
atomic_numbers (sequence of int) – Atomic numbers of the molecule,
(N,).positions (array-like) – Positions in Angstrom,
(N, 3), that define the topology.charge (int, optional) – Total charge.
cutoff (float, optional) – Radius of the neighbor list of the input graphs. The model evaluates all pairs and does not read the list.
cache_dir (str or Path, optional) – Model cache holding the downloaded element parameters.
use_fast (bool or "auto", optional) –
False: the eager terms, differentiable to any order.True: the fused kernels ofgfnff_kernelson CPUs and GPUs, the same energies, forces and stress to rounding, differentiable twice (their tangent kernels give the second derivatives of a force or stress loss)."auto"(the default): the kernels in evaluation and training mode where they can run, the eager terms otherwise.skin (float, optional) – Margin in Angstrom of the hydrogen- and halogen-bond candidates.
fixed_lists (bool, optional) – Keep the hydrogen- and halogen-bond rows of the given structure for every conformation instead.
cell (array-like, optional) – Lattice vectors in Angstrom,
(3, 3)rows, for a structure periodic in three dimensions; the topology is that of the unit cell with its images.
- Raises:
NotImplementedError – For an element or a bonding situation the rules do not cover.
- fused(positions)[source]#
The launches of the fused kernels when this evaluation takes the fast path, else
None.- Parameters:
positions (Tensor)
- energy_and_gradient(positions, cell=None)[source]#
Term energies and the gradient of their sum for one conformation, by the fused kernels where
fused()selects them and by the eager terms otherwise.- Parameters:
positions (Tensor) – Positions in Angstrom,
(N, 3).cell (Tensor, optional) – Lattice vectors in Angstrom of a periodic model,
(3, 3)rows; the bound cell by default.
- Returns:
The energies
(9,)in Hartree in the order ofTERMS, and the gradient(N, 3)in Hartree per Angstrom; a periodic model adds the gradient in the cell at fixed positions(3, 3)in Hartree per Angstrom.- Return type:
tuple of Tensor
- follow(positions)[source]#
Regenerate the hydrogen- and halogen-bond candidates when an atom of
positions(Angstrom) has moved by more than half the skin since they were generated.- Parameters:
positions (Tensor)
- Return type:
None
- classmethod from_atoms(structure, *, charge=0, **kwargs)[source]#
Build the force field of a structure.
- classmethod from_config(cfg)[source]#
Construct the model from a core model config.
cfg.extraholdsatomic_numbersandpositions(the structure that defines the topology) and optionallycharge,use_fast,skin,fixed_listsandcell(the lattice vectors of a periodic structure, one per row).- Parameters:
cfg (xnn.common.config.schema.ModelConfig) – The core model config.
- Returns:
The model.
- Return type:
- Raises:
ValueError – If the structure is missing.
- forms_forces(data)[source]#
Whether
forward_direct()serves this evaluation: always in evaluation mode, unless the positions carry an autograd graph that the outputs must continue.- Parameters:
data (AtomicGraph)
- Return type:
- forward_direct(data)[source]#
forward()with the forces"forces"and the strain derivative"virial"ofenergy_and_gradient()(seedirect_outputs()); the cell of a periodic structure is the one of the graph. The outputs carry no autograd graph.- Parameters:
data (AtomicGraph)
- Return type:
- export_core()[source]#
The scriptable core of
export_torchscript_potential(): the bound molecule or cluster (GFNFFExport) or periodic cell (GFNFFCellExport).- Return type:
- forward(data)[source]#
Evaluate the energy of a batch of conformations.
- Parameters:
data (AtomicGraph) – The batched graph; every structure is a conformation of the molecule the model was built for.
- Returns:
energy(B,)andnode_energy(N,)in eV, and onee_<term>(B,)per entry ofTERMS.- Return type:
dict of str to Tensor
- Raises:
ValueError – If a structure is not a conformation of the bound molecule.