Commits

dalke  committed 86d997c

Finished the program. It now leave elements which aren't in the organic subset inside of []s

  • Participants
  • Parent commits 480723c

Comments (0)

Files changed (1)

File subgraph_enumeration.pyx

             else:
                 state = 4
         elif state == 2:
-            smarts.push_back(smiles[i])
-            state = 5
+            if (smiles[i+1] == ']'):
+                if (smiles[i] == 'C' or smiles[i] == 'B' or smiles[i] == 'N' or
+                    smiles[i] == 'O' or smiles[i] == 'S' or smiles[i] == 'P' or
+                    smiles[i] == 'F' or smiles[i] == 'I'):
+                    # Organic subset
+                    smarts.push_back(smiles[i])
+                    state = 9 # don't need the ']'
+                else:
+                    smarts.push_back('[')
+                    smarts.push_back(smiles[i])
+                    state = 8  # require the ']'
+            else:
+                if ((smiles[i] == "B" and smiles[i+1] == "r")  or
+                    (smiles[i] == "C" and smiles[i+1] == "l")):
+                    smarts.push_back(smiles[i])
+                    state = 9  # don't need the ']'
+                else:
+                    smarts.push_back('[')
+                    smarts.push_back(smiles[i])
+                    state = 8  # require the ']'
+                    
         elif state == 3:
-            smarts.push_back(smiles[i]+32)
-            state = 5
+            if (smiles[i+1] == ']'):
+                if (smiles[i] == 'B' or smiles[i] == 'C' or smiles[i] == 'N' or
+                    smiles[i] == 'O' or smiles[i] == 'S' or smiles[i] == 'P'):
+                    smarts.push_back(smiles[i]+32)
+                    state = 9 # don't need the ']'
+                else:
+                    smarts.push_back('[')
+                    smarts.push_back(smiles[i]+32)
+                    state = 8 # require the ']'
+            else:
+                smarts.push_back('[')
+                smarts.push_back(smiles[i]+32)
+                state = 8 # require the ']'
+
         elif state == 4:
             smarts.push_back('*')
-        elif state == 5:
+
+        elif state == 8:  # require the ']'
+            smarts.push_back(smiles[i])
+            if smiles[i] == ']':
+                state = 0
+        elif state == 9: # ignore the ']'
             if smiles[i] == ']':
                 state = 0
             else: