def test_nematic_order_args():
    assert_raises(ValueError, lambda: order.compute_nematic_order(TRAJ2, indices='dog'))
    assert_raises(ValueError, lambda: order.compute_nematic_order(TRAJ2, indices='O'))
    assert_raises(ValueError, lambda: order.compute_nematic_order(TRAJ2, indices=1))
    # Input indices with wrong "shapes".
    assert_raises(ValueError, lambda: order.compute_nematic_order(TRAJ2, indices=[[1, [2]], [2]]))
    assert_raises(ValueError, lambda: order.compute_nematic_order(TRAJ2, indices=[1, 2, 3]))
Beispiel #2
0
def test_write_units_mismatch():
    velocoties = units.Quantity(np.random.randn(4, 10,3), units.angstroms/units.picosecond)

    with HDF5TrajectoryFile(temp, 'w') as f:
        # if you try to write coordinates that are unitted and not
        # in the correct units, we find that
        assert_raises(TypeError, lambda: f.write(coordinates=velocoties))
Beispiel #3
0
def test_write_inconsistent():
    coordinates = np.random.randn(4, 10,3)
    with HDF5TrajectoryFile(temp, 'w') as f:
        f.write(coordinates)
        # since the first frames we saved didn't contain velocities, we
        # can't save more velocities
        assert_raises(ValueError, lambda: f.write(coordinates, velocities=coordinates))
Beispiel #4
0
def test_write_inconsistent_2():
    coordinates = np.random.randn(4, 10,3)
    with HDF5TrajectoryFile(temp, 'w') as f:
        f.write(coordinates, velocities=coordinates)
        # we're saving a deficient set of data, since before we wrote
        # more information.
        assert_raises(ValueError, lambda: f.write(coordinates))
Beispiel #5
0
def test_select_atom_indices():
    top = md.load(get_fn("native.pdb")).topology

    yield lambda: eq(top.select_atom_indices("alpha"), np.array([8]))
    yield lambda: eq(top.select_atom_indices("minimal"), np.array([4, 5, 6, 8, 10, 14, 15, 16, 18]))

    assert_raises(ValueError, lambda: top.select_atom_indices("sdfsdfsdf"))
Beispiel #6
0
def test_write_inconsistent_2():
    coordinates = np.random.randn(4, 10, 3)
    with HDF5TrajectoryFile(temp, 'w') as f:
        f.write(coordinates, velocities=coordinates)
        # we're saving a deficient set of data, since before we wrote
        # more information.
        assert_raises(ValueError, lambda: f.write(coordinates))
Beispiel #7
0
def test_select_atom_indices():
    top = md.load(get_fn('native.pdb')).topology

    yield lambda: eq(top.select_atom_indices('alpha'), np.array([8]))
    yield lambda: eq(top.select_atom_indices('minimal'),
                     np.array([4, 5, 6, 8, 10, 14, 15, 16, 18]))

    assert_raises(ValueError, lambda: top.select_atom_indices('sdfsdfsdf'))
Beispiel #8
0
def test_write_inconsistent():
    coordinates = np.random.randn(4, 10, 3)
    with HDF5TrajectoryFile(temp, 'w') as f:
        f.write(coordinates)
        # since the first frames we saved didn't contain velocities, we
        # can't save more velocities
        assert_raises(ValueError,
                      lambda: f.write(coordinates, velocities=coordinates))
Beispiel #9
0
def test_write_units_mismatch():
    velocoties = units.Quantity(np.random.randn(4, 10, 3),
                                units.angstroms / units.picosecond)

    with HDF5TrajectoryFile(temp, 'w') as f:
        # if you try to write coordinates that are unitted and not
        # in the correct units, we find that
        assert_raises(TypeError, lambda: f.write(coordinates=velocoties))
Beispiel #10
0
def test_atoms_by_name():
    top = md.load(get_fn('bpti.pdb')).topology

    atoms = list(top.atoms)
    for atom1, atom2 in zip(top.atoms_by_name('CA'), top.chain(0).atoms_by_name('CA')):
        assert atom1 == atom2
        assert atom1 in atoms
        assert atom1.name == 'CA'

    assert len(list(top.atoms_by_name('CA'))) == sum(1 for _ in atoms if _.name == 'CA')
    assert top.residue(15).atom('CA') == [a for a in top.residue(15).atoms if a.name == 'CA'][0]

    assert_raises(KeyError, lambda: top.residue(15).atom('sdfsdsdf'))
Beispiel #11
0
def test_1():
    # https://github.com/rmcgibbo/mdtraj/issues/438
    try:
        traj = md.load(get_fn('frame0.h5'))
        np.save('temp.npy', traj.xyz)

        traj.xyz = np.load('temp.npy', mmap_mode='r')

        # since traj isn't precentered, this requires centering
        # the coordinates which is done inplace. but that's not possible
        # with mmap_mode = 'r'
        assert_raises(ValueError, md.rmsd, traj, traj, 0)

        # this should work
        traj.xyz = np.load('temp.npy', mmap_mode='c')
        md.rmsd(traj, traj, 0)

    finally:
        del traj
        os.unlink('temp.npy')
Beispiel #12
0
def test_rdf_args():
    assert_raises(
        ValueError,
        lambda: md.geometry.rdf.compute_rdf(TRAJ, pair_names=('O', 'O', 'O')))
    assert_raises(ValueError,
                  lambda: md.geometry.rdf.compute_rdf(TRAJ, pair_names=('O')))
    assert_raises(
        ValueError,
        lambda: md.geometry.rdf.compute_rdf(TRAJ, pair_names=('C', 'C')))
Beispiel #13
0
def test_immutable():
    def f():
        element.hydrogen.mass = 1
    def g():
        element.radium.symbol = 'sdfsdfsdf'
    def h():
        element.iron.name = 'sdfsdf'

    assert_raises(AttributeError, f)
    assert_raises(AttributeError, g)
    assert_raises(AttributeError, h)
    assert element.hydrogen.mass == 1.007947
    assert element.radium.symbol == 'Ra'
    assert element.iron.name == 'iron'
Beispiel #14
0
def test_immutable():
    def f():
        element.hydrogen.mass = 1
    def g():
        element.radium.symbol = 'sdfsdfsdf'
    def h():
        element.iron.name = 'sdfsdf'

    assert_raises(AttributeError, f)
    assert_raises(AttributeError, g)
    assert_raises(AttributeError, h)
    assert element.hydrogen.mass == 1.007947
    assert element.radium.symbol == 'Ra'
    assert element.iron.name == 'iron'
Beispiel #15
0
def test_2():
    # https://github.com/mdtraj/mdtraj/issues/438
    try:
        dir = tempfile.mkdtemp()
        fn = os.path.join(dir, 'temp.npy')
        traj = md.load(get_fn('frame0.h5'))
        # precenter the coordinates
        traj.center_coordinates()
        traces = traj._rmsd_traces
        np.save(fn, traj.xyz)
        traj.xyz = np.load(fn, mmap_mode='r')
        traj._rmsd_traces = traces

        with assert_raises(ValueError):
            md.rmsd(traj, traj, 0, precentered=True)

    finally:
        del traj
        os.unlink(fn)
        os.rmdir(dir)
Beispiel #16
0
def test_1():
    # https://github.com/mdtraj/mdtraj/issues/438
    try:
        dir = tempfile.mkdtemp()
        fn = os.path.join(dir, 'temp.npy')
        traj = md.load(get_fn('frame0.h5'))
        np.save(fn, traj.xyz)

        traj.xyz = np.load(fn, mmap_mode='r')

        # since traj isn't precentered, this requires centering
        # the coordinates which is done inplace. but that's not possible
        # with mmap_mode = 'r'
        with assert_raises(ValueError):
            md.rmsd(traj, traj, 0)

        # this should work
        traj.xyz = np.load(fn, mmap_mode='c')
        md.rmsd(traj, traj, 0)

    finally:
        del traj
        os.unlink(fn)
        os.rmdir(dir)
Beispiel #17
0
def test_raises():
    assert_raises(ValueError, lambda: parse_selection('or'))
    assert_raises(ValueError, lambda: parse_selection('a <'))
Beispiel #18
0
def test_mismatch():
    # loading a 22 atoms xtc with a topology that has 2,000 atoms
    # some kind of error should happen!
    assert_raises(ValueError, lambda: md.load(get_fn('frame0.xtc'), top=get_fn('4ZUO.pdb')))
Beispiel #19
0
def test_raises():
    assert_raises(ValueError, lambda: parse_selection('or'))
    assert_raises(ValueError, lambda: parse_selection('a <'))
Beispiel #20
0
def test_raises2():
    assert_raises(ValueError, lambda: parse_selection('dog 5'))
    assert_raises(ValueError, lambda: parse_selection('dog == 5'))
    assert_raises(ValueError, lambda: parse_selection('dog frog'))
    assert_raises(ValueError, lambda: parse_selection('not dog'))
    assert_raises(ValueError, lambda: parse_selection('protein or dog'))
    assert_raises(ValueError, lambda: parse_selection('dog 1 to 5'))
    assert_raises(ValueError, lambda: parse_selection('dog'))
Beispiel #21
0
 def test_2():
     fn = 'temp-2%s' % ext
     open(fn, 'w').close()
     assert_raises(IOError,
                   lambda: t_ref.save(fn, force_overwrite=False))
Beispiel #22
0
def test_raises2():
    assert_raises(ValueError, lambda: parse_selection('dog 5'))
    assert_raises(ValueError, lambda: parse_selection('dog == 5'))
    assert_raises(ValueError, lambda: parse_selection('dog frog'))
    assert_raises(ValueError, lambda: parse_selection('not dog'))
    assert_raises(ValueError, lambda: parse_selection('protein or dog'))
    assert_raises(ValueError, lambda: parse_selection('dog 1 to 5'))
    assert_raises(ValueError, lambda: parse_selection('dog'))
Beispiel #23
0
 def test_2():
     fn = 'temp-2%s' % ext
     open(fn, 'w').close()
     assert_raises(IOError,
                   lambda: t_ref.save(fn, force_overwrite=False))