1 Star 0 Fork 0

deepmodeling/DeepH-pack

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
LGPL-3.0


DOI:10.1038/s43588-022-00265-6 Documentation Status

DeepH-pack is the official implementation of the DeepH (Deep Hamiltonian) method described in the paper Deep-learning density functional theory Hamiltonian for efficient ab initio electronic-structure calculation and in the Research Briefing.

DeepH-pack supports DFT results made by ABACUS, OpenMX, FHI-aims or SIESTA and will support HONPAS soon.

For more information, see the documentation and the talk (in Chinese).

Contents

  1. How to cite
  2. Requirements
  3. Usage
  4. Demo
  5. Team

How to cite

@article{deeph,
   author = {Li, He and Wang, Zun and Zou, Nianlong and Ye, Meng and Xu, Runzhang and Gong, Xiaoxun and Duan, Wenhui and Xu, Yong},
   title = {Deep-learning density functional theory Hamiltonian for efficient ab initio electronic-structure calculation},
   journal = {Nature Computational Science},
   volume = {2},
   number = {6},
   pages = {367-377},
   ISSN = {2662-8457},
   DOI = {10.1038/s43588-022-00265-6},
   url = {https://doi.org/10.1038/s43588-022-00265-6},
   year = {2022},
   type = {Journal Article}
}

Recent development

@article{deephe3,
   author = {Gong, Xiaoxun and Li, He and Zou, Nianlong and Xu, Runzhang and Duan, Wenhui and Xu, Yong},
   title = {General framework for E(3)-equivariant neural network representation of density functional theory Hamiltonian},
   journal = {Nature Communications},
   volume = {14},
   number = {1},
   pages = {2848},
   ISSN = {2041-1723},
   DOI = {10.1038/s41467-023-38468-8},
   url = {https://doi.org/10.1038/s41467-023-38468-8},
   year = {2023},
   type = {Journal Article}
}

@article{xdeeph,
   author = {Li, He and Tang, Zechen and Gong, Xiaoxun and Zou, Nianlong and Duan, Wenhui and Xu, Yong},
   title = {Deep-learning electronic-structure calculation of magnetic superstructures},
   journal = {Nature Computational Science},
   volume = {3},
   number = {4},
   pages = {321-327},
   ISSN = {2662-8457},
   DOI = {10.1038/s43588-023-00424-3},
   url = {https://doi.org/10.1038/s43588-023-00424-3},
   year = {2023},
   type = {Journal Article}
}

Requirements

To use DeepH-pack, following environments and packages are required:

Python

Prepare the Python 3.9 interpreter. Install the following Python packages required:

  • NumPy
  • SciPy
  • PyTorch = 1.9.1
  • PyTorch Geometric = 1.7.2
  • e3nn = 0.3.5
  • pymatgen
  • h5py
  • TensorBoard
  • pathos
  • psutil

In Linux, you can quickly achieve the requirements by running

# install miniconda with python 3.9
wget https://repo.anaconda.com/miniconda/Miniconda3-py39_4.10.3-Linux-x86_64.sh
bash Miniconda3-py39_4.10.3-Linux-x86_64.sh

# install packages by conda
conda install numpy
conda install scipy
conda install pytorch==1.9.1 ${pytorch_config}
conda install pytorch-geometric=1.7.2 -c rusty1s -c conda-forge
conda install pymatgen -c conda-forge

# install packages by pip
pip install e3nn==0.3.5
pip install h5py
pip install tensorboard
pip install pathos
pip install psutil

with ${pytorch_config} replaced by your own configuration. You can find how to set it in the official website of PyTorch.

Julia

Prepare the Julia 1.6.6 interpreter. Install the following Julia packages required with Julia's builtin package manager:

  • Arpack.jl
  • HDF5.jl
  • ArgParse.jl
  • JLD.jl
  • JSON.jl
  • IterativeSolvers.jl
  • DelimitedFiles.jl
  • StaticArrays.jl
  • LinearMaps.jl
  • Pardiso.jl

In Linux, you can quickly achieve the requirements by first running

# install julia 1.6.6
wget https://julialang-s3.julialang.org/bin/linux/x64/1.6/julia-1.6.6-linux-x86_64.tar.gz
tar xzvf julia-1.6.6-linux-x86_64.tar.gz

# open the julia REPL
julia

Then enter the pkg REPL by pressing ] from the Julia REPL. In the pkg REPL run

(@v1.6) pkg> add Arpack
(@v1.6) pkg> add HDF5
(@v1.6) pkg> add ArgParse
(@v1.6) pkg> add JLD
(@v1.6) pkg> add JSON
(@v1.6) pkg> add IterativeSolvers
(@v1.6) pkg> add DelimitedFiles
(@v1.6) pkg> add StaticArrays
(@v1.6) pkg> add LinearMaps

Follow these instructions to install Pardiso.jl.

One of the supported DFT packages

One of the supported DFT packages is required to obtain the dataset and calculate the overlap matrix for large-scale material systems. DeepH-pack supports DFT results made by ABACUS, OpenMX, FHI-aims or SIESTA and will support HONPAS soon.

  1. ABACUS: Install ABACUS package for density functional theory Hamiltonian matrix calculation to construct datasets. DeepH-pack requires ABACUS version >= 2.3.2.
  2. OpenMX:
    1. Install OpenMX package version 3.9 for density functional theory Hamiltonian matrix calculation to construct datasets. If you are using Intel MKL and Intel MPI environments, you can use the following variable definitions for makefile
      CC = mpiicc -O3 -xHOST -ip -no-prec-div -qopenmp -I${MKLROOT}/include/fftw -I${MKLROOT}/include
      FC = mpiifort -O3 -xHOST -ip -no-prec-div -qopenmp -I${MKLROOT}/include
      LIB = ${CMPLR_ROOT}/linux/compiler/lib/intel64_lin/libiomp5.a ${MKLROOT}/lib/intel64/libmkl_blas95_lp64.a ${MKLROOT}/lib/intel64/libmkl_lapack95_lp64.a ${MKLROOT}/lib/intel64/libmkl_scalapack_lp64.a -Wl,--start-group ${MKLROOT}/lib/intel64/libmkl_intel_lp64.a ${MKLROOT}/lib/intel64/libmkl_intel_thread.a ${MKLROOT}/lib/intel64/libmkl_core.a ${MKLROOT}/lib/intel64/libmkl_blacs_intelmpi_lp64.a -Wl,--end-group ${CMPLR_ROOT}/linux/compiler/lib/intel64_lin/libifcoremt.a -lpthread -lm -ldl
      
      Or edit the makefile yourself according to your environment to install OpenMX version 3.9.
    2. A modified OpenMX package is also used to compute overlap matrices only for large-scale materials structure. Install 'overlap only' OpenMX according to the readme documentation in this repository.
  3. SIESTA: Install SIESTA package for density functional theory Hamiltonian matrix calculation to construct datasets. DeepH-pack requires SIESTA version >= 4.1.5.

Usage

Install DeepH-pack

Run the following command in the path of DeepH-pack:

git clone https://github.com/mzjb/DeepH-pack.git
cd DeepH-pack
pip install .

Prepare the dataset

To perform efficient ab initio electronic structure calculation by DeepH method for a class of large-scale material systems, one needs to design an appropriate dataset of small structures that have close chemical bonding environment with the target large-scale material systems. Therefore, the first step of a DeepH study is to perform the DFT calculation on the above dataset to get the DFT Hamiltonian matrices with the localized basis. DeepH-pack supports DFT results made by ABACUS, OpenMX, FHI-aims or SIESTA and will support HONPAS soon.

For more information, see the documentation.

Preprocess the dataset

Preprocess is a part of DeepH-pack. Through Preprocess, DeepH-pack will convert the unit of physical quantity, store the data files in the format of text and HDF5 for each structure in a separate folder, generate local coordinates, and perform basis transformation for DFT Hamiltonian matrices. We use the following convention of units:

Quantity Unit
Length Å
Energy eV

You need to edit a configuration in the format of ini, setting up the file referring to the default file DeepH-pack/deeph/preprocess/preprocess_default.ini. The meaning of the keywords can be found in the documentation. For a quick start, you must set up raw_dir, processed_dir and interface.

With the configuration file prepared, run

deeph-preprocess --config ${config_path}

with ${config_path} replaced by the path of your configuration file.

Train your model

Train is a part of DeepH-pack, which is used to train a deep learning model using the processed dataset.

Prepare a configuration in the format of ini, setting up the file referring to the default DeepH-pack/deeph/default.ini. The meaning of the keywords can be found in the documentation. For a quick start, you must set up graph_dir, save_dir, raw_dir and orbital, other keywords can stay default and be adjusted later.

With the configuration file prepared, run

deeph-train --config ${config_path}

with ${config_path} replaced by the path of your configuration file.

Tips:

  • Name your dataset. Use dataset_name to name your dataset, the same names may overwrite each other.

  • Hyperparameters of the neural network. The neural network here contains some hyperparameters. For a specific problem your should try adjusting the hyperparameters to obtain better results.

  • The keyword orbital. The keyword orbital states which orbitals or matrix elements are predicted. It is a little complicated to understand its data structure. To figure out it, you can refer to the documentation or the method make_mask in class DeepHKernel defined in DeepH-pack/deeph/kernel.py.

    Alternatively, a Python script at DeepH-pack/tools/get_all_orbital_str.py can be used to generate a default configuration to predict all orbitals with one model.

  • Use TensorBoard for visualizations. You can track and visualize the training process through TensorBoard by running

    tensorboard --logdir=./tensorboard
    

    in the output directory (save_dir):

Inference with your model

Inference is a part of DeepH-pack, which is used to predict the DFT Hamiltonian for large-scale material structures and perform sparse calculation of physical properties.

Firstly, one should prepare the structure file of large-scale material and calculate the overlap matrix. Overlap matrix calculation does not require SCF. Even if the material system is large, only a small calculation time and memory consumption are required. Following are the steps to calculate the overlap matrix using different supported DFT packages:

  1. ABACUS: Set the following parameters in the input file of ABACUS INPUT:
    calculation   get_S
    
    and run ABACUS like a normal SCF calculation. ABACUS version >= 2.3.2 is required.
  2. OpenMX: See this repository.

For overlap matrix calculation, you need to use the same basis set and DFT software when preparing the dataset.

Then, prepare a configuration in the format of ini, setting up the file referring to the default DeepH-pack/deeph/inference/inference_default.ini. The meaning of the keywords can be found in the INPUT KEYWORDS section. For a quick start, you must set up OLP_dir, work_dir, interface, trained_model_dir and sparse_calc_config, as well as a JSON configuration file located at sparse_calc_config for sparse calculation.

With the configuration files prepared, run

deeph-inference --config ${config_path}

with ${config_path} replaced by the path of your configuration file.

Demo: DeepH study on twisted bilayer bismuthene

When the directory structure of the code folder is not modified, the scripts in it can be used to generate a dataset of non-twisted structures, train a DeepH model, make predictions on the DFT Hamiltonian matrix of twisted structure, and perform sparse diagonalization to compute the band structure for the example study of bismuthene.

Firstly, generate example input files according to your environment path by running the following command:

cd DeepH-pack
python gen_example.py ${openmx_path} ${openmx_overlap_path} ${pot_path} ${python_interpreter} ${julia_interpreter}

with ${openmx_path}, ${openmx_overlap_path}, ${pot_path}, ${python_interpreter}, and ${julia_interpreter} replaced by the path of original OpenMX executable program, modified 'overlap only' OpenMX executable program, VPS and PAO directories of OpenMX, Python interpreter, and Julia interpreter, respectively. For example,

cd DeepH-pack
python gen_example.py /home/user/openmx/source/openmx /home/user/openmx_overlap/source/openmx /home/user/openmx/DFT_DATA19 python /home/user/julia-1.5.4/bin/julia

Secondly, enter the generated example/ folder and run run.sh in each folder one-by-one from 1 to 5. Please note that run.sh should be run in the directory where the run.sh file is located.

cd example/1_DFT_calculation
bash run.sh
cd ../2_preprocess
bash run.sh
cd ../3_train
bash run.sh
cd ../4_compute_overlap
bash run.sh
cd ../5_inference
bash run.sh

The third step, the neural network training process, is recommended to be carried out on the GPU. In addition, in order to get the energy band faster, it is recommended to calculate the eigenvalues ​​of different k points in parallel in the fifth step by which_k interface.

After completing the calculation, you can find the band structure data in OpenMX Band format of twisted bilayer bismuthene with 244 atoms per supercell computed by the predicted DFT Hamiltonian in the file below:

example/work_dir/inference/5_4/openmx.Band

The plotted band structure will be consistent with the right pannel of figure 6c in our paper.

Demo: Reproduce the experimental results of the paper

You can train DeepH models using the existing dataset to reproduce the results of our paper.

Firstly, download the processed dataset for graphene (graphene_dataset.zip), MoS2 (MoS2_dataset.zip), twisted bilayer graphene (TBG_dataset.zip) or twisted bilayer bismuthene (TBB_dataset.zip). Uncompress the ZIP file.

Secondly, edit corresponding config files in the DeepH-pack/ini/. raw_dir should be set to the path of the downloaded dataset. graph_dir and save_dir should be set to the path to save your graph file and results file during the training. For grahene, twisted bilayer graphene and twisted bilayer bismuthene, a single MPNN model is used for each dataset. For MoS2, four MPNN models are used. Run

deeph-train --config ${config_path}

with ${config_path} replaced by the path of config file for training.

After completing the training, you can find the trained model in save_dir, which can be used to make prediction on new structures by run

deeph-inference --config ${inference_config_path}

with ${inference_config_path} replaced by the path of config file for inference. Please note that the DFT results in this dataset were calculated using OpenMX. This means that if you want to use a model trained on this dataset to calculate properties, you need to use the overlap calculated using OpenMX. The orbital information required for overlap calculations can be found in the paper.

Demo: Train the DeepH model using the ABACUS interface

Train the DeepH model by random graphene supercells and predict the Hamiltonian of carbon nanotube using the ABACUS interface. See README.md in this file for details.

Team

Main developers

  • He Li

    Tsinghua University

    mzjb313 [at] gmail [dot] com

  • Zechen Tang

    Tsinghua University

Collaborators

  • Xiaoxun Gong
  • Honggeng Tao
  • Zun Wang
  • Nianlong Zou
  • Ting Bao

Supervisors

  • Yong Xu

    Tsinghua University

    yongxu [at] tsinghua [dot] edu [dot] cn

  • Wenhui Duan

    Tsinghua University

    duanw [at] tsinghua [dot] edu [dot] cn

GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.

简介

暂无描述 展开 收起
Python 等 2 种语言
LGPL-3.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/deepmodeling/DeepH-pack.git
git@gitee.com:deepmodeling/DeepH-pack.git
deepmodeling
DeepH-pack
DeepH-pack
main

搜索帮助