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)
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)
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()
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()
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()
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()
def result_exists(conn, tn, r_id, c_id, p_id, chargeset, tautomers): stm = "select 1 from {0} where receptor_id = {1} and compound_id = {2} and pose_id = {3} and chargeset_id = {4} and tautomers = {5}".format(tn, r_id, c_id, p_id, chargeset, tautomers) return mddb_utils.execute_query(conn, stm) != None