1#!/usr/bin/env python
2# Copyright 2014-2020 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
16from pyscf import lib
17from pyscf import scf
18from pyscf.ci import cisd
19from pyscf.ci import ucisd
20from pyscf.ci import gcisd
21from pyscf.cc import qcisd
22
23def CISD(mf, frozen=None, mo_coeff=None, mo_occ=None):
24    from pyscf.soscf import newton_ah
25
26    if isinstance(mf, scf.uhf.UHF):
27        return UCISD(mf, frozen, mo_coeff, mo_occ)
28    elif isinstance(mf, scf.rohf.ROHF):
29        lib.logger.warn(mf, 'RCISD method does not support ROHF method. ROHF object '
30                        'is converted to UHF object and UCISD method is called.')
31        return UCISD(mf, frozen, mo_coeff, mo_occ)
32    else:
33        return RCISD(mf, frozen, mo_coeff, mo_occ)
34CISD.__doc__ = cisd.CISD.__doc__
35
36def RCISD(mf, frozen=None, mo_coeff=None, mo_occ=None):
37    from pyscf.soscf import newton_ah
38
39    if isinstance(mf, newton_ah._CIAH_SOSCF) or not isinstance(mf, scf.hf.RHF):
40        mf = scf.addons.convert_to_rhf(mf)
41
42    if getattr(mf, 'with_df', None):
43        raise NotImplementedError('DF-RCISD')
44    else:
45        return cisd.RCISD(mf, frozen, mo_coeff, mo_occ)
46RCISD.__doc__ = cisd.RCISD.__doc__
47
48def UCISD(mf, frozen=None, mo_coeff=None, mo_occ=None):
49    from pyscf.soscf import newton_ah
50
51    if isinstance(mf, newton_ah._CIAH_SOSCF) or not isinstance(mf, scf.uhf.UHF):
52        mf = scf.addons.convert_to_uhf(mf)
53
54    if getattr(mf, 'with_df', None):
55        raise NotImplementedError('DF-UCISD')
56    else:
57        return ucisd.UCISD(mf, frozen, mo_coeff, mo_occ)
58UCISD.__doc__ = ucisd.UCISD.__doc__
59
60
61def GCISD(mf, frozen=None, mo_coeff=None, mo_occ=None):
62    from pyscf.soscf import newton_ah
63
64    if isinstance(mf, newton_ah._CIAH_SOSCF) or not isinstance(mf, scf.ghf.GHF):
65        mf = scf.addons.convert_to_ghf(mf)
66
67    if getattr(mf, 'with_df', None):
68        raise NotImplementedError('DF-GCISD')
69    else:
70        return gcisd.GCISD(mf, frozen, mo_coeff, mo_occ)
71GCISD.__doc__ = gcisd.GCISD.__doc__
72
73
74def QCISD(mf, frozen=None, mo_coeff=None, mo_occ=None):
75    if isinstance(mf, scf.uhf.UHF):
76        raise NotImplementedError
77    elif isinstance(mf, scf.ghf.GHF):
78        raise NotImplementedError
79    else:
80        return RQCISD(mf, frozen, mo_coeff, mo_occ)
81QCISD.__doc__ = qcisd.QCISD.__doc__
82
83scf.hf.SCF.QCISD = QCISD
84
85def RQCISD(mf, frozen=None, mo_coeff=None, mo_occ=None):
86    import numpy
87    from pyscf import lib
88    from pyscf.soscf import newton_ah
89
90    if isinstance(mf, scf.uhf.UHF):
91        raise RuntimeError('RQCISD cannot be used with UHF method.')
92    elif isinstance(mf, scf.rohf.ROHF):
93        lib.logger.warn(mf, 'RQCISD method does not support ROHF method. ROHF object '
94                        'is converted to UHF object and UQCISD method is called.')
95        mf = scf.addons.convert_to_uhf(mf)
96        raise NotImplementedError
97
98    if isinstance(mf, newton_ah._CIAH_SOSCF) or not isinstance(mf, scf.hf.RHF):
99        mf = scf.addons.convert_to_rhf(mf)
100
101    elif numpy.iscomplexobj(mo_coeff) or numpy.iscomplexobj(mf.mo_coeff):
102        raise NotImplementedError
103
104    else:
105        return qcisd.QCISD(mf, frozen, mo_coeff, mo_occ)
106RQCISD.__doc__ = qcisd.QCISD.__doc__
107