示例#1
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);
        }
示例#2
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;
                     }
                 }
             }
         }
     }
 }