Spaces:
Runtime error
Runtime error
File size: 3,183 Bytes
9fe9db1 1d03008 9fe9db1 1d03008 9fe9db1 1d03008 9fe9db1 1d03008 9fe9db1 8369633 729fc8a 8369633 19b0396 9fe9db1 e10dc20 74facf3 e10dc20 9fe9db1 729fc8a 9fe9db1 729fc8a |
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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
import streamlit as st
from chemical_utils import get_chemical_name, visualize_molecule
from materials_utils import get_mpid, get_data_from_mpid, get_structure_description
import pubchempy as pcp
st.title("Materials and Chemical Data Retrieval")
# st.text("This app retrieves data from the Materials Project API and PubChemPy API.")
if "step" not in st.session_state:
st.session_state["step"] = 1
with st.sidebar:
st.header("How to Use the Material Project Retrieval App")
st.write("""
This app helps you retrieve data from the Materials Project API and PubChemPy API.
**Steps:**
1. Enter a chemical formula and click 'Get MP IDs'.
2. Select a material from the list.
3. View detailed information about the selected material.
""")
if st.session_state["step"] == 1:
st.header("Enter Chemical Formula")
chemical = st.text_input("Enter a chemical formula:", "Fe2O3")
if st.button("Get MP IDs"):
mpid_dict = get_mpid(chemical)
if mpid_dict:
st.session_state["mpid_dict"] = mpid_dict
st.session_state["chemical"] = chemical
st.session_state["step"] = 2
else:
st.write("No MP IDs found for this formula.")
elif st.session_state["step"] == 2:
st.header("Select MP ID")
st.text("Selected Chemical Formula: " + st.session_state["chemical"])
st.text("Number of MP IDs found: " + str(len(st.session_state["mpid_dict"])))
st.text("Material IDs(Structure, System, Space Group, Number of Sites, Energy Above Hull, Band Gap):")
chemical = st.session_state["chemical"]
mpid_dict = st.session_state["mpid_dict"]
# Create a display list with both mpid and crystal_system
display_list = [f"{mpid} ({info[1].value}, {info[2]}, {info[3]}, {info[4]}, {info[5]})" for mpid, info in mpid_dict.items()]
selected_display = st.selectbox("Select an MP ID:", display_list)
# Extract the selected mpid
selected_mpid = selected_display.split(" ")[0]
if st.button("Get Data"):
with st.spinner("Retrieving data..."):
st.write(f"Material ID: {selected_mpid}")
with st.container(border=True, height=250):
data_dict = get_data_from_mpid(selected_mpid)
if data_dict:
st.write("Structure Description:")
description = get_structure_description(selected_mpid)
st.write(description)
else:
st.write("No data found for this material ID.")
chemical_name = get_chemical_name(chemical)
if chemical_name:
st.write(f"Chemical Name: {chemical_name}")
try:
compounds = pcp.get_compounds(chemical_name, 'name')
if compounds:
smiles = compounds[0].isomeric_smiles
st.write("3D Structure:(Only in case of Covalent Structure)")
visualize_molecule(smiles)
else:
st.write("No 3D structure found for this formula.")
except Exception as e:
st.write(f"Error retrieving 3D structure: {e}")
else:
st.write("No chemical name found for this formula.")
|