Add Chinese README section
Browse files233 unmodified lines234235236233 unmodified lines- The MatterGen-related code comes from the MatChem examples in the OneScience project and refers to the upstream MatterGen project (https://github.com/microsoft/mattergen). The upstream MatterGen code is released under the [MIT License](https://github.com/microsoft/mattergen/blob/main/LICENSE).- If you use MatterGen training or generation results in research, please cite the original MatterGen paper, the relevant OneScience projects, and the datasets used.233 unmodified lines234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452233 unmodified lines- The MatterGen-related code comes from the MatChem examples in the OneScience project and refers to the upstream MatterGen project (https://github.com/microsoft/mattergen). The upstream MatterGen code is released under the [MIT License](https://github.com/microsoft/mattergen/blob/main/LICENSE).- If you use MatterGen training or generation results in research, please cite the original MatterGen paper, the relevant OneScience projects, and the datasets used.---# 中文说明## 模型简介MatterGen 是 Microsoft Research 开发的无机材料生成模型。它联合生成元素组成、晶胞和周期性原子坐标,支持以材料属性为条件生成候选晶体。论文《*MatterGen:用于无机材料设计的生成模型*》<br>参考实现 https://github.com/microsoft/mattergen## 模型描述MatterGen 使用扩散模型学习原子种类、分数坐标和晶格的分布。它支持无条件生成晶体,也支持以化学体系、空间群、磁密度、带隙和体模量等属性为条件生成晶体。本仓库包含经 OneScience 适配的 MatterGen 模型、扩散和采样代码,以及训练、属性微调(fine-tuning)、晶体生成和数据转换的入口。模型代码位于 `model/`。数据处理、通用网络层和属性嵌入由 OneScience MatChem 提供。## 使用场景| 使用场景 | 说明 || :---: | :--- || 无条件晶体生成 | 使用基础模型权重(检查点)(checkpoint)生成新的候选晶体结构 || 属性条件生成 | 为磁密度、带隙及体模量等目标属性生成结构 || 固定组成的结构预测 | 搜索指定组成对应的可能晶体结构 || 从头训练 | 使用 MP-20 或兼容 MatterGen 缓存格式的数据进行训练 || 属性微调 | 在预训练模型中加入属性适配器并微调 || 环境连通性检查 | 通过生成一个样本验证 OneScience、模型权重(检查点)及 GPU/DCU 是否可用 |## 使用方法### 1. 使用 OneCode在 OneCode 在线环境中体验智能一键 AI4S 编程。[体验智能一键 AI4S 编程](https://web-2069360198568017922-iaaj.ksai.scnet.cn:58043/home)### 2. 手动安装与使用**硬件要求**- 建议使用 GPU 或 DCU。- 可使用 CPU 进行导入和配置连通性检查,完整生成和训练会较慢。- DCU 需要 DTK 与 PyTorch 构建版本匹配。已在 DTK 25.04.2 和 `torch 2.5.1+das.opt1.dtk25042` 环境中验证单样本生成。#### 下载模型包```bashhf download OneScience-Group/Mattergencd Mattergen```#### 安装运行环境**DCU 环境**```bash# Activate DTK and conda firstmodule load compiler/dtk/25.04.2conda create -n onescience311 python=3.11 -yconda activate onescience311# uv installation is also supportedpip install onescience[matchem-dcu] \-i http://mirrors.onescience.ai:3141/pypi/simple/ \--trusted-host mirrors.onescience.ai```**GPU 环境**```bash# Activate conda firstconda create -n onescience311 python=3.11 -y \libstdcxx-ng=12 libgcc-ng=12 gcc_linux-64=12 gxx_linux-64=12conda activate onescience311# uv installation is also supportedpip install onescience[matchem-gpu] \-i http://mirrors.onescience.ai:3141/pypi/simple/ \--trusted-host mirrors.onescience.ai```#### 训练数据MatterGen 训练使用转换后的数据缓存。MP-20 数据集可直接从 Hugging Face 下载。```bashhf download OneScience-Group/mp20 --repo-type dataset```下载的 MatterGen 缓存位于以下路径。```textdatasets/mp20/data/MP20/cache/mp_20/├── train/├── val/└── test/```默认训练 YAML 需在 `args` 下添加实际路径后,才能使用已下载的数据。例如,按以下方式更新 `demo/configs/train_8dcu.yaml`。```yamlargs:data_module: mp_20data_module.root_dir: ./datasets/mp20/data/MP20/cache/mp_20```进行属性微调时,还需添加 `data_module.root_dir`,位置是 `args` 下,配置文件为 `demo/configs/finetune_dft_mag_density_smoke.yaml`。如果数据下载在其他位置,请使用相应的绝对路径。首先转换自定义 CSV 数据。```bashpython csv_to_dataset.py \--csv-folder /path/to/csv_folder \--dataset-name my_dataset \--cache-folder ./datasets/cache```#### 训练权重通过上述 Hugging Face 命令下载模型包后,预训练模型权重(检查点)位于 `weight/`。```textweight/├── mattergen_base/│ ├── config.yaml│ └── checkpoints/│ └── last.ckpt└── dft_mag_density/├── config.yaml└── checkpoints/└── last.ckpt```本仓库还提供针对 `chemical_system`、`dft_band_gap`、`dft_mag_density`、`ml_bulk_modulus` 和 `space_group` 的属性条件模型权重(检查点)。使用示例 YAML 时,将 `checkpoint`(位于 `demo/configs/generate_base.yaml` 或 `demo/configs/generate_dft_mag_density.yaml` 中)设置为对应的 `./weight/<model_name>` 路径。进行微调时,更新 `adapter.model_path`(位于 `demo/configs/finetune_dft_mag_density_smoke.yaml` 中)。#### 推理(inference)无条件生成一个晶体结构。```bashpython generate.py \--checkpoint ./weight/mattergen_base \--output outputs/generate/mattergen_base \--batch-size 1 \--num-batches 1```生成的输出包括```textoutputs/generate/mattergen_base/├── generated_crystals.extxyz└── generated_crystals_cif.zip```以磁密度为条件生成需要匹配的属性模型权重(检查点)。```bashpython generate.py \--checkpoint ./weight/dft_mag_density \--output outputs/generate/dft_mag_density \--batch-size 1 \--num-batches 1 \--properties '{"dft_mag_density": 0.15}'```也可使用示例 YAML 文件。```bashcd demobash run.sh --config configs/generate_base.yamlbash run.sh --config configs/generate_dft_mag_density.yaml```#### 训练使用 MP-20 缓存提交八 DCU 训练作业。```bashcd demobash run.sh --config configs/train_8dcu.yaml --submit```也可在仓库根目录使用 Hydra 参数直接启动训练。```bashpython train.py \data_module=mp_20 \data_module.root_dir=./datasets/mp20/data/MP20/cache/mp_20 \trainer.devices=1 \data_module.batch_size.train=4```#### 微调本仓库提供用于磁密度属性微调的冒烟测试配置。默认仅运行一个训练批次和一个验证批次。```bashcd demobash run.sh --config configs/finetune_dft_mag_density_smoke.yaml```进行完整微调时,复制该 YAML 文件,并更新 `adapter.model_path`、`data_module.properties`、属性嵌入、批大小和训练轮数。删除 `trainer.limit_train_batches` 和 `trainer.limit_val_batches`。## OneScience 官方资源| 平台 | OneScience 主仓库 | Skills 仓库 || --- | --- | --- || Gitee | https://gitee.com/onescience-ai/onescience | https://gitee.com/onescience-ai/oneskills || GitHub | https://github.com/onescience-ai/OneScience | https://github.com/onescience-ai/oneskills |---## 引用与许可证- MatterGen 相关代码来自 OneScience 项目的 MatChem 示例,并参考上游 MatterGen 项目 (https://github.com/microsoft/mattergen)。上游 MatterGen 代码按 [MIT 许可证](https://github.com/microsoft/mattergen/blob/main/LICENSE)发布。- 如果在研究中使用 MatterGen 的训练或生成结果,请引用 MatterGen 原始论文、相关 OneScience 项目,以及所用数据集。
README.md+216