Open In Colab

Water on NaCl surface

Set up environment (optional)

These steps are required for Google Colab, but may work on other systems too:

[1]:
#import locale
#locale.getpreferredencoding = lambda: "UTF-8"
#!python3 -m pip install pack-mm data-tutorials weas-widget

let us start by creating a box of NaCl with vaccum

[2]:
from weas_widget import WeasWidget
from ase.build import bulk

NaCl = bulk("NaCl", "rocksalt", a=5.61, cubic=True)
NaCl_super = NaCl*(3,3,3)
cell = NaCl_super.get_cell()
cell[2] *=3
NaCl_super.set_cell(cell)
NaCl_super.center()
viewer = WeasWidget()

indert_centre = (8.5, 8.5, 37)
a = 16.9
b = 16.9
c = 7

box= [{
    "type":"cube",
    "materialType": "Standard",
    "opacity": 0.25,
    "shape": {
        "width": a,
        "height": b,
        "depth": c,
        "widthSegments": 32,
        "heightSegments": 32,
        "depthSegments": 32,
      },
    "instances": [{
        "position": indert_centre,
        "scale": [1, 1, 1],
        "rotation": [0, 0, 0],
        "color": "#0000ff",
        }]
    }]

viewer.from_ase(NaCl_super)
viewer.avr.model_style = 1
viewer.imp.settings = box
viewer
[2]:
[3]:
from pack_mm.core.core import pack_molecules

e, final = pack_molecules(
        system=NaCl_super,
        molecule="H2O",
        nmols=20,
        arch="mace_mp",
        model="small-0b2",
        device="cpu",
        where="box",
        center=indert_centre,
        a=a,
        b=b,
        c=c,
        seed=2042,
        temperature=300,
        ntries=20,
        threshold=0.5,
        geometry=False,
        )
Inserting 20 H2O molecules in Cl108Na108+.
Using mace_mp model small-0b2 on cpu.
Insert in box.
/home/runner/work/pack-mm/pack-mm/.venv/lib/python3.12/site-packages/e3nn/o3/_wigner.py:10: UserWarning: Environment variable TORCH_FORCE_NO_WEIGHTS_ONLY_LOAD detected, since the`weights_only` argument was not explicitly passed to `torch.load`, forcing weights_only=False.
  _Jd, _W3j_flat, _W3j_indices = torch.load(os.path.join(os.path.dirname(__file__), 'constants.pt'))
cuequivariance or cuequivariance_torch is not available. Cuequivariance acceleration will be disabled.
Using Materials Project MACE for MACECalculator with /home/runner/.cache/mace/macesmalldensityagnesistressmodel
Using float64 for MACECalculator, which is slower but more accurate. Recommended for geometry optimization.
/home/runner/work/pack-mm/pack-mm/.venv/lib/python3.12/site-packages/mace/calculators/mace.py:139: UserWarning: Environment variable TORCH_FORCE_NO_WEIGHTS_ONLY_LOAD detected, since the`weights_only` argument was not explicitly passed to `torch.load`, forcing weights_only=False.
  torch.load(f=model_path, map_location=device)
Old energy=-722.6495705816244, new energy=-736.819502877273, de=-14.16993229564855, acc=1.1078127747888251e+238, random=0.9224082858823739
Inserted particle 1
Old energy=-736.819502877273, new energy=-750.9822274031393, de=-14.162724525866338, acc=8.382645971728316e+237, random=0.49465704267998434
Inserted particle 2
Old energy=-750.9822274031393, new energy=-765.1891028647846, de=-14.206875461645268, acc=4.624709450717762e+238, random=0.9374033072986
Inserted particle 3
Old energy=-765.1891028647846, new energy=-779.3590112922312, de=-14.169908427446671, acc=1.1067904436090272e+238, random=0.11301187136860802
Inserted particle 4
Old energy=-779.3590112922312, new energy=-789.2676329985507, de=-9.908621706319423, acc=2.867972001069925e+166, random=0.6368663379349846
Inserted particle 5
Old energy=-789.2676329985507, new energy=-803.4692100604739, de=-14.201577061923217, acc=3.7676905441524146e+238, random=0.039025507402559945
Inserted particle 6
Old energy=-803.4692100604739, new energy=-817.6176589775163, de=-14.148448917042401, acc=4.825711675025035e+237, random=0.7816264095523812
Inserted particle 7
Old energy=-817.6176589775163, new energy=-831.3717199695861, de=-13.754060992069867, acc=1.1432299285991774e+231, random=0.7946384160766508
Inserted particle 8
Old energy=-831.3717199695861, new energy=-845.5508387418473, de=-14.179118772261177, acc=1.5804924882908478e+238, random=0.3018355440106446
Inserted particle 9
Old energy=-845.5508387418473, new energy=-859.8440321607758, de=-14.293193418928468, acc=1.3036553936100705e+240, random=0.8610063339435549
Inserted particle 10
Old energy=-859.8440321607758, new energy=-873.9735194901637, de=-14.12948732938787, acc=2.3175046243752873e+237, random=0.8710374922225326
Inserted particle 11
Old energy=-873.9735194901637, new energy=-888.390010394459, de=-14.416490904295301, acc=1.5362790176203024e+242, random=0.9372407961015686
Inserted particle 12
Old energy=-888.390010394459, new energy=-902.6369589400576, de=-14.246948545598684, acc=2.1791286108170244e+239, random=0.8108197601233099
Inserted particle 13
Old energy=-902.6369589400576, new energy=-916.9585304149655, de=-14.321571474907842, acc=3.907449067534872e+240, random=0.44068985410214423
Inserted particle 14
Old energy=-916.9585304149655, new energy=-931.2062273604673, de=-14.247696945501843, acc=2.2431351048164295e+239, random=0.8847889911084612
Inserted particle 15
Old energy=-931.2062273604673, new energy=-932.3490353975458, de=-1.1428080370784528, acc=1.578834352811686e+19, random=0.2117478385102951
Old energy=-931.2062273604673, new energy=-945.3494484228156, de=-14.143221062348289, acc=3.942187231747792e+237, random=0.8188187672234769
Inserted particle 16
Old energy=-945.3494484228156, new energy=-959.5835928934792, de=-14.234144470663637, acc=1.3279563438766754e+239, random=0.2555871566261533
Inserted particle 17
Old energy=-959.5835928934792, new energy=-973.7830515113415, de=-14.199458617862206, acc=3.471258204501571e+238, random=0.5587630356823694
Inserted particle 18
Old energy=-973.7830515113415, new energy=-987.7693746278162, de=-13.98632311647475, acc=9.119412679358459e+234, random=0.807305293242636
Inserted particle 19
Old energy=-987.7693746278162, new energy=-999.3733863713766, de=-11.604011743560363, acc=8.68727678560177e+194, random=0.6110986123209559
Inserted particle 20
[4]:
viewer2=WeasWidget()
viewer2.from_ase(final)
viewer2.avr.model_style = 1
viewer2.avr.show_hydrogen_bonds = True
viewer2.imp.settings = box
viewer2
[4]: