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

NaN potential energy in LAMMPS #123

Closed omorrison1 closed 2 years ago

omorrison1 commented 3 years ago

I am using N2P2 potentials in LAMMPS to run MD simulations.

Some simulations have functioned correctly, but an increasing number seem to be assigning -nan to the potential energy.

Do you have any idea why this might be occurring or how I might debug it.

image

Thanks, Oliver M

vsumaria commented 3 years ago

Have you checked what it happening to the structures during the MD run? From the error it seems that some atoms have no neighbors meaning the cell might have exploded (mainly due to having a not so good NNP)

omorrison1 commented 2 years ago

The structure never changes from the initial state, as the simulation fails on the first frame. I would take this as indication that the initial structure is wrong, but I've used the same lammps data file for other simulations without issue.

If I instead use the ZBL potential (built in pair style in lammps), then this initial structure is not a problem.

singraber commented 2 years ago

Is the NNP maybe trained with different units (in particular length units)? Have you checked the cutoff radius argument in the LAMMPS script? Can you please attach the LAMMPS log file and the starting configuration?

omorrison1 commented 2 years ago

The NNP was originally trained using the AMP package for python.

It was then converted to N2P2 files.

It was trained using eV and Angstrom units.

Cutoff is 6A and this is reflected in the input.nn file and the lammps script.

Please find the relevant files attached. (data.H2gas_0 is the initial structure and out.X is the lammps log file).

Thanks, Oliver


From: Andreas Singraber @.> Sent: 29 September 2021 11:19 To: CompPhysVienna/n2p2 @.> Cc: Oliver Morrison @.>; Author @.> Subject: Re: [CompPhysVienna/n2p2] NaN potential energy in LAMMPS (#123)

Is the NNP maybe trained with different units (in particular length units)? Have you checked the cutoff radius argument in the LAMMPS script? Can you please attach the LAMMPS log file and the starting configuration?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/CompPhysVienna/n2p2/issues/123#issuecomment-930044412, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AQNITHTLL47MIZVXCCIXATLUELR2XANCNFSM5DEB6NNA. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

This message and any attachment are intended solely for the addressee and may contain confidential information. If you have received this message in error, please contact the sender and delete the email and attachment.

Any views or opinions expressed by the author of this email do not necessarily reflect the views of the University of Nottingham. Email communications with the University of Nottingham may be monitored where permitted by law.

singraber commented 2 years ago

I think attachments are not forwarded to Github if you reply via mail, you'll have to use the web interface.

singraber commented 2 years ago

Have you tried whether the same configuration works with the standalone tool nnp-predict (you'll have to convert to the input.data format)? The error message indicates that the neighbor list of all the atoms is empty. That should of course not happen.. maybe the cutoff radius does not match with the configuration or there is a mismatch in elements <=> LAMMPS types..

omorrison1 commented 2 years ago

Here are the files. Hopefully you can see them this time:

n2p2-simulations.zip

I have not used the nnp-predict tool before. I will have a look at your wiki page for that.

singraber commented 2 years ago

The scaling data is broken:

Scaling data for symmetry functions element  H :
-------------------------------------------------------------------------------
 ind       min       max      mean     sigma        sf  Smin  Smax t
-------------------------------------------------------------------------------
   1  9.59E-01  1.64E+01  8.70E+00  7.74E+00  1.29E-01 -1.00  1.00 1
   2  0.00E+00  0.00E+00  0.00E+00  0.00E+00       INF -1.00  1.00 1
   3  9.60E-01  1.66E+01  8.78E+00  7.82E+00  1.28E-01 -1.00  1.00 1
   4  0.00E+00  0.00E+00  0.00E+00  0.00E+00       INF -1.00  1.00 1
...

You cannot have zeros in both the min and max columns of scaling.data:

#########################################################################################################################
#        1          2                        3                        4                        5                        6
#  e_index   sf_index                   sf_min                   sf_max                  sf_mean                 sf_sigma
#########################################################################################################################
         1          1   9.5884989053533154E-01   1.6432564224973781E+01   8.6957070577545572E+00   7.7368571672192248E+00
         1          2   0.0000000000000000E+00   0.0000000000000000E+00   0.0000000000000000E+00   0.0000000000000000E+00
         1          3   9.6033764775611907E-01   1.6596175329404815E+01   8.7782564885804675E+00   7.8179188408243476E+00
         1          4   0.0000000000000000E+00   0.0000000000000000E+00   0.0000000000000000E+00   0.0000000000000000E+00
...

In this case the scaling factor will be INF and hence everything results in NaNs. You should create the scaling data from a data set which contains both elements, not just H!

Also, are you sure the additional single neuron at the end is intentional? Does that come from the conversion AMP->n2p2?

-------------------------------------------------------------------------------
Atomic short range NN for element  H :
Number of weights    :    721
Number of biases     :     32
Number of connections:    753
Architecture       32   15   15    1    1
-------------------------------------------------------------------------------
   1   G   t   t   t   l
   2   G   t   t
   3   G   t   t
...
omorrison1 commented 2 years ago

Well spotted!

The original AMP file seems to have saved some finger print ranges as (0, 0). I expect this is the root of the problem.

I believe the AMP NNP should have the structure of 32-15-15-1, with the final layer being linear. I'll have a look into that as well.

Thank you for your time and patience. You have given me some direction in fixing this.

Thanks, Oliver M

singraber commented 2 years ago

I'm glad I could give you some hints.. let me know if further problems occur! I'm still a bit surprised by the "low neighbor" warning.. but let's see if that still happens when you have fixed the scaling stuff.

Maybe the second single neuron at the end is indeed intentional, after all there are corresponding weights and biases in the weights.???.data files. It could be due to some additional scaling and shifting of the output in AMP?

All the best, Andi

omorrison1 commented 2 years ago

The function used to convert between AMP and N2P2 is quite new. I may even be the only person using it, so it's possible that the second neuron is just a mistake.

The N2P2 calculator that I showed you is for a H-Mg system. Since the scaling entries are only problematic for Mg related lines, is it possible to strip out the Mg stuff to create an equivalent calculator that will work for a hydrogen only system?

Given how the gaussian descriptors are defined, I think all of the Mg related inputs all reduce to 0 in a hydrogen system anyway?

Thanks, Oliver M


From: Andreas Singraber @.> Sent: 29 September 2021 15:57 To: CompPhysVienna/n2p2 @.> Cc: Oliver Morrison @.>; Author @.> Subject: Re: [CompPhysVienna/n2p2] NaN potential energy in LAMMPS (#123)

I'm glad I could give you some hints.. let me know if further problems occur! I'm still a bit surprised by the "low neighbor" warning.. but let's see if that still happens when you have fixed the scaling stuff.

Maybe the second single neuron at the end is indeed intentional, after all there are corresponding weights and biases in the weights.???.data files. It could be due to some additional scaling and shifting of the output in AMP?

All the best, Andi

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/CompPhysVienna/n2p2/issues/123#issuecomment-930257674, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AQNITHW2LPGZ3SJ2NS7NP3TUEMSORANCNFSM5DEB6NNA. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

This message and any attachment are intended solely for the addressee and may contain confidential information. If you have received this message in error, please contact the sender and delete the email and attachment.

Any views or opinions expressed by the author of this email do not necessarily reflect the views of the University of Nottingham. Email communications with the University of Nottingham may be monitored where permitted by law.

singraber commented 2 years ago

If the NNP has also been trained on H-only data, then you could try to work around the problem by setting some arbitrary non-zero numbers in the scaling.data file, i.e.

#########################################################################################################################
#        1          2                        3                        4                        5                        6
#  e_index   sf_index                   sf_min                   sf_max                  sf_mean                 sf_sigma
#########################################################################################################################
...
         1          2   0.0000000000000000E+00   1.0000000000000000E+00   0.5000000000000000E+00   0.2500000000000000E+00
...
         1          4   0.0000000000000000E+00   1.0000000000000000E+00   0.5000000000000000E+00   0.2500000000000000E+00
...

This will be easier than stripping out the Mg symmetry functions everywhere (keep in mind that you would also need to change the weights.???.data files to remove the Mg input neurons and all associated weights).

However, I cannot guarantee that this has no side-effects that pop up at a later stage.. it would be better to fit a new potential with H-only data!

singraber commented 2 years ago

I saw that you are using the scale_symmetry_functions keyword which means that the formula for entry ST_SCALE documented here applies. Hence, you need to set

scale_min_short 0.0

in input.nn, otherwise the resulting input node value will not be 0.0!!!