GetConformerRMSMatrix#
- nvmolkit.conformerRmsd.GetConformerRMSMatrix(
- mol: Mol,
- prealigned: bool = False,
- stream: Stream | None = None,
- *,
- output_format: str = 'condensed',
- alignment_mode: str = 'pairwise',
Compute the pairwise RMSD matrix between all conformers of a molecule on GPU.
For N conformers with M atoms, computes N*(N-1)/2 pairwise RMSD values using one GPU thread-block per pair. When
prealignedis False (default), the alignment behavior is selected byalignment_mode.The default
alignment_mode="pairwise"optimally superimposes every pair independently via the Kabsch algorithm. Its alignment semantics are similar to usingrdkit.Chem.rdMolAlign.GetAllConformerBestRMS()with an identity atom map andsymmetrizeConjugatedTerminalGroups=False:identity_map = [[(i, i) for i in range(mol.GetNumAtoms())]] rdMolAlign.GetAllConformerBestRMS( mol, map=identity_map, symmetrizeConjugatedTerminalGroups=False, )
alignment_mode="first-conformer"followsrdkit.Chem.AllChem.GetConformerRMSMatrix(): each conformer is aligned to conformer 0, then RMSDs are computed between those aligned coordinates. The input molecule is not modified in either mode.Differences from RDKit:
Zero-atom molecules always raise
ValueErrorregardless of conformer count. RDKit returns[nan]for exactly 2 zero-atom conformers and raisesZeroDivisionErrorfor 3 or more.Results are returned as an
AsyncGpuResult(device tensor) rather than a Python list, to keep the conformer-selection pipeline on the GPU.
By default, the result matches RDKit’s condensed lower-triangle shape. Use
output_format="square"when a downstream API expects anN x Ndistance matrix, such asnvmolkit.clustering.butina().- Parameters:
mol – RDKit molecule with two or more conformers. Strip hydrogens first (
Chem.RemoveHs) if you want heavy-atom RMSD, as this function operates on all atoms present in the molecule.prealigned – If True, skip Kabsch alignment and compute RMSD on raw coordinates. If False (default), use
alignment_mode.stream – CUDA stream to use. If None, uses the current stream.
output_format –
"condensed"returns anAsyncGpuResultwrapping a 1-D RDKit-style lower-triangle vector."square"returns a symmetrictorch.Tensorof shape(N, N)on the GPU with zeros on the diagonal.alignment_mode –
"pairwise"(default) optimally aligns each conformer pair independently."first-conformer"aligns every conformer to conformer 0 before computing pairwise RMSDs. Ignored whenprealigned=True.
- Returns:
With
output_format="condensed", anAsyncGpuResultwrapping a 1-D tensor of shape(N*(N-1)/2,)containing RMSD values in lower-triangle condensed order. The RMSD for conformer pair (i, j) with i > j is at indexi*(i-1)//2 + j.With
output_format="square", a symmetric CUDAtorch.Tensorof shape(N, N).- Raises:
ValueError – If
molis None, has conformers but no atoms, or an unsupportedalignment_modeis requested.TypeError – If
streamis not atorch.cuda.Streamor None.
Example
>>> from rdkit import Chem >>> from rdkit.Chem import AllChem, rdDistGeom >>> from nvmolkit.conformerRmsd import GetConformerRMSMatrix >>> from nvmolkit.clustering import butina >>> >>> mol = Chem.AddHs(Chem.MolFromSmiles('CCCCCC')) >>> rdDistGeom.EmbedMultipleConfs(mol, numConfs=50) >>> no_h = Chem.RemoveHs(mol) >>> >>> # Independently align each conformer pair >>> rmsd_matrix = GetConformerRMSMatrix(no_h) >>> # Match AllChem.GetConformerRMSMatrix alignment semantics >>> rdkit_style = GetConformerRMSMatrix(no_h, alignment_mode="first-conformer") >>> >>> # Request square output for GPU Butina clustering >>> square = GetConformerRMSMatrix(no_h, output_format="square") >>> clusters = butina(square, cutoff=0.5)