t7morgen commited on
Commit
2382dff
1 Parent(s): a2ec139

figure added

Browse files
Files changed (6) hide show
  1. .xyz +19 -16
  2. app.py +98 -15
  3. dummy_struct.xyz +20 -17
  4. dummy_struct_dens.cub +0 -0
  5. qm_atom_features.csv +18 -15
  6. thermodynamics.csv +0 -0
.xyz CHANGED
@@ -1,17 +1,20 @@
1
- 15
2
 
3
- N -1.9997737 0.2248998 0.0000000
4
- C -1.8902337 -1.1433002 0.0000000
5
- C -0.8943837 1.0293398 0.0000000
6
- C 0.3497463 0.4090598 0.0000000
7
- C 0.4321763 -0.9418902 0.0000000
8
- N -0.6604037 -1.7419602 0.0000000
9
- N 1.5839363 0.9436498 0.0000000
10
- C 2.4005863 -0.1441302 0.0000000
11
- N 1.7162263 -1.3147602 0.0000000
12
- N -1.0273937 2.4370398 0.0000000
13
- H -2.7833637 -1.7527702 0.0000000
14
- H 3.4806763 -0.0808802 0.0000000
15
- H -1.9629337 2.8682998 0.0000000
16
- H -0.1966537 3.0466298 0.0000000
17
- H 2.1045263 -2.2838602 0.0000000
 
 
 
 
1
+ 18
2
 
3
+ C -2.8804300 -1.2859700 -0.3524300
4
+ C -3.8582700 -0.3294800 -0.0640300
5
+ C -3.4984000 1.0164400 0.1059900
6
+ C -2.1392600 1.3994900 -0.0163500
7
+ C -1.1678600 0.4287700 -0.3062000
8
+ C -1.5402800 -0.9082700 -0.4730600
9
+ H -4.8922100 -0.6407800 0.0258000
10
+ C -4.4698000 1.9871600 0.3958400
11
+ C -1.7793900 2.7454200 0.1536700
12
+ H -0.1241500 0.7030400 -0.4033800
13
+ H -0.7881200 -1.6538300 -0.6965000
14
+ H -3.1620700 -2.3229000 -0.4828100
15
+ C -4.0973800 3.3242000 0.5627200
16
+ C -2.7572300 3.7019000 0.4420900
17
+ H -5.5135100 1.7128900 0.4930200
18
+ H -4.8495400 4.0697500 0.7861700
19
+ H -0.7454500 3.0567100 0.0638400
20
+ H -2.4755800 4.7388200 0.5724900
app.py CHANGED
@@ -5,6 +5,7 @@ import numpy as np
5
  from Bio.PDB import PDBParser
6
  import pandas as pd
7
  import os, sys
 
8
  #sys.path.append(os.getcwd())
9
  print('importing...')
10
  from run_gfn import run_gfn2
@@ -54,6 +55,21 @@ def get_qm_atom_features(gfn2_output):
54
  qm_atom_features['Polarizability'] = pol
55
  return qm_atom_features
56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
 
58
  def get_qm_mol_features(gfn2_output):
59
  qm_mol_features = {}
@@ -66,6 +82,10 @@ def export_csv(d):
66
  d.to_csv("qm_atom_features.csv")
67
  return gr.File.update(value="qm_atom_features.csv", visible=True)
68
 
 
 
 
 
69
  def get_basic_visualization(input_f,input_format):
70
  view = py3Dmol.view(width=600, height=400)
71
  view.setBackgroundColor('white')
@@ -110,15 +130,18 @@ def get_feature_visualization(input_f,input_format, features, xyz):
110
  view.addModel(input_f, input_format, viewer=(1,0))
111
  view.addModel(input_f, input_format, viewer=(1,0))
112
  view.setStyle({'stick': {'colorscheme': {'prop': 'resi', 'C': '#cccccc'}}}, viewer=(0,0))
113
- view.setStyle({'stick': {'colorscheme': {'prop': 'resi', 'C': '#cccccc'}}}, viewer=(0,1))
114
- view.setStyle({'stick': {'colorscheme': {'prop': 'resi', 'C': '#cccccc'}}}, viewer=(1,0))
115
- view.setStyle({'stick': {'colorscheme': {'prop': 'resi', 'C': '#cccccc'}}}, viewer=(0,1))
116
- print('features', features)
117
  add_spheres_feature_view(view, features["fetchatomicprops"]["charges"], xyz, (0,1), 1.0, '#4c4e9e')
118
  add_spheres_feature_view(view, features["fetchatomicprops"]["polarisabilities"], xyz, (1,0), 1.0, '#809BAC')
119
  add_densities(view, open('dummy_struct_dens.cub', "r").read(), '#F7D7BE', (1,1))
120
  #view.setStyle({'stick': {'colorscheme': {'prop': 'resi', 'C': '#cccccc'}},'cartoon': {'color': '#4c4e9e', 'alpha':"0.6"}})
121
  view.zoomTo(viewer=(0,0))
 
 
 
122
  output = view._make_html().replace("'", '"')
123
  x = f"""<!DOCTYPE html><html> {output} </html>""" # do not use ' in this input
124
  visualization_html = f"""<iframe style="width: 100%; height:620px" name="result" allow="midi; geolocation; microphone; camera;
@@ -129,25 +152,76 @@ def get_feature_visualization(input_f,input_format, features, xyz):
129
  return visualization_html
130
 
131
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
 
133
  def predict(input_file):
134
  input_f = open(input_file.name, "r").read()
135
  input_format = input_file.name.split('.')[-1]
136
-
137
  with open('dummy_struct.'+input_format, "w") as oF:
138
  oF.write(input_f)
139
 
140
  input_f2 = open('dummy_struct.'+input_format, "r").read()
141
- gfn2_input = ["filename","geom=dummy_struct."+input_format, 'calcdens=1']
142
  gfn2_output = run_gfn2(gfn2_input)
143
-
144
 
145
  #qm_mol_features = get_qm_mol_features(gfn2_output, checked_features)
146
  #basic_visualization_html = get_basic_visualization(input_f,input_format)
147
- feature_visualization_html = get_feature_visualization(input_f,input_format, gfn2_output, gfn2_output['xyz'])
148
  qm_atom_features = get_qm_atom_features(gfn2_output)
 
 
 
 
149
 
150
- return feature_visualization_html, pd.DataFrame(qm_atom_features)#, pd.DataFrame(qm_mol_features, index=[0])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
 
152
  with gr.Blocks() as demo:
153
  gr.Markdown("# QM property calculation")
@@ -159,28 +233,37 @@ with gr.Blocks() as demo:
159
 
160
 
161
  with gr.Row():
162
- input_file = gr.File(label="Structure file for input")
 
163
  charge = gr.Textbox(placeholder="Total charge", label="Give the total charge of the input molecule. (Default=0)")
 
164
  #checked_features = gr.CheckboxGroup(["Charge", "Polarizability", "Koopman IP", "Electronic Density"], label="QM features", info="Which features shall be calculated?")
165
  #temperature = gr.Slider(value=300,minimum=0, maximum=1000, label="Temperature for Thermodynamics evaluation in K", step=5)
166
 
167
  single_btn = gr.Button(label="Run")
168
  with gr.Row():
169
  basic_html = gr.HTML()
170
-
 
171
  gr.HighlightedText(value=[("Positive Charge","Purple"),("Negative charge","red"),("Polarizability","Light blue"), ("Electronic Densities", "Beige")], color_map={"red":"#a0210f", "Light blue":"#809BAC", "Purple":"#4c4e9e", "Beige":"#F7D7BE"})
172
 
173
  with gr.Row():
174
  Dbutton = gr.Button("Download calculated atom features")
175
  csv = gr.File(interactive=False, visible=False)
 
 
 
176
  with gr.Row():
177
  df_atom_features = gr.Dataframe()
178
- #df_mol_features = gr.Dataframe()
179
 
180
- single_btn.click(fn=predict, inputs=[input_file], outputs=[basic_html, df_atom_features])
 
 
 
181
  Dbutton.click(export_csv, df_atom_features, csv)
182
-
183
-
184
 
185
 
186
  demo.launch(server_name="0.0.0.0", server_port=7860)
 
5
  from Bio.PDB import PDBParser
6
  import pandas as pd
7
  import os, sys
8
+ import matplotlib.pyplot as plt
9
  #sys.path.append(os.getcwd())
10
  print('importing...')
11
  from run_gfn import run_gfn2
 
55
  qm_atom_features['Polarizability'] = pol
56
  return qm_atom_features
57
 
58
+ def get_thermo_data(gfn2_output):
59
+ thermo_features = {}
60
+ temperature = gfn2_output["fetchthermo"]["temperature"]
61
+ entropy = gfn2_output["fetchthermo"]["entropy"]
62
+ enthalpy = gfn2_output["fetchthermo"]["enthalpy"]
63
+ cp = gfn2_output["fetchthermo"]["cp"]
64
+ #atom_list = atom_list.append('Molecule')
65
+ #charge = charge.append("")
66
+ #pol = pol.append(gfn2_output["totalpol"])
67
+ thermo_features['Temperature'] = temperature
68
+ thermo_features['entropy'] = entropy
69
+ thermo_features['enthalpy'] = enthalpy
70
+ thermo_features['cp'] = cp
71
+ return thermo_features
72
+
73
 
74
  def get_qm_mol_features(gfn2_output):
75
  qm_mol_features = {}
 
82
  d.to_csv("qm_atom_features.csv")
83
  return gr.File.update(value="qm_atom_features.csv", visible=True)
84
 
85
+ def export_csv_thermo(d):
86
+ d.to_csv("thermodynamics.csv")
87
+ return gr.File.update(value="thermodynamics.csv", visible=True)
88
+
89
  def get_basic_visualization(input_f,input_format):
90
  view = py3Dmol.view(width=600, height=400)
91
  view.setBackgroundColor('white')
 
130
  view.addModel(input_f, input_format, viewer=(1,0))
131
  view.addModel(input_f, input_format, viewer=(1,0))
132
  view.setStyle({'stick': {'colorscheme': {'prop': 'resi', 'C': '#cccccc'}}}, viewer=(0,0))
133
+ view.setStyle({'stick': {'colorscheme': {'prop': 'resi', 'C': '#cccccc'}, "radius":"0.07"}}, viewer=(0,1))
134
+ view.setStyle({'stick': {'colorscheme': {'prop': 'resi', 'C': '#cccccc'}, "radius":"0.07"}}, viewer=(1,0))
135
+ #view.setStyle({'stick': {'colorscheme': {'prop': 'resi', 'C': '#cccccc'}, "radius":"0.5"}}, viewer=(0,1))
136
+ #print('features', features)
137
  add_spheres_feature_view(view, features["fetchatomicprops"]["charges"], xyz, (0,1), 1.0, '#4c4e9e')
138
  add_spheres_feature_view(view, features["fetchatomicprops"]["polarisabilities"], xyz, (1,0), 1.0, '#809BAC')
139
  add_densities(view, open('dummy_struct_dens.cub', "r").read(), '#F7D7BE', (1,1))
140
  #view.setStyle({'stick': {'colorscheme': {'prop': 'resi', 'C': '#cccccc'}},'cartoon': {'color': '#4c4e9e', 'alpha':"0.6"}})
141
  view.zoomTo(viewer=(0,0))
142
+ view.zoomTo(viewer=(0,1))
143
+ view.zoomTo(viewer=(1,0))
144
+ view.zoomTo(viewer=(1,1))
145
  output = view._make_html().replace("'", '"')
146
  x = f"""<!DOCTYPE html><html> {output} </html>""" # do not use ' in this input
147
  visualization_html = f"""<iframe style="width: 100%; height:620px" name="result" allow="midi; geolocation; microphone; camera;
 
152
  return visualization_html
153
 
154
 
155
+ def create_input_files(input_file):
156
+ input_f = open(input_file.name, "r").read()
157
+ input_format = input_file.name.split('.')[-1]
158
+
159
+ with open('dummy_struct.'+input_format, "w") as oF:
160
+ oF.write(input_f)
161
+ return input_format
162
+
163
+ def plot_thermo(thermo_data):
164
+ fig, (ax1,ax2,ax3) = plt.subplots(3, 1, figsize=(8,8))
165
+ ax1.plot(thermo_data['Temperature'], thermo_data['entropy'], lw=2,color= "#a0210f")
166
+ ax2.plot(thermo_data['Temperature'], thermo_data['enthalpy'], lw=2, color= "#4c4e9e")
167
+ ax3.plot(thermo_data['Temperature'], thermo_data['cp'], lw=2, color= "#809BAC")
168
+ fig.suptitle('Thermodynamics')
169
+ ax3.set_xlabel('Temperature K')
170
+ ax1.set_ylabel('Entropy [J/Kmol]')
171
+ ax2.set_ylabel('Enthalpy [J]')
172
+ ax3.set_ylabel('Heat capacity [J/Kmol]')
173
+ fig.tight_layout()
174
+ #ax1.legend(loc='lower right')
175
+ return fig
176
 
177
  def predict(input_file):
178
  input_f = open(input_file.name, "r").read()
179
  input_format = input_file.name.split('.')[-1]
180
+
181
  with open('dummy_struct.'+input_format, "w") as oF:
182
  oF.write(input_f)
183
 
184
  input_f2 = open('dummy_struct.'+input_format, "r").read()
185
+ gfn2_input = ["filename","geom=dummy_struct."+input_format, 'calcdens=1', 'thermo=1']
186
  gfn2_output = run_gfn2(gfn2_input)
187
+ print(gfn2_output['fetchthermo'].keys())
188
 
189
  #qm_mol_features = get_qm_mol_features(gfn2_output, checked_features)
190
  #basic_visualization_html = get_basic_visualization(input_f,input_format)
191
+ feature_visualization_html = get_feature_visualization(input_f2,input_format, gfn2_output, gfn2_output['xyz'])
192
  qm_atom_features = get_qm_atom_features(gfn2_output)
193
+ thermo_data = get_thermo_data(gfn2_output)
194
+ plot = plot_thermo(thermo_data)
195
+ #pd.DataFrame(thermo_data)
196
+ return feature_visualization_html, pd.DataFrame(qm_atom_features), pd.DataFrame(thermo_data), plot#, pd.DataFrame(thermo_data)#, pd.DataFrame(qm_mol_features, index=[0])
197
 
198
+
199
+ def line_plot_fn(input_exe):
200
+ #input_f = open(input_file.name, "r").read()
201
+ #input_format = input_file.name.split('.')[-1]
202
+ #
203
+ #with open('dummy_struct.'+input_format, "w") as oF:
204
+ # oF.write(input_f)
205
+
206
+ #input_f2 = open('dummy_struct.'+input_format, "r").read()
207
+ gfn2_input = ["filename",input_exe, 'thermo=1']
208
+ gfn2_output = run_gfn2(gfn2_input)
209
+ print(gfn2_output['fetchthermo'].keys())
210
+
211
+ #qm_mol_features = get_qm_mol_features(gfn2_output, checked_features)
212
+ #basic_visualization_html = get_basic_visualization(input_f,input_format)
213
+ #feature_visualization_html = get_feature_visualization(input_f2,input_format, gfn2_output, gfn2_output['xyz'])
214
+ #qm_atom_features = get_qm_atom_features(gfn2_output)
215
+ thermo_data = get_thermo_data(gfn2_output)
216
+ pd.DataFrame(thermo_data)
217
+ return pd.DataFrame(thermo_data)#, pd.DataFrame(qm_mol_features, index=[0])
218
+
219
+
220
+
221
+ #def get_plot_data(input_format):
222
+ # gfn2_input = ["filename","geom=dummy_struct."+input_format, 'thermo=1']
223
+ # gfn2_output = run_gfn2(gfn2_input)
224
+ # print('plot data output', gfn2_output)
225
 
226
  with gr.Blocks() as demo:
227
  gr.Markdown("# QM property calculation")
 
233
 
234
 
235
  with gr.Row():
236
+ input_file = gr.File(label="Structure file for input (xyz format)")
237
+ input_file2 = input_file
238
  charge = gr.Textbox(placeholder="Total charge", label="Give the total charge of the input molecule. (Default=0)")
239
+
240
  #checked_features = gr.CheckboxGroup(["Charge", "Polarizability", "Koopman IP", "Electronic Density"], label="QM features", info="Which features shall be calculated?")
241
  #temperature = gr.Slider(value=300,minimum=0, maximum=1000, label="Temperature for Thermodynamics evaluation in K", step=5)
242
 
243
  single_btn = gr.Button(label="Run")
244
  with gr.Row():
245
  basic_html = gr.HTML()
246
+ plot = gr.Plot()
247
+ #gr.LinePlot(get_plot_data(input_format), every=5, x="Date", y="Sales", y_title="Sales ($ millions)", overlay_point=True, width=500, height=500)
248
  gr.HighlightedText(value=[("Positive Charge","Purple"),("Negative charge","red"),("Polarizability","Light blue"), ("Electronic Densities", "Beige")], color_map={"red":"#a0210f", "Light blue":"#809BAC", "Purple":"#4c4e9e", "Beige":"#F7D7BE"})
249
 
250
  with gr.Row():
251
  Dbutton = gr.Button("Download calculated atom features")
252
  csv = gr.File(interactive=False, visible=False)
253
+ D2button = gr.Button("Download thermodynamic properties")
254
+ csv2 = gr.File(interactive=False, visible=False)
255
+
256
  with gr.Row():
257
  df_atom_features = gr.Dataframe()
258
+ df_thermo_props = gr.Dataframe()
259
 
260
+ #with gr.Row():
261
+ # plot = gr.Plot()
262
+
263
+ single_btn.click(fn=predict, inputs=[input_file], outputs=[basic_html, df_atom_features, df_thermo_props, plot])
264
  Dbutton.click(export_csv, df_atom_features, csv)
265
+ D2button.click(export_csv_thermo, df_thermo_props, csv2)
266
+ #demo.load(fn=line_plot_fn, inputs=[input_exe], ouputs=plot)
267
 
268
 
269
  demo.launch(server_name="0.0.0.0", server_port=7860)
dummy_struct.xyz CHANGED
@@ -1,17 +1,20 @@
1
- 15
2
- test structure for adenine
3
- N -3.34715 2.34204 -0.00000
4
- C -3.23761 0.97384 0.00000
5
- C -2.24176 3.14648 0.00000
6
- C -0.99763 2.52620 -0.00000
7
- C -0.91520 1.17525 -0.00000
8
- N -2.00778 0.37518 0.00000
9
- N 0.23656 3.06079 0.00000
10
- C 1.05321 1.97301 0.00000
11
- N 0.36885 0.80238 0.00000
12
- N -2.37477 4.55418 0.00000
13
- H -4.13074 0.36437 -0.00000
14
- H 2.13330 2.03626 -0.00000
15
- H -3.31031 4.98544 -0.00000
16
- H -1.54403 5.16377 -0.00000
17
- H 0.75715 -0.16672 -0.00000
 
 
 
 
1
+ 18
2
+
3
+ C -2.88043 -1.28597 -0.35243
4
+ C -3.85827 -0.32948 -0.06403
5
+ C -3.49840 1.01644 0.10599
6
+ C -2.13926 1.39949 -0.01635
7
+ C -1.16786 0.42877 -0.30620
8
+ C -1.54028 -0.90827 -0.47306
9
+ H -4.89221 -0.64078 0.02580
10
+ C -4.46980 1.98716 0.39584
11
+ C -1.77939 2.74542 0.15367
12
+ H -0.12415 0.70304 -0.40338
13
+ H -0.78812 -1.65383 -0.69650
14
+ H -3.16207 -2.32290 -0.48281
15
+ C -4.09738 3.32420 0.56272
16
+ C -2.75723 3.70190 0.44209
17
+ H -5.51351 1.71289 0.49302
18
+ H -4.84954 4.06975 0.78617
19
+ H -0.74545 3.05671 0.06384
20
+ H -2.47558 4.73882 0.57249
dummy_struct_dens.cub CHANGED
The diff for this file is too large to render. See raw diff
 
qm_atom_features.csv CHANGED
@@ -1,16 +1,19 @@
1
  ,atom type,Charge,Polarizability
2
- 0,7,-0.2927107,7.9022415
3
- 1,6,0.1330993,8.2041169
4
- 2,6,0.162086,8.1111222
5
- 3,6,0.0412075,8.3483554
6
- 4,6,0.144987,8.0719558
7
- 5,7,-0.3111943,7.9682014
8
- 6,7,-0.2861547,7.8825044
9
- 7,6,0.0893093,8.1131044
10
- 8,7,-0.0936049,7.1331855
11
- 9,7,-0.2467183,7.6358162
12
- 10,1,0.0567793,2.3388726
13
- 11,1,0.0466292,2.4035132
14
- 12,1,0.1834568,1.7122248
15
- 13,1,0.1898361,1.6868968
16
- 14,1,0.1829925,1.7143291
 
 
 
 
1
  ,atom type,Charge,Polarizability
2
+ 0,6,-0.0318051,8.7986948
3
+ 1,6,-0.0372131,8.8194373
4
+ 2,6,0.0180579,8.6176499
5
+ 3,6,0.0180484,8.6176839
6
+ 4,6,-0.0371993,8.8193854
7
+ 5,6,-0.0318169,8.7987388
8
+ 6,1,0.0309827,2.5081171
9
+ 7,6,-0.0372016,8.819394
10
+ 8,6,-0.0371842,8.8193289
11
+ 9,1,0.0309828,2.5081162
12
+ 10,1,0.029009,2.5217377
13
+ 11,1,0.0290073,2.5217494
14
+ 12,6,-0.0318231,8.7987621
15
+ 13,6,-0.0318508,8.7988664
16
+ 14,1,0.0309837,2.5081098
17
+ 15,1,0.0290121,2.5217165
18
+ 16,1,0.0309787,2.5081448
19
+ 17,1,0.0290316,2.5215795
thermodynamics.csv ADDED
The diff for this file is too large to render. See raw diff