public override object VisitBranched_atom([NotNull] smilesParser.Branched_atomContext context)
 {
     foreach (IParseTree tree in context.children)
     {
         if (typeof(smilesParser.AtomContext).IsAssignableFrom(tree.GetType()))
         {
             Atom current = (Atom)VisitAtom((smilesParser.AtomContext)tree);
             if (current.Element != ELEMENTS.H)
             {
                 retVal.AddAtom(current);
                 if (addExplicitHToNext)
                 {
                     current.ExplicitHydrogens++;
                     addExplicitHToNext = false;
                 }
                 if (last != null)
                 {
                     if (last.AtomType == AtomType.AROMATIC && current.AtomType == AtomType.AROMATIC)
                     {
                         nextBond = BondType.Aromatic;
                     }
                 }
                 Bond b = retVal.AddBond(last, current, nextBond, BondStereo.NotStereoOrUseXYZ, BondTopology.Either, BondReactingCenterStatus.Unmarked);
                 if (!string.IsNullOrEmpty(cisTrans) && nextBond == BondType.Double)
                 {
                     doubleBonds.Add(b);
                 }
                 nextBond = BondType.Single;
                 last     = current;
             }
             else
             {
                 if (last != null)
                 {
                     last.ExplicitHydrogens++;
                 }
                 else
                 {
                     addExplicitHToNext = true;
                 }
             }
         }
         else if (typeof(smilesParser.RingbondContext).IsAssignableFrom(tree.GetType()))
         {
             int ring = (int)VisitRingbond((smilesParser.RingbondContext)tree);
             if (ringAtoms.ContainsKey(ring))
             {
                 BondType nextType = (BondType)ringbonds[ring];
                 if (nextType != BondType.Single && (nextBond == BondType.Single || nextBond == nextType))
                 {
                     nextBond = nextType;
                 }
                 Bond b = retVal.AddBond(last, (Atom)ringAtoms[ring], nextBond, BondStereo.NotStereoOrUseXYZ, BondTopology.Either, BondReactingCenterStatus.Unmarked);
                 if (!string.IsNullOrEmpty(cisTrans) && nextBond == BondType.Double)
                 {
                     doubleBonds.Add(b);
                 }
                 nextBond = BondType.Single;
                 ringAtoms.Remove(ring);
                 ringbonds.Remove(ring);
             }
             else
             {
                 ringAtoms.Add(ring, last);
                 ringbonds.Add(ring, nextBond);
                 nextBond = BondType.Single;
             }
         }
         else if (typeof(smilesParser.BranchContext).IsAssignableFrom(tree.GetType()))
         {
             Atom temp = last;
             VisitBranch((smilesParser.BranchContext)tree);
             last = temp;
         }
         else if (typeof(smilesParser.BondContext).IsAssignableFrom(tree.GetType()))
         {
             nextBond = (BondType)VisitBond((smilesParser.BondContext)context.GetChild(1));
         }
         else
         {
             throw new System.InvalidOperationException("uhoh");
         }
     }
     return(null);
 }
Esempio n. 2
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="smilesParser.branched_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 VisitBranched_atom([NotNull] smilesParser.Branched_atomContext context)
 {
     return(VisitChildren(context));
 }
Esempio n. 3
0
 /// <summary>
 /// Exit a parse tree produced by <see cref="smilesParser.branched_atom"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitBranched_atom([NotNull] smilesParser.Branched_atomContext context)
 {
 }