Esempio n. 1
0
class TestBaseDatabase(unittest.TestCase):
    """
    Contains unit tests for the base class of rmgpy.data.
    """
    def setUp(self):
        """
        A function run before each unit test in this class.
        """
        # Set up a dummy database
        self.database = Database()

    def test_match_node_to_structure(self):
        """
        Test that the MatchNodeToStructure family works properly.
        """
        entry1 = Entry(item=Group().from_adjacency_list("""
                1 *3 C  u1 {2,D} {3,S}
                2    C  u0 {1,D}
                3 *5 Cd u0 {1,S} {4,D}
                4    C  u0 {3,D}
                """))

        entry2 = Entry(item=Group().from_adjacency_list("""
                1 *3 C  u1 {2,D} {3,S}
                2 *5 C  u0 {1,D}
                3    Cd u0 {1,S} {4,D}
                4    C  u0 {3,D}
                """))

        entry3 = Entry(item=Group().from_adjacency_list("""
                1 *3 C  u1 {2,D} {3,S}
                2    C  u0 {1,D}
                3    Cd u0 {1,S} {4,D}
                4    C  u0 {3,D}
                """))
        # The group should match to itself
        self.assertTrue(
            self.database.match_node_to_structure(
                entry1, entry1.item,
                atoms=entry1.item.get_all_labeled_atoms()))

        # These groups should not match each other
        self.assertFalse(
            self.database.match_node_to_structure(
                entry1, entry2.item,
                atoms=entry2.item.get_all_labeled_atoms()))

        # entry1 contains more labels than entry3, therefore cannot be matched by entry3
        self.assertFalse(
            self.database.match_node_to_structure(
                entry3, entry1.item,
                atoms=entry1.item.get_all_labeled_atoms()))

        # entry3 contains fewer labels than entry1, therefore it can be matched
        self.assertTrue(
            self.database.match_node_to_structure(
                entry1, entry3.item,
                atoms=entry3.item.get_all_labeled_atoms()))

    def test_match_node_to_node(self):
        """
        Test that nodes can match other nodes.
        """
        entry1 = Entry(item=Group().from_adjacency_list("""
                1 *1 R!H u1
                """))

        entry2 = Entry(item=Group().from_adjacency_list("""
                1 *1 Cb u1
                """))
        self.assertTrue(self.database.match_node_to_node(entry1, entry1))
        self.assertFalse(self.database.match_node_to_node(entry1, entry2))