RajarshiMondal
commited on
Commit
•
cd9cc79
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,100 @@ 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 +303,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 +331,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 |
+
|
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 |
+
|
218 |
+
"""
|
219 |
+
output = view._make_html().replace("'", '"')
|
220 |
+
"""
|
221 |
+
|
222 |
+
output = view.render_notebook()
|
223 |
+
|
224 |
+
"""
|
225 |
+
x = f"""<!DOCTYPE html><html> {output} </html>""" # do not use ' in this input
|
226 |
+
return f"""<iframe style="width: 100%; height:420px" name="result" allow="midi; geolocation; microphone; camera;
|
227 |
+
display-capture; encrypted-media;" sandbox="allow-modals allow-forms
|
228 |
+
allow-scripts allow-same-origin allow-popups
|
229 |
+
allow-top-navigation-by-user-activation allow-downloads" allowfullscreen=""
|
230 |
+
allowpaymentrequest="" frameborder="0" srcdoc='{x}'></iframe>""", pd.DataFrame(data, columns=['index','element','x','y','z','Adaptability'])
|
231 |
+
|
232 |
+
"""
|
233 |
+
|
234 |
+
return output, pd.DataFrame(data, columns=['index','element','x','y','z','Adaptability'])
|
235 |
+
|
236 |
+
|
237 |
+
callback = gr.CSVLogger()
|
238 |
+
|
239 |
+
"""
|
240 |
+
def predict(pdb_code, pdb_file):
|
241 |
+
#path_to_pdb = get_pdb(pdb_code=pdb_code, filepath=pdb_file)
|
242 |
+
|
243 |
+
#pdb = open(path_to_pdb, "r").read()
|
244 |
+
# switch to misato env if not running from container
|
245 |
+
|
246 |
+
pdbid = get_pdbid_from_filename(pdb_file.name)
|
247 |
+
mdh5_file = "inference_for_md.hdf5"
|
248 |
+
mappath = "/maps"
|
249 |
+
mask = "!@H="
|
250 |
+
preprocess(pdbid=pdbid, ouputfile=mdh5_file, mask=mask, mappath=mappath)
|
251 |
+
|
252 |
+
md_H5File = h5py.File(mdh5_file)
|
253 |
+
|
254 |
+
column_names = ["x", "y", "z", "element"]
|
255 |
+
atoms_protein = pd.DataFrame(columns = column_names)
|
256 |
+
cutoff = md_H5File[pdbid]["molecules_begin_atom_index"][:][-1] # cutoff defines protein atoms
|
257 |
+
|
258 |
+
atoms_protein["x"] = md_H5File[pdbid]["atoms_coordinates_ref"][:][:cutoff, 0]
|
259 |
+
atoms_protein["y"] = md_H5File[pdbid]["atoms_coordinates_ref"][:][:cutoff, 1]
|
260 |
+
atoms_protein["z"] = md_H5File[pdbid]["atoms_coordinates_ref"][:][:cutoff, 2]
|
261 |
+
|
262 |
+
atoms_protein["element"] = md_H5File[pdbid]["atoms_element"][:][:cutoff]
|
263 |
+
|
264 |
+
item = {}
|
265 |
+
item["scores"] = 0
|
266 |
+
item["id"] = pdbid
|
267 |
+
item["atoms_protein"] = atoms_protein
|
268 |
+
|
269 |
+
transform = GNNTransformMD()
|
270 |
+
data_item = transform(item)
|
271 |
+
adaptability = model(data_item)
|
272 |
+
adaptability = adaptability.detach().numpy()
|
273 |
+
|
274 |
+
data = []
|
275 |
+
|
276 |
+
|
277 |
for i in range(adaptability.shape[0]):
|
278 |
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]])
|
279 |
|
|
|
303 |
|
304 |
|
305 |
callback = gr.CSVLogger()
|
306 |
+
"""
|
307 |
|
308 |
def run():
|
309 |
with gr.Blocks() as demo:
|
|
|
331 |
|
332 |
|
333 |
if __name__ == "__main__":
|
334 |
+
run()
|