@Override Pattern create(IAtomContainer container) { return Ullmann.findSubstructure(container); } }
/** * Create a pattern for the provided SMARTS - if the SMARTS is '?' a pattern * is not created. * * @param smarts a smarts pattern * @param builder chem object builder * @return the pattern to match */ private Pattern createPattern(String smarts, IChemObjectBuilder builder) { if (smarts.equals("?")) return null; return Ullmann.findSubstructure(SMARTSParser.parse(smarts, builder)); } }
public List<List<Occurence>> getNonSymetricMatches(IAtomContainer atomContainer) { List<int[]> mappings = FluentIterable.from(Ullmann.findSubstructure(query).matchAll(atomContainer)) .filter(new SmartsStereoMatch(query, atomContainer)) .filter(new ComponentGrouping(query, atomContainer)).toList(); final HashMap<List<Integer>, List<List<Occurence>>> variants = new HashMap<>(); for (int[] map : mappings) { final List<Integer> imap = new ArrayList<>(map.length); for (int i : map) imap.add(i); Collections.sort(imap); final List<Occurence> ocs = new ArrayList<>(); for (int i=0; i < map.length; ++i) { if (atomid2occurence.containsKey(i)) { int o = atomid2occurence.get(i); ocs.add(new Occurence(atomContainer, o, originalSmarts, map[i], strOffsets[o], strLenghts[o])); } } Collections.sort(ocs, Comparator.comparingInt(a -> a.stringOffset)); variants.computeIfAbsent(imap, (x)->new ArrayList<>()).add(ocs); } final List<List<Occurence>> finalList = new ArrayList<>(); for (List<List<Occurence>> xs : variants.values()) { xs.sort(Comparator.comparing(x->toSmarts(x,defaultFormatter))); finalList.add(xs.get(0)); } return finalList; }
public List<List<Occurence>> match(IAtomContainer atomContainer) { List<List<Occurence>> list = new ArrayList<>(); List<int[]> mappings = FluentIterable.from(Ullmann.findSubstructure(query).matchAll(atomContainer)) .filter(new SmartsStereoMatch(query, atomContainer)) .filter(new ComponentGrouping(query, atomContainer)).toList(); for (int[] map : mappings) { final List<Occurence> ocs = new ArrayList<>(); list.add(ocs); int k=0; for (int i=0; i < map.length; ++i) { if (atomid2occurence.containsKey(i)) { int o = atomid2occurence.get(i); ocs.add(new Occurence(atomContainer,o, originalSmarts, map[i], strOffsets[o], strLenghts[o])); } } Collections.sort(ocs, Comparator.comparingInt(a -> a.stringOffset)); } return list; }
@Test public void napthaleneSubsearch() throws Exception { int[] match = Ullmann.findSubstructure(TestMoleculeFactory.makeNaphthalene()).match( TestMoleculeFactory.makeBenzene()); assertThat(match, is(new int[0])); int count = FluentIterable.from( Ullmann.findSubstructure(TestMoleculeFactory.makeNaphthalene()).matchAll( TestMoleculeFactory.makeBenzene())).size(); assertThat(count, is(0)); } }
@Test public void benzeneSubsearch() throws Exception { int[] match = Ullmann.findSubstructure(TestMoleculeFactory.makeBenzene()).match( TestMoleculeFactory.makeNaphthalene()); assertThat(match, is(new int[]{2, 7, 6, 5, 4, 3})); int count = FluentIterable.from( Ullmann.findSubstructure(TestMoleculeFactory.makeBenzene()).matchAll( TestMoleculeFactory.makeNaphthalene())).size(); assertThat(count, is(6)); // note: aromatic one would be 24 }