Exemple #1
0
def run_docking_combo_local(job_dict):
  r_id               = job_dict['r_id']
  c_id               = job_dict['c_id']
  p_id               = job_dict['p_id']
  cs_id              = job_dict['cs_id']
  taut               = job_dict['taut'] 
  mol_fn             = job_dict['mol_fn']
  docker             = job_dict['docker']

  mol_fn_rel         = os.path.basename(mol_fn)


  sub_dir            = "{0}".format(c_id)
  if not os.path.exists(in_dir + "/" + sub_dir + "/grid.bmp"):
    shutil.copy(in_dir + "/grid.bmp", in_dir + "/" + sub_dir)

  if not os.path.exists(in_dir + "/" + sub_dir + "/grid.nrg"):
    shutil.copy(in_dir + "/grid.nrg", in_dir + "/" + sub_dir)

  if not os.path.exists(in_dir + "/" + sub_dir + "/selected_spheres.sph"):
    shutil.copy(in_dir + "/selected_spheres.sph", in_dir + "/" + sub_dir)

  head,tail          = os.path.splitext(mol_fn)
  amber_score_mol_fn = head + ".amber_score" + tail


  pdb_fn             = "{0}/3D7F_h.pdb".format(in_dir)
  recp_fn            = "{0}/3D7F.oeb.gz".format(in_dir)

  fn_dict = prepare_filenames(job_dict)
  dock6_inp = fn_dict['dock6_inp']
  dock6_out = fn_dict['dock6_out']
  dock6_amber_inp = fn_dict['dock6_amber_inp']
  dock6_amber_out = fn_dict['dock6_amber_out']
  fred_prefix = fn_dict['fred_prefix']
  fred_out = fn_dict['fred_out']

  conn = mddb_utils.get_dbconn(dbname, dbuser, dbhost, dbpass)
 
  if docker == 1:
    if not result_exists(conn, "bindingscoresfred", r_id, c_id, p_id, cs_id, taut):
      print "==========================================================================="
      print "Running fred"
  
      run_fred(recp_fn, mol_fn, fred_prefix, sub_dir)
      fred_scores = lddb_parsers.parse_fred(fred_out)
      insert_fred_scores(r_id, c_id, p_id, cs_id, taut, fred_scores)
    else:
      print "Skip fred for {0}".format(mol_fn)
  
  
  if docker == 2:
    if not result_exists(conn, "bindingscoresdock6", r_id, c_id, p_id, cs_id, taut):
      print "==========================================================================="
      print "Running dock6"
      run_dock6(mol_fn_rel, dock6_inp, dock6_out, sub_dir)
      dock6_scores = lddb_parsers.parse_dock6(dock6_out)
      insert_dock6_scores(r_id, c_id, p_id, cs_id, taut, dock6_scores)
    else:
      print "Skip dock6 for {0}".format(mol_fn)
  if docker == 3: 
    if not result_exists(conn, "bindingscoresdock6amber", r_id, c_id, p_id, cs_id, taut):
      print "==========================================================================="
      print "Running dock6 with amber"
      run_dock6_with_amber(mol_fn_rel, pdb_fn, dock6_amber_inp, dock6_amber_out, sub_dir)
      dock6_amber_scores = lddb_parsers.parse_dock6_amber(dock6_amber_out)
      insert_dock6_amber_scores(r_id, c_id, p_id, cs_id, taut, dock6_amber_scores)
    else:
      print "Skip dock6amber for {0}".format(mol_fn)
  return ''
Exemple #2
0
  def load(self, conn, prefix, d, local_paths):
    #trj_dir = os.path.join(d['dest_dir'], "recp{receptor_id}_model{model_id}/trj{trj_id}".format(**d))
    #frame_dir     = os.path.join(recpmodel_dir, "frame{t}".format(**d))
    frame_dir = d['frame_dir']

    grid_fn = 'grid.out'
    selected_spheres_fn = 'selected_spheres.sph'
    boxpdb_fn = 'step2_box.pdb'
    bmp_fn = 'step3_grid_score.bmp'
    nrg_fn = 'step3_grid_score.nrg'
    if not (os.path.exists(os.path.join(frame_dir, grid_fn)) and \
          os.path.exists(os.path.join(frame_dir, selected_spheres_fn)) and \
          os.path.exists(os.path.join(frame_dir, bmp_fn)) and \
          os.path.exists(os.path.join(frame_dir, nrg_fn)) and \
          os.path.exists(os.path.join(frame_dir, boxpdb_fn)) ):
      cmd_st = 'cp *grid* *.sph *box* {0}'.format(frame_dir)
      subprocess.call(cmd_st, shell = True, cwd = prefix, stdout=subprocess.PIPE,
                      stdin=subprocess.PIPE)
      print 'Copied all to %s' % frame_dir

    # Move the docked file to the unique name
    original_docked_fn = 'docked_ligand_scored.mol2'
    docked_fn = '{0}_level{1}_docked_{2}.mol2'.format(d['docker'], d['docker_level'], d['compoundstate_id'])
    cmd_st = 'mv {0} {1}'.format(original_docked_fn, docked_fn)
    subprocess.call(cmd_st, shell = True, cwd = prefix, stdout=subprocess.PIPE,
                      stdin=subprocess.PIPE)

    # Copy the docked file to the frame dir
    cmd_st = 'cp {0} {1}'.format(docked_fn, frame_dir)
    subprocess.call(cmd_st, shell = True, cwd = prefix, stdout=subprocess.PIPE,
                      stdin=subprocess.PIPE)
 
    d['dest_dir']        = os.path.join(local_paths['resource_prefix'],
                                        d['dbname'])
    job_dir = os.path.join(d['dest_dir'], 'job'+str(d['job_id']))
    if not os.path.exists(job_dir):
      os.makedirs(job_dir)

    cmd_st = 'cp * {0}'.format(job_dir)
    subprocess.call(cmd_st, shell = True, cwd = prefix, stdout=subprocess.PIPE,
                    stdin=subprocess.PIPE)
    #with open(os.path.join(job_dir, 'job_dict.txt'), 'w') as ofp:
    #  ofp.write(str(d))

    score_fn = os.path.join(job_dir, 'step4_dock6.out')

    results = lddb_parsers.parse_dock6(score_fn)
    
    st_out = cStringIO.StringIO()
    for r in results:
      r = [d['job_id']] + r
      r = map(str, r)
      st_out.write('\t'.join(r) + '\n')

    st_out.seek(0)

    cur = conn.cursor()
    cur.copy_from(st_out, 'Level1_dock6scores', columns = ('job_id', 'gs', 'gvdw', 'ges', 'inen'))
    cur.close()
    conn.commit()
    return bool(results), job_dir