This issue arises due to the way that the potential energy associated with the forces being passed to OpenMM by NanoVer is defined, specifically the expression IMD_FORCE_EXPRESSION = "-fx * x - fy * y - fz * z". This expression defines the potential energy that OpenMM associates with the user interaction, which yields the correct force when taking the derivative with respect to the position of the atom (and therefore produced the correct dynamics in OpenMM), but calculates the incorrect potential energy for the specific forces applied to the simulation.
The form of this expression also explains why we have been experiencing direction-dependent potential energies, as the expression above accounts only for the xyz coordinates of the atoms, rather than the distance vector between the position of the user interaction and the atom to which it is applied. This means that the sign of the potential energy calculated from this expression changes (and can do so discontinuously) when the force is applied to an atom from the opposite direction. Were this the only issue, the fix would be to replace the expression with -fx * (x - x0) - fy * (y - y0) - fz * (z - z0), where x0,y0,z0 defines the position of the user interaction.
We should clarify in code and comments that IMD_FORCE_EXPRESSION is actually a potential energy expression, and that it is not directly true to the forces, but is only intended to derive to the correct forces
It seems a reason we seem use such a general expression instead of the true energy expression between atom and interaction is because an atom may be affected by multiple instances of multiple force types, and we really just want to apply forces directly to them
We definitely report potential energy incorrectly when forces are applied, but it should be possible to introduce a correction so that we report the right value
This issue arises due to the way that the potential energy associated with the forces being passed to OpenMM by NanoVer is defined, specifically the expression
IMD_FORCE_EXPRESSION = "-fx * x - fy * y - fz * z"
. This expression defines the potential energy that OpenMM associates with the user interaction, which yields the correct force when taking the derivative with respect to the position of the atom (and therefore produced the correct dynamics in OpenMM), but calculates the incorrect potential energy for the specific forces applied to the simulation.The form of this expression also explains why we have been experiencing direction-dependent potential energies, as the expression above accounts only for the xyz coordinates of the atoms, rather than the distance vector between the position of the user interaction and the atom to which it is applied. This means that the sign of the potential energy calculated from this expression changes (and can do so discontinuously) when the force is applied to an atom from the opposite direction. Were this the only issue, the fix would be to replace the expression with
-fx * (x - x0) - fy * (y - y0) - fz * (z - z0)
, where x0,y0,z0 defines the position of the user interaction.