def hierarchy(matcher): node = FilterCatalog.FilterHierarchyMatcher(matcher) self.assertEquals(matcher.GetName(), node.GetName()) return node
def testFilterHierarchyMatcher(self): # test root = FilterCatalog.FilterHierarchyMatcher() sm = h = FilterCatalog.SmartsMatcher( "Halogen", "[$([F,Cl,Br,I]-!@[#6]);!$([F,Cl,Br,I]" "-!@C-!@[F,Cl,Br,I]);!$([F,Cl,Br,I]-[C,S]" "(=[O,S,N]))]", 1) root.SetPattern(sm) def hierarchy(matcher): node = FilterCatalog.FilterHierarchyMatcher(matcher) self.assertEquals(matcher.GetName(), node.GetName()) return node sm = FilterCatalog.SmartsMatcher("Halogen.Aromatic", "[F,Cl,Br,I;$(*-!@c)]") root.AddChild(hierarchy(sm)) sm = FilterCatalog.SmartsMatcher( "Halogen.NotFluorine", "[$([Cl,Br,I]-!@[#6]);!$([Cl,Br,I]" "-!@C-!@[F,Cl,Br,I]);!$([Cl,Br,I]-[C,S]" "(=[O,S,N]))]") node = hierarchy(sm) halogen_notf_children = [ hierarchy(x) for x in [ FilterCatalog.SmartsMatcher( "Halogen.NotFluorine.Aliphatic", "[$([Cl,Br,I]-!@C);!$([Cl,Br,I]" "-!@C-!@[F,Cl,Br,I]);!$([Cl,Br,I]-[C,S](=[O,S,N]))]"), FilterCatalog.SmartsMatcher("Halogen.NotFluorine.Aromatic", "[$([Cl,Br,I]-!@c)]") ] ] for child in halogen_notf_children: node.AddChild(child) root.AddChild(node) sm = FilterCatalog.SmartsMatcher( "Halogen.Bromine", "[Br;$([Br]-!@[#6]);!$([Br]-!@C-!@[F,Cl,Br,I])" ";!$([Br]-[C,S](=[O,S,N]))]", 1) node = hierarchy(sm) halogen_bromine_children = [ hierarchy(x) for x in [ FilterCatalog.SmartsMatcher( "Halogen.Bromine.Aliphatic", "[Br;$(Br-!@C);!$(Br-!@C-!@[F,Cl,Br,I]);" "!$(Br-[C,S](=[O,S,N]))]"), FilterCatalog.SmartsMatcher("Halogen.Bromine.Aromatic", "[Br;$(Br-!@c)]"), FilterCatalog.SmartsMatcher("Halogen.Bromine.BromoKetone", "[Br;$(Br-[CH2]-C(=O)-[#6])]") ] ] for child in halogen_bromine_children: node.AddChild(child) root.AddChild(node) m = Chem.MolFromSmiles("CCl") assert h.HasMatch(m) res = root.GetMatches(m) self.assertEquals(len(res), 1) self.assertEquals([match.filterMatch.GetName() for match in res], ['Halogen.NotFluorine.Aliphatic']) m = Chem.MolFromSmiles("c1ccccc1Cl") assert h.HasMatch(m) res = root.GetMatches(m) self.assertEquals(len(res), 2) m = Chem.MolFromSmiles("c1ccccc1Br") assert h.HasMatch(m) res = root.GetMatches(m) self.assertEquals(len(res), 3) self.assertEquals([match.filterMatch.GetName() for match in res], [ 'Halogen.Aromatic', 'Halogen.NotFluorine.Aromatic', 'Halogen.Bromine.Aromatic' ]) m = Chem.MolFromSmiles("c1ccccc1F") assert h.HasMatch(m) res = root.GetMatches(m) self.assertEquals(len(res), 1) self.assertEquals([match.filterMatch.GetName() for match in res], ['Halogen.Aromatic']) m = Chem.MolFromSmiles("CBr") assert h.HasMatch(m) res = root.GetMatches(m) self.assertEquals( [match.filterMatch.GetName() for match in res], ['Halogen.NotFluorine.Aliphatic', 'Halogen.Bromine.Aliphatic'])