-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to the latest metatensor-torch
- Loading branch information
Showing
10 changed files
with
216 additions
and
124 deletions.
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 @@ | ||
collected-extensions/ | ||
nickel-lj-extensions.pt | ||
|
||
lj-nickel.out | ||
lj-nickel.restart | ||
lj-nickel.xc.xyz | ||
RESTART |
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 |
---|---|---|
@@ -1,16 +1,44 @@ | ||
metatensor - i-PI example | ||
======================== | ||
|
||
Runs a _very_ contrieved example of a metatensor model. | ||
The model is just a hard-coded Einstein crystal model for a | ||
chunk of diamond. No periodic boundary conditions, no ability | ||
to work with a different number of atoms or just a differently | ||
oriented sample. Really, this is just to show how to run the | ||
driver. Given that metatensor model takes a torchsript file | ||
for a model, the very same machinery can be used for actual | ||
ML potentials, or torchscript-implemented models. | ||
# Metatensor example | ||
|
||
Runs an example of a metatensor model, implementing a basic Lennard-Jones model | ||
with the parameters for Nickel. | ||
|
||
This driver can be used with any model following the [metatensor atomistic | ||
models](https://lab-cosmo.github.io/metatensor/latest/atomistic/index.html) | ||
interface. This can be used for classical force-fields, but it more intended for | ||
machine learning potentials. | ||
|
||
## Installation | ||
|
||
The code is compatible with metatensor-torch v0.5, which you can install with | ||
|
||
```bash | ||
# install all metatensor packages simultaneously | ||
pip install "metatensor[torch]" | ||
|
||
# install packages individually, with explicit control over the installed versions | ||
pip install "metatensor-torch ==0.5.*" "metatensor-operations ==0.2.*" | ||
``` | ||
|
||
## Running the example | ||
|
||
```bash | ||
i-pi input.xml; sleep 1 & | ||
i-pi-py_driver -a metatensor -u -m metatensor -o initial.xyz,harmonic-model.pt | ||
i-pi-py_driver -a metatensor -u -m metatensor -o nickel.xyz,nickel-lj.pt | ||
|
||
# with all the optional parameters: | ||
i-pi-py_driver -a metatensor -u -m metatensor -o nickel.xyz,nickel-lj.pt,device=cpu,extensions=some-extensions-dir/,check_consistency=True | ||
``` | ||
|
||
The options (after `-o`) are as follow: | ||
|
||
- the path to a template file, we will use it to get the types for all atoms in | ||
the system | ||
- the path to the model file | ||
- `device` controls which torch device to use to run the model | ||
- `extensions` is the path to a directory containing TorchScript extensions. If | ||
the model requires such extensions, we will try to load them from this | ||
directory first | ||
- `check_consistency` controls whether we should run some extra internal | ||
consistency checks about data given to the model and data returned by the | ||
model. |
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,28 @@ | ||
# Use https://github.com/Luthaf/metatensor-lj-test/ to define a basic LJ model, | ||
# with and without a custom TorchScript extension | ||
import metatensor_lj_test | ||
|
||
# LJ parameters for Ni are taken from https://doi.org/10.1021/jp801931d | ||
model = metatensor_lj_test.lennard_jones_model( | ||
atomic_type=28, | ||
cutoff=6.5, | ||
sigma=2.552, | ||
epsilon=5.65, | ||
length_unit="Angstrom", | ||
energy_unit="kcal/mol", | ||
with_extension=False, | ||
) | ||
|
||
model.export("nickel-lj.pt") | ||
|
||
|
||
model = metatensor_lj_test.lennard_jones_model( | ||
atomic_type=28, | ||
cutoff=6.5, | ||
sigma=2.552, | ||
epsilon=5.65, | ||
length_unit="Angstrom", | ||
energy_unit="kcal/mol", | ||
with_extension=True, | ||
) | ||
model.export("nickel-lj-extensions.pt", collect_extensions="collected-extensions/") |
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,47 @@ | ||
<simulation verbosity="medium"> | ||
<output prefix="harmonic-carbon"> | ||
<properties stride="5" filename="out"> [ step, time{picosecond}, conserved{electronvolt}, | ||
temperature{kelvin}, kinetic_md{electronvolt}, potential{electronvolt}, pressure_md{bar}, volume{angstrom3}, | ||
ensemble_temperature{kelvin}, cell_abcABC] </properties> | ||
<trajectory filename="xc" stride="5" cell_units="angstrom"> x_centroid{angstrom} </trajectory> | ||
<checkpoint stride="1000"/> | ||
</output> | ||
<total_steps> 1000</total_steps> | ||
<prng><seed>12345</seed></prng> | ||
<ffsocket mode='unix' name='driver' pbc="false"> | ||
<latency> 1.00000000e-02</latency> | ||
<slots>4</slots> | ||
<port>12345</port> | ||
<timeout>60.000000e+00</timeout> | ||
<address>metatensor</address> | ||
</ffsocket> | ||
<system> | ||
<initialize nbeads="1"> | ||
<file mode="ase" units="angstrom"> initial.xyz </file> | ||
<velocities mode="thermal" units="kelvin"> 250.0 </velocities> | ||
</initialize> | ||
<forces> | ||
<force forcefield='driver'/> | ||
</forces> | ||
<motion mode="dynamics"> | ||
<dynamics mode="nvt"> | ||
<timestep units="femtosecond"> 0.5 </timestep> | ||
<thermostat mode='gle'> | ||
<A shape='(5,5)'> | ||
[ | ||
4.498098855452e-3, 6.594810718477e-6, 2.788030342989e-4, -8.808265165053e-4, 5.605371493938e-3, | ||
-6.726802271646e-6, 2.079069559861e-9, 1.746169548818e-5, -4.800164465960e-6, 1.025830873432e-5, | ||
-3.586191452340e-4, -1.746169548818e-5, 3.287481976399e-5, 1.245698716799e-4, -2.417657162526e-4, | ||
-2.508912543565e-4, 4.800164465960e-6, -1.245698716799e-4, 6.449207766266e-4, 2.783583234046e-4, | ||
5.273493443008e-3, -1.025830873432e-5, 2.417657162526e-4, -2.783583234046e-4, 7.488477456790e-3 | ||
] | ||
</A> | ||
</thermostat> | ||
</dynamics> | ||
</motion> | ||
<ensemble> | ||
<temperature units="kelvin"> 250.0 </temperature> | ||
</ensemble> | ||
</system> | ||
<output prefix="lj-nickel"> | ||
<properties stride="5" filename="out"> | ||
[step, time{picosecond}, conserved{electronvolt}, temperature{kelvin}, | ||
kinetic_md{electronvolt}, potential{electronvolt}, pressure_md{bar}, | ||
volume{angstrom3}, ensemble_temperature{kelvin}, cell_abcABC] | ||
</properties> | ||
<trajectory filename="xc" stride="5" cell_units="angstrom"> x_centroid{angstrom} </trajectory> | ||
<checkpoint stride="1000"/> | ||
</output> | ||
<total_steps> 1000</total_steps> | ||
<prng><seed>12345</seed></prng> | ||
|
||
<ffsocket mode='unix' name='driver' pbc="false"> | ||
<port>12345</port> | ||
<address>metatensor</address> | ||
</ffsocket> | ||
|
||
<system> | ||
<initialize nbeads="1"> | ||
<file mode="ase" units="angstrom"> nickel.xyz </file> | ||
<velocities mode="thermal" units="kelvin"> 250.0 </velocities> | ||
</initialize> | ||
<forces> | ||
<force forcefield='driver'/> | ||
</forces> | ||
|
||
<motion mode="dynamics"> | ||
<dynamics mode="nvt"> | ||
<timestep units="femtosecond"> 0.5 </timestep> | ||
<thermostat mode='gle'> | ||
<A shape='(5,5)'>[ | ||
4.49e-3, 6.59e-6, 2.79e-4, -8.81e-4, 5.61e-3, | ||
-6.73e-6, 2.08e-9, 1.75e-5, -4.80e-6, 1.03e-5, | ||
-3.59e-4, -1.75e-5, 3.29e-5, 1.24e-4, -2.42e-4, | ||
-2.51e-4, 4.80e-6, -1.24e-4, 6.45e-4, 2.78e-4, | ||
5.27e-3, -1.03e-5, 2.42e-4, -2.78e-4, 7.49e-3 | ||
]</A> | ||
</thermostat> | ||
</dynamics> | ||
</motion> | ||
|
||
<ensemble> | ||
<temperature units="kelvin"> 250.0 </temperature> | ||
</ensemble> | ||
</system> | ||
</simulation> |
Binary file not shown.
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,34 @@ | ||
32 | ||
Lattice="7.2 0.0 0.0 0.0 7.2 0.0 0.0 0.0 7.2" Properties=species:S:1:pos:R:3 pbc="T T T" | ||
Ni 0.04454187 0.15457874 0.12596108 | ||
Ni 0.04370318 1.95000420 1.91184154 | ||
Ni 1.83573509 0.12884331 1.91958398 | ||
Ni 1.92303186 1.89265686 0.07165795 | ||
Ni 0.19190924 0.04701160 3.61889659 | ||
Ni 0.04116880 1.91517186 5.56317915 | ||
Ni 1.91817295 0.03169102 5.58591245 | ||
Ni 1.90862314 1.82490488 3.69025253 | ||
Ni 0.16624021 3.78437918 0.07411722 | ||
Ni 0.11502732 5.41155667 1.80895247 | ||
Ni 1.88561487 3.68501992 1.91533902 | ||
Ni 1.89092684 5.47334069 0.13616005 | ||
Ni 0.13256096 3.78185764 3.77535577 | ||
Ni 0.01409603 5.46866518 5.46642113 | ||
Ni 1.97184883 3.60053345 5.44955058 | ||
Ni 1.95063962 5.40970450 3.62949639 | ||
Ni 3.61636855 0.00654232 0.19947714 | ||
Ni 3.76729948 1.93207137 1.83696219 | ||
Ni 5.47783206 0.09663835 1.87546754 | ||
Ni 5.51789413 1.88532203 0.15452776 | ||
Ni 3.66412964 0.13315923 3.68647837 | ||
Ni 3.71818983 1.96085601 5.43543213 | ||
Ni 5.54731704 0.16090601 5.59503045 | ||
Ni 5.40527227 1.81865617 3.73525599 | ||
Ni 3.77409855 3.77888268 0.04458552 | ||
Ni 3.77575860 5.56995384 1.83599413 | ||
Ni 5.49352058 3.71215650 1.92995287 | ||
Ni 5.53270737 5.51022677 0.07537065 | ||
Ni 3.60323764 3.73888965 3.76030754 | ||
Ni 3.77150406 5.57225362 5.48239838 | ||
Ni 5.48403719 3.68038819 5.43621244 | ||
Ni 5.51535161 5.56333248 3.64169044 |