File size: 3,016 Bytes
d9ed521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
221dfe3
 
d9ed521
 
 
 
 
 
 
 
 
 
 
 
 
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import streamlit as st
from ase.data import chemical_symbols
from pymatgen.core import Element

elements = [Element.from_Z(z) for z in range(1, 119)]

# Define the number of rows and columns in the periodic table
rows = 9  # There are 7 rows in the conventional periodic table
columns = 18

# Define a function to display the periodic table
def display_periodic_table():
    # elements = [
    #     (element, element) for element in chemical_symbols[1:]
    # ]

    # cols = st.columns(18, gap='small', vertical_alignment='bottom')  # Create 18 columns for the periodic table layout

    row = 0
    for element in elements:
        symbol = element.symbol
        atomic_number = element.Z
        group = element.group

        if element.row > row:
            cols = st.columns(columns, gap='small', vertical_alignment='bottom')
        row = element.row

        if element.block == 'f':
            continue

        with cols[group - 1]:
            if st.button(symbol, use_container_width=True):
                st.session_state.selected_element = symbol
                st.session_state.selected_name = symbol
                st.rerun()
                # st.experimental_rerun()
    
    for element in elements:
        symbol = element.symbol
        atomic_number = element.Z
        group = element.group

        if element.row > row:
            cols = st.columns(columns, gap='small', vertical_alignment='bottom')
        row = element.row

        if element.block == 'f':
            noble = Element.from_row_and_group(row-1, 18)
            row += 2
            group += atomic_number - noble.Z - 2
        else:
            continue

        with cols[group - 1]:
            if st.button(symbol, use_container_width=True):
                st.session_state.selected_element = symbol
                st.session_state.selected_name = symbol
                st.rerun()
                # st.experimental_rerun()
    
    
    # for idx, (symbol, name) in enumerate(elements):
    #     with cols[idx % 18]:  # Place each element in the correct column
    #         if st.button(symbol, use_container_width=True):
    #             st.session_state.selected_element = symbol
    #             st.session_state.selected_name = name
    #             st.experimental_rerun()

# Define a function to display the details of an element
def display_element_details():
    symbol = st.session_state.selected_element
    name = st.session_state.selected_name
    st.write(f"### {name} ({symbol})")
    st.write(f"Details about {name} ({symbol}) will be displayed here.")
    if st.button("Back to Periodic Table"):
        st.session_state.selected_element = None
        st.session_state.selected_name = None
        st.rerun()
        # st.experimental_rerun()


st.title("Periodic Table")

# st.balloons()
if 'selected_element' not in st.session_state:
    st.session_state.selected_element = None

if st.session_state.selected_element:
    display_element_details()
else:
    display_periodic_table()