Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
d7dcd14
add charge validation
jthorton Aug 11, 2026
84174f3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 11, 2026
3c76241
add tests
jthorton Aug 11, 2026
2874599
Merge branch 'main' into charge_validation
jthorton Aug 14, 2026
36784f9
add validation to all protocols, remove runtime charge generation
jthorton Aug 14, 2026
251474c
fix tests
jthorton Aug 17, 2026
ba3f47d
Merge branch 'main' into charge_validation
jthorton Aug 17, 2026
045954d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 17, 2026
6c0d7d4
fix protocol charge generation tests
jthorton Aug 17, 2026
960b874
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 17, 2026
96b5d24
fix tests with missing charges
jthorton Aug 17, 2026
e2099ed
Merge branch 'main' into charge_validation
jthorton Aug 18, 2026
b8f7ecb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 18, 2026
98152db
speedup smoke test
jthorton Aug 18, 2026
df24ca1
add mixed charge/uncharged system testing
jthorton Aug 18, 2026
7dfdb3f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 18, 2026
0c8e7dd
switch to using sdfs
jthorton Aug 19, 2026
540aefa
remove extra file
jthorton Aug 19, 2026
bacb1c3
fix cli tests
jthorton Aug 19, 2026
9cb4322
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 19, 2026
7b7e4ee
add charges to inputs, remove slow mark
jthorton Aug 20, 2026
c43dbf0
Update src/openfe/tests/protocols/test_openmmutils.py
jthorton Aug 20, 2026
6c32c99
add news, update error to list all molecules with missing charges.
jthorton Aug 20, 2026
4cf822d
catch missing librarycharges handler in ff
jthorton Aug 21, 2026
b8846df
Merge branch 'main' into charge_validation
jthorton Nov 19, 2026
b62989f
add forcefield as a method, add back runtime charge assignment, add m…
jthorton Nov 20, 2026
0fe8f4b
add missing import
jthorton Nov 20, 2026
50d2bcb
add dry run tests with deterministic charges
jthorton Nov 20, 2026
5497b91
Merge branch 'main' into charge_validation
jthorton Nov 20, 2026
9721831
fix ruff issues
jthorton Nov 20, 2026
71b1124
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 20, 2026
e280b4a
Update news/charge_validation.rst
jthorton Nov 27, 2026
4d01238
Apply batched suggestions from code review
jthorton Nov 27, 2026
99f372b
PR feedback, add test for failed force field loading.
jthorton Nov 27, 2026
fc4fe45
Merge branch 'main' into charge_validation
jthorton Nov 27, 2026
b05ab4d
fix abfe and septop var name
jthorton Nov 27, 2026
4a27757
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 27, 2026
7675e5c
fmt fix
jthorton Nov 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions news/charge_validation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* An option to assign run time partial charges using a small molecule force field. Set the ``partial_charge_method`` of :class:`OpenFFPartialChargeSettings` to ``forcefield`` in the protocol settings (`PR #2132 <https://github.com/OpenFreeEnergy/openfe/pull/2132>`_).

**Changed:**

* All protocols will raise a ``ProtocolValidationError`` error if a non-deterministic partial charge generation method (AM1-BCC or AM1-BCC-ELF10) is used at run time, please provide molecules with pre-calculated charges to use ``am1bcc`` or use a deterministic method such as library charges or AshGC (`PR #2132 <https://github.com/OpenFreeEnergy/openfe/pull/2132>`_).

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
18 changes: 16 additions & 2 deletions src/openfe/protocols/openmm_afe/base_afe_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ def _pre_equilibrate(
def _assign_partial_charges(
partial_charge_settings: OpenFFPartialChargeSettings,
small_mols: dict[SmallMoleculeComponent, OFFMolecule],
small_molecule_forcefield: str | None = None,
) -> None:
"""
Assign partial charges to the OpenFF Molecules associated with
Expand All @@ -379,7 +380,15 @@ def _assign_partial_charges(
small_mols : dict[SmallMoleculeComponent, openff.toolkit.Molecule]
Dictionary of OpenFF Molecules to add, keyed by their
associated SmallMoleculeComponent.
small_molecule_forcefield : str | None
The small molecule force field used to apply the partial charges if the method is ``forcefield``.
"""
# only pass through the force field if the method is forcefield, otherwise it will raise an error
if partial_charge_settings.partial_charge_method == "forcefield" and small_molecule_forcefield is not None: # fmt: skip
force_fields = [small_molecule_forcefield]
else:
force_fields = None

for mol in small_mols.values():
charge_generation.assign_offmol_partial_charges(
offmol=mol,
Expand All @@ -388,6 +397,7 @@ def _assign_partial_charges(
toolkit_backend=partial_charge_settings.off_toolkit_backend,
generate_n_conformers=partial_charge_settings.number_of_conformers,
nagl_model=partial_charge_settings.nagl_model,
forcefields=force_fields,
)

@staticmethod
Expand All @@ -405,7 +415,7 @@ def _get_system_generator(
----------
settings : dict[str, SettingsBaseModel]
A dictionary of settings object for the unit.
solvent_comp : BaseSolventComponent | None
solvent_component : BaseSolventComponent | None
The solvent component of this system, if there is one.
openff_molecules : list[openff.toolkit.Molecule] | None
A list of OpenFF Molecules to generate templates for, if any.
Expand Down Expand Up @@ -719,7 +729,11 @@ def run(
settings = self._get_settings()

# Assign partial charges now to avoid any discrepancies later
self._assign_partial_charges(settings["charge_settings"], small_mols)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been thinking more about this one - we're silently removing this, but won't users get caught out if they do use a deterministic charge method in the partial charge settings, e.g. NAGL?

@jthorton jthorton Aug 21, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that would be the downside, users would have to either use a ff with a NAGL handler or pre-charge them. If we keep support for NAGL and espaloma charge methods at runtime only that could work with the default setting being forcefield. It could be confusing if users have to define the forcefield to use in two places 1) the charges setting object and 2) small molecule force field, and then what happens if these are different?

Ideally I would love to keep this as simple as possible for users, we already encourage charging before running so moving to openfe will do no runtime charge generation doesn't feel like too much of a change?

self._assign_partial_charges(
settings["charge_settings"],
small_mols,
settings["forcefield_settings"].small_molecule_forcefield,
)

# Get OpenMM topology, positions, system, and comp_resids
omm_topology, omm_system, positions, comp_resids = self._get_omm_objects(
Expand Down
9 changes: 9 additions & 0 deletions src/openfe/protocols/openmm_afe/equil_binding_afe_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,15 @@ def _validate(
system_validation.validate_chemical_system(stateB)
self._validate_endstates(stateA, stateB)

# validate small molecule charges
small_ff = self.settings.forcefield_settings.small_molecule_forcefield
system_validation.validate_nondeterministic_charges(
stateA, small_ff, self.settings.partial_charge_settings
)
system_validation.validate_nondeterministic_charges(
stateB, small_ff, self.settings.partial_charge_settings
)

# Validate the complex lambda schedule
self._validate_lambda_schedule(
self.settings.complex_lambda_settings,
Expand Down
9 changes: 9 additions & 0 deletions src/openfe/protocols/openmm_afe/equil_solvation_afe_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,15 @@ def _validate(
system_validation.validate_chemical_system(stateB)
self._validate_endstates(stateA, stateB)

# validate small molecule charges
small_ff = self.settings.solvent_forcefield_settings.small_molecule_forcefield
system_validation.validate_nondeterministic_charges(
stateA, small_ff, self.settings.partial_charge_settings
)
system_validation.validate_nondeterministic_charges(
stateB, small_ff, self.settings.partial_charge_settings
)

# Validate the lambda schedule
self._validate_lambda_schedule(
self.settings.solvent_lambda_settings,
Expand Down
21 changes: 20 additions & 1 deletion src/openfe/protocols/openmm_md/plain_md_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,13 @@ def _validate(
# Validate the ChemicalSystem
system_validation.validate_chemical_system(stateA)

# Validate small molecule charges
system_validation.validate_nondeterministic_charges(
stateA,
self.settings.forcefield_settings.small_molecule_forcefield,
self.settings.partial_charge_settings,
)

# Validate solvent component if present
nonbond = self.settings.forcefield_settings.nonbonded_method
system_validation.validate_solvent(stateA, nonbond)
Expand Down Expand Up @@ -344,6 +351,7 @@ class PlainMDSetupUnit(PlainMDUnitMixin, gufe.ProtocolUnit):
def _assign_partial_charges(
charge_settings: OpenFFPartialChargeSettings,
smc_components: dict[SmallMoleculeComponent, OFFMolecule],
small_molecule_forcefield: str | None = None,
) -> None:
"""
Assign partial charges to SMCs.
Expand All @@ -355,7 +363,15 @@ def _assign_partial_charges(
smc_components : dict[SmallMoleculeComponent, openff.toolkit.Molecule]
Dictionary of OpenFF Molecules to add, keyed by
SmallMoleculeComponent.
small_molecule_forcefield : str | None
The small molecule force field used to apply the partial charges if the method is ``forcefield``.
"""
# only pass through the force field if the method is forcefield, otherwise it will raise an error
if charge_settings.partial_charge_method == "forcefield" and small_molecule_forcefield is not None: # fmt: skip
force_fields = [small_molecule_forcefield]
else:
force_fields = None

for mol in smc_components.values():
charge_generation.assign_offmol_partial_charges(
offmol=mol,
Expand All @@ -364,6 +380,7 @@ def _assign_partial_charges(
toolkit_backend=charge_settings.off_toolkit_backend,
generate_n_conformers=charge_settings.number_of_conformers,
nagl_model=charge_settings.nagl_model,
forcefields=force_fields,
)

def run(
Expand Down Expand Up @@ -483,7 +500,9 @@ def run(
used_resnums.add(resnum)

# b. assign partial charges to smcs
self._assign_partial_charges(charge_settings, smc_components)
self._assign_partial_charges(
charge_settings, smc_components, forcefield_settings.small_molecule_forcefield
)

# c. get a system generator
if output_settings.forcefield_cache is not None:
Expand Down
9 changes: 9 additions & 0 deletions src/openfe/protocols/openmm_rfe/hybridtop_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,15 @@ def _validate(
system_validation.validate_chemical_system(stateB)
self._validate_endstates(stateA, stateB)

# Validate small molecule charges
small_ff = self.settings.forcefield_settings.small_molecule_forcefield
system_validation.validate_nondeterministic_charges(
stateA, small_ff, self.settings.partial_charge_settings
)
system_validation.validate_nondeterministic_charges(
stateB, small_ff, self.settings.partial_charge_settings
)

# Validate the mapping
alchem_comps = system_validation.get_alchemical_components(stateA, stateB)
self._validate_mapping(mapping, alchem_comps)
Expand Down
16 changes: 15 additions & 1 deletion src/openfe/protocols/openmm_rfe/hybridtop_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ def _get_components(
def _assign_partial_charges(
charge_settings: OpenFFPartialChargeSettings,
small_mols: dict[SmallMoleculeComponent, OFFMolecule],
small_molecule_forcefield: str | None = None,
) -> None:
"""
Assign partial charges to the OpenFF Molecules associated with all
Expand All @@ -221,7 +222,15 @@ def _assign_partial_charges(
small_mols : dict[SmallMoleculeComponent, openff.toolkit.Molecule]
Dictionary of OpenFF Molecules to add, keyed by
their associated SmallMoleculeComponent.
small_molecule_forcefield : str | None
The small molecule force field used to apply the partial charges if the method is ``forcefield``.
"""
# only pass through the force field if the method is forcefield, otherwise it will raise an error
if charge_settings.partial_charge_method == "forcefield" and small_molecule_forcefield is not None: # fmt: skip
force_fields = [small_molecule_forcefield]
else:
force_fields = None

for smc, mol in small_mols.items():
charge_generation.assign_offmol_partial_charges(
offmol=mol,
Expand All @@ -230,6 +239,7 @@ def _assign_partial_charges(
toolkit_backend=charge_settings.off_toolkit_backend,
generate_n_conformers=charge_settings.number_of_conformers,
nagl_model=charge_settings.nagl_model,
forcefields=force_fields,
)

@staticmethod
Expand Down Expand Up @@ -762,7 +772,11 @@ def run(
alchem_resnames = [assigned[alchem_comps["stateA"][0]]]

# Assign partial charges now to avoid any discrepancies later
self._assign_partial_charges(settings["charge_settings"], small_mols)
self._assign_partial_charges(
settings["charge_settings"],
small_mols,
settings["forcefield_settings"].small_molecule_forcefield,
)

(
stateA_system,
Expand Down
12 changes: 11 additions & 1 deletion src/openfe/protocols/openmm_septop/base_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,18 +461,27 @@ def _get_system_generator(
def _assign_partial_charges(
partial_charge_settings: OpenFFPartialChargeSettings,
smc_components: dict[SmallMoleculeComponent, OFFMolecule],
small_molecule_forcefield: str | None = None,
) -> None:
"""
Assign partial charges to OFFMolecules inplace.

Parameters
----------
charge_settings : OpenFFPartialChargeSettings
partial_charge_settings : OpenFFPartialChargeSettings
Settings for controlling how the partial charges are assigned.
smc_components : dict[SmallMoleculeComponent, openff.toolkit.Molecule]
Dictionary of OpenFF Molecules to add, keyed by
SmallMoleculeComponent.
small_molecule_forcefield: str | None = None,
The small molecule force field used to apply the partial charges if the method is ``forcefield``.
"""
# only pass through the force field if the method is forcefield, otherwise it will raise an error
if partial_charge_settings.partial_charge_method == "forcefield" and small_molecule_forcefield is not None: # fmt: skip
force_fields = [small_molecule_forcefield]
else:
force_fields = None

for mol in smc_components.values():
charge_generation.assign_offmol_partial_charges(
offmol=mol,
Expand All @@ -481,6 +490,7 @@ def _assign_partial_charges(
toolkit_backend=partial_charge_settings.off_toolkit_backend,
generate_n_conformers=partial_charge_settings.number_of_conformers,
nagl_model=partial_charge_settings.nagl_model,
forcefields=force_fields,
)

def _get_modeller(
Expand Down
9 changes: 9 additions & 0 deletions src/openfe/protocols/openmm_septop/equil_septop_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,15 @@ def _validate(
system_validation.validate_chemical_system(stateB)
self._validate_endstates(stateA, stateB)

# Validate small molecule charges
small_ff = self.settings.forcefield_settings.small_molecule_forcefield
system_validation.validate_nondeterministic_charges(
stateA, small_ff, self.settings.partial_charge_settings
)
system_validation.validate_nondeterministic_charges(
stateB, small_ff, self.settings.partial_charge_settings
)

# Validate the lambda schedule
self._validate_lambda_schedule(
self.settings.solvent_lambda_settings,
Expand Down
12 changes: 10 additions & 2 deletions src/openfe/protocols/openmm_septop/septop_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,11 @@ def run(
settings = self._get_settings()

# 4. Assign partial charges
self._assign_partial_charges(settings["charge_settings"], smc_comps_AB)
self._assign_partial_charges(
settings["charge_settings"],
smc_comps_AB,
settings["forcefield_settings"].small_molecule_forcefield,
)

# 5. Get the OpenMM systems
omm_system_A, omm_topology_A, positions_A, modeller_A, comp_resids_A = (
Expand Down Expand Up @@ -1081,7 +1085,11 @@ def run(
settings = self._get_settings()

# 3. Assign partial charges
self._assign_partial_charges(settings["charge_settings"], smc_comps_AB)
self._assign_partial_charges(
settings["charge_settings"],
smc_comps_AB,
settings["forcefield_settings"].small_molecule_forcefield,
)

# 4. Update the positions of ligand B:
# - solvent: Offset ligand B with respect to ligand A
Expand Down
4 changes: 3 additions & 1 deletion src/openfe/protocols/openmm_utils/charge_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,9 @@ def assign_offmol_partial_charges(
raise ValueError(errmsg)

# If you have non-zero charges and not overwriting, just return
if offmol.partial_charges is not None and np.any(offmol.partial_charges):
if offmol.partial_charges is not None and not np.allclose(
offmol.partial_charges.m_as(unit.elementary_charge), 0
):
if not overwrite:
return offmol

Expand Down
7 changes: 6 additions & 1 deletion src/openfe/protocols/openmm_utils/omm_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class OpenFFPartialChargeSettings(BasePartialChargeSettings):
Settings for controlling partial charge assignment using the OpenFF tooling
"""

partial_charge_method: Literal["am1bcc", "am1bccelf10", "nagl", "espaloma"] = "am1bcc"
partial_charge_method: Literal["am1bcc", "am1bccelf10", "nagl", "espaloma", "forcefield"] = "forcefield" # fmt: skip
"""
Selection of method for partial charge generation.

Expand Down Expand Up @@ -312,6 +312,11 @@ class OpenFFPartialChargeSettings(BasePartialChargeSettings):
<https://github.com/choderalab/espaloma_charge>`_
Only ``ambertools`` and ``rdkit`` `off_toolkit_backend`` options
are supported. A maximum of one conformer is allowed.

``forcefield``:
Assign partial charges using a SMIRNOFF force field's defined charge model, this is useful to get the correct
NAGL(AshGC) model for a specific force field or to use LibraryCharges.

"""


Expand Down
Loading
Loading