예제 #1
0
    def test_scf_grad(self):
        mf = ddcosmo.ddcosmo_for_scf(scf.RHF(mol0)).run()
        # solvent only
        de_cosmo = ddcosmo_grad.kernel(mf.with_solvent, mf.make_rdm1())
        self.assertAlmostEqual(lib.fp(de_cosmo), 0.000770107393352652, 6)
        # solvent + solute
        de = mf.nuc_grad_method().kernel()
        self.assertAlmostEqual(lib.fp(de), -0.1920179073822721, 6)

        dm1 = mf.make_rdm1()

        mf1 = ddcosmo.ddcosmo_for_scf(scf.RHF(mol1)).run()
        e1 = mf1.e_tot
        e1_cosmo = mf1.with_solvent.energy(dm1)

        mf2 = ddcosmo.ddcosmo_for_scf(scf.RHF(mol2)).run()
        e2 = mf2.e_tot
        e2_cosmo = mf2.with_solvent.energy(dm1)
        self.assertAlmostEqual(abs((e2 - e1) / dx - de[0, 2]).max(), 0, 7)
        self.assertAlmostEqual(
            abs((e2_cosmo - e1_cosmo) / dx - de_cosmo[0, 2]).max(), 0, 7)

        sc = mf.nuc_grad_method().as_scanner()
        e, g = sc('H 0 1 0; H 0 1 1.2; H 1. 0 0; H .5 .5 0')
        self.assertAlmostEqual(e, -0.8317337703056022, 8)
        self.assertAlmostEqual(lib.fp(g), 0.06804297145388238, 6)

        mol3 = gto.M(atom='H 0 1 0; H 0 1 1.2; H 1. 0 0; H .5 .5 0', unit='B')
        mf = ddcosmo.ddcosmo_for_scf(scf.RHF(mol3)).run()
        de = mf.nuc_grad_method().kernel()
        self.assertAlmostEqual(lib.fp(de), 0.06804297145388238, 6)
예제 #2
0
    def test_ddcosmo_scf(self):
        mol = gto.M(atom=''' H 0 0 0 ''',
                    charge=1,
                    basis='sto3g',
                    verbose=7,
                    output='/dev/null')
        pcm = ddcosmo.DDCOSMO(mol)
        pcm.lmax = 10
        pcm.lebedev_order = 29
        mf = ddcosmo.ddcosmo_for_scf(scf.RHF(mol), pcm)
        mf.init_guess = '1e'
        mf.run()
        self.assertAlmostEqual(mf.e_tot, -0.1645636146393864, 9)

        mol = gto.M(atom='''
               6        0.000000    0.000000   -0.542500
               8        0.000000    0.000000    0.677500
               1        0.000000    0.935307   -1.082500
               1        0.000000   -0.935307   -1.082500
                    ''',
                    basis='sto3g',
                    verbose=7,
                    output='/dev/null')
        pcm = ddcosmo.DDCOSMO(mol)
        pcm.lmax = 6
        pcm.lebedev_order = 17
        mf = ddcosmo.ddcosmo_for_scf(scf.RHF(mol), pcm).run()
        self.assertAlmostEqual(mf.e_tot, -112.35450855007909, 9)
예제 #3
0
    def test_scf_grad(self):
        mf = ddcosmo.ddcosmo_for_scf(scf.RHF(mol0)).run()
        de_cosmo = ddcosmo_grad.kernel(mf._solvent, mf.make_rdm1())
        de = mf.nuc_grad_method().kernel()
        dm1 = mf.make_rdm1()

        mf = ddcosmo.ddcosmo_for_scf(scf.RHF(mol1)).run()
        e1 = mf.e_tot
        e1_cosmo = mf._solvent.energy(dm1)

        mf = ddcosmo.ddcosmo_for_scf(scf.RHF(mol2)).run()
        e2 = mf.e_tot
        e2_cosmo = mf._solvent.energy(dm1)
        self.assertAlmostEqual(abs((e2-e1)/dx - de[0,2]).max(), 0, 7)
        self.assertAlmostEqual(abs((e2_cosmo-e1_cosmo)/dx - de_cosmo[0,2]).max(), 0, 7)
예제 #4
0
    def test_scf_grad(self):
        mf = ddcosmo.ddcosmo_for_scf(scf.RHF(mol0)).run()
        de_cosmo = ddcosmo_grad.kernel(mf.with_solvent, mf.make_rdm1())
        de = mf.nuc_grad_method().kernel()
        dm1 = mf.make_rdm1()

        mf = ddcosmo.ddcosmo_for_scf(scf.RHF(mol1)).run()
        e1 = mf.e_tot
        e1_cosmo = mf.with_solvent.energy(dm1)

        mf = ddcosmo.ddcosmo_for_scf(scf.RHF(mol2)).run()
        e2 = mf.e_tot
        e2_cosmo = mf.with_solvent.energy(dm1)
        self.assertAlmostEqual(abs((e2-e1)/dx - de[0,2]).max(), 0, 7)
        self.assertAlmostEqual(abs((e2_cosmo-e1_cosmo)/dx - de_cosmo[0,2]).max(), 0, 7)
예제 #5
0
def ddCOSMO(method_or_mol, solvent_obj=None, dm=None):
    '''Initialize ddCOSMO model.

    Examples:

    >>> mf = ddCOSMO(scf.RHF(mol))
    >>> mf.kernel()
    >>> sol = ddCOSMO(mol)
    >>> mc = ddCOSMO(CASCI(mf, 6, 6), sol)
    >>> mc.kernel()
    '''
    from pyscf import gto
    from pyscf import scf, mcscf
    from pyscf import tdscf

    if isinstance(method_or_mol, gto.mole.Mole):
        return ddcosmo.DDCOSMO(method_or_mol)

    elif isinstance(method_or_mol, scf.hf.SCF):
        return ddcosmo.ddcosmo_for_scf(method_or_mol, solvent_obj, dm)
    elif isinstance(method_or_mol, mcscf.mc1step.CASSCF):
        return ddcosmo.ddcosmo_for_casscf(method_or_mol, solvent_obj, dm)
    elif isinstance(method_or_mol, mcscf.casci.CASCI):
        return ddcosmo.ddcosmo_for_casci(method_or_mol, solvent_obj, dm)
    elif isinstance(method_or_mol, (tdscf.rhf.TDA, tdscf.rhf.TDHF)):
        return ddcosmo.ddcosmo_for_tdscf(method_or_mol, solvent_obj, dm)
    else:
        return ddcosmo.ddcosmo_for_post_scf(method_or_mol, solvent_obj, dm)
예제 #6
0
파일: __init__.py 프로젝트: chrinide/pyscf
def ddCOSMO(method_or_mol, solvent_obj=None, dm=None):
    '''Initialize ddCOSMO model.

    Examples::

    >>> mf = ddCOSMO(scf.RHF(mol))
    >>> mf.kernel()
    >>> sol = ddCOSMO(mol)
    >>> mc = ddCOSMO(CASCI(mf, 6, 6), sol)
    >>> mc.kernel()
    '''
    from pyscf import gto
    from pyscf import scf, mcscf
    from pyscf import tdscf

    if isinstance(method_or_mol, gto.mole.Mole):
        return DDCOSMO(mol)

    elif isinstance(method_or_mol, scf.hf.SCF):
        return ddcosmo.ddcosmo_for_scf(method_or_mol, solvent_obj, dm)
    elif isinstance(method_or_mol, mcscf.mc1step.CASSCF):
        return ddcosmo.ddcosmo_for_casscf(method_or_mol, solvent_obj, dm)
    elif isinstance(method_or_mol, mcscf.casci.CASCI):
        return ddcosmo.ddcosmo_for_casci(method_or_mol, solvent_obj, dm)
    elif isinstance(method_or_mol, (tdscf.rhf.TDA, tdscf.rhf.TDHF)):
        raise NotImplementedError('Solvent model for %s' % method_or_mol)
    else:
        return ddcosmo.ddcosmo_for_post_scf(method_or_mol, solvent_obj, dm)
예제 #7
0
    def test_as_scanner(self):
        mol = gto.M(atom='''
               6        0.000000    0.000000   -0.542500
               8        0.000000    0.000000    0.677500
               1        0.000000    0.935307   -1.082500
               1        0.000000   -0.935307   -1.082500
                    ''', basis='sto3g', verbose=7,
                    output='/dev/null')
        mf_scanner = ddcosmo.ddcosmo_for_scf(scf.RHF(mol)).as_scanner()
        mf_scanner(mol)
        self.assertEqual(mf_scanner.with_solvent.grids.coords.shape, (48212, 3))
        mf_scanner('H  0. 0. 0.; H  0. 0. .9')
        self.assertEqual(mf_scanner.with_solvent.grids.coords.shape, (20048, 3))

        h2 = gto.M(atom='H  0. 0. 0.; H  0. 0. .9', basis='sto3g', verbose=7,
                   output='/dev/null')
        mf_h2 = ddcosmo.ddcosmo_for_scf(scf.RHF(h2)).run()
        self.assertAlmostEqual(mf_h2.e_tot, mf_scanner.e_tot, 9)
예제 #8
0
    def test_ddcosmo_scf(self):
        mol = gto.M(atom=''' H 0 0 0 ''', charge=1, basis='sto3g', verbose=7,
                    output='/dev/null')
        pcm = ddcosmo.DDCOSMO(mol)
        pcm.lmax = 10
        pcm.lebedev_order = 29
        mf = ddcosmo.ddcosmo_for_scf(scf.RHF(mol), pcm)
        mf.init_guess = '1e'
        mf.run()
        self.assertAlmostEqual(mf.e_tot, -0.1645636146393864, 9)

        mol = gto.M(atom='''
               6        0.000000    0.000000   -0.542500
               8        0.000000    0.000000    0.677500
               1        0.000000    0.935307   -1.082500
               1        0.000000   -0.935307   -1.082500
                    ''', basis='sto3g', verbose=7,
                    output='/dev/null')
        pcm = ddcosmo.DDCOSMO(mol)
        pcm.lmax = 6
        pcm.lebedev_order = 17
        mf = ddcosmo.ddcosmo_for_scf(scf.RHF(mol), pcm).run()
        self.assertAlmostEqual(mf.e_tot, -112.35450855007909, 9)
예제 #9
0
    def test_as_scanner(self):
        mol = gto.M(atom='''
               6        0.000000    0.000000   -0.542500
               8        0.000000    0.000000    0.677500
               1        0.000000    0.935307   -1.082500
               1        0.000000   -0.935307   -1.082500
                    ''',
                    basis='sto3g',
                    verbose=7,
                    output='/dev/null')
        mf_scanner = ddcosmo.ddcosmo_for_scf(scf.RHF(mol)).as_scanner()
        mf_scanner(mol)
        self.assertEqual(mf_scanner.with_solvent.grids.coords.shape,
                         (48212, 3))
        mf_scanner('H  0. 0. 0.; H  0. 0. .9')
        self.assertEqual(mf_scanner.with_solvent.grids.coords.shape,
                         (20048, 3))

        h2 = gto.M(atom='H  0. 0. 0.; H  0. 0. .9',
                   basis='sto3g',
                   verbose=7,
                   output='/dev/null')
        mf_h2 = ddcosmo.ddcosmo_for_scf(scf.RHF(h2)).run()
        self.assertAlmostEqual(mf_h2.e_tot, mf_scanner.e_tot, 9)
예제 #10
0
    def test_ddcosmo_scf_with_overwritten_attributes(self):
        mf = ddcosmo.ddcosmo_for_scf(scf.RHF(mol))
        mf.kernel()
        self.assertAlmostEqual(mf.e_tot, -75.57036436805902, 9)

        mf.with_solvent.lebedev_order = 15
        mf.with_solvent.lmax = 5
        mf.with_solvent.eps = .5
        mf.with_solvent.conv_tol = 1e-8
        mf.kernel()
        self.assertAlmostEqual(mf.e_tot, -75.55326109712902, 9)

        mf.with_solvent.grids.radi_method = dft.mura_knowles
        mf.with_solvent.grids.atom_grid = {"H": (8, 50), "O": (8, 50),}
        mf.kernel()
        self.assertAlmostEqual(mf.e_tot, -75.55216799624262, 9)
예제 #11
0
    def test_ddcosmo_scf_with_overwritten_attributes(self):
        mf = ddcosmo.ddcosmo_for_scf(scf.RHF(mol))
        mf.kernel()
        self.assertAlmostEqual(mf.e_tot, -75.57036436805902, 9)

        mf.with_solvent.lebedev_order = 15
        mf.with_solvent.lmax = 5
        mf.with_solvent.eps = .5
        mf.with_solvent.conv_tol = 1e-8
        mf.kernel()
        self.assertAlmostEqual(mf.e_tot, -75.55326109712902, 9)

        mf.with_solvent.grids.radi_method = dft.mura_knowles
        mf.with_solvent.grids.atom_grid = {
            "H": (8, 50),
            "O": (8, 50),
        }
        mf.kernel()
        self.assertAlmostEqual(mf.e_tot, -75.55216799624262, 9)
예제 #12
0
파일: __init__.py 프로젝트: zwang123/pyscf
def ddCOSMO(method):
    return ddcosmo.ddcosmo_for_scf(method)
예제 #13
0
        vtmp = numpy.zeros((3,nao,nao))
        aow = numpy.einsum('pi,p->pi', ao[0], weight*eta_nj)
        rks_grad._d1_dot_(vtmp, mol, ao[1:4], aow, mask, ao_loc, True)
        vmat += vtmp

    aoslices = mol.aoslice_by_atom()
    for ia in range(natm):
        shl0, shl1, p0, p1 = aoslices[ia]
        psi1[ia] += numpy.einsum('xij,ij->x', vmat[:,p0:p1], dm[p0:p1]) * 2
    return psi1


if __name__ == '__main__':
    from pyscf import scf
    mol = gto.M(atom='H 0 0 0; H 0 1 1.2; H 1. .1 0; H .5 .5 1', unit='B')
    mf = ddcosmo.ddcosmo_for_scf(scf.RHF(mol))
    mf.kernel()
    de = mf.nuc_grad_method().kernel()
    de_cosmo = kernel(mf.with_solvent, mf.make_rdm1())
    dm1 = mf.make_rdm1()

    mol = gto.M(atom='H 0 0 -0.001; H 0 1 1.2; H 1. .1 0; H .5 .5 1', unit='B')
    mf = ddcosmo.ddcosmo_for_scf(scf.RHF(mol))
    e1 = mf.kernel()
    e1_cosmo = mf.with_solvent.energy(dm1)

    mol = gto.M(atom='H 0 0 0.001; H 0 1 1.2; H 1. .1 0; H .5 .5 1', unit='B')
    mf = ddcosmo.ddcosmo_for_scf(scf.RHF(mol))
    e2 = mf.kernel()
    e2_cosmo = mf.with_solvent.energy(dm1)
    print(abs((e2-e1)/0.002 - de[0,2]).max())
예제 #14
0
#!/usr/bin/env python
#
# Author: Qiming Sun <*****@*****.**>
#
'''
A simple example of using solvent model in the mean-field calculations.
'''

from pyscf import gto, scf
from pyscf.solvent import ddcosmo, ddpcm

mol = gto.M(atom='''
C        0.000000    0.000000             -0.542500
O        0.000000    0.000000              0.677500
H        0.000000    0.9353074360871938   -1.082500
H        0.000000   -0.9353074360871938   -1.082500
            ''', )
mf = scf.RHF(mol)

ddcosmo.ddcosmo_for_scf(mf).run()
ddpcm.ddpcm_for_scf(mf).run()
예제 #15
0
def ddpcm_for_scf(mf, pcmobj=None):
    if pcmobj is None:
        pcmobj = DDPCM(mf.mol)
    return ddcosmo.ddcosmo_for_scf(mf, pcmobj)
예제 #16
0
파일: ddpcm.py 프로젝트: zwgsyntax/pyscf
def ddpcm_for_scf(mf, solvent_obj=None, dm=None):
    if solvent_obj is None:
        solvent_obj = DDPCM(mf.mol)
    return ddcosmo.ddcosmo_for_scf(mf, solvent_obj, dm)
예제 #17
0
파일: ddcosmo_grad.py 프로젝트: tmash/pyscf
        vtmp = numpy.zeros((3,nao,nao))
        aow = numpy.einsum('pi,p->pi', ao[0], weight*eta_nj)
        rks_grad._d1_dot_(vtmp, mol, ao[1:4], aow, mask, ao_loc, True)
        vmat += vtmp

    aoslices = mol.aoslice_by_atom()
    for ia in range(natm):
        shl0, shl1, p0, p1 = aoslices[ia]
        psi1[ia] += numpy.einsum('xij,ij->x', vmat[:,p0:p1], dm[p0:p1]) * 2
    return psi1


if __name__ == '__main__':
    from pyscf import scf
    mol = gto.M(atom='H 0 0 0; H 0 1 1.2; H 1. .1 0; H .5 .5 1', unit='B')
    mf = ddcosmo.ddcosmo_for_scf(scf.RHF(mol))
    mf.kernel()
    de = mf.nuc_grad_method().kernel()
    de_cosmo = kernel(mf.with_solvent, mf.make_rdm1())
    dm1 = mf.make_rdm1()

    mol = gto.M(atom='H 0 0 -0.001; H 0 1 1.2; H 1. .1 0; H .5 .5 1', unit='B')
    mf = ddcosmo.ddcosmo_for_scf(scf.RHF(mol))
    e1 = mf.kernel()
    e1_cosmo = mf.with_solvent.energy(dm1)

    mol = gto.M(atom='H 0 0 0.001; H 0 1 1.2; H 1. .1 0; H .5 .5 1', unit='B')
    mf = ddcosmo.ddcosmo_for_scf(scf.RHF(mol))
    e2 = mf.kernel()
    e2_cosmo = mf.with_solvent.energy(dm1)
    print(abs((e2-e1)/0.002 - de[0,2]).max())
예제 #18
0
파일: ddpcm.py 프로젝트: chrinide/pyscf
def ddpcm_for_scf(mf, solvent_obj=None, dm=None):
    if solvent_obj is None:
        solvent_obj = DDPCM(mf.mol)
    return ddcosmo.ddcosmo_for_scf(mf, solvent_obj, dm)