Does the neighbor list update when setPositions is called using C++ API?

The functionality of OpenMM will (eventually) include everything that one would need to run modern molecular simulation.
POST REPLY
User avatar
Joseph Lawrence
Posts: 1
Joined: Thu Nov 14, 2024 6:22 pm

Does the neighbor list update when setPositions is called using C++ API?

Post by Joseph Lawrence » Thu Nov 14, 2024 7:00 pm

I need to use OpenMM to calculate forces and energies but not to propagate as this is done by an external routine. (I understand this does not make use of many of the advantages of OpenMM, but I require this for now.)

Specifically, after the external code has updated the positions I want to know whether the following is sufficient to correctly calculate forces at the new positions:

// setting positions in OpenMM
context.setPositions(posInNm);
// followed by getting forces at the updated positions
OpenMM::State state = context.getState(OpenMM::State::Forces);
const std::vector<OpenMM::Vec3>& forceMM = state.getForces();

I want to be sure that by doing this OpenMM will still correctly manage the neighbor list etc. Searching the documentation I could not determine:
1) Whether calling setPositions will automatically cause the neighbor list to update (or if one needs to do something else to force this such as manually advancing the time step)?

and

2) If this does force neighbor list update if it is completely reconstructed or if it is updated as normal? If the latter case then, for platforms such as OpenCL that may internally swap the positions and velocities of identical solvent molecules, does this swap also affect the forces. i.e. would one also need to call getPositions and monitor if molecules had been swapped by OpenMM?

User avatar
Peter Eastman
Posts: 2593
Joined: Thu Aug 09, 2007 1:25 pm

Re: Does the neighbor list update when setPositions is called using C++ API?

Post by Peter Eastman » Thu Nov 14, 2024 7:05 pm

Yes. Neighbor lists and similar structures are strictly an implementation detail. They're used to speed up calculations without changing any results. Similarly for the reordering done internally by some platforms: it's never visible to the user. The forces reported by getState() are the correct forces for the current positions.

POST REPLY