处理 CP2K 输出文件的 Python 工具
项目描述
cp2k-输出工具
模块化 CP2K 输出文件解析器,主要以正则表达式的形式加上其他工具来处理各种 CP2K 输出:
cp2kparse...解析 CP2K 输出(对于重新启动和输入文件,请查看cp2k-input-tools项目)并允许轻松选择常用值。xyz_restart_parser...当在 MD 期间发生重新启动时,您可能最终会在轨迹中出现重复的帧,这个工具会过滤它们(并且可以轻松处理大文件)cp2k_bs2csv... 将 CP2K 能带结构文件转换为多个(每组一个)CSV 文件,以便于绘图。如果您需要将能带结构数据导入您的应用程序,还可以使用 API。cp2k_pdos... 在 CP2K PDOS 输出的规则网格上应用高斯卷积,并生成 CSV 文件以进行进一步处理或绘图。相同的网格用于所有输入文件,并自动确定网格的最小值/最大值,但不会对不同的投影进行求和。
要求
- Python 3.6+
- 正则表达式 2021+
- 点击 8+
- numpy 1.19+
- 可选:ruamel.yaml
用于开发:https ://poetry.eustace.io/ https://pytest.org/
用法:cp2kparse
有一个简单的命令行界面cp2kparse:
$ cp2kparse --help
Usage: cp2kparse [OPTIONS] [FILE|-]
Parse the CP2K output FILE and return a structured output
Options:
-f, --format [json|yaml|highlight]
Output format (json or yaml are structure
formats, highlight shows which lines of the
output have been matched)
--color [auto|always] When to colorize output
-s, --safe-keys generate 'safe' key names (e.g. without
spaces, dashes, ..)
-S, --statistics print some statistics to stderr
-k, --key <PATH> Path, ex.: 'energies/total force_eval'
--help Show this message and exit.
$ cp2kparse calc.out
{
"cp2k": {
"cp2kflags: libint fftw3 libxc xsmm spglib": " ",
"data directory path": "/data/tiziano/cp2k/data",
"input file name": "Si-supercell-001.inp",
"is freely available from": "https://www.cp2k.org/",
"program compiled at": "Mon Sep 16 14:42:43 CEST 2019",
"program compiled for": "local",
"program compiled on": "tcpc18",
"source code revision number": "git:43f50e2",
"version string": "CP2K version 7.0 (Development Version)"
},
"dbcsr": {
"cpu multiplication driver": "XSMM",
"maximum elements for images": "UNLIMITED",
"multiplication size stacks": 3,
"multiplication stack size": 1000,
"multiplicative factor virtual images": 1,
"multrec recursion limit": 512,
"use multiplication densification": true
},
"energies": {
"total force_eval": -251.6873903110507
},
"global": {
"all-to-all communication in single precision": false,
"basis set file name": "BASIS_MOLOPT",
"coordinate file name": "__STD_INPUT__",
"cpu model name": "Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz",
"cpuid": 1002,
"ffts using library dependent lengths": false,
"force environment number": 1,
"global print level": "MEDIUM",
"method name": "CP2K",
"mm potential file name": "MM_POTENTIAL",
"mpi i/o enabled": true,
"number of threads for this process": 1,
"potential file name": "POTENTIAL",
"preferred diagonalization lib.": "SL",
"preferred fft library": "FFTW3",
"project name": "Si-supercell-001",
"run type": "ENERGY_FORCE",
"this output is from process": 0,
"total number of message passing processes": 1
},
"mulliken population analysis": {
"per atom": [
{
"charge": 7e-06,
"element": "Si",
"kind": 1,
"population": 3.999993
},
{
"charge": 0.0,
"element": "Si",
"kind": 1,
"population": 4.0
},
{
"charge": -0.0,
"element": "Si",
"kind": 1,
"population": 4.0
},
{
"charge": -1e-06,
"element": "Si",
"kind": 1,
"population": 4.000001
},
{
"charge": -0.0,
"element": "Si",
"kind": 1,
"population": 4.0
},
{
"charge": -1e-06,
"element": "Si",
"kind": 1,
"population": 4.000001
},
{
"charge": -1e-06,
"element": "Si",
"kind": 1,
"population": 4.000001
},
{
"charge": -0.0,
"element": "Si",
"kind": 1,
"population": 4.0
},
{
"charge": 0.000137,
"element": "Si",
"kind": 1,
"population": 3.999863
},
{
"charge": -2e-05,
"element": "Si",
"kind": 1,
"population": 4.00002
},
{
"charge": -0.000133,
"element": "Si",
"kind": 1,
"population": 4.000133
},
{
"charge": 2.1e-05,
"element": "Si",
"kind": 1,
"population": 3.999979
},
{
"charge": -0.000133,
"element": "Si",
"kind": 1,
"population": 4.000133
},
{
"charge": 2.1e-05,
"element": "Si",
"kind": 1,
"population": 3.999979
},
{
"charge": 0.000137,
"element": "Si",
"kind": 1,
"population": 3.999863
},
{
"charge": -2e-05,
"element": "Si",
"kind": 1,
"population": 4.00002
},
{
"charge": -3.9e-05,
"element": "Si",
"kind": 1,
"population": 4.000039
},
{
"charge": 3.6e-05,
"element": "Si",
"kind": 1,
"population": 3.999964
},
{
"charge": -1e-05,
"element": "Si",
"kind": 1,
"population": 4.00001
},
{
"charge": 1e-05,
"element": "Si",
"kind": 1,
"population": 3.99999
},
{
"charge": -3.9e-05,
"element": "Si",
"kind": 1,
"population": 4.000039
},
{
"charge": 3.6e-05,
"element": "Si",
"kind": 1,
"population": 3.999964
},
{
"charge": -1e-05,
"element": "Si",
"kind": 1,
"population": 4.00001
},
{
"charge": 1e-05,
"element": "Si",
"kind": 1,
"population": 3.99999
},
{
"charge": -3.9e-05,
"element": "Si",
"kind": 1,
"population": 4.000039
},
{
"charge": 3.6e-05,
"element": "Si",
"kind": 1,
"population": 3.999964
},
{
"charge": -3.9e-05,
"element": "Si",
"kind": 1,
"population": 4.000039
},
{
"charge": 3.6e-05,
"element": "Si",
"kind": 1,
"population": 3.999964
},
{
"charge": -1e-05,
"element": "Si",
"kind": 1,
"population": 4.00001
},
{
"charge": 1e-05,
"element": "Si",
"kind": 1,
"population": 3.99999
},
{
"charge": -1e-05,
"element": "Si",
"kind": 1,
"population": 4.00001
},
{
"charge": 1e-05,
"element": "Si",
"kind": 1,
"population": 3.99999
},
{
"charge": 6e-06,
"element": "Si",
"kind": 1,
"population": 3.999994
},
{
"charge": 3.5e-05,
"element": "Si",
"kind": 1,
"population": 3.999965
},
{
"charge": 3.3e-05,
"element": "Si",
"kind": 1,
"population": 3.999967
},
{
"charge": 9e-06,
"element": "Si",
"kind": 1,
"population": 3.999991
},
{
"charge": 3.3e-05,
"element": "Si",
"kind": 1,
"population": 3.999967
},
{
"charge": 9e-06,
"element": "Si",
"kind": 1,
"population": 3.999991
},
{
"charge": 3e-06,
"element": "Si",
"kind": 1,
"population": 3.999997
},
{
"charge": -0.000312,
"element": "Si",
"kind": 1,
"population": 4.000312
},
{
"charge": 3e-06,
"element": "Si",
"kind": 1,
"population": 3.999997
},
{
"charge": -0.000311,
"element": "Si",
"kind": 1,
"population": 4.000311
},
{
"charge": 3.4e-05,
"element": "Si",
"kind": 1,
"population": 3.999966
},
{
"charge": 1e-05,
"element": "Si",
"kind": 1,
"population": 3.99999
},
{
"charge": 3.4e-05,
"element": "Si",
"kind": 1,
"population": 3.999966
},
{
"charge": 1e-05,
"element": "Si",
"kind": 1,
"population": 3.99999
},
{
"charge": 6e-06,
"element": "Si",
"kind": 1,
"population": 3.999994
},
{
"charge": 3.5e-05,
"element": "Si",
"kind": 1,
"population": 3.999965
},
{
"charge": -9e-06,
"element": "Si",
"kind": 1,
"population": 4.000009
},
{
"charge": -3.3e-05,
"element": "Si",
"kind": 1,
"population": 4.000033
},
{
"charge": 0.000308,
"element": "Si",
"kind": 1,
"population": 3.999692
},
{
"charge": -4e-06,
"element": "Si",
"kind": 1,
"population": 4.000004
},
{
"charge": -3.6e-05,
"element": "Si",
"kind": 1,
"population": 4.000036
},
{
"charge": -7e-06,
"element": "Si",
"kind": 1,
"population": 4.000007
},
{
"charge": -9e-06,
"element": "Si",
"kind": 1,
"population": 4.000009
},
{
"charge": -3.3e-05,
"element": "Si",
"kind": 1,
"population": 4.000033
},
{
"charge": -8e-06,
"element": "Si",
"kind": 1,
"population": 4.000008
},
{
"charge": -3.3e-05,
"element": "Si",
"kind": 1,
"population": 4.000033
},
{
"charge": -3.5e-05,
"element": "Si",
"kind": 1,
"population": 4.000035
},
{
"charge": -6e-06,
"element": "Si",
"kind": 1,
"population": 4.000006
},
{
"charge": 0.000308,
"element": "Si",
"kind": 1,
"population": 3.999692
},
{
"charge": -4e-06,
"element": "Si",
"kind": 1,
"population": 4.000004
},
{
"charge": -8e-06,
"element": "Si",
"kind": 1,
"population": 4.000008
},
{
"charge": -3.3e-05,
"element": "Si",
"kind": 1,
"population": 4.000033
}
],
"total": {
"charge": 0.0,
"population": 256.0
}
},
"program info": {
"ended at": "2019-09-17 17:02:35.738",
"process id": "23773",
"ran by": "tiziano",
"ran on": "tcpc18",
"started at": "2019-09-17 17:01:19.273",
"started by": "tiziano",
"started in": "/users/tiziano/work/phonopy/example/Si-CP2K",
"started on": "tcpc18",
"stopped in": "/users/tiziano/work/phonopy/example/Si-CP2K"
}
}
和一个 API:
from cp2k_output_tools import parse_iter
with open("calc.out", "r") as fhandle:
for match in parse_iter(fhandle.read()):
print(match.values)
用法:xyz_restart_cleaner
$ xyz_restart_cleaner orig_trajectory.xyz new_trajectory.xyz
found restart point @1, dropping 1 frames, flushing 1
flushing remaining 2 frames
用法:cp2k_bs2csv
给定一个.bs由 CP2K 编写的文件,脚本将.set-X.csv在与源文件相同的目录中生成具有相同名称和后缀的 CSV 文件:
$ cp2k_bs2csv WO3.bs
writing point set WO3.bs.set-1.csv (total number of k-points: 11)
with the following special points:
GAMMA: 0.00000000 / 0.00000000 / 0.00000000
X: 0.00000000 / 0.50000000 / 0.00000000
writing point set WO3.bs.set-2.csv (total number of k-points: 11)
with the following special points:
X: 0.00000000 / 0.50000000 / 0.00000000
M: 0.50000000 / 0.50000000 / 0.00000000
writing point set WO3.bsset-3.csv (total number of k-points: 11)
with the following special points:
M: 0.50000000 / 0.50000000 / 0.00000000
GAMMA: 0.00000000 / 0.00000000 / 0.00000000
writing point set WO3.bs.set-4.csv (total number of k-points: 11)
with the following special points:
GAMMA: 0.00000000 / 0.00000000 / 0.00000000
R: 0.50000000 / 0.50000000 / 0.50000000
writing point set WO3.bs.set-5.csv (total number of k-points: 11)
with the following special points:
R: 0.50000000 / 0.50000000 / 0.50000000
X: 0.00000000 / 0.50000000 / 0.00000000
writing point set WO3.bs.set-6.csv (total number of k-points: 11)
with the following special points:
R: 0.50000000 / 0.50000000 / 0.50000000
M: 0.50000000 / 0.50000000 / 0.00000000
$ ls
WO3.cp2k-8.bs WO3.cp2k-8.bs.set-2.csv WO3.cp2k-8.bs.set-4.csv WO3.cp2k-8.bs.set-6.csv
WO3.cp2k-8.bs.set-1.csv WO3.cp2k-8.bs.set-3.csv WO3.cp2k-8.bs.set-5.csv
发展
$ poetry install
$ poetry run pytest -v
项目详情
下载文件
下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。
源分布
cp2k-output-tools-0.5.0.tar.gz
(20.4 kB
查看哈希)
内置分布
cp2k_output_tools-0.5.0-py3-none-any.whl
(22.7 kB
查看哈希)
关
cp2k_output_tools -0.5.0-py3-none-any.whl 的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | 8269ede667cf2eeaa1a55c8651a1c1921a549df796e098e52d68ef90815c8986 |
|
| MD5 | 6b6108ac9990605370c4863331f29182 |
|
| 布莱克2-256 | 6ff6e711eb52478b1b63baf856f4efd8d6a9c4238a7e96c340250fd1d30cbe1e |