File size: 7,790 Bytes
f0fdb88
 
 
 
1925de9
f0fdb88
da724dc
f0fdb88
 
 
 
 
da724dc
 
 
f0fdb88
 
 
da724dc
 
 
 
 
1effaf5
 
 
 
 
8b028aa
1effaf5
 
 
8b028aa
f0fdb88
 
 
 
da724dc
f0fdb88
 
 
 
 
 
 
 
 
 
 
 
 
 
da724dc
f0fdb88
 
 
 
 
 
 
 
 
 
da724dc
f0fdb88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1925de9
f0fdb88
da724dc
f0fdb88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1925de9
f0fdb88
 
1effaf5
 
 
 
 
 
 
f0fdb88
 
da724dc
f0fdb88
 
 
da724dc
f0fdb88
 
 
 
 
 
 
1925de9
f0fdb88
da724dc
f0fdb88
 
 
 
 
c1d2139
 
 
 
da724dc
 
c1d2139
 
f0fdb88
 
 
 
c1d2139
 
 
da724dc
c1d2139
 
 
1925de9
c1d2139
1925de9
c1d2139
 
f0fdb88
1effaf5
c1d2139
f0fdb88
da724dc
f0fdb88
 
 
 
 
1925de9
f0fdb88
 
 
 
 
 
 
 
da724dc
 
 
f0fdb88
 
da724dc
 
 
 
f0fdb88
 
 
da724dc
f0fdb88
 
 
da724dc
f0fdb88
cf512f3
f0fdb88
 
 
 
 
1925de9
f0fdb88
 
 
 
 
1925de9
f0fdb88
 
 
 
c1d2139
1925de9
c1d2139
da724dc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f0fdb88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a671cbd
f0fdb88
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pathlib import Path\n",
    "\n",
    "from dask.distributed import Client\n",
    "from dask_jobqueue import SLURMCluster\n",
    "from mlip_arena.models import REGISTRY, MLIPEnum\n",
    "from mlip_arena.tasks.md import run as MD\n",
    "from mlip_arena.tasks.utils import get_calculator\n",
    "from prefect import flow\n",
    "from prefect_dask import DaskTaskRunner\n",
    "\n",
    "from ase import Atoms, units\n",
    "from ase.build import molecule\n",
    "from ase.io import read, write\n",
    "from pymatgen.core import Molecule\n",
    "from pymatgen.io.packmol import PackmolBoxGen"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "jp-MarkdownHeadingCollapsed": true,
    "tags": []
   },
   "source": [
    "## Intial configuration"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "h2 = molecule(\"H2\")\n",
    "o2 = molecule(\"O2\")\n",
    "h2o = molecule(\"H2O\")\n",
    "\n",
    "write(\"h2.xyz\", h2)\n",
    "write(\"o2.xyz\", o2)\n",
    "write(\"h2o.xyz\", h2o)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "h2 = Molecule.from_file(\"h2.xyz\")\n",
    "o2 = Molecule.from_file(\"o2.xyz\")\n",
    "h2o = Molecule.from_file(\"h2o.xyz\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "molecules = []\n",
    "\n",
    "for m, number in zip([h2, o2], [128, 64]):\n",
    "    molecules.append(\n",
    "        {\n",
    "            \"name\": m.composition.to_pretty_string(),\n",
    "            \"number\": number,\n",
    "            \"coords\": m,\n",
    "        }\n",
    "    )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "tolerance = 2.0\n",
    "input_gen = PackmolBoxGen(\n",
    "    tolerance=tolerance,\n",
    "    seed=1,\n",
    ")\n",
    "margin = 0.5 * tolerance\n",
    "\n",
    "a = 30\n",
    "\n",
    "packmol_set = input_gen.get_input_set(\n",
    "    molecules=molecules,\n",
    "    box=[margin, margin, margin, a - margin, a - margin, a - margin],\n",
    ")\n",
    "packmol_set.write_input(\".\")\n",
    "packmol_set.run(\".\")\n",
    "\n",
    "atoms = read(\"packmol_out.xyz\")\n",
    "atoms.cell = [a, a, a]\n",
    "atoms.pbc = True\n",
    "\n",
    "print(atoms)\n",
    "\n",
    "write(f\"{atoms.get_chemical_formula()}.extxyz\", atoms)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Run workflow"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "atoms = read(\"H256O128.extxyz\")\n",
    "print(atoms)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "nodes_per_alloc = 1\n",
    "gpus_per_alloc = 4\n",
    "ntasks = 1\n",
    "\n",
    "cluster_kwargs = dict(\n",
    "    cores=1,\n",
    "    memory=\"64 GB\",\n",
    "    shebang=\"#!/bin/bash\",\n",
    "    account=\"m4282\",\n",
    "    walltime=\"00:30:00\",\n",
    "    job_mem=\"0\",\n",
    "    job_script_prologue=[\n",
    "        \"source ~/.bashrc\",\n",
    "        \"module load python\",\n",
    "        \"source activate /pscratch/sd/c/cyrusyc/.conda/mlip-arena\",\n",
    "    ],\n",
    "    job_directives_skip=[\"-n\", \"--cpus-per-task\", \"-J\"],\n",
    "    job_extra_directives=[\n",
    "        \"-J combustion-water\",\n",
    "        \"-q debug\",\n",
    "        f\"-N {nodes_per_alloc}\",\n",
    "        \"-C gpu\",\n",
    "        f\"-G {gpus_per_alloc}\",\n",
    "        \"--exclusive\",\n",
    "    ],\n",
    "    death_timeout=86400,\n",
    ")\n",
    "\n",
    "cluster = SLURMCluster(**cluster_kwargs)\n",
    "\n",
    "\n",
    "print(cluster.job_script())\n",
    "cluster.adapt(minimum_jobs=1, maximum_jobs=1)\n",
    "client = Client(cluster)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "@flow(task_runner=DaskTaskRunner(address=client.scheduler.address), log_prints=True)\n",
    "def combustion(atoms: Atoms):\n",
    "    futures = []\n",
    "\n",
    "    for model in MLIPEnum:\n",
    "        if model.name != \"MatterSim\":\n",
    "            continue\n",
    "\n",
    "        future = MD.submit(\n",
    "            atoms=atoms,\n",
    "            calculator=get_calculator(\n",
    "                calculator_name=model,\n",
    "                calculator_kwargs=None,\n",
    "            ),\n",
    "            ensemble=\"nvt\",\n",
    "            dynamics=\"nose-hoover\",\n",
    "            time_step=None,\n",
    "            dynamics_kwargs=dict(ttime=25 * units.fs, pfactor=None),\n",
    "            total_time=1000_000,\n",
    "            temperature=[300, 3000, 3000, 300],\n",
    "            pressure=None,\n",
    "            velocity_seed=0,\n",
    "            traj_file=Path(REGISTRY[model.name][\"family\"])\n",
    "            / f\"{model.name}_{atoms.get_chemical_formula()}.traj\",\n",
    "            traj_interval=1000,\n",
    "            restart=True,\n",
    "        )\n",
    "\n",
    "        futures.append(future)\n",
    "\n",
    "    return [future.result() for future in futures]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "results = combustion(atoms)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def combustion(atoms: Atoms):\n",
    "    futures = []\n",
    "\n",
    "    for model in MLIPEnum:\n",
    "        if model.name != \"MatterSim\":\n",
    "            continue\n",
    "\n",
    "        future = MD(\n",
    "            atoms=atoms,\n",
    "            calculator=get_calculator(\n",
    "                calculator_name=model,\n",
    "                calculator_kwargs=None,\n",
    "            ),\n",
    "            ensemble=\"nvt\",\n",
    "            dynamics=\"nose-hoover\",\n",
    "            time_step=None,\n",
    "            dynamics_kwargs=dict(ttime=25 * units.fs, pfactor=None),\n",
    "            total_time=1000_000,\n",
    "            temperature=[300, 3000, 3000, 300],\n",
    "            pressure=None,\n",
    "            velocity_seed=0,\n",
    "            traj_file=Path(REGISTRY[model.name][\"family\"])\n",
    "            / f\"{model.name}_{atoms.get_chemical_formula()}.traj\",\n",
    "            traj_interval=1000,\n",
    "            restart=True,\n",
    "        )\n",
    "\n",
    "        futures.append(future)\n",
    "\n",
    "    return [future.result() for future in futures]\n",
    "\n",
    "\n",
    "results = combustion(atoms)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "mlip-arena",
   "language": "python",
   "name": "mlip-arena"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.8"
  },
  "widgets": {
   "application/vnd.jupyter.widget-state+json": {
    "state": {},
    "version_major": 2,
    "version_minor": 0
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}