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 ∞.")