MolecularDiffusion.modules.models.syncogen.utils.rdkit¶
RDKit utility functions for molecule building and validation.
Functions¶
|
Build a molecule from model outputs. Used in calculating pvalid. |
Build RDKit molecules from graphs with optional coordinates. |
|
|
Calculate MMFF94 or UFF energy for an RDKit molecule. Prefer MMFF if available, otherwise UFF. Return None if calculation fails. |
|
Get Lipinski descriptors for a molecule or batch of molecules (Rule of 5). |
|
Check if an action is valid for the current molecule fragment graph. |
|
Check if a SMILES string is valid and can be fully sanitized. |
|
Extract pharmacophore conditioning from a reference molecule. |
|
Save molecule to SDF file with optional properties. |
|
Load coordinates from SDF file. |
|
Set 3D coordinates on an RDKit molecule. |
Module Contents¶
- MolecularDiffusion.modules.models.syncogen.utils.rdkit.build_molecule(nodes: torch.Tensor, decoded_edges: torch.Tensor, smiles: bool = False) str¶
Build a molecule from model outputs. Used in calculating pvalid.
- Parameters:
nodes – Tensor of node indices [n_nodes]
decoded_edges – Tensor of decoded model outputs [n_edges, 5] containing (reaction_id, node1_order, node2_order, center1_idx, center2_idx). These are not the same as actions for adding to MFG and must be converted.
smiles – Whether to return a SMILES string or an RDKit molecule
- Returns:
SMILES string of the molecule
- MolecularDiffusion.modules.models.syncogen.utils.rdkit.build_molecules_from_graphs(graphs: MolecularDiffusion.modules.models.syncogen.api.graph.graph.BBRxnGraph, coords: torch.Tensor | None = None) List[rdkit.Chem.Mol | None]¶
Build RDKit molecules from graphs with optional coordinates.
- Parameters:
graphs – BBRxnGraph object (batched or unbatched)
coords – Optional [B, N, 3] coordinate tensor
- Returns:
List of RDKit molecules (None for failed reconstructions). Each successful mol has coordinates set if coords was provided.
- MolecularDiffusion.modules.models.syncogen.utils.rdkit.calc_energy(mol: rdkit.Chem.Mol, per_atom: bool = False) float | None¶
Calculate MMFF94 or UFF energy for an RDKit molecule. Prefer MMFF if available, otherwise UFF. Return None if calculation fails.
- MolecularDiffusion.modules.models.syncogen.utils.rdkit.get_lipinski_descriptors(mols) list¶
Get Lipinski descriptors for a molecule or batch of molecules (Rule of 5).
- Parameters:
mols – RDKit molecule or list of RDKit molecules
- Returns:
List of dicts with Lipinski Rule of 5 descriptors (MW, LogP, HBD, HBA)
- Return type:
- MolecularDiffusion.modules.models.syncogen.utils.rdkit.is_valid_action(mfg: MolecularDiffusion.modules.models.syncogen.api.rdkit.assembly.RDKitMoleculeAssembly, action: list) bool¶
Check if an action is valid for the current molecule fragment graph.
- Parameters:
mfg – Current molecule fragment graph
action – List of [new_fragment_global_id, reaction_id, existing_frag_idx, center1_idx, center2_idx]
- Returns:
Whether the action is valid
- Return type:
- MolecularDiffusion.modules.models.syncogen.utils.rdkit.is_valid_smiles(smiles_or_mol)¶
Check if a SMILES string is valid and can be fully sanitized.
- MolecularDiffusion.modules.models.syncogen.utils.rdkit.mol_to_pharm_cond(mol: rdkit.Chem.Mol, batch_size: int, n_subset: int, center: bool = True, normalize: bool = True) Tuple[torch.Tensor, torch.Tensor, torch.Tensor]¶
Extract pharmacophore conditioning from a reference molecule.
- Parameters:
mol – RDKit molecule with conformer
batch_size – Number of copies to create (for batched conditioning)
n_subset – Max pharmacophores per sample (randomly subsampled per batch element)
center – Center molecule coordinates before extraction
normalize – Normalize positions by COORDS_STD
- Returns:
[batch_size, n_subset, n_pharm_types] one-hot pharmacophore types pos: [batch_size, n_subset, 3] pharmacophore positions mask: [batch_size, n_subset] padding mask
- Return type:
- MolecularDiffusion.modules.models.syncogen.utils.rdkit.save_as_sdf(mol: rdkit.Chem.Mol, filepath: str, properties: dict | None = None)¶
Save molecule to SDF file with optional properties.
- Parameters:
mol – RDKit molecule with conformer
filepath – Output file path
properties – Optional dict of properties to add as SDF data fields
- MolecularDiffusion.modules.models.syncogen.utils.rdkit.sdf_to_coordinates(sdf_path: str) torch.Tensor¶
Load coordinates from SDF file.
- Parameters:
sdf_path – Path to SDF file
- Returns:
Tensor of shape [n_atoms, 3]
- MolecularDiffusion.modules.models.syncogen.utils.rdkit.set_mol_coordinates(mol: rdkit.Chem.Mol, coords: torch.Tensor) rdkit.Chem.Mol¶
Set 3D coordinates on an RDKit molecule.
- Parameters:
mol – RDKit molecule (will be modified in place)
coords – [n_atoms, 3] coordinate tensor
- Returns:
Molecule with updated conformer