本文整理汇总了Python中pyscf.lib.logger.new_logger函数的典型用法代码示例。如果您正苦于以下问题:Python new_logger函数的具体用法?Python new_logger怎么用?Python new_logger使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了new_logger函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: uhf_internal
def uhf_internal(mf, with_symmetry=True, verbose=None):
log = logger.new_logger(mf, verbose)
g, hop, hdiag = newton_ah.gen_g_hop_uhf(mf, mf.mo_coeff, mf.mo_occ,
with_symmetry=with_symmetry)
hdiag *= 2
def precond(dx, e, x0):
hdiagd = hdiag - e
hdiagd[abs(hdiagd)<1e-8] = 1e-8
return dx/hdiagd
def hessian_x(x): # See comments in function rhf_internal
return hop(x).real * 2
x0 = numpy.zeros_like(g)
x0[g!=0] = 1. / hdiag[g!=0]
if not with_symmetry: # allow to break point group symmetry
x0[numpy.argmin(hdiag)] = 1
e, v = lib.davidson(hessian_x, x0, precond, tol=1e-4, verbose=log)
if e < -1e-5:
log.note('UHF/UKS wavefunction has an internal instablity.')
nocca = numpy.count_nonzero(mf.mo_occ[0]> 0)
nvira = numpy.count_nonzero(mf.mo_occ[0]==0)
mo = (_rotate_mo(mf.mo_coeff[0], mf.mo_occ[0], v[:nocca*nvira]),
_rotate_mo(mf.mo_coeff[1], mf.mo_occ[1], v[nocca*nvira:]))
else:
log.note('UHF/UKS wavefunction is stable in the intenral stability analysis')
mo = mf.mo_coeff
return mo
示例2: casci
def casci(self, mo_coeff, ci0=None, eris=None, verbose=None, envs=None):
if eris is None:
fcasci = copy.copy(self)
fcasci.ao2mo = self.get_h2cas
else:
fcasci = _fake_h_for_fast_casci(self, mo_coeff, eris)
log = logger.new_logger(self, verbose)
e_tot, e_cas, fcivec = ucasci.kernel(fcasci, mo_coeff, ci0, log)
if envs is not None and log.verbose >= logger.INFO:
log.debug('CAS space CI energy = %.15g', e_cas)
if 'imicro' in envs: # Within CASSCF iteration
log.info('macro iter %d (%d JK %d micro), '
'UCASSCF E = %.15g dE = %.8g',
envs['imacro'], envs['njk'], envs['imicro'],
e_tot, e_tot-envs['elast'])
if 'norm_gci' in envs:
log.info(' |grad[o]|=%5.3g '
'|grad[c]|= %s |ddm|=%5.3g',
envs['norm_gorb0'],
envs['norm_gci'], envs['norm_ddm'])
else:
log.info(' |grad[o]|=%5.3g |ddm|=%5.3g',
envs['norm_gorb0'], envs['norm_ddm'])
else: # Initialization step
log.info('UCASCI E = %.15g', e_tot)
return e_tot, e_cas, fcivec
示例3: rhf_external
def rhf_external(mf, with_symmetry=True, verbose=None):
log = logger.new_logger(mf, verbose)
hop1, hdiag1, hop2, hdiag2 = _gen_hop_rhf_external(mf, with_symmetry)
def precond(dx, e, x0):
hdiagd = hdiag1 - e
hdiagd[abs(hdiagd)<1e-8] = 1e-8
return dx/hdiagd
x0 = numpy.zeros_like(hdiag1)
x0[hdiag1>1e-5] = 1. / hdiag1[hdiag1>1e-5]
if not with_symmetry: # allow to break point group symmetry
x0[numpy.argmin(hdiag1)] = 1
e1, v1 = lib.davidson(hop1, x0, precond, tol=1e-4, verbose=log)
if e1 < -1e-5:
log.note('RHF/RKS wavefunction has a real -> complex instablity')
else:
log.note('RHF/RKS wavefunction is stable in the real -> complex stability analysis')
def precond(dx, e, x0):
hdiagd = hdiag2 - e
hdiagd[abs(hdiagd)<1e-8] = 1e-8
return dx/hdiagd
x0 = v1
e3, v3 = lib.davidson(hop2, x0, precond, tol=1e-4, verbose=log)
if e3 < -1e-5:
log.note('RHF/RKS wavefunction has a RHF/RKS -> UHF/UKS instablity.')
mo = (_rotate_mo(mf.mo_coeff, mf.mo_occ, v3), mf.mo_coeff)
else:
log.note('RHF/RKS wavefunction is stable in the RHF/RKS -> UHF/UKS stability analysis')
mo = (mf.mo_coeff, mf.mo_coeff)
return mo
示例4: mulliken_pop
def mulliken_pop(mol, dm, s=None, verbose=logger.DEBUG):
r'''Mulliken population analysis
.. math:: M_{ij} = D_{ij} S_{ji}
Mulliken charges
.. math:: \delta_i = \sum_j M_{ij}
'''
if s is None: s = get_ovlp(mol)
log = logger.new_logger(mol, verbose)
pop = numpy.einsum('ij,ji->i', dm, s).real
log.info(' ** Mulliken pop **')
for i, s in enumerate(mol.spinor_labels()):
log.info('pop of %s %10.5f', s, pop[i])
log.note(' ** Mulliken atomic charges **')
chg = numpy.zeros(mol.natm)
for i, s in enumerate(mol.spinor_labels(fmt=None)):
chg[s[0]] += pop[i]
chg = mol.atom_charges() - chg
for ia in range(mol.natm):
symb = mol.atom_symbol(ia)
log.note('charge of %d%s = %10.5f', ia, symb, chg[ia])
return pop, chg
示例5: rhf_internal
def rhf_internal(mf, verbose=None):
log = logger.new_logger(mf, verbose)
g, hop, hdiag = newton_ah.gen_g_hop_rhf(mf, mf.mo_coeff, mf.mo_occ)
def precond(dx, e, x0):
hdiagd = hdiag*2 - e
hdiagd[abs(hdiagd)<1e-8] = 1e-8
return dx/hdiagd
# The results of hop(x) corresponds to a displacement that reduces
# gradients g. It is the vir-occ block of the matrix vector product
# (Hessian*x). The occ-vir block equals to x2.T.conj(). The overall
# Hessian for internal reotation is x2 + x2.T.conj(). This is
# the reason we apply (.real * 2) below
def hessian_x(x):
return hop(x).real * 2
x0 = numpy.zeros_like(g)
x0[g!=0] = 1. / hdiag[g!=0]
e, v = lib.davidson(hessian_x, x0, precond, tol=1e-4, verbose=log)
if e < -1e-5:
log.log('KRHF/KRKS wavefunction has an internal instablity')
mo = _rotate_mo(mf.mo_coeff, mf.mo_occ, v)
else:
log.log('KRHF/KRKS wavefunction is stable in the intenral stability analysis')
mo = mf.mo_coeff
return mo
示例6: gen_hop
def gen_hop(hobj, mo_energy=None, mo_coeff=None, mo_occ=None, verbose=None):
log = logger.new_logger(hobj, verbose)
mol = hobj.mol
mf = hobj.base
if mo_energy is None: mo_energy = mf.mo_energy
if mo_occ is None: mo_occ = mf.mo_occ
if mo_coeff is None: mo_coeff = mf.mo_coeff
natm = mol.natm
nao, nmo = mo_coeff.shape
mocc = mo_coeff[:,mo_occ>0]
nocc = mocc.shape[1]
atmlst = range(natm)
max_memory = max(2000, hobj.max_memory - lib.current_memory()[0])
de2 = hobj.partial_hess_elec(mo_energy, mo_coeff, mo_occ, atmlst,
max_memory, log)
de2 += hobj.hess_nuc()
# Compute H1 integrals and store in hobj.chkfile
hobj.make_h1(mo_coeff, mo_occ, hobj.chkfile, atmlst, log)
aoslices = mol.aoslice_by_atom()
s1a = -mol.intor('int1e_ipovlp', comp=3)
fvind = gen_vind(mf, mo_coeff, mo_occ)
def h_op(x):
x = x.reshape(natm,3)
hx = numpy.einsum('abxy,ax->by', de2, x)
h1ao = 0
s1ao = 0
for ia in range(natm):
shl0, shl1, p0, p1 = aoslices[ia]
h1ao_i = lib.chkfile.load(hobj.chkfile, 'scf_f1ao/%d' % ia)
h1ao += numpy.einsum('x,xij->ij', x[ia], h1ao_i)
s1ao_i = numpy.zeros((3,nao,nao))
s1ao_i[:,p0:p1] += s1a[:,p0:p1]
s1ao_i[:,:,p0:p1] += s1a[:,p0:p1].transpose(0,2,1)
s1ao += numpy.einsum('x,xij->ij', x[ia], s1ao_i)
s1vo = reduce(numpy.dot, (mo_coeff.T, s1ao, mocc))
h1vo = reduce(numpy.dot, (mo_coeff.T, h1ao, mocc))
mo1, mo_e1 = cphf.solve(fvind, mo_energy, mo_occ, h1vo, s1vo)
mo1 = numpy.dot(mo_coeff, mo1)
mo_e1 = mo_e1.reshape(nocc,nocc)
dm1 = numpy.einsum('pi,qi->pq', mo1, mocc)
dme1 = numpy.einsum('pi,qi,i->pq', mo1, mocc, mo_energy[mo_occ>0])
dme1 = dme1 + dme1.T + reduce(numpy.dot, (mocc, mo_e1.T, mocc.T))
for ja in range(natm):
q0, q1 = aoslices[ja][2:]
h1ao = lib.chkfile.load(hobj.chkfile, 'scf_f1ao/%s'%ja)
hx[ja] += numpy.einsum('xpq,pq->x', h1ao, dm1) * 4
hx[ja] -= numpy.einsum('xpq,pq->x', s1a[:,q0:q1], dme1[q0:q1]) * 2
hx[ja] -= numpy.einsum('xpq,qp->x', s1a[:,q0:q1], dme1[:,q0:q1]) * 2
return hx.ravel()
hdiag = numpy.einsum('aaxx->ax', de2).ravel()
return h_op, hdiag
示例7: ghf_stability
def ghf_stability(mf, verbose=None):
log = logger.new_logger(mf, verbose)
with_symmetry = True
g, hop, hdiag = newton_ah.gen_g_hop_ghf(mf, mf.mo_coeff, mf.mo_occ,
with_symmetry=with_symmetry)
hdiag *= 2
def precond(dx, e, x0):
hdiagd = hdiag - e
hdiagd[abs(hdiagd)<1e-8] = 1e-8
return dx/hdiagd
def hessian_x(x): # See comments in function rhf_internal
return hop(x).real * 2
x0 = numpy.zeros_like(g)
x0[g!=0] = 1. / hdiag[g!=0]
if not with_symmetry: # allow to break point group symmetry
x0[numpy.argmin(hdiag)] = 1
e, v = lib.davidson(hessian_x, x0, precond, tol=1e-4, verbose=log)
if e < -1e-5:
log.note('GHF wavefunction has an internal instablity')
mo = _rotate_mo(mf.mo_coeff, mf.mo_occ, v)
else:
log.note('GHF wavefunction is stable in the intenral stability analysis')
mo = mf.mo_coeff
return mo
示例8: mulliken_pop
def mulliken_pop(mol, dm, s=None, verbose=logger.DEBUG):
'''Mulliken population analysis
'''
if s is None: s = hf.get_ovlp(mol)
log = logger.new_logger(mol, verbose)
if isinstance(dm, numpy.ndarray) and dm.ndim == 2:
dm = numpy.array((dm*.5, dm*.5))
pop_a = numpy.einsum('ij,ji->i', dm[0], s).real
pop_b = numpy.einsum('ij,ji->i', dm[1], s).real
log.info(' ** Mulliken pop alpha | beta **')
for i, s in enumerate(mol.ao_labels()):
log.info('pop of %s %10.5f | %-10.5f',
s, pop_a[i], pop_b[i])
log.info('In total %10.5f | %-10.5f', sum(pop_a), sum(pop_b))
log.note(' ** Mulliken atomic charges ( Nelec_alpha | Nelec_beta ) **')
nelec_a = numpy.zeros(mol.natm)
nelec_b = numpy.zeros(mol.natm)
for i, s in enumerate(mol.ao_labels(fmt=None)):
nelec_a[s[0]] += pop_a[i]
nelec_b[s[0]] += pop_b[i]
chg = mol.atom_charges() - (nelec_a + nelec_b)
for ia in range(mol.natm):
symb = mol.atom_symbol(ia)
log.note('charge of %d%s = %10.5f ( %10.5f %10.5f )',
ia, symb, chg[ia], nelec_a[ia], nelec_b[ia])
return (pop_a,pop_b), chg
示例9: rhf_internal
def rhf_internal(mf, verbose=None):
log = logger.new_logger(mf, verbose)
mol = mf.mol
mo_coeff = mf.mo_coeff
mo_energy = mf.mo_energy
mo_occ = mf.mo_occ
nmo = mo_coeff.shape[1]
nocc = numpy.count_nonzero(mo_occ)
nvir = nmo - nocc
eri_mo = ao2mo.full(mol, mo_coeff)
eri_mo = ao2mo.restore(1, eri_mo, nmo)
eai = lib.direct_sum('a-i->ai', mo_energy[nocc:], mo_energy[:nocc])
# A
h = numpy.einsum('ckld->kcld', eri_mo[nocc:,:nocc,:nocc,nocc:]) * 2
h-= numpy.einsum('cdlk->kcld', eri_mo[nocc:,nocc:,:nocc,:nocc])
for a in range(nvir):
for i in range(nocc):
h[i,a,i,a] += eai[a,i]
# B
h+= numpy.einsum('ckdl->kcld', eri_mo[nocc:,:nocc,nocc:,:nocc]) * 2
h-= numpy.einsum('cldk->kcld', eri_mo[nocc:,:nocc,nocc:,:nocc])
nov = nocc * nvir
e = scipy.linalg.eigh(h.reshape(nov,nov))[0]
log.debug('rhf_internal: lowest eigs = %s', e[e<=max(e[0],1e-5)])
if e[0] < -1e-5:
log.log('RHF wavefunction has an internal instablity')
else:
log.log('RHF wavefunction is stable in the intenral stablity analysis')
示例10: get_jk
def get_jk(self, mol=None, dm=None, hermi=1):
if mol is None: mol = self.mol
if dm is None: dm = self.make_rdm1()
t0 = (time.clock(), time.time())
log = logger.new_logger(self)
if self.direct_scf and self.opt[0] is None:
self.opt = self.init_direct_scf(mol)
opt_llll, opt_ssll, opt_ssss, opt_gaunt = self.opt
vj, vk = get_jk_coulomb(mol, dm, hermi, self._coulomb_now,
opt_llll, opt_ssll, opt_ssss, log)
if self.with_breit:
if 'SSSS' in self._coulomb_now.upper():
vj1, vk1 = _call_veff_gaunt_breit(mol, dm, hermi, opt_gaunt, True)
log.debug('Add Breit term')
vj += vj1
vk += vk1
elif self.with_gaunt and 'SS' in self._coulomb_now.upper():
log.debug('Add Gaunt term')
vj1, vk1 = _call_veff_gaunt_breit(mol, dm, hermi, opt_gaunt, False)
vj += vj1
vk += vk1
log.timer('vj and vk', *t0)
return vj, vk
示例11: get_jk_coulomb
def get_jk_coulomb(mol, dm, hermi=1, coulomb_allow='SSSS',
opt_llll=None, opt_ssll=None, opt_ssss=None, verbose=None):
log = logger.new_logger(mol, verbose)
if coulomb_allow.upper() == 'LLLL':
log.debug('Coulomb integral: (LL|LL)')
j1, k1 = _call_veff_llll(mol, dm, hermi, opt_llll)
n2c = j1.shape[1]
vj = numpy.zeros_like(dm)
vk = numpy.zeros_like(dm)
vj[...,:n2c,:n2c] = j1
vk[...,:n2c,:n2c] = k1
elif coulomb_allow.upper() == 'SSLL' \
or coulomb_allow.upper() == 'LLSS':
log.debug('Coulomb integral: (LL|LL) + (SS|LL)')
vj, vk = _call_veff_ssll(mol, dm, hermi, opt_ssll)
j1, k1 = _call_veff_llll(mol, dm, hermi, opt_llll)
n2c = j1.shape[1]
vj[...,:n2c,:n2c] += j1
vk[...,:n2c,:n2c] += k1
else: # coulomb_allow == 'SSSS'
log.debug('Coulomb integral: (LL|LL) + (SS|LL) + (SS|SS)')
vj, vk = _call_veff_ssll(mol, dm, hermi, opt_ssll)
j1, k1 = _call_veff_llll(mol, dm, hermi, opt_llll)
n2c = j1.shape[1]
vj[...,:n2c,:n2c] += j1
vk[...,:n2c,:n2c] += k1
j1, k1 = _call_veff_ssss(mol, dm, hermi, opt_ssss)
vj[...,n2c:,n2c:] += j1
vk[...,n2c:,n2c:] += k1
return vj, vk
示例12: polarizability_with_freq
def polarizability_with_freq(polobj, freq=None):
from pyscf.prop.nmr import rhf as rhf_nmr
log = logger.new_logger(polobj)
mf = polobj._scf
mol = mf.mol
mo_energy = mf.mo_energy
mo_coeff = mf.mo_coeff
mo_occ = mf.mo_occ
occidx = mo_occ > 0
orbo = mo_coeff[:, occidx]
orbv = mo_coeff[:,~occidx]
charges = mol.atom_charges()
coords = mol.atom_coords()
charge_center = numpy.einsum('i,ix->x', charges, coords) / charges.sum()
with mol.with_common_orig(charge_center):
int_r = mol.intor_symmetric('int1e_r', comp=3)
h1 = lib.einsum('xpq,pi,qj->xij', int_r, orbv.conj(), orbo)
mo1 = cphf_with_freq(mf, mo_energy, mo_occ, h1, freq,
polobj.max_cycle_cphf, polobj.conv_tol, verbose=log)[0]
e2 = numpy.einsum('xpi,ypi->xy', h1, mo1[0])
e2 += numpy.einsum('xpi,ypi->xy', h1, mo1[1])
# *-1 from the definition of dipole moment. *2 for double occupancy
e2 *= -2
log.debug('Polarizability tensor with freq %s', freq)
log.debug('%s', e2)
return e2
示例13: kernel
def kernel(self, h1, h2, norb, nelec, ci0=None, verbose=0, **kwargs):
# Note self.orbsym is initialized lazily in mc1step_symm.kernel function
log = logger.new_logger(self, verbose)
es = []
cs = []
for solver, c0 in loop_solver(fcisolvers, ci0):
e, c = solver.kernel(h1, h2, norb, get_nelec(solver, nelec), c0,
orbsym=self.orbsym, verbose=log, **kwargs)
if solver.nroots == 1:
es.append(e)
cs.append(c)
else:
es.extend(e)
cs.extend(c)
e_states[0] = es
if log.verbose >= logger.DEBUG:
if has_spin_square:
ss, multip = collect(solver.spin_square(c0, norb, get_nelec(solver, nelec))
for solver, c0 in loop_civecs(fcisolvers, cs))
for i, ei in enumerate(es):
log.debug('state %d E = %.15g S^2 = %.7f', i, ei, ss[i])
else:
for i, ei in enumerate(es):
log.debug('state %d E = %.15g', i, ei)
return numpy.einsum('i,i', numpy.array(es), weights), cs
示例14: kernel
def kernel(casci, mo_coeff=None, ci0=None, verbose=logger.NOTE):
'''CASCI solver
'''
if mo_coeff is None: mo_coeff = casci.mo_coeff
log = logger.new_logger(casci, verbose)
t0 = (time.clock(), time.time())
log.debug('Start CASCI')
ncas = casci.ncas
nelecas = casci.nelecas
# 2e
eri_cas = casci.get_h2eff(mo_coeff)
t1 = log.timer('integral transformation to CAS space', *t0)
# 1e
h1eff, energy_core = casci.get_h1eff(mo_coeff)
log.debug('core energy = %.15g', energy_core)
t1 = log.timer('effective h1e in CAS space', *t1)
if h1eff.shape[0] != ncas:
raise RuntimeError('Active space size error. nmo=%d ncore=%d ncas=%d' %
(mo_coeff.shape[1], casci.ncore, ncas))
# FCI
max_memory = max(400, casci.max_memory-lib.current_memory()[0])
e_tot, fcivec = casci.fcisolver.kernel(h1eff, eri_cas, ncas, nelecas,
ci0=ci0, verbose=log,
max_memory=max_memory,
ecore=energy_core)
t1 = log.timer('FCI solver', *t1)
e_cas = e_tot - energy_core
return e_tot, e_cas, fcivec
示例15: dump_flags
def dump_flags(self, verbose=None):
log = logger.new_logger(self, verbose)
log.info('')
log.info('******** CASCI flags ********')
ncore = self.ncore
ncas = self.ncas
nvir = self.mo_coeff.shape[1] - ncore - ncas
log.info('CAS (%de+%de, %do), ncore = %d, nvir = %d', \
self.nelecas[0], self.nelecas[1], ncas, ncore, nvir)
assert(self.ncas > 0)
log.info('natorb = %s', self.natorb)
log.info('canonicalization = %s', self.canonicalization)
log.info('sorting_mo_energy = %s', self.sorting_mo_energy)
log.info('max_memory %d (MB)', self.max_memory)
if getattr(self.fcisolver, 'dump_flags', None):
self.fcisolver.dump_flags(log.verbose)
if self.mo_coeff is None:
log.error('Orbitals for CASCI are not specified. The relevant SCF '
'object may not be initialized.')
if (getattr(self._scf, 'with_solvent', None) and
not getattr(self, 'with_solvent', None)):
log.warn('''Solvent model %s was found in SCF object.
It is not applied to the CASSCF object. The CASSCF result is not affected by the SCF solvent model.
To enable the solvent model for CASSCF, a decoration to CASSCF object as below needs be called
from pyscf import solvent
mc = mcscf.CASSCF(...)
mc = solvent.ddCOSMO(mc)
''',
self._scf.with_solvent.__class__)
return self