public void TestAssignAtomTyps_bug_amideRingAtomType() { var smiles = "O=C1N(C(=O)C(C(=O)N1)(CC)CC)C"; var parser = CDK.SmilesParser; var bugmol = parser.ParseSmiles(smiles); forceFieldConfigurator.SetForceFieldConfigurator("mmff94"); IAtom nitrogen1 = bugmol.Atoms[2]; HOSECodeGenerator hscodegen = new HOSECodeGenerator(); forceFieldConfigurator.ConfigureAtom(nitrogen1, hscodegen.GetHOSECode(bugmol, nitrogen1, 3), false); Assert.AreEqual("NC=O", nitrogen1.AtomTypeName); }
public void TestAssignAtomTyps_bug_so2() { var smiles = "CS(=O)(=O)NC(=O)NN1CC2CCCC2C1"; var parser = CDK.SmilesParser; var bugmol = parser.ParseSmiles(smiles); forceFieldConfigurator.SetForceFieldConfigurator("mmff94"); IAtom sulphur = bugmol.Atoms[1]; HOSECodeGenerator hscodegen = new HOSECodeGenerator(); forceFieldConfigurator.ConfigureAtom(sulphur, hscodegen.GetHOSECode(bugmol, sulphur, 3), false); Assert.AreEqual("SO2", sulphur.AtomTypeName); }
[TestMethod(), Ignore()] // Old atom typing method - see new Mmff class public void TestAssignAtomTyps_bug_nitrogenatomType() { var smiles = "CNC(=O)N(C)N=O"; var parser = CDK.SmilesParser; var bugmol = parser.ParseSmiles(smiles); forceFieldConfigurator.SetForceFieldConfigurator("mmff94"); IAtom nitrogen1 = bugmol.Atoms[1]; IAtom nitrogen2 = bugmol.Atoms[4]; IAtom nitrogen3 = bugmol.Atoms[6]; HOSECodeGenerator hscodegen = new HOSECodeGenerator(); forceFieldConfigurator.ConfigureAtom(nitrogen1, hscodegen.GetHOSECode(bugmol, nitrogen1, 3), false); forceFieldConfigurator.ConfigureAtom(nitrogen2, hscodegen.GetHOSECode(bugmol, nitrogen2, 3), false); forceFieldConfigurator.ConfigureAtom(nitrogen3, hscodegen.GetHOSECode(bugmol, nitrogen3, 3), false); Assert.AreEqual("NC=O", nitrogen1.AtomTypeName); Assert.AreEqual("NC=O", nitrogen2.AtomTypeName); }
private static void SetActiveCenters(IAtomContainer reactant, int length, bool checkPrev, AtomCheck atomCheck) { var hcg = new HOSECodeGenerator(); foreach (var atomi in reactant.Atoms) { if (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.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 (atomCheck(atomR)) { atomi.IsReactiveCenter = true; atoml.IsReactiveCenter = true; atomR.IsReactiveCenter = true; reactant.GetBond(atomR, atoml).IsReactiveCenter = true;; } } } } } } }
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> /// Method assigns atom types to atoms (calculates sssr and aromaticity) /// </summary> /// <returns>sssrf set</returns> /// <exception cref="CDKException"> Problems detecting aromaticity or making hose codes.</exception> public IRingSet AssignAtomTyps(IAtomContainer molecule) { IAtom atom = null; string hoseCode = ""; HOSECodeGenerator hcg = new HOSECodeGenerator(); int NumberOfRingAtoms = 0; IRingSet ringSetMolecule = Cycles.FindSSSR(molecule).ToRingSet(); bool isInHeteroRing = false; try { AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule); Aromaticity.CDKLegacy.Apply(molecule); } catch (Exception cdk1) { throw new CDKException("AROMATICITYError: Cannot determine aromaticity due to: " + cdk1.Message, cdk1); } for (int i = 0; i < molecule.Atoms.Count; i++) { atom = molecule.Atoms[i]; if (ringSetMolecule.Contains(atom)) { NumberOfRingAtoms = NumberOfRingAtoms + 1; atom.IsInRing = true; atom.IsAliphatic = false; var ringSetA = ringSetMolecule.GetRings(atom).ToList(); RingSetManipulator.Sort(ringSetA); IRing sring = (IRing)ringSetA[ringSetA.Count - 1]; atom.SetProperty("RING_SIZE", sring.RingSize); foreach (var ring in ringSetA) { if (IsHeteroRingSystem(ring)) { break; } } } else { atom.IsAliphatic = true; atom.IsInRing = false; isInHeteroRing = false; } atom.SetProperty("MAX_BOND_ORDER", molecule.GetMaximumBondOrder(atom).Numeric()); try { hoseCode = hcg.GetHOSECode(molecule, atom, 3); //Debug.WriteLine("HOSECODE GENERATION: ATOM "+i+" HoseCode: "+hoseCode+" "); } catch (CDKException ex1) { Console.Out.WriteLine("Could not build HOSECode from atom " + i + " due to " + ex1.ToString()); throw new CDKException("Could not build HOSECode from atom " + i + " due to " + ex1.ToString(), ex1); } try { ConfigureAtom(atom, hoseCode, isInHeteroRing); } catch (CDKException ex2) { Console.Out.WriteLine("Could not final configure atom " + i + " due to " + ex2.ToString()); throw new CDKException("Could not final configure atom due to problems with force field", ex2); } } // IBond[] bond = molecule.Bonds; string bondType; foreach (var bond in molecule.Bonds) { //Debug.WriteLine("bond[" + i + "] properties : " + molecule.Bonds[i].GetProperties()); bondType = "0"; if (bond.Order == BondOrder.Single) { if ((bond.Begin.AtomTypeName.Equals("Csp2", StringComparison.Ordinal)) && ((bond.End.AtomTypeName.Equals("Csp2", StringComparison.Ordinal)) || (bond.End.AtomTypeName.Equals("C=", StringComparison.Ordinal)))) { bondType = "1"; } if ((bond.Begin.AtomTypeName.Equals("C=", StringComparison.Ordinal)) && ((bond.End.AtomTypeName.Equals("Csp2", StringComparison.Ordinal)) || (bond.End.AtomTypeName.Equals("C=", StringComparison.Ordinal)))) { bondType = "1"; } if ((bond.Begin.AtomTypeName.Equals("Csp", StringComparison.Ordinal)) && (bond.End.AtomTypeName.Equals("Csp", StringComparison.Ordinal))) { bondType = "1"; } } // molecule.Bonds[i].SetProperty("MMFF94 bond type", bondType); bond.SetProperty("MMFF94 bond type", bondType); //Debug.WriteLine("bond[" + i + "] properties : " + molecule.Bonds[i].GetProperties()); } return(ringSetMolecule); }
/// <summary> /// extract from the db the ionization energy. /// </summary> /// <param name="container">The IAtomContainer</param> /// <param name="atom">The IAtom</param> /// <returns>The energy value</returns> public static double ExtractIP(IAtom atom, IAtomContainer container, IReadOnlyDictionary <string, double> hoseVSenergy, IReadOnlyDictionary <string, double> hoseVSenergyS) { if (!FamilyHalogen(atom)) { return(0); } var hcg = new HOSECodeGenerator(); //Check starting from the exact sphere hose code and maximal a value of 10 int exactSphere = 0; string hoseCode = ""; for (int spheres = maxSpheresToUse; spheres > 0; spheres--) { hcg.GetSpheres(container, atom, spheres, true); var atoms = hcg.GetNodesInSphere(spheres); if (atoms.Any()) { exactSphere = spheres; hoseCode = hcg.GetHOSECode(container, atom, spheres, true); if (hoseVSenergy.ContainsKey(hoseCode)) { return(hoseVSenergy[hoseCode]); } if (hoseVSenergyS.ContainsKey(hoseCode)) { return(hoseVSenergyS[hoseCode]); } break; } } //Check starting from the rings bigger and smaller //TODO:IP: Better application for (int i = 0; i < 3; i++) { // two rings for (int plusMinus = 0; plusMinus < 2; plusMinus++) { // plus==bigger, minus==smaller int sign = -1; if (plusMinus == 1) { sign = 1; } var st = Strings.Tokenize(hoseCode, '(', ')', '/').GetEnumerator(); var hoseCodeBuffer = new StringBuilder(); int sum = exactSphere + sign * (i + 1); for (int k = 0; k < sum; k++) { if (st.MoveNext()) { string partcode = st.Current; hoseCodeBuffer.Append(partcode); } switch (k) { case 0: hoseCodeBuffer.Append('('); break; case 3: hoseCodeBuffer.Append(')'); break; default: hoseCodeBuffer.Append('/'); break; } } string hoseCodeBU = hoseCodeBuffer.ToString(); if (hoseVSenergyS.ContainsKey(hoseCodeBU)) { return(hoseVSenergyS[hoseCodeBU]); } } } return(0); }