t7morgen
commited on
Commit
•
2382dff
1
Parent(s):
a2ec139
figure added
Browse files- .xyz +19 -16
- app.py +98 -15
- dummy_struct.xyz +20 -17
- dummy_struct_dens.cub +0 -0
- qm_atom_features.csv +18 -15
- thermodynamics.csv +0 -0
.xyz
CHANGED
@@ -1,17 +1,20 @@
|
|
1 |
-
|
2 |
|
3 |
-
|
4 |
-
C -
|
5 |
-
C -
|
6 |
-
C
|
7 |
-
C
|
8 |
-
|
9 |
-
|
10 |
-
C
|
11 |
-
|
12 |
-
|
13 |
-
H -
|
14 |
-
H
|
15 |
-
|
16 |
-
|
17 |
-
H
|
|
|
|
|
|
|
|
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(
|
148 |
qm_atom_features = get_qm_atom_features(gfn2_output)
|
|
|
|
|
|
|
|
|
149 |
|
150 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
179 |
|
180 |
-
|
|
|
|
|
|
|
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 |
-
|
2 |
-
|
3 |
-
|
4 |
-
C -3.
|
5 |
-
C -
|
6 |
-
C -
|
7 |
-
C -
|
8 |
-
|
9 |
-
|
10 |
-
C
|
11 |
-
|
12 |
-
|
13 |
-
H -
|
14 |
-
H
|
15 |
-
|
16 |
-
|
17 |
-
H
|
|
|
|
|
|
|
|
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,
|
3 |
-
1,6
|
4 |
-
2,6,0.
|
5 |
-
3,6,0.
|
6 |
-
4,6
|
7 |
-
5,
|
8 |
-
6,
|
9 |
-
7,6
|
10 |
-
8,
|
11 |
-
9,
|
12 |
-
10,1,0.
|
13 |
-
11,1,0.
|
14 |
-
12,
|
15 |
-
13,
|
16 |
-
14,1,0.
|
|
|
|
|
|
|
|
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
|
|