コード例 #1
0
ファイル: seq_controller.py プロジェクト: nutanong/mddb
  def load_trjs_dir(self):    
    conn = mddb_utils.get_dbconn(self.param_dict['dbname'],
                                 self.param_dict['dbuser'],
                                 self.param_dict['dbhost'],
                                 self.param_dict['dbpass'])

    cur = conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor)

    cur.execute("select S.pdb_id from seq_pdb S left join trajectories T on S.pdb_id = T.pdb_id where T.pdb_id is null;")
    run_params = cur.fetchall()
    cur.close()
    conn.close()

    wanted_list = map(lambda d: int(d['pdb_id']), run_params)

    print wanted_list
    trj_dir = '/damsl/projects/{dbname}/trajectories'.format(**self.param_dict)
    pdb_id_dirs = os.listdir(trj_dir)
    #print pdb_id_dirs

    for pdb_id_dir in pdb_id_dirs:
      try:
        pdb_id_dir = int(pdb_id_dir)
        if pdb_id_dir in wanted_list:
          d = {'pdb_id': pdb_id_dir, 'trj_prefix': trj_dir}
          d.update(self.param_dict)
          self.load_trj(d)
        else:
          print 'pdb_id_dir:', pdb_id_dir, 'is already loaded'
      except Exception as e:
        print e
        pass
コード例 #2
0
ファイル: seq_controller.py プロジェクト: nutanong/mddb
  def load_one(self):
    try:
      query = "SELECT jq_entry_id,data FROM loadingqueue ORDER BY jq_entry_id limit 1"

      conn = mddb_utils.get_dbconn(self.param_dict['dbname'],
                                 self.param_dict['dbuser'],
                                 self.param_dict['dbhost'],
                                 self.param_dict['dbpass'])
      cur = conn.cursor()
      cur.execute(query)
  
      row = cur.fetchone()
      id = row[0]
      
      data = row[1]
      d = eval(data)


      self.load_trj(d)   
      print "Loaded: id"
      cur.execute("DELETE FROM loadingqueue WHERE jq_entry_id = %s",(id,))

      cur.close()
       
      conn.commit() 
      conn.close() 
      return True
    except Exception as e:
      traceback.print_exc()
      print "failed" 
      return False
コード例 #3
0
ファイル: lddb_controller.py プロジェクト: nutanong/mddb
  def load_receptor_frames(self):
    data_dir = '/damsl/projects/molecules/data/Odorant_GPCR/'
    frames_fn         = os.path.join(data_dir, 'frames.txt')
    trajectories_fn   = os.path.join(data_dir, 'trajectories.txt')
    receptormodels_fn = os.path.join(data_dir, 'receptormodels.txt')
    conn = mddb_utils.get_dbconn(self.param_dict['dbname'],
                                 self.param_dict['dbuser'],
                                 self.param_dict['dbhost'],
                                 self.param_dict['dbpass'])
    cur = conn.cursor()
    with open(receptormodels_fn, 'r') as ifp:
      cur.copy_from(ifp, 'ReceptorModels',
                    columns = ('receptor_id', 'model_id', 'pdb_fn'))
      cur.execute('select count(*) from ReceptorModels')
      print cur.fetchone()[0], 'receptor models added'

    
    with open(trajectories_fn, 'r') as ifp:
      cur.copy_from(ifp, 'Trajectories',
                    columns = ('receptormodel_id', 'expsolv', 'bilayer', 'trj_dir'))
      cur.execute('select count(*) from Trajectories')
      print cur.fetchone()[0], 'trajectories added'

    with open(frames_fn, 'r') as ifp:
      cur.copy_from(ifp, 'Frames',
                    columns = ('trj_id', 't', 'fred_fn', 'dock6_fn', 'pdb_fn'))
      cur.execute('select count(*) from Frames')
      print cur.fetchone()[0], 'frames added'



    cur.close
    conn.commit()
    conn.close()
コード例 #4
0
ファイル: lddb_utils.py プロジェクト: nutanong/mddb
def queue_more_jobs(job_dict):
  print "queuing more jobs"
  offset = job_dict['offset']
  limit  = job_dict['limit']
  docker = job_dict['docker']

  stm = 'select receptor_id, model_id, fred_fn, dock6_fn, compound_id, tautomers, smi_fn, sdf_fn ' +\
        'from UnfinishedJobsView J ' +\
        'order by job_id ' +\
        'offset {0} limit {1}'.format(offset, limit)

  conn = mddb_utils.get_dbconn(dbname, dbuser, dbhost, dbpass)
  cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
  cur.execute(stm)
  rows = cur.fetchall()

  job_size = 1
  num_entries = len(rows)
  groups = list(chunks(rows, job_size))
  for rows in groups:

    json_st = "[{0}]".format(",".join(rows))

    stm = "select queue_gearman_job(E'{0}', E'{1}', E'{2}')".format(
                           json_st,
                           gmdhost, 
                           gmdport)

    print stm
    cur.execute(stm)


  cur.close()
  conn.commit()
  conn.close()  
コード例 #5
0
ファイル: lddb_controller.py プロジェクト: nutanong/mddb
  def load_compounds(self):
    smi_list_fn = '/damsl/projects/molecules/data/Odorant_GPCR/smi_list.txt'
    with open(smi_list_fn, 'r') as ifp:
      smi_list = ifp.readlines()


    output = StringIO.StringIO()
    dict   = {}

    for f in smi_list:
      dir,f = os.path.split(f)
      m = re.search('ODL(.+?)_', f)
      c_id = int(m.group(1))
      t = 'tautomers' in f
      if not t:
        with open(os.path.join('/damsl/projects',dir, f.rstrip()), 'r') as smi_fp:
          smi_st = smi_fp.read().split()[0]

        output.write("{0},{1},{2},{3},{4}\n".format(c_id,t, f.rstrip(), smi_st, dir))

    output.seek(0)
    conn = mddb_utils.get_dbconn(self.param_dict['dbname'],
                                 self.param_dict['dbuser'],
                                 self.param_dict['dbhost'],
                                 self.param_dict['dbpass'])
    cur = conn.cursor()
    cur.copy_from(output, 'InitialCompounds', sep = ',',
                  columns = ('compound_id', 'tautomers', 'smi_fn', 'smiles', 'compound_dir'))

    cur.execute('select count(*) from InitialCompounds')
    print cur.fetchone()[0], 'compounds added'
    cur.close
    conn.commit()
    conn.close()
    output.close()  
コード例 #6
0
ファイル: seq_controller.py プロジェクト: nutanong/mddb
  def createjobs(self):
    conn = mddb_utils.get_dbconn(self.param_dict['dbname'],
                                 self.param_dict['dbuser'],
                                 self.param_dict['dbhost'],
                                 self.param_dict['dbpass'])

    cur = conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
    cur.execute("select S.pdb_id from seq_pdb S left join trajectories T on S.pdb_id = T.pdb_id where T.pdb_id is null;")
    run_params = cur.fetchall()
    

    cur.execute("truncate table jobqueue")
    #cur.execute("truncate table loadingqueue")

    for d in run_params:
      d['generator'] = 'impsolv'
      d['dbname']    = self.param_dict['dbname']
      d['dbuser']    = self.param_dict['dbuser']
      d['dbhost']    = self.param_dict['dbhost']
      d['dbpass']    = self.param_dict['dbpass']
      data = 'ARRAY' + str([json.dumps(d)])
      cur.execute('select jobqueue_insert({0})'.format(data))
      #print d

    cur.close()
    conn.commit()
    conn.close()
コード例 #7
0
ファイル: mddb_controller.py プロジェクト: nutanong/mddb
  def sample_loop(self):
    while True:
      #try:
        conn = mddb_utils.get_dbconn(self.param_dict['dbname'],
                                     self.param_dict['dbuser'],
                                     self.param_dict['dbhost'],
                                     self.param_dict['dbpass'])
    
    
        res = mddb_utils.execute_query(conn,
          "select param_value from ControlParams where param_name = 'sampleloop'")
    
        print datetime.datetime.now()
        try:
          nt = mddb_utils.execute_query(conn, "select resample_blocking(E'{gmdhost}:{gmdport}')".format(**self.param_dict))
        except Exception as e:
          m = "Error {0}".format(str(e))
          print m
          try:
            mddb_utils.execute_query(conn, "insert into ErrorMessages values (statement_timestamp(),{0},{1})".format("sample_loop", m.encode("utf-8")))
          except:
            pass
          nt = 0
          time.sleep(2)
          continue
  
        if int(nt) > 0:
          time.sleep(0.05)
        else:
          time.sleep(2)
  
        print res
        if res == 'quitting':
          mddb_utils.execute_query(conn,
            "select controlparams_upsert('sampleloop', 'notrunning')")
          mddb_utils.execute_query(conn,
            "update ExpJobs set active = False;")
    
          conn.close()
          break
    
        cur = conn.cursor()
        cur.execute('select S.subspace_id from subspaces S, expjobs E where S.subspace_id = E.subspace_id group by S.subspace_id having bool_or(active)')

        num_active_subspaces = cur.rowcount
        
        if num_active_subspaces == 0:
          cur = conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
          cur.execute('select * from mdq_pop()')
          if cur.rowcount > 0:
            ss_dict = cur.fetchone()

            if any(ss_dict.values()):
              ss_dict['protein_seq'] = "".join(ss_dict['expanded_terms'])
              mddb_utils.subspace_init(dict(self.param_dict.items() + ss_dict.items()))

          cur.close()
          conn.commit()
          conn.close()
コード例 #8
0
ファイル: lddb_utils.py プロジェクト: nutanong/mddb
def insert_fred_scores(r_id, c_id, p_id, chargeset, tautomers, scores):
  if scores != None and len(scores) != 0:
    vals = '({0})'.format(', '.join(map(str, [r_id,c_id, p_id, chargeset, tautomers] + scores))) 
    stm = "insert into BindingScoresFred values\n{0}".format(vals)
  else:
    stm = "insert into BindingScoresFred (receptor_id, compound_id, pose_id, chargeset_id, tautomers) " +\
          "values ({0},{1},{2},{3},{4})".format(r_id,c_id, p_id, chargeset, tautomers)

  conn = mddb_utils.get_dbconn(dbname, dbuser, dbhost, dbpass)
  mddb_utils.execute_query(conn, stm)
コード例 #9
0
ファイル: mddb_controller.py プロジェクト: nutanong/mddb
  def clear_jobqueue(self):
    conn = mddb_utils.get_dbconn(self.param_dict['dbname'],
                                 self.param_dict['dbuser'],
                                 self.param_dict['dbhost'],
                                 self.param_dict['dbpass'])

    cur = conn.cursor()

    cur.execute('truncate table JobQueue')
    cur.close()
    conn.commit()
    conn.close()
コード例 #10
0
ファイル: worker.py プロジェクト: nutanong/mddb
  def process_work(self):
    print "start processing work"

    try:
      gateway_host = self.resource.gateway_host or 'localhost'
    except:
      gateway_host = 'localhost'
      
    # session directory is named after the gateway host appended by a random string for uniqueness
    session_dir    = 's_' + gateway_host + '_' + str(uuid.uuid4())[0:8]

    while True:
      if self.resource.check_deployments():

        conn = mddb_utils.get_dbconn(self.param_dict['dbname'],
                                     self.param_dict['dbuser'],
                                     self.param_dict['dbhost'],
                                     self.param_dict['dbpass'])
        cur = conn.cursor()
        deployment_size = self.resource.job_concurrency * self.param_dict['avg_seq_jobs']
        sql_st = 'select jobqueue_dequeue({0})'.format(deployment_size)
        cur.execute(sql_st)

        try:
          res = cur.fetchone()[0]
          job_dicts = map(eval, res)

          print datetime.datetime.now()
          print res
        except:
          job_dicts = []

        cur.close()
        conn.commit()
        conn.close()

        if job_dicts: # got job, got slot
          self.resource.deploy(session_dir, job_dicts, self.param_dict)
          if not self.resource.__class__ == resources.LocalResource:
            time.sleep(50)
     
        else: # got job, no slot
          time.sleep(3)

      else: # no slot
        time.sleep(3)

    #local_paths = resource.LocalResource.get_paths()
    # delete the session directory
    # shutil.rmtree(session_dir)

    return
コード例 #11
0
ファイル: lddb_utils.py プロジェクト: nutanong/mddb
def insert_dock6_amber_scores(r_id, c_id, p_id, chargeset, tautomers, list_of_score_tups):
  if list_of_score_tups != None and len(list_of_score_tups) != 0:
    vals = ',\n'.join(
      map(lambda x: '({0})'.format(', '.join(map(str, [r_id,c_id, p_id, chargeset, tautomers] + list(x)))), list_of_score_tups)
    )
  
    stm = "insert into BindingScoresDock6Amber values\n{0}".format(vals)
  else:
    stm = "insert into BindingScoresDock6Amber (receptor_id, compound_id, pose_id, chargeset_id, tautomers) " +\
          "values ({0},{1},{2},{3},{4})".format(r_id,c_id, p_id, chargeset, tautomers)

  conn = mddb_utils.get_dbconn(dbname, dbuser, dbhost, dbpass)
  mddb_utils.execute_query(conn, stm)
コード例 #12
0
ファイル: mddb_controller.py プロジェクト: nutanong/mddb
 def load_configs(self):
   conn = mddb_utils.get_dbconn(self.param_dict['dbname'],
                                self.param_dict['dbuser'],
                                self.param_dict['dbhost'],
                                self.param_dict['dbpass'])
 
   c_id_all = mddb_utils.execute_query(conn, "select insert_new_config('charmm', 'all')")
   self.load_config(c_id_all, '/damsl/mddb/data/amino_configs/config_charmm')
   c_id_ua = mddb_utils.execute_query(conn, "select insert_new_config('charmm', 'ua')")
   self.load_config(c_id_ua,  '/damsl/mddb/data/amino_configs/config_ua_charmm')
 
   #mddb_utils.load_machine_info(conn, ['mddb','mddb2','qp2','qp3','qp4','qp5','qp6'])
   conn.commit()
   conn.close() 
コード例 #13
0
ファイル: lddb_utils.py プロジェクト: nutanong/mddb
def fetch_results():
    st = mddb_utils.run_cmd("ssh hhpc python2.6 nutanong/mddb/scheduler/lddb_sqlite_utils.py --mode getresults")
    sql_stms = st.split("\n")

    conn = mddb_utils.get_dbconn(dbname, dbuser, dbhost, dbpass)
    cur = conn.cursor()
    for stm in sql_stms:
      print stm
      try:
        cur.execute(stm)
      except:
        pass

      conn.commit()
    cur.close()
    conn.close()
コード例 #14
0
ファイル: controller.py プロジェクト: nutanong/mddb
 def quit_existing_workers(self):
   conn = mddb_utils.get_dbconn(self.param_dict['dbname'],
                                self.param_dict['dbuser'],
                                self.param_dict['dbhost'],
                                self.param_dict['dbpass'])
   cur = conn.cursor()
   cur.execute("select worker_name from Workers")
   for rec in cur:
     gw_name = rec[0]
     mddb_utils.run_cmd("screen -X -S {0} quit".format(gw_name))
 
   cur.execute("truncate Workers cascade")
   cur.execute("select setval((select pg_get_serial_sequence('workers', 'worker_id')), 1, false)")
   conn.commit()
   cur.close()
   conn.close()
コード例 #15
0
ファイル: seq_controller.py プロジェクト: nutanong/mddb
  def load_trj(self,d):
    print d
    d2 = copy.deepcopy(self.param_dict)
    d2.update(d)
    d = d2
    print d
    pdbid = d['pdb_id']
    query = "SELECT SS.subspace_id, SS.seqid FROM seq_pdb SP, seq_subspace SS WHERE SP.pdb_id = %s AND SP.seqid = SS.seqid"
   
    conn = mddb_utils.get_dbconn(d['dbname'],
                                 d['dbuser'],
                                 d['dbhost'],
                                 d['dbpass'])
    cur = conn.cursor()
    cur.execute(query,(pdbid,))
    
    rows = cur.fetchall()
    ss_id = None
    seq_id = None
    if (len(rows) == 0):
      print "Creating New Subspace:"
      query = "SELECT seqid from seq_pdb where pdb_id = %s"
      cur = conn.cursor()
      cur.execute(query,(pdbid,))
      seqid = cur.fetchall()[0][0]
      cur.close()
      self.update_dict(d,pdbid)
      self.config_ss()
      ss_id = mddb_utils.subspace_init(d)
    else:
      ss_id = rows[0][0]
      seqid = rows[0][1]
      self.update_dict(d,pdbid)
      mddb_utils.load_trajectories(conn,ss_id,d)

    cur.close()
    cur = conn.cursor()
    query = "INSERT INTO seq_subspace (seqid,subspace_id) VALUES (%s, %s)"
    print query
    cur.execute(query, (seqid, ss_id))
    conn.commit()  
    print cur.fetchone()[0]

    cur.close()
    conn.close()

    print "Successfuly Loaded Trajectory"
コード例 #16
0
ファイル: controller.py プロジェクト: nutanong/mddb
  def setup_workers(self, l):
    conn = mddb_utils.get_dbconn(self.param_dict['dbname'],
                                 self.param_dict['dbuser'],
                                 self.param_dict['dbhost'],
                                 self.param_dict['dbpass'])
  
    for d in l:
      h = d['hostname']
      self.param_dict['res_config_name'] = d.get('res_config_name') or 'default'
      self.param_dict['avg_seq_jobs'] = d.get('avg_seq_jobs') or 1
      self.prepare_worker(h)
      prefix = os.path.join(os.getenv('HOME'),
                            self.param_dict['user'],
                            self.param_dict['mwd'])

      self.param_dict['remotegen'] = ""
      
      self.param_dict['gen_host'] = h
      remote_resource_names = [k for k,v in resources.resource_dict.items() if v != resources.LocalResource]
      if h in remote_resource_names:
        self.param_dict['worker_host'] = 'localhost'
      else:
        self.param_dict['worker_host'] = self.param_dict['gen_host']

      # centos hosts reqires a different PYTHONPATH than ubuntu hosts
      # TODO: add more centos hosts all qp-hm* and qp-hd*
      if self.param_dict['worker_host'] in ['mddb', 'mddb2', 'localhost']:
        self.param_dict['pythonpaths'] = self.centos_pythonpaths.format(prefix)
      else:
        self.param_dict['pythonpaths'] = self.ubuntu_pythonpaths.format(prefix)

      # insert the worker name into the 'workers' table
      i = mddb_utils.execute_query(conn, "select workers_insert('{gen_host}');".format(**self.param_dict))
      self.param_dict['worker_id']  = i
      self.param_dict['worker_name'] = "gmw_{dbname}_{gen_host}_{worker_id}_{user}".format(**self.param_dict)
      self.start_gmw(conn)
    conn.commit()
    conn.close()
コード例 #17
0
ファイル: lddb_controller.py プロジェクト: nutanong/mddb
  def load_compound_states(self):
    self.load_compounds()

    prefix = '/damsl/projects/'
    taut_cmd = '/damsl/projects/molecules/software/DD/OpenEye/openeye/bin/tautomers'

    conn = mddb_utils.get_dbconn(self.param_dict['dbname'],
                                 self.param_dict['dbuser'],
                                 self.param_dict['dbhost'],
                                 self.param_dict['dbpass'])

    cur = conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
    cur.execute('select compound_dir,smi_fn,compound_id from initialcompounds order by compound_id')
    compound_dicts = cur.fetchall()
    #cur.execute('truncate table CompoundStates')

    for d in compound_dicts:
      output = StringIO.StringIO()
      cmd = taut_cmd + ' ' + os.path.join(prefix,d['compound_dir'], d['smi_fn'])
      taut_fn = '/tmp/tautout{0}.txt'.format(d['compound_id'])
      with open(taut_fn, 'w') as ofp:
        subprocess.call(cmd, shell=True, stdout=ofp,
                         cwd=os.environ['HOME']
                       )
      with open(taut_fn, 'r') as ifp:
        l = ifp.readlines()
        print l
        for state_id,compound_state_smi in enumerate(l):
          compound_state_smi = compound_state_smi.split()[0]
          line = '{0}\t{1}\t{2}\n'.format(d['compound_id'], state_id, compound_state_smi)
          print line
          output.write(line)

      output.seek(0)
      cur.copy_from(output, 'CompoundStates', columns = ('compound_id', 'state_id', 'smiles'))
      conn.commit()

    conn.close()
コード例 #18
0
ファイル: mddb_controller.py プロジェクト: nutanong/mddb
  def queue_jobs(self, jobfile):
    conn = mddb_utils.get_dbconn(self.param_dict['dbname'],
                                 self.param_dict['dbuser'],
                                 self.param_dict['dbhost'],
                                 self.param_dict['dbpass'])

    with open(jobfile, 'r') as ifp:
      content = ifp.read()
      print content
      job_obj = ast.literal_eval(content)  #json.loads(content, object_hook=mddb_utils.ascii_encode_dict)


      print job_obj
      job_dicts = controller.Controller.get_job_dicts(**job_obj)

    for d in job_dicts:
      print 'queue job: ', d

      mddb_utils.mdq_push(conn,**d)
      #mddb_utils.mdq_push(conn, 0, psp_terms, num_expjobs, num_iterations, num_steps_sim, u_id, policy,
      #                    simulator, config_id)

    return
コード例 #19
0
ファイル: lddb_controller.py プロジェクト: nutanong/mddb
  def work(self):
    comment = "mode: initdb\nRequired Param: --dbname"
    print comment

    self.load_stored_procedures(['lddb_utils.sql'])
    self.quit_everything()
    self.load_stored_procedures(['job_control.sql'])
    l = []
    l.append({'hostname':'localhost', 'avg_seq_jobs': '1', 'res_config_name': 'def'})
    #l.append({'hostname':'stampede',  'avg_seq_jobs': '1', 'res_config_name': 'dev'})
    #l.append({'hostname':'lonestar',  'avg_seq_jobs': '1', 'res_config_name': 'mpi'})

    self.setup_workers(l)
    conn = mddb_utils.get_dbconn(self.param_dict['dbname'],
                                 self.param_dict['dbuser'],
                                 self.param_dict['dbhost'],
                                 self.param_dict['dbpass'])

    cur = conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
    cur.execute("select * from level1_unfinishedjobsview order by job_id;")
    #cur.execute("select * from level1_unfinishedjobsview order by job_id;")
    #cur.execute("select 'membrane' as generator,* from unprocessedreceptormodelsview order by receptor_id,model_id;")

   

    run_params = cur.fetchall()
    #run_params = run_params[:5]

    for d in run_params:
      d['dbname']    = self.param_dict['dbname']
      data = json.dumps(d)
      job_id = d.get('job_id') or 'NULL'
      cur.execute("select jobqueue_insert({0},'{1}')".format(job_id, data))

    cur.close()
    conn.commit()
    conn.close()
コード例 #20
0
ファイル: worker.py プロジェクト: nutanong/mddb
  def __init__(self):

    # parse command line arguments
    self.param_dict = param_dict_parser.parse(self.param_dict)


    print self.param_dict

    res_name = self.param_dict.get('gen_host') or 'localhost'
    proc_id = os.getpid();
    conn = mddb_utils.get_dbconn(self.param_dict['dbname'],
                                 self.param_dict['dbuser'],
                                 self.param_dict['dbhost'],
                                 self.param_dict['dbpass'])

    cur = conn.cursor()

    # update the worker entry
    st = "update Workers set worker_name = '{0}', process_id = {1}, resource_name = '{2}' where worker_id = {3}"

    cur.execute(st.format(self.param_dict['worker_name'], 
                          proc_id,
                          res_name,
                          self.param_dict['worker_id'],
                ))
    cur.close()
    conn.commit()
    conn.close()

    res_class = resources.resource_dict[res_name]

    # init resource object
    self.resource = res_class(self.param_dict.get('user'), 
                              self.param_dict.get('res_config_name'), 
                              worker_id = self.param_dict['worker_id'])
    print st
    print self.param_dict
コード例 #21
0
ファイル: mddb_controller.py プロジェクト: nutanong/mddb
  def start_sampleloop(self):
    conn = mddb_utils.get_dbconn(self.param_dict['dbname'],
                                 self.param_dict['dbuser'],
                                 self.param_dict['dbhost'],
                                 self.param_dict['dbpass'])
 
    prefix = os.path.join(os.getenv('HOME'),
                          self.param_dict['user'],
                          controller.Controller.mwd)


    pp = controller.Controller.centos_pythonpaths.format(prefix)
 
 
    env = "PYTHONPATH={0} GPHOME=/opt/greenplum-db/. PGHOST=localhost4 PGOPTIONS=--client-min-messages=error ".format(pp)
    env = env + "PATH={PATH} LD_LIBRARY_PATH={LD_LIBRARY_PATH} ".format(**os.environ)

    self.param_dict['env'] = env

    sample_loop_cmd = ("""screen -S {dbname}_{user}_sample_loop -d -m """+\
                       """env {env}""" +\
                       """/opt/greenplum-db/ext/python/bin/python """+ os.path.abspath( __file__ ) +\
                       """ --mode loop """+\
                       """ --dbname  {dbname} """+\
                       """ --dbpass  {dbpass} """+\
                       """ 2>&1 | tee /tmp/{dbname}_{user}_sampleloop.log >&1 """).format(**self.param_dict);
  
  
  
    mddb_utils.run_cmd(sample_loop_cmd)
  
    mddb_utils.execute_query(conn,
      "select controlparams_upsert('sampleloop', 'running')")
  
    conn.commit()
    conn.close()
コード例 #22
0
ファイル: impsolv_pipeline.py プロジェクト: nutanong/mddb
  def preprocess(d, local_paths):
    
    d['dest_dir']        = os.path.join(local_paths['resource_prefix'],
                                        d['dbname'])


    session_dir = d['session_dir']    
    #pdb_path = os.path.join('/damsl/projects/molecules/data/PTEN/data/josh/output', seq_id, seq_id+'.B99990001.pdb')
   
    output_prefix = os.path.join(local_paths['resource_prefix'], local_paths['io_dir'], session_dir, d['run_dir'])
    
    conn = mddb_utils.get_dbconn(d['dbname'],
                                 d['dbuser'],
                                 d['dbhost'],
                                 d['dbpass'])

    if not os.path.exists(output_prefix):
      os.makedirs(output_prefix)
    
    print 'output_prefix: ', output_prefix
    
    if ('sim_input_id' in d):
      cur = conn.cursor()
      cur.execute('select sim_input_fn from sim_inputs where sim_input_id = {0}').format(d['sim_input_id'])

      sim_input_fn = cur.fetchone()['sim_input_fn']
      d['charmm_s0in'] = sim_input_fn + '_start,in'
      d['charmm_s1in'] = sim_input_fn + '_1,in'


    if ('pdb_id' not in d):   
      # need to do structure prediction. First insert sequence into db
      insert_query = "SELECT sequence_insert(%s)"
      aaseq = d['aaseq']
      fasta = ""
      
      cur1 = conn.cursor()
      cur1.execute(insert_query,(fasta,)) 
      rows = cur1.fetchall()
      
       
       
      seqid = str(rows[0][0])
      d['seqid'] = seqid 
      cur1.close()
      conn.commit()
      
      fasta = ">" + seqid + "\n" + aaseq
      update_query = "UPDATE sequences_josh SET fasta=%s where seqid=%s"
      cur2 = conn.cursor()
      cur2.execute(update_query,(fasta, int(seqid)))
      cur2.close()
      conn.commit() 
            

      #  create modeller pdb
      # create file names for later use 
      fastaFileName = output_prefix + seqid + ".fasta"
      f = open(fastaFileName,'w+')
      f.write(fasta)
      f.close()     
      pirFileName = output_prefix + seqid +'.ali'
      # TODO check this
      pdbFileName = os.path.join(local_paths['template_prefix'].format("/home/webapp",d['user']),ImpSolvPipeline.template_dir,'1d5r.pdb')
      alignFileName = output_prefix + seqid +'-p60484'+ '.ali'
      # convert fasta file to pir file
      MT.fastaToPir(fastaFileName,pirFileName)
      # align pir to pdb file
      MT.alignPirToPdb(pirFileName,pdbFileName,seqid,alignFileName)
      # insert alignment to DB
      MT.dbInsertAlignment(conn, seqid, alignFileName)
      # build homology models
      MT.doAutoModel(alignFileName,pdbFileName,seqid)
      # move output to proper directory
      pdbfile = seqid + ".B99990001.pdb"
      f = open(pdbfile,'r')
      pdb = f.read()
      f.close()
               
      insert_query = "SELECT pdb_insert(%s,%s,%s)"
      
      cur1 = conn.cursor()
      cur1.execute(insert_query,(seqid,pdb,"modeller"))
      rows = cur1.fetchall()
      id = rows[0][0]
      cur1.close()
      conn.commit()
      d['pdb_id'] = id
       

    pdb_id = d['pdb_id']
    cur = conn.cursor()
    cur.execute('select pdb from seq_pdb where pdb_id = {0}'.format(pdb_id));
    pdb_content = cur.fetchone()[0]

 
    with open(os.path.join(output_prefix, 'protein0.pdb'), 'w') as ofp:
      ofp.write(pdb_content)

    cmd0 = 'python /damsl/projects/molecules/software/tools/pdb2pqr/pdb2pqr-1.8/pdb2pqr.py ' +\
          '--ffout=charmm --ff=charmm {0} {1}'.format('protein0.pdb', 'protein1.pdb')  
    # preprocess pdb file
    cmd1 = 'python /damsl/projects/molecules/data/PTEN/Full/Charmm/ACE/charmm-gui-model1/add_segid_PTEN.py ' +\
           '-f protein1.pdb -o protein2.pdb -p pdb -s ' +\
           '/damsl/projects/molecules/data/PTEN/Full/Charmm/ACE/charmm-gui-model1/resids.dat' 
    
    cmd2 = "sed 's/ ATOM/ATOM/' protein2.pdb | " +\
           "sed 's/CD1 ILE/CD  ILE/' | " +\
           "sed 's/1CBDISU/ CB CYS/' | " +\
           "sed 's/1SGDISU/ SG CYS/' > protein.pdb "   
 
    print cmd0
    subprocess.call(cmd0, shell=True, cwd = output_prefix)
    print cmd1
    subprocess.call(cmd1, shell=True, cwd = output_prefix)
    print cmd2
    subprocess.call(cmd2, shell=True, cwd = output_prefix)    
コード例 #23
0
ファイル: mddb_controller.py プロジェクト: nutanong/mddb
  def __init__(self):
    self.param_dict = dict(self.param_dict.items() + self.mddb_param_dict.items())
    self.add_parser_options(self.param_dict)
    self.param_dict = self.parse_param_dict()

    if self.param_dict['mode'] == 'initdb':
      self.quit_everything()
      self.init_database(self.schema_files)
      self.load_stored_procedures(self.sp_files)
      self.load_configs()
      sys.exit(0)

    if self.param_dict['mode'] == 'initss':
      mddb_utils.subspace_init(self.param_dict)
      sys.exit(0)

    if self.param_dict['mode'] == 'trjs':
      conn = mddb_utils.get_dbconn(self.param_dict['dbname'],
                                   self.param_dict['dbuser'],
                                   self.param_dict['dbhost'],
                                   self.param_dict['dbpass'])

      mddb_utils.add_trajectories(conn, self.param_dict)
      conn.close()
      sys.exit(0)




    if self.param_dict['mode'] == 'loop':
      self.sample_loop()
      sys.exit(0)
  
    if self.param_dict['mode'] == 'setup':
      self.quit_everything()
      #self.clear_jobqueue()
      #self.init_database(self.schema_files)
      #self.load_stored_procedures(self.sp_files)
      #self.load_configs()
      l = []
      l.append({'hostname':'stampede', 'sequentialism': '1', 'res_config_name': 'gpu'})

      self.setup_workers(l)
      #self.start_sampleloop()
      sys.exit(0)

    if self.param_dict['mode'] == 'qjobs':
      #trj_id_list = ['137']
      #trj_len = 1000
      #num_points = 1 



      #l = map(lambda x: getStartingPoints(x, trj_len, num_points), trj_id_list)

      #l = list(itertools.chain(*l))

      l = []
      timestamps = [(3294, 555, 50), (3264, 5, 50), (3264, 929, 100)]
      for ts in timestamps:
        l = l + MDDBController.get_prev_timestamps(*ts)

      l = map(lambda (trj_id,t): {'trj_id': "{0:03d}".format(trj_id), 't': t}, l)

      l = l[99:]

      default_params = {'nstep_simulation': 50000000,
                        'trj_save_freq': 50000,
                        'source': 'deshaw',
                        'generator': 'amber',
                        'template_dir': 'amber_min',
                        'dbname': self.param_dict['dbname'],
                        'dbuser': self.param_dict['dbuser'],
                        'dbhost': self.param_dict['dbhost'],
                        'dbpass': self.param_dict['dbpass'],
                       }


      conn = mddb_utils.get_dbconn(self.param_dict['dbname'],
                                   self.param_dict['dbuser'],
                                   self.param_dict['dbhost'],
                                   self.param_dict['dbpass'])


      cur = conn.cursor()
      cur.execute('truncate table jobqueue')
      for d in l:
        d.update(default_params)
        print d
        data = 'ARRAY' + str([json.dumps(d)])
        cur.execute('select jobqueue_insert({0})'.format(data))


      cur.close()
      conn.commit()
      conn.close()      


    if self.param_dict['mode'] == 'cmd':
      mc = mddb_cmd()
      mc.init_conn(self.param_dict)
      mc.cmdloop()
      sys.exit(0)
コード例 #24
0
ファイル: lddb_utils.py プロジェクト: nutanong/mddb
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 ''
コード例 #25
0
ファイル: lddb_utils.py プロジェクト: nutanong/mddb
  receptor_id = '3D7F_h'

  dbname      = options.dbname
  dbhost      = options.dbhost
  dbuser      = options.dbuser
  dbpass      = options.dbpass

  remotegen   = options.remotegen

  gmdhost     = options.gmdhost
  gmdport     = options.gmdport

  run_on_gpu  = options.run_on_gpu
  task_id     = options.task_id
  worker_name = options.worker_name

  worker      = CustomGearmanWorker(["{0}:{1}".format(gmdhost,gmdport)])
  worker.set_client_id(options.client_id)
  worker.register_task(task_id, process_work)

  hostname    = socket.gethostname()
  conn = mddb_utils.get_dbconn(dbname, dbuser, dbhost, dbpass)

  cur = conn.cursor()
  sys.stdout.flush()
  #cur.execute(st)
  cur.close()
  conn.commit()
  conn.close()
  worker.work()