-
Notifications
You must be signed in to change notification settings - Fork 4
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
ZBL short-range potential #335
Merged
Merged
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
498e566
ZBL potential (not integrated into any architecture yet)
frostedoyster 55847c7
Fix docs?
frostedoyster 396a67c
Integrate ZBL into models
frostedoyster bfe2959
Incorporate into SOAP-BPNN trainer
frostedoyster f193378
Merge branch 'main' into zbl
frostedoyster b15ab35
Integrate into GAP and Alchemical trainers
frostedoyster 78f476c
Fix gradient training
frostedoyster ee028dc
Add ZBL tutorial
frostedoyster 52ffa9a
Add explanation for the H-H curve
frostedoyster 35b7b41
Fix PET hyperparameter
frostedoyster d62fbc2
Fix GAP tests
frostedoyster 3ae490d
Fix bugg
frostedoyster 5b297c5
Improve tutorial
frostedoyster 43dbc23
New function to find all requested neighbor lists in a model
frostedoyster 18c87ad
Add NL request for ZBL
frostedoyster 603daa0
Fix PET
frostedoyster 1b6726b
Warn about covalent radii not known by ASE
frostedoyster b9cf4f9
Fix ZBL test
frostedoyster a596b1b
Merge branch 'main' into zbl
frostedoyster b3072e6
Update interaction ranges + docs + more testing
frostedoyster 82f55f0
Merge branch 'main' into zbl
frostedoyster 51d0108
Merge branch 'main' into zbl
frostedoyster 02dd91c
Change docs section title
frostedoyster File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Composition model | ||
################# | ||
|
||
.. automodule:: metatrain.utils.additive.composition | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Data | ||
==== | ||
|
||
API for handling additive models in ``metatrain``. These are models that | ||
can be added to one or more architectures. | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
|
||
remove_additive | ||
composition | ||
zbl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Removing additive contributions | ||
############################### | ||
|
||
.. automodule:: metatrain.utils.additive.remove | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
ZBL short-range potential | ||
######################### | ||
|
||
.. automodule:: metatrain.utils.additive.zbl | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,11 +42,6 @@ | |
|
||
# %% | ||
# | ||
# .. note:: | ||
# We have to import ``rascaline.torch`` even though it is not used explicitly in this | ||
# tutorial. The SOAP-BPNN model contains compiled extensions and therefore the import | ||
# is required. | ||
# | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎉 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well spotted, thanks! |
||
# Setting up the simulation | ||
# ------------------------- | ||
# | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Running molecular dynamics with ASE | ||
=================================== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
""" | ||
Training a model with ZBL corrections | ||
===================================== | ||
|
||
This tutorial demonstrates how to train a model with ZBL corrections. | ||
|
||
The training set for this example consists of a | ||
subset of the ethanol moleculs from the `rMD17 dataset | ||
<https://iopscience.iop.org/article/10.1088/2632-2153/abba6f/meta>`_. | ||
|
||
The models are trained using the following training options, respectively: | ||
|
||
.. literalinclude:: options_no_zbl.yaml | ||
:language: yaml | ||
|
||
.. literalinclude:: options_zbl.yaml | ||
:language: yaml | ||
|
||
As you can see, they are identical, except for the ``zbl`` key in the | ||
``model`` section. | ||
You can train the same models yourself with | ||
|
||
.. literalinclude:: train.sh | ||
:language: bash | ||
|
||
A detailed step-by-step introduction on how to train a model is provided in | ||
the :ref:`label_basic_usage` tutorial. | ||
""" | ||
|
||
# %% | ||
# | ||
# First, we start by importing the necessary libraries, including the integration of ASE | ||
# calculators for metatensor atomistic models. | ||
|
||
import ase | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
import torch | ||
from metatensor.torch.atomistic.ase_calculator import MetatensorCalculator | ||
|
||
|
||
# %% | ||
# | ||
# Setting up the dimers | ||
# --------------------- | ||
# | ||
# We set up a series of dimers with different atom pairs and distances. We will | ||
# calculate the energies of these dimers using the models trained with and without ZBL | ||
# corrections. | ||
|
||
distances = np.linspace(0.5, 6.0, 200) | ||
pairs = {} | ||
for pair in [("H", "H"), ("H", "C"), ("C", "C"), ("C", "O"), ("O", "O"), ("H", "O")]: | ||
structures = [] | ||
for distance in distances: | ||
atoms = ase.Atoms( | ||
symbols=[pair[0], pair[1]], | ||
positions=[[0, 0, 0], [0, 0, distance]], | ||
) | ||
structures.append(atoms) | ||
pairs[pair] = structures | ||
|
||
# %% | ||
# | ||
# We now load the two exported models, one with and one without ZBL corrections | ||
|
||
calc_no_zbl = MetatensorCalculator( | ||
"model_no_zbl.pt", extensions_directory="extensions/" | ||
) | ||
calc_zbl = MetatensorCalculator("model_zbl.pt", extensions_directory="extensions/") | ||
|
||
|
||
# %% | ||
# | ||
# Calculate and plot energies without ZBL | ||
# --------------------------------------- | ||
# | ||
# We calculate the energies of the dimer curves for each pair of atoms and | ||
# plot the results, using the non-ZBL-corrected model. | ||
|
||
for pair, structures_for_pair in pairs.items(): | ||
energies = [] | ||
for atoms in structures_for_pair: | ||
atoms.set_calculator(calc_no_zbl) | ||
with torch.jit.optimized_execution(False): | ||
energies.append(atoms.get_potential_energy()) | ||
energies = np.array(energies) - energies[-1] | ||
plt.plot(distances, energies, label=f"{pair[0]}-{pair[1]}") | ||
plt.title("Dimer curves - no ZBL") | ||
plt.xlabel("Distance (Å)") | ||
plt.ylabel("Energy (eV)") | ||
plt.legend() | ||
plt.tight_layout() | ||
plt.show() | ||
|
||
# %% | ||
# | ||
# Calculate and plot energies from the ZBL-corrected model | ||
# -------------------------------------------------------- | ||
# | ||
# We repeat the same procedure as above, but this time with the ZBL-corrected model. | ||
|
||
for pair, structures_for_pair in pairs.items(): | ||
energies = [] | ||
for atoms in structures_for_pair: | ||
atoms.set_calculator(calc_zbl) | ||
with torch.jit.optimized_execution(False): | ||
energies.append(atoms.get_potential_energy()) | ||
energies = np.array(energies) - energies[-1] | ||
plt.plot(distances, energies, label=f"{pair[0]}-{pair[1]}") | ||
plt.title("Dimer curves - with ZBL") | ||
plt.xlabel("Distance (Å)") | ||
plt.ylabel("Energy (eV)") | ||
plt.legend() | ||
plt.tight_layout() | ||
plt.show() | ||
|
||
# %% | ||
# | ||
# It can be seen that all the dimer curves include a strong repulsion | ||
# at short distances, which is due to the ZBL contribution. Even the H-H dimer, | ||
# whose ZBL correction is very weak due to the small covalent radii of hydrogen, | ||
# would show a strong repulsion closer to the origin (here, we only plotted | ||
# starting from a distance of 0.5 Å). Let's zoom in on the H-H dimer to see | ||
# this effect more clearly. | ||
|
||
new_distances = np.linspace(0.1, 2.0, 200) | ||
|
||
structures = [] | ||
for distance in new_distances: | ||
atoms = ase.Atoms( | ||
symbols=["H", "H"], | ||
positions=[[0, 0, 0], [0, 0, distance]], | ||
) | ||
structures.append(atoms) | ||
|
||
for atoms in structures: | ||
atoms.set_calculator(calc_zbl) | ||
with torch.jit.optimized_execution(False): | ||
energies = [atoms.get_potential_energy() for atoms in structures] | ||
energies = np.array(energies) - energies[-1] | ||
plt.plot(new_distances, energies, label="H-H") | ||
plt.title("Dimer curve - H-H with ZBL") | ||
plt.xlabel("Distance (Å)") | ||
plt.ylabel("Energy (eV)") | ||
plt.legend() | ||
plt.tight_layout() | ||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../ase/ethanol_reduced_100.xyz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
seed: 42 | ||
|
||
architecture: | ||
name: experimental.soap_bpnn | ||
model: | ||
zbl: false | ||
training: | ||
num_epochs: 10 | ||
|
||
# training set section | ||
training_set: | ||
systems: | ||
read_from: ethanol_reduced_100.xyz | ||
length_unit: angstrom | ||
targets: | ||
energy: | ||
key: "energy" | ||
unit: "eV" # very important to run simulations | ||
|
||
validation_set: 0.1 | ||
test_set: 0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
seed: 42 | ||
|
||
architecture: | ||
name: experimental.soap_bpnn | ||
model: | ||
zbl: true | ||
training: | ||
num_epochs: 10 | ||
|
||
# training set section | ||
training_set: | ||
systems: | ||
read_from: ethanol_reduced_100.xyz | ||
length_unit: angstrom | ||
targets: | ||
energy: | ||
key: "energy" | ||
unit: "eV" # very important to run simulations | ||
|
||
validation_set: 0.1 | ||
test_set: 0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
|
||
mtt train options_no_zbl.yaml -o model_no_zbl.pt | ||
mtt train options_zbl.yaml -o model_zbl.pt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ model: | |
bpnn: | ||
hidden_sizes: [32, 32] | ||
output_size: 1 | ||
zbl: false | ||
|
||
training: | ||
batch_size: 8 | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Title seems wrong for this section