Skip to content

Commit

Permalink
Use preserveState=True rather than saving state ourselves.
Browse files Browse the repository at this point in the history
  • Loading branch information
lohedges committed Oct 14, 2024
1 parent c58fc13 commit 152ab02
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions wrapper/Convert/SireOpenMM/lambdalever.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1796,26 +1796,13 @@ double LambdaLever::setLambda(OpenMM::Context &context,
}
}

// reinitialize the context if the constraints have changed
// we need to reinitialize the context if the constraints have changed
// since updating the parameters in the system will not update the context
// itself
if (have_constraints_changed)
{
// we need to reinitialize the context if the constraints have changed
// since updating the parameters in the system will not update the context
// itself

// get the current state
const auto state = context.getState(OpenMM::State::Positions | OpenMM::State::Velocities);

// store the current positions and velocities
const auto positions = state.getPositions();
const auto velocities = state.getVelocities();

// reinitialize the context
context.reinitialize();

// set the positions and velocities back to what they were
context.setPositions(positions);
context.setVelocities(velocities);
// reinitialize the context, preserving the state
context.reinitialize(true);
}

return lambda_value;
Expand Down

0 comments on commit 152ab02

Please sign in to comment.