def test_only_same_level_different_universes(self): def dummy(self, other): return True u = make_Universe() u2 = make_Universe() _only_same_level = mda.core.groups._only_same_level assert_raises(ValueError, _only_same_level(dummy), u.atoms, u2.atoms)
def translate_universes(): # create the Universe objects for the tests # this universe has no masses and some tests need it as such reference = make_Universe(trajectory=True) transformed = make_Universe(['masses'], trajectory=True) transformed.trajectory.ts.dimensions = np.array([372., 373., 374., 90, 90, 90]) return reference, transformed
def __init__(self, reference=None): if reference is None: reference = GROReference() super(TestGROWriter, self).__init__(reference) self.u_no_resnames = make_Universe(['names', 'resids'], trajectory=True) self.u_no_resids = make_Universe(['names', 'resnames'], trajectory=True) self.u_no_names = make_Universe(['resids', 'resnames'], trajectory=True)
def setUp(self): self.universe = mda.Universe(PSF, PDB_small) self.universe2 = mda.Universe(PSF, DCD) # 3 decimals in PDB spec # http://www.wwpdb.org/documentation/format32/sect9.html#ATOM self.prec = 3 ext = ".pdb" self.tmpdir = tempdir.TempDir() self.outfile = self.tmpdir.name + '/primitive-pdb-writer' + ext self.u_no_resnames = make_Universe(['names', 'resids'], trajectory=True) self.u_no_resids = make_Universe(['names', 'resnames'], trajectory=True) self.u_no_names = make_Universe(['resids', 'resnames'], trajectory=True)
def test_add_segment_no_attrs(self): u = make_Universe() assert_(len(u.segments) == 5) s = u.add_Segment() assert_(isinstance(s, MDAnalysis.core.groups.Segment)) assert_(len(u.segments) == 6)
def test_record_types_default(self): u = make_Universe() u.add_TopologyAttr('record_type') assert u.atoms[0].record_type == 'ATOM' assert_equal(u.atoms[:10].record_types, 'ATOM')
def test_wrong_n_atoms(self, outfile): from MDAnalysis.coordinates.TRJ import NCDFWriter with NCDFWriter(outfile, 100) as w: u = make_Universe(trajectory=True) with pytest.raises(IOError): w.write(u.trajectory.ts)
def test_empty_UAG(): u = make_Universe() # technically possible to make a UAG without any selections.. uag = mda.core.groups.UpdatingAtomGroup(u.atoms, (), '') assert_(isinstance(uag, mda.core.groups.UpdatingAtomGroup))
def test_add_Residue_with_attrs(self): u = make_Universe(('resnames', 'resids')) r_new = u.add_Residue(segment=u.segments[0], resid=4321, resname='New') assert_(r_new.resid == 4321) assert_(r_new.resname == 'New')
def test_segment_getattr_singular(self): u = make_Universe(('resnames',)) res = u.segments[0].RsB assert isinstance(res, groups.Residue) assert res == u.residues[1]
def test_residuegroup_getattr_single(self): u = make_Universe(('resnames',)) res = u.residues.RsB assert isinstance(res, groups.Residue) assert res == u.residues[1]
def setUp(self): self.u = make_Universe(trajectory=True) self.group_dict = { 'atom': self.u.atoms, 'residue': self.u.residues, 'segment': self.u.segments }
def test_all(self): # all combinations of which trajectory attributes we have # positions is always present for pos, vel, force in ( (True, False, False), (True, True, False), (True, False, True), (True, True, True), ): u = make_Universe(trajectory=pos, velocities=vel, forces=force) # AtomGroup access yield self._check_atomgroup_positions_access, u, pos yield self._check_atomgroup_velocities_access, u, vel yield self._check_atomgroup_forces_access, u, force # Atom access yield self._check_atom_position_access, u, pos yield self._check_atom_velocity_access, u, vel yield self._check_atom_force_access, u, force # AtomGroup setting yield self._check_atomgroup_positions_setting, u, pos yield self._check_atomgroup_velocities_setting, u, vel yield self._check_atomgroup_forces_setting, u, force # Atom setting yield self._check_atom_position_setting, u, pos yield self._check_atom_velocity_setting, u, vel yield self._check_atom_force_setting, u, force
def test_segment_getattr_multiple(self): u = make_Universe(('resnames',)) u.residues[:3].resnames = 'bar' rg = u.segments[0].bar assert isinstance(rg, groups.ResidueGroup) assert len(rg) == 3
def test_warns(self, missing_attr, tmpdir): attrs = list(self.req_attrs.keys()) attrs.remove(missing_attr) u = make_Universe(attrs, trajectory=True) outfile = str(tmpdir) + '/out.crd' with pytest.warns(UserWarning): u.atoms.write(outfile)
def test_requires_failure_singular(self): @requires('masses') def mass_multiplier(ag1, ag2, scalar): return (ag1.masses + ag2.masses) * scalar u = make_Universe(('charges',)) with pytest.raises(NoDataError): mass_multiplier(u.atoms[:10], u.atoms[20:30], 4.0)
def test_segid_and_resid(): u = make_Universe(('segids', 'resids')) ag = u.select_atoms('segid SegB and resid 1-100') ref = ag.select_atoms('segid SegB').select_atoms('resid 1-100') assert_array_equal(ag.indices, ref.indices)
def test_residuegroup_getattr_multiple(self): u = make_Universe(('resnames',)) u.residues[:10].resnames = 'ABC' rg = u.residues.ABC assert isinstance(rg, groups.ResidueGroup) assert len(rg) == 10
def _check_warns(self, missing_attr): attrs = list(self.req_attrs.keys()) attrs.remove(missing_attr) u = make_Universe(attrs, trajectory=True) tmpdir = tempdir.TempDir() outfile = tmpdir.name + '/out.crd' assert_warns(UserWarning, u.atoms.write, outfile)
def test_requires_failure_multiple(self): @requires('masses', 'charges') def mass_multiplier(ag1, ag2, scalar): return (ag1.masses + ag2.charges) * scalar u = make_Universe(('masses', 'types')) assert_raises(NoDataError, mass_multiplier, u.atoms[:10], u.atoms[20:30], 4.0)
def test_nobonds_warns(self, u): u = make_Universe(('names',)) # empty bond topology attr batt = mda.core.topologyattrs.Bonds([]) u.add_TopologyAttr(batt) with pytest.warns(UserWarning): u.select_atoms('bonded name AAA')
def test_single_name(self): u = make_Universe(trajectory=True) w = XYZWriter(self.outfile, atoms='ABC') w.write(u.trajectory.ts) w.close() u2 = mda.Universe(self.outfile) assert_(all(u2.atoms.names == 'ABC'))
def test_add_Segment_NDE_message(self): u = make_Universe(('segids',)) try: u.add_Segment() except NoDataError as e: assert_('segid' in e[0]) else: raise AssertionError
def test_nobonds_warns(): u = make_Universe(('names',)) # empty bond topology attr batt = mda.core.topologyattrs.Bonds([]) u.add_TopologyAttr(batt) assert_warns(UserWarning, u.select_atoms, 'bonded name AAA')
def test_write_no_types(self, tmpout): u = make_Universe(('masses',), trajectory=True) try: u.atoms.write(tmpout) except NoDataError as e: assert 'types' in e.args[0] else: pytest.fail()
def test_write_non_numerical_types(self): u = make_Universe(('types', 'masses'), trajectory=True) try: u.atoms.write(self.outfile) except ValueError as e: assert_('must be convertible to integers' in e.args[0]) else: raise AssertionError
def test_write_non_numerical_types(self, tmpout): u = make_Universe(('types', 'masses'), trajectory=True) try: u.atoms.write(tmpout) except ValueError as e: assert 'must be convertible to integers' in e.args[0] else: raise pytest.fail()
def test_write_no_types(self): u = make_Universe(('masses',), trajectory=True) try: u.atoms.write(self.outfile) except NoDataError as e: assert_('types' in e.args[0]) else: raise AssertionError
def test_add_Residue_NDE_message(self): # check error message asks for missing attr u = make_Universe(('resnames', 'resids')) try: u.add_Residue(segment=u.segments[0], resid=42) except NoDataError as e: assert_('resname' in e[0]) else: raise AssertionError
def test_requires_success(self): @requires('masses') def mass_multiplier(ag1, ag2, scalar): return (ag1.masses + ag2.masses) * scalar u = make_Universe(('masses',)) result = mass_multiplier(u.atoms[:10], u.atoms[20:30], 4.0) assert isinstance(result, np.ndarray)
def ag(self, request): u = make_Universe(('masses', 'charges')) u.atoms[::2].masses = 1.5 u.atoms[::2].charges = 1.5 return u.atoms[request.param]
def setUp(self): self.u = make_Universe()
def u(): return make_Universe()
def test_wrong_n_atoms(self): from MDAnalysis.coordinates.TRJ import NCDFWriter with NCDFWriter(self.outfile, 100) as w: u = make_Universe(trajectory=True) assert_raises(IOError, w.write, u.trajectory.ts)
def test_atom_fragment_nobonds_NDE(self): # should raise NDE u = make_Universe() assert_raises(NoDataError, getattr, u.atoms[10], 'fragment')
class TestGroupSlicing(object): """All Groups (Atom, Residue, Segment) should slice like a numpy array TODO ---- TopologyGroup is technically called group, add this in too! """ u = make_Universe() # test universe is 5:1 mapping 3 times group_dict = { 'atom': u.atoms, 'residue': u.residues, 'segment': u.segments } singulars = { 'atom': groups.Atom, 'residue': groups.Residue, 'segment': groups.Segment } slices = ( slice(0, 10), slice(0, 2), slice(1, 3), slice(0, 2, 2), slice(0, -1), slice(5, 1, -1), slice(10, 0, -2), ) length = {'atom': 125, 'residue': 25, 'segment': 5} levels = ('atom', 'residue', 'segment') @pytest.fixture(params=levels) def level(self, request): return request.param @pytest.fixture def group(self, level): return self.group_dict[level] @pytest.fixture def nparray(self, level): return np.arange(self.length[level]) @pytest.fixture def singular(self, level): return self.singulars[level] def test_n_atoms(self, group): assert len(group.atoms) == group.n_atoms def test_n_residues(self, group): assert len(group.residues) == group.n_residues def test_n_segments(self, group): assert len(group.segments) == group.n_segments def test_len(self, group, level): ref = self.length[level] assert len(group) == ref @pytest.mark.parametrize('func', [list, np.array]) def test_boolean_slicing(self, group, func): # func is the container type that will be used to slice group = group[:5] sli = func([True, False, False, True, True]) result = group[sli] assert len(result) == 3 for ref, val in zip(sli, group): if ref: assert val in result else: assert val not in result def test_indexerror(self, group, level): idx = self.length[level] with pytest.raises(IndexError): group.__getitem__(idx) @pytest.mark.parametrize('sl,func', itertools.product(( slice(0, 10), slice(0, 2), slice(1, 3), slice(0, 2, 2), slice(0, -1), slice(5, 1, -1), slice(10, 0, -2), ), [list, lambda x: np.array(x, dtype=np.int64)])) def test_slice(self, group, nparray, sl, func): """Check that slicing a np array is identical""" g2 = group[sl] o2 = nparray[sl] assert len(g2) == len(o2) # Check identity of items in the sliced result for o, g in zip(o2, g2): if o in nparray: assert g in g2 else: assert g not in g2 @pytest.mark.parametrize('idx', [0, 1, -1, -2]) def test_integer_getitem(self, group, nparray, idx, singular): a = group[idx] ref = nparray[idx] assert a.ix == ref assert isinstance(a, singular)
def test_missing_icodes_VE(self, u): # trying a selection with icodes in a Universe without raises VA u = make_Universe(('resids', )) with pytest.raises(ValueError): u.select_atoms('resid 10A')
class TestComponentComparisons(object): """Use of operators (< > == != <= >=) with Atom, Residue, and Segment""" u = make_Universe() levels = [u.atoms, u.residues, u.segments] @pytest.fixture(params=levels) def abc(self, request): level = request.param return level[0], level[1], level[2] @pytest.fixture def a(self, abc): return abc[0] @pytest.fixture def b(self, abc): return abc[1] @pytest.fixture def c(self, abc): return abc[2] def test_lt(self, a, b, c): assert a < b assert a < c assert not b < a assert not a < a def test_gt(self, a, b, c): assert b > a assert c > a assert not a > c assert not a > a def test_ge(self, a, b, c): assert b >= a assert c >= a assert b >= b assert not b >= c def test_le(self, a, b, c): assert b <= c assert b <= b assert not b <= a def test_neq(self, a, b, c): assert a != b assert not a != a def test_eq(self, a, b, c): assert a == a assert not a == b def test_sorting(self, a, b, c): assert sorted([b, a, c]) == [a, b, c] @pytest.mark.parametrize('x, y', itertools.permutations( (u.atoms[0], u.residues[0], u.segments[0]), 2)) def test_crosslevel_cmp(self, x, y): with pytest.raises(TypeError): operator.lt(x, y) with pytest.raises(TypeError): operator.le(x, y) with pytest.raises(TypeError): operator.gt(x, y) with pytest.raises(TypeError): operator.ge(x, y) @pytest.mark.parametrize('x, y', itertools.permutations( (u.atoms[0], u.residues[0], u.segments[0]), 2)) def test_crosslevel_eq(self, x, y): with pytest.raises(TypeError): operator.eq(x, y) with pytest.raises(TypeError): operator.ne(x, y)
def u(self): return make_Universe(('segids', 'charges', 'resids'))
def u(self): return make_Universe(trajectory=True)
def u(self): return make_Universe()
class TestGroupAddition(object): """Tests for combining Group objects Contents -------- Addition of Groups should work like list addition Addition of Singular objects should make Group A + A -> AG AG + A -> AG A + AG -> AG AG + AG -> AG Cross level addition (eg AG + RG) raises TypeError Sum() should work on an iterable of many same level Components/Groups Groups contain items "x in y" """ u = make_Universe() levels = ['atom', 'residue', 'segment'] group_dict = { 'atom': u.atoms[:5], 'residue': u.residues[:5], 'segment': u.segments[:5], } singles = { 'atom': u.atoms[0], 'residue': u.residues[0], 'segment': u.segments[0], } groupclasses = { 'atom': groups.AtomGroup, 'residue': groups.ResidueGroup, 'segment': groups.SegmentGroup, } # TODO: actually use this singleclasses = { 'atom': groups.Atom, 'residue': groups.Residue, 'segment': groups.Segment } @pytest.fixture(params=levels) def level(self, request): return request.param @pytest.fixture def group(self, level): return self.group_dict[level] @pytest.fixture def single(self, level): return self.singles[level] @pytest.fixture def two_groups(self, group, single): return itertools.product([group, single], repeat=2) @pytest.fixture def three_groups(self, group, single): return itertools.product([group, single], repeat=3) @staticmethod def itr(x): # singular objects don't iterate try: x[0] except TypeError: return [x] else: return x @pytest.mark.parametrize('a, b, refclass', _yield_groups(group_dict, singles, levels, groupclasses, repeat=2)) def test_addition(self, a, b, refclass): """Combine a and b, check length, returned type and ordering""" newgroup = a + b reflen = len(self.itr(a)) + len(self.itr(b)) assert len(newgroup) == reflen assert isinstance(newgroup, refclass) # Check ordering of created Group for x, y in zip(newgroup, itertools.chain(self.itr(a), self.itr(b))): assert x == y @pytest.mark.parametrize('a, b, c, refclass', _yield_groups(group_dict, singles, levels, groupclasses, repeat=3)) def test_sum(self, a, b, c, refclass): # weird hack in radd allows this summed = sum([a, b, c]) assert isinstance(summed, refclass) assert_equal(len(summed), len(self.itr(a)) + len(self.itr(b)) + len(self.itr(c))) for x, y in zip(summed, itertools.chain(self.itr(a), self.itr(b), self.itr(c))): assert x == y @pytest.mark.parametrize('a, b, c, refclass', _yield_groups(group_dict, singles, levels, groupclasses, repeat=3)) def test_bad_sum(self, a, b, c, refclass): # sum with bad first argument with pytest.raises(TypeError): sum([10, a, b, c]) def test_contains(self, group): assert group[2] in group def test_contains_false(self, group): assert not group[3] in group[:2] @pytest.mark.parametrize( 'one_level, other_level', [(l1, l2) for l1, l2 in itertools.product(levels, repeat=2) if l1 != l2]) def test_contains_wronglevel(self, one_level, other_level): group = self.group_dict[one_level] group2 = self.group_dict[other_level] assert not group[2] in group2 @pytest.mark.parametrize( 'a, b', [(typeA[alevel], typeB[blevel]) for (typeA, typeB), (alevel, blevel) in itertools.product( itertools.product([singles, group_dict], repeat=2), itertools.permutations(levels, 2))]) def test_crosslevel(self, a, b): with pytest.raises(TypeError): a + b
def test_hash_diff_cross_universe(self, level, u): u2 = make_Universe(size=(3, 3, 3)) a = getattr(u, level) b = getattr(u2, level) assert hash(a) != hash(b)
class TestGroupBaseOperators(object): u = make_Universe() components = (u.atoms[0], u.residues[0], u.segments[0]) component_groups = (u.atoms, u.residues, u.segments) @pytest.fixture(params=('atoms', 'residues', 'segments')) def level(self, request): return request.param @pytest.fixture def groups_simple(self, level): n_segments = 10 n_residues = n_segments * 5 n_atoms = n_residues * 5 u = make_Universe(size=(n_atoms, n_residues, n_segments)) # 0123456789 # a **** # b ***** # c ** # e *** # d empty # # None of the group start at 0, nor ends at the end. Each group # has a different size. The end of a slice is not the last element. # This increase the odds of catching errors. a = getattr(u, level)[1:5] b = getattr(u, level)[3:8] c = getattr(u, level)[3:5] d = getattr(u, level)[0:0] e = getattr(u, level)[5:8] return a, b, c, d, e @pytest.fixture def groups_duplicated_and_scrambled(self, level): # The content of the groups is the same as for make_groups, but the # elements can appear several times and their order is scrambled. n_segments = 10 n_residues = n_segments * 5 n_atoms = n_residues * 5 u = make_Universe(size=(n_atoms, n_residues, n_segments)) a = getattr(u, level)[[1, 3, 2, 1, 2, 4, 4]] b = getattr(u, level)[[7, 4, 4, 6, 5, 3, 7, 6]] c = getattr(u, level)[[4, 4, 3, 4, 3, 3]] d = getattr(u, level)[0:0] e = getattr(u, level)[[6, 5, 7, 7, 6]] return a, b, c, d, e @pytest.fixture(params=('simple', 'scrambled')) def groups(self, request, groups_simple, groups_duplicated_and_scrambled): return { 'simple': groups_simple, 'scrambled': groups_duplicated_and_scrambled }[request.param] def test_len(self, groups_simple): a, b, c, d, e = groups_simple assert_equal(len(a), 4) assert_equal(len(b), 5) assert_equal(len(c), 2) assert_equal(len(d), 0) assert_equal(len(e), 3) def test_len_duplicated_and_scrambled(self, groups_duplicated_and_scrambled): a, b, c, d, e = groups_duplicated_and_scrambled assert_equal(len(a), 7) assert_equal(len(b), 8) assert_equal(len(c), 6) assert_equal(len(d), 0) assert_equal(len(e), 5) def test_equal(self, groups): a, b, c, d, e = groups assert a == a assert a != b assert not a == b assert not a[0:1] == a[0], \ 'Element should not equal single element group.' def test_issubset(self, groups): a, b, c, d, e = groups assert c.issubset(a) assert not c.issubset(e) assert not a.issubset(c) assert d.issubset(a) assert not a.issubset(d) def test_is_strict_subset(self, groups): a, b, c, d, e = groups assert c.is_strict_subset(a) assert not c.is_strict_subset(e) assert not a.is_strict_subset(a) def test_issuperset(self, groups): a, b, c, d, e = groups assert a.issuperset(c) assert not e.issuperset(c) assert not c.issuperset(a) assert a.issuperset(d) assert not d.issuperset(a) def test_is_strict_superset(self, groups): a, b, c, d, e = groups assert a.is_strict_superset(c) assert not c.is_strict_superset(e) assert not a.is_strict_superset(a) def test_concatenate(self, groups): a, b, c, d, e = groups cat_ab = a.concatenate(b) assert cat_ab[:len(a)] == a assert cat_ab[len(a):] == b cat_ba = b.concatenate(a) assert cat_ba[:len(b)] == b assert cat_ba[len(b):] == a cat_aa = a.concatenate(a) assert cat_aa[:len(a)] == a assert cat_aa[len(a):] == a cat_ad = a.concatenate(d) assert cat_ad == a cat_da = d.concatenate(a) assert cat_da == a def test_union(self, groups): a, b, c, d, e = groups union_ab = a.union(b) assert union_ab.ix.tolist() == sorted(union_ab.ix) assert list(sorted(set(union_ab.ix))) == list(sorted(union_ab.ix)) assert a.union(b) == b.union(a) assert_array_equal(a.union(a).ix, np.arange(1, 5)) assert a.union(d), np.arange(1, 5) def test_intersection(self, groups): a, b, c, d, e = groups intersect_ab = a.intersection(b) assert_array_equal(intersect_ab.ix, np.arange(3, 5)) assert a.intersection(b) == b.intersection(a) assert_equal(len(a.intersection(d)), 0) def test_subtract(self, groups): a, b, c, d, e = groups subtract_ab = a.subtract(b) reference = np.array([1, 2, 1, 2]) # The groups can be "simple" or "scrambled", if they are simple they # do not contain repetitions and they are ordered. The reference for # the simple groups should follow the same patern and should be ordered # and without repetitions. if len(a) == len(np.unique(a)): reference = np.unique(reference) assert_array_equal(subtract_ab.ix, reference) subtract_ba = b.subtract(a) reference = np.array([7, 6, 5, 7, 6]) if len(a) == len(np.unique(a)): reference = np.unique(reference) assert_array_equal(subtract_ba.ix, reference) subtract_ad = a.subtract(d) assert_equal(subtract_ad, a) subtract_ae = a.subtract(e) assert_equal(subtract_ae, a) def test_difference(self, groups): a, b, c, d, e = groups difference_ab = a.difference(b) assert_array_equal(difference_ab.ix, np.arange(1, 3)) difference_ba = b.difference(a) assert_array_equal(difference_ba.ix, np.arange(5, 8)) assert_array_equal(a.difference(d).ix, np.arange(1, 5)) assert_array_equal(a.difference(e).ix, np.arange(1, 5)) def test_symmetric_difference(self, groups): a, b, c, d, e = groups symdiff_ab = a.symmetric_difference(b) assert_array_equal(symdiff_ab.ix, np.array(list(range(1, 3)) + list(range(5, 8)))) assert a.symmetric_difference(b) == b.symmetric_difference(a) assert_array_equal(a.symmetric_difference(e).ix, np.arange(1, 8)) def test_isdisjoint(self, groups): a, b, c, d, e = groups assert a.isdisjoint(e) assert e.isdisjoint(a) assert a.isdisjoint(d) assert d.isdisjoint(a) assert not a.isdisjoint(b) @pytest.mark.parametrize( 'left, right', itertools.chain( # Do inter-levels pairs of groups fail as expected? itertools.permutations(component_groups, 2), # Do inter-levels pairs of components itertools.permutations(components, 2), # Do inter-levels pairs of components/groups fail as expected? _yield_mix(component_groups, components), # Does the function fail with inputs that are not components or groups ( (u.atoms, 'invalid'), ), )) def test_failing_pairs(self, left, right): def dummy(self, other): return True with pytest.raises(TypeError): mda.core.groups._only_same_level(dummy)(left, right) @pytest.mark.parametrize( 'left, right', itertools.chain( # Groups _yield_sliced_groups(u, slice(0, 2), slice(1, 3)), # Components _yield_sliced_groups(u, 0, 1), # Mixed _yield_sliced_groups(u, slice(0, 2), 1), _yield_sliced_groups(u, 1, slice(0, 2)), )) def test_succeeding_pairs(self, left, right): def dummy(self, other): return True assert mda.core.groups._only_same_level(dummy)(left, right) def test_only_same_level_different_universes(self): def dummy(self, other): return True u = make_Universe() u2 = make_Universe() _only_same_level = mda.core.groups._only_same_level with pytest.raises(ValueError): _only_same_level(dummy)(u.atoms, u2.atoms) @pytest.mark.parametrize( 'op, method', ((operator.add, 'concatenate'), (operator.sub, 'difference'), (operator.and_, 'intersection'), (operator.or_, 'union'), (operator.xor, 'symmetric_difference'))) def test_shortcut_overriding(self, op, method, level): def check_operator(op, method, level): left = getattr(u, level)[1:3] right = getattr(u, level)[2:4] assert_equal(op(left, right), getattr(left, method)(right)) n_segments = 5 n_residues = n_segments * 3 n_atoms = n_residues * 3 u = make_Universe(size=(n_atoms, n_residues, n_segments)) check_operator(op, method, level)
def test_missing_icodes_range_VE(self, u): u = make_Universe(('resids', )) with pytest.raises(ValueError): u.select_atoms('resid 10A-12')
def u(self): return make_Universe(size=(3, 3, 3))
def test_mol2_write_NIE(): mytempdir = tempdir.TempDir() outfile = os.path.join(mytempdir.name, 'test.mol2') u = make_Universe(trajectory=True) assert_raises(NotImplementedError, u.atoms.write, outfile)
def setUp(self): self.universe = make_Universe(('segids', )) self.sB = self.universe.segments[1]
def ag(self): u = make_Universe(trajectory=True) return u.atoms[10:30]
def u_no_resids(self): return make_Universe(['names', 'resnames'], trajectory=True)
def setUp(self): self.u = make_Universe(("resids", "resnames", "segids", "names"))
def universe(): return make_Universe( ('names', 'types', 'resids', 'resnums', 'resnames', 'segids'))
def setUp(self): self.u = make_Universe(('types', 'charges', 'resids'))
def test_PDB_atom_repr(self): u = make_Universe(extras=('altLocs', 'names', 'types', 'resnames', 'resids', 'segids')) assert_equal( "<Atom 1: AAA of type TypeA of resname RsA, resid 1 and segid SegA and altLoc A>", u.atoms[0].__repr__())
def test_mol2_write_NIE(tmpdir): with tmpdir.as_cwd(): outfile = os.path.join('test.mol2') u = make_Universe(trajectory=True) with pytest.raises(NotImplementedError): u.atoms.write(outfile)
def u_no_names(): return make_Universe(['resids', 'resnames'], trajectory=True)
def test_guess_bonds_Error(): u = make_Universe(trajectory=True) with pytest.raises(ValueError): guessers.guess_bonds(u.atoms[:4], u.atoms.positions[:5])
def u(self): return make_Universe(("resids", "resnames", "segids", "names"))
def attr_universe(): return make_Universe(('names', 'resids', 'segids'))
def universe(): return make_Universe( ('names', 'masses', 'resids', 'resnames', 'resnums'))