Skip to main content

pychemstation: A Python package for automated control of Chemstation using MACROs

PyPI - Downloads

PyPI Latest Release

NOTE: If you are running Python 3.8, use versions 0.8.x. If you are running Python 3.9 use versions 0.9.x. If you are running Python >=3.10, use version 0.10.x. Older versions of pychemstation are not the most feature-rich and bug-free. Please consider upgrading to using Python 3.10!

Unofficial Python package to control Agilent Chemstation; we are not affiliated with Agilent. Check out the docs for usage instructions. This project is under active development, and breaking changes may occur at any moment.

Getting started

Before running this library, these are the steps you need to complete.

Add python package

pip install pychemstation

Add required MACRO script

  1. Open ChemStation
  2. Run this in the ChemStation command line: Print _AutoPath$. Go to this path in your file navigator, as this is where you will put your MACRO file(s).
  3. Download the hplc_talk.mac.
    • On line 69, change the path name up to \cmd and \reply. For instance, you should have: MonitorFile "[my path]\cmd", "[my path]\reply"
    • and then add this file to the folder from the previous step.
  4. To have these MACRO files be read by ChemStation, you must either:
    • Open ChemStation and run:
macro hplc_talk.mac
HPLCTalk_Run
  • OR add the above lines to a MACRO file named: user.mac, and then put user.mac in the same folder from step 3.
    • ChemStation will automatically load these MACRO files for you. However, sometimes this does not work, and if it does not, you will have to run the lines in the user.mac manually.

Example Usage

import time
from pychemstation.control import HPLCController
from pychemstation.utils.method_types import *
import pandas as pd

DEFAULT_COMMAND_PATH = "C:\\Users\\User\\Desktop\\Lucy\\"
CUSTOM_DATA_DIR = "C:\\Users\\Public\\Documents\\ChemStation\\2\\Data\\MyData"

# Initialize HPLC Controller
hplc_controller = HPLCController(extra_data_dirs=[CUSTOM_DATA_DIR],
                                 comm_dir=DEFAULT_COMMAND_PATH)

# Switching a method
hplc_controller.switch_method("General-Poroshell")

# Editing a method
new_method = MethodDetails(
    name="General-Poroshell",
    params=HPLCMethodParams(
        organic_modifier=7,
        flow=0.44),
    timetable=[
        TimeTableEntry(
            start_time=0.10,
            organic_modifer=7,
            flow=0.34
        ),
        TimeTableEntry(
            start_time=4,
            organic_modifer=99,
            flow=0.55
        )
    ],
    stop_time=5,
    post_time=2
)
hplc_controller.edit_method(new_method)

# Run a method and get a report or data from last run method
hplc_controller.run_method(experiment_name="test_experiment", stall_while_running=False)
time_left, done = hplc_controller.check_method_complete()
while not done:
    print(time_left)
    time.sleep(time_left/2)
    time_left, done = hplc_controller.check_method_complete()
    
# Save the path the HPLC data for later!  
file_path = hplc_controller.get_last_run_method_file_path()

# Make sure CSV reports are being generated in the post-run MACRO!
report = hplc_controller.get_last_run_method_report()
vial_location = report.vial_location

# Save, analyze or plot the data!
chrom = hplc_controller.get_last_run_method_data()
chromatogram_data = pd.DataFrame.from_dict({"x": chrom.A.x, "y": chrom.A.y})
chromatogram_data.to_csv("Run 10.csv", index=False) 

Adding your own MACROs

If you wish to add your own MACRO functions, then all you need to do is write you MACRO (using Agilent's) MACRO guide, put the file in the user.mac file and then list the function you want to use.

Developing

If you would like to contribute to this project, check out our GitLab!

Authors and Acknowledgements

Lucy Hao, Maria Politi

Metadata

Release files for pychemstation 0.10.13

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pychemstation 0.10.13
File Size Uploaded Provenance Actions
pychemstation-0.10.13.tar.gz 20.8 MB Without provenance Details for pychemstation-0.10.13.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pychemstation 0.10.13
File Interpreter ABI Platform Actions
pychemstation-0.10.13-py3-none-any.whl Python 3 none any Details for pychemstation-0.10.13-py3-none-any.whl

Total release size: 20.9 MB

Release files / pychemstation-0.10.13.tar.gz

Download URL pychemstation-0.10.13.tar.gz
Size 20.8 MB
Tags Source
SHA-256 checksum
How to use checksums
ce667715a9ea7ac157eb74e5b2fbe4de3372bde775cbaf9f9361bf66e06f74b7
BLAKE2b-256 checksum
How to use checksums
21c998e32dcde9f21147fa922e9704e6eb803d5165ac5c9c37353e2dab1b1623
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.10

Release files / pychemstation-0.10.13-py3-none-any.whl

Download URL pychemstation-0.10.13-py3-none-any.whl
Size 73.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5d278c844be5242c1fae27f4c1980f654e0c53d7131bfbbb6268619fb94a28b5
BLAKE2b-256 checksum
How to use checksums
24645b5a6d0adc1ab370871ef2d283ba6327b5d72506d488dfde96da860bd805
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.10

Security for pychemstation 0.10.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.10.13 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page