tfep.potentials.psi4.Psi4Potential
- class tfep.potentials.psi4.Psi4Potential(name, molecule=None, positions_unit=None, energy_unit=None, precompute_gradient=True, parallelization_strategy=None, on_unconverged='raise', **kwargs)[source]
Bases:
PotentialBasePotential energy and forces with Psi4.
This
Modulewraps :class:.Psi4PotentialEnergyFuncto provide a differentiable potential energy function for training. It also provides an API to compute energies and forces with Psi4 from batches of coordinates innumpyarrays in standard format (i.e., shape(n_atoms, 3)) rather than flattenedtorch.Tensor``s (i.e., shape ``(n_atoms*3,)).See also
Psi4PotentialEnergyFuncMore details on input parameters and implementation details.
psi4.energydocumentation:More information on the supported keyword arguments.
psi4.gradientdocumentation:More information on the supported keyword arguments.
- __init__(name, molecule=None, positions_unit=None, energy_unit=None, precompute_gradient=True, parallelization_strategy=None, on_unconverged='raise', **kwargs)[source]
Constructor
- Parameters:
name (str) – The name of the potential to pass to
psi4.energy().molecule (psi4.core.Molecule, optional) – If not
None, this will be set as the currently activated molecule in Psi4. Note that the old active molecule is not restored at the end of the execution.positions_unit (pint.Unit, optional) – The unit of the positions passed to the class methods. Since
Tensor``s and positions returned by MDAnalysis normally do not have ``pintunits attached, this is used to appropriately convertbatch_positionsto Psi4 units. IfNone, no conversion is performed, which assumes that the input positions are in the same units used by Psi4.energy_unit (pint.Unit, optional) – The unit used for the returned energies (and as a consequence forces). Since
Tensor``s and positions returned by MDAnalysis normally do not have ``pintunits attached, this is used to appropriately convert Psi4 energies into the desired units. IfNone, no conversion is performed, which means that energies and forces will be returned in Psi4 units.precompute_gradient (bool, optional) – If
True, the gradient is computed in the forward pass and saved to be consumed during backward.parallelization_strategy (tfep.utils.parallel.ParallelizationStrategy, optional) – The parallelization strategy used to distribute batches of energy and gradient calculations. By default, these are executed serially using the thread-based parallelization native in psi4.
on_unconverged (str, optional) – Specifies how to handle the case in which the calculation did not converge. It can have the following values: -
'raise': Raise the Psi4 exception. -'nan': Returnfloat('nan')energy and zero forces. To treat the calculation as converged and return the latest energy, force, and/or wavefunction, simply set the psi4 global option'fail_on_maxiter'.**kwargs – Other keyword arguments to pass to :class:
.Psi4PotentialEnergyFunc,psi4.energy, andpsi4.gradient.
Methods
__init__(name[, molecule, positions_unit, ...])Constructor
add_module(name, module)Add a child module to the current module.
apply(fn)Apply
fnrecursively to every submodule (as returned by.children()) as well as self.bfloat16()Casts all floating point parameters and buffers to
bfloat16datatype.buffers([recurse])Return an iterator over module buffers.
children()Return an iterator over immediate children modules.
compile(*args, **kwargs)Compile this Module's forward using
torch.compile().cpu()Move all model parameters and buffers to the CPU.
cuda([device])Move all model parameters and buffers to the GPU.
default_energy_unit(unit_registry)Return the default energy units.
default_positions_unit(unit_registry)Return the default positions units.
double()Casts all floating point parameters and buffers to
doubledatatype.energy(batch_positions)Compute a the potential energy of a batch of configurations.
eval()Set the module in evaluation mode.
extra_repr()Set the extra representation of the module.
float()Casts all floating point parameters and buffers to
floatdatatype.force(batch_positions)Compute the force for a batch of configurations.
forward(batch_positions)Compute a differential potential energy for a batch of configurations.
get_buffer(target)Return the buffer given by
targetif it exists, otherwise throw an error.get_extra_state()Return any extra state to include in the module's state_dict.
get_parameter(target)Return the parameter given by
targetif it exists, otherwise throw an error.get_submodule(target)Return the submodule given by
targetif it exists, otherwise throw an error.half()Casts all floating point parameters and buffers to
halfdatatype.ipu([device])Move all model parameters and buffers to the IPU.
load_state_dict(state_dict[, strict, assign])Copy parameters and buffers from
state_dictinto this module and its descendants.modules()Return an iterator over all modules in the network.
mtia([device])Move all model parameters and buffers to the MTIA.
named_buffers([prefix, recurse, ...])Return an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.
named_children()Return an iterator over immediate children modules, yielding both the name of the module as well as the module itself.
named_modules([memo, prefix, remove_duplicate])Return an iterator over all modules in the network, yielding both the name of the module as well as the module itself.
named_parameters([prefix, recurse, ...])Return an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.
parameters([recurse])Return an iterator over module parameters.
register_backward_hook(hook)Register a backward hook on the module.
register_buffer(name, tensor[, persistent])Add a buffer to the module.
register_forward_hook(hook, *[, prepend, ...])Register a forward hook on the module.
register_forward_pre_hook(hook, *[, ...])Register a forward pre-hook on the module.
register_full_backward_hook(hook[, prepend])Register a backward hook on the module.
register_full_backward_pre_hook(hook[, prepend])Register a backward pre-hook on the module.
register_load_state_dict_post_hook(hook)Register a post-hook to be run after module's
load_state_dict()is called.register_load_state_dict_pre_hook(hook)Register a pre-hook to be run before module's
load_state_dict()is called.register_module(name, module)Alias for
add_module().register_parameter(name, param)Add a parameter to the module.
register_state_dict_post_hook(hook)Register a post-hook for the
state_dict()method.register_state_dict_pre_hook(hook)Register a pre-hook for the
state_dict()method.requires_grad_([requires_grad])Change if autograd should record operations on parameters in this module.
set_extra_state(state)Set extra state contained in the loaded state_dict.
set_submodule(target, module)Set the submodule given by
targetif it exists, otherwise throw an error.share_memory()See
torch.Tensor.share_memory_().state_dict(*args[, destination, prefix, ...])Return a dictionary containing references to the whole state of the module.
to(*args, **kwargs)Move and/or cast the parameters and buffers.
to_empty(*, device[, recurse])Move the parameters and buffers to the specified device without copying storage.
train([mode])Set the module in training mode.
type(dst_type)Casts all parameters and buffers to
dst_type.xpu([device])Move all model parameters and buffers to the XPU.
zero_grad([set_to_none])Reset gradients of all model parameters.
Attributes
The default energy unit.
The default positions unit.
T_destinationcall_super_initdump_patchesThe energy units of the returned potential.
The positions unit requested for the input.
training- DEFAULT_ENERGY_UNIT: str = 'hartree'
The default energy unit.
- DEFAULT_POSITIONS_UNIT: str = 'bohr'
The default positions unit.
- classmethod default_energy_unit(unit_registry) Quantity
Return the default energy units.
- classmethod default_positions_unit(unit_registry) Quantity
Return the default positions units.
- energy(batch_positions)[source]
Compute a the potential energy of a batch of configurations.
- Parameters:
batch_positions (numpy.ndarray or pint.Quantity) – A batch of configurations in standard format (i.e., with shape
(batch_size, n_atoms, 3)or(n_atoms, 3)). If no units are attached to the array, it is assumed the positions are is inself.positions_unitunits (or Psi4 units ifpositions_unitis not provided).- Returns:
potential_energies –
potential_energies[i]is the potential energy of configurationbatch_positions[i].- Return type:
pint.Quantity
- property energy_unit: Quantity
The energy units of the returned potential.
- force(batch_positions)[source]
Compute the force for a batch of configurations.
- Parameters:
batch_positions (numpy.ndarray or pint.Quantity) – A batch of configurations in standard format (i.e., with shape
(batch_size, n_atoms, 3)or(n_atoms, 3)). If no units are attached to the array, it is assumed the positions are is inself.positions_unitunits (or Psi4 units ifpositions_unitis not provided).- Returns:
forces –
forces[i]is the force of configurationbatch_positions[i].- Return type:
pint.Quantity
- forward(batch_positions)[source]
Compute a differential potential energy for a batch of configurations.
- Parameters:
batch_positions (torch.Tensor) – A tensor of positions in flattened format (i.e., with shape
(batch_size, 3*n_atoms)) in units ofself.positions_unit(or Psi4 units ifpositions_unitis not provided).- Returns:
potential_energy –
potential_energy[i]is the potential energy of configurationbatch_positions[i]in units ofself.energy_unit.- Return type:
torch.Tensor
- property positions_unit: Quantity
The positions unit requested for the input.