Пример #1
0
        public void TestLeftRight(
            string input, Type[] expectedOutputTypes, Type[] expectedInnerTypes,
            string leftBoundary, string rightBoundary, string expectedLatex)
        {
            var builder = new LaTeXBuilder(input);
            var list    = builder.Build();

            Assert.NotNull(list);
            Assert.Null(builder.Error);

            CheckAtomTypes(list, expectedOutputTypes);
            Assert.Single(expectedOutputTypes, t => t == typeof(Inner));
            CheckAtom <Inner>("", inner => {
                CheckAtomTypes(inner.InnerList, expectedInnerTypes);
                Assert.Equal(leftBoundary, inner.LeftBoundary.Nucleus);
                Assert.Equal(rightBoundary, inner.RightBoundary.Nucleus);
            })(list[Array.IndexOf(expectedOutputTypes, typeof(Inner))]);
            Assert.Equal(expectedLatex, LaTeXBuilder.MathListToLaTeX(list).ToString());
        }
Пример #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);
        }
Пример #3
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;
                     }
                 }
             }
         }
     }
 }
        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;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }