Beispiel #1
0
    def test_center(self):
        traj = pt.iterload(fn('tz2.ortho.nc'), fn('tz2.ortho.parm7'))
        pt.load(fn("tz2.center_mass.nc"), traj.top)

        fa = traj[:]
        fa2 = traj[:].copy()
        pt.center(fa, mask=':1', mass=True)
        aa_eq(fa.xyz, fa.xyz, decimal=5)

        # raise if center not in 'origin', 'box'
        with pytest.raises(ValueError):
            pt.center(fa, center='oh')

        # center to point

        pt.center(fa, ':1', center=[0, 1, 2], mass=True)
        aa_eq(pt.center_of_mass(fa, ':1')[0], [0, 1, 2])

        pt.center(fa, ':1', center=[0, 1, 2], mass=False)
        aa_eq(pt.center_of_geometry(fa, ':1')[0], [0, 1, 2])

        fa2.center(':1', center=[0, 1, 2], mass=False)
        aa_eq(pt.center_of_geometry(fa2, ':1')[0], [0, 1, 2])

        # on_disk
        traj_on_disk = pt.iterload(fn('tz2.ortho.nc'), fn('tz2.ortho.parm7'))
        pt.center(traj_on_disk, ':1', center=[0, 1, 2], mass=True)
        aa_eq(pt.center_of_mass(traj_on_disk, ':1')[0], [0, 1, 2])
    def test_0(self):
        import numpy as np

        traj = pt.iterload(fn('Tc5b.x'), fn('Tc5b.top'))
        traj2 = traj[:]
        d1 = pt.calc_center_of_mass(traj, dtype='dataset')
        d2 = pt.calc_center_of_mass(traj2, dtype='dataset')

        for frame in traj:
            pass

        saved_d0 = np.loadtxt(fn('vec.out'), skiprows=1, usecols=(1, 2, 3))

        aa_eq(d1.to_ndarray().flatten(), saved_d0.flatten())
        aa_eq(d2.to_ndarray().flatten(), saved_d0.flatten())

        aa_eq(pt.center_of_geometry(traj, dtype='ndarray'),
              pt.center_of_geometry(traj2, dtype='ndarray'))
    def test_0(self):
        import numpy as np

        traj = pt.iterload("./data/Tc5b.x", "./data/Tc5b.top")
        traj2 = traj[:]
        d1 = pt.calc_center_of_mass(traj, dtype='dataset')
        d2 = pt.calc_center_of_mass(traj2, dtype='dataset')

        for frame in traj:
            pass

        saved_d0 = np.loadtxt("./data/vec.out", skiprows=1, usecols=(1, 2, 3))

        aa_eq(d1.to_ndarray().flatten(), saved_d0.flatten())
        aa_eq(d2.to_ndarray().flatten(), saved_d0.flatten())

        aa_eq(
            pt.center_of_geometry(traj,
                                  dtype='ndarray'),
            pt.center_of_geometry(traj2,
                                  dtype='ndarray'))
import pytraj as pt

# use load method to load all frames to memory
traj = pt.load("../tests/data/Tc5b.x", "../tests/data/Tc5b.top")

# compute center of geometry for residue 1, use all atoms
mask0 = ':1'
cog_0 = pt.center_of_geometry(traj, mask=mask0)
# should be ndarray, shape=(n_frames, 3)
print(cog_0)

# compute center of geometry for residue 1, exclude H atoms
mask1 = ':1&!:1@H='
print(set(atom.name for atom in traj.top[mask1].atoms)
      )  # should get {'OD1', 'CA', 'ND2', 'CB', 'O', 'C', 'N', 'CG'
cog_1 = pt.center_of_geometry(traj, mask=mask1)
print(cog_1)

# compute center of geometry for residue 1, 3, 5 and use all atoms
mask2 = ':1,3,5'
print(set(atom.name for atom in traj.top[mask2].atoms))
cog_2 = pt.center_of_geometry(traj, mask=mask2)
print(cog_2)

# compute center of geometry for residue 1, 3, 5 and use only CA atoms
mask3 = ':1,3,5@CA'
print(set(atom.name for atom in traj.top[mask3].atoms))  # should get {'@CA'}
cog_3 = pt.center_of_geometry(traj, mask=mask3)
print(cog_3)