Spaces:
Runtime error

Indice / app.py
NH-640's picture
Create app.py
ae64f95 verified
Raw History Blame Contribute Delete
2.26 kB
import streamlit as st
st.set_page_config(page_title="Miller Indices Calculator", layout="centered")
st.title("πŸ”· Miller Indices Calculator")
st.write("Compute Miller indices (h, k, l) from intercepts along crystal axes.")
st.markdown("---")
st.header("πŸ“₯ Input Intercepts")
st.write("Enter intercepts along x, y, z axes (use ∞ for parallel planes)")
x = st.text_input("Intercept along X-axis (a)", "1")
y = st.text_input("Intercept along Y-axis (b)", "1")
z = st.text_input("Intercept along Z-axis (c)", "1")
def parse_input(val):
if val.lower() in ["inf", "∞"]:
return float("inf")
return float(val)
def calculate_miller(x, y, z):
try:
x, y, z = parse_input(x), parse_input(y), parse_input(z)
# Step 1: Take reciprocals
h = 0 if x == float("inf") else 1/x
k = 0 if y == float("inf") else 1/y
l = 0 if z == float("inf") else 1/z
reciprocals = [h, k, l]
# Step 2: Find LCM multiplier
denominators = []
for val in reciprocals:
if val != 0:
frac = str(val).split(".")
if len(frac) > 1:
denominators.append(10**len(frac[1]))
multiplier = max(denominators) if denominators else 1
hkl = [int(round(val * multiplier)) for val in reciprocals]
return reciprocals, hkl
except:
return None, None
if st.button("Calculate"):
reciprocals, hkl = calculate_miller(x, y, z)
if hkl:
st.success(f"βœ… Miller Indices: ({hkl[0]} {hkl[1]} {hkl[2]})")
st.subheader("πŸ“Š Step-by-Step")
st.write(f"Reciprocals β†’ {reciprocals}")
st.write(f"Scaled to integers β†’ {hkl}")
st.markdown("---")
st.subheader("πŸ“ Concept Diagram")
st.code("""
3D Axis Representation:
Z
|
|
|____ Y
/
/
X
Intercepts example:
X = 1, Y = 2, Z = ∞
Step 1: Reciprocals
(1, 1/2, 0)
Step 2: Multiply to clear fractions
(2, 1, 0)
Final Miller Index:
(2 1 0)
""")
else:
st.error("Invalid input. Please enter valid numbers or ∞.")