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.
/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=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.
/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)
       Step     Time          Energy          fmax
LBFGS:    0 21:43:55     -422.307454       13.877663
LBFGS:    1 21:43:56     -435.791603       15.542238
LBFGS:    2 21:43:56     -445.636460        8.628340
LBFGS:    3 21:43:57     -451.808973        4.176232
LBFGS:    4 21:43:58     -455.545885        3.666724
LBFGS:    5 21:43:58     -458.932705        3.087802
LBFGS:    6 21:43:59     -462.238560        2.496349
LBFGS:    7 21:43:59     -464.286151        3.489929
LBFGS:    8 21:44:00     -466.032275        2.215424
LBFGS:    9 21:44:01     -467.425347        1.697507
LBFGS:   10 21:44:01     -468.662562        2.029074
LBFGS:   11 21:44:02     -469.699687        2.413723
LBFGS:   12 21:44:02     -470.733457        1.752417
LBFGS:   13 21:44:03     -471.567068        1.079853
LBFGS:   14 21:44:04     -472.669489        1.711636
LBFGS:   15 21:44:04     -473.205563        1.634225
LBFGS:   16 21:44:05     -473.831545        1.175250
LBFGS:   17 21:44:06     -474.157829        2.514301
LBFGS:   18 21:44:06     -474.720307        1.106639
LBFGS:   19 21:44:07     -475.243021        0.929779
LBFGS:   20 21:44:07     -475.673385        1.057766
LBFGS:   21 21:44:08     -475.932370        0.881880
LBFGS:   22 21:44:09     -476.175535        0.882676
LBFGS:   23 21:44:09     -476.420049        1.188850
LBFGS:   24 21:44:10     -476.594292        0.765145
LBFGS:   25 21:44:10     -476.862982        0.805157
LBFGS:   26 21:44:11     -477.133243        0.879516
LBFGS:   27 21:44:12     -477.358436        1.161428
LBFGS:   28 21:44:12     -477.583134        0.853986
LBFGS:   29 21:44:13     -477.816074        0.892980
LBFGS:   30 21:44:13     -478.002069        0.802879
LBFGS:   31 21:44:14     -478.159765        0.907363
LBFGS:   32 21:44:14     -478.304739        0.732561
LBFGS:   33 21:44:15     -478.516317        0.698569
LBFGS:   34 21:44:16     -478.721229        0.788372
LBFGS:   35 21:44:16     -478.936063        0.775582
LBFGS:   36 21:44:17     -479.103873        0.650802
LBFGS:   37 21:44:17     -479.262580        0.675939
LBFGS:   38 21:44:18     -479.421737        0.860773
LBFGS:   39 21:44:18     -479.601171        0.640421
LBFGS:   40 21:44:19     -479.790530        0.622390
LBFGS:   41 21:44:20     -479.910151        0.659465
LBFGS:   42 21:44:20     -480.006815        0.481454
LBFGS:   43 21:44:21     -480.136074        0.590734
LBFGS:   44 21:44:21     -480.262922        0.953696
LBFGS:   45 21:44:22     -480.392769        0.508664
LBFGS:   46 21:44:23     -480.490737        0.586978
LBFGS:   47 21:44:23     -480.588302        0.639654
LBFGS:   48 21:44:24     -480.763744        0.638177
LBFGS:   49 21:44:25     -480.897251        0.534118
LBFGS:   50 21:44:25     -481.021311        0.485723
LBFGS:   51 21:44:26     -481.127862        0.582302
LBFGS:   52 21:44:26     -481.232738        0.612588
LBFGS:   53 21:44:27     -481.347576        0.649466
LBFGS:   54 21:44:28     -481.454183        0.629958
LBFGS:   55 21:44:28     -481.556168        0.408971
LBFGS:   56 21:44:29     -481.641221        0.448516
LBFGS:   57 21:44:29     -481.724783        0.448668
LBFGS:   58 21:44:30     -481.835808        0.413646
LBFGS:   59 21:44:31     -481.914032        0.685601
LBFGS:   60 21:44:31     -481.981834        0.460009
LBFGS:   61 21:44:32     -482.056799        0.391624
LBFGS:   62 21:44:33     -482.132678        0.308693
LBFGS:   63 21:44:33     -482.215704        0.362441
LBFGS:   64 21:44:34     -482.271780        0.359791
LBFGS:   65 21:44:34     -482.338623        0.381272
LBFGS:   66 21:44:35     -482.395852        0.422197
LBFGS:   67 21:44:35     -482.458444        0.386613
LBFGS:   68 21:44:36     -482.532481        0.394048
LBFGS:   69 21:44:36     -482.601371        0.402546
LBFGS:   70 21:44:37     -482.653404        0.353862
LBFGS:   71 21:44:38     -482.691509        0.377310
LBFGS:   72 21:44:38     -482.734611        0.330249
LBFGS:   73 21:44:39     -482.799811        0.381771
LBFGS:   74 21:44:40     -482.857080        0.447662
LBFGS:   75 21:44:40     -482.917838        0.376530
LBFGS:   76 21:44:41     -482.968576        0.315092
LBFGS:   77 21:44:42     -483.020101        0.310454
LBFGS:   78 21:44:42     -483.066142        0.347737
LBFGS:   79 21:44:43     -483.112253        0.311655
LBFGS:   80 21:44:44     -483.152855        0.330687
LBFGS:   81 21:44:44     -483.191872        0.268214
LBFGS:   82 21:44:45     -483.224914        0.444314
LBFGS:   83 21:44:45     -483.260812        0.273215
LBFGS:   84 21:44:46     -483.299696        0.464131
LBFGS:   85 21:44:47     -483.342284        0.301555
LBFGS:   86 21:44:47     -483.380349        0.306767
LBFGS:   87 21:44:48     -483.408996        0.324211
LBFGS:   88 21:44:48     -483.442423        0.342084
LBFGS:   89 21:44:49     -483.484117        0.290656
LBFGS:   90 21:44:50     -483.530734        0.297088
LBFGS:   91 21:44:50     -483.560967        0.248771
LBFGS:   92 21:44:51     -483.600029        0.496099
LBFGS:   93 21:44:52     -483.648500        0.461463
LBFGS:   94 21:44:52     -483.694032        0.991481
LBFGS:   95 21:44:53     -483.760075        0.537253
LBFGS:   96 21:44:53     -483.806151        0.382515
LBFGS:   97 21:44:54     -483.840036        0.343295
LBFGS:   98 21:44:55     -483.870776        0.350422
LBFGS:   99 21:44:55     -483.921631        0.429895
LBFGS:  100 21:44:56     -483.964606        0.493320
LBFGS:  101 21:44:56     -483.996736        0.413153
LBFGS:  102 21:44:57     -484.032976        0.290601
LBFGS:  103 21:44:57     -484.070603        0.287103
LBFGS:  104 21:44:58     -484.102650        0.266610
LBFGS:  105 21:44:59     -484.135817        0.265643
LBFGS:  106 21:44:59     -484.162171        0.250369
LBFGS:  107 21:45:00     -484.189260        0.292546
LBFGS:  108 21:45:00     -484.218740        0.307706
LBFGS:  109 21:45:01     -484.248908        0.565371
LBFGS:  110 21:45:02     -484.278317        0.251354
LBFGS:  111 21:45:02     -484.303058        0.216327
LBFGS:  112 21:45:03     -484.320560        0.222344
LBFGS:  113 21:45:04     -484.340146        0.220412
LBFGS:  114 21:45:04     -484.365009        0.237987
LBFGS:  115 21:45:05     -484.388229        0.175008
LBFGS:  116 21:45:05     -484.410060        0.206289
LBFGS:  117 21:45:06     -484.430236        0.204077
LBFGS:  118 21:45:07     -484.452477        0.252451
LBFGS:  119 21:45:07     -484.475909        0.273568
LBFGS:  120 21:45:08     -484.498683        0.301674
LBFGS:  121 21:45:09     -484.518715        0.308904
LBFGS:  122 21:45:09     -484.537707        0.230892
LBFGS:  123 21:45:10     -484.559027        0.203116
LBFGS:  124 21:45:11     -484.580842        0.256442
LBFGS:  125 21:45:11     -484.603562        0.279154
LBFGS:  126 21:45:12     -484.623792        0.214331
LBFGS:  127 21:45:12     -484.642449        0.210542
LBFGS:  128 21:45:13     -484.661975        0.295669
LBFGS:  129 21:45:14     -484.689154        0.401151
LBFGS:  130 21:45:14     -484.718332        0.308726
LBFGS:  131 21:45:15     -484.741818        0.382969
LBFGS:  132 21:45:15     -484.763953        0.216638
LBFGS:  133 21:45:16     -484.787856        0.235513
LBFGS:  134 21:45:17     -484.812531        0.264937
LBFGS:  135 21:45:17     -484.835766        0.402124
LBFGS:  136 21:45:18     -484.858430        0.217953
LBFGS:  137 21:45:18     -484.877321        0.179554
LBFGS:  138 21:45:19     -484.898387        0.261446
LBFGS:  139 21:45:19     -484.921435        0.243394
LBFGS:  140 21:45:20     -484.948703        0.319621
LBFGS:  141 21:45:21     -484.971011        0.261375
LBFGS:  142 21:45:21     -484.991352        0.230271
LBFGS:  143 21:45:22     -485.011476        0.211258
LBFGS:  144 21:45:23     -485.036650        0.291015
LBFGS:  145 21:45:23     -485.059316        0.183163
LBFGS:  146 21:45:24     -485.079177        0.199940
LBFGS:  147 21:45:24     -485.097575        0.197279
LBFGS:  148 21:45:25     -485.115220        0.225396
LBFGS:  149 21:45:25     -485.131850        0.206028
LBFGS:  150 21:45:26     -485.148505        0.180702
LBFGS:  151 21:45:27     -485.164133        0.192611
LBFGS:  152 21:45:27     -485.179739        0.192113
LBFGS:  153 21:45:28     -485.193961        0.157355
LBFGS:  154 21:45:28     -485.206883        0.150161
LBFGS:  155 21:45:29     -485.217582        0.131592
LBFGS:  156 21:45:30     -485.226837        0.132444
LBFGS:  157 21:45:30     -485.236188        0.135832
LBFGS:  158 21:45:31     -485.246934        0.128134
LBFGS:  159 21:45:32     -485.258847        0.150498
LBFGS:  160 21:45:32     -485.271095        0.170130
LBFGS:  161 21:45:33     -485.282843        0.206553
LBFGS:  162 21:45:33     -485.293838        0.155075
LBFGS:  163 21:45:34     -485.304935        0.155148
LBFGS:  164 21:45:35     -485.316105        0.131736
LBFGS:  165 21:45:35     -485.327063        0.189752
LBFGS:  166 21:45:36     -485.337150        0.153041
LBFGS:  167 21:45:36     -485.347754        0.150834
LBFGS:  168 21:45:37     -485.359310        0.153122
LBFGS:  169 21:45:38     -485.371676        0.162032
LBFGS:  170 21:45:38     -485.382159        0.141829
LBFGS:  171 21:45:39     -485.390717        0.119533
LBFGS:  172 21:45:39     -485.399287        0.143391
LBFGS:  173 21:45:40     -485.410824        0.179853
LBFGS:  174 21:45:40     -485.424947        0.205613
LBFGS:  175 21:45:41     -485.438451        0.241444
LBFGS:  176 21:45:42     -485.448004        0.214438
LBFGS:  177 21:45:42     -485.456397        0.134944
LBFGS:  178 21:45:43     -485.464157        0.134600
LBFGS:  179 21:45:44     -485.473787        0.186862
LBFGS:  180 21:45:44     -485.480682        0.173867
LBFGS:  181 21:45:45     -485.487156        0.115708
LBFGS:  182 21:45:45     -485.493831        0.128686
LBFGS:  183 21:45:46     -485.501392        0.116803
LBFGS:  184 21:45:47     -485.508188        0.154473
LBFGS:  185 21:45:47     -485.513987        0.102476
LBFGS:  186 21:45:48     -485.519603        0.105021
LBFGS:  187 21:45:48     -485.525997        0.152851
LBFGS:  188 21:45:49     -485.532837        0.173253
LBFGS:  189 21:45:50     -485.538829        0.115083
LBFGS:  190 21:45:50     -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