-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uks dev #78
Merged
Merged
Uks dev #78
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b431eb7
Add the UHF module.
puzhichen 9f42598
Add the UHF and unit test.
puzhichen c4aee59
Reuse the _kernel in hf.py, and correct the unit test for UHF.
puzhichen 910416f
Add the UKS and a unit test for it.
puzhichen 730cd7a
Fix typos in test_uks.py
puzhichen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_rks_lda(self): | ||
print('------- LDA ----------------') | ||
e_tot = run_dft("LDA, vwn5") | ||
assert np.allclose(e_tot, -75.42821982483972) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are those values from qchem? |
||
|
||
def test_rks_pbe(self): | ||
print('------- PBE ----------------') | ||
e_tot = run_dft('PBE') | ||
assert np.allclose(e_tot, -75.91732813416843) | ||
|
||
def test_rks_b3lyp(self): | ||
print('-------- B3LYP -------------') | ||
e_tot = run_dft('B3LYP') | ||
assert np.allclose(e_tot, -76.00306439862237) | ||
|
||
def test_rks_m06(self): | ||
print('--------- M06 --------------') | ||
e_tot = run_dft("M06") | ||
assert np.allclose(e_tot, -75.96551006522827) | ||
|
||
def test_rks_wb97(self): | ||
print('-------- wB97 --------------') | ||
e_tot = run_dft("HYB_GGA_XC_WB97") | ||
assert np.allclose(e_tot, -75.987601337562) | ||
|
||
def test_rks_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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test_uks_lda