simonduerr commited on
Commit
ce3871f
·
verified ·
1 Parent(s): fb83fd2

Update inference_app.py

Browse files
Files changed (1) hide show
  1. inference_app.py +16 -79
inference_app.py CHANGED
@@ -21,86 +21,10 @@ from plinder.eval.docking.write_scores import evaluate
21
 
22
  EVAL_METRICS = ["system", "LDDT-PLI", "LDDT-LP", "BISY-RMSD"]
23
 
 
 
24
 
25
- def vina(
26
- ligand, receptor, pocket_center, output_folder: Path, size=10, max_num_poses=5
27
- ):
28
- app = VinaApp(
29
- ligand,
30
- receptor,
31
- center=pocket_center,
32
- size=[size, size, size],
33
- )
34
- app.set_max_number_of_models(max_num_poses)
35
- app.start()
36
- app.join()
37
- docked_ligand = from_template(ligand, app.get_ligand_coord())
38
- docked_ligand = docked_ligand[..., ~np.isnan(docked_ligand.coord[0]).any(axis=-1)]
39
- output_files = []
40
- for i in range(max_num_poses):
41
- sdf_file = MOLFile()
42
- sdf_file.set_structure(docked_ligand[i])
43
- output_file = output_folder / f"docked_ligand_{i}.sdf"
44
- sdf_file.write(output_file)
45
- output_files.append(output_file)
46
- return output_files
47
-
48
-
49
- def predict(
50
- input_sequence: str,
51
- input_ligand: str,
52
- input_msa: gr.File | None = None,
53
- input_protein: gr.File | None = None,
54
- max_num_poses: int = 1,
55
- ):
56
- """
57
- Main prediction function that calls ligsite and smina
58
- Parameters
59
- ----------
60
- input_sequence: str
61
- monomer sequence
62
- input_ligand: str
63
- ligand as SMILES string
64
- input_msa: gradio.File | None
65
- Gradio file object to MSA a3m file
66
- input_protein: gradio.File | None
67
- Gradio file object to monomer protein structure as CIF file
68
- max_num_poses: int
69
- Number of poses to generate
70
- Returns
71
- -------
72
- output_structures: tuple
73
- (output_protein, output_ligand_sdf)
74
- run_time: float
75
- run time of the program
76
- """
77
- start_time = time.time()
78
 
79
- if input_protein is None:
80
- raise gr.Error("need input_protein")
81
- print(input_protein)
82
- ligand_file = Path(input_protein).parent / "ligand.sdf"
83
- print(ligand_file)
84
- conformer = Chem.AddHs(Chem.MolFromSmiles(input_ligand))
85
- AllChem.EmbedMolecule(conformer)
86
- AllChem.MMFFOptimizeMolecule(conformer)
87
- Chem.SDWriter(ligand_file).write(conformer)
88
- ligand = SDFile.read(ligand_file).record.get_structure()
89
- receptor = load_structure(input_protein, include_bonds=True)
90
- docking_poses = vina(
91
- ligand,
92
- receptor,
93
- centroid(receptor),
94
- Path(input_protein).parent,
95
- max_num_poses=max_num_poses,
96
- )
97
- end_time = time.time()
98
- run_time = end_time - start_time
99
- pdb_file = PDBFile()
100
- pdb_file.set_structure(receptor)
101
- output_pdb = Path(input_protein).parent / "receptor.pdb"
102
- pdb_file.write(output_pdb)
103
- return [str(output_pdb), str(docking_poses[0])], run_time
104
 
105
 
106
  def get_metrics(
@@ -109,6 +33,8 @@ def get_metrics(
109
  ligand_file: Path,
110
  flexible: bool = True,
111
  posebusters: bool = True,
 
 
112
  ) -> tuple[pd.DataFrame, float]:
113
  start_time = time.time()
114
  metrics = pd.DataFrame(
@@ -159,9 +85,20 @@ def get_metrics(
159
  return metrics, run_time
160
 
161
 
 
 
 
 
 
 
 
 
 
 
 
162
  with gr.Blocks() as app:
163
  with gr.Tab("🧬 PINDER evaluation template"):
164
- with gr.Row():
165
  with gr.Column():
166
  input_system_id_pinder = gr.Textbox(label="PINDER system ID")
167
  input_receptor_file_pinder = gr.File(label="Receptor file")
 
21
 
22
  EVAL_METRICS = ["system", "LDDT-PLI", "LDDT-LP", "BISY-RMSD"]
23
 
24
+ EVAL_METRICS_PINDER = ["system","L_rms", "I_rms", "F_nat", "DOCKQ", "CAPRI_class"]
25
+
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
 
30
  def get_metrics(
 
33
  ligand_file: Path,
34
  flexible: bool = True,
35
  posebusters: bool = True,
36
+ methodname: str,
37
+ store:bool =True
38
  ) -> tuple[pd.DataFrame, float]:
39
  start_time = time.time()
40
  metrics = pd.DataFrame(
 
85
  return metrics, run_time
86
 
87
 
88
+ def get_metrics_pinder(
89
+ system_id: str,
90
+ receptor_file: Path,
91
+ ligand_file: Path,
92
+ flexible: bool = True,
93
+ posebusters: bool = True,
94
+ methodname: str,
95
+ store:bool =True
96
+ ) -> tuple[pd.DataFrame, float]:
97
+ return pd.DataFrame(), 0
98
+
99
  with gr.Blocks() as app:
100
  with gr.Tab("🧬 PINDER evaluation template"):
101
+ with gr.Row():
102
  with gr.Column():
103
  input_system_id_pinder = gr.Textbox(label="PINDER system ID")
104
  input_receptor_file_pinder = gr.File(label="Receptor file")