MolecularDiffusion.modules.models.ditmc.graph_features¶
Per-molecule featurization: node_attr, shortest hops, Laplacian eigen.
Port of the parts of dit_mc/prepare_dataset.py that produce what the model
consumes. Upstream computes these once at dataset-build time and caches by
SMILES; so does this module, with an in-process LRU rather than a pickle.
The three quantities:
node_attrThe 64-d (QM9) / 94-d (Drugs) RDKit atom featurization, reproduced column for column from
get_node_attr_from_mol– seeNODE_ATTR_BLOCKSfor the exact layout.one_hot_encodingalways appends a trailing “misc” slot except for the atom-symbol block, which upstream slices with[:-1].shortest_hopsFloyd-Warshall over the bond adjacency, off-diagonal entries in C-order over
(i, j)– the same order the all-pairs edge list is built in, which is the only reason the two line up element for element. Unreachable pairs get the sentinel 510 (algos.pyx:28-34), hence the 512-row embedding.D, PEigendecomposition of the bond-graph Laplacian
L = D - A, withD = 1/sqrt(lambda)and the zero modes set to 0 – which is what removes the centre of mass from the harmonic prior. The number of zero modes is the number of RDKit fragments.
Attributes¶
Classes¶
SMILES-keyed cache of the three per-molecule quantities. |
Functions¶
|
Symmetric 0/1 adjacency from an upper-triangular bond index. |
|
All ordered pairs excluding self-loops, C-order over ``(i, j)``. |
|
Reproduce |
|
|
|
Width of |
|
Off-diagonal Floyd-Warshall distances, C-order over |
Module Contents¶
- class MolecularDiffusion.modules.models.ditmc.graph_features.MoleculeFeatureCache(dataset: str = 'qm9', maxsize: int = 200000)¶
SMILES-keyed cache of the three per-molecule quantities.
Upstream caches by SMILES at dataset-build time. Here the cache is in-process and bounded; a miss just recomputes.
- dataset = 'qm9'¶
- MolecularDiffusion.modules.models.ditmc.graph_features.adjacency_from_bonds(bond_index: numpy.ndarray, n_nodes: int) numpy.ndarray¶
Symmetric 0/1 adjacency from an upper-triangular bond index.
- MolecularDiffusion.modules.models.ditmc.graph_features.all_pairs_edges(n_nodes: int, device=None)¶
All ordered pairs excluding self-loops, C-order over ``(i, j)``.
Returns
(receivers, senders) = (i, j). Matching this ordering toshortest_hopsis not optional – upstream relies on both being C-order.
- MolecularDiffusion.modules.models.ditmc.graph_features.get_node_attr_from_mol(mol, dataset: str) numpy.ndarray¶
Reproduce
prepare_dataset.get_node_attr_from_molexactly.
- MolecularDiffusion.modules.models.ditmc.graph_features.laplacian_eigen(adj: numpy.ndarray, num_components: int | None = None, threshold: float = 0.0001)¶
(D, P)for the harmonic prior:D = 1/sqrt(lambda), zero modes 0.eighreturns ascending eigenvalues, so thenum_componentssmallest are the zero modes (one per connected fragment). Eigenvector sign ambiguity is not a fidelity risk: the prior drawsP diag(D) zwithzstandard normal, whose distribution is invariant under column sign flips.
- MolecularDiffusion.modules.models.ditmc.graph_features.node_attr_dim(dataset: str) int¶
Width of
node_attrfor a dataset name.
- MolecularDiffusion.modules.models.ditmc.graph_features.shortest_hops_from_adjacency(adj: numpy.ndarray) numpy.ndarray¶
Off-diagonal Floyd-Warshall distances, C-order over
(i, j).scipy.sparse.csgraph.floyd_warshallreplaces the Cythonalgos.pyx;infis clamped to the same 510 sentinel upstream writes.
- MolecularDiffusion.modules.models.ditmc.graph_features.ATOMIC_TYPES¶
- MolecularDiffusion.modules.models.ditmc.graph_features.NODE_ATTR_BLOCKS = (('chiral_tag', 5), ('total_num_h', 6), ('num_radical_electrons', 6), ('atom_symbol', None),...¶
- MolecularDiffusion.modules.models.ditmc.graph_features.UNREACHABLE_HOPS = 510¶