def extract_docking_results(self, file_s, input_file_r, input_file_l): subprocess.check_output(license.wrap_command( "moebatch -exec \"db_ExportTriposMOL2 ['dock.mdb', 'lig.mol2', 'mol', []]\"", 'moe'), shell=True, executable='/bin/bash') if os.path.exists('lig.mol2'): ligname = reader.open(input_file_l).ligname mol2.update_mol2file('lig.mol2', 'lig-.mol2', ligname=ligname, multi=True) os.remove('lig.mol2') # get SDF to extract scores sdffile = 'lig.sdf' subprocess.check_output(license.wrap_command( "moebatch -exec \"db_ExportSD ['dock.mdb', '%s', ['mol','S'], []]\"" % sdffile, 'moe'), shell=True, executable='/bin/bash') with open(sdffile, 'r') as sdff: with open(file_s, 'w') as sf: for line in sdff: if line.startswith("> <S>"): print >> sf, sdff.next().strip() os.remove(sdffile) else: open(file_s, 'w').close()
def extract_docking_results(self, file_s, input_file_r, input_file_l): """Extract Glide docking results""" if os.path.exists('dock_pv.maegz'): # (1) cmd to extract results subprocess.check_output( 'glide_sort -r sort.rept dock_pv.maegz -o dock_sorted.mae', shell=True, executable='/bin/bash') # (2) convert to .mol2 subprocess.check_output( 'mol2convert -n 2: -imae dock_sorted.mae -omol2 dock_sorted.mol2', shell=True, executable='/bin/bash') if os.path.exists('dock_sorted.mol2'): ligname = reader.open(input_file_l).ligname mol2.update_mol2file('dock_sorted.mol2', 'lig-.mol2', ligname=ligname, multi=True) # extract scores with open('dock.rept', 'r') as ffin: with open(file_s, 'w') as ffout: line = ffin.next() while not line.startswith('===='): line = ffin.next() while True: line = ffin.next() if line.strip(): print >> ffout, line[43:51].strip() else: break
def __init__(self, args, task='docking'): # check if config file exist if os.path.exists(args.config_file): config = ConfigParser.SafeConfigParser() config.read(args.config_file) else: raise ValueError("Config file %s not found!" % (args.config_file)) # check if ligand file exists if not os.path.isfile(args.input_file_l): raise IOError("File %s not found!" % (args.input_file_l)) file_l_abs = os.path.abspath(args.input_file_l) base = os.path.basename(args.input_file_l) pref, ext = os.path.splitext(base) if ext != '.mol2': raise IOError( "Ligand file provided with -l option should be in .mol2 format! %s format detected!" % ext) nligands = int( subprocess.check_output('fgrep -c "@<TRIPOS>ATOM" %s' % file_l_abs, shell=True)) if nligands == 0: raise IOError("No ligand detected in %s, check your file again!" % args.input_file_l) elif nligands > 1: raise IOError( "More than one ligand detected in %s. Only one structure per ligand file is allowed!" % args.input_file_l) # new ligand file with unique names for every atom new_file_l = pref + '_dbx' + ext # create a ligand file with unique atom names mol2.update_mol2file(file_l_abs, new_file_l, unique=True, ligname='LIG') self.input_file_l = os.path.abspath(new_file_l) if task == 'docking': self.docking = configure.DockingSetup(config) self.rescoring = configure.RescoringSetup(config) elif task == 'scoring': self.scoring = configure.ScoringSetup(config) else: raise ValueError("Task should be one of docking or scoring") self.check_pdbfile(args.input_file_r)
def update_output_mol2files(self, sample=None): nfiles = len(glob('pose-*.mol2')) mgltools_path = subprocess.check_output('which prepare_ligand4.py', shell=True, executable='/bin/bash') mgltools_path = '/'.join(mgltools_path.split('/')[:-3]) for idx in range(nfiles): mol2file = 'pose-%s.mol2' % (idx + 1) mol2.update_mol2file(mol2file, mol2file, ADupdate=sample, unique=True, mask=['h', 'H']) mol2.arrange_hydrogens(mol2file, 'tmp.mol2', path=mgltools_path) shutil.move('tmp.mol2', mol2file)
def extract_docking_results(self, file_s, input_file_r, input_file_l): # save scores if os.path.isfile('lig_out_scored.mol2'): with open('lig_out_scored.mol2', 'r') as ffin: with open(file_s, 'w') as ffout: idx = 0 for line in ffin: if line.startswith('########## Grid Score:'): print >> ffout, line.split()[3] idx += 1 if idx == int(self.options['nposes']): break # create multiple mol2 files ligname = reader.open('lig_out_scored.mol2').ligname mol2.update_mol2file('lig_out_scored.mol2', 'lig-.mol2', ligname=ligname, multi=True, last=int(self.options['nposes'])) else: open(file_s, 'w').close()
def extract_docking_results(self, file_s, input_file_r, input_file_l): for idx, mol2file in enumerate(sorted(glob('gold_soln_*_m1_*.mol2'))): output_mol2file = 'lig-%s.mol2' % (idx + 1) mol2.update_mol2file(mol2file, output_mol2file, remove='LP')