xnn.ffnn.models.opls.OPLSForceField#

class xnn.ffnn.models.opls.OPLSForceField(library, trainable=())[source]#

Bases: Module

The trainable parameter tensors of an OPLS parameter library.

Assembles the library’s per-atom-type nonbonded parameters and per-class bonded parameter tables into dense tensors (eV / Angstrom / radians), exposed as a torch.nn.ParameterDict so any group can be refit by gradient descent. One instance can be shared by several OPLS models (different molecules) to train transferable parameters jointly.

Parameters:
  • library (OPLSLibrary, str or Path) – The parameter library (or a built-in set name / file path, see read_opls()).

  • trainable (sequence of str or "all", optional) – Parameter groups to expose to the optimizer: any of "charge", "sigma", "epsilon", "bond_k", "bond_r0", "angle_k", "angle_theta0", "dihedral_v", "improper_v2"; "all" unfreezes every group. Default: none (a fixed classical force field).

Variables:
  • params (torch.nn.ParameterDict) – charge (T,) in e, sigma (T,) in Angstrom, epsilon (T,) in eV, bond_k (NB,) in eV/A^2, bond_r0 (NB,), angle_k (NA,) in eV/rad^2, angle_theta0 (NA,) in rad, dihedral_v (ND, 5) in eV and improper_v2 (NI,) in eV.

  • improper_keys (type_names, bond_keys, angle_keys, dihedral_keys,) – Row labels of the parameter tensors, in assembly order.

  • fudge_qq (fudge_lj,) – The library’s 1,4 scaling factors.

type_index(name)[source]#

Row index of atom type name.

Parameters:

name (str) – The atom-type name (e.g. "opls_135").

Returns:

Index into the per-type parameter tensors.

Return type:

int

Raises:

KeyError – If the library has no such atom type.

resolve_bond(a, b)[source]#

Bond-type row for the class pair (a, b).

Parameters:
  • a (str) – Atom classes of the bond’s ends.

  • b (str) – Atom classes of the bond’s ends.

Returns:

Row index into bond_k / bond_r0.

Return type:

int

Raises:

KeyError – If the library has no parameters for this bond type.

resolve_angle(a, b, c)[source]#

Angle-type row for the class triple (a, b, c).

Parameters:
  • a (str) – Atom classes, center second.

  • b (str) – Atom classes, center second.

  • c (str) – Atom classes, center second.

Returns:

Row index into angle_k / angle_theta0.

Return type:

int

Raises:

KeyError – If the library has no parameters for this angle type.

resolve_dihedral(a, b, c, d)[source]#

Dihedral-type row for the class quadruple (wildcards allowed).

Parameters:
  • a (str) – Atom classes along the dihedral.

  • b (str) – Atom classes along the dihedral.

  • c (str) – Atom classes along the dihedral.

  • d (str) – Atom classes along the dihedral.

Returns:

Row index into dihedral_v.

Return type:

int

Raises:

KeyError – If no library entry (exact or wildcard) matches.

resolve_improper(*args)[source]#

Improper-type row, by exact key or by class quadruple.

Parameters:

*args (str) – Either one opaque key ("Z-CM-X-Y", from a topology’s improper_keys), or four atom classes i, j, k, l with k the trigonal center, matched against the library’s "I-J-K-L" patterns (X wildcards) in SEAMM’s precedence order (resolve_improper_type()).

Returns:

Row index into improper_v2.

Return type:

int

Raises:

KeyError – If nothing in the library matches.

improper_defined(i, j, k, l)[source]#

Whether an improper pattern exists for the class quadruple.

Parameters:
Return type:

bool

export_library()[source]#

Write the current (possibly trained) parameters back to a library.

Returns:

A new library in OPLS units (kcal/mol, Angstrom, degrees), round-trippable through OPLSLibrary.save() / read_opls().

Return type:

OPLSLibrary