Esempio n. 1
0
def test_pipes():
    ref = PdbFile(os.environ["TEST_DATA_PATH"] +
                  "/trjtool/GB1/run00001.pdb").frames()[0]

    traj = Trajectory(ref)
    traj.extend(
        TrjtoolDatFile(os.environ["TEST_DATA_PATH"] +
                       "/trjtool/GB1/run00001.dat"))

    first_geom_center = XYZ(8.422286, 0.967190, -13.856332)

    for frame in traj:
        assert frame.coords.mean().distance(first_geom_center) < 0.001
        break
    del frame

    for frame in traj | AngstromsToNanometers():
        assert frame.coords.mean().distance(first_geom_center * 10) < 0.001
        break
    del frame

    for frame in traj | Align(by=lambda a: True):
        assert frame.coords.mean().distance(first_geom_center) < 0.001
    del frame
    for frame in traj[0:10] | Align(by=lambda a: True):
        assert frame.coords.mean().distance(first_geom_center) < 0.001
    del frame
    for frame in traj[0:10] | Align(
            by=lambda a: True) | AngstromsToNanometers():
        assert frame.coords.mean().distance(first_geom_center * 10) < 0.001
    del frame
Esempio n. 2
0
def test_trajectory_integer_indexing():
    from pyxmolpp2 import PdbFile, TrjtoolDatFile as DatFile, Trajectory

    frame = PdbFile(os.environ["TEST_DATA_PATH"] +
                    "/trjtool/GB1/run00001.pdb").frames()[0]

    trj = Trajectory(frame)
    trj.extend(
        DatFile(os.environ["TEST_DATA_PATH"] + "/trjtool/GB1/run00001.dat"))

    n = trj.n_frames

    trj[-n]
    trj[n - 1]

    with pytest.raises(IndexError):
        trj[n]

    with pytest.raises(IndexError):
        trj[-n - 1]

    frame1 = trj[0]
    frame2 = trj[-n]
    frame3 = trj[0]

    assert frame1 != frame2
    assert frame1 != frame3
Esempio n. 3
0
def test_traj_iteration():
    from pyxmolpp2 import PdbFile, TrjtoolDatFile as DatFile, Trajectory
    frame = PdbFile(os.environ["TEST_DATA_PATH"] +
                    "/trjtool/GB1/run00001.pdb").frames()[0]

    assert frame.atoms.size > 0

    datfile1 = DatFile(os.environ["TEST_DATA_PATH"] +
                       "/trjtool/GB1/run00001.dat")
    datfile2 = DatFile(os.environ["TEST_DATA_PATH"] +
                       "/trjtool/GB1/run00002.dat")

    trj = Trajectory(frame)

    trj.extend(datfile1)
    trj.extend(datfile2)

    assert trj.n_frames == datfile1.n_frames() + datfile2.n_frames()

    n = 0
    stride = 50
    for f in trj[::stride]:
        r = f.atoms[0].r
        n += 1

    assert trj.n_frames // stride == n
Esempio n. 4
0
def test_read_frames():
    from pyxmolpp2 import PdbFile
    import glob

    for filename in glob.glob(os.environ["TEST_DATA_PATH"] +
                              "/pdb/rcsb/*.pdb"):
        frames = PdbFile(filename).frames()

        assert len(frames) > 0
        print(len(frames))
Esempio n. 5
0
def test_trajectory_bad_n_atoms():
    from pyxmolpp2 import PdbFile, TrjtoolDatFile as DatFile, Trajectory

    frame = PdbFile(os.environ["TEST_DATA_PATH"] +
                    "/pdb/rcsb/1PGB.pdb").frames()[0]

    trj = Trajectory(frame)
    with pytest.raises(RuntimeError):
        trj.extend(
            DatFile(os.environ["TEST_DATA_PATH"] +
                    "/trjtool/GB1/run00001.dat"))
Esempio n. 6
0
def test_writer():
    from pyxmolpp2 import PdbFile, XtcWriter, Translation, XYZ

    xtc_writer = XtcWriter("test.xtc", 1000)
    frame = PdbFile(os.environ["TEST_DATA_PATH"] +
                    "/gromacs/xtc/1am7_protein.pdb").frames()[0]
    for i in range(10):
        frame.cell.scale_by(1.2)
        frame.coords.apply(Translation(XYZ(1, 0, 0)))
        xtc_writer.write(frame)
    del xtc_writer
    os.remove("test.xtc")
Esempio n. 7
0
def test_traj_exceptions():
    from pyxmolpp2 import PdbFile, TrjtoolDatFile as DatFile, Trajectory

    datfile1 = DatFile(os.environ["TEST_DATA_PATH"] +
                       "/trjtool/GB1/run00001.dat")

    # atom name is different
    with pytest.raises(RuntimeError):
        frame = PdbFile(os.environ["TEST_DATA_PATH"] +
                        "/trjtool/GB1/run00001.pdb").frames()[0]
        frame.atoms[0].name = "XX"
        trj = Trajectory(frame)
        trj.extend(datfile1)

    # atom number of atoms is different
    with pytest.raises(RuntimeError):
        frame = PdbFile(os.environ["TEST_DATA_PATH"] +
                        "/trjtool/GB1/run00001.pdb").frames()[0]
        frame.atoms[0].erase()
        trj = Trajectory(frame)
        trj.extend(datfile1)
Esempio n. 8
0
def test_read_trjtool():
    from pyxmolpp2 import PdbFile, TrjtoolDatFile

    frame = PdbFile(os.environ["TEST_DATA_PATH"] + "/trjtool/GB1/run00001.pdb").frames()[0]

    assert frame.atoms.size > 0

    datfile = TrjtoolDatFile(os.environ["TEST_DATA_PATH"] + "/trjtool/GB1/run00001.dat")

    assert datfile.n_frames() == 1000
    assert datfile.n_atoms() == frame.atoms.size
    datfile.advance(0)
    datfile.read_frame(0, frame)
Esempio n. 9
0
def test_read_netcdf():
    from pyxmolpp2 import PdbFile, AmberNetCDF

    frame = PdbFile(os.environ["TEST_DATA_PATH"] +
                    "/amber/GB1_F30C_MTSL/box.pdb").frames()[0]

    assert frame.atoms.size > 0

    datfile = AmberNetCDF(os.environ["TEST_DATA_PATH"] +
                          "/amber/GB1_F30C_MTSL/GB1_F30C_MTSL_10_frames.nc")

    assert datfile.n_frames() == 10
    assert datfile.n_atoms() == frame.atoms.size

    datfile.read_frame(0, frame)
Esempio n. 10
0
def test_read_one_file():
    from pyxmolpp2 import PdbFile, GromacsXtcFile

    frame = PdbFile(os.environ["TEST_DATA_PATH"] +
                    "/gromacs/xtc/1am7_protein.pdb").frames()[0]

    assert frame.atoms.size > 0

    inp = GromacsXtcFile(
        os.environ["TEST_DATA_PATH"] + "/gromacs/xtc/1am7_corrected.xtc", 51)

    assert inp.n_frames() == 51
    assert inp.n_atoms() == frame.atoms.size
    inp.advance(0)
    inp.read_frame(0, frame)
Esempio n. 11
0
def test_tqdm():
    from tqdm import tqdm
    ref = PdbFile(os.environ["TEST_DATA_PATH"] +
                  "/trjtool/GB1/run00001.pdb").frames()[0]

    traj = Trajectory(ref)
    traj.extend(
        TrjtoolDatFile(os.environ["TEST_DATA_PATH"] +
                       "/trjtool/GB1/run00001.dat"))
    for _ in tqdm(traj):
        pass
    del _
    for _ in tqdm(traj[::2]):
        pass
    del _
Esempio n. 12
0
def test_unit_cell_scale():
    ref = PdbFile(os.environ["TEST_DATA_PATH"] +
                  "/trjtool/GB1/run00001.pdb").frames()[0]
    traj = Trajectory(ref)
    traj.extend(
        TrjtoolDatFile(os.environ["TEST_DATA_PATH"] +
                       "/trjtool/GB1/run00002.dat"))
    volumes = []
    for frame in traj[::100] | ScaleUnitCell(
            os.environ["TEST_DATA_PATH"] +
            "/trjtool/GB1/summary/summary.VOLUME"):
        volumes += [frame.cell.volume]

    assert np.allclose(volumes, [
        112190.6817, 111667.0223, 112060.3447, 112010.4530, 111899.7620,
        112420.6936, 111794.6408, 112093.9081, 111655.2990, 111978.6604
    ])
Esempio n. 13
0
def test_read_frame():
    from pyxmolpp2 import PdbFile, UnitCell, Degrees

    cells = [
        UnitCell(36.633, 36.633, 79.254, Degrees(90), Degrees(90),
                 Degrees(120.00)),
        UnitCell(50.840, 42.770, 28.950, Degrees(90), Degrees(90.00),
                 Degrees(90.00)),
        UnitCell(52.323, 79.498, 52.406, Degrees(90), Degrees(90.14),
                 Degrees(90.00)),
        UnitCell(25.037, 37.194, 49.217, Degrees(90), Degrees(90.00),
                 Degrees(90.00)),
    ]

    for pdb_code, cell in zip(['1PGB', '1UBQ', '5BMG', '5BMH'], cells):
        frames = PdbFile(os.environ["TEST_DATA_PATH"] +
                         f"/pdb/rcsb/{pdb_code}.pdb").frames()
        for frame in frames:
            for i in range(3):
                assert cell[i].distance(frame.cell[i]) == pytest.approx(0)
            assert frame.atoms.size > 0
Esempio n. 14
0
def test_traj_size():
    from pyxmolpp2 import PdbFile, TrjtoolDatFile as DatFile, Trajectory
    frame = PdbFile(os.environ["TEST_DATA_PATH"] +
                    "/trjtool/GB1/run00001.pdb").frames()[0]

    assert frame.atoms.size > 0

    trj = Trajectory(frame)
    trj.extend(
        DatFile(os.environ["TEST_DATA_PATH"] + "/trjtool/GB1/run00001.dat"))

    assert sum([1 for _ in trj[0:10]]) == 10
    assert sum([1 for _ in trj[0:10:10]]) == 1
    assert sum([1 for _ in trj[0:10:100]]) == 1
    assert sum([1 for _ in trj[0:100:10]]) == 10

    assert sum([1 for _ in trj[0:-1000]]) == 0
    assert sum([1 for _ in trj[-100:]]) == 100
    assert sum([1 for _ in trj[:-100]]) == 900

    with pytest.raises(TypeError):
        trj[::-1]
Esempio n. 15
0
def test_calc_sasa():
    from pyxmolpp2 import PdbFile, calc_sasa
    from timeit import default_timer as timer
    import numpy as np
    import glob

    for filename in sorted(glob.glob(os.environ["TEST_DATA_PATH"] + "/pdb/rcsb/*.pdb")):
        frame = PdbFile(filename).frames()[0]
        coords = frame.coords.values
        radii = np.array([1.0] * frame.atoms.size)

        t1 = timer()
        assert calc_sasa(coords, radii, 0.0, np.array([0], dtype=np.intc)).size == 1
        t2 = timer()
        assert calc_sasa(coords, radii, 0.0, np.array([0, 1, 2, 3, 4], dtype=np.intc)).size == 5
        t3 = timer()
        assert calc_sasa(coords, radii, 0.0).size == radii.size
        t4 = timer()
        assert calc_sasa(coords, radii, 0.0, n_samples=1).size == radii.size

        T1, T3 = t2 - t1, t4 - t3
        assert T3 > T1
Esempio n. 16
0
def test_read_non_existent_file():
    from pyxmolpp2 import PdbFile

    with pytest.raises(RuntimeError):
        PdbFile("does_not_exists.pdb")
Esempio n. 17
0
from ccr_scripts.save_utils import fit_and_save_crosscorr_func
from ccr_scripts.process_utils.fit import fit_corrfunc_amp_unfixed

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='fit crosscorr')
    parser.add_argument(
        '--path-to-crosscorr-csv',
        required=True,
    )
    parser.add_argument('--limit', default=None, type=int)
    parser.add_argument('--path-to-reference-pdb')
    parser.add_argument('--output-directory', default="./")
    args = parser.parse_args()

    bounds = [
        ([[0, 0.001, 0, 0.01, 0, 0.1, 0, 1], [1, 0.01, 1, 0.1, 1, 1, 1, 10]]),
    ]

    scales = [1]

    ref = PdbFile(args.path_to_reference_pdb).frames()[0]
    residue_name_map = {r.id.serial: r.name for r in ref.residues}

    fit_and_save_crosscorr_func(args.path_to_crosscorr_csv,
                                bounds=bounds,
                                scales=scales,
                                residue_name_map=residue_name_map,
                                limit=args.limit,
                                output_directory=args.output_directory,
                                fit_func=fit_corrfunc_amp_unfixed)
Esempio n. 18
0
    parser.add_argument('--trajectory-length', required=True, type=int)
    parser.add_argument('--frames-per-trajectory-file', type=int, default=1000)
    parser.add_argument('--vectors', required=True)
    parser.add_argument('--output-directory', default=".")
    args = parser.parse_args()

    trj_reader_dict = {
        "dat": TrjtoolDatFile,
        "nc": AmberNetCDF,
        "xtc": XtcFileReaderWrapper(args.frames_per_trajectory_file)
    }

    subdir_prefix = {"one_residue": "", "next_residue": "p1"}

    # load trajectory
    traj = Trajectory(PdbFile(args.path_to_reference_pdb).frames()[0])
    for ind in tqdm(range(1, args.trajectory_length + 1), desc="traj_reading"):
        fname = "{pattern}.{filetype}".format(pattern=args.pattern,
                                              filetype=args.filetype)
        traj.extend(trj_reader_dict[args.filetype](os.path.join(
            args.path_to_trajectory, fname % (ind))))

    # define processes for writing of vectors coordinates
    processes = []
    for vector in args.vectors.split(","):
        atom_pair, residue_mode = vector.split("_", 1)
        atom_1, atom_2 = atom_pair.split("-")
        subdir = f"{vector_name_to_basename(atom_pair)}{subdir_prefix[residue_mode]}"
        processes.append(
            WriteVectorsToCsvWithMetadata(
                atom_pairs_selector(atom_1.split("|"),
Esempio n. 19
0
def test_read_empty_file():
    from pyxmolpp2 import PdbFile
    import os

    assert len(PdbFile(os.devnull).frames()) == 0