/// <summary> /// Gets the fragments from a target matching a set of query fragments. /// </summary> /// <remarks> /// This method returns a list of lists. Each list contains the atoms of the target <see cref="IAtomContainer"/> /// that arise in the mapping of bonds in the target molecule to the bonds in the query fragment. /// The query fragments should be constructed /// using the <see cref="QueryAtomContainerCreator.CreateAnyAtomAnyBondContainer(IAtomContainer, bool)"/> method of the <see cref="QueryAtomContainerCreator"/> /// CDK class, since we are only interested in connectivity and not actual atom or bond type information. /// </remarks> /// <param name="atomContainer">The target <see cref="IAtomContainer"/></param> /// <param name="queries">An array of query fragments</param> /// <returns>A list of lists, each list being the atoms that match the query fragments</returns> public static List <List <int> > GetFragments(IAtomContainer atomContainer, QueryAtomContainer[] queries) { var universalIsomorphismTester = new UniversalIsomorphismTester(); var uniqueSubgraphs = new List <List <int> >(); foreach (var query in queries) { IReadOnlyList <IReadOnlyList <RMap> > subgraphMaps = null; try { // we get the list of bond mappings subgraphMaps = universalIsomorphismTester.GetSubgraphMaps(atomContainer, query).ToReadOnlyList(); } catch (CDKException e) { Console.Error.WriteLine(e.StackTrace); } if (subgraphMaps == null) { continue; } if (!subgraphMaps.Any()) { continue; } // get the atom paths in the unique set of bond maps uniqueSubgraphs.AddRange(GetUniqueBondSubgraphs(subgraphMaps, atomContainer)); } // lets run a check on the length of each returned fragment and delete // any that don't match the length of out query fragments. Note that since // sometimes a fragment might be a ring, it will have number of atoms // equal to the number of bonds, where as a fragment with no rings // will have number of atoms equal to the number of bonds+1. So we need to check // fragment size against all unique query sizes - I get lazy and don't check // unique query sizes, but the size of each query var ret = new List <List <int> >(uniqueSubgraphs.Count); foreach (var fragment in uniqueSubgraphs) { foreach (var query in queries) { if (fragment.Count == query.Atoms.Count) { ret.Add(fragment); break; } } } return(ret); }
/// <summary> /// Determine the number of amino acids groups the supplied <see cref="IAtomContainer"/>. /// </summary> /// <returns>the number of aromatic atoms of this AtomContainer</returns> public Result Calculate(IAtomContainer container) { container = (IAtomContainer)container.Clone(); var results = new List <int>(substructureSet.Count); var universalIsomorphismTester = new UniversalIsomorphismTester(); foreach (var substructure in substructureSet) { var maps = universalIsomorphismTester.GetSubgraphMaps(container, substructure); results.Add(maps.Count()); } return(new Result(results)); }
public void TestSFBug1708336() { var atomContainer = builder.NewAtomContainer(); atomContainer.Atoms.Add(builder.NewAtom("C")); atomContainer.Atoms.Add(builder.NewAtom("C")); atomContainer.Atoms.Add(builder.NewAtom("N")); atomContainer.AddBond(atomContainer.Atoms[0], atomContainer.Atoms[1], BondOrder.Single); atomContainer.AddBond(atomContainer.Atoms[1], atomContainer.Atoms[2], BondOrder.Single); var query = new QueryAtomContainer(); if (!Smarts.Parse(query, "C*C")) { Assert.Fail(Smarts.GetLastErrorMessage()); } var list = uiTester.GetSubgraphMaps(atomContainer, query); Assert.IsTrue(list.Count() == 0); }