public void TestRemove_IMolecularFormulaSet_IMolecularFormula_IMolecularFormula() { var formulaMin = new MolecularFormula(); formulaMin.Add(builder.NewIsotope("C"), 1); formulaMin.Add(builder.NewIsotope("H"), 1); formulaMin.Add(builder.NewIsotope("O"), 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 formulaSet = new MolecularFormulaSet { mf1 }; var newMFSet = MolecularFormulaSetManipulator.Remove(formulaSet, formulaMin, formulaMax); Assert.IsNull(newMFSet); }
public override void TestValidate_IMolecularFormula() { var formula = new MolecularFormula(); formula.Add(ifac.GetMajorIsotope("C"), 5); formula.Add(ifac.GetMajorIsotope("H"), 13); formula.Add(ifac.GetMajorIsotope("N"), 2); formula.Add(ifac.GetMajorIsotope("O"), 2); formula.Charge = 0; // experimental results var spectrum = new List <double[]> { new double[] { 133.0977, 100.00 }, new double[] { 134.09475, 0.6 }, new double[] { 134.1010, 5.4 } }; var rule = new IsotopePatternRule(); var parameters = new object[2]; parameters[0] = spectrum; parameters[1] = 0.001; rule.Parameters = parameters; Assert.AreEqual(0.9433, rule.Validate(formula), 0.001); }
public void TestRemove_IMolecularFormulaSet_MolecularFormulaRange() { var formulaRange = new MolecularFormulaRange(); formulaRange.AddIsotope(builder.NewIsotope("C"), 0, 4); formulaRange.AddIsotope(builder.NewIsotope("H"), 0, 12); formulaRange.AddIsotope(builder.NewIsotope("N"), 0, 2); var mf2 = new MolecularFormula(); mf2.Add(builder.NewIsotope("C"), 1); mf2.Add(builder.NewIsotope("H"), 11); mf2.Add(builder.NewIsotope("N"), 1); var mf1 = new MolecularFormula(); mf1.Add(builder.NewIsotope("C"), 3); mf1.Add(builder.NewIsotope("H"), 10); var formulaSet = new MolecularFormulaSet { mf1, mf2 }; var newMFSet = MolecularFormulaSetManipulator.Remove(formulaSet, formulaRange); /* the mf2 is excluded from the limits. It doesn't contain N */ Assert.AreEqual(2, newMFSet.Count()); }
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])); }
public void TestReactionSchemeWithFormula() { var writer = new StringWriter(); var scheme1 = builder.NewReactionScheme(); scheme1.Id = "rs0"; var reaction = builder.NewReaction(); reaction.Id = "r1"; var moleculeA = reaction.Builder.NewAtomContainer(); moleculeA.Id = "A"; var formula = new MolecularFormula(); formula.Add(reaction.Builder.NewIsotope("C"), 10); formula.Add(reaction.Builder.NewIsotope("H"), 15); formula.Add(reaction.Builder.NewIsotope("N"), 2); formula.Add(reaction.Builder.NewIsotope("O"), 1); moleculeA.SetProperty(CDKPropertyName.Formula, formula); var moleculeB = reaction.Builder.NewAtomContainer(); moleculeB.Id = "B"; reaction.Reactants.Add(moleculeA); reaction.Products.Add(moleculeB); scheme1.Add(reaction); var reaction2 = reaction.Builder.NewReaction(); reaction2.Id = "r2"; var moleculeC = reaction.Builder.NewAtomContainer(); moleculeC.Id = "C"; reaction2.Reactants.Add(moleculeB); reaction2.Products.Add(moleculeC); scheme1.Add(reaction2); using (var cmlWriter = new CMLWriter(writer)) { cmlWriter.Write(scheme1); } var cmlContent = writer.ToString(); Debug.WriteLine("****************************** TestReactionCustomization()"); Debug.WriteLine(cmlContent); Debug.WriteLine("******************************"); Assert.IsTrue(cmlContent.IndexOf("<reactionScheme id=\"rs0") != -1); Assert.IsTrue(cmlContent.IndexOf("<reaction id=\"r1") != -1); Assert.IsTrue(cmlContent.IndexOf("<reaction id=\"r2") != -1); Assert.IsTrue(cmlContent.IndexOf("<molecule id=\"A") != -1); Assert.IsTrue(cmlContent.IndexOf("<formula concise=") != -1); Assert.IsTrue(cmlContent.IndexOf("<molecule id=\"B") != -1); Assert.IsTrue(cmlContent.IndexOf("<molecule id=\"C") != -1); }
public void TestDefaultValidTrue() { IRule rule = new MMElementRule(); var formula = new MolecularFormula(); formula.Add(builder.NewIsotope("C"), 2); formula.Add(builder.NewIsotope("H"), 6); Assert.AreEqual(1.0, rule.Validate(formula), 0.0001); }
public void TestDefaultValidFalseSetParam() { IRule rule = new ChargeRule(); var formula = new MolecularFormula(); formula.Add(builder.NewIsotope("C"), 2); formula.Add(builder.NewIsotope("H"), 200); formula.Charge = 1; rule.Parameters = new object[] { -1.0 }; Assert.AreEqual(0.0, rule.Validate(formula), 0.0001); }
public virtual void TestValidate_IMolecularFormula() { var rule = GetRule(); IMolecularFormula mf = new MolecularFormula(); mf.Add(new Isotope("C", 13)); mf.Add(new Isotope("H", 2), 4); rule.Validate(mf); // can it handle an empty MF? rule.Validate(new MolecularFormula()); }
public void TestDefaultValidFalse() { IRule rule = new ToleranceRangeRule(); var formula = new MolecularFormula(); IIsotope carb = builder.NewIsotope("C"); carb.ExactMass = 12.00; IIsotope cl = builder.NewIsotope("Cl"); cl.ExactMass = 34.96885268; formula.Add(carb); formula.Add(cl); Assert.AreEqual(0.0, rule.Validate(formula), 0.0001); }
public void TestDefaultValidFalseSetParam() { IRule rule = new ElementRule(); var formula = new MolecularFormula(); formula.Add(builder.NewIsotope("C"), 2); formula.Add(builder.NewIsotope("H"), 6); MolecularFormulaRange mfRange = new MolecularFormulaRange(); mfRange.AddIsotope(builder.NewIsotope("C"), 1, 2); mfRange.AddIsotope(builder.NewIsotope("H"), 1, 2); rule.Parameters = new object[] { mfRange }; Assert.AreEqual(0.0, rule.Validate(formula), 0.0001); }
public void TestGetMaximalFormula_MolecularFormulaRange_IChemObjectBuilder() { var mf1 = new MolecularFormula(); /* C4H12NO4 */ mf1.Add(builder.NewIsotope("C"), 4); mf1.Add(builder.NewIsotope("H"), 12); mf1.Add(builder.NewIsotope("N"), 1); mf1.Add(builder.NewIsotope("O"), 4); var mf2 = new MolecularFormula(); /* C7H20N4O2 */ mf2.Add(builder.NewIsotope("C"), 7); mf2.Add(builder.NewIsotope("H"), 20); mf2.Add(builder.NewIsotope("N"), 4); mf2.Add(builder.NewIsotope("O"), 2); var mf3 = new MolecularFormula(); /* C9H5O7 */ mf3.Add(builder.NewIsotope("C"), 9); mf3.Add(builder.NewIsotope("H"), 5); mf3.Add(builder.NewIsotope("O"), 7); var mfSet = new MolecularFormulaSet { mf1, mf2, mf3 }; MolecularFormulaRange mfRange = MolecularFormulaRangeManipulator.GetRange(mfSet); IMolecularFormula formula = MolecularFormulaRangeManipulator.GetMaximalFormula(mfRange, builder); /* Result: C4-9H5-20N0-4O2-7 */ Assert.AreEqual(4, mfRange.GetIsotopes().Count()); Assert.AreEqual(formula.GetCount(builder.NewIsotope("C")), mfRange.GetIsotopeCountMax(builder.NewIsotope("C"))); Assert.AreEqual(formula.GetCount(builder.NewIsotope("H")), mfRange.GetIsotopeCountMax(builder.NewIsotope("H"))); Assert.AreEqual(formula.GetCount(builder.NewIsotope("N")), mfRange.GetIsotopeCountMax(builder.NewIsotope("N"))); Assert.AreEqual(formula.GetCount(builder.NewIsotope("O")), mfRange.GetIsotopeCountMax(builder.NewIsotope("O"))); }
public void TestGetRange_IMolecularFormulaSet() { var mf1 = new MolecularFormula(); /* C4H12NO4 */ mf1.Add(builder.NewIsotope("C"), 4); mf1.Add(builder.NewIsotope("H"), 12); mf1.Add(builder.NewIsotope("N"), 1); mf1.Add(builder.NewIsotope("O"), 4); var mf2 = new MolecularFormula(); /* C7H20N4O2 */ mf2.Add(builder.NewIsotope("C"), 7); mf2.Add(builder.NewIsotope("H"), 20); mf2.Add(builder.NewIsotope("N"), 4); mf2.Add(builder.NewIsotope("O"), 2); var mf3 = new MolecularFormula(); /* C9H5O7 */ mf3.Add(builder.NewIsotope("C"), 9); mf3.Add(builder.NewIsotope("H"), 5); mf3.Add(builder.NewIsotope("O"), 7); var mfSet = new MolecularFormulaSet { mf1, mf2, mf3 }; MolecularFormulaRange mfRange = MolecularFormulaRangeManipulator.GetRange(mfSet); /* Result: C4-9H5-20N0-4O2-7 */ Assert.AreEqual(4, mfRange.GetIsotopes().Count()); Assert.AreEqual(4, mfRange.GetIsotopeCountMin(builder.NewIsotope("C"))); Assert.AreEqual(9, mfRange.GetIsotopeCountMax(builder.NewIsotope("C"))); Assert.AreEqual(5, mfRange.GetIsotopeCountMin(builder.NewIsotope("H"))); Assert.AreEqual(20, mfRange.GetIsotopeCountMax(builder.NewIsotope("H"))); Assert.AreEqual(0, mfRange.GetIsotopeCountMin(builder.NewIsotope("N"))); Assert.AreEqual(4, mfRange.GetIsotopeCountMax(builder.NewIsotope("N"))); Assert.AreEqual(2, mfRange.GetIsotopeCountMin(builder.NewIsotope("O"))); Assert.AreEqual(7, mfRange.GetIsotopeCountMax(builder.NewIsotope("O"))); }
public void TestContains_IMolecularFormulaSet_IMolecularFormula() { var mf1 = new MolecularFormula(); mf1.Add(builder.NewIsotope("C"), 4); mf1.Add(builder.NewIsotope("H"), 12); mf1.Add(builder.NewIsotope("N"), 1); mf1.Add(builder.NewIsotope("O"), 4); var mf3 = new MolecularFormula(); mf3.Add(builder.NewIsotope("C"), 9); mf3.Add(builder.NewIsotope("H"), 5); mf3.Add(builder.NewIsotope("O"), 7); var formulaSet = new MolecularFormulaSet { mf1, mf3 }; var mf2 = new MolecularFormula(); mf2.Add(builder.NewIsotope("C"), 4); mf2.Add(builder.NewIsotope("H"), 12); mf2.Add(builder.NewIsotope("N"), 1); mf2.Add(builder.NewIsotope("O"), 4); var mf4 = new MolecularFormula(); mf4.Add(builder.NewIsotope("C"), 4); var hyd = builder.NewIsotope("H"); hyd.ExactMass = 2.0032342; mf4.Add(hyd, 12); mf4.Add(builder.NewIsotope("N"), 1); mf4.Add(builder.NewIsotope("O"), 4); Assert.IsTrue(MolecularFormulaSetManipulator.Contains(formulaSet, mf2)); Assert.IsFalse(MolecularFormulaSetManipulator.Contains(formulaSet, mf4)); }
public void TestDefaultValidFalse_SetParam() { IRule rule = new ToleranceRangeRule(); var formula = new MolecularFormula(); IIsotope carb = builder.NewIsotope("C"); carb.ExactMass = 12.00; IIsotope cl = builder.NewIsotope("Cl"); cl.ExactMass = 34.96885268; formula.Add(carb); formula.Add(cl); object[] parameters = new object[2]; parameters[0] = 46.0; // real -> 46.96885268 parameters[1] = 0.00005; rule.Parameters = parameters; Assert.AreEqual(0.0, rule.Validate(formula), 0.0001); }
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 TestGetMinOccurrenceElements_IMolecularFormulaSet() { var mf1 = new MolecularFormula(); /* C4H12NO4 */ mf1.Add(builder.NewIsotope("C"), 4); mf1.Add(builder.NewIsotope("H"), 12); mf1.Add(builder.NewIsotope("N"), 1); mf1.Add(builder.NewIsotope("O"), 4); var mf2 = new MolecularFormula(); /* C7H20N4O2 */ mf2.Add(builder.NewIsotope("C"), 7); mf2.Add(builder.NewIsotope("H"), 20); mf2.Add(builder.NewIsotope("N"), 4); mf2.Add(builder.NewIsotope("O"), 2); var mf3 = new MolecularFormula(); /* C9H5O7 */ mf3.Add(builder.NewIsotope("C"), 9); mf3.Add(builder.NewIsotope("H"), 5); mf3.Add(builder.NewIsotope("O"), 7); var mfSet = new MolecularFormulaSet { mf1, mf2, mf3 }; var molecularFormula = MolecularFormulaSetManipulator.GetMinOccurrenceElements(mfSet); /* Result: C4H5NO2 */ Assert.AreEqual(12, MolecularFormulaManipulator.GetAtomCount(molecularFormula)); Assert.AreEqual(4, molecularFormula.Isotopes.Count()); Assert.AreEqual(4, molecularFormula.GetCount(builder.NewIsotope("C"))); Assert.AreEqual(5, molecularFormula.GetCount(builder.NewIsotope("H"))); Assert.AreEqual(1, molecularFormula.GetCount(builder.NewIsotope("N"))); Assert.AreEqual(2, molecularFormula.GetCount(builder.NewIsotope("O"))); }
public void TestValidBromine() { var spectrum = new List <double[]> { new double[] { 157.8367, 51.399 }, new double[] { 159.8346, 100.00 }, new double[] { 161.8326, 48.639 } }; var rule = new IsotopePatternRule(); var parameters = new object[2]; parameters[0] = spectrum; parameters[1] = 0.001; rule.Parameters = parameters; var formula = new MolecularFormula(); formula.Add(ifac.GetMajorIsotope("C"), 2); formula.Add(ifac.GetMajorIsotope("Br"), 2); formula.Charge = 0; Assert.AreEqual(0.0, rule.Validate(formula), 0.0001); }