chemphase 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) 2024 Phase Diagram Generator Team
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,111 @@
1
+ Metadata-Version: 2.4
2
+ Name: chemphase
3
+ Version: 0.1.0
4
+ Summary: 相图与化学势热图统一生成器 — 一键生成二元/三元成分相图、化学势热图,支持 Materials Project API 和本地 VASP 数据
5
+ Author: Phase Diagram Generator Team
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/user/chemphase
8
+ Project-URL: Repository, https://github.com/user/chemphase
9
+ Project-URL: Issues, https://github.com/user/chemphase/issues
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Topic :: Scientific/Engineering :: Physics
17
+ Classifier: Topic :: Scientific/Engineering :: Chemistry
18
+ Requires-Python: >=3.10
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: pymatgen>=2023.0.0
22
+ Requires-Dist: doped>=3.2.0
23
+ Requires-Dist: matplotlib>=3.5.0
24
+ Requires-Dist: numpy>=1.21.0
25
+ Requires-Dist: scipy>=1.7.0
26
+ Requires-Dist: plotly>=5.0.0
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest>=8.0; extra == "dev"
29
+ Requires-Dist: pytest-cov; extra == "dev"
30
+ Requires-Dist: ruff; extra == "dev"
31
+ Dynamic: license-file
32
+
33
+ # chemphase
34
+
35
+ **相图与化学势热图统一生成器 v5.0**
36
+
37
+ [![Python](https://img.shields.io/badge/Python-3.10%2B-blue)](https://python.org)
38
+ [![License](https://img.shields.io/badge/License-MIT-green)](LICENSE)
39
+
40
+ 一键从 Materials Project API 或本地 VASP 计算结果生成高质量相图。
41
+
42
+ ## 功能
43
+
44
+ - **API 模式**:从 Materials Project 数据库下载热力学数据
45
+ - **本地模式**:读取本地 VASP 计算目录 (POSCAR + vasprun.xml/OUTCAR)
46
+ - **混合模式**:本地数据 + API 补充
47
+ - **二元成分相图**:ΔE vs 成分,含 Hull 连线、自动标签避让
48
+ - **三元成分相图**:Gibbs 三角图 (Plotly 交互式),含 Hull 三角剖分
49
+ - **结构对比**:检测本地计算与 MP 数据库的晶体结构差异
50
+
51
+ ## 安装
52
+
53
+ ```bash
54
+ pip install chemphase
55
+ ```
56
+
57
+ ## 快速开始
58
+
59
+ ### API 模式(默认)
60
+
61
+ ```bash
62
+ # 使用默认元素 Cu-Ag-O-Se
63
+ chemphase
64
+
65
+ # 指定元素
66
+ chemphase --elements Li O Co
67
+ ```
68
+
69
+ ### 本地 VASP 数据模式
70
+
71
+ ```bash
72
+ chemphase --local /path/to/vasp/calculations --elements Cu Ag O Se
73
+ ```
74
+
75
+ ### 结构对比
76
+
77
+ ```bash
78
+ chemphase --local /path/to/vasp/calculations --elements Cu Ag O Se --compare-structure
79
+ ```
80
+
81
+ ## 依赖
82
+
83
+ - [pymatgen](https://pymatgen.org) — 材料分析库
84
+ - [doped](https://github.com/SMTG-Bham/doped) — 缺陷计算工具
85
+ - [matplotlib](https://matplotlib.org) — 二维绘图
86
+ - [plotly](https://plotly.com) — 交互式三元图
87
+
88
+ ## API 密钥
89
+
90
+ API 模式需要 Materials Project API 密钥。设置环境变量:
91
+
92
+ ```bash
93
+ export MATERIALS_PROJECT_API_KEY=你的密钥
94
+ ```
95
+
96
+ 获取密钥:https://materialsproject.org/api
97
+
98
+ ## 命令行参数
99
+
100
+ | 参数 | 说明 | 默认值 |
101
+ |------|------|--------|
102
+ | `--elements` | 元素列表 | `Cu Ag O Se` |
103
+ | `--local` | 本地VASP目录 | — |
104
+ | `--output` | 输出目录 | `phase_diagrams_output` |
105
+ | `--eah` | E above hull 阈值 | `0.05` eV/atom |
106
+ | `--compare-structure` | 启用结构对比 | `False` |
107
+ | `--debug` | 调试模式 | `False` |
108
+
109
+ ## 许可证
110
+
111
+ MIT License — 详见 [LICENSE](LICENSE)
@@ -0,0 +1,79 @@
1
+ # chemphase
2
+
3
+ **相图与化学势热图统一生成器 v5.0**
4
+
5
+ [![Python](https://img.shields.io/badge/Python-3.10%2B-blue)](https://python.org)
6
+ [![License](https://img.shields.io/badge/License-MIT-green)](LICENSE)
7
+
8
+ 一键从 Materials Project API 或本地 VASP 计算结果生成高质量相图。
9
+
10
+ ## 功能
11
+
12
+ - **API 模式**:从 Materials Project 数据库下载热力学数据
13
+ - **本地模式**:读取本地 VASP 计算目录 (POSCAR + vasprun.xml/OUTCAR)
14
+ - **混合模式**:本地数据 + API 补充
15
+ - **二元成分相图**:ΔE vs 成分,含 Hull 连线、自动标签避让
16
+ - **三元成分相图**:Gibbs 三角图 (Plotly 交互式),含 Hull 三角剖分
17
+ - **结构对比**:检测本地计算与 MP 数据库的晶体结构差异
18
+
19
+ ## 安装
20
+
21
+ ```bash
22
+ pip install chemphase
23
+ ```
24
+
25
+ ## 快速开始
26
+
27
+ ### API 模式(默认)
28
+
29
+ ```bash
30
+ # 使用默认元素 Cu-Ag-O-Se
31
+ chemphase
32
+
33
+ # 指定元素
34
+ chemphase --elements Li O Co
35
+ ```
36
+
37
+ ### 本地 VASP 数据模式
38
+
39
+ ```bash
40
+ chemphase --local /path/to/vasp/calculations --elements Cu Ag O Se
41
+ ```
42
+
43
+ ### 结构对比
44
+
45
+ ```bash
46
+ chemphase --local /path/to/vasp/calculations --elements Cu Ag O Se --compare-structure
47
+ ```
48
+
49
+ ## 依赖
50
+
51
+ - [pymatgen](https://pymatgen.org) — 材料分析库
52
+ - [doped](https://github.com/SMTG-Bham/doped) — 缺陷计算工具
53
+ - [matplotlib](https://matplotlib.org) — 二维绘图
54
+ - [plotly](https://plotly.com) — 交互式三元图
55
+
56
+ ## API 密钥
57
+
58
+ API 模式需要 Materials Project API 密钥。设置环境变量:
59
+
60
+ ```bash
61
+ export MATERIALS_PROJECT_API_KEY=你的密钥
62
+ ```
63
+
64
+ 获取密钥:https://materialsproject.org/api
65
+
66
+ ## 命令行参数
67
+
68
+ | 参数 | 说明 | 默认值 |
69
+ |------|------|--------|
70
+ | `--elements` | 元素列表 | `Cu Ag O Se` |
71
+ | `--local` | 本地VASP目录 | — |
72
+ | `--output` | 输出目录 | `phase_diagrams_output` |
73
+ | `--eah` | E above hull 阈值 | `0.05` eV/atom |
74
+ | `--compare-structure` | 启用结构对比 | `False` |
75
+ | `--debug` | 调试模式 | `False` |
76
+
77
+ ## 许可证
78
+
79
+ MIT License — 详见 [LICENSE](LICENSE)
@@ -0,0 +1,64 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "chemphase"
7
+ version = "0.1.0"
8
+ description = "相图与化学势热图统一生成器 — 一键生成二元/三元成分相图、化学势热图,支持 Materials Project API 和本地 VASP 数据"
9
+ authors = [
10
+ {name = "Phase Diagram Generator Team"}
11
+ ]
12
+ readme = "README.md"
13
+ license = "MIT"
14
+ license-files = ["LICENSE"]
15
+ requires-python = ">=3.10"
16
+ classifiers = [
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.10",
19
+ "Programming Language :: Python :: 3.11",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Intended Audience :: Science/Research",
22
+ "Operating System :: OS Independent",
23
+ "Topic :: Scientific/Engineering :: Physics",
24
+ "Topic :: Scientific/Engineering :: Chemistry",
25
+ ]
26
+
27
+ dependencies = [
28
+ "pymatgen>=2023.0.0",
29
+ "doped>=3.2.0",
30
+ "matplotlib>=3.5.0",
31
+ "numpy>=1.21.0",
32
+ "scipy>=1.7.0",
33
+ "plotly>=5.0.0",
34
+ ]
35
+
36
+ [project.optional-dependencies]
37
+ dev = [
38
+ "pytest>=8.0",
39
+ "pytest-cov",
40
+ "ruff",
41
+ ]
42
+
43
+ [project.scripts]
44
+ chemphase = "chemphase.cli:main"
45
+
46
+ [project.urls]
47
+ Homepage = "https://github.com/user/chemphase"
48
+ Repository = "https://github.com/user/chemphase"
49
+ Issues = "https://github.com/user/chemphase/issues"
50
+
51
+ [tool.setuptools.packages.find]
52
+ where = ["src"]
53
+ exclude = ["tests*", "docs*"]
54
+
55
+ [tool.setuptools.package-data]
56
+ "chemphase" = ["py.typed"]
57
+
58
+ [tool.ruff]
59
+ line-length = 100
60
+ lint.select = ["E", "F", "I", "N", "W", "UP", "B", "SIM"]
61
+
62
+ [tool.pytest.ini_options]
63
+ testpaths = ["tests"]
64
+ pythonpath = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,35 @@
1
+ """chemphase — 相图与化学势热图生成器
2
+
3
+ 一键从 Materials Project API 或本地 VASP 计算结果生成:
4
+ - 二元/三元成分相图(含 Hull 连线、标签自动避让)
5
+ - 化学势热图
6
+ - 结构对比报告
7
+ """
8
+
9
+ __version__ = "0.1.0"
10
+
11
+
12
+ def __getattr__(name):
13
+ """惰性导入:仅在实际使用子模块时才导入"""
14
+ if name == "PhaseDiagramConfig":
15
+ from chemphase.core import PhaseDiagramConfig
16
+ return PhaseDiagramConfig
17
+ if name == "generate_binary_composition_diagram":
18
+ from chemphase.diagrams import generate_binary_composition_diagram
19
+ return generate_binary_composition_diagram
20
+ if name == "generate_ternary_composition_diagram":
21
+ from chemphase.diagrams import generate_ternary_composition_diagram
22
+ return generate_ternary_composition_diagram
23
+ if name == "main":
24
+ from chemphase.cli import main
25
+ return main
26
+ raise AttributeError(f"module 'chemphase' has no attribute '{name}'")
27
+
28
+
29
+ __all__ = [
30
+ "__version__",
31
+ "PhaseDiagramConfig",
32
+ "generate_binary_composition_diagram",
33
+ "generate_ternary_composition_diagram",
34
+ "main",
35
+ ]
@@ -0,0 +1,9 @@
1
+ """chemphase 命令行入口
2
+
3
+ 支持 python -m chemphase 调用
4
+ """
5
+
6
+ from chemphase.cli import main
7
+
8
+ if __name__ == "__main__":
9
+ main()
@@ -0,0 +1,205 @@
1
+ """命令行接口 (CLI)
2
+
3
+ 安装后通过终端命令 `chemphase` 或 `python -m chemphase` 调用
4
+ """
5
+
6
+ import sys
7
+ import argparse
8
+ from pathlib import Path
9
+ from itertools import combinations
10
+
11
+ from chemphase.core import (
12
+ PhaseDiagramConfig, validate_elements, ensure_api_key,
13
+ scan_local_phases, build_local_entries, structure_comparison_report,
14
+ get_entries_from_mp, get_system_name, get_all_element_combinations,
15
+ print_banner, DEFAULT_ELEMENTS,
16
+ )
17
+ from chemphase.diagrams import (
18
+ generate_binary_composition_diagram,
19
+ generate_ternary_composition_diagram,
20
+ )
21
+
22
+
23
+ def run_local_mode(config: PhaseDiagramConfig, elements, output_root: str):
24
+ """本地数据模式:读取 VASP 计算结果生成相图"""
25
+ print(f"\n扫描本地目录: {config.local_dir}")
26
+ local_phases = scan_local_phases(config.local_dir, elements, config.eah_threshold)
27
+ print(f"找到 {len(local_phases)} 个相关相")
28
+
29
+ if not local_phases:
30
+ print("没有找到有效的相数据")
31
+ return
32
+
33
+ # 结构对比
34
+ if config.compare_structure:
35
+ print("\n" + "=" * 60)
36
+ print(" 结构对比分析")
37
+ print("=" * 60)
38
+ report = structure_comparison_report(local_phases, config)
39
+ print(f" 总共对比: {report['total_compared']}")
40
+ print(f" 结构匹配: {report['matching']}")
41
+ print(f" 结构不同: {report['different']}")
42
+ print(f" MP未收录: {report['not_found_in_mp']}")
43
+
44
+ import json
45
+ report_file = Path(output_root) / "structure_comparison_report.json"
46
+ report_file.parent.mkdir(parents=True, exist_ok=True)
47
+ with open(report_file, 'w') as f:
48
+ json.dump(report, f, indent=2, sort_keys=True)
49
+ print(f" 报告已保存: {report_file}")
50
+
51
+ entries = build_local_entries(local_phases)
52
+ print(f"\n构建了 {len(entries)} 个PhaseDiagramEntry")
53
+
54
+ output_dir = Path(output_root)
55
+ output_dir.mkdir(parents=True, exist_ok=True)
56
+
57
+ binary_combos = list(combinations(elements, 2))
58
+ ternary_combos = list(combinations(elements, 3))
59
+
60
+ # 二元相图
61
+ print("\n" + "=" * 60)
62
+ print(" 生成二元相图")
63
+ print("=" * 60)
64
+ binary_dir = output_dir / "binary"
65
+ binary_dir.mkdir(parents=True, exist_ok=True)
66
+ for e1, e2 in binary_combos:
67
+ sub_entries = [e for e in entries if set(e.composition.as_dict().keys()) <= {e1, e2}]
68
+ if len(sub_entries) >= 2:
69
+ generate_binary_composition_diagram(sub_entries, (e1, e2), binary_dir, "本地数据")
70
+
71
+ # 三元相图
72
+ print("\n" + "=" * 60)
73
+ print(" 生成三元相图")
74
+ print("=" * 60)
75
+ ternary_dir = output_dir / "ternary"
76
+ ternary_dir.mkdir(parents=True, exist_ok=True)
77
+ for e1, e2, e3 in ternary_combos:
78
+ sub_entries = [e for e in entries if set(e.composition.as_dict().keys()) <= {e1, e2, e3}]
79
+ if len(sub_entries) >= 3:
80
+ generate_ternary_composition_diagram(sub_entries, (e1, e2, e3), ternary_dir, "本地数据")
81
+
82
+ print("\n" + "=" * 60)
83
+ print(" 本地数据模式完成")
84
+ print("=" * 60)
85
+ print(f"输出目录: {output_dir}")
86
+
87
+
88
+ def run_api_mode(config: PhaseDiagramConfig, elements, output_root: str):
89
+ """API 下载模式:从 Materials Project 下载数据生成相图"""
90
+ print(f"\n从Materials Project下载 {get_system_name(elements)} 体系数据")
91
+
92
+ output_dir = Path(output_root)
93
+ output_dir.mkdir(parents=True, exist_ok=True)
94
+
95
+ binary_combos = list(combinations(elements, 2))
96
+ ternary_combos = list(combinations(elements, 3))
97
+
98
+ # 二元相图
99
+ print("\n" + "=" * 60)
100
+ print(" 生成二元相图")
101
+ print("=" * 60)
102
+ binary_dir = output_dir / "binary"
103
+ binary_dir.mkdir(parents=True, exist_ok=True)
104
+ for e1, e2 in binary_combos:
105
+ try:
106
+ entries = get_entries_from_mp(config, [e1, e2])
107
+ if len(entries) >= 2:
108
+ from pymatgen.analysis.phase_diagram import PDEntry
109
+ pd_entries = [PDEntry(composition=e.composition, energy=e.energy, name=e.name)
110
+ for e in entries]
111
+ generate_binary_composition_diagram(pd_entries, (e1, e2), binary_dir, "MP数据")
112
+ except Exception as e:
113
+ print(f" - {e1}-{e2}: {e}")
114
+
115
+ # 三元相图
116
+ print("\n" + "=" * 60)
117
+ print(" 生成三元相图")
118
+ print("=" * 60)
119
+ ternary_dir = output_dir / "ternary"
120
+ ternary_dir.mkdir(parents=True, exist_ok=True)
121
+ for e1, e2, e3 in ternary_combos:
122
+ try:
123
+ entries = get_entries_from_mp(config, [e1, e2, e3])
124
+ if len(entries) >= 3:
125
+ from pymatgen.analysis.phase_diagram import PDEntry
126
+ pd_entries = [PDEntry(composition=e.composition, energy=e.energy, name=e.name)
127
+ for e in entries]
128
+ generate_ternary_composition_diagram(pd_entries, (e1, e2, e3), ternary_dir, "MP数据")
129
+ except Exception as e:
130
+ print(f" - {e1}-{e2}-{e3}: {e}")
131
+
132
+ print("\n" + "=" * 60)
133
+ print(" API模式完成")
134
+ print("=" * 60)
135
+ print(f"输出目录: {output_dir}")
136
+
137
+
138
+ def main():
139
+ """主入口函数"""
140
+ parser = argparse.ArgumentParser(
141
+ prog="chemphase",
142
+ description="相图与化学势热图统一生成器 v5.0",
143
+ formatter_class=argparse.RawDescriptionHelpFormatter,
144
+ epilog="""
145
+ 使用示例:
146
+ # API模式 - 下载CuAgOSe数据(默认)
147
+ chemphase
148
+
149
+ # 指定API模式的元素
150
+ chemphase --elements Li O Co
151
+
152
+ # 本地模式 - 读取VASP计算结果
153
+ chemphase --local /path/to/calculations --elements Cu Ag O Se
154
+
155
+ # 混合模式 - 本地数据为主
156
+ chemphase --local /path/to/data --elements Cu Ag O Se
157
+
158
+ # 启用结构对比
159
+ chemphase --local /path/to/data --elements Cu Ag O Se --compare-structure
160
+ """
161
+ )
162
+ parser.add_argument('--local', type=str, help='本地VASP计算结果目录')
163
+ parser.add_argument('--elements', nargs='+', help='目标元素列表(如 Cu Ag O Se)')
164
+ parser.add_argument('--output', default='phase_diagrams_output', help='输出目录 (默认: phase_diagrams_output)')
165
+ parser.add_argument('--eah', type=float, default=0.05, help='Energy above hull 阈值 (默认: 0.05 eV/atom)')
166
+ parser.add_argument('--compare-structure', action='store_true', help='启用本地结构 vs MP数据库对比')
167
+ parser.add_argument('--debug', action='store_true', help='调试模式')
168
+
169
+ args = parser.parse_args()
170
+
171
+ print_banner()
172
+
173
+ config = PhaseDiagramConfig(
174
+ eah_threshold=args.eah,
175
+ output_root=args.output,
176
+ local_dir=Path(args.local) if args.local else None,
177
+ compare_structure=args.compare_structure,
178
+ debug=args.debug
179
+ )
180
+
181
+ if args.local:
182
+ if not args.elements:
183
+ print("错误: 本地模式需要指定 --elements")
184
+ sys.exit(1)
185
+ ok, valid, errors = validate_elements(args.elements)
186
+ if not ok:
187
+ print("错误: " + ", ".join(errors))
188
+ sys.exit(1)
189
+ run_local_mode(config, valid, args.output)
190
+ else:
191
+ ensure_api_key(config)
192
+ elements = args.elements if args.elements else DEFAULT_ELEMENTS
193
+ ok, valid, errors = validate_elements(elements)
194
+ if not ok:
195
+ print("错误: " + ", ".join(errors))
196
+ sys.exit(1)
197
+ run_api_mode(config, valid, args.output)
198
+
199
+ print("\n" + "=" * 60)
200
+ print(" 执行完成")
201
+ print("=" * 60)
202
+
203
+
204
+ if __name__ == "__main__":
205
+ main()