|
11 | 11 | "# pip install mpcontribs-client mp_api pandas flatten_dict\n", |
12 | 12 | "import os\n", |
13 | 13 | "import gzip\n", |
| 14 | + "import json\n", |
14 | 15 | "\n", |
15 | 16 | "from pathlib import Path\n", |
16 | 17 | "from mpcontribs.client import Client\n", |
|
27 | 28 | "metadata": {}, |
28 | 29 | "outputs": [], |
29 | 30 | "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}" |
32 | 53 | ] |
33 | 54 | }, |
34 | 55 | { |
|
50 | 71 | "outputs": [], |
51 | 72 | "source": [ |
52 | 73 | "# 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 | + "# )" |
58 | 79 | ] |
59 | 80 | }, |
60 | 81 | { |
|
120 | 141 | " # assuming there's only one CIF per directory\n", |
121 | 142 | " structure = Structure.from_file(cifs[0])\n", |
122 | 143 | "\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", |
125 | 146 | "\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", |
135 | 156 | "\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", |
144 | 165 | "\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", |
150 | 175 | " \n", |
151 | 176 | " # make sure everything's gzipped\n", |
152 | 177 | " for p in subdir.glob(\"*.*\"):\n", |
|
155 | 180 | " \n", |
156 | 181 | " # init contribution; add all files as attachments; add structure\n", |
157 | 182 | " contrib = {\n", |
158 | | - " \"identifier\": identifier, \"data\": {},\n", |
| 183 | + " \"identifier\": identifier, \"formula\": formula, \"data\": {},\n", |
159 | 184 | " \"attachments\": list(subdir.glob(\"*.gz\"))\n", |
160 | 185 | " }\n", |
161 | 186 | " if identifier.startswith(\"mp-\"):\n", |
|
182 | 207 | " contributions.append(contrib)" |
183 | 208 | ] |
184 | 209 | }, |
| 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 | + }, |
185 | 220 | { |
186 | 221 | "cell_type": "code", |
187 | 222 | "execution_count": null, |
|
0 commit comments