Esempio n. 1
0
    Sigma[:, n2c:,
          n2c:] = .25 / c**2 * mol.intor('int1e_spsigmasp_spinor', comp=3)
    effspin = numpy.einsum('xij,ji->x', Sigma, dm0) * .5
    log.debug('Eff-spin %s', effspin.real)
    g = (g / effspin).real

    facppt = 1e3
    gshift = (g - nist.G_ELECTRON) * facppt
    log.note('G shift (ppt) %s', gshift)
    return g


class GTensor(dhf_nmr.NMR):
    kernel = kernel


if __name__ == '__main__':
    from pyscf import gto
    from pyscf import scf
    mol = gto.M(
        atom=[
            ['Ne', (0., 0., 0.)],
            #['He', (.4,.7,0.)],
        ],
        basis='ccpvdz',
        spin=2,
        charge=2)
    mf = scf.DHF(mol).run()
    print(GTensor(mf).kernel((0, 0, 0)))
    print(GTensor(mf).kernel(mb='RMB'))
Esempio n. 2
0
['C',(0.6649585374, -0.3739765481, 0.0000000000)],
['H',(0.7125760695, -1.0301702097, 0.8769078936)],
['H',(0.7125760695, -1.0301702097, -0.8769078936)],
['C',(-0.6649585374, 0.3739765481, 0.0000000000)],
['H',(-0.7125760695, 1.0301702097, -0.8769078936)],
['H',(-0.7125760695, 1.0301702097, 0.8769078936)],
['C',(-1.8773135249, -0.5535425093, 0.0000000000)],
['H',(-1.8289548319, -1.2081298850 ,0.8760991121)],
['H',(-1.8289548319, -1.2081298850, -0.8760991121)],
['C',(-3.1987314968, 0.2104570612, 0.0000000000)],
['H',(-3.2763256850, 0.8506634635, -0.8816038652)],
['H',(-4.0552248738, -0.4654264605, 0.0000000000)],
['H',(-3.2763256850, 0.8506634635, 0.8816038652)]]
basis ='cc-pv5z'

mol = gto.M(atom=atoms,basis='cc-pv5z')
m   = scf.RHF(mol)
m.kernel()
mm  = cc.CCSD(m)# uncomment this line and comment the line below to switch to CC
#mm = mp.MP2(m)
mm.kernel()

del mol,m,mm

bs     = '5z'
basis  = {'C': 'cc-pv'+bs, 'H': 'cc-pv'+bs}
shells = {'C': ['sto-6g','cc-pv'+bs], 'H': ['sto-6g','cc-pv'+bs]}
charge = 0
spin   = 0

fragments = [[0,1,2,3],[4,5,6],[7,8,9],[10,11,12],[13,14,15],[16,17,18,19]]
Esempio n. 3
0
                dm2[i, j, j, i] -= 2

    # dm2 was computed as dm2[p,q,r,s] = < p^\dagger r^\dagger s q > in the
    # above. Transposing it so that it be contracted with ERIs (in Chemist's
    # notation):
    #   E = einsum('pqrs,pqrs', eri, rdm2)
    return dm2.transpose(1, 0, 3, 2)


if __name__ == '__main__':
    from pyscf import gto
    from pyscf import scf
    from pyscf.cc import ccsd
    from pyscf import ao2mo

    mol = gto.M()
    mf = scf.RHF(mol)
    mcc = ccsd.CCSD(mf)

    numpy.random.seed(2)
    nocc = 5
    nmo = 12
    nvir = nmo - nocc
    eri0 = numpy.random.random((nmo, nmo, nmo, nmo))
    eri0 = ao2mo.restore(1, ao2mo.restore(8, eri0, nmo), nmo)
    fock0 = numpy.random.random((nmo, nmo))
    fock0 = fock0 + fock0.T + numpy.diag(range(nmo)) * 2
    t1 = numpy.random.random((nocc, nvir))
    t2 = numpy.random.random((nocc, nocc, nvir, nvir))
    t2 = t2 + t2.transpose(1, 0, 3, 2)
    l1 = numpy.random.random((nocc, nvir))
Esempio n. 4
0
#!/usr/bin/env python
#
# Author: Qiming Sun <*****@*****.**>
#
'''
A simple example to run CCSD calculation.
'''

from pyscf import gto, scf, cc

mol = gto.M(atom='H 0 0 0; F 0 0 1.1', basis='ccpvdz')

mf = scf.RHF(mol).run()

mycc = cc.CCSD(mf).run()
print('CCSD correlation energy', mycc.e_corr)
Esempio n. 5
0
#!/usr/bin/env python
'''
User defined XC functional

See also
* The parser parse_xc function implemented in pyscf.dft.libxc
* Example 24-define_xc_functional.py to input a functional which is not
  provided in Libxc or XcFun library.
'''

from pyscf import gto
from pyscf import dft

mol = gto.M(atom='''
    O  0.   0.       0.
    H  0.   -0.757   0.587
    H  0.   0.757    0.587 ''',
            basis='ccpvdz')

#
# DFT can parse the custom XC functional, following the rules:
# * The given functional description must be a one-line string.
# * The functional description is case-insensitive.
# * The functional description string has two parts, separated by ",".  The
#   first part describes the exchange functional, the second is the correlation
#   functional.
#   - If "," was not presented in string, the entire string is treated as a
#     compound XC functional (including both X and C functionals, such as b3lyp).
#   - To input only X functional (without C functional), leave the second part
#     blank. E.g. description='slater,' for pure LDA functional.
#   - To neglect the X functional (only input C functional), leave the first
Esempio n. 6
0
#!/usr/bin/env python3
## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
import adcc

from pyscf import gto, scf

# Run SCF in pyscf
mol = gto.M(atom='O 0 0 0;'
            'H 0 0 1.795239827225189;'
            'H 1.693194615993441 0 -0.599043184453037',
            basis='sto-3g',
            spin=2,
            unit="Bohr")
scfres = scf.UHF(mol)
scfres.conv_tol = 1e-8
scfres.conv_tol_grad = 1e-8
scfres.max_cycle = 100
scfres.verbose = 4
scfres.kernel()

# Explicitly initialise ADC virtual memory pool to (256 MiB)
# (if this call is missing than only RAM is used. This allows
#  to dump data to disk as well such that maximally up to the
#  specified amount of data (in bytes) will reside in RAM)
adcc.memory_pool.initialise(max_memory=256 * 1024 * 1024)

# Run an adc2 calculation:
singlets = adcc.adc2(scfres, n_states=5)
# triplets = adcc.adc2(singlets.matrix, n_triplets=3)

print(singlets.describe())
Esempio n. 7
0
  atom2bas_s = np.array([len(_bas)]*(natoms+1), dtype=np.int32)
  for ib,[at,l,ngto,nctr,a,b,c,d] in enumerate(_bas): atom2bas_s[at] = min(atom2bas_s[at],ib)
  return atom2bas_s


if __name__ == '__main__':
  """
    Compute only bilocal part of the four-orbitals, two-center Coulomb integrals
  """
  from pyscf import gto
  from pyscf.nao.m_system_vars import system_vars_c
  from pyscf.nao.m_conv_yzx2xyz import conv_yzx2xyz_c

  tol = 1e-5
  
  mol = gto.M(atom='O 0 0 0; H 0 -0.1 1; H 0 0.1 -1', basis='ccpvdz')
  sv = system_vars_c(gto=mol)
  na = sv.natm
  for ia1,n1 in zip(range(na), sv.atom2s[1:]-sv.atom2s[0:na]):
    for ia2,n2 in zip(range(ia1+1,sv.natm+1), sv.atom2s[ia1+2:]-sv.atom2s[ia1+1:na]):
      mol2 = gto.Mole_pure(atom=[mol._atom[ia1], mol._atom[ia2]], basis=mol.basis).build()
      bs = get_atom2bas_s(mol2._bas)
      ss = (bs[0],bs[1], bs[1],bs[2], bs[0],bs[1], bs[1],bs[2])
      eri = mol2.intor('cint2e_sph', shls_slice=ss).reshape([n1,n2,n1,n2])

      eri = conv_yzx2xyz_c(mol2).conv_yzx2xyz_4d(eri, 'pyscf2nao', ss).reshape([n1*n2,n1*n2])
      ee,xx = np.linalg.eigh(eri)

      nlinindep = list(ee>tol).count(True)
      print(' ia1, ia2, n1, n2: ', ia1, ia2, n1, n2, eri.shape, n1*n2, nlinindep, n1*n2/nlinindep)
Esempio n. 8
0
'''
Pass initial guess to SCF calculation.

SCF kernel function takes one argument dm (density matrix) as the initial
guess.  If not given, SCF constructs an atomic density superposition for the
initial guess.
'''

import tempfile
from pyscf import gto
from pyscf import scf


mol0 = gto.M(
    atom = '''
        C     0.   0.   0.625
        C     0.   0.  -0.625 ''',
    basis = 'cc-pVDZ',
)

mf = scf.RHF(mol0).run()

#
# Save the density matrix as the initial guess for the next calculation
#
dm_init_guess = mf.make_rdm1()


mol = gto.M(
    atom = '''
        C     0.   0.   0.7
        C     0.   0.  -0.7 ''',
Esempio n. 9
0
# Author: Qiming Sun <*****@*****.**>
#
'''
Writing FCIDUMP file for given integrals or SCF orbitals
'''

from functools import reduce
import numpy
from pyscf import gto, scf, ao2mo
from pyscf import tools
from pyscf import symm

mol = gto.M(
    atom=[['H', 0, 0, i] for i in range(6)],
    basis='6-31g',
    verbose=0,
    symmetry=1,
    symmetry_subgroup='D2h',
)
myhf = scf.RHF(mol)
myhf.kernel()

#
# Example 1: Convert an SCF object to FCIDUMP
#
tools.fcidump.from_scf(myhf, 'fcidump.example1')

#
# Example 2: Given a set of orbitals to transform integrals then dump the
# integrals to FCIDUMP
#
Esempio n. 10
0
    grad_elec = grad_elec


Grad = Gradients

from pyscf.cc import uccsd
uccsd.UCCSD.Gradients = lib.class_as_method(Gradients)

if __name__ == '__main__':
    from pyscf import gto
    from pyscf import scf
    from pyscf.cc import uccsd

    mol = gto.M(
        atom=[["O", (0., 0., 0.)], [1, (0., -0.757, 0.587)],
              [1, (0., 0.757, 0.587)]],
        basis='631g',
        spin=2,
    )
    mf = scf.UHF(mol).run()
    mycc = uccsd.UCCSD(mf).run()
    g1 = mycc.Gradients().kernel()
    # O    -0.0000000000    -0.0000000000     0.1474630318
    # H     0.0000000000     0.1118073694    -0.0737315159
    # H     0.0000000000    -0.1118073694    -0.0737315159
    print(lib.finger(g1) - -0.22892718069135981)

    myccs = mycc.as_scanner()
    mol.atom[0] = ["O", (0., 0., 0.001)]
    mol.build(0, 0)
    e1 = myccs(mol)
    mol.atom[0] = ["O", (0., 0., -0.001)]
# Author: Qiming Sun <*****@*****.**>
#
'''
The force from QM region acting on the background MM particles.
'''

from functools import reduce
import numpy
from pyscf import gto, scf, mp, qmmm

mol = gto.M(atom='''
C       1.1879  -0.3829 0.0000
C       0.0000  0.5526  0.0000
O       -1.1867 -0.2472 0.0000
H       -1.9237 0.3850  0.0000
H       2.0985  0.2306  0.0000
H       1.1184  -1.0093 0.8869
H       1.1184  -1.0093 -0.8869
H       -0.0227 1.1812  0.8852
H       -0.0227 1.1812  -0.8852
            ''',
            basis='3-21g')

numpy.random.seed(1)
coords = numpy.random.random((5, 3)) * 10
charges = (numpy.arange(5) + 1.) * -.1


def force(dm):
    # The interaction between QM atoms and MM particles
    # \sum_K d/dR (1/|r_K-R|) = \sum_K (r_K-R)/|r_K-R|^3
    qm_coords = mol.atom_coords()
Esempio n. 12
0
import numpy as np
from pyscf import gto, scf
from kspies import zmp, util
import matplotlib.pyplot as plt

#Target density from HF
mol = gto.M(atom='Ne', basis='aug-cc-pVTZ')
mf = scf.RHF(mol).run()
dm_tar = mf.make_rdm1()

#Define plotting domain
coords = []
for x in np.linspace(0, 3, 1001):
    coords.append((x, 0., 0.))
coords = np.array(coords)

plt.figure(figsize=(3, 4))

#ZMP calculations
mz = zmp.RZMP(mol, dm_tar)
mz.guide = 'faxc'
for l in [16, 128, 1024]:
    mz.level_shift = 0.1 * l
    mz.zscf(l)
    dmxc = l * mz.dm - (l + 1. / mol.nelectron) * dm_tar
    vxc = util.eval_vh(mol, coords, dmxc)
    plt.plot(coords[:, 0], vxc, label=r'$\lambda$=' + str(l))

plt.xlabel("x")
plt.ylabel("vx(r)")
plt.xlim(0, 3)
Esempio n. 13
0
#!/usr/bin/env python
'''
Mulliken population analysis with IAO orbitals
'''
import numpy
from functools import reduce
from pyscf import gto, scf, lo
from functools import reduce

x = .63
mol = gto.M(atom=[['C', (0, 0, 0)], ['H', (x, x, x)], ['H', (-x, -x, x)],
                  ['H', (-x, x, -x)], ['H', (x, -x, -x)]],
            basis='ccpvtz')
mf = scf.RHF(mol).run()

mo_occ = mf.mo_coeff[:, mf.mo_occ > 0]
a = lo.iao.iao(mol, mo_occ)

# Orthogonalize IAO
a = lo.vec_lowdin(a, mf.get_ovlp())

# transform mo_occ to IAO representation. Note the AO dimension is reduced
mo_occ = reduce(numpy.dot, (a.T, mf.get_ovlp(), mo_occ))

dm = numpy.dot(mo_occ, mo_occ.T) * 2
# IAO should span the occupied space
assert (abs(dm.trace() - mol.nelectron) < 1e-13)

pmol = mol.copy()
pmol.build(False, False, basis='minao')
mf.mulliken_pop(pmol, dm, s=numpy.eye(pmol.nao_nr()))
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import print_function, division
import unittest, numpy as np
from pyscf import gto, scf
from pyscf.nao import system_vars_c
from pyscf.nao.hf import RHF

mol = gto.M( verbose = 1,
    atom = '''
        H     0    0        0
        H     0    0.757    0.587''', basis = 'cc-pvdz',)

class KnowValues(unittest.TestCase):
    
  def test_scf_gto_vs_nao(self):
    """ Test computation of overlaps between NAOs against overlaps computed between GTOs"""
    gto_hf = scf.RHF(mol)
    gto_hf.kernel()
    
    sv = system_vars_c().init_pyscf_gto(mol, verbose=0)
    nao_hf = RHF(sv)
    nao_hf.dump_chkfile=False
    nao_hf.kernel()
    self.assertAlmostEqual(gto_hf.e_tot, nao_hf.e_tot, 4)
    for e1,e2 in zip(nao_hf.mo_energy,gto_hf.mo_energy): self.assertAlmostEqual(e1, e2, 3)
Esempio n. 15
0
import copy
import unittest
import numpy
from pyscf import lib
from pyscf import gto
from pyscf import scf
from pyscf import dft
from pyscf import fci
from pyscf import mcscf

b = 1.4
mol = gto.M(
verbose = 7,
output = '/dev/null',
atom = [
    ["O" , (0. , 0.     , 0.)],
    [1   , (0. , -0.757 , 0.587)],
    [1   , (0. , 0.757  , 0.587)] ],
basis = '631g',
spin = 2,
)
m = scf.UHF(mol)
m.conv_tol = 1e-10
m.scf()

def tearDownModule():
    global mol, m
    mol.stdout.close()
    del mol, m


class KnownValues(unittest.TestCase):
Esempio n. 16
0
from pyscf import gto
import time
from qsome import interaction_mediator, cluster_subsystem, cluster_supersystem

from copy import deepcopy as copy

#All mol objects which will be used for testing.

sn2_mol1 = gto.M()
sn2_mol1.atom = '''
Cl         3.51109       -0.30375        0.00020
C          1.97915        0.64190        0.00018
H          2.00892        1.27702       -0.88401
H          2.00850        1.27637        0.88486
'''

sn2_mol2 = gto.M()
sn2_mol2.atom = '''
C          0.77452       -0.25849       -0.00044
H          0.80952       -0.91242       -0.87692
H          0.80921       -0.91317        0.87550
C         -0.51363        0.54349       -0.00030
H         -0.53565        1.20393        0.87514
H         -0.53562        1.20434       -0.87545
C         -1.75043       -0.33137       -0.00050
H         -1.72894       -0.99275       -0.87536
H         -1.72864       -0.99348        0.87379
C         -3.04233        0.46077        0.00008
H         -3.05786        1.12092        0.87408
H         -3.05853        1.12117       -0.87372
C         -4.26820       -0.42758        0.00047
Esempio n. 17
0
    doovv[OA[:, None, None, None], OA[:, None, None], VA[:, None], VA] = d2[3]
    dovvo[OA[:, None, None, None], VA[:, None, None], VA[:, None], OA] = d2[4]
    dovvv[OA[:, None, None, None], VA[:, None, None], VA[:, None], VA] = d2[6]
    dooov[OA[:, None, None, None], OA[:, None, None], OA[:, None], VA] = d2[7]
    dvvov = dovvv.transpose(2, 3, 0, 1)
    return dovov, dvvvv, doooo, doovv, dovvo, dvvov, dovvv, dooov


if __name__ == '__main__':
    from pyscf import gto
    from pyscf import scf
    from pyscf.cc import ccsd
    from pyscf import grad

    mol = gto.M(verbose=0,
                atom=[["O", (0., 0., 0.)], [1, (0., -0.757, 0.587)],
                      [1, (0., 0.757, 0.587)]],
                basis='631g')
    mf = scf.RHF(mol).run()
    mycc = ccsd.CCSD(mf)
    ecc, t1, t2 = mycc.kernel()
    l1, l2 = mycc.solve_lambda()
    g1 = kernel(mycc, t1, t2, l1, l2)
    ghf = grad.RHF(mf).grad()
    print('gcc')
    print(ghf + g1)
    print(lib.finger(g1) - -0.042511000925747583)
    #[[ 0   0                1.00950969e-02]
    # [ 0   2.28063353e-02  -5.04754844e-03]
    # [ 0  -2.28063353e-02  -5.04754844e-03]]

    print('-----------------------------------')
Esempio n. 18
0
            idx = numpy.argsort(es)
            assert(numpy.allclose(es[idx], esub, rtol=1e-3, atol=1e-4))
            c[:,degidx] = numpy.hstack(cs)[:,idx]
    return c


if __name__ == '__main__':
    from pyscf import scf
    from pyscf import gto
    from pyscf import mcscf

    mol = gto.M(
    verbose = 0,
    atom = '''
           H    0.000000,  0.500000,  1.5   
           O    0.000000,  0.000000,  1.
           O    0.000000,  0.000000, -1.
           H    0.000000, -0.500000, -1.5''',
        basis = 'ccpvdz',
    )

    mf = scf.RHF(mol)
    mf.scf()

    aolst = [i for i,s in enumerate(mol.ao_labels()) if 'H 1s' in s]
    dm = mf.make_rdm1()
    ncas, nelecas, mo = guess_cas(mf, dm, aolst, verbose=4)
    mc = mcscf.CASSCF(mf, ncas, nelecas).set(verbose=4)
    emc = mc.kernel(mo)[0]
    print(emc,)
Esempio n. 19
0
def setuph2(r):
    from pyscf import gto, scf, lo
    from pyqmc.accumulators import LinearTransform, EnergyAccumulator
    from pyqmc.obdm import OBDMAccumulator
    from pyqmc.tbdm import TBDMAccumulator
    from pyqmc.cvmc import DescriptorFromOBDM, DescriptorFromTBDM, PGradDescriptor

    import itertools

    # ccECP from A. Annaberdiyev et al. Journal of Chemical Physics 149, 134108 (2018)
    basis = {
        "H": gto.basis.parse(
            """
    H S
23.843185 0.00411490
10.212443 0.01046440
4.374164 0.02801110
1.873529 0.07588620
0.802465 0.18210620
0.343709 0.34852140
0.147217 0.37823130
0.063055 0.11642410
"""
        )
    }
    """
H S
0.040680 1.00000000
H S
0.139013 1.00000000
H P
0.166430 1.00000000
H P
0.740212 1.00000000
"""
    ecp = {
        "H": gto.basis.parse_ecp(
            """
    H nelec 0
H ul
1 21.24359508259891 1.00000000000000
3 21.24359508259891 21.24359508259891
2 21.77696655044365 -10.85192405303825
"""
        )
    }

    mol = gto.M(
        atom=f"H 0. 0. 0.; H 0. 0. {r}", unit="bohr", basis=basis, ecp=ecp, verbose=5
    )
    mf = scf.RHF(mol).run()
    
    wf = pyqmc.slater_jastrow(mol, mf)
    freeze = {}
    for k in wf.parameters:
        freeze[k] = np.zeros(wf.parameters[k].shape,dtype='bool')
    print(freeze.keys())
    print(wf.parameters['wf1mo_coeff_alpha'])
    #this freezing allows us to easily go between bonding and 
    # AFM configurations.
    freeze['wf1mo_coeff_alpha'][0,0]=True
    freeze['wf1mo_coeff_beta'][1,0]=True
    
    mo_occ = mf.mo_coeff[:, mf.mo_occ > 0]
    a = lo.iao.iao(mol, mo_occ)
    a = lo.vec_lowdin(a, mf.get_ovlp())

    obdm_up = OBDMAccumulator(mol=mol, orb_coeff=a, spin=0)
    obdm_down = OBDMAccumulator(mol=mol, orb_coeff=a, spin=1)
    descriptors = {
        "t": [[(1.0, (0, 1)), (1.0, (1, 0))], [(1.0, (0, 1)), (1.0, (1, 0))]],
        "trace": [[(1.0, (0, 0)), (1.0, (1, 1))], [(1.0, (0, 0)), (1.0, (1, 1))]],
    }
    for i in [0, 1]:
        descriptors[f"nup{i}"] = [[(1.0, (i, i))], []]
        descriptors[f"ndown{i}"] = [[], [(1.0, (i, i))]]
    
    tbdm_up_down = TBDMAccumulator(mol=mol, orb_coeff=np.array([a,a]), spin=(0,1), ijkl=[[0,0,0,0]])
    tbdm_down_up = TBDMAccumulator(mol=mol, orb_coeff=np.array([a,a]), spin=(1,0), ijkl=[[0,0,0,0]])
    descriptors_tbdm = {
        "U": [[(1.0,(0))],[(1.0,(0))]]
    }

    acc = PGradDescriptor(
        EnergyAccumulator(mol),
        LinearTransform(wf.parameters, freeze=freeze),
        {
          'obdm': [obdm_up, obdm_down], 
          'tbdm': [tbdm_up_down, tbdm_down_up],
        },
        {
          'obdm': DescriptorFromOBDM(descriptors, norm=2.0),
          'tbdm': DescriptorFromTBDM(descriptors_tbdm, norm=2.0*(2.0-1.0)),
        },
    )

    return {"wf": wf, "acc": acc, "mol": mol, "mf": mf, "descriptors": descriptors, "descriptors_tbdm": descriptors_tbdm}
Esempio n. 20
0
 def setUpClass(cls):
     mol = gto.M(atom='O 0 0 0; H 0 0 1; H 0 1 0',
                 basis='cc-pvdz',
                 verbose=0)
     cls.mf = scf.RHF(mol)
     cls.mf.run(conv_tol=1e-12)
Esempio n. 21
0
#!/usr/bin/env python
'''
Write orbitals, electron density, molecular electrostatic potential in
Gaussian cube file format.
'''

from pyscf import gto, scf, qmmm
from pyscf.tools import cubegen
from pyscf.data.nist import BOHR
import numpy as np

ang2bohr = 1.0 / BOHR

mol = gto.M(atom='''
O   0.0000000000000000        0.0000000000000000        0.000
H  -0.26312631683261728       0.92177640310981912       0.000
H   0.9645910938303689        4.0006988432649347E-002   0.000
''',
            basis='aug-cc-pVDZ')

mm_crd = np.array(
    [[2.9125407227330018, 0.0000000000000000, 0.000],
     [3.3354011353264896, -0.41314678971687741, -0.75710308103585677],
     [3.3354011558614673, -0.41314667699843621, 0.75710313896414105]])
mm_crd *= ang2bohr
mm_chgs = np.array([-0.68, 0.34, 0.34])

mf = qmmm.mm_charge(scf.RHF(mol), mm_crd, mm_chgs).run()
# electron density
cubegen.density(mol, 'h2o_den_qmmm.cube', mf.make_rdm1())

# molecular electrostatic potential
Esempio n. 22
0
from __future__ import print_function, division
import unittest, numpy as np
from pyscf import gto, scf
from pyscf.nao import gw

mol = gto.M(
    verbose=1,
    atom='''
        H     0    0        0
        H     0    0.757    0.587''',
    basis='def2-TZVP',
)


class KnowValues(unittest.TestCase):
    def test_scf_gto_vs_nao(self):
        """ Test computation of overlaps between NAOs against overlaps computed between GTOs"""
        gto_hf = scf.RHF(mol)
        gto_hf.kernel()
        print(gto_hf.mo_energy)

        nao_gw = gw(mf=gto_hf,
                    gto=mol,
                    pb_algorithm='fp',
                    verbosity=1,
                    rescf=True,
                    perform_gw=True)
        nao_gw.dump_chkfile = False
        for e1, egw, e2 in zip(nao_gw.mo_energy[0, 0],
                               nao_gw.mo_energy_gw[0, 0], gto_hf.mo_energy):
            print(e1, egw, e2)
Esempio n. 23
0
    def _finalize(self):
        if self.verbose >= logger.NOTE:
            logger.note(self, '--------------- %s gradients ---------------',
                        self.base.__class__.__name__)
            rhf_grad._write(self, self.mol, self.de, self.atmlst)
            logger.note(self, '----------------------------------------------')

    as_scanner = as_scanner


if __name__ == '__main__':
    from pyscf import gto
    from pyscf import scf

    mol = gto.M(atom=[["O", (0., 0., 0.)], [1, (0., -0.757, 0.587)],
                      [1, (0., 0.757, 0.587)]],
                basis='631g')
    mf = scf.RHF(mol).run()
    mycc = ccsd.CCSD(mf).run()
    g1 = Gradients(mycc).kernel()
    #[[ 0   0                1.00950925e-02]
    # [ 0   2.28063426e-02  -5.04754623e-03]
    # [ 0  -2.28063426e-02  -5.04754623e-03]]
    print(lib.finger(g1) - -0.036999389889460096)

    mcs = mycc.as_scanner()
    mol.set_geom_([["O", (0., 0., 0.001)], [1, (0., -0.757, 0.587)],
                   [1, (0., 0.757, 0.587)]])
    e1 = mcs(mol)
    mol.set_geom_([["O", (0., 0., -0.001)], [1, (0., -0.757, 0.587)],
                   [1, (0., 0.757, 0.587)]])
Esempio n. 24
0
    d.append({"error": norm_grad, "deriv": "grad", "type": "norm"})
    d.append({"error": norm_lap, "deriv": "lap", "type": "norm"})
    return d


if __name__ == "__main__":
    from pyscf import lib, gto, scf
    import pyqmc
    from pyqmc.slateruhf import PySCFSlaterUHF

    # from pyqmc.jastrow import Jastrow2B
    from pyqmc.coord import OpenConfigs
    import time
    import pandas as pd

    mol = gto.M(atom="Li 0. 0. 0.; Li 0. 0. 1.5", basis="cc-pvtz", unit="bohr")
    mf = scf.UHF(mol).run()
    wf = PySCFSlaterUHF(mol, mf)

    # wf=Jastrow2B(10,mol)
    df = []
    for i in range(5):
        configs = OpenConfigs(np.random.randn(18000, np.sum(mol.nelec), 3))
        res = test_wf_gradient_laplacian(wf, configs)
        for d in res:
            d.update({"step": i})
        df.extend(res)
    print("testing gradient: errors\n", pd.DataFrame(df))
    quit()
    for i in range(5):
        configs = OpenConfigs(np.random.randn(10, np.sum(mol.nelec), 3))
Esempio n. 25
0
    # @  https://jyx.jyu.fi/dspace/bitstream/handle/123456789/45989/URN%3ANBN%3Afi%3Ajyu-201505211947.pdf?sequence=1, Eq.(84)
    # for further information.
    return -2 * (HS - LS) / (S2_HS - S2_LS) * 219474


# First, we read the structure for the high spin configuration.

atoms = read('HHeH.xyz')

# Now, we set up the mole object.

spin = 2
charge = 0
xc = 'LDA,PW'
b = 'cc-pVQZ'
mol = gto.M(atom=ase2pyscf(atoms), basis=b, spin=spin, charge=charge)

# Now we set up the calculator.

dft_object = dft.UKS(mol)
dft_object.max_cycle = 300
dft_object.xc = xc
dft_object.conv_tol = 1e-7

# With this, we can calculate the high-spin total ground state energy.

E_HS_DFT = dft_object.kernel()

# Next, we need the low-spin solution. The first steps are completely similar to the high-spin calculation.
# In addition we now apply a small electric field.
Esempio n. 26
0
# Author: Qiming Sun <*****@*****.**>
#

from pyscf import gto
from pyscf import scf
from pyscf import mcscf
from pyscf.dmrgscf import DMRGCI, DMRGSCF
'''
When Block code is used for active space solver, state-average calculation can
be set up in various ways.
'''

b = 1.2
mol = gto.M(
    verbose=4,
    atom='N 0 0 %f; N 0 0 %f' % (-b * .5, b * .5),
    basis='cc-pvdz',
    symmetry=True,
)
m = scf.RHF(mol)
m.kernel()

#
# Simple state-average calculation
#
mc = DMRGSCF(m, 8, 8)
mc.state_average_([0.5, 0.5])
mc.kernel()
print(mc.e_tot)

#
# More general and/or complicated state-average calculations:
Esempio n. 27
0
        # pointer to sp_mu2rcut
        svn[i] = s + 1
        i += 1
        f = s + nrt
        svn[s:f] = conc(self.psi_log).reshape(nrt)
        s = f
        # pointer to psi_log
        svn[i] = s + 1
        i += 1
        f = s + nms
        svn[s:f] = conc(self.sp_mu2s)
        s = f
        # pointer to sp_mu2s
        svn[i] = s + 1
        # this is a terminator to simple operation
        return svn


#
#
#
if __name__ == "__main__":
    from pyscf import gto
    from pyscf.nao.m_ao_log import ao_log_c
    """ Interpreting small Gaussian calculation """
    mol = gto.M(atom='O 0 0 0; H 0 0 1; H 0 1 0',
                basis='ccpvdz')  # coordinates in Angstrom!
    ao_log = ao_log_c(gto=mol)

    print(ao_log.sp2norbs)
Esempio n. 28
0
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import ctypes
import unittest
import numpy
from pyscf import lib, gto

libcgto = lib.load_library('libdft')
BLKSIZE = 64

mol = gto.M(atom='''
            O 0.5 0.5 0.
            H  1.  1.2 0.
            H  0.  0.  1.3
            ''',
            basis='ccpvqz')

def eval_gto(mol, eval_name, coords,
             comp=1, shls_slice=None, non0tab=None, ao_loc=None, out=None):
    atm = numpy.asarray(mol._atm, dtype=numpy.int32, order='C')
    bas = numpy.asarray(mol._bas, dtype=numpy.int32, order='C')
    env = numpy.asarray(mol._env, dtype=numpy.double, order='C')
    coords = numpy.asarray(coords, dtype=numpy.double, order='F')
    natm = atm.shape[0]
    nbas = bas.shape[0]
    ngrids = coords.shape[0]
    if ao_loc is None:
        ao_loc = gto.moleintor.make_loc(bas, eval_name)
Esempio n. 29
0
        qeri = ((eri.feri['qmo/aa'], eri.feri['qmo/ab']), 
                (eri.feri['qmo/ba'], eri.feri['qmo/bb']))
    elif spin == 0:
        qeri = (eri.feri['qmo/aa'], eri.feri['qmo/ab'])
    elif spin == 1:
        qeri = (eri.feri['qmo/bb'], eri.feri['qmo/ba'])

    log.timer('QMO integral transformation', *cput0)

    return qeri



if __name__ == '__main__':
    from pyscf import gto, scf, mp

    mol = gto.M(atom='O 0 0 0; H 0 0 1; H 0 1 0', basis='cc-pvdz', charge=-1, spin=1, verbose=3)
    uhf = scf.UHF(mol)
    uhf.conv_tol = 1e-11
    uhf.run()

    uagf2 = UAGF2(uhf, frozen=0)

    uagf2.run()
    uagf2.ipagf2(nroots=5)
    uagf2.eaagf2(nroots=5)

    
    uagf2 = uagf2.density_fit()
    uagf2.run()
Esempio n. 30
0
so this example is almost identical to 02-dfagf2.py). 

MPI support is provided by mpi4py module. The implementation is also hybrid 
parallelized, and therefore may benefit from a combination of OMP threads 
and MPI processes. OMP threads will automatically be used if OMP_NUM_THREADS
is appropriately set.

Default AGF2 corresponds to the AGF2(1,0) method outlined in the papers:
  - O. J. Backhouse, M. Nusspickel and G. H. Booth, J. Chem. Theory Comput., 16, 1090 (2020).
  - O. J. Backhouse and G. H. Booth, J. Chem. Theory Comput., 16, 6294 (2020).
'''

from pyscf import gto, scf, agf2

mol = gto.M(atom='O 0 0 0; H 0 0 1; H 0 1 0',
            basis='cc-pvdz',
            verbose=3 if agf2.mpi_helper.rank == 0 else 0)

mf = scf.RHF(mol).density_fit(auxbasis='cc-pv5z-ri')
mf.conv_tol = 1e-12
mf.run()

# Run an AGF2 calculation
gf2 = agf2.AGF2(mf)
gf2.conv_tol = 1e-7
gf2.run(verbose=4 if agf2.mpi_helper.rank == 0 else 0)

# Print the first 3 ionization potentials
gf2.ipagf2(nroots=3)

# Print the first 3 electron affinities