neurosnap.chemistry.geometry module#

Geometry helpers for small molecules.

neurosnap.chemistry.geometry.align_molecule_to_reference(mol, ref_mol)[source]#

Aligns a molecule to a reference molecule and returns the aligned copy.

The alignment is performed using RDKit’s coordinate-based molecular alignment routine. The input molecule is copied before alignment, so the original object remains unchanged.

Parameters:
  • mol (Chem.Mol) – Molecule to align, with at least one conformer.

  • ref_mol (Chem.Mol) – Reference molecule defining the target orientation.

Returns:

A copy of mol aligned to ref_mol.

Return type:

Chem.Mol

Raises:

ValueError – If either molecule is None or lacks conformers.

neurosnap.chemistry.geometry.calculate_distance_matrix(mol)[source]#

Calculates the pairwise 3D distance matrix for a molecule.

Distances are computed from the atomic coordinates stored in the molecule’s active conformer. The returned matrix is square with one row and column per atom.

Parameters:

mol (Chem.Mol) – Input RDKit molecule with at least one conformer.

Returns:

A square NumPy array of shape (n_atoms, n_atoms)

containing pairwise Euclidean distances in Angstroms.

Return type:

np.ndarray

Raises:

ValueError – If the input molecule is None or has no conformers.

neurosnap.chemistry.geometry.calculate_rmsd(mol_a, mol_b)[source]#

Calculates the best-fit RMSD between two molecules.

This function uses RDKit’s alignment-based RMSD calculation, meaning the molecules are optimally superimposed before the RMSD value is reported. As a result, pure rigid-body translations and rotations do not by themselves increase the returned RMSD.

Parameters:
  • mol_a (Chem.Mol) – First RDKit molecule with at least one conformer.

  • mol_b (Chem.Mol) – Second RDKit molecule with at least one conformer.

Returns:

Best-fit root-mean-square deviation between the two molecules.

Return type:

float

Raises:

ValueError – If either molecule is None or lacks conformers.

neurosnap.chemistry.geometry.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.chemistry.geometry.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:

str

Raises:

ValueError – If the ligand cannot be parsed from the input SDF file.

neurosnap.chemistry.geometry.translate_molecule(mol, vector)[source]#

Translates all atomic coordinates in a molecule by a vector.

The input molecule is not modified in place. Instead, a copy is made and every atom position in the first conformer is shifted by the provided [x, y, z] vector.

Parameters:
  • mol (Chem.Mol) – Input RDKit molecule with at least one conformer.

  • vector – Translation vector of length 3 containing the x, y, and z shifts.

Returns:

A translated copy of the input molecule.

Return type:

Chem.Mol

Raises:

ValueError – If the molecule is None, has no conformers, or the translation vector is not length 3.