-
Notifications
You must be signed in to change notification settings - Fork 0
/
3.screen_with_solubility_and_band_gap_criteria.py
60 lines (48 loc) · 3.03 KB
/
3.screen_with_solubility_and_band_gap_criteria.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import pandas as pd
import timeout_decorator
from pymatgen.analysis.phase_diagram import PhaseDiagram
from pymatgen.core import Composition, Element
from pymatgen.ext.matproj import MPRester
from retrying import retry
from tqdm import tqdm
@retry(stop_max_attempt_number=20)
@timeout_decorator.timeout(300)
def recheck_e_above_hull(material_id, key_element):
with MPRester(api_key='') as mpr:
entry = mpr.get_entry_by_material_id(material_id)
pretty_formula = entry.name
chemsys = Composition(pretty_formula).chemical_system + '-' + key_element
# using GGA and GGA+U mixed scheme as default, namely compatible_only=True
entries = mpr.get_entries_in_chemsys(chemsys)
phase_diagram = PhaseDiagram(entries)
e_above_hull = phase_diagram.get_e_above_hull(entry)
# to avoid kind of values -1.77635683940025E-15, and -0.000 after rounded
if 0 > e_above_hull >= -phase_diagram.numerical_tol:
e_above_hull = 0.0
return(e_above_hull)
key_element = 'Li'
tieline_dataframe = pd.read_csv('Tables/{element}/tieline_distinct.csv'.format(element=key_element))
# remove noble gas
boolean_gas = tieline_dataframe.pretty_formula.apply(lambda x : True not in [e.is_noble_gas for e in Composition(x).elements])
no_nobel_gas_dataframe = tieline_dataframe[boolean_gas]
# screen phases without the key element
boolean_element = no_nobel_gas_dataframe.pretty_formula.apply(lambda x : Element(key_element) not in Composition(x).elements)
vanishing_solubility_phases_dataframe = no_nobel_gas_dataframe[boolean_element]
vanishing_solubility_phases_dataframe.reset_index(drop=True, inplace=True)
vanishing_solubility_phases_dataframe.to_csv('Tables/{element}/tieline_without_solubility_and_gas.csv'.format(element=key_element), index=False)
# pick up those phases with band gap >= 3eV
material_id_list = vanishing_solubility_phases_dataframe['material_id'].to_list()
with MPRester(api_key='') as mpr:
# entry id is an alias of task id
candidates = mpr.query(criteria={'task_id':{'$in': material_id_list}, 'band_gap':{'$gte':3.0}}, properties=['material_id', 'pretty_formula', 'theoretical', 'band_gap', 'density', 'e_above_hull', 'icsd_ids'])
candidates_dataframe = pd.DataFrame(candidates)
# Due to bug in Materials Project database, e_above_hull needs to be checked
# https://discuss.matsci.org/t/materials-project-database-release-log/1609
# utilize progress_apply instead of apply to show process bar
# https://github.com/tqdm/tqdm
tqdm.pandas(desc="pandas_apply_process_1st")
candidates_dataframe['e_above_hull'] = candidates_dataframe.material_id.progress_apply(recheck_e_above_hull, key_element=key_element)
candidates_dataframe = candidates_dataframe.round({'band_gap':3,'density':3,'e_above_hull':3})
# sort with band gap order, in the meanwhile, make experimental structures shown on top
candidates_dataframe.sort_values(by=['theoretical', 'band_gap'], ascending=[True, False], inplace=True)
candidates_dataframe.to_csv('Tables/{element}/candidates.csv'.format(element=key_element), float_format='%.3f', index=False)