Beispiel #1
0
def test_ired_simple_for_coverage():
    '''
    '''
    traj = pt.iterload(traj_dir, parm_dir)
    h_indices = pt.select_atoms('@H', traj.top)
    n_indices = pt.select_atoms('@H', traj.top) - 1
    nh_indices = list(zip(n_indices, h_indices))
    vecs_and_mat = pt.ired_vector_and_matrix(traj, nh_indices, dtype='tuple')
    vecs_and_mat = pt.ired_vector_and_matrix(traj, nh_indices, dtype='tuple')
    state_vecs = vecs_and_mat[0]
    mat_ired = vecs_and_mat[1]

    # get eigenvalues and eigenvectors
    modes = pt.matrix.diagonalize(mat_ired, n_vecs=len(state_vecs))
    evals, evecs = modes

    data_0 = _ired(
        state_vecs, modes=(evals, evecs), NHbond=True, tcorr=10000, tstep=1.)

    data_1 = _ired(state_vecs, modes=modes, NHbond=True, tcorr=10000, tstep=1)

    for d0, d1 in zip(data_0, data_1):
        if d0.dtype not in [
                'modes',
        ]:
            aa_eq(d0.values, d1.values)
        else:
            # modes
            # values: tuple
            aa_eq(d0.values[0], d1.values[0])
            aa_eq(d0.values[1], d1.values[1])

    # try different dtype
    out_try_new_dtype = pt.ired_vector_and_matrix(
        traj, nh_indices, dtype='cpptraj_dataset')
Beispiel #2
0
def test_ired_need_lapack_cpptraj():
    state = pt.load_cpptraj_state(txt)
    state.run()
    xyz = state.data['CRD1'].xyz
    top = state.data['CRD1'].top
    traj = pt.Trajectory(xyz=xyz, top=top)
    state_vecs = state.data[1:-3].values

    h_indices = pt.select_atoms('@H', traj.top)
    n_indices = pt.select_atoms('@H', traj.top) - 1
    nh_indices = list(zip(n_indices, h_indices))
    mat_ired = pt.ired_vector_and_matrix(traj, mask=nh_indices, order=2)[-1]
    mat_ired /= mat_ired[0, 0]

    # matired: make sure to reproduce cpptraj output
    aa_eq(mat_ired, state.data['matired'].values)

    # get modes
    modes = state.data[-2]
    cpp_eigenvalues = modes.eigenvalues
    cpp_eigenvectors = modes.eigenvectors
    evals, evecs = np.linalg.eigh(mat_ired)

    # need to sort a bit
    evals = evals[::-1]
    # cpptraj's eigvenvalues
    aa_eq(evals, cpp_eigenvalues)

    # cpptraj's eigvenvectors
    # use absolute values to avoid flipped sign
    # from Dan Roe
    # In practice, the "sign" of an eigenvector depends on the math library used to calculate it.
    # This is in fact why the modes command displacement test is disabled for cpptraj.
    # I bet if you use a different math library (e.g. use your system BLAS/LAPACK instead of the one bundled with Amber
    # or vice versa) you will get different signs.
    # Bottom line is that eigenvector sign doesn't matter.

    aa_eq(np.abs(evecs[:, ::-1].T), np.abs(cpp_eigenvectors), decimal=4)
    data = _ired(state_vecs, modes=(cpp_eigenvectors, cpp_eigenvalues))
    order_s2 = data['IRED_00127[S2]']

    # load cpptraj's output and compare to pytraj' values for S2 order paramters
    cpp_order_s2 = np.loadtxt(
        os.path.join(cpptraj_test_dir, 'Test_IRED', 'orderparam.save')).T[-1]
    aa_eq(order_s2, cpp_order_s2, decimal=5)