RajarshiMondal commited on
Commit
0107ce5
1 Parent(s): cd9cc79

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +10 -87
main.py CHANGED
@@ -143,42 +143,6 @@ def get_pdbid_from_filename(filename: str):
143
  # Assuming the filename would be of the standard form 11GS.pdb
144
  return filename.split(".")[0]
145
 
146
- def predict(pdb_code, pdb_file):
147
- #path_to_pdb = get_pdb(pdb_code=pdb_code, filepath=pdb_file)
148
-
149
- #pdb = open(path_to_pdb, "r").read()
150
- # switch to misato env if not running from container
151
-
152
- pdbid = get_pdbid_from_filename(pdb_file.name)
153
- mdh5_file = "inference_for_md.hdf5"
154
- mappath = "/maps"
155
- mask = "!@H="
156
- preprocess(pdbid=pdbid, ouputfile=mdh5_file, mask=mask, mappath=mappath)
157
-
158
- md_H5File = h5py.File(mdh5_file)
159
-
160
- column_names = ["x", "y", "z", "element"]
161
- atoms_protein = pd.DataFrame(columns = column_names)
162
- cutoff = md_H5File[pdbid]["molecules_begin_atom_index"][:][-1] # cutoff defines protein atoms
163
-
164
- atoms_protein["x"] = md_H5File[pdbid]["atoms_coordinates_ref"][:][:cutoff, 0]
165
- atoms_protein["y"] = md_H5File[pdbid]["atoms_coordinates_ref"][:][:cutoff, 1]
166
- atoms_protein["z"] = md_H5File[pdbid]["atoms_coordinates_ref"][:][:cutoff, 2]
167
-
168
- atoms_protein["element"] = md_H5File[pdbid]["atoms_element"][:][:cutoff]
169
-
170
- item = {}
171
- item["scores"] = 0
172
- item["id"] = pdbid
173
- item["atoms_protein"] = atoms_protein
174
-
175
- transform = GNNTransformMD()
176
- data_item = transform(item)
177
- adaptability = model(data_item)
178
- adaptability = adaptability.detach().numpy()
179
-
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")],
@@ -189,54 +153,7 @@ def predict(pdb_code, pdb_file):
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
 
@@ -273,12 +190,18 @@ def predict(pdb_code, pdb_file):
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
 
280
- topN = 100
281
- topN_ind = np.argsort(adaptability)[::-1][:topN]
282
 
283
  pdb = open(pdb_file.name, "r").read()
284
 
@@ -303,7 +226,7 @@ def predict(pdb_code, pdb_file):
303
 
304
 
305
  callback = gr.CSVLogger()
306
- """
307
 
308
  def run():
309
  with gr.Blocks() as demo:
 
143
  # Assuming the filename would be of the standard form 11GS.pdb
144
  return filename.split(".")[0]
145
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
 
147
  for i in range(10):
148
  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")],
 
153
 
154
  pdb = open(pdb_file.name, "r").read()
155
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
 
 
157
  def predict(pdb_code, pdb_file):
158
  #path_to_pdb = get_pdb(pdb_code=pdb_code, filepath=pdb_file)
159
 
 
190
 
191
  data = []
192
 
193
+ for i in range(10):
194
+ 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")],
195
+ atoms_protein.iloc[topN_ind[i], atoms_protein.columns.get_loc("y")],
196
+ atoms_protein.iloc[topN_ind[i], atoms_protein.columns.get_loc("z")],
197
+ adaptability[topN_ind[i]]
198
+ ])
199
+
200
  for i in range(adaptability.shape[0]):
201
  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]])
202
 
203
+ #topN = 100
204
+ #topN_ind = np.argsort(adaptability)[::-1][:topN]
205
 
206
  pdb = open(pdb_file.name, "r").read()
207
 
 
226
 
227
 
228
  callback = gr.CSVLogger()
229
+
230
 
231
  def run():
232
  with gr.Blocks() as demo: