|
10 | 10 | from pymatgen.core.composition import CompositionError
|
11 | 11 | from pymatgen.util.string import unicodeify
|
12 | 12 | from mp_api import MPRester
|
| 13 | +from mp_api.client import MPRestError |
13 | 14 |
|
14 | 15 |
|
15 | 16 | from pymatgen.util.string import unicodeify_spacegroup
|
@@ -127,44 +128,42 @@ def get_human_readable_results_from_search_term(search_term):
|
127 | 128 |
|
128 | 129 | with MPRester() as mpr:
|
129 | 130 | try:
|
130 |
| - entries = mpr.search.search( |
131 |
| - search_term, |
| 131 | + entries = mpr.summary.search_summary_docs( |
| 132 | + formula=search_term, |
132 | 133 | fields=[
|
133 |
| - "task_id", |
| 134 | + "material_id", |
134 | 135 | "formula_pretty",
|
135 |
| - "e_above_hull", |
| 136 | + "energy_above_hull", |
136 | 137 | "symmetry",
|
137 | 138 | ],
|
138 | 139 | )
|
139 |
| - except CompositionError: |
| 140 | + except MPRestError: |
140 | 141 | entries = []
|
141 | 142 |
|
142 | 143 | if len(entries) == 0:
|
143 | 144 | self.logger.info(f"Search: no results for {search_term}")
|
144 | 145 | return {"error": f"No results found for {search_term}."}
|
145 | 146 |
|
146 |
| - # sort by e_above_hull if a normal query, or by Levenshtein distance |
147 |
| - # if fuzzy matching (order of mpids list if present matches Levenshtein distance) |
148 |
| - if not mpids: |
149 |
| - entries = sorted(entries, key=lambda x: x["e_above_hull"]) |
150 |
| - else: |
151 |
| - entries = sorted(entries, key=lambda x: mpids.index(x["task_id"])) |
| 147 | + entries = sorted(entries, key=lambda x: x.energy_above_hull) |
152 | 148 |
|
| 149 | + human_readable_hull_labels = [] |
153 | 150 | for entry in entries:
|
154 |
| - e_hull = entry["e_above_hull"] |
| 151 | + e_hull = entry.energy_above_hull |
155 | 152 | if e_hull == 0:
|
156 |
| - entry["e_above_hull_human"] = "predicted stable phase" |
| 153 | + human_readable_hull_labels.append("predicted stable phase") |
157 | 154 | elif e_hull >= 0.01:
|
158 |
| - entry["e_above_hull_human"] = f"+{e_hull:.2f} eV/atom" |
| 155 | + human_readable_hull_labels.append(f"+{e_hull:.2f} eV/atom") |
159 | 156 | else:
|
160 | 157 | e_hull_str = np.format_float_scientific(e_hull, precision=2)
|
161 |
| - entry["e_above_hull_human"] = f"+{e_hull_str} eV/atom" |
| 158 | + human_readable_hull_labels.append(f"+{e_hull_str} eV/atom") |
162 | 159 |
|
163 | 160 | human_readable_results = {
|
164 |
| - entry["task_id"]: f"{unicodeify(entry['pretty_formula'])} " |
165 |
| - f"({unicodeify_spacegroup(entry['spacegroup.symbol'])}) " |
166 |
| - f"{entry['e_above_hull_human']}" |
167 |
| - for entry in entries |
| 161 | + entry.material_id: f"{unicodeify(entry.formula_pretty)} " |
| 162 | + f"({unicodeify_spacegroup(entry.symmetry.symbol)}) " |
| 163 | + f"{human_readable_hull_label}" |
| 164 | + for entry, human_readable_hull_label in zip( |
| 165 | + entries, human_readable_hull_labels |
| 166 | + ) |
168 | 167 | }
|
169 | 168 |
|
170 | 169 | return human_readable_results
|
|
0 commit comments