MolecularDiffusion.modules.models.difflinker.size_gnn¶
Size GNN: an auxiliary, fragment-geometry-conditioned linker-size
classifier, ported from DiffLinker’s src/linker_size.py
(SizeGNN) and src/linker_size_lightning.py (SizeClassifier’s
inference path only – training machinery is out of scope).
See docs/model_integrations/difflinker/INTEGRATION_PLAN.md’s “Revision 8 –
Size GNN” section for the full design (why this is a small helper class, not
a new Task; the exact upstream inference contract this ports; the
documented per-retry-resampling simplification). Used only as an optional,
additive size predictor plugged into
MolecularDiffusion.modules.tasks.diffusion_difflinker.DiffLinkerTask.sample()
– unrelated to, and architecturally distinct from, linker_size.py’s
DistributionNodes (unconditional histogram sampling).
Classes¶
Thin inference-only wrapper matching |
|
Ported near-verbatim from |
Module Contents¶
- class MolecularDiffusion.modules.models.difflinker.size_gnn.LinkerSizePredictor(in_node_nf: int, hidden_nf: int, out_node_nf: int, n_layers: int, normalization: str | None, linker_id2size: list)¶
Bases:
torch.nn.ModuleThin inference-only wrapper matching
SizeClassifier’s own state-dict key layout exactly (self.gnn = SizeGNN(...)– every checkpoint key is prefixedgnn., confirmed in INTEGRATION_PLAN.md Revision 8’s Phase A6). Never routed throughcli/generate.py’sTask-loading machinery – this is not aTask, so its own converted-checkpoint format is a plain, self-describing{"state_dict", "hyper_parameters"}dict.- classmethod from_checkpoint(path: str, map_location='cpu') LinkerSizePredictor¶
- predict(one_hot: torch.Tensor, positions: torch.Tensor, fragment_mask: torch.Tensor | None = None) torch.Tensor¶
Reproduces
SizeClassifier.forward(..., return_loss=False)(linker_size_lightning.py:83-109) +generate.py’s softmax/Categorical/id-to-size sampling (generate.py:90-99) in one pass.one_hot/positionsare the fragment-only tensors ((B, N, n_vocab)/(B, N, 3)); with nofragment_masksupplied, every atom inNis treated as a real fragment atom (the reference structure is the fragment, by construction – matchesDiffLinkerTask.sample()’s ownref_onehot/ref_positions). Returns a(B,)torch.LongTensorof predicted linker-only atom counts.
- gnn¶
- linker_id2size¶
- class MolecularDiffusion.modules.models.difflinker.size_gnn.SizeGNN(in_node_nf: int, hidden_nf: int, out_node_nf: int, n_layers: int, normalization: str | None = None)¶
Bases:
torch.nn.ModulePorted near-verbatim from
others/difflinker/src/linker_size.py:45-91.A plain stack of message-passing
GCLlayers (imported from the already-portedegnn.py, not reimplemented) producing a per-node hidden vector – no coordinate output, no coordinate-update layer anywhere (unlikeDynamics/EGNN).- forward(h, edges, distances, node_mask, edge_mask)¶
- embedding_in¶
- embedding_out¶
- gcl1¶
- gcl_layers¶
- out_node_nf¶