Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
nd = (l + 1) * (l + 2) // 2
else:
nd = l * 2 + 1
p0, p1 = p1, p1 + nd * nc
if l <= 4:
idx.append(range(p0, p1))
idx = numpy.hstack(idx)
return pmol, mo_coeff[idx]
if __name__ == '__main__':
from pyscf import scf
import tempfile
mol = gto.Mole()
mol.verbose = 5
mol.output = None#'out_gho'
mol.atom = [['C', (0.,0.,0.)],
['H', ( 1, 1, 1)],
['H', (-1,-1, 1)],
['H', ( 1,-1,-1)],
['H', (-1, 1,-1)], ]
mol.basis = {
'C': 'sto-3g',
'H': 'sto-3g'}
mol.build(dump_input=False)
m = scf.RHF(mol)
m.scf()
header(mol, mol.stdout)
print(order_ao_index(mol))
orbital_coeff(mol, mol.stdout, m.mo_coeff)
# Author: Qiming Sun
#
r'''
Applying creation or annihilation operators on FCI wavefunction
a |0>
Compute density matrices by
gamma_{ij} = <0| i^+ j |0>
Gamma_{ij,kl} = <0| i^+ j^+ l k |0>
'''
import numpy
from pyscf import gto, scf, fci
mol = gto.M(atom='H 0 0 0; Li 0 0 1.1', basis='sto3g')
m = scf.RHF(mol).run()
fs = fci.FCI(mol, m.mo_coeff)
e, c = fs.kernel()
norb = m.mo_energy.size
neleca = nelecb = mol.nelectron // 2
#
# Spin-free 1-particle density matrix
#
#
dm1 = numpy.zeros((norb,norb))
for i in range(norb):
for j in range(norb):
tmp = fci.addons.des_a(c , norb, (neleca ,nelecb), j)
tmp = fci.addons.cre_a(tmp, norb, (neleca-1,nelecb), i)
def _make_fakemol(coords):
nbas = coords.shape[0]
fakeatm = numpy.zeros((nbas,gto.ATM_SLOTS), dtype=numpy.int32)
fakebas = numpy.zeros((nbas,gto.BAS_SLOTS), dtype=numpy.int32)
fakeenv = [0] * gto.PTR_ENV_START
ptr = gto.PTR_ENV_START
fakeatm[:,gto.PTR_COORD] = numpy.arange(ptr, ptr+nbas*3, 3)
fakeenv.append(coords.ravel())
ptr += nbas*3
fakebas[:,gto.ATOM_OF] = numpy.arange(nbas)
fakebas[:,gto.NPRIM_OF] = 1
fakebas[:,gto.NCTR_OF] = 1
# approximate point charge with gaussian distribution exp(-1e9*r^2)
fakebas[:,gto.PTR_EXP] = ptr
fakebas[:,gto.PTR_COEFF] = ptr+1
expnt = 1e9
fakeenv.append([expnt, 1/(2*numpy.sqrt(numpy.pi)*gto.mole._gaussian_int(2,expnt))])
ptr += 2
fakemol = gto.Mole()
#!/usr/bin/env python
#
# 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 symm
from pyscf.tools import fcidump
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
#
fcidump.from_scf(myhf, 'fcidump.example1')
#
H -0.00000000 -0.84695236 0.59109389
H -0.00000000 0.89830571 0.52404783 '''
mol.basis = '3-21g' #cc-pvdz'
mol.build()
cm = DDCOSMO(mol)
cm.verbose = 4
mf = ddcosmo_for_scf(scf.RHF(mol), cm)#.newton()
mf.verbose = 4
print(mf.kernel() - -75.570364368059)
cm.verbose = 3
e = ddcosmo_for_casci(mcscf.CASCI(mf, 4, 4)).kernel()[0]
print(e - -75.5743583693215)
cc_cosmo = ddcosmo_for_post_scf(cc.CCSD(mf)).run()
print(cc_cosmo.e_tot - -75.70961637250134)
mol = gto.Mole()
mol.atom = ''' Fe 0.00000000 0.00000000 -0.11081188
H -0.00000000 -0.84695236 0.59109389
H -0.00000000 0.89830571 0.52404783 '''
mol.basis = '3-21g' #cc-pvdz'
mol.build()
cm = DDCOSMO(mol)
cm.eps = -1
cm.verbose = 4
mf = ddcosmo_for_scf(scf.ROHF(mol), cm).newton()
mf.verbose=4
mf.kernel()
print(hpol)
def apply_E(E):
mf.get_hcore = lambda *args, **kwargs: h1 + numpy.einsum('x,xij->ij', E, ao_dip)
mf.run(conv_tol=1e-14)
return Polarizability(mf).polarizability()
e1 = apply_E([ 0.0001, 0, 0])
e2 = apply_E([-0.0001, 0, 0])
print((e1 - e2) / 0.0002)
e1 = apply_E([0, 0.0001, 0])
e2 = apply_E([0,-0.0001, 0])
print((e1 - e2) / 0.0002)
e1 = apply_E([0, 0, 0.0001])
e2 = apply_E([0, 0,-0.0001])
print((e1 - e2) / 0.0002)
mol = gto.M(atom='''O 0. 0. 0.
H 0. -0.757 0.587
H 0. 0.757 0.587''',
basis='6-31g')
mf = scf.RHF(mol).run(conv_tol=1e-14)
print(Polarizability(mf).polarizability())
print(Polarizability(mf).polarizability_with_freq(freq= 0.))
print(Polarizability(mf).polarizability_with_freq(freq= 0.1))
print(Polarizability(mf).polarizability_with_freq(freq=-0.1))
if __name__ == '__main__':
from pyscf import gto
from pyscf import scf
mol = gto.Mole()
mol.verbose = 0
mol.output = None
mol.atom = [['He', (0.,0.,0.)], ]
mol.basis = {'He': 'ccpvdz'}
mol.build()
method = scf.RHF(mol)
method.scf()
g = Gradients(method)
print(g.grad())
h2o = gto.Mole()
h2o.verbose = 0
h2o.output = None#'out_h2o'
h2o.atom = [
['O' , (0. , 0. , 0.)],
[1 , (0. , -0.757 , 0.587)],
[1 , (0. , 0.757 , 0.587)] ]
h2o.basis = {'H': '631g',
'O': '631g',}
h2o.build()
rhf = scf.RHF(h2o)
rhf.conv_tol = 1e-14
rhf.scf()
g = Gradients(rhf)
print(g.grad())
#[[ 0 0 -2.41134256e-02]
def minao_basis(symb, nelec_ecp):
occ = []
basis_ano = []
if gto.is_ghost_atom(symb):
return occ, basis_ano
stdsymb = gto.mole._std_symbol(symb)
basis_add = gto.basis.load('ano', stdsymb)
# coreshl defines the core shells to be removed in the initial guess
coreshl = gto.ecp.core_configuration(nelec_ecp)
#coreshl = (0,0,0,0) # it keeps all core electrons in the initial guess
for l in range(4):
ndocc, frac = atom_hf.frac_occ(stdsymb, l)
assert ndocc >= coreshl[l]
degen = l * 2 + 1
occ_l = [2,]*(ndocc-coreshl[l]) + [frac,]
occ.append(numpy.repeat(occ_l, degen))
basis_ano.append([l] + [b[:1] + b[1+coreshl[l]:ndocc+2]
for b in basis_add[l][1:]])
occ = numpy.hstack(occ)
def randomString(stringLength=10):
"""Generate a random string of fixed length """
letters = string.ascii_lowercase
return "".join(random.choice(letters) for i in range(stringLength))
config.run_dir = "parsldir" + randomString(4)
##########################
# The calculation
##########################
mol = gto.M(
atom="O 0 0 0; H 0 -2.757 2.587; H 0 2.757 2.587", basis="bfd_vtz", ecp="bfd"
)
mf = scf.RHF(mol).run()
# clean_pyscf_objects gets rid of the TextIO objects that can't
# be sent using parsl.
mol, mf = clean_pyscf_objects(mol, mf)
# It's better to load parsl after pyscf has run. Some of the
# executors have timeouts and will kill the job while pyscf is running!
parsl.load(config)
# We make a Slater-Jastrow wave function and
# only optimize the Jastrow coefficients.
wf = pyqmc.slater_jastrow(mol, mf)
acc = pyqmc.gradient_generator(mol, wf, ["wf2acoeff", "wf2bcoeff"])