Skip to content

Instantly share code, notes, and snippets.

@asaboor-gh
Last active August 20, 2020 01:34
Show Gist options
  • Save asaboor-gh/823b40873991fc7160523d3cdffc969d to your computer and use it in GitHub Desktop.
Save asaboor-gh/823b40873991fc7160523d3cdffc969d to your computer and use it in GitHub Desktop.
Streamlit minimal app to view VASP output from remote server without downloading files. See instructions in comments!
import streamlit as st
import pivotpy as pp
import os
st.write('# Streamlit from Remote Server!')
path_project = st.text_input("Literal Path to project folder", os.getcwd())
with st.spinner('Selecting Files ...'):
if os.path.isdir(path_project):
files = pp.get_child_items(path_project,include=['vasprun.xml'],filesOnly = True)
else:
st.warning('Path is incorrect, falling back to launch path')
files = pp.get_child_items(include=['vasprun.xml'],filesOnly = True)
if len(files[0]) == 0:
st.error('No files available with current input')
st.stop()
filter_in = st.text_input("Type to filter subdirectories")
if filter_in:
s_fs = [f for f in files[0] if filter_in in f]
if len(s_fs) == 0:
st.error('No files available with input filter')
st.stop()
else:
files = [s_fs, files[1]]
fs = [os.path.join(files[1],f) for f in files[0]]
option = st.selectbox(
'Select File', tuple(fs))
@st.cache(suppress_st_warning=True)
def i_plot(path):
return pp.plotly_rgb_lines(path)
try:
fig1 = i_plot(option)
st.plotly_chart(fig1,use_container_width=True)
#st.balloons()
except:
st.error('Something went wrong! Check EIGENVAL or vasprun.xml')
# Showing datafiles
cars = ['INCAR','OSZICAR','POSCAR','KPOINTS']
dir_ = os.path.split(option)[0]
cars_path = [os.path.join(dir_,car) for car in cars]
for car,car_p in zip(cars,cars_path):
if st.checkbox("Show {}".format(car),value = True) and os.path.isfile(car_p):
lines = []
with open(car_p,'r') as f:
lines = ''.join([l for l in f.readlines() if '#' not in l])
st.code("{}".format(lines), language='shell')
f.close()
@asaboor-gh
Copy link
Author

asaboor-gh commented Aug 20, 2020

App Screenshots

image
image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment