def test_rna_frame1to10_frame10(self): ''' test a dcd based on a rna molecule of 10 frames write the 10th frame ''' # # # pdbFileName = DataPath + 'rna-1to10.pdb' dcdFileName = moduleDataPath + 'test-results/rna-1to10-writedcd_step-test.dcd' # nnatoms = 1 frame = 9 step = 1 self.o.read_pdb(pdbFileName) #fp=dcdio.open_dcd_write(dcdFileName) #self.o.write_dcd_header(fp, nnatoms) fp = self.o.open_dcd_write(dcdFileName) self.o.write_dcd_step(fp, frame, step) dcdio.close_dcd_write(fp) # otest = system.Molecule(0) otest.read_dcd(dcdFileName) result_coor = otest.coor() sum_result_coor = sum(sum(sum(result_coor))) print '\nresult_coor \n', result_coor self.assertEqual(len(result_coor[0]), 10632) expected_sample_coor = numpy.array([-6.392, 14.348, 20.914], floattype) sum_expected_coor = -42837.531 self.assert_list_almost_equal(expected_sample_coor, result_coor[0][10631], self.prcsn) self.assertAlmostEqual(sum_result_coor, sum_expected_coor, self.prcsn) os.remove(dcdFileName)
def generate(fin='rna.pdb', fout='rna.dcd', frames=1000): path = os.path.dirname(os.path.realpath(__file__)) fin = os.path.join(path, '../', 'data', 'pdb_common', fin) if not os.path.exists(fin): raise Exception, fin + ' does not exist while generating huge rna dcd files' return #fout = os.path.join(path,'../','data','dcd_common',fout) fout = os.path.join('/tmp/', fout) if os.path.exists(fout): return o = system.Molecule(0) o.read_pdb(fin) outfile = dcdio.open_dcd_write(fout) nset = frames natoms = o._coor[0, :, 0].shape[0] istart = 0 nsavc = 1 delta = 1.0 o.write_dcd_header(outfile, frames) tx = o.coor()[0, :, 0].astype(np.float32) ty = o.coor()[0, :, 1].astype(np.float32) tz = o.coor()[0, :, 2].astype(np.float32) for i in range(frames): dcdio.write_dcdstep(outfile, tx, ty, tz, i + 1) o.close_dcd_write(outfile)
def main(pdb_fname, dcd_fname='', in_dir='', out_dir='', restart=False): ''' calculate the pair-distance distribution ''' full_pdb_fname = os.path.join(in_dir, pdb_fname) assert os.path.exists(full_pdb_fname), 'No such file: {}'.format( full_pdb_fname) mol = system.Molecule(full_pdb_fname) if dcd_fname: full_dcd_fname = os.path.join(in_dir, dcd_fname) assert os.path.exists(full_dcd_fname), 'No such file: {}'.format( full_dcd_fname) dcd_file = mol.open_dcd_read(full_dcd_fname) n_frames = dcd_file[2] out_prefix = dcd_fname[:-4] else: n_frames = 1 out_prefix = pdb_fname[:-4] if out_dir: mkdir_p(out_dir) out_prefix = os.path.join(out_dir, out_prefix) tic = time.time() n_start = 0 if restart: fnames = glob.glob(os.path.join(out_dir, '*.pr')) if fnames: fnames.sort() n_start = int(fnames[-1].replace('{}_'.format(out_prefix), '')[:-3]) for i in xrange(n_start): mol.read_dcd_step(dcd_file, i) for i in xrange(n_start, n_frames): mol.read_dcd_step(dcd_file, i) pr = calc_pr_numba(mol.coor()[0]) # output the result out_fname = '{}_{:05d}.pr'.format(out_prefix, i + 1) np.savetxt(out_fname, pr, fmt='%d', delimiter=',') toc = time.time() - tic if n_start < n_frames: logging.info('calculated P(r) for {} structures in {} s'.format( n_frames - n_start, toc)) logging.info('{} s for each structure'.format(toc / (n_frames - n_start))) else: logging.info('Output already exists. To recalculate, ' 'run using `restart=False``') mol.close_dcd_read(dcd_file[0])
def setUp(self): self.centertmp = operate.Move.center self.m = Mocker() operate.Move.center = self.m.mock() operate.Move.center(ARGS) self.m.result(None) self.m.count(0, None) self.m.replay() self.o = system.Molecule(0)
def test_id(self): ''' test initializer with id ''' # id = 3 o = system.Molecule(id) self.assertEqual(o.id(), id) self.assertEqual(o.total_mass(), 0.0) self.assertEqual(o.natoms(), 0) self.assertEqual(o.mass(), None) self.assertEqual(o.coor(), None) self.assertEqual(o.com(), None)
def setUp(self): self.o = system.Molecule(0) charmm_names = self.o.charmm_names() hl = charmm_names['hydrogen'] cl = charmm_names['carbon'] nl = charmm_names['nitrogen'] ol = charmm_names['oxygen'] sl = charmm_names['sulfur'] pl = charmm_names['phosphorus'] otherl = charmm_names['other'] (self.hl, self.cl, self.nl, self.ol, self.sl, self.pl, self.otherl) = (hl, cl, nl, ol, sl, pl, otherl)
def test_1CRN(self): ''' test a dcd from a small protein of crambin ''' # pdbFile = pdbDataPath + '1CRN.pdb' dcdFile = moduleDataPath + 'test-results/1CRN-writedcd.dcd' self.o.read_pdb(pdbFile) self.o.write_dcd(dcdFile) o1 = system.Molecule(0) o1.read_dcd(dcdFile) result_coor = o1.coor() sum_result_coor = sum(sum(sum(result_coor))) print '\nresult_coor \n', result_coor, '\nsum of result_coor\n', sum_result_coor os.remove(dcdFile) # self.assertEqual(len(result_coor[0]), 327) expected_sample_coor = numpy.array([9.555, 2.856, 3.730], floattype) sum_expected_coor = 8509.587 self.assert_list_almost_equal(expected_sample_coor, result_coor[0][100], self.prcsn) self.assertAlmostEqual(sum_result_coor, sum_expected_coor, self.prcsn)
def test_2AAD_frame1(self): ''' test a dcd with 3 frames based on a 2-aa pdb write the 1st frame ''' # pdbFileName = DataPath + '2AAD-1to3.pdb' dcdFileName = moduleDataPath + 'test-results/2AAD-1to3-writedcd_step-test.dcd' # nnatoms = 1 frame = 0 step = 1 self.o.read_pdb(pdbFileName) #fp=dcdio.open_dcd_write(dcdFileName) #self.o.write_dcd_header(fp, nnatoms) fp = self.o.open_dcd_write(dcdFileName) self.o.write_dcd_step(fp, frame, step) dcdio.close_dcd_write(fp) # otest = system.Molecule(0) otest.read_dcd(dcdFileName) result_coor = otest.coor() sum_result_coor = sum(sum(sum(result_coor))) print '\nresult_coor\n', result_coor expected_coor = numpy.array( [[[73.944, 41.799, 41.652], [74.229, 42.563, 40.456], [75.667, 43.093, 40.463], [76.264, 43.279, 39.401], [73.210, 43.734, 40.336], [71.856, 43.168, 39.926], [73.677, 44.782, 39.354], [70.721, 44.177, 39.946], [76.231, 43.330, 41.647], [77.592, 43.852, 41.730], [78.617, 42.820, 42.184], [79.712, 43.169, 42.656], [77.671, 45.097, 42.648], [77.054, 44.816, 43.910], [76.970, 46.273, 42.000]]], floattype) sum_expected_coor = 2407.676 self.assert_list_almost_equal(expected_coor, result_coor, self.prcsn) self.assertAlmostEqual(sum_result_coor, sum_expected_coor, self.prcsn) os.remove(dcdFileName)
def setUp(self): self.o1 = system.Molecule(0) self.o2 = system.Molecule(0) self.o1Sub = system.Molecule(0) self.o2Sub = system.Molecule(0)
def setUp(self): self.o = system.Molecule(0) (self.protein, self.dna, self.rna, self.nucleic, self.water) = self.o.get_resnames()
def setUp(self): self.o = system.Molecule(0) self.amino_acid_sld = self.o.amino_acid_sld()
def setUp(self): self.o=system.Molecule(0) self.standard_atomic_weight = self.o.amu()