Esempio n. 1
0
    def testSubgraphIsomorphismManyLabels(self):
        molecule = Molecule()  # specific case (species)
        molecule.fromAdjacencyList("""
1 *1 C  u1 p0 c0 {2,S} {3,S} {4,S}
2    C  u0 p0 c0 {1,S} {3,S} {5,S} {6,S}
3    C  u0 p0 c0 {1,S} {2,S} {7,S} {8,S}
4    H  u0 p0 c0 {1,S}
5    H  u0 p0 c0 {2,S}
6    H  u0 p0 c0 {2,S}
7    H  u0 p0 c0 {3,S}
8    H  u0 p0 c0 {3,S}
        """)

        group = Group()  # general case (functional group)
        group.fromAdjacencyList("""
1 *1 C   u1 p0 c0 {2,S}, {3,S}
2    R!H u0 p0 c0 {1,S}
3    R!H u0 p0 c0 {1,S}
        """)

        labeled1 = molecule.getLabeledAtoms()
        labeled2 = group.getLabeledAtoms()
        initialMap = {}
        for label, atom1 in labeled1.iteritems():
            initialMap[atom1] = labeled2[label]
        self.assertTrue(molecule.isSubgraphIsomorphic(group, initialMap))

        mapping = molecule.findSubgraphIsomorphisms(group, initialMap)
        self.assertEqual(len(mapping), 2)
        for map in mapping:
            self.assertTrue(
                len(map) == min(len(molecule.atoms), len(group.atoms)))
            for key, value in map.iteritems():
                self.assertTrue(key in molecule.atoms)
                self.assertTrue(value in group.atoms)
Esempio n. 2
0
    def testSubgraphIsomorphismManyLabels(self):
        molecule = Molecule() # specific case (species)
        molecule.fromAdjacencyList("""
1 *1 C  u1 p0 c0 {2,S} {3,S} {4,S}
2    C  u0 p0 c0 {1,S} {3,S} {5,S} {6,S}
3    C  u0 p0 c0 {1,S} {2,S} {7,S} {8,S}
4    H  u0 p0 c0 {1,S}
5    H  u0 p0 c0 {2,S}
6    H  u0 p0 c0 {2,S}
7    H  u0 p0 c0 {3,S}
8    H  u0 p0 c0 {3,S}
        """)

        group = Group() # general case (functional group)
        group.fromAdjacencyList("""
1 *1 C   u1 p0 c0 {2,S}, {3,S}
2    R!H u0 p0 c0 {1,S}
3    R!H u0 p0 c0 {1,S}
        """)

        labeled1 = molecule.getLabeledAtoms()
        labeled2 = group.getLabeledAtoms()
        initialMap = {}
        for label,atom1 in labeled1.iteritems():
            initialMap[atom1] = labeled2[label]
        self.assertTrue(molecule.isSubgraphIsomorphic(group, initialMap))

        mapping = molecule.findSubgraphIsomorphisms(group, initialMap)
        self.assertEqual(len(mapping), 2)
        for map in mapping:
            self.assertTrue(len(map) == min(len(molecule.atoms), len(group.atoms)))
            for key, value in map.iteritems():
                self.assertTrue(key in molecule.atoms)
                self.assertTrue(value in group.atoms)
 def clean_detergent(self):
     """
     Return molecular representation of input detergent structure        """
     try:
         detergent = Molecule()
         detergent.fromAdjacencyList(str(self.cleaned_data['detergent']))
     except Exception, e:
         import traceback
         traceback.print_exc(e)
         raise forms.ValidationError('Invalid SMILES entry.')
Esempio n. 4
0
 def clean_detergent(self):
     """
     Return molecular representation of input detergent structure        """
     try:
         detergent = Molecule()
         detergent.fromAdjacencyList(str(self.cleaned_data['detergent']))
     except Exception, e:
         import traceback
         traceback.print_exc(e)
         raise forms.ValidationError('Invalid SMILES entry.')
 def clean_reactant1(self):
     """
     Custom validation for the reactant1 field to ensure that a valid
     adjacency list has been provided.
     """
     try:
         molecule = Molecule()
         molecule.fromAdjacencyList(str(self.cleaned_data['reactant1']))
     except Exception, e:
         import traceback
         traceback.print_exc(e)
         raise forms.ValidationError('Invalid adjacency list.')
Esempio n. 6
0
 def clean_reactant1(self):
     """
     Custom validation for the reactant1 field to ensure that a valid
     adjacency list has been provided.
     """
     try:
         molecule = Molecule()
         molecule.fromAdjacencyList(str(self.cleaned_data['reactant1']))
     except Exception, e:
         import traceback
         traceback.print_exc(e)
         raise forms.ValidationError('Invalid adjacency list.')
 def clean_adjlist(self):
     """
     Custom validation for the adjlist field to ensure that a valid adjacency
     list has been provided.
     """
     try:
         adjlist = str(self.cleaned_data['adjlist'])
         if adjlist == '' : return ''
         molecule = Molecule()
         molecule.fromAdjacencyList(adjlist)
     except Exception, e:
         import traceback
         traceback.print_exc(e)
         raise forms.ValidationError('Invalid adjacency list.')
Esempio n. 8
0
 def clean_adjlist(self):
     """
     Custom validation for the adjlist field to ensure that a valid adjacency
     list has been provided.
     """
     try:
         adjlist = str(self.cleaned_data['adjlist'])
         if adjlist == '' : return ''
         molecule = Molecule()
         molecule.fromAdjacencyList(adjlist)
     except Exception, e:
         import traceback
         traceback.print_exc(e)
         raise forms.ValidationError('Invalid adjacency list.')
Esempio n. 9
0
    def testSubgraphIsomorphismAgain(self):
        molecule = Molecule()
        molecule.fromAdjacencyList("""
        1 * C u0 p0 c0 {2,D} {7,S} {8,S}
        2   C u0 p0 c0 {1,D} {3,S} {9,S}
        3   C u0 p0 c0 {2,S} {4,D} {10,S}
        4   C u0 p0 c0 {3,D} {5,S} {11,S}
        5   C u0 p0 c0 {4,S} {6,S} {12,S} {13,S}
        6   C u0 p0 c0 {5,S} {14,S} {15,S} {16,S}
        7   H u0 p0 c0 {1,S}
        8   H u0 p0 c0 {1,S}
        9   H u0 p0 c0 {2,S}
        10  H u0 p0 c0 {3,S}
        11  H u0 p0 c0 {4,S}
        12  H u0 p0 c0 {5,S}
        13  H u0 p0 c0 {5,S}
        14  H u0 p0 c0 {6,S}
        15  H u0 p0 c0 {6,S}
        16  H u0 p0 c0 {6,S}
        """)

        group = Group()
        group.fromAdjacencyList("""
        1 * C u0 p0 c0 {2,D} {3,S} {4,S}
        2   C u0 p0 c0 {1,D}
        3   H u0 p0 c0 {1,S}
        4   H u0 p0 c0 {1,S}
        """)

        labeled1 = molecule.getLabeledAtoms().values()[0]
        labeled2 = group.getLabeledAtoms().values()[0]

        initialMap = {labeled1: labeled2}
        self.assertTrue(molecule.isSubgraphIsomorphic(group, initialMap))

        initialMap = {labeled1: labeled2}
        mapping = molecule.findSubgraphIsomorphisms(group, initialMap)
        self.assertTrue(
            len(mapping) == 2,
            "len(mapping) = %d, should be = 2" % (len(mapping)))
        for map in mapping:
            self.assertTrue(
                len(map) == min(len(molecule.atoms), len(group.atoms)))
            for key, value in map.iteritems():
                self.assertTrue(key in molecule.atoms)
                self.assertTrue(value in group.atoms)
Esempio n. 10
0
    def testSubgraphIsomorphismAgain(self):
        molecule = Molecule()
        molecule.fromAdjacencyList("""
        1 * C u0 p0 c0 {2,D} {7,S} {8,S}
        2   C u0 p0 c0 {1,D} {3,S} {9,S}
        3   C u0 p0 c0 {2,S} {4,D} {10,S}
        4   C u0 p0 c0 {3,D} {5,S} {11,S}
        5   C u0 p0 c0 {4,S} {6,S} {12,S} {13,S}
        6   C u0 p0 c0 {5,S} {14,S} {15,S} {16,S}
        7   H u0 p0 c0 {1,S}
        8   H u0 p0 c0 {1,S}
        9   H u0 p0 c0 {2,S}
        10  H u0 p0 c0 {3,S}
        11  H u0 p0 c0 {4,S}
        12  H u0 p0 c0 {5,S}
        13  H u0 p0 c0 {5,S}
        14  H u0 p0 c0 {6,S}
        15  H u0 p0 c0 {6,S}
        16  H u0 p0 c0 {6,S}
        """)

        group = Group()
        group.fromAdjacencyList("""
        1 * C u0 p0 c0 {2,D} {3,S} {4,S}
        2   C u0 p0 c0 {1,D}
        3   H u0 p0 c0 {1,S}
        4   H u0 p0 c0 {1,S}
        """)

        labeled1 = molecule.getLabeledAtoms().values()[0]
        labeled2 = group.getLabeledAtoms().values()[0]

        initialMap = {labeled1: labeled2}
        self.assertTrue(molecule.isSubgraphIsomorphic(group, initialMap))

        initialMap = {labeled1: labeled2}
        mapping = molecule.findSubgraphIsomorphisms(group, initialMap)
        self.assertTrue(len(mapping) == 2,  "len(mapping) = %d, should be = 2" % (len(mapping)))
        for map in mapping:
            self.assertTrue(len(map) == min(len(molecule.atoms), len(group.atoms)))
            for key, value in map.iteritems():
                self.assertTrue(key in molecule.atoms)
                self.assertTrue(value in group.atoms)