tfep.nn.dynamics.egnn.EGNNDynamics

class tfep.nn.dynamics.egnn.EGNNDynamics(node_types, r_cutoff, time_feat_dim=16, node_feat_dim=64, distance_feat_dim=64, n_layers=4, speed_factor=1.0, initialize_identity=True)[source]

Bases: FixedGraph

E(n) equivariant graph neural network for continuous normalizing flows.

This implements a variation of the E(n) equivariant graph neural network used in [1] as the dynamics in a continuous normalizing flow. First, messages are passed only between nodes whose distance is smaller than a user-provided cutoff.

Second, the message for each edge is built as an input of the two node features (which is initialized as a function of the node types), their distance, and the integration time. Each of these inputs is first encoded into a vector of fixed dimension (see parameters node_feat_dim, distance_feat_dim, and time_feat_dim), and then concatenated. Specifically:

  • Node features are initialized with a random vector as a function of the node type similarly to SchNet [2].

  • Particle distances are projected onto a Gaussian basis with a cutoff switching function using Behler-Parrinello symmetry functions [3].

  • Time is also projected onto a Gaussian basis similarly to a Kernel flow [4]. For this the time of integration is assumed to have limits 0.0 and 1.0.

For distances and time, the bandwidth (i.e., standard deviation) of each Gaussian is optimized during training.

References

[1] Satorras VG, Hoogeboom E, Fuchs FB, Posner I, Welling M. E(n)

Equivariant Normalizing Flows for Molecule Generation in 3D. arXiv preprint arXiv:2105.09016. 2021 May 19.

[2] Schütt KT, Sauceda HE, Kindermans PJ, Tkatchenko A, Müller KR.

Schnet–a deep learning architecture for molecules and materials. The Journal of Chemical Physics. 2018 Jun 28;148(24):241722.

[3] Behler J, Parrinello M. Generalized neural-network representation of

high-dimensional potential-energy surfaces. Physical review letters. 2007 Apr 2;98(14):146401.

[4] Köhler J, Klein L, Noé F. Equivariant flows: exact likelihood generative

learning for symmetric densities. InInternational Conference on Machine Learning 2020 Nov 21 (pp. 5361-5370). PMLR.

__init__(node_types, r_cutoff, time_feat_dim=16, node_feat_dim=64, distance_feat_dim=64, n_layers=4, speed_factor=1.0, initialize_identity=True)[source]

Constructor.

Parameters:
  • node_types (Sequence[int]) – Shape (n_nodes,). node_types[i] is the ID of the node type for the i-th node. These are usually used to indicate an atom element. These are encoded using torch.nn.functional.one_hot so they should start from 0 and contain only consecutive numbers to limit the size of the encoding (i.e., 0 <= node_types[i] < n_node_types for all i).

  • r_cutoff (float) – The radial cutoff in the same units used for the coordinate positions in the forward pass.

  • time_feat_dim (int, optional) – The number of Gaussians used for expanding the time input, which is assumed to be in the interval [0, 1].

  • node_feat_dim (int, optional) – The dimension of the node feature.

  • distance_feat_dim (int, optional) – The number of Gaussians used for expanding the distance input.

  • n_layers (int, optional) – The number of message passing layers.

  • speed_factor (float, optional) – The output of the dynamics is such that each neighbor contributes to the node velocity with an additive vector with magnitude in [-speed_factor,speed_factor].

  • initialize_identity (bool, optional) – If True (default), the layers are initialized so that the dynamics performs the identity function, which in this context means that outputs zero velocities.

Methods

__init__(node_types, r_cutoff[, ...])

Constructor.

add_module(name, module)

Add a child module to the current module.

apply(fn)

Apply fn recursively to every submodule (as returned by .children()) as well as self.

bfloat16()

Casts all floating point parameters and buffers to bfloat16 datatype.

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 double datatype.

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 float datatype.

forward(t, x)

Output the velocity in the continuous normalizing flow.

get_buffer(target)

Return the buffer given by target if it exists, otherwise throw an error.

get_edges(batch_size)

Return the edges between nodes for the given batch size.

get_extra_state()

Return any extra state to include in the module's state_dict.

get_parameter(target)

Return the parameter given by target if it exists, otherwise throw an error.

get_submodule(target)

Return the submodule given by target if it exists, otherwise throw an error.

half()

Casts all floating point parameters and buffers to half datatype.

ipu([device])

Move all model parameters and buffers to the IPU.

load_state_dict(state_dict[, strict, assign])

Copy parameters and buffers from state_dict into 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 target if 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_destination

call_super_init

dump_patches

n_edges

Number of edges in the graph.

n_nodes

Number of nodes in the graph.

training

forward(t, x)[source]

Output the velocity in the continuous normalizing flow.

Parameters:
  • t (torch.Tensor) – A tensor of shape (1,) with the time of the integration.

  • x (torch.Tensor) – A tensor of shape (batch_size, n_nodes*3) where x[b, 3*a+i] is the i-th component of the position vector of the a-th node for batch b.

Returns:

v – A tensor of shape (batch_size, n_nodes*3) where v[b, 3*a+i] is the i-th component of the velocity vector of the a-th node for batch b.

Return type:

torch.Tensor

get_edges(batch_size)

Return the edges between nodes for the given batch size.

Parameters:

batch_size (int) – The size of the current batch.

Returns:

edges – Shape (2, batch_size*n_edges). The i-th edge is created from node edges[0][i] to edges[1][i], where edges[0][i] is a node index in the range [0, batch_size*n_nodes].

Edges are directional so if a message must be passed in both directions, two entries connecting the nodes with inverse order are present.

Return type:

torch.Tensor

property n_edges

Number of edges in the graph.

Type:

int

property n_nodes

Number of nodes in the graph.

Type:

int