public override object VisitAtom([NotNull] smilesParser.AtomContext context)
        {
            string    symbol    = string.Empty;
            Chirality ch        = Chirality.UNSPECIFIED;
            int       isotope   = 0;
            int       hCount    = 0;
            int       charge    = 0;
            int       atomClass = 0;

            foreach (IParseTree tree in context.children)
            {
                if (typeof(smilesParser.AromaticContext).IsAssignableFrom(tree.GetType()))
                {
                    Atom a = (Atom)VisitAromatic((smilesParser.AromaticContext)tree);
                    a.AtomType = ChemInfo.AtomType.AROMATIC;
                    return(a);
                }
                else if (typeof(smilesParser.OrganicContext).IsAssignableFrom(tree.GetType()))
                {
                    Atom a = (Atom)VisitOrganic((smilesParser.OrganicContext)tree);
                    a.AtomType = ChemInfo.AtomType.ORGANIC;
                    return(a);
                }
                else if (typeof(smilesParser.HalogenContext).IsAssignableFrom(tree.GetType()))
                {
                    Atom a = (Atom)VisitHalogen((smilesParser.HalogenContext)tree);
                    a.AtomType = ChemInfo.AtomType.ORGANIC;
                    return(a);
                }
                else
                {
                    if (typeof(smilesParser.SymbolContext).IsAssignableFrom(tree.GetType()))
                    {
                        symbol = (string)VisitSymbol((smilesParser.SymbolContext)tree);
                    }
                    if (typeof(smilesParser.ChiralContext).IsAssignableFrom(tree.GetType()))
                    {
                        ch = (Chirality)VisitChiral((smilesParser.ChiralContext)tree);
                    }
                    if (typeof(smilesParser.IsotopeContext).IsAssignableFrom(tree.GetType()))
                    {
                        isotope = (int)VisitIsotope((smilesParser.IsotopeContext)tree);
                    }
                    if (typeof(smilesParser.HcountContext).IsAssignableFrom(tree.GetType()))
                    {
                        hCount = (int)VisitHcount((smilesParser.HcountContext)tree);
                    }
                    if (typeof(smilesParser.ChargeContext).IsAssignableFrom(tree.GetType()))
                    {
                        charge = (int)VisitCharge((smilesParser.ChargeContext)tree);
                    }
                    if (typeof(smilesParser.AtomclassContext).IsAssignableFrom(tree.GetType()))
                    {
                        atomClass = (int)VisitAtomclass((smilesParser.AtomclassContext)tree);
                    }
                }
            }
            if (addExplicitHToNext)
            {
                hCount++;
                this.addExplicitHToNext = false;
            }
            string[] organics  = { "B", "C", "N", "O", "S", "P", "F", "Cl", "Br", "I", "X" };
            string[] aromatics = { "b", "c", "n", "o", "p", "s", "se", "as" };
            AtomType type      = AtomType.NONE;

            if (organics.Contains(symbol))
            {
                type = AtomType.ORGANIC;
            }
            else if (aromatics.Contains(symbol))
            {
                type = AtomType.AROMATIC;
            }
            return(new Atom(symbol, type, isotope, ch, hCount, charge, atomClass));
        }
Пример #2
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="smilesParser.atom"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitAtom([NotNull] smilesParser.AtomContext context)
 {
     return(VisitChildren(context));
 }
Пример #3
0
 /// <summary>
 /// Exit a parse tree produced by <see cref="smilesParser.atom"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitAtom([NotNull] smilesParser.AtomContext context)
 {
 }