Example #1
0
    def handle_mole_cell(self, entry_name, ctx):
        config = self.config[entry_name]
        klass = entry_name.split('-')[0]

        if self.dry_run:
            args = ',\n    '.join(_assignment_statements(config))
            if ctx is None:
                if klass == 'Mole':
                    ctx = 'mol'
                else:
                    ctx = 'cell'
                print('%s = pyscf.M(%s)' % (ctx, args))
            else:
                print('%s.build(%s)' % (ctx, args))
            self._ctx.append(ctx)
        else:
            if ctx is None:
                if 'verbose' in config:
                    ctx = pyscf.M(**config)
                else:
                    ctx = pyscf.M(**config, verbose=2)
            else:
                ctx.build(**config)
            self._ctx.append(ctx)

        self.extract_results(entry_name, ctx)
        return ctx
Example #2
0
    def test_rmindo(self):
        mol = pyscf.M(atom=[(8, (0, 0, 0)), (1, (1., 0, 0)), (1, (0, 1., 0))])
        mf = semiempirical.RMINDO3(mol).run(conv_tol=1e-6)
        self.assertAlmostEqual(mf.e_heat_formation, -48.82621264564841, 6)

        mol = pyscf.M(atom=[(6, (0, 0,
                                 0)), (1, (1., 0,
                                           0)), (1,
                                                 (0, 1.,
                                                  0)), (1,
                                                        (0, 0,
                                                         1.)), (1, (0, 0,
                                                                    -1.))])
        mf = semiempirical.RMINDO3(mol).run(conv_tol=1e-6)
        self.assertAlmostEqual(mf.e_heat_formation, 75.76019731515225, 6)
Example #3
0
def tddft(geom, confId=None, method='B3LYP', basis='def2-svp', nstates=5):
    """
    Run TD-DFT with pyscf

    :param geom: an RDKit.Mol or a string
    :param method: method to use
    :param basis: basis to use
    :param nstates: number of excited states to compute
    :param confId: the ID of the conformer to optimize, if needed
    """
    if not isinstance(geom, str):
        assert confId
        geom = make_geometry(geom, confId)

    mol = pyscf.M(
        atom=geom,
        basis=basis,
        symmetry=True,
    )

    mf = mol.RKS()
    mf.xc = method
    mf.run()

    mytd = mf.TDDFT()
    mytd.nstates = nstates
    mytd.run()
    mytd.analyze()
Example #4
0
def get_homolumo(molstr, charge=0, verbose=0, tol=1e-6):
    """Get the H**O-1, H**O, LUMO, LUMO+1 energies in eV using MINDO3.

    See https://pyscf.org/quickstart.html for more information.

    Parameters
    ----------
    molstr : str
        Input string for pySCF containing elements and positions in Angstroms
        (e.g., "C 0.0 0.0 0.0; H 1.54 0.0 0.0")
    charge : int, default 0
        If the molecule which we are calculating the energies of has a charge,
        it can be specified.
    verbose : int, default 0
        Verbosity level of the MINDO calculation output. 0 will silence output,
        4 will show convergence.
    tol : float, default 1e-6
        Tolerance of the MINDO convergence.

    Returns
    -------
    numpy.ndarray
        Array containing H**O-1, H**O, LUMO, LUMO+1 energies in eV
    """
    mol = pyscf.M(atom=molstr, charge=charge)
    mf = MINDO3(mol).run(verbose=verbose, conv_tol=tol)
    occ = mf.get_occ()
    i_lumo = np.argmax(occ < 1)
    energies = mf.mo_energy[i_lumo - 2:i_lumo + 2]
    energies *= 27.2114  # convert Eh to eV
    return energies
Example #5
0
def v2rdm_pyscf():

    # pyscf reference
    np.set_printoptions(linewidth=500)
    basis = 'STO-3G'
    mol = pyscf.M(
        atom='B 0 0 0; H 0 0 {}'.format(1.1),
        basis=basis)

    mf = mol.RHF()
    mf.verbose = 3
    mf.run()

    # make h1 and spatial integrals in MO basis
    eri = ao2mo.kernel(mol, mf.mo_coeff)
    eri = ao2mo.restore(1, eri, mf.mo_coeff.shape[1])

    # this produces spatial MO h1 integrals
    h1 = reduce(np.dot, (mf.mo_coeff.T, mf.get_hcore(), mf.mo_coeff))

    # these parameters are hard-coded for now
    nalpha = 3
    nbeta  = 3
    nmo    = 6

    # hilbert options
    psi4.set_module_options('hilbert', {
      #'sdp_solver':      'rrsdp',
      'positivity':      'dqg',
      'r_convergence':   1e-5,
      'e_convergence':   1e-4,
      'maxiter':         20000,
    })

    # grab options object
    options = psi4.core.get_options()
    options.set_current_module('HILBERT')

    v2rdm_pyscf = hilbert.v2RDMHelper(nalpha,nbeta,nmo,h1.flatten(),eri.flatten(),options)
    current_energy = v2rdm_pyscf.compute_energy()

    return current_energy
Example #6
0
def CCSDExample():

    print("\nSimple CCSD example with H2.");

    # set up geometry of the H2 molecule
    mol = ps.M(
        unit = 'Bohr',
        atom = 'H 0 0 0; H 0 0 1.4', # near gd state
        basis = 'ccpvdz',
        verbose = 3 ); #supress output for this example
    print("\nH2 geometry =\n",mol.atom_coords() );

    # use restricted HF to approx energy of HF gd state
    EHF = mol.RHF().run();
    print("\nEHF = mol.RHF().run() computes the HF gd state energy.",
    "\nAccess it using EHF.kernel(): E_HF = %.5g" %EHF.kernel() );

    # use coupled cluster singles doubles to approx correlation energy
    ECC = EHF.CCSD().run();
    print("\nECC = mf.CCSD().run() computes the correlation energy.",
    "\nAccess it using ECC.e_corr: ECC = %.5g" %ECC.e_corr );
Example #7
0
#!/usr/bin/env python
'''
Compute electron density in real space.

See also the example dft/31-xc_value_on_grid.py
'''

import numpy as np
import pyscf

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

cc = mol.CCSD().run()

# Put 100x100x100 uniform grids in a box. The unit for coordinates is Bohr
xs = np.arange(-5, 5, .1)
ys = np.arange(-5, 5, .1)
zs = np.arange(-5, 5, .1)
grids = pyscf.lib.cartesian_prod([xs, ys, zs])

# Compute density matrix and evaluate the electron density with it.
# Note the density matrix has to be in AO basis
dm = cc.make_rdm1(ao_repr=True)
ao_value = pyscf.dft.numint.eval_ao(mol, grids, deriv=0)
rho = pyscf.dft.numint.eval_rho(mol, ao_value, dm)

print('The shape of the electron density', rho.shape)
Example #8
0
#!/usr/bin/env python
'''
A simple example to run an NVE BOMD simulation.
'''

import pyscf
import pyscf.md

mol = pyscf.M(atom='O 0 0 0; O 0 0 1.2', verbose=3, basis='ccpvdz', spin=2)

myhf = mol.RHF().run()

# 6 orbitals, 8 electrons
mycas = myhf.CASSCF(6, 8)
myscanner = mycas.nuc_grad_method().as_scanner()

# Generate the integrator
# sets the time step to 5 a.u. and will run for 10 steps
# or for 50 a.u.
myintegrator = pyscf.md.NVE(myscanner, dt=5, steps=10)


def my_callback(local_dict):
    local_dict['scanner'].base.verbose = 4
    local_dict['scanner'].base.analyze()
    local_dict['scanner'].base.verbose = 3


myintegrator.callback = my_callback

myintegrator.run()
Example #9
0
#!/usr/bin/env python
'''
PySCF doesn't have its own input parser.  The input file is a Python program.

Before going throught the rest part, be sure the PySCF path is added in PYTHONPATH.
'''

import pyscf

# mol is an object to hold molecule information.
mol = pyscf.M(
    verbose=4,
    output='out_h2o',
    atom='''
      o     0    0       0
      h     0    -.757   .587
      h     0    .757    .587''',
    basis='6-31g',
)
# For more details, see pyscf/gto/mole.py and pyscf/examples/gto

#
# The package follow the convention that each method has its class to hold
# control parameters.  The calculation can be executed by the kernel function.
# Eg, to do Hartree-Fock, (1) create HF object, (2) call kernel function
#
mf = mol.RHF()
print('E=%.15g' % mf.kernel())

#
# The above code can be simplified using stream operations.
Example #10
0
#!/usr/bin/env python
import pyscf
from pyscf.tools.mo_mapping import mo_comps
from benchmarking_utils import setup_logger, get_cpu_timings

log = setup_logger()

for bas in ('3-21g', '6-31g**', 'cc-pVTZ', 'ANO-Roos-TZ'):
    mol = pyscf.M(atom='''
c   1.217739890298750 -0.703062453466927  0.000000000000000
h   2.172991468538160 -1.254577209307266  0.000000000000000
c   1.217739890298750  0.703062453466927  0.000000000000000
h   2.172991468538160  1.254577209307266  0.000000000000000
c   0.000000000000000  1.406124906933854  0.000000000000000
h   0.000000000000000  2.509154418614532  0.000000000000000
c  -1.217739890298750  0.703062453466927  0.000000000000000
h  -2.172991468538160  1.254577209307266  0.000000000000000
c  -1.217739890298750 -0.703062453466927  0.000000000000000
h  -2.172991468538160 -1.254577209307266  0.000000000000000
c   0.000000000000000 -1.406124906933854  0.000000000000000
h   0.000000000000000 -2.509154418614532  0.000000000000000
''',
                  basis=bas)
    cpu0 = get_cpu_timings()

    mf = mol.RHF().run()
    cpu0 = log.timer('C6H6 %s RHF' % bas, *cpu0)

    mymp2 = mf.MP2().run()
    cpu0 = log.timer('C6H6 %s MP2' % bas, *cpu0)
Example #11
0
#!/usr/bin/env python
#
# Author: Qiming Sun <*****@*****.**>
#
'''
Active space can be adjusted by specifing the number of orbitals for each irrep.
'''

import pyscf

mol = pyscf.M(
    atom='N  0  0  0; N  0  0  2',
    basis='ccpvtz',
    symmetry=True,
)
myhf = mol.RHF()
myhf.kernel()

mymc = myhf.CASSCF(8, 4)
# Select active orbitals which have the specified symmetry
# 2 E1gx orbitals, 2 E1gy orbitals, 2 E1ux orbitals, 2 E1uy orbitals
cas_space_symmetry = {'E1gx': 2, 'E1gy': 2, 'E1ux': 2, 'E1uy': 2}
mo = pyscf.mcscf.sort_mo_by_irrep(mymc, myhf.mo_coeff, cas_space_symmetry)
mymc.kernel(mo)

mol = pyscf.M(
    atom='Ti',
    basis='ccpvdz',
    symmetry=True,
    spin=2,
)
Example #12
0
from pyscf import lib, scf

scf_kernel = scf.hf.SCF.kernel


def kernel(self, dm0=None, **kwargs):
    scf_kernel(self, dm0, **kwargs)

    if not self.converged and not self.level_shift:
        with lib.temporary_env(self, level_shift=.2):
            lib.logger.note(self, 'DIIS does not converge. Try level shift')
            scf_kernel(self, self.make_rdm1(), **kwargs)

    if not self.converged:
        lib.logger.note(self, 'DIIS does not converge. Try SOSCF')
        mf1 = self.newton().run()

        # Note: delete mf1._scf because it leads to circular reference to self.
        del mf1._scf
        self.__dict__.update(mf1.__dict__)

    return self.e_tot


scf.hf.SCF.kernel = kernel

# Using the patched SCF kernel
import pyscf
pyscf.M(atom='Ne', basis='ccpvdz',
        verbose=3).RKS().density_fit().run(max_cycle=3)
Example #13
0
def main():
    from itertools import product
    import pyscf
    import openfermion as of
    from openfermion.chem.molecular_data import spinorb_from_spatial
    from openfermionpyscf import run_pyscf
    from pyscf.cc.addons import spatial2spin
    import numpy as np

    basis = 'cc-pvdz'
    mol = pyscf.M(atom='H 0 0 0; B 0 0 {}'.format(1.6), basis=basis)

    mf = mol.RHF().run()
    mycc = mf.CCSD().run()
    print('CCSD correlation energy', mycc.e_corr)

    molecule = of.MolecularData(geometry=[['H', (0, 0, 0)], ['B',
                                                             (0, 0, 1.6)]],
                                basis=basis,
                                charge=0,
                                multiplicity=1)
    molecule = run_pyscf(molecule, run_ccsd=True)
    oei, tei = molecule.get_integrals()
    norbs = int(mf.mo_coeff.shape[1])
    occ = mf.mo_occ
    nele = int(sum(occ))
    nocc = nele // 2
    assert np.allclose(np.transpose(mycc.t2, [1, 0, 3, 2]), mycc.t2)

    soei, stei = spinorb_from_spatial(oei, tei)
    astei = np.einsum('ijkl', stei) - np.einsum('ijlk', stei)

    # put in physics notation. OpenFermion stores <12|2'1'>
    gtei = astei.transpose(0, 1, 3, 2)

    eps = np.kron(molecule.orbital_energies, np.ones(2))
    n = np.newaxis
    o = slice(None, 2 * nocc)
    v = slice(2 * nocc, None)

    e_abij = 1 / (-eps[v, n, n, n] - eps[n, v, n, n] + eps[n, n, o, n] +
                  eps[n, n, n, o])
    e_ai = 1 / (-eps[v, n] + eps[n, o])

    fock = soei + np.einsum('piiq->pq', astei[:, o, o, :])
    hf_energy = 0.5 * np.einsum('ii', (fock + soei)[o, o])
    hf_energy_test = 1.0 * einsum('ii', fock[o, o]) - 0.5 * einsum(
        'ijij', gtei[o, o, o, o])
    print(hf_energy_test, hf_energy)
    assert np.isclose(hf_energy + molecule.nuclear_repulsion,
                      molecule.hf_energy)

    g = gtei
    nsvirt = 2 * (norbs - nocc)
    nsocc = 2 * nocc
    t1f, t2f = kernel(np.zeros((nsvirt, nsocc)),
                      np.zeros((nsvirt, nsvirt, nsocc, nsocc)), fock, g, o, v,
                      e_ai, e_abij)
    print(ccsd_energy(t1f, t2f, fock, g, o, v) - hf_energy)

    t1f, t2f = kernel(np.zeros((nsvirt, nsocc)),
                      np.zeros((nsvirt, nsvirt, nsocc, nsocc)),
                      fock,
                      g,
                      o,
                      v,
                      e_ai,
                      e_abij,
                      diis_size=8,
                      diis_start_cycle=4)
    print(ccsd_energy(t1f, t2f, fock, g, o, v) - hf_energy)
Example #14
0
'''
A simple example of using polarizable embedding model in the mean-field
calculations. This example requires the cppe library

GitHub:      https://github.com/maxscheurer/cppe
Code:        10.5281/zenodo.3345696
Publication: https://doi.org/10.1021/acs.jctc.9b00758

The CPPE library can be installed via:
pip install git+https://github.com/maxscheurer/cppe.git

The potfile required by this example can be generated with the script
04-pe_potfile_from_pyframe.py
'''

import pyscf
from pyscf import solvent

mol = pyscf.M(atom='''
C        0.000000    0.000000             -0.542500
O        0.000000    0.000000              0.677500
H        0.000000    0.9353074360871938   -1.082500
H        0.000000   -0.9353074360871938   -1.082500
            ''',
            verbose = 4)
mf = mol.UKS()
mf.xc = 'b3lyp'
mf = solvent.PE(mf, '4NP_in_water/4NP_in_water.pot')
mf.run()

Example #15
0
#!/usr/bin/env python
#
# Author: Qiming Sun <*****@*****.**>
#
'''
Symmetry is not immutable

CASSCF solver can have different symmetry to reference Hartree-Fock calculation.
'''

import pyscf

mol = pyscf.M(
    atom='Cr   0  0  0',
    basis='cc-pvtz',
    spin=6,
    symmetry=True,
)
myhf = mol.RHF()
myhf.irrep_nelec = {
    's+0': (4, 3),
    'd-2': (1, 0),
    'd-1': (1, 0),
    'd+0': (1, 0),
    'd+1': (1, 0),
    'd+2': (1, 0)
}
myhf.kernel()

myhf.mol.build(0, 0, symmetry='D2h')
mymc = myhf.CASSCF(9, 6)
#!/usr/bin/env python
'''
State average over custom FCI solvers

This example shows how to put custom FCI solvers into one state-average solver
using the method state_average_mix_.
'''

import numpy as np
import pyscf

mol = pyscf.M(atom=[
    ['C', (0., 0., -.485)],
    ['C', (0., 0., .485)],
],
              basis='cc-pvdz',
              symmetry=True)
mf = mol.RHF()
mf.irrep_nelec = {
    'A1g': 4,
    'E1gx': 0,
    'E1gy': 0,
    'A1u': 4,
    'E1uy': 2,
    'E1ux': 2,
    'E2gx': 0,
    'E2gy': 0,
    'E2uy': 0,
    'E2ux': 0
}
ehf = mf.kernel()
#!/usr/bin/env python
#
# Author: Qiming Sun <*****@*****.**>
#

'''
Example for the value of FCI wave function on specific electrons coordinates
'''

import numpy as np
import pyscf
from pyscf import fci

mol = pyscf.M(atom='H 0 0 0; H 0 0 1.1', basis='6-31g', verbose=0)
mf = mol.RHF().run()
e1, ci1 = fci.FCI(mol, mf.mo_coeff).kernel()
print('FCI energy', e1)

# coordinates for all electrons in the molecule
e_coords = np.random.rand(mol.nelectron, 3)
ao_on_grid = mol.eval_gto('GTOval', e_coords)
mo_on_grid = ao_on_grid.dot(mf.mo_coeff)

# View mo_on_grid as a transformation from MO to grid basis
mo_grid_ovlp = mo_on_grid.T

# ci_on_grid gives the value on e_grids for each CI determinant
ci_on_grid = fci.addons.transform_ci(ci1, mol.nelec, mo_grid_ovlp)
print(f'For electrons on grids\n{e_coords}\nCI value = {ci_on_grid.sum()}')
Example #18
0
#!/usr/bin/env python
#
# Author: Qiming Sun <*****@*****.**>
#
'''
Overlap of two FCI wave functions
'''

from functools import reduce
import numpy
import pyscf

myhf1 = pyscf.M(atom='H 0 0 0; F 0 0 1.1', basis='6-31g',
                verbose=0).RHF().run()
e1, ci1 = pyscf.fci.FCI(myhf1).kernel()
print('FCI energy of mol1', e1)

myhf2 = pyscf.M(atom='H 0 0 0; F 0 0 1.2', basis='6-31g',
                verbose=0).RHF().run()
e2, ci2 = pyscf.fci.FCI(myhf2).kernel()
print('FCI energy of mol2', e2)

myhf3 = pyscf.M(atom='H 0 0 0; F 0 0 1.3', basis='6-31g',
                verbose=0).UHF().run()
e3, ci3 = pyscf.fci.FCI(myhf3).kernel()
print('FCI energy of mol3', e3)

#
# Overlap between FCI wfn of different geometries
#
s12 = pyscf.gto.intor_cross('int1e_ovlp', myhf1.mol, myhf2.mol)
Example #19
0
File: n2.py Project: zzy2014/pyscf
import time
import pyscf
from pyscf.tools.mo_mapping import mo_comps

log = pyscf.lib.logger.Logger(verbose=5)
with open('/proc/cpuinfo') as f:
    for line in f:
        if 'model name' in line:
            log.note(line[:-1])
            break
with open('/proc/meminfo') as f:
    log.note(f.readline()[:-1])
log.note('OMP_NUM_THREADS=%s\n', os.environ.get('OMP_NUM_THREADS', None))

for bas in ('3-21g', '6-31g*', 'cc-pVTZ', 'ANO-Roos-TZ'):
    mol = pyscf.M(atom='N 0 0 0; N 0 0 1.1', basis=bas)
    cpu0 = time.clock(), time.time()

    mf = mol.RHF().run()
    cpu0 = log.timer('N2 %s RHF' % bas, *cpu0)

    mymp2 = mf.MP2().run()
    cpu0 = log.timer('N2 %s MP2' % bas, *cpu0)

    mymc = mf.CASSCF(4, 4)
    idx_2pz = mo_comps('2p[xy]', mol, mf.mo_coeff).argsort()[-4:]
    mo = mymc.sort_mo(idx_2pz, base=0)
    mymc.kernel(mo)
    cpu0 = log.timer('N2 %s CASSCF' % bas, *cpu0)

    mycc = mf.CCSD().run()
Example #20
0
cell0 = pyscf.M(a=np.eye(3) * boxlen,
                atom="""
O      12.235322       1.376642      10.869880
O       6.445390       3.706940       8.650794
O       0.085977       2.181322       8.276663
O      12.052554       2.671366       2.147199
O      12.250036       4.190930      12.092014
O       7.187422       0.959062       4.733469
O       8.346457       7.210040       4.667644
O      12.361546      11.527875       8.106887
O       3.299984       4.440816       9.193275
O       2.855829       3.759909       6.552815
O       1.392494       6.362753       0.586172
O       1.858645       8.694013       2.068738
O       3.770231      12.094519       8.652183
O       6.432508       3.669828       2.772418
O       1.998724       1.820217       4.876440
O       8.248581       2.404730       6.931303
O       5.753814       3.360029      12.461534
O      11.322212       5.649239       2.236798
O       4.277318       2.113956      10.590808
O       5.405015       3.349247       5.484702
O       6.493278      11.869958       0.684912
O       3.275250       2.346576       2.425241
O       7.981003       6.352512       7.507970
O       5.985990       6.512854      12.194648
O      10.636714      11.856872      12.209540
O       9.312283       3.670384       3.508594
O       1.106885       5.830301       6.638695
O       8.008007       3.326363      10.869818
O      12.403000       9.687405      11.761901
O       4.219782       7.085315       8.153470
O       3.781557       8.203821      11.563272
O      11.088898       4.532081       7.809475
O      10.387548       8.408890       1.017882
O       1.979016       6.418091      10.374159
O       4.660547       0.549666       5.617403
O       8.745880      12.256257       8.089383
O       2.662041      10.489890       0.092980
O       7.241661      10.471815       4.226946
O       2.276827       0.276647      10.810417
O       8.887733       0.946877       1.333885
O       1.943554       8.088552       7.567650
O       9.667942       8.056759       9.868847
O      10.905491       8.339638       6.484782
O       3.507733       4.862402       1.557439
O       8.010457       8.642846      12.055969
O       8.374446      10.035932       6.690309
O       5.635247       6.076875       5.563993
O      11.728434       1.601906       5.079475
O       9.771134       9.814114       3.548703
O       3.944355      10.563450       4.687536
O       0.890357       6.382287       4.065806
O       6.862447       6.425182       2.488202
O       3.813963       6.595122       3.762649
O       6.562448       8.295463       8.807182
O       9.809455       0.143325       3.886553
O       4.117074      11.661225       2.221679
O       5.295317       8.735561       2.763183
O       9.971999       5.379339       5.340378
O      12.254708       8.643874       3.957116
O       2.344274      10.761274       6.829162
O       7.013416       0.643488      10.518797
O       5.152349      10.233624      10.359388
O      11.184278       5.884064      10.298279
O      12.252335       8.974142       9.070831
H      12.415139       2.233125      11.257611
H      11.922476       1.573799       9.986994
H       5.608192       3.371543       8.971482
H       6.731226       3.060851       8.004962
H      -0.169205       1.565594       7.589645
H      -0.455440       2.954771       8.118939
H      12.125168       2.826463       1.205443
H      12.888828       2.969761       2.504745
H      11.553255       4.386613      11.465566
H      12.818281       4.960808      12.067151
H       7.049495       1.772344       4.247898
H       6.353019       0.798145       5.174047
H       7.781850       7.384852       5.420566
H       9.103203       6.754017       5.035898
H      12.771232      11.788645       8.931744
H      12.018035      10.650652       8.276334
H       3.557245       3.792529       9.848846
H       2.543844       4.884102       9.577958
H       2.320235       4.521250       6.329813
H       2.872128       3.749963       7.509824
H       1.209685       7.121391       1.140501
H       2.238885       6.038801       0.894245
H       2.763109       8.856353       2.336735
H       1.329379       9.047369       2.783755
H       4.315639      11.533388       9.203449
H       3.098742      12.433043       9.244412
H       5.987369       3.448974       3.590530
H       5.813096       3.419344       2.086985
H       1.057126       1.675344       4.969379
H       2.248496       2.292119       5.670892
H       8.508264       1.653337       7.464411
H       8.066015       2.034597       6.067646
H       5.197835       2.915542      11.821572
H       6.630900       3.329981      12.079371
H      10.788986       6.436672       2.127933
H      11.657923       5.463602       1.359832
H       3.544476       1.634958      10.977765
H       4.755770       1.455054      10.087655
H       4.465371       3.375459       5.665294
H       5.682663       4.264430       5.524498
H       6.174815      11.778676       1.582954
H       5.713640      12.089924       0.174999
H       3.476076       1.498708       2.028983
H       2.730229       2.134295       3.182949
H       7.119624       5.936450       7.474030
H       8.536492       5.799405       6.958665
H       5.909499       5.717477      11.667621
H       6.125402       6.196758      13.087330
H      11.203499      12.513536      11.804844
H      10.260930      12.300153      12.970145
H       9.985036       3.927685       2.878172
H       8.545584       3.468329       2.972331
H       1.399882       6.620092       7.093246
H       0.963561       6.112523       5.735345
H       8.067363       3.674002       9.979955
H       8.000737       2.375959      10.756190
H      11.821629      10.402510      12.020482
H      12.206854       8.983242      12.379892
H       3.461473       7.606485       7.889688
H       3.844478       6.304711       8.560946
H       3.179884       7.585614      11.148494
H       4.401957       7.652030      12.039573
H      11.573777       5.053211       7.169515
H      10.342076       4.186083       7.320831
H      10.065640       8.919194       1.760981
H       9.629585       8.322499       0.439729
H       1.396302       6.546079       9.625630
H       1.405516       6.479759      11.138049
H       4.024008       1.232518       5.405828
H       4.736858       0.579881       6.571077
H       9.452293      12.313381       8.732772
H       8.976559      11.502788       7.545965
H       1.834701      10.012311       0.153462
H       3.295197       9.836403      -0.204175
H       7.056724      11.401702       4.095264
H       6.499038      10.020287       3.825865
H       1.365541       0.487338      11.013887
H       2.501591      -0.428131      11.417871
H       8.644279       1.812362       1.005409
H       8.142674       0.388030       1.112955
H       1.272659       8.365063       8.191888
H       2.142485       8.877768       7.063867
H       8.961493       7.826192       9.265523
H       9.227102       8.487654      10.601118
H      10.150144       7.758934       6.392768
H      10.596082       9.187988       6.167290
H       3.463106       4.096188       2.129414
H       3.919461       4.539801       0.755791
H       7.418998       9.394959      12.028876
H       7.430413       7.883095      12.106546
H       7.972905      10.220334       5.841196
H       7.675111       9.631498       7.203725
H       5.332446       6.381336       6.419473
H       5.000025       6.434186       4.943466
H      11.575078       2.271167       4.412540
H      11.219802       0.847030       4.783357
H       8.865342       9.721516       3.843998
H      10.000732      10.719285       3.758898
H       3.186196      10.476397       5.265333
H       4.407331      11.335128       5.013723
H       0.558187       7.255936       3.859331
H       0.341672       5.789383       3.552346
H       7.459933       6.526049       3.229193
H       6.696228       5.483739       2.440372
H       3.864872       6.313007       2.849385
H       2.876419       6.621201       3.953862
H       5.631529       8.079145       8.753997
H       7.003296       7.568245       8.367822
H       9.615413       0.527902       3.031755
H       8.962985       0.109366       4.332162
H       3.825854      11.139182       1.474087
H       4.063988      11.063232       2.967211
H       5.784391       7.914558       2.708486
H       4.780461       8.655167       3.566110
H      10.880659       5.444664       5.046607
H       9.593331       4.687991       4.797350
H      11.562317       8.960134       3.376765
H      11.926084       8.816948       4.839320
H       2.856874      11.297981       7.433660
H       1.492332      11.195517       6.786033
H       7.145820       0.090200       9.749009
H       7.227275       0.077690      11.260665
H       4.662021       9.538430      10.798155
H       5.994537       9.833472      10.142985
H      10.544299       6.595857      10.301445
H      11.281750       5.653082       9.374494
H      12.103020       8.841164      10.006916
H      11.491592       8.576221       8.647557
""",
                basis='gth-tzv2p',
                pseudo='gth-pade',
                max_memory=50000,
                precision=1e-6)
Example #21
0
#!/usr/bin/env python
'''
Analytical nuclear gradients of state-average CASSCF

More examples can be found in 12-excited_state_casscf_grad.py
'''

import pyscf

mol = pyscf.M(atom='N 0 0 0; N 0 0 1.2', basis='ccpvdz', verbose=5)

mf = mol.RHF().run()
sa_mc = mf.CASSCF(4, 4).state_average_([0.5, 0.5]).run()
print('State-average CASSCF total energy', sa_mc.e_tot)

sa_mc_grad = sa_mc.Gradients()

# The state-averaged nuclear gradients
de_avg = sa_mc_grad.kernel()

# Nuclear gradients for state 1
de_0 = sa_mc_grad.kernel(state=0)

# Nuclear gradients for state 2
de_1 = sa_mc_grad.kernel(state=1)
Example #22
0
#!/usr/bin/env python
#
# Author: Qiming Sun <*****@*****.**>
#
'''
CCSD and CCSD(T) lambda equation
'''

import pyscf

mol = pyscf.M(atom='''
O    0.   0.       0.
H    0.   -0.757   0.587
H    0.   0.757    0.587''',
              basis='cc-pvdz')
mf = mol.RHF().run()
cc = mf.CCSD().run()
#
# Solutions for CCSD Lambda equations are saved in cc.l1 and cc.l2
#
cc.solve_lambda()
print(cc.l1.shape)
print(cc.l2.shape)

###
#
# Compute CCSD(T) lambda with ccsd_t-slow implementation
# (as of pyscf v1.7)
#
from pyscf.cc import ccsd_t_lambda_slow as ccsd_t_lambda
conv, l1, l2 = ccsd_t_lambda.kernel(cc, cc.ao2mo(), cc.t1, cc.t2, tol=1e-8)
Example #23
0
#!/usr/bin/env python
#
# Author: Qiming Sun <*****@*****.**>
#
'''
A simple example to run CCSD(T) and UCCSD(T) calculation.
'''

import pyscf

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

mf = mol.RHF().run()
mycc = mf.CCSD().run()
et = mycc.ccsd_t()
print('CCSD(T) correlation energy', mycc.e_corr + et)

mf = mol.UHF().run()
mycc = mf.CCSD().run()
et = mycc.ccsd_t()
print('UCCSD(T) correlation energy', mycc.e_corr + et)
Example #24
0
 def test_umindo(self):
     mol = pyscf.M(atom=[(8, (0, 0, 0)), (1, (1., 0, 0))], spin=1)
     mf = semiempirical.UMINDO3(mol).run(conv_tol=1e-6)
     self.assertAlmostEqual(mf.e_heat_formation, 18.08247965492137)
Example #25
0
File: c60.py Project: zzy2014/pyscf
#!/usr/bin/env python

import os
import time
import pyscf
from pyscf.tools import c60struct

log = pyscf.lib.logger.Logger(verbose=5)
with open('/proc/cpuinfo') as f:
    for line in f:
        if 'model name' in line:
            log.note(line[:-1])
            break
with open('/proc/meminfo') as f:
    log.note(f.readline()[:-1])
log.note('OMP_NUM_THREADS=%s\n', os.environ.get('OMP_NUM_THREADS', None))

for bas in ('6-31g**', 'cc-pVTZ'):
    mol = pyscf.M(atom=[('C', r) for r in c60struct.make60(1.46, 1.38)],
                  basis=bas,
                  max_memory=40000)

    cpu0 = time.clock(), time.time()
    mf = pyscf.scf.fast_newton(mol.RHF())
    cpu0 = logger.timer('SOSCF/%s' % bas, *cpu0)

    mf = mol.RHF().density_fit().run()
    cpu0 = logger.timer('density-fitting-HF/%s' % bas, *cpu0)
Example #26
0
#!/usr/bin/env python
'''
A simple example to run CAM-B3LYP TDDFT calculation.

You need to switch to xcfun library if you found an error like
NotImplementedError: libxc library does not support derivative order 2 for  camb3lyp
    This functional derivative is supported in the xcfun library.
    The following code can be used to change the libxc library to xcfun library:

        from pyscf.dft import xcfun
        mf._numint.libxc = xcfun
'''

import pyscf

mol = pyscf.M(
    atom='H 0 0 0; F 0 0 1.1',
    basis='6-31g(d,p)',
    symmetry=True,
)

mf = mol.RKS()
mf.xc = 'camb3lyp'
mf.run()

# Note you need to switch to xcfun library for cam-b3lyp tddft
mf._numint.libxc = pyscf.dft.xcfun
mytd = mf.TDDFT()
mytd.kernel()
Example #27
0
#!/usr/bin/env python
'''
PySCF doesn't have its own input parser.  The input file is a Python program.

Before going throught the rest part, be sure the PySCF path is added in PYTHONPATH.
'''

import pyscf

# mol is an object to hold molecule information.
mol = pyscf.M(
    verbose=4,
    output='out_h2o',
    atom='''
      o     0    0       0
      h     0    -.757   .587
      h     0    .757    .587''',
    basis='6-31g',
)
# For more details, see pyscf/gto/mole.py and pyscf/examples/gto

#
# The package follow the convention that each method has its class to hold
# control parameters.  The calculation can be executed by the kernel function.
# Eg, to do Hartree-Fock, (1) create HF object, (2) call kernel function
#
mf = mol.RHF()
print('E(HF)=%.15g' % mf.kernel())

#
# A post-HF method can be applied.
Example #28
0
# Cmake flag -DWITH_RANGE_COULOMB=1 should be set

import time
import numpy
import pyscf
mol = pyscf.M(
    atom='''H 0 0 0;
H 0 -1 1
H 0  1 1
H 1 0 -1''',
    basis={
        'H': [[0, (2., .8), (1.5, .3)], [0, (.625, 1)], [1, (.8, 1)],
              [2, (1.2, 1)]]
    },
)

eri = mol.intor('int2e')
with mol.with_range_coulomb(.3):
    eri_lr = mol.intor('int2e')
with mol.with_range_coulomb(-.3):
    eri_sr = mol.intor('int2e')

print(abs(eri_lr + eri_sr - eri).max())
Example #29
0
A simple example to call integral transformation for given orbitals
'''

mol = gto.Mole()
mol.build(
    atom='H 0 0 0; F 0 0 1.1',  # in Angstrom
    basis='ccpvdz',
    symmetry=True,
)

myhf = scf.RHF(mol)
myhf.kernel()

orb = myhf.mo_coeff
eri_4fold = ao2mo.kernel(mol, orb)
print('MO integrals (ij|kl) with 4-fold symmetry i>=j, k>=l have shape %s' %
      str(eri_4fold.shape))

#
# Starting from PySCF-1.7, the MO integrals can be computed with the code
# below.
#
import pyscf
mol = pyscf.M(
    atom='H 0 0 0; F 0 0 1.1',  # in Angstrom
    basis='ccpvdz',
    symmetry=True,
)
orb = mol.RHF().run().mo_coeff
eri_4fold = mol.ao2mo(orb)
Example #30
0
#!/usr/bin/env python
'''
Various Pipek-Mezey localization schemes

See more discussions in paper  JCTC, 10, 642 (2014); DOI:10.1021/ct401016x
'''

import pyscf

x = .63
mol = pyscf.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 = mol.RHF().run()

orbitals = mf.mo_coeff[:, mf.mo_occ > 0]
pm = pyscf.lo.PM(mol, orbitals, mf)


def print_coeff(local_orb):
    import sys
    idx = mol.search_ao_label(['C 1s', 'C 2s', 'C 2p', 'H 1s'])
    ao_labels = mol.ao_labels()
    labels = [ao_labels[i] for i in idx]
    pyscf.tools.dump_mat.dump_rec(sys.stdout, local_orb[idx], labels)


print('---')
pm.pop_method = 'mulliken'
print_coeff(pm.kernel())