def test_DatasetDouble(self): dslist = CpptrajDatasetList() d = dslist.add_new(dtype='double') a = range(8) # append for i in a: d.append(i) aa_eq(a, d) assert int(d[2]) == a[2] == 2, 'must be equal'
def test_DatasetDouble(self): dslist = CpptrajDatasetList() d = dslist.add_new(dtype='double') a = range(8) # append for i in a: d.append(i) aa_eq(a, d) assert int(d[2]) == a[2] == 2, 'must be equal'
def test_add_new_for_CpptrajDatasetList(self): # TODO: dslist = CpptrajDatasetList() # integer dslist.add_new(dtype='integer', name='my_int') dslist[-1].data = [2, 3] aa_eq(dslist[-1].values, [2, 3]) # double dslist.add_new(dtype='double', name='my_double') dslist[-1].data = [2, 3] aa_eq(dslist[-1].values, [2, 3]) # float dslist.add_new(dtype='float', name='my_float') dslist[-1].data = [2, 3] aa_eq(dslist[-1].values, [2, 3]) # string dslist.add_new(dtype='string', name='my_string') dslist[-1].data = ['H', 'T'] assert dslist[-1].values.tolist() == ['H', 'T'], 'string must be equal' # reference dslist.add_new(dtype='reference', name='my_reference') dslist[-1].data = self.traj[-2] aa_eq(dslist[-1].xyz, self.traj[-2].xyz) # matrix3x3 dslist.add_new(dtype='matrix3x3', name='my_mat3x3') mat = pt.calc_rotation_matrix(self.traj, ref=0, mask='@CA') # there is no assignment. Need to update by another method dslist[-1]._append_from_array(mat) aa_eq(dslist[-1].values, mat) # TRAJ dslist.add_new(dtype='traj', name='my_traj') dslist[-1].top = self.traj.top dslist[-1]._load(self.traj.filename) traj_new = dslist[-1] # FIXME: segmentation fault # CRD dslist.add_new(dtype='coords', name='my_crd') dslist[-1].top = self.traj.top dslist[-1].load(self.traj.filename) traj_new = dslist[-1] aa_eq(traj_new.xyz, self.traj.xyz) aa_eq(pt.rmsd(traj_new), pt.rmsd(self.traj)) # vector dslist.add_new(dtype='vector', name='my_vec') vecs = pt.vector.vector_mask(self.traj, ':3 :2') dslist[-1].data = vecs aa_eq(dslist[-1].values, vecs) # grid dslist.add_new(dtype='grid', name='my_grid') arr = np.random.rand(8, 9, 3).astype('f4') dslist[-1].data = arr aa_eq(dslist[-1].values, arr) # mesh dslist.add_new(dtype='xymesh', name='my_mesh') arr = np.random.rand(8, 2).astype('f8') # there is not easy method to update, use _append_from_array dslist[-1]._append_from_array(arr) aa_eq(dslist[-1].values, arr) # modes mat = pt.matrix.covar(self.traj, '@CA') modes = pt.matrix.diagonalize(mat, n_vecs=mat.shape[0], dtype='dataset')[0] modes2 = modes.__class__() # dummy test to set name and scalar_type # (prepare for pca) modes2.name = 'test_mode' modes2.scalar_type = 'covar' modes2._set_modes(False, mat.shape[0], modes.eigenvectors.shape[0], modes.eigenvalues, modes.eigenvectors.flatten()) aa_eq(modes.eigenvalues, modes2.eigenvalues) aa_eq(modes.eigenvectors, modes2.eigenvectors)
def test_add_new_for_CpptrajDatasetList(self): # TODO: dslist = CpptrajDatasetList() # integer dslist.add_new(dtype='integer', name='my_int') dslist[-1].data = [2, 3] aa_eq(dslist[-1].values, [2, 3]) # double dslist.add_new(dtype='double', name='my_double') dslist[-1].data = [2, 3] aa_eq(dslist[-1].values, [2, 3]) # float dslist.add_new(dtype='float', name='my_float') dslist[-1].data = [2, 3] aa_eq(dslist[-1].values, [2, 3]) # string dslist.add_new(dtype='string', name='my_string') dslist[-1].data = ['H', 'T'] assert dslist[-1].values.tolist() == ['H', 'T'], 'string must be equal' # reference dslist.add_new(dtype='reference', name='my_reference') dslist[-1].data = self.traj[-2] aa_eq(dslist[-1].xyz, self.traj[-2].xyz) # matrix3x3 dslist.add_new(dtype='matrix3x3', name='my_mat3x3') mat = pt.calc_rotation_matrix(self.traj, ref=0, mask='@CA') # there is no assignment. Need to update by another method dslist[-1]._append_from_array(mat) aa_eq(dslist[-1].values, mat) # TRAJ dslist.add_new(dtype='traj', name='my_traj') dslist[-1].top = self.traj.top dslist[-1]._load(self.traj.filename) traj_new = dslist[-1] # FIXME: segmentation fault # CRD dslist.add_new(dtype='coords', name='my_crd') dslist[-1].top = self.traj.top dslist[-1].load(self.traj.filename) traj_new = dslist[-1] aa_eq(traj_new.xyz, self.traj.xyz) aa_eq(pt.rmsd(traj_new), pt.rmsd(self.traj)) # vector dslist.add_new(dtype='vector', name='my_vec') vecs = pt.vector.vector_mask(self.traj, ':3 :2') dslist[-1].data = vecs aa_eq(dslist[-1].values, vecs) # grid dslist.add_new(dtype='grid', name='my_grid') arr = np.random.rand(8, 9, 3).astype('f4') dslist[-1].data = arr aa_eq(dslist[-1].values, arr) # mesh dslist.add_new(dtype='xymesh', name='my_mesh') arr = np.random.rand(8, 2).astype('f8') # there is not easy method to update, use _append_from_array dslist[-1]._append_from_array(arr) aa_eq(dslist[-1].values, arr) # modes mat = pt.matrix.covar(self.traj, '@CA') modes = pt.matrix.diagonalize(mat, n_vecs=mat.shape[0], dtype='dataset')[0] modes2 = modes.__class__() # dummy test to set name and scalar_type # (prepare for pca) modes2.name = 'test_mode' modes2.scalar_type = 'covar' modes2._set_modes(False, mat.shape[0], modes.eigenvectors.shape[0], modes.eigenvalues, modes.eigenvectors.flatten()) aa_eq(modes.eigenvalues, modes2.eigenvalues) aa_eq(modes.eigenvectors, modes2.eigenvectors)