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:197: 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.169908427446721, de=-14.169908427446721, acc=np.float64(1.1067904436111663e+238), random=0.6573675854710377
Inserted particle 1
Old energy=-14.169908427446721, new energy=-28.388449306260227, de=-14.218540878813506, acc=np.float64(7.261977566078882e+238), random=0.7694578719378116
Inserted particle 2
Old energy=-28.388449306260227, new energy=-42.56138109854783, de=-14.1729317922876, acc=np.float64(1.2441012080377765e+238), random=0.6663921049033288
Inserted particle 3
Old energy=-42.56138109854783, new energy=-56.7204517043842, de=-14.159070605836376, acc=np.float64(7.277763676746241e+237), random=0.5196536887579605
Inserted particle 4
Old energy=-56.7204517043842, new energy=-70.95493496595596, de=-14.234483261571754, acc=np.float64(1.3454737732753098e+239), random=0.06739574665921966
Inserted particle 5
Old energy=-70.95493496595596, new energy=-85.20119759619391, de=-14.24626263023795, acc=np.float64(2.122071379141933e+239), random=0.49961201043327175
Inserted particle 6
Old energy=-85.20119759619391, new energy=-99.4226181862961, de=-14.221420590102198, acc=np.float64(8.117680232384532e+238), random=0.1050746012583641
Inserted particle 7
Old energy=-99.4226181862961, new energy=-113.7966213027276, de=-14.374003116431496, acc=np.float64(2.969657990416907e+241), random=0.9378701885604214
Inserted particle 8
Old energy=-113.7966213027276, new energy=-128.13062203759785, de=-14.334000734870244, acc=np.float64(6.319689981838217e+240), random=0.3762683149324123
Inserted particle 9
Old energy=-128.13062203759785, new energy=-141.85615337199786, de=-13.725531334400017, acc=np.float64(3.791894695894241e+230), random=0.6727933834766038
Inserted particle 10
Old energy=-141.85615337199786, new energy=-156.06180658142108, de=-14.205653209423218, acc=np.float64(4.411146815908922e+238), random=0.09706066849775918
Inserted particle 11
Old energy=-156.06180658142108, new energy=-170.53713931561305, de=-14.475332734191966, acc=np.float64(1.4961311672701558e+243), random=0.47590567428965436
Inserted particle 12
Old energy=-170.53713931561305, new energy=-184.44423715363098, de=-13.907097838017933, acc=np.float64(4.256379248324519e+233), random=0.1445197281328413
Inserted particle 13
Old energy=-184.44423715363098, new energy=-198.8723316569115, de=-14.428094503280533, acc=np.float64(2.40658967246052e+242), random=0.6096984257895941
Inserted particle 14
Old energy=-198.8723316569115, new energy=-213.04724634722007, de=-14.174914690308555, acc=np.float64(1.3432812220825123e+238), random=0.10084644599814097
Inserted particle 15
Old energy=-213.04724634722007, new energy=-225.548543930126, de=-12.50129758290592, acc=np.float64(1.0295025792403101e+210), random=0.8475810108898351
Inserted particle 16
Old energy=-225.548543930126, new energy=-237.81867754510063, de=-12.27013361497464, acc=np.float64(1.3466116834684025e+206), random=0.9573928760728474
Inserted particle 17
Old energy=-237.81867754510063, new energy=-251.6971639080533, de=-13.878486362952685, acc=np.float64(1.4073059625976879e+233), random=0.3273810695294246
Inserted particle 18
Old energy=-251.6971639080533, new energy=-240.75598269219512, de=10.941181215858194, acc=np.float64(1.5710242942247803e-184), random=0.06247404096988407
Old energy=-251.6971639080533, new energy=-265.98484303063964, de=-14.287679122586326, acc=np.float64(1.0532383716559922e+240), random=0.9267631049637567
Inserted particle 19
Old energy=-265.98484303063964, new energy=-273.78462117763786, de=-7.7997781469982215, acc=np.float64(1.0728779686195097e+131), random=0.3402871935608006
Inserted particle 20
Old energy=-273.78462117763786, new energy=-285.09649060859454, de=-11.311869430956676, acc=np.float64(1.0742544121330106e+190), random=0.1776678297264329
Inserted particle 21
Old energy=-285.09649060859454, new energy=-298.767292786814, de=-13.670802178219446, acc=np.float64(4.565061135204045e+229), random=0.6002380235886438
Inserted particle 22
Old energy=-298.767292786814, new energy=-286.09731608351757, de=12.669976703296413, acc=np.float64(1.4245808268214723e-213), random=0.868138468423006
Old energy=-298.767292786814, new energy=-312.4208127465705, de=-13.653519959756522, acc=np.float64(2.3394728388110177e+229), random=0.657014836768514
Inserted particle 23
Old energy=-312.4208127465705, new energy=-315.2519351263058, de=-2.831122379735291, acc=np.float64(3.63729764383905e+47), random=0.5318473353823712
Old energy=-312.4208127465705, new energy=-324.3828667679099, de=-11.962054021339384, acc=np.float64(8.989410999100251e+200), random=0.9616436876719956
Inserted particle 24
Old energy=-324.3828667679099, new energy=-334.7276976756465, de=-10.344830907736593, acc=np.float64(6.103366546767006e+173), random=0.21200357006485315
Inserted particle 25
Old energy=-334.7276976756465, new energy=-348.8852358657079, de=-14.157538190061416, acc=np.float64(6.85890027328025e+237), random=0.4817459907937399
Inserted particle 26
Old energy=-348.8852358657079, new energy=-360.37717264453835, de=-11.49193677883045, acc=np.float64(1.1379062387516487e+193), random=0.7175118692379753
Inserted particle 27
Old energy=-360.37717264453835, new energy=-370.7194668673783, de=-10.34229422283994, acc=np.float64(5.532927860076645e+173), random=0.4094954707153864
Inserted particle 28
Old energy=-370.7194668673783, new energy=-381.9078188817429, de=-11.188352014364625, acc=np.float64(9.038683297532999e+187), random=0.19004083637014857
Inserted particle 29
Old energy=-381.9078188817429, new energy=-390.1891332215734, de=-8.281314339830487, acc=np.float64(1.3182721379881335e+139), random=0.2593074228409512
Inserted particle 30
Old energy=-390.1891332215734, new energy=-392.7194210876554, de=-2.5302878660820056, acc=np.float64(3.2135105364398734e+42), random=0.368706041406911
Old energy=-390.1891332215734, new energy=-343.2277035252213, de=46.96142969635213, acc=np.float64(0.0), random=0.29948735641057544
Old energy=-390.1891332215734, new energy=-391.9470646471931, de=-1.757931425619688, acc=np.float64(3.4037542061970436e+29), random=0.11024899776641639
Old energy=-390.1891332215734, new energy=-397.4714077514512, de=-7.282274529877782, acc=np.float64(2.1720471159658727e+122), random=0.853089891818317
Inserted particle 31
Old energy=-397.4714077514512, new energy=-201.84842710657364, de=195.62298064487754, acc=np.float64(0.0), random=0.7172312048224184
Old energy=-397.4714077514512, new energy=-409.5175885928934, de=-12.046180841442208, acc=np.float64(2.328091753690233e+202), random=0.7007421832233066
Inserted particle 32
Old energy=-409.5175885928934, new energy=-422.30745403223574, de=-12.78986543934235, acc=np.float64(7.250295553023568e+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:197: 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 14:57:03     -422.307454       13.877663
LBFGS:    1 14:57:04     -435.791603       15.542238
LBFGS:    2 14:57:04     -445.636460        8.628340
LBFGS:    3 14:57:05     -451.808973        4.176232
LBFGS:    4 14:57:05     -455.545885        3.666724
LBFGS:    5 14:57:06     -458.932705        3.087802
LBFGS:    6 14:57:06     -462.238560        2.496349
LBFGS:    7 14:57:07     -464.286151        3.489929
LBFGS:    8 14:57:07     -466.032275        2.215424
LBFGS:    9 14:57:08     -467.425347        1.697507
LBFGS:   10 14:57:08     -468.662562        2.029074
LBFGS:   11 14:57:09     -469.699687        2.413723
LBFGS:   12 14:57:09     -470.733457        1.752417
LBFGS:   13 14:57:10     -471.567068        1.079853
LBFGS:   14 14:57:10     -472.669489        1.711636
LBFGS:   15 14:57:11     -473.205563        1.634225
LBFGS:   16 14:57:11     -473.831545        1.175250
LBFGS:   17 14:57:12     -474.157829        2.514301
LBFGS:   18 14:57:12     -474.720307        1.106639
LBFGS:   19 14:57:13     -475.243021        0.929779
LBFGS:   20 14:57:13     -475.673385        1.057766
LBFGS:   21 14:57:14     -475.932370        0.881880
LBFGS:   22 14:57:14     -476.175535        0.882676
LBFGS:   23 14:57:15     -476.420049        1.188850
LBFGS:   24 14:57:15     -476.594292        0.765145
LBFGS:   25 14:57:16     -476.862982        0.805157
LBFGS:   26 14:57:16     -477.133243        0.879516
LBFGS:   27 14:57:17     -477.358436        1.161428
LBFGS:   28 14:57:18     -477.583134        0.853986
LBFGS:   29 14:57:18     -477.816074        0.892980
LBFGS:   30 14:57:19     -478.002069        0.802879
LBFGS:   31 14:57:19     -478.159765        0.907363
LBFGS:   32 14:57:20     -478.304739        0.732561
LBFGS:   33 14:57:20     -478.516317        0.698569
LBFGS:   34 14:57:21     -478.721229        0.788372
LBFGS:   35 14:57:21     -478.936063        0.775582
LBFGS:   36 14:57:22     -479.103873        0.650802
LBFGS:   37 14:57:22     -479.262580        0.675939
LBFGS:   38 14:57:23     -479.421737        0.860773
LBFGS:   39 14:57:23     -479.601171        0.640421
LBFGS:   40 14:57:24     -479.790530        0.622390
LBFGS:   41 14:57:24     -479.910151        0.659465
LBFGS:   42 14:57:25     -480.006815        0.481454
LBFGS:   43 14:57:25     -480.136074        0.590734
LBFGS:   44 14:57:26     -480.262922        0.953696
LBFGS:   45 14:57:26     -480.392769        0.508664
LBFGS:   46 14:57:27     -480.490737        0.586978
LBFGS:   47 14:57:27     -480.588302        0.639654
LBFGS:   48 14:57:28     -480.763744        0.638177
LBFGS:   49 14:57:28     -480.897251        0.534118
LBFGS:   50 14:57:29     -481.021311        0.485723
LBFGS:   51 14:57:29     -481.127862        0.582302
LBFGS:   52 14:57:30     -481.232738        0.612588
LBFGS:   53 14:57:30     -481.347576        0.649466
LBFGS:   54 14:57:31     -481.454183        0.629958
LBFGS:   55 14:57:31     -481.556168        0.408971
LBFGS:   56 14:57:32     -481.641221        0.448516
LBFGS:   57 14:57:32     -481.724783        0.448668
LBFGS:   58 14:57:33     -481.835808        0.413646
LBFGS:   59 14:57:33     -481.914032        0.685601
LBFGS:   60 14:57:34     -481.981834        0.460009
LBFGS:   61 14:57:34     -482.056799        0.391624
LBFGS:   62 14:57:35     -482.132678        0.308693
LBFGS:   63 14:57:35     -482.215704        0.362441
LBFGS:   64 14:57:36     -482.271780        0.359791
LBFGS:   65 14:57:36     -482.338623        0.381272
LBFGS:   66 14:57:37     -482.395852        0.422197
LBFGS:   67 14:57:37     -482.458444        0.386613
LBFGS:   68 14:57:38     -482.532481        0.394048
LBFGS:   69 14:57:38     -482.601371        0.402546
LBFGS:   70 14:57:39     -482.653404        0.353862
LBFGS:   71 14:57:39     -482.691509        0.377310
LBFGS:   72 14:57:40     -482.734611        0.330249
LBFGS:   73 14:57:40     -482.799811        0.381771
LBFGS:   74 14:57:41     -482.857080        0.447662
LBFGS:   75 14:57:42     -482.917838        0.376530
LBFGS:   76 14:57:42     -482.968576        0.315092
LBFGS:   77 14:57:43     -483.020101        0.310454
LBFGS:   78 14:57:43     -483.066142        0.347737
LBFGS:   79 14:57:44     -483.112253        0.311655
LBFGS:   80 14:57:44     -483.152855        0.330687
LBFGS:   81 14:57:45     -483.191872        0.268214
LBFGS:   82 14:57:45     -483.224914        0.444314
LBFGS:   83 14:57:46     -483.260812        0.273215
LBFGS:   84 14:57:46     -483.299696        0.464131
LBFGS:   85 14:57:47     -483.342284        0.301555
LBFGS:   86 14:57:47     -483.380349        0.306767
LBFGS:   87 14:57:48     -483.408996        0.324211
LBFGS:   88 14:57:48     -483.442423        0.342084
LBFGS:   89 14:57:49     -483.484117        0.290656
LBFGS:   90 14:57:49     -483.530734        0.297088
LBFGS:   91 14:57:50     -483.560967        0.248771
LBFGS:   92 14:57:50     -483.600029        0.496099
LBFGS:   93 14:57:51     -483.648500        0.461463
LBFGS:   94 14:57:51     -483.694032        0.991481
LBFGS:   95 14:57:52     -483.760075        0.537253
LBFGS:   96 14:57:52     -483.806151        0.382515
LBFGS:   97 14:57:53     -483.840036        0.343295
LBFGS:   98 14:57:53     -483.870776        0.350422
LBFGS:   99 14:57:54     -483.921631        0.429895
LBFGS:  100 14:57:54     -483.964606        0.493320
LBFGS:  101 14:57:55     -483.996736        0.413153
LBFGS:  102 14:57:56     -484.032976        0.290601
LBFGS:  103 14:57:56     -484.070603        0.287103
LBFGS:  104 14:57:57     -484.102650        0.266610
LBFGS:  105 14:57:57     -484.135817        0.265643
LBFGS:  106 14:57:58     -484.162171        0.250369
LBFGS:  107 14:57:58     -484.189260        0.292546
LBFGS:  108 14:57:59     -484.218740        0.307706
LBFGS:  109 14:57:59     -484.248908        0.565371
LBFGS:  110 14:58:00     -484.278317        0.251354
LBFGS:  111 14:58:00     -484.303058        0.216327
LBFGS:  112 14:58:01     -484.320560        0.222344
LBFGS:  113 14:58:01     -484.340146        0.220412
LBFGS:  114 14:58:02     -484.365009        0.237987
LBFGS:  115 14:58:02     -484.388229        0.175008
LBFGS:  116 14:58:03     -484.410060        0.206289
LBFGS:  117 14:58:03     -484.430236        0.204077
LBFGS:  118 14:58:04     -484.452477        0.252451
LBFGS:  119 14:58:04     -484.475909        0.273568
LBFGS:  120 14:58:05     -484.498683        0.301674
LBFGS:  121 14:58:05     -484.518715        0.308904
LBFGS:  122 14:58:06     -484.537707        0.230892
LBFGS:  123 14:58:06     -484.559027        0.203116
LBFGS:  124 14:58:07     -484.580842        0.256442
LBFGS:  125 14:58:07     -484.603562        0.279154
LBFGS:  126 14:58:08     -484.623792        0.214331
LBFGS:  127 14:58:08     -484.642449        0.210542
LBFGS:  128 14:58:09     -484.661975        0.295669
LBFGS:  129 14:58:09     -484.689154        0.401151
LBFGS:  130 14:58:10     -484.718332        0.308726
LBFGS:  131 14:58:10     -484.741818        0.382969
LBFGS:  132 14:58:11     -484.763953        0.216638
LBFGS:  133 14:58:12     -484.787856        0.235513
LBFGS:  134 14:58:12     -484.812531        0.264937
LBFGS:  135 14:58:13     -484.835766        0.402124
LBFGS:  136 14:58:13     -484.858430        0.217953
LBFGS:  137 14:58:14     -484.877321        0.179554
LBFGS:  138 14:58:14     -484.898387        0.261446
LBFGS:  139 14:58:15     -484.921435        0.243394
LBFGS:  140 14:58:15     -484.948703        0.319621
LBFGS:  141 14:58:16     -484.971011        0.261375
LBFGS:  142 14:58:16     -484.991352        0.230271
LBFGS:  143 14:58:17     -485.011476        0.211258
LBFGS:  144 14:58:17     -485.036650        0.291015
LBFGS:  145 14:58:18     -485.059316        0.183163
LBFGS:  146 14:58:18     -485.079177        0.199940
LBFGS:  147 14:58:19     -485.097575        0.197279
LBFGS:  148 14:58:19     -485.115220        0.225396
LBFGS:  149 14:58:20     -485.131850        0.206028
LBFGS:  150 14:58:20     -485.148505        0.180702
LBFGS:  151 14:58:21     -485.164133        0.192611
LBFGS:  152 14:58:21     -485.179739        0.192113
LBFGS:  153 14:58:22     -485.193961        0.157355
LBFGS:  154 14:58:22     -485.206883        0.150161
LBFGS:  155 14:58:23     -485.217582        0.131592
LBFGS:  156 14:58:23     -485.226837        0.132444
LBFGS:  157 14:58:24     -485.236188        0.135832
LBFGS:  158 14:58:24     -485.246934        0.128134
LBFGS:  159 14:58:25     -485.258847        0.150498
LBFGS:  160 14:58:25     -485.271095        0.170130
LBFGS:  161 14:58:26     -485.282843        0.206553
LBFGS:  162 14:58:26     -485.293838        0.155075
LBFGS:  163 14:58:27     -485.304935        0.155148
LBFGS:  164 14:58:27     -485.316105        0.131736
LBFGS:  165 14:58:28     -485.327063        0.189752
LBFGS:  166 14:58:28     -485.337150        0.153041
LBFGS:  167 14:58:29     -485.347754        0.150834
LBFGS:  168 14:58:30     -485.359310        0.153122
LBFGS:  169 14:58:30     -485.371676        0.162032
LBFGS:  170 14:58:31     -485.382159        0.141829
LBFGS:  171 14:58:31     -485.390717        0.119533
LBFGS:  172 14:58:32     -485.399287        0.143391
LBFGS:  173 14:58:32     -485.410824        0.179853
LBFGS:  174 14:58:33     -485.424947        0.205613
LBFGS:  175 14:58:33     -485.438451        0.241444
LBFGS:  176 14:58:34     -485.448004        0.214438
LBFGS:  177 14:58:34     -485.456397        0.134944
LBFGS:  178 14:58:35     -485.464157        0.134600
LBFGS:  179 14:58:35     -485.473787        0.186862
LBFGS:  180 14:58:36     -485.480682        0.173867
LBFGS:  181 14:58:36     -485.487156        0.115708
LBFGS:  182 14:58:37     -485.493831        0.128686
LBFGS:  183 14:58:37     -485.501392        0.116803
LBFGS:  184 14:58:38     -485.508188        0.154473
LBFGS:  185 14:58:38     -485.513987        0.102476
LBFGS:  186 14:58:39     -485.519603        0.105021
LBFGS:  187 14:58:39     -485.525997        0.152851
LBFGS:  188 14:58:40     -485.532837        0.173253
LBFGS:  189 14:58:40     -485.538829        0.115083
LBFGS:  190 14:58:41     -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