Skip to content

Commit dc8a348

Browse files
committed
save changes to HPF2023 notebook
1 parent b3ce9b7 commit dc8a348

1 file changed

Lines changed: 67 additions & 32 deletions

File tree

  • mpcontribs-portal/notebooks/contribs.materialsproject.org

mpcontribs-portal/notebooks/contribs.materialsproject.org/HFP2023.ipynb

Lines changed: 67 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"# pip install mpcontribs-client mp_api pandas flatten_dict\n",
1212
"import os\n",
1313
"import gzip\n",
14+
"import json\n",
1415
"\n",
1516
"from pathlib import Path\n",
1617
"from mpcontribs.client import Client\n",
@@ -27,8 +28,28 @@
2728
"metadata": {},
2829
"outputs": [],
2930
"source": [
30-
"client = Client(project=\"HFP2023\")\n",
31-
"mpr = MPRester(api_key=os.environ[\"MPCONTRIBS_API_KEY\"])"
31+
"# mpr = MPRester(api_key=os.environ[\"MPCONTRIBS_API_KEY\"])"
32+
]
33+
},
34+
{
35+
"cell_type": "code",
36+
"execution_count": null,
37+
"id": "7bf789df-1db1-4ff9-b7ca-0811a2ea840c",
38+
"metadata": {},
39+
"outputs": [],
40+
"source": [
41+
"with open(\"/Users/patrick/Downloads/usf_formates_tasks.json\", \"r\") as f:\n",
42+
" tasks = json.load(f)"
43+
]
44+
},
45+
{
46+
"cell_type": "code",
47+
"execution_count": null,
48+
"id": "824df967-358b-4399-b24f-18b31a42c864",
49+
"metadata": {},
50+
"outputs": [],
51+
"source": [
52+
"lookup = {doc[\"formula_pretty\"] + \"_\" + str(doc[\"symmetry\"][\"number\"]): doc[\"task_id\"] for doc in tasks}"
3253
]
3354
},
3455
{
@@ -50,11 +71,11 @@
5071
"outputs": [],
5172
"source": [
5273
"# function to search MP via its summary API endpoint\n",
53-
"def search(formula=None, spacegroup_number=None, chemsys=None):\n",
54-
" return mpr.summary.search(\n",
55-
" formula=formula, chemsys=chemsys, spacegroup_number=spacegroup_number,\n",
56-
" fields=[\"material_id\"], sort_fields=\"energy_above_hull\"\n",
57-
" )"
74+
"# def search(formula=None, spacegroup_number=None, chemsys=None):\n",
75+
"# return mpr.summary.search(\n",
76+
"# formula=formula, chemsys=chemsys, spacegroup_number=spacegroup_number,\n",
77+
"# fields=[\"material_id\"], sort_fields=\"energy_above_hull\"\n",
78+
"# )"
5879
]
5980
},
6081
{
@@ -120,33 +141,37 @@
120141
" # assuming there's only one CIF per directory\n",
121142
" structure = Structure.from_file(cifs[0])\n",
122143
"\n",
123-
" # try to match CIF against MP\n",
124-
" matching_mpids = mpr.find_structure(structure)\n",
144+
" # # try to match CIF against MP\n",
145+
" # matching_mpids = mpr.find_structure(structure)\n",
125146
"\n",
126-
" if matching_mpids:\n",
127-
" identifier = matching_mpids[0]\n",
128-
" else:\n",
129-
" # structure not in MP (yet)\n",
130-
" # get composition, formula, space group, and chemical system\n",
131-
" composition = structure.composition\n",
132-
" formula, _ = composition.get_reduced_formula_and_factor()\n",
133-
" _, spacegroup_number = structure.get_space_group_info()\n",
134-
" chemsys = composition.chemical_system\n",
147+
" # if matching_mpids:\n",
148+
" # identifier = matching_mpids[0]\n",
149+
" # else:\n",
150+
" # # structure not in MP (yet)\n",
151+
" # # get composition, formula, space group, and chemical system\n",
152+
" # composition = structure.composition\n",
153+
" # formula, _ = composition.get_reduced_formula_and_factor()\n",
154+
" # _, spacegroup_number = structure.get_space_group_info()\n",
155+
" # chemsys = composition.chemical_system\n",
135156
"\n",
136-
" # 1) try formula and space group \n",
137-
" docs = search(formula=formula, spacegroup_number=spacegroup_number)\n",
138-
" if not docs:\n",
139-
" # 2) try formula\n",
140-
" docs = search(formula=formula)\n",
141-
" if not docs:\n",
142-
" # 3) try chemical system\n",
143-
" docs = search(chemsys=chemsys)\n",
157+
" # # 1) try formula and space group \n",
158+
" # docs = search(formula=formula, spacegroup_number=spacegroup_number)\n",
159+
" # if not docs:\n",
160+
" # # 2) try formula\n",
161+
" # docs = search(formula=formula)\n",
162+
" # if not docs:\n",
163+
" # # 3) try chemical system\n",
164+
" # docs = search(chemsys=chemsys)\n",
144165
"\n",
145-
" if docs:\n",
146-
" # always use material with lowest energy above hull\n",
147-
" identifier = docs[0].material_id\n",
148-
" \n",
149-
" print(identifier) # \"link to MP\"\n",
166+
" # if docs:\n",
167+
" # # always use material with lowest energy above hull\n",
168+
" # identifier = docs[0].material_id\n",
169+
"\n",
170+
" composition = structure.composition\n",
171+
" formula, _ = composition.get_reduced_formula_and_factor()\n",
172+
" _, spacegroup_number = structure.get_space_group_info()\n",
173+
" identifier = lookup[f\"{formula}_{spacegroup_number}\"]\n",
174+
" print(identifier) # \"link to MP\"\n",
150175
" \n",
151176
" # make sure everything's gzipped\n",
152177
" for p in subdir.glob(\"*.*\"):\n",
@@ -155,7 +180,7 @@
155180
" \n",
156181
" # init contribution; add all files as attachments; add structure\n",
157182
" contrib = {\n",
158-
" \"identifier\": identifier, \"data\": {},\n",
183+
" \"identifier\": identifier, \"formula\": formula, \"data\": {},\n",
159184
" \"attachments\": list(subdir.glob(\"*.gz\"))\n",
160185
" }\n",
161186
" if identifier.startswith(\"mp-\"):\n",
@@ -182,6 +207,16 @@
182207
" contributions.append(contrib)"
183208
]
184209
},
210+
{
211+
"cell_type": "code",
212+
"execution_count": null,
213+
"id": "43104a49-3e15-4f27-a794-db2acfab11e0",
214+
"metadata": {},
215+
"outputs": [],
216+
"source": [
217+
"client = Client(project=\"HFP2023\")"
218+
]
219+
},
185220
{
186221
"cell_type": "code",
187222
"execution_count": null,

0 commit comments

Comments
 (0)