pychemstation 0.8.3__py3-none-any.whl → 0.10.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. pychemstation/analysis/__init__.py +4 -0
  2. pychemstation/analysis/base_spectrum.py +9 -9
  3. pychemstation/analysis/process_report.py +13 -7
  4. pychemstation/analysis/utils.py +1 -3
  5. pychemstation/control/__init__.py +4 -0
  6. pychemstation/control/comm.py +206 -0
  7. pychemstation/control/controllers/__init__.py +6 -0
  8. pychemstation/control/controllers/comm.py +12 -5
  9. pychemstation/control/controllers/devices/column.py +12 -0
  10. pychemstation/control/controllers/devices/dad.py +0 -0
  11. pychemstation/control/controllers/devices/device.py +10 -7
  12. pychemstation/control/controllers/devices/injector.py +18 -84
  13. pychemstation/control/controllers/devices/pump.py +43 -0
  14. pychemstation/control/controllers/method.py +338 -0
  15. pychemstation/control/controllers/sequence.py +190 -0
  16. pychemstation/control/controllers/table_controller.py +266 -0
  17. pychemstation/control/controllers/tables/method.py +35 -13
  18. pychemstation/control/controllers/tables/sequence.py +46 -37
  19. pychemstation/control/controllers/tables/table.py +46 -30
  20. pychemstation/control/hplc.py +27 -11
  21. pychemstation/control/table/__init__.py +3 -0
  22. pychemstation/control/table/method.py +274 -0
  23. pychemstation/control/table/sequence.py +210 -0
  24. pychemstation/control/table/table_controller.py +201 -0
  25. pychemstation/generated/dad_method.py +1 -1
  26. pychemstation/generated/pump_method.py +1 -1
  27. pychemstation/utils/chromatogram.py +2 -5
  28. pychemstation/utils/injector_types.py +1 -1
  29. pychemstation/utils/macro.py +3 -3
  30. pychemstation/utils/method_types.py +2 -2
  31. pychemstation/utils/num_utils.py +65 -0
  32. pychemstation/utils/parsing.py +1 -0
  33. pychemstation/utils/sequence_types.py +3 -3
  34. pychemstation/utils/spec_utils.py +304 -0
  35. {pychemstation-0.8.3.dist-info → pychemstation-0.10.0.dist-info}/METADATA +19 -8
  36. pychemstation-0.10.0.dist-info/RECORD +62 -0
  37. {pychemstation-0.8.3.dist-info → pychemstation-0.10.0.dist-info}/WHEEL +2 -1
  38. pychemstation-0.10.0.dist-info/top_level.txt +2 -0
  39. tests/__init__.py +0 -0
  40. tests/constants.py +134 -0
  41. tests/test_comb.py +136 -0
  42. tests/test_comm.py +65 -0
  43. tests/test_inj.py +39 -0
  44. tests/test_method.py +99 -0
  45. tests/test_nightly.py +80 -0
  46. tests/test_offline_stable.py +69 -0
  47. tests/test_online_stable.py +275 -0
  48. tests/test_proc_rep.py +52 -0
  49. tests/test_runs_stable.py +225 -0
  50. tests/test_sequence.py +125 -0
  51. tests/test_stable.py +276 -0
  52. pychemstation/control/README.md +0 -124
  53. pychemstation/control/controllers/README.md +0 -1
  54. pychemstation-0.8.3.dist-info/RECORD +0 -37
  55. {pychemstation-0.8.3.dist-info → pychemstation-0.10.0.dist-info}/licenses/LICENSE +0 -0
tests/test_comb.py ADDED
@@ -0,0 +1,136 @@
1
+ import os
2
+
3
+ import unittest
4
+
5
+ from pychemstation.control import HPLCController
6
+ from tests.constants import *
7
+
8
+ run_too = True
9
+
10
+
11
+ class TestCombinations(unittest.TestCase):
12
+ def setUp(self):
13
+ path_constants = room(242)
14
+ for path in path_constants:
15
+ if not os.path.exists(path):
16
+ self.fail(
17
+ f"{path} does not exist on your system. If you would like to run tests, please change this path.")
18
+
19
+ self.hplc_controller = HPLCController(comm_dir=path_constants[0],
20
+ method_dir=path_constants[1],
21
+ data_dir=path_constants[2],
22
+ sequence_dir=path_constants[3])
23
+
24
+ def test_run_method_after_update(self):
25
+ try:
26
+ self.hplc_controller.method_controller.switch(DEFAULT_METHOD)
27
+ rand_method = MethodDetails(
28
+ params=HPLCMethodParams(organic_modifier=5,
29
+ flow=0.65),
30
+ timetable=[TimeTableEntry(start_time=3.5,
31
+ organic_modifer=100,
32
+ flow=0.65)],
33
+ name=DEFAULT_METHOD,
34
+ stop_time=10,
35
+ post_time=9)
36
+ self.hplc_controller.edit_method(rand_method, save=True)
37
+ if run_too:
38
+ self.hplc_controller.run_method(experiment_name="changed_method")
39
+ chrom = self.hplc_controller.get_last_run_method_data()
40
+ self.assertEqual(len(chrom.__dict__), 8)
41
+ except Exception as e:
42
+ self.fail(f"Should have not failed: {e}")
43
+
44
+ def test_run_after_table_edit(self):
45
+ try:
46
+ self.hplc_controller.switch_sequence(sequence_name=DEFAULT_SEQUENCE)
47
+ seq_table = self.hplc_controller.load_sequence()
48
+ seq_table.rows.append(SequenceEntry(
49
+ vial_location=TenVialColumn.ONE,
50
+ method=DEFAULT_METHOD,
51
+ num_inj=3,
52
+ inj_vol=4,
53
+ sample_name="Sampel1",
54
+ sample_type=SampleType.SAMPLE,
55
+ ))
56
+ seq_table.rows[0] = SequenceEntry(
57
+ vial_location=TenVialColumn.ONE,
58
+ method=DEFAULT_METHOD,
59
+ num_inj=3,
60
+ inj_vol=4,
61
+ sample_name="Sampel2",
62
+ sample_type=SampleType.SAMPLE)
63
+ self.hplc_controller.edit_sequence(seq_table)
64
+ if run_too:
65
+ self.hplc_controller.run_sequence()
66
+ chrom = self.hplc_controller.get_last_run_sequence_data()
67
+ self.assertTrue(len(chrom) == 2)
68
+ except Exception as e:
69
+ self.fail("Failed")
70
+
71
+ def test_run_after_existing_row_edit(self):
72
+ try:
73
+ self.hplc_controller.switch_sequence(sequence_name=DEFAULT_SEQUENCE)
74
+ seq_table = self.hplc_controller.load_sequence()
75
+ self.hplc_controller.edit_sequence_row(seq_entry, 1)
76
+ if run_too:
77
+ self.hplc_controller.run_sequence()
78
+ chrom = self.hplc_controller.get_last_run_sequence_data()
79
+ self.assertTrue(len(chrom) == 2)
80
+ except Exception:
81
+ self.fail("Failed")
82
+
83
+ def test_update_method_update_seq_table_run(self):
84
+ try:
85
+ self.hplc_controller.method_controller.switch(DEFAULT_METHOD)
86
+ rand_method = MethodDetails(
87
+ name=DEFAULT_METHOD,
88
+ params=HPLCMethodParams(
89
+ organic_modifier=5,
90
+ flow=0.65),
91
+ timetable=[TimeTableEntry(
92
+ start_time=0.50,
93
+ organic_modifer=99,
94
+ flow=0.34)],
95
+ stop_time=10,
96
+ post_time=5)
97
+ self.hplc_controller.edit_method(rand_method, save=True)
98
+
99
+ self.hplc_controller.switch_sequence(sequence_name=DEFAULT_SEQUENCE)
100
+ seq_table = SequenceTable(
101
+ name=DEFAULT_SEQUENCE,
102
+ rows=[SequenceEntry(
103
+ vial_location=8320,
104
+ sample_name="WM-01-001_Cr-Org",
105
+ method=DEFAULT_METHOD,
106
+ inj_source=InjectionSource.HIP_ALS,
107
+ inj_vol=2,
108
+ num_inj=1,
109
+ sample_type=SampleType.SAMPLE
110
+ ), SequenceEntry(
111
+ vial_location=8448,
112
+ sample_name="WM-01-001_Cr-Aq",
113
+ method=DEFAULT_METHOD,
114
+ inj_source=InjectionSource.HIP_ALS,
115
+ inj_vol=2,
116
+ num_inj=1,
117
+ sample_type=SampleType.SAMPLE)])
118
+
119
+ self.hplc_controller.edit_sequence(seq_table)
120
+ if run_too:
121
+ self.hplc_controller.preprun()
122
+ self.hplc_controller.run_sequence()
123
+ chrom = self.hplc_controller.get_last_run_sequence_data()
124
+ self.assertTrue(len(chrom) == 2)
125
+ except Exception:
126
+ self.fail("Failed")
127
+
128
+ def test_run_sequence(self):
129
+ try:
130
+ self.hplc_controller.switch_sequence(sequence_name=DEFAULT_SEQUENCE)
131
+ self.hplc_controller.preprun()
132
+ self.hplc_controller.run_sequence()
133
+ chrom = self.hplc_controller.get_last_run_sequence_data()
134
+ self.assertTrue(len(chrom) == 1)
135
+ except Exception:
136
+ self.fail("Failed")
tests/test_comm.py ADDED
@@ -0,0 +1,65 @@
1
+ import os
2
+
3
+ import unittest
4
+
5
+ from pychemstation.control import HPLCController
6
+ from pychemstation.utils.macro import *
7
+ from tests.constants import *
8
+
9
+
10
+ class TestComm(unittest.TestCase):
11
+
12
+ def setUp(self):
13
+ path_constants = room(242)
14
+ for path in path_constants:
15
+ if not os.path.exists(path):
16
+ self.fail(
17
+ f"{path} does not exist on your system. If you would like to run tests, please change this path.")
18
+
19
+ self.hplc_controller = HPLCController(comm_dir=path_constants[0],
20
+ method_dir=path_constants[1],
21
+ data_dir=path_constants[2],
22
+ sequence_dir=path_constants[3])
23
+
24
+ def test_status_check_standby(self):
25
+ self.hplc_controller.standby()
26
+ self.assertTrue(self.hplc_controller.status() in [HPLCAvailStatus.STANDBY, HPLCRunningStatus.NOTREADY])
27
+
28
+ def test_status_check_preprun(self):
29
+ self.hplc_controller.preprun()
30
+ self.assertTrue(self.hplc_controller.status() in [HPLCAvailStatus.PRERUN, HPLCAvailStatus.STANDBY,
31
+ HPLCRunningStatus.NOTREADY])
32
+
33
+ def test_send_command(self):
34
+ try:
35
+ self.hplc_controller.send(Command.GET_METHOD_CMD)
36
+ except Exception as e:
37
+ self.fail(f"Should not throw error: {e}")
38
+
39
+ def test_send_str(self):
40
+ try:
41
+ self.hplc_controller.send("Local TestNum")
42
+ self.hplc_controller.send("TestNum = 0")
43
+ self.hplc_controller.send("Print TestNum")
44
+ self.hplc_controller.send("response_num = TestNum")
45
+ self.hplc_controller.send("Print response_num")
46
+ except Exception as e:
47
+ self.fail(f"Should not throw error: {e}")
48
+
49
+ def test_get_num(self):
50
+ try:
51
+ self.hplc_controller.send("response_num = 10")
52
+ res = self.hplc_controller.receive().num_response
53
+ self.assertEqual(res, 10)
54
+ except Exception as e:
55
+ self.fail(f"Should not throw error: {e}")
56
+
57
+ def test_get_response(self):
58
+ try:
59
+ self.hplc_controller.switch_method(method_name=DEFAULT_METHOD)
60
+ self.hplc_controller.send(Command.GET_METHOD_CMD)
61
+ res = self.hplc_controller.receive()
62
+ self.assertTrue(DEFAULT_METHOD in res.string_response)
63
+ except Exception as e:
64
+ self.fail(f"Should not throw error: {e}")
65
+
tests/test_inj.py ADDED
@@ -0,0 +1,39 @@
1
+ import os
2
+ import unittest
3
+
4
+ from pychemstation.control import HPLCController
5
+ from pychemstation.utils.tray_types import FiftyFourVialPlate, Letter, Plate, Num
6
+ from tests.constants import *
7
+
8
+ offline = True
9
+
10
+
11
+ class TestInj(unittest.TestCase):
12
+ def setUp(self):
13
+ path_constants = room(254)
14
+ for path in path_constants:
15
+ if not offline and not os.path.exists(path):
16
+ self.fail(
17
+ f"{path} does not exist on your system. If you would like to run tests, please change this path.")
18
+
19
+ self.hplc_controller = HPLCController(offline=offline,
20
+ comm_dir=path_constants[0],
21
+ method_dir=path_constants[1],
22
+ data_dir=path_constants[2],
23
+ sequence_dir=path_constants[3])
24
+ if not offline:
25
+ self.hplc_controller.switch_method(DEFAULT_METHOD)
26
+
27
+ def test_load_inj(self):
28
+ try:
29
+ inj_table = self.hplc_controller.load_injector_program()
30
+ self.assertTrue(len(inj_table.functions) == 2)
31
+ except Exception as e:
32
+ self.fail(f"Should have not failed, {e}")
33
+
34
+ def test_plate_number(self):
35
+ self.assertEqual(4096, FiftyFourVialPlate(plate=Plate.ONE, letter=Letter.A, num=Num.FOUR).value())
36
+
37
+
38
+ if __name__ == '__main__':
39
+ unittest.main()
tests/test_method.py ADDED
@@ -0,0 +1,99 @@
1
+ import os
2
+ import unittest
3
+
4
+ from pychemstation.control import HPLCController
5
+ from tests.constants import *
6
+
7
+
8
+ class TestMethod(unittest.TestCase):
9
+ def setUp(self):
10
+ path_constants = room(254)
11
+ for path in path_constants:
12
+ if not os.path.exists(path):
13
+ self.fail(
14
+ f"{path} does not exist on your system. If you would like to run tests, please change this path.")
15
+
16
+ self.hplc_controller = HPLCController(comm_dir=path_constants[0],
17
+ method_dir=path_constants[1],
18
+ data_dir=path_constants[2],
19
+ sequence_dir=path_constants[3])
20
+
21
+ def test_load_method_from_disk(self):
22
+ self.hplc_controller.switch_method(DEFAULT_METHOD)
23
+ try:
24
+ gp_mtd = self.hplc_controller.method_controller.load_from_disk(DEFAULT_METHOD)
25
+ self.assertTrue(gp_mtd.first_row.organic_modifier == 5)
26
+ except Exception as e:
27
+ self.fail(f"Should have not failed, {e}")
28
+
29
+ def test_edit_method(self):
30
+ self.hplc_controller.method_controller.switch(DEFAULT_METHOD)
31
+ new_method = MethodDetails(name=DEFAULT_METHOD,
32
+ timetable=[TimeTableEntry(start_time=1,
33
+ organic_modifer=20,
34
+ flow=0.65),
35
+ TimeTableEntry(start_time=2,
36
+ organic_modifer=30,
37
+ flow=0.65),
38
+ TimeTableEntry(start_time=2.5,
39
+ organic_modifer=60,
40
+ flow=0.65),
41
+ TimeTableEntry(start_time=3,
42
+ organic_modifer=80,
43
+ flow=0.65),
44
+ TimeTableEntry(start_time=3.5,
45
+ organic_modifer=100,
46
+ flow=0.65)],
47
+ stop_time=4,
48
+ post_time=1,
49
+ params=HPLCMethodParams(organic_modifier=5, flow=0.65))
50
+ try:
51
+ self.hplc_controller.edit_method(new_method)
52
+ except Exception as e:
53
+ self.fail(f"Should have not failed: {e}")
54
+
55
+ def test_load_method(self):
56
+ self.hplc_controller.method_controller.switch(DEFAULT_METHOD)
57
+ new_method = gen_rand_method()
58
+ try:
59
+ self.hplc_controller.edit_method(new_method)
60
+ loaded_method = self.hplc_controller.load_method()
61
+ self.assertEqual(new_method.params.organic_modifier,
62
+ loaded_method.params.organic_modifier)
63
+ self.assertEqual(new_method.timetable[0].organic_modifer,
64
+ loaded_method.timetable[0].organic_modifer)
65
+ self.assertEqual(round(new_method.params.flow, 2),
66
+ round(loaded_method.params.flow, 2))
67
+ except Exception as e:
68
+ self.fail(f"Should have not failed: {e}")
69
+
70
+ def test_run_method(self):
71
+ try:
72
+ self.hplc_controller.run_method(experiment_name="test_experiment")
73
+ chrom = self.hplc_controller.get_last_run_method_data()
74
+ except Exception as e:
75
+ self.fail(f"Should have not failed: {e}")
76
+
77
+ def test_run_10_times(self):
78
+ self.hplc_controller.method_controller.switch(DEFAULT_METHOD)
79
+ rand_method = MethodDetails(
80
+ name=DEFAULT_METHOD,
81
+ params=HPLCMethodParams(
82
+ organic_modifier=5,
83
+ flow=0.65),
84
+ timetable=[TimeTableEntry(
85
+ start_time=0.50,
86
+ organic_modifer=99,
87
+ flow=0.65)],
88
+ stop_time=1,
89
+ post_time=0)
90
+ self.hplc_controller.edit_method(rand_method, save=True)
91
+ try:
92
+ for _ in range(10):
93
+ self.hplc_controller.run_method(experiment_name="limiting_testing")
94
+ except Exception as e:
95
+ self.fail(f"Should have not failed: {e}")
96
+
97
+
98
+ if __name__ == '__main__':
99
+ unittest.main()
tests/test_nightly.py ADDED
@@ -0,0 +1,80 @@
1
+ import unittest
2
+
3
+ from pluggy import Result
4
+
5
+ from pychemstation.analysis.process_report import process_csv_report
6
+ from pychemstation.utils.tray_types import FiftyFourVialPlate, Letter, Plate, Num
7
+ from tests.constants import *
8
+
9
+ offline = True
10
+
11
+
12
+ class TestNightly(unittest.TestCase):
13
+ def setUp(self):
14
+ path_constants = room(254)
15
+ for path in path_constants:
16
+ if not offline and not os.path.exists(path):
17
+ self.fail(
18
+ f"{path} does not exist on your system. If you would like to run tests, please change this path.")
19
+
20
+ self.hplc_controller = HPLCController(offline=offline,
21
+ comm_dir=path_constants[0],
22
+ method_dir=path_constants[1],
23
+ data_dir=path_constants[2],
24
+ sequence_dir=path_constants[3])
25
+ if not offline:
26
+ self.hplc_controller.switch_method(DEFAULT_METHOD)
27
+
28
+ def test_load_inj(self):
29
+ try:
30
+ inj_table = self.hplc_controller.load_injector_program()
31
+ self.assertTrue(len(inj_table.functions) == 2)
32
+ except Exception as e:
33
+ self.fail(f"Should have not failed, {e}")
34
+
35
+ def test_plate_number(self):
36
+ self.assertEqual(4096, FiftyFourVialPlate(plate=Plate.ONE, letter=Letter.A, num=Num.FOUR).value())
37
+
38
+ def test_build_peak_regex(self):
39
+ try:
40
+ # TODO
41
+ print('yes')
42
+ except Exception as e:
43
+ self.fail(f"Should have not failed, {e}")
44
+
45
+ def test_parse_area_report(self):
46
+ try:
47
+ # TODO
48
+ print('yes')
49
+ except Exception as e:
50
+ self.fail(f"Should have not failed, {e}")
51
+
52
+ def test_process_export_report(self):
53
+ try:
54
+ import pandas as pd
55
+
56
+ file_path = "/Users/lucyhao/Codes/pychemstation/tests/0_2025-03-15 19-14-35.D/Report00.CSV"
57
+ df = pd.read_csv(file_path, encoding="utf-16")
58
+
59
+ # Print the first column
60
+ print(df)
61
+ except Exception as e:
62
+ self.fail(f"Should have not failed, {e}")
63
+
64
+ def test_process_folder(self):
65
+ try:
66
+ # TODO
67
+ print('yes')
68
+ except Exception as e:
69
+ self.fail(f"Should have not failed, {e}")
70
+
71
+ def test_report_csv(self):
72
+ try:
73
+ report: Result = process_csv_report(folder_path="0_2025-03-15 19-14-35.D")
74
+ print(report)
75
+ except Exception as e:
76
+ self.fail(f"Should have not failed: {e}")
77
+
78
+
79
+ if __name__ == '__main__':
80
+ unittest.main()
@@ -0,0 +1,69 @@
1
+ import unittest
2
+
3
+ from pychemstation.analysis.process_report import ReportType
4
+ from pychemstation.utils.sequence_types import SequenceDataFiles
5
+ from pychemstation.utils.tray_types import FiftyFourVialPlate
6
+ from tests.constants import DEFAULT_SEQUENCE, VIAL_PLATES, clean_up, set_up_utils
7
+
8
+
9
+ class TestStable(unittest.TestCase):
10
+ """
11
+ These tests should always work, while the controller is offline or online.
12
+ """
13
+
14
+ def setUp(self):
15
+ self.hplc_controller = set_up_utils(242, offline=True)
16
+
17
+ def tearDown(self):
18
+ clean_up(self.hplc_controller)
19
+
20
+ def test_tray_nums_only(self):
21
+ for i in range(len(VIAL_PLATES)):
22
+ self.assertEqual(VIAL_PLATES[i], FiftyFourVialPlate.from_int(VIAL_PLATES[i].value()))
23
+
24
+ def test_get_last_run_sequence(self):
25
+ path = "hplc_testing 2025-03-27 17-13-47"
26
+ self.hplc_controller.sequence_controller.data_files.append(SequenceDataFiles(dir=path,
27
+ sequence_name=DEFAULT_SEQUENCE))
28
+ try:
29
+ most_recent_folder = self.hplc_controller.sequence_controller.data_files[-1]
30
+ check_folder = self.hplc_controller.sequence_controller.fuzzy_match_most_recent_folder(
31
+ most_recent_folder=most_recent_folder)
32
+ self.assertEqual(check_folder.ok_value.dir, path)
33
+ self.hplc_controller.sequence_controller.data_files[-1].dir = check_folder.ok_value
34
+ chrom = self.hplc_controller.get_last_run_sequence_data()
35
+ self.assertTrue(chrom)
36
+ except Exception:
37
+ self.fail()
38
+
39
+ def test_plate_number(self):
40
+ self.assertEqual(FiftyFourVialPlate.from_str("P1-A1").value(), 4096)
41
+ self.assertEqual(FiftyFourVialPlate.from_str("P1-A4").value(), 4099)
42
+
43
+ def test_get_method_report(self):
44
+ method_path = "0_2025-03-15 19-14-35.D"
45
+ report = self.hplc_controller.get_last_run_method_report(custom_path=method_path, report_type=ReportType.CSV)
46
+ self.assertEqual(report.vial_location, FiftyFourVialPlate.from_int(4096))
47
+
48
+ def test_get_seq_report(self):
49
+ seq_path = "hplc_testing 2025-03-27 17-13-47"
50
+ report = self.hplc_controller.get_last_run_sequence_reports(custom_path=seq_path, report_type=ReportType.TXT)
51
+ self.assertEqual(len(report[0].signals[0].peaks), 12)
52
+
53
+ def test_get_method_uv(self):
54
+ method_path = "0_2025-03-15 19-14-35.D"
55
+ try:
56
+ uv_data = self.hplc_controller.get_last_run_method_data(custom_path=method_path, read_uv=True)
57
+ except Exception:
58
+ pass
59
+
60
+ def test_get_seq_uv(self):
61
+ seq_path = "hplc_testing 2025-03-27 17-13-47"
62
+ try:
63
+ uv_datas = self.hplc_controller.get_last_run_sequence_data(custom_path=seq_path, read_uv=True)
64
+ except Exception:
65
+ pass
66
+
67
+
68
+ if __name__ == '__main__':
69
+ unittest.main()