Esempio n. 1
0
def convert_to_rhf(mf, out=None):
    '''Convert the given mean-field object to the corresponding restricted
    HF/KS object
    '''
    from pyscf.pbc import scf
    from pyscf.pbc import dft

    if getattr(mf, 'nelec', None) is None:
        nelec = mf.cell.nelec
    else:
        nelec = mf.nelec

    if out is not None:
        assert(isinstance(out, (scf.hf.RHF, scf.khf.KRHF)))
        if isinstance(mf, scf.khf.KSCF):
            assert(isinstance(out, scf.khf.KSCF))
        else:
            assert(not isinstance(out, scf.khf.KSCF))

    elif nelec[0] != nelec[1] and isinstance(mf, scf.rohf.ROHF):
        if getattr(mf, '_scf', None):
            return mol_addons._update_mf_without_soscf(mf, copy.copy(mf._scf), False)
        else:
            return copy.copy(mf)

    else:
        if isinstance(mf, (scf.hf.RHF, scf.khf.KRHF)):
            return copy.copy(mf)
        else:
            unknown_cls = [scf.kghf.KGHF]
            for i, cls in enumerate(mf.__class__.__mro__):
                if cls in unknown_cls:
                    raise NotImplementedError(
                        "No conversion from %s to rhf object" % cls)

            if nelec[0] == nelec[1]:
                known_cls = {dft.kuks.KUKS : dft.krks.KRKS,
                             scf.kuhf.KUHF : scf.khf.KRHF ,
                             dft.uks.UKS   : dft.rks.RKS  ,
                             scf.uhf.UHF   : scf.hf.RHF   ,
                             dft.kroks.KROKS : dft.krks.KRKS,
                             scf.krohf.KROHF : scf.khf.KRHF ,
                             dft.roks.ROKS   : dft.rks.RKS  ,
                             scf.rohf.ROHF   : scf.hf.RHF   }
            else:
                known_cls = {dft.kuks.KUKS : dft.krks.KROKS,
                             scf.kuhf.KUHF : scf.khf.KROHF ,
                             dft.uks.UKS   : dft.rks.ROKS  ,
                             scf.uhf.UHF   : scf.hf.ROHF   }
            # .with_df should never be removed or changed during the conversion.
            # It is needed to compute JK matrix in all pbc SCF objects
            out = mol_addons._object_without_soscf(mf, known_cls, remove_df=False)

    out = mol_addons.convert_to_rhf(mf, out, False)
    # Manually update .with_df because this attribute may not be passed to the
    # output object correctly in molecular convert function
    out.with_df = mf.with_df
    return out
Esempio n. 2
0
def convert_to_rhf(mf, out=None):
    '''Convert the given mean-field object to the corresponding restricted
    HF/KS object
    '''
    from pyscf.scf import addons as mol_addons
    from pyscf.pbc import scf
    from pyscf.pbc import dft

    if getattr(mf, 'nelec', None) is None:
        nelec = mf.cell.nelec
    else:
        nelec = mf.nelec

    if out is not None:
        assert (isinstance(out, (scf.hf.RHF, scf.khf.KRHF)))
        if isinstance(mf, scf.khf.KSCF):
            assert (isinstance(out, scf.khf.KSCF))
        else:
            assert (not isinstance(out, scf.khf.KSCF))

    elif nelec[0] != nelec[1] and isinstance(mf, scf.rohf.ROHF):
        if hasattr(mf, '_scf'):
            return mol_addons._update_mf_without_soscf(mf, copy.copy(mf._scf),
                                                       False)
        else:
            return copy.copy(mf)

    else:
        if isinstance(mf, (scf.hf.RHF, scf.khf.KRHF)):
            return copy.copy(mf)
        else:
            unknown_cls = [scf.kghf.KGHF]
            for i, cls in enumerate(mf.__class__.__mro__):
                if cls in unknown_cls:
                    raise NotImplementedError(
                        "No conversion from %s to rhf object" % cls)

            if nelec[0] == nelec[1]:
                known_cls = {
                    dft.kuks.KUKS: dft.krks.KRKS,
                    scf.kuhf.KUHF: scf.khf.KRHF,
                    dft.uks.UKS: dft.rks.RKS,
                    scf.uhf.UHF: scf.hf.RHF,
                    dft.kroks.KROKS: dft.krks.KRKS,
                    scf.krohf.KROHF: scf.khf.KRHF,
                    dft.roks.ROKS: dft.rks.RKS,
                    scf.rohf.ROHF: scf.hf.RHF
                }
            else:
                known_cls = {
                    dft.kuks.KUKS: dft.krks.KROKS,
                    scf.kuhf.KUHF: scf.khf.KROHF,
                    dft.uks.UKS: dft.rks.ROKS,
                    scf.uhf.UHF: scf.hf.ROHF
                }
            out = mol_addons._object_without_soscf(mf, known_cls, False)

    return mol_addons.convert_to_rhf(mf, out, False)
Esempio n. 3
0
def convert_to_rhf(mf, out=None):
    '''Convert the given mean-field object to the corresponding restricted
    HF/KS object
    '''
    from pyscf.scf import addons as mol_addons
    from pyscf.pbc import scf
    from pyscf.pbc import dft

    if getattr(mf, 'nelec', None) is None:
        nelec = mf.cell.nelec
    else:
        nelec = mf.nelec

    if out is not None:
        assert(isinstance(out, (scf.hf.RHF, scf.khf.KRHF)))
        if isinstance(mf, scf.khf.KSCF):
            assert(isinstance(out, scf.khf.KSCF))
        else:
            assert(not isinstance(out, scf.khf.KSCF))

    elif nelec[0] != nelec[1] and isinstance(mf, scf.rohf.ROHF):
        if getattr(mf, '_scf', None):
            return mol_addons._update_mf_without_soscf(mf, copy.copy(mf._scf), False)
        else:
            return copy.copy(mf)

    else:
        if isinstance(mf, (scf.hf.RHF, scf.khf.KRHF)):
            return copy.copy(mf)
        else:
            unknown_cls = [scf.kghf.KGHF]
            for i, cls in enumerate(mf.__class__.__mro__):
                if cls in unknown_cls:
                    raise NotImplementedError(
                        "No conversion from %s to rhf object" % cls)

            if nelec[0] == nelec[1]:
                known_cls = {dft.kuks.KUKS : dft.krks.KRKS,
                             scf.kuhf.KUHF : scf.khf.KRHF ,
                             dft.uks.UKS   : dft.rks.RKS  ,
                             scf.uhf.UHF   : scf.hf.RHF   ,
                             dft.kroks.KROKS : dft.krks.KRKS,
                             scf.krohf.KROHF : scf.khf.KRHF ,
                             dft.roks.ROKS   : dft.rks.RKS  ,
                             scf.rohf.ROHF   : scf.hf.RHF   }
            else:
                known_cls = {dft.kuks.KUKS : dft.krks.KROKS,
                             scf.kuhf.KUHF : scf.khf.KROHF ,
                             dft.uks.UKS   : dft.rks.ROKS  ,
                             scf.uhf.UHF   : scf.hf.ROHF   }
            out = mol_addons._object_without_soscf(mf, known_cls, False)

    return mol_addons.convert_to_rhf(mf, out, False)
Esempio n. 4
0
    def test_convert_to_scf(self):
        from pyscf.x2c import x2c
        from pyscf.df import df_jk
        from pyscf.soscf import newton_ah
        addons.convert_to_rhf(dft.RKS(mol))
        addons.convert_to_uhf(dft.RKS(mol))
        addons.convert_to_ghf(dft.RKS(mol))
        addons.convert_to_rhf(dft.UKS(mol))
        addons.convert_to_uhf(dft.UKS(mol))
        addons.convert_to_ghf(dft.UKS(mol))
        #addons.convert_to_rhf(dft.GKS(mol))
        #addons.convert_to_uhf(dft.GKS(mol))
        addons.convert_to_ghf(dft.GKS(mol))

        self.assertTrue(isinstance(addons.convert_to_rhf(mf), scf.rhf.RHF))
        self.assertTrue(isinstance(addons.convert_to_uhf(mf), scf.uhf.UHF))
        self.assertTrue(isinstance(addons.convert_to_ghf(mf), scf.ghf.GHF))
        self.assertTrue(
            isinstance(addons.convert_to_rhf(scf.UHF(mol)), scf.rhf.RHF))
        self.assertTrue(isinstance(addons.convert_to_rhf(mf_u), scf.rohf.ROHF))
        self.assertTrue(isinstance(addons.convert_to_uhf(mf_u), scf.uhf.UHF))
        self.assertTrue(isinstance(addons.convert_to_ghf(mf_u), scf.ghf.GHF))
        self.assertTrue(
            isinstance(addons.convert_to_rhf(sym_mf), scf.hf_symm.RHF))
        self.assertTrue(
            isinstance(addons.convert_to_uhf(sym_mf), scf.uhf_symm.UHF))
        self.assertTrue(
            isinstance(addons.convert_to_ghf(sym_mf), scf.ghf_symm.GHF))
        self.assertTrue(
            isinstance(addons.convert_to_rhf(sym_mf_u), scf.hf_symm.ROHF))
        self.assertTrue(
            isinstance(addons.convert_to_uhf(sym_mf_u), scf.uhf_symm.UHF))
        self.assertTrue(
            isinstance(addons.convert_to_ghf(sym_mf_u), scf.ghf_symm.GHF))

        mf1 = copy.copy(mf)
        self.assertTrue(isinstance(mf1.convert_from_(mf), scf.rhf.RHF))
        self.assertTrue(isinstance(mf1.convert_from_(mf_u), scf.rhf.RHF))
        self.assertFalse(isinstance(mf1.convert_from_(mf_u), scf.rohf.ROHF))
        self.assertTrue(isinstance(mf1.convert_from_(sym_mf), scf.rhf.RHF))
        self.assertTrue(isinstance(mf1.convert_from_(sym_mf_u), scf.rhf.RHF))
        self.assertFalse(isinstance(mf1.convert_from_(sym_mf_u),
                                    scf.rohf.ROHF))
        self.assertFalse(isinstance(mf1.convert_from_(sym_mf),
                                    scf.hf_symm.RHF))
        self.assertFalse(
            isinstance(mf1.convert_from_(sym_mf_u), scf.hf_symm.RHF))
        mf1 = copy.copy(mf_u)
        self.assertTrue(isinstance(mf1.convert_from_(mf), scf.uhf.UHF))
        self.assertTrue(isinstance(mf1.convert_from_(mf_u), scf.uhf.UHF))
        self.assertTrue(isinstance(mf1.convert_from_(sym_mf), scf.uhf.UHF))
        self.assertTrue(isinstance(mf1.convert_from_(sym_mf_u), scf.uhf.UHF))
        self.assertFalse(
            isinstance(mf1.convert_from_(sym_mf), scf.uhf_symm.UHF))
        self.assertFalse(
            isinstance(mf1.convert_from_(sym_mf_u), scf.uhf_symm.UHF))
        mf1 = scf.GHF(mol)
        self.assertTrue(isinstance(mf1.convert_from_(mf), scf.ghf.GHF))
        self.assertTrue(isinstance(mf1.convert_from_(mf_u), scf.ghf.GHF))
        self.assertTrue(isinstance(mf1.convert_from_(sym_mf), scf.ghf.GHF))
        self.assertTrue(isinstance(mf1.convert_from_(sym_mf_u), scf.ghf.GHF))
        self.assertFalse(
            isinstance(mf1.convert_from_(sym_mf), scf.ghf_symm.GHF))
        self.assertFalse(
            isinstance(mf1.convert_from_(sym_mf_u), scf.ghf_symm.GHF))

        self.assertTrue(
            isinstance(
                addons.convert_to_rhf(scf.RHF(mol).density_fit(),
                                      remove_df=False), df_jk._DFHF))
        self.assertTrue(
            isinstance(
                addons.convert_to_uhf(scf.RHF(mol).density_fit(),
                                      remove_df=False), df_jk._DFHF))
        self.assertTrue(
            isinstance(
                addons.convert_to_ghf(scf.RHF(mol).density_fit(),
                                      remove_df=False), df_jk._DFHF))
        self.assertTrue(
            isinstance(
                addons.convert_to_rhf(scf.UHF(mol).density_fit(),
                                      remove_df=False), df_jk._DFHF))
        self.assertTrue(
            isinstance(
                addons.convert_to_uhf(scf.UHF(mol).density_fit(),
                                      remove_df=False), df_jk._DFHF))
        self.assertTrue(
            isinstance(
                addons.convert_to_ghf(scf.UHF(mol).density_fit(),
                                      remove_df=False), df_jk._DFHF))
        #self.assertTrue(isinstance(addons.convert_to_rhf(scf.GHF(mol).density_fit(), remove_df=False),df_jk. _DFHF))
        #self.assertTrue(isinstance(addons.convert_to_uhf(scf.GHF(mol).density_fit(), remove_df=False),df_jk. _DFHF))
        self.assertTrue(
            isinstance(
                addons.convert_to_ghf(scf.GHF(mol).density_fit(),
                                      remove_df=False), df_jk._DFHF))
        self.assertFalse(
            isinstance(
                addons.convert_to_rhf(scf.RHF(mol).density_fit(),
                                      out=scf.RHF(mol),
                                      remove_df=False), df_jk._DFHF))
        self.assertFalse(
            isinstance(
                addons.convert_to_uhf(scf.RHF(mol).density_fit(),
                                      out=scf.UHF(mol),
                                      remove_df=False), df_jk._DFHF))
        self.assertFalse(
            isinstance(
                addons.convert_to_ghf(scf.RHF(mol).density_fit(),
                                      out=scf.GHF(mol),
                                      remove_df=False), df_jk._DFHF))
        self.assertFalse(
            isinstance(
                addons.convert_to_rhf(scf.UHF(mol).density_fit(),
                                      out=scf.RHF(mol),
                                      remove_df=False), df_jk._DFHF))
        self.assertFalse(
            isinstance(
                addons.convert_to_uhf(scf.UHF(mol).density_fit(),
                                      out=scf.UHF(mol),
                                      remove_df=False), df_jk._DFHF))
        self.assertFalse(
            isinstance(
                addons.convert_to_ghf(scf.UHF(mol).density_fit(),
                                      out=scf.GHF(mol),
                                      remove_df=False), df_jk._DFHF))
        #self.assertFalse(isinstance(addons.convert_to_rhf(scf.GHF(mol).density_fit(), out=scf.RHF(mol), remove_df=False),df_jk. _DFHF))
        #self.assertFalse(isinstance(addons.convert_to_uhf(scf.GHF(mol).density_fit(), out=scf.UHF(mol), remove_df=False),df_jk. _DFHF))
        self.assertFalse(
            isinstance(
                addons.convert_to_ghf(scf.GHF(mol).density_fit(),
                                      out=scf.GHF(mol),
                                      remove_df=False), df_jk._DFHF))
        self.assertFalse(
            isinstance(
                addons.convert_to_rhf(scf.RHF(mol).density_fit(),
                                      out=scf.RHF(mol),
                                      remove_df=True), df_jk._DFHF))
        self.assertFalse(
            isinstance(
                addons.convert_to_uhf(scf.RHF(mol).density_fit(),
                                      out=scf.UHF(mol),
                                      remove_df=True), df_jk._DFHF))
        self.assertFalse(
            isinstance(
                addons.convert_to_ghf(scf.RHF(mol).density_fit(),
                                      out=scf.GHF(mol),
                                      remove_df=True), df_jk._DFHF))
        self.assertFalse(
            isinstance(
                addons.convert_to_rhf(scf.UHF(mol).density_fit(),
                                      out=scf.RHF(mol),
                                      remove_df=True), df_jk._DFHF))
        self.assertFalse(
            isinstance(
                addons.convert_to_uhf(scf.UHF(mol).density_fit(),
                                      out=scf.UHF(mol),
                                      remove_df=True), df_jk._DFHF))
        self.assertFalse(
            isinstance(
                addons.convert_to_ghf(scf.UHF(mol).density_fit(),
                                      out=scf.GHF(mol),
                                      remove_df=True), df_jk._DFHF))
        #self.assertFalse(isinstance(addons.convert_to_rhf(scf.GHF(mol).density_fit(), out=scf.RHF(mol), remove_df=True),df_jk. _DFHF))
        #self.assertFalse(isinstance(addons.convert_to_uhf(scf.GHF(mol).density_fit(), out=scf.UHF(mol), remove_df=True),df_jk. _DFHF))
        self.assertFalse(
            isinstance(
                addons.convert_to_ghf(scf.GHF(mol).density_fit(),
                                      out=scf.GHF(mol),
                                      remove_df=True), df_jk._DFHF))

        addons.convert_to_rhf(scf.RHF(mol).x2c().density_fit())
        addons.convert_to_uhf(scf.RHF(mol).x2c().density_fit())
        addons.convert_to_ghf(scf.RHF(mol).x2c().density_fit())
        addons.convert_to_rhf(scf.UHF(mol).x2c().density_fit())
        addons.convert_to_uhf(scf.UHF(mol).x2c().density_fit())
        addons.convert_to_ghf(scf.UHF(mol).x2c().density_fit())
        #addons.convert_to_rhf(scf.GHF(mol).x2c().density_fit())
        #addons.convert_to_uhf(scf.GHF(mol).x2c().density_fit())
        addons.convert_to_ghf(scf.GHF(mol).x2c().density_fit())

        self.assertFalse(
            isinstance(
                addons.convert_to_rhf(
                    scf.RHF(mol).x2c().newton().density_fit()),
                newton_ah._CIAH_SOSCF))
        self.assertFalse(
            isinstance(
                addons.convert_to_uhf(
                    scf.RHF(mol).x2c().newton().density_fit()),
                newton_ah._CIAH_SOSCF))
        self.assertFalse(
            isinstance(
                addons.convert_to_ghf(
                    scf.RHF(mol).x2c().newton().density_fit()),
                newton_ah._CIAH_SOSCF))
        self.assertFalse(
            isinstance(
                addons.convert_to_rhf(
                    scf.UHF(mol).x2c().newton().density_fit()),
                newton_ah._CIAH_SOSCF))
        self.assertFalse(
            isinstance(
                addons.convert_to_uhf(
                    scf.UHF(mol).x2c().newton().density_fit()),
                newton_ah._CIAH_SOSCF))
        self.assertFalse(
            isinstance(
                addons.convert_to_ghf(
                    scf.UHF(mol).x2c().newton().density_fit()),
                newton_ah._CIAH_SOSCF))
        #self.assertFalse(isinstance(addons.convert_to_rhf(scf.GHF(mol).x2c().newton().density_fit()), newton_ah._CIAH_SOSCF))
        #self.assertFalse(isinstance(addons.convert_to_uhf(scf.GHF(mol).x2c().newton().density_fit()), newton_ah._CIAH_SOSCF))
        self.assertFalse(
            isinstance(
                addons.convert_to_ghf(
                    scf.GHF(mol).x2c().newton().density_fit()),
                newton_ah._CIAH_SOSCF))

        self.assertFalse(
            isinstance(
                addons.convert_to_rhf(scf.RHF(mol).newton().density_fit()),
                df_jk._DFHF))
        self.assertFalse(
            isinstance(
                addons.convert_to_uhf(scf.RHF(mol).newton().density_fit()),
                df_jk._DFHF))
        self.assertFalse(
            isinstance(
                addons.convert_to_ghf(scf.RHF(mol).newton().density_fit()),
                df_jk._DFHF))
        self.assertFalse(
            isinstance(
                addons.convert_to_rhf(scf.UHF(mol).newton().density_fit()),
                df_jk._DFHF))
        self.assertFalse(
            isinstance(
                addons.convert_to_uhf(scf.UHF(mol).newton().density_fit()),
                df_jk._DFHF))
        self.assertFalse(
            isinstance(
                addons.convert_to_ghf(scf.UHF(mol).newton().density_fit()),
                df_jk._DFHF))
        #self.assertFalse(isinstance(addons.convert_to_rhf(scf.GHF(mol).newton().density_fit()), df_jk._DFHF))
        #self.assertFalse(isinstance(addons.convert_to_uhf(scf.GHF(mol).newton().density_fit()), df_jk._DFHF))
        self.assertFalse(
            isinstance(
                addons.convert_to_ghf(scf.GHF(mol).newton().density_fit()),
                df_jk._DFHF))

        self.assertTrue(
            isinstance(
                addons.convert_to_rhf(scf.RHF(mol).density_fit().newton()),
                df_jk._DFHF))
        self.assertTrue(
            isinstance(
                addons.convert_to_uhf(scf.RHF(mol).density_fit().newton()),
                df_jk._DFHF))
        self.assertTrue(
            isinstance(
                addons.convert_to_ghf(scf.RHF(mol).density_fit().newton()),
                df_jk._DFHF))
        self.assertTrue(
            isinstance(
                addons.convert_to_rhf(scf.UHF(mol).density_fit().newton()),
                df_jk._DFHF))
        self.assertTrue(
            isinstance(
                addons.convert_to_uhf(scf.UHF(mol).density_fit().newton()),
                df_jk._DFHF))
        self.assertTrue(
            isinstance(
                addons.convert_to_ghf(scf.UHF(mol).density_fit().newton()),
                df_jk._DFHF))
        #self.assertTrue(isinstance(addons.convert_to_rhf(scf.GHF(mol).density_fit().newton()), df_jk._DFHF))
        #self.assertTrue(isinstance(addons.convert_to_uhf(scf.GHF(mol).density_fit().newton()), df_jk._DFHF))
        self.assertTrue(
            isinstance(
                addons.convert_to_ghf(scf.GHF(mol).density_fit().newton()),
                df_jk._DFHF))
Esempio n. 5
0
    def test_convert_to_scf(self):
        from pyscf.x2c import x2c
        from pyscf.df import df_jk
        from pyscf.soscf import newton_ah
        addons.convert_to_rhf(dft.RKS(mol))
        addons.convert_to_uhf(dft.RKS(mol))
        #addons.convert_to_ghf(dft.RKS(mol))
        addons.convert_to_rhf(dft.UKS(mol))
        addons.convert_to_uhf(dft.UKS(mol))
        #addons.convert_to_ghf(dft.UKS(mol))
        #addons.convert_to_rhf(dft.GKS(mol))
        #addons.convert_to_uhf(dft.GKS(mol))
        #addons.convert_to_ghf(dft.GKS(mol))

        self.assertTrue(isinstance(addons.convert_to_rhf(mf), scf.rhf.RHF))
        self.assertTrue(isinstance(addons.convert_to_uhf(mf), scf.uhf.UHF))
        self.assertTrue(isinstance(addons.convert_to_ghf(mf), scf.ghf.GHF))
        self.assertTrue(isinstance(addons.convert_to_rhf(scf.UHF(mol)), scf.rhf.RHF))
        self.assertTrue(isinstance(addons.convert_to_rhf(mf_u), scf.rohf.ROHF))
        self.assertTrue(isinstance(addons.convert_to_uhf(mf_u), scf.uhf.UHF))
        self.assertTrue(isinstance(addons.convert_to_ghf(mf_u), scf.ghf.GHF))
        self.assertTrue(isinstance(addons.convert_to_rhf(sym_mf), scf.hf_symm.RHF))
        self.assertTrue(isinstance(addons.convert_to_uhf(sym_mf), scf.uhf_symm.UHF))
        self.assertTrue(isinstance(addons.convert_to_ghf(sym_mf), scf.ghf_symm.GHF))
        self.assertTrue(isinstance(addons.convert_to_rhf(sym_mf_u), scf.hf_symm.ROHF))
        self.assertTrue(isinstance(addons.convert_to_uhf(sym_mf_u), scf.uhf_symm.UHF))
        self.assertTrue(isinstance(addons.convert_to_ghf(sym_mf_u), scf.ghf_symm.GHF))

        mf1 = copy.copy(mf)
        self.assertTrue(isinstance(mf1.convert_from_(mf), scf.rhf.RHF))
        self.assertTrue(isinstance(mf1.convert_from_(mf_u), scf.rhf.RHF))
        self.assertFalse(isinstance(mf1.convert_from_(mf_u), scf.rohf.ROHF))
        self.assertTrue(isinstance(mf1.convert_from_(sym_mf), scf.rhf.RHF))
        self.assertTrue(isinstance(mf1.convert_from_(sym_mf_u), scf.rhf.RHF))
        self.assertFalse(isinstance(mf1.convert_from_(sym_mf_u), scf.rohf.ROHF))
        self.assertFalse(isinstance(mf1.convert_from_(sym_mf), scf.hf_symm.RHF))
        self.assertFalse(isinstance(mf1.convert_from_(sym_mf_u), scf.hf_symm.RHF))
        mf1 = copy.copy(mf_u)
        self.assertTrue(isinstance(mf1.convert_from_(mf), scf.uhf.UHF))
        self.assertTrue(isinstance(mf1.convert_from_(mf_u), scf.uhf.UHF))
        self.assertTrue(isinstance(mf1.convert_from_(sym_mf), scf.uhf.UHF))
        self.assertTrue(isinstance(mf1.convert_from_(sym_mf_u), scf.uhf.UHF))
        self.assertFalse(isinstance(mf1.convert_from_(sym_mf), scf.uhf_symm.UHF))
        self.assertFalse(isinstance(mf1.convert_from_(sym_mf_u), scf.uhf_symm.UHF))
        mf1 = scf.GHF(mol)
        self.assertTrue(isinstance(mf1.convert_from_(mf), scf.ghf.GHF))
        self.assertTrue(isinstance(mf1.convert_from_(mf_u), scf.ghf.GHF))
        self.assertTrue(isinstance(mf1.convert_from_(sym_mf), scf.ghf.GHF))
        self.assertTrue(isinstance(mf1.convert_from_(sym_mf_u), scf.ghf.GHF))
        self.assertFalse(isinstance(mf1.convert_from_(sym_mf), scf.ghf_symm.GHF))
        self.assertFalse(isinstance(mf1.convert_from_(sym_mf_u), scf.ghf_symm.GHF))

        self.assertTrue(isinstance(addons.convert_to_rhf(scf.RHF(mol).density_fit(), remove_df=False), df_jk._DFHF))
        self.assertTrue(isinstance(addons.convert_to_uhf(scf.RHF(mol).density_fit(), remove_df=False), df_jk._DFHF))
        self.assertTrue(isinstance(addons.convert_to_ghf(scf.RHF(mol).density_fit(), remove_df=False), df_jk._DFHF))
        self.assertTrue(isinstance(addons.convert_to_rhf(scf.UHF(mol).density_fit(), remove_df=False), df_jk._DFHF))
        self.assertTrue(isinstance(addons.convert_to_uhf(scf.UHF(mol).density_fit(), remove_df=False), df_jk._DFHF))
        self.assertTrue(isinstance(addons.convert_to_ghf(scf.UHF(mol).density_fit(), remove_df=False), df_jk._DFHF))
        #self.assertTrue(isinstance(addons.convert_to_rhf(scf.GHF(mol).density_fit(), remove_df=False),df_jk. _DFHF))
        #self.assertTrue(isinstance(addons.convert_to_uhf(scf.GHF(mol).density_fit(), remove_df=False),df_jk. _DFHF))
        self.assertTrue(isinstance(addons.convert_to_ghf(scf.GHF(mol).density_fit(), remove_df=False), df_jk._DFHF))
        self.assertFalse(isinstance(addons.convert_to_rhf(scf.RHF(mol).density_fit(), out=scf.RHF(mol), remove_df=False), df_jk._DFHF))
        self.assertFalse(isinstance(addons.convert_to_uhf(scf.RHF(mol).density_fit(), out=scf.UHF(mol), remove_df=False), df_jk._DFHF))
        self.assertFalse(isinstance(addons.convert_to_ghf(scf.RHF(mol).density_fit(), out=scf.GHF(mol), remove_df=False), df_jk._DFHF))
        self.assertFalse(isinstance(addons.convert_to_rhf(scf.UHF(mol).density_fit(), out=scf.RHF(mol), remove_df=False), df_jk._DFHF))
        self.assertFalse(isinstance(addons.convert_to_uhf(scf.UHF(mol).density_fit(), out=scf.UHF(mol), remove_df=False), df_jk._DFHF))
        self.assertFalse(isinstance(addons.convert_to_ghf(scf.UHF(mol).density_fit(), out=scf.GHF(mol), remove_df=False), df_jk._DFHF))
        #self.assertFalse(isinstance(addons.convert_to_rhf(scf.GHF(mol).density_fit(), out=scf.RHF(mol), remove_df=False),df_jk. _DFHF))
        #self.assertFalse(isinstance(addons.convert_to_uhf(scf.GHF(mol).density_fit(), out=scf.UHF(mol), remove_df=False),df_jk. _DFHF))
        self.assertFalse(isinstance(addons.convert_to_ghf(scf.GHF(mol).density_fit(), out=scf.GHF(mol), remove_df=False), df_jk._DFHF))
        self.assertFalse(isinstance(addons.convert_to_rhf(scf.RHF(mol).density_fit(), out=scf.RHF(mol), remove_df=True), df_jk._DFHF))
        self.assertFalse(isinstance(addons.convert_to_uhf(scf.RHF(mol).density_fit(), out=scf.UHF(mol), remove_df=True), df_jk._DFHF))
        self.assertFalse(isinstance(addons.convert_to_ghf(scf.RHF(mol).density_fit(), out=scf.GHF(mol), remove_df=True), df_jk._DFHF))
        self.assertFalse(isinstance(addons.convert_to_rhf(scf.UHF(mol).density_fit(), out=scf.RHF(mol), remove_df=True), df_jk._DFHF))
        self.assertFalse(isinstance(addons.convert_to_uhf(scf.UHF(mol).density_fit(), out=scf.UHF(mol), remove_df=True), df_jk._DFHF))
        self.assertFalse(isinstance(addons.convert_to_ghf(scf.UHF(mol).density_fit(), out=scf.GHF(mol), remove_df=True), df_jk._DFHF))
        #self.assertFalse(isinstance(addons.convert_to_rhf(scf.GHF(mol).density_fit(), out=scf.RHF(mol), remove_df=True),df_jk. _DFHF))
        #self.assertFalse(isinstance(addons.convert_to_uhf(scf.GHF(mol).density_fit(), out=scf.UHF(mol), remove_df=True),df_jk. _DFHF))
        self.assertFalse(isinstance(addons.convert_to_ghf(scf.GHF(mol).density_fit(), out=scf.GHF(mol), remove_df=True), df_jk._DFHF))

        addons.convert_to_rhf(scf.RHF(mol).x2c().density_fit())
        addons.convert_to_uhf(scf.RHF(mol).x2c().density_fit())
        addons.convert_to_ghf(scf.RHF(mol).x2c().density_fit())
        addons.convert_to_rhf(scf.UHF(mol).x2c().density_fit())
        addons.convert_to_uhf(scf.UHF(mol).x2c().density_fit())
        addons.convert_to_ghf(scf.UHF(mol).x2c().density_fit())
        #addons.convert_to_rhf(scf.GHF(mol).x2c().density_fit())
        #addons.convert_to_uhf(scf.GHF(mol).x2c().density_fit())
        addons.convert_to_ghf(scf.GHF(mol).x2c().density_fit())

        self.assertFalse(isinstance(addons.convert_to_rhf(scf.RHF(mol).x2c().newton().density_fit()), newton_ah._CIAH_SOSCF))
        self.assertFalse(isinstance(addons.convert_to_uhf(scf.RHF(mol).x2c().newton().density_fit()), newton_ah._CIAH_SOSCF))
        self.assertFalse(isinstance(addons.convert_to_ghf(scf.RHF(mol).x2c().newton().density_fit()), newton_ah._CIAH_SOSCF))
        self.assertFalse(isinstance(addons.convert_to_rhf(scf.UHF(mol).x2c().newton().density_fit()), newton_ah._CIAH_SOSCF))
        self.assertFalse(isinstance(addons.convert_to_uhf(scf.UHF(mol).x2c().newton().density_fit()), newton_ah._CIAH_SOSCF))
        self.assertFalse(isinstance(addons.convert_to_ghf(scf.UHF(mol).x2c().newton().density_fit()), newton_ah._CIAH_SOSCF))
        #self.assertFalse(isinstance(addons.convert_to_rhf(scf.GHF(mol).x2c().newton().density_fit()), newton_ah._CIAH_SOSCF))
        #self.assertFalse(isinstance(addons.convert_to_uhf(scf.GHF(mol).x2c().newton().density_fit()), newton_ah._CIAH_SOSCF))
        self.assertFalse(isinstance(addons.convert_to_ghf(scf.GHF(mol).x2c().newton().density_fit()), newton_ah._CIAH_SOSCF))

        self.assertFalse(isinstance(addons.convert_to_rhf(scf.RHF(mol).newton().density_fit()), df_jk._DFHF))
        self.assertFalse(isinstance(addons.convert_to_uhf(scf.RHF(mol).newton().density_fit()), df_jk._DFHF))
        self.assertFalse(isinstance(addons.convert_to_ghf(scf.RHF(mol).newton().density_fit()), df_jk._DFHF))
        self.assertFalse(isinstance(addons.convert_to_rhf(scf.UHF(mol).newton().density_fit()), df_jk._DFHF))
        self.assertFalse(isinstance(addons.convert_to_uhf(scf.UHF(mol).newton().density_fit()), df_jk._DFHF))
        self.assertFalse(isinstance(addons.convert_to_ghf(scf.UHF(mol).newton().density_fit()), df_jk._DFHF))
        #self.assertFalse(isinstance(addons.convert_to_rhf(scf.GHF(mol).newton().density_fit()), df_jk._DFHF))
        #self.assertFalse(isinstance(addons.convert_to_uhf(scf.GHF(mol).newton().density_fit()), df_jk._DFHF))
        self.assertFalse(isinstance(addons.convert_to_ghf(scf.GHF(mol).newton().density_fit()), df_jk._DFHF))

        self.assertTrue(isinstance(addons.convert_to_rhf(scf.RHF(mol).density_fit().newton()), df_jk._DFHF))
        self.assertTrue(isinstance(addons.convert_to_uhf(scf.RHF(mol).density_fit().newton()), df_jk._DFHF))
        self.assertTrue(isinstance(addons.convert_to_ghf(scf.RHF(mol).density_fit().newton()), df_jk._DFHF))
        self.assertTrue(isinstance(addons.convert_to_rhf(scf.UHF(mol).density_fit().newton()), df_jk._DFHF))
        self.assertTrue(isinstance(addons.convert_to_uhf(scf.UHF(mol).density_fit().newton()), df_jk._DFHF))
        self.assertTrue(isinstance(addons.convert_to_ghf(scf.UHF(mol).density_fit().newton()), df_jk._DFHF))
        #self.assertTrue(isinstance(addons.convert_to_rhf(scf.GHF(mol).density_fit().newton()), df_jk._DFHF))
        #self.assertTrue(isinstance(addons.convert_to_uhf(scf.GHF(mol).density_fit().newton()), df_jk._DFHF))
        self.assertTrue(isinstance(addons.convert_to_ghf(scf.GHF(mol).density_fit().newton()), df_jk._DFHF))
Esempio n. 6
0
File: hf.py Progetto: berquist/pyscf
 def convert_from_(self, mf):
     '''Convert given mean-field object to RHF/ROHF'''
     from pyscf.scf import addons
     addons.convert_to_rhf(mf, self)
     return self
Esempio n. 7
0
File: hf.py Progetto: pulkin/pyscf
 def convert_from_(self, mf):
     '''Convert given mean-field object to RHF/ROHF'''
     from pyscf.scf import addons
     addons.convert_to_rhf(mf, self)
     return self