예제 #1
0
파일: grid.py 프로젝트: chrinide/pyaim
#!/usr/bin/env python

import numpy
import ctypes
from pyscf import lib
from pyscf.lib import parameters as param

libdft = lib.load_library('libdft')

HMINIMAL = numpy.finfo(numpy.float64).eps

EPS = 1e-7
LEBEDEV_NGRID = numpy.asarray((
    1   , 6   , 14  , 26  , 38  , 50  , 74  , 86  , 110 , 146 ,
    170 , 194 , 230 , 266 , 302 , 350 , 434 , 590 , 770 , 974 ,
    1202, 1454, 1730, 2030, 2354, 2702, 3074, 3470, 3890, 4334,
    4802, 5294, 5810))

#########################
# JCP 41 3199 (1964).
BRAGG = 1.0/param.BOHR * numpy.array((0,  # Ghost atom
        0.35,                                     1.40,             # 1s
        1.45, 1.05, 0.85, 0.70, 0.65, 0.60, 0.50, 1.50,             # 2s2p
        1.80, 1.50, 1.25, 1.10, 1.00, 1.00, 1.00, 1.80,             # 3s3p
        2.20, 1.80,                                                 # 4s
        1.60, 1.40, 1.35, 1.40, 1.40, 1.40, 1.35, 1.35, 1.35, 1.35, # 3d
                    1.30, 1.25, 1.15, 1.15, 1.15, 1.90,             # 4p
        2.35, 2.00,                                                 # 5s
        1.80, 1.55, 1.45, 1.45, 1.35, 1.30, 1.35, 1.40, 1.60, 1.55, # 4d
                    1.55, 1.45, 1.45, 1.40, 1.40, 2.10,             # 5p
        2.60, 2.15,                                                 # 6s
예제 #2
0
파일: xcfun.py 프로젝트: chrinide/pyscf
#
# Author: Qiming Sun <*****@*****.**>
#

'''
XC functional, the interface to xcfun (https://github.com/dftlibs/xcfun)
U. Ekstrom et al, J. Chem. Theory Comput., 6, 1971
'''

import copy
import ctypes
import math
import numpy
from pyscf import lib

_itrf = lib.load_library('libxcfun_itrf')

XC = XC_CODES = {
'SLATERX'       :  0,  # Slater LDA exchange
'PW86X'         :  1,  # PW86 exchange
'VWN3C'         :  2,  # VWN3 LDA Correlation functional
'VWN5C'         :  3,  # VWN5 LDA Correlation functional
'PBEC'          :  4,  # PBE correlation functional
'PBEX'          :  5,  # PBE Exchange Functional
'BECKEX'        :  6,  # Becke 88 exchange
'BECKECORRX'    :  7,  # Becke 88 exchange correction
'BECKESRX'      :  8,  # Short range Becke 88 exchange
'BECKECAMX'     :  9,  # CAM Becke 88 exchange
'BRX'           : 10,  # Becke-Roussells exchange with jp dependence
'BRC'           : 11,  # Becke-Roussells correlation with jp dependence
'BRXC'          : 12,  # Becke-Roussells correlation with jp dependence
예제 #3
0
# Authors: Qiming Sun <*****@*****.**>
#          Susi Lehtola <*****@*****.**>

'''
XC functional, the interface to libxc
(http://www.tddft.org/programs/octopus/wiki/index.php/Libxc)
'''

import sys
import copy
import ctypes
import math
import numpy
from pyscf import lib

_itrf = lib.load_library('libxc_itrf')
_itrf.LIBXC_is_lda.restype = ctypes.c_int
_itrf.LIBXC_is_gga.restype = ctypes.c_int
_itrf.LIBXC_is_meta_gga.restype = ctypes.c_int
_itrf.LIBXC_is_hybrid.restype = ctypes.c_int
_itrf.LIBXC_max_deriv_order.restype = ctypes.c_int
_itrf.LIBXC_hybrid_coeff.restype = ctypes.c_double

# xc_code from libxc
#cat lib/deps/include/xc_funcs.h  | awk '{printf("'\''%s'\'' %3i",$2,$3); for(i=4;i<NF;i++) {printf(" %s",$i)}; printf("\n")}'  | sed "s|/\*|# |g" | awk '{printf("%-30s : %4i\,",$1,$2); for(i=4;i<NF;i++) {printf(" %s",$i)}; printf("\n")}'

XC = XC_CODES = {
'XC_LDA_X'                     :    1, # Exchange
'XC_LDA_C_WIGNER'              :    2, # Wigner parametrization
'XC_LDA_C_RPA'                 :    3, # Random Phase Approximation
'XC_LDA_C_HL'                  :    4, # Hedin & Lundqvist
예제 #4
0
#!/usr/bin/env python

import os
import ctypes
import unittest
import numpy
from pyscf import lib
from pyscf import scf
from pyscf import gto
from pyscf import ao2mo

libcvhf2 = lib.load_library('libcvhf')

mol = gto.Mole()
mol.verbose = 0
mol.output = None#'out_h2o'
mol.atom = [
    ['O' , (0. , 0.     , 0.)],
    [1   , (0. , -0.757 , 0.587)],
    [1   , (0. , 0.757  , 0.587)] ]

mol.basis = 'cc-pvdz'

mol.build()
rhf = scf.RHF(mol)
rhf.scf()


nao = mol.nao_nr()
npair = nao*(nao+1)//2
c_atm = numpy.array(mol._atm, dtype=numpy.int32)
예제 #5
0
import numpy
import h5py
import ctypes
import signal
from pyscf import lib
from pyscf.lib import logger

signal.signal(signal.SIGINT, signal.SIG_DFL)

# For code compatiblity in python-2 and python-3
if sys.version_info >= (3,):
    unicode = str

_loaderpath = os.path.dirname(__file__)
libaim = numpy.ctypeslib.load_library('libaim.so', _loaderpath)
libcgto = lib.load_library('libcgto')

name = 'h2o.chk.h5'

idx = 1
jdx = 2
        
idx1 = 'qlm'+str(idx)
idx2 = 'qlm'+str(jdx)
with h5py.File(name) as f:
    lmax1 = f[idx1+'/lmax'].value
    qlm1 = f[idx1+'/totprops'].value
    lmax2 = f[idx2+'/lmax'].value
    qlm2 = f[idx2+'/totprops'].value
idx1 = 'atom'+str(idx)
with h5py.File(name) as f:
예제 #6
0
파일: rdm.py 프로젝트: sunqm/pyscf
Note the 1-particle density matrix has the same convention as the mean-field
1-particle density matrix (see McWeeney's book Eq 5.4.20), which is
        dm[p,q] = < q^+ p >
The contraction between 1-particle Hamiltonian and 1-pdm is
        E = einsum('pq,qp', h1, 1pdm)
Different conventions are used in the high order density matrices:
        dm[p,q,r,s,...] = < p^+ r^+ ... s q >
'''

import ctypes
import numpy
from pyscf import lib
from pyscf.fci import cistring
from pyscf.fci.addons import _unpack_nelec

librdm = lib.load_library('libfci')

def reorder_rdm(rdm1, rdm2, inplace=False):
    nmo = rdm1.shape[0]
    if not inplace:
        rdm2 = rdm2.copy()
    for k in range(nmo):
        rdm2[:,k,k,:] -= rdm1.T
    #return rdm1, rdm2
    rdm2 = lib.transpose_sum(rdm2.reshape(nmo*nmo,-1), inplace=True) * .5
    return rdm1, rdm2.reshape(nmo,nmo,nmo,nmo)

# dm[p,q] = <|q^+ p|>
def make_rdm1_ms0(fname, cibra, ciket, norb, nelec, link_index=None):
    assert(cibra is not None and ciket is not None)
    cibra = numpy.asarray(cibra, order='C')
예제 #7
0
파일: test.py 프로젝트: chrinide/pyaim
import sys
import time
import numpy
import ctypes
import signal

from pyscf.pbc import lib as libpbc
from pyscf.pbc import dft
from pyscf import lib
from pyscf.lib import logger

import grid

_loaderpath = os.path.dirname(__file__)
libaim = numpy.ctypeslib.load_library('libaim.so', _loaderpath)
libpbcgto = lib.load_library('libpbc')

signal.signal(signal.SIGINT, signal.SIG_DFL)

# For code compatiblity in python-2 and python-3
if sys.version_info >= (3,):
    unicode = str

GRADEPS = 1e-10
RHOEPS = 1e-10
MINSTEP = 1e-6
MAXSTEP = 0.75
SAFETY = 0.9
ENLARGE = 1.6
HMINIMAL = numpy.finfo(numpy.float64).eps
예제 #8
0
파일: hci.py 프로젝트: chrinide/pyscf
(JCTC 2016, 12, 3674-3680)

Simple usage::

'''

import numpy
import time
import ctypes
from pyscf import lib
from pyscf import ao2mo
from pyscf.lib import logger
from pyscf.fci import cistring
from pyscf.fci import direct_spin1

libhci = lib.load_library('libhci')

def contract_2e_ctypes(h1_h2, civec, norb, nelec, hdiag=None, **kwargs):
    h1, eri = h1_h2
    strs = civec._strs
    ndet = len(strs)
    if hdiag is None:
        hdiag = make_hdiag(h1, eri, strs, norb, nelec)
    ci1 = numpy.zeros_like(civec)

    h1 = numpy.asarray(h1, order='C')
    eri = numpy.asarray(eri, order='C')
    strs = numpy.asarray(strs, order='C')
    civec = numpy.asarray(civec, order='C')
    hdiag = numpy.asarray(hdiag, order='C')
    ci1 = numpy.asarray(ci1, order='C')
예제 #9
0
파일: outcore.py 프로젝트: ushnishray/pyscf
import scipy.linalg
import h5py
from pyscf import lib
from pyscf import gto
from pyscf.lib import logger
from pyscf import ao2mo
from pyscf.ao2mo import _ao2mo
from pyscf.scf import _vhf
from pyscf.df import incore
from pyscf.df import _ri

#
# for auxe1 (P|ij)
#

libri = lib.load_library("libri")


def cholesky_eri(
    mol,
    erifile,
    auxbasis="weigend+etb",
    dataname="eri_mo",
    tmpdir=None,
    int3c="cint3c2e_sph",
    aosym="s2ij",
    int2c="cint2c2e_sph",
    comp=1,
    ioblk_size=256,
    auxmol=None,
    verbose=0,
예제 #10
0
from pyscf import gto, scf
from pyscf.tools import molden
from pyscf.lib import parameters as param
from pyscf.lib import logger
from pyscf.lib import linalg_helper
from pyscf.scf import _vhf
from pyscf import ao2mo

import numpy as np
import scipy
#import time

import ctypes
from pyscf.lib import load_library
liblocalizer = load_library('liblocalizer')


class localizer:
    def __init__(self, mol, orbital_coeff, thetype, use_full_hessian=True):
        r'''Initializer for the localization procedure

        Args:
            mol : A molecule which has been built
            orbital_coeff: Set of orthonormal orbitals, expressed in terms of the AO, which should be localized
            thetype: Which cost function to optimize: 'boys' or 'edmiston'
            use_full_hessian: Whether to do augmented Hessian Newton-Raphson (True) or just -gradient/diag(hessian) (False)
        '''

        assert ((thetype == 'boys') or (thetype == 'edmiston'))
예제 #11
0
파일: dmrgci.py 프로젝트: pyscf/dmrgscf
import sys
import struct

import tempfile
from subprocess import check_call, check_output, STDOUT, CalledProcessError
import numpy
from pyscf import lib
from pyscf import tools
from pyscf.lib import logger
from pyscf import ao2mo
from pyscf import mcscf
from pyscf.dmrgscf import dmrg_sym
from pyscf import __config__

# Libraries
libunpack = lib.load_library('libunpack')

# Settings
try:
    from pyscf.dmrgscf import settings
except ImportError:
    settings = lambda: None
    settings.BLOCKEXE = getattr(__config__, 'dmrgscf_BLOCKEXE', None)
    settings.BLOCKEXE_COMPRESS_NEVPT = \
            getattr(__config__, 'dmrgscf_BLOCKEXE_COMPRESS_NEVPT', None)
    settings.BLOCKSCRATCHDIR = getattr(__config__, 'dmrgscf_BLOCKSCRATCHDIR',
                                       None)
    settings.BLOCKRUNTIMEDIR = getattr(__config__, 'dmrgscf_BLOCKRUNTIMEDIR',
                                       None)
    settings.MPIPREFIX = getattr(__config__, 'dmrgscf_MPIPREFIX', None)
    settings.BLOCKVERSION = getattr(__config__, 'dmrgscf_BLOCKVERSION', None)
예제 #12
0
# You may obtain a copy of the License at
#
#     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.

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')
예제 #13
0
파일: sgx_jk.py 프로젝트: wangya134/sgX
def _gen_jk_direct(mol, aosym, with_j, with_k, direct_scf_tol):
    '''Contraction between sgX Coulomb integrals and density matrices
    J: einsum('guv,xg->xuv', gbn, dms) if dms == rho at grid
       einsum('gij,xij->xg', gbn, dms) if dms are density matrices
    K: einsum('gtv,xgt->xgv', gbn, fg)
    '''
    intor = mol._add_suffix('int3c2e')
    cintopt = gto.moleintor.make_cintopt(mol._atm, mol._bas, mol._env, intor)
    ncomp = 1
    nao = mol.nao

    vhfopt = _vhf.VHFOpt(mol, 'int1e_ovlp', 'SGXnr_ovlp_prescreen',
                         'SGXsetnr_direct_scf')
    vhfopt.direct_scf_tol = direct_scf_tol
    cintor = _vhf._fpointer(intor)
    fdot = _vhf._fpointer('SGXdot_nr' + aosym)
    drv = _vhf.libcvhf.SGXnr_direct_drv

    # for linsgx, from _vhf.VHFOpt
    libcvhf = lib.load_library('libcvhf')
    intor = mol._add_suffix('int1e_ovlp')
    c_atm = numpy.asarray(mol._atm, dtype=numpy.int32, order='C')
    c_bas = numpy.asarray(mol._bas, dtype=numpy.int32, order='C')
    c_env = numpy.asarray(mol._env, dtype=numpy.double, order='C')
    natm = ctypes.c_int(c_atm.shape[0])
    nbas = ctypes.c_int(c_bas.shape[0])

    @profile
    def jk_part(mol, grid_coords, dms, fg):

        # transfer bvv to SGXsetnr_direct_scf_blk. from _vhf.VHFOpt
        # need add mol._bvv in scf.mole.py
        c_bvv = numpy.asarray(mol._bvv, dtype=numpy.int32, order='C')
        nbvv = ctypes.c_int(c_bvv.shape[0])
        ao_loc = make_loc(c_bas, intor)
        fsetqcond = getattr(libcvhf, 'SGXsetnr_direct_scf_blk')
        fsetqcond(vhfopt._this, getattr(libcvhf, intor), lib.c_null_ptr(),
                  ao_loc.ctypes.data_as(ctypes.c_void_p),
                  c_atm.ctypes.data_as(ctypes.c_void_p), natm,
                  c_bas.ctypes.data_as(ctypes.c_void_p), nbas,
                  c_env.ctypes.data_as(ctypes.c_void_p),
                  c_bvv.ctypes.data_as(ctypes.c_void_p), nbvv)

        fakemol = gto.fakemol_for_charges(grid_coords)
        atm, bas, env = gto.mole.conc_env(mol._atm, mol._bas, mol._env,
                                          fakemol._atm, fakemol._bas,
                                          fakemol._env)

        ao_loc = moleintor.make_loc(bas, intor)
        shls_slice = (0, mol.nbas, 0, mol.nbas, mol.nbas, len(bas))
        ngrids = grid_coords.shape[0]

        vj = vk = None
        fjk = []
        dmsptr = []
        vjkptr = []
        if with_j:
            if dms[0].ndim == 1:  # the value of density at each grid
                vj = numpy.zeros((len(dms), ncomp, nao, nao))[:, 0]
                for i, dm in enumerate(dms):
                    dmsptr.append(dm.ctypes.data_as(ctypes.c_void_p))
                    vjkptr.append(vj[i].ctypes.data_as(ctypes.c_void_p))
                    fjk.append(_vhf._fpointer('SGXnr' + aosym + '_ijg_g_ij'))
            else:
                vj = numpy.zeros((len(dms), ncomp, ngrids))[:, 0]
                for i, dm in enumerate(dms):
                    dmsptr.append(dm.ctypes.data_as(ctypes.c_void_p))
                    vjkptr.append(vj[i].ctypes.data_as(ctypes.c_void_p))
                    fjk.append(_vhf._fpointer('SGXnr' + aosym + '_ijg_ji_g'))
        if with_k:
            vk = numpy.zeros((len(fg), ncomp, ngrids, nao))[:, 0]
            for i, dm in enumerate(fg):
                dmsptr.append(dm.ctypes.data_as(ctypes.c_void_p))
                vjkptr.append(vk[i].ctypes.data_as(ctypes.c_void_p))
                fjk.append(_vhf._fpointer('SGXnr' + aosym + '_ijg_gj_gi'))

        n_dm = len(fjk)
        fjk = (ctypes.c_void_p * (n_dm))(*fjk)
        dmsptr = (ctypes.c_void_p * (n_dm))(*dmsptr)
        vjkptr = (ctypes.c_void_p * (n_dm))(*vjkptr)

        drv(cintor, fdot, fjk, dmsptr, vjkptr, n_dm, ncomp,
            (ctypes.c_int * 6)(*shls_slice),
            ao_loc.ctypes.data_as(ctypes.c_void_p), cintopt, vhfopt._this,
            atm.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(mol.natm),
            bas.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(mol.nbas),
            env.ctypes.data_as(ctypes.c_void_p))
        return vj, vk

    return jk_part
예제 #14
0
#!/usr/bin/env python

import os
import ctypes
import unittest
from functools import reduce
import numpy
import h5py
from pyscf import lib
from pyscf import scf
from pyscf import gto
from pyscf import ao2mo
from pyscf.ao2mo import _ao2mo
from pyscf.scf import _vhf

libao2mo1 = lib.load_library("libao2mo")

mol = gto.Mole()
mol.verbose = 0
mol.output = None  #'out_h2o'
mol.atom.extend([["O", (0.0, 0.0, 0.0)], [1, (0.0, -0.757, 0.587)], [1, (0.0, 0.757, 0.587)]])

mol.basis = "cc-pvdz"
mol.build()
nao = mol.nao_nr()
naopair = nao * (nao + 1) // 2
numpy.random.seed(15)
mo = numpy.random.random((nao, nao))
mo = mo.copy(order="F")

c_atm = numpy.array(mol._atm, dtype=numpy.int32)
예제 #15
0
#!/usr/bin/env python
#
# Author: Qiming Sun <*****@*****.**>
#
'''
XC functional, the interface to xcfun (https://github.com/dftlibs/xcfun)
U. Ekstrom et al, J. Chem. Theory Comput., 6, 1971
'''

import copy
import ctypes
import math
import numpy
from pyscf import lib

_itrf = lib.load_library('libxcfun_itrf')

XC = XC_CODES = {
    'SLATERX': 0,  # Slater LDA exchange
    'VWN5C': 1,  # VWN5 LDA Correlation functional
    'BECKEX': 2,  # Becke 88 exchange
    'BECKECORRX': 3,  # Becke 88 exchange correction
    'BECKESRX': 4,  # Short range Becke 88 exchange
    'OPTX': 5,  # OPTX Handy & Cohen exchange
    'LYPC': 6,  # LYP correlation
    'PBEX': 7,  # PBE Exchange Functional
    'REVPBEX': 8,  # Revised PBE Exchange Functional
    'RPBEX': 9,  # RPBE Exchange Functional
    'PBEC': 10,  # PBE correlation functional
    'SPBEC': 11,  # sPBE correlation functional
    'VWN_PBEC': 12,  # PBE correlation functional using VWN LDA correlation.
예제 #16
0
파일: am1.py 프로젝트: wmizukami/pyscf
[2] J. J. Stewart, J. Mol. Model 10, 155 (2004)
'''
raise NotImplementedError('AM1 model is in testing')

import ctypes
import copy
import numpy
from pyscf import lib
from pyscf.lib import logger
from pyscf import gto
from pyscf import scf
from pyscf import ao2mo
from pyscf.data.elements import _symbol
from pyscf.semiempirical import mopac_param, mindo3

libsemiempirical = lib.load_library('libsemiempirical')
ndpointer = numpy.ctypeslib.ndpointer
libsemiempirical.MOPAC_rotate.argtypes = [
    ctypes.c_int,
    ctypes.c_int,
    ndpointer(dtype=numpy.double),  # xi
    ndpointer(dtype=numpy.double),  # xj
    ndpointer(dtype=numpy.double),  # w
    ndpointer(dtype=numpy.double),  # e1b
    ndpointer(dtype=numpy.double),  # e2a
    ndpointer(dtype=numpy.double),  # enuc
    ndpointer(dtype=numpy.double),  # alp
    ndpointer(dtype=numpy.double),  # dd
    ndpointer(dtype=numpy.double),  # qq
    ndpointer(dtype=numpy.double),  # am
    ndpointer(dtype=numpy.double),  # ad
예제 #17
0
파일: spin_op.py 프로젝트: zzy2014/pyscf
#
#     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 functools import reduce
import numpy
from pyscf import lib
from pyscf.fci import cistring
from pyscf.fci.addons import _unpack_nelec

librdm = lib.load_library('libfci')

######################################################
# Spin squared operator
######################################################
# S^2 = (S+ * S- + S- * S+)/2 + Sz * Sz
# S+ = \sum_i S_i+ ~ effective for all beta occupied orbitals.
# S- = \sum_i S_i- ~ effective for all alpha occupied orbitals.
# There are two cases for S+*S-
# 1) same electron \sum_i s_i+*s_i-, <CI|s_i+*s_i-|CI> gives
#       <p|s+s-|q> \gammalpha_qp = trace(\gammalpha) = neleca
# 2) different electrons for \sum s_i+*s_j- (i\neq j, n*(n-1) terms)
# As a two-particle operator S+*S-
#       = <ij|s+s-|kl>Gamma_{ik,jl} = <iajb|s+s-|kbla>Gamma_{iakb,jbla}
#       = <ia|s+|kb><jb|s-|la>Gamma_{iakb,jbla}
# <CI|S+*S-|CI> = neleca + <ia|s+|kb><jb|s-|la>Gamma_{iakb,jbla}
예제 #18
0
파일: gen_grid.py 프로젝트: chrinide/pyscf
Reference for Lebedev-Laikov grid:
  V. I. Lebedev, and D. N. Laikov "A quadrature formula for the sphere of the
  131st algebraic order of accuracy", Doklady Mathematics, 59, 477-481 (1999)
'''


import ctypes
import numpy
from pyscf import lib
from pyscf.lib import logger
from pyscf import gto
from pyscf.dft import radi
from pyscf import __config__

libdft = lib.load_library('libdft')
BLKSIZE = 128  # needs to be the same to lib/gto/grid_ao_drv.c

# ~= (L+1)**2/3
LEBEDEV_ORDER = {
      0:    1,
      3:    6,
      5:   14,
      7:   26,
      9:   38,
     11:   50,
     13:   74,
     15:   86,
     17:  110,
     19:  146,
     21:  170,
예제 #19
0
# Author: Qiming Sun <*****@*****.**>
#

import time
import ctypes
import tempfile
import numpy
import h5py
import pyscf.lib as lib
from pyscf.lib import logger
import pyscf.ao2mo
import pyscf.cc.ccsd_slow as ccsd
from pyscf.cc import ccsd_rdm
from pyscf import grad

libcc = lib.load_library('libcc')

def IX_intermediates(cc, t1, t2, l1, l2, eris=None, d1=None, d2=None):
    if eris is None:
# Note eris are in Chemist's notation
        eris = ccsd._ERIS(cc)
    if d1 is None:
        doo, dvv = ccsd_rdm.gamma1_intermediates(cc, t1, t2, l1, l2)
    else:
        doo, dvv = d1
    if d2 is None:
# Note gamma2 are in Chemist's notation
        d2 = ccsd_rdm.gamma2_intermediates(cc, t1, t2, l1, l2)
    dovov, dvvvv, doooo, doovv, dovvo, dvvov, dovvv, dooov = d2
    dvvov = dovvv.transpose(2,3,0,1)
    nocc, nvir = t1.shape
예제 #20
0
파일: _ccsd.py 프로젝트: raybrad/pyscf
#!/usr/bin/env python

import os
import ctypes
import numpy
from pyscf import lib

libcc = lib.load_library("libcc")


# NOTE requisite on data continuous


def unpack_tril(tril, out=None):
    assert tril.flags.c_contiguous
    count = tril.shape[0]
    nd = int(numpy.sqrt(tril.shape[1] * 2))
    if out is None:
        out = numpy.empty((count, nd, nd))
    libcc.CCunpack_tril(
        tril.ctypes.data_as(ctypes.c_void_p), out.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(count), ctypes.c_int(nd)
    )
    return out


def pack_tril(mat, out=None):
    assert mat.flags.c_contiguous
    count, nd = mat.shape[:2]
    if out is None:
        out = numpy.empty((count, nd * (nd + 1) // 2))
    libcc.CCpack_tril(
예제 #21
0
(JCTC 2016, 12, 3674-3680)

Simple usage::

'''

import numpy
import time
import ctypes
from pyscf import lib
from pyscf import ao2mo
from pyscf.lib import logger
from pyscf.fci import cistring
from pyscf.fci import direct_spin1

libhci = lib.load_library('libhci')

def contract_2e_ctypes(h1_h2, civec, norb, nelec, hdiag=None, **kwargs):
    h1, eri = h1_h2
    strs = civec._strs
    ndet = len(strs)
    if hdiag is None:
        hdiag = make_hdiag(h1, eri, strs, norb, nelec)
    ci1 = numpy.zeros_like(civec)

    h1 = numpy.asarray(h1, order='C')
    eri = numpy.asarray(eri, order='C')
    strs = numpy.asarray(strs, order='C')
    civec = numpy.asarray(civec, order='C')
    hdiag = numpy.asarray(hdiag, order='C')
    ci1 = numpy.asarray(ci1, order='C')
예제 #22
0
        if (sys.platform.startswith('linux') or
            sys.platform.startswith('gnukfreebsd')):
            so_ext = '.so'
        elif sys.platform.startswith('darwin'):
            so_ext = '.dylib'
        elif sys.platform.startswith('win'):
            so_ext = '.dll'
        else:
            raise OSError('Unknown platform')
        libname_so = libname + so_ext
        return ctypes.CDLL(os.path.join(os.path.dirname(__file__), libname_so))
    else:
        _loaderpath = os.path.dirname(__file__)
        return np.ctypeslib.load_library(libname, _loaderpath)

libdft = lib.load_library('libdft')
libcvhf = lib.load_library('libcvhf')
def eval_rhoc(mol, ao, mo_coeff, mo_occ, non0tab=None, xctype='LDA',
              verbose=None):

    assert(ao.flags.c_contiguous)
    xctype = xctype.upper()
    if xctype == 'LDA':
        ngrids, nao = ao.shape
    else:
        ngrids, nao = ao[0].shape

    if non0tab is None:
        non0tab = np.ones(((ngrids+BLKSIZE-1)//BLKSIZE,mol.nbas),
                             dtype=np.int8)
    pos = mo_occ.real > OCCDROP
예제 #23
0
파일: dmrgci.py 프로젝트: sunqm/pyscf
import struct
import time
import tempfile
from subprocess import check_call, check_output, STDOUT, CalledProcessError
import numpy
from pyscf import lib
from pyscf import tools
from pyscf.lib import logger
from pyscf import ao2mo
from pyscf import mcscf
from pyscf.dmrgscf import dmrg_sym
from pyscf import __config__

# Libraries
import pyscf.lib
libunpack = lib.load_library('libicmpspt')

# Settings
try:
    from pyscf.dmrgscf import settings
except ImportError:
    settings = lambda: None
    settings.BLOCKEXE = getattr(__config__, 'dmrgscf_BLOCKEXE', None)
    settings.BLOCKEXE_COMPRESS_NEVPT = \
            getattr(__config__, 'dmrgscf_BLOCKEXE_COMPRESS_NEVPT', None)
    settings.BLOCKSCRATCHDIR = getattr(__config__, 'dmrgscf_BLOCKSCRATCHDIR', None)
    settings.BLOCKRUNTIMEDIR = getattr(__config__, 'dmrgscf_BLOCKRUNTIMEDIR', None)
    settings.MPIPREFIX = getattr(__config__, 'dmrgscf_MPIPREFIX', None)
    settings.BLOCKVERSION = getattr(__config__, 'dmrgscf_BLOCKVERSION', None)
    if (settings.BLOCKEXE is None or settings.BLOCKSCRATCHDIR is None):
        import sys
예제 #24
0
    >>> mf = scf.RHF(mol).run()
    >>> h1 = mf.mo_coeff.T.dot(mf.get_hcore()).dot(mf.mo_coeff)
    >>> h2 = ao2mo.kernel(mol, mf.mo_coeff)
    >>> e = fci.select_ci.kernel(h1, h2, mf.mo_coeff.shape[1], mol.nelectron)[0]
"""

import ctypes
import numpy
from pyscf import lib
from pyscf.lib import logger
from pyscf import ao2mo
from pyscf.fci import cistring
from pyscf.fci import direct_spin1
from pyscf.fci import rdm

libfci = lib.load_library("libfci")


def contract_2e(eri, civec_strs, norb, nelec, link_index=None):
    ci_coeff, nelec, ci_strs = _unpack(civec_strs, nelec)
    if link_index is None:
        link_index = _all_linkstr_index(ci_strs, norb, nelec)
    cd_indexa, dd_indexa, cd_indexb, dd_indexb = link_index
    na, nlinka = cd_indexa.shape[:2]
    nb, nlinkb = cd_indexb.shape[:2]
    ma, mlinka = dd_indexa.shape[:2]
    mb, mlinkb = dd_indexb.shape[:2]

    eri = ao2mo.restore(1, eri, norb)
    eri1 = eri.transpose(0, 2, 1, 3) - eri.transpose(0, 2, 3, 1)
    idx, idy = numpy.tril_indices(norb, -1)
예제 #25
0
# limitations under the License.
#
# Author: Qiming Sun <*****@*****.**>
#

import copy
import time
import ctypes
import numpy
import scipy.linalg
from pyscf import lib
from pyscf import scf
from pyscf.lib import logger
from pyscf.ao2mo import _ao2mo

libri = lib.load_library('libri')


def density_fit(mf, auxbasis=None, with_df=None, only_dfj=False):
    '''For the given SCF object, update the J, K matrix constructor with
    corresponding density fitting integrals.

    Args:
        mf : an SCF object

    Kwargs:
        auxbasis : str or basis dict
            Same format to the input attribute mol.basis.  If auxbasis is
            None, optimal auxiliary basis based on AO basis (if possible) or
            even-tempered Gaussian basis will be used.
예제 #26
0
import numpy
import ctypes
import math
from functools import reduce
#import sys, os
#sys.path.append(os.path.join(os.path.dirname(__file__), '../lib'))

from shci4qmc.lib.rel_parity import rel_parity
import shci4qmc.src.vec as vec

import pyscf
from pyscf import symm
from pyscf.lib import load_library

ndpointer = numpy.ctypeslib.ndpointer
shci_lib = load_library('libshciscf')

transformComplex = shci_lib.transformDinfh
transformComplex.restyp = None
transformComplex.argtypes = [
    ctypes.c_int,
    ndpointer(ctypes.c_int32),
    ndpointer(ctypes.c_int32),
    ndpointer(ctypes.c_double),
    ndpointer(ctypes.c_double),
    ndpointer(ctypes.c_double)
]

writeIntNoSymm = shci_lib.writeIntNoSymm
writeIntNoSymm.argtypes = [
    ctypes.c_int,
예제 #27
0
except ImportError:
    from pyscf import __config__
    settings = lambda: None
    settings.SHCIEXE = getattr(__config__, 'shci_SHCIEXE', None)
    settings.SHCISCRATCHDIR = getattr(__config__, 'shci_SHCISCRATCHDIR', None)
    settings.SHCIRUNTIMEDIR = getattr(__config__, 'shci_SHCIRUNTIMEDIR', None)
    settings.MPIPREFIX = getattr(__config__, 'shci_MPIPREFIX', None)
    if (settings.SHCIEXE is None or settings.SHCISCRATCHDIR is None):
        import sys
        sys.stderr.write(
            'settings.py not found.  Please create %s\n' %
            os.path.join(os.path.dirname(__file__), 'settings.py'))
        raise ImportError('settings.py not found')

# Libraries
libE3unpack = load_library('libicmpspt')
# TODO: Organize this better.
shciLib = load_library('libshciscf')

transformDinfh = shciLib.transformDinfh
transformDinfh.restyp = None
transformDinfh.argtypes = [
    ctypes.c_int,
    ndpointer(ctypes.c_int32),
    ndpointer(ctypes.c_int32),
    ndpointer(ctypes.c_double),
    ndpointer(ctypes.c_double),
    ndpointer(ctypes.c_double)
]

transformRDMDinfh = shciLib.transformRDMDinfh
예제 #28
0
파일: eval_gto.py 프로젝트: chrinide/pyscf
# 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.
#
# Author: Qiming Sun <*****@*****.**>
#

import warnings
import ctypes
import numpy
from pyscf import lib
from pyscf.gto.moleintor import make_loc

BLKSIZE = 128 # needs to be the same to lib/gto/grid_ao_drv.c

libcgto = lib.load_library('libcgto')

def eval_gto(mol, eval_name, coords,
             comp=None, shls_slice=None, non0tab=None, ao_loc=None, out=None):
    r'''Evaluate AO function value on the given grids,

    Args:
        eval_name : str

            ==================  ======  =======================
            Function            comp    Expression
            ==================  ======  =======================
            "GTOval_sph"        1       |AO>
            "GTOval_ip_sph"     3       nabla |AO>
            "GTOval_ig_sph"     3       (#C(0 1) g) |AO>
            "GTOval_ipig_sph"   3       (#C(0 1) nabla g) |AO>
예제 #29
0
파일: dmrgci.py 프로젝트: zzy2014/pyscf
import sys
import struct
import time
import tempfile
from subprocess import check_call, check_output, STDOUT, CalledProcessError
import numpy
from pyscf import lib
from pyscf import tools
from pyscf.lib import logger
from pyscf import ao2mo
from pyscf import mcscf
from pyscf.dmrgscf import dmrg_sym
from pyscf import __config__

# Libraries
libunpack = lib.load_library('libicmpspt')

# Settings
try:
    from pyscf.dmrgscf import settings
except ImportError:
    settings = lambda: None
    settings.BLOCKEXE = getattr(__config__, 'dmrgscf_BLOCKEXE', None)
    settings.BLOCKEXE_COMPRESS_NEVPT = \
            getattr(__config__, 'dmrgscf_BLOCKEXE_COMPRESS_NEVPT', None)
    settings.BLOCKSCRATCHDIR = getattr(__config__, 'dmrgscf_BLOCKSCRATCHDIR',
                                       None)
    settings.BLOCKRUNTIMEDIR = getattr(__config__, 'dmrgscf_BLOCKRUNTIMEDIR',
                                       None)
    settings.MPIPREFIX = getattr(__config__, 'dmrgscf_MPIPREFIX', None)
    settings.BLOCKVERSION = getattr(__config__, 'dmrgscf_BLOCKVERSION', None)
예제 #30
0
파일: moleintor.py 프로젝트: cyniu220/pyscf
def getints4c(intor_name,
              atm,
              bas,
              env,
              shls_slice=None,
              comp=1,
              aosym='s1',
              ao_loc=None,
              cintopt=None,
              out=None):
    aosym = _stand_sym_code(aosym)

    atm = numpy.asarray(atm, dtype=numpy.int32, order='C')
    bas = numpy.asarray(bas, dtype=numpy.int32, order='C')
    env = numpy.asarray(env, dtype=numpy.double, order='C')
    c_atm = atm.ctypes.data_as(ctypes.c_void_p)
    c_bas = bas.ctypes.data_as(ctypes.c_void_p)
    c_env = env.ctypes.data_as(ctypes.c_void_p)
    natm = atm.shape[0]
    nbas = bas.shape[0]

    ao_loc = make_loc(bas, intor_name)
    if cintopt is None:
        cintopt = make_cintopt(atm, bas, env, intor_name)

    if aosym == 's8':
        #assert(intor_name in ('int2e_sph', 'int2e_cart'))
        assert (shls_slice is None)
        libcvhf = lib.load_library('libcvhf')
        nao = ao_loc[-1]
        nao_pair = nao * (nao + 1) // 2
        out = numpy.ndarray((nao_pair * (nao_pair + 1) // 2), buffer=out)
        drv = libcvhf.GTO2e_cart_or_sph
        drv(getattr(libcgto, intor_name), out.ctypes.data_as(ctypes.c_void_p),
            ao_loc.ctypes.data_as(ctypes.c_void_p), c_atm, ctypes.c_int(natm),
            c_bas, ctypes.c_int(nbas), c_env)
        return out

    else:
        if shls_slice is None:
            shls_slice = (0, nbas, 0, nbas, 0, nbas, 0, nbas)
        elif len(shls_slice) == 4:
            shls_slice = shls_slice + (0, nbas, 0, nbas)
        else:
            assert (shls_slice[1] <= nbas and shls_slice[3] <= nbas
                    and shls_slice[5] <= nbas and shls_slice[7] <= nbas)
        i0, i1, j0, j1, k0, k1, l0, l1 = shls_slice
        naoi = ao_loc[i1] - ao_loc[i0]
        naoj = ao_loc[j1] - ao_loc[j0]
        naok = ao_loc[k1] - ao_loc[k0]
        naol = ao_loc[l1] - ao_loc[l0]
        if aosym in ('s4', 's2ij'):
            nij = naoi * (naoi + 1) // 2
            assert (numpy.all(ao_loc[i0:i1] - ao_loc[i0] == ao_loc[j0:j1] -
                              ao_loc[j0]))
        else:
            nij = naoi * naoj
        if aosym in ('s4', 's2kl'):
            nkl = naok * (naok + 1) // 2
            assert (numpy.all(ao_loc[k0:k1] - ao_loc[k0] == ao_loc[l0:l1] -
                              ao_loc[l0]))
        else:
            nkl = naok * naol
        if comp == 1:
            out = numpy.ndarray((nij, nkl), buffer=out)
        else:
            out = numpy.ndarray((comp, nij, nkl), buffer=out)

        prescreen = lib.c_null_ptr()
        drv = libcgto.GTOnr2e_fill_drv
        drv(getattr(libcgto, intor_name),
            getattr(libcgto, 'GTOnr2e_fill_' + aosym), prescreen,
            out.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(comp),
            (ctypes.c_int * 8)(*shls_slice),
            ao_loc.ctypes.data_as(ctypes.c_void_p), cintopt, c_atm,
            ctypes.c_int(natm), c_bas, ctypes.c_int(nbas), c_env)
        return out
예제 #31
0
#!/usr/bin/env python

import os
import ctypes
import unittest
import numpy
from pyscf import lib
from pyscf import scf
from pyscf import gto
from pyscf import ao2mo

libcvhf2 = lib.load_library("libcvhf")

mol = gto.Mole()
mol.verbose = 0
mol.output = None  #'out_h2o'
mol.atom = [["O", (0.0, 0.0, 0.0)], [1, (0.0, -0.757, 0.587)], [1, (0.0, 0.757, 0.587)]]

mol.basis = "cc-pvdz"

mol.build()
rhf = scf.RHF(mol)
rhf.scf()


nao = mol.nao_nr()
npair = nao * (nao + 1) // 2
c_atm = numpy.array(mol._atm, dtype=numpy.int32)
c_bas = numpy.array(mol._bas, dtype=numpy.int32)
c_env = numpy.array(mol._env)
natm = ctypes.c_int(c_atm.shape[0])
예제 #32
0
from pyscf import gto, scf
from pyscf.tools import molden
from pyscf.lib import parameters as param
from pyscf.lib import logger
from pyscf.lib import linalg_helper
from pyscf.scf import _vhf
from pyscf import ao2mo

import numpy as np
import scipy
#import time

import ctypes
import _ctypes
from pyscf.lib import load_library
liblocalizer = load_library('liblocalizer')

class localizer:

    def __init__( self, mol, orbital_coeff, thetype, use_full_hessian=True ):
        r'''Initializer for the localization procedure

        Args:
            mol : A molecule which has been built
            orbital_coeff: Set of orthonormal orbitals, expressed in terms of the AO, which should be localized
            thetype: Which cost function to optimize: 'boys' or 'edmiston'
            use_full_hessian: Whether to do augmented Hessian Newton-Raphson (True) or just -gradient/diag(hessian) (False)
        '''

        assert( ( thetype == 'boys' ) or ( thetype == 'edmiston' ) )
예제 #33
0
파일: nevpt2.py 프로젝트: chrinide/pyscf
import os
import ctypes
import time
import tempfile
from functools import reduce
import numpy
import h5py
from pyscf import lib
from pyscf.lib import logger
from pyscf import fci
from pyscf.mcscf import mc_ao2mo
from pyscf import ao2mo
from pyscf.ao2mo import _ao2mo

libmc = lib.load_library('libmcscf')

NUMERICAL_ZERO = 1e-14
# Ref JCP, 117, 9138

# h1e is the CAS space effective 1e hamiltonian
# h2e is the CAS space 2e integrals in  notation # a' -> p # b' -> q # c' -> r
# d' -> s

def make_a16(h1e, h2e, dms, civec, norb, nelec, link_index=None):
    dm3 = dms['3']
    #dm4 = dms['4']
    if 'f3ca' in dms and 'f3ac' in dms:
        f3ca = dms['f3ca']
        f3ac = dms['f3ac']
    else:
예제 #34
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.
#
# Author: Oliver J. Backhouse <*****@*****.**>
#         Alejandro Santana-Bonilla <*****@*****.**>
#         George H. Booth <*****@*****.**>
#

import numpy as np
import ctypes
from pyscf import lib
from pyscf.agf2 import mpi_helper

libagf2 = lib.load_library('libagf2')


def cholesky_build(vv, vev, eps=1e-16):
    ''' Constructs the truncated auxiliaries from :attr:`vv` and :attr:`vev`.
        Performs a Cholesky decomposition via :func:`numpy.linalg.cholesky`,
        for a positive-definite or positive-semidefinite matrix. For the
        latter, the null space is removed.

        The :attr:`vv` matrix of :func:`build_se_part` can be positive-
        semidefinite when :attr:`gf_occ.naux` < :attr:`gf_occ.nphys` for
        the occupied self-energy, or :attr:`gf_vir.naux` < :attr:`gf_vir.nphys`
        for the virtual self-energy.
    '''

    nmo = vv.shape[0]
예제 #35
0
#!/usr/bin/env python
#
# Author: Qiming Sun <*****@*****.**>
#

import ctypes
import numpy
from pyscf import lib
from pyscf.lib import logger
from pyscf import ao2mo
from pyscf.fci import direct_spin1
from pyscf.fci import direct_spin1_symm
from pyscf.fci import select_ci
from pyscf.fci import addons

libfci = lib.load_library('libfci')

def reorder4irrep_minors(eri, norb, link_index, orbsym):
    if orbsym is None:
        return eri, link_index, numpy.array(norb, dtype=numpy.int32)
    orbsym = numpy.asarray(orbsym) % 10
    trilirrep = (orbsym[:,None]^orbsym)[numpy.tril_indices(norb,-1)]
    dimirrep = numpy.array(numpy.bincount(trilirrep), dtype=numpy.int32)
    order = numpy.argsort(trilirrep)
    rank = order.argsort()
    eri = lib.take_2d(eri, order, order)
    link_index_irrep = link_index.copy()
    link_index_irrep[:,:,0] = rank[link_index[:,:,0]]
    return numpy.asarray(eri, order='C'), link_index_irrep, dimirrep

def contract_2e(eri, civec_strs, norb, nelec, link_index=None, orbsym=None):
예제 #36
0
# Author: Qiming Sun <*****@*****.**>
#

import time
import ctypes
import tempfile
import numpy
import h5py
import pyscf.lib as lib
from pyscf.lib import logger
import pyscf.ao2mo
import pyscf.cc.ccsd_slow as ccsd
from pyscf.cc import ccsd_rdm
from pyscf import grad

libcc = lib.load_library('libcc')

def IX_intermediates(cc, t1, t2, l1, l2, eris=None, d1=None, d2=None):
    if eris is None:
# Note eris are in Chemist's notation
        eris = ccsd._ERIS(cc)
    if d1 is None:
        doo, dov, dvo, dvv = ccsd_rdm.gamma1_intermediates(cc, t1, t2, l1, l2)
    else:
        doo, dov, dvo, dvv = d1
    if d2 is None:
# Note gamma2 are in Chemist's notation
        d2 = ccsd_rdm.gamma2_intermediates(cc, t1, t2, l1, l2)
    dovov, dvvvv, doooo, doovv, dovvo, dvvov, dovvv, dooov = d2
    dvvov = dovvv.transpose(2,3,0,1)
    nocc, nvir = t1.shape
예제 #37
0
파일: cell.py 프로젝트: berquist/pyscf
import ctypes
import numpy as np
import scipy.linalg
import scipy.optimize
import pyscf.lib.parameters as param
from pyscf import lib
from pyscf.lib import logger
from pyscf.gto import mole
from pyscf.gto import moleintor
from pyscf.gto.mole import _symbol, _rm_digit, _std_symbol, _charge
from pyscf.gto.mole import conc_env
from pyscf.pbc.gto import basis
from pyscf.pbc.gto import pseudo
from pyscf.pbc.tools import pbc as pbctools

libpbc = lib.load_library('libpbc')

def M(**kwargs):
    r'''This is a shortcut to build up Cell object.

    Examples:

    >>> from pyscf.pbc import gto
    >>> cell = gto.M(h=numpy.eye(3)*4, atom='He 1 1 1', basis='6-31g', gs=[10]*3)
    '''
    cell = Cell()
    cell.build(**kwargs)
    return cell


def format_pseudo(pseudo_tab):
예제 #38
0
#!/usr/bin/env python

import os
import ctypes
import _ctypes
import unittest
import numpy
from pyscf import lib
from pyscf import scf
from pyscf import gto
from pyscf import ao2mo

libcvhf2 = lib.load_library('libcvhf')

mol = gto.Mole()
mol.verbose = 0
mol.output = None#'out_h2o'
mol.atom = [
    ['O' , (0. , 0.     , 0.)],
    [1   , (0. , -0.757 , 0.587)],
    [1   , (0. , 0.757  , 0.587)] ]

mol.basis = 'cc-pvdz'

mol.build()
rhf = scf.RHF(mol)
rhf.scf()


nao = mol.nao_nr()
npair = nao*(nao+1)//2
예제 #39
0
파일: addons.py 프로젝트: chrinide/pyscf
# 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.
#
# Author: Qiming Sun <*****@*****.**>
#

import ctypes
import tempfile
import numpy
import h5py
from pyscf import lib

libao2mo = lib.load_library('libao2mo')

class load(object):
    '''load 2e integrals from hdf5 file

    Usage:
        with load(erifile) as eri:
            print(eri.shape)
    '''
    def __init__(self, eri, dataname='eri_mo'):
        self.eri = eri
        self.dataname = dataname
        self.feri = None

    def __enter__(self):
        if isinstance(self.eri, str):
예제 #40
0
#
#     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.

import ctypes
import unittest
import numpy
from pyscf import lib, gto, df
from pyscf.gto.eval_gto import BLKSIZE

libcgto = lib.load_library('libdft')

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]
예제 #41
0
파일: nevpt2.py 프로젝트: y1xiaoc/pyscf
#

import ctypes
import time
import tempfile
from functools import reduce
import numpy
import h5py
from pyscf import lib
from pyscf.lib import logger
from pyscf import fci
from pyscf.mcscf import mc_ao2mo
from pyscf import ao2mo
from pyscf.ao2mo import _ao2mo

libmc = lib.load_library('libmcscf')

NUMERICAL_ZERO = 1e-14
# Ref JCP 117, 9138 (2002); DOI:10.1063/1.1515317

# h1e is the CAS space effective 1e hamiltonian
# h2e is the CAS space 2e integrals in  notation # a' -> p # b' -> q # c' -> r
# d' -> s

def make_a16(h1e, h2e, dms, civec, norb, nelec, link_index=None):
    dm3 = dms['3']
    #dm4 = dms['4']
    if 'f3ca' in dms and 'f3ac' in dms:
        f3ca = dms['f3ca']
        f3ac = dms['f3ac']
    else:
예제 #42
0
파일: test_df.py 프로젝트: chrinide/pyscf
# 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 os
import ctypes
import unittest
import numpy
from pyscf import lib
from pyscf import scf
from pyscf import gto
from pyscf import ao2mo

# FIXME

libri1 = lib.load_library('libri')

mol = gto.Mole()
mol.verbose = 0
mol.output = None#'out_h2o'
mol.atom = [
    ['O' , (0. , 0.     , 0.)],
    [1   , (0. , -0.757 , 0.587)],
    [1   , (0. , 0.757  , 0.587)] ]

mol.basis = {'H': 'cc-pvdz',
             'O': 'cc-pvdz',}
mol.build()
rhf = scf.RHF(mol)
rhf.scf()
예제 #43
0
import scipy.linalg
import scipy.optimize
import pyscf.lib.parameters as param
from pyscf import lib
from pyscf import dft
from pyscf.lib import logger
from pyscf.gto import mole
from pyscf.gto import moleintor
from pyscf.gto.mole import _symbol, _rm_digit, _std_symbol, _charge
from pyscf.gto.mole import conc_env
from pyscf.pbc.gto import basis
from pyscf.pbc.gto import pseudo
from pyscf.pbc.tools import pbc as pbctools
from pyscf.gto.basis import ALIAS as MOLE_ALIAS

libpbc = lib.load_library('libpbc')


def M(**kwargs):
    r'''This is a shortcut to build up Cell object.

    Examples:

    >>> from pyscf.pbc import gto
    >>> cell = gto.M(a=numpy.eye(3)*4, atom='He 1 1 1', basis='6-31g', gs=[10]*3)
    '''
    cell = Cell()
    cell.build(**kwargs)
    return cell

예제 #44
0
# limitations under the License.

import os
import ctypes
import unittest
from functools import reduce
import numpy
import h5py
from pyscf import lib
from pyscf import scf
from pyscf import gto
from pyscf import ao2mo
from pyscf.ao2mo import _ao2mo
from pyscf.scf import _vhf

libao2mo1 = lib.load_library('libao2mo')

mol = gto.Mole()
mol.verbose = 0
mol.output = None  #'out_h2o'
mol.atom.extend([['O', (0., 0., 0.)], [1, (0., -0.757, 0.587)],
                 [1, (0., 0.757, 0.587)]])

mol.basis = 'cc-pvdz'
mol.build()
nao = mol.nao_nr()
naopair = nao * (nao + 1) // 2
numpy.random.seed(15)
mo = numpy.random.random((nao, nao))
mo = mo.copy(order='F')
예제 #45
0
# limitations under the License.
#
# Author: Qiming Sun <*****@*****.**>
#

import ctypes
import numpy
from pyscf import lib
from pyscf import ao2mo
from pyscf.fci import direct_spin1
from pyscf.fci import direct_spin1_symm
from pyscf.fci import selected_ci
from pyscf.fci import selected_ci_symm
from pyscf.fci import selected_ci_spin0

libfci = lib.load_library('libfci')


def contract_2e(eri, civec_strs, norb, nelec, link_index=None, orbsym=None):
    ci_coeff, nelec, ci_strs = selected_ci._unpack(civec_strs, nelec)
    if link_index is None:
        link_index = selected_ci._all_linkstr_index(ci_strs, norb, nelec)
    cd_indexa, dd_indexa, cd_indexb, dd_indexb = link_index
    na, nlinka = nb, nlinkb = cd_indexa.shape[:2]

    eri = ao2mo.restore(1, eri, norb)
    eri1 = eri.transpose(0, 2, 1, 3) - eri.transpose(0, 2, 3, 1)
    idx, idy = numpy.tril_indices(norb, -1)
    idx = idx * norb + idy
    eri1 = lib.take_2d(eri1.reshape(norb**2, -1), idx, idx) * 2
    lib.transpose_sum(eri1, inplace=True)
예제 #46
0
파일: test_ao2mo.py 프로젝트: raybrad/pyscf
#!/usr/bin/env python

import os
import ctypes
import _ctypes
import unittest
from functools import reduce
import numpy
import h5py
from pyscf import lib
from pyscf import scf
from pyscf import gto
from pyscf import ao2mo
import pyscf.scf._vhf as _vhf

libcvhf = lib.load_library("libcvhf")
libao2mo1 = lib.load_library("libao2mo")

mol = gto.Mole()
mol.verbose = 0
mol.output = None  #'out_h2o'
mol.atom.extend([["O", (0.0, 0.0, 0.0)], [1, (0.0, -0.757, 0.587)], [1, (0.0, 0.757, 0.587)]])

mol.basis = "cc-pvdz"
mol.build()
nao = mol.nao_nr()
naopair = nao * (nao + 1) // 2
numpy.random.seed(15)
mo = numpy.random.random((nao, nao))
mo = mo.copy(order="F")