t7morgen commited on
Commit
80c8aa3
1 Parent(s): f343ded

colors etc

Browse files
.xyz ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
__pycache__/run_gfn.cpython-310.pyc CHANGED
Binary files a/__pycache__/run_gfn.cpython-310.pyc and b/__pycache__/run_gfn.cpython-310.pyc differ
 
app.py CHANGED
@@ -31,17 +31,31 @@ function(atom,viewer) {
31
  }
32
  }"""
33
 
34
- def get_qm_atom_features(gfn2_output, checked_features):
 
 
 
 
 
 
 
 
 
 
35
  qm_atom_features = {}
36
- qm_atom_features['atom type'] = gfn2_output["fetchatomicprops"]["atmlist"]
37
- for checked_feature in checked_features:
38
- if checked_feature == 'Charge':
39
- qm_atom_features['Charge'] = gfn2_output["fetchatomicprops"]["charges"]
40
- if checked_feature == 'Polarizability':
41
- qm_atom_features['Polarizability'] = gfn2_output["fetchatomicprops"]["polarisabilities"]
 
 
 
42
  return qm_atom_features
43
 
44
- def get_qm_mol_features(gfn2_output, checked_features):
 
45
  qm_mol_features = {}
46
  qm_mol_features['Total Energy'] = gfn2_output["etotal"]
47
  qm_mol_features['Total Polarizability'] = gfn2_output["totalpol"]
@@ -70,16 +84,17 @@ def get_basic_visualization(input_f,input_format):
70
  return visualization_html
71
 
72
  def add_spheres_feature_view(view, feature,xyz, viewnum, sizefactor, spec_color):
 
73
  for i in range(len(feature)):
74
  if feature[i]<0:
75
- color="red"
76
  else:
77
  color=spec_color
78
  view.addSphere({'center':{
79
  'x':xyz[i][0],
80
  'y':xyz[i][1],
81
  'z':xyz[i][2]},
82
- 'radius':abs(feature[i])*sizefactor,'color':color,'alpha':1.00}, viewer=viewnum)
83
  return view
84
 
85
  def add_densities(view, dens, color, viewnum):
@@ -88,23 +103,24 @@ def add_densities(view, dens, color, viewnum):
88
 
89
 
90
  def get_feature_visualization(input_f,input_format, features, xyz):
91
- view = py3Dmol.view(width=600, height=400, viewergrid=(2,2))
92
  view.setBackgroundColor('white')
93
  view.addModel(input_f, input_format, viewer=(0,0))
94
- view.addModel(input_f, input_format, viewer=(0,1))
95
- view.addModel(input_f, input_format, viewer=(1,0))
96
  view.setStyle({'stick': {'colorscheme': {'prop': 'resi', 'C': '#cccccc'}}}, viewer=(0,0))
97
- view.setStyle({'stick': {'colorscheme': {'prop': 'resi', 'C': '#cccccc'}}}, viewer=(0,1))
98
- view.setStyle({'stick': {'colorscheme': {'prop': 'resi', 'C': '#cccccc'}}}, viewer=(1,0))
99
  #view.setStyle({'stick': {'colorscheme': {'prop': 'resi', 'C': '#cccccc'}}}, viewer=(0,1))
100
- add_spheres_feature_view(view, features["fetchatomicprops"]["charges"], xyz, (0,1), 20, 'blue')
101
- add_spheres_feature_view(view, features["fetchatomicprops"]["polarisabilities"], xyz, (1,0), 0.2, 'orange')
102
- add_densities(view, open('dummy_struct_dens.cub', "r").read(), 'green', (1,1))
 
 
 
103
  #view.setStyle({'stick': {'colorscheme': {'prop': 'resi', 'C': '#cccccc'}},'cartoon': {'color': '#4c4e9e', 'alpha':"0.6"}})
104
  view.zoomTo(viewer=(0,0))
105
  output = view._make_html().replace("'", '"')
106
  x = f"""<!DOCTYPE html><html> {output} </html>""" # do not use ' in this input
107
- visualization_html = f"""<iframe style="width: 100%; height:420px" name="result" allow="midi; geolocation; microphone; camera;
108
  display-capture; encrypted-media;" sandbox="allow-modals allow-forms
109
  allow-scripts allow-same-origin allow-popups
110
  allow-top-navigation-by-user-activation allow-downloads" allowfullscreen=""
@@ -113,7 +129,7 @@ def get_feature_visualization(input_f,input_format, features, xyz):
113
 
114
 
115
 
116
- def predict(checked_features, input_file, temperature):
117
  input_f = open(input_file.name, "r").read()
118
  input_format = input_file.name.split('.')[-1]
119
 
@@ -124,11 +140,11 @@ def predict(checked_features, input_file, temperature):
124
  gfn2_input = ["filename","geom=dummy_struct."+input_format, 'calcdens=1']
125
  gfn2_output = run_gfn2(gfn2_input)
126
 
127
- qm_atom_features = get_qm_atom_features(gfn2_output, checked_features)
128
- qm_mol_features = get_qm_mol_features(gfn2_output, checked_features)
129
  #basic_visualization_html = get_basic_visualization(input_f,input_format)
130
  feature_visualization_html = get_feature_visualization(input_f,input_format, gfn2_output, gfn2_output['xyz'])
131
-
132
 
133
  return feature_visualization_html, pd.DataFrame(qm_atom_features)#, pd.DataFrame(qm_mol_features, index=[0])
134
 
@@ -144,18 +160,15 @@ with gr.Blocks() as demo:
144
  with gr.Row():
145
  input_file = gr.File(label="Structure file for input")
146
  charge = gr.Textbox(placeholder="Total charge", label="Give the total charge of the input molecule. (Default=0)")
147
- checked_features = gr.CheckboxGroup(["Charge", "Polarizability", "Koopman IP", "Electronic Density"], label="QM features", info="Which features shall be calculated?")
148
- temperature = gr.Slider(value=300,minimum=0, maximum=1000, label="Temperature for Thermodynamics evaluation in K", step=5)
149
- #with gr.Row():
150
- # helix = gr.ColorPicker(label="helix")
151
- # sheet = gr.ColorPicker(label="sheet")
152
- # loop = gr.ColorPicker(label="loop")
153
  single_btn = gr.Button(label="Run")
154
  with gr.Row():
155
  basic_html = gr.HTML()
156
- gr.HighlightedText(value=[("Positive Charge","blue"),("Negative charge","red"),("Polarizability","orange"), ("Electronic Densities", "Green")], color_map={"red":"red", "blue":"blue", "orange":"orange", "Green":"green"})
157
- #with gr.Row():
158
- # basic_html = gr.HTML()
159
  with gr.Row():
160
  Dbutton = gr.Button("Download calculated atom features")
161
  csv = gr.File(interactive=False, visible=False)
@@ -163,7 +176,7 @@ with gr.Blocks() as demo:
163
  df_atom_features = gr.Dataframe()
164
  #df_mol_features = gr.Dataframe()
165
 
166
- single_btn.click(fn=predict, inputs=[checked_features, input_file, temperature], outputs=[basic_html, df_atom_features])
167
  Dbutton.click(export_csv, df_atom_features, csv)
168
 
169
 
 
31
  }
32
  }"""
33
 
34
+ #def get_qm_atom_features(gfn2_output, checked_features):
35
+ # qm_atom_features = {}
36
+ # qm_atom_features['atom type'] = gfn2_output["fetchatomicprops"]["atmlist"]
37
+ # for checked_feature in checked_features:
38
+ # if checked_feature == 'Charge':
39
+ # qm_atom_features['Charge'] = gfn2_output["fetchatomicprops"]["charges"]
40
+ # if checked_feature == 'Polarizability':
41
+ # qm_atom_features['Polarizability'] = gfn2_output["fetchatomicprops"]["polarisabilities"]
42
+ # return qm_atom_features
43
+
44
+ def get_qm_atom_features(gfn2_output):
45
  qm_atom_features = {}
46
+ atom_list = gfn2_output["fetchatomicprops"]["atmlist"]
47
+ charge = gfn2_output["fetchatomicprops"]["charges"]
48
+ pol = gfn2_output["fetchatomicprops"]["polarisabilities"]
49
+ #atom_list = atom_list.append('Molecule')
50
+ #charge = charge.append("")
51
+ #pol = pol.append(gfn2_output["totalpol"])
52
+ qm_atom_features['atom type'] = atom_list
53
+ qm_atom_features['Charge'] = charge
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 = {}
60
  qm_mol_features['Total Energy'] = gfn2_output["etotal"]
61
  qm_mol_features['Total Polarizability'] = gfn2_output["totalpol"]
 
84
  return visualization_html
85
 
86
  def add_spheres_feature_view(view, feature,xyz, viewnum, sizefactor, spec_color):
87
+ normalization = max(max(feature),abs(min(feature)))
88
  for i in range(len(feature)):
89
  if feature[i]<0:
90
+ color="#a0210f"
91
  else:
92
  color=spec_color
93
  view.addSphere({'center':{
94
  'x':xyz[i][0],
95
  'y':xyz[i][1],
96
  'z':xyz[i][2]},
97
+ 'radius':abs(feature[i])/normalization*sizefactor,'color':color,'alpha':1.00}, viewer=viewnum)
98
  return view
99
 
100
  def add_densities(view, dens, color, viewnum):
 
103
 
104
 
105
  def get_feature_visualization(input_f,input_format, features, xyz):
106
+ view = py3Dmol.view(width=620, height=620, viewergrid=(2,2))
107
  view.setBackgroundColor('white')
108
  view.addModel(input_f, input_format, viewer=(0,0))
109
+ #view.addModel(input_f, input_format, viewer=(0,1))
110
+ #view.addModel(input_f, input_format, viewer=(1,0))
111
  view.setStyle({'stick': {'colorscheme': {'prop': 'resi', 'C': '#cccccc'}}}, viewer=(0,0))
 
 
112
  #view.setStyle({'stick': {'colorscheme': {'prop': 'resi', 'C': '#cccccc'}}}, viewer=(0,1))
113
+ #view.setStyle({'stick': {'colorscheme': {'prop': 'resi', 'C': '#cccccc'}}}, viewer=(1,0))
114
+ #view.setStyle({'stick': {'colorscheme': {'prop': 'resi', 'C': '#cccccc'}}}, viewer=(0,1))
115
+ print('features', features)
116
+ add_spheres_feature_view(view, features["fetchatomicprops"]["charges"], xyz, (0,1), 1.0, '#4c4e9e')
117
+ add_spheres_feature_view(view, features["fetchatomicprops"]["polarisabilities"], xyz, (1,0), 1.0, '#809BAC')
118
+ add_densities(view, open('dummy_struct_dens.cub', "r").read(), '#F7D7BE', (1,1))
119
  #view.setStyle({'stick': {'colorscheme': {'prop': 'resi', 'C': '#cccccc'}},'cartoon': {'color': '#4c4e9e', 'alpha':"0.6"}})
120
  view.zoomTo(viewer=(0,0))
121
  output = view._make_html().replace("'", '"')
122
  x = f"""<!DOCTYPE html><html> {output} </html>""" # do not use ' in this input
123
+ visualization_html = f"""<iframe style="width: 100%; height:620px" name="result" allow="midi; geolocation; microphone; camera;
124
  display-capture; encrypted-media;" sandbox="allow-modals allow-forms
125
  allow-scripts allow-same-origin allow-popups
126
  allow-top-navigation-by-user-activation allow-downloads" allowfullscreen=""
 
129
 
130
 
131
 
132
+ def predict(input_file):
133
  input_f = open(input_file.name, "r").read()
134
  input_format = input_file.name.split('.')[-1]
135
 
 
140
  gfn2_input = ["filename","geom=dummy_struct."+input_format, 'calcdens=1']
141
  gfn2_output = run_gfn2(gfn2_input)
142
 
143
+
144
+ #qm_mol_features = get_qm_mol_features(gfn2_output, checked_features)
145
  #basic_visualization_html = get_basic_visualization(input_f,input_format)
146
  feature_visualization_html = get_feature_visualization(input_f,input_format, gfn2_output, gfn2_output['xyz'])
147
+ qm_atom_features = get_qm_atom_features(gfn2_output)
148
 
149
  return feature_visualization_html, pd.DataFrame(qm_atom_features)#, pd.DataFrame(qm_mol_features, index=[0])
150
 
 
160
  with gr.Row():
161
  input_file = gr.File(label="Structure file for input")
162
  charge = gr.Textbox(placeholder="Total charge", label="Give the total charge of the input molecule. (Default=0)")
163
+ #checked_features = gr.CheckboxGroup(["Charge", "Polarizability", "Koopman IP", "Electronic Density"], label="QM features", info="Which features shall be calculated?")
164
+ #temperature = gr.Slider(value=300,minimum=0, maximum=1000, label="Temperature for Thermodynamics evaluation in K", step=5)
165
+
 
 
 
166
  single_btn = gr.Button(label="Run")
167
  with gr.Row():
168
  basic_html = gr.HTML()
169
+
170
+ 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"})
171
+
172
  with gr.Row():
173
  Dbutton = gr.Button("Download calculated atom features")
174
  csv = gr.File(interactive=False, visible=False)
 
176
  df_atom_features = gr.Dataframe()
177
  #df_mol_features = gr.Dataframe()
178
 
179
+ single_btn.click(fn=predict, inputs=[input_file], outputs=[basic_html, df_atom_features])
180
  Dbutton.click(export_csv, df_atom_features, csv)
181
 
182
 
dummy_struct.pdb ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ CRYST1 81.052 81.052 81.052 109.47 109.47 109.47 1
2
+ ATOM 1 N GLU 199 36.081 39.009 29.686 1.00 0.00 N
3
+ ATOM 2 H1 GLU 199 35.429 38.796 30.426 1.00 0.00 H
4
+ ATOM 3 H2 GLU 199 36.154 38.207 29.076 1.00 0.00 H
5
+ ATOM 4 H3 GLU 199 35.853 39.916 29.303 1.00 0.00 H
6
+ ATOM 5 CA GLU 199 37.432 39.167 30.291 1.00 0.00 C
7
+ ATOM 6 HA GLU 199 38.116 38.436 29.860 1.00 0.00 H
8
+ ATOM 7 CB GLU 199 37.982 40.570 30.022 1.00 0.00 C
9
+ ATOM 8 HB2 GLU 199 38.901 40.671 30.598 1.00 0.00 H
10
+ ATOM 9 HB3 GLU 199 38.212 40.628 28.958 1.00 0.00 H
11
+ ATOM 10 CG GLU 199 37.028 41.688 30.394 1.00 0.00 C
12
+ ATOM 11 HG2 GLU 199 36.079 41.510 29.887 1.00 0.00 H
13
+ ATOM 12 HG3 GLU 199 36.878 41.635 31.472 1.00 0.00 H
14
+ ATOM 13 CD GLU 199 37.549 43.062 30.023 1.00 0.00 C
15
+ ATOM 14 OE1 GLU 199 38.098 43.217 28.907 1.00 0.00 O
16
+ ATOM 15 OE2 GLU 199 37.394 43.992 30.847 1.00 0.00 O
17
+ ATOM 16 C GLU 199 37.378 38.880 31.790 1.00 0.00 C
18
+ ATOM 17 O GLU 199 36.391 39.196 32.464 1.00 0.00 O
19
+ ATOM 18 N ASP 200 38.421 38.232 32.294 1.00 0.00 N
20
+ ATOM 19 H ASP 200 39.166 37.937 31.679 1.00 0.00 H
21
+ ATOM 20 CA ASP 200 38.512 37.883 33.705 1.00 0.00 C
22
+ ATOM 21 HA ASP 200 37.703 38.355 34.262 1.00 0.00 H
23
+ ATOM 22 CB ASP 200 38.401 36.370 33.871 1.00 0.00 C
24
+ ATOM 23 HB2 ASP 200 39.160 35.871 33.269 1.00 0.00 H
25
+ ATOM 24 HB3 ASP 200 38.581 36.162 34.926 1.00 0.00 H
26
+ ATOM 25 CG ASP 200 37.030 35.856 33.483 1.00 0.00 C
27
+ ATOM 26 OD1 ASP 200 36.116 35.958 34.323 1.00 0.00 O
28
+ ATOM 27 OD2 ASP 200 36.851 35.393 32.334 1.00 0.00 O
29
+ ATOM 28 C ASP 200 39.827 38.407 34.256 1.00 0.00 C
30
+ ATOM 29 O ASP 200 40.869 37.761 34.126 1.00 0.00 O
31
+ ATOM 30 N LEU 201 39.771 39.607 34.828 1.00 0.00 N
32
+ ATOM 31 H LEU 201 38.893 40.106 34.850 1.00 0.00 H
33
+ ATOM 32 CA LEU 201 40.950 40.261 35.373 1.00 0.00 C
34
+ ATOM 33 HA LEU 201 41.853 39.729 35.075 1.00 0.00 H
35
+ ATOM 34 CB LEU 201 41.025 41.684 34.837 1.00 0.00 C
36
+ ATOM 35 HB2 LEU 201 40.080 42.153 35.112 1.00 0.00 H
37
+ ATOM 36 HB3 LEU 201 41.851 42.260 35.254 1.00 0.00 H
38
+ ATOM 37 CG LEU 201 41.150 41.645 33.318 1.00 0.00 C
39
+ ATOM 38 HG LEU 201 40.848 40.661 32.961 1.00 0.00 H
40
+ ATOM 39 CD1 LEU 201 40.276 42.692 32.696 1.00 0.00 C
41
+ ATOM 40 HD11 LEU 201 40.578 43.677 33.052 1.00 0.00 H
42
+ ATOM 41 HD12 LEU 201 40.375 42.652 31.612 1.00 0.00 H
43
+ ATOM 42 HD13 LEU 201 39.237 42.509 32.972 1.00 0.00 H
44
+ ATOM 43 CD2 LEU 201 42.612 41.790 32.919 1.00 0.00 C
45
+ ATOM 44 HD21 LEU 201 43.189 40.972 33.350 1.00 0.00 H
46
+ ATOM 45 HD22 LEU 201 42.697 41.762 31.833 1.00 0.00 H
47
+ ATOM 46 HD23 LEU 201 42.997 42.740 33.289 1.00 0.00 H
48
+ ATOM 47 C LEU 201 40.979 40.272 36.891 1.00 0.00 C
49
+ ATOM 48 O LEU 201 42.089 40.361 37.458 1.00 0.00 O
50
+ ATOM 49 OXT LEU 201 39.891 40.190 37.498 1.00 0.00 O
51
+ TER 50 LEU 201
52
+ END
dummy_struct.xyz CHANGED
@@ -1,20 +1,17 @@
1
- 18
2
-
3
- C 1.1681569 -0.2550550 0.8756595
4
- C 1.3484628 0.1965789 -0.5826021
5
- C -0.1630149 0.2550556 1.4507918
6
- C -1.3484630 -0.1965791 0.5826038
7
- C -1.1681567 0.2550548 -0.8756576
8
- C 0.1630149 -0.2550556 -1.4507899
9
- H -1.4440620 -1.2992544 0.6239080
10
- H -2.2954881 0.2017985 0.9917659
11
- H -0.2922653 -0.1016823 2.4895446
12
- H -0.1446071 1.3607175 1.5133326
13
- H 1.4440620 1.2992544 -0.6239060
14
- H 2.2954880 -0.2017985 -0.9917640
15
- H 2.0131366 0.1016836 1.4934968
16
- H 1.2010813 -1.3607168 0.9319297
17
- H 0.2922653 0.1016827 -2.4895433
18
- H 0.1446071 -1.3607176 -1.5133316
19
- H -2.0131365 -0.1016835 -1.4934950
20
- H -1.2010813 1.3607168 -0.9319277
 
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
 
 
 
dummy_struct_dens.cub CHANGED
The diff for this file is too large to render. See raw diff
 
qm_atom_features.csv CHANGED
@@ -1,19 +1,16 @@
1
- ,atom type
2
- 0,6
3
- 1,6
4
- 2,6
5
- 3,6
6
- 4,6
7
- 5,6
8
- 6,1
9
- 7,1
10
- 8,1
11
- 9,1
12
- 10,1
13
- 11,1
14
- 12,1
15
- 13,1
16
- 14,1
17
- 15,1
18
- 16,1
19
- 17,1
 
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