|
61 | 61 | "\n",
|
62 | 62 | "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 | 63 | "\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 | 64 | "ORGANIZATION_ID - Authentication parameter needed for when working with collaborative accounts https://docs.mat3ra.com/collaboration/organizations/overview/\n",
|
67 | 65 | "\n",
|
68 | 66 | "> <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 | 67 | ]
|
70 | 68 | },
|
71 | 69 | {
|
72 | 70 | "cell_type": "code",
|
73 |
| - "execution_count": null, |
74 | 71 | "metadata": {
|
75 | 72 | "cellView": "form",
|
76 | 73 | "colab": {
|
|
79 | 76 | "id": "nXDYU_oP8GIr",
|
80 | 77 | "outputId": "aee909b7-1a48-43c2-81b7-3659e0fc9c79"
|
81 | 78 | },
|
82 |
| - "outputs": [], |
83 | 79 | "source": [
|
| 80 | + "from tokenize import blank_re\n", |
| 81 | + "\n", |
84 | 82 | "# @title Authorization Form\n",
|
85 | 83 | "ACCOUNT_ID = \"ACCOUNT_ID\" # @param {type:\"string\"}\n",
|
86 | 84 | "AUTH_TOKEN = \"AUTH_TOKEN\" # @param {type:\"string\"}\n",
|
87 |
| - "MATERIALS_PROJECT_API_KEY = \"MATERIALS_PROJECT_API_KEY\" # @param {type:\"string\"}\n", |
88 | 85 | "ORGANIZATION_ID = \"ORGANIZATION_ID\" # @param {type:\"string\"}\n",
|
89 | 86 | "\n",
|
90 | 87 | "import os\n",
|
|
95 | 92 | " dict(\n",
|
96 | 93 | " ACCOUNT_ID=ACCOUNT_ID,\n",
|
97 | 94 | " AUTH_TOKEN=AUTH_TOKEN,\n",
|
98 |
| - " MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n", |
99 | 95 | " ORGANIZATION_ID=ORGANIZATION_ID,\n",
|
100 | 96 | " )\n",
|
101 | 97 | " )\n",
|
|
109 | 105 | " dict(\n",
|
110 | 106 | " ACCOUNT_ID=apiConfig.get(\"accountId\"),\n",
|
111 | 107 | " AUTH_TOKEN=apiConfig.get(\"authToken\"),\n",
|
112 |
| - " MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n", |
113 | 108 | " ORGANIZATION_ID=apiConfig.get(\"organizationId\") or \"\",\n",
|
114 | 109 | " )\n",
|
115 | 110 | " )\n",
|
|
121 | 116 | " from utils.jupyterlite import install_packages\n",
|
122 | 117 | "\n",
|
123 | 118 | " await install_packages(\"\")"
|
124 |
| - ] |
| 119 | + ], |
| 120 | + "outputs": [], |
| 121 | + "execution_count": null |
125 | 122 | },
|
126 | 123 | {
|
127 | 124 | "attachments": {},
|
|
135 | 132 | },
|
136 | 133 | {
|
137 | 134 | "cell_type": "code",
|
138 |
| - "execution_count": null, |
139 | 135 | "metadata": {
|
140 | 136 | "id": "rG9HfjnR8GIs"
|
141 | 137 | },
|
142 |
| - "outputs": [], |
143 | 138 | "source": [
|
144 | 139 | "# Import settings file and utils file\n",
|
145 |
| - "from utils.settings import ENDPOINT_ARGS, ACCOUNT_ID, MATERIALS_PROJECT_API_KEY\n", |
| 140 | + "from utils.settings import ENDPOINT_ARGS, ACCOUNT_ID\n", |
146 | 141 | "from utils.generic import (\n",
|
147 | 142 | " wait_for_jobs_to_finish,\n",
|
148 | 143 | " get_property_by_subworkflow_and_unit_indicies,\n",
|
|
154 | 149 | "from exabyte_api_client.endpoints.jobs import JobEndpoints\n",
|
155 | 150 | "from exabyte_api_client.endpoints.projects import ProjectEndpoints\n",
|
156 | 151 | "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 |
| - ] |
| 152 | + "from exabyte_api_client.endpoints.bank_materials import BankMaterialEndpoints\n", |
| 153 | + "from exabyte_api_client.endpoints.bank_workflows import BankWorkflowEndpoints" |
| 154 | + ], |
| 155 | + "outputs": [], |
| 156 | + "execution_count": null |
160 | 157 | },
|
161 | 158 | {
|
162 | 159 | "attachments": {},
|
|
180 | 177 | },
|
181 | 178 | {
|
182 | 179 | "cell_type": "code",
|
183 |
| - "execution_count": null, |
184 | 180 | "metadata": {
|
185 | 181 | "colab": {
|
186 | 182 | "base_uri": "https://localhost:8080/"
|
187 | 183 | },
|
188 | 184 | "id": "le9f28c08GIt",
|
189 | 185 | "outputId": "27e9b94f-29dd-4742-9448-2e1bce79cb15"
|
190 | 186 | },
|
191 |
| - "outputs": [], |
192 | 187 | "source": [
|
193 | 188 | "# Get some account information\n",
|
194 | 189 | "project_endpoints = ProjectEndpoints(*ENDPOINT_ARGS)\n",
|
|
199 | 194 | "\n",
|
200 | 195 | "# Get a workflow for the job from the bank, and copy it to our account\n",
|
201 | 196 | "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", |
| 197 | + "WORKFLOW_QUERY = {\"systemName\": \"espresso-total-energy\"}\n", |
| 198 | + "bank_workflow_id = bank_workflow_endpoints.list(WORKFLOW_QUERY)[0][\"_id\"]\n", |
| 199 | + "workflow_id = bank_workflow_endpoints.copy(bank_workflow_id, owner_id)[\"_id\"]\n", |
| 200 | + "\n", |
| 201 | + "# Get materials from bank and copy one to our account\n", |
| 202 | + "material_bank_endpoints = BankMaterialEndpoints(*ENDPOINT_ARGS)\n", |
| 203 | + "MATERIAL_QUERY = {\"formula\": \"Si\"}\n", |
| 204 | + "bank_materials = material_bank_endpoints.list(MATERIAL_QUERY)\n", |
| 205 | + "bank_material_id = bank_materials[0][\"_id\"]\n", |
206 | 206 | "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", |
| 207 | + "material_id = material_bank_endpoints.copy(bank_material_id, owner_id)[\"_id\"]\n", |
| 208 | + "materials = material_endpoints.list({\"owner._id\": owner_id})\n", |
209 | 209 | "\n",
|
210 | 210 | "# Create the job\n",
|
211 | 211 | "job_endpoints = JobEndpoints(*ENDPOINT_ARGS)\n",
|
|
216 | 216 | "# Submit the job\n",
|
217 | 217 | "job_endpoints.submit(job[\"_id\"])\n",
|
218 | 218 | "wait_for_jobs_to_finish(job_endpoints, [job[\"_id\"]])"
|
219 |
| - ] |
| 219 | + ], |
| 220 | + "outputs": [], |
| 221 | + "execution_count": null |
220 | 222 | },
|
221 | 223 | {
|
222 | 224 | "attachments": {},
|
|
243 | 245 | },
|
244 | 246 | {
|
245 | 247 | "cell_type": "code",
|
246 |
| - "execution_count": null, |
247 | 248 | "metadata": {
|
248 | 249 | "colab": {
|
249 | 250 | "base_uri": "https://localhost:8080/"
|
250 | 251 | },
|
251 | 252 | "id": "yijRe7qp8GIv",
|
252 | 253 | "outputId": "19b147fc-736e-41f0-bd0f-6f69e77b0adf"
|
253 | 254 | },
|
254 |
| - "outputs": [], |
255 | 255 | "source": [
|
256 | 256 | "files = job_endpoints.list_files(job[\"_id\"])\n",
|
257 | 257 | "paths = [file[\"key\"] for file in files]\n",
|
258 | 258 | "for path in paths:\n",
|
259 | 259 | " if \"outdir\" not in path:\n",
|
260 | 260 | " print(path)"
|
261 |
| - ] |
| 261 | + ], |
| 262 | + "outputs": [], |
| 263 | + "execution_count": null |
262 | 264 | },
|
263 | 265 | {
|
264 | 266 | "attachments": {},
|
|
283 | 285 | },
|
284 | 286 | {
|
285 | 287 | "cell_type": "code",
|
286 |
| - "execution_count": null, |
287 | 288 | "metadata": {
|
288 | 289 | "colab": {
|
289 | 290 | "base_uri": "https://localhost:8080/"
|
290 | 291 | },
|
291 | 292 | "id": "U2dq0A1e8GIw",
|
292 | 293 | "outputId": "7b4f8c36-6342-46fa-d02e-0825b44e6c64"
|
293 | 294 | },
|
294 |
| - "outputs": [], |
295 | 295 | "source": [
|
296 | 296 | "for file in files:\n",
|
297 | 297 | " if file[\"name\"] == \"pw_scf.out\":\n",
|
298 | 298 | " output_file_metadata = file\n",
|
299 | 299 | "display_JSON(output_file_metadata)"
|
300 |
| - ] |
| 300 | + ], |
| 301 | + "outputs": [], |
| 302 | + "execution_count": null |
301 | 303 | },
|
302 | 304 | {
|
303 | 305 | "attachments": {},
|
|
313 | 315 | },
|
314 | 316 | {
|
315 | 317 | "cell_type": "code",
|
316 |
| - "execution_count": null, |
317 | 318 | "metadata": {
|
318 | 319 | "colab": {
|
319 | 320 | "base_uri": "https://localhost:8080/"
|
320 | 321 | },
|
321 | 322 | "id": "OpdOMuDT8GIw",
|
322 | 323 | "outputId": "e4e2e6b1-8431-439a-8606-ae500534e601"
|
323 | 324 | },
|
324 |
| - "outputs": [], |
325 | 325 | "source": [
|
326 | 326 | "import urllib\n",
|
327 | 327 | "\n",
|
|
336 | 336 | "lines = output_file.split(\"\\n\")\n",
|
337 | 337 | "for line in lines[-90:]:\n",
|
338 | 338 | " print(line)"
|
339 |
| - ] |
| 339 | + ], |
| 340 | + "outputs": [], |
| 341 | + "execution_count": null |
340 | 342 | },
|
341 | 343 | {
|
342 | 344 | "attachments": {},
|
|
352 | 354 | },
|
353 | 355 | {
|
354 | 356 | "cell_type": "code",
|
355 |
| - "execution_count": null, |
356 | 357 | "metadata": {
|
357 | 358 | "id": "osy2JKpB8GIx"
|
358 | 359 | },
|
359 |
| - "outputs": [], |
360 | 360 | "source": [
|
361 | 361 | "# We've already got an output file, so let's grab the input file we sent to Quantum Espresso\n",
|
362 | 362 | "for file in files:\n",
|
363 | 363 | " if \"pw_scf.in\" == file[\"name\"]:\n",
|
364 | 364 | " input_file_metadata = file\n",
|
365 | 365 | "server_response = urllib.request.urlopen(input_file_metadata[\"signedUrl\"])\n",
|
366 | 366 | "input_file_bytes = server_response.read()"
|
367 |
| - ] |
| 367 | + ], |
| 368 | + "outputs": [], |
| 369 | + "execution_count": null |
368 | 370 | },
|
369 | 371 | {
|
370 | 372 | "cell_type": "code",
|
371 |
| - "execution_count": null, |
372 | 373 | "metadata": {
|
373 | 374 | "id": "COPinBrO8GIx"
|
374 | 375 | },
|
375 |
| - "outputs": [], |
376 | 376 | "source": [
|
377 | 377 | "# 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 | 378 | "# Although we could decode before writing to disk, we can just write it directly with the \"wb\" (write bytes) file mode.\n",
|
379 | 379 | "with open(input_file_metadata[\"name\"], \"wb\") as file_descriptor:\n",
|
380 | 380 | " file_descriptor.write(input_file_bytes)"
|
381 |
| - ] |
| 381 | + ], |
| 382 | + "outputs": [], |
| 383 | + "execution_count": null |
382 | 384 | },
|
383 | 385 | {
|
384 | 386 | "cell_type": "code",
|
385 |
| - "execution_count": null, |
386 | 387 | "metadata": {
|
387 | 388 | "id": "rzDcWyrL8GIx"
|
388 | 389 | },
|
389 |
| - "outputs": [], |
390 | 390 | "source": [
|
391 | 391 | "# 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 | 392 | "with open(output_file_metadata[\"name\"], \"w\") as file_descriptor:\n",
|
393 | 393 | " file_descriptor.write(output_file)"
|
394 |
| - ] |
| 394 | + ], |
| 395 | + "outputs": [], |
| 396 | + "execution_count": null |
395 | 397 | }
|
396 | 398 | ],
|
397 | 399 | "metadata": {
|
|
0 commit comments