neurosnap.chemicals module#
Provides functions and classes related to processing chemical data.
- neurosnap.chemicals.get_mol_center(mol, use_mass=False)[source]#
Computes the geometric center or center of mass of a molecule.
- Parameters:
mol (Mol) – An RDKit molecule object with 3D coordinates.
use_mass (bool, optional) – If True, computes the center of mass using atomic masses. If False, computes the simple geometric center. Defaults to False.
- Returns:
- A NumPy array of shape (3,) representing the [x, y, z] center coordinates.
Returns None if the molecule has no conformers.
- Return type:
np.ndarray
- Raises:
ValueError – If no conformer is found in the molecule.
- neurosnap.chemicals.move_ligand_to_center(ligand_sdf_path, receptor_pdb_path, output_sdf_path, use_mass=False)[source]#
Moves the center of a ligand in an SDF file to match the center of a receptor in a PDB file.
This function reads a ligand from an SDF file and a receptor from a PDB file, calculates their respective centers (center of mass or geometric center), and translates the ligand such that its center aligns with the receptor’s center. The modified ligand is then saved to a new SDF file.
- Parameters:
ligand_sdf_path (str) – Path to the input ligand SDF file.
receptor_pdb_path (str) – Path to the input receptor PDB file.
output_sdf_path (str) – Path where the adjusted ligand SDF will be saved.
use_mass (bool, optional) – If True, compute center of mass; otherwise use geometric center. Defaults to False.
- Returns:
Path to the output SDF file with the translated ligand.
- Return type:
- Raises:
ValueError – If the ligand cannot be parsed from the input SDF file.
- neurosnap.chemicals.sdf_to_smiles(fpath)[source]#
Converts molecules in an SDF file to SMILES strings.
Reads an input SDF file and extracts SMILES strings from its molecules. Invalid or unreadable molecules are skipped, with warnings logged.
- Parameters:
fpath (str) – Path to the input SDF file.
- Returns:
A list of SMILES strings corresponding to valid molecules in the SDF file.
- Return type:
List[str]
- Raises:
FileNotFoundError – If the SDF file cannot be found.
IOError – If the file cannot be read.
- neurosnap.chemicals.smiles_to_sdf(smiles, output_path)[source]#
Converts a SMILES string to an sdf file. Will overwrite existing results.
NOTE: This function does the bare minimum in terms of generating the SDF molecule. The
neurosnap.conformersmodule should be used in most cases.