deepmodeling / deepmd-kit

A deep learning package for many-body potential energy representation and molecular dynamics
https://docs.deepmodeling.com/projects/deepmd/
GNU Lesser General Public License v3.0
1.42k stars 486 forks source link

Potential sign mismatch between the reference formula the implementation of the forces and stresses #3674

Closed mtaillefumier closed 3 months ago

mtaillefumier commented 3 months ago

Summary

I am currently working on a deterministic version of this set of functions, prod_force_{a,r}_gpu which is related to the issue #3270. I compared both implementations to the equations found in the PRL paper https://journals.aps.org/prl/supplemental/10.1103/PhysRevLett.120.143001.

After looking at both the CPU and GPU implementation of the forces, I found a possible inconsistency between the code (both on CPU and GPU) and the formula found in the supplementary material. Let me take the CPU variant as all terms are in the same function

the line https://github.com/deepmodeling/deepmd-kit/blob/f8a0b3128e51ee523515cce26e520dde09a973f9/source/lib/src/prod_force.cc#L45 has -= which agrees with the formula in the paper but the line after https://github.com/deepmodeling/deepmd-kit/blob/f8a0b3128e51ee523515cce26e520dde09a973f9/source/lib/src/prod_force.cc#L61 which describes the "non-local" part of the atomic forces contains a += operation in contradiction with the the second part of the formula for the forces.

All terms in the original article contain a minus sign. The code contains -=and +=. the net_deriv which corresponds to the gradient of the energy is calculated here https://github.com/deepmodeling/deepmd-kit/blob/f8a0b3128e51ee523515cce26e520dde09a973f9/deepmd/descriptor/loc_frame.py#L342.

Why is there a sign change between the article and the implementation ?

DeePMD-kit Version

all

Backend and its version

CPU and GPU

Python Version, CUDA Version, GCC Version, LAMMPS Version, etc

No response

Details

see summary

mtaillefumier commented 3 months ago

@asedova

njzjz commented 3 months ago

The equation in the paper contains a typo. $D{jk}^\alpha$ in the first term should be $D{ik}^\alpha$:

image

In the formula $\nabla Ri D{jk}^\alpha$, when $k$ is $i$, it is equal to $-\nabla Rj D{jk}^\alpha$, which introduces a sign change.

mtaillefumier commented 3 months ago

thank you very much. It was not obvious from the formula and the code combined.