Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ovlpso[numpy.diag_indices(csym.shape[1])] += 1e-12
norm[i] = numpy.einsum('ik,ki->i', moso, lib.cho_solve(ovlpso, moso.T))
norm /= numpy.sum(norm, axis=0) # for orbitals which are not normalized
iridx = numpy.argmax(norm, axis=0)
orbsym = numpy.asarray([irrep_name[i] for i in iridx])
logger.debug(mol, 'irreps of each MO %s', orbsym)
if check:
largest_norm = norm[iridx,numpy.arange(nmo)]
orbidx = numpy.where(largest_norm < 1-tol)[0]
if orbidx.size > 0:
idx = numpy.where(largest_norm < 1-tol*1e2)[0]
if idx.size > 0:
raise ValueError('orbitals %s not symmetrized, norm = %s' %
(idx, largest_norm[idx]))
else:
logger.warn(mol, 'orbitals %s not strictly symmetrized.',
numpy.unique(orbidx))
logger.warn(mol, 'They can be symmetrized with '
'pyscf.symm.symmetrize_space function.')
logger.debug(mol, 'norm = %s', largest_norm[orbidx])
return orbsym
def get_k_kpts(mydf, dm_kpts, hermi=1, kpts=numpy.zeros((1,3)), kpts_band=None,
exxdiv=None):
if exxdiv is not None and exxdiv != 'ewald':
logger.warn(mydf, 'MDF does not support exxdiv %s. '
'exxdiv needs to be "ewald" or None', exxdiv)
raise RuntimeError('GDF does not support exxdiv %s' % exxdiv)
vk_kpts = aft_jk.get_k_kpts(mydf, dm_kpts, hermi, kpts, kpts_band, exxdiv)
vk_kpts += df_jk.get_k_kpts(mydf, dm_kpts, hermi, kpts, kpts_band, None)
return vk_kpts
def get_jk(self, dm, hermi=1, kpts=None, kpts_band=None,
with_j=True, with_k=True, exxdiv='ewald', **kwargs):
from pyscf.pbc.df import fft_jk
if with_k:
logger.warn(self, 'MultiGridFFTDF does not support HFX. '
'HFX is computed by FFTDF.get_k_kpts function.')
if kpts is None:
if numpy.all(self.kpts == 0): # Gamma-point J/K by default
kpts = numpy.zeros(3)
else:
kpts = self.kpts
else:
kpts = numpy.asarray(kpts)
vj = vk = None
if kpts.shape == (3,):
if with_k:
vk = fft_jk.get_jk(self, dm, hermi, kpts, kpts_band,
False, True, exxdiv)[1]
vj = get_j_kpts(self, dm, hermi, kpts.reshape(1,3), kpts_band)
def check_sanity(self):
mol_hf.SCF.check_sanity(self)
self.with_df.check_sanity()
if (isinstance(self.exxdiv, str) and self.exxdiv.lower() != 'ewald' and
isinstance(self.with_df, df.df.DF)):
logger.warn(self, 'exxdiv %s is not supported in DF or MDF',
self.exxdiv)
return self
def dump_input(self):
import __main__
if hasattr(__main__, '__file__'):
try:
filename = os.path.abspath(__main__.__file__)
finput = open(filename, 'r')
self.stdout.write('#INFO: **** input file is %s ****\n' % filename)
self.stdout.write(finput.read())
self.stdout.write('#INFO: ******************** input file end ********************\n')
self.stdout.write('\n')
self.stdout.write('\n')
finput.close()
except IOError:
logger.warn(self, 'input file does not exist')
self.stdout.write('System: %s Threads %s\n' %
(str(platform.uname()), lib.num_threads()))
self.stdout.write('Python %s\n' % sys.version)
self.stdout.write('numpy %s scipy %s\n' %
(numpy.__version__, scipy.__version__))
self.stdout.write('Date: %s\n' % time.ctime())
import pyscf
pyscfdir = os.path.abspath(os.path.join(__file__, '..', '..'))
self.stdout.write('PySCF version %s\n' % pyscf.__version__)
self.stdout.write('PySCF path %s\n' % pyscfdir)
try:
with open(os.path.join(pyscfdir, '..', '.git', 'ORIG_HEAD'), 'r') as f:
self.stdout.write('GIT ORIG_HEAD %s' % f.read())
except IOError:
pass
def run_mfs(mf, cells_a, cells_b):
'''perform a set of calculations on given two sets of cellcules'''
nconfigs = len(cells_a)
dm0 = mf.make_rdm1()
mflist = []
for i in range(nconfigs):
mf1 = copy_mf(mf, cells_a[i])
mf2 = copy_mf(mf, cells_b[i])
mf1.kernel(dm0=dm0)
mf2.kernel(dm0=dm0)
if not (mf1.converged):
logger.warn(mf, "%ith config mf1 not converged", i)
if not (mf2.converged):
logger.warn(mf, "%ith config mf2 not converged", i)
mflist.append((mf1, mf2))
return mflist
if getattr(mo[0], 'ndim', None) == 1: # RHF/GHF/DHF
if nao*2 == mo.shape[0]: # GHF or DHF
if project:
raise NotImplementedError('Project initial guess from '
'different geometry')
else:
dm = hf.make_rdm1(mo, mo_occ)
else: # RHF
mo_coeff = fproj(mo)
mo_occa = (mo_occ>1e-8).astype(numpy.double)
mo_occb = mo_occ - mo_occa
dma, dmb = uhf.make_rdm1([mo_coeff]*2, (mo_occa, mo_occb))
dm = scipy.linalg.block_diag(dma, dmb)
else: #UHF
if getattr(mo[0][0], 'ndim', None) == 2: # KUHF
logger.warn(mol, 'k-point UHF results are found. Density matrix '
'at Gamma point is used for the molecular SCF initial guess')
mo = mo[0]
dma, dmb = uhf.make_rdm1([fproj(mo[0]),fproj(mo[1])], mo_occ)
dm = scipy.linalg.block_diag(dma, dmb)
return dm
def set_occ(mo_energy, mo_coeff=None):
mol = mf.mol
mo_occ = numpy.zeros_like(mo_energy)
nocc = mol.nelectron / 2
mo_occ[:nocc] = 2
if abs(mo_energy[nocc-1] - mo_energy[nocc]) < tol:
lst = abs(mo_energy - mo_energy[nocc-1]) < tol
nsocc = int(lst.sum())
ndocc = nocc - int(lst[:nocc].sum())
frac = 2.*(nocc-ndocc)/nsocc
mo_occ[nsocc:ndocc] = frac
log.warn(mf, 'fraction occ = %6g, [%d:%d]', frac, ndocc, ndocc+nsocc)
if nocc < mo_occ.size:
log.info(mf, 'HOMO = %.12g, LUMO = %.12g,', \
mo_energy[nocc-1], mo_energy[nocc])
else:
log.info(mf, 'HOMO = %.12g,', mo_energy[nocc-1])
log.debug(mf, ' mo_energy = %s', mo_energy)
return mo_occ
return set_occ
self.verbose = scf_method.mol.verbose
self.stdout = scf_method.mol.stdout
self.chkfile = scf_method.chkfile
self._scf = scf_method
self.cphf = True
self.max_cycle_cphf = 20
self.conv_tol = 1e-9
self.sso = False # Two-electron spin-same-orbit coupling
self.soo = False # Two-electron spin-other-orbit coupling
self.so_eff_charge = True
self.mo10 = None
self.mo_e10 = None
self._keys = set(self.__dict__.keys())
logger.warn(self, 'UHF-ZFS is an experimental feature. It is still in '
'testing\nFeatures and APIs may be changed in the future.')
orbvb = mob[:,noccb:]
if (mp.mol.incore_anyway or
(mp._scf._eri is not None and mem_incore+mem_now < mp.max_memory)):
log.debug('transform (ia|jb) incore')
if callable(ao2mofn):
eris.ovov = ao2mofn((orboa,orbva,orboa,orbva)).reshape(nocca*nvira,nocca*nvira)
eris.ovOV = ao2mofn((orboa,orbva,orbob,orbvb)).reshape(nocca*nvira,noccb*nvirb)
eris.OVOV = ao2mofn((orbob,orbvb,orbob,orbvb)).reshape(noccb*nvirb,noccb*nvirb)
else:
eris.ovov = ao2mo.general(mp._scf._eri, (orboa,orbva,orboa,orbva))
eris.ovOV = ao2mo.general(mp._scf._eri, (orboa,orbva,orbob,orbvb))
eris.OVOV = ao2mo.general(mp._scf._eri, (orbob,orbvb,orbob,orbvb))
elif getattr(mp._scf, 'with_df', None):
logger.warn(mp, 'UMP2 detected DF being used in the HF object. '
'MO integrals are computed based on the DF 3-index tensors.\n'
'It\'s recommended to use DF-UMP2 module.')
log.debug('transform (ia|jb) with_df')
eris.ovov = mp._scf.with_df.ao2mo((orboa,orbva,orboa,orbva))
eris.ovOV = mp._scf.with_df.ao2mo((orboa,orbva,orbob,orbvb))
eris.OVOV = mp._scf.with_df.ao2mo((orbob,orbvb,orbob,orbvb))
else:
log.debug('transform (ia|jb) outcore')
eris.feri = lib.H5TmpFile()
_ao2mo_ovov(mp, (orboa,orbva,orbob,orbvb), eris.feri,
max(2000, max_memory), log)
eris.ovov = eris.feri['ovov']
eris.ovOV = eris.feri['ovOV']
eris.OVOV = eris.feri['OVOV']