MolecularDiffusion.modules.models.kgdiff.uni_transformer¶
KGDiff’s SE(3)-equivariant attention transformer (uni_o2).
Ported from KGDiff models/uni_transformer.py (commit ad893fc), which
is itself TargetDiff’s backbone. One block of num_layers alternating
x2h / h2x attention updates over a kNN graph rebuilt once per block.
The graph is geometric, not chemical: _connect_edge() is a plain
knn_graph(x, k=32) over the joint pocket+ligand point cloud, and the
edge_feat_dim: 4 channel is a one-hot of the four ligand/protein
incidence combinations (ll / lp / pl / pp), not a bond order. No bond
information reaches this network.
Only cutoff_mode='knn' is ported; the released config and the released
checkpoint both use it, and the hybrid branch pulled in a
batch_hybrid_edge_connection helper nothing else needs.
Module and parameter names are kept byte-for-byte compatible with the
released checkpoint (refine_net.base_block.<i>.x2h_layers.0.hk_func.net.*
and friends), so conversion is a pure prefix add.
Classes¶
One layer: |
|
Multi-head attention that emits an equivariant coordinate update. |
|
Multi-head attention that updates scalar node features from geometry. |
|
The |
Module Contents¶
- class MolecularDiffusion.modules.models.kgdiff.uni_transformer.AttentionLayerO2TwoUpdateNodeGeneral(hidden_dim: int, n_heads: int, num_r_gaussian: int, edge_feat_dim: int, act_fn: str = 'relu', norm: bool = True, num_x2h: int = 1, num_h2x: int = 1, r_min: float = 0.0, r_max: float = 10.0, num_node_types: int = 8, ew_net_type: str = 'r', x2h_out_fc: bool = True, sync_twoup: bool = False)¶
Bases:
torch.nn.ModuleOne layer:
num_x2hfeature updates thennum_h2xcoord updates.- forward(h, x, edge_attr, edge_index, mask_ligand, e_w=None, fix_x=False)¶
- act_fn = 'relu'¶
- distance_expansion¶
- edge_feat_dim¶
- ew_net_type = 'r'¶
- h2x_layers¶
- n_heads¶
- norm = True¶
- num_h2x = 1¶
- num_node_types = 8¶
- num_r_gaussian¶
- num_x2h = 1¶
- sync_twoup = False¶
- x2h_layers¶
- x2h_out_fc = True¶
- class MolecularDiffusion.modules.models.kgdiff.uni_transformer.BaseH2XAttLayer(input_dim: int, hidden_dim: int, output_dim: int, n_heads: int, edge_feat_dim: int, r_feat_dim: int, act_fn: str = 'relu', norm: bool = True, ew_net_type: str = 'r')¶
Bases:
torch.nn.ModuleMulti-head attention that emits an equivariant coordinate update.
- forward(h, rel_x, r_feat, edge_feat, edge_index, e_w=None)¶
- act_fn = 'relu'¶
- edge_feat_dim¶
- ew_net_type = 'r'¶
- input_dim¶
- n_heads¶
- output_dim¶
- r_feat_dim¶
- xk_func¶
- xq_func¶
- xv_func¶
- class MolecularDiffusion.modules.models.kgdiff.uni_transformer.BaseX2HAttLayer(input_dim: int, hidden_dim: int, output_dim: int, n_heads: int, edge_feat_dim: int, r_feat_dim: int, act_fn: str = 'relu', norm: bool = True, ew_net_type: str = 'r', out_fc: bool = True)¶
Bases:
torch.nn.ModuleMulti-head attention that updates scalar node features from geometry.
- forward(h, r_feat, edge_feat, edge_index, e_w=None)¶
- act_fn = 'relu'¶
- edge_feat_dim¶
- ew_net_type = 'r'¶
- hk_func¶
- hq_func¶
- hv_func¶
- input_dim¶
- n_heads¶
- out_fc = True¶
- output_dim¶
- r_feat_dim¶
- class MolecularDiffusion.modules.models.kgdiff.uni_transformer.UniTransformerO2TwoUpdateGeneral(num_blocks: int, num_layers: int, hidden_dim: int, n_heads: int = 1, k: int = 32, num_r_gaussian: int = 50, edge_feat_dim: int = 0, num_node_types: int = 8, act_fn: str = 'relu', norm: bool = True, cutoff_mode: str = 'knn', ew_net_type: str = 'r', num_init_x2h: int = 1, num_init_h2x: int = 0, num_x2h: int = 1, num_h2x: int = 1, r_max: float = 10.0, x2h_out_fc: bool = True, sync_twoup: bool = False)¶
Bases:
torch.nn.ModuleThe
uni_o2refine net:num_blocksxnum_layersattention.init_h_emb_layeris built (and therefore present in the released checkpoint) but never called –forward()only iteratesself.base_block. It is kept so the checkpoint’s key set matches exactly rather than needing a justified drop.- forward(h, x, mask_ligand, batch, return_all=False, fix_x=False)¶
- act_fn = 'relu'¶
- base_block¶
- cutoff_mode = 'knn'¶
- distance_expansion¶
- edge_feat_dim = 0¶
- ew_net_type = 'r'¶
- init_h_emb_layer¶
- k = 32¶
- n_heads = 1¶
- norm = True¶
- num_blocks¶
- num_h2x = 1¶
- num_init_h2x = 0¶
- num_init_x2h = 1¶
- num_layers¶
- num_node_types = 8¶
- num_r_gaussian = 50¶
- num_x2h = 1¶
- r_max = 10.0¶
- sync_twoup = False¶
- x2h_out_fc = True¶