Exemple #1
0
 private static void SetActiveCenters(IAtomContainer reactant, CheckReactantAtom checkReactantAtom, CheckAtom checkAtom, CheckBond checkBond)
 {
     foreach (var atomi in reactant.Atoms)
     {
         if (checkReactantAtom(reactant, atomi))
         {
             foreach (var bondi in reactant.GetConnectedBonds(atomi))
             {
                 if (checkBond(bondi))
                 {
                     IAtom atomj = bondi.GetOther(atomi);
                     if (checkAtom(atomj) && !reactant.GetConnectedSingleElectrons(atomj).Any())
                     {
                         atomi.IsReactiveCenter = true;
                         atomj.IsReactiveCenter = true;
                         bondi.IsReactiveCenter = true;
                     }
                 }
             }
         }
     }
 }
Exemple #2
0
        internal IReactionSet Initiate(IChemObjectSet <IAtomContainer> reactants, IChemObjectSet <IAtomContainer> agents, bool isReverse, CheckReactantAtom checkReactantAtom, CheckAtom checkAtom, CheckBond checkBond)
        {
            CheckInitiateParams(reactants, agents);

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

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

            if (ipr != null && !ipr.IsSetParameter)
            {
                SetActiveCenters(reactant, checkReactantAtom, checkAtom, checkBond);
            }

            foreach (var atomi in reactant.Atoms)
            {
                if (atomi.IsReactiveCenter && checkReactantAtom(reactant, atomi))
                {
                    foreach (var bondi in reactant.GetConnectedBonds(atomi))
                    {
                        if (bondi.IsReactiveCenter && checkBond(bondi))
                        {
                            IAtom atomj = bondi.GetOther(atomi);
                            if (atomj.IsReactiveCenter && checkAtom(atomj) && !reactant.GetConnectedSingleElectrons(atomj).Any())
                            {
                                IAtom[] atomList;
                                if (isReverse)
                                {
                                    atomList = new[] { atomj, atomi }
                                }
                                ;
                                else
                                {
                                    atomList = new[] { atomi, atomj }
                                };
                                var bondList = new[] { bondi };

                                IChemObjectSet <IAtomContainer> moleculeSet = reactant.Builder.NewChemObjectSet <IAtomContainer>();

                                moleculeSet.Add(reactant);
                                IReaction reaction = Mechanism.Initiate(moleculeSet, atomList, bondList);
                                if (reaction == null)
                                {
                                    continue;
                                }
                                else
                                {
                                    setOfReactions.Add(reaction);
                                }
                            }
                        }
                    }
                }
            }
            return(setOfReactions);
        }
        internal IReactionSet Initiate(IChemObjectSet <IAtomContainer> reactants, IChemObjectSet <IAtomContainer> agents, CheckReactant checkReactant, CheckReactantAtom checkReatantAtom, CheckAtom checkAtom)
        {
            CheckInitiateParams(reactants, agents);

            IReactionSet   setOfReactions = reactants.Builder.NewReactionSet();
            IAtomContainer 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, checkReactant, checkReatantAtom, checkAtom);
            }

            foreach (var atomi in reactant.Atoms)
            {
                if (atomi.IsReactiveCenter && checkReatantAtom(reactant, atomi))
                {
                    foreach (var bondi in reactant.GetConnectedBonds(atomi))
                    {
                        if (bondi.IsReactiveCenter && bondi.Order == BondOrder.Single)
                        {
                            IAtom atomj = bondi.GetOther(atomi);
                            if (atomj.IsReactiveCenter &&
                                (atomj.FormalCharge ?? 0) == 0 &&
                                !reactant.GetConnectedSingleElectrons(atomj).Any())
                            {
                                foreach (var bondj in reactant.GetConnectedBonds(atomj))
                                {
                                    if (bondj.Equals(bondi))
                                    {
                                        continue;
                                    }

                                    if (bondj.IsReactiveCenter &&
                                        bondj.Order == BondOrder.Double)
                                    {
                                        IAtom atomk = bondj.GetOther(atomj);
                                        if (atomk.IsReactiveCenter &&
                                            checkAtom(atomk) &&
                                            !reactant.GetConnectedSingleElectrons(atomk).Any())
                                        {
                                            var atomList = new List <IAtom>
                                            {
                                                atomi,
                                                atomj,
                                                atomk
                                            };
                                            var bondList = new List <IBond>
                                            {
                                                bondi,
                                                bondj
                                            };

                                            var moleculeSet = reactant.Builder.NewChemObjectSet <IAtomContainer>();

                                            moleculeSet.Add(reactant);
                                            var reaction = Mechanism.Initiate(moleculeSet, atomList, bondList);
                                            if (reaction == null)
                                            {
                                                continue;
                                            }
                                            else
                                            {
                                                setOfReactions.Add(reaction);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(setOfReactions);
        }
        private static void SetActiveCenters(IAtomContainer reactant, CheckReactant checkReatant, CheckReactantAtom checkReatantAtom, CheckAtom checkAtom)
        {
            if (checkReatant != null && !checkReatant(reactant))
            {
                return;
            }

            foreach (var atomi in reactant.Atoms)
            {
                if (checkReatantAtom(reactant, atomi))
                {
                    foreach (var bondi in reactant.GetConnectedBonds(atomi))
                    {
                        if (bondi.Order == BondOrder.Single)
                        {
                            IAtom atomj = bondi.GetOther(atomi);
                            if ((atomj.FormalCharge ?? 0) == 0 &&
                                !reactant.GetConnectedSingleElectrons(atomj).Any())
                            {
                                foreach (var bondj in reactant.GetConnectedBonds(atomj))
                                {
                                    if (bondj.Equals(bondi))
                                    {
                                        continue;
                                    }

                                    if (bondj.Order == BondOrder.Double)
                                    {
                                        IAtom atomk = bondj.GetOther(atomj);
                                        if (checkAtom(atomk) &&
                                            !reactant.GetConnectedSingleElectrons(atomk).Any())
                                        {
                                            atomi.IsReactiveCenter = true;
                                            atomj.IsReactiveCenter = true;
                                            atomk.IsReactiveCenter = true;
                                            bondi.IsReactiveCenter = true;
                                            bondj.IsReactiveCenter = true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }