forked from pyscf/pyscf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Ready for review] Complete implementation of pbc/tdscf (pyscf#1793)
* Bug fix for RSDF due to Mole basis sorting * Bug fix for pbc df Jbuild for hermi == 0 * improve TDSCF init guess degeneracy handle * complete pbc tdscf * b3lyp -> b3lyp5 * adjust values due to v2.3 * add examples; add finalize * remove non-gamma point exception * fix flake8 error * remove numer instable tests (higher roots) * update tests * fix wrong num of states * bug fix in response * keep minimal changes for pbc _response * better handle of exxdiv, including vcut * add NotImplementedError for rsjk + non-zero kshift * fix shifted kpt for TDRKS/UKS * fix flake8 error * revert CasidaTDDFT * fix flake error --------- Co-authored-by: hongzhouye <>
- Loading branch information
1 parent
e90d834
commit 4c0998d
Showing
41 changed files
with
2,673 additions
and
432 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 |
---|---|---|
@@ -1,65 +1,91 @@ | ||
#!/usr/bin/env python | ||
# | ||
# Author: Hong-Zhou Ye <[email protected]> | ||
# | ||
|
||
''' | ||
TDDFT with k-point sampling or at an individual k-point | ||
import numpy as np | ||
from pyscf.pbc import gto, scf, tdscf | ||
from pyscf import scf as molscf | ||
from pyscf import lib | ||
|
||
(This feature is in testing. We observe numerical stability problem in TDDFT | ||
diagonalization.) | ||
|
||
''' | ||
TDSCF with k-point sampling | ||
''' | ||
atom = 'C 0 0 0; C 0.8925000000 0.8925000000 0.8925000000' | ||
a = ''' | ||
1.7850000000 1.7850000000 0.0000000000 | ||
0.0000000000 1.7850000000 1.7850000000 | ||
1.7850000000 0.0000000000 1.7850000000 | ||
''' | ||
basis = ''' | ||
C S | ||
9.031436 -1.960629e-02 | ||
3.821255 -1.291762e-01 | ||
0.473725 5.822572e-01 | ||
C P | ||
4.353457 8.730943e-02 | ||
1.266307 2.797034e-01 | ||
0.398715 5.024424e-01 | ||
''' # a trimmed DZ basis for fast test | ||
pseudo = 'gth-hf-rev' | ||
cell = gto.M(atom=atom, basis=basis, a=a, pseudo=pseudo).set(verbose=3) | ||
kmesh = [2,1,1] | ||
kpts = cell.make_kpts(kmesh) | ||
nkpts = len(kpts) | ||
mf = scf.KRHF(cell, kpts).rs_density_fit().run() | ||
|
||
from pyscf.pbc import gto | ||
from pyscf.pbc import scf | ||
from pyscf.pbc import df | ||
from pyscf.pbc import tdscf | ||
log = lib.logger.new_logger(mf) | ||
|
||
cell = gto.Cell() | ||
cell.unit = 'B' | ||
cell.atom = ''' | ||
C 0. 0. 0. | ||
C 1.68506879 1.68506879 1.68506879 | ||
''' | ||
cell.a = ''' | ||
0. 3.37013758 3.37013758 | ||
3.37013758 0. 3.37013758 | ||
3.37013758 3.37013758 0. | ||
''' k-point TDSCF solutions can have non-zero momentum transfer between particle and hole. | ||
This can be controlled by `td.kshift_lst`. By default, kshift_lst = [0] and only the | ||
zero-momentum transfer solution (i.e., 'vertical' in k-space) will be solved, as | ||
demonstrated in the example below. | ||
''' | ||
cell.basis = 'gth-szv' | ||
cell.pseudo = 'gth-pade' | ||
cell.build() | ||
mf = scf.KRHF(cell, cell.make_kpts([2,2,2])) | ||
mf.run() | ||
td = mf.TDA().set(nstates=5).run() | ||
log.note('RHF-TDA:') | ||
for kshift,es in zip(td.kshift_lst,td.e): | ||
log.note('kshift = %d Eex = %s', kshift, ' '.join([f'{e:.3f}' for e in es*27.2114])) | ||
|
||
td = tdscf.KTDA(mf) | ||
td.nstates = 5 | ||
td.verbose = 5 | ||
print(td.kernel()[0] * 27.2114) | ||
''' If GDF/RSDF is used as the density fitting method (as in this example), solutions | ||
with non-zero particle-hole momentum-transfer solution is also possible. The example | ||
below demonstrates how to calculate solutions with all possible kshift. | ||
td = tdscf.KTDDFT(mf) | ||
td.nstates = 5 | ||
td.verbose = 5 | ||
print(td.kernel()[0] * 27.2114) | ||
NOTE: if FFTDF is used, pyscf will set `kshift_lst` to [0]. | ||
''' | ||
td = mf.TDHF().set(nstates=5, kshift_lst=list(range(nkpts))).run() | ||
log.note('RHF-TDHF:') | ||
for kshift,es in zip(td.kshift_lst,td.e): | ||
log.note('kshift = %d Eex = %s', kshift, ' '.join([f'{e:.3f}' for e in es*27.2114])) | ||
|
||
mf = scf.RHF(cell) | ||
mf.kernel() | ||
td = tdscf.TDA(mf) | ||
td.kernel() | ||
|
||
# | ||
# Gamma-point RKS | ||
# | ||
ks = scf.RKS(cell) | ||
ks.run() | ||
''' TDHF at a single k-point compared to molecular TDSCF | ||
''' | ||
atom = ''' | ||
O 0.00000 0.00000 0.11779 | ||
H 0.00000 0.75545 -0.47116 | ||
H 0.00000 -0.75545 -0.47116 | ||
''' | ||
a = np.eye(3) * 20 # big box to match isolated molecule | ||
basis = 'sto-3g' | ||
auxbasis = 'weigend' | ||
cell = gto.M(atom=atom, basis=basis, a=a).set(verbose=3) | ||
mol = cell.to_mol() | ||
|
||
td = tdscf.KTDDFT(ks) | ||
td.nstates = 5 | ||
td.verbose = 5 | ||
print(td.kernel()[0] * 27.2114) | ||
log = lib.logger.new_logger(cell) | ||
|
||
xc = 'b3lyp' | ||
# pbc | ||
mf = scf.RKS(cell).set(xc=xc).rs_density_fit(auxbasis=auxbasis).run() | ||
pbctda = mf.TDA().run() | ||
pbctd = mf.TDDFT().run() | ||
# mol | ||
molmf = molscf.RKS(cell).set(xc=xc).density_fit(auxbasis=auxbasis).run() | ||
moltda = molmf.TDA().run() | ||
moltd = molmf.TDDFT().run() | ||
|
||
# TODO: | ||
#kpt = cell.get_abs_kpts([0.25, 0.25, 0.25]) | ||
#mf = scf.RHF(cell, kpt=kpt) | ||
#mf.kernel() | ||
#td = tdscf.TDA(mf) | ||
#td.kernel() | ||
_format = lambda e: ' '.join([f'{x*27.2114:.3f}' for x in e]) | ||
log.note('PBC TDA : %s', _format(pbctda.e)) | ||
log.note('Mol TDA : %s', _format(moltda.e)) | ||
log.note('PBC TDDFT: %s', _format(pbctd.e)) | ||
log.note('Mol TDDFT: %s', _format(moltd.e)) |
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,46 @@ | ||
#!/usr/bin/env python | ||
# | ||
# Author: Hong-Zhou Ye <[email protected]> | ||
# | ||
|
||
|
||
from pyscf import gto, scf, tdscf | ||
|
||
|
||
''' TDSCF selected particle-hole pairs that have low energy difference (e.g., HOMO -> LUMO, | ||
HOMO -> LUMO+1 etc.) as init guess for the iterative solution of the TDSCF equation. | ||
In cases where there are many near degenerate p-h pairs, their contributions to the | ||
final TDSCF solutions can all be significnat and all such pairs should be included. | ||
The determination of such near degeneracies in p-h pairs is controlled by the | ||
`deg_eia_thresh` variable: if the excitation energy of two p-h pairs differs less | ||
than `deg_eia_thresh`, they will be considered degenerate and selected simultaneously | ||
as init guess. | ||
This example demonstrates the use of this variable to reduce the chance of missing | ||
roots in TDSCF calculations. A molecule is used here for demonstration but the same | ||
applies to periodic TDSCF calculations. | ||
''' | ||
|
||
atom = ''' | ||
O 0.00000 0.00000 0.11779 | ||
H 0.00000 0.75545 -0.47116 | ||
H 0.00000 -0.75545 -0.47116 | ||
O 4.00000 0.00000 0.11779 | ||
H 4.00000 0.75545 -0.47116 | ||
H 4.00000 -0.75545 -0.47116 | ||
''' | ||
basis = 'cc-pvdz' | ||
|
||
mol = gto.M(atom=atom, basis=basis) | ||
mf = scf.RHF(mol).density_fit().run() | ||
|
||
''' By default, `deg_eia_thresh` = 1e-3 (Ha) as can be seen in the output if verbose >= 4. | ||
''' | ||
mf.TDA().set(nroots=6).run() | ||
|
||
''' One can check if there are missing roots by using a larger value for `deg_eia_thresh`. | ||
Note that this will increase the number of init guess vectors and increase the cost of | ||
solving the TDSCF equation. | ||
''' | ||
mf.TDA().set(nroots=6, deg_eia_thresh=0.1).run() |
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
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
Oops, something went wrong.