Dynamics.current_potential_energy() returns the energy from before the last run() block unless that block happened to save energies. The integrator advances positions without going through SOMMContext.setPositions(), so the context's _energy_cache is never invalidated, and the only clear on the dynamics path is gated behind if save_energy:.
import sire as sr, openmm
mols = sr.load_test_files("ala.top", "ala.crd")
d = mols.dynamics(timestep="1fs", temper
def direct(d):
return (
d.context()
.getState(getEnergy=True)
.getPotentialEnergy()
.value_in_unit(openmm.unit.kilocalorie_per_mole)
)
print(d.current_potential_energy().value
d.run("5ps")
print(d.current_potential_energy().value
d.run("5ps", energy_frequency="1ps")
print(d.current_potential_energy().value
d.run("5ps")
print(d.current_potential_energy().value
cached direct
initial -5987.8102 -5987.8102
after run(5ps) -5987.8102 -6194.3530 <-- stale
after run(5ps, energy_frequency) -6094.2036 -6094.2036 <-- fine
after run(5ps) again -6094.2036 -6132.6996 <-- stale
Dynamics.current_potential_energy()returns the energy from before the lastrun()block unless that block happened to save energies. The integrator advances positions without going throughSOMMContext.setPositions(), so the context's_energy_cacheis never invalidated, and the only clear on the dynamics path is gated behindif save_energy:.