ThorbenF commited on
Commit
1705a41
·
1 Parent(s): c5491c0
Files changed (2) hide show
  1. .ipynb_checkpoints/app-checkpoint.py +24 -36
  2. app.py +24 -36
.ipynb_checkpoints/app-checkpoint.py CHANGED
@@ -42,6 +42,20 @@ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
42
  model.to(device)
43
  model.eval()
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  def is_valid_sequence_length(length: int) -> bool:
46
  """Check if sequence length is within valid range."""
47
  return 100 <= length <= 1500
@@ -215,7 +229,6 @@ def fetch_pdb(pdb_id):
215
  print(f"Error fetching PDB: {e}")
216
  return None
217
 
218
-
219
  def score_to_color(score):
220
  norm = Normalize(vmin=0, vmax=1) # Normalize scores between 0 and 1
221
  color_map = cm.coolwarm # Directly use the colormap (e.g., 'cividis', 'coolwarm', etc.)
@@ -243,40 +256,9 @@ def process_pdb(pdb_id):
243
  # Prepare result string
244
  result_str = "\n".join([f"{aa}: {score:.2f}" for aa, score in zip(sequence, normalized_scores)])
245
 
246
- # Prepare representations for Molecule3D
247
- reps = [
248
- {
249
- "model": 0,
250
- "chain": "",
251
- "resname": "",
252
- "style": "cartoon",
253
- "color": "spectrum",
254
- "residue_range": "",
255
- "around": 0,
256
- "byres": False,
257
- "visible": True
258
- }
259
- ]
260
-
261
- # Add color-coded residues based on binding site scores
262
- #for i, score in enumerate(normalized_scores):
263
- # if score > 0.7: # You can adjust this threshold
264
- # reps.append({
265
- # "model": 0,
266
- # "chain": chain.get_id(),
267
- # "style": "stick",
268
- # "color": score_to_color(score),
269
- # "residue_range": f"{i+1}-{i+1}",
270
- # "byres": True,
271
- # "visible": True
272
- # })
273
-
274
- # Create Molecule3D with the PDB file and representations
275
- molecule_viewer = Molecule3D(
276
- reps=reps
277
- )
278
-
279
- return result_str, molecule_viewer
280
 
281
  # Create Gradio interface
282
  with gr.Blocks() as demo:
@@ -292,10 +274,16 @@ with gr.Blocks() as demo:
292
  predict_btn = gr.Button("Predict Binding Sites")
293
 
294
  with gr.Column():
 
295
  predictions_output = gr.Textbox(
296
  label="Binding Site Predictions"
297
  )
298
- molecule_output = Molecule3D(label="Protein Structure")
 
 
 
 
 
299
 
300
  # Prediction logic
301
  predict_btn.click(
 
42
  model.to(device)
43
  model.eval()
44
 
45
+ reps = [
46
+ {
47
+ "model": 0,
48
+ "chain": "",
49
+ "resname": "",
50
+ "style": "cartoon",
51
+ "color": "spectrum",
52
+ "residue_range": "",
53
+ "around": 0,
54
+ "byres": False,
55
+ "visible": True
56
+ }
57
+ ]
58
+
59
  def is_valid_sequence_length(length: int) -> bool:
60
  """Check if sequence length is within valid range."""
61
  return 100 <= length <= 1500
 
229
  print(f"Error fetching PDB: {e}")
230
  return None
231
 
 
232
  def score_to_color(score):
233
  norm = Normalize(vmin=0, vmax=1) # Normalize scores between 0 and 1
234
  color_map = cm.coolwarm # Directly use the colormap (e.g., 'cividis', 'coolwarm', etc.)
 
256
  # Prepare result string
257
  result_str = "\n".join([f"{aa}: {score:.2f}" for aa, score in zip(sequence, normalized_scores)])
258
 
259
+ pdb_path = fetch_pdb(pdb_id)
260
+
261
+ return result_str, pdb_path
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
262
 
263
  # Create Gradio interface
264
  with gr.Blocks() as demo:
 
274
  predict_btn = gr.Button("Predict Binding Sites")
275
 
276
  with gr.Column():
277
+ # Binding site predictions output
278
  predictions_output = gr.Textbox(
279
  label="Binding Site Predictions"
280
  )
281
+
282
+ # 3D Molecule visualization
283
+ molecule_output = Molecule3D(
284
+ label="Protein Structure",
285
+ reps=reps
286
+ )
287
 
288
  # Prediction logic
289
  predict_btn.click(
app.py CHANGED
@@ -42,6 +42,20 @@ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
42
  model.to(device)
43
  model.eval()
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  def is_valid_sequence_length(length: int) -> bool:
46
  """Check if sequence length is within valid range."""
47
  return 100 <= length <= 1500
@@ -215,7 +229,6 @@ def fetch_pdb(pdb_id):
215
  print(f"Error fetching PDB: {e}")
216
  return None
217
 
218
-
219
  def score_to_color(score):
220
  norm = Normalize(vmin=0, vmax=1) # Normalize scores between 0 and 1
221
  color_map = cm.coolwarm # Directly use the colormap (e.g., 'cividis', 'coolwarm', etc.)
@@ -243,40 +256,9 @@ def process_pdb(pdb_id):
243
  # Prepare result string
244
  result_str = "\n".join([f"{aa}: {score:.2f}" for aa, score in zip(sequence, normalized_scores)])
245
 
246
- # Prepare representations for Molecule3D
247
- reps = [
248
- {
249
- "model": 0,
250
- "chain": "",
251
- "resname": "",
252
- "style": "cartoon",
253
- "color": "spectrum",
254
- "residue_range": "",
255
- "around": 0,
256
- "byres": False,
257
- "visible": True
258
- }
259
- ]
260
-
261
- # Add color-coded residues based on binding site scores
262
- #for i, score in enumerate(normalized_scores):
263
- # if score > 0.7: # You can adjust this threshold
264
- # reps.append({
265
- # "model": 0,
266
- # "chain": chain.get_id(),
267
- # "style": "stick",
268
- # "color": score_to_color(score),
269
- # "residue_range": f"{i+1}-{i+1}",
270
- # "byres": True,
271
- # "visible": True
272
- # })
273
-
274
- # Create Molecule3D with the PDB file and representations
275
- molecule_viewer = Molecule3D(
276
- reps=reps
277
- )
278
-
279
- return result_str, molecule_viewer
280
 
281
  # Create Gradio interface
282
  with gr.Blocks() as demo:
@@ -292,10 +274,16 @@ with gr.Blocks() as demo:
292
  predict_btn = gr.Button("Predict Binding Sites")
293
 
294
  with gr.Column():
 
295
  predictions_output = gr.Textbox(
296
  label="Binding Site Predictions"
297
  )
298
- molecule_output = Molecule3D(label="Protein Structure")
 
 
 
 
 
299
 
300
  # Prediction logic
301
  predict_btn.click(
 
42
  model.to(device)
43
  model.eval()
44
 
45
+ reps = [
46
+ {
47
+ "model": 0,
48
+ "chain": "",
49
+ "resname": "",
50
+ "style": "cartoon",
51
+ "color": "spectrum",
52
+ "residue_range": "",
53
+ "around": 0,
54
+ "byres": False,
55
+ "visible": True
56
+ }
57
+ ]
58
+
59
  def is_valid_sequence_length(length: int) -> bool:
60
  """Check if sequence length is within valid range."""
61
  return 100 <= length <= 1500
 
229
  print(f"Error fetching PDB: {e}")
230
  return None
231
 
 
232
  def score_to_color(score):
233
  norm = Normalize(vmin=0, vmax=1) # Normalize scores between 0 and 1
234
  color_map = cm.coolwarm # Directly use the colormap (e.g., 'cividis', 'coolwarm', etc.)
 
256
  # Prepare result string
257
  result_str = "\n".join([f"{aa}: {score:.2f}" for aa, score in zip(sequence, normalized_scores)])
258
 
259
+ pdb_path = fetch_pdb(pdb_id)
260
+
261
+ return result_str, pdb_path
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
262
 
263
  # Create Gradio interface
264
  with gr.Blocks() as demo:
 
274
  predict_btn = gr.Button("Predict Binding Sites")
275
 
276
  with gr.Column():
277
+ # Binding site predictions output
278
  predictions_output = gr.Textbox(
279
  label="Binding Site Predictions"
280
  )
281
+
282
+ # 3D Molecule visualization
283
+ molecule_output = Molecule3D(
284
+ label="Protein Structure",
285
+ reps=reps
286
+ )
287
 
288
  # Prediction logic
289
  predict_btn.click(