HailMogambo09 commited on
Commit
8369633
1 Parent(s): 55536f2

Crystal Structure Added

Browse files
Files changed (2) hide show
  1. app.py +11 -8
  2. materials_utils.py +3 -8
app.py CHANGED
@@ -1,7 +1,6 @@
1
  import streamlit as st
2
  from chemical_utils import get_chemical_name, visualize_molecule
3
  from materials_utils import get_mpid, get_data_from_mpid, get_structure_description
4
- from visualization_utils import display_data_table
5
  import pubchempy as pcp
6
 
7
  st.title("Materials and Chemical Data Retrieval")
@@ -26,16 +25,20 @@ elif st.session_state["step"] == 2:
26
  st.header("Step 2: Select MP ID")
27
  chemical = st.session_state["chemical"]
28
  mpid_dict = st.session_state["mpid_dict"]
29
- mpid = st.selectbox("Select an MP ID:", list(mpid_dict.keys()))
 
 
 
 
 
 
 
30
  if st.button("Get Data"):
31
- st.write(f"Material ID: {mpid}")
32
- data_dict = get_data_from_mpid(mpid)
33
  if data_dict:
34
- # available_fields = list(data_dict.keys())
35
- # selected_fields = st.multiselect("Select fields to display:", available_fields, default=available_fields)
36
- # display_data_table(data_dict, selected_fields)
37
  st.write("Structure Description:")
38
- description = get_structure_description(mpid)
39
  st.write(description)
40
  else:
41
  st.write("No data found for this material ID.")
 
1
  import streamlit as st
2
  from chemical_utils import get_chemical_name, visualize_molecule
3
  from materials_utils import get_mpid, get_data_from_mpid, get_structure_description
 
4
  import pubchempy as pcp
5
 
6
  st.title("Materials and Chemical Data Retrieval")
 
25
  st.header("Step 2: Select MP ID")
26
  chemical = st.session_state["chemical"]
27
  mpid_dict = st.session_state["mpid_dict"]
28
+
29
+ # Create a display list with both mpid and crystal_system
30
+ display_list = [f"{mpid} (Crystal System: {info[1].value})" for mpid, info in mpid_dict.items()]
31
+ selected_display = st.selectbox("Select an MP ID:", display_list)
32
+
33
+ # Extract the selected mpid
34
+ selected_mpid = selected_display.split(" ")[0]
35
+
36
  if st.button("Get Data"):
37
+ st.write(f"Material ID: {selected_mpid}")
38
+ data_dict = get_data_from_mpid(selected_mpid)
39
  if data_dict:
 
 
 
40
  st.write("Structure Description:")
41
+ description = get_structure_description(selected_mpid)
42
  st.write(description)
43
  else:
44
  st.write("No data found for this material ID.")
materials_utils.py CHANGED
@@ -8,18 +8,16 @@ load_dotenv()
8
 
9
  api_key = os.getenv("api_key")
10
 
11
-
12
  def get_mpid(formula):
13
  try:
14
  with MPRester(api_key) as mpr:
15
- docs = mpr.materials.summary.search(formula=[formula], fields=["material_id", "formula_pretty"])
16
- mpid_formula_dict = {doc.material_id: doc.formula_pretty for doc in docs}
17
- return mpid_formula_dict
18
  except Exception as e:
19
  st.write(f"Error finding MP data for formula {formula}: {e}")
20
  return None
21
 
22
-
23
  def extract_data(doc, field_list):
24
  extracted_data = {}
25
  for field in field_list:
@@ -28,7 +26,6 @@ def extract_data(doc, field_list):
28
  extracted_data[field] = value
29
  return extracted_data
30
 
31
-
32
  field_list = [
33
  'builder_meta', 'nsites', 'elements', 'nelements', 'composition',
34
  'composition_reduced', 'formula_pretty', 'formula_anonymous', 'chemsys',
@@ -50,7 +47,6 @@ field_list = [
50
  'theoretical', 'database_IDs'
51
  ]
52
 
53
-
54
  def get_data_from_mpid(mpid):
55
  with MPRester(api_key) as mpr:
56
  docs = mpr.materials.summary.search(material_ids=[mpid])
@@ -60,7 +56,6 @@ def get_data_from_mpid(mpid):
60
  else:
61
  return None
62
 
63
-
64
  def get_structure_description(mpid):
65
  with MPRester(api_key) as mpr:
66
  structure = mpr.get_structure_by_material_id(mpid)
 
8
 
9
  api_key = os.getenv("api_key")
10
 
 
11
  def get_mpid(formula):
12
  try:
13
  with MPRester(api_key) as mpr:
14
+ docs = mpr.materials.summary.search(formula=[formula], fields=["material_id", "formula_pretty", "symmetry"])
15
+ mpid_dict = {doc.material_id: (doc.formula_pretty, doc.symmetry.crystal_system) for doc in docs}
16
+ return mpid_dict
17
  except Exception as e:
18
  st.write(f"Error finding MP data for formula {formula}: {e}")
19
  return None
20
 
 
21
  def extract_data(doc, field_list):
22
  extracted_data = {}
23
  for field in field_list:
 
26
  extracted_data[field] = value
27
  return extracted_data
28
 
 
29
  field_list = [
30
  'builder_meta', 'nsites', 'elements', 'nelements', 'composition',
31
  'composition_reduced', 'formula_pretty', 'formula_anonymous', 'chemsys',
 
47
  'theoretical', 'database_IDs'
48
  ]
49
 
 
50
  def get_data_from_mpid(mpid):
51
  with MPRester(api_key) as mpr:
52
  docs = mpr.materials.summary.search(material_ids=[mpid])
 
56
  else:
57
  return None
58
 
 
59
  def get_structure_description(mpid):
60
  with MPRester(api_key) as mpr:
61
  structure = mpr.get_structure_by_material_id(mpid)