xnn.dnn.models.qrnn.QRNN#

class xnn.dnn.models.qrnn.QRNN(species=[1, 6, 7, 8, 9, 15, 16, 17], radial_cutoff=5.2, angular_cutoff=3.5, hidden=(128, 128, 64), charge_hidden=None, activation='gelu', atomic_energies=None, aev_kwargs=None, charge_model='recursive', n_iterations=2, initial_charges='uniform', hardness=None, min_width=0.05, coulomb=True, coulomb_midpoint=2.2, coulomb_steepness=8.5, dispersion=True, dispersion_s6=1.0, dispersion_damping=6.0)[source]#

Bases: ExactFloat64Constants, DescriptorPotential

QRNN interatomic potential: an HDNNP with recursively predicted charges.

See the module docstring for the equations. The element networks read the AEV followed by the charge and the charge-weighted radial vector.

Parameters:
  • species (sequence of int, optional) – Atomic numbers, by default H, C, N, O, F, P, S, Cl.

  • radial_cutoff (float, optional) – Radial cutoff of the AEV, by default 5.2.

  • angular_cutoff (float, optional) – Angular cutoff of the AEV, by default 3.5.

  • hidden (sequence of int or dict[int, sequence of int], optional) – Hidden widths of the energy networks (shared or per element), by default (128, 128, 64).

  • charge_hidden (sequence of int or dict[int, sequence of int], optional) – Hidden widths of the charge networks; None (default) takes hidden.

  • activation (str, optional) – Hidden activation of every network, by default "gelu".

  • atomic_energies (sequence of float or None, optional) – Per-species energy added to every atom (aligned with species).

  • aev_kwargs (dict, optional) – Extra arguments of AEV (grids, radial_prefactor, angular_cos_factor); the defaults are the ANI-1x grids.

  • charge_model (str, optional) – "recursive" (default, QRNN) or "qeq" (QeqNN).

  • n_iterations (int, optional) – Cycles of the recursion, by default 2.

  • initial_charges (str, optional) – Charges entering the first cycle: "uniform" (default, the net charge spread evenly) or "zero".

  • hardness (sequence of float or None, optional) – Fixed hardnesses J_ii in eV per e^2 aligned with species; None (default) takes eeq_hardness().

  • min_width (float, optional) – QeqNN: the smallest Gaussian width sigma_0 in Angstrom, by default 0.05.

  • coulomb (bool, optional) – Add the attenuated Coulomb energy of the charges, by default True.

  • coulomb_midpoint (float, optional) – Distance a of the attenuation in Angstrom, by default 2.2.

  • coulomb_steepness (float, optional) – Steepness b of the attenuation in inverse Angstrom, by default 8.5.

  • dispersion (bool, optional) – Add the wB97X-D dispersion energy, by default True.

  • dispersion_s6 (float, optional) – Scale of the dispersion energy, by default 1.0.

  • dispersion_damping (float, optional) – Damping parameter a_d, by default 6.0.

Variables:

charge_nets (_ElementNetworks) – Per-element networks of the effective electronegativities (QRNN) or of X and S (QeqNN).

fast_policies()[source]#

The "auto" policies (evaluation, training) of xnn.dnn.fast.qrnn.

receptive_field()[source]#

None: the charge constraint couples every atom of a structure.

Return type:

float | None

compute(atomic_numbers, edge_index, edge_vec, pos, batch, num_graphs, total_charge, cell, pbc, triplets=None, width=0, element_widths=None)[source]#

Energies and charges of a batch from tensors (TorchScript-compatible).

Parameters:
  • atomic_numbers (Tensor) – Atomic numbers (N,).

  • edge_index (Tensor) – Edge index (2, E); row 0 the neighbor, row 1 the center.

  • edge_vec (Tensor) – Edge vectors (E, 3).

  • pos (Tensor) – Positions (N, 3) (the all-pair terms and QeqNN).

  • batch (Tensor) – Structure index per atom (N,).

  • num_graphs (int) – Number of structures B.

  • total_charge (Tensor) – Net charge of every structure (B,).

  • cell (Tensor or None) – Cells (B, 3, 3).

  • pbc (Tensor or None) – Periodicity flags (B, 3).

  • triplets (tuple of Tensor, optional) – The enumerated triplets of the AEV (QRNNPlanner).

  • width (int, optional) – A positive value evaluates without reading a value back from the device (a captured step): the networks of every element together with blocks of width rows, the all-pair terms as masked matrices. By default 0.

  • element_widths (list of int, optional) – In a captured step, the rows of each element’s block in the order of species (QRNNPlanner) instead of width for every element.

Returns:

"node_energy" (N,), "charges" (N,), "electronegativities" (N,) (the effective ones of the last cycle, or QeqNN’s chi), "node_energy_short", "node_energy_elec" and "node_energy_dispersion" (N,) and "node_features" (the AEV).

Return type:

dict of str to Tensor

node_features_energy_charges(atomic_numbers, edge_index, edge_vec, pos, cell, pbc, total_charge, spin_multiplicity)[source]#

TorchScript core of one structure: the AEV, atomic energies and charges.

Parameters:
  • atomic_numbers (Tensor) – Atomic numbers (N,).

  • edge_index (Tensor) – Edge index (2, E); row 0 the neighbor, row 1 the center.

  • edge_vec (Tensor) – Edge vectors (E, 3).

  • pos (Tensor) – Positions (N, 3).

  • cell (Tensor) – Cell (3, 3) (used by QeqNN where pbc is set).

  • pbc (Tensor) – Periodicity flags (3,).

  • total_charge (float) – Net charge of the structure.

  • spin_multiplicity (float) – Unused.

Returns:

The AEV (N, D), the atomic energies (N,) and the charges (N,).

Return type:

tuple of Tensor

node_features_energy(atomic_numbers, edge_index, edge_vec)[source]#

TorchScript core of one neutral structure from its edges alone: the AEV and the atomic energies. Only for the recursive charges without the Coulomb and dispersion terms, which need the positions (node_features_energy_charges() serves every setting).

Parameters:
Return type:

Tuple[Tensor, Tensor]

forward(data)[source]#

Energies and charges of a batched graph.

Parameters:

data (AtomicGraph) – Batched atomic graph; its total_charge (per structure, zero when absent) fixes the sum of the charges.

Returns:

The outputs of compute(), with "energy" (B,), "energy_short", "energy_elec" and "energy_dispersion" per structure and, for molecules, "dipole" (B, 3) (the charges times the positions).

Return type:

dict of str to Tensor

index_planner()[source]#

The planner of a captured evaluation or training step (QRNNPlanner).

Raises:

ValueError – For QeqNN, whose charge equilibration does not run in a captured step.

Return type:

QRNNPlanner

classmethod from_config(cfg)[source]#

Build a QRNN from a configuration object.

Every option is read from cfg.extra under its constructor name.

Parameters:

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

Returns:

Instantiated model.

Return type:

QRNN