/// <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; } } } }
public override void TestInitiate_IAtomContainerSet_IAtomContainerSet() { IReactionProcess type = new SharingChargeDBReaction(); var setOfReactants = GetExampleReactants(); IAtomContainer molecule = setOfReactants[0]; /* initiate */ var paramList = new List <IParameterReaction>(); var param = new SetReactionCenter { IsSetParameter = false }; paramList.Add(param); type.ParameterList = paramList; var setOfReactions = type.Initiate(setOfReactants, null); Assert.AreEqual(1, setOfReactions.Count); Assert.AreEqual(1, setOfReactions[0].Products.Count); IAtomContainer product = setOfReactions[0].Products[0]; Assert.AreEqual(1, product.Atoms[1].FormalCharge.Value); Assert.AreEqual(0, product.GetConnectedLonePairs(product.Atoms[1]).Count()); /* C[C+]O| */ IAtomContainer molecule2 = GetExpectedProducts()[0]; IQueryAtomContainer queryAtom = QueryAtomContainerCreator.CreateSymbolAndChargeQueryContainer(product); Assert.IsTrue(new UniversalIsomorphismTester().IsIsomorph(molecule2, queryAtom)); }
public override void TestInitiate_IAtomContainerSet_IAtomContainerSet() { /* Ionize(>C=O): C=CCC(=O)CC -> C=CCC(=O*)CC , set the reactive center */ IAtomContainer reactant = builder.NewAtomContainer();//CreateFromSmiles("C=CCC(=O)CC") reactant.Atoms.Add(builder.NewAtom("C")); reactant.Atoms.Add(builder.NewAtom("C")); reactant.Atoms.Add(builder.NewAtom("C")); reactant.Atoms.Add(builder.NewAtom("C")); reactant.Atoms.Add(builder.NewAtom("O")); reactant.Atoms.Add(builder.NewAtom("C")); reactant.Atoms.Add(builder.NewAtom("C")); reactant.AddBond(reactant.Atoms[0], reactant.Atoms[1], BondOrder.Double); reactant.AddBond(reactant.Atoms[1], reactant.Atoms[2], BondOrder.Single); reactant.AddBond(reactant.Atoms[2], reactant.Atoms[3], BondOrder.Single); reactant.AddBond(reactant.Atoms[3], reactant.Atoms[4], BondOrder.Double); reactant.AddBond(reactant.Atoms[3], reactant.Atoms[5], BondOrder.Single); reactant.AddBond(reactant.Atoms[5], reactant.Atoms[6], BondOrder.Single); AddExplicitHydrogens(reactant); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(reactant); CDK.LonePairElectronChecker.Saturate(reactant); foreach (var atom in reactant.Atoms) { if (reactant.GetConnectedLonePairs(atom).Count() > 0) { atom.IsReactiveCenter = true; } } var setOfReactants = ChemObjectBuilder.Instance.NewAtomContainerSet(); setOfReactants.Add(reactant); /* initiate */ MakeSureAtomTypesAreRecognized(reactant); IReactionProcess type = new ElectronImpactNBEReaction(); var paramList = new List <IParameterReaction>(); IParameterReaction param = new SetReactionCenter { IsSetParameter = true }; paramList.Add(param); type.ParameterList = paramList; var setOfReactions = type.Initiate(setOfReactants, null); Assert.AreEqual(1, setOfReactions.Count); Assert.AreEqual(1, setOfReactions[0].Products.Count); IAtomContainer molecule = setOfReactions[0].Products[0]; Assert.AreEqual(1, molecule.Atoms[4].FormalCharge.Value); Assert.AreEqual(1, molecule.GetConnectedSingleElectrons(molecule.Atoms[4]).Count()); Assert.IsTrue(setOfReactions[0].Mappings.Any()); }
/// <inheritdoc/> public bool IsSaturated(IAtom atom, IAtomContainer ac) { var atomType = factory.GetAtomType(atom.AtomTypeName); var lpCount = atomType.GetProperty <int>(CDKPropertyName.LonePairCount); var foundLPCount = ac.GetConnectedLonePairs(atom).Count(); return(foundLPCount >= lpCount); }
/// <summary> /// set the active center for this molecule. The active center /// will be heteroatoms which contain at least one group of /// lone pair electrons. /// </summary> /// <param name="reactant">The molecule to set the activity</param> private static void SetActiveCenters(IAtomContainer reactant) { foreach (var atom in reactant.Atoms) { if (reactant.GetConnectedLonePairs(atom).Any() && !reactant.GetConnectedSingleElectrons(atom).Any()) { atom.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); }
/// <inheritdoc/> public void Saturate(IAtom atom, IAtomContainer ac) { Trace.TraceInformation("Saturating atom by adjusting lone pair electrons..."); var atomType = factory.GetAtomType(atom.AtomTypeName); var lpCount = atomType.GetProperty <int>(CDKPropertyName.LonePairCount); var missingLPs = lpCount - ac.GetConnectedLonePairs(atom).Count(); for (int j = 0; j < missingLPs; j++) { var lp = atom.Builder.NewLonePair(atom); ac.LonePairs.Add(lp); } }
/// <summary> /// Performs a BreadthFirstSearch in an AtomContainer starting with a /// particular sphere, which usually consists of one start atom. While /// searching the graph, the method marks each visited atom. It then puts all /// the atoms connected to the atoms in the given sphere into a new vector /// which forms the sphere to search for the next recursive method call. All /// atoms that have been visited are put into a molecule container. This /// BreadthFirstSearch does thus find the connected graph for a given start /// atom. /// <para>IMPORTANT: this method does not reset the VISITED flags, which must be /// done if calling this method twice! /// </para> /// </summary> /// <param name="atomContainer">The AtomContainer to be searched</param> /// <param name="sphere">A sphere of atoms to start the search with</param> /// <param name="molecule">A molecule into which all the atoms and bonds are stored that are found during search</param> /// <param name="max">max</param> public static void BreadthFirstSearch(IAtomContainer atomContainer, IEnumerable <IAtom> sphere, IAtomContainer molecule, int max) { IAtom nextAtom; List <IAtom> newSphere = new List <IAtom>(); foreach (var atom in sphere) { molecule.Atoms.Add(atom); // first copy LonePair's and SingleElectron's of this Atom as they need // to be copied too var lonePairs = atomContainer.GetConnectedLonePairs(atom); foreach (var lonePair in lonePairs) { molecule.LonePairs.Add(lonePair); } var singleElectrons = atomContainer.GetConnectedSingleElectrons(atom); foreach (var singleElectron in singleElectrons) { molecule.SingleElectrons.Add(singleElectron); } // now look at bonds var bonds = atomContainer.GetConnectedBonds(atom); foreach (var bond in bonds) { nextAtom = bond.GetOther(atom); if (!bond.IsVisited) { molecule.Atoms.Add(nextAtom); molecule.Bonds.Add(bond); bond.IsVisited = true; } if (!nextAtom.IsVisited) { newSphere.Add(nextAtom); nextAtom.IsVisited = true; } } if (max > -1 && molecule.Atoms.Count > max) { return; } } if (newSphere.Count > 0) { BreadthFirstSearch(atomContainer, newSphere, molecule, max); } }
/// <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); }
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> /// Calculate the electronegativity of orbitals pi. /// </summary> /// <param name="ac"></param> /// <param name="atom">atom for which effective atom electronegativity should be calculated</param> /// <param name="maxIterations">The maximal number of Iteration</param> /// <param name="maxResonStruc">The maximal number of Resonance Structures</param> /// <returns>Electronegativity of orbitals pi.</returns> public double CalculatePiElectronegativity(IAtomContainer ac, IAtom atom, int maxIterations, int maxResonStruc) { MaxIterations = maxIterations; MaxResonanceStructures = maxResonStruc; double electronegativity = 0; try { if (!ac.Equals(acOldP)) { molPi = ac.Builder.NewAtomContainer(ac); peoe = new GasteigerMarsiliPartialCharges(); peoe.AssignGasteigerMarsiliSigmaPartialCharges(molPi, true); var iSet = ac.Builder.NewAtomContainerSet(); iSet.Add(molPi); iSet.Add(molPi); gasteigerFactors = pepe.AssignrPiMarsilliFactors(iSet); acOldP = ac; } IAtom atomi = molPi.Atoms[ac.Atoms.IndexOf(atom)]; int atomPosition = molPi.Atoms.IndexOf(atomi); int stepSize = pepe.StepSize; int start = (stepSize * (atomPosition) + atomPosition); double q = atomi.Charge.Value; if (molPi.GetConnectedLonePairs(molPi.Atoms[atomPosition]).Any() || molPi.GetMaximumBondOrder(atomi) != BondOrder.Single || atomi.FormalCharge != 0) { return((gasteigerFactors[1][start]) + (q * gasteigerFactors[1][start + 1]) + (gasteigerFactors[1][start + 2] * (q * q))); } } catch (Exception e) { Trace.TraceError(e.StackTrace); } return(electronegativity); }
/// <summary> /// Check an Atom whether it may be conjugated or not. /// </summary> /// <param name="ac">The AtomContainer containing currentAtom</param> /// <param name="currentAtom">The Atom to check</param> /// <returns>-1 if isolated, 0 if conjugated, 1 if cumulative db</returns> private static int CheckAtom(IAtomContainer ac, IAtom currentAtom) { int check = -1; var atoms = ac.GetConnectedAtoms(currentAtom).ToReadOnlyList(); var bonds = ac.GetConnectedBonds(currentAtom).ToReadOnlyList(); if (currentAtom.IsAromatic) { check = 0; } else if (currentAtom.FormalCharge == 1) /* && currentAtom.Symbol.Equals("C") */ { check = 0; } else if (currentAtom.FormalCharge == -1) { //// NEGATIVE CHARGES WITH A NEIGHBOOR PI BOND //// int counterOfPi = 0; foreach (var atom in atoms) { if (ac.GetMaximumBondOrder(atom) != BondOrder.Single) { counterOfPi++; } } if (counterOfPi > 0) { check = 0; } } else { int se = ac.GetConnectedSingleElectrons(currentAtom).Count(); if (se == 1) { check = 0; //// DETECTION of radicals } else if (ac.GetConnectedLonePairs(currentAtom).Any() /* && (currentAtom.Symbol.Equals("N") */) { check = 0; //// DETECTION of lone pair } else { int highOrderBondCount = 0; for (int j = 0; j < atoms.Count; j++) { var bond = bonds[j]; if (bond == null || bond.Order != BondOrder.Single) { highOrderBondCount++; } else { } } if (highOrderBondCount == 1) { check = 0; } else if (highOrderBondCount > 1) { check = 1; } } } return(check); }
/// <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"); } 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); } 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); } IAtom atomH = reactant.Builder.NewAtom("H"); atomH.FormalCharge = 1; atomList.Add(atomH); var bondList = new List <IBond> { bondi }; IChemObjectSet <IAtomContainer> 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, bondList); if (reaction == null) { continue; } else { setOfReactions.Add(reaction); } } } } } return(setOfReactions); }