/// <summary> /// Constructor for the Electronegativity object. /// </summary> /// <param name="maxIterations">The maximal number of Iteration</param> /// <param name="maxResonStruc">The maximal number of Resonance Structures</param> public PiElectronegativity(int maxIterations, int maxResonStruc) { peoe = new GasteigerMarsiliPartialCharges(); pepe = new GasteigerPEPEPartialCharges(); MaxIterations = maxIterations; MaxResonanceStructures = maxResonStruc; }
public void TestSetStepSize() { GasteigerMarsiliPartialCharges peoe = new GasteigerMarsiliPartialCharges(); int StepSize = 22; peoe.StepSize = StepSize; Assert.AreEqual(StepSize, peoe.StepSize); }
public void TestSetChiCatHydrogen_Double() { GasteigerMarsiliPartialCharges peoe = new GasteigerMarsiliPartialCharges(); double DEOC_HYDROGEN = 22; peoe.ChiCatHydrogen = DEOC_HYDROGEN; Assert.AreEqual(DEOC_HYDROGEN, peoe.ChiCatHydrogen, 0.01); }
public void TestSetMaxGasteigerDamp_Double() { GasteigerMarsiliPartialCharges peoe = new GasteigerMarsiliPartialCharges(); double MX_DAMP = 1; peoe.MaxGasteigerDamp = MX_DAMP; Assert.AreEqual(MX_DAMP, peoe.MaxGasteigerDamp, 0.01); }
public void TestSetMaxGasteigerIters_Double() { GasteigerMarsiliPartialCharges peoe = new GasteigerMarsiliPartialCharges(); double MX_ITERATIONS = 10; peoe.MaxGasteigerIterations = MX_ITERATIONS; Assert.AreEqual(MX_ITERATIONS, peoe.MaxGasteigerIterations, 0.01); }
/// <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); }
public void TestAssignGasteigerSigmaMarsiliFactors_IAtomContainer() { GasteigerMarsiliPartialCharges peoe = new GasteigerMarsiliPartialCharges(); IAtomContainer molecule = builder.NewAtomContainer(); molecule.Atoms.Add(builder.NewAtom("C")); molecule.Atoms[0].Charge = 0.0; molecule.Atoms.Add(builder.NewAtom("F")); molecule.Atoms[1].Charge = 0.0; molecule.AddBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Single); AddExplicitHydrogens(molecule); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule); CDK.LonePairElectronChecker.Saturate(molecule); foreach (var atom in molecule.Atoms) { atom.Charge = 0.0; } Assert.IsNotNull(peoe.AssignGasteigerSigmaMarsiliFactors(molecule).Length); }
public void TestCalculateCharges_IAtomContainer() { double[] testResult = { 0.07915, -0.25264, 0.05783, 0.05783, 0.05783 }; var peoe = new GasteigerMarsiliPartialCharges(); var molecule = builder.NewAtomContainer(); molecule.Atoms.Add(builder.NewAtom("C")); molecule.Atoms.Add(builder.NewAtom("F")); molecule.AddBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Single); AddExplicitHydrogens(molecule); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule); CDK.LonePairElectronChecker.Saturate(molecule); peoe.CalculateCharges(molecule); for (int i = 0; i < molecule.Atoms.Count; i++) { Assert.AreEqual(testResult[i], molecule.Atoms[i].Charge.Value, 0.01); } }
public void TestAssignGasteigerMarsiliSigmaPartialCharges_IAtomContainer_Boolean() { double[] testResult = { 0.07915, -0.25264, 0.05783, 0.05783, 0.05783 }; GasteigerMarsiliPartialCharges peoe = new GasteigerMarsiliPartialCharges(); IAtomContainer molecule = builder.NewAtomContainer(); molecule.Atoms.Add(builder.NewAtom("C")); molecule.Atoms.Add(builder.NewAtom("F")); molecule.AddBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Single); AddExplicitHydrogens(molecule); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule); CDK.LonePairElectronChecker.Saturate(molecule); peoe.AssignGasteigerMarsiliSigmaPartialCharges(molecule, true); for (int i = 0; i < molecule.Atoms.Count; i++) { //Debug.WriteLine("Charge for atom:"+i+" S:"+mol.GetAtomAt(i).Symbol+" Charge:"+mol.GetAtomAt(i).Charge); Assert.AreEqual(testResult[i], molecule.Atoms[i].Charge.Value, 0.01); } }
public void TestUndefinedPartialCharge() { var filename = "NCDK.Data.MDL.burden_undefined.sdf"; var ins = ResourceLoader.GetAsStream(filename); var reader = new MDLV2000Reader(ins); var content = reader.Read(builder.NewChemFile()); reader.Close(); var cList = ChemFileManipulator.GetAllAtomContainers(content); var ac = cList.First(); Assert.IsNotNull(ac); AddExplicitHydrogens(ac); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(ac); Aromaticity.CDKLegacy.Apply(ac); AddExplicitHydrogens(ac); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(ac); CDK.LonePairElectronChecker.Saturate(ac); var peoe = new GasteigerMarsiliPartialCharges(); peoe.CalculateCharges(ac); }
public void TestGetStepSize() { GasteigerMarsiliPartialCharges peoe = new GasteigerMarsiliPartialCharges(); Assert.AreEqual(5, peoe.StepSize); }
public void TestGetChiCatHydrogen() { GasteigerMarsiliPartialCharges peoe = new GasteigerMarsiliPartialCharges(); Assert.AreEqual(20, peoe.MaxGasteigerIterations, 0.01); }
/// <summary> /// Main method which assigns Gasteiger partial pi charges. /// </summary> /// <param name="ac">AtomContainer</param> /// <param name="setCharge">currently unused</param> /// <returns>AtomContainer with partial charges</returns> public IAtomContainer AssignGasteigerPiPartialCharges(IAtomContainer ac, bool setCharge) { // we save the aromaticity flags for the input molecule so that // we can add them back before we return var oldBondAromaticity = new bool[ac.Bonds.Count]; var oldAtomAromaticity = new bool[ac.Atoms.Count]; for (int i = 0; i < ac.Atoms.Count; i++) { oldAtomAromaticity[i] = ac.Atoms[i].IsAromatic; } for (int i = 0; i < ac.Bonds.Count; i++) { oldBondAromaticity[i] = ac.Bonds[i].IsAromatic; } /* 0: remove charge, and possible flag ac */ for (int j = 0; j < ac.Atoms.Count; j++) { ac.Atoms[j].Charge = 0.0; ac.Atoms[j].IsPlaced = false; } for (int j = 0; j < ac.Bonds.Count; j++) { ac.Bonds[j].IsPlaced = false; } /* 1: detect resonance structure */ var gR1 = new StructureResonanceGenerator(); // according G. should be integrated the breaking bonding var reactionList1 = gR1.Reactions.ToList(); var paramList1 = new List <IParameterReaction>(); var param = new SetReactionCenter { IsSetParameter = true }; paramList1.Add(param); var reactionHCPB = new HeterolyticCleavagePBReaction { ParameterList = paramList1 }; reactionList1.Add(new SharingAnionReaction()); foreach (var reaction in reactionList1) { reaction.ParameterList = paramList1; } gR1.Reactions = reactionList1; // according G. should be integrated the breaking bonding var gR2 = new StructureResonanceGenerator { MaximalStructures = MaxResonanceStructures }; var reactionList2 = gR2.Reactions.ToList(); var paramList = new List <IParameterReaction>(); var paramA = new SetReactionCenter { IsSetParameter = true }; paramList.Add(paramA); reactionList2.Add(new HeterolyticCleavagePBReaction()); reactionList2.Add(new SharingAnionReaction()); foreach (var reaction in reactionList2) { reaction.ParameterList = paramList; } gR2.Reactions = reactionList2; /* find resonance containers, which eliminates the repetitions */ StructureResonanceGenerator gRN = new StructureResonanceGenerator(); // according G. should be integrated the breaking bonding var acSet = gRN.GetContainers(RemovingFlagsAromaticity(ac)); var iSet = ac.Builder.NewAtomContainerSet(); iSet.Add(ac); if (acSet != null) { foreach (var container in acSet) { ac = SetFlags(container, ac, true); // Aromatic don't break its double bond homolytically if (Aromaticity.CDKLegacy.Apply(ac)) { reactionList1.Remove(reactionHCPB); } else { reactionList1.Add(reactionHCPB); } var a = gR1.GetStructures(RemovingFlagsAromaticity(ac)); if (a.Count > 1) { for (int j = 1; j < a.Count; j++) { // the first is already added iSet.Add(a[j]); } } ac = SetFlags(container, ac, false); /* processing for bonds which are not in resonance */ for (int number = 0; number < ac.Bonds.Count; number++) { IAtomContainer aa = SetAntiFlags(container, ac, number, true); if (aa != null) { var ab = gR2.GetStructures(aa); if (ab.Count > 1) { for (int j = 1; j < ab.Count; j++) { // the first is already added iSet.Add(ab[j]); } } ac = SetAntiFlags(container, aa, number, false); } } } } /* detect hyperconjugation interactions */ var setHI = GetHyperconjugationInteractions(ac, iSet); if (setHI != null) { if (setHI.Count != 0) { iSet.AddRange(setHI); } Debug.WriteLine($"setHI: {iSet.Count}"); } if (iSet.Count < 2) { for (int i = 0; i < ac.Atoms.Count; i++) { ac.Atoms[i].IsAromatic = oldAtomAromaticity[i]; } for (int i = 0; i < ac.Bonds.Count; i++) { ac.Bonds[i].IsAromatic = oldBondAromaticity[i]; } return(ac); } /* 2: search whose atoms which don't keep their formal charge and set flags */ var sumCharges = Arrays.CreateJagged <double>(iSet.Count, ac.Atoms.Count); for (int i = 1; i < iSet.Count; i++) { var iac = iSet[i]; for (int j = 0; j < iac.Atoms.Count; j++) { sumCharges[i][j] = iac.Atoms[j].FormalCharge.Value; } } for (int i = 1; i < iSet.Count; i++) { var iac = iSet[i]; int count = 0; for (int j = 0; j < ac.Atoms.Count; j++) { if (count < 2) { if (sumCharges[i][j] != ac.Atoms[j].FormalCharge) { ac.Atoms[j].IsPlaced = true; iac.Atoms[j].IsPlaced = true; count++; /* TODO- error */ } } } } /* 3: set sigma charge (PEOE). Initial start point */ var peoe = new GasteigerMarsiliPartialCharges();; peoe.MaxGasteigerIterations = 6; IAtomContainer acCloned; var gasteigerFactors = AssignPiFactors(iSet);//a,b,c,deoc,chi,q /* 4: calculate topological weight factors Wt=fQ*fB*fA */ var Wt = new double[iSet.Count - 1]; for (int i = 1; i < iSet.Count; i++) { Wt[i - 1] = GetTopologicalFactors(iSet[i], ac); Debug.WriteLine($", W:{Wt[i - 1]}"); acCloned = (IAtomContainer)iSet[i].Clone(); acCloned = peoe.AssignGasteigerMarsiliSigmaPartialCharges(acCloned, true); for (int j = 0; j < acCloned.Atoms.Count; j++) { if (iSet[i].Atoms[j].IsPlaced) { gasteigerFactors[i][StepSize * j + j + 5] = acCloned.Atoms[j].Charge.Value; } } } // calculate electronegativity for changed atoms and make the difference // between whose atoms which change their formal charge for (int iter = 0; iter < MaxGasteigerIterations; iter++) { for (int k = 1; k < iSet.Count; k++) { IAtomContainer iac = iSet[k]; double[] electronegativity = new double[2]; int count = 0; int atom1 = 0; int atom2 = 0; for (int j = 0; j < iac.Atoms.Count; j++) { if (count == 2) // The change of sign is product of only two atoms, is not true { break; } if (iac.Atoms[j].IsPlaced) { Debug.WriteLine("Atom: " + j + ", S:" + iac.Atoms[j].Symbol + ", C:" + iac.Atoms[j].FormalCharge); if (count == 0) { atom1 = j; } else { atom2 = j; } double q1 = gasteigerFactors[k][StepSize * j + j + 5]; electronegativity[count] = gasteigerFactors[k][StepSize * j + j + 2] * q1 * q1 + gasteigerFactors[k][StepSize * j + j + 1] * q1 + gasteigerFactors[k][StepSize * j + j]; Debug.WriteLine("e:" + electronegativity[count] + ",q1: " + q1 + ", c:" + gasteigerFactors[k][StepSize * j + j + 2] + ", b:" + gasteigerFactors[k][StepSize * j + j + 1] + ", a:" + gasteigerFactors[k][StepSize * j + j]); count++; } } Debug.WriteLine("Atom1:" + atom1 + ",Atom2:" + atom2); /* difference of electronegativity 1 lower */ var max1 = Math.Max(electronegativity[0], electronegativity[1]); var min1 = Math.Min(electronegativity[0], electronegativity[1]); double DX = 1.0; if (electronegativity[0] < electronegativity[1]) { DX = gasteigerFactors[k][StepSize * atom1 + atom1 + 3]; } else { DX = gasteigerFactors[k][StepSize * atom2 + atom2 + 3]; } var Dq = (max1 - min1) / DX; Debug.WriteLine("Dq : " + Dq + " = (" + max1 + "-" + min1 + ")/" + DX); var epN1 = GetElectrostaticPotentialN(iac, atom1, gasteigerFactors[k]); var epN2 = GetElectrostaticPotentialN(iac, atom2, gasteigerFactors[k]); var SumQN = Math.Abs(epN1 - epN2); Debug.WriteLine("sum(" + SumQN + ") = (" + epN1 + ") - (" + epN2 + ")"); /* electronic weight */ var WE = Dq + fE * SumQN; Debug.WriteLine("WE : " + WE + " = Dq(" + Dq + ")+FE(" + fE + ")*SumQN(" + SumQN); var iTE = iter + 1; /* total topological */ var W = WE * Wt[k - 1] * fS / (iTE); Debug.WriteLine("W : " + W + " = WE(" + WE + ")*Wt(" + Wt[k - 1] + ")*FS(" + fS + ")/iter(" + iTE + "), atoms: " + atom1 + ", " + atom2); /* iac == new structure, ac == old structure */ /* atom1 */ if (iac.Atoms[atom1].FormalCharge == 0) { if (ac.Atoms[atom1].FormalCharge < 0) { gasteigerFactors[k][StepSize * atom1 + atom1 + 5] = -1 * W; } else { gasteigerFactors[k][StepSize * atom1 + atom1 + 5] = W; } } else if (iac.Atoms[atom1].FormalCharge > 0) { gasteigerFactors[k][StepSize * atom1 + atom1 + 5] = W; } else { gasteigerFactors[k][StepSize * atom1 + atom1 + 5] = -1 * W; } /* atom2 */ if (iac.Atoms[atom2].FormalCharge == 0) { if (ac.Atoms[atom2].FormalCharge < 0) { gasteigerFactors[k][StepSize * atom2 + atom2 + 5] = -1 * W; } else { gasteigerFactors[k][StepSize * atom2 + atom2 + 5] = W; } } else if (iac.Atoms[atom2].FormalCharge > 0) { gasteigerFactors[k][StepSize * atom2 + atom2 + 5] = W; } else { gasteigerFactors[k][StepSize * atom2 + atom2 + 5] = -1 * W; } } for (int k = 1; k < iSet.Count; k++) { for (int i = 0; i < ac.Atoms.Count; i++) { if (iSet[k].Atoms[i].IsPlaced) { var charge = ac.Atoms[i].Charge.Value; double chargeT = 0.0; chargeT = charge + gasteigerFactors[k][StepSize * i + i + 5]; Debug.WriteLine("i<|" + ac.Atoms[i].Symbol + ", " + chargeT + "=c:" + charge + "+g: " + gasteigerFactors[k][StepSize * i + i + 5]); ac.Atoms[i].Charge = chargeT; } } } }// iterations Debug.WriteLine("final"); // before getting back we should set back the aromatic flags for (int i = 0; i < ac.Atoms.Count; i++) { ac.Atoms[i].IsAromatic = oldAtomAromaticity[i]; } for (int i = 0; i < ac.Bonds.Count; i++) { ac.Bonds[i].IsAromatic = oldBondAromaticity[i]; } return(ac); }
public void TestGetMaxGasteigerDamp() { var peoe = new GasteigerMarsiliPartialCharges(); Assert.AreEqual(20, peoe.MaxGasteigerIterations, 0.01); }