CederGroupHub / chgnet

Pretrained universal neural network potential for charge-informed atomistic modeling https://chgnet.lbl.gov
https://doi.org/10.1038/s42256-023-00716-3
Other
220 stars 60 forks source link

LAMMPS interface for CHGNet #57

Open advancesoftcorp opened 1 year ago

advancesoftcorp commented 1 year ago

Dear developers of CHGNet,

We have developed the interface of LAMMPS for CHGNet: https://github.com/advancesoftcorp/lammps/tree/based-on-lammps_2Jun2022/src/ML-CHGNET It would be great that it will interest you.

Best Regards, Satomichi Nishihara AdvanceSoft Corp.

BowenD-UCB commented 1 year ago

Thanks a lot! We appreciate your efforts. This will be very valuable to users familiar with lammps.

janosh commented 1 year ago

@advancesoftcorp Thank you very much! I assume you've tested the CHGNet interface on an example system? Are you able the share the code for that? We'd be happy to add that to our example notebooks as a starting guide for LAMMPS users.

advancesoftcorp commented 1 year ago

We have tested the CHGNet interface for ZrO2, which input file is here: https://github.com/advancesoftcorp/lammps/tree/based-on-lammps_2Jun2022/examples/CHGNET

BowenD-UCB commented 1 year ago

@advancesoftcorp Thanks again! I see the CHGNet driver file has a input argument for loading different CHGNet weights. def chgnet_initialize(model_name = None, dftd3 = False, gpu = True):

Say, now we have another CHGNet that can be loaded like myCHGNet = CHGNet.load('new_model') Could you please share how is it possible to use this model_name key to load different CHGNet in the inp.lammps input file?

advancesoftcorp commented 1 year ago

You can set the model_name at the line of pair_coeff as https://github.com/advancesoftcorp/lammps/blob/22fc3bec34a10c095222b281714af27bedd1677d/examples/CHGNET/inp.lammps#L24C1-L24C36

advancesoftcorp commented 1 year ago

Now, we have already developed the GUI of LAMMPS/CHGNet as the following figure. Please let us know the name of "new_model", if you have already defined it. The GUI is our product of Advance/NanoLabo: https://www.nanolabo.advancesoft.jp/en/

WS000000

BowenD-UCB commented 1 year ago

@advancesoftcorp Currently CHGNet.load() method only supports loading the MPtrj pretrained CHGNet. When users load their own fine-tuned model, it's loaded through CHGNet.from_file('weight_path') If there can be an interface to load CHGNet from a local path with CHGNet.from_file in the inp.lammps that will be helpful.

advancesoftcorp commented 1 year ago

@BowenD-UCB I did it.

chgnet_driver.py -> https://github.com/advancesoftcorp/lammps/blob/1ab512916a99e38b46d1d8a6660b0212da95592f/src/ML-CHGNET/chgnet_driver.py#L41C6-L41C6

inp.lammps -> https://github.com/advancesoftcorp/lammps/blob/1ab512916a99e38b46d1d8a6660b0212da95592f/examples/CHGNET/inp.lammps#L25

BowenD-UCB commented 1 year ago

This looks great, thanks!

FuXiao-153 commented 11 months ago

@advancesoftcorp Thank you very much for developing this interface! When I installed the 2JUN2022 version of LAMMPS, some problems occurred. I can run the program using other pair style, but CHGNet fails. I was wondering if the installation of this version is different from the installation of other versions of LAMMPS?

advancesoftcorp commented 11 months ago

Did you make yes-ML-CHGNET, before compile LAMMPS ?

FuXiao-153 commented 11 months ago

@advancesoftcorp yes,before compiling LAMMPS,we completed making yes-[KSPACE/ MANYBODY/ ML-CHGNET/ MOLECULE/ PYTHON/ RIGID].

advancesoftcorp commented 11 months ago

It seems you did not set LD_LIBRARY_PATH for python or compilation was not correct.

FuXiao-153 commented 11 months ago

@advancesoftcorp Sorry to bother you again, we set LD_LIBRARY_PATH for python in .bashrc and have tried different ways of compilation, the program still reported the same error:


LAMMPS (2 Jun 2022)
  using 1 OpenMP thread(s) per MPI task
Reading data file ...
  triclinic box = (0 0 0) to (25.256318 25.844557 25.363354) with tilt (0.997650                                                       81 -1.0715861 1.0101746)
  1 by 1 by 1 MPI processor grid
  reading atoms ...
  1280 atoms
  read_data CPU = 0.036 seconds
Segmentation fault

Could you please help us check the cause of the error? Thank you very much

advancesoftcorp commented 11 months ago

You have to resolve the problem by yourself, because I cannot see what you see.

mhsiron commented 9 months ago

Hello @advancesoftcorp I am using CHGnet plug-in that you have built in LAMMPS mostly successfully. However when the amount of atoms changes such as with a fix dep command (like so): fix dep0 adatom deposit 100 0 20 7087 region deposregion near 3 mol molec vz -410.8341 -502.1306 vx -0.0 -0.0 vy -0.0 -0.0

I run into the following error due to the number of atoms changing:

ValueError: Array "numbers" has wrong shape (772,) != (768,).
ERROR: Cannot calculate energy, forces and stress by python of CHGNet. (src/ML-CHGNET/pair_chgnet.cpp:672)

I was able to get the code to still work by changing line 92 in chgnet_driver.py from: global myAtoms to myAtoms = None

I'm wondering if there is any downstream effect you suspect from this and why myAtoms was made a global variable?

advancesoftcorp commented 9 months ago

@mhsiron Thank you for pointing out the bug. As you said, chgnet_driver.py did not support atomic depositions or grand canonical ensembles. But I fix it now: https://github.com/advancesoftcorp/lammps/blob/d3dc7730a0f2640eb725015e9edaa0b74b222d81/src/ML-CHGNET/chgnet_driver.py#L96

myAtoms is still a global variable, to avoid multiply creating instances of ase.Atoms for speed-up.

heroiciota commented 9 months ago

@advancesoftcorp Hi, When I use your software named Nanalabo pro, which I got licence from your guys days before, to run my own cif structrue, it reminds me _"Traceback (most recent call last):File "C:\Program Files\AdvanceSoft\NanoLabo\chgnet\chgnetdriver.py", line 11, in from chgnet.model import CHGNet, CHGNetCalculator ModuleNotFoundError: No module named 'chgnet.model',And I went to log file , there is an ERROR: _'Cannot initialize python for pair_coeff of CHGNet. (../pairchgnet.cpp:503)' hope to get you guys reply sooner, thx you anyway.

advancesoftcorp commented 9 months ago

@heroiciota It seems that you did not install chgnet into your machine. Do "pip install chgnet".

heroiciota commented 9 months ago

@advancesoftcorp Thx!Actually,I have had chgnet installed. But somehow my system can't point to the right environment. I am struggling with it, hopefully I would fix it today.

heroiciota commented 8 months ago

@FuXiao-153 @advancesoftcorp I met the same problem :unrecognized pair style 'chgnet/d3' is part of the ML-CHGNET package which is not enabled in this LAMMPS binary. (../force.cpp:271)Last command: pair_style chgnet/d3 ../../potentials/CHGNET I wonder did any one succeed in running the example? Can anyone share the experience of it . Also , I have my ML-CHGNET package installed too. Appreciate.

Mofahdi commented 3 months ago

I have an error here: it seems that TypeError: chgnet_initialize() takes from 0 to 3 positional arguments but 4 were given

This is what I wrote in my input file which is the same as the tutorial ERROR: Cannot initialize python for pair_coeff of CHGNet. (src/lammps_releases/advancesoftcorp/lammps/src/ML-CHGNET/pair_chgnet.cpp:519) Last command: pair_coeff 0.3.0 Zr O How can I solve this issue?

advancesoftcorp commented 3 months ago

@heroiciota it seems you did NOT make yes-ML-CHGNET.

advancesoftcorp commented 3 months ago

@Mofahdi the chgnet_driver.py that you had used may be broken.

naji-usr commented 2 months ago

@advancesoftcorp Thank you!If installed in HPC, how can I run parallel calculations (at least is there any way to speed it up!) .

advancesoftcorp commented 2 months ago

@naji-usr you cannot use MPI parallel. but OpenMP is available.

naji-usr commented 2 months ago

Thank you @advancesoftcorp it works.