-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.py
74 lines (59 loc) · 2.78 KB
/
index.py
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
# Varsha Tumburu (1901CS69)
# import modules
import streamlit as st
import pandas as pd
# Set title
st.set_page_config(
page_title = "Nanoparticles"
)
st.title("Nanomaterials Properties")
# Functions to deduce number atoms per layer
def cuboctahedral_total(layer):
return int((10 * (layer ** 3) + 15 * (layer ** 2) + 11 * layer + 3) / 3)
def cuboctahedral_surface(layer):
return int(10 * (layer ** 2) + 2)
def spherical_total(layer):
return int((10 * (layer ** 3) - 15 * (layer ** 2) + 11 * layer - 3) / 3)
def spherical_surface(layer):
return int(10 * (layer ** 2) - 20 * layer + 12)
# Inputs for shape and application of nanoparticle
shape = st.radio("Select shape of nanoparticle:",('Cuboctahedral', 'Spherical'))
application = st.selectbox("Select an application:",('Optical', 'Electrical', 'Magnetic', 'Strength', 'None'), 4)
# Set minimum and maximum ranges accordingly
global max_range, min_range
if(application=='Optical'):
min_range=40; max_range=100
elif(application=='Electrical'):
min_range=10; max_range=20
elif(application=='Magnetic'):
min_range=1; max_range=10
elif(application=='Strength'):
min_range=1; max_range=50
else:
min_range=1; max_range=100
values = st.slider('Specify size limits for nanoparticle: (in nm)', min_range, max_range, (min_range, 50))
sizes = [i for i in range(values[0], values[1]+1)]
atoms_surface = []
atoms_bulk = []
atom_data = []
# Populate data for tables and graphs depending on shape and range
if(shape=='Cuboctahedral'):
atom_data = [[i,int(cuboctahedral_total(i)-cuboctahedral_surface(i)),cuboctahedral_surface(i), cuboctahedral_total(i)] for i in sizes]
atoms_surface = [(cuboctahedral_surface(k)/cuboctahedral_total(k))*100 for k in sizes]
atoms_bulk = [(1-(cuboctahedral_surface(k)/cuboctahedral_total(k)))*100 for k in sizes]
elif(shape=='Spherical'):
atom_data = [[i,int(spherical_total(i)-spherical_surface(i)),spherical_surface(i), spherical_total(i)] for i in sizes]
atoms_surface = [(spherical_surface(k)/spherical_total(k))*100 for k in sizes]
atoms_bulk = [(1-(spherical_surface(k)/spherical_total(k)))*100 for k in sizes]
percentages = [[atoms_surface[i], atoms_bulk[i]] for i in range(len(sizes))]
ratios = [atoms_bulk[i]/atoms_surface[i]*100 for i in range(len(sizes))]
atoms_df = pd.DataFrame(atom_data[:5], columns = ['Particle Size','Bulk atoms', 'Surface atoms', 'Total atoms'])
st.table(atoms_df)
chart_data = pd.DataFrame(percentages, columns=['Surface atoms', 'Bulk atoms'])
ratio_data = pd.DataFrame(ratios)
# On clicking button after setting all parameters
if st.button('Plot graphs'):
st.write("% of Bulk and Surface atoms vs. Particle Size")
st.line_chart(chart_data)
st.write("Ratio of bulk/surface atoms vs. Particle Size")
st.line_chart(ratio_data)