CompPhysVienna / n2p2

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

ASE LAMMPSrun with lammps-nnp binary #197

Open TomaSusi opened 8 months ago

TomaSusi commented 8 months ago

I'm trying to do parallel N2P2 calculations using the LAMMPS interface with the neural network potential for water.

I've successfully compiled the lammps-nnp interface and am able to run the example code in n2p2/examples/interface-LAMMPS/H2O_RPBE-D3 directly in LAMMPS via the command line without any issues.

However, when I try to run my own system using the ASE LAMMPSrun interface, I get the error:

ERROR: LAMMPS cutoff via pair_coeff keyword is smaller than maximum symmetry function cutoff.

Thus I think this seems to be an issue with the N2P2 calculator in ASE, which I've posted an issue about there, but I though it might benefit other N2P2 users if they saw this here, too – plus perhaps one of you has insight into the issue!

https://gitlab.com/ase/ase/-/issues/1419

visika commented 7 months ago

I ran into that error when tweaking the runnerCutoff variable. Values as low as 6.0 triggered the error. Higher values are okay. Try setting that to a higher value.

I will paste here the parameters I've been using for comparison. Differently from you, I'm using lammpslib instead of lammpsrun, so you might need to adapt the definition of the variable in your dictionary.

cmd_nn = [
    "#!/bin/bash",
    'variable runnerDir       string "/path/to/train_008"',
    "variable runnerCutoff    equal  8.466835984",
    "pair_style hdnnp ${runnerCutoff} dir ${runnerDir} showew no showewsum 1 resetew yes maxew 200000 cflength 1.889726 cfenergy 0.036749",
    "pair_coeff * * H O",
]
TomaSusi commented 7 months ago

Thanks for the tip! However, I didn't explicitly set runnerCutoff in my scripts, and don't think I can – it seems you are using the ML-HDNNP package instead of the standard N2P2 lammps-nnp interface?

TomaSusi commented 7 months ago

Ahh... now I realize what I did wrong. I was reading the N2P2 interface instructions and trying to translate them into a LAMMPSrun dictionary, but what my syntax:

parameters = {'pair_style': 'nnp showew no showewsum 10 resetew no maxew 100 cflength 1.8897261328 cfenergy 0.0367493254 emap "1:H,2:O"',
              'pair_style': 'nnp dir ' + directory,
              'pair_coeff': ['* * 6.36'],
             }

ended up doing was overriding the first pair_style keyword with the second one, and thus losing the scale normalizations. I still couldn't figure out how to give both the dir and the parameters at the same time, but putting my NN files into the default nnp folder and omitting that line resolves the issue.

I did also have to hack the LAMMPSrun ASCII parsers since that was throwing errors that made this harder to troubleshoot.

TomaSusi commented 7 months ago

Unfortunately my MD runs keep producing unphysically large forces/velocities and crashing LAMMPS, I don't think I saw similar issues with the ASE N2P2 calculator but it could be I was only able to reach longer runs in this system size with the LAMMPS calculator...

visika commented 7 months ago

Unfortunately my MD runs keep producing unphysically large forces/velocities and crashing LAMMPS, I don't think I saw similar issues with the ASE N2P2 calculator but it could be I was only able to reach longer runs in this system size with the LAMMPS calculator...

@TomaSusi Which version of ASE are you using? In the release notes for the master branch (version 3.23.0b1) there is a fix that could interest you:

Fixed conversion of force units between LAMMPS and ASE (MR: !2720)

TomaSusi commented 7 months ago

Hmm... probably slightly older than that, but my crashes started happening after a long while of nice-looking dynamics, so I don't think it could be just a unit error. But I'll try to update to verify, and maybe also just need to look into lammpslib...

TomaSusi commented 7 months ago

No help from updating ASE (and LAMMPS version). LAMMPSlib is probably my last hope, or the MD I am trying to run is simply difficult for the neural network (I'm kicking water molecules around to emulate electron impacts).