Skip to content

Let the force field resolve the partial charge assignment - #2152

Open
jthorton wants to merge 11 commits into
mainfrom
charge_from_ff
Open

Let the force field resolve the partial charge assignment#2152
jthorton wants to merge 11 commits into
mainfrom
charge_from_ff

Conversation

@jthorton

@jthorton jthorton commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Fixes #2116, #2117

LLM / AI generated code disclosure

LLMs or other AI-powered tools (beyond simple IDE use cases) were used in this contribution: yes / no
If yes, please provide details here: No

Checklist

  • All new code is appropriately documented (user-facing code must have complete docstrings).
  • Added a news entry, or the changes are not user-facing.
  • Ran pre-commit: you can run pre-commit locally or comment on this PR with pre-commit.ci autofix.
  • Filled in the AI generated code disclosure.

Manual Tests: these are slow so don't need to be run every commit, only before merging and when relevant changes are made (generally at reviewer-discretion).

Developers certificate of origin

@github-actions

Copy link
Copy Markdown

No API break detected ✅

View workflow run

Griffe output
$ griffe check "openfe" -s src --no-inspection --no-color --verbose -a origin/main

$ griffe check "openfecli" -s src --no-inspection --no-color --verbose -a origin/main

Comment thread src/openfe/protocols/openmm_utils/charge_generation.py Outdated
@codecov

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.59%. Comparing base (110503a) to head (3eb3600).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2152      +/-   ##
==========================================
- Coverage   95.20%   90.59%   -4.61%     
==========================================
  Files         213      213              
  Lines       21138    21169      +31     
==========================================
- Hits        20124    19178     -946     
- Misses       1014     1991     +977     
Flag Coverage Δ
fast-tests 90.59% <100.00%> (?)
slow-tests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@IAlibay IAlibay left a comment

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.

quick first look

RDKitToolkitWrapper,
)
from openff.units import unit
from sympy.codegen.ast import continue_

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.

Is this import necessary?

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.

good catch not sure why pycharm pulled that in!

@@ -290,6 +291,7 @@ def assign_offmol_partial_charges(

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 liked your idea yesterday of having a "forcefield" entry to make it clear that this is the method that was being applied.

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.

Added!

Comment thread src/openfe/protocols/openmm_utils/charge_generation.py Outdated
Comment thread src/openfe/protocols/openmm_utils/charge_generation.py Outdated
@jthorton

Copy link
Copy Markdown
Collaborator Author

pre-commit.ci autofix

@jthorton
jthorton requested a review from IAlibay August 20, 2026 08:32

@IAlibay IAlibay left a comment

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.

Couple of things - mainly it doesn't look like the CLI would work right now (maybe it just needs a test to check it).

off_toolkit_backend: ambertools
number_of_conformers: None
nagl_model: None
forcefields: None

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.

Are there other changes necessary to enable this on the CLI? If so and you want them in a different PR, I'd move these changes to a separate CLI-focused PR.

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.

Finished up the CLI support and added tests, I did intend to do it all in this PR.

offmol: OFFMol,
overwrite: bool,
method: Literal["am1bcc", "am1bccelf10", "nagl", "espaloma"],
method: Literal["am1bcc", "am1bccelf10", "nagl", "espaloma", "forcefield"],

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.

We'll need to update the OpenFFPartialChargeSettings to match this.

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.

Updated!

forcefields = [forcefields]

# this expects the full file name of the force field offxml file, e.g. "openff-2.0.0.offxml"
# which is different to how settings work which can leave off the .offxml extension

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 think now we can use .offxml directly right? Should we change the defaults?

Also what happens if this encounters a non .offxml str? Should we try to add it?

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.

Updated to accept both and added a test, and yes maybe the default should now have the extension as well.

Charges are applied based on the following source preferences:
- Charges already present on the ligand are retained if overwrite is ``False``
- Charges are applied using the input method and settings
- the forcefield option will apply the default charges as intended by the force field.

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 think this is no longer true, is that correct?

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.

Updated to represent the correct ordering.

# which is different to how settings work which can leave off the .offxml extension
ff = ForceField(*forcefields)
# let the force field resolve the partial charge assignment
charges = ff.get_partial_charges(offmol)

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 believe this needs to get wrapped around toolkit_registry_manager, otherwise we'll go back to encountering the annoying rdkit & openeye toolkit aren't compatible problem.

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.

Probably but which registry would we use as it could influence the charge method used? I think the default is openeye and am1bccelf10 and then fall back to AmberToolsam1bcc?

)

assert uncharged_mol.partial_charges is not None
assert np.any(uncharged_mol.partial_charges)

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.

Do you want to check against charging with ashgc directly?

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 extended the test to cover this.

@jthorton

Copy link
Copy Markdown
Collaborator Author

pre-commit.ci autofix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a "forcefield" optional to assign_partial_charges

2 participants