pychemstation 0.5.7.dev1__py3-none-any.whl → 0.5.8__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.
@@ -49,6 +49,15 @@ class SequenceController(TableController):
49
49
  inj_source=inj_source,
50
50
  sample_type=sample_type, )
51
51
 
52
+ def check(self) -> str:
53
+ time.sleep(2)
54
+ self.send(Command.GET_SEQUENCE_CMD)
55
+ time.sleep(2)
56
+ res = self.receive()
57
+ if res.is_ok():
58
+ return res.ok_value.string_response
59
+ return "ERROR"
60
+
52
61
  def switch(self, seq_name: str):
53
62
  """
54
63
  Switch to the specified sequence. The sequence name does not need the '.S' extension.
@@ -197,7 +206,7 @@ class SequenceController(TableController):
197
206
  else:
198
207
  self.data_files[-1].dir = self.fuzzy_match_most_recent_folder(folder_name).ok_value
199
208
 
200
- def retrieve_recent_data_files(self):
209
+ def retrieve_recent_data_files(self) -> str:
201
210
  sequence_data_files: SequenceDataFiles = self.data_files[-1]
202
211
  return sequence_data_files.dir
203
212
 
@@ -19,12 +19,14 @@ from ...utils.sequence_types import SequenceDataFiles, SequenceTable
19
19
  from ...utils.table_types import Table, TableOperation, RegisterFlag
20
20
 
21
21
 
22
+ TableType = Union[MethodTimetable, SequenceTable]
23
+
22
24
  class TableController(abc.ABC):
23
25
 
24
26
  def __init__(self, controller: CommunicationController, src: str, data_dir: str, table: Table):
25
27
  self.controller = controller
26
28
  self.table = table
27
- self.table_state : Optional[TableController] = None
29
+ self.table_state : Optional[TableType] = None
28
30
 
29
31
  if os.path.isdir(src):
30
32
  self.src: str = src
@@ -154,6 +156,7 @@ class TableController(abc.ABC):
154
156
  Checks if ChemStation has finished running and can read data back
155
157
 
156
158
  :param method: if you are running a method and want to read back data, the timeout period will be adjusted to be longer than the method's runtime
159
+ :param sequence: if you are running a sequence and want to read back data, the timeout period will be adjusted to be longer than the sequence's runtime
157
160
  :return: Return True if data can be read back, else False.
158
161
  """
159
162
  timeout = 10 * 60
@@ -7,7 +7,7 @@ Authors: Lucy Hao
7
7
  from typing import Union, Optional
8
8
 
9
9
  from ..control.controllers import MethodController, SequenceController, CommunicationController
10
- from ..utils.chromatogram import AgilentHPLCChromatogram, AgilentChannelChromatogramData
10
+ from ..utils.chromatogram import AgilentChannelChromatogramData
11
11
  from ..utils.macro import Command, HPLCRunningStatus, HPLCAvailStatus, HPLCErrorStatus, Response
12
12
  from ..utils.method_types import MethodTimetable
13
13
  from ..utils.sequence_types import SequenceTable, SequenceEntry
@@ -30,14 +30,15 @@ class HPLCController:
30
30
  comm_dir: str,
31
31
  data_dir: str,
32
32
  method_dir: str,
33
- sequence_dir: str):
33
+ sequence_dir: str,
34
+ offline: bool = False):
34
35
  """Initialize HPLC controller. The `hplc_talk.mac` macro file must be loaded in the Chemstation software.
35
36
  `comm_dir` must match the file path in the macro file.
36
37
 
37
38
  :param comm_dir: Name of directory for communication, where ChemStation will read and write from. Can be any existing directory.
38
39
  :raises FileNotFoundError: If either `data_dir`, `method_dir` or `comm_dir` is not a valid directory.
39
40
  """
40
- self.comm = CommunicationController(comm_dir=comm_dir)
41
+ self.comm = CommunicationController(comm_dir=comm_dir) if not offline else None
41
42
  self.method_controller = MethodController(controller=self.comm,
42
43
  src=method_dir,
43
44
  data_dir=data_dir,
@@ -49,12 +50,18 @@ class HPLCController:
49
50
  method_dir=method_dir)
50
51
 
51
52
  def send(self, cmd: Union[Command, str]):
53
+ if not self.comm:
54
+ raise RuntimeError("Communication controller must be initialized before sending command. It is currently in offline mode.")
52
55
  self.comm.send(cmd)
53
56
 
54
57
  def receive(self) -> Response:
58
+ if not self.comm:
59
+ raise RuntimeError("Communication controller must be initialized before sending command. It is currently in offline mode.")
55
60
  return self.comm.receive().value
56
61
 
57
62
  def status(self) -> Union[HPLCRunningStatus | HPLCAvailStatus | HPLCErrorStatus]:
63
+ if not self.comm:
64
+ raise RuntimeError("Communication controller must be initialized before sending command. It is currently in offline mode.")
58
65
  return self.comm.get_status()
59
66
 
60
67
  def switch_method(self, method_name: str):
@@ -67,6 +74,8 @@ class HPLCController:
67
74
  :raises IndexError: Response did not have expected format. Try again.
68
75
  :raises AssertionError: The desired method is not selected. Try again.
69
76
  """
77
+ if not self.comm:
78
+ raise RuntimeError("Communication controller must be initialized before sending command. It is currently in offline mode.")
70
79
  self.method_controller.switch(method_name)
71
80
 
72
81
  def switch_sequence(self, sequence_name: str):
@@ -76,9 +85,11 @@ class HPLCController:
76
85
 
77
86
  :param sequence_name: The name of the sequence file
78
87
  """
88
+ if not self.comm:
89
+ raise RuntimeError("Communication controller must be initialized before sending command. It is currently in offline mode.")
79
90
  self.sequence_controller.switch(sequence_name)
80
91
 
81
- def run_method(self, experiment_name: str):
92
+ def run_method(self, experiment_name: str, stall_while_running: bool = True):
82
93
  """
83
94
  This is the preferred method to trigger a run.
84
95
  Starts the currently selected method, storing data
@@ -87,18 +98,23 @@ class HPLCController:
87
98
  Device must be ready.
88
99
 
89
100
  :param experiment_name: Name of the experiment
101
+ :param stall_while_running: whether this method should return or stall while HPLC runs.
90
102
  """
91
- self.method_controller.run(experiment_name)
103
+ if not self.comm:
104
+ raise RuntimeError("Communication controller must be initialized before sending command. It is currently in offline mode.")
105
+ self.method_controller.run(experiment_name, stall_while_running)
92
106
 
93
- def run_sequence(self):
107
+ def run_sequence(self, stall_while_running: bool = True):
94
108
  """
95
109
  Starts the currently loaded sequence, storing data
96
110
  under the <data_dir>/<sequence table name> folder.
97
111
  Device must be ready.
98
112
 
99
- :param sequence_name:
113
+ :param stall_while_running: whether this method should return or stall while HPLC runs.
100
114
  """
101
- self.sequence_controller.run()
115
+ if not self.comm:
116
+ raise RuntimeError("Communication controller must be initialized before sending command. It is currently in offline mode.")
117
+ self.sequence_controller.run(stall_while_running=stall_while_running)
102
118
 
103
119
  def edit_method(self, updated_method: MethodTimetable, save: bool = False):
104
120
  """Updated the currently loaded method in ChemStation with provided values.
@@ -106,6 +122,8 @@ class HPLCController:
106
122
  :param updated_method: the method with updated values, to be sent to Chemstation to modify the currently loaded method.
107
123
  :param save:
108
124
  """
125
+ if not self.comm:
126
+ raise RuntimeError("Communication controller must be initialized before sending command. It is currently in offline mode.")
109
127
  self.method_controller.edit(updated_method, save)
110
128
 
111
129
  def edit_sequence(self, updated_sequence: SequenceTable):
@@ -115,6 +133,8 @@ class HPLCController:
115
133
 
116
134
  :param updated_sequence:
117
135
  """
136
+ if not self.comm:
137
+ raise RuntimeError("Communication controller must be initialized before sending command. It is currently in offline mode.")
118
138
  self.sequence_controller.edit(updated_sequence)
119
139
 
120
140
  def edit_sequence_row(self, row: SequenceEntry, num: int):
@@ -124,55 +144,86 @@ class HPLCController:
124
144
  :param row: sequence row entry with updated information
125
145
  :param row_num: the row to edit, based on -1-based indexing
126
146
  """
147
+ if not self.comm:
148
+ raise RuntimeError("Communication controller must be initialized before sending command. It is currently in offline mode.")
127
149
  self.sequence_controller.edit_row(row, num)
128
150
 
129
- def get_last_run_method_data(self) -> AgilentChannelChromatogramData:
151
+ def get_last_run_method_data(self, data: Optional[str] = None) -> AgilentChannelChromatogramData:
130
152
  """
131
153
  Returns the last run method data.
132
154
  """
133
- return self.method_controller.get_data()
155
+ return self.method_controller.get_data(custom_path=data)
134
156
 
135
- def get_last_run_sequence_data(self) -> list[AgilentChannelChromatogramData]:
157
+ def get_last_run_sequence_data(self, data: Optional[str] = None) -> list[AgilentChannelChromatogramData]:
136
158
  """
137
159
  Returns data for all rows in the last run sequence data.
138
160
  """
139
- return self.sequence_controller.get_data()
161
+ return self.sequence_controller.get_data(custom_path=data)
162
+
163
+ def check_loaded_sequence(self) -> str:
164
+ """
165
+ Returns the name of the currently loaded sequence.
166
+ """
167
+ if not self.comm:
168
+ raise RuntimeError("Communication controller must be initialized before sending command. It is currently in offline mode.")
169
+ return self.sequence_controller.check()
140
170
 
141
171
  def check_loaded_method(self) -> str:
142
- return self.method_controller.check_loaded_method()
172
+ """
173
+ Returns the name of the currently loaded method.
174
+ """
175
+ if not self.comm:
176
+ raise RuntimeError("Communication controller must be initialized before sending command. It is currently in offline mode.")
177
+ return self.method_controller.check()
143
178
 
144
179
  def load_method(self) -> MethodTimetable:
145
180
  """
146
- Returns the currently loaded method, including its timetable.
181
+ Returns all details of the currently loaded method, including its timetable.
147
182
  """
183
+ if not self.comm:
184
+ raise RuntimeError("Communication controller must be initialized before sending command. It is currently in offline mode.")
148
185
  return self.method_controller.load()
149
186
 
150
187
  def load_sequence(self) -> SequenceTable:
151
188
  """
152
189
  Returns the currently loaded sequence.
153
190
  """
191
+ if not self.comm:
192
+ raise RuntimeError("Communication controller must be initialized before sending command. It is currently in offline mode.")
154
193
  return self.sequence_controller.load()
155
194
 
156
195
  def standby(self):
157
196
  """Switches all modules in standby mode. All lamps and pumps are switched off."""
197
+ if not self.comm:
198
+ raise RuntimeError("Communication controller must be initialized before sending command. It is currently in offline mode.")
158
199
  self.send(Command.STANDBY_CMD)
159
200
 
160
201
  def preprun(self):
161
202
  """ Prepares all modules for run. All lamps and pumps are switched on."""
203
+ if not self.comm:
204
+ raise RuntimeError("Communication controller must be initialized before sending command. It is currently in offline mode.")
162
205
  self.send(Command.PREPRUN_CMD)
163
206
 
164
207
  def lamp_on(self):
165
208
  """Turns the UV lamp on."""
209
+ if not self.comm:
210
+ raise RuntimeError("Communication controller must be initialized before sending command. It is currently in offline mode.")
166
211
  self.send(Command.LAMP_ON_CMD)
167
212
 
168
213
  def lamp_off(self):
169
214
  """Turns the UV lamp off."""
215
+ if not self.comm:
216
+ raise RuntimeError("Communication controller must be initialized before sending command. It is currently in offline mode.")
170
217
  self.send(Command.LAMP_OFF_CMD)
171
218
 
172
219
  def pump_on(self):
173
220
  """Turns on the pump on."""
221
+ if not self.comm:
222
+ raise RuntimeError("Communication controller must be initialized before sending command. It is currently in offline mode.")
174
223
  self.send(Command.PUMP_ON_CMD)
175
224
 
176
225
  def pump_off(self):
177
226
  """Turns the pump off."""
227
+ if not self.comm:
228
+ raise RuntimeError("Communication controller must be initialized before sending command. It is currently in offline mode.")
178
229
  self.send(Command.PUMP_OFF_CMD)
@@ -86,3 +86,6 @@ def str_to_status(status: str) -> Union[HPLCAvailStatus, HPLCErrorStatus, HPLCRu
86
86
  if HPLCAvailStatus.has_member_key(status):
87
87
  return HPLCAvailStatus[status]
88
88
  raise KeyError(status)
89
+
90
+
91
+ Status = Union[HPLCRunningStatus, HPLCAvailStatus, HPLCErrorStatus]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pychemstation
3
- Version: 0.5.7.dev1
3
+ Version: 0.5.8
4
4
  Summary: Library to interact with Chemstation software, primarily used in Hein lab
5
5
  Home-page: https://gitlab.com/heingroup/device-api/pychemstation
6
6
  Author: Lucy Hao
@@ -1,16 +1,16 @@
1
1
  pychemstation/__init__.py,sha256=SpTl-Tg1B1HTyjNOE-8ue-N2wGnXN_2zl7RFUSxlkiM,33
2
2
  pychemstation/analysis/__init__.py,sha256=EWoU47iyn9xGS-b44zK9eq50bSjOV4AC5dvt420YMI4,44
3
- pychemstation/analysis/base_spectrum.py,sha256=FBvwzLtF9mdqW7f8ETY9G4cpfJ-SzbiSkZq9EtXcSXo,17045
4
- pychemstation/analysis/spec_utils.py,sha256=8NZMV0dtfxZLARjWzM5ks0tgEYQv_SKUiZzba2IoKgw,10505
3
+ pychemstation/analysis/base_spectrum.py,sha256=XPf9eJ72uz0CnxCY5uFOyu1MbVX-OTTXeN1tLzIMok4,16536
4
+ pychemstation/analysis/spec_utils.py,sha256=UOo9hJR3evJfmaohEEsyb7aq6X996ofuUfu-GKjiDi8,10201
5
5
  pychemstation/analysis/utils.py,sha256=ISupAOb_yqA4_DZRK9v18UL-XjUQccAicIJKb1VMnGg,2055
6
6
  pychemstation/control/__init__.py,sha256=4xTy8X-mkn_PPZKr7w9rnj1wZhtmTesbQptPhpYmKXs,64
7
7
  pychemstation/control/comm.py,sha256=u44g1hTluQ0yUG93Un-QAshScoDpgYRrZfFTgweP5tY,7386
8
- pychemstation/control/hplc.py,sha256=s600b9Oq_muO3uNilMpvSfP4XQIl5A07QzppmdOMPmc,6835
8
+ pychemstation/control/hplc.py,sha256=mIq7iN-BkWLSCNGCQPWc19Wjx82_mA_0X5Cy8TJoaUQ,10751
9
9
  pychemstation/control/controllers/__init__.py,sha256=di3ytLIK-35XC_THw4IjNaOtCUTe7GuEOFb-obmREw4,166
10
- pychemstation/control/controllers/comm.py,sha256=-fJqPcis30fbWS07Tiv68lRFk7ALKC8OitcEBQ_xDTE,7409
11
- pychemstation/control/controllers/method.py,sha256=dzP8mvgVOOpeAPMp4PLNYxqvaBrGkAe3lPfHWZaD2uk,13290
12
- pychemstation/control/controllers/sequence.py,sha256=Oi74EhVSgbDVQBxPvITvK5Eo52Ugtz_xCHFYCIq_4Oo,11070
13
- pychemstation/control/controllers/table_controller.py,sha256=U7oa_mwIKsySASMVWx-heD6C6tVkf5Yb26ksu9x5lQQ,8876
10
+ pychemstation/control/controllers/comm.py,sha256=IU4I_Q42VNCNUlVi93MxCmw2EBY9hiBDkU9FxubKg3c,7441
11
+ pychemstation/control/controllers/method.py,sha256=Z_nLu_zXyXhpixDq7xTOljMWVBn9ioFvmSLXhTHXw-Y,13322
12
+ pychemstation/control/controllers/sequence.py,sha256=ME9F5nWt-GqL5Qonhe8uNRU0K9oRwGPkPpb_YgqbziI,11318
13
+ pychemstation/control/controllers/table_controller.py,sha256=RARvXS2UIfVdinoVOD5aBFQFhEtu95K57bcNgwOKCME,9081
14
14
  pychemstation/control/table/__init__.py,sha256=RgMN4uIWHdNUHpGRBWdzmzAbk7XEKl6Y-qtqWCxzSZU,124
15
15
  pychemstation/control/table/method.py,sha256=THVoGomSXff_CTU3eAYme0BYwkPzab5UgZKsiZ29QSk,12196
16
16
  pychemstation/control/table/sequence.py,sha256=Eri52AnbE3BGthfrRSvYKYciquUzvHKo0lYUTySYYE8,10542
@@ -20,7 +20,7 @@ pychemstation/generated/dad_method.py,sha256=0W8Z5WDtF5jpIcudMqb7XrkTnR2EGg_QOCs
20
20
  pychemstation/generated/pump_method.py,sha256=sUhE2Oo00nzVcoONtq3EMWsN4wLSryXbG8f3EeViWKg,12174
21
21
  pychemstation/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
22
  pychemstation/utils/chromatogram.py,sha256=-q3_hL9GTyi4C95os7IwAiOrkTM4EXIiigm-nW9pFmM,3221
23
- pychemstation/utils/macro.py,sha256=BAIcE_dppNffwrSqGq8gh0ccE9YAJfQFQZHXJgA1WtA,2586
23
+ pychemstation/utils/macro.py,sha256=9rSdup9HucmVfT9ZnhwMUpH3vjxDsILXnBCGXQGVdYU,2656
24
24
  pychemstation/utils/method_types.py,sha256=Hyd_Kxf-ygKW7LlOtEhGG-uujwFPE1w-orqyxcDz17E,877
25
25
  pychemstation/utils/parsing.py,sha256=bnFIsZZwFy9NKzVUf517yN-ogzQbm0hp_aho3KUD6Is,9317
26
26
  pychemstation/utils/sequence_types.py,sha256=3VqiUHsfFEdynAxfR-z8JIWBCo7PdnGwTvsk7sm7Ij8,1055
@@ -28,12 +28,12 @@ pychemstation/utils/table_types.py,sha256=H67-7I96X8Zkm2HygHYttYwG_XuNDmV2AKZW10
28
28
  pychemstation/utils/tray_types.py,sha256=UUDED-IAf-8FmPVZezuWSiIQE_HgiZQMV2sTqu4oZw8,177
29
29
  tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
30
30
  tests/constants.py,sha256=lLwT_QaVriivL5llkul6RxXxPriwUp1E-Y3G9fejvbo,2092
31
- tests/test_comb.py,sha256=pfPpw2wKuF7_v39SOmT4tbbarqBa7NfcRTUVdLLsvWw,5769
31
+ tests/test_comb.py,sha256=Ef5PD_uEVszCMmpurbzlweSAXzGH6o1rblFqYhGC9r0,5680
32
32
  tests/test_comm.py,sha256=1ZZd0UrIBOKe91wzA-XI-gSRgXmId9mLWYSMeche82Y,2973
33
33
  tests/test_method.py,sha256=uCPpZVYKPz1CNWwhmBo_8TH0ku2V0ZpDZJj3f8iINB4,2440
34
34
  tests/test_sequence.py,sha256=yIQGhUTehtHz6D1ai5W6AlP0zes2icF0VdQ0IGJ2CbQ,4901
35
- pychemstation-0.5.7.dev1.dist-info/LICENSE,sha256=9bdF75gIf1MecZ7oymqWgJREVz7McXPG-mjqrTmzzD8,18658
36
- pychemstation-0.5.7.dev1.dist-info/METADATA,sha256=-JJQIwuYuatng6sohJy6y7-7WV8UBUOSJgMqkoi8OZ8,4312
37
- pychemstation-0.5.7.dev1.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
38
- pychemstation-0.5.7.dev1.dist-info/top_level.txt,sha256=zXfKu_4nYWwPHo3OsuhshMNC3SPkcoTGCyODjURaghY,20
39
- pychemstation-0.5.7.dev1.dist-info/RECORD,,
35
+ pychemstation-0.5.8.dist-info/LICENSE,sha256=9bdF75gIf1MecZ7oymqWgJREVz7McXPG-mjqrTmzzD8,18658
36
+ pychemstation-0.5.8.dist-info/METADATA,sha256=26690ZaxEouoE36tiXIBFH7DwfNr4DNTzABSddb3Rlw,4307
37
+ pychemstation-0.5.8.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
38
+ pychemstation-0.5.8.dist-info/top_level.txt,sha256=zXfKu_4nYWwPHo3OsuhshMNC3SPkcoTGCyODjURaghY,20
39
+ pychemstation-0.5.8.dist-info/RECORD,,
tests/test_comb.py CHANGED
@@ -28,16 +28,13 @@ class TestCombinations(unittest.TestCase):
28
28
  first_row=HPLCMethodParams(
29
29
  organic_modifier=5,
30
30
  flow=0.65,
31
- maximum_run_time=1),
31
+ maximum_run_time=4),
32
32
  subsequent_rows=[
33
33
  TimeTableEntry(
34
- start_time=0.10,
35
- organic_modifer=5,
36
- flow=0.34),
37
- TimeTableEntry(
38
- start_time=0.5,
39
- organic_modifer=98,
40
- flow=0.55)])
34
+ start_time=3.5,
35
+ organic_modifer=100,
36
+ flow=0.65)],
37
+ name=DEFAULT_METHOD)
41
38
  self.hplc_controller.edit_method(rand_method, save=True)
42
39
  if run_too:
43
40
  self.hplc_controller.run_method(experiment_name="changed_method")
@@ -97,7 +94,8 @@ class TestCombinations(unittest.TestCase):
97
94
  TimeTableEntry(
98
95
  start_time=0.50,
99
96
  organic_modifer=99,
100
- flow=0.34)])
97
+ flow=0.34)],
98
+ name=DEFAULT_METHOD)
101
99
  self.hplc_controller.edit_method(rand_method, save=True)
102
100
 
103
101
  self.hplc_controller.switch_sequence(sequence_name=DEFAULT_SEQUENCE)