Skip to content

Add heavy atom only option for symmetry corrected RMSD - #136

Open
hannahbaumann wants to merge 7 commits into
mainfrom
heavyatom-sym-rmsd
Open

hannahbaumann wants to merge 7 commits into
mainfrom
heavyatom-sym-rmsd

Conversation

@hannahbaumann

Copy link
Copy Markdown
Contributor

Related to OpenFreeEnergy/openfe#2290

A user had reported that the analysis in SepTop can sometimes hang for a long time.

We had discussed testing out a heavy atom only RMSD option, marking heavy atoms with hydrogens such that the symmetry correction is still applied correctly.

On sildenafil this substantially sped things up:

from time import perf_counter
from unittest.mock import patch

import MDAnalysis as mda
import numpy as np
from rdkit import Chem
from rdkit.Chem import AllChem
from spyrmsd import graph

from openfe_analysis.rmsd import SymmetryCorrectedLigandRMSD


# Sildenafil
smiles = (
    "CCCC1=NN(C2=C1N=C(NC2=O)"
    "C3=C(C=CC(=C3)S(=O)(=O)N4CCN(CC4)C)OCC)C"
)
mol = Chem.AddHs(Chem.MolFromSmiles(smiles))
assert AllChem.EmbedMolecule(mol, randomSeed=42) == 0
coords = mol.GetConformer().GetPositions()

# Generate a synthetic 10-frame trajectory
rng = np.random.default_rng(42)
frames = coords + rng.normal(scale=0.05, size=(10, *coords.shape))

u = mda.Universe.empty(mol.GetNumAtoms(), trajectory=True)
u.load_new(frames, order="fac")

original_match = graph.match_graphs


def timed_match(*args, **kwargs):
    start = perf_counter()
    mappings = original_match(*args, **kwargs)
    print(f"Graph matching: {perf_counter() - start:.6f} s")
    return mappings


for heavy in [False, True]:
    print(f"\nheavy_atoms_only={heavy}")
    u.trajectory[0]

    with patch.object(graph, "match_graphs", timed_match):
        start = perf_counter()
        result = SymmetryCorrectedLigandRMSD(
            u.atoms, rdmol=mol, heavy_atoms_only=heavy
        ).run()
        elapsed = perf_counter() - start

    print(f"Mappings: {len(result._isomorphisms):,}")
    print(f"Total time: {elapsed:.6f} s")

Results for 10 frames:

heavy_atoms_only=False
Graph matching: 3.428625 s
Mappings: 663,552
Total time: 39.792127 s

heavy_atoms_only=True
Graph matching: 0.000072 s
Mappings: 4
Total time: 0.068255 s

Since in practice we analyze ~500 frames for e.g. 19 lambda windows/26 lambda windows, this could indeed explain why the analysis may take hours for some molecules.

@hannahbaumann hannahbaumann changed the title Add heavy atom only option for symmetry corrected RMSD [WIP] Add heavy atom only option for symmetry corrected RMSD Nov 25, 2026
@codecov

codecov Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.42%. Comparing base (56d3ae0) to head (f6ce709).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #136      +/-   ##
==========================================
+ Coverage   98.38%   98.42%   +0.03%     
==========================================
  Files          10       10              
  Lines         496      507      +11     
==========================================
+ Hits          488      499      +11     
  Misses          8        8              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hannahbaumann hannahbaumann self-assigned this Nov 30, 2026
@hannahbaumann hannahbaumann changed the title [WIP] Add heavy atom only option for symmetry corrected RMSD Add heavy atom only option for symmetry corrected RMSD Nov 30, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant