Exemplo n.º 1
0
def test_timecorr():

    with tempfolder():
        # center of mass
        trajin = """
        parm {}
        trajin {}
        vector center v0
        timecorr vec1 v0
        """.format(tc5b_top, tc5b_trajin)

        state = pt.load_cpptraj_state(trajin)
        state.run()
        cpptraj_output = state.data

        traj = pt.iterload(tc5b_trajin, tc5b_top)
        dslist0 = pt.center_of_mass(traj)
        data = pt.timecorr(dslist0, dslist0)
        aa_eq(data, cpptraj_output[-1].values)

        # 2 vectors
        cm = """
        parm {}
        trajin {}
        vector v0 :2 :5
        vector v1 :3 :7
        timecorr vec1 v0 vec2 v1
        """.format(tc5b_top, tc5b_trajin)
        state = pt.load_cpptraj_state(cm)
        state.run()
        cpptraj_output = state.data

        dslist0 = pt.vector.vector(traj, [':2 :5', ':3 :7'])
        data = pt.timecorr(dslist0[0], dslist0[1])
        aa_eq(data, cpptraj_output[-1].values)

        # corrplane
        cm = """
        parm {}
        trajin {}
        vector v0 @2,@5,@9 corrplane
        vector v1 @3,@7,@20 corrplane
        timecorr vec1 v0 vec2 v1
        """.format(tc5b_top, tc5b_trajin)

        state = pt.load_cpptraj_state(cm)
        state.run()
        cpptraj_output = state.data

        dslist0 = pt.vector.vector(traj,
                                 ['@2,@5,@9 corrplane', '@3,@7,@20 corrplane'])
        dslist1 = pt.vector.corrplane(traj, ['@2,@5,@9', '@3,@7,@20'])
        data0 = pt.timecorr(dslist0[0], dslist0[1])
        data1 = pt.timecorr(dslist1[0], dslist1[1])
        aa_eq(data0, cpptraj_output[-1].values)
        aa_eq(data1, cpptraj_output[-1].values)
Exemplo n.º 2
0
    def test_0(self):

        # center of mass
        trajin = """
        parm data/Tc5b.top
        trajin data/Tc5b.x
        vector center v0
        timecorr vec1 v0
        """

        state = pt.load_cpptraj_state(trajin)
        state.run()
        cpptraj_output = state.data

        traj = pt.iterload("./data/Tc5b.x", "./data/Tc5b.top")
        dslist0 = pt.center_of_mass(traj)
        data = pt.timecorr(dslist0, dslist0)
        aa_eq(data, cpptraj_output[-1].values)

        # 2 vectors
        cm = """
        parm data/Tc5b.top
        trajin data/Tc5b.x
        vector v0 :2 :5
        vector v1 :3 :7
        timecorr vec1 v0 vec2 v1
        """
        state = pt.load_cpptraj_state(cm)
        state.run()
        cpptraj_output = state.data

        dslist0 = pt.calc_vector(traj, [':2 :5', ':3 :7'])
        data = pt.timecorr(dslist0[0], dslist0[1])
        aa_eq(data, cpptraj_output[-1].values)

        # corrplane
        cm = """
        parm data/Tc5b.top
        trajin data/Tc5b.x
        vector v0 @2,@5,@9 corrplane
        vector v1 @3,@7,@20 corrplane
        timecorr vec1 v0 vec2 v1
        """

        state = pt.load_cpptraj_state(cm)
        state.run()
        cpptraj_output = state.data

        dslist0 = pt.calc_vector(traj,
                                 ['@2,@5,@9 corrplane', '@3,@7,@20 corrplane'])
        dslist1 = pt.vector.corrplane(traj, ['@2,@5,@9', '@3,@7,@20'])
        data0 = pt.timecorr(dslist0[0], dslist0[1])
        data1 = pt.timecorr(dslist1[0], dslist1[1])
        aa_eq(data0, cpptraj_output[-1].values)
        aa_eq(data1, cpptraj_output[-1].values)
Exemplo n.º 3
0
    def test_0(self):

        # center of mass
        trajin = """
        parm data/Tc5b.top
        trajin data/Tc5b.x
        vector center v0
        timecorr vec1 v0
        """

        state = pt.load_cpptraj_state(trajin)
        state.run()
        cpptraj_output = state.data

        traj = pt.iterload("./data/Tc5b.x", "./data/Tc5b.top")
        dslist0 = pt.center_of_mass(traj)
        data = pt.timecorr(dslist0, dslist0)
        aa_eq(data, cpptraj_output[-1].values)

        # 2 vectors
        cm = """
        parm data/Tc5b.top
        trajin data/Tc5b.x
        vector v0 :2 :5
        vector v1 :3 :7
        timecorr vec1 v0 vec2 v1
        """
        state = pt.load_cpptraj_state(cm)
        state.run()
        cpptraj_output = state.data

        dslist0 = pt.calc_vector(traj, [':2 :5', ':3 :7'])
        data = pt.timecorr(dslist0[0], dslist0[1])
        aa_eq(data, cpptraj_output[-1].values)

        # corrplane
        cm = """
        parm data/Tc5b.top
        trajin data/Tc5b.x
        vector v0 @2,@5,@9 corrplane
        vector v1 @3,@7,@20 corrplane
        timecorr vec1 v0 vec2 v1
        """

        state = pt.load_cpptraj_state(cm)
        state.run()
        cpptraj_output = state.data

        dslist0 = pt.calc_vector(traj,
                                 ['@2,@5,@9 corrplane', '@3,@7,@20 corrplane'])
        dslist1 = pt.vector.corrplane(traj, ['@2,@5,@9', '@3,@7,@20'])
        data0 = pt.timecorr(dslist0[0], dslist0[1])
        data1 = pt.timecorr(dslist1[0], dslist1[1])
        aa_eq(data0, cpptraj_output[-1].values)
        aa_eq(data1, cpptraj_output[-1].values)
Exemplo n.º 4
0
Arquivo: noe.py Projeto: n-salvi/adaMD
 def calcACFreff(self):
     self.ACFreff = dict()
     #self.test=dict()
     for (r1, a1), (r2, a2) in zip(self.list1, self.list2):
         label = str(r1) + a1 + ':' + str(r2) + a2
         first_in_seq = list(self.traj.top.residues)[0].index
         idx1 = pt.select_atoms(
             searchAT[a1] + ' & :' + str(r1 - first_in_seq), self.traj.top)
         idx2 = pt.select_atoms(
             searchAT[a2] + ' & :' + str(r2 - first_in_seq), self.traj.top)
         pairs = list(map(list, product(idx1, idx2)))
         data_vec = va.vector_mask(self.traj, pairs, dtype='ndarray')
         if len(data_vec.shape) < 3:
             data_vec = [data_vec]
         self.ACFreff[label] = [
             pt.timecorr(vals,
                         vals,
                         order=2,
                         tstep=1,
                         tcorr=len(vals),
                         norm=False,
                         dtype='ndarray') for vals in data_vec
         ]
         #for testing only: calculate the ACF without pytraj.timecorr
         #self.test[label] = []
         #for vals in data_vec:
         #vals2 = np.array([unit_vector(v) for v in vals])
         #x = vals2[:, 0]
         #y = vals2[:, 1]
         #z = vals2[:, 2]
         #x2 = mycorrelate2(x**2, norm=False)
         #y2 = mycorrelate2(y**2, norm=False)
         #z2 = mycorrelate2(z**2, norm=False)
         #xy = mycorrelate2(x*y, norm=False)
         #yz = mycorrelate2(y*z, norm=False)
         #xz = mycorrelate2(x*z, norm=False)
         #tot = (x2+y2+z2+2*xy+2*xz+2*yz)
         #tot /= tot[0]
         #tot = 1.5*(tot)-.5
         dump(self.ACFreff, open(get_today() + '-ACFreff.pkl', 'wb'))
Exemplo n.º 5
0
    def __init__(self,
                 top,
                 trajs,
                 rotfit=False,
                 mask='@CA',
                 stride=1,
                 n_blocks=1,
                 bframes=50000,
                 skip=25000):
        #read sequence
        if trajs[0][-3:] == 'dcd':
            traj = pt.iterload(trajs[0], top)
        else:
            #filename, top_name = get_fn(trajs[0]), get_fn(top)
            m_traj = md.load(trajs[0], top=top)
            traj = pt.Trajectory(xyz=m_traj.xyz.astype('f8'), top=top)
        self.sequence = {res.index + 1: res.name for res in traj.top.residues}
        self.top = top
        self.trajs = trajs
        n_frames = len(traj)

        self.n_indices = pt.select_atoms('@N & !(:1) & !(:PRO)', traj.top)
        self.h_indices = self.n_indices + 1
        self.nh_pairs = np.array(list(zip(self.n_indices, self.h_indices)))

        res_list = sorted(
            [k for k, val in self.sequence.items() if val != 'PRO' and k != 1])

        self.acf = dict()
        self.S2 = dict()

        if n_blocks == 1:
            for tt, t in enumerate(self.trajs):
                if t[-3:] == 'dcd':
                    traj = pt.load(t, top, stride=stride)
                else:
                    #filename, top_name = get_fn(t), get_fn(top)
                    m_traj = md.load(t, top=top)
                    traj = pt.Trajectory(xyz=m_traj.xyz.astype('f8'), top=top)
                if rotfit == True:
                    #print('RMSD fitting on '+mask)
                    _ = traj.superpose(ref=-1, mask='@CA')
                data_vec = va.vector_mask(traj, self.nh_pairs, dtype='ndarray')
                self.acf[tt] = {
                    res_list[n]: pt.timecorr(vals,
                                             vals,
                                             order=2,
                                             tstep=1,
                                             tcorr=len(vals),
                                             norm=False,
                                             dtype='ndarray')
                    for n, vals in enumerate(data_vec)
                }
                self.S2[tt] = {
                    res_list[n]: S2(vals)
                    for n, vals in enumerate(data_vec)
                }
        else:
            index = 0
            bcount = 0
            for tt, t in enumerate(self.trajs):
                print(tt + 1, '/', len(self.trajs))
                while bcount < n_blocks:
                    first_frame = bcount * skip
                    last_frame = first_frame + bframes
                    if t[-3:] == 'dcd':
                        traj = pt.load(t,
                                       top,
                                       frame_indices=slice(
                                           first_frame, last_frame, stride))
                    else:
                        #filename, top_name = get_fn(t), get_fn(top)
                        m_traj = md.load(t, top=top)
                        m_traj = m_traj[first_frame:last_frame:stride]
                        traj = pt.Trajectory(xyz=m_traj.xyz.astype('f8'),
                                             top=top)
                    if rotfit == True:
                        _ = traj.superpose(ref=-1, mask='@CA')
                    data_vec = va.vector_mask(traj,
                                              self.nh_pairs,
                                              dtype='ndarray')
                    self.acf[index] = {
                        res_list[n]: pt.timecorr(vals,
                                                 vals,
                                                 order=2,
                                                 tstep=1,
                                                 tcorr=len(vals),
                                                 norm=False,
                                                 dtype='ndarray')
                        for n, vals in enumerate(data_vec)
                    }
                    self.S2[index] = {
                        res_list[n]: S2(vals)
                        for n, vals in enumerate(data_vec)
                    }
                    bcount += 1
                    index += 1
                bcount = 0