Exemplo n.º 1
0
    def kinetics_checkChildParentRelationships(self, family_name):
        """
        This test checks that groups' parent-child relationships are correct in the database.
        """
        from rmgpy.data.base import Database
        originalFamily = self.database.kinetics.families[family_name]
        family = Database()
        family.entries = originalFamily.groups.entries
        for nodeName, childNode in family.entries.iteritems():
            #top nodes and product nodes don't have parents by definition, so they get an automatic pass:
            if childNode in originalFamily.groups.top or childNode in originalFamily.forwardTemplate.products: continue
            parentNode = childNode.parent
            # Check whether the node has proper parents unless it is the top reactant or product node
            # The parent should be more general than the child
            nose.tools.assert_true(family.matchNodeToChild(parentNode, childNode),
                            "In {family} family, group {parent} is not a proper parent of its child {child}.".format(family=family_name, parent=parentNode, child=nodeName))

            #check that parentNodes which are LogicOr do not have an ancestor that is a Group
            #If it does, then the childNode must also be a child of the ancestor
            if isinstance(parentNode, LogicOr):
                ancestorNode = childNode
                while ancestorNode not in originalFamily.groups.top and isinstance(ancestorNode, LogicOr):
                    ancestorNode = ancestorNode.parent
                if isinstance(ancestorNode, Group):
                    nose.tools.assert_true(family.matchNodeToChild(ancestorNode, childNode),
                                    "In {family} family, group {ancestor} is not a proper ancestor of its child {child}.".format(family=family_name, ancestor=ancestorNode, child=nodeName))
Exemplo n.º 2
0
    def kinetics_checkChildParentRelationships(self, family_name):
        """
        This test checks that groups' parent-child relationships are correct in the database.
        """
        from rmgpy.data.base import Database
        originalFamily = self.database.kinetics.families[family_name]
        family = Database()
        family.entries = originalFamily.groups.entries
        for nodeName, childNode in family.entries.iteritems():
            #top nodes and product nodes don't have parents by definition, so they get an automatic pass:
            if childNode in originalFamily.groups.top or childNode in originalFamily.forwardTemplate.products:
                continue
            parentNode = childNode.parent
            # Check whether the node has proper parents unless it is the top reactant or product node
            # The parent should be more general than the child
            nose.tools.assert_true(
                family.matchNodeToChild(parentNode, childNode),
                "In {family} family, group {parent} is not a proper parent of its child {child}."
                .format(family=family_name, parent=parentNode, child=nodeName))

            #check that parentNodes which are LogicOr do not have an ancestor that is a Group
            #If it does, then the childNode must also be a child of the ancestor
            if isinstance(parentNode, LogicOr):
                ancestorNode = childNode
                while ancestorNode not in originalFamily.groups.top and isinstance(
                        ancestorNode, LogicOr):
                    ancestorNode = ancestorNode.parent
                if isinstance(ancestorNode, Group):
                    nose.tools.assert_true(
                        family.matchNodeToChild(ancestorNode, childNode),
                        "In {family} family, group {ancestor} is not a proper ancestor of its child {child}."
                        .format(family=family_name,
                                ancestor=ancestorNode,
                                child=nodeName))
Exemplo n.º 3
0
    def kinetics_checkSiblingsForParents(self, family_name):
        """
        This test checks that siblings in a tree are not actually parent/child
        """
        from rmgpy.data.base import Database

        originalFamily = self.database.kinetics.families[family_name]
        family = Database()
        family.entries = originalFamily.groups.entries
        for nodeName, node in family.entries.iteritems():
            # Some families also construct a 2-level trees for the products
            # (root with all entries down one level) We don't care about this
            # tree as it is not used in searching, so we ignore products
            if node in originalFamily.forwardTemplate.products:
                continue
            for index, child1 in enumerate(node.children):
                for child2 in node.children[index + 1 :]:
                    # Don't check a node against itself
                    if child1 is child2:
                        continue
                    nose.tools.assert_false(
                        family.matchNodeToChild(child1, child2),
                        "In family {0}, node {1} is written as a sibling of {2}, when it is actually a parent.".format(
                            family_name, child1, child2
                        ),
                    )
                    nose.tools.assert_false(
                        family.matchNodeToChild(child2, child1),
                        "In family {0}, node {1} is written as a sibling of {2}, when it is actually a parent.".format(
                            family_name, child2, child1
                        ),
                    )
Exemplo n.º 4
0
 def kinetics_checkSiblingsForParents(self, family_name):
     """
     This test checks that siblings in a tree are not actually parent/child
     """
     from rmgpy.data.base import Database
     originalFamily = self.database.kinetics.families[family_name]
     family = Database()
     family.entries = originalFamily.groups.entries
     for nodeName, node in family.entries.iteritems():
         #Some families also construct a 2-level trees for the products
         #(root with all entries down one level) We don't care about this
         #tree as it is not used in searching, so we ignore products
         if node in originalFamily.forwardTemplate.products: continue
         for index, child1 in enumerate(node.children):
             for child2 in node.children[index + 1:]:
                 #Don't check a node against itself
                 if child1 is child2: continue
                 nose.tools.assert_false(
                     family.matchNodeToChild(child1, child2),
                     "In family {0}, node {1} is written as a sibling of {2}, when it is actually a parent."
                     .format(family_name, child1, child2))
                 nose.tools.assert_false(
                     family.matchNodeToChild(child2, child1),
                     "In family {0}, node {1} is written as a sibling of {2}, when it is actually a parent."
                     .format(family_name, child2, child1))