diffalign.models package

Subpackages

Submodules

diffalign.models.common module

class diffalign.models.common.MultiLayerPerceptron(input_dim, hidden_dims, activation='relu', dropout=0)[source]

Bases: Module

Multi-layer Perceptron. Note there is no activation or dropout in the last layer. :param input_dim: input dimension :type input_dim: int :param hidden_dim: hidden dimensions :type hidden_dim: list of int :param activation: activation function :type activation: str or function, optional :param dropout: dropout rate :type dropout: float, optional

forward(input)[source]
diffalign.models.common.extend_graph_order_radius(num_nodes, pos, edge_index, edge_type, batch, order=3, cutoff=10.0, extend_order=True, extend_radius=True)[source]
diffalign.models.common.extend_to_cross_attention(pos, cutoff, batch, graph_idx)[source]

Module contents

Public model API for DiffAlign.

class diffalign.models.CrossAttention(dim: int, heads: int = 4, dropout: float = 0.0, coord_update: bool = True)[source]

Bases: Module

Q <- R masked dense cross-attention with optional coordinate updates.

forward(h_q, x_q, h_r, x_r, q2r_edge_index=None, k_train: int | None = None)[source]

Legacy-compatible interface (kept for callers in DiffAlign).

forward_dense(h_q: Tensor, x_q: Tensor, h_r: Tensor, x_r: Tensor, mask_q: Tensor, mask_r: Tensor, *, pre_k: Tensor | None = None, pre_v: Tensor | None = None, pre_rh: Tensor | None = None, coord_chunk_M: int = 256) tuple[Tensor, Tensor][source]

h_q: [B,N,D], x_q: [B,N,3], mask_q: [B,N] (True=valid) h_r: [B,M,D], x_r: [B,M,3], mask_r: [B,M]

preproject_R(h_r: Tensor) tuple[Tensor, Tensor, Tensor][source]

h_r: [B,M,D] -> (rh [B,M,D], k_r [B,H,M,Dh], v_r [B,H,M,Dh])

class diffalign.models.CrossGraphAligner(dim: int, heads: int = 4, dropout: float = 0.0, coord_update: bool = True, num_layers: int = 6, recompute_each: int = 1, coord_chunk_M: int = 256)[source]

Bases: Module

Masked dense cross-attention aligner (drop-in).

forward(h, x, batch, graph_idx)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

static knn_q2r_edges(*args, **kwargs)[source]
class diffalign.models.DiffAlign(node_feature_dim: int = 64, time_embed_dim: int = 32, query_embed_dim: int = 32, edge_encoder_dim: int = 64, gnn_hidden_dim: int = 128, gnn_layers_intra: int = 12, gnn_layers_intra_2: int = 4, gnn_layers_inter: int = 8, max_atom_types: int = 100, num_timesteps: int = 32, beta_start: float = 0.0001, beta_end: float = 0.02, schedule_type: str = 'cosine', repulsion_weight: float = 0.01, repulsion_margin: float = 1.2, repulsion_exclude_hops: int = 3)[source]

Bases: Module

Isotropic Gaussian Diffusion (v-parameterization; T steps) - Backbone: EGNN + CrossGraphAligner (only query coordinates move) - Output: v_t in merged (Q,R) order - Loss: v MSE + x0 anchor + optional repulsion

DDPM_Sampling_UFF(query_batch: Batch, reference_batch: Batch, *, clamp: float = 1e-10, cfg_scale: float = 1.0, query_mols=None, pocket_mols=None, uff_guidance_scale: float = 0.0, uff_inner_steps: int = 8, uff_clamp: float = 1.0, uff_start_ratio: float = 0.0, snr_gate_gamma: float = 1.0, noise_temperature: float = 0.3, uff_vdw_multiplier: float = 10.0, debug_log: bool = False)[source]

Standard DDPM (v-param) + UFFTorch-based UFF steering on x0. Note: _refresh_nonbond_candidates is called with ligand+pocket coords merged.

forward(query_batch: Batch, reference_batch: Batch, t: Tensor, condition: bool = True) Tensor[source]
Predict v_t for merged (query, reference) batches.
  • query_batch, reference_batch: torch_geometric.data.Batch

  • t: [G] timesteps (0..T-1) per graph

class diffalign.models.EGNN(in_node_nf: int, in_edge_nf: int, hidden_nf: int, device: str = 'cpu', act_fn=SiLU(), n_layers: int = 4, attention: bool = False, norm_diff: bool = True, out_node_nf: int | None = None, tanh: bool = False, coords_range: float = 15.0, agg: str = 'sum', norm_constant: float = 0.0)[source]

Bases: Module

forward(h: Tensor, x: Tensor, edges: Tensor, edge_attr: Tensor | None = None, node_mask: Tensor | None = None, edge_mask: Tensor | None = None, coord_mask: Tensor | None = None, node_attr: Tensor | None = None)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class diffalign.models.E_GCL(input_nf: int, output_nf: int, hidden_nf: int, edges_in_d: int = 0, nodes_att_dim: int = 0, act_fn=SiLU(), attention: bool = False, norm_diff: bool = True, tanh: bool = False, coords_range: float = 1.0, norm_constant: float = 0.0)[source]

Bases: Module

coord2radial(edge_index: Tensor, coord: Tensor)[source]
coord_model(coord, edge_index, coord_diff, edge_feat, edge_mask, coord_mask)[source]
edge_model(source, target, radial, edge_attr, edge_mask)[source]
forward(h: Tensor, edge_index: Tensor, coord: Tensor, edge_attr: Tensor | None = None, node_attr: Tensor | None = None, node_mask: Tensor | None = None, edge_mask: Tensor | None = None, coord_mask: Tensor | None = None)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

node_model(x, edge_index, edge_feat, node_attr)[source]
class diffalign.models.MLPEdgeEncoder(hidden_dim=100, activation='relu')[source]

Bases: Module

forward(edge_length, edge_type)[source]
Input:

edge_length: The length of edges, shape=(E, 1). edge_type: The type pf edges, shape=(E,)

Returns:

The representation of edges. (E, self.hidden_dim)

Return type:

edge_attr

property out_channels
class diffalign.models.MultiLayerPerceptron(input_dim, hidden_dims, activation='relu', dropout=0)[source]

Bases: Module

Multi-layer Perceptron. Note there is no activation or dropout in the last layer. :param input_dim: input dimension :type input_dim: int :param hidden_dim: hidden dimensions :type hidden_dim: list of int :param activation: activation function :type activation: str or function, optional :param dropout: dropout rate :type dropout: float, optional

forward(input)[source]
diffalign.models.extend_graph_order_radius(num_nodes, pos, edge_index, edge_type, batch, order=3, cutoff=10.0, extend_order=True, extend_radius=True)[source]