Skip to content

chen121760/CHTC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CHTC - Crystal High-Throughput Calculation

高通量晶体结构生成与筛选工作流 v2.0

简介

CHTC 是一个基于 Python 的高通量材料计算工作流工具,用于自动化晶体结构的生成、优化、筛选和分析。集成了 PyXtal、MatterSim 等多个计算材料学库,实现从结构生成到相图分析的完整流程。

主要功能

  • 结构生成:基于 PyXtal 自动生成随机晶体结构
  • 结构去重:基于指纹识别的高效去重算法
  • 批量优化:使用 MatterSim 机器学习力场的真正 GPU 批处理优化
  • 热力学筛选:基于凸胞能(Energy Above Hull)的热力学稳定性分析
  • 声子谱预测:自动识别动力学稳定结构(无虚频)
  • 相图绘制:自动生成二元/三元相图
  • 多 GPU 支持:优化和声子计算支持多 GPU 并行
  • 搜索空间分析:在生成前分析配比数量和空间群兼容性,智能推荐结构数量

快速开始 ⚡

三步上手

# 1. 生成配置文件
chtc -g

# 2. 编辑 chtc.yaml,设置元素、原子数范围等

# 3. 分析搜索空间(推荐!)
chtc -t

# 4. 根据统计结果调整配置文件中的 target_total

# 5. 运行完整流程
chtc -r

完整命令

# 1. 初始化配置
chtc init --config chtc.yaml
# 或使用快捷命令: chtc -g

# 2. 分析搜索空间(推荐!)
chtc analyze-space --config chtc.yaml
# 或使用快捷命令: chtc -t

# 3. 运行完整流程
chtc run --config chtc.yaml --output output/
# 或使用快捷命令: chtc -r

完整工作流程

CHTC v2.0 提供灵活的模块化工作流

标准流程(无热力学筛选)

1. generate      → 生成结构
2. deduplicate   → 去重
3. optimize      → 3步优化 (fmax: 0.1 → 0.02 → 0.002)
4. phonon        → 声子谱预测(动力学稳定性)
5. hull_final    → 凸胞能计算 + 相图绘制

完整流程(含热力学筛选)

1. generate      → 生成结构
2. deduplicate   → 去重
3. optimize      → 3步优化
4. hull_filter   → 第一次凸胞能计算(热力学筛选 Ed < 0.1 eV/atom)
5. standardize   → 标准化结构
6. deduplicate2  → 再次去重
7. phonon        → 声子谱预测(动力学稳定性)
8. hull_final    → 第二次凸胞能计算 + 相图绘制

流程控制:在配置文件中设置 hull_filter.enabled: false/true 来选择标准或完整流程。

安装

# 克隆仓库
git clone https://github.com/your-username/CHTC.git
cd CHTC

# 创建 conda 环境
conda create -n chtc python=3.10
conda activate chtc

# 安装依赖
pip install -e .

# 或手动安装
pip install pyxtal pymatgen mattersim ase spglib numpy pandas pyyaml loguru tqdm

快速开始

推荐工作流程 🌟

# 步骤1: 生成配置文件
chtc -g
# 生成 chtc.yaml 配置文件

# 步骤2: 编辑配置文件
# 设置元素、原子数范围、空间群范围等参数

# 步骤3: 分析搜索空间(重要!)
chtc -t
# 查看配比数量、空间群兼容性统计
# 根据推荐设置 target_total

# 步骤4: 运行完整流程
chtc -r
# 自动执行所有步骤

命令行快捷方式

快捷命令 完整命令 说明
chtc -g chtc init --config chtc.yaml 生成配置文件
chtc -t chtc analyze-space --config chtc.yaml 分析搜索空间
chtc -r chtc run --config chtc.yaml --output output/ 运行完整流程
chtc -h chtc --help 显示帮助信息
chtc -v chtc --version 显示版本信息

1. 初始化配置

# 使用快捷命令
chtc -g

# 或使用完整命令
chtc init --config chtc.yaml

# 生成高级配置模板(包含所有可选参数)
chtc init --config chtc.yaml --advanced

2. 编辑配置文件

# 基本设置
elements: [La, S]
atom_range: [1, 6]
atom_step: 1

# 空间群设置
space_groups: [1-230]

# 结构生成
allocation_mode: total   # 推荐使用 total 模式
target_total: 10000      # 根据 chtc -t 的建议设置

# 优化设置
model_path: MatterSim-v1.0.0-5M.pth
filter: FrechetCellFilter
pressure_GPa: 0.0
multi_gpu: true

# 凸胞能过滤(可选)
hull_filter:
  enabled: false        # true 启用热力学筛选
  threshold_ev: 0.1     # 筛选阈值 (eV/atom)

# 声子谱设置
phonon:
  enabled: true
  supercell: "222"      # 超胞设置
  qmesh: "666"          # q点网格
  find_prim: true       # 搜索原胞

3. 分析搜索空间(推荐!)⭐

在生成结构之前,先分析搜索空间大小:

# 使用快捷命令
chtc -t

# 或使用完整命令
chtc analyze-space --config chtc.yaml

# 导出统计结果
chtc analyze-space --config chtc.yaml --export-json stats.json --export-csv details.csv

输出示例

【基本统计】
  配比总数: 45
  (配比, 空间群) 组合总数: 8,234
  平均每个配比兼容空间群数: 183.0

【结构数量建议】
  保守:   8,234 个结构 (每个组合 1 个)
  适中:  24,702 个结构 (每个组合 3 个)  ← 推荐
  充分:  41,170 个结构 (每个组合 5 个)
  详尽:  82,340 个结构 (每个组合 10 个)

根据建议,在配置文件中设置 target_total

4. 运行完整流程

# 使用快捷命令
chtc -r

# 或使用完整命令
chtc run --config chtc.yaml --output output/

# 断点续算
chtc run --config chtc.yaml --output output/ --resume

5. 运行指定步骤

# 只执行部分步骤
chtc run --config chtc.yaml --output output/ \
    --steps generate deduplicate optimize phonon hull_final

命令行使用

快捷命令总览

chtc -g              # 生成配置文件
chtc -t              # 分析搜索空间
chtc -r              # 运行完整流程
chtc -h              # 显示帮助
chtc -v              # 显示版本

查看帮助

chtc -h                # 查看所有命令
chtc <command> -h      # 查看特定命令的帮助
chtc generate -h       # 查看 generate 命令的参数
chtc phonon -h         # 查看 phonon 命令的参数

单独运行各步骤

# 1. 生成结构
chtc generate --config chtc.yaml --output raw/

# 2. 结构去重
chtc deduplicate --input raw/ --output unique/

# 3. 多步优化
chtc optimize --input unique/ --output opt/ \
    --steps 3 --config chtc.yaml

# 4. 热力学筛选(可选)
chtc hull_filter \
    --relaxed-csv opt/opt3/output_rlx.csv \
    --output-csv hull1/output_hull.csv \
    --output-dir hull1/ \
    --threshold 0.1

# 5. 标准化
chtc standardize --input hull1/stable/ --output std/

# 6. 再次去重
chtc deduplicate --input std/ --output unique2/

# 7. 声子谱预测
chtc phonon --input unique2/ --output phonon/ \
    --supercell 222 --qmesh 666 --find-prim --multi-gpu

# 8. 最终分析(凸胞能 + 相图)
chtc hull_final \
    --phonon-csv phonon/output_phonon.csv \
    --output-csv analysis/output_hull_final.csv \
    --output-dir analysis/ --plot

配置文件说明

完整配置示例

# ============================================================
# CHTC 配置文件
# ============================================================

# 元素设置
elements: [La, S]
atom_range: [1, 6]
atom_step: 1

# 空间群设置
space_groups: [1-230]

# 结构生成分配模式
allocation_mode: per_sg  # per_sg 或 total
structures_per_sg: 10    # per_sg 模式:每个(成分,空间群)组合生成的数量
target_total: 50000      # total 模式:总目标结构数

# 模型设置
model_path: MatterSim-v1.0.0-5M.pth

# 优化设置
optimizer: FIRE
filter: FrechetCellFilter
pressure_GPa: 0.0
max_natoms_per_batch: 512
multi_gpu: true

# 去重设置
deduplicate:
  enabled: true
  mode: simple           # simple 或 crystalnn
  threshold: 0.1

# 凸胞能过滤(热力学筛选)
hull_filter:
  enabled: false         # 设置为 true 启用热力学筛选
  threshold_ev: 0.1      # 筛选阈值 (eV/atom)

# Materials Project 设置
mp_strategy: loose       # loose/cell-only/single-point
fmax_mp: 0.1
steps_mp: 50

# 声子谱设置
phonon:
  enabled: true
  supercell: "222"       # 2x2x2 超胞
  qmesh: "666"           # 6x6x6 q点网格
  find_prim: true        # 搜索原胞

关键参数说明

allocation_mode

  • per_sg:为每个(成分, 空间群)组合生成固定数量的结构

    • 适用于:系统探索所有可能的空间群
    • 参数:structures_per_sg
  • total:总结构数平均分配到所有兼容的(成分, 空间群)组合

    • 适用于:快速生成大量结构
    • 参数:target_total

hull_filter.enabled

  • false(推荐):跳过热力学筛选,直接对所有优化结构进行声子谱预测

    • 流程:5步(generate → deduplicate → optimize → phonon → hull_final)
  • true:先进行热力学筛选,再对稳定结构进行声子谱预测

    • 流程:8步(增加 hull_filter, standardize, deduplicate2)
    • 适用于:结构数量非常大,需要提前过滤

输出目录结构

标准流程 (hull_filter.enabled: false)

output/
├── 01_raw/                        # 生成的原始结构
├── 02_unique/                     # 去重后的结构
├── 03_optimized/
│   ├── opt1/                      # 第一步优化 (fmax=0.1)
│   ├── opt2/                      # 第二步优化 (fmax=0.02)
│   └── opt3/                      # 第三步优化 (fmax=0.002)
│       └── output_rlx.csv         # 优化结果CSV
├── 07_phonon/
│   ├── stable/                    # 动力学稳定的结构
│   ├── fail/                      # 不稳定或失败的结构
│   └── output_phonon.csv          # 声子谱结果CSV
└── 08_analysis/
    ├── output_hull_final.csv      # 凸胞能结果
    └── phase_diagram_La-S.png     # 相图

完整流程 (hull_filter.enabled: true)

output/
├── 01_raw/
├── 02_unique/
├── 03_optimized/
│   └── opt3/
│       └── output_rlx.csv
├── 04_hull_filter/
│   ├── stable/                    # 热力学稳定 (Ed < 0.1)
│   ├── unstable/                  # 热力学不稳定
│   └── output_hull.csv            # 第一次凸胞能计算
├── 05_standardized/               # 标准化后的结构
├── 06_unique_final/               # 再次去重
├── 07_phonon/
│   ├── stable/                    # 动力学稳定
│   ├── fail/
│   └── output_phonon.csv
└── 08_analysis/
    ├── output_hull_final.csv      # 第二次凸胞能计算
    └── phase_diagram_La-S.png

高级功能

多 GPU 并行

# 优化支持多GPU(在配置文件中设置)
multi_gpu: true

# 或命令行指定
chtc optimize --input unique/ --output opt/ --multi-gpu

# 声子谱预测多GPU
chtc phonon --input std/ --output phonon/ --multi-gpu

断点续算

所有步骤都支持断点续算,通过 --resume 参数:

chtc run --config chtc.yaml --output output/ --resume

缓存管理

# 查看缓存统计
chtc cache --stats

# 清空缓存
chtc cache --clear

输出文件说明

output_rlx.csv - 优化结果

列名 说明
chemsys 化学体系 (如 "La-S")
formula 化学式
elements 元素列表
composition 组成(JSON)
natoms 原子数
pressure_GPa 优化压力
fmax 力收敛标准
optimizer 优化器
filter 晶胞过滤器
cell_opt 是否优化晶胞
spacegroup 空间群
total_energy_eV 总能量
energy_per_atom_eV 单位原子能量
converged 是否收敛
n_steps 优化步数
timestamp 时间戳
structure_file 结构文件名

output_phonon.csv - 声子谱结果

列名 说明
structure 结构名称
formula 化学式
natoms 原子数
supercell 超胞设置
primitivecell 是否搜索原胞
qmesh q点网格
has_imaginary 是否有虚频
stable 是否稳定(无虚频)
dev 计算设备
gpu_name GPU名称
gpu_id GPU ID

output_hull_final.csv - 凸胞能结果

列名 说明
structure 结构名称
formula 化学式
elements 元素列表
composition 组成(JSON)
natoms 原子数
n_elem 元素个数
total_energy_eV 总能量
E_f (eV/atom) 形成能
E_d (eV/atom) 凸胞上方能(分解能)
decomp_compositions 分解产物组成
decomp_fractions 分解产物摩尔分数

常见问题

Q: hull_filter 应该启用吗?

推荐:enabled: false(跳过热力学筛选)

原因:

  • 声子谱预测才是最终的稳定性判据(动力学稳定)
  • 热力学不稳定的结构可能动力学稳定(亚稳态)
  • 避免遗漏有趣的亚稳相

仅在结构数量非常大(>10000)且计算资源有限时,才建议启用热力学筛选。

Q: 如何选择 allocation_mode?

  • 探索性研究:使用 per_sg 模式,确保覆盖所有空间群
  • 快速筛选:使用 total 模式,快速生成大量结构

Q: 多 GPU 模式如何工作?

CHTC 会自动检测可用 GPU 并平均分配任务:

  • 优化:每个 GPU 负责一部分结构的优化
  • 声子谱:每个 GPU 负责一部分结构的声子谱计算
  • 自动合并结果到单个 CSV 文件

性能建议

  • 批处理大小max_natoms_per_batch: 512(GPU 显存允许时可增大)
  • 优化步骤:默认 3 步已经足够(fmax: 0.1 → 0.02 → 0.002)
  • 声子谱
    • 小系统:supercell: "222", qmesh: "666"
    • 大系统:supercell: "111", qmesh: "333"

依赖项

  • Python >= 3.8
  • PyXtal - 随机晶体结构生成
  • PyMatGen - 晶体结构分析
  • MatterSim - 机器学习力场
  • ASE - 原子模拟环境
  • spglib - 空间群识别
  • NumPy / Pandas - 数值计算
  • PyYAML - 配置文件
  • loguru - 日志
  • tqdm - 进度条
  • matplotlib - 相图绘制

许可证

MIT License

致谢

本项目使用了以下开源库:

About

Crystal High-Throughput Calculation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages