hg-mc-auto 0.1.0__tar.gz

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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Chufan Zhou
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,501 @@
1
+ Metadata-Version: 2.4
2
+ Name: hg-mc-auto
3
+ Version: 0.1.0
4
+ Summary: Element-aware automation toolkit for isotope analysis workflows.
5
+ Author: IGeochemCloud
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/IGeochemCloud/Hg-MC-Auto
8
+ Project-URL: Repository, https://github.com/IGeochemCloud/Hg-MC-Auto
9
+ Project-URL: Issues, https://github.com/IGeochemCloud/Hg-MC-Auto/issues
10
+ Keywords: isotope,mc-icp-ms,automation,mcp,agent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: OS Independent
18
+ Requires-Python: >=3.9
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Provides-Extra: ml
22
+ Requires-Dist: scikit-learn>=1.6; extra == "ml"
23
+ Requires-Dist: xgboost>=2.1; extra == "ml"
24
+ Requires-Dist: joblib>=1.2; extra == "ml"
25
+ Provides-Extra: mcp
26
+ Requires-Dist: mcp>=1.0; extra == "mcp"
27
+ Provides-Extra: release
28
+ Requires-Dist: build>=1.2; extra == "release"
29
+ Requires-Dist: twine>=5.0; extra == "release"
30
+ Dynamic: license-file
31
+
32
+ # Hg-MC-Auto
33
+
34
+ Hg-MC-Auto is an element-aware automation toolkit for isotope analysis workflows, with bilingual CLI support, agent-facing MCP tooling, and cross-platform Python packaging.
35
+ ![alt text](<docs/Graphic abstract.png>)
36
+
37
+ - [A data-driven, post-acquisition quality diagnostic pipeline for isotope analysis by MC-ICP-MS](https://pubs.rsc.org/ja/article-abstract/41/5/1894/1230352/A-data-driven-post-acquisition-quality-diagnostic?redirectedFrom=fulltext)
38
+
39
+
40
+ ## Quick summary
41
+
42
+ - User-ready package: `pip install hg-mc-auto`
43
+ - CLI entry points: `hgmc` and `hg-mc-auto`
44
+ - Supported elements: `hg`, `fe`, `cd`
45
+ - Platforms: Windows, Linux, macOS
46
+ - Release flow: `hgmc-release` and `hgmc release`
47
+
48
+ ---
49
+
50
+ ## 1) User guide
51
+
52
+ ### Install
53
+
54
+ ```bash
55
+ python -m venv hg-mc-auto
56
+ source hg-mc-auto/bin/activate
57
+ pip install --upgrade pip
58
+ pip install hg-mc-auto
59
+ ```
60
+
61
+ On Windows PowerShell:
62
+
63
+ ```powershell
64
+ python -m venv hg-mc-auto
65
+ hg-mc-auto\Scripts\activate
66
+ pip install --upgrade pip
67
+ pip install hg-mc-auto
68
+ ```
69
+
70
+ ### Start the app
71
+
72
+ ```bash
73
+ hgmc
74
+ ```
75
+
76
+ Or:
77
+
78
+ ```bash
79
+ hg-mc-auto
80
+ ```
81
+
82
+ ### Common CLI commands
83
+
84
+ ```bash
85
+ hgmc --help
86
+ hgmc list-elements
87
+ hgmc workflow --element fe
88
+ hgmc run --element fe --task export --language zh
89
+ hgmc language --lang en
90
+ hgmc platform
91
+ hgmc project-summary
92
+ hgmc guide --element hg --language zh
93
+ ```
94
+
95
+ Use `hgmc list-elements` to check maturity. At present, Hg is the production
96
+ legacy workflow; Fe and Cd are scaffolds, not validated element-specific
97
+ analytical pipelines. The generic `run` command resolves task metadata and must
98
+ not be mistaken for executing a complete scientific workflow for every element.
99
+
100
+ ### Structured QC and optional LLM interpretation
101
+
102
+ The QC assistant accepts structured metrics, results, and anomaly flags. It does
103
+ not send raw instrument files by default, and an LLM response is advisory only:
104
+ the result remains `pending_human_review`.
105
+
106
+ ```bash
107
+ hgmc qc --input docs/qc_packet.example.json
108
+ ```
109
+
110
+ For a near-real-time, read-only directory monitor, point the command at the
111
+ directory where the calculation or prediction workflow writes result files:
112
+
113
+ ```bash
114
+ hgmc monitor --directory results --element hg --once
115
+ ```
116
+
117
+ Remove `--once` to keep polling. The monitor emits a `qc.v1` packet when a JSON,
118
+ CSV, or Excel result file is created or modified. It does not change instrument
119
+ settings or automatically approve a recommendation.
120
+
121
+ To request an interpretation through an OpenAI-compatible provider such as
122
+ OrcaRouter, set the provider key first:
123
+
124
+ ```bash
125
+ export ORCA_KEY="your-key"
126
+ hgmc qc --input docs/qc_packet.example.json --llm --language zh
127
+ ```
128
+
129
+ The assistant can explain quality signals, rank plausible causes, and suggest
130
+ checks. It must not directly change instrument parameters or start an
131
+ instrument run.
132
+
133
+ ### Install with MCP support
134
+
135
+ ```bash
136
+ pip install "hg-mc-auto[mcp]"
137
+ hgmc mcp --action status
138
+ ```
139
+
140
+ ### Connect this checkout to VS Code Agent
141
+
142
+ When opening this repository as the VS Code workspace, it includes
143
+ `.vscode/mcp.json`. Run **MCP: List Servers**, select `hg-mc-auto`, then start
144
+ the server. In Chat, choose Agent mode and enable the server's tools. If VS Code
145
+ does not discover the configuration, run **Developer: Reload Window** and
146
+ inspect **MCP: Show Installed Servers**.
147
+
148
+ The workspace configuration uses the repository-local virtual environment. If
149
+ you moved or renamed that environment, update the command in `.vscode/mcp.json`.
150
+
151
+ Try asking the Agent: “Use Hg-MC-Auto MCP to list the supported elements and
152
+ explain the Hg workflow.” It should call `list_elements` and `resolve_workflow`.
153
+
154
+ Current tools provide metadata, workflow routing, plans, and structured QC
155
+ packet creation. In particular, `run_element_task` only resolves the target
156
+ script; it does not execute Evaluation GUI automation or control the instrument.
157
+
158
+ ### Notes
159
+
160
+ - If you only need normal usage, `pip install hg-mc-auto` is enough.
161
+ - `hgmc` is the recommended command for end users.
162
+ - `python src/main.py` remains available for legacy local development workflows.
163
+
164
+ ---
165
+
166
+ ## 2) Developer guide
167
+
168
+ ### Clone and set up the repo
169
+
170
+ ```bash
171
+ git clone https://github.com/IGeochemCloud/Hg-MC-Auto.git
172
+ cd Hg-MC-Auto
173
+ python -m venv hg-mc-auto
174
+ source hg-mc-auto/bin/activate
175
+ pip install --upgrade pip
176
+ pip install -e .
177
+ pip install -r requirements.txt
178
+ ```
179
+
180
+ ### Run tests
181
+
182
+ ```bash
183
+ PYTHONPATH=. python -m unittest tests.test_main_cli -v
184
+ ```
185
+
186
+ ### CLI development
187
+
188
+ ```bash
189
+ hgmc --help
190
+ hgmc list-elements
191
+ hgmc workflow --element fe
192
+ hgmc run --element cd --task export --language en
193
+ ```
194
+
195
+ See [docs/ELEMENT_EXPANSION.md](docs/ELEMENT_EXPANSION.md) for reviewed
196
+ MC-ICP-MS method references, element support gates, and the proposed plugin
197
+ contract.
198
+
199
+ ### MCP development
200
+
201
+ ```bash
202
+ hgmc mcp --action status
203
+ hgmc mcp --action tools
204
+ hgmc mcp --action json
205
+ hgmc mcp --action stdio
206
+ ```
207
+
208
+ The stdio action is intended for agent/IDE integrations. It is compatible with the installed `mcp` 2.x API and exposes the project’s tool surface over standard input/output.
209
+
210
+ The MCP layer can later expose the same structured QC packet and advisory
211
+ assessment to an agent. Keep the human approval step outside the model: an
212
+ agent may prepare a review, but a qualified operator confirms any action.
213
+
214
+ ### Release flow
215
+
216
+ The recommended way to publish a new version to both GitHub and PyPI is the
217
+ one-command sync helper. It validates the version, refuses to run with
218
+ uncommitted changes, checks credentials, then builds, tags, pushes to GitHub,
219
+ and uploads to PyPI.
220
+
221
+ ```bash
222
+ # 1. Bump the version in pyproject.toml (e.g. 0.1.1)
223
+ # 2. Commit your changes
224
+ # 3. Export your PyPI token (never commit it)
225
+ export PYPI_TOKEN="your-token"
226
+
227
+ # 4. Dry-run to validate without publishing
228
+ hgmc-release sync --version 0.1.1 --dry-run
229
+
230
+ # 5. Publish to GitHub and PyPI together
231
+ hgmc-release sync --version 0.1.1 --message "release 0.1.1"
232
+ ```
233
+
234
+ The sync helper will fail early if the requested version does not match
235
+ `pyproject.toml`, if the git tag already exists, if the working tree is dirty,
236
+ or if `PYPI_TOKEN` / `twine` are missing.
237
+
238
+ Individual steps are also available:
239
+
240
+ ```bash
241
+ hgmc-release check
242
+ hgmc-release build
243
+ hgmc-release publish
244
+ ```
245
+
246
+ ### PyPI publishing
247
+
248
+ ```bash
249
+ python -m build
250
+ python -m twine upload dist/*
251
+ ```
252
+
253
+ Set `PYPI_TOKEN` before publishing if you are using automation. Create the token
254
+ at https://pypi.org/manage/account/token/ and use `__token__` as the username.
255
+
256
+ ### OrcaRouter open-source maintainer application
257
+
258
+ The project can apply through [OrcaRouter Built With](https://www.orcarouter.ai/zh-CN/built-with).
259
+ The page currently states that the repository must be public, owned by the
260
+ applicant, and contain commits from the applicant's GitHub account; approval is
261
+ manual. Listing is attribution and support, not an endorsement or an exclusive
262
+ provider agreement. Other model providers can remain supported.
263
+
264
+ Before applying, publish the repository and make the project description clear:
265
+ structured MC-ICP-MS QC, bilingual workflow support, MCP integration, and
266
+ human-confirmed recommendations. Do not include API keys, raw laboratory data,
267
+ or private instrument credentials in the repository.
268
+
269
+ ---
270
+
271
+ ## 3) Project structure
272
+
273
+ ![alt text](<docs/Overall Architecture Diagram.png>)
274
+
275
+ ```bash
276
+ Hg-MC-Auto/
277
+ ├── src/
278
+ │ ├── main.py
279
+ │ ├── hg_mc_auto/
280
+ │ │ ├── cli.py
281
+ │ │ ├── mcp_server.py
282
+ │ │ ├── release.py
283
+ │ │ ├── core/
284
+ │ │ └── ...
285
+ │ └── ...
286
+ ├── tests/
287
+ ├── docs/
288
+ ├── data/
289
+ ├── model/
290
+ ├── results/
291
+ ├── pyproject.toml
292
+ ├── requirements.txt
293
+ ├── README.md
294
+ ├── LICENSE
295
+ └── .gitignore
296
+ ```
297
+
298
+ ---
299
+
300
+ ## 4) Platform notes
301
+
302
+ ### Windows
303
+
304
+ ```powershell
305
+ python -m venv hg-mc-auto
306
+ hg-mc-auto\Scripts\activate
307
+ pip install -e .
308
+ hgmc --help
309
+ ```
310
+
311
+ ### Linux
312
+
313
+ ```bash
314
+ python3 -m venv hg-mc-auto
315
+ source hg-mc-auto/bin/activate
316
+ pip install -e .
317
+ hgmc --help
318
+ ```
319
+
320
+ ### macOS
321
+
322
+ ```bash
323
+ python3 -m venv hg-mc-auto
324
+ source hg-mc-auto/bin/activate
325
+ pip install -e .
326
+ hgmc --help
327
+ ```
328
+
329
+ ---
330
+
331
+ ## 5) Release status
332
+
333
+ This project is currently in a release-oriented v0.1.0 state with:
334
+
335
+ - bilingual CLI support
336
+ - generalized element routing for `hg`, `fe`, and `cd`
337
+ - agent-oriented MCP tooling
338
+ - PyPI packaging support
339
+ - structured QC packets with advisory LLM interpretation
340
+ - mandatory human confirmation before operational action
341
+ - Windows / Linux / macOS compatibility notes
342
+
343
+ ---
344
+
345
+ ## 6) Citation and contact
346
+
347
+ If you use this project in published work, please cite the project and associated manuscript as appropriate for your workflow and repository policy.
348
+
349
+ For development questions or collaboration, use the repository issue tracker or project maintainer contact listed in the upstream project metadata.
350
+ │ ├── 3_Empirical_model.py # Expert rule-based classification
351
+ │ ├── 4_ML_Predict.py # ML model prediction interface
352
+ │ ├── 5_Exter_ML_train.py # Binary classifier training
353
+ │ └── 6.Inter_ML_train.py # Multi-class classifier training
354
+ │
355
+ ├── custom_ranges_config.json # User-configurable acceptance ranges
356
+ ├── mouse_coordinates.config # RPA coordinate settings
357
+ ├── requirements.txt # Python dependencies
358
+ ├── LICENSE # MIT License
359
+ └── README.md # This file
360
+ ```
361
+ ## 📖 Usage Guide
362
+ Launching the Application
363
+ After installation, run:
364
+
365
+ ```bash
366
+ python src/main.py
367
+ ```
368
+
369
+ You will see the interactive interface:
370
+
371
+ ```bash
372
+ Welcome to Hg_MC_Auto!
373
+ ============================================================
374
+
375
+ Please select a task:
376
+ 1. Automatically export isotope data
377
+ 2. Automatically export instrument parameters, merge isotope data, and calculate isotope fractionation values
378
+ 3. Classify data using an empirical model
379
+ 4. Classify data using a machine learning model
380
+ 5. Train your own machine learning expert model
381
+ 0. Exit
382
+ ```
383
+ ## Task Options Explained
384
+ Option 1: Automated Data Export
385
+ Converts proprietary .dat files to structured CSV format
386
+
387
+ Merges with corresponding instrument log files
388
+
389
+ Uses RPA for vendor software interaction
390
+
391
+ Option 2: Isotope Calculation
392
+ Calculates δ202Hg values relative to NIST SRM 3133
393
+
394
+ Computes mass-independent fractionation anomalies (Δ-values)
395
+
396
+ Batch processes entire datasets
397
+
398
+ Option 3: Empirical Model Classification
399
+ Applies literature-based acceptance ranges (Table 1 in manuscript)
400
+
401
+ Flags measurements outside 95% confidence intervals
402
+
403
+ User-configurable thresholds via custom_ranges_config.json
404
+
405
+ Option 4: ML Model Prediction
406
+ Uses pre-trained ensemble models for quality assessment
407
+
408
+ Provides confidence scores for each prediction
409
+
410
+ Identifies probable causes for abnormal measurements
411
+
412
+ Option 5: Custom Model Training
413
+ Train laboratory-specific models using your annotated data
414
+
415
+ Supports both binary and multi-class classification
416
+
417
+ Adapts to different instrument performances and sample matrices
418
+
419
+ ## 🤖 Models
420
+ Binary Classification Models
421
+ Purpose: Distinguish between "Normal" and "Abnormal" measurements
422
+
423
+ Performance: Test F1-score: 0.9960, AUC: 0.999-1.0
424
+
425
+ Algorithms: Random Forest, XGBoost, Bagging Classifiers
426
+
427
+ Sampling Strategies: SMOTE, ADASYN, SMOTEENN, UnderSampling
428
+
429
+ Multi-class Diagnostic Models
430
+ Purpose: Identify root causes of abnormalities
431
+
432
+ Categories:
433
+
434
+ "Possible instrument instability"
435
+
436
+ "Potential concentration anomaly"
437
+
438
+ "Combined factors"
439
+
440
+ "Other reasons, retesting recommended"
441
+
442
+ Features: Internal precision metrics, concentration mismatch ratios
443
+
444
+ ## 📊 Performance Highlights
445
+ Metric Binary Classification Multi-class Diagnosis
446
+ Accuracy 99.61% 99.84%
447
+ F1-Score 0.9960 0.9909 (balanced)
448
+ Recall (Normal) 99.8% -
449
+ AUC 0.999-1.0 -
450
+ Based on validation with 26,218 historical measurements
451
+
452
+ ## 📝 Citation
453
+ If you use Hg-MC-Auto in your research, please cite:
454
+
455
+ bibtex
456
+ @article{zhou2025selfdriving,
457
+ title={A Data‑Driven, Post‑Acquisition Quality Diagnostic Pipeline for Isotope Analysis by MC-ICP-MS},
458
+ author={Zhou, Chufan and Huang, Qiang and Tang, Yang and Zhong, Ying and Feng, Xinbin},
459
+ journal={Journal of Analytical Atomic Spectrometry},
460
+ year={2025},
461
+ doi={10.1039/D5JA00519A}
462
+ }
463
+ ## 🤝 Contributing
464
+ We welcome contributions! Please:
465
+
466
+ Fork the repository
467
+
468
+ Create a feature branch
469
+
470
+ Submit a pull request
471
+
472
+ Ensure code follows PEP 8 guidelines
473
+
474
+ Include tests for new functionality
475
+
476
+ ## 🐛 Issues and Support
477
+ Bug Reports: Use the GitHub Issues page
478
+
479
+ Questions: Check the Wiki or open a discussion
480
+
481
+ Feature Requests: Submit via GitHub Issues with the "enhancement" label
482
+
483
+ ## 📧 Contact
484
+ Laboratory of Karst Environmental Evolution and Ecological Security,
485
+ Institute of Geochemistry, Chinese Academy of Sciences,
486
+ Guiyang, Guizhou 550081, China
487
+
488
+ We welcome experts from different laboratories to contribute their expertise
489
+ and make contributions to the intelligent geochemistry laboratory.
490
+ Welcome to join us and make a change together.
491
+
492
+ Chufan Zhou:
493
+ 📧 zhouchufan@mail.gyig.ac.cn
494
+ 🔗 ORCID: [0009-0008-0144-9017](https://orcid.org/0009-0008-0144-9017)
495
+
496
+ Qiang Huang (Corresponding Author):
497
+ 📧 huangqiang@mail.gyig.ac.cn
498
+ 🔗 ORCID: [0000-0003-1568-9042](https://orcid.org/0000-0003-1568-9042)
499
+
500
+ 📄 License
501
+ This project is licensed under the MIT License - see the LICENSE file for details.