tfep.potentials.gromacs.GROMACSPotential
- class tfep.potentials.gromacs.GROMACSPotential(tpr_file_path: str, launcher: Launcher | None = None, positions_unit: Unit | None = None, energy_unit: Unit | None = None, precompute_gradient: bool = True, working_dir_path: str | List[str] | None = None, cleanup_working_dir: bool = False, parallelization_strategy: ParallelizationStrategy | None = None, launcher_kwargs: Dict[str, Any] | None = None, mdrun_kwargs: Dict[str, Any] | None = None, on_mdrun_error: Literal['raise', 'nan'] = 'raise')[source]
Bases:
PotentialBasePotential energy and forces with GROMACS.
This
Modulewraps :class:.GROMACSPotentialEnergyFuncto provide a differentiable potential energy function for training.- __init__(tpr_file_path: str, launcher: Launcher | None = None, positions_unit: Unit | None = None, energy_unit: Unit | None = None, precompute_gradient: bool = True, working_dir_path: str | List[str] | None = None, cleanup_working_dir: bool = False, parallelization_strategy: ParallelizationStrategy | None = None, launcher_kwargs: Dict[str, Any] | None = None, mdrun_kwargs: Dict[str, Any] | None = None, on_mdrun_error: Literal['raise', 'nan'] = 'raise')[source]
Constructor.
- Parameters:
tpr_file_path (str) – The path to the
.tprfile holding the information on topology and the simulation parameters. The coordinates in this file are not important as they will be overwritten by the positions passed in the forward pass.launcher (tfep.utils.cli.Launcher, optional) – The
Launcherto use to run themdruncommand used to compute energies and forces. If not passed, a newtfep.utils.cli.Launcheris created.positions_unit (pint.Unit, optional) – The unit of the positions passed. This is used to appropriately convert
batch_positionsto GROMACS’ units. IfNone, no conversion is performed, which assumes that the input positions are in nm.energy_unit (pint.Unit, optional) – The unit used for the returned energies (and as a consequence forces). This is used to appropriately convert GROMACS energies into the desired units. If
None, no conversion is performed, which means that energies and forces will be in kJ/mol and kJ/mol/nm respectively.precompute_gradient (bool, optional) – If
False, the forces are not read after executing GROMACS. This might save a small amount of time if backpropagation is not needed.working_dir_path (str or List[str], optional) – The working directory to be used to run the GROMACS’ commands. This must exist. If a list,
batch_positions[i]is evaluated in the directoryworking_dir_path[i].cleanup_working_dir (bool, optional) – If
Trueandworking_dir_pathis passed, all the files inside the working directory are removed after executing GROMACS. The directory(s) itself is not deleted.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.
launcher_kwargs (Dict, optional) – Other kwargs for
launcher(with the exception ofcwdwhich is automatically determined based onworking_dir_path).mdrun_kwargs (Dict, optional) – Other kwargs for
GmxMdrun.on_mdrun_error (Literal[‘raise’, ‘nan’], optional) – Whether to raise an exception or return NaN potential when the single- point energy calculation with mdrun fails. In the latter case, the returned forces are set to zero.
See also
GROMACSPotentialEnergyFuncMore details on input parameters and implementation details.
Methods
__init__(tpr_file_path[, launcher, ...])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.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.forward(batch_positions, batch_cell)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 = 'kJ/mol'
The default energy unit.
- DEFAULT_POSITIONS_UNIT: str = 'nanometer'
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.
- property energy_unit: Quantity
The energy units of the returned potential.
- forward(batch_positions: Tensor, batch_cell: Tensor) Tensor[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.batch_cell (torch.Tensor) – Shape
(batch_size, 6). Unitcell dimensions. For each data point, the first 3 elements represent the vector lengths in units ofself.positions_unitand the last 3 their respective angles (in degrees).
- Returns:
potential_energy –
potential_energy[i]is the potential energy of configurationbatch_positions[i]andbatch_cell[i]in units ofself.energy_unit(or GROMACS units ifenergy_unitis not provided).- Return type:
torch.Tensor
- property positions_unit: Quantity
The positions unit requested for the input.