RajarshiMondal
commited on
Commit
•
9cb37e8
1
Parent(s):
096a065
Upload main.py
Browse files
main.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
|
2 |
import gradio as gr
|
3 |
import py3Dmol
|
4 |
from Bio.PDB import *
|
@@ -14,6 +13,7 @@ from transformMD import GNNTransformMD
|
|
14 |
import sys
|
15 |
import pytraj as pt
|
16 |
import pickle
|
|
|
17 |
|
18 |
# JavaScript functions
|
19 |
resid_hover = """function(atom,viewer) {{
|
@@ -180,6 +180,97 @@ def predict(pdb_code, pdb_file):
|
|
180 |
data = []
|
181 |
|
182 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
183 |
for i in range(adaptability.shape[0]):
|
184 |
data.append([i, atom_mapping[atoms_protein.iloc[i, atoms_protein.columns.get_loc("element")] - 1], atoms_protein.iloc[i, atoms_protein.columns.get_loc("x")],atoms_protein.iloc[i, atoms_protein.columns.get_loc("y")],atoms_protein.iloc[i, atoms_protein.columns.get_loc("z")],adaptability[i]])
|
185 |
|
@@ -209,6 +300,7 @@ def predict(pdb_code, pdb_file):
|
|
209 |
|
210 |
|
211 |
callback = gr.CSVLogger()
|
|
|
212 |
|
213 |
def run():
|
214 |
with gr.Blocks() as demo:
|
@@ -236,4 +328,4 @@ def run():
|
|
236 |
|
237 |
|
238 |
if __name__ == "__main__":
|
239 |
-
run()
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import py3Dmol
|
3 |
from Bio.PDB import *
|
|
|
13 |
import sys
|
14 |
import pytraj as pt
|
15 |
import pickle
|
16 |
+
import nglview as nv
|
17 |
|
18 |
# JavaScript functions
|
19 |
resid_hover = """function(atom,viewer) {{
|
|
|
180 |
data = []
|
181 |
|
182 |
|
183 |
+
for i in range(10):
|
184 |
+
data.append([i, atom_mapping[atoms_protein.iloc[i, atoms_protein.columns.get_loc("element")] - 1], atoms_protein.iloc[topN_ind[i], atoms_protein.columns.get_loc("x")],
|
185 |
+
atoms_protein.iloc[topN_ind[i], atoms_protein.columns.get_loc("y")],
|
186 |
+
atoms_protein.iloc[topN_ind[i], atoms_protein.columns.get_loc("z")],
|
187 |
+
adaptability[topN_ind[i]]
|
188 |
+
])
|
189 |
+
|
190 |
+
pdb = open(pdb_file.name, "r").read()
|
191 |
+
|
192 |
+
""" NGL
|
193 |
+
view = nv.NGLWidget()
|
194 |
+
view._remote_call("setSize", target="Widget", args=["800px", "600px"])
|
195 |
+
view.add_pdbstr(pdb, defaultRepresentation=True)
|
196 |
+
"""
|
197 |
+
|
198 |
+
view = py3Dmol.view(width=600, height=400)
|
199 |
+
view.setBackgroundColor('white')
|
200 |
+
view.addModel(pdb, "pdb")
|
201 |
+
view.setStyle({'stick': {'colorscheme': {'prop': 'resi', 'C': 'turquoise'}}})
|
202 |
+
|
203 |
+
for i in range(10):
|
204 |
+
view.addSphere({'center':{'x':atoms_protein.iloc[topN_ind[i], atoms_protein.columns.get_loc("x")], 'y':atoms_protein.iloc[topN_ind[i], atoms_protein.columns.get_loc("y")],'z':atoms_protein.iloc[topN_ind[i], atoms_protein.columns.get_loc("z")]},'radius':adaptability[topN_ind[i]]/1.5,'color':'orange','alpha':0.75})
|
205 |
+
|
206 |
+
# Add lighting and shading options to the view object:
|
207 |
+
view.setStyle({'stick': {'colorscheme': {'prop': 'resi', 'C': 'turquoise'}}})
|
208 |
+
view.setStyle({'sphere': {}})
|
209 |
+
view.addLight([0, 0, 10], [1, 1, 1], 1) # Add directional light from the z-axis
|
210 |
+
view.setSpecular(0.5) # Adjust the specular lighting effect
|
211 |
+
view.setAmbient(0.5) # Adjust the ambient lighting effect
|
212 |
+
|
213 |
+
view.zoomTo()
|
214 |
+
view.rotate(180, "y") # Rotate the structure by 180 degrees along the y-axis
|
215 |
+
# Add animation options to the view object:
|
216 |
+
view.animate({'loop': 'forward', 'reps': 2}) # Animate the visualization to loop forward 2 times
|
217 |
+
output = view._make_html().replace("'", '"')
|
218 |
+
|
219 |
+
""" NGLviewer
|
220 |
+
output = view.render_notebook()
|
221 |
+
"""
|
222 |
+
|
223 |
+
x = f"""<!DOCTYPE html><html> {output} </html>""" # do not use ' in this input
|
224 |
+
return f"""<iframe style="width: 100%; height:420px" name="result" allow="midi; geolocation; microphone; camera;
|
225 |
+
display-capture; encrypted-media;" sandbox="allow-modals allow-forms
|
226 |
+
allow-scripts allow-same-origin allow-popups
|
227 |
+
allow-top-navigation-by-user-activation allow-downloads" allowfullscreen=""
|
228 |
+
allowpaymentrequest="" frameborder="0" srcdoc='{x}'></iframe>""", pd.DataFrame(data, columns=['index','element','x','y','z','Adaptability'])
|
229 |
+
|
230 |
+
""" NGLviewer
|
231 |
+
return output, pd.DataFrame(data, columns=['index','element','x','y','z','Adaptability'])
|
232 |
+
"""
|
233 |
+
|
234 |
+
callback = gr.CSVLogger()
|
235 |
+
|
236 |
+
"""
|
237 |
+
def predict(pdb_code, pdb_file):
|
238 |
+
#path_to_pdb = get_pdb(pdb_code=pdb_code, filepath=pdb_file)
|
239 |
+
|
240 |
+
#pdb = open(path_to_pdb, "r").read()
|
241 |
+
# switch to misato env if not running from container
|
242 |
+
|
243 |
+
pdbid = get_pdbid_from_filename(pdb_file.name)
|
244 |
+
mdh5_file = "inference_for_md.hdf5"
|
245 |
+
mappath = "/maps"
|
246 |
+
mask = "!@H="
|
247 |
+
preprocess(pdbid=pdbid, ouputfile=mdh5_file, mask=mask, mappath=mappath)
|
248 |
+
|
249 |
+
md_H5File = h5py.File(mdh5_file)
|
250 |
+
|
251 |
+
column_names = ["x", "y", "z", "element"]
|
252 |
+
atoms_protein = pd.DataFrame(columns = column_names)
|
253 |
+
cutoff = md_H5File[pdbid]["molecules_begin_atom_index"][:][-1] # cutoff defines protein atoms
|
254 |
+
|
255 |
+
atoms_protein["x"] = md_H5File[pdbid]["atoms_coordinates_ref"][:][:cutoff, 0]
|
256 |
+
atoms_protein["y"] = md_H5File[pdbid]["atoms_coordinates_ref"][:][:cutoff, 1]
|
257 |
+
atoms_protein["z"] = md_H5File[pdbid]["atoms_coordinates_ref"][:][:cutoff, 2]
|
258 |
+
|
259 |
+
atoms_protein["element"] = md_H5File[pdbid]["atoms_element"][:][:cutoff]
|
260 |
+
|
261 |
+
item = {}
|
262 |
+
item["scores"] = 0
|
263 |
+
item["id"] = pdbid
|
264 |
+
item["atoms_protein"] = atoms_protein
|
265 |
+
|
266 |
+
transform = GNNTransformMD()
|
267 |
+
data_item = transform(item)
|
268 |
+
adaptability = model(data_item)
|
269 |
+
adaptability = adaptability.detach().numpy()
|
270 |
+
|
271 |
+
data = []
|
272 |
+
|
273 |
+
|
274 |
for i in range(adaptability.shape[0]):
|
275 |
data.append([i, atom_mapping[atoms_protein.iloc[i, atoms_protein.columns.get_loc("element")] - 1], atoms_protein.iloc[i, atoms_protein.columns.get_loc("x")],atoms_protein.iloc[i, atoms_protein.columns.get_loc("y")],atoms_protein.iloc[i, atoms_protein.columns.get_loc("z")],adaptability[i]])
|
276 |
|
|
|
300 |
|
301 |
|
302 |
callback = gr.CSVLogger()
|
303 |
+
"""
|
304 |
|
305 |
def run():
|
306 |
with gr.Blocks() as demo:
|
|
|
328 |
|
329 |
|
330 |
if __name__ == "__main__":
|
331 |
+
run()
|