예제 #1
0
    def test_TG_without_bondclass(self):
        ag = self.universe.atoms

        tg = TopologyGroup.from_indices([(0, 1), (1, 2), (2, 3)], ag)
        assert_(len(tg) == 3)
        assert_(type(tg[0]) == Bond)

        tg = TopologyGroup.from_indices([(0, 1, 2), (1, 2, 3), (2, 3, 4)], ag)
        assert_(len(tg) == 3)
        assert_(type(tg[0]) == Angle)

        tg = TopologyGroup.from_indices([(0, 1, 2, 3), (1, 2, 3, 4)], ag)
        assert_(len(tg) == 2)
        assert_(type(tg[0]) == Dihedral)
예제 #2
0
    def test_angle_tg_creation_notype(self, PSFDCD):
        vals = np.array([[0, 5, 10], [5, 10, 15]])
        tg = TopologyGroup(vals, PSFDCD)

        assert tg.btype == 'angle'
        assert_equal(tg[0].indices, (0, 5, 10))
        assert_equal(tg[1].indices, (5, 10, 15))
예제 #3
0
    def test_TG_getitem_fancy(self, PSFDCD):
        tg = PSFDCD.atoms.bonds[:10]
        tg2 = tg[[1, 4, 5]]

        manual = TopologyGroup(tg.indices[[1, 4, 5]], tg.universe, tg.btype)

        assert list(tg2) == list(manual)
예제 #4
0
    def test_TG_without_bondclass(self):
        ag = self.universe.atoms

        tg = TopologyGroup.from_indices([(0, 1), (1, 2), (2, 3)], ag)
        assert_(len(tg) == 3)
        assert_(type(tg[0]) == Bond)

        tg = TopologyGroup.from_indices([(0, 1, 2), (1, 2, 3), (2, 3, 4)],
                                        ag)
        assert_(len(tg) == 3)
        assert_(type(tg[0]) == Angle)

        tg = TopologyGroup.from_indices([(0, 1, 2, 3), (1, 2, 3, 4)],
                                        ag)
        assert_(len(tg) == 2)
        assert_(type(tg[0]) == Dihedral)
예제 #5
0
    def test_dihedral_tg_creation_notype(self):
        vals = np.array([[0, 2, 4, 6], [5, 7, 9, 11]])

        tg = TopologyGroup(vals, self.universe)

        assert_(tg.btype == 'dihedral')
        assert_array_equal(tg[0].indices, (0, 2, 4, 6))
        assert_array_equal(tg[1].indices, (5, 7, 9, 11))
예제 #6
0
    def test_TG_getitem_fancy(self):
        tg = self.universe.bonds[:10]

        tg2 = tg[[1, 4, 5]]

        manual = TopologyGroup([tg[i] for i in [1, 4, 5]])

        assert_equal(list(tg2), list(manual))
예제 #7
0
    def test_dihedral_tg_creation_notype(self, PSFDCD):
        vals = np.array([[0, 2, 4, 6], [5, 7, 9, 11]])

        tg = TopologyGroup(vals, PSFDCD)

        assert tg.btype == 'dihedral'
        assert_equal(tg[0].indices, (0, 2, 4, 6))
        assert_equal(tg[1].indices, (5, 7, 9, 11))
예제 #8
0
    def test_TG_getitem_fancy(self):
        tg = self.universe.atoms.bonds[:10]

        tg2 = tg[[1, 4, 5]]

        manual = TopologyGroup(tg.indices[[1, 4, 5]], tg.universe, tg.btype)

        assert_equal(list(tg2), list(manual))
예제 #9
0
    def test_angle_tg_creation_notype(self):
        vals = np.array([[0, 5, 10], [5, 10, 15]])

        tg = TopologyGroup(vals, self.universe)

        assert_(tg.btype == 'angle')
        assert_array_equal(tg[0].indices, (0, 5, 10))
        assert_array_equal(tg[1].indices, (5, 10, 15))
예제 #10
0
        def manual(topg, atomg):
            if len(atomg) == 1:  # hack for Atom input
                atomg = [atomg]
            man = []
            for b in topg.bondlist:
                if all(a in atomg for a in b.atoms):
                    man.append(b)

            if len(man) > 0:
                return TopologyGroup(man)
            else:
                return None
예제 #11
0
    def test_create_empty_TG(self):
        tg = TopologyGroup([])

        def check(a):
            if a:
                return True
            else:
                return False

        assert_equal(check(tg), False)
        assert_equal(len(tg), 0)
        assert_equal(tg.toptype, None)
예제 #12
0
    def test_from_indices_nonglobal_idx(self):
        idx = [(0, 1), (4, 5)]

        ag = self.universe.atoms[100:]

        tg = TopologyGroup.from_indices(idx, ag)

        b1 = self.universe.atoms[[100, 101]].bond
        b2 = self.universe.atoms[[104, 105]].bond

        assert_(b1 in tg)
        assert_(b2 in tg)
예제 #13
0
    def test_from_indices_nonglobal_idx(self):
        idx = [(0, 1), (4, 5)]

        ag = self.universe.atoms[100:]

        tg = TopologyGroup.from_indices(idx, ag)

        b1 = self.universe.atoms[[100, 101]].bond
        b2 = self.universe.atoms[[104, 105]].bond

        assert_(b1 in tg)
        assert_(b2 in tg)
예제 #14
0
    def test_TG_indices_creation(self):
        """Create a TG from indices"""
        bonds = [(0, 1), (1, 2)]

        tg = TopologyGroup.from_indices(bonds, self.universe.atoms,
                                        bondclass=Bond)

        assert_equal(len(tg), 2)
        b1 = self.universe.atoms[[0, 1]].bond
        b2 = self.universe.atoms[[1, 2]].bond
        assert_(b1 in tg)
        assert_(b2 in tg)
        assert_equal(bonds, tg.to_indices())
예제 #15
0
    def test_TG_from_indices_roundtrip(self):
        """Round trip check of dumping indices then recreating"""
        tg = self.universe.bonds[:10]
        idx = tg.to_indices()

        tg2 = TopologyGroup.from_indices(idx, self.universe.atoms,
                                         bondclass=Bond)

        # This doesn't work as it uses set operation and .from_indices
        # has created new Bond instances
        # assert_equal(tg, tg2)
        # instead...
        assert_equal(len(tg), len(tg2))
        assert_equal(tg.to_indices(), tg2.to_indices())
예제 #16
0
    def test_TG_indices_creation(self):
        """Create a TG from indices"""
        bonds = [(0, 1), (1, 2)]

        tg = TopologyGroup.from_indices(bonds,
                                        self.universe.atoms,
                                        bondclass=Bond)

        assert_equal(len(tg), 2)
        b1 = self.universe.atoms[[0, 1]].bond
        b2 = self.universe.atoms[[1, 2]].bond
        assert_(b1 in tg)
        assert_(b2 in tg)
        assert_equal(bonds, tg.to_indices())
예제 #17
0
    def test_TG_from_indices_roundtrip(self):
        """Round trip check of dumping indices then recreating"""
        tg = self.universe.bonds[:10]
        idx = tg.to_indices()

        tg2 = TopologyGroup.from_indices(idx,
                                         self.universe.atoms,
                                         bondclass=Bond)

        # This doesn't work as it uses set operation and .from_indices
        # has created new Bond instances
        # assert_equal(tg, tg2)
        # instead...
        assert_equal(len(tg), len(tg2))
        assert_equal(tg.to_indices(), tg2.to_indices())
예제 #18
0
    def test_verticalTG(self):
        b1 = self.universe.atoms[0].dihedrals[0]
        b2 = self.universe.atoms[20].dihedrals[0]

        TG = TopologyGroup([b1, b2])

        forwards = [AtomGroup([b1[i], b2[i]]) for i in range(4)]
        backwards = [AtomGroup([b2[i], b1[i]]) for i in range(4)]

        verts = [TG.atom1, TG.atom2, TG.atom3, TG.atom4]

        # the lists might be in one of two formats, but always in a strict order
        # ie any(1234 or 4321) but not (1324)
        assert_equal(
            any([
                all(list(x) == list(y) for x, y in zip(forwards, verts)),
                all(list(x) == list(y) for x, y in zip(backwards, verts))
            ]), True)
예제 #19
0
 def _load_bonds(self):
     # Load some bonds into Universe, not required for all tests
     bondlist = [(0, 1), (1, 2), (1, 3), (1, 4), (4, 5), (4, 6), (4, 7)]
     tg = TopologyGroup.from_indices(bondlist, self.u.atoms, bondclass=Bond)
     self.u.bonds = tg
예제 #20
0
 def test_force_bondclass(self):
     # Make a TG of improper dihedral
     tg = TopologyGroup.from_indices([(0, 1, 2, 3), (2, 3, 4, 6)],
                                     self.universe.atoms,
                                     bondclass=ImproperDihedral)
     assert_(type(tg[0]) == ImproperDihedral)
예제 #21
0
    def test_create_guessed_tg_2(self):
        vals = np.array([[0, 10], [5, 15]])

        tg = TopologyGroup(vals, self.universe, guessed=False)

        assert_array_equal(tg._guessed, np.array([[False], [False]]))
    def test_nobonds_warns(self):
        self.u.bonds = TopologyGroup([])

        assert_warns(UserWarning, self.u.select_atoms,
                     'type 2 and bonded name N')
예제 #23
0
 def manual(topg, atomg):
     man = []
     for b in topg.bondlist:
         if any(a in atomg for a in b.atoms):
             man.append(b)
     return TopologyGroup(man)
예제 #24
0
    def test_create_guessed_tg_2(self, PSFDCD):
        vals = np.array([[0, 10], [5, 15]])
        tg = TopologyGroup(vals, PSFDCD, guessed=False)

        assert_equal(tg._guessed, np.array([[False], [False]]))
예제 #25
0
 def test_tg_creation_bad_btype(self, PSFDCD):
     vals = np.array([[0, 10], [5, 15]])
     with pytest.raises(ValueError):
         TopologyGroup(vals, PSFDCD, btype='apple')
예제 #26
0
 def test_bad_creation_TG(self):
     """Test making a TopologyGroup out of nonsense"""
     inputlist = ['a', 'b', 'c']
     with pytest.raises(TypeError):
         TopologyGroup(inputlist)
예제 #27
0
 def _load_bonds(self):
     # Load some bonds into Universe, not required for all tests
     bondlist = [(0, 1), (1, 2), (1, 3), (1, 4), (4, 5), (4, 6), (4, 7)]
     tg = TopologyGroup.from_indices(bondlist, self.u.atoms, bondclass=Bond)
     self.u.bonds = tg
예제 #28
0
 def test_force_bondclass(self):
     # Make a TG of improper dihedral
     tg = TopologyGroup.from_indices([(0, 1, 2, 3), (2, 3, 4, 6)],
                                     self.universe.atoms,
                                     bondclass=ImproperDihedral)
     assert_(type(tg[0]) == ImproperDihedral)