Zaixi commited on
Commit
627f393
1 Parent(s): 6231ed5

Update motif_sample.py

Browse files
Files changed (1) hide show
  1. motif_sample.py +0 -93
motif_sample.py CHANGED
@@ -5,7 +5,6 @@ import random
5
  import torch
6
  import numpy as np
7
  import math
8
- from vina import Vina
9
  from openbabel import pybel
10
  import subprocess
11
  import multiprocessing as mp
@@ -21,7 +20,6 @@ from rdkit import RDConfig
21
  from rdkit.Chem.Descriptors import MolLogP, qed
22
  from copy import deepcopy
23
  import tempfile
24
- import AutoDockTools
25
  import contextlib
26
  from torch_scatter import scatter_add, scatter_mean
27
  from rdkit.Geometry import Point3D
@@ -57,97 +55,6 @@ def supress_stdout(func):
57
  return wrapper
58
 
59
 
60
- class PrepLig(object):
61
- def __init__(self, input_mol, mol_format):
62
- if mol_format == 'smi':
63
- self.ob_mol = pybel.readstring('smi', input_mol)
64
- elif mol_format == 'sdf':
65
- self.ob_mol = next(pybel.readfile(mol_format, input_mol))
66
- else:
67
- raise ValueError(f'mol_format {mol_format} not supported')
68
-
69
- def addH(self, polaronly=False, correctforph=True, PH=7):
70
- self.ob_mol.OBMol.AddHydrogens(polaronly, correctforph, PH)
71
- obutils.writeMolecule(self.ob_mol.OBMol, 'tmp_h.sdf')
72
-
73
- def gen_conf(self):
74
- sdf_block = self.ob_mol.write('sdf')
75
- rdkit_mol = Chem.MolFromMolBlock(sdf_block, removeHs=False)
76
- AllChem.EmbedMolecule(rdkit_mol, Chem.rdDistGeom.ETKDGv3())
77
- self.ob_mol = pybel.readstring('sdf', Chem.MolToMolBlock(rdkit_mol))
78
- obutils.writeMolecule(self.ob_mol.OBMol, 'conf_h.sdf')
79
-
80
- @supress_stdout
81
- def get_pdbqt(self, lig_pdbqt=None):
82
- preparator = MoleculePreparation()
83
- preparator.prepare(self.ob_mol.OBMol)
84
- if lig_pdbqt is not None:
85
- preparator.write_pdbqt_file(lig_pdbqt)
86
- return
87
- else:
88
- return preparator.write_pdbqt_string()
89
-
90
-
91
- class PrepProt(object):
92
- def __init__(self, pdb_file):
93
- self.prot = pdb_file
94
-
95
- def del_water(self, dry_pdb_file): # optional
96
- with open(self.prot) as f:
97
- lines = [l for l in f.readlines() if l.startswith('ATOM') or l.startswith('HETATM')]
98
- dry_lines = [l for l in lines if not 'HOH' in l]
99
-
100
- with open(dry_pdb_file, 'w') as f:
101
- f.write(''.join(dry_lines))
102
- self.prot = dry_pdb_file
103
-
104
- def addH(self, prot_pqr): # call pdb2pqr
105
- self.prot_pqr = prot_pqr
106
- subprocess.Popen(['pdb2pqr30', '--ff=AMBER', self.prot, self.prot_pqr],
107
- stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL).communicate()
108
-
109
- def get_pdbqt(self, prot_pdbqt):
110
- prepare_receptor = os.path.join(AutoDockTools.__path__[0], 'Utilities24/prepare_receptor4.py')
111
- subprocess.Popen(['python3', prepare_receptor, '-r', self.prot_pqr, '-o', prot_pdbqt],
112
- stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL).communicate()
113
-
114
-
115
- def calculate_vina(number, pro_path, lig_path):
116
- lig_path = os.path.join(lig_path, str(number)+'.sdf')
117
- size_factor = 1.2
118
- buffer = 5.
119
- # openmm_relax(pro_path)
120
- # relax_sdf(lig_path)
121
- mol = Chem.MolFromMolFile(lig_path, sanitize=True)
122
- pos = mol.GetConformer(0).GetPositions()
123
- center = np.mean(pos, 0)
124
- ligand_pdbqt = './data/tmp/' + str(number) + '_lig.pdbqt'
125
- protein_pqr = './data/tmp/' + str(number) + '_pro.pqr'
126
- protein_pdbqt = './data/tmp/' + str(number) + '_pro.pdbqt'
127
- lig = PrepLig(lig_path, 'sdf')
128
- lig.addH()
129
- lig.get_pdbqt(ligand_pdbqt)
130
-
131
- prot = PrepProt(pro_path)
132
- prot.addH(protein_pqr)
133
- prot.get_pdbqt(protein_pdbqt)
134
-
135
- v = Vina(sf_name='vina', seed=0, verbosity=0)
136
- v.set_receptor(protein_pdbqt)
137
- v.set_ligand_from_file(ligand_pdbqt)
138
- x, y, z = (pos.max(0) - pos.min(0)) * size_factor + buffer
139
- v.compute_vina_maps(center=center, box_size=[x, y, z])
140
- energy = v.score()
141
- print('Score before minimization: %.3f (kcal/mol)' % energy[0])
142
- energy_minimized = v.optimize()
143
- print('Score after minimization : %.3f (kcal/mol)' % energy_minimized[0])
144
- v.dock(exhaustiveness=64, n_poses=32)
145
- score = v.energies(n_poses=1)[0][0]
146
- print('Score after docking : %.3f (kcal/mol)' % score)
147
-
148
- return score
149
-
150
-
151
  def get_feat(mol):
152
  fdefName = os.path.join(RDConfig.RDDataDir, 'BaseFeatures.fdef')
153
  factory = ChemicalFeatures.BuildFeatureFactory(fdefName)
 
5
  import torch
6
  import numpy as np
7
  import math
 
8
  from openbabel import pybel
9
  import subprocess
10
  import multiprocessing as mp
 
20
  from rdkit.Chem.Descriptors import MolLogP, qed
21
  from copy import deepcopy
22
  import tempfile
 
23
  import contextlib
24
  from torch_scatter import scatter_add, scatter_mean
25
  from rdkit.Geometry import Point3D
 
55
  return wrapper
56
 
57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  def get_feat(mol):
59
  fdefName = os.path.join(RDConfig.RDDataDir, 'BaseFeatures.fdef')
60
  factory = ChemicalFeatures.BuildFeatureFactory(fdefName)