Open In Colab

MOF+ethanol+water

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

download the data needed for the tutorial.

[2]:
from data_tutorials.data import get_data

get_data(
    url="https://raw.githubusercontent.com/ddmms/pack-mm/main/examples/data/",
    filename=["Cu2L.cif"],
    folder="data",
)
try to download Cu2L.cif from https://raw.githubusercontent.com/ddmms/pack-mm/main/examples/data/ and save it in data/Cu2L.cif
saved in data/Cu2L.cif

Let us start by adding few water molecules in a MoF, UiO66. We read it using ase and visualising with weas widget

[3]:
from weas_widget import WeasWidget
from ase.io import read
viewer = WeasWidget()

mof = read("data/Cu2L.cif")
insert_centre = (5.18,8.15,25.25)
radius = 1.0

sphere = [{
    "type":"sphere",
    "materialType": "Standard",
    "opacity": 0.25,
    "shape":{
        "radius": radius,
        "radiusSegments": 32,
        },
    "instances": [{
        "position": insert_centre,
        "scale": [1, 1, 1],

        }]
    }]

viewer.from_ase(mof)
viewer.avr.model_style = 1
viewer.avr.show_hydrogen_bonds = True
viewer.imp.settings = sphere
viewer
[3]:

we start by adding an ethanol molecule in the ellipsoidal pocket, we use a sphere to control the insertion

[4]:
from pack_mm.core.core import pack_molecules

e, mofEthanol = pack_molecules(
        system=mof,
        molecule="CH3CH2OH",
        nmols=1,
        arch="mace_mp",
        model="small-0b2",
        device="cpu",
        where="sphere",
        center=insert_centre,
        radius=radius,
        seed=2042,
        temperature=300,
        ntries=20,
        geometry=False,
        threshold=0.5,
        )
Inserting 1 CH3CH2OH molecules in C280H400Cu40N80+.
Using mace_mp model small-0b2 on cpu.
Insert in sphere.
/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=-4601.962380505345, new energy=-4648.878707318432, de=-46.916326813086926, acc=inf, random=0.9224082858823739
Inserted particle 1
/home/runner/work/pack-mm/pack-mm/pack_mm/core/core.py:343: RuntimeWarning: overflow encountered in exp
  acc = exp(-de / kbt)
/home/runner/work/pack-mm/pack-mm/.venv/lib/python3.12/site-packages/ase/io/cif.py:834: UserWarning: Occupancies present but no occupancy info for "{symbol}"
  warnings.warn(str(err))

visualise the final configurations.

[5]:
viewer2 = WeasWidget()
viewer2.from_ase(mofEthanol)
viewer2.avr.model_style = 1
viewer2.avr.show_hydrogen_bonds = True
viewer2
[5]:
[6]:
insert_centre = (5.18,8.15,25.25)
a = 5.00
b = 8
c = 6
radius = a

ellipsoid = [{
    "type":"sphere",
    "materialType": "Standard",
    "opacity": 0.25,
    "shape":{
        "radius": radius,
        "radiusSegments": 32,
        },
    "instances": [{
        "position": insert_centre,
        "scale": [1, b/a, c/a],

        }]
    }]
viewer2.imp.settings = ellipsoid
viewer2

[6]:

adding water in the ellipsoid channel of the mof.

[7]:
e, final = pack_molecules(
        system= mofEthanol,
        molecule="H2O",
        nmols=20,
        arch="mace_mp",
        model="small-0b2",
        device="cpu",
        where="ellipsoid",
        center=insert_centre,
        a=a,
        b=b,
        c=c,
        seed=2042,
        temperature=300,
        ntries=20,
        geometry=False,
        threshold=0.5,
        )
/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)
Inserting 20 H2O molecules in C282H406Cu40N80O+.
Using mace_mp model small-0b2 on cpu.
Insert in ellipsoid.
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.
Old energy=-4648.878707318432, new energy=-4662.43093447982, de=-13.552227161388146, acc=4.650217983471612e+227, random=0.9224082858823739
Inserted particle 1
/home/runner/work/pack-mm/pack-mm/.venv/lib/python3.12/site-packages/ase/io/cif.py:834: UserWarning: Occupancies present but no occupancy info for "{symbol}"
  warnings.warn(str(err))
Old energy=-4662.43093447982, new energy=-4676.499063663318, de=-14.068129183498058, acc=2.158980778049481e+236, random=0.49465704267998434
Inserted particle 2
Old energy=-4676.499063663318, new energy=-4690.683956701911, de=-14.184893038592236, acc=1.976040648053565e+238, random=0.9374033072986
Inserted particle 3
Old energy=-4690.683956701911, new energy=-4689.808280687596, de=0.8756760143141946, acc=1.9466390251598317e-15, random=0.11301187136860802
Old energy=-4690.683956701911, new energy=-4704.192683990928, de=-13.50872728901777, acc=8.64385295984088e+226, random=0.6368663379349846
Inserted particle 4
Old energy=-4704.192683990928, new energy=-4712.793770986489, de=-8.601086995560763, acc=3.104209893099579e+144, random=0.039025507402559945
Inserted particle 5
Old energy=-4712.793770986489, new energy=-4715.355550514341, de=-2.5617795278521953, acc=1.086467003521343e+43, random=0.7816264095523812
Old energy=-4712.793770986489, new energy=-4726.871544022668, de=-14.077773036178769, acc=3.135150728687432e+236, random=0.7946384160766508
Inserted particle 6
Old energy=-4726.871544022668, new energy=-4740.932103412928, de=-14.060559390260096, acc=1.6109490428081643e+236, random=0.3018355440106446
Inserted particle 7
Old energy=-4740.932103412928, new energy=-4706.742542756843, de=34.18956065608472, acc=0.0, random=0.8610063339435549
Old energy=-4740.932103412928, new energy=-4745.436301279554, de=-4.504197866625873, acc=4.647501287683485e+75, random=0.8710374922225326
Old energy=-4740.932103412928, new energy=-4755.2597802412565, de=-14.32767682832855, acc=4.948331472750822e+240, random=0.9372407961015686
Inserted particle 8
Old energy=-4755.2597802412565, new energy=-4742.906949273605, de=12.352830967651244, acc=3.030419628085434e-208, random=0.8108197601233099
Old energy=-4755.2597802412565, new energy=-4767.469558035583, de=-12.209777794326328, acc=1.3040939290643494e+205, random=0.44068985410214423
Inserted particle 9
Old energy=-4767.469558035583, new energy=-4774.0134861954175, de=-6.54392815983465, acc=8.574166940907144e+109, random=0.8847889911084612
Old energy=-4767.469558035583, new energy=-4613.621717723892, de=153.84784031169056, acc=0.0, random=0.2117478385102951
Old energy=-4767.469558035583, new energy=-4778.2250107257605, de=-10.755452690177663, acc=4.827409412674386e+180, random=0.8188187672234769
Inserted particle 10
Old energy=-4778.2250107257605, new energy=-4792.605239199413, de=-14.380228473652096, acc=3.778225451436102e+241, random=0.2555871566261533
Inserted particle 11
Old energy=-4792.605239199413, new energy=-4806.32260937446, de=-13.717370175047108, acc=2.765379752185081e+230, random=0.5587630356823694
Inserted particle 12
Old energy=-4806.32260937446, new energy=-4804.840160120196, de=1.4824492542638836, acc=1.2472116875520546e-25, random=0.807305293242636
Old energy=-4806.32260937446, new energy=-4744.37170590108, de=61.950903473380095, acc=0.0, random=0.6110986123209559
Old energy=-4806.32260937446, new energy=-4819.484439951355, de=-13.161830576895227, acc=1.2855741112918478e+221, random=0.631222202449424
Inserted particle 13
Old energy=-4819.484439951355, new energy=-4833.542026191865, de=-14.057586240510318, acc=1.4359359502060322e+236, random=0.8612732489649417
Inserted particle 14
Old energy=-4833.542026191865, new energy=-4846.960013163305, de=-13.41798697143986, acc=2.5842624045084605e+225, random=0.5019879170553969
Inserted particle 15
Old energy=-4846.960013163305, new energy=-4859.275239419894, de=-12.315226256589085, acc=7.704876355109996e+206, random=0.8002614415162514
Inserted particle 16
Old energy=-4859.275239419894, new energy=-4858.018157408544, de=1.257082011350576, acc=7.619816370375294e-22, random=0.7117058040956253
Old energy=-4859.275239419894, new energy=-4873.440940318909, de=-14.165700899015064, acc=9.405502646732347e+237, random=0.8707401703354793
Inserted particle 17
Old energy=-4873.440940318909, new energy=-4860.202579922086, de=13.238360396822827, acc=4.029563978187638e-223, random=0.2190248203340861
Old energy=-4873.440940318909, new energy=-4885.386855185563, de=-11.945914866653766, acc=4.815099648069473e+200, random=0.0113592443716658
Inserted particle 18
Old energy=-4885.386855185563, new energy=-4899.703177192814, de=-14.316322007251074, acc=3.189378928540479e+240, random=0.15251555599374556
Inserted particle 19
Old energy=-4899.703177192814, new energy=-4905.666357013982, de=-5.963179821167614, acc=1.5033009398677035e+100, random=0.1678701161691194
Old energy=-4899.703177192814, new energy=-4913.331731790897, de=-13.628554598082701, acc=8.906729192798791e+228, random=0.11413860595939296
Inserted particle 20
[8]:
viewer3 = WeasWidget()
viewer3.from_ase(final)
viewer3.avr.model_style = 1
viewer3.avr.show_hydrogen_bonds = True
viewer3.imp.settings = ellipsoid
viewer3
[8]:
[ ]: