Skip to content
23 changes: 23 additions & 0 deletions news/deprecate_alchemical_charge_diff.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* <news item>

**Changed:**

* <news item>

**Deprecated:**

* Deprecated ``openfe.utils.ligand_utils.get_alchemical_charge_difference()``, which is replaced by ``LigandAtomMapping.get_alchemical_charge_difference()`` in ``gufe`` (PR #1479).

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
10 changes: 2 additions & 8 deletions openfe/protocols/openmm_rfe/equil_rfe_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,8 @@ def _get_alchemical_charge_difference(
The formal charge difference between states A and B.
This is defined as sum(charge state A) - sum(charge state B)
"""
chg_A = Chem.rdmolops.GetFormalCharge(
mapping.componentA.to_rdkit()
)
chg_B = Chem.rdmolops.GetFormalCharge(
mapping.componentB.to_rdkit()
)

difference = chg_A - chg_B

difference = mapping.get_alchemical_charge_difference()

if abs(difference) > 0:
if explicit_charge_correction:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
RFEComponentLabels,
)
from ...protocols.openmm_rfe.equil_rfe_methods import RelativeHybridTopologyProtocol
from ...utils.ligand_utils import get_alchemical_charge_difference

# TODO: move/or find better structure for protocol_generator combinations!
PROTOCOL_GENERATOR = {
Expand Down Expand Up @@ -331,7 +330,7 @@ def _build_transformation(
protocol_settings = transformation_protocol.settings.unfrozen_copy()
if "vacuum" in transformation_name:
protocol_settings.forcefield_settings.nonbonded_method = "nocutoff"
elif get_alchemical_charge_difference(ligand_mapping_edge) != 0:
elif ligand_mapping_edge.get_alchemical_charge_difference() != 0:
wmsg = ("Charge changing transformation between ligands "
f"{ligand_mapping_edge.componentA.name} and {ligand_mapping_edge.componentB.name}. "
"A more expensive protocol with 22 lambda windows, sampled "
Expand Down
7 changes: 6 additions & 1 deletion openfe/tests/setup/atom_mapping/test_atommapper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from openfe.setup.atom_mapping.ligandatommapper import LigandAtomMapper

from openfe.utils import ligand_utils

class TestAtomMapper:
def test_abstract_error(self, simple_mapping):
Expand Down Expand Up @@ -42,3 +42,8 @@ def _mappings_generator(self, componentA, componentB):
results = list(mapper.suggest_mappings(molA, molB))
assert len(results) == 2
assert results == [simple_mapping, other_mapping]


def test_alchemical_charge_deprecation_warning(self, simple_mapping):
with pytest.warns(DeprecationWarning, match=r"Use gufe\.LigandAtomMapping"):
ligand_utils.get_alchemical_charge_difference(simple_mapping)
7 changes: 3 additions & 4 deletions openfe/utils/ligand_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from gufe import LigandAtomMapping
import warnings

def get_alchemical_charge_difference(mapping: LigandAtomMapping) -> int:
"""
Expand All @@ -14,7 +15,5 @@ def get_alchemical_charge_difference(mapping: LigandAtomMapping) -> int:
int:
The difference in formal charge between the end states.
"""
from rdkit import Chem
charge_a = Chem.rdmolops.GetFormalCharge(mapping.componentA.to_rdkit())
charge_b = Chem.rdmolops.GetFormalCharge(mapping.componentB.to_rdkit())
return charge_a - charge_b
warnings.warn("Use gufe.LigandAtomMapping.get_alchemical_charge_difference() instead.", DeprecationWarning)
return mapping.get_alchemical_charge_difference()
Loading