From dfcbed21f15bcca81cf542b786886f0e4c395001 Mon Sep 17 00:00:00 2001 From: Qiming Sun Date: Wed, 4 Sep 2024 09:20:56 -0700 Subject: [PATCH] Add examples for DFT+U --- CHANGELOG | 1 + examples/pbc/22-dft+u.py | 40 +++++++++++++++++++++++++++++++++++ pyscf/pbc/dft/krkspu.py | 29 ------------------------- pyscf/pbc/dft/krkspu_ksymm.py | 30 -------------------------- pyscf/pbc/dft/kukspu.py | 27 ----------------------- pyscf/pbc/dft/kukspu_ksymm.py | 30 -------------------------- 6 files changed, 41 insertions(+), 116 deletions(-) create mode 100644 examples/pbc/22-dft+u.py diff --git a/CHANGELOG b/CHANGELOG index 8f665a8c41..8521edd817 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -328,6 +328,7 @@ PySCF 1.7.6 (2021-03-28) - Auxiliary second-order Green's function perturbation theory (AGF2) - Smearing for molecules - Visscher small component correction approximation for DHF + - DFT+U * Improved - Threading safety in Mole temporary context - Basis parser to support arithmetic expressions in basis data diff --git a/examples/pbc/22-dft+u.py b/examples/pbc/22-dft+u.py new file mode 100644 index 0000000000..0414e2d7b3 --- /dev/null +++ b/examples/pbc/22-dft+u.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python + +''' +DFT+U with kpoint sampling +''' + +from pyscf.pbc import gto, dft +cell = gto.Cell() +cell.unit = 'A' +cell.atom = 'C 0., 0., 0.; C 0.8917, 0.8917, 0.8917' +cell.a = '''0. 1.7834 1.7834 + 1.7834 0. 1.7834 + 1.7834 1.7834 0. ''' + +cell.basis = 'gth-dzvp' +cell.pseudo = 'gth-pade' +cell.verbose = 4 +cell.build() + +kmesh = [2, 2, 2] +kpts = cell.make_kpts(kmesh) +# Add U term to the 2p orbital of the second Carbon atom +U_idx = ['1 C 2p'] +U_val = [5.0] +mf = dft.KRKSpU(cell, kpts, U_idx=U_idx, U_val=U_val, minao_ref='gth-szv') +print(mf.U_idx) +print(mf.U_val) +mf.run() + +# When space group symmetry in k-point samples is enabled, the symmetry adapted +# DFT+U method will be invoked automatically. +kpts = cell.make_kpts( + kmesh, wrap_around=True, space_group_symmetry=True, time_reversal_symmetry=True) +# Add U term to 2s and 2p orbitals +U_idx = ['2p', '2s'] +U_val = [5.0, 2.0] +mf = dft.KUKSpU(cell, kpts, U_idx=U_idx, U_val=U_val, minao_ref='gth-szv') +print(mf.U_idx) +print(mf.U_val) +mf.run() diff --git a/pyscf/pbc/dft/krkspu.py b/pyscf/pbc/dft/krkspu.py index bc39a58cb3..d5a0502096 100644 --- a/pyscf/pbc/dft/krkspu.py +++ b/pyscf/pbc/dft/krkspu.py @@ -280,32 +280,3 @@ def __init__(self, cell, kpts=np.zeros((1,3)), xc='LDA,VWN', def nuc_grad_method(self): raise NotImplementedError - -if __name__ == '__main__': - from pyscf.pbc import gto - np.set_printoptions(3, linewidth=1000, suppress=True) - cell = gto.Cell() - cell.unit = 'A' - cell.atom = 'C 0., 0., 0.; C 0.8917, 0.8917, 0.8917' - cell.a = '''0. 1.7834 1.7834 - 1.7834 0. 1.7834 - 1.7834 1.7834 0. ''' - - cell.basis = 'gth-dzvp' - cell.pseudo = 'gth-pade' - cell.verbose = 7 - cell.build() - kmesh = [2, 2, 2] - kpts = cell.make_kpts(kmesh, wrap_around=True) - #U_idx = ["2p", "2s"] - #U_val = [5.0, 2.0] - U_idx = ["1 C 2p"] - U_val = [5.0] - - mf = KRKSpU(cell, kpts, U_idx=U_idx, U_val=U_val, C_ao_lo='minao', - minao_ref='gth-szv') - mf.conv_tol = 1e-10 - print (mf.U_idx) - print (mf.U_val) - print (mf.C_ao_lo.shape) - print (mf.kernel()) diff --git a/pyscf/pbc/dft/krkspu_ksymm.py b/pyscf/pbc/dft/krkspu_ksymm.py index 5ed432b5be..5aef54374f 100644 --- a/pyscf/pbc/dft/krkspu_ksymm.py +++ b/pyscf/pbc/dft/krkspu_ksymm.py @@ -38,33 +38,3 @@ def __init__(self, cell, kpts=libkpts.KPoints(), xc='LDA,VWN', minao_ref=minao_ref, **kwargs) KRKSpU = KsymAdaptedKRKSpU - -if __name__ == '__main__': - from pyscf.pbc import gto - np.set_printoptions(3, linewidth=1000, suppress=True) - cell = gto.Cell() - cell.unit = 'A' - cell.atom = 'C 0., 0., 0.; C 0.8917, 0.8917, 0.8917' - cell.a = '''0. 1.7834 1.7834 - 1.7834 0. 1.7834 - 1.7834 1.7834 0. ''' - - cell.basis = 'gth-dzvp' - cell.pseudo = 'gth-pade' - cell.verbose = 7 - cell.build() - kmesh = [2, 2, 2] - kpts = cell.make_kpts(kmesh, wrap_around=True, - space_group_symmetry=True, time_reversal_symmetry=True) - #U_idx = ["2p", "2s"] - #U_val = [5.0, 2.0] - U_idx = ["1 C 2p"] - U_val = [5.0] - - mf = KRKSpU(cell, kpts, U_idx=U_idx, U_val=U_val, C_ao_lo='minao', - minao_ref='gth-szv') - mf.conv_tol = 1e-10 - print (mf.U_idx) - print (mf.U_val) - print (mf.C_ao_lo.shape) - print (mf.kernel()) diff --git a/pyscf/pbc/dft/kukspu.py b/pyscf/pbc/dft/kukspu.py index 42b9131413..1f78f16beb 100644 --- a/pyscf/pbc/dft/kukspu.py +++ b/pyscf/pbc/dft/kukspu.py @@ -172,30 +172,3 @@ def __init__(self, cell, kpts=np.zeros((1,3)), xc='LDA,VWN', def nuc_grad_method(self): raise NotImplementedError - -if __name__ == '__main__': - from pyscf.pbc import gto - cell = gto.Cell() - cell.unit = 'A' - cell.atom = 'C 0., 0., 0.; C 0.8917, 0.8917, 0.8917' - cell.a = '''0. 1.7834 1.7834 - 1.7834 0. 1.7834 - 1.7834 1.7834 0. ''' - - cell.basis = 'gth-dzvp' - cell.pseudo = 'gth-pade' - cell.verbose = 7 - cell.build() - kmesh = [2, 2, 2] - kpts = cell.make_kpts(kmesh, wrap_around=True) - #U_idx = ["2p", "2s"] - #U_val = [5.0, 2.0] - U_idx = ["1 C 2p"] - U_val = [5.0] - - mf = KUKSpU(cell, kpts, U_idx=U_idx, U_val=U_val, minao_ref='gth-szv') - mf.conv_tol = 1e-10 - print (mf.U_idx) - print (mf.U_val) - print (mf.C_ao_lo.shape) - print (mf.kernel()) diff --git a/pyscf/pbc/dft/kukspu_ksymm.py b/pyscf/pbc/dft/kukspu_ksymm.py index 9ce89eb8e3..85c83183cd 100644 --- a/pyscf/pbc/dft/kukspu_ksymm.py +++ b/pyscf/pbc/dft/kukspu_ksymm.py @@ -38,33 +38,3 @@ def __init__(self, cell, kpts=libkpts.KPoints(), xc='LDA,VWN', minao_ref=minao_ref, **kwargs) KUKSpU = KsymAdaptedKUKSpU - -if __name__ == '__main__': - from pyscf.pbc import gto - np.set_printoptions(3, linewidth=1000, suppress=True) - cell = gto.Cell() - cell.unit = 'A' - cell.atom = 'C 0., 0., 0.; C 0.8917, 0.8917, 0.8917' - cell.a = '''0. 1.7834 1.7834 - 1.7834 0. 1.7834 - 1.7834 1.7834 0. ''' - - cell.basis = 'gth-dzvp' - cell.pseudo = 'gth-pade' - cell.verbose = 7 - cell.build() - kmesh = [2, 2, 2] - kpts = cell.make_kpts(kmesh, wrap_around=True, - space_group_symmetry=True, time_reversal_symmetry=True) - #U_idx = ["2p", "2s"] - #U_val = [5.0, 2.0] - U_idx = ["1 C 2p"] - U_val = [5.0] - - mf = KUKSpU(cell, kpts, U_idx=U_idx, U_val=U_val, C_ao_lo='minao', - minao_ref='gth-szv') - mf.conv_tol = 1e-10 - print (mf.U_idx) - print (mf.U_val) - print (mf.C_ao_lo.shape) - print (mf.kernel())