Skip to content

Commit

Permalink
Added an example of the direct calculator with metatensor
Browse files Browse the repository at this point in the history
  • Loading branch information
ceriottm committed Nov 11, 2024
1 parent 3398632 commit ee45891
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 3 deletions.
14 changes: 12 additions & 2 deletions examples/clients/metatensor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ machine learning potentials.

## Installation

The code is compatible with metatensor-torch v0.5, which you can install with
The code is compatible with metatensor-torch v0.6, 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.*"
pip install "metatensor-torch ==0.6.*" "metatensor-operations ==0.2.*"
```

## Running the example
Expand All @@ -42,3 +42,13 @@ The options (after `-o`) are as follow:
- `check_consistency` controls whether we should run some extra internal
consistency checks about data given to the model and data returned by the
model.

## Running with FFDirect

It is also possible to run the metatensor PES directly, without the need for an external
driver. To do so, you need to use a `<ffdirect>` clause in the input, and specify
the appropriate options as a dictionary. Then, you can simply run

```bash
i-pi input-direct.xml
```
47 changes: 47 additions & 0 deletions examples/clients/metatensor/input-direct.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<simulation verbosity="medium">
<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>

<ffdirect name='driver'>
<pes> metatensor </pes>
<parameters> {template:nickel.xyz,model:nickel-lj.pt,device:cpu } </parameters>
</ffdirect>

<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>
6 changes: 5 additions & 1 deletion ipi/engine/forcefields.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,11 @@ def __init__(
self.driver = __drivers__[self.pes](verbose=verbosity.high, **pars)

def evaluate(self, request):
request["result"] = list(self.driver(request["cell"][0], request["pos"]))
results = list(self.driver(request["cell"][0], request["pos"].reshape(-1, 3)))
# ensure forces and virial have the correct shape
results[1] = results[1].reshape(-1)
results[2] = results[2].reshape(3, 3)
request["result"] = results
request["status"] = "Done"


Expand Down

0 comments on commit ee45891

Please sign in to comment.