Last active
August 20, 2020 01:34
-
-
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!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
View DFT with VASP output using SSH Tunnel and Streamlit
To use this app:
"ssh -o logLevel=ERROR -L 8501:localhost:8501 user@host"
"streamlit run https://gist.githubusercontent.com/massgh/823b40873991fc7160523d3cdffc969d/raw/StreamlitRemoteServer.py"
from remote server's project folder you are working in.
loacalhost:8501
in your browser and see the app running!