Skip to content

Commit c534c75

Browse files
Add AbsoluteFactory options to AlchemicalSettings (#1742)
* Add absolute alchemical settings * Expose settings in AFE protocols * expose settings in septop * Fix up settings * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add some tests * Add septop tests for sterics force settings * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add news item * add an extra parameterize option * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 3e2976c commit c534c75

File tree

8 files changed

+345
-22
lines changed

8 files changed

+345
-22
lines changed

news/absolute_settings.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
**Added:**
2+
3+
* New options have been added to the ``AlchemicalSettings``
4+
of the ``SepTopProtocol``, ``AbsoluteSolvationProtocol``
5+
and ``AbsoluteBindingProtocol``. Notably, these options allow users to
6+
control the softcore parameters as well as the use of
7+
long range dispersion corrections.
8+
9+
**Changed:**
10+
11+
* <news item>
12+
13+
**Deprecated:**
14+
15+
* <news item>
16+
17+
**Removed:**
18+
19+
* <news item>
20+
21+
**Fixed:**
22+
23+
* <news item>
24+
25+
**Security:**
26+
27+
* <news item>

openfe/protocols/openmm_afe/base.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from openff.units import Quantity, unit
3737
from openff.units.openmm import ensure_quantity, from_openmm, to_openmm
3838
from openmm import app
39-
from openmm import unit as omm_unit
39+
from openmm import unit as ommunit
4040
from openmmforcefields.generators import SystemGenerator
4141
from openmmtools import multistate
4242
from openmmtools.alchemy import (
@@ -52,6 +52,7 @@
5252
)
5353

5454
from openfe.protocols.openmm_afe.equil_afe_settings import (
55+
AlchemicalSettings,
5556
BaseSolvationSettings,
5657
IntegratorSettings,
5758
MultiStateOutputSettings,
@@ -168,10 +169,10 @@ def _pre_equilibrate(
168169
self,
169170
system: openmm.System,
170171
topology: openmm.app.Topology,
171-
positions: omm_unit.Quantity,
172+
positions: ommunit.Quantity,
172173
settings: dict[str, SettingsBaseModel],
173174
dry: bool,
174-
) -> tuple[omm_unit.Quantity, omm_unit.Quantity]:
175+
) -> tuple[ommunit.Quantity, ommunit.Quantity]:
175176
"""
176177
Run a non-alchemical equilibration to get a stable system.
177178
@@ -619,6 +620,7 @@ def _get_alchemical_system(
619620
system: openmm.System,
620621
comp_resids: dict[Component, npt.NDArray],
621622
alchem_comps: dict[str, list[Component]],
623+
alchemical_settings: AlchemicalSettings,
622624
) -> tuple[AbsoluteAlchemicalFactory, openmm.System, list[int]]:
623625
"""
624626
Get an alchemically modified system and its associated factory
@@ -633,6 +635,8 @@ def _get_alchemical_system(
633635
A dictionary of residues for each component in the System.
634636
alchem_comps : dict[str, list[Component]]
635637
A dictionary of alchemical components for each end state.
638+
alchemical_settings : AlchemicalSettings
639+
Settings controlling how the alchemical system is built.
636640
637641
Returns
638642
-------
@@ -652,9 +656,26 @@ def _get_alchemical_system(
652656

653657
alchemical_region = AlchemicalRegion(
654658
alchemical_atoms=alchemical_indices,
659+
softcore_alpha=alchemical_settings.softcore_alpha,
660+
annihilate_electrostatics=True,
661+
annihilate_sterics=alchemical_settings.annihilate_sterics,
662+
softcore_a=alchemical_settings.softcore_a,
663+
softcore_b=alchemical_settings.softcore_b,
664+
softcore_c=alchemical_settings.softcore_c,
665+
softcore_beta=0.0,
666+
softcore_d=1.0,
667+
softcore_e=1.0,
668+
softcore_f=2.0,
655669
)
656670

657-
alchemical_factory = AbsoluteAlchemicalFactory()
671+
alchemical_factory = AbsoluteAlchemicalFactory(
672+
consistent_exceptions=False,
673+
switch_width=1.0 * ommunit.angstroms,
674+
alchemical_pme_treatment="exact",
675+
alchemical_rf_treatment="switched",
676+
disable_alchemical_dispersion_correction=alchemical_settings.disable_alchemical_dispersion_correction,
677+
split_alchemical_forces=True,
678+
)
658679
alchemical_system = alchemical_factory.create_alchemical_system(system, alchemical_region)
659680

660681
return alchemical_factory, alchemical_system, alchemical_indices
@@ -1141,7 +1162,11 @@ def run(
11411162

11421163
# 7. Get alchemical system
11431164
alchem_factory, alchem_system, alchem_indices = self._get_alchemical_system(
1144-
omm_topology, restrained_omm_system, comp_resids, alchem_comps
1165+
topology=omm_topology,
1166+
system=restrained_omm_system,
1167+
comp_resids=comp_resids,
1168+
alchem_comps=alchem_comps,
1169+
alchemical_settings=settings["alchemical_settings"],
11451170
)
11461171

11471172
# 8. Get compound and sampler states

openfe/protocols/openmm_afe/equil_afe_settings.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,48 @@
4242

4343

4444
class AlchemicalSettings(SettingsBaseModel):
45-
"""Settings for the alchemical protocol
45+
"""
46+
Alchemical settings for Protocols which use the
47+
AbsoluteAlchemicalFactory.
48+
"""
49+
50+
disable_alchemical_dispersion_correction: bool = False
51+
"""
52+
If True, the long-range dispersion correction will not
53+
be included for the alchemical region, avoiding the need
54+
to recompute the correction. This can improve performance,
55+
at the cost of accuracy. Default is False.
56+
"""
57+
annihilate_sterics: bool = False
58+
"""
59+
If True, sterics (Lennard-Jones) will be annhilated instead
60+
of decoupled. Default is False.
61+
"""
62+
softcore_alpha: float = 0.5
63+
"""
64+
Alchemical softcore parameter for the Lennard-Jones interactions
65+
(default is 0.5).
4666
47-
Empty place holder for right now.
67+
The generalized softcore potential formalism introduced by
68+
Pham and Shirts, J. Chem. Phys. 135, 034114 (2011), equation 13,
69+
is used here. The ``softcore_a``, ``softcore_b``, and
70+
``softcore_c`` parameters are used alongside ``softcore_alpha``
71+
to control how the potential is scaled.
72+
"""
73+
softcore_a: float = 1.0
74+
"""
75+
Scaling constant ``a`` in
76+
Eq. 13 from Pham and Shirts, J. Chem. Phys. 135, 034114 (2011).
77+
"""
78+
softcore_b: float = 1.0
79+
"""
80+
Scaling constant ``b`` in
81+
Eq. 13 from Pham and Shirts, J. Chem. Phys. 135, 034114 (2011).
82+
"""
83+
softcore_c: float = 6.0
84+
"""
85+
Scaling constant ``c`` in
86+
Eq. 13 from Pham and Shirts, J. Chem. Phys. 135, 034114 (2011).
4887
"""
4988

5089

openfe/protocols/openmm_septop/base.py

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
)
4646

4747
from openfe.protocols.openmm_afe.equil_afe_settings import (
48+
AlchemicalSettings,
4849
BaseSolvationSettings,
4950
IntegratorSettings,
5051
MultiStateOutputSettings,
@@ -285,6 +286,7 @@ def _get_alchemical_system(
285286
system: openmm.System,
286287
alchem_indices_A: list[int],
287288
alchem_indices_B: list[int],
289+
alchemical_settings: AlchemicalSettings,
288290
) -> tuple[AbsoluteAlchemicalFactory, openmm.System]:
289291
"""
290292
Get an alchemically modified system and its associated factory
@@ -293,12 +295,14 @@ def _get_alchemical_system(
293295
----------
294296
system : openmm.System
295297
System to alchemically modify.
296-
alchem_indices_A: list[int]
298+
alchem_indices_A : list[int]
297299
A list of atom indices for the alchemically modified
298300
ligand A in the system.
299-
alchem_indices_B: list[int]
301+
alchem_indices_B : list[int]
300302
A list of atom indices for the alchemically modified
301303
ligand B in the system.
304+
alchemical_settings : AlchemicalSettings
305+
Settings controlling how the alchemical system will be built.
302306
303307
Returns
304308
-------
@@ -313,13 +317,42 @@ def _get_alchemical_system(
313317
switch_width=1.0 * unit.angstroms,
314318
alchemical_pme_treatment="exact",
315319
alchemical_rf_treatment="switched",
316-
disable_alchemical_dispersion_correction=False,
320+
disable_alchemical_dispersion_correction=alchemical_settings.disable_alchemical_dispersion_correction,
317321
split_alchemical_forces=True,
318322
)
323+
319324
# Alchemical Region for ligand A
320-
alchemical_region_A = AlchemicalRegion(alchemical_atoms=alchem_indices_A, name="A")
325+
alchemical_region_A = AlchemicalRegion(
326+
alchemical_atoms=alchem_indices_A,
327+
name="A",
328+
softcore_alpha=alchemical_settings.softcore_alpha,
329+
annihilate_electrostatics=True,
330+
annihilate_sterics=alchemical_settings.annihilate_sterics,
331+
softcore_a=alchemical_settings.softcore_a,
332+
softcore_b=alchemical_settings.softcore_b,
333+
softcore_c=alchemical_settings.softcore_c,
334+
softcore_beta=0.0,
335+
softcore_d=1.0,
336+
softcore_e=1.0,
337+
softcore_f=2.0,
338+
)
339+
321340
# Alchemical Region for ligand B
322-
alchemical_region_B = AlchemicalRegion(alchemical_atoms=alchem_indices_B, name="B")
341+
alchemical_region_B = AlchemicalRegion(
342+
alchemical_atoms=alchem_indices_B,
343+
name="B",
344+
softcore_alpha=alchemical_settings.softcore_alpha,
345+
annihilate_electrostatics=True,
346+
annihilate_sterics=alchemical_settings.annihilate_sterics,
347+
softcore_a=alchemical_settings.softcore_a,
348+
softcore_b=alchemical_settings.softcore_b,
349+
softcore_c=alchemical_settings.softcore_c,
350+
softcore_beta=0.0,
351+
softcore_d=1.0,
352+
softcore_e=1.0,
353+
softcore_f=2.0,
354+
)
355+
323356
alchemical_system = alchemical_factory.create_alchemical_system(
324357
system, [alchemical_region_A, alchemical_region_B]
325358
)

openfe/protocols/openmm_septop/equil_septop_method.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1971,6 +1971,7 @@ def run(
19711971
omm_system_AB,
19721972
atom_indices_AB_A,
19731973
atom_indices_AB_B,
1974+
settings["alchemical_settings"],
19741975
)
19751976

19761977
# 10. Apply Restraints
@@ -2254,6 +2255,7 @@ def run(
22542255
omm_system_AB,
22552256
atom_indices_AB_A,
22562257
atom_indices_AB_B,
2258+
settings["alchemical_settings"],
22572259
)
22582260

22592261
# 8. Apply Restraints

openfe/protocols/openmm_septop/equil_septop_settings.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from openff.units import unit as offunit
2424
from pydantic import field_validator
2525

26+
from openfe.protocols.openmm_afe.equil_afe_settings import AlchemicalSettings
2627
from openfe.protocols.openmm_utils.omm_settings import (
2728
IntegratorSettings,
2829
MDOutputSettings,
@@ -36,13 +37,6 @@
3637
from openfe.protocols.restraint_utils.settings import BaseRestraintSettings
3738

3839

39-
class AlchemicalSettings(SettingsBaseModel):
40-
"""Settings for the alchemical protocol
41-
42-
Empty place holder for right now.
43-
"""
44-
45-
4640
class LambdaSettings(SettingsBaseModel):
4741
"""Lambda schedule settings.
4842

0 commit comments

Comments
 (0)