1+ # Copyright 2021-2025 The PySCF Developers. All Rights Reserved.
2+ #
3+ # Licensed under the Apache License, Version 2.0 (the "License");
4+ # you may not use this file except in compliance with the License.
5+ # You may obtain a copy of the License at
6+ #
7+ # http://www.apache.org/licenses/LICENSE-2.0
8+ #
9+ # Unless required by applicable law or agreed to in writing, software
10+ # distributed under the License is distributed on an "AS IS" BASIS,
11+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ # See the License for the specific language governing permissions and
13+ # limitations under the License.
14+
15+ import pyscf
16+ import numpy as np
17+ import unittest
18+ import pytest
19+ from pyscf import dft
20+ from pyscf .geomopt .geometric_solver import optimize
21+ import gpu4pyscf .tdscf .ris as ris
22+
23+ atom = """
24+ H 1.2953527433 -0.4895463266 0.8457608681
25+ C 0.6689912970 -0.0128659340 0.0499408027
26+ H 1.3504336752 0.5361460613 -0.6478375784
27+ C -0.6690192526 -0.0870427249 -0.0501820705
28+ H -1.4008634673 0.6483035475 0.3700152345
29+ H -1.2449949956 -0.8949946232 -0.5680972562
30+ """
31+
32+ bas0 = "def2tzvp"
33+
34+ def setUpModule ():
35+ global mol
36+ mol = pyscf .M (
37+ atom = atom , basis = bas0 , max_memory = 32000 , output = "/dev/null" , verbose = 1 )
38+
39+
40+ def tearDownModule ():
41+ global mol
42+ mol .stdout .close ()
43+ del mol
44+
45+ class KnownValues (unittest .TestCase ):
46+ def test_opt_rks_tda_1 (self ):
47+ mf = dft .RKS (mol , xc = 'pbe0' ).to_gpu ()
48+ mf .kernel ()
49+ assert mf .converged
50+ td_ris = ris .TDA (mf = mf , nstates = 5 , spectra = False , single = False , gram_schmidt = True )
51+ td_ris .conv_tol = 1.0E-5
52+ td_ris .Ktrunc = 0.0
53+ td_ris .kernel ()
54+ mol_gpu = optimize (td_ris )
55+
56+ mff = dft .RKS (mol_gpu , xc = 'pbe0' ).to_gpu ()
57+ mff .kernel ()
58+ assert mff .converged
59+ tdf_ris = ris .TDA (mf = mff , nstates = 5 , spectra = False , single = False , gram_schmidt = True )
60+ tdf_ris .conv_tol = 1.0E-5
61+ tdf_ris .Ktrunc = 0.0
62+ tdf_ris .kernel ()
63+ excited_gradf_ris = tdf_ris .nuc_grad_method ()
64+ excited_gradf_ris .kernel ()
65+ assert np .linalg .norm (excited_gradf_ris .de ) < 3.0e-4
66+
67+ def test_opt_rks_tda_2 (self ):
68+ mf = dft .RKS (mol , xc = 'pbe0' ).to_gpu ()
69+ mf .kernel ()
70+ assert mf .converged
71+ td_ris = ris .TDA (mf = mf , nstates = 5 , spectra = False , single = False , gram_schmidt = True )
72+ td_ris .conv_tol = 1.0E-5
73+ td_ris .Ktrunc = 0.0
74+ td_ris .kernel ()
75+
76+ excited_grad = td_ris .nuc_grad_method ().as_scanner (state = 1 )
77+ mol_gpu = excited_grad .optimizer ().kernel ()
78+
79+ mff = dft .RKS (mol_gpu , xc = 'pbe0' ).to_gpu ()
80+ mff .kernel ()
81+ assert mff .converged
82+ tdf_ris = ris .TDA (mf = mff , nstates = 5 , spectra = False , single = False , gram_schmidt = True )
83+ tdf_ris .conv_tol = 1.0E-5
84+ tdf_ris .Ktrunc = 0.0
85+ tdf_ris .kernel ()
86+ excited_gradf_ris = tdf_ris .nuc_grad_method ()
87+ excited_gradf_ris .kernel ()
88+ assert np .linalg .norm (excited_gradf_ris .de ) < 3.0e-4
89+
90+
91+ if __name__ == "__main__" :
92+ print ("Full Tests for geomtry optimization for excited states using TDDFT-ris." )
93+ unittest .main ()
0 commit comments