public void Test3Aminomethane_cation() { var builder = CDK.Builder; var mol = builder.NewAtomContainer(); mol.Atoms.Add(builder.NewAtom("N")); mol.Atoms.Add(builder.NewAtom("C")); mol.AddBond(mol.Atoms[0], mol.Atoms[1], BondOrder.Single); mol.Atoms.Add(builder.NewAtom("C")); mol.AddBond(mol.Atoms[0], mol.Atoms[2], BondOrder.Single); mol.Atoms.Add(builder.NewAtom("C")); mol.AddBond(mol.Atoms[0], mol.Atoms[3], BondOrder.Single); mol.Atoms[3].FormalCharge = +1; mol.Atoms.Add(builder.NewAtom("N")); mol.AddBond(mol.Atoms[3], mol.Atoms[4], BondOrder.Single); mol.Atoms.Add(builder.NewAtom("C")); mol.AddBond(mol.Atoms[4], mol.Atoms[5], BondOrder.Single); mol.Atoms.Add(builder.NewAtom("C")); mol.AddBond(mol.Atoms[4], mol.Atoms[6], BondOrder.Single); mol.Atoms.Add(builder.NewAtom("N")); mol.AddBond(mol.Atoms[3], mol.Atoms[7], BondOrder.Single); mol.Atoms.Add(builder.NewAtom("C")); mol.AddBond(mol.Atoms[7], mol.Atoms[8], BondOrder.Single); mol.Atoms.Add(builder.NewAtom("C")); mol.AddBond(mol.Atoms[7], mol.Atoms[8], BondOrder.Single); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(mol); AddImplicitHydrogens(mol); CDK.LonePairElectronChecker.Saturate(mol); Aromaticity.CDKLegacy.Apply(mol); var acSet = ConjugatedPiSystemsDetector.Detect(mol); Assert.AreEqual(1, acSet.Count); IAtomContainer ac1 = acSet[0]; Assert.AreEqual(4, ac1.Atoms.Count); Assert.AreEqual(3, ac1.Bonds.Count); }
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 TestPartialSigmaChargeDescriptor_Methyl_Floride() { double[] testResult = { 0.07915, -0.25264, 0.05783, 0.05783, 0.05783 }; // from Petra online: http://www2.chemie.uni-erlangen.de/services/petra/smiles.phtml var mol = CDK.Builder.NewAtomContainer(); mol.Atoms.Add(CDK.Builder.NewAtom("C")); mol.Atoms.Add(CDK.Builder.NewAtom("F")); mol.AddBond(mol.Atoms[0], mol.Atoms[1], BondOrder.Single); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(mol); AddExplicitHydrogens(mol); CDK.LonePairElectronChecker.Saturate(mol); AddExplicitHydrogens(mol); var descriptor = CreateDescriptor(mol); for (int i = 0; i < mol.Atoms.Count; i++) { var result = descriptor.Calculate(mol.Atoms[i]).Value; Assert.AreEqual(testResult[i], result, 0.001); } }
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 static IAtomContainer CreateSimpleAmine() { IAtomContainer result = builder.NewAtomContainer(); IAtom c1 = builder.NewAtom("C"); IAtom c2 = builder.NewAtom("N"); result.Atoms.Add(c1); result.Atoms.Add(c2); IBond bond = builder.NewBond(c1, c2, BondOrder.Single); result.Bonds.Add(bond); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(result); var adder = CDK.HydrogenAdder; adder.AddImplicitHydrogens(result); Aromaticity.CDKLegacy.Apply(result); return(result); }
public void TestM26() { IAtomContainer expected1 = builder.NewAtomContainer(); expected1.Atoms.Add(builder.NewAtom("F")); expected1.Atoms[0].FormalCharge = 1; expected1.Atoms.Add(builder.NewAtom("C")); expected1.AddBond(expected1.Atoms[0], expected1.Atoms[1], BondOrder.Double); expected1.Atoms.Add(builder.NewAtom("C")); expected1.Atoms[2].FormalCharge = -1; expected1.AddBond(expected1.Atoms[1], expected1.Atoms[2], BondOrder.Single); expected1.Atoms.Add(builder.NewAtom("C")); expected1.AddBond(expected1.Atoms[2], expected1.Atoms[3], BondOrder.Single); expected1.Atoms.Add(builder.NewAtom("C")); expected1.AddBond(expected1.Atoms[3], expected1.Atoms[4], BondOrder.Double); expected1.Atoms.Add(builder.NewAtom("C")); expected1.AddBond(expected1.Atoms[4], expected1.Atoms[5], BondOrder.Single); expected1.Atoms.Add(builder.NewAtom("C")); expected1.AddBond(expected1.Atoms[5], expected1.Atoms[6], BondOrder.Double); expected1.AddBond(expected1.Atoms[6], expected1.Atoms[1], BondOrder.Single); AddExplicitHydrogens(expected1); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(expected1); CDK.LonePairElectronChecker.Saturate(expected1); string[] expectedTypes = { "F.plus.sp2", "C.sp2", "C.minus.planar", "C.sp2", "C.sp2", "C.sp2", "C.sp2", "H", "H", "H", "H", "H" }; Assert.AreEqual(expectedTypes.Length, expected1.Atoms.Count); for (int i = 0; i < expectedTypes.Length; i++) { IAtom nextAtom = expected1.Atoms[i]; IAtomType perceivedType = matcher.FindMatchingAtomType(expected1, nextAtom); Assert.IsNotNull(perceivedType, "Missing atom type for: " + nextAtom + " " + i + " expected: " + expectedTypes[i]); Assert.AreEqual(expectedTypes[i], perceivedType.AtomTypeName, "Incorrect atom type perceived for: " + nextAtom); nextAtom.Hybridization = Hybridization.Unset; AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(expected1); IAtomType type = matcher.FindMatchingAtomType(expected1, nextAtom); Assert.IsNotNull(type); } }
public void TestBug771485() { var builder = CDK.Builder; var filename = "NCDK.Data.MDL.bug771485-1.mol"; var ins = ResourceLoader.GetAsStream(filename); var reader = new MDLV2000Reader(ins, ChemObjectReaderMode.Strict); IAtomContainer structure1 = (IAtomContainer)reader.Read(builder.NewAtomContainer()); filename = "NCDK.Data.MDL.bug771485-2.mol"; ins = ResourceLoader.GetAsStream(filename); reader = new MDLV2000Reader(ins, ChemObjectReaderMode.Strict); IAtomContainer structure2 = (IAtomContainer)reader.Read(builder.NewAtomContainer()); // these molecules are different resonance forms of the same molecule // make sure aromaticity is detected. although some fingerprinters do this // one should not expected all implementations to do so. AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(structure1); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(structure2); Aromaticity.CDKLegacy.Apply(structure1); Aromaticity.CDKLegacy.Apply(structure2); AddImplicitHydrogens(structure1); AddImplicitHydrogens(structure2); Kekulization.Kekulize(structure1); Kekulization.Kekulize(structure2); // hydrogens loaded from MDL mol files if non-query. Structure 2 has // query aromatic bonds and the hydrogen counts are not assigned - ensure // this is done here. CDK.HydrogenAdder.AddImplicitHydrogens(structure1); CDK.HydrogenAdder.AddImplicitHydrogens(structure2); IFingerprinter fingerprinter = GetBitFingerprinter(); BitArray superBS = fingerprinter.GetBitFingerprint(structure2).AsBitSet(); BitArray subBS = fingerprinter.GetBitFingerprint(structure1).AsBitSet(); bool isSubset = FingerprinterTool.IsSubset(superBS, subBS); Assert.IsTrue(isSubset); }
/// <summary> /// get the molecule 1: C[O+]!-!C /// </summary> /// <returns>The IAtomContainerSet</returns> private IChemObjectSet <IAtomContainer> GetExampleReactants() { var setOfReactants = ChemObjectBuilder.Instance.NewAtomContainerSet(); IAtomContainer molecule = builder.NewAtomContainer(); molecule.Atoms.Add(builder.NewAtom("C")); molecule.Atoms.Add(builder.NewAtom("O")); molecule.Atoms[1].FormalCharge = +1; molecule.Atoms.Add(builder.NewAtom("C")); molecule.AddBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Single); molecule.AddBond(molecule.Atoms[1], molecule.Atoms[2], BondOrder.Single); molecule.Atoms.Add(builder.NewAtom("H")); molecule.Atoms.Add(builder.NewAtom("H")); molecule.Atoms.Add(builder.NewAtom("H")); molecule.Atoms.Add(builder.NewAtom("H")); molecule.Atoms.Add(builder.NewAtom("H")); molecule.Atoms.Add(builder.NewAtom("H")); molecule.Atoms.Add(builder.NewAtom("H")); molecule.AddBond(molecule.Atoms[0], molecule.Atoms[3], BondOrder.Single); molecule.AddBond(molecule.Atoms[0], molecule.Atoms[4], BondOrder.Single); molecule.AddBond(molecule.Atoms[0], molecule.Atoms[5], BondOrder.Single); molecule.AddBond(molecule.Atoms[1], molecule.Atoms[6], BondOrder.Single); molecule.AddBond(molecule.Atoms[2], molecule.Atoms[7], BondOrder.Single); molecule.AddBond(molecule.Atoms[2], molecule.Atoms[8], BondOrder.Single); molecule.AddBond(molecule.Atoms[2], molecule.Atoms[9], BondOrder.Single); try { AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule); CDK.LonePairElectronChecker.Saturate(molecule); } catch (CDKException e) { Console.Out.WriteLine(e.StackTrace); } setOfReactants.Add(molecule); return(setOfReactants); }
public void TestNN_dimethylaniline_cation() { IAtomContainer mol = null; var filename = "NCDK.Data.MDL.NN_dimethylaniline.mol"; var ins = ResourceLoader.GetAsStream(filename); var reader = new MDLV2000Reader(ins); var chemFile = reader.Read(builder.NewChemFile()); mol = chemFile[0][0].MoleculeSet[0]; AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(mol); AddImplicitHydrogens(mol); CDK.LonePairElectronChecker.Saturate(mol); Aromaticity.CDKLegacy.Apply(mol); var acSet = ConjugatedPiSystemsDetector.Detect(mol); Assert.AreEqual(1, acSet.Count); IAtomContainer ac1 = acSet[0]; Assert.AreEqual(6, ac1.Atoms.Count); Assert.AreEqual(5, ac1.Bonds.Count); }
public void Testfp2() { IFingerprinter printer = new PubchemFingerprinter(); var mol1 = parser.ParseSmiles("CC(N)CCCN"); var mol2 = parser.ParseSmiles("CC(N)CCC"); var mol3 = parser.ParseSmiles("CCCC"); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(mol1); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(mol2); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(mol3); Aromaticity.CDKLegacy.Apply(mol1); Aromaticity.CDKLegacy.Apply(mol2); Aromaticity.CDKLegacy.Apply(mol3); BitArray bs1 = printer.GetBitFingerprint(mol1).AsBitSet(); BitArray bs2 = printer.GetBitFingerprint(mol2).AsBitSet(); BitArray bs3 = printer.GetBitFingerprint(mol3).AsBitSet(); Assert.IsTrue(FingerprinterTool.IsSubset(bs1, bs2)); Assert.IsTrue(FingerprinterTool.IsSubset(bs2, bs3)); }
public void TestAromaticSystem() { var mol = TestMoleculeFactory.MakeAzulene(); Assert.IsNotNull(mol, "Created molecule was null"); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(mol); Aromaticity.CDKLegacy.Apply(mol); var it = new EquivalentClassPartitioner(mol); var equivalentClass = it.GetTopoEquivClassbyHuXu(mol); var arrEquivalent = new char[mol.Atoms.Count]; for (int i = 1; i < equivalentClass.Length; i++) { arrEquivalent[i - 1] = equivalentClass[i].ToString()[0]; } string strEquivalent = new string(arrEquivalent); Assert.IsNotNull(equivalentClass, "Equivalent class was null"); Assert.AreEqual(mol.Atoms.Count + 1, equivalentClass.Length, "Unexpected equivalent class length"); Assert.AreEqual(6, equivalentClass[0], "Wrong number of equivalent classes");//number of Class Assert.AreEqual("1232145654", strEquivalent, "Wrong class assignment"); }
public void TestUndefinedValues() { var filename = "NCDK.Data.MDL.burden_undefined.sdf"; IChemFile content; using (var reader = new MDLV2000Reader(ResourceLoader.GetAsStream(filename))) { content = reader.Read(CDK.Builder.NewChemFile()); } var cList = ChemFileManipulator.GetAllAtomContainers(content).ToReadOnlyList(); var ac = cList[0]; Assert.IsNotNull(ac); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(ac); AddExplicitHydrogens(ac); Aromaticity.CDKLegacy.Apply(ac); var e = CreateDescriptor().Calculate(ac).Exception; Assert.IsNotNull(e); // make sure exception was a NPE etc. Assert.AreEqual("Could not calculate partial charges: Partial charge not-supported for element: 'As'.", e.Message); }
public static void ConfigureAtomContainer(IAtomContainer mol) { //SystemUtil.LoadAssembly(@"C:\Mobius_OpenSource\MobiusClient\Client\bin\Debug\IKVM.OpenJDK.XML.Parse.dll"); //var s = new [email protected](); //var t = new com.sun.org.apache.xalan.@internal.xsltc.trax.TransformerFactoryImpl(); try // Throws “Provider com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl not found” { AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(mol); // Perceive Configure atoms } catch (Exception ex) { ex = ex; } GetHydrogenAdder().AddImplicitHydrogens(mol); // Be sure implicit hydrogens have been added ApplyAromaticity(mol); //// If bond order 4 was present, deduce bond orders // DeduceBondSystemTool dbst = new DeduceBondSystemTool(); // mol = dbst.fixAromaticBondOrders(mol); return; }
public void TestCalculateCharges_IAtomContainer() { double[] testResult = { 0.0, 0.0, 0.0, 0.0, 0.0 }; GasteigerPEPEPartialCharges peoe = new GasteigerPEPEPartialCharges(); 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.CalculateCharges(molecule); 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 TestPartialSigmaChargeDescriptor_Allyl_bromide() { var testResult = -0.1366; // from Petra online: http://www2.chemie.uni-erlangen.de/services/petra/smiles.phtml var mol = CDK.Builder.NewAtomContainer(); mol.Atoms.Add(CDK.Builder.NewAtom("C")); mol.Atoms.Add(CDK.Builder.NewAtom("C")); mol.AddBond(mol.Atoms[0], mol.Atoms[1], BondOrder.Double); mol.Atoms.Add(CDK.Builder.NewAtom("C")); mol.AddBond(mol.Atoms[1], mol.Atoms[2], BondOrder.Single); mol.Atoms.Add(CDK.Builder.NewAtom("Br")); mol.AddBond(mol.Atoms[2], mol.Atoms[3], BondOrder.Single); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(mol); AddExplicitHydrogens(mol); CDK.LonePairElectronChecker.Saturate(mol); var descriptor = CreateDescriptor(mol); var result = descriptor.Calculate(mol.Atoms[3]).Value; Assert.AreEqual(testResult, result, 0.01); }
/// <summary> /// Get the example set of molecules. /// </summary> /// <returns>The IAtomContainerSet</returns> private IChemObjectSet <IAtomContainer> GetExampleReactants() { var setOfReactants = ChemObjectBuilder.Instance.NewAtomContainerSet(); IAtomContainer molecule = builder.NewAtomContainer(); molecule.Atoms.Add(builder.NewAtom("C")); molecule.Atoms.Add(builder.NewAtom("O")); molecule.AddBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Double); try { AddExplicitHydrogens(molecule); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule); CDK.LonePairElectronChecker.Saturate(molecule); } catch (Exception e) { Console.Out.WriteLine(e.StackTrace); } setOfReactants.Add(molecule); return(setOfReactants); }
public override void TestBug706786() { IAtomContainer superStructure = Bug706786_1(); IAtomContainer subStructure = Bug706786_2(); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(superStructure); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(subStructure); AddImplicitHydrogens(superStructure); AddImplicitHydrogens(subStructure); // SMARTS is now correct and D will include H atoms, CDK had this wrong // for years (had it has non-H count). Whilst you can set the optional // SMARTS flavor CDK_LEGACY this is not correct AtomContainerManipulator.SuppressHydrogens(superStructure); AtomContainerManipulator.SuppressHydrogens(subStructure); IFingerprinter fpr = new EStateFingerprinter(); IBitFingerprint superBits = fpr.GetBitFingerprint(superStructure); IBitFingerprint subBits = fpr.GetBitFingerprint(subStructure); Assert.IsTrue(BitArrays.Equals(AsBitSet(6, 11, 12, 15, 16, 18, 33, 34, 35), superBits.AsBitSet())); Assert.IsTrue(BitArrays.Equals(AsBitSet(8, 11, 16, 35), subBits.AsBitSet())); }
public void TestNewSaturate_Methyl_alcohol_AddH() { // test Methyl alcohol, CH3OH var m = new AtomContainer(); m.Atoms.Add(new Atom("C")); m.Atoms.Add(new Atom("O")); for (int i = 0; i < 4; i++) { m.Atoms.Add(new Atom("H")); } m.AddBond(m.Atoms[0], m.Atoms[1], BondOrder.Single); m.AddBond(m.Atoms[0], m.Atoms[2], BondOrder.Single); m.AddBond(m.Atoms[0], m.Atoms[3], BondOrder.Single); m.AddBond(m.Atoms[0], m.Atoms[4], BondOrder.Single); m.AddBond(m.Atoms[1], m.Atoms[5], BondOrder.Single); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(m); CDK.LonePairElectronChecker.Saturate(m); Assert.AreEqual(2, m.GetConnectedLonePairs(m.Atoms[1]).Count()); Assert.AreEqual(0, m.GetConnectedLonePairs(m.Atoms[0]).Count()); }
public void TestGetSubgraphAtomsMapsIAtomContainer() { int[] result1 = { 6, 5, 7, 8, 0 }; int[] result2 = { 3, 4, 2, 1, 0 }; var mol = TestMoleculeFactory.MakeIndole(); var frag1 = TestMoleculeFactory.MakePyrrole(); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(mol); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(frag1); Aromaticity.CDKLegacy.Apply(mol); Aromaticity.CDKLegacy.Apply(frag1); var list = uiTester.GetSubgraphAtomsMaps(mol, frag1).ToReadOnlyList(); var first = list[0]; for (int i = 0; i < first.Count; i++) { var rmap = first[i]; Assert.AreEqual(rmap.Id1, result1[i]); Assert.AreEqual(rmap.Id2, result2[i]); } }
private IChemObjectSet <IAtomContainer> GetExampleReactants() { var setOfReactants = CDK.Builder.NewAtomContainerSet(); var molecule = builder.NewAtomContainer(); molecule.Atoms.Add(builder.NewAtom("C")); molecule.Atoms[0].FormalCharge = 1; molecule.Atoms.Add(builder.NewAtom("C")); molecule.AddBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Single); molecule.Atoms.Add(builder.NewAtom("C")); molecule.AddBond(molecule.Atoms[1], molecule.Atoms[2], BondOrder.Single); try { AddExplicitHydrogens(molecule); } catch (Exception e) { Console.Out.WriteLine(e.StackTrace); } IAtom atom = molecule.Atoms[0]; molecule.SingleElectrons.Add(CDK.Builder.NewSingleElectron(atom)); atom.FormalCharge = 0; try { AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule); MakeSureAtomTypesAreRecognized(molecule); } catch (CDKException e) { Console.Out.WriteLine(e.StackTrace); } setOfReactants.Add(molecule); return(setOfReactants); }
public void TestBasicAmineOnDrugs_cdkAromaticModel() { var filename = "drugs.smi"; var ins = ResourceLoader.GetAsStream(GetType(), filename); using (EnumerableSMILESReader reader = new EnumerableSMILESReader(ins, ChemObjectBuilder.Instance)) { SMARTSQueryTool sqt = new SMARTSQueryTool("[NX3;H2,H1;!$(NC=O)]", ChemObjectBuilder.Instance); sqt.SetAromaticity(new Aromaticity(ElectronDonation.CDKModel, Cycles.CDKAromaticSetFinder)); int nmatch = 0; int nmol = 0; foreach (var container in reader) { AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(container); // skip un-typed atoms, they can't be run through the CDK aromatic // model foreach (var atom in container.Atoms) { if (atom.AtomTypeName == null) { goto continue_READ; } } if (sqt.Matches(container)) { nmatch++; } nmol++; continue_READ: ; } Assert.AreEqual(141, nmol); Assert.AreEqual(4, nmatch); } }
public static IAtomContainer CreateAcetone() { IAtomContainer result = builder.NewAtomContainer(); IAtom c1 = builder.NewAtom("C"); c1.Id = "1"; IAtom c2 = builder.NewAtom("C"); c2.Id = "2"; IAtom c3 = builder.NewAtom("C"); c3.Id = "3"; IAtom c4 = builder.NewAtom("O"); c4.Id = "4"; result.Atoms.Add(c1); result.Atoms.Add(c2); result.Atoms.Add(c3); result.Atoms.Add(c4); IBond bond1 = builder.NewBond(c1, c2, BondOrder.Single); IBond bond2 = builder.NewBond(c2, c3, BondOrder.Single); IBond bond3 = builder.NewBond(c3, c4, BondOrder.Double); result.Bonds.Add(bond1); result.Bonds.Add(bond2); result.Bonds.Add(bond3); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(result); var adder = CDK.HydrogenAdder; adder.AddImplicitHydrogens(result); Aromaticity.CDKLegacy.Apply(result); return(result); }
/// <param name="maxIterations">Number of maximum iterations</param> /// <param name="checkLonePairElectron">Checking lone pair electrons. Default <see langword="true"/></param> /// <param name="maxResonanceStructures">Number of maximum resonance structures to be searched</param> public PiElectronegativityDescriptor(IAtomContainer container, int maxIterations = int.MaxValue, bool checkLonePairElectron = true, int maxResonanceStructures = int.MaxValue ) { clonedContainer = (IAtomContainer)container.Clone(); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(clonedContainer); if (checkLonePairElectron) { CDK.LonePairElectronChecker.Saturate(clonedContainer); } electronegativity = new PiElectronegativity(); if (maxIterations != int.MaxValue) { electronegativity.MaxIterations = maxIterations; } if (maxResonanceStructures != int.MaxValue) { electronegativity.MaxResonanceStructures = maxResonanceStructures; } this.container = container; }
public void TestNewSaturate_methoxide_anion() { // test methoxide anion, CH3O- Atom c1 = new Atom("C") { ImplicitHydrogenCount = 3 }; Atom o = new Atom("O") { FormalCharge = -1 }; Bond b1 = new Bond(c1, o, BondOrder.Single); var m = new AtomContainer(); m.Atoms.Add(c1); m.Atoms.Add(o); m.Bonds.Add(b1); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(m); CDK.LonePairElectronChecker.Saturate(m); Assert.AreEqual(3, m.GetConnectedLonePairs(o).Count()); }
public void TestNewSaturate_Methyl_alcohol() { // test Methyl chloride, CH3OH Atom c1 = new Atom("C") { ImplicitHydrogenCount = 3 }; Atom o = new Atom("O") { ImplicitHydrogenCount = 1 }; Bond b1 = new Bond(c1, o, BondOrder.Single); var m = new AtomContainer(); m.Atoms.Add(c1); m.Atoms.Add(o); m.Bonds.Add(b1); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(m); CDK.LonePairElectronChecker.Saturate(m); Assert.AreEqual(2, m.GetConnectedLonePairs(o).Count()); Assert.AreEqual(0, m.GetConnectedLonePairs(c1).Count()); }
public void TestPartialPiChargeDescriptor_FormicAcid() { double[] testResult = { 0.0221, -0.1193, 0.0972, 0.0, 0.0 }; // from Petra online: http://www2.chemie.uni-erlangen.de/services/petra/smiles.phtml var mol = CDK.Builder.NewAtomContainer(); mol.Atoms.Add(CDK.Builder.NewAtom("C")); mol.Atoms.Add(CDK.Builder.NewAtom("O")); mol.AddBond(mol.Atoms[0], mol.Atoms[1], BondOrder.Double); mol.Atoms.Add(CDK.Builder.NewAtom("O")); mol.AddBond(mol.Atoms[0], mol.Atoms[2], BondOrder.Single); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(mol); AddExplicitHydrogens(mol); CDK.LonePairElectronChecker.Saturate(mol); var descriptor = CreateDescriptor(mol); for (int i = 0; i < mol.Atoms.Count; i++) { var result = descriptor.Calculate(mol.Atoms[i]).Value; Assert.IsNotNull(result); if (testResult[i] == 0.0) { Assert.IsTrue(result == 0.0); } else { Assert.IsTrue(result != 0.0); Assert.AreEqual(GetSign(testResult[i]), GetSign(result), 0.00001); } Assert.AreEqual(testResult[i], result, 0.04); } }
/// <summary> /// Calculates the three classes of BCUT descriptors. /// </summary> /// <returns>An ArrayList containing the descriptors. The default is to return /// all calculated eigenvalues of the Burden matrices in the order described /// above. If a parameter list was supplied, then only the specified number /// of highest and lowest eigenvalues (for each class of BCUT) will be returned. /// </returns> /// <param name="nhigh">The number of highest eigenvalue</param> /// <param name="nlow">The number of lowest eigenvalue</param> public Result Calculate(IAtomContainer container, int nhigh = 1, int nlow = 1) { container = (IAtomContainer)container.Clone(); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(container); var hAdder = CDK.HydrogenAdder; hAdder.AddImplicitHydrogens(container); AtomContainerManipulator.ConvertImplicitToExplicitHydrogens(container); if (checkAromaticity) { AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(container); Aromaticity.CDKLegacy.Apply(container); } try { return(CalculateMain(container, nhigh, nlow)); } catch (CDKException e) { return(new Result(e)); } }
public void TestSearchMCS() { try { var sp = new SmilesParser(ChemObjectBuilder.Instance, false); IAtomContainer target = null; target = sp.ParseSmiles("C\\C=C/Nc1cccc(c1)N(O)\\C=C\\C\\C=C\\C=C/C"); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(target); var queryac = sp.ParseSmiles("Nc1ccccc1"); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(queryac); Aromaticity.CDKLegacy.Apply(target); Aromaticity.CDKLegacy.Apply(queryac); Isomorphism smsd1 = new Isomorphism(Algorithm.Default, true); smsd1.Init(queryac, target, true, true); smsd1.SetChemFilters(true, true, true); Assert.AreEqual(7, smsd1.GetFirstAtomMapping().Count); Assert.AreEqual(2, smsd1.GetAllAtomMapping().Count); Assert.IsNotNull(smsd1.GetFirstMapping()); } catch (InvalidSmilesException ex) { Trace.TraceError(ex.Message); } }
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 TestDisconnectedStructureHandling() { var disconnected = CDK.Builder.NewAtomContainer(); var chloride = CDK.Builder.NewAtom("Cl"); chloride.FormalCharge = -1; disconnected.Atoms.Add(chloride); var sodium = CDK.Builder.NewAtom("Na"); sodium.FormalCharge = +1; disconnected.Atoms.Add(sodium); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(disconnected); AddImplicitHydrogens(disconnected); try { var v1 = CreateDescriptor().Calculate(disconnected); } catch (ThreeDRequiredException) { // ignore } }