MolecularDiffusion.modules.models.syncogen.utils.file_readers¶
File readers for molecular structure files with building block annotations.
Functions¶
|
Get list of available conformer keys for a molecule. |
|
Read molecular coordinates and optionally bonds from MOL2 data. |
|
Get MOL2 data from LMDB database. |
|
Read raw pharmacophore data from LMDB database. |
|
Parse MOL2 data to extract bond information. |
|
Parse MOL2 data into fragment-grouped coordinates, accounting for dropped atoms. |
|
Parse MOL2 data to extract coordinates, bonds, and building block annotations. |
|
Select a conformer key for a molecule. |
Module Contents¶
- MolecularDiffusion.modules.models.syncogen.utils.file_readers.get_conformer_keys(data_index: str | int, lmdb_path: pathlib.Path) List[str]¶
Get list of available conformer keys for a molecule.
- Parameters:
data_index – Base identifier for the molecule (e.g. “mol_0”)
lmdb_path – Path to LMDB database
- Returns:
List of valid conformer keys for this molecule
- Return type:
conformer_keys
- MolecularDiffusion.modules.models.syncogen.utils.file_readers.get_coordinates(key: str, lmdb_path: pathlib.Path, filetype: str = 'mol2', mask_value: float = 0.0, return_bonds: bool = False, atom_mask: torch.Tensor | None = None) Tuple[torch.Tensor, torch.Tensor, torch.Tensor | None]¶
Read molecular coordinates and optionally bonds from MOL2 data.
- Parameters:
key – Conformer key (e.g. “mol_0_final_conf_0”)
lmdb_path – Path to LMDB database
filetype – File format (‘mol2’)
mask_value – Value to use for masked atoms
return_bonds – If True, also return bond information
atom_mask – Optional tensor of shape [n_fragments, MAX_ATOMS] indicating valid positions. If provided, atoms are placed skipping over invalid positions.
- Returns:
torch.Tensor of shape [n_fragments, max_atoms_per_fragment, 3] coords_mask: torch.Tensor of shape [n_fragments, max_atoms_per_fragment] bonds: Optional torch.Tensor of shape [n_bonds, 3] (if return_bonds=True)
- Return type:
coords_tensor
- MolecularDiffusion.modules.models.syncogen.utils.file_readers.get_mol2_data(key: str, lmdb_path: pathlib.Path) bytes¶
Get MOL2 data from LMDB database.
- Parameters:
key – Key to look up in LMDB (e.g. “mol_0_final_conf_0”)
lmdb_path – Path to LMDB database
- Returns:
MOL2 file contents as bytes
- Return type:
mol2_data
- MolecularDiffusion.modules.models.syncogen.utils.file_readers.get_pharmacophores(key: str | int, lmdb_path: pathlib.Path) Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]¶
Read raw pharmacophore data from LMDB database.
- Parameters:
key – LMDB key to look up
lmdb_path – Path to LMDB database
- Returns:
Raw tensor of pharmacophore type indices positions: Raw tensor of 3D coordinates for each pharmacophore vectors: Raw tensor of pharmacophore vectors or None if not present
- Return type:
- MolecularDiffusion.modules.models.syncogen.utils.file_readers.mol2_to_bonds(mol2_data: bytes) torch.Tensor¶
Parse MOL2 data to extract bond information.
- Parameters:
mol2_data – MOL2 file contents
- Returns:
- torch.Tensor of shape [n_bonds, 3] containing (atom1, atom2, bond_type)
Bond types: 1=single, 2=double, 3=triple, 4=aromatic
- Return type:
- MolecularDiffusion.modules.models.syncogen.utils.file_readers.mol2_to_coordinates(mol2_data: bytes, mask_value: float = 0.0, return_bonds: bool = False, atom_mask: torch.Tensor | None = None) Tuple[torch.Tensor, torch.Tensor, torch.Tensor | None]¶
Parse MOL2 data into fragment-grouped coordinates, accounting for dropped atoms.
- Parameters:
mol2_data – MOL2 file contents with building block annotations
mask_value – Value to use for masked atoms
return_bonds – If True, also return bonds mapped to flattened padded indices
atom_mask – Optional tensor of shape [n_fragments, MAX_ATOMS] indicating valid atom positions. If provided, atoms are placed skipping over invalid positions (dropped atoms). If None, atoms are placed sequentially (old behavior, incorrect for reactions).
- Returns:
torch.Tensor of shape [n_fragments, MAX_ATOMS, 3] coords_mask: torch.Tensor of shape [n_fragments, MAX_ATOMS] bonds: Optional torch.Tensor of shape [n_bonds, 3] containing (flat_i, flat_j, bond_type)
- Return type:
coords_tensor
- MolecularDiffusion.modules.models.syncogen.utils.file_readers.parse_mol2_file(mol2_data: bytes) Tuple[numpy.ndarray, List[Tuple[int, int, str]], Dict[int, Tuple[str, int, int]]]¶
Parse MOL2 data to extract coordinates, bonds, and building block annotations.
- Parameters:
mol2_data – MOL2 file contents as bytes
- Returns:
numpy array of shape [n_atoms, 3] with atomic coordinates bonds: List of (atom1_idx, atom2_idx, bond_type) tuples (0-indexed) annotations: Dict mapping atom index to (element, bb_idx, order_idx)
- Return type:
- MolecularDiffusion.modules.models.syncogen.utils.file_readers.select_conformer_key(data_index: str | int, lmdb_path: pathlib.Path, random_conformer: bool = False) str¶
Select a conformer key for a molecule.
- Parameters:
data_index – Base identifier for the molecule (e.g. “mol_0”)
lmdb_path – Path to LMDB database
random_conformer – If True, randomly select a conformer, otherwise use conformer 0
- Returns:
Selected conformer key (e.g. “mol_0_final_conf_0”)
- Return type: