tfep.nn.flows.centroid.CenteredCentroidFlow
- class tfep.nn.flows.centroid.CenteredCentroidFlow(flow: Module, space_dimension: int, subset_point_indices: Sequence[int] | None = None, weights: Sequence[float] | None = None, fixed_point_idx: int = 0, origin: Sequence[float] | None = None, translate_back: bool = True, return_partial: bool = False)[source]
Bases:
PartialFlowA transformation constraining the (weighted) centroid of the DOFs.
This flow performs the following operations: - It computes the (optionally weighted) centroid of the input features (or
a subset of them).
Translates the system to move the centroid to the origin or a user-defined point.
Removes N degrees of freedom (DOFs) from the input features (where N is the dimensionality of a point in space) and runs the remaining features through the wrapped flow.
Re-adds the N constrained DOFs so that the flow preserves the centroid.
Optionally, translates the system to restore the original coordinates of the centroid.
The flow assumes that the input features have shape
(batch_size, n_dofs), and each batch sample represent a sequence of points in an N-dimensional space. The points must must be listed so thatinput[b][N*i:N*i+N]are the coordinates of thei-th point for batch sampleb.- Parameters:
flow (torch.nn.Module) – The wrapped flow.
space_dimension (int) – The dimensionality of a single point in space (e.g.,
3if the input features represent points in a 3D space).subset_point_indices (array-like of int, optional) – A vector of shape
(n_points,). If passed, the centroid is computed over a subset ofn_pointspoints. If not passed, the centroid is computed using all the input features.Note that the indices must refer to the points, not the feature indices. For example, in a 3D space,
subset_point_indices = [1, 3]will compute the centroid using the feature indices[3, 4, 5, 9, 10, 11].weights (array-like of floats, optional) – A vector of shape
(n_points,), wheren_pointsis the number of points used to compute the centroid (which depends onsubset_point_indices).weights[i]is the (unnormalized) weight used for thei-th point. If not passed, the center of geometry is computed. This can be used for example to center the system on the center of mass.fixed_point_idx (int, optional) – The index of the point that is fixed and does not go through the flow. Note that this refers to the index of the point, not the input feature. Also, if
subset_point_indicesis passed, this index is relative to the subset of atoms used to compute the centroid.For example, if
fixed_point_idxis 1 andsubset_point_indicesisNone, the fixed DOFs will be[3, 4, 5]in a 3D space. However, ifsubset_point_indices = [1, 2]then the fixed DOFs will be[6, 7, 8].origin (array-like of floats, optional) – A vector of shape
(space_dimension,). If the centroid must be moved to a point different than zero.translate_back (bool, optional) – If
False, the output configuration has the centroid in theorigin. Otherwise, it the centroid is restored to the original position.return_partial (bool, optional) – If
True, only the propagated indices are returned.
- Variables:
flow (torch.nn.Module) – The wrapped flow.
origin (Tensor of floats) – The position of the origin where the centroid is translated before going through the flow.
translate_back (bool) – Whether the centroid is restored to its original position in the output configuration or if it is left at the
origin.return_partial (bool) – If
True, only the propagated indices are returned.
- __init__(flow: Module, space_dimension: int, subset_point_indices: Sequence[int] | None = None, weights: Sequence[float] | None = None, fixed_point_idx: int = 0, origin: Sequence[float] | None = None, translate_back: bool = True, return_partial: bool = False)[source]
Initialize internal Module state, shared by both nn.Module and ScriptModule.
Methods
__init__(flow, space_dimension[, ...])Initialize internal Module state, shared by both nn.Module and ScriptModule.
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.
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(x)Transform the input configuration.
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.inverse(y)Invert the forward transformation.
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.
int: The total number of parameters that can be optimized.
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
T_destinationcall_super_initdump_patchesThe dimensionality of a single point in space.
Wrapped flow.
If
True, only the propagated indices are returned.training- flow
Wrapped flow.
- inverse(y: Tensor) Tuple[Tensor][source]
Invert the forward transformation.
This works only if the forward transformation was performed with
translate_backset toTrue.
- n_parameters()
int: The total number of parameters that can be optimized.
- return_partial
If
True, only the propagated indices are returned.
- property space_dimension
The dimensionality of a single point in space.
For example,
3if the input features represent points in a 3D space.- Type:
int