/// <summary> /// Internal - create a query atom container that exactly matches the molecule provided. /// Similar to <see cref="QueryAtomContainerCreator"/> /// but we can't access SMARTS query classes from that module (cdk-isomorphism). /// </summary> /// <param name="mol">molecule</param> /// <returns>query container</returns> /// <seealso cref="QueryAtomContainerCreator"/> private static IQueryAtomContainer MatchExact(IAtomContainer mol) { var bldr = mol.Builder; var qry = new QueryAtomContainer(); var atmmap = new Dictionary <IAtom, IAtom>(); foreach (var atom in mol.Atoms) { var qatom = MatchExact(mol, atom); if (qatom != null) { atmmap[atom] = qatom; qry.Atoms.Add(qatom); } } foreach (var bond in mol.Bonds) { var beg = atmmap[bond.Begin]; var end = atmmap[bond.End]; // attach bond skipped if (beg == null || end == null) { continue; } var qbond = new QueryBond(beg, end, ExprType.True); qry.Bonds.Add(qbond); } return(qry); }
public static QueryAtomContainer CreateSymbolChargeIDQueryContainer(IAtomContainer container) { var queryContainer = new QueryAtomContainer(container.Builder); for (int i = 0; i < container.Atoms.Count; i++) { queryContainer.Atoms.Add(new SymbolChargeIDQueryAtom(container.Atoms[i])); } foreach (var bond in container.Bonds) { int index1 = container.Atoms.IndexOf(bond.Begin); int index2 = container.Atoms.IndexOf(bond.End); if (bond.IsAromatic) { QueryBond qbond = new QueryBond(queryContainer.Atoms[index1], queryContainer.Atoms[index2], ExprType.IsAromatic); queryContainer.Bonds.Add(qbond); } else { QueryBond qbond = new QueryBond(queryContainer.Atoms[index1], queryContainer.Atoms[index2], ExprType.Order, bond.Order.Numeric()) { Order = bond.Order // backwards compatibility }; queryContainer.Bonds.Add(qbond); } } return(queryContainer); }
static void Main() { IAtomContainer mol = null; #region 1 if (Smarts.Parse(mol, "[aD3]a-a([aD3])[aD3]")) { var smarts = Smarts.Generate(mol); } #endregion { #region GenerateAtom var expr = new Expr(ExprType.Degree, 4).And( new Expr(ExprType.IsAromatic)); var aExpr = Smarts.GenerateAtom(expr); // aExpr = "[D4a]" #endregion } { #region GenerateBond var expr = new Expr(ExprType.True); var bExpr = Smarts.GenerateBond(expr); // // bExpr='~' #endregion } { #region Generate var qatom1 = new QueryAtom(); var qatom2 = new QueryAtom(); var qbond = new QueryBond(); qatom1.Expression = new Expr(ExprType.IsAromatic); qatom2.Expression = new Expr(ExprType.IsAromatic); qbond.Expression = new Expr(ExprType.IsAliphatic); qbond.SetAtoms(new IAtom[] { qatom1, qatom2 }); mol.Atoms.Add(qatom1); mol.Atoms.Add(qatom2); mol.Bonds.Add(qbond); var smartsStr = Smarts.Generate(mol); // smartsStr = 'a!:a' #endregion } }