Fix charges output and total_charge handling for QET in PESCalculator and JAX path#803
Merged
shyuep merged 1 commit intoJun 10, 2026
Conversation
… and JAX path When the DGL backend was removed, the only calculator with charge plumbing went with it. For charge-predicting potentials (QET): - get_charges() raised PropertyNotImplementedError on both PESCalculator and JAXPESCalculator: "charges" was missing from implemented_properties and never stored in results, even though the torch Potential returns them and the JAX QEq solve computes them. - total_charge was silently ignored everywhere: the torch calculator never passed it (LinearQeq treats None as zero) and the JAX conversion baked it as a static 0.0, so charged cells ran as neutral with no error. atoms.set_initial_charges(), which the DGL calculator consumed, was also ignored. Changes: - PESCalculator: "charges" in implemented_properties, results populated when potential.calc_charge is set, total_charge/ext_pot kwargs restored with the atoms.get_initial_charges() fallback. Relaxer and MolecularDynamics inherit this automatically. - make_potential_fn(): public (E, forces, stress) 3-tuple contract unchanged by default. with_charges=True (QET only) returns a callable with a trailing total_charge argument that also returns per-atom charges; total_charge is traced, so varying it triggers no recompilation. - qet_energy_and_charges() returns (energy, charges) and accepts a traced total_charge; qet_energy() stays a thin wrapper. - JAXPESCalculator mirrors PESCalculator: "charges" exposed, total_charge kwarg with the initial-charges fallback.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the DGL backend was removed, the only calculator with charge plumbing went with it. For charge-predicting potentials (QET):
Changes: