MolecularDiffusion.modules.models.kgdiff.common¶
Shared building blocks for the KGDiff backbone.
Ported from KGDiff’s models/common.py (commit ad893fc). Only the
pieces uni_transformer.py / score_model.py actually reach are kept:
the custom-offset GaussianSmearing, the MLP used inside
every attention head, outer_product(), compose_context(), and
ShiftedSoftplus.
Dropped on purpose (dead for this integration, verified by call site):
AngleExpansion/Swish/get_h_dist/get_r_feat are referenced
nowhere in the ported path, and hybrid_edge_connection /
batch_hybrid_edge_connection only serve cutoff_mode='hybrid', which
neither the released config nor the released checkpoint uses (both are
cutoff_mode: knn).
Attributes¶
Classes¶
Distance expansion on a hand-picked, non-uniform offset grid. |
|
MLP with the same hidden dim across all layers. |
|
|
Functions¶
|
Interleave pocket and ligand tokens into one graph-ordered node set. |
|
Flattened outer product, folded left to right. |
Module Contents¶
- class MolecularDiffusion.modules.models.kgdiff.common.GaussianSmearing(start: float = 0.0, stop: float = 5.0, num_gaussians: int = 50)¶
Bases:
torch.nn.ModuleDistance expansion on a hand-picked, non-uniform offset grid.
start/stopare recorded for__repr__only – upstream overrides the linspace with a fixed 20-point table biased towards bond distances, andcoeffis derived from the first gap (1.0 A), so the kernel width is constant even though the grid is not.- forward(dist: torch.Tensor) torch.Tensor¶
- coeff¶
- num_gaussians = 50¶
- start = 0.0¶
- stop = 5.0¶
- class MolecularDiffusion.modules.models.kgdiff.common.MLP(in_dim: int, out_dim: int, hidden_dim: int, num_layer: int = 2, norm: bool = True, act_fn: str = 'relu', act_last: bool = False)¶
Bases:
torch.nn.ModuleMLP with the same hidden dim across all layers.
The
netattribute name and the exactnn.Sequentialordering (Linear, LayerNorm, activation) are load-bearing: the released checkpoint’s keys are*.net.0/1/3.*.- forward(x: torch.Tensor) torch.Tensor¶
- net¶
- class MolecularDiffusion.modules.models.kgdiff.common.ShiftedSoftplus¶
Bases:
torch.nn.Modulesoftplus(x) - log(2), sof(0) == 0.- forward(x: torch.Tensor) torch.Tensor¶
- shift¶
- MolecularDiffusion.modules.models.kgdiff.common.compose_context(h_protein: torch.Tensor, h_ligand: torch.Tensor, pos_protein: torch.Tensor, pos_ligand: torch.Tensor, batch_protein: torch.Tensor, batch_ligand: torch.Tensor)¶
Interleave pocket and ligand tokens into one graph-ordered node set.
The sort is stable, so ligand atoms keep their relative order within each complex – upstream’s comment records that an unstable sort broke fixed-atom-type runs.
- Returns:
(h_ctx, pos_ctx, batch_ctx, mask_ligand)wheremask_ligandisTrueon ligand rows.
- MolecularDiffusion.modules.models.kgdiff.common.outer_product(*vectors: torch.Tensor) torch.Tensor¶
Flattened outer product, folded left to right.
- MolecularDiffusion.modules.models.kgdiff.common.NONLINEARITIES¶