예제 #1
0
    def test_0(self):
        traj = mdio.iterload("./data/Tc5b.x", "./data/Tc5b.top")
        mdio.write_traj("test_1.pdb", traj[0], top=traj.top, overwrite=True)
        mdio.write_traj("test_1.dcd", traj[0], top=traj.top, overwrite=True)

        with TrajectoryWriter("./output/test_1", overwrite=True) as trajout:
            trajout.write(traj[0])
예제 #2
0
def test_trajectory_writer():
    traj = pt.iterload(tc5b_trajin, tc5b_top)
    with tempfolder():
        pt.write_traj("test_1.pdb", traj[0], top=traj.top, overwrite=True)
        pt.write_traj("test_1.dcd", traj[0], top=traj.top, overwrite=True)

        with TrajectoryWriter("test_1", overwrite=True) as trajout:
            trajout.write(traj[0])
예제 #3
0
def test_write_pdb():
    # TODO: get absolute path so we can use `tempfolder`
    # if not: wrong dir if using TrajectoryIterator
    traj = pt.iterload(tc5b_trajin, tc5b_top)[:]
    TrajectoryWriter()

    # multiple pdb in multiple files, using `save` method in traj
    with tempfolder():
        basename = "test_pdb_files.pdb"
        traj.save(basename, overwrite=True, options="multi")
        for i in range(10):
            fname = basename + "." + str(i + 1)  # cpptraj use `1`
            frame = pt.iterload(fname, traj.top)[0]
            aa_eq(frame.xyz, traj[i].xyz)

    # multiple pdb in multiple files, using `pt.write_traj`
    with tempfolder():
        basename = "test_pdb_files_pt_write_traj.pdb"
        pt.write_traj(basename, traj, overwrite=True, options="multi")
        for i in range(10):
            fname = basename + "." + str(i + 1)  # cpptraj use `1`
            frame = pt.iterload(fname, traj.top)[0]
            aa_eq(frame.xyz, traj[i].xyz)

        with pytest.raises(IOError):
            # write files again, raise if file exists
            pt.write_traj(basename, traj, overwrite=False, options="multi")

    # keepext
    with tempfolder():
        basename = 'test_pdb_files_pt_write_traj.pdb'
        basename2 = 'test_pdb_files_pt_write_traj'
        pt.write_traj(basename, traj, overwrite=True, options="multi keepext")
        for i in range(10):
            fname = "{}.{}.pdb".format(basename2, i + 1)
            frame = pt.iterload(fname, traj.top)[0]
            aa_eq(frame.xyz, traj[i].xyz)

        with pytest.raises(IOError):
            pt.write_traj(basename,
                          traj,
                          overwrite=False,
                          options="multi keepext")

    # multiple pdb in SINGLE file
    with tempfolder():
        basename = "test_pdb_files.pdb"
        traj.save(basename, overwrite=True)
        traj2 = pt.load(basename, traj.top)
        aa_eq(traj.xyz, traj2.xyz)

    # multiple pdb in SINGLE file with `model` keyword
    # write to output so we can manually check
    basename = "test_pdb_files_model.pdb"
    with tempfolder():
        traj.save(basename, overwrite=True, options='model')
        traj3 = pt.load(basename, traj.top)
        aa_eq(traj.xyz, traj3.xyz)
예제 #4
0
def test_write_force_from_scratch():
    traj = pt.iterload(fn('tz2.nc'), fn('tz2.parm7'))
    assert traj[0].force is None

    def add_force(traj):
        for frame in traj:
            frame.force = np.zeros(traj.n_atoms * 3) + 1.
            yield frame

    with tempfolder():
        out_fn = 'out.nc'
        with TrajectoryWriter(out_fn, top=traj.top, crdinfo={'has_force': True}) as writer:
            for frame in add_force(traj):
                writer.write(frame)
        traj2 = pt.iterload(out_fn, top=traj.top)
        assert traj2.metadata['has_force']
        assert not traj2.metadata['has_velocity']
예제 #5
0
파일: test_io.py 프로젝트: recherHE/pytraj
def test_write_velocity_from_scratch():
    traj = pt.iterload(fn('tz2.nc'), fn('tz2.parm7'))
    assert traj[0].velocity is None

    def add_velocity(traj):
        for frame in traj:
            frame.velocity = np.zeros(traj.n_atoms * 3) + 1.
            yield frame

    with tempfolder():
        out_fn = 'out.nc'
        with TrajectoryWriter(out_fn,
                              top=traj.top,
                              crdinfo={'has_velocity': True}) as writer:
            for frame in add_velocity(traj):
                writer.write(frame)
        traj2 = pt.iterload(out_fn, top=traj.top)
        assert traj2.metadata['has_velocity']
        assert not traj2.metadata['has_force']
        # make sure no segmentation fault
        # issues/1486
        assert traj2[:].n_frames == traj2.n_frames
예제 #6
0
    def test_1(self):
        # TODO: get absolute path so we can use `tempfolder`
        # if not: wrong dir if using TrajectoryIterator
        traj = mdio.iterload("./data/Tc5b.x", "./data/Tc5b.top")[:]
        trajout = TrajectoryWriter()

        # multiple pdb in multiple files, using `save` method in traj
        with tempfolder():
            basename = "test_pdb_files.pdb"
            traj.save(basename, overwrite=True, options="multi")
            for i in range(10):
                fname = basename + "." + str(i + 1)  # cpptraj use `1`
                frame = mdio.iterload(fname, traj.top)[0]
                aa_eq(frame.xyz, traj[i].xyz)

        # multiple pdb in multiple files, using `mdio.write_traj`
        with tempfolder():
            basename = "test_pdb_files_mdio_write_traj.pdb"
            mdio.write_traj(basename, traj, overwrite=True, options="multi")
            for i in range(10):
                fname = basename + "." + str(i + 1)  # cpptraj use `1`
                frame = pt.iterload(fname, traj.top)[0]
                aa_eq(frame.xyz, traj[i].xyz)

        # multiple pdb in SINGLE file
        with tempfolder():
            basename = "test_pdb_files.pdb"
            traj.save(basename, overwrite=True)
            traj2 = mdio.load(basename, traj.top)
            aa_eq(traj.xyz, traj2.xyz)

        # multiple pdb in SINGLE file with `model` keyword
        # write to output so we can manually check
        basename = "./output/test_pdb_files_model.pdb"
        traj.save(basename, overwrite=True, options='model')
        traj3 = mdio.load(basename, traj.top)
        aa_eq(traj.xyz, traj3.xyz)