AndySAnker commited on
Commit
066ac37
1 Parent(s): 9000099

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -43
app.py CHANGED
@@ -5,49 +5,6 @@ import matplotlib.pyplot as plt
5
  import argparse, h5py, os, re, pkg_resources
6
  import streamlit as st
7
 
8
- st.title('POMFinder')
9
-
10
- st.write('Welcome to DeepStruc that is a Deep Generative Model which has been trained to solve a mono-metallic structure (<200 atoms) based on a PDF!')
11
- st.write('Upload a PDF to use DeepStruc to predict the structure.')
12
-
13
- # Define the file upload widget
14
- pdf_file = st.file_uploader("Upload PDF file in .gr format", type=["gr"])
15
-
16
- # Define the form to get the other parameters
17
- num_structures = st.number_input("Qmin value", min_value=0, max_value=2, value=0.7)
18
- #structure_index = st.number_input("Index of structure to visualize", min_value=0, value=3)
19
- #sigma = st.number_input("Standard deviation for sampling", min_value=0.1, value=3.0)
20
-
21
- parser = argparse.ArgumentParser(prog='POMFinder', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
22
-
23
- requiredNamed = parser.add_argument_group('required named arguments')
24
-
25
- requiredNamed.add_argument("-d", "--data", default=None, type=str,
26
- help="a directory of PDFs or a file.", required=True)
27
-
28
- requiredNamed.add_argument("-n", "--nyquist", default="No", type=str,
29
- help="is the data nyquist sampled", required=True)
30
-
31
- parser.add_argument("-i", "--Qmin", default=0.7, type=float,
32
- help="Qmin value of the experimental PDF")
33
-
34
- parser.add_argument("-a", "--Qmax", default=30, type=float,
35
- help="Qmax value of the experimental PDF")
36
-
37
- parser.add_argument("-f", "--file_name", default='', type=str,
38
- help="Name of the output file")
39
-
40
- parser.add_argument("-m", "--Qdamp", default=0.04, type=float,
41
- help="Qdamp value of the experimental PDF")
42
-
43
- def main(args=None):
44
- args = parser.parse_args(args=args)
45
- y, y_onehotenc_cat, y_onehotenc_values, POMFinder = get_POMFinder()
46
- r, Gr = PDF_Preparation(args.data, args.Qmin, args.Qmax, args.Qdamp, rmax=10, nyquist=args.nyquist)
47
- res, y_pred_proba = POMPredicter(POMFinder, Gr, y_onehotenc_cat);
48
-
49
-
50
-
51
  def get_POMFinder():
52
  # Get file paths
53
  load_files = pkg_resources.resource_listdir(__name__, 'Backend/')
@@ -129,3 +86,69 @@ def POMPredicter(POMFinder, Gr, y_onehotenc_cat):
129
  return res, y_pred_proba
130
 
131
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  import argparse, h5py, os, re, pkg_resources
6
  import streamlit as st
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  def get_POMFinder():
9
  # Get file paths
10
  load_files = pkg_resources.resource_listdir(__name__, 'Backend/')
 
86
  return res, y_pred_proba
87
 
88
 
89
+ st.title('POMFinder')
90
+
91
+ st.write('Welcome to DeepStruc that is a Deep Generative Model which has been trained to solve a mono-metallic structure (<200 atoms) based on a PDF!')
92
+ st.write('Upload a PDF to use DeepStruc to predict the structure.')
93
+
94
+ # Define the file upload widget
95
+ pdf_file = st.file_uploader("Upload PDF file in .gr format", type=["gr"])
96
+
97
+ # Define the form to get the other parameters
98
+ Qmin = st.number_input("Qmin value of the experimental PDF", min_value=0.0, max_value=2.0, value=0.7)
99
+ Qmax = st.number_input("Qmax value of the experimental PDF", min_value=15.0, max_value=40.0, value=30.0)
100
+ Qdamp = st.number_input("Qdamp value of the experimental PDF", min_value=0.00, max_value=0.08, value=0.04)
101
+
102
+ parser = argparse.ArgumentParser(prog='POMFinder', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
103
+ args = parser.parse_args()
104
+ args.data = "uploaded_file.gr"
105
+ args.nyquist = "True"
106
+ args.Qmin = Qmin
107
+ args.Qmax = Qmax
108
+ args.Qdamp = Qdamp
109
+ args.file_name = "POMFinder_results.txt"
110
+
111
+ if pdf_file is None:
112
+ st.warning("Please upload a PDF file.")
113
+ else:
114
+ # Get the contents of the file as bytes
115
+ file_bytes = pdf_file.read()
116
+
117
+ # Save the contents of the file to disk
118
+ with open("uploaded_file.gr", "wb") as f:
119
+ f.write(file_bytes)
120
+
121
+ #Predict with POMFinder
122
+ y, y_onehotenc_cat, y_onehotenc_values, POMFinder = get_POMFinder()
123
+ r, Gr = PDF_Preparation(args.data, args.Qmin, args.Qmax, args.Qdamp, rmax=10, nyquist=args.nyquist)
124
+ res, y_pred_proba = POMPredicter(POMFinder, Gr, y_onehotenc_cat);
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+
134
+ st.subheader('Cite')
135
+
136
+ st.write('If you use DeepStruc, our code or results, please consider citing our papers. Thanks in advance!')
137
+
138
+ st.write('DeepStruc: Towards structure solution from pair distribution function data using deep generative models **2023** (https://pubs.rsc.org/en/content/articlehtml/2022/dd/d2dd00086e)')
139
+ st.write('Characterising the atomic structure of mono-metallic nanoparticles from x-ray scattering data using conditional generative models **2020** (https://par.nsf.gov/biblio/10300745)')
140
+
141
+ st.subheader('LICENSE')
142
+
143
+ st.write('This project is licensed under the Apache License Version 2.0, January 2004 - see the LICENSE file at https://github.com/EmilSkaaning/DeepStruc/blob/main/LICENSE.md for details.')
144
+ st.write("")
145
+
146
+ st.subheader('Github')
147
+ st.write('https://github.com/EmilSkaaning/DeepStruc')
148
+
149
+ st.subheader('Questions')
150
+ st.write('andy@chem.ku.dk or etsk@chem.ku.dk')
151
+
152
+
153
+
154
+