openff-interchange
openff-interchange copied to clipboard
`charge_from_molecules` silently ignores isomorphic molecules in list, only using the first entry
Description
Passing two isomorphic Molecules with different partial charges to from_smirnoff's charge_from_molecules flag will lead to partial charges only being assigned from the first Molecule.
Reproduction
from openff.toolkit import Molecule, Topology, ForceField
from openff.interchange.components._packmol import solvate_topology_nonwater
from openff.interchange import Interchange
import pytest
solvent = Molecule.from_smiles('c1ccccc1')
solvent.assign_partial_charges(partial_charge_method='gasteiger')
print("solvent charges: ", solvent.partial_charges)
ligand = Molecule.from_smiles('c1ccccc1')
ligand.generate_conformers()
ligand.assign_partial_charges(partial_charge_method='am1bcc')
print("ligand charges: ", ligand.partial_charges)
print("molecules are isomorphic: ", ligand.is_isomorphic_with(solvent))
off_top = Topology.from_molecules(ligand)
solvated_off_top = solvate_topology_nonwater(topology=off_top, solvent=solvent)
ff = ForceField('openff-2.2.0.offxml', 'opc.offxml')
inter = Interchange.from_smirnoff(topology=solvated_off_top, force_field=ff, charge_from_molecules=[ligand, solvent])
for _, c in inter.collections["Electrostatics"].charges.items():
assert abs(c.m) == pytest.approx(0.13)
inter = Interchange.from_smirnoff(topology=solvated_off_top, force_field=ff, charge_from_molecules=[solvent, ligand])
for _, c in inter.collections["Electrostatics"].charges.items():
assert abs(c.m) == pytest.approx(0.06226857)
Output
solvent charges: [-0.062268570782092456 -0.062268570782092456 -0.062268570782092456 -0.062268570782092456 -0.062268570782092456 -0.062268570782092456 0.062268570782092456 0.062268570782092456 0.062268570782092456 0.062268570782092456 0.062268570782092456 0.062268570782092456] elementary_charge
ligand charges: [-0.13 -0.13 -0.13 -0.13 -0.13 -0.13 0.13 0.13 0.13 0.13 0.13 0.13] elementary_charge
molecules are isomorphic: True
Software versions
Interchange v0.3.29