Spaces:
Sleeping
Sleeping
Update inference_app.py
Browse files- inference_app.py +28 -3
inference_app.py
CHANGED
@@ -6,6 +6,7 @@ import gradio as gr
|
|
6 |
from gradio_molecule3d import Molecule3D
|
7 |
|
8 |
import numpy as np
|
|
|
9 |
from biotite.structure.io.pdb import PDBFile
|
10 |
from rdkit import Chem
|
11 |
from rdkit.Chem import AllChem
|
@@ -60,24 +61,48 @@ def set_protein_to_new_coord(input_pdb_file, new_coord, output_file):
|
|
60 |
file.write(output_file)
|
61 |
|
62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
def predict(input_sequence, input_ligand, input_msa, input_protein):
|
64 |
start_time = time.time()
|
65 |
|
66 |
# Do inference here
|
67 |
-
mol = generate_input_conformer(input_ligand, minimize_maxIters=
|
68 |
|
69 |
molwriter = Chem.SDWriter("test_docking_pose.sdf")
|
70 |
molwriter.write(mol)
|
71 |
|
72 |
mol_coords = mol.GetConformer().GetPositions()
|
73 |
# new_coord = [0, 0, 0]
|
74 |
-
new_coord = np.mean(mol_coords, axis=0) + [3.5, 3.5, 3.5]
|
|
|
|
|
75 |
output_file = "test_out.pdb"
|
76 |
set_protein_to_new_coord(input_protein, new_coord, output_file)
|
77 |
|
78 |
# return an output pdb file with the protein and ligand with resname LIG or UNK.
|
79 |
# also return any metrics you want to log, metrics will not be used for evaluation but might be useful for users
|
80 |
-
|
81 |
metrics = {}
|
82 |
|
83 |
end_time = time.time()
|
|
|
6 |
from gradio_molecule3d import Molecule3D
|
7 |
|
8 |
import numpy as np
|
9 |
+
from scipy.optimize import differential_evolution, NonlinearConstraint
|
10 |
from biotite.structure.io.pdb import PDBFile
|
11 |
from rdkit import Chem
|
12 |
from rdkit.Chem import AllChem
|
|
|
61 |
file.write(output_file)
|
62 |
|
63 |
|
64 |
+
def optimize_coordinate(points, bound_buffer=15, dmin=6.05):
|
65 |
+
|
66 |
+
bounds = list(
|
67 |
+
zip(
|
68 |
+
np.average(points, axis=0) - [bound_buffer]*3,
|
69 |
+
np.average(points, axis=0) + [bound_buffer]*3
|
70 |
+
)
|
71 |
+
)
|
72 |
+
|
73 |
+
# Define the constraint function (ensure dmin distance)
|
74 |
+
con = NonlinearConstraint(lambda x: np.min(np.linalg.norm(points - x, axis=1)), dmin, 10)
|
75 |
+
|
76 |
+
# Define the objective function (minimize pairwise distance)
|
77 |
+
def objective(x):
|
78 |
+
return np.sum(np.linalg.norm(points - x, axis=1))
|
79 |
+
|
80 |
+
# Perform differential evolution to find the optimal coordinate
|
81 |
+
result = differential_evolution(objective, bounds, constraints=con)
|
82 |
+
|
83 |
+
return result.x, result.fun
|
84 |
+
|
85 |
+
|
86 |
def predict(input_sequence, input_ligand, input_msa, input_protein):
|
87 |
start_time = time.time()
|
88 |
|
89 |
# Do inference here
|
90 |
+
mol = generate_input_conformer(input_ligand, minimize_maxIters=500)
|
91 |
|
92 |
molwriter = Chem.SDWriter("test_docking_pose.sdf")
|
93 |
molwriter.write(mol)
|
94 |
|
95 |
mol_coords = mol.GetConformer().GetPositions()
|
96 |
# new_coord = [0, 0, 0]
|
97 |
+
# new_coord = np.mean(mol_coords, axis=0) + [3.5, 3.5, 3.5]
|
98 |
+
new_coord, min_dist = optimize_coordinate(mol_coords)
|
99 |
+
|
100 |
output_file = "test_out.pdb"
|
101 |
set_protein_to_new_coord(input_protein, new_coord, output_file)
|
102 |
|
103 |
# return an output pdb file with the protein and ligand with resname LIG or UNK.
|
104 |
# also return any metrics you want to log, metrics will not be used for evaluation but might be useful for users
|
105 |
+
metrics = {"min_dist": min_dist}
|
106 |
metrics = {}
|
107 |
|
108 |
end_time = time.time()
|