1#!/usr/bin/env python
2# Copyright 2014-2018 The PySCF Developers. All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16# Author: Qiming Sun <osirpt.sun@gmail.com>
17#
18
19from pyscf.pbc.tdscf import rhf
20from pyscf.pbc.tdscf import uhf
21from pyscf.pbc.tdscf import krhf
22from pyscf.pbc.tdscf import kuhf
23
24try:
25    from pyscf.pbc.tdscf import rks
26    from pyscf.pbc.tdscf import uks
27    from pyscf.pbc.tdscf import krks
28    from pyscf.pbc.tdscf import kuks
29except (ImportError, IOError):
30    pass
31
32def TDHF(mf):
33    import numpy
34    if numpy.abs(getattr(mf, 'kpt', 0)).max() > 1e-9:
35        raise NotImplementedError
36    from pyscf.pbc import scf
37    if getattr(mf, 'xc', None):
38        raise RuntimeError('TDHF does not support DFT object %s' % mf)
39    if isinstance(mf, scf.uhf.UHF):
40        #mf = scf.addons.convert_to_uhf(mf) # To remove newton decoration
41        return uhf.TDHF(mf)
42    else:
43        #mf = scf.addons.convert_to_rhf(mf)
44        return rhf.TDHF(mf)
45
46def TDA(mf):
47    import numpy
48    if numpy.abs(getattr(mf, 'kpt', 0)).max() > 1e-9:
49        raise NotImplementedError
50    from pyscf.pbc import scf
51    if isinstance(mf, scf.uhf.UHF):
52        #mf = scf.addons.convert_to_uhf(mf)
53        if getattr(mf, 'xc', None):
54            return uks.TDA(mf)
55        else:
56            return uhf.TDA(mf)
57    else:
58        #mf = scf.addons.convert_to_rhf(mf)
59        if getattr(mf, 'xc', None):
60            return rks.TDA(mf)
61        else:
62            return rhf.TDA(mf)
63
64def TDDFT(mf):
65    import numpy
66    if numpy.abs(getattr(mf, 'kpt', 0)).max() > 1e-9:
67        raise NotImplementedError
68    from pyscf.pbc import scf
69    if isinstance(mf, scf.uhf.UHF):
70        #mf = scf.addons.convert_to_uhf(mf)
71        if getattr(mf, 'xc', None):
72            return uks.tddft(mf)
73        else:
74            return uhf.TDHF(mf)
75    else:
76        #mf = scf.addons.convert_to_rhf(mf)
77        if getattr(mf, 'xc', None):
78            return rks.tddft(mf)
79        else:
80            return rhf.TDHF(mf)
81
82def KTDHF(mf):
83    from pyscf.pbc import scf
84    if getattr(mf, 'xc', None):
85        raise RuntimeError('TDHF does not support DFT object %s' % mf)
86    if isinstance(mf, scf.uhf.UHF):
87        return kuhf.TDHF(mf)
88    else:
89        return krhf.TDHF(mf)
90
91def KTDA(mf):
92    from pyscf.pbc import scf
93    if isinstance(mf, scf.uhf.UHF):
94        if getattr(mf, 'xc', None):
95            return kuks.TDA(mf)
96        else:
97            return kuhf.TDA(mf)
98    else:
99        if getattr(mf, 'xc', None):
100            return krks.TDA(mf)
101        else:
102            return krhf.TDA(mf)
103
104def KTDDFT(mf):
105    from pyscf.pbc import scf
106    if isinstance(mf, scf.uhf.UHF):
107        if getattr(mf, 'xc', None):
108            return kuks.tddft(mf)
109        else:
110            return kuhf.TDHF(mf)
111    else:
112        if getattr(mf, 'xc', None):
113            return krks.tddft(mf)
114        else:
115            return krhf.TDHF(mf)
116
117KTD = KTDDFT
118
119