Files
tools/calc_utils/README.md
2026-01-11 11:43:35 +08:00

74 lines
2.6 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# calc-utils
个人使用的计算化学工具集,主要基于 [ASE (Atomic Simulation Environment)](https://wiki.fysik.dtu.dk/ase/) 和 [RDKit](https://www.rdkit.org/)。
包含了一些方便的转换工具以及针对特定服务器环境PBS/Slurm/Custom定制的 `ase.calculators.gaussian` 补丁。
专用软件,`futils.gaussian`在不同服务器环境中无法直接运行,必须予以修改。
## 安装
需要 Python 3.12+。
```bash
git clone https://github.com/your-repo/calc-utils.git
cd calc-utils
pip install .
```
## 功能模块
### 1. `futils.gaussian` (**Breaking Change**)
这是一个对 `ase.calculators.gaussian` 的深度定制和 Monkey Patch。
**注意:导入此模块会直接修改 `ase.calculators.gaussian` 中的类定义。**
主要修改内容:
- **强制任务提交脚本**:计算器的 `command` 默认被设置为调用 `gsub_wait` 脚本。
- 默认路径硬编码为 `/home/fanhj/calcs/lele/tools/gsub_wait`(需要在 `futils/gaussian.py` 中按需修改 `GSUB` 变量)。
- **文件后缀变更**:输入文件使用 `.gin` 而非 `.gjf`,输出文件默认读取 `.out`
- **参数增强**`__init__` 方法提供了更详细的 Type Hinting 和默认参数(如 `mem="30GB"`, `proc=32`)。
- **辅助方法**:增加了 `mod()` 方法用于快速复制并修改计算器参数。
```python
from futils.gaussian import Gaussian
from ase import Atoms
# 使用定制后的 Gaussian 计算器
# 注意:这会尝试调用 gsub_wait 提交任务
calc = Gaussian(label='test_calc', method='B3LYP', basis='6-31G(d)')
```
### 2. `futils.rdkit2ase`
提供 RDKit 分子对象 (`rdkit.Chem.Mol`) 与 ASE 原子对象 (`ase.Atoms`) 之间的无缝转换,**保留 3D 坐标**。
```python
from futils.rdkit2ase import MolToAtoms, AtomsToMol
from rdkit import Chem
# RDKit -> ASE
mol = Chem.MolFromMolFile("molecule.mol")
atoms = MolToAtoms(mol)
# ASE -> RDKit
new_mol = AtomsToMol(atoms)
```
### 3. `futils.rdkit_utils`
一些 RDKit 绘图辅助函数。
- `draw2D(mol)`: 生成 SVG 格式的 2D 分子图。
- `draw3D(mol)`: 使用 IPythonConsole 绘制 3D 分子图。
## 脚本工具 (`bin/`)
本项目包含了一些用于任务提交管理的 Shell 脚本,适用于特定的集群环境。
- **`gsub`**: 任务提交脚本。支持本地或通过 SSH 远程提交到名为 `cluster` 的主机。
- **`gsub_wait`**: 提交任务并阻塞等待完成,用于 ASE Calculator 的 `command` 调用,以便实现 Python 脚本的同步执行。
**配置说明**
使用前请检查 `bin/` 下的脚本以及 `futils/gaussian.py` 中的 `GSUB` 路径,根据您的服务器环境进行调整。