Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update thermo.py #899

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions matminer/featurizers/composition/thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,21 @@ def featurize(self, comp, formation_energy_per_atom=None):

if not formation_energy_per_atom:
# Get formation energy of most stable structure from MP
struct_lst = MPRester(self.mapi_key).get_data(comp.reduced_formula)
# Now it can habdel legacy API and new API from matertials project depending on the API key length provided.
try:
struct_lst = MPRester(self.mapi_key).get_data(comp.reduced_formula)
except:
struct_lst = []
struct_lst_obj = MPRester(self.mapi_key).summary.search(formula=comp.reduced_formula, fields=["formation_energy_per_atom"])
for i in struct_lst_obj:
struct_lst.append(i)
if len(struct_lst) > 0:
most_stable_entry = sorted(struct_lst, key=lambda e: e["energy_per_atom"])[0]
formation_energy_per_atom = most_stable_entry["formation_energy_per_atom"]
try:
most_stable_entry = sorted(struct_lst, key=lambda e: e["energy_per_atom"])[0]
formation_energy_per_atom = most_stable_entry["formation_energy_per_atom"]
except:
most_stable_entry = sorted(struct_lst, key=lambda e: e.formation_energy_per_atom)[0]
formation_energy_per_atom = most_stable_entry.formation_energy_per_atom
else:
raise ValueError(f"No structure found in MP for {comp}")

Expand Down