OleinikovasV commited on
Commit
d5d6c6c
·
verified ·
1 Parent(s): 3f86c33

Update inference_app.py

Browse files
Files changed (1) hide show
  1. inference_app.py +24 -25
inference_app.py CHANGED
@@ -10,6 +10,7 @@ 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
 
13
 
14
 
15
  def generate_input_conformer(
@@ -61,50 +62,48 @@ def set_protein_to_new_coord(input_pdb_file, new_coord, output_file):
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, 8)
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_sum = optimize_coordinate(mol_coords)
99
- # get mindist to protein
100
- min_dist = np.min(np.linalg.norm(mol_coords - new_coord, axis=1))
101
-
102
  output_file = "test_out.pdb"
103
  set_protein_to_new_coord(input_protein, new_coord, output_file)
104
 
105
  # return an output pdb file with the protein and ligand with resname LIG or UNK.
106
  # also return any metrics you want to log, metrics will not be used for evaluation but might be useful for users
107
- metrics = {"min_dist": min_dist, "min_dist_sum": min_dist_sum}
108
 
109
  end_time = time.time()
110
  run_time = end_time - start_time
 
10
  from biotite.structure.io.pdb import PDBFile
11
  from rdkit import Chem
12
  from rdkit.Chem import AllChem
13
+ from rdkit.Geometry import Point3D
14
 
15
 
16
  def generate_input_conformer(
 
62
  file.write(output_file)
63
 
64
 
65
+ # def optimize_coordinate(points, bound_buffer=15, dmin=6.05):
66
 
67
+ # bounds = list(
68
+ # zip(
69
+ # np.average(points, axis=0) - [bound_buffer]*3,
70
+ # np.average(points, axis=0) + [bound_buffer]*3
71
+ # )
72
+ # )
73
 
74
+ # # Define the constraint function (ensure dmin distance)
75
+ # con = NonlinearConstraint(lambda x: np.min(np.linalg.norm(points - x, axis=1)), dmin, 8)
76
 
77
+ # # Define the objective function (minimize pairwise distance)
78
+ # def objective(x):
79
+ # return np.sum(np.linalg.norm(points - x, axis=1))
80
 
81
+ # # Perform differential evolution to find the optimal coordinate
82
+ # result = differential_evolution(objective, bounds, constraints=con)
83
 
84
+ # return result.x, result.fun
85
 
86
 
87
  def predict(input_sequence, input_ligand, input_msa, input_protein):
88
  start_time = time.time()
89
 
90
  # Do inference here
91
+ mol = generate_input_conformer(input_ligand)
92
+ conf = mol.GetConformer()
93
+ # set ligand
94
+ for i in range(mol.GetNumAtoms()):
95
+ conf.SetAtomPosition(i, Point3D(0,0,0))
96
  molwriter = Chem.SDWriter("test_docking_pose.sdf")
97
  molwriter.write(mol)
98
 
99
+ # set protein
100
+ new_coord = [6.05, 0, 0]
 
 
 
 
 
101
  output_file = "test_out.pdb"
102
  set_protein_to_new_coord(input_protein, new_coord, output_file)
103
 
104
  # return an output pdb file with the protein and ligand with resname LIG or UNK.
105
  # also return any metrics you want to log, metrics will not be used for evaluation but might be useful for users
106
+ metrics = {}
107
 
108
  end_time = time.time()
109
  run_time = end_time - start_time