Open In Colab

Bulk 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

Let us start by creating a small box of water 10 A in size, for normal density that means 33 water molecules.

[2]:
from pack_mm.core.core import pack_molecules
from weas_widget import WeasWidget


e, final = pack_molecules(
        molecule="H2O",
        nmols=33,
        arch="mace_mp",
        model="small-0b2",
        device="cpu",
        where="anywhere",
        cell_a=10,
        cell_b=10,
        cell_c=10,
        seed=2025,
        temperature=300,
        ntries=20,
        geometry=True,
        threshold=0.5,
        )
Inserting 33 H2O molecules in .
Using mace_mp model small-0b2 on cpu.
Insert in anywhere.
/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.
Using head default out of ['default']
/home/runner/work/pack-mm/pack-mm/.venv/lib/python3.12/site-packages/mace/calculators/mace.py:143: 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=0.0, new energy=-14.169908427446725, de=-14.169908427446725, acc=1.106790443611292e+238, random=0.6573675854710377
Inserted particle 1
Old energy=-14.169908427446725, new energy=-28.388449306260235, de=-14.21854087881351, acc=7.261977566080532e+238, random=0.7694578719378116
Inserted particle 2
Old energy=-28.388449306260235, new energy=-42.56138109854783, de=-14.172931792287592, acc=1.2441012080374936e+238, random=0.6663921049033288
Inserted particle 3
Old energy=-42.56138109854783, new energy=-56.72045170438421, de=-14.159070605836384, acc=7.277763676747897e+237, random=0.5196536887579605
Inserted particle 4
Old energy=-56.72045170438421, new energy=-70.95493496595596, de=-14.234483261571746, acc=1.345473773274851e+239, random=0.06739574665921966
Inserted particle 5
Old energy=-70.95493496595596, new energy=-85.20119759619391, de=-14.24626263023795, acc=2.122071379141933e+239, random=0.49961201043327175
Inserted particle 6
Old energy=-85.20119759619391, new energy=-99.4226181862961, de=-14.221420590102198, acc=8.117680232384532e+238, random=0.1050746012583641
Inserted particle 7
Old energy=-99.4226181862961, new energy=-113.79662130272759, de=-14.374003116431481, acc=2.9696579904155567e+241, random=0.9378701885604214
Inserted particle 8
Old energy=-113.79662130272759, new energy=-128.1306220375978, de=-14.334000734870202, acc=6.319689981828159e+240, random=0.3762683149324123
Inserted particle 9
Old energy=-128.1306220375978, new energy=-141.85615337199786, de=-13.725531334400074, acc=3.7918946959024316e+230, random=0.6727933834766038
Inserted particle 10
Old energy=-141.85615337199786, new energy=-156.06180658142108, de=-14.205653209423218, acc=4.411146815908922e+238, random=0.09706066849775918
Inserted particle 11
Old energy=-156.06180658142108, new energy=-170.53713931561308, de=-14.475332734191994, acc=1.4961311672716866e+243, random=0.47590567428965436
Inserted particle 12
Old energy=-170.53713931561308, new energy=-184.44423715363098, de=-13.907097838017904, acc=4.256379248320164e+233, random=0.1445197281328413
Inserted particle 13
Old energy=-184.44423715363098, new energy=-198.8723316569115, de=-14.428094503280533, acc=2.40658967246052e+242, random=0.6096984257895941
Inserted particle 14
Old energy=-198.8723316569115, new energy=-213.0472463472201, de=-14.174914690308583, acc=1.3432812220838868e+238, random=0.10084644599814097
Inserted particle 15
Old energy=-213.0472463472201, new energy=-225.548543930126, de=-12.501297582905892, acc=1.0295025792391397e+210, random=0.8475810108898351
Inserted particle 16
Old energy=-225.548543930126, new energy=-237.81867754510063, de=-12.27013361497464, acc=1.3466116834684025e+206, random=0.9573928760728474
Inserted particle 17
Old energy=-237.81867754510063, new energy=-251.69716390805326, de=-13.878486362952628, acc=1.4073059625944881e+233, random=0.3273810695294246
Inserted particle 18
Old energy=-251.69716390805326, new energy=-240.75598269219518, de=10.94118121585808, acc=1.571024294231746e-184, random=0.06247404096988407
Old energy=-251.69716390805326, new energy=-265.98484303063964, de=-14.287679122586383, acc=1.0532383716582671e+240, random=0.9267631049637567
Inserted particle 19
Old energy=-265.98484303063964, new energy=-273.78462117763786, de=-7.7997781469982215, acc=1.07287796861951e+131, random=0.3402871935608006
Inserted particle 20
Old energy=-273.78462117763786, new energy=-285.09649060859454, de=-11.311869430956676, acc=1.0742544121330106e+190, random=0.1776678297264329
Inserted particle 21
Old energy=-285.09649060859454, new energy=-298.76729278681404, de=-13.670802178219503, acc=4.5650611352144245e+229, random=0.6002380235886438
Inserted particle 22
Old energy=-298.76729278681404, new energy=-286.0973160835177, de=12.669976703296356, acc=1.4245808268246304e-213, random=0.868138468423006
Old energy=-298.76729278681404, new energy=-312.42081274657045, de=-13.653519959756409, acc=2.339472838800911e+229, random=0.657014836768514
Inserted particle 23
Old energy=-312.42081274657045, new energy=-315.2519351263058, de=-2.8311223797353477, acc=3.63729764384701e+47, random=0.5318473353823712
Old energy=-312.42081274657045, new energy=-324.38286676790995, de=-11.962054021339497, acc=8.989410999140108e+200, random=0.9616436876719956
Inserted particle 24
Old energy=-324.38286676790995, new energy=-334.7276976756465, de=-10.344830907736537, acc=6.103366546753475e+173, random=0.21200357006485315
Inserted particle 25
Old energy=-334.7276976756465, new energy=-348.8852358657079, de=-14.157538190061416, acc=6.85890027328025e+237, random=0.4817459907937399
Inserted particle 26
Old energy=-348.8852358657079, new energy=-360.3771726445383, de=-11.491936778830393, acc=1.1379062387491906e+193, random=0.7175118692379753
Inserted particle 27
Old energy=-360.3771726445383, new energy=-370.71946686737834, de=-10.342294222840053, acc=5.532927860100863e+173, random=0.4094954707153864
Inserted particle 28
Old energy=-370.71946686737834, new energy=-381.90781888174286, de=-11.188352014364511, acc=9.038683297493437e+187, random=0.19004083637014857
Inserted particle 29
Old energy=-381.90781888174286, new energy=-390.1891332215735, de=-8.281314339830658, acc=1.3182721379968262e+139, random=0.2593074228409512
Inserted particle 30
Old energy=-390.1891332215735, new energy=-392.71942108765535, de=-2.530287866081835, acc=3.2135105364186836e+42, random=0.368706041406911
Old energy=-390.1891332215735, new energy=-343.227703525221, de=46.961429696352525, acc=0.0, random=0.29948735641057544
Old energy=-390.1891332215735, new energy=-391.94706464719314, de=-1.7579314256196312, acc=3.403754206189546e+29, random=0.11024899776641639
Old energy=-390.1891332215735, new energy=-397.4714077514512, de=-7.282274529877668, acc=2.1720471159563655e+122, random=0.853089891818317
Inserted particle 31
Old energy=-397.4714077514512, new energy=-201.84842710657364, de=195.62298064487754, acc=0.0, random=0.7172312048224184
Old energy=-397.4714077514512, new energy=-409.51758859289333, de=-12.046180841442151, acc=2.328091753685072e+202, random=0.7007421832233066
Inserted particle 32
Old energy=-409.51758859289333, new energy=-422.30745403223574, de=-12.789865439342407, acc=7.250295553039641e+214, random=0.37954479237838723
Inserted particle 33
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.
Using head default out of ['default']
/home/runner/work/pack-mm/pack-mm/.venv/lib/python3.12/site-packages/mace/calculators/mace.py:143: 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)
       Step     Time          Energy          fmax
LBFGS:    0 10:03:49     -422.307454       13.877663
LBFGS:    1 10:03:49     -435.791603       15.542238
LBFGS:    2 10:03:50     -445.636460        8.628340
LBFGS:    3 10:03:51     -451.808973        4.176232
LBFGS:    4 10:03:51     -455.545885        3.666724
LBFGS:    5 10:03:52     -458.932705        3.087802
LBFGS:    6 10:03:53     -462.238560        2.496349
LBFGS:    7 10:03:53     -464.286151        3.489929
LBFGS:    8 10:03:54     -466.032275        2.215424
LBFGS:    9 10:03:55     -467.425347        1.697507
LBFGS:   10 10:03:55     -468.662562        2.029074
LBFGS:   11 10:03:56     -469.699687        2.413723
LBFGS:   12 10:03:57     -470.733457        1.752417
LBFGS:   13 10:03:57     -471.567068        1.079853
LBFGS:   14 10:03:58     -472.669489        1.711636
LBFGS:   15 10:03:58     -473.205563        1.634225
LBFGS:   16 10:03:59     -473.831545        1.175250
LBFGS:   17 10:04:00     -474.157829        2.514301
LBFGS:   18 10:04:00     -474.720307        1.106639
LBFGS:   19 10:04:01     -475.243021        0.929779
LBFGS:   20 10:04:02     -475.673385        1.057766
LBFGS:   21 10:04:02     -475.932370        0.881880
LBFGS:   22 10:04:03     -476.175535        0.882676
LBFGS:   23 10:04:04     -476.420049        1.188850
LBFGS:   24 10:04:04     -476.594292        0.765145
LBFGS:   25 10:04:05     -476.862982        0.805157
LBFGS:   26 10:04:05     -477.133243        0.879516
LBFGS:   27 10:04:06     -477.358436        1.161428
LBFGS:   28 10:04:07     -477.583134        0.853986
LBFGS:   29 10:04:07     -477.816074        0.892980
LBFGS:   30 10:04:08     -478.002069        0.802879
LBFGS:   31 10:04:08     -478.159765        0.907363
LBFGS:   32 10:04:09     -478.304739        0.732561
LBFGS:   33 10:04:10     -478.516317        0.698569
LBFGS:   34 10:04:10     -478.721229        0.788372
LBFGS:   35 10:04:11     -478.936063        0.775582
LBFGS:   36 10:04:11     -479.103873        0.650802
LBFGS:   37 10:04:12     -479.262580        0.675939
LBFGS:   38 10:04:13     -479.421737        0.860773
LBFGS:   39 10:04:13     -479.601171        0.640421
LBFGS:   40 10:04:14     -479.790530        0.622390
LBFGS:   41 10:04:15     -479.910151        0.659465
LBFGS:   42 10:04:15     -480.006815        0.481454
LBFGS:   43 10:04:16     -480.136074        0.590734
LBFGS:   44 10:04:17     -480.262922        0.953696
LBFGS:   45 10:04:17     -480.392769        0.508664
LBFGS:   46 10:04:18     -480.490737        0.586978
LBFGS:   47 10:04:18     -480.588302        0.639654
LBFGS:   48 10:04:19     -480.763744        0.638177
LBFGS:   49 10:04:20     -480.897251        0.534118
LBFGS:   50 10:04:20     -481.021311        0.485723
LBFGS:   51 10:04:21     -481.127862        0.582302
LBFGS:   52 10:04:22     -481.232738        0.612588
LBFGS:   53 10:04:22     -481.347576        0.649466
LBFGS:   54 10:04:23     -481.454183        0.629958
LBFGS:   55 10:04:24     -481.556168        0.408971
LBFGS:   56 10:04:24     -481.641221        0.448516
LBFGS:   57 10:04:25     -481.724783        0.448668
LBFGS:   58 10:04:25     -481.835808        0.413646
LBFGS:   59 10:04:26     -481.914032        0.685601
LBFGS:   60 10:04:27     -481.981834        0.460009
LBFGS:   61 10:04:27     -482.056799        0.391624
LBFGS:   62 10:04:28     -482.132678        0.308693
LBFGS:   63 10:04:29     -482.215704        0.362441
LBFGS:   64 10:04:29     -482.271780        0.359791
LBFGS:   65 10:04:30     -482.338623        0.381272
LBFGS:   66 10:04:31     -482.395852        0.422197
LBFGS:   67 10:04:31     -482.458444        0.386613
LBFGS:   68 10:04:32     -482.532481        0.394048
LBFGS:   69 10:04:32     -482.601371        0.402546
LBFGS:   70 10:04:33     -482.653404        0.353862
LBFGS:   71 10:04:33     -482.691509        0.377310
LBFGS:   72 10:04:34     -482.734611        0.330249
LBFGS:   73 10:04:35     -482.799811        0.381771
LBFGS:   74 10:04:35     -482.857080        0.447662
LBFGS:   75 10:04:36     -482.917838        0.376530
LBFGS:   76 10:04:36     -482.968576        0.315092
LBFGS:   77 10:04:37     -483.020101        0.310454
LBFGS:   78 10:04:38     -483.066142        0.347737
LBFGS:   79 10:04:38     -483.112253        0.311655
LBFGS:   80 10:04:39     -483.152855        0.330687
LBFGS:   81 10:04:40     -483.191872        0.268214
LBFGS:   82 10:04:40     -483.224914        0.444314
LBFGS:   83 10:04:41     -483.260812        0.273215
LBFGS:   84 10:04:41     -483.299696        0.464131
LBFGS:   85 10:04:42     -483.342284        0.301555
LBFGS:   86 10:04:43     -483.380349        0.306767
LBFGS:   87 10:04:43     -483.408996        0.324211
LBFGS:   88 10:04:44     -483.442423        0.342084
LBFGS:   89 10:04:45     -483.484117        0.290656
LBFGS:   90 10:04:45     -483.530734        0.297088
LBFGS:   91 10:04:46     -483.560967        0.248771
LBFGS:   92 10:04:46     -483.600029        0.496099
LBFGS:   93 10:04:47     -483.648500        0.461463
LBFGS:   94 10:04:48     -483.694032        0.991481
LBFGS:   95 10:04:48     -483.760075        0.537253
LBFGS:   96 10:04:49     -483.806151        0.382515
LBFGS:   97 10:04:50     -483.840036        0.343295
LBFGS:   98 10:04:50     -483.870776        0.350422
LBFGS:   99 10:04:51     -483.921631        0.429895
LBFGS:  100 10:04:52     -483.964606        0.493320
LBFGS:  101 10:04:52     -483.996736        0.413153
LBFGS:  102 10:04:53     -484.032976        0.290601
LBFGS:  103 10:04:54     -484.070603        0.287103
LBFGS:  104 10:04:54     -484.102650        0.266610
LBFGS:  105 10:04:55     -484.135817        0.265643
LBFGS:  106 10:04:56     -484.162171        0.250369
LBFGS:  107 10:04:56     -484.189260        0.292546
LBFGS:  108 10:04:57     -484.218740        0.307706
LBFGS:  109 10:04:57     -484.248908        0.565371
LBFGS:  110 10:04:58     -484.278317        0.251354
LBFGS:  111 10:04:59     -484.303058        0.216327
LBFGS:  112 10:04:59     -484.320560        0.222344
LBFGS:  113 10:05:00     -484.340146        0.220412
LBFGS:  114 10:05:00     -484.365009        0.237987
LBFGS:  115 10:05:01     -484.388229        0.175008
LBFGS:  116 10:05:02     -484.410060        0.206289
LBFGS:  117 10:05:02     -484.430236        0.204077
LBFGS:  118 10:05:03     -484.452477        0.252451
LBFGS:  119 10:05:04     -484.475909        0.273568
LBFGS:  120 10:05:04     -484.498683        0.301674
LBFGS:  121 10:05:05     -484.518715        0.308904
LBFGS:  122 10:05:06     -484.537707        0.230892
LBFGS:  123 10:05:06     -484.559027        0.203116
LBFGS:  124 10:05:07     -484.580842        0.256442
LBFGS:  125 10:05:07     -484.603562        0.279154
LBFGS:  126 10:05:08     -484.623792        0.214331
LBFGS:  127 10:05:09     -484.642449        0.210542
LBFGS:  128 10:05:10     -484.661975        0.295669
LBFGS:  129 10:05:10     -484.689154        0.401151
LBFGS:  130 10:05:11     -484.718332        0.308726
LBFGS:  131 10:05:11     -484.741818        0.382969
LBFGS:  132 10:05:12     -484.763953        0.216638
LBFGS:  133 10:05:13     -484.787856        0.235513
LBFGS:  134 10:05:13     -484.812531        0.264937
LBFGS:  135 10:05:14     -484.835766        0.402124
LBFGS:  136 10:05:15     -484.858430        0.217953
LBFGS:  137 10:05:15     -484.877321        0.179554
LBFGS:  138 10:05:16     -484.898387        0.261446
LBFGS:  139 10:05:17     -484.921435        0.243394
LBFGS:  140 10:05:17     -484.948703        0.319621
LBFGS:  141 10:05:18     -484.971011        0.261375
LBFGS:  142 10:05:18     -484.991352        0.230271
LBFGS:  143 10:05:19     -485.011476        0.211258
LBFGS:  144 10:05:19     -485.036650        0.291015
LBFGS:  145 10:05:20     -485.059316        0.183163
LBFGS:  146 10:05:21     -485.079177        0.199940
LBFGS:  147 10:05:21     -485.097575        0.197279
LBFGS:  148 10:05:22     -485.115220        0.225396
LBFGS:  149 10:05:23     -485.131850        0.206028
LBFGS:  150 10:05:23     -485.148505        0.180702
LBFGS:  151 10:05:24     -485.164133        0.192611
LBFGS:  152 10:05:25     -485.179739        0.192113
LBFGS:  153 10:05:25     -485.193961        0.157355
LBFGS:  154 10:05:26     -485.206883        0.150161
LBFGS:  155 10:05:26     -485.217582        0.131592
LBFGS:  156 10:05:27     -485.226837        0.132444
LBFGS:  157 10:05:28     -485.236188        0.135832
LBFGS:  158 10:05:28     -485.246934        0.128134
LBFGS:  159 10:05:29     -485.258847        0.150498
LBFGS:  160 10:05:30     -485.271095        0.170130
LBFGS:  161 10:05:30     -485.282843        0.206553
LBFGS:  162 10:05:31     -485.293838        0.155075
LBFGS:  163 10:05:32     -485.304935        0.155148
LBFGS:  164 10:05:32     -485.316105        0.131736
LBFGS:  165 10:05:33     -485.327063        0.189752
LBFGS:  166 10:05:34     -485.337150        0.153041
LBFGS:  167 10:05:34     -485.347754        0.150834
LBFGS:  168 10:05:35     -485.359310        0.153122
LBFGS:  169 10:05:35     -485.371676        0.162032
LBFGS:  170 10:05:36     -485.382159        0.141829
LBFGS:  171 10:05:37     -485.390717        0.119533
LBFGS:  172 10:05:37     -485.399287        0.143391
LBFGS:  173 10:05:38     -485.410824        0.179853
LBFGS:  174 10:05:39     -485.424947        0.205613
LBFGS:  175 10:05:39     -485.438451        0.241444
LBFGS:  176 10:05:40     -485.448004        0.214438
LBFGS:  177 10:05:41     -485.456397        0.134944
LBFGS:  178 10:05:41     -485.464157        0.134600
LBFGS:  179 10:05:42     -485.473787        0.186862
LBFGS:  180 10:05:42     -485.480682        0.173867
LBFGS:  181 10:05:43     -485.487156        0.115708
LBFGS:  182 10:05:44     -485.493831        0.128686
LBFGS:  183 10:05:44     -485.501392        0.116803
LBFGS:  184 10:05:45     -485.508188        0.154473
LBFGS:  185 10:05:46     -485.513987        0.102476
LBFGS:  186 10:05:46     -485.519603        0.105021
LBFGS:  187 10:05:47     -485.525997        0.152851
LBFGS:  188 10:05:48     -485.532837        0.173253
LBFGS:  189 10:05:48     -485.538829        0.115083
LBFGS:  190 10:05:49     -485.543717        0.090572
[3]:
viewer=WeasWidget()
viewer.from_ase(final)
viewer.avr.model_style = 1
viewer.avr.show_hydrogen_bonds = True
viewer
[3]:
[4]:
m = sum(final.get_masses())*1.660538921*10**(-24)
V = final.get_volume()*10**(-24)
rho = m/V
print(final.cell.cellpar())
print(f"Mass: {m:.3e} g")
print(f"Volume: {V:.3e} cm^3")
print(f"Density: {rho:.2f} g/cm^3")
[10.12960782 10.12960782 10.12960782 90.         90.         90.        ]
Mass: 9.872e-22 g
Volume: 1.039e-21 cm^3
Density: 0.95 g/cm^3