Ejemplo n.º 1
0
    def testMatchNodeToNode(self):
        """
        Test that nodes can match other nodes.
        """
        entry1 = Entry(item=Group().fromAdjacencyList("""
        1 *1 R!H u1
        """))

        entry2 = Entry(item=Group().fromAdjacencyList("""
        1 *1 Cb u1
        """))
        self.assertTrue(self.database.matchNodeToNode(entry1, entry1))
        self.assertFalse(self.database.matchNodeToNode(entry1, entry2))
 def clean_group(self):
         """
         Custom validation for the species field to ensure that a valid adjacency
         list has been provided.
         """
         from rmgpy.molecule import Group
         try:
             adjlist = str(self.cleaned_data['group'])
             if adjlist == '' : return ''
             group = Group()
             group.fromAdjacencyList(str(self.cleaned_data['group']))
         except Exception, e:
             import traceback
             traceback.print_exc(e)
             raise forms.ValidationError('Invalid adjacency list.')
Ejemplo n.º 3
0
 def clean_group(self):
         """
         Custom validation for the species field to ensure that a valid adjacency
         list has been provided.
         """
         from rmgpy.molecule import Group
         try:
             adjlist = str(self.cleaned_data['group'])
             if adjlist == '' : return ''
             group = Group()
             group.fromAdjacencyList(str(self.cleaned_data['group']))
         except Exception, e:
             import traceback
             traceback.print_exc(e)
             raise forms.ValidationError('Invalid adjacency list.')
Ejemplo n.º 4
0
 def loadEntry(
     self,
     index,
     label,
     group,
     statmech,
     reference=None,
     referenceType='',
     shortDesc='',
     longDesc='',
 ):
     if (group[0:3].upper() == 'OR{' or group[0:4].upper() == 'AND{'
             or group[0:7].upper() == 'NOT OR{'
             or group[0:8].upper() == 'NOT AND{'):
         item = makeLogicNode(group)
     else:
         item = Group().fromAdjacencyList(group)
     self.entries[label] = Entry(
         index=index,
         label=label,
         item=item,
         data=statmech,
         reference=reference,
         referenceType=referenceType,
         shortDesc=shortDesc,
         longDesc=longDesc.strip(),
     )
Ejemplo n.º 5
0
 def load_entry(self,
                index,
                label,
                group,
                transportGroup,
                reference=None,
                referenceType='',
                shortDesc='',
                longDesc='',
                ):
     """
     Method for parsing entries in database files.
     Note that these argument names are retained for backward compatibility.
     """
     if (group[0:3].upper() == 'OR{' or
             group[0:4].upper() == 'AND{' or
             group[0:7].upper() == 'NOT OR{' or
             group[0:8].upper() == 'NOT AND{'):
         item = make_logic_node(group)
     else:
         item = Group().from_adjacency_list(group)
     self.entries[label] = Entry(
         index=index,
         label=label,
         item=item,
         data=transportGroup,
         reference=reference,
         reference_type=referenceType,
         short_desc=shortDesc,
         long_desc=longDesc.strip(),
     )
Ejemplo n.º 6
0
 def load_entry(
         self,
         index,
         label,
         group,
         distances,
         reference=None,
         reference_type='',
         short_desc='',
         long_desc=''):
     if group[0:3].upper() == 'OR{' or group[0:4].upper(
     ) == 'AND{' or group[0:7].upper() == 'NOT OR{' or group[0:8].upper() == 'NOT AND{':
         item = make_logic_node(group)
     else:
         item = Group().from_adjacency_list(group)
     self.entries[label] = Entry(
         index=index,
         label=label,
         item=item,
         data=distances,
         reference=reference,
         reference_type=reference_type,
         short_desc=short_desc,
         long_desc=long_desc.strip(),
     )
Ejemplo n.º 7
0
    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()))
Ejemplo n.º 8
0
    def loadEntry(
        self,
        index,
        group1=None,
        group2=None,
        group3=None,
        group4=None,
        kinetics=None,
        degeneracy=1,
        label='',
        duplicate=False,
        reversible=True,
        reference=None,
        referenceType='',
        shortDesc='',
        longDesc='',
        rank=None,
    ):

        reactants = []

        if group1[0:3].upper() == 'OR{' or group1[0:4].upper(
        ) == 'AND{' or group1[0:7].upper() == 'NOT OR{' or group1[0:8].upper(
        ) == 'NOT AND{':
            reactants.append(makeLogicNode(group1))
        else:
            reactants.append(Group().fromAdjacencyList(group1))
        if group2 is not None:
            if group2[0:3].upper() == 'OR{' or group2[0:4].upper(
            ) == 'AND{' or group2[0:7].upper(
            ) == 'NOT OR{' or group2[0:8].upper() == 'NOT AND{':
                reactants.append(makeLogicNode(group2))
            else:
                reactants.append(Group().fromAdjacencyList(group2))
        if group3 is not None:
            if group3[0:3].upper() == 'OR{' or group3[0:4].upper(
            ) == 'AND{' or group3[0:7].upper(
            ) == 'NOT OR{' or group3[0:8].upper() == 'NOT AND{':
                reactants.append(makeLogicNode(group3))
            else:
                reactants.append(Group().fromAdjacencyList(group3))
        if group4 is not None:
            if group4[0:3].upper() == 'OR{' or group4[0:4].upper(
            ) == 'AND{' or group4[0:7].upper(
            ) == 'NOT OR{' or group4[0:8].upper() == 'NOT AND{':
                reactants.append(makeLogicNode(group4))
            else:
                reactants.append(Group().fromAdjacencyList(group4))

        reaction = Reaction(reactants=reactants, products=[])

        entry = Entry(
            index=index,
            label=label,
            item=reaction,
            data=kinetics,
            reference=reference,
            referenceType=referenceType,
            shortDesc=shortDesc,
            longDesc=longDesc.strip(),
            rank=rank,
        )
        try:
            self.entries[label].append(entry)
        except KeyError:
            self.entries[label] = [entry]
        return entry