-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add the UHF module. * Add the UHF and unit test. * Reuse the _kernel in hf.py, and correct the unit test for UHF. * Add the UKS and a unit test for it. * Fix typos in test_uks.py
- Loading branch information
Showing
5 changed files
with
621 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# gpu4pyscf is a plugin to use Nvidia GPU in PySCF package | ||
# | ||
# Copyright (C) 2022 Qiming Sun | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import numpy as np | ||
import unittest | ||
import pyscf | ||
from gpu4pyscf.dft import uks | ||
|
||
atom = ''' | ||
O 0.0000000000 -0.0000000000 0.1174000000 | ||
H -0.7570000000 -0.0000000000 -0.4696000000 | ||
H 0.7570000000 0.0000000000 -0.4696000000 | ||
''' | ||
bas='def2-qzvpp' | ||
grids_level = 3 | ||
nlcgrids_level = 1 | ||
|
||
def setUpModule(): | ||
global mol | ||
mol = pyscf.M( | ||
atom=atom, | ||
basis=bas, | ||
max_memory=32000, | ||
verbose = 1, | ||
spin = 1, | ||
charge = 1, | ||
output = '/dev/null' | ||
) | ||
|
||
def tearDownModule(): | ||
global mol | ||
mol.stdout.close() | ||
del mol | ||
|
||
def run_dft(xc): | ||
mf = uks.UKS(mol, xc=xc) | ||
mf.grids.level = grids_level | ||
mf.nlcgrids.level = nlcgrids_level | ||
e_dft = mf.kernel() | ||
return e_dft | ||
|
||
class KnownValues(unittest.TestCase): | ||
''' | ||
known values are obtained by pyscf | ||
''' | ||
def test_uks_lda(self): | ||
print('------- LDA ----------------') | ||
e_tot = run_dft("LDA, vwn5") | ||
assert np.allclose(e_tot, -75.42821982483972) | ||
|
||
def test_uks_pbe(self): | ||
print('------- PBE ----------------') | ||
e_tot = run_dft('PBE') | ||
assert np.allclose(e_tot, -75.91732813416843) | ||
|
||
def test_uks_b3lyp(self): | ||
print('-------- B3LYP -------------') | ||
e_tot = run_dft('B3LYP') | ||
assert np.allclose(e_tot, -76.00306439862237) | ||
|
||
def test_uks_m06(self): | ||
print('--------- M06 --------------') | ||
e_tot = run_dft("M06") | ||
assert np.allclose(e_tot, -75.96551006522827) | ||
|
||
def test_uks_wb97(self): | ||
print('-------- wB97 --------------') | ||
e_tot = run_dft("HYB_GGA_XC_WB97") | ||
assert np.allclose(e_tot, -75.987601337562) | ||
|
||
def test_uks_vv10(self): | ||
print("------- wB97m-v -------------") | ||
e_tot = run_dft('HYB_MGGA_XC_WB97M_V') | ||
assert np.allclose(e_tot, -75.97363094678428) | ||
|
||
#TODO: add test cases for D3/D4 and gradient | ||
|
||
if __name__ == "__main__": | ||
print("Full Tests for dft") | ||
unittest.main() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
# | ||
# Author: Qiming Sun <[email protected]> | ||
# | ||
# modified by Xiaojie Wu <[email protected]> | ||
# modified by Xiaojie Wu <[email protected]>; Zhichen Pu <[email protected]> | ||
|
||
""" | ||
DIIS | ||
|
@@ -64,9 +64,13 @@ def get_num_vec(self): | |
|
||
def get_err_vec(s, d, f): | ||
'''error vector = SDF - FDS''' | ||
if isinstance(f, cupy.ndarray): | ||
if isinstance(f, cupy.ndarray) and f.ndim == 2: | ||
sdf = reduce(cupy.dot, (s,d,f)) | ||
errvec = (sdf.T.conj() - sdf) | ||
return errvec | ||
errvec = (sdf.conj().T - sdf).ravel() | ||
elif f.ndim == s.ndim+1 and f.shape[0] == 2: # for UHF | ||
errvec = cupy.hstack([ | ||
get_err_vec(s, d[0], f[0]).ravel(), | ||
get_err_vec(s, d[1], f[1]).ravel()]) | ||
else: | ||
cpu_diis.get_err_vec(s, d, f) | ||
raise RuntimeError('Unknown SCF DIIS type') | ||
return errvec |
Oops, something went wrong.