Skip to content

Commit

Permalink
Added i-PI inputs and tweaked model parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
ceriottm committed Oct 12, 2024
1 parent 3591057 commit 2682b7e
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 16 deletions.
39 changes: 39 additions & 0 deletions examples/metatensor-plumed/data/input-md.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<simulation safe_stride='10' verbosity='medium'>
<ffsocket mode='unix' name='driver'>
<latency> 1.00000000e-04</latency> <address>lj-driver</address>
</ffsocket>
<total_steps>5000</total_steps>
<output prefix="base-md">
<trajectory stride="10" filename="pos" cell_units="atomic_unit">positions{atomic_unit}</trajectory>
<properties stride="10">
[ step, time, conserved, temperature, kinetic_md, potential, ensemble_bias ]
</properties>
</output>
<prng>
<seed>18885</seed>
</prng>
<system>
<forces>
<force forcefield="driver"></force>
</forces>
<initialize nbeads="1">
<file mode="xyz">data/lj38.xyz</file>
<masses mode="manual"> [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]</masses>
<cell>
[ 100, 0, 0, 0, 100, 0, 0, 0, 100 ]
</cell>
</initialize>
<ensemble>
<temperature units="atomic_unit"> 0.30 </temperature>
</ensemble>
<motion mode="dynamics">
<fixcom> False </fixcom>
<dynamics mode="nvt">
<timestep units="atomic_unit"> 0.02 </timestep>
<thermostat mode="langevin">
<tau units="atomic_unit"> 10 </tau>
</thermostat>
</dynamics>
</motion>
</system>
</simulation>
51 changes: 51 additions & 0 deletions examples/metatensor-plumed/data/input-meta.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<simulation safe_stride='10' verbosity='medium'>
<ffsocket mode='unix' name='driver'>
<latency> 1.00000000e-04</latency> <address>lj-driver</address>
</ffsocket>
<ffplumed name="plumed">
<file mode="xyz">data/lj38.xyz</file>
<plumeddat> data/plumed.dat </plumeddat>
<plumed_extras> [cv1, cv2, mtd.bias ] </plumed_extras>
</ffplumed>
<total_steps>5000</total_steps>
<output prefix="meta-md">
<trajectory stride="10" filename="pos" cell_units="atomic_unit">positions{atomic_unit}</trajectory>
<trajectory stride="10" filename="colvar" bead="0" extra_type="cv1,cv2,mtd.bias"> extras_bias </trajectory>
<properties stride="10">
[ step, time, conserved, temperature, kinetic_md, potential, ensemble_bias ]
</properties>
</output>
<prng>
<seed>18885</seed>
</prng>
<system>
<forces>
<force forcefield="driver"></force>
</forces>
<initialize nbeads="1">
<file mode="xyz">data/lj38.xyz</file>
<masses mode="manual"> [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]</masses>
<cell>
[ 100, 0, 0, 0, 100, 0, 0, 0, 100 ]
</cell>
</initialize>
<ensemble>
<temperature units="atomic_unit"> 0.30 </temperature>
<bias>
<force forcefield="plumed"/>
</bias>
</ensemble>
<motion mode="dynamics">
<fixcom> False </fixcom>
<dynamics mode="nvt">
<timestep units="atomic_unit"> 0.02 </timestep>
<thermostat mode="langevin">
<tau units="atomic_unit"> 10 </tau>
</thermostat>
</dynamics>
</motion>
</system>
<smotion mode="metad">
<metad> <metaff> [ plumed ] </metaff> </metad>
</smotion>
</simulation>
40 changes: 40 additions & 0 deletions examples/metatensor-plumed/data/lj38.xyz
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
38
# Step 100000000
Ar 1.4267876E+000 2.9212078E+000 1.0701605E+000
Ar -6.1336159E-001 1.3366171E+000 9.8967797E-001
Ar -7.1959392E-002 1.9963731E+000 2.9199481E-001
Ar 1.4336444E+000 1.1270242E+000 1.0450441E+000
Ar 2.2149714E+000 1.7976783E+000 2.1410531E+000
Ar 1.3734694E+000 2.6020966E+000 2.6952938E+000
Ar 9.1665725E-001 1.3886509E-001 1.2365719E+000
Ar 3.1414994E-001 3.7667848E+000 2.3424693E+000
Ar 9.8263797E-001 2.0201570E+000 6.6390178E-001
Ar 4.1439813E-001 1.0970310E+000 7.5153475E-001
Ar -1.0887056E+000 5.8302904E-001 1.8687178E+000
Ar 2.8615674E-001 2.9154779E+000 7.1026823E-001
Ar -3.3917867E-001 3.4038120E+000 1.4536682E+000
Ar -3.8905351E-001 1.9077154E+000 3.1118603E+000
Ar -6.7077782E-001 3.3591081E+000 2.6207557E+000
Ar -1.1449957E-001 5.0378829E-001 1.5028689E+000
Ar -5.4573740E-001 3.8732958E-001 2.8483650E+000
Ar 1.6481073E-001 1.9170175E+000 1.3753046E+000
Ar 5.1444560E-001 1.9761151E+000 2.4004309E+000
Ar -6.9012030E-001 2.4364761E+000 1.0438342E+000
Ar -1.3149162E+000 3.0291069E+000 1.8041757E+000
Ar 2.1566535E+000 2.0243254E+000 9.8121294E-001
Ar 1.3838741E+000 3.6177568E+000 2.0154838E+000
Ar 2.1685344E+000 2.8098050E+000 1.8275828E+000
Ar -1.3254347E+000 1.2746350E+000 2.7507219E+000
Ar 1.3956249E+000 1.3881537E+000 2.6916380E+000
Ar -1.3201815E+000 2.4262575E+000 2.6909376E+000
Ar 3.4406330E-001 1.0391058E+000 2.9605370E+000
Ar 3.0221745E-001 2.8678386E+000 2.9556254E+000
Ar 5.7627097E-001 2.8893057E+000 1.8005862E+000
Ar 7.7447852E-001 2.0078518E+000 3.4195584E+000
Ar 6.2013735E-001 4.8378593E-002 2.3725838E+000
Ar 1.2838145E+000 2.0173886E+000 1.6958543E+000
Ar -1.2221551E+000 1.8286569E+000 1.7668366E+000
Ar 7.0190189E-001 3.8124480E+000 1.2117366E+000
Ar -3.5844585E-001 1.3234871E+000 2.1555337E+000
Ar 7.0158765E-001 1.0394241E+000 1.8553935E+000
Ar -4.3723088E-001 2.3968664E+000 2.1187988E+000
12 changes: 12 additions & 0 deletions examples/metatensor-plumed/data/plumed.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# default (nm, kJ/mol) to atomic
UNITS LENGTH=0.052917721 ENERGY=0.00038087988
cv: METATENSOR MODEL=custom-cv.pt EXTENSIONS_DIRECTORY=./extensions/ SPECIES1=1-38 SPECIES_TO_TYPES=18
# extract the different components from METATENSOR output into scalar
# (METAD only accepts scalars, and METATENSOR output is a vector here)
cv1: SELECT_COMPONENTS ARG=cv COMPONENTS=1
cv2: SELECT_COMPONENTS ARG=cv COMPONENTS=2
# run metadynamics with this collective variable
mtd: METAD ARG=cv1,cv2 HEIGHT=0.05 PACE=50 SIGMA=1,2.5 GRID_MIN=-20,-40 GRID_MAX=20,40 GRID_BIN=500,500 BIASFACTOR=5 FILE=HILLS TEMP=0.18
# prints out trajectory
PRINT ARG=cv1,cv2,mtd.* STRIDE=10 FILE=COLVAR
FLUSH STRIDE=1
40 changes: 24 additions & 16 deletions examples/metatensor-plumed/lj-crystal.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"""

import os
os.environ["PLUMED_KERNEL"] = "PLEASE SET THIS!"
os.environ["PLUMED_KERNEL"] = os.path.join(os.environ["HOME"],"lavoro/source/plumed-conda-metatensor/src/lib/libplumedKernel.so")


from typing import Dict, List, Optional
Expand Down Expand Up @@ -90,9 +90,9 @@ def __init__(self, cutoff, angular_list):

self.max_angular = max(angular_list)
# initialize and store the rascaline calculator inside the class
self.soap = rascaline.torch.SphericalExpansion(
self.spex = rascaline.torch.SphericalExpansion(
cutoff=cutoff,
max_radial=6,
max_radial=4,
max_angular=self.max_angular,
atomic_gaussian_width=0.3,
radial_basis={"Gto": {}},
Expand All @@ -111,11 +111,11 @@ def forward(
) -> Dict[str, mts.TensorMap]:

# execute the same code as above
soap = self.soap(
spex = self.spex(
systems, selected_samples=selected_atoms, selected_keys=self.selected_keys
)

if len(soap) == 0:
if len(spex) == 0:
# PLUMED will first call the model with 0 atoms to get the size of the
# output, so we need to handle this case first
keys = mts.Labels("_", torch.tensor([[0]]))
Expand All @@ -126,23 +126,24 @@ def forward(
properties=self.selected_keys,
)
return {"features": mts.TensorMap(keys, [block])}

spex = mts.remove_dimension(spex, axis="keys", name="o3_sigma")
spex = spex.keys_to_properties("neighbor_type")
spex = spex.keys_to_samples("center_type")

soap = mts.remove_dimension(soap, axis="keys", name="o3_sigma")
soap = soap.keys_to_properties("neighbor_type")
soap = soap.keys_to_samples("center_type")
spex = mts.sum_over_samples(spex, sample_names=["atom", "center_type"])

soap = mts.sum_over_samples(soap, sample_names=["atom", "center_type"])
blocks: List[mts.TensorBlock] = []
for block in soap.blocks():
for block in spex.blocks():
new_block = mts.TensorBlock(
block.values.sum(dim=(1, 2)).reshape(-1, 1),
(block.values**2).sum(dim=(1, 2)).reshape(-1, 1),
samples=block.samples,
components=[],
properties=mts.Labels("n", torch.tensor([[0]])),
)
blocks.append(new_block)

summed_q = mts.TensorMap(soap.keys, blocks)
summed_q = mts.TensorMap(spex.keys, blocks)
summed_q = summed_q.keys_to_properties("o3_lambda")

# This model has a single output, named "features". This can be used by multiple
Expand All @@ -160,7 +161,7 @@ def forward(
# See [TODO link] for more information about exporting metatensor models.

# initialize the model
cutoff = 3.5
cutoff = 1.3
module = CollectiveVariable(cutoff, angular_list=[4, 6])

# metatdata about the model itself
Expand Down Expand Up @@ -216,17 +217,24 @@ def forward(
"cv2: SELECT_COMPONENTS ARG=cv COMPONENTS=2",
# run metadynamics with this collective variable
"""
METAD
mtd: METAD
ARG=cv1,cv2
HEIGHT=0.05
PACE=50
SIGMA=1,2.5
GRID_MIN=-5,-40
GRID_MAX=15,10
GRID_MIN=-20,-40
GRID_MAX=20,40
GRID_BIN=500,500
BIASFACTOR=5
FILE=HILLS
""",
# prints out trajectory
"""
PRINT ARG=cv.*,mtd.* STRIDE=10 FILE=COLVAR
""",
"""
FLUSH STRIDE=1
"""
]

atoms.calc = ase.calculators.plumed.Plumed(
Expand Down

0 comments on commit 2682b7e

Please sign in to comment.