def load_trajectories(conn, ss_id, param_dict): e_id = execute_query(conn, """select expjobs_insert({0}, Null, Null, Null, Null, Null)""".format(ss_id)) trj_list_fn = os.path.join(param_dict['trj_dir'], param_dict['trj_list_fn']) pdb_fn = os.path.join(param_dict['pdb_dir'], param_dict['pdb_fn']) with open(trj_list_fn, 'r') as ifp: fn_list = ifp.readlines() fn_list = map(lambda t: t.split(',')[1].rstrip(), fn_list) for dcd_fn in fn_list: trj_id = execute_query(conn, """select trajectories_insert({0}, Null, Null, Null, Null)""".format(e_id)) trj_fn = os.path.join(param_dict['trj_dir'], dcd_fn) step = 1 l = mddb_parser.get_trjectory_length(pdb_fn, trj_fn) chunk_size = 10 num_chunks = int(math.ceil(float(l)/chunk_size)) cur = conn.cursor() for i in xrange(0, num_chunks): start = i * chunk_size stop = min(start + chunk_size, l) print "trj_id: ", trj_id, " range: ", start, "->", stop \ ," total: ", l, " time: ", datetime.datetime.now() st_io = mddb_parser.parse_trajectory_range_to_buffer(trj_id, pdb_fn, trj_fn, start, stop, step) cur = conn.cursor() cur.copy_from(st_io, 'AtomPositions', columns=('trj_id', 't', 'atom_id', 'x', 'y', 'z')) cur.close() conn.commit() return
def load(self, conn, result_dir, d, local_paths): d['prefix'] = result_dir out_fns = self.__class__.get_output_fns(d) trj_id = d['trj_id'] e_id = d['e_id'] sim_fn = out_fns['sim_fn'] trj_fn = out_fns['trj_fn'] nrg_fn = out_fns['nrg_fn'] vel_fn = out_fns.get('vel_fn') print "simulation file: ", sim_fn print "trajectory file: ", trj_fn ap_t_name = 'trj_{0}_ap'.format(trj_id) pf_t_name = 'trj_{0}_pf'.format(trj_id) step = 1 l = mddb_parser.get_trjectory_length(sim_fn, trj_fn) chunk_size = 100000 num_chunks = int(math.ceil(float(l)/chunk_size)) cur = conn.cursor() for i in xrange(0, num_chunks): start = i * chunk_size stop = min(start + chunk_size, l) print "trj_id: ", trj_id, " range: ", start, "->", stop \ ," total: ", l, " time: ", datetime.datetime.now() crd_st_io = mddb_parser.parse_trajectory_range_to_buffer(trj_id, sim_fn, trj_fn, start, stop, step) if vel_fn and os.path.isfile(vel_fn): print "velocity file: ", vel_fn if os.path.splitext(vel_fn)[1] == '.dcd': self.__class__.reformat_velocity_dcd(vel_fn) vel_st_io = mddb_parser.parse_trajectory_range_to_buffer(trj_id, sim_fn, vel_fn, start, stop, step) if vel_st_io != None: cur.copy_from(vel_st_io, 'AtomVelocities', columns=('trj_id', 't', 'atom_id', 'x', 'y', 'z')) if crd_st_io == None: print "Empty string returned" return False st = "select create_NewAtomPositions_table(E'{0}', {1});".format(ap_t_name, trj_id) cur.execute(st) cur.copy_from(crd_st_io, ap_t_name, columns=('trj_id', 't', 'atom_id', 'x', 'y', 'z')) cur.execute('create index {0}Index on {0} (trj_id, t);'.format(ap_t_name)) cur.execute("select compute_features ({0}, E'{1}', E'{2}')".format(e_id, ap_t_name, pf_t_name)) cur.execute('insert into AtomPositions select * from {0}'.format(ap_t_name)) cur.execute('insert into ConformationSpace select * from {0}'.format(pf_t_name)) cur.execute("drop table if exists {0}".format(ap_t_name)) cur.execute("drop table if exists {0}".format(pf_t_name)) with open(nrg_fn, 'r') as ifp: table_width = len(ifp.readline().split()) ifp.seek(0) if table_width == 3: cur.copy_from(ifp, 'Energies', columns=('trj_id', 't', 'total')) elif table_width == 16: cur.copy_from(ifp, 'Energies', columns=('trj_id', 't', 'bond', 'angle', 'dihed', 'imprp', 'elect', 'vdw', 'boundary', 'misc', 'kinetic', 'total', 'temp', 'potential', 'total3', 'tempavg')) cur.close() conn.commit() return True