internal IReactionSet Initiate(IChemObjectSet <IAtomContainer> reactants, IChemObjectSet <IAtomContainer> agents, BondCheck bondChecker) { 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, bondChecker); } foreach (var bondi in reactant.Bonds) { IAtom atom1 = bondi.Begin; IAtom atom2 = bondi.End; if (bondi.IsReactiveCenter && bondChecker(bondi) && atom1.IsReactiveCenter && atom2.IsReactiveCenter && (atom1.FormalCharge ?? 0) == 0 && (atom2.FormalCharge ?? 0) == 0 && !reactant.GetConnectedSingleElectrons(atom1).Any() && !reactant.GetConnectedSingleElectrons(atom2).Any()) { for (int j = 0; j < 2; j++) { var atomList = new List <IAtom>(); if (j == 0) { atomList.Add(atom1); atomList.Add(atom2); } else { atomList.Add(atom2); atomList.Add(atom1); } var bondList = new List <IBond> { bondi }; IChemObjectSet <IAtomContainer> moleculeSet = reactant.Builder.NewAtomContainerSet(); 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, 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, 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); }
/// <summary> /// Initiate process. /// It is needed to call the addExplicitHydrogensToSatisfyValency /// from the class tools.HydrogenAdder. /// </summary> /// <param name="reactants">Reactants of the reaction</param> /// <param name="agents">Agents of the reaction (Must be in this case null)</param> /// <exception cref="CDKException"> Description of the Exception</exception> public IReactionSet Initiate(IChemObjectSet <IAtomContainer> reactants, IChemObjectSet <IAtomContainer> agents) { Debug.WriteLine("initiate reaction: ElectronImpactNBEReaction"); if (reactants.Count != 1) { throw new CDKException("ElectronImpactNBEReaction only expects one reactant"); } if (agents != null) { throw new CDKException("ElectronImpactNBEReaction don't expects 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); } foreach (var atom in reactant.Atoms) { if (atom.IsReactiveCenter && reactant.GetConnectedLonePairs(atom).Any() && !reactant.GetConnectedSingleElectrons(atom).Any()) { var atomList = new List <IAtom> { atom }; IChemObjectSet <IAtomContainer> moleculeSet = reactant.Builder.NewAtomContainerSet(); moleculeSet.Add(reactant); IReaction reaction = Mechanism.Initiate(moleculeSet, atomList, null); if (reaction == null) { continue; } else { setOfReactions.Add(reaction); } } } return(setOfReactions); }
internal IReactionSet Initiate(IChemObjectSet <IAtomContainer> reactants, IChemObjectSet <IAtomContainer> agents, int length, bool checkPrev, AtomCheck atomCheck) { CheckInitiateParams(reactants, agents); IReactionSet setOfReactions = reactants.Builder.NewReactionSet(); IAtomContainer reactant = reactants[0]; AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(reactant); Aromaticity.CDKLegacy.Apply(reactant); AllRingsFinder arf = new AllRingsFinder(); IRingSet ringSet = arf.FindAllRings(reactant); for (int ir = 0; ir < ringSet.Count; ir++) { IRing ring = (IRing)ringSet[ir]; for (int jr = 0; jr < ring.Atoms.Count; jr++) { IAtom aring = ring.Atoms[jr]; aring.IsInRing = true; } } // 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, length, checkPrev, atomCheck); } HOSECodeGenerator hcg = new HOSECodeGenerator(); foreach (var atomi in reactant.Atoms) { if (atomi.IsReactiveCenter && reactant.GetConnectedSingleElectrons(atomi).Count() == 1) { IEnumerable <IAtom> atom1s = null; if (checkPrev) { hcg.GetSpheres(reactant, atomi, length - 1, true); atom1s = hcg.GetNodesInSphere(length - 1); } hcg.GetSpheres(reactant, atomi, length, true); foreach (var atoml in hcg.GetNodesInSphere(length)) { if (atoml != null && atoml.IsReactiveCenter && !atoml.IsInRing && (atoml.FormalCharge ?? 0) == 0 && !atoml.AtomicNumber.Equals(AtomicNumbers.H) && reactant.GetMaximumBondOrder(atoml) == BondOrder.Single) { foreach (var atomR in reactant.GetConnectedAtoms(atoml)) { if (atom1s != null && atom1s.Contains(atomR)) { continue; } if (reactant.GetBond(atomR, atoml).IsReactiveCenter && atomR.IsReactiveCenter && atomCheck(atomR)) { var atomList = new List <IAtom> { atomR, atomi, atoml }; var bondList = new List <IBond> { reactant.GetBond(atomR, atoml) }; 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); }
/// <summary> /// Initiate process. /// It is needed to call the addExplicitHydrogensToSatisfyValency /// from the class tools.HydrogenAdder. /// </summary> /// <param name="reactants">reactants of the reaction.</param> /// <param name="agents">agents of the reaction (Must be in this case null).</param> /// <exception cref="CDKException"> Description of the Exception</exception> public IReactionSet Initiate(IChemObjectSet <IAtomContainer> reactants, IChemObjectSet <IAtomContainer> agents) { Debug.WriteLine("initiate reaction: SharingChargeDBReaction"); if (reactants.Count != 1) { throw new CDKException("SharingChargeDBReaction only expects one reactant"); } if (agents != null) { throw new CDKException("SharingChargeDBReaction don't expects 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); } foreach (var atomi in reactant.Atoms) { if (atomi.IsReactiveCenter && atomi.FormalCharge == 1) { 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) { if (!reactant.GetConnectedSingleElectrons(atomj).Any()) { var atomList = new List <IAtom> { atomj, atomi }; var bondList = new List <IBond> { bondi }; 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); }
/// <summary> /// Initiate process. /// It is needed to call the addExplicitHydrogensToSatisfyValency /// from the class tools.HydrogenAdder. /// </summary> /// <exception cref="CDKException"></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) { 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); } foreach (var atomi in reactant.Atoms) { if (atomi.IsReactiveCenter && atomi.FormalCharge == 1) { 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.Single) { IAtom atomk = bondj.GetOther(atomj); if (atomk.IsReactiveCenter && (atomk.FormalCharge ?? 0) == 0 && !reactant.GetConnectedSingleElectrons(atomk).Any() && atomk.AtomicNumber.Equals(AtomicNumbers.H) ) { 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); }
internal IReactionSet Initiate(IChemObjectSet <IAtomContainer> reactants, IChemObjectSet <IAtomContainer> agents, string atomSymbol, int charge) { 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, atomSymbol, charge); } foreach (var atomi in reactants[0].Atoms) { if (atomi.IsReactiveCenter && reactant.GetConnectedSingleElectrons(atomi).Count() == 1 && atomi.FormalCharge == charge) { 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) { foreach (var bondj in reactant.GetConnectedBonds(atomj)) { if (bondj.Equals(bondi)) { continue; } if (bondj.IsReactiveCenter && bondj.Order == BondOrder.Single) { IAtom atomk = bondj.GetOther(atomj); if (atomk.IsReactiveCenter && atomk.Symbol.Equals(atomSymbol, StringComparison.Ordinal) && atomk.FormalCharge == 0) { var atomList = new List <IAtom> { atomi, atomj, atomk }; var bondList = new List <IBond> { bondi, bondj }; 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); }
/// <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); }