CompPhysVienna / n2p2

n2p2 - A Neural Network Potential Package
https://compphysvienna.github.io/n2p2/
GNU General Public License v3.0
217 stars 82 forks source link

Compute pe/atom in LAMMPS interface does not include normalization offset #131

Closed owenrett closed 2 years ago

owenrett commented 2 years ago

Describe the bug The command compute pe/atom (atom specific energy) in lammps returns the potential energy without either the normalization offset ("mean_energy"), nor the atom energy offset ("atom_energy"). The command compute pe (total system energy) appears to include these offsets. For a small scale system (96 atoms, 3 species, Zr Ce O) the energies returned by compute pe/atom (reduced and summed) are:

Relevant input.nn Settings mean_energy: -3.3958016388641306E+00 atom_energy Zr -7.73537698 atom_energy Ce -4.63794868 atom_energy O -1.54279418

System Setup N_Zr N_Ce N_O 28 4 64

LAMMPS: computing energies per atom compute ZrEnA ZrGp pe/atom compute ZrEn ZrGp reduce sum c_ZrEnA

ZrEn = -210.00812 CeEn = 4.1838487 OEn = 211.13337

Computing total energy compute peAll all pe -654.24414

Comparing Zr_En_Sum + N_Zr Mean_Energy + N_Zr atom_energy_Zr = -210.00812 + 28 -3.395 + 28 -7.735 = -522.715 Ce_En_Sum + N_Ce Mean_Energy + N_Ce atom_energy_Ce = 4.1838487 + 4 -3.395 + 4 -4.637 = -27.584 O_En_Sum + N_O Mean_Energy + N_O atom_energy_O = 211.13337 + 64 -3.395 + 64 - 1.543 = -103.944

(-522.715) + (-27.584) + (-103.944) = -654.24414

To Reproduce Steps to reproduce the behavior:

  1. Which git commit version is used? commit 293a6a2
  2. What are the compilation options (compiler, flags)? Standard Intel Compilation with: PROJECT_CFLAGS=-O3 -xHost -std=c++11 -ipo -xSSSE3 -axSSE4.2,AVX,CORE-AVX-I,CORE-AVX2
  3. Which application is affected? LAMMPS-n2p2 interface
  4. What are the actual settings (please provide a minimal example if possible)? I have attached the input.nn, md.lmp, and log.lammps files.
  5. Please provide the error message or describe the crash behavior. No Error Message given; compute pe/atom does not match compute pe when summed

Expected behavior A clear and concise description of what you expected to happen. Expect compute pe/atom to match `compute pe when per atom energies are summed. This issue can be fixed in post if energies calculated are necessary, however I figured that it should be brought to your attention.

Additional context The relevant files have been attached below.

md_NETO.lmp.txt log.lammps.txt input.nn.txt


My apologies if the information here is not enough or formatted incorrectly. I have not submitted many issues through github before. I had drafted this issue for a significantly larger system before reporting for a smaller system, so some numbers may be slightly off; I am trying to fix them.

-Owen Rettenmaier

owenrett commented 2 years ago

I realize I forgot to attach the lammps structure file to the issue. I have attached it here.

Ce12_M_S.lmp.txt

singraber commented 2 years ago

Hello Owen!

thank you very much for this carefully prepared bug report, your effort makes it really much easier for me to follow the description and trace back the origin. I greatly appreciate that :-)!

I just submitted a commit (https://github.com/CompPhysVienna/n2p2/commit/e3ee6abef466d8d313f5b1d4bda421a444d3e4a0) to the master branch which should fix the problem, could you please test if that is the case? (I cannot because I would need also the weights.???.data and scaling.data files.)

Thanks a lot for catching this!

Best, Andreas Singraber

owenrett commented 2 years ago

My apologies on the delay; had a bug on my system related to openmpi, so took a while to recompile. The energies on a per atom and system basis seem to agree now; that is both are giving equivalent values.