Пример #1
0
    def test_mass(self):
        traj = self.traj
        # cpptraj output
        cm = '''
        reference avg.pdb
        rms R0 reference @CA,C,N,O savematrices mass
        '''

        state = pt.load_batch(traj, cm)
        state.run()
        saved_mat = state.data[-1].values

        # pytraj output
        avg = pt.mean_structure(traj)
        mat = pt.calc_rotation_matrix(traj,
                                      ref=avg,
                                      mask='@CA,C,N,O',
                                      mass=True)
        assert mat.shape == (traj.n_frames, 3, 3), 'mat shape'
        aa_eq(mat.flatten(), saved_mat.flatten())

        # with rmsd
        avg = pt.mean_structure(traj)
        mat2, rmsd_ = pt.calc_rotation_matrix(traj,
                                              ref=avg,
                                              mask='@CA,C,N,O',
                                              mass=True,
                                              with_rmsd=True)
        aa_eq(mat2.flatten(), saved_mat.flatten())
        assert pt.tools.rmsd(rmsd_, state.data['R0']) < 1E-3
Пример #2
0
    def test_nomass(self):
        traj = self.traj
        # cpptraj output
        cm = '''
        reference avg.pdb
        rms R0 reference @CA,C,N,O savematrices
        '''

        state = pt.load_batch(traj, cm)
        state.run()
        saved_mat = state.data[-1].values

        # pytraj output
        avg = pt.mean_structure(traj)
        mat = pt.calc_rotation_matrix(traj, ref=avg, mask='@CA,C,N,O')
        assert mat.shape == (traj.n_frames, 3, 3), 'mat shape'
        aa_eq(mat.flatten(), saved_mat.flatten())

        # not specify reference
        cm = '''
        rms R0 @CA,C,N,O savematrices
        '''
        state = pt.load_batch(traj, cm)
        state.run()
        saved_mat = state.data[-1].values
        mat = pt.calc_rotation_matrix(traj, mask='@CA,C,N,O')
        aa_eq(mat.flatten(), saved_mat.flatten())
Пример #3
0
    def test_DatasetMatrix3x3(self):
        # test _append_from_array
        mat0 = pt.calc_rotation_matrix(self.traj, ref=0)

        shape2d = (mat0.shape[0], mat0.shape[1] * mat0.shape[2])
        dmat3x3 = c_datasets.DatasetMatrix3x3()
        dmat3x3._append_from_array(mat0.reshape(shape2d))
        aa_eq(mat0, dmat3x3.values)
Пример #4
0
    def test_DatasetMatrix3x3(self):
        # test _append_from_array
        mat0 = pt.calc_rotation_matrix(self.traj, ref=0)

        shape2d = (mat0.shape[0], mat0.shape[1] * mat0.shape[2])
        dmat3x3 = c_datasets.DatasetMatrix3x3()
        dmat3x3._append_from_array(mat0.reshape(shape2d))
        aa_eq(mat0, dmat3x3.values)
Пример #5
0
    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)
Пример #6
0
    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)