Skip to content

Isomorphism comparisons are slow on similar large molecules #2072

Open
@galioguo

Description

@galioguo

Description and Output

I have two quite large (291 atoms each) stereoisomers that differ at precisely one chiral site. I'll call them offmol1 and offmol2. I want to feed them into an Interchange using from_smirnoff. I precomputed their partial charges, and fed this in through the 'charge_from_molecules' field.

import logging
import openff.toolkit as tk

logging.basicConfig(level=logging.DEBUG)
topology = tk.Topology.from_molecules([offmol1, offmol2])
sage = tk.ForceField('openff_unconstrained-2.2.1.offxml')
interchange = Interchange.from_smirnoff(
    force_field = sage, 
    topology = topology, 
    charge_from_molecules = [offmol1, offmol2], 
    allow_nonintegral_charges = True
)

This code hangs indefinitely. Upon checking debug logs, this originates from the isomorphism checks under _assign_charges_from_molecules inside interchange.smirnoff._nonbonded.py

def _assign_charges_from_molecules(
    cls,
    topology: Topology,
    unique_molecule: Molecule,
    charge_from_molecules=Optional[list[Molecule]],
) -> tuple[bool, dict, dict]:
    if charge_from_molecules is None:
        return False, dict(), dict()

    for molecule_with_charges in charge_from_molecules:
        if molecule_with_charges.is_isomorphic_with(unique_molecule):
            break
    else:
        return False, dict(), dict()

    _, atom_map = Molecule.are_isomorphic(
        molecule_with_charges,
        unique_molecule,
        return_atom_map=True,
    )

Although partial charges are in general dependent on stereochemistry, it would be helpful to add an option to ignore stereochemistry when specifying charges from molecules.

Metadata

Metadata

Assignees

No one assigned

    Labels

    polymer-performanceRuntime of loading and/or parametrizing (bio)polymers

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions