|
30 | 30 | "\n", |
31 | 31 | "After working through this notebook, you will be able to:\n", |
32 | 32 | "\n", |
33 | | - "1. Import [the structure of Si](https://materialsproject.org/materials/mp-149/) from Materials Project\n", |
| 33 | + "1. Import [the structure of Si](https://materialsproject.org/materials/mp-149/) from Materials Bank\n", |
34 | 34 | "2. Set up and run a single-point calculation using Quantum Espresso.\n", |
35 | 35 | "3. List files currently in the job's directory\n", |
36 | 36 | "4. Check metadata for every file (modification date, size, etc)\n", |
|
42 | 42 | "The explanation below assumes that the reader is familiar with the concepts used in Mat3ra platform and RESTful API. We outline these below and direct the reader to the original sources of information:\n", |
43 | 43 | "\n", |
44 | 44 | "- [Generating RESTful API authentication parameters](../system/get_authentication_params.ipynb)\n", |
45 | | - "- [Importing materials from materials project](../material/import_materials_from_materialsproject.ipynb)\n", |
46 | 45 | "- [Creating and submitting jobs](../job/create_and_submit_job.ipynb)" |
47 | 46 | ] |
48 | 47 | }, |
|
61 | 60 | "\n", |
62 | 61 | "ACCOUNT_ID and AUTH_TOKEN - Authentication parameters needed for when making requests to [Mat3ra.com's API Endpoints](https://docs.mat3ra.com/rest-api/endpoints/).\n", |
63 | 62 | "\n", |
64 | | - "MATERIALS_PROJECT_API_KEY - Authentication parameter needed for when making requests to [Material Project's API](https://materialsproject.org/open)\n", |
65 | | - "\n", |
66 | 63 | "ORGANIZATION_ID - Authentication parameter needed for when working with collaborative accounts https://docs.mat3ra.com/collaboration/organizations/overview/\n", |
67 | 64 | "\n", |
68 | 65 | "> <span style=\"color: orange\">**NOTE**</span>: If you are running this notebook from Jupyter, the variables ACCOUNT_ID, AUTH_TOKEN, MATERIALS_PROJECT_API_KEY, and ORGANIZATION_ID should be set in the file [settings.json](../../utils/settings.json) if you need to use these variables. To obtain API token parameters, please see the following link to the documentation explaining how to get them: https://docs.mat3ra.com/accounts/ui/preferences/api/" |
69 | 66 | ] |
70 | 67 | }, |
71 | 68 | { |
72 | 69 | "cell_type": "code", |
73 | | - "execution_count": null, |
74 | 70 | "metadata": { |
75 | 71 | "cellView": "form", |
76 | 72 | "colab": { |
|
79 | 75 | "id": "nXDYU_oP8GIr", |
80 | 76 | "outputId": "aee909b7-1a48-43c2-81b7-3659e0fc9c79" |
81 | 77 | }, |
82 | | - "outputs": [], |
83 | 78 | "source": [ |
84 | 79 | "# @title Authorization Form\n", |
85 | 80 | "ACCOUNT_ID = \"ACCOUNT_ID\" # @param {type:\"string\"}\n", |
86 | 81 | "AUTH_TOKEN = \"AUTH_TOKEN\" # @param {type:\"string\"}\n", |
87 | | - "MATERIALS_PROJECT_API_KEY = \"MATERIALS_PROJECT_API_KEY\" # @param {type:\"string\"}\n", |
88 | 82 | "ORGANIZATION_ID = \"ORGANIZATION_ID\" # @param {type:\"string\"}\n", |
89 | 83 | "\n", |
90 | 84 | "import os\n", |
|
95 | 89 | " dict(\n", |
96 | 90 | " ACCOUNT_ID=ACCOUNT_ID,\n", |
97 | 91 | " AUTH_TOKEN=AUTH_TOKEN,\n", |
98 | | - " MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n", |
99 | 92 | " ORGANIZATION_ID=ORGANIZATION_ID,\n", |
100 | 93 | " )\n", |
101 | 94 | " )\n", |
|
109 | 102 | " dict(\n", |
110 | 103 | " ACCOUNT_ID=apiConfig.get(\"accountId\"),\n", |
111 | 104 | " AUTH_TOKEN=apiConfig.get(\"authToken\"),\n", |
112 | | - " MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n", |
113 | 105 | " ORGANIZATION_ID=apiConfig.get(\"organizationId\") or \"\",\n", |
114 | 106 | " )\n", |
115 | 107 | " )\n", |
|
121 | 113 | " from utils.jupyterlite import install_packages\n", |
122 | 114 | "\n", |
123 | 115 | " await install_packages(\"\")" |
124 | | - ] |
| 116 | + ], |
| 117 | + "outputs": [], |
| 118 | + "execution_count": null |
125 | 119 | }, |
126 | 120 | { |
127 | 121 | "attachments": {}, |
|
135 | 129 | }, |
136 | 130 | { |
137 | 131 | "cell_type": "code", |
138 | | - "execution_count": null, |
139 | 132 | "metadata": { |
140 | 133 | "id": "rG9HfjnR8GIs" |
141 | 134 | }, |
142 | | - "outputs": [], |
143 | 135 | "source": [ |
144 | 136 | "# Import settings file and utils file\n", |
145 | | - "from utils.settings import ENDPOINT_ARGS, ACCOUNT_ID, MATERIALS_PROJECT_API_KEY\n", |
| 137 | + "from utils.settings import ENDPOINT_ARGS, ACCOUNT_ID\n", |
146 | 138 | "from utils.generic import (\n", |
147 | 139 | " wait_for_jobs_to_finish,\n", |
148 | 140 | " get_property_by_subworkflow_and_unit_indicies,\n", |
|
154 | 146 | "from exabyte_api_client.endpoints.jobs import JobEndpoints\n", |
155 | 147 | "from exabyte_api_client.endpoints.projects import ProjectEndpoints\n", |
156 | 148 | "from exabyte_api_client.endpoints.materials import MaterialEndpoints\n", |
157 | | - "from exabyte_api_client.endpoints.bank_workflows import BankWorkflowEndpoints\n", |
158 | | - "from exabyte_api_client.endpoints.properties import PropertiesEndpoints" |
159 | | - ] |
| 149 | + "from exabyte_api_client.endpoints.bank_materials import BankMaterialEndpoints\n", |
| 150 | + "from exabyte_api_client.endpoints.bank_workflows import BankWorkflowEndpoints" |
| 151 | + ], |
| 152 | + "outputs": [], |
| 153 | + "execution_count": null |
160 | 154 | }, |
161 | 155 | { |
162 | 156 | "attachments": {}, |
|
173 | 167 | "\n", |
174 | 168 | "The PBE functional is used in conjunction with an ultrasoft pseudopotential and a planewave basis set.\n", |
175 | 169 | "\n", |
176 | | - "The material we will investigate is elemental [Silicon](https://materialsproject.org/materials/mp-149/), as-is from Materials Project.\n", |
| 170 | + "The material we will investigate is elemental [Silicon](https://materialsproject.org/materials/mp-149/), as-is from Materials Bank.\n", |
177 | 171 | "\n", |
178 | | - "> <span style=\"color: orange\">Note</span>: This cell uses our API to copy the unit cell of silicon from Materials Project into your account. It then copies a workflow to get the total energy of a system using Quantum Espresso to your account. Finally, a job is created using the Quantum Espresso workflow for the silicon unit cell, and the job is submitted to the cluster. For more information, please refer to our [run-simulation-and-extract-properties](./run-simulations-and-extract-properties.ipynb) notebook, located in this directory." |
| 172 | + "> <span style=\"color: orange\">Note</span>: This cell uses our API to copy the unit cell of silicon from Materials Bank into your account. It then copies a workflow to get the total energy of a system using Quantum Espresso to your account. Finally, a job is created using the Quantum Espresso workflow for the silicon unit cell, and the job is submitted to the cluster. For more information, please refer to our [run-simulation-and-extract-properties](./run-simulations-and-extract-properties.ipynb) notebook, located in this directory." |
179 | 173 | ] |
180 | 174 | }, |
181 | 175 | { |
182 | 176 | "cell_type": "code", |
183 | | - "execution_count": null, |
184 | 177 | "metadata": { |
185 | 178 | "colab": { |
186 | 179 | "base_uri": "https://localhost:8080/" |
187 | 180 | }, |
188 | 181 | "id": "le9f28c08GIt", |
189 | 182 | "outputId": "27e9b94f-29dd-4742-9448-2e1bce79cb15" |
190 | 183 | }, |
191 | | - "outputs": [], |
192 | 184 | "source": [ |
193 | 185 | "# Get some account information\n", |
194 | 186 | "project_endpoints = ProjectEndpoints(*ENDPOINT_ARGS)\n", |
|
199 | 191 | "\n", |
200 | 192 | "# Get a workflow for the job from the bank, and copy it to our account\n", |
201 | 193 | "bank_workflow_endpoints = BankWorkflowEndpoints(*ENDPOINT_ARGS)\n", |
202 | | - "BANK_WORKFLOW_ID = \"84DAjE9YyTFndx6z3\"\n", |
203 | | - "workflow_id = bank_workflow_endpoints.copy(BANK_WORKFLOW_ID, owner_id)[\"_id\"]\n", |
204 | | - "\n", |
205 | | - "# Get materials for the job\n", |
| 194 | + "WORKFLOW_QUERY = {\"systemName\": \"espresso-total-energy\"}\n", |
| 195 | + "bank_workflow_id = bank_workflow_endpoints.list(WORKFLOW_QUERY)[0][\"_id\"]\n", |
| 196 | + "workflow_id = bank_workflow_endpoints.copy(bank_workflow_id, owner_id)[\"_id\"]\n", |
| 197 | + "\n", |
| 198 | + "# Get materials from bank and copy one to our account\n", |
| 199 | + "material_bank_endpoints = BankMaterialEndpoints(*ENDPOINT_ARGS)\n", |
| 200 | + "MATERIAL_QUERY = {\"formula\": \"Si\"}\n", |
| 201 | + "bank_materials = material_bank_endpoints.list(MATERIAL_QUERY)\n", |
| 202 | + "bank_material_id = bank_materials[0][\"_id\"]\n", |
206 | 203 | "material_endpoints = MaterialEndpoints(*ENDPOINT_ARGS)\n", |
207 | | - "material_project_id = [\"mp-149\"] # The importer expects a list\n", |
208 | | - "materials = material_endpoints.import_from_materialsproject(MATERIALS_PROJECT_API_KEY, material_project_id, owner_id)\n", |
| 204 | + "material_id = material_bank_endpoints.copy(bank_material_id, owner_id)[\"_id\"]\n", |
| 205 | + "materials = material_endpoints.list({\"owner._id\": owner_id})\n", |
209 | 206 | "\n", |
210 | 207 | "# Create the job\n", |
211 | 208 | "job_endpoints = JobEndpoints(*ENDPOINT_ARGS)\n", |
|
216 | 213 | "# Submit the job\n", |
217 | 214 | "job_endpoints.submit(job[\"_id\"])\n", |
218 | 215 | "wait_for_jobs_to_finish(job_endpoints, [job[\"_id\"]])" |
219 | | - ] |
| 216 | + ], |
| 217 | + "outputs": [], |
| 218 | + "execution_count": null |
220 | 219 | }, |
221 | 220 | { |
222 | 221 | "attachments": {}, |
|
243 | 242 | }, |
244 | 243 | { |
245 | 244 | "cell_type": "code", |
246 | | - "execution_count": null, |
247 | 245 | "metadata": { |
248 | 246 | "colab": { |
249 | 247 | "base_uri": "https://localhost:8080/" |
250 | 248 | }, |
251 | 249 | "id": "yijRe7qp8GIv", |
252 | 250 | "outputId": "19b147fc-736e-41f0-bd0f-6f69e77b0adf" |
253 | 251 | }, |
254 | | - "outputs": [], |
255 | 252 | "source": [ |
256 | 253 | "files = job_endpoints.list_files(job[\"_id\"])\n", |
257 | 254 | "paths = [file[\"key\"] for file in files]\n", |
258 | 255 | "for path in paths:\n", |
259 | 256 | " if \"outdir\" not in path:\n", |
260 | 257 | " print(path)" |
261 | | - ] |
| 258 | + ], |
| 259 | + "outputs": [], |
| 260 | + "execution_count": null |
262 | 261 | }, |
263 | 262 | { |
264 | 263 | "attachments": {}, |
|
283 | 282 | }, |
284 | 283 | { |
285 | 284 | "cell_type": "code", |
286 | | - "execution_count": null, |
287 | 285 | "metadata": { |
288 | 286 | "colab": { |
289 | 287 | "base_uri": "https://localhost:8080/" |
290 | 288 | }, |
291 | 289 | "id": "U2dq0A1e8GIw", |
292 | 290 | "outputId": "7b4f8c36-6342-46fa-d02e-0825b44e6c64" |
293 | 291 | }, |
294 | | - "outputs": [], |
295 | 292 | "source": [ |
296 | 293 | "for file in files:\n", |
297 | 294 | " if file[\"name\"] == \"pw_scf.out\":\n", |
298 | 295 | " output_file_metadata = file\n", |
299 | 296 | "display_JSON(output_file_metadata)" |
300 | | - ] |
| 297 | + ], |
| 298 | + "outputs": [], |
| 299 | + "execution_count": null |
301 | 300 | }, |
302 | 301 | { |
303 | 302 | "attachments": {}, |
|
313 | 312 | }, |
314 | 313 | { |
315 | 314 | "cell_type": "code", |
316 | | - "execution_count": null, |
317 | 315 | "metadata": { |
318 | 316 | "colab": { |
319 | 317 | "base_uri": "https://localhost:8080/" |
320 | 318 | }, |
321 | 319 | "id": "OpdOMuDT8GIw", |
322 | 320 | "outputId": "e4e2e6b1-8431-439a-8606-ae500534e601" |
323 | 321 | }, |
324 | | - "outputs": [], |
325 | 322 | "source": [ |
326 | 323 | "import urllib\n", |
327 | 324 | "\n", |
|
336 | 333 | "lines = output_file.split(\"\\n\")\n", |
337 | 334 | "for line in lines[-90:]:\n", |
338 | 335 | " print(line)" |
339 | | - ] |
| 336 | + ], |
| 337 | + "outputs": [], |
| 338 | + "execution_count": null |
340 | 339 | }, |
341 | 340 | { |
342 | 341 | "attachments": {}, |
|
352 | 351 | }, |
353 | 352 | { |
354 | 353 | "cell_type": "code", |
355 | | - "execution_count": null, |
356 | 354 | "metadata": { |
357 | 355 | "id": "osy2JKpB8GIx" |
358 | 356 | }, |
359 | | - "outputs": [], |
360 | 357 | "source": [ |
361 | 358 | "# We've already got an output file, so let's grab the input file we sent to Quantum Espresso\n", |
362 | 359 | "for file in files:\n", |
363 | 360 | " if \"pw_scf.in\" == file[\"name\"]:\n", |
364 | 361 | " input_file_metadata = file\n", |
365 | 362 | "server_response = urllib.request.urlopen(input_file_metadata[\"signedUrl\"])\n", |
366 | 363 | "input_file_bytes = server_response.read()" |
367 | | - ] |
| 364 | + ], |
| 365 | + "outputs": [], |
| 366 | + "execution_count": null |
368 | 367 | }, |
369 | 368 | { |
370 | 369 | "cell_type": "code", |
371 | | - "execution_count": null, |
372 | 370 | "metadata": { |
373 | 371 | "id": "COPinBrO8GIx" |
374 | 372 | }, |
375 | | - "outputs": [], |
376 | 373 | "source": [ |
377 | 374 | "# Let's write the input file to disk. Note that we get files as a bytes string from the server, which is convenient for binaries, images, and other non-human-readable data.\n", |
378 | 375 | "# Although we could decode before writing to disk, we can just write it directly with the \"wb\" (write bytes) file mode.\n", |
379 | 376 | "with open(input_file_metadata[\"name\"], \"wb\") as file_descriptor:\n", |
380 | 377 | " file_descriptor.write(input_file_bytes)" |
381 | | - ] |
| 378 | + ], |
| 379 | + "outputs": [], |
| 380 | + "execution_count": null |
382 | 381 | }, |
383 | 382 | { |
384 | 383 | "cell_type": "code", |
385 | | - "execution_count": null, |
386 | 384 | "metadata": { |
387 | 385 | "id": "rzDcWyrL8GIx" |
388 | 386 | }, |
389 | | - "outputs": [], |
390 | 387 | "source": [ |
391 | 388 | "# Now, let's write our output file to the disk. Note that because we already decoded it, we can just use the 'w' file mode.\n", |
392 | 389 | "with open(output_file_metadata[\"name\"], \"w\") as file_descriptor:\n", |
393 | 390 | " file_descriptor.write(output_file)" |
394 | | - ] |
| 391 | + ], |
| 392 | + "outputs": [], |
| 393 | + "execution_count": null |
395 | 394 | } |
396 | 395 | ], |
397 | 396 | "metadata": { |
|
0 commit comments