Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate virials and stress with vectors to get atomic virial #528

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

pobo95
Copy link

@pobo95 pobo95 commented Jul 21, 2024

Description

Calculate virials and stress with vectors instead of displacement .

Motivation and Formula

Motivation
To get atomic virial for NPT simulations and stress/atom in LAMMPS .

Formula

image

image

How Has It Been Tested?

virials and stress ouput of vectors and displacement are consistent.

image

image

based on MACE ver.0.3.4
You can use with this code to pair LAMMPS

Reference
Yu, H., Zhong, Y., Ji, J., Gong, X. & Xiang, H. Preprint at https://doi.org/10.26434/chemrxiv-2022-h6f69 (2022).

@wcwitt
Copy link
Collaborator

wcwitt commented Jul 23, 2024

Hi @pobo95, would you please email me at [email protected]? I think we should discuss this PR on a Zoom call.

@pobo95
Copy link
Author

pobo95 commented Jul 24, 2024

@wcwitt Yes of course! I just sent you an email.

@ilyes319
Copy link
Contributor

ilyes319 commented Jan 9, 2025

@wcwitt Looked at the PR and it seems great, what do you think?

@yyhb777
Copy link

yyhb777 commented Jan 25, 2025

Firstly, I would like to express my sincere gratitude for your efforts in improving the code. I have attempted to use the code from the atom_virial branch for training, and subsequently employed pair_mace to integrate it with LAMMPS. However, upon running the Green-Kubo simulation in LAMMPS, I encountered the following error:
”Exception:Expected Tensor but got None
Exception raised from reportToTensorTypeError at ../aten/src/ATen/core/ivalue.cpp:950 (most recent call first):
frame #0: c10::Error::Error(c10::SourceLocation, std::string) + 0x57 (0x2ab2a9e87d77 in /share/home/mace_GK/libtorch/lib/libc10.so)
frame #1: c10::detail::torchCheckFail(char const*, char const*, unsigned int, std::string const&) + 0x64 (0x2ab2a9e51abb in /share/home/mace_GK/libtorch/lib/libc10.so)
frame #2: c10::IValue::reportToTensorTypeError() const + 0x58 (0x2ab2add61b98 in /share/home/mace_GK/libtorch/lib/libtorch_cpu.so)
frame #3: /share/home/mace_GK/lammps-mace/build/lmp() [0x8ff28d]
frame #4: /share/home/mace_GK/lammps-mace/build/lmp() [0x607060]
frame #5: /share/home/mace_GK/lammps-mace/build/lmp() [0x593498]
frame #6: /share/home/mace_GK/lammps-mace/build/lmp() [0x4971db]
frame #7: /share/home/mace_GK/lammps-mace/build/lmp() [0x4974bd]
frame #8: /share/home/mace_GK/lammps-mace/build/lmp() [0x488138]
frame #9: __libc_start_main + 0xf5 (0x2ab2c5710c05 in /lib64/libc.so.6)
frame #10: /share/home/mace_GK/lammps-mace/build/lmp() [0x489c67]
application called MPI_Abort(MPI_COMM_WORLD, 1) - process 0“

I am writing to inquire whether this issue might be related to the model I trained still not being able to output the atom virial. Enclosed are my training input files and LAMMPS input files. I look forward to your response.
input.zip

@pobo95
Copy link
Author

pobo95 commented Jan 26, 2025

@yyhb777
Can you show me the log with error_table=PerAtomRMSEstressvirials?
stress/virial information is handled as None if missing, but it seems like there is no stress/virial information during the training process.
Also, could you share your computing environment and training set?

@pobo95
Copy link
Author

pobo95 commented Jan 26, 2025

@yyhb777
Wolud you like to try it with these files?
Si_test.zip

mace_run_train     --name="mace"     --train_file="train.xyz"     --valid_fraction=0.05     --test_file="validate.xyz"     --E0s={14:-0.08755009}     --model="MACE"     --num_interactions=2     --hidden_irreps='64x0e + 64x1o'     --max_L=1     --correlation=2     --r_max=5.0     --forces_weight=1000     --energy_weight=10     --batch_size=5     --valid_batch_size=2     --max_num_epochs=50   --compute_stress=”true”  --start_swa=10     --scheduler_patience=5     --patience=15     --eval_interval=3     --ema     --swa     --swa_forces_weight=10     --default_dtype="float64"    --device=cuda     --seed=123     --restart_latest     --save_cpu --error_table=PerAtomRMSEstressvirials 

@yyhb777
Copy link

yyhb777 commented Jan 26, 2025

@pobo95
I would like to begin by sincerely thanking you for your prompt response. For the sake of clarity, I have used my computational environment to train the Si_test.zip file you provided and have subsequently converted the model for LAMMPS-GK simulations through the create_lammps_model.py script. I have provided the following three files, two of which could not be uploaded due to file size restrictions and will sent to your email. Please check your inbox at your convenience:
1.env_mace_gk.zip: my computational environment.
2.Si_train and MD simulation.zip: The training and MD simulation files for Si_test.zip, which include a detailed README for clarification.
3.software-packages.zip: The software packages employed in the training and MD simulations, with the LAMMPS executable(lmp) located at /lammps-mace/build and the build.sh script used for the compilation process.
Once again, thank you for your valuable time and assistance.
Si_train and MD simulation.zip

@edwardsmith999
Copy link

Hi , thank you @wcwitt, @yyhb777 for the excellent mace code and @pobo95 for the additional to include stresses per atom. Given getting something working with LAMMPS is a little tricky (especially with C++ code, the variation in LAMMPS version, limited python support, etc, etc), it would be useful as a first step to simply get the get_stresses working in the ASE code. I have merged pobo95 code into the latest main branch in a forked version here https://github.com/edwardsmith999/mace (with a little uncertainty about if batch/displacement arguments are replaced needed). I have then added the required code so ASE has the get_stresses function working. This satisfies the conditions:

atoms.cell.volume*atoms.get_stress() == np.sum(atoms.get_stresses(),0)

I don't want to overwrite pobo95's contribution or confuse things with another pull request but it would be useful to have this functionality in if possible. Please let me know if I can help further getting this included.

@pobo95
Copy link
Author

pobo95 commented Mar 13, 2025

Hi! @edwardsmith999
Thanks for your work on this! I really appreciate you taking the time to merge and improve the functionality. If everything is working correctly and aligns with what you need, feel free to proced.
I don't mind how this gets integrated, just let me know if you need any input from my side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants