Example #1
0
    def test_0(self):
        # merge_coordinates
        pass

        # load 2 frames
        traj = pt.iterload(fn('Tc5b.x'), fn('Tc5b.top'), frame_slice=(0, 2))

        # test mutable traj
        coords = pt.tools.merge_coordinates(traj[:])
        r0 = pt.tools.rmsd(coords, pt.get_coordinates(traj), True)
        assert r0 == 0.

        # test immutable traj
        coords = pt.tools.merge_coordinates(traj)
        r0 = pt.tools.rmsd(coords, pt.get_coordinates(traj), True)
        assert r0 == 0.

        # test tuple
        coords = pt.tools.merge_coordinates((frame for frame in traj))
        r0 = pt.tools.rmsd(coords, pt.get_coordinates(traj), True)
        assert r0 == 0.

        coords = pt.tools.merge_coordinates([f.copy() for f in traj])
        r0 = pt.tools.rmsd(coords, pt.get_coordinates(traj), True)
        assert r0 == 0.
Example #2
0
    def test_0(self):
        # merge_coordinates
        import numpy as np

        # load 2 frames
        traj = pt.iterload("./data/Tc5b.x",
                           "./data/Tc5b.top",
                           frame_slice=(0, 2))

        # test mutable traj
        coords = pt.tools.merge_coordinates(traj[:])
        r0 = pt.tools.rmsd(coords, pt.get_coordinates(traj))
        assert r0 == 0.

        # test immutable traj
        coords = pt.tools.merge_coordinates(traj)
        r0 = pt.tools.rmsd(coords, pt.get_coordinates(traj), True)
        assert r0 == 0.

        # test tuple
        coords = pt.tools.merge_coordinates((frame for frame in traj))
        r0 = pt.tools.rmsd(coords, pt.get_coordinates(traj), True)
        assert r0 == 0.

        coords = pt.tools.merge_coordinates([f.copy() for f in traj])
        r0 = pt.tools.rmsd(coords, pt.get_coordinates(traj), True)
        assert r0 == 0.
Example #3
0
    def test_0(self):
        import numpy as np

        # load 2 frames
        traj = pt.iterload("./data/Tc5b.x",
                           "./data/Tc5b.top",
                           frame_slice=(0, 2))

        # test mutable traj
        big_frame = pt.tools.merge_frames(traj[:])
        assert pt.tools.rmsd(big_frame.xyz.flatten(),
                             pt.get_coordinates(traj).flatten()) < 1E-5

        # test immutable traj
        big_frame = pt.tools.merge_frames(traj)
        assert pt.tools.rmsd(big_frame.xyz.flatten(),
                             pt.get_coordinates(traj).flatten()) < 1E-5

        # test tuple
        big_frame = pt.tools.merge_frames((frame for frame in traj))
        assert pt.tools.rmsd(big_frame.xyz.flatten(),
                             pt.get_coordinates(traj).flatten()) < 1E-5

        # test list
        big_frame = pt.tools.merge_frames([frame.copy() for frame in traj])
        assert pt.tools.rmsd(big_frame.xyz.flatten(),
                             pt.get_coordinates(traj).flatten()) < 1E-5
Example #4
0
    def test_0(self):
        pass

        # load 2 frames
        traj = pt.iterload(fn('Tc5b.x'), fn('Tc5b.top'), frame_slice=(0, 2))

        # test mutable traj
        big_frame = pt.tools.merge_frames(traj[:])
        assert pt.tools.rmsd(big_frame.xyz.flatten(),
                             pt.get_coordinates(traj).flatten()) < 1E-5

        # test immutable traj
        big_frame = pt.tools.merge_frames(traj)
        assert pt.tools.rmsd(big_frame.xyz.flatten(),
                             pt.get_coordinates(traj).flatten()) < 1E-5

        # test tuple
        big_frame = pt.tools.merge_frames((frame for frame in traj))
        assert pt.tools.rmsd(big_frame.xyz.flatten(),
                             pt.get_coordinates(traj).flatten()) < 1E-5

        # test list
        big_frame = pt.tools.merge_frames([frame.copy() for frame in traj])
        assert pt.tools.rmsd(big_frame.xyz.flatten(),
                             pt.get_coordinates(traj).flatten()) < 1E-5
Example #5
0
def test_get_coordinates_trajectory():
    '''mutable pytraj.Trajectory
    '''
    traj = pt.Trajectory(xyz=traj_tz2_ortho.xyz, top=traj_tz2_ortho.top)
    # make a different copy since ``traj`` is mutable
    traj2 = traj.copy()

    # all coordinates
    xyz = pt.get_coordinates(traj)
    aa_eq(traj.xyz, xyz)

    # given frames
    xyz = pt.get_coordinates(traj, frame_indices=[0, 5])
    aa_eq(traj[[0, 5]].xyz, xyz)

    # given frames, autoimage=True
    xyz = pt.get_coordinates(traj, frame_indices=[0, 5], autoimage=True)
    aa_eq(traj2[[0, 5]].autoimage().xyz, xyz)

    # given frames, autoimage=True, rmsfit=ref
    ref = traj[-3]
    pt.autoimage(ref, top=traj.top)
    xyz = pt.get_coordinates(traj,
                             frame_indices=[0, 5],
                             autoimage=True,
                             rmsfit=ref)
    aa_eq(traj2[[0, 5]].autoimage().superpose(ref=ref).xyz, xyz)
Example #6
0
    def test_0(self):
        import numpy as np

        # load 2 frames
        traj = pt.iterload("./data/Tc5b.x",
                           "./data/Tc5b.top",
                           frame_slice=(0, 2))

        # test mutable traj
        big_frame = pt.tools.merge_frames(traj[:])
        assert pt.tools.rmsd(big_frame.xyz.flatten(),
                             pt.get_coordinates(traj).flatten()) < 1E-5

        # test immutable traj
        big_frame = pt.tools.merge_frames(traj)
        assert pt.tools.rmsd(big_frame.xyz.flatten(),
                             pt.get_coordinates(traj).flatten()) < 1E-5

        # test tuple
        big_frame = pt.tools.merge_frames((frame for frame in traj))
        assert pt.tools.rmsd(big_frame.xyz.flatten(),
                             pt.get_coordinates(traj).flatten()) < 1E-5

        # test list
        big_frame = pt.tools.merge_frames([frame.copy() for frame in traj])
        assert pt.tools.rmsd(big_frame.xyz.flatten(),
                             pt.get_coordinates(traj).flatten()) < 1E-5
Example #7
0
    def test_1(self):
        # merge_frames
        import numpy as np

        # load 2 frames
        traj = pt.iterload("./data/Tc5b.x",
                           "./data/Tc5b.top",
                           frame_slice=(0, 2))

        # test mutable traj
        t0 = traj[:]
        frame = pt.tools.merge_frames(t0)
        r0 = pt.tools.rmsd(frame.xyz, pt.get_coordinates(traj), True)
        assert r0 == 0.

        # test immutable traj
        assert np.any(pt.tools.merge_frames(traj).xyz.flatten() ==
                      pt.get_coordinates(traj).flatten())

        # tuple
        assert np.any(pt.tools.merge_frames((
            frame for frame in traj)).xyz.flatten() == pt.get_coordinates(
                traj).flatten())

        # list
        assert np.any(pt.tools.merge_frames(
            [frame for frame in traj]).xyz.flatten() == pt.get_coordinates(
                traj).flatten())

        # frame_iter: all atoms
        assert np.any(pt.tools.merge_frames(traj()).xyz.flatten() ==
                      pt.get_coordinates(traj()).flatten())
Example #8
0
    def test_pieline(self):
        traj = pt.iterload("./data/tz2.nc", "./data/tz2.parm7")

        fi = pt.pipe(traj, ['autoimage', ])
        aa_eq(pt.get_coordinates(fi), traj[:].autoimage().xyz)

        fi = pt.pipe(traj, ['autoimage', ], frame_indices=[3, 5])
        aa_eq(pt.get_coordinates(fi), traj[[3, 5]].autoimage().xyz)
Example #9
0
    def test_pieline(self):
        traj = pt.iterload(fn('tz2.nc'), fn('tz2.parm7'))

        fi = pt.pipe(traj, ['autoimage', ])
        aa_eq(pt.get_coordinates(fi), traj[:].autoimage().xyz)

        fi = pt.pipe(traj, ['autoimage', ], frame_indices=[3, 5])
        aa_eq(pt.get_coordinates(fi), traj[[3, 5]].autoimage().xyz)
Example #10
0
    def test_closest_compared_to_cpptraj(self):
        trajin = fn('tz2.ortho.nc')
        parm = fn('tz2.ortho.parm7')
        traj = pt.iterload(trajin, parm, frame_slice=[
            (0, 2),
        ])
        state = pt.load_cpptraj_state('''
        parm {}
        trajin {} 1 2
        autoimage
        closest 100 :1-13
        createcrd mycrd'''.format(parm, trajin))
        state.run()

        fi, top = pt.closest(traj(autoimage=True),
                             mask=':1-13',
                             n_solvents=100)
        xyz = pt.get_coordinates(fi)
        t0 = pt.Trajectory(xyz=xyz, top=top)
        aa_eq(state.data['mycrd'].xyz, t0.xyz)

        # dtype = 'trajectory'
        t1 = pt.closest(traj(autoimage=True),
                        mask=':1-13',
                        n_solvents=100,
                        dtype='trajectory')
        aa_eq(state.data['mycrd'].xyz, t1.xyz)
    def test_issue807(self):
        # files are provided by Chris Lee
        traj = pt.iterload("./data/issue807/trunc.nc",
                           "./data/issue807/system.prmtop")

        traj[0]
        for frame in traj:
            pass
        traj[::2]
        pt.radgyr(traj[[0, 3]])
        pt.radgyr(traj, frame_indices=[0, 3])
        pt.radgyr(traj())
        traj[:3, '@O'].xyz
        pt.get_coordinates((traj.iterframe(mask='@O')))
        pt.radgyr(traj(mask='@O'))
        for c in pt.iterchunk(traj, 4):
            assert c[0].n_atoms == traj.top.n_atoms
    def test_issue807(self):
        # files are provided by Chris Lee
        traj = pt.iterload("./data/issue807/trunc.nc",
                           "./data/issue807/system.prmtop")

        traj[0]
        for frame in traj:
            pass
        traj[::2]
        pt.radgyr(traj[[0, 3]])
        pt.radgyr(traj, frame_indices=[0, 3])
        pt.radgyr(traj())
        traj[:3, '@O'].xyz
        pt.get_coordinates((traj.iterframe(mask='@O')))
        pt.radgyr(traj(mask='@O'))
        for c in pt.iterchunk(traj, 4):
            assert c[0].n_atoms == traj.top.n_atoms
Example #13
0
    def test_comprehensive(self):
        traj = pt.iterload(fn('Tc5b.x'), fn('Tc5b.top'))
        # make sure we DO reproducing cpptraj output
        f_saved = pt.iterload(fn("avg.Tc5b.pdb"), traj.top)[0]

        # shorter
        frame2 = mean_structure(traj)
        aa_eq(frame2.xyz, f_saved.xyz, decimal=3)

        frame3 = mean_structure(traj=traj)
        aa_eq(frame3.xyz, f_saved.xyz, decimal=3)

        # test list
        frame4 = mean_structure(traj=[traj, traj[:3]], top=traj.top)

        # test iter
        frame5 = mean_structure(traj=traj(1, 8, 2), top=traj.top)
        f5_saved = pt.iterload(fn("avg.Tc5b.frame_2_to_8_skip_2.pdb"),
                               traj.top)[0]
        aa_eq(frame5.xyz, f5_saved.xyz, decimal=3)

        # test iter CA
        frame5 = mean_structure(traj[[0, 3, 7]], '@CA', top=traj.top)

        # use atom_indices
        ca_indices = pt.select('@CA', traj.top)
        frame5_1 = mean_structure(traj[[0, 3, 7]], ca_indices, top=traj.top)

        # test frame_indices
        frame6 = mean_structure(traj, mask='@CA', frame_indices=[0, 3, 7])
        aa_eq(frame5.xyz, frame6.xyz, decimal=3)
        aa_eq(frame5_1.xyz, frame6.xyz, decimal=3)

        xyz_0 = pt.get_coordinates(traj(1, 8, 2))
        xyz_1 = np.array([
            frame.xyz.copy()
            for frame in traj.iterframe(frame_indices=range(1, 8, 2))
        ])
        aa_eq(xyz_0, xyz_1, decimal=3)

        # test as traj
        out_traj = mean_structure(traj,
                                  mask='@CA',
                                  frame_indices=[0, 3, 7],
                                  dtype='traj')
        assert isinstance(out_traj, Trajectory), 'must be Trajectory'
        aa_eq(out_traj.xyz, frame6.xyz, decimal=3)

        # raise if not trajectory, traj or frame
        self.assertRaises(ValueError,
                          lambda: pt.mean_structure(traj, dtype='trajxyz'))
Example #14
0
def test_get_coordinates_trajecotoryiterator():
    '''immutable pytraj.TrajectoryIterator
    '''
    traj = traj_tz2_ortho.copy()

    # all coordinates
    xyz = pt.get_coordinates(traj)
    aa_eq(traj.xyz, xyz)

    # given frames
    xyz = pt.get_coordinates(traj, frame_indices=[0, 5])
    aa_eq(traj[[0, 5]].xyz, xyz)

    # given frames, autoimage=True
    xyz = pt.get_coordinates(traj, frame_indices=[0, 5], autoimage=True)
    aa_eq(traj[[0, 5]].autoimage().xyz, xyz)

    # given frames, autoimage=True, rmsfit=ref
    ref = traj[-3]
    pt.autoimage(ref, top=traj.top)
    xyz = pt.get_coordinates(traj,
                             frame_indices=[0, 5],
                             autoimage=True,
                             rmsfit=ref)
    aa_eq(traj[[0, 5]].autoimage().superpose(ref=ref).xyz, xyz)

    xyz = pt.get_coordinates(traj,
                             frame_indices=range(3),
                             autoimage=True,
                             rmsfit=ref)

    # with mask
    xyz = pt.get_coordinates(traj, mask='@CA')
    aa_eq(xyz, traj['@CA'].xyz)

    # slow
    fi = pt.pipe(traj, ['autoimage'])
    aa_eq(pt.get_coordinates(fi), traj[:].autoimage().xyz)

    # raise
    with pytest.raises(ValueError):
        pt.get_coordinates(traj(), frame_indices=[0, 2])
Example #15
0
    def test_comprehensive(self):
        traj = pt.iterload("./data/Tc5b.x", "./data/Tc5b.top")
        # make sure we DO reproducing cpptraj output
        f_saved = pt.iterload("./data/avg.Tc5b.pdb", traj.top)[0]

        # shorter
        frame2 = mean_structure(traj)
        aa_eq(frame2.xyz, f_saved.xyz, decimal=3)

        frame3 = mean_structure(traj=traj)
        aa_eq(frame3.xyz, f_saved.xyz, decimal=3)

        # test list
        frame4 = mean_structure(traj=[traj, traj[:3]], top=traj.top)

        # test iter
        frame5 = mean_structure(traj=traj(1, 8, 2), top=traj.top)
        f5_saved = pt.iterload("./data/avg.Tc5b.frame_2_to_8_skip_2.pdb",
                               traj.top)[0]
        aa_eq(frame5.xyz, f5_saved.xyz, decimal=3)

        # test iter CA
        frame5 = mean_structure(traj[[0, 3, 7]], '@CA', top=traj.top)

        # use atom_indices
        ca_indices = pt.select('@CA', traj.top)
        frame5_1 = mean_structure(traj[[0, 3, 7]], ca_indices, top=traj.top)

        # test frame_indices
        frame6 = mean_structure(traj, mask='@CA', frame_indices=[0, 3, 7])
        aa_eq(frame5.xyz, frame6.xyz, decimal=3)
        aa_eq(frame5_1.xyz, frame6.xyz, decimal=3)

        xyz_0 = pt.get_coordinates(traj(1, 8, 2))
        xyz_1 = np.array([frame.xyz.copy(
        ) for frame in traj.iterframe(frame_indices=range(1, 8, 2))])
        aa_eq(xyz_0, xyz_1, decimal=3)

        # test as traj
        out_traj = mean_structure(traj,
                                  mask='@CA',
                                  frame_indices=[0, 3, 7],
                                  dtype='traj')
        assert isinstance(out_traj, Trajectory), 'must be Trajectory'
        aa_eq(out_traj.xyz, frame6.xyz, decimal=3)

        # raise if not trajectory, traj or frame
        self.assertRaises(ValueError, lambda: pt.mean_structure(traj, dtype='trajxyz'))
Example #16
0
    def test_closest_compared_to_cpptraj(self):
        traj = pt.iterload("./data/tz2.ortho.nc", "./data/tz2.ortho.parm7")
        state = pt.load_cpptraj_state('''
        autoimage
        closest 100 :1-13
        createcrd mycrd''', traj)
        state.run()

        fi, top = pt.closest(traj(autoimage=True), mask=':1-13', n_solvents=100)
        xyz = pt.get_coordinates(fi)
        t0 = pt.Trajectory(xyz=xyz, top=top)
        aa_eq(state.data['mycrd'].xyz, t0.xyz)

        # dtype = 'trajectory'
        t1 = pt.closest(traj(autoimage=True), mask=':1-13', n_solvents=100, dtype='trajectory')
        aa_eq(state.data['mycrd'].xyz, t1.xyz)
Example #17
0
    def test_modify_frame_use_Pipeline(self):
        traj = pt.iterload("data/tz2.ortho.nc", "data/tz2.ortho.parm7")
        dslist = CpptrajDatasetList()
        dslist.add_new('topology', name='mytop')

        # add a new topology
        dslist[0].data = pt.strip(traj.top, ':WAT')
        commands = ['autoimage', 'strip :WAT', 'createcrd mycrd', ]

        actlist = Pipeline(commands, top=traj.top, dslist=dslist)

        for frame in traj:
            actlist.compute(frame)

        aa_eq(dslist['mycrd'].xyz,
              pt.get_coordinates(traj,
                                 mask='!:WAT',
                                 autoimage=True))
Example #18
0
    def test_closest(self):
        # raise if not has solvent
        traj0 = pt.iterload(fn('tz2.nc'),
                            fn('tz2.parm7'),
                            frame_slice=[(0, 2)])
        self.assertRaises(RuntimeError, lambda: pt.closest(traj0))

        traj = pt.iterload(fn('tz2.ortho.nc'),
                           fn('tz2.ortho.parm7'),
                           frame_slice=[(0, 2)])
        fi, top = pt.closest(traj)

        coords = []
        for frame in fi:
            coords.append(frame.xyz.copy())
            assert isinstance(frame, pt.Frame), 'must be Frame'

        # make a Trajectory
        fi, top = pt.closest(traj)
        xyz = pt.get_coordinates(fi)
        t0 = pt.Trajectory(xyz=xyz, top=top)
        aa_eq(np.array(coords), t0.xyz)

        # test write to disk
        fi, top = pt.closest(traj)

        pt.write_traj(outputname('fi.nc'), fi, top=top, overwrite=True)
        # load back
        t1 = pt.load(outputname('fi.nc'), top=top)
        aa_eq(t0.xyz, t1.xyz)

        # make sure n_sovent=10 (default)
        n_solvents = 0
        for mol in top.mols:
            if mol.is_solvent():
                n_solvents += 1
        assert n_solvents == 10, 'must be 10 solvents'

        fi, top = pt.closest(traj)
        pt.write_traj(outputname('test.pdb'),
                      next(fi),
                      top=top,
                      overwrite=True)
Example #19
0
    def test_modify_frame_use_Pipeline(self):
        traj = pt.iterload(fn("tz2.ortho.nc"), fn("tz2.ortho.parm7"))
        dslist = CpptrajDatasetList()
        dslist.add('topology', name='mytop')

        # add a new topology
        dslist[0].data = pt.strip(traj.top, ':WAT')
        commands = [
            'autoimage',
            'strip :WAT',
            'createcrd mycrd',
        ]

        actlist = Pipeline(commands, top=traj.top, dslist=dslist)

        for frame in traj:
            actlist.compute(frame)

        aa_eq(dslist['mycrd'].xyz,
              pt.get_coordinates(traj, mask='!:WAT', autoimage=True))
Example #20
0
    def test_4(self):
        # combined with get_coordinates
        traj0 = pt.iterload("./data/tz2.truncoct.nc",
                            "./data/tz2.truncoct.parm7")

        # test autoimage
        traj1 = traj0[:]
        xyz0 = pt.get_coordinates(traj0(autoimage=True))
        traj1.autoimage()
        xyz1 = traj1.xyz
        # OK
        assert rmsd_1darray(xyz0.flatten(), xyz1.flatten()) == 0.

        # rmsfit
        # reset traj1
        traj1 = traj0[:]
        # get new trajectory from traj0
        traj2 = pt._load_from_frame_iter(traj0(rmsfit=(0, '@CA,C,N')))
        traj1.rmsfit(ref=0, mask='@CA,C,N')

        # take '@CA,C,N' xyz
        xyz2 = traj2['@CA,C,N'].xyz
        xyz1 = traj1['@CA,C,N'].xyz
        # OK
        assert rmsd_1darray(xyz1.flatten(), xyz2.flatten()) < 1E-10

        # combine autoimage with rmsfit
        # reset traj1
        traj1 = traj0[:]
        # get new trajectory from traj0
        traj2 = pt._load_from_frame_iter(traj0(autoimage=True,
                                               rmsfit=(0, '@CA,C,N')))
        traj1.autoimage()
        traj1.rmsfit(ref=0, mask='@CA,C,N')

        # take '@CA,C,N' xyz
        xyz2 = traj2['@CA,C,N'].xyz
        xyz1 = traj1['@CA,C,N'].xyz
        # PASSED
        assert rmsd_1darray(xyz1.flatten(), xyz2.flatten()) < 1E-10
Example #21
0
    def test_4(self):
        # combined with get_coordinates
        traj0 = pt.iterload(fn('tz2.truncoct.nc'),
                            fn('tz2.truncoct.parm7'))

        # test autoimage
        traj1 = traj0[:]
        xyz0 = pt.get_coordinates(traj0(autoimage=True))
        traj1.autoimage()
        xyz1 = traj1.xyz
        # OK
        assert rmsd_1darray(xyz0.flatten(), xyz1.flatten()) == 0.

        # rmsfit
        # reset traj1
        traj1 = traj0[:]
        # get new trajectory from traj0
        traj2 = pt.load_from_frame_iter(traj0(rmsfit=(0, '@CA,C,N')))
        traj1.rmsfit(ref=0, mask='@CA,C,N')

        # take '@CA,C,N' xyz
        xyz2 = traj2['@CA,C,N'].xyz
        xyz1 = traj1['@CA,C,N'].xyz
        # OK
        assert rmsd_1darray(xyz1.flatten(), xyz2.flatten()) < 1E-10

        # combine autoimage with rmsfit
        # reset traj1
        traj1 = traj0[:]
        # get new trajectory from traj0
        traj2 = pt.load_from_frame_iter(traj0(autoimage=True,
                                               rmsfit=(0, '@CA,C,N')))
        traj1.autoimage()
        traj1.rmsfit(ref=0, mask='@CA,C,N')

        # take '@CA,C,N' xyz
        xyz2 = traj2['@CA,C,N'].xyz
        xyz1 = traj1['@CA,C,N'].xyz
        # PASSED
        assert rmsd_1darray(xyz1.flatten(), xyz2.flatten()) < 1E-10
Example #22
0
    def test_closest_compared_to_cpptraj(self):
        traj = pt.iterload(fn('tz2.ortho.nc'), fn('tz2.ortho.parm7'))
        state = pt.load_cpptraj_state(
            '''
        autoimage
        closest 100 :1-13
        createcrd mycrd''', traj)
        state.run()

        fi, top = pt.closest(traj(autoimage=True),
                             mask=':1-13',
                             n_solvents=100)
        xyz = pt.get_coordinates(fi)
        t0 = pt.Trajectory(xyz=xyz, top=top)
        aa_eq(state.data['mycrd'].xyz, t0.xyz)

        # dtype = 'trajectory'
        t1 = pt.closest(traj(autoimage=True),
                        mask=':1-13',
                        n_solvents=100,
                        dtype='trajectory')
        aa_eq(state.data['mycrd'].xyz, t1.xyz)
Example #23
0
    def test_closest(self):
        # raise if not has solvent
        traj0 = pt.iterload("./data/tz2.nc", "./data/tz2.parm7")
        self.assertRaises(RuntimeError, lambda: pt.closest(traj0))

        traj = pt.iterload("./data/tz2.ortho.nc", "./data/tz2.ortho.parm7")
        fi, top = pt.closest(traj)

        coords = []
        for frame in fi:
            coords.append(frame.xyz.copy())
            assert isinstance(frame, pt.Frame), 'must be Frame'

        # make a Trajectory
        fi, top = pt.closest(traj)
        xyz = pt.get_coordinates(fi)
        t0 = pt.Trajectory(xyz=xyz, top=top)
        aa_eq(np.array(coords), t0.xyz)

        # test write to disk
        fi, top = pt.closest(traj)

        pt.write_traj('output/fi.nc', fi, top=top, overwrite=True)
        # load back
        t1 = pt.load('output/fi.nc', top=top)
        aa_eq(t0.xyz, t1.xyz)

        # make sure n_sovent=10 (default)
        n_solvents = 0
        for mol in top.mols:
            if mol.is_solvent():
                n_solvents += 1
        assert n_solvents == 10, 'must be 10 solvents'

        fi, top = pt.closest(traj)
        pt.write_traj('output/test.pdb', next(fi), top=top, overwrite=True)
    def test_1(self):
        # merge_frames
        import numpy as np

        # load 2 frames
        traj = pt.iterload(fn('Tc5b.x'), fn('Tc5b.top'), frame_slice=(0, 2))

        # test mutable traj
        frame = pt.tools.merge_frames(traj[:])
        r0 = pt.tools.rmsd(frame.xyz, pt.get_coordinates(traj), True)
        assert r0 == 0.

        #, True) test immutable traj
        assert np.any(
            pt.tools.merge_frames(traj).xyz.flatten() == pt.get_coordinates(
                traj).flatten())

        # tuple
        assert np.any(
            pt.tools.merge_frames(
                (frame for frame in traj
                 )).xyz.flatten() == pt.get_coordinates(traj).flatten())

        # list
        assert np.any(
            pt.tools.merge_frames([
                frame for frame in traj
            ]).xyz.flatten() == pt.get_coordinates(traj).flatten())

        # frame_iter: all atoms
        assert np.any(
            pt.tools.merge_frames(traj()).xyz.flatten() == pt.get_coordinates(
                traj()).flatten())

        # frame_iter: CA atoms
        assert np.any(
            pt.tools.merge_frames(traj(mask='@CA')).xyz.flatten() ==
            pt.get_coordinates(traj(mask='@CA')).flatten())
def _get_coordinates(traj):
    return pt.get_coordinates(traj, autoimage=True, rmsfit=(0, mask), mask=mask)
def _get_coordinates(traj):
    return pt.get_coordinates(traj,
                              autoimage=True,
                              rmsfit=(0, '@CA'),
                              mask='@CA')