mcta 0.0.34__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.
Potentially problematic release.
This version of mcta might be problematic. Click here for more details.
- mcta/__init__.py +11 -0
- mcta/__main__.py +118 -0
- mcta/_flags.py +375 -0
- mcta/bandplot/dos.py +204 -0
- mcta/bandplot/mass.py +164 -0
- mcta/bandplot/ph.py +1437 -0
- mcta/bandplot/ph3.py +893 -0
- mcta/bandplot/ph3doc.py +232 -0
- mcta/bandplot/phdoc.py +256 -0
- mcta/bandplot/phdos.py +193 -0
- mcta/bandplot/phono3py_docs.json +1361 -0
- mcta/bandplot/phonopy_docs.json +3295 -0
- mcta/bandplot/plots.py +576 -0
- mcta/bandplot/pplots.py +439 -0
- mcta/bandplot/projected.py +220 -0
- mcta/bandplot/readdata.py +174 -0
- mcta/bandplot/vaspread.py +1047 -0
- mcta/bandplot/wrapper.py +842 -0
- mcta/mc/engine.py +1137 -0
- mcta/mc/geometry/__init__.py +55 -0
- mcta/mc/geometry/bilayer_aa.py +183 -0
- mcta/mc/geometry/bilayer_ab.py +275 -0
- mcta/mc/geometry/bilayer_ab_u_3.py +211 -0
- mcta/mc/geometry/from_structure.py +328 -0
- mcta/mc/geometry/simple_cubic.py +119 -0
- mcta/mc/geometry/square.py +190 -0
- mcta/mc/geometry/triangular.py +195 -0
- mcta/mc/geometry/xy_geometry.py +238 -0
- mcta/mc/parallel.py +160 -0
- mcta/mc/plots.py +303 -0
- mcta/mc/wrapper.py +287 -0
- mcta/mc/xy_engine.py +393 -0
- mcta/seek/agent.py +283 -0
- mcta/seek/cli.py +359 -0
- mcta/seek/config.py +181 -0
- mcta/seek/curate.py +651 -0
- mcta/seek/llm.py +42 -0
- mcta/seek/ml.py +230 -0
- mcta/seek/sqs.py +504 -0
- mcta/seek/state.py +70 -0
- mcta/seek/tools.py +776 -0
- mcta/server/3Dmol.LICENSE.txt +90 -0
- mcta/server/3dmol-min.js +2 -0
- mcta/server/__init__.py +1415 -0
- mcta/server/_handlers.py +1845 -0
- mcta/server/_page.py +11 -0
- mcta/server/_remote.py +2218 -0
- mcta/server/_structure.py +606 -0
- mcta/server/_terminal.py +233 -0
- mcta/server/_util.py +559 -0
- mcta/server/app.css +589 -0
- mcta/server/app.js +3815 -0
- mcta/server/page.html +418 -0
- mcta/server/viewer.js +5814 -0
- mcta/server/xterm.LICENSE.txt +21 -0
- mcta/server/xterm.css +218 -0
- mcta/server/xterm.js +8 -0
- mcta/sh/cli.py +222 -0
- mcta/sh/scripts/ck.sh +5 -0
- mcta/sh/scripts/cp.sh +3 -0
- mcta/sh/scripts/en.sh +3 -0
- mcta/sh/scripts/ex.sh +6 -0
- mcta/sh/scripts/gr.sh +5 -0
- mcta/sh/scripts/ig.sh +8 -0
- mcta/sh/scripts/il.sh +8 -0
- mcta/sh/scripts/kb.sh +48 -0
- mcta/sh/scripts/kg.sh +18 -0
- mcta/sh/scripts/make_supercell.py +249 -0
- mcta/sh/scripts/md.sh +24 -0
- mcta/sh/scripts/mv.sh +3 -0
- mcta/sh/scripts/po.sh +80 -0
- mcta/sh/scripts/pr.sh +3 -0
- mcta/sh/scripts/re.sh +5 -0
- mcta/sh/scripts/sh.sh +3 -0
- mcta/sh/scripts/su.sh +15 -0
- mcta/sh/scripts/sy.sh +42 -0
- mcta/sh/scripts/symmetry_info.py +266 -0
- mcta/sh/scripts/x.sh +32 -0
- mcta/sh/scripts/xy.sh +36 -0
- mcta/sh/scripts/y.sh +32 -0
- mcta/sh/scripts/z2.sh +44 -0
- mcta/sh/scripts/z2_convert.py +247 -0
- mcta/skl/__init__.py +4 -0
- mcta/skl/cli.py +70 -0
- mcta/sqs/__init__.py +4 -0
- mcta/sqs/cli.py +141 -0
- mcta-0.0.34.dist-info/METADATA +187 -0
- mcta-0.0.34.dist-info/RECORD +92 -0
- mcta-0.0.34.dist-info/WHEEL +5 -0
- mcta-0.0.34.dist-info/entry_points.txt +14 -0
- mcta-0.0.34.dist-info/licenses/LICENSE +21 -0
- mcta-0.0.34.dist-info/top_level.txt +1 -0
mcta/__init__.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""McTa —— Meta Crystal Toolkit & Analysis"""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import platform
|
|
5
|
+
|
|
6
|
+
__version__ = "0.0.34"
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def version_string() -> str:
|
|
10
|
+
"""统一的 -V 输出格式。"""
|
|
11
|
+
return "McTa (Meta Crystal Toolkit & Analysis) " + __version__ + " from " + os.path.dirname(__file__) + ' (python' + platform.python_version() + ')'
|
mcta/__main__.py
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"""mt:命令统一入口,负责说明用途并把参数原样转给对应的工具。
|
|
2
|
+
|
|
3
|
+
mt < band | dos | phband | phdos | ph | ph3 | seek | skl | sqs | mc | sh | server > [参数]
|
|
4
|
+
等价于 mt.band | mt.dos | mt.phband | mt.phdos | mt.ph | mt.ph3 | mt.seek mt.skl | mt.sqs | mt.sh | mt.server [参数]
|
|
5
|
+
|
|
6
|
+
环境变量(也可写入 ~/.config/mcta/config,KEY=VALUE;环境变量优先):
|
|
7
|
+
|
|
8
|
+
绘图(mt.band / mt.dos / mt.phband / mt.phdos / mt.mc):
|
|
9
|
+
MT_FONT_FAMILY 字体族,默认 STIXGeneral
|
|
10
|
+
MT_MATHTEXT_FONTSET 数学文本字体集,默认 cm
|
|
11
|
+
MT_RESOL 图片 DPI,默认 500
|
|
12
|
+
MT_XTICK_DIRECTION x 轴刻度方向,默认 in
|
|
13
|
+
MT_YTICK_DIRECTION y 轴刻度方向,默认 in
|
|
14
|
+
|
|
15
|
+
结构检索与描述符分析(mt.seek / mt.sqs / mt.skl 共用工作目录与配置文件设置):
|
|
16
|
+
MP_API_KEY Materials Project 密钥(在线检索必填)
|
|
17
|
+
MT_SEEK_HOME 工作根目录,默认当前目录
|
|
18
|
+
MT_SEEK_CONFIG 配置文件路径,默认 ~/.config/mcta/config
|
|
19
|
+
MT_SEEK_API_KEY LLM 密钥(所有引擎统一使用,自然语言模式)
|
|
20
|
+
MT_SEEK_PROVIDER LLM 引擎,默认 openai;可选 deepseek/qwen/glm/kimi/siliconflow/gemini/openrouter/ollama/vllm
|
|
21
|
+
MT_SEEK_BASE_URL 覆盖所选 LLM 引擎的 API 端点
|
|
22
|
+
MT_SEEK_MODEL 覆盖所选 LLM 引擎的模型
|
|
23
|
+
MT_SEEK_MAX_TURNS LLM 最大交互轮数,默认 30
|
|
24
|
+
MT_SEEK_MAX_CAND LLM 最大候选结构数,默认 20
|
|
25
|
+
|
|
26
|
+
本地文件与终端服务(mt.server):
|
|
27
|
+
MCTA_REMOTE_SOCKET 远端 mt.server Unix socket 路径,默认 ~/.config/mcta/sock/mcta-render.sock
|
|
28
|
+
MCTA_REMOTE_RENDER_MIN_MB -R 下启用远端 3D 解析的大小阈值 MB,默认 8
|
|
29
|
+
MCTA_REMOTE_LIST_TTL 远端目录列表缓存秒数,默认 1,0 表示关闭
|
|
30
|
+
MCTA_RENDER_CACHE_MAX_MB 3D 渲染缓存容量上限 MB,默认 512
|
|
31
|
+
MCTA_CACHE_FRESH_SECONDS 渲染缓存淘汰保护窗口秒数,默认 30
|
|
32
|
+
MCTA_RENDER_RETRY_SECONDS 远端渲染通道失败后的重试间隔秒数,默认 30
|
|
33
|
+
MCTA_RENDER_TOTAL_SECONDS 单次远端渲染总时长上限秒数,默认 60
|
|
34
|
+
MCTA_XFER_CHANNELS 传输通道数,默认 3(第 3 条只传小文件)
|
|
35
|
+
MCTA_XFER_LARGE_MB 大文件阈值 MB,默认 4
|
|
36
|
+
XDG_CACHE_HOME 缓存根目录(3D 渲染与 -R 文件缓存),默认 ~/.cache
|
|
37
|
+
|
|
38
|
+
其他工具:
|
|
39
|
+
MT_PH_DOCS mt.ph 自定义词库 JSON 路径
|
|
40
|
+
MT_PH3_DOCS mt.ph3 自定义词库 JSON 路径
|
|
41
|
+
MTSH_SCRIPTS mt.sh 自定义脚本目录(本地 ./NAME.sh 优先)
|
|
42
|
+
PBE_PATH PBE 赝势目录(mt.sh/po.sh,优先)
|
|
43
|
+
LDA_PATH LDA 赝势目录(mt.sh/po.sh)
|
|
44
|
+
GGA_PATH GGA 赝势目录(mt.sh/po.sh)
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
import sys
|
|
48
|
+
|
|
49
|
+
from mcta import version_string
|
|
50
|
+
from mcta._flags import TOOLS, _tool, overview, which
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _run(key, argv):
|
|
54
|
+
"""在进程内调用对应入口,参数与 ``<命令> [参数]`` 完全一致。
|
|
55
|
+
|
|
56
|
+
只导入目标命令所需模块:绘图命令才依赖 matplotlib,其他命令在缺少
|
|
57
|
+
绘图依赖时也应可用(例如 ``mt seek -h`` / ``mt server``)。
|
|
58
|
+
"""
|
|
59
|
+
entry = {}
|
|
60
|
+
if key in ("band", "dos", "phband", "phdos", "ph", "ph3"):
|
|
61
|
+
from mcta.bandplot import dos, ph, ph3, phdos, wrapper
|
|
62
|
+
entry.update({"band": wrapper.main, "dos": dos.main, "phband": wrapper.pmain,
|
|
63
|
+
"phdos": phdos.main, "ph": ph.main, "ph3": ph3.main})
|
|
64
|
+
if key == "seek":
|
|
65
|
+
from mcta.seek import cli as seek_cli
|
|
66
|
+
entry["seek"] = seek_cli.main
|
|
67
|
+
elif key == "skl":
|
|
68
|
+
from mcta.skl import cli as skl_cli
|
|
69
|
+
entry["skl"] = skl_cli.main
|
|
70
|
+
elif key == "sqs":
|
|
71
|
+
from mcta.sqs import cli as sqs_cli
|
|
72
|
+
entry["sqs"] = sqs_cli.main
|
|
73
|
+
elif key == "sh":
|
|
74
|
+
from mcta.sh import cli as sh_cli
|
|
75
|
+
entry["sh"] = sh_cli.main
|
|
76
|
+
elif key == "mc":
|
|
77
|
+
from mcta.mc import wrapper as mc_wrapper
|
|
78
|
+
entry["mc"] = mc_wrapper.main
|
|
79
|
+
elif key == "server":
|
|
80
|
+
from mcta.server import main as server_main
|
|
81
|
+
entry["server"] = server_main
|
|
82
|
+
name = _tool(key)["name"]
|
|
83
|
+
saved = sys.argv
|
|
84
|
+
sys.argv = [name] + list(argv)
|
|
85
|
+
try:
|
|
86
|
+
return entry[key]()
|
|
87
|
+
finally:
|
|
88
|
+
sys.argv = saved
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def main(argv=None):
|
|
92
|
+
args = list(sys.argv[1:] if argv is None else argv)
|
|
93
|
+
if not args:
|
|
94
|
+
overview()
|
|
95
|
+
return 0
|
|
96
|
+
|
|
97
|
+
head, rest = args[0], args[1:]
|
|
98
|
+
if head in ("-h", "-H", "--help", "help"):
|
|
99
|
+
print((__doc__ or "").strip())
|
|
100
|
+
print("\n<命令 " + " | ".join(t["key"] for t in TOOLS) + " >")
|
|
101
|
+
print("\nmt <命令> -h 查看该命令的参数;mt -v 版本;mt which 查看安装位置")
|
|
102
|
+
return 0
|
|
103
|
+
if head in ("-v", "-V", "--version", "version"):
|
|
104
|
+
print(version_string())
|
|
105
|
+
return 0
|
|
106
|
+
if head in ("which", "where"):
|
|
107
|
+
return which()
|
|
108
|
+
|
|
109
|
+
if _tool(head) is None:
|
|
110
|
+
print("ERROR: 未知命令 %r。" % head)
|
|
111
|
+
print("可用:mt / mt band / mt dos / mt phband / mt phdos / mt ph / mt ph3 / mt seek / mt skl / mt sqs / mt sh / mt mc / mt which / mt -v/-V")
|
|
112
|
+
return 2
|
|
113
|
+
result = _run(head, rest)
|
|
114
|
+
return result if isinstance(result, int) else 0
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
if __name__ == "__main__":
|
|
118
|
+
sys.exit(main())
|
mcta/_flags.py
ADDED
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
"""mt 的子命令表、总览、参数转发与绘图配置。
|
|
2
|
+
|
|
3
|
+
命令行入口与帮助文本在 mcta/__main__.py;这里只提供它需要的表格与函数。
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import glob
|
|
7
|
+
import os
|
|
8
|
+
import platform
|
|
9
|
+
import shutil
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
from mcta import __version__
|
|
13
|
+
|
|
14
|
+
# 命令表:短名 -> (可执行文件名, 说明, 数据来源, 示例)
|
|
15
|
+
TOOLS = (
|
|
16
|
+
{
|
|
17
|
+
"key": "band",
|
|
18
|
+
"name": "mt.band",
|
|
19
|
+
"what": "电子能带 / 态密度",
|
|
20
|
+
"source": "VASP 的 vasprun.xml、EIGENVAL、DOSCAR、PROCAR,或 vaspkit 的 BAND*/PDOS*.dat",
|
|
21
|
+
"examples": (
|
|
22
|
+
("mt.band -i calc", "当前目录/指定目录的能带"),
|
|
23
|
+
("mt.band -i calc -d", "能带 + 态密度(并排)"),
|
|
24
|
+
("mt.band -i calc -r -p Mo-d", "投影能带(PROCAR)"),
|
|
25
|
+
),
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"key": "dos",
|
|
29
|
+
"name": "mt.dos",
|
|
30
|
+
"what": "态密度(DOS / PDOS,Energy 为横轴)",
|
|
31
|
+
"source": "VASP 的 DOSCAR,或 vaspkit 的 PDOS*.dat / TDOS*.dat",
|
|
32
|
+
"examples": (
|
|
33
|
+
("mt.dos -i calc", "DOSCAR 或 PDOS*.dat 画 DOS(横轴 Energy)"),
|
|
34
|
+
("mt.dos -i calc -p d", "只画 d 轨道投影"),
|
|
35
|
+
("mt.dos -i calc -n", "交换坐标轴,纵轴 Energy(同 mt.band -d 面板)"),
|
|
36
|
+
),
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"key": "phband",
|
|
40
|
+
"name": "mt.phband",
|
|
41
|
+
"what": "声子能带",
|
|
42
|
+
"source": "phonopy-bandplot 写出的 BAND.dat(-i 可给多个文件对比)",
|
|
43
|
+
"examples": (
|
|
44
|
+
("mt.phband -i BAND.dat", "声子能带"),
|
|
45
|
+
("mt.phband -i BAND.dat -d", "声子能带 + 声子态密度(并排)"),
|
|
46
|
+
("mt.phband -B 23 100 -y -2 110", "断轴显示光学支"),
|
|
47
|
+
),
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"key": "phdos",
|
|
51
|
+
"name": "mt.phdos",
|
|
52
|
+
"what": "声子态密度(Frequency 为横轴)",
|
|
53
|
+
"source": "phonopy 的 projected_dos.dat / total_dos.dat",
|
|
54
|
+
"examples": (
|
|
55
|
+
("mt.phdos", "当前目录的 DOS 文件"),
|
|
56
|
+
("mt.phdos -i calc -z", "填充曲线"),
|
|
57
|
+
("mt.phdos -i calc -n", "交换坐标轴,纵轴 Frequency(同 mt.phband -d 面板)"),
|
|
58
|
+
),
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"key": "ph",
|
|
62
|
+
"name": "mt.ph",
|
|
63
|
+
"what": "phonopy 流程引导",
|
|
64
|
+
"source": "POSCAR/CONTCAR + VASP 力计算输出(vasprun.xml)",
|
|
65
|
+
"examples": (
|
|
66
|
+
("mt.ph -b -d", "写 band.conf 与 mesh.conf"),
|
|
67
|
+
("mt.ph fs vasprun.xml", "单份力文件计算力常数"),
|
|
68
|
+
("mt.ph w --dim", "离线查用法:先英文原文,后中文翻译"),
|
|
69
|
+
),
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"key": "ph3",
|
|
73
|
+
"name": "mt.ph3",
|
|
74
|
+
"what": "phono3py 热导率流程引导",
|
|
75
|
+
"source": "POSCAR-unitcell + VASP 力计算输出(vasprun.xml)",
|
|
76
|
+
"examples": (
|
|
77
|
+
("mt.ph3 -s 2 2 2 -S 4 4 4", "fc3/fc2 超胞 + 位移"),
|
|
78
|
+
("mt.ph3 cf3 -n disp-{00001..00755}", "收集力 -> FORCES_FC3"),
|
|
79
|
+
("mt.ph3 kappa -m 11 11 11", "RTA 热导率 -> kappa-m*.hdf5"),
|
|
80
|
+
),
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"key": "seek",
|
|
84
|
+
"name": "mt.seek",
|
|
85
|
+
"what": "MP 结构检索 / 策展",
|
|
86
|
+
"source": "Materials Project API(mp-api)",
|
|
87
|
+
"examples": (
|
|
88
|
+
("mt.seek -c Ti-C -k 3", "按化学体系检索近稳定相并导出结构包"),
|
|
89
|
+
("mt.seek -f MoS2 -k 5 -F cif,poscar", "按化学式检索,只留 CIF/POSCAR"),
|
|
90
|
+
("mt.seek -w \"ehull<=0.05 and is_2d\"", "规则筛选本地已下载结构(-R 预览)"),
|
|
91
|
+
),
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"key": "skl",
|
|
95
|
+
"name": "mt.skl",
|
|
96
|
+
"what": "scikit-learn 结构清单分析",
|
|
97
|
+
"source": "工作根下 <name>/manifest.csv(离线,不联网)",
|
|
98
|
+
"examples": (
|
|
99
|
+
("mt.skl", "随机森林预测 ehull 与带隙,输出 <home>/ml/"),
|
|
100
|
+
("mt.skl --home .", "指定工作根目录(默认当前目录)"),
|
|
101
|
+
),
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"key": "sqs",
|
|
105
|
+
"name": "mt.sqs",
|
|
106
|
+
"what": "自定义晶胞 → 准随机固溶体(SQS)",
|
|
107
|
+
"source": "sqsgenerator(C++ 引擎,不联网、不需要 MP_API_KEY)",
|
|
108
|
+
"examples": (
|
|
109
|
+
("mt.sqs -c cell.vasp -a \"Cu:0.5,Au:0.5\"", "CuAu 等比合金,默认 3³ 超胞 + 10 万次迭代"),
|
|
110
|
+
("mt.sqs -c LaAlO3.cif --host La -a \"La:0.5,Sr:0.5\"", "A 位随机化,Al/O 保持不变"),
|
|
111
|
+
("mt.sqs -c cell.vasp -a Cu,Au -R", "预览:只搜索、不写盘"),
|
|
112
|
+
),
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
"key": "mc",
|
|
116
|
+
"name": "mt.mc",
|
|
117
|
+
"what": "自旋(Ising/Heisenberg)蒙特卡洛模拟,内置晶格或从晶体结构自动构建",
|
|
118
|
+
"source": "内置方形/三角/双层……模型,或任意晶体结构的原子邻居图(需要 numba:pip install mcta[mc])",
|
|
119
|
+
"examples": (
|
|
120
|
+
("mt.mc -h", "全部参数"),
|
|
121
|
+
("mt.mc -x 100 -y 100 -t 35", "方格子 100×100,0–34 K 共 35 个温度"),
|
|
122
|
+
("mt.mc -s POSCAR -A Fe -D 2.7 3.2 -x 2 -y 2 -z 2", "从 POSCAR 构建超胞 + Fe 原子邻居图,两通道"),
|
|
123
|
+
),
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"key": "sh",
|
|
127
|
+
"name": "mt.sh",
|
|
128
|
+
"what": "执行内置*.sh脚本",
|
|
129
|
+
"source": "随包分发的 scripts/ 目录脚本",
|
|
130
|
+
"examples": (
|
|
131
|
+
("mt.sh", "列出可用脚本及来源"),
|
|
132
|
+
("mt.sh xy", "执行内置 xy.sh(参数原样转给脚本)"),
|
|
133
|
+
),
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"key": "server",
|
|
137
|
+
"name": "mt.server",
|
|
138
|
+
"what": "本地文件与终端服务:浏览目录、编辑文本、查看图片、SSH 级终端",
|
|
139
|
+
"source": "以当前用户身份运行,可访问该用户有权限的所有文件;每次启动生成随机 token 写入 URL,默认只监听 127.0.0.1",
|
|
140
|
+
"examples": (
|
|
141
|
+
("mt.server", "后台启动,地址与 token 在启动后打印"),
|
|
142
|
+
("mt.server -p 8080", "指定端口"),
|
|
143
|
+
("mt.server -R user@host:22 -d /home/user/project", "SSH/SFTP 浏览远程服务器(用户/端口可省,先探测再安全提示密码)"),
|
|
144
|
+
("mt.server -R user@host -P 9069 -p 9068", "远端 TCP 端口转发到本地 -p(强制 token)"),
|
|
145
|
+
("mt.server -R user@host --socket -p 9068", "远端 Unix socket 转发到本地 -p(token 可选)"),
|
|
146
|
+
("mt.server -f", "前台运行,Ctrl+C 停止"),
|
|
147
|
+
("mt.server -S", "停止后台服务"),
|
|
148
|
+
),
|
|
149
|
+
},
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
# 总览分组:每组两行解释 + 三条示例;TOOLS 仍是完整的命令表(_tool / which 使用)。
|
|
153
|
+
GROUPS = (
|
|
154
|
+
{
|
|
155
|
+
"title": "能带 / 态密度绘图",
|
|
156
|
+
"names": "mt.band mt.dos mt.phband mt.phdos",
|
|
157
|
+
"lines": (
|
|
158
|
+
"电子与声子的能带和态密度绘图:band / phband 画能带,dos / phdos 画态密度,可并排、投影或交换坐标轴。",
|
|
159
|
+
"数据来源:vasprun.xml / EIGENVAL / DOSCAR / PROCAR、vaspkit BAND*/PDOS*.dat,以及 phonopy BAND.dat / total_dos.dat。",
|
|
160
|
+
),
|
|
161
|
+
"examples": (
|
|
162
|
+
("mt.band -i calc -d", "电子能带 + 态密度并排"),
|
|
163
|
+
("mt.dos -i calc -p d", "d 轨道投影态密度(Energy 横轴)"),
|
|
164
|
+
("mt.phband -i BAND.dat -d", "声子能带 + 声子态密度"),
|
|
165
|
+
),
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
"title": "声子流程",
|
|
169
|
+
"names": "mt.ph mt.ph3",
|
|
170
|
+
"lines": (
|
|
171
|
+
"phonopy / phono3py 流程引导:写计算配置、收集力、求力常数,再衔接声子能带/态密度或热导率。",
|
|
172
|
+
"数据来源:POSCAR / CONTCAR + VASP 力计算输出 vasprun.xml;ph3 另需 POSCAR-unitcell 与位移、力文件。",
|
|
173
|
+
),
|
|
174
|
+
"examples": (
|
|
175
|
+
("mt.ph -b -d", "生成 band.conf 与 mesh.conf"),
|
|
176
|
+
("mt.ph fs vasprun.xml", "由一份力计算求力常数"),
|
|
177
|
+
("mt.ph3 kappa -m 11 11 11", "RTA 热导率 -> kappa-m*.hdf5"),
|
|
178
|
+
),
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
"title": "结构检索与数据工具",
|
|
182
|
+
"names": "mt.seek mt.skl mt.sqs",
|
|
183
|
+
"lines": (
|
|
184
|
+
"从 Materials Project 检索并策展结构,用 scikit-learn 分析结构清单,或生成准随机固溶体 SQS。",
|
|
185
|
+
"数据来源:MP API(需 MP_API_KEY)、*/manifest.csv(离线)、本地晶胞文件;三者共用 MT_SEEK_HOME 工作目录。",
|
|
186
|
+
),
|
|
187
|
+
"examples": (
|
|
188
|
+
("mt.seek -c Ti-C -k 3", "按化学体系检索近稳定相"),
|
|
189
|
+
("mt.skl", "随机森林预测 ehull 与带隙"),
|
|
190
|
+
('mt.sqs -c cell.vasp -a Cu,Au', "CuAu 等比合金 SQS"),
|
|
191
|
+
),
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
"title": "蒙特卡洛模拟",
|
|
195
|
+
"names": "mt.mc",
|
|
196
|
+
"lines": (
|
|
197
|
+
"自旋(Ising / Heisenberg)蒙特卡洛:内置晶格模型,或从晶体结构的原子邻居图自动构建。",
|
|
198
|
+
"数据来源:内置方形/三角/双层模型或任意晶体结构(POSCAR/CIF);大体系需 numba(pip install mcta[mc])。",
|
|
199
|
+
),
|
|
200
|
+
"examples": (
|
|
201
|
+
("mt.mc -h", "全部参数"),
|
|
202
|
+
("mt.mc -x 100 -y 100 -t 35", "方格子 100×100,0–34 K 共 35 个温度"),
|
|
203
|
+
("mt.mc -s POSCAR -A Fe", "从 POSCAR 构建 Fe 原子邻居图"),
|
|
204
|
+
),
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
"title": "内置脚本",
|
|
208
|
+
"names": "mt.sh",
|
|
209
|
+
"lines": (
|
|
210
|
+
"列出并执行随包分发的 bash 脚本,参数原样转给脚本;本地 ./NAME.sh 优先于内置同名脚本。",
|
|
211
|
+
"脚本来源:mcta/sh/scripts/ 目录;可用 MTSH_SCRIPTS 指定自定义脚本目录。",
|
|
212
|
+
),
|
|
213
|
+
"examples": (
|
|
214
|
+
("mt.sh", "列出可用脚本及来源"),
|
|
215
|
+
("mt.sh xy", "执行内置 xy.sh(参数原样转发)"),
|
|
216
|
+
("mt.sh po", "执行内置 po.sh(赝势相关)"),
|
|
217
|
+
),
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
"title": "本地文件与终端服务",
|
|
221
|
+
"names": "mt.server",
|
|
222
|
+
"lines": (
|
|
223
|
+
"浏览器里浏览目录、编辑文本、查看图片/PDF/3D 结构,并提供与 SSH 一致的交互式终端。",
|
|
224
|
+
"-R 走 SSH/SFTP 浏览远程服务器,支持 u@h:22 / u h 22 / h;用户名默认本机用户,端口默认 22,先非交互探测再安全提示密码。",
|
|
225
|
+
),
|
|
226
|
+
"examples": (
|
|
227
|
+
("mt.server", "后台启动,地址与 token 在启动后打印"),
|
|
228
|
+
("mt.server -p 8080", "指定端口"),
|
|
229
|
+
("mt.server -R u@remote.example:2222 -d /example/project", "SSH/SFTP 浏览远程目录(先探测,密码不回显)"),
|
|
230
|
+
("mt.server -S", "停止后台服务"),
|
|
231
|
+
),
|
|
232
|
+
},
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
_VASP_MARKS = ("EIGENVAL", "DOSCAR", "PROCAR")
|
|
236
|
+
_PHONON_MARKS = ("vasprun.xml", "phonopy_params.yaml", "SPOSCAR",
|
|
237
|
+
"band.yaml", "band.conf", "mesh.conf", "FORCE_SETS",
|
|
238
|
+
"FORCE_CONSTANTS", "projected_dos.dat", "total_dos.dat")
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def _tool(key):
|
|
242
|
+
for tool in TOOLS:
|
|
243
|
+
if tool["key"] == key:
|
|
244
|
+
return tool
|
|
245
|
+
return None
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def _line(text, width=17):
|
|
249
|
+
"""把说明文字按命令行宽度对齐(CJK 字符按两列计)。"""
|
|
250
|
+
shown = sum(2 if ord(ch) > 0x2E80 else 1 for ch in text)
|
|
251
|
+
return text + " " * max(width - shown, 1)
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
_NAME_COL, _ARG_COL = 17, 32
|
|
255
|
+
_IND = " " * (2 + _NAME_COL)
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
# ------------------------------------------------------------------ 概览 ---
|
|
259
|
+
def _detect(directory="."):
|
|
260
|
+
"""按当前目录里的文件猜下一步该用哪个命令,返回 (发现, 建议列表)。"""
|
|
261
|
+
found = [n for n in _VASP_MARKS if os.path.exists(os.path.join(directory, n))]
|
|
262
|
+
phonon = [n for n in _PHONON_MARKS if os.path.exists(os.path.join(directory, n))]
|
|
263
|
+
dat = sorted(os.path.basename(p) for pattern in ("BAND.dat", "PBAND*.dat", "PDOS*.dat")
|
|
264
|
+
for p in glob.glob(os.path.join(directory, pattern)))
|
|
265
|
+
|
|
266
|
+
hints = []
|
|
267
|
+
if found:
|
|
268
|
+
if "EIGENVAL" in found:
|
|
269
|
+
hints.append("mt.band -i . -d" if "DOSCAR" in found
|
|
270
|
+
else "mt.band -i .")
|
|
271
|
+
if "DOSCAR" in found:
|
|
272
|
+
hints.append("mt.dos -i .")
|
|
273
|
+
elif "DOSCAR" in found:
|
|
274
|
+
hints.append("mt.dos")
|
|
275
|
+
else:
|
|
276
|
+
hints.append("mt.band -r -p s,p,d")
|
|
277
|
+
if phonon:
|
|
278
|
+
if any(n in phonon for n in ("band.conf", "mesh.conf")):
|
|
279
|
+
hints.append("mt.ph band" if "band.conf" in phonon else "mt.ph dos")
|
|
280
|
+
elif "phonopy_params.yaml" in phonon:
|
|
281
|
+
hints.append("mt.ph band")
|
|
282
|
+
elif "vasprun.xml" in phonon:
|
|
283
|
+
# vasprun.xml 既可能是能带计算的输出,也可能是声子的力计算
|
|
284
|
+
hints.append("mt.band -i .")
|
|
285
|
+
hints.append("mt.ph -x")
|
|
286
|
+
elif "FORCE_SETS" in phonon or "FORCE_CONSTANTS" in phonon:
|
|
287
|
+
hints.append("mt.ph band")
|
|
288
|
+
if "projected_dos.dat" in phonon or "total_dos.dat" in phonon:
|
|
289
|
+
hints.append("mt.phdos")
|
|
290
|
+
if dat and not found:
|
|
291
|
+
hints.append("mt.band -i ." if any("BAND" in n for n in dat)
|
|
292
|
+
else "mt.dos")
|
|
293
|
+
return found + phonon + dat, hints
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
def overview(directory="."):
|
|
297
|
+
for group in GROUPS:
|
|
298
|
+
print(" " + group["title"] + " " + group["names"])
|
|
299
|
+
for line in group["lines"]:
|
|
300
|
+
print(" " + line)
|
|
301
|
+
for command, note in group["examples"]:
|
|
302
|
+
print(" " + _line(command, _ARG_COL) + note)
|
|
303
|
+
print()
|
|
304
|
+
|
|
305
|
+
print("用法 mt <命令> [参数...] 参数原样转给该命令,如 mt ph -h")
|
|
306
|
+
print(" mt which 命令的安装位置")
|
|
307
|
+
print()
|
|
308
|
+
|
|
309
|
+
found, hints = _detect(directory)
|
|
310
|
+
print("当前目录 %s" % os.path.abspath(directory))
|
|
311
|
+
if found:
|
|
312
|
+
print("发现 " + ", ".join(found))
|
|
313
|
+
if hints:
|
|
314
|
+
print("建议 " + hints[0])
|
|
315
|
+
for hint in hints[1:]:
|
|
316
|
+
print(" " + hint)
|
|
317
|
+
elif not found:
|
|
318
|
+
print("无可识别的 VASP / phonopy 结果文件")
|
|
319
|
+
print("\nMcTa %s %s (python %s)\n" % (__version__, os.path.dirname(os.path.abspath(__file__)),
|
|
320
|
+
platform.python_version()))
|
|
321
|
+
|
|
322
|
+
def which():
|
|
323
|
+
print("McTa %s (python %s)" % (__version__, platform.python_version()))
|
|
324
|
+
names = ("mt",) + tuple(tool["name"] for tool in TOOLS)
|
|
325
|
+
for name in names:
|
|
326
|
+
path = shutil.which(name)
|
|
327
|
+
print(" " + _line(name, 15) + (path or "未找到(当前环境未安装 mt)"))
|
|
328
|
+
return 0 if all(shutil.which(name) for name in names) else 1
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
# ---------------------------------------------------------------- 绘图配置 ---
|
|
332
|
+
# 优先级:环境变量 > ~/.config/mcta/config > 内置默认值。
|
|
333
|
+
_CONFIG_FILE = Path.home() / ".config" / "mcta" / "config"
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
def _read_conf_file(name: str) -> str:
|
|
337
|
+
"""从 ~/.config/mcta/config 读一项(KEY=VALUE 行,# 开头为注释)。"""
|
|
338
|
+
try:
|
|
339
|
+
if not _CONFIG_FILE.is_file():
|
|
340
|
+
return ""
|
|
341
|
+
for line in _CONFIG_FILE.read_text(encoding="utf-8").splitlines():
|
|
342
|
+
line = line.strip()
|
|
343
|
+
if not line or line[0] in "#;" or "=" not in line:
|
|
344
|
+
continue
|
|
345
|
+
k, v = line.split("=", 1)
|
|
346
|
+
if k.strip() == name:
|
|
347
|
+
return v.strip().strip("'\"")
|
|
348
|
+
except OSError:
|
|
349
|
+
pass
|
|
350
|
+
return ""
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
def _get(name: str, default: str) -> str:
|
|
354
|
+
"""环境变量优先,其次配置文件,最后默认值。"""
|
|
355
|
+
return os.environ.get(name) or _read_conf_file(name) or default
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
def font_family() -> str:
|
|
359
|
+
return _get("MT_FONT_FAMILY", "STIXGeneral")
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
def mathtext_fontset() -> str:
|
|
363
|
+
return _get("MT_MATHTEXT_FONTSET", "cm")
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
def resol() -> int:
|
|
367
|
+
return int(_get("MT_RESOL", "500"))
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
def xtick_direction() -> str:
|
|
371
|
+
return _get("MT_XTICK_DIRECTION", "in")
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
def ytick_direction() -> str:
|
|
375
|
+
return _get("MT_YTICK_DIRECTION", "in")
|