本文整理汇总了Python中mdtraj.testing.assert_raises函数的典型用法代码示例。如果您正苦于以下问题:Python assert_raises函数的具体用法?Python assert_raises怎么用?Python assert_raises使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了assert_raises函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_write_inconsistent
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))
示例2: test_write_inconsistent_2
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))
示例3: test_nematic_order_args
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]))
示例4: test_write_units_mismatch
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))
示例5: test_select_atom_indices
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"))
示例6: test_atoms_by_name
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'))
示例7: test_1
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')
示例8: test_immutable
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'
示例9: test_2
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)
示例10: test_1
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)
示例11: test_raises
def test_raises():
assert_raises(ValueError, lambda: parse_selection('or'))
assert_raises(ValueError, lambda: parse_selection('a <'))
示例12: test_mismatch
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')))
示例13: test_raises2
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'))
示例14: test_2
def test_2():
fn = 'temp-2%s' % ext
open(fn, 'w').close()
assert_raises(IOError,
lambda: t_ref.save(fn, force_overwrite=False))