Пример #1
0
        public void TestFixedElementCounts()
        {
            var      ifac = BODRIsotopeFactory.Instance;
            IIsotope c    = ifac.GetMajorIsotope("C");
            IIsotope h    = ifac.GetMajorIsotope("H");
            IIsotope n    = ifac.GetMajorIsotope("N");
            IIsotope o    = ifac.GetMajorIsotope("O");

            MolecularFormulaRange mfRange = new MolecularFormulaRange();

            mfRange.AddIsotope(c, 7, 7);
            mfRange.AddIsotope(h, 15, 15);
            mfRange.AddIsotope(o, 4, 4);
            mfRange.AddIsotope(n, 2, 2);

            double massMin = 10d;
            double massMax = 1000d;
            MolecularFormulaGenerator gen = new MolecularFormulaGenerator(builder, massMin, massMax, mfRange);

            IMolecularFormulaSet mfSet = gen.GetAllFormulas();

            Assert.IsNotNull(mfSet);
            Assert.AreEqual(1, mfSet.Count);
            Assert.AreEqual("C7H15N2O4", MolecularFormulaManipulator.GetString(mfSet[0]));
        }
Пример #2
0
        public void TestFormulaFoundInRange2()
        {
            var      ifac = BODRIsotopeFactory.Instance;
            IIsotope c    = ifac.GetMajorIsotope("C");
            IIsotope h    = ifac.GetMajorIsotope("H");
            IIsotope n    = ifac.GetMajorIsotope("N");
            IIsotope o    = ifac.GetMajorIsotope("O");

            MolecularFormulaRange mfRange = new MolecularFormulaRange();

            mfRange.AddIsotope(c, 1, 50);
            mfRange.AddIsotope(h, 1, 100);
            mfRange.AddIsotope(o, 1, 50);
            mfRange.AddIsotope(n, 1, 50);

            double minMass = 187;
            double maxMass = 189;

            MolecularFormulaGenerator gen   = new MolecularFormulaGenerator(builder, minMass, maxMass, mfRange);
            IMolecularFormulaSet      mfSet = gen.GetAllFormulas();

            Assert.AreEqual(528, mfSet.Count);
            bool found = false;

            foreach (var formula in mfSet)
            {
                string mf = MolecularFormulaManipulator.GetString(formula);
                if (mf.Equals("C11H10NO2"))
                {
                    found = true;
                    break;
                }
            }
            Assert.IsTrue(found, "The molecular formula C11H10NO2 should be found");
        }
Пример #3
0
        public void TestCompoundWith7Elements()
        {
            var      ifac = BODRIsotopeFactory.Instance;
            IIsotope c    = ifac.GetMajorIsotope("C");
            IIsotope h    = ifac.GetMajorIsotope("H");
            IIsotope n    = ifac.GetMajorIsotope("N");
            IIsotope o    = ifac.GetMajorIsotope("O");
            IIsotope s    = ifac.GetMajorIsotope("S");
            IIsotope p    = ifac.GetMajorIsotope("P");
            IIsotope cl   = ifac.GetMajorIsotope("Cl");

            MolecularFormulaRange mfRange = new MolecularFormulaRange();

            mfRange.AddIsotope(c, 7, 9);
            mfRange.AddIsotope(h, 8, 10);
            mfRange.AddIsotope(o, 1, 3);
            mfRange.AddIsotope(n, 0, 2);
            mfRange.AddIsotope(s, 0, 2);
            mfRange.AddIsotope(p, 0, 2);
            mfRange.AddIsotope(cl, 2, 4);

            double minMass = 318.915719 - 0.0001;
            double maxMass = 318.915719 + 0.0001;

            MolecularFormulaGenerator gen   = new MolecularFormulaGenerator(builder, minMass, maxMass, mfRange);
            IMolecularFormulaSet      mfSet = gen.GetAllFormulas();

            Assert.IsNotNull(mfSet);
            Assert.AreEqual(1, mfSet.Count);
            Assert.AreEqual("C8H9Cl3NO2PS", MolecularFormulaManipulator.GetString(mfSet[0]));
        }
Пример #4
0
        public void TestMiddleMass()
        {
            var      ifac = BODRIsotopeFactory.Instance;
            IIsotope c    = ifac.GetMajorIsotope("C");
            IIsotope h    = ifac.GetMajorIsotope("H");
            IIsotope n    = ifac.GetMajorIsotope("N");
            IIsotope o    = ifac.GetMajorIsotope("O");

            MolecularFormulaRange mfRange = new MolecularFormulaRange();

            mfRange.AddIsotope(c, 0, 50);
            mfRange.AddIsotope(h, 0, 100);
            mfRange.AddIsotope(o, 0, 30);
            mfRange.AddIsotope(n, 0, 10);

            double minMass = 698.25879 - 0.0001;
            double maxMass = 698.25879 + 0.0001;

            MolecularFormulaGenerator gen   = new MolecularFormulaGenerator(builder, minMass, maxMass, mfRange);
            IMolecularFormulaSet      mfSet = gen.GetAllFormulas();

            Assert.IsNotNull(mfSet);
            Assert.AreEqual(1, mfSet.Count);
            Assert.AreEqual("C37H38N4O10", MolecularFormulaManipulator.GetString(mfSet[0]));
        }
Пример #5
0
        public void TestHighMass()
        {
            var      ifac = BODRIsotopeFactory.Instance;
            IIsotope c    = ifac.GetMajorIsotope("C");
            IIsotope h    = ifac.GetMajorIsotope("H");
            IIsotope n    = ifac.GetMajorIsotope("N");
            IIsotope o    = ifac.GetMajorIsotope("O");
            IIsotope s    = ifac.GetMajorIsotope("S");

            MolecularFormulaRange mfRange = new MolecularFormulaRange();

            mfRange.AddIsotope(c, 350, 400);
            mfRange.AddIsotope(h, 620, 650);
            mfRange.AddIsotope(o, 100, 150);
            mfRange.AddIsotope(n, 100, 150);
            mfRange.AddIsotope(s, 0, 10);

            double minMass = 8445.573784 - 0.00001;
            double maxMass = 8445.573784 + 0.00001;

            MolecularFormulaGenerator gen   = new MolecularFormulaGenerator(builder, minMass, maxMass, mfRange);
            IMolecularFormulaSet      mfSet = gen.GetAllFormulas();

            Assert.IsNotNull(mfSet);
            Assert.AreEqual(1, mfSet.Count);
            Assert.AreEqual("C374H623N103O116S", MolecularFormulaManipulator.GetString(mfSet[0]));
        }
        public void TestRemove_1()
        {
            var formulaMin = new MolecularFormula();

            formulaMin.Add(builder.NewIsotope("C"), 1);
            formulaMin.Add(builder.NewIsotope("H"), 1);
            formulaMin.Add(builder.NewIsotope("N"), 1);

            var formulaMax = new MolecularFormula();

            formulaMax.Add(builder.NewIsotope("C"), 4);
            formulaMax.Add(builder.NewIsotope("H"), 12);
            formulaMax.Add(builder.NewIsotope("N"), 2);

            var mf1 = new MolecularFormula();

            mf1.Add(builder.NewIsotope("C"), 3);
            mf1.Add(builder.NewIsotope("H"), 10);
            mf1.Add(builder.NewIsotope("N"), 1);

            var mf2 = new MolecularFormula();

            mf2.Add(builder.NewIsotope("C"), 1);
            mf2.Add(builder.NewIsotope("H"), 1);
            mf2.Add(builder.NewIsotope("N"), 1);

            var mf3 = new MolecularFormula();

            mf3.Add(builder.NewIsotope("C"), 4);
            mf3.Add(builder.NewIsotope("H"), 12);
            mf3.Add(builder.NewIsotope("N"), 2);

            var mf4 = new MolecularFormula();

            mf4.Add(builder.NewIsotope("C"), 7);
            mf4.Add(builder.NewIsotope("H"), 10);
            mf4.Add(builder.NewIsotope("N"), 1);

            var formulaSet = new MolecularFormulaSet
            {
                mf1,
                mf2,
                mf3,
                mf4
            };

            var newMFSet = MolecularFormulaSetManipulator.Remove(formulaSet, formulaMin, formulaMax);

            /* the mf4 is excluded from the limits */

            Assert.AreEqual(3, newMFSet.Count());
            Assert.AreEqual(MolecularFormulaManipulator.GetString(mf1),
                            MolecularFormulaManipulator.GetString(newMFSet[0]));
            Assert.AreEqual(MolecularFormulaManipulator.GetString(mf2),
                            MolecularFormulaManipulator.GetString(newMFSet[1]));
            Assert.AreEqual(MolecularFormulaManipulator.GetString(mf3),
                            MolecularFormulaManipulator.GetString(newMFSet[2]));
        }
Пример #7
0
        /// <summary>
        /// Get all combinatorial chemical isotopes given a structure.
        /// </summary>
        /// <param name="molFor">The IMolecularFormula to start</param>
        /// <returns>A IsotopePattern object containing the different combinations</returns>
        public IsotopePattern GetIsotopes(IMolecularFormula molFor)
        {
            if (builder == null)
            {
                try
                {
                    isoFactory = CDK.IsotopeFactory;
                    builder    = molFor.Builder;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.StackTrace);
                }
            }
            var mf = MolecularFormulaManipulator.GetString(molFor, true);

            var molecularFormula = MolecularFormulaManipulator.GetMajorIsotopeMolecularFormula(mf, builder);

            IsotopePattern abundance_Mass = null;

            foreach (var isos in molecularFormula.Isotopes)
            {
                var elementSymbol = isos.Symbol;
                var atomCount     = molecularFormula.GetCount(isos);

                // Generate possible isotope containers for the current atom's
                // these will then me 'multiplied' with the existing patten
                var additional = new List <IsotopeContainer>();
                foreach (var isotope in isoFactory.GetIsotopes(elementSymbol))
                {
                    double mass      = isotope.ExactMass.Value;
                    double abundance = isotope.Abundance.Value;
                    if (abundance <= 0.000000001)
                    {
                        continue;
                    }
                    IsotopeContainer container = new IsotopeContainer(mass, abundance);
                    if (storeFormula)
                    {
                        container.Formula = AsFormula(isotope);
                    }
                    additional.Add(container);
                }
                for (int i = 0; i < atomCount; i++)
                {
                    abundance_Mass = CalculateAbundanceAndMass(abundance_Mass, additional);
                }
            }

            var isoP = IsotopePatternManipulator.SortAndNormalizedByIntensity(abundance_Mass);

            isoP = CleanAbundance(isoP, minIntensity);
            var isoPattern = IsotopePatternManipulator.SortByMass(isoP);

            return(isoPattern);
        }
Пример #8
0
        static void Main(string[] args)
        {
            IAtomContainer    mol1  = Chem.MolFromSmiles("[C:1]([C:5]1[CH:10]=[CH:9][C:8]([OH:11])=[CH:7][CH:6]=1)([CH3:4])([CH3:3])[CH3:2]");
            IMolecularFormula form1 = MolecularFormulaManipulator.GetMolecularFormula(mol1);

            Console.WriteLine(MolecularFormulaManipulator.GetString(form1));
            IAtomContainer mol2  = Chem.MolFromFile("/Users/john/My Documents/1,3-diisopropenylbenzene.mol");
            var            form2 = MolecularFormulaManipulator.GetMolecularFormula(mol2);

            Console.WriteLine(MolecularFormulaManipulator.GetString(form2));
        }
Пример #9
0
        public string MolFormula => GetMolecularFormula(NativeMol);            // get mol formula

        /// <summary>
        /// GetMolecularFormula
        /// </summary>
        /// <param name="mol"></param>
        /// <returns></returns>

        public static string GetMolecularFormula(IAtomContainer mol)
        {
            if (mol == null)
            {
                return("");
            }
            IMolecularFormula moleculeFormula = MolecularFormulaManipulator.GetMolecularFormula(mol);
            String            formula         = MolecularFormulaManipulator.GetString(moleculeFormula);

            return(formula);
        }
Пример #10
0
        public SingleStructureRandomGeneratorTest()
        {
            Console.Out.WriteLine("Instantiating MoleculeListViewer");
            Console.Out.WriteLine("Instantiating SingleStructureRandomGenerator");
            ssrg = new SingleStructureRandomGenerator();
            Console.Out.WriteLine("Assining unbonded set of atoms");
            AtomContainer ac = GetBunchOfUnbondedAtoms();

            mf = MolecularFormulaManipulator.GetString(MolecularFormulaManipulator.GetMolecularFormula(ac));
            Console.Out.WriteLine("Molecular Formula is: " + mf);
            ssrg.SetAtomContainer(ac);
        }
Пример #11
0
        public static void Script8_3()
        {
            var parser = new SmilesParser();
            var hAdder = CDKHydrogenAdder.GetInstance();

            var methanol = parser.ParseSmiles("CO");

            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(methanol);
            hAdder.AddImplicitHydrogens(methanol);
            AtomContainerManipulator.ConvertImplicitToExplicitHydrogens(methanol);

            var dimethoxymethane = parser.ParseSmiles("COC");

            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(dimethoxymethane);
            hAdder.AddImplicitHydrogens(dimethoxymethane);
            AtomContainerManipulator.ConvertImplicitToExplicitHydrogens(dimethoxymethane);

            var water = parser.ParseSmiles("O");

            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(water);
            hAdder.AddImplicitHydrogens(water);
            AtomContainerManipulator.ConvertImplicitToExplicitHydrogens(water);

            var reaction = new Reaction();

            reaction.Reactants.Add(methanol, 2.0D);
            reaction.Products.Add(dimethoxymethane);
            reaction.Products.Add(water);

            Console.WriteLine("Reactants:");

            foreach (var reactant in reaction.Reactants)
            {
                var formula = MolecularFormulaManipulator.GetMolecularFormula(reactant);
                Console.WriteLine(MolecularFormulaManipulator.GetString(formula));
            }

            Console.WriteLine("Products: ");
            foreach (var product in reaction.Products)
            {
                var formula = MolecularFormulaManipulator.GetMolecularFormula(product);
                Console.WriteLine(MolecularFormulaManipulator.GetString(formula));
            }
        }
Пример #12
0
        public void TestCarbons()
        {
            var      ifac = BODRIsotopeFactory.Instance;
            IIsotope c    = ifac.GetMajorIsotope("C");

            MolecularFormulaRange mfRange = new MolecularFormulaRange();

            mfRange.AddIsotope(c, 0, 100000);

            double minMass = 120000.0 - 1;
            double maxMass = 120000.0 + 1;

            MolecularFormulaGenerator gen   = new MolecularFormulaGenerator(builder, minMass, maxMass, mfRange);
            IMolecularFormulaSet      mfSet = gen.GetAllFormulas();

            Assert.IsNotNull(mfSet);
            Assert.AreEqual(1, mfSet.Count);
            Assert.AreEqual("C10000", MolecularFormulaManipulator.GetString(mfSet[0]));
        }
Пример #13
0
        public void TestWater()
        {
            var      ifac = BODRIsotopeFactory.Instance;
            IIsotope c    = ifac.GetMajorIsotope("C");
            IIsotope h    = ifac.GetMajorIsotope("H");
            IIsotope n    = ifac.GetMajorIsotope("N");
            IIsotope o    = ifac.GetMajorIsotope("O");
            IIsotope p    = ifac.GetMajorIsotope("P");
            IIsotope s    = ifac.GetMajorIsotope("S");

            MolecularFormulaRange mfRange = new MolecularFormulaRange();

            mfRange.AddIsotope(c, 0, 10);
            mfRange.AddIsotope(h, 0, 10);
            mfRange.AddIsotope(o, 0, 10);
            mfRange.AddIsotope(n, 0, 10);
            mfRange.AddIsotope(p, 0, 10);
            mfRange.AddIsotope(s, 0, 10);

            double minMass = 1;
            double maxMass = 20;

            MolecularFormulaGenerator gen   = new MolecularFormulaGenerator(builder, minMass, maxMass, mfRange);
            IMolecularFormulaSet      mfSet = gen.GetAllFormulas();

            Assert.IsNotNull(mfSet);

            bool found = false;

            foreach (IMolecularFormula formula in mfSet)
            {
                string mf = MolecularFormulaManipulator.GetString(formula);
                if (mf.Equals("H2O"))
                {
                    found = true;
                    break;
                }
            }
            Assert.IsTrue(found, "The molecular formula H2O should be found");
        }
        public void TestRemove_3()
        {
            var formulaMin = new MolecularFormula();

            formulaMin.Add(builder.NewIsotope("C"), 1);
            formulaMin.Add(builder.NewIsotope("H"), 1);
            formulaMin.Add(builder.NewIsotope("N"), 1);

            var formulaMax = new MolecularFormula();

            formulaMax.Add(builder.NewIsotope("C"), 4);
            formulaMax.Add(builder.NewIsotope("H"), 12);
            formulaMax.Add(builder.NewIsotope("N"), 2);

            var mf1 = new MolecularFormula();

            mf1.Add(builder.NewIsotope("C"), 3);
            mf1.Add(builder.NewIsotope("H"), 10);
            mf1.Add(builder.NewIsotope("N"), 1);

            var mf2 = new MolecularFormula();

            mf2.Add(builder.NewIsotope("C"), 1);
            mf2.Add(builder.NewIsotope("H"), 1);
            mf2.Add(builder.NewIsotope("O"), 1);

            var formulaSet = new MolecularFormulaSet
            {
                mf1,
                mf2
            };

            var newMFSet = MolecularFormulaSetManipulator.Remove(formulaSet, formulaMin, formulaMax);

            /* the mf2 is excluded from the limits. It doesn't contain N */

            Assert.AreEqual(1, newMFSet.Count());
            Assert.AreEqual(MolecularFormulaManipulator.GetString(mf1),
                            MolecularFormulaManipulator.GetString(newMFSet[0]));
        }
        public void TestSelectingMF()
        {
            var is_ = new IsotopePatternSimilarity();

            IsotopePattern spExp = new IsotopePattern(new[]
            {
                new IsotopeContainer(156.07770, 1),
                new IsotopeContainer(157.07503, 0.0101),
                new IsotopeContainer(157.08059, 0.074),
                new IsotopeContainer(158.08135, 0.0024),
            });

            spExp.MonoIsotope = spExp.Isotopes[0];
            spExp.Charge      = 1;

            double score    = 0;
            string mfString = "";

            string[] listMF = { "C4H8N6O", "C2H12N4O4", "C3H12N2O5", "C6H10N3O2", "CH10N5O4", "C4H14NO5" };

            for (int i = 0; i < listMF.Length; i++)
            {
                IMolecularFormula       formula             = MolecularFormulaManipulator.GetMajorIsotopeMolecularFormula(listMF[i], builder);
                IsotopePatternGenerator isotopeGe           = new IsotopePatternGenerator(0.01);
                IsotopePattern          patternIsoPredicted = isotopeGe.GetIsotopes(formula);

                IsotopePattern patternIsoNormalize = IsotopePatternManipulator.Normalize(patternIsoPredicted);
                double         tempScore           = is_.Compare(spExp, patternIsoNormalize);
                if (score < tempScore)
                {
                    mfString = MolecularFormulaManipulator.GetString(formula);
                    score    = tempScore;
                }
            }
            Assert.AreEqual("C6H10N3O2", mfString);
        }
Пример #16
0
        [TestCategory("VerySlowTest")] // structgen is slow... a single method here currently takes ~6 seconds
        public void TestDoCrossover_IAtomContainer()
        {
            IChemObjectSet <IAtomContainer> som;

            var filename = "NCDK.Data.Smiles.c10h16isomers.smi";

            using (var ins = ResourceLoader.GetAsStream(filename))
                using (SMILESReader reader = new SMILESReader(ins))
                {
                    som = reader.Read(CDK.Builder.NewAtomContainerSet());
                    Assert.AreEqual(99, som.Count, "We must have read 99 structures");
                }

            // Comment out next line to enable time seed random.
            RandomNumbersTool.RandomSeed = 0L;

            CrossoverMachine cm             = new CrossoverMachine();
            string           correctFormula = "C10H16";
            int errorcount = 0;

            for (int i = 0; i < som.Count; i++)
            {
                int[] hydrogencount1 = new int[4];
                foreach (var atom in som[i].Atoms)
                {
                    hydrogencount1[atom.ImplicitHydrogenCount.Value]++;
                }
                for (int k = i + 1; k < som.Count; k++)
                {
                    try
                    {
                        var   result         = cm.DoCrossover(som[i], som[k]);
                        int[] hydrogencount2 = new int[4];
                        foreach (var atom in som[k].Atoms)
                        {
                            hydrogencount2[atom.ImplicitHydrogenCount.Value]++;
                        }
                        Assert.AreEqual(2, result.Count, "Result size must be 2");
                        for (int l = 0; l < 2; l++)
                        {
                            IAtomContainer ac = result[l];
                            Assert.IsTrue(ConnectivityChecker.IsConnected(ac), "Result must be connected");
                            Assert.AreEqual(
                                MolecularFormulaManipulator.GetString(MolecularFormulaManipulator.GetMolecularFormula(ac)),
                                correctFormula,
                                "Molecular formula must be the same as" + "of the input");
                            int[] hydrogencountresult = new int[4];
                            int   hcounttotal         = 0;
                            foreach (var atom in result[l].Atoms)
                            {
                                hydrogencountresult[atom.ImplicitHydrogenCount.Value]++;
                                hcounttotal += atom.ImplicitHydrogenCount.Value;
                            }
                            if (hydrogencount1[0] == hydrogencount2[0])
                            {
                                Assert.AreEqual(
                                    hydrogencount1[0], hydrogencountresult[0],
                                    "Hydrogen count of the result must" + " be same as of input");
                            }
                            if (hydrogencount1[1] == hydrogencount2[1])
                            {
                                Assert.AreEqual(
                                    hydrogencount1[1], hydrogencountresult[1],
                                    "Hydrogen count of the result must" + " be same as of input");
                            }
                            if (hydrogencount1[2] == hydrogencount2[2])
                            {
                                Assert.AreEqual(
                                    hydrogencount1[2], hydrogencountresult[2],
                                    "Hydrogen count of the result must" + " be same as of input");
                            }
                            if (hydrogencount1[3] == hydrogencount2[3])
                            {
                                Assert.AreEqual(
                                    hydrogencount1[3], hydrogencountresult[3],
                                    "Hydrogen count of the result must" + " be same as of input");
                            }
                            Assert.AreEqual(16, hcounttotal);
                        }
                    }
                    catch (CDKException)
                    {
                        errorcount++;
                    }
                }
            }
            Assert.IsTrue(errorcount < 300, "We tolerate up to 300 errors");
        }