Exemplo n.º 1
0
        def test_indices(self):
            def callback(mer1, mer2, val):
                # This is just for prettiness. It won't fail the test.
                self.assertEqual(
                    self.struct.contact_map.get_contact_value(mer1, mer2), val)

                # This is ugly. Failing assertion inside a callback doesn't
                # prevent it from returning to C. Unittest in such a case is
                # unable to catch an exception and fail the test. We have to
                # pass the failure to C, check for it, and pass it back to
                # Python.
                if self.struct.contact_map.get_contact_value(mer1,
                                                             mer2) != val:
                    return 1
                else:
                    return 0

            CBFUNC = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_int, ctypes.c_int,
                                      ctypes.c_int)

            cs = cydesc.CStructure(self.struct)
            ccm = cydesc.CContactMap(cs, self.struct.contact_map)
            res = libcydesc_test.CContactMapTest_indices(
                ctypes.byref(ccm), CBFUNC(callback))
            self.assertEqual(res, 0)
Exemplo n.º 2
0
        def test_init(self):
            cs = cydesc.CStructure(self.struct)

            self.assertEqual(self.struct.name, cs.name)
            self.assertEqual(cs.n_monomers, len(self.struct))

            for m, cm in zip(self.struct, cs.monomers):
                assert_monomers_equal(self, m, cm)

            def renumber(seg):
                return [list(self.struct)[i].ind for i in list(seg)]

            sum_len = 0
            for seg in cs.segs[0:cs.n_segs]:
                start, end = seg
                frag = self.struct[start:end]
                sum_len += len(frag)

                if seg.start != seg.end:
                    self.assertIsInstance(frag, structure.Segment)

            self.assertEqual(len(self.struct), sum_len)

            for s1, s2 in zip(cs.segs[0:cs.n_segs], cs.segs[1:cs.n_segs]):
                end1 = s1.end
                start2 = s2.start
                frag = self.struct[end1:start2]
                self.assertIsInstance(frag, structure.UserStructure)

            repr(cs)
Exemplo n.º 3
0
    def structure(self, struct):
        """
        Structure setter. Creates a corresponding C structure.
        """

        # This method is called in __init__
        # pylint: disable=W0201
        self._structure = struct
        self._c_structure = None if struct is None else cydesc.CStructure(struct)
Exemplo n.º 4
0
        def test_adjusted_number(self):
            cs = cydesc.CStructure(self.struct)

            for dummy in range(100):
                start, end = sorted(
                    map(operator.attrgetter('ind'),
                        random.sample(list(self.struct), 2)))
                res = libcydesc_test.CStructureTest_adjusted_number(
                    ctypes.byref(cs), start, end)

                self.assertEqual(res, self.struct[start:end].adjusted_number())
Exemplo n.º 5
0
        def test_init(self):
            cs = cydesc.CStructure(self.struct)
            ccm = cydesc.CContactMap(cs, self.struct.contact_map)

            n_contacts = sum(
                map(len, self.struct.contact_map.contacts.values()))

            self.assertEqual(ctypes.addressof(ccm.structure.contents),
                             ctypes.addressof(cs))
            self.assertEqual(ccm.n_contacts, n_contacts)

            visited = {}

            for c in ccm.contacts[0:n_contacts]:
                self.assertEqual(
                    c.val,
                    self.struct.contact_map.get_contact_value(c.mer1, c.mer2))
                if (c.mer1, c.mer2) in visited:
                    self.fail("Contact duplicated")
                visited[(c.mer1, c.mer2)] = 1
                repr(c)

            repr(ccm)
Exemplo n.º 6
0
        def test_del(self):
            cs = cydesc.CStructure(self.struct)
            ccm = cydesc.CContactMap(cs, self.struct.contact_map)

            del ccm
Exemplo n.º 7
0
 def test_indices(self):
     cs = cydesc.CStructure(self.struct)
     res = libcydesc_test.CStructureTest_indices(ctypes.byref(cs))
     self.assertEqual(res, 0)