A Package for Developing Machine Learning-Based Chemically Accurate Energy and Density Functional Models
Total Page:16
File Type:pdf, Size:1020Kb
DeePKS-kit: a package for developing machine learning-based chemically accurate energy and density functional models Yixiao Chena, Linfeng Zhanga, Han Wangb, Weinan Ea,c aProgram in Applied and Computational Mathematics, Princeton University, Princeton, NJ, USA bLaboratory of Computational Physics, Institute of Applied Physics and Computational Mathematics, Huayuan Road 6, Beijing 100088, People’s Republic of China cDepartment of Mathematics, Princeton University, Princeton, NJ, USA Abstract We introduce DeePKS-kit, an open-source software package for developing machine learning based energy and density functional models. DeePKS-kit is interfaced with PyTorch, an open-source machine learning library, and PySCF, an ab initio computational chemistry program that provides simple and customized tools for developing quantum chemistry codes. It supports the DeePHF and DeePKS methods. In addition to explaining the details in the methodology and the software, we also provide an example of developing a chemically accurate model for water clusters. Keywords: Electronic structure, Density functional theory, Exchange-correlation functional, Deep learning PROGRAM SUMMARY reached great accuracy in specific applications[4]. However, Program Title: DeePKS-kit in general, chemical accuracy cannot be easily achieved for Developer’s repository link: these methods, and the design of xc-functionals can take a https://github.com/deepmodeling/deepks-kit lot of efforts. Licensing provisions: LGPL Recent advances in machine learning is changing the Programming language: Python state of affairs. Significant progress has been made by Nature of problem: using machine learning methods to represent a wide range Modeling the energy and density functional in electronic struc- of quantities directly as functions of atomic positions and ture problems with high accuracy by neural network models. chemical species. An incomplete list includes Refs. 5–19. Solving electronic ground state energy and charge density using These methods generally scale linearly, yet require a large the learned model. amount of training data that is beyond the current ca- Solution method: DeePHS and DeePKS methods are imple- pability of high level methods like CCSD(T). Meanwhile, mented, interfaced with PyTorch and PySCF for neural network there have been efforts in parametrizing many body wave- training and self-consistent field calculations. An iterative learn- function and using variational Monte Carlo approach to ing procedure is included to train the model self-consistently. solve the electronic Schrödinger equation directly[20–22]. These methods are generally very accurate and do not need any training label, but the computational cost can be very 1. Introduction expensive (although remaining in cubic scaling) due to the need of Monte Carlo sampling. Conventional computational methods for electronic struc- Lately, new machine learning models has been devel- ture problems follow a clear-cut hierarchy concerning the oped, that target at achieving chemical accuracy, for a trade-off between efficiency and accuracy. The full configu- wide variety of atomic and molecular systems, at the cost ration interaction (FCI) [1] method should be sufficiently similar to DFT or HF methods, and requiring fewer train- accurate at the complete basis set limit, but it typically ing labels. These methods can be roughly divided into arXiv:2012.14615v2 [physics.chem-ph] 21 Jun 2021 scales exponentially with respect to the number of electrons two classes. One class is like the post-HF methods, which N. Coupled cluster singles, doubles and perturbative triples use the ground-state electronic orbitals of a underlying (CCSD(T)) [2], the so-called golden standard of quantum model (HF or DFT) as the input, and output the energy 7 chemistry, has a scaling of O N . The cost of Kohn-Sham difference between the model and the ground truth. In this (KS) density functional theory (DFT) [3] and the Hartree- regard, machine learning based methods are used to pa- 3 4 Fock (HF) method typically scale as O N and O N , re- rameterize the dependence of the energy difference on the spectively, and some recently developed xc-functionals has input orbitals, following certain physics-based principles. Representative methods in this class include the MOB-ML Email addresses: [email protected] (Linfeng method [23, 24], the DeePHF method [25], etc. The other Zhang), [email protected] (Han Wang) 1 class of the methods is in the spirit of DFT, in which ma- ground-state energy of the system can be written as chine learning based methods are used to parameterize the Etot = min E0[Ψ (x1, x2, . , xN )] energy functional (of the charge density or Kohn-Sham Ψ orbitals) and can be solved to get the ground state en- (1) = min hΨ|T + W + Vext|Ψi , ergy in a self-consistent way. Methods in this class include Ψ some earlier attempts[26–30] that may not be fully self- x , x , . , x N consistent, the NeuralXC method [31], and the DeePKS where Ψ ( 1 2 N ) is the -electron wavefunction, 1 2 1 P 1 P ZI T = − ∇ , W = and Vext = method [32], etc. There are also attempts in using dif- 2 2 i,j |xi−xj | I,i |XI −xi| ferentiable programming[33–35] to impose self-consistency are the kinetic, electron-electron interaction, and ion-electron and improve sample efficiency, at the expense of significant interaction operators, respectively. higher computational cost in the training procedure. Following the (generalized) Kohn-Sham approach, we With the booming of machine learning based meth- introduce an auxiliary system that can be represented √1 ϕ x ods for quantum chemistry problems, the community is in by a single Slater determinant Φ = N det[ i( j)], where urgent need of codes that can serve as a bridge between ma- {ϕi(x)} is the set of one-particle orbitals. We define another chine learning platforms and quantum chemistry softwares, energy functional E[··· ], which takes these one-particle promote the transparency and reproducibility of different orbitals as input: results, and better leverage the resultant models for ap- Etot = min E[Φ (x1, x2, . , xN )] plications. Developing such a code will not only benefit Φ more potential users, but also avoid unnecessary efforts on (2) = min E[{ϕi}]. reinventing the wheel. In particular, since the field is at its {ϕi},hϕi|ϕj i=δij early stage, good codes should not only implement certain methods in a user-friendly way, but also provide flexible Solving this variational problem with respect to {ϕi} under interfaces for developing new methods or incorporating the orthonormality condition hϕi|ϕji = δij gives us the more functionalities. celebrated self-consistent field (SCF) equation, In this work, we introduce DeePKS-kit, an open-source H[{ϕj}] |ϕii = εi |ϕii for i = 1 . N. (3) software package, publicly available at GitHub 1 under the LGPL-3.0 License, for developing chemically accurate where H = δE denotes the effective single particle Hamil- energy and density functional models. DeePKS-kit is inter- δhϕi| tonian that usually consists of kinetic and potential terms. faced with PyTorch[36] in one end, and at the other end, This is a non-linear equation and needs to be solved iter- it interfaces with PySCF[37], an ab initio computational atively. The key to the Kohn-Sham DFT methods is to chemistry program that provides a simple, light-weight, find a good approximation of E, so that the ground-state and efficient platform for quantum chemistry code devel- energy and charge density obtained by solving Eq. 2 are oping and calculation. DeePKS-kit supports the DeePHF close to those obtained by solving Eq. 1. and DeePKS methods that were developed by the authors We divide E into two parts, earlier. Furthermore, it is also designed to provide certain flexibilities for, e.g., modification of the model construction, E {ϕi}|ω = Ebase[{ϕi}] + Eδ {ϕi}|ω , (4) changing the training scheme, interfacing other quantum chemistry packages, etc. where Ebase is an energy functional of the baseline method, The rest of the paper is organized as follows. In Sec- such as the HF functional or the DFT functional with a tion 2, we introduce the theoretical framework of the certain exchange correlation, and Eδ is the correction term, DeePHF and DeePKS methods as well as the notations. whose parameters ω will be determined by a supervised In Section 3, we provide a brief introduction on how to use learning procedure. DeePKS-kit to train different quantum chemistry models We follow Ref. 25 to construct Eδ as a neural network and how to use these models in production calculations. In model that takes the “local density matrix” as input and Section 4, we use training DeePHF and DeePKS models satisfies locality and symmetry requirements. The “local for water clusters as an example to show how to use the density matrix” is constructed by projecting the density I package. Finally, we conclude with some remarks for future matrix onto a set of atomic basis functions αnlm cen- directions. tered on each atom I and indexed by the radial number n, azimuthal number l, magnetic (angular) number m. 2. Methodology I X I I Dnl mm0 = αnlm ϕi ϕi αnlm0 . (5) We consider a many-body system with N electrons i i M I indexed by and clamped ions indexed by . The For simplicity and locality, we only take the block diagonal part of the full projection. In other words, the indices I, 1https://github.com/deepmodeling/deepks-kit n and l are taken to be the same on both sides, and only angular indices m and m0 differ. 2 ∗ We take the eigenvalues of those local density matrices where {ϕi } denotes the minimizer of the total energy func- to ensure the resulting descriptors are rotational invariant tional and we write out the dependence on the parameters ω I I explicitly. Note that the force depends directly on NN d 0 D , nl = EigenValsmm nl mm0 (6) parameters ω, this allows us to include the force in the loss function for the iterative training procedure.