/// <summary>
        /// set the active center for this molecule.
        /// The active center will be those which correspond with X=Y.
        /// </summary>
        /// <param name="reactant">The molecule to set the activity</param>
        private static void SetActiveCenters(IAtomContainer reactant)
        {
            if (AtomContainerManipulator.GetTotalCharge(reactant) != 0)
            {
                return;
            }

            foreach (var bondi in reactant.Bonds)
            {
                if (((bondi.Order == BondOrder.Double) || (bondi.Order == BondOrder.Triple)))
                {
                    int chargeAtom0 = bondi.Begin.FormalCharge ?? 0;
                    int chargeAtom1 = bondi.End.FormalCharge ?? 0;
                    if (chargeAtom0 >= 0 && chargeAtom1 >= 0 &&
                        !reactant.GetConnectedSingleElectrons(bondi.Begin).Any() &&
                        !reactant.GetConnectedSingleElectrons(bondi.End).Any() &&
                        !reactant.GetConnectedLonePairs(bondi.Begin).Any() &&
                        !reactant.GetConnectedLonePairs(bondi.End).Any())
                    {
                        bondi.IsReactiveCenter       = true;
                        bondi.Begin.IsReactiveCenter = true;
                        bondi.End.IsReactiveCenter   = true;
                    }
                }
            }
        }
        internal IReactionSet Initiate(IChemObjectSet <IAtomContainer> reactants, IChemObjectSet <IAtomContainer> agents, string atomSymbol)
        {
            CheckInitiateParams(reactants, agents);

            IReactionSet   setOfReactions = reactants.Builder.NewReactionSet();
            IAtomContainer reactant       = reactants[0];

            IParameterReaction ipr = base.GetParameterClass(typeof(SetReactionCenter));

            if (ipr != null && !ipr.IsSetParameter)
            {
                SetActiveCenters(reactant);
            }

            if (AtomContainerManipulator.GetTotalCharge(reactant) > 0)
            {
                return(setOfReactions);
            }

            foreach (var atomi in reactant.Atoms)
            {
                if (atomi.IsReactiveCenter &&
                    (atomi.FormalCharge ?? 0) <= 0 &&
                    reactant.GetConnectedLonePairs(atomi).Any() &&
                    !reactant.GetConnectedSingleElectrons(atomi).Any())
                {
                    var atomList = new List <IAtom> {
                        atomi
                    };
                    IAtom atomH = reactant.Builder.NewAtom(atomSymbol);
                    atomH.FormalCharge = 1;
                    atomList.Add(atomH);

                    var moleculeSet = reactant.Builder.NewAtomContainerSet();
                    moleculeSet.Add(reactant);
                    IAtomContainer adduct = reactant.Builder.NewAtomContainer();
                    adduct.Atoms.Add(atomH);
                    moleculeSet.Add(adduct);

                    IReaction reaction = Mechanism.Initiate(moleculeSet, atomList, null);
                    if (reaction == null)
                    {
                        continue;
                    }
                    else
                    {
                        setOfReactions.Add(reaction);
                    }
                }
            }

            return(setOfReactions);
        }
        private static void SetActiveCenters(IAtomContainer reactant)
        {
            if (AtomContainerManipulator.GetTotalCharge(reactant) > 0)
            {
                return;
            }

            foreach (var atomi in reactant.Atoms)
            {
                if ((atomi.FormalCharge ?? 0) <= 0 &&
                    reactant.GetConnectedLonePairs(atomi).Any() &&
                    !reactant.GetConnectedSingleElectrons(atomi).Any())
                {
                    atomi.IsReactiveCenter = true;
                }
            }
        }
        /// <summary>
        ///  Initiate process.
        ///  It is needed to call the addExplicitHydrogensToSatisfyValency
        ///  from the class tools.HydrogenAdder.
        /// </summary>
        /// <exception cref="CDKException"> Description of the Exception</exception>
        /// <param name="reactants">reactants of the reaction</param>
        /// <param name="agents">agents of the reaction (Must be in this case null)</param>
        public IReactionSet Initiate(IChemObjectSet <IAtomContainer> reactants, IChemObjectSet <IAtomContainer> agents)
        {
            Debug.WriteLine($"initiate reaction: {GetType().Name}");

            if (reactants.Count != 1)
            {
                throw new CDKException($"{GetType().Name} only expects one reactant");
            }
            if (agents != null)
            {
                throw new CDKException($"{GetType().Name} don't expects agents");
            }

            var setOfReactions = reactants.Builder.NewReactionSet();
            var reactant       = reactants[0];

            // if the parameter hasActiveCenter is not fixed yet, set the active centers
            var ipr = base.GetParameterClass(typeof(SetReactionCenter));

            if (ipr != null && !ipr.IsSetParameter)
            {
                SetActiveCenters(reactant);
            }

            if (AtomContainerManipulator.GetTotalCharge(reactant) != 0)
            {
                return(setOfReactions);
            }

            foreach (var bondi in reactant.Bonds)
            {
                if (bondi.IsReactiveCenter &&
                    ((bondi.Order == BondOrder.Double) || (bondi.Order == BondOrder.Triple)) &&
                    bondi.Begin.IsReactiveCenter &&
                    bondi.End.IsReactiveCenter)
                {
                    int chargeAtom0 = bondi.Begin.FormalCharge ?? 0;
                    int chargeAtom1 = bondi.End.FormalCharge ?? 0;
                    if (chargeAtom0 >= 0 && chargeAtom1 >= 0 &&
                        !reactant.GetConnectedSingleElectrons(bondi.Begin).Any() &&
                        !reactant.GetConnectedSingleElectrons(bondi.End).Any() &&
                        !reactant.GetConnectedLonePairs(bondi.Begin).Any() &&
                        !reactant.GetConnectedLonePairs(bondi.End).Any())
                    {
                        for (int j = 0; j < 2; j++)
                        {
                            var atomList = new List <IAtom>();
                            if (j == 0)
                            {
                                atomList.Add(bondi.Begin);
                                atomList.Add(bondi.End);
                            }
                            else
                            {
                                atomList.Add(bondi.End);
                                atomList.Add(bondi.Begin);
                            }
                            var atomH = reactant.Builder.NewAtom("H");
                            atomH.FormalCharge = 1;
                            atomList.Add(atomH);

                            var bondList = new List <IBond> {
                                bondi
                            };

                            var moleculeSet = reactant.Builder.NewAtomContainerSet();
                            moleculeSet.Add(reactant);
                            var adduct = reactant.Builder.NewAtomContainer();
                            adduct.Atoms.Add(atomH);
                            moleculeSet.Add(adduct);

                            var reaction = Mechanism.Initiate(moleculeSet, atomList, bondList);
                            if (reaction == null)
                            {
                                continue;
                            }
                            else
                            {
                                setOfReactions.Add(reaction);
                            }
                        }
                    }
                }
            }

            return(setOfReactions);
        }