Skip to content

Commit 87c78cf

Browse files
committed
update: swap mp to our bank
1 parent d3f8653 commit 87c78cf

File tree

1 file changed

+43
-41
lines changed

1 file changed

+43
-41
lines changed

examples/job/get-file-from-job.ipynb

+43-41
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,13 @@
6161
"\n",
6262
"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",
6363
"\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",
6664
"ORGANIZATION_ID - Authentication parameter needed for when working with collaborative accounts https://docs.mat3ra.com/collaboration/organizations/overview/\n",
6765
"\n",
6866
"> <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/"
6967
]
7068
},
7169
{
7270
"cell_type": "code",
73-
"execution_count": null,
7471
"metadata": {
7572
"cellView": "form",
7673
"colab": {
@@ -79,12 +76,12 @@
7976
"id": "nXDYU_oP8GIr",
8077
"outputId": "aee909b7-1a48-43c2-81b7-3659e0fc9c79"
8178
},
82-
"outputs": [],
8379
"source": [
80+
"from tokenize import blank_re\n",
81+
"\n",
8482
"# @title Authorization Form\n",
8583
"ACCOUNT_ID = \"ACCOUNT_ID\" # @param {type:\"string\"}\n",
8684
"AUTH_TOKEN = \"AUTH_TOKEN\" # @param {type:\"string\"}\n",
87-
"MATERIALS_PROJECT_API_KEY = \"MATERIALS_PROJECT_API_KEY\" # @param {type:\"string\"}\n",
8885
"ORGANIZATION_ID = \"ORGANIZATION_ID\" # @param {type:\"string\"}\n",
8986
"\n",
9087
"import os\n",
@@ -95,7 +92,6 @@
9592
" dict(\n",
9693
" ACCOUNT_ID=ACCOUNT_ID,\n",
9794
" AUTH_TOKEN=AUTH_TOKEN,\n",
98-
" MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n",
9995
" ORGANIZATION_ID=ORGANIZATION_ID,\n",
10096
" )\n",
10197
" )\n",
@@ -109,7 +105,6 @@
109105
" dict(\n",
110106
" ACCOUNT_ID=apiConfig.get(\"accountId\"),\n",
111107
" AUTH_TOKEN=apiConfig.get(\"authToken\"),\n",
112-
" MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n",
113108
" ORGANIZATION_ID=apiConfig.get(\"organizationId\") or \"\",\n",
114109
" )\n",
115110
" )\n",
@@ -121,7 +116,9 @@
121116
" from utils.jupyterlite import install_packages\n",
122117
"\n",
123118
" await install_packages(\"\")"
124-
]
119+
],
120+
"outputs": [],
121+
"execution_count": null
125122
},
126123
{
127124
"attachments": {},
@@ -135,14 +132,12 @@
135132
},
136133
{
137134
"cell_type": "code",
138-
"execution_count": null,
139135
"metadata": {
140136
"id": "rG9HfjnR8GIs"
141137
},
142-
"outputs": [],
143138
"source": [
144139
"# 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",
146141
"from utils.generic import (\n",
147142
" wait_for_jobs_to_finish,\n",
148143
" get_property_by_subworkflow_and_unit_indicies,\n",
@@ -154,9 +149,11 @@
154149
"from exabyte_api_client.endpoints.jobs import JobEndpoints\n",
155150
"from exabyte_api_client.endpoints.projects import ProjectEndpoints\n",
156151
"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
160157
},
161158
{
162159
"attachments": {},
@@ -180,15 +177,13 @@
180177
},
181178
{
182179
"cell_type": "code",
183-
"execution_count": null,
184180
"metadata": {
185181
"colab": {
186182
"base_uri": "https://localhost:8080/"
187183
},
188184
"id": "le9f28c08GIt",
189185
"outputId": "27e9b94f-29dd-4742-9448-2e1bce79cb15"
190186
},
191-
"outputs": [],
192187
"source": [
193188
"# Get some account information\n",
194189
"project_endpoints = ProjectEndpoints(*ENDPOINT_ARGS)\n",
@@ -199,13 +194,18 @@
199194
"\n",
200195
"# Get a workflow for the job from the bank, and copy it to our account\n",
201196
"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",
206206
"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",
209209
"\n",
210210
"# Create the job\n",
211211
"job_endpoints = JobEndpoints(*ENDPOINT_ARGS)\n",
@@ -216,7 +216,9 @@
216216
"# Submit the job\n",
217217
"job_endpoints.submit(job[\"_id\"])\n",
218218
"wait_for_jobs_to_finish(job_endpoints, [job[\"_id\"]])"
219-
]
219+
],
220+
"outputs": [],
221+
"execution_count": null
220222
},
221223
{
222224
"attachments": {},
@@ -243,22 +245,22 @@
243245
},
244246
{
245247
"cell_type": "code",
246-
"execution_count": null,
247248
"metadata": {
248249
"colab": {
249250
"base_uri": "https://localhost:8080/"
250251
},
251252
"id": "yijRe7qp8GIv",
252253
"outputId": "19b147fc-736e-41f0-bd0f-6f69e77b0adf"
253254
},
254-
"outputs": [],
255255
"source": [
256256
"files = job_endpoints.list_files(job[\"_id\"])\n",
257257
"paths = [file[\"key\"] for file in files]\n",
258258
"for path in paths:\n",
259259
" if \"outdir\" not in path:\n",
260260
" print(path)"
261-
]
261+
],
262+
"outputs": [],
263+
"execution_count": null
262264
},
263265
{
264266
"attachments": {},
@@ -283,21 +285,21 @@
283285
},
284286
{
285287
"cell_type": "code",
286-
"execution_count": null,
287288
"metadata": {
288289
"colab": {
289290
"base_uri": "https://localhost:8080/"
290291
},
291292
"id": "U2dq0A1e8GIw",
292293
"outputId": "7b4f8c36-6342-46fa-d02e-0825b44e6c64"
293294
},
294-
"outputs": [],
295295
"source": [
296296
"for file in files:\n",
297297
" if file[\"name\"] == \"pw_scf.out\":\n",
298298
" output_file_metadata = file\n",
299299
"display_JSON(output_file_metadata)"
300-
]
300+
],
301+
"outputs": [],
302+
"execution_count": null
301303
},
302304
{
303305
"attachments": {},
@@ -313,15 +315,13 @@
313315
},
314316
{
315317
"cell_type": "code",
316-
"execution_count": null,
317318
"metadata": {
318319
"colab": {
319320
"base_uri": "https://localhost:8080/"
320321
},
321322
"id": "OpdOMuDT8GIw",
322323
"outputId": "e4e2e6b1-8431-439a-8606-ae500534e601"
323324
},
324-
"outputs": [],
325325
"source": [
326326
"import urllib\n",
327327
"\n",
@@ -336,7 +336,9 @@
336336
"lines = output_file.split(\"\\n\")\n",
337337
"for line in lines[-90:]:\n",
338338
" print(line)"
339-
]
339+
],
340+
"outputs": [],
341+
"execution_count": null
340342
},
341343
{
342344
"attachments": {},
@@ -352,46 +354,46 @@
352354
},
353355
{
354356
"cell_type": "code",
355-
"execution_count": null,
356357
"metadata": {
357358
"id": "osy2JKpB8GIx"
358359
},
359-
"outputs": [],
360360
"source": [
361361
"# We've already got an output file, so let's grab the input file we sent to Quantum Espresso\n",
362362
"for file in files:\n",
363363
" if \"pw_scf.in\" == file[\"name\"]:\n",
364364
" input_file_metadata = file\n",
365365
"server_response = urllib.request.urlopen(input_file_metadata[\"signedUrl\"])\n",
366366
"input_file_bytes = server_response.read()"
367-
]
367+
],
368+
"outputs": [],
369+
"execution_count": null
368370
},
369371
{
370372
"cell_type": "code",
371-
"execution_count": null,
372373
"metadata": {
373374
"id": "COPinBrO8GIx"
374375
},
375-
"outputs": [],
376376
"source": [
377377
"# 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",
378378
"# Although we could decode before writing to disk, we can just write it directly with the \"wb\" (write bytes) file mode.\n",
379379
"with open(input_file_metadata[\"name\"], \"wb\") as file_descriptor:\n",
380380
" file_descriptor.write(input_file_bytes)"
381-
]
381+
],
382+
"outputs": [],
383+
"execution_count": null
382384
},
383385
{
384386
"cell_type": "code",
385-
"execution_count": null,
386387
"metadata": {
387388
"id": "rzDcWyrL8GIx"
388389
},
389-
"outputs": [],
390390
"source": [
391391
"# 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",
392392
"with open(output_file_metadata[\"name\"], \"w\") as file_descriptor:\n",
393393
" file_descriptor.write(output_file)"
394-
]
394+
],
395+
"outputs": [],
396+
"execution_count": null
395397
}
396398
],
397399
"metadata": {

0 commit comments

Comments
 (0)