ThorbenFroehlking commited on
Commit
06bab06
·
1 Parent(s): c5bfc38
.ipynb_checkpoints/app-checkpoint.py CHANGED
@@ -7,8 +7,7 @@ from Bio.SeqUtils import seq1
7
  from typing import Optional, Tuple
8
  import numpy as np
9
  import os
10
- # Remove the gradio_molecule3d import as it may be incompatible
11
- # from gradio_molecule3d import Molecule3D
12
 
13
  from model_loader import load_model
14
 
@@ -412,7 +411,19 @@ def molecule(input_pdb, residue_scores=None, segment='A'):
412
  return f'<iframe width="100%" height="700" srcdoc="{html_content.replace(chr(34), "&quot;").replace(chr(39), "&#39;")}"></iframe>'
413
 
414
  # Gradio UI
415
- with gr.Blocks() as demo:
 
 
 
 
 
 
 
 
 
 
 
 
416
  gr.Markdown("# Protein Binding Site Prediction")
417
 
418
  # Mode selection
@@ -426,15 +437,23 @@ with gr.Blocks() as demo:
426
  # Input components based on mode
427
  pdb_input = gr.Textbox(value="2F6V", label="PDB ID", placeholder="Enter PDB ID here...")
428
  pdb_file = gr.File(label="Upload PDB/CIF File", visible=False)
429
- visualize_btn = gr.Button("Visualize Structure")
430
-
431
- # Replace Molecule3D with HTML component
432
- molecule_output2 = gr.HTML(label="Protein Structure")
 
 
 
 
 
 
 
 
433
 
434
  with gr.Row():
435
  segment_input = gr.Textbox(value="A", label="Chain ID (protein)", placeholder="Enter Chain ID here...",
436
  info="Choose in which chain to predict binding sites.")
437
- prediction_btn = gr.Button("Predict Binding Site")
438
 
439
  molecule_output = gr.HTML(label="Protein Structure")
440
  explanation_vis = gr.Markdown("""
@@ -453,50 +472,29 @@ with gr.Blocks() as demo:
453
  if mode == "PDB ID":
454
  return process_pdb(pdb_id, chain_id)
455
  elif mode == "Upload File":
456
- try:
457
- # Handle new Gradio file format
458
- file_path = pdb_file.name
459
- except AttributeError:
460
- # For older Gradio versions that provided a tuple
461
- if isinstance(pdb_file, tuple):
462
- file_path = pdb_file[0]
463
- else:
464
- file_path = pdb_file
465
-
466
- _, ext = os.path.splitext(file_path)
467
  if ext == '.cif':
468
  pdb_path = convert_cif_to_pdb(file_path)
469
  else:
470
- pdb_path = file_path
471
  return process_pdb(pdb_path, chain_id)
472
  else:
473
  return "Error: Invalid mode selected", None, None
474
 
475
  def fetch_interface(mode, pdb_id, pdb_file):
476
  if mode == "PDB ID":
477
- pdb_path = fetch_pdb(pdb_id)
478
- if pdb_path:
479
- mol_html = molecule(pdb_path)
480
- return mol_html
481
- return "Failed to fetch PDB"
482
  elif mode == "Upload File":
483
- try:
484
- # Handle new Gradio file format
485
- file_path = pdb_file.name
486
- except AttributeError:
487
- # For older Gradio versions that provided a tuple
488
- if isinstance(pdb_file, tuple):
489
- file_path = pdb_file[0]
490
- else:
491
- file_path = pdb_file
492
-
493
- _, ext = os.path.splitext(file_path)
494
  if ext == '.cif':
495
  pdb_path = convert_cif_to_pdb(file_path)
496
  else:
497
- pdb_path = file_path
498
- mol_html = molecule(pdb_path)
499
- return mol_html
500
  else:
501
  return "Error: Invalid mode selected"
502
 
@@ -535,4 +533,5 @@ with gr.Blocks() as demo:
535
  outputs=[predictions_output, molecule_output, download_output]
536
  )
537
 
538
- demo.launch()
 
 
7
  from typing import Optional, Tuple
8
  import numpy as np
9
  import os
10
+ from gradio_molecule3d import Molecule3D
 
11
 
12
  from model_loader import load_model
13
 
 
411
  return f'<iframe width="100%" height="700" srcdoc="{html_content.replace(chr(34), "&quot;").replace(chr(39), "&#39;")}"></iframe>'
412
 
413
  # Gradio UI
414
+ with gr.Blocks(css="""
415
+ /* Customize Gradio button colors */
416
+ #visualize-btn, #predict-btn {
417
+ background-color: #FF7300; /* Deep orange */
418
+ color: white;
419
+ border-radius: 5px;
420
+ padding: 10px;
421
+ font-weight: bold;
422
+ }
423
+ #visualize-btn:hover, #predict-btn:hover {
424
+ background-color: #CC5C00; /* Darkened orange on hover */
425
+ }
426
+ """) as demo:
427
  gr.Markdown("# Protein Binding Site Prediction")
428
 
429
  # Mode selection
 
437
  # Input components based on mode
438
  pdb_input = gr.Textbox(value="2F6V", label="PDB ID", placeholder="Enter PDB ID here...")
439
  pdb_file = gr.File(label="Upload PDB/CIF File", visible=False)
440
+ visualize_btn = gr.Button("Visualize Structure", elem_id="visualize-btn")
441
+
442
+ molecule_output2 = Molecule3D(label="Protein Structure", reps=[
443
+ {
444
+ "model": 0,
445
+ "style": "cartoon",
446
+ "color": "whiteCarbon",
447
+ "residue_range": "",
448
+ "around": 0,
449
+ "byres": False,
450
+ }
451
+ ])
452
 
453
  with gr.Row():
454
  segment_input = gr.Textbox(value="A", label="Chain ID (protein)", placeholder="Enter Chain ID here...",
455
  info="Choose in which chain to predict binding sites.")
456
+ prediction_btn = gr.Button("Predict Binding Site", elem_id="predict-btn")
457
 
458
  molecule_output = gr.HTML(label="Protein Structure")
459
  explanation_vis = gr.Markdown("""
 
472
  if mode == "PDB ID":
473
  return process_pdb(pdb_id, chain_id)
474
  elif mode == "Upload File":
475
+ _, ext = os.path.splitext(pdb_file.name)
476
+ file_path = os.path.join('./', f"{_}{ext}")
 
 
 
 
 
 
 
 
 
477
  if ext == '.cif':
478
  pdb_path = convert_cif_to_pdb(file_path)
479
  else:
480
+ pdb_path= file_path
481
  return process_pdb(pdb_path, chain_id)
482
  else:
483
  return "Error: Invalid mode selected", None, None
484
 
485
  def fetch_interface(mode, pdb_id, pdb_file):
486
  if mode == "PDB ID":
487
+ return fetch_pdb(pdb_id)
 
 
 
 
488
  elif mode == "Upload File":
489
+ _, ext = os.path.splitext(pdb_file.name)
490
+ file_path = os.path.join('./', f"{_}{ext}")
491
+ #print(ext)
 
 
 
 
 
 
 
 
492
  if ext == '.cif':
493
  pdb_path = convert_cif_to_pdb(file_path)
494
  else:
495
+ pdb_path= file_path
496
+ #print(pdb_path)
497
+ return pdb_path
498
  else:
499
  return "Error: Invalid mode selected"
500
 
 
533
  outputs=[predictions_output, molecule_output, download_output]
534
  )
535
 
536
+ #demo.launch(share=True)
537
+ demo.launch()
.ipynb_checkpoints/requirements-checkpoint.txt CHANGED
@@ -9,4 +9,5 @@ scikit-learn>=0.24.0
9
  sentencepiece
10
  huggingface_hub>=0.15.0
11
  requests
 
12
  biopython>=1.81
 
9
  sentencepiece
10
  huggingface_hub>=0.15.0
11
  requests
12
+ gradio_molecule3d
13
  biopython>=1.81
app.py CHANGED
@@ -7,8 +7,7 @@ from Bio.SeqUtils import seq1
7
  from typing import Optional, Tuple
8
  import numpy as np
9
  import os
10
- # Remove the gradio_molecule3d import as it may be incompatible
11
- # from gradio_molecule3d import Molecule3D
12
 
13
  from model_loader import load_model
14
 
@@ -412,7 +411,19 @@ def molecule(input_pdb, residue_scores=None, segment='A'):
412
  return f'<iframe width="100%" height="700" srcdoc="{html_content.replace(chr(34), "&quot;").replace(chr(39), "&#39;")}"></iframe>'
413
 
414
  # Gradio UI
415
- with gr.Blocks() as demo:
 
 
 
 
 
 
 
 
 
 
 
 
416
  gr.Markdown("# Protein Binding Site Prediction")
417
 
418
  # Mode selection
@@ -426,15 +437,23 @@ with gr.Blocks() as demo:
426
  # Input components based on mode
427
  pdb_input = gr.Textbox(value="2F6V", label="PDB ID", placeholder="Enter PDB ID here...")
428
  pdb_file = gr.File(label="Upload PDB/CIF File", visible=False)
429
- visualize_btn = gr.Button("Visualize Structure")
430
-
431
- # Replace Molecule3D with HTML component
432
- molecule_output2 = gr.HTML(label="Protein Structure")
 
 
 
 
 
 
 
 
433
 
434
  with gr.Row():
435
  segment_input = gr.Textbox(value="A", label="Chain ID (protein)", placeholder="Enter Chain ID here...",
436
  info="Choose in which chain to predict binding sites.")
437
- prediction_btn = gr.Button("Predict Binding Site")
438
 
439
  molecule_output = gr.HTML(label="Protein Structure")
440
  explanation_vis = gr.Markdown("""
@@ -453,50 +472,29 @@ with gr.Blocks() as demo:
453
  if mode == "PDB ID":
454
  return process_pdb(pdb_id, chain_id)
455
  elif mode == "Upload File":
456
- try:
457
- # Handle new Gradio file format
458
- file_path = pdb_file.name
459
- except AttributeError:
460
- # For older Gradio versions that provided a tuple
461
- if isinstance(pdb_file, tuple):
462
- file_path = pdb_file[0]
463
- else:
464
- file_path = pdb_file
465
-
466
- _, ext = os.path.splitext(file_path)
467
  if ext == '.cif':
468
  pdb_path = convert_cif_to_pdb(file_path)
469
  else:
470
- pdb_path = file_path
471
  return process_pdb(pdb_path, chain_id)
472
  else:
473
  return "Error: Invalid mode selected", None, None
474
 
475
  def fetch_interface(mode, pdb_id, pdb_file):
476
  if mode == "PDB ID":
477
- pdb_path = fetch_pdb(pdb_id)
478
- if pdb_path:
479
- mol_html = molecule(pdb_path)
480
- return mol_html
481
- return "Failed to fetch PDB"
482
  elif mode == "Upload File":
483
- try:
484
- # Handle new Gradio file format
485
- file_path = pdb_file.name
486
- except AttributeError:
487
- # For older Gradio versions that provided a tuple
488
- if isinstance(pdb_file, tuple):
489
- file_path = pdb_file[0]
490
- else:
491
- file_path = pdb_file
492
-
493
- _, ext = os.path.splitext(file_path)
494
  if ext == '.cif':
495
  pdb_path = convert_cif_to_pdb(file_path)
496
  else:
497
- pdb_path = file_path
498
- mol_html = molecule(pdb_path)
499
- return mol_html
500
  else:
501
  return "Error: Invalid mode selected"
502
 
@@ -535,4 +533,5 @@ with gr.Blocks() as demo:
535
  outputs=[predictions_output, molecule_output, download_output]
536
  )
537
 
538
- demo.launch()
 
 
7
  from typing import Optional, Tuple
8
  import numpy as np
9
  import os
10
+ from gradio_molecule3d import Molecule3D
 
11
 
12
  from model_loader import load_model
13
 
 
411
  return f'<iframe width="100%" height="700" srcdoc="{html_content.replace(chr(34), "&quot;").replace(chr(39), "&#39;")}"></iframe>'
412
 
413
  # Gradio UI
414
+ with gr.Blocks(css="""
415
+ /* Customize Gradio button colors */
416
+ #visualize-btn, #predict-btn {
417
+ background-color: #FF7300; /* Deep orange */
418
+ color: white;
419
+ border-radius: 5px;
420
+ padding: 10px;
421
+ font-weight: bold;
422
+ }
423
+ #visualize-btn:hover, #predict-btn:hover {
424
+ background-color: #CC5C00; /* Darkened orange on hover */
425
+ }
426
+ """) as demo:
427
  gr.Markdown("# Protein Binding Site Prediction")
428
 
429
  # Mode selection
 
437
  # Input components based on mode
438
  pdb_input = gr.Textbox(value="2F6V", label="PDB ID", placeholder="Enter PDB ID here...")
439
  pdb_file = gr.File(label="Upload PDB/CIF File", visible=False)
440
+ visualize_btn = gr.Button("Visualize Structure", elem_id="visualize-btn")
441
+
442
+ molecule_output2 = Molecule3D(label="Protein Structure", reps=[
443
+ {
444
+ "model": 0,
445
+ "style": "cartoon",
446
+ "color": "whiteCarbon",
447
+ "residue_range": "",
448
+ "around": 0,
449
+ "byres": False,
450
+ }
451
+ ])
452
 
453
  with gr.Row():
454
  segment_input = gr.Textbox(value="A", label="Chain ID (protein)", placeholder="Enter Chain ID here...",
455
  info="Choose in which chain to predict binding sites.")
456
+ prediction_btn = gr.Button("Predict Binding Site", elem_id="predict-btn")
457
 
458
  molecule_output = gr.HTML(label="Protein Structure")
459
  explanation_vis = gr.Markdown("""
 
472
  if mode == "PDB ID":
473
  return process_pdb(pdb_id, chain_id)
474
  elif mode == "Upload File":
475
+ _, ext = os.path.splitext(pdb_file.name)
476
+ file_path = os.path.join('./', f"{_}{ext}")
 
 
 
 
 
 
 
 
 
477
  if ext == '.cif':
478
  pdb_path = convert_cif_to_pdb(file_path)
479
  else:
480
+ pdb_path= file_path
481
  return process_pdb(pdb_path, chain_id)
482
  else:
483
  return "Error: Invalid mode selected", None, None
484
 
485
  def fetch_interface(mode, pdb_id, pdb_file):
486
  if mode == "PDB ID":
487
+ return fetch_pdb(pdb_id)
 
 
 
 
488
  elif mode == "Upload File":
489
+ _, ext = os.path.splitext(pdb_file.name)
490
+ file_path = os.path.join('./', f"{_}{ext}")
491
+ #print(ext)
 
 
 
 
 
 
 
 
492
  if ext == '.cif':
493
  pdb_path = convert_cif_to_pdb(file_path)
494
  else:
495
+ pdb_path= file_path
496
+ #print(pdb_path)
497
+ return pdb_path
498
  else:
499
  return "Error: Invalid mode selected"
500
 
 
533
  outputs=[predictions_output, molecule_output, download_output]
534
  )
535
 
536
+ #demo.launch(share=True)
537
+ demo.launch()
requirements.txt CHANGED
@@ -9,4 +9,5 @@ scikit-learn>=0.24.0
9
  sentencepiece
10
  huggingface_hub>=0.15.0
11
  requests
 
12
  biopython>=1.81
 
9
  sentencepiece
10
  huggingface_hub>=0.15.0
11
  requests
12
+ gradio_molecule3d
13
  biopython>=1.81