def test_eq_false(self):
     """Test __eq__ for different Label Instance."""
     data1 = {"C13": 2, "O18": 3, "H02": 2}
     data2 = {"C13": 1, "O18": 3, "H02": 2}
     label1 = ip.Label(data1, self.molecule_info)
     label2 = ip.Label(data2, self.molecule_info)
     self.assertFalse(label1 == label2)
 def test_le(self):
     """Test __le__."""
     label1 = ip.Label({"C13": 2, "H02": 3}, self.molecule_info)
     label2 = ip.Label({"O18": 3, "H02": 1}, self.molecule_info)
     label3 = ip.Label({"O18": 2, "H02": 1}, self.molecule_info)
     self.assertTrue(label1 <= label2)
     self.assertTrue(label1 <= label3)
 def test_result_label_missmatch_with_res_corr(self):
     """Possible result for missmatch with resolution correction."""
     label1 = ip.Label("2N15 4C13", self.molecule_info2)
     label2 = ip.Label("1N15 6C13", self.molecule_info2)
     res_corr_info = rc.ResolutionCorrectionInfo(True, 60000, 200,
                                                 self.molecule_info2)
     res = ic.calc_transition_prob(label1, label2, res_corr_info)
     self.assertAlmostEqual(res, 0.1794381)
 def test_wrong_type(self):
     """Type error with dict as molecule."""
     label1 = ip.Label("1N15", self.molecule_info)
     label2 = ip.Label("2N152C13", self.molecule_info)
     molecule = {"C": 12, "N": 15}
     with self.assertRaises(TypeError):
         ic.calc_transition_prob(label1, label2, molecule,
                                 self.res_corr_info)
 def test_result_label_missmatch_without_res_corr(self):
     """Zero result with no possible transition without res_corr."""
     label1 = ip.Label("2N15 4C13", self.molecule_info2)
     label2 = ip.Label("1N15 6C13", self.molecule_info2)
     res_corr_info = rc.ResolutionCorrectionInfo(False, 60000, 200,
                                                 self.molecule_info2)
     res = ic.calc_transition_prob(label1, label2, res_corr_info)
     self.assertEqual(res, 0)
 def test_result_molecule_formula(self):
     """Result with molecule formula."""
     molecule_info = ip.MoleculeInfo.get_molecule_info(
         molecule_name="Test1",
         molecules_file=self.molecules_file,
         isotopes_file=self.isotopes_file,
     )
     label1 = ip.Label("1N15", molecule_info)
     label2 = ip.Label("2N152C13", molecule_info)
     res = ic.calc_transition_prob(label1, label2, self.res_corr_info)
     self.assertAlmostEqual(res, 0.00042029)
 def test_subtract_result(self):
     """Return correct elements."""
     label1 = ip.Label("1N15 1C13", self.molecule_info)
     label2 = ip.Label("2N15 3C13 1H02", self.molecule_info)
     res_corr = ip.Label(pandas.Series({
         "C13": 2,
         "H02": 1,
         "N15": 1
     }), self.molecule_info)
     res = label2.subtract(label1)
     assert_series_equal(res.as_series, res_corr.as_series)
 def test_result_wrong_label(self):
     """ValueError with impossible label."""
     with self.assertRaises(ValueError):
         ip.calc_correction_factor(
             self.molecule_info,
             label=ip.Label("100C131N15", self.molecule_info),
         )
 def test_subtract_different_molecule(self):
     """Raise ValueError if labels have different molecule_info instances."""
     molecule_info1 = ip.MoleculeInfo.get_molecule_info(
         molecule_name="Test1",
         molecules_file=self.molecules_file,
         isotopes_file=self.isotopes_file,
     )
     molecule_info2 = ip.MoleculeInfo.get_molecule_info(
         molecule_name="Test4",
         molecules_file=self.molecules_file,
         isotopes_file=self.isotopes_file,
     )
     label1 = ip.Label("1N15 1C13", molecule_info1)
     label2 = ip.Label("2N15 3C13 1H02", molecule_info2)
     with self.assertRaises(ValueError):
         label1.subtract(label2)
 def test_result_with_label(self):
     """Result with complex label."""
     res = ip.calc_correction_factor(
         self.molecule_info,
         label=ip.Label("10C13 1N15 12H02", self.molecule_info),
     )
     self.assertAlmostEqual(res, 1.19257588)
 def test_init_result(self):
     """Correct results for list of labels."""
     data = ["C13", "2C13 2H02", "H02"]
     res = ip.LabelTuple(data, self.molecule_info)
     self.assertEqual(len(res), 3)
     self.assertEqual(res[2], ip.Label("2C13 2H02", self.molecule_info))
     self.assertEqual(res.molecule_info, self.molecule_info)
 def test_sort_list(self):
     """Sort_labels gives correct order with list of strings."""
     data = [
         ip.Label(label, self.molecule_info)
         for label in ["4C13", "3C13", "N154C13", "No label"]
     ]
     res_corr = ["No label", "3C13", "4C13", "N154C13"]
     res = ip.sort_labels(data)
     for t, c in zip(res, res_corr):
         self.assertEqual(t.as_string, c)
 def test_init_label_dict(self):
     """Init Label instance with dict as input."""
     data = {"C13": 2, "O18": 3, "H02": 2}
     res = ip.Label(data, self.molecule_info)
     self.assertEqual(res.as_dict, data)
 def test_eq_false_type(self):
     """Test __eq__ for differnt types."""
     data = {"C13": 2, "O18": 3, "H02": 2}
     label = ip.Label(data, self.molecule_info)
     iso = ip.IsotopeInfo(self.isotopes_file)
     self.assertFalse(label == iso)
 def test_label_split_label(self):
     """Parse_label parses composite label correctly."""
     data = "NAD:2N153C13H02"
     res_corr = {"N15": 2, "C13": 3, "H02": 1}
     res = ip.Label(data, self.molecule_info)
     self.assertEqual(res.as_dict, res_corr)
 def test_eq_true(self):
     """Test __eq__ for same Label Instance."""
     data = {"C13": 2, "O18": 3, "H02": 2}
     label1 = ip.Label(data, self.molecule_info)
     label2 = ip.Label(data, self.molecule_info)
     self.assertTrue(label1 == label2)
 def test_init_label_series(self):
     """Init Label instance with pandas Series as input."""
     data = pandas.Series([2, 3, 2], index=["C13", "O18", "H02"])
     res_corr = {"C13": 2, "O18": 3, "H02": 2}
     res = ip.Label(data, self.molecule_info)
     self.assertEqual(res.as_dict, res_corr)
 def test_getitem(self):
     """Get value."""
     data = ["C13", "2C13 2H02", "H02"]
     lt = ip.LabelTuple(data, self.molecule_info)
     self.assertEqual(lt[2], ip.Label("2C13 2H02", self.molecule_info))
 def test_label_bad_split_label(self):
     """Parse_label raises ValueError with bad composite label."""
     data = "NAD:NamPT:2N153C13H02"
     with self.assertRaises(ValueError):
         ip.Label(data, self.molecule_info)
 def test_str_result(self):
     """Return correct string representation."""
     data = "2N153C13H02"
     res = str(ip.Label(data, self.molecule_info))
     res_corr = "Label: 2N153C13H02"
     self.assertEqual(res, res_corr)
 def test_result_simple_diff_label(self):
     """Result with simple one atom diff label."""
     label = ip.Label("1C13", self.molecule_info)
     diff_label = ip.Label("1C13", self.molecule_info)
     res = ip.calc_label_diff_prob(label, diff_label)
     self.assertAlmostEqual(res, 0.1744399)
 def test_result_empty_diff_label(self):
     """Result with empty diff label."""
     label = ip.Label("1C13", self.molecule_info)
     diff_label = ip.Label({}, self.molecule_info)
     res = ip.calc_label_diff_prob(label, diff_label)
     self.assertEqual(res, 0)
 def test_subtract_bad_type(self):
     """Raise TypeError for dict as label."""
     label1 = ip.Label("2O18 3C13 1H02", self.molecule_info)
     label2 = {"N": 1, "C": 2, "H": 1}
     with self.assertRaises(TypeError):
         label1.subtract(label2)
 def test_isotope_to_element_result(self):
     """Return correct elements."""
     label = ip.Label("2N15 3C13 1H02", self.molecule_info)
     res_corr = {"N": 2, "C": 3, "H": 1}
     res = label.isotope_to_element(label)
     self.assertEqual(res, res_corr)
 def test_result_negative_diff_label(self):
     """Result with negative diff label."""
     label = ip.Label("1C13", self.molecule_info)
     diff_label = ip.Label({"C13": -1, "N15": 1}, self.molecule_info)
     res = ip.calc_label_diff_prob(label, diff_label)
     self.assertEqual(res, 0)
 def test_check_isotopes_error(self):
     """ValueError is raised for unknown isotope."""
     with self.assertRaises(ValueError):
         ip.Label("2O15 3C13 1H02", self.molecule_info)
 def test_result_complex_diff_label(self):
     """Result with diff label containing multiple atoms."""
     label = ip.Label("1C13", self.molecule_info)
     diff_label = ip.Label("1C13 1N15", self.molecule_info)
     res = ip.calc_label_diff_prob(label, diff_label)
     self.assertAlmostEqual(res, 0.0043485)
 def test_mass_nolabel(self):
     """Molecule mass calculation without label."""
     label = ip.Label("No label", self.molecule_info)
     res = label.calc_isotopologue_mass()
     self.assertAlmostEqual(res, 664.116947, places=5)
 def test_gt(self):
     """Test __gt__."""
     label1 = ip.Label({"C13": 2, "H02": 3}, self.molecule_info)
     label2 = ip.Label({"O18": 1, "H02": 1}, self.molecule_info)
     self.assertTrue(label1 > label2)
 def test_mass_label(self):
     """Molecule mass calculation with correct label."""
     label = ip.Label("15C13", self.molecule_info)
     res = label.calc_isotopologue_mass()
     self.assertAlmostEqual(res, 679.167270, places=5)