Skip to content

Commit

Permalink
Import all pyscf modules in __all__.py. Implicit import pyscf modules…
Browse files Browse the repository at this point in the history
… in gto.Mole class
  • Loading branch information
sunqm committed Apr 24, 2019
1 parent 51a148f commit ab7f66e
Show file tree
Hide file tree
Showing 43 changed files with 420 additions and 162 deletions.
17 changes: 10 additions & 7 deletions examples/0-readme.py
Expand Up @@ -6,11 +6,10 @@
Before going throught the rest part, be sure the PySCF path is added in PYTHONPATH.
'''

from pyscf import gto
from pyscf import scf
import pyscf

# mol is an object to hold molecule information.
mol = gto.M(
mol = pyscf.M(
verbose = 4,
output = 'out_h2o',
atom = '''
Expand All @@ -26,22 +25,26 @@
# 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 = scf.RHF(mol)
mf = mol.RHF()
print('E=%.15g' % mf.kernel())



#
# The above code can be simplified using stream operations.
# There are three stream functions ".set", ".run", ".apply" to pipe computing
# streams. Stream operations allows writing computing script in one line.
# streams. Stream operations allows writing multiple computing tasks in one
# line.
#
mf = gto.M(
mf = pyscf.M(
atom = '''
O 0 0 0
h 0 -.757 .587
1 0 .757 .587''',
basis = '6-31g'
).apply(scf.RHF).run()
).RHF().run()
print('E=%.15g' % mf.e_tot)


mp2 = mol.RHF().run().MP2().run()
print('E=%.15g' % mp2.e_tot)
8 changes: 4 additions & 4 deletions examples/cc/00-simple_ccsd.py
Expand Up @@ -7,14 +7,14 @@
A simple example to run CCSD calculation.
'''

from pyscf import gto, scf, cc
import pyscf

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

mf = scf.RHF(mol).run()
mf = mol.RHF().run()

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

12 changes: 6 additions & 6 deletions examples/cc/00-simple_ccsd_t.py
Expand Up @@ -7,19 +7,19 @@
A simple example to run CCSD(T) and UCCSD(T) calculation.
'''

from pyscf import gto, scf, cc
import pyscf

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

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

mf = scf.UHF(mol).run()
mycc = cc.UCCSD(mf).run()
mf = mol.UHF().run()
mycc = mf.CCSD().run()
et = mycc.ccsd_t()
print('UCCSD(T) correlation energy', mycc.e_corr + et)

12 changes: 6 additions & 6 deletions examples/ci/00-simple_cisd.py
Expand Up @@ -7,17 +7,17 @@
A simple example to run CISD calculation.
'''

from pyscf import gto, scf, ci
import pyscf

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

mf = scf.RHF(mol).run()
mycc = ci.CISD(mf).run()
mf = mol.HF().run()
mycc = mf.CISD().run()
print('RCISD correlation energy', mycc.e_corr)

mf = scf.UHF(mol).run()
mycc = ci.CISD(mf).run()
mf = mol.UHF().run()
mycc = mf.CISD().run()
print('UCISD correlation energy', mycc.e_corr)

7 changes: 3 additions & 4 deletions examples/dft/00-simple_dft.py
Expand Up @@ -3,7 +3,7 @@
# Author: Qiming Sun <osirpt.sun@gmail.com>
#

from pyscf import gto, dft
import pyscf

'''
A simple example to run DFT calculation.
Expand All @@ -12,14 +12,13 @@
available XC functionals.
'''

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

mf = dft.RKS(mol)
mf = mol.KS()
#mf.xc = 'svwn' # shorthand for slater,vwn
#mf.xc = 'bp86' # shorthand for b88,p86
#mf.xc = 'blyp' # shorthand for b88,lyp
Expand Down
16 changes: 9 additions & 7 deletions examples/mcscf/00-simple_casci.py
Expand Up @@ -7,20 +7,22 @@
A simple example to run CASCI calculation.
'''

import numpy
from pyscf import gto, scf, mcscf
import pyscf

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

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

# 6 orbitals, 8 electrons
mycas = mcscf.CASCI(myhf, 6, 8)
mycas.kernel()
mycas = myhf.CASCI(6, 8).run()
#
# Note this mycas object can also be created using the APIs of mcscf module:
#
# from pyscf import mcscf
# mycas = mcscf.CASCI(myhf, 6, 8).run()

# Natural occupancy in CAS space, Mulliken population etc.
mycas.verbose = 4
Expand Down
16 changes: 9 additions & 7 deletions examples/mcscf/00-simple_casscf.py
Expand Up @@ -7,20 +7,22 @@
A simple example to run CASSCF calculation.
'''

import numpy
from pyscf import gto, scf, mcscf
import pyscf

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

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

# 6 orbitals, 8 electrons
mycas = mcscf.CASSCF(myhf, 6, 8)
mycas.kernel()
mycas = myhf.CASSCF(6, 8).run()
#
# Note this mycas object can also be created using the APIs of mcscf module:
#
# from pyscf import mcscf
# mycas = mcscf.CASSCF(myhf, 6, 8).run()

# Natural occupancy in CAS space, Mulliken population etc.
# See also 00-simple_casci.py for the instruction of the output of analyze()
Expand Down
21 changes: 17 additions & 4 deletions examples/scf/00-simple_hf.py
Expand Up @@ -10,17 +10,30 @@
.analyze() function calls the Mulliken population analysis etc.
'''

from pyscf import gto, scf
import pyscf

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

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

# Orbital energies, Mulliken population etc.
myhf.analyze()


#
# myhf object can also be created using the APIs of gto, scf module
#
from pyscf import gto, scf
mol = gto.M(
atom = 'H 0 0 0; F 0 0 1.1', # in Angstrom
basis = 'ccpvdz',
symmetry = True,
)
myhf = scf.HF(mol)
myhf.kernel()

40 changes: 40 additions & 0 deletions pyscf/__all__.py
@@ -0,0 +1,40 @@
from . import post_scf
from . import grad
from . import gw
from . import hci
from . import hessian
from . import lo
from . import mrpt
from . import prop
from . import qmmm
#from . import semiempirical
from . import sgx
from . import solvent
from . import tools

#from . import geomopt

#try:
# from . import dftd3
#except ImportError:
# pass
#try:
# from . import dmrgscf
#except ImportError:
# pass
#try:
# from . import icmpspt
#except ImportError:
# pass
#try:
# from . import shciscf
#except ImportError:
# pass
#try:
# from . import cornell_shci
#except ImportError:
# pass

from .pbc import __all__
del __all__

10 changes: 9 additions & 1 deletion pyscf/__init__.py
Expand Up @@ -35,7 +35,7 @@
'''

__version__ = '1.6.1'
__version__ = '1.7.1'

import os
import sys
Expand All @@ -59,4 +59,12 @@

DEBUG = __config__.DEBUG

def M(**kwargs):
'''Main driver to create Molecule object (mol) or Material crystal object (cell)'''
if kwargs.get('a') is not None: # a is crystal lattice parameter
from pyscf.pbc import gto as pgto
return pgto.M(**kwargs)
else: # Molecule
return gto.M(**kwargs)

del(os, sys, LooseVersion, numpy)
2 changes: 1 addition & 1 deletion pyscf/cornell_shci/shci.py
Expand Up @@ -52,7 +52,7 @@
settings.MPIPREFIX = getattr(__config__, 'shci_MPIPREFIX', None)
if settings.SHCIEXE is None:
import sys
sys.stderr.write('settings.py not found. Please create %s\n'
sys.stderr.write('settings.py not found for module cornell_shci. Please create %s\n'
% os.path.join(os.path.dirname(__file__), 'settings.py'))
raise ImportError('settings.py not found')

Expand Down
2 changes: 2 additions & 0 deletions pyscf/dft/__init__.py
Expand Up @@ -27,10 +27,12 @@

try:
from pyscf.dft import libxc
XC = libxc.XC
except (ImportError, OSError):
pass
try:
from pyscf.dft import xcfun
XC = xcfun.XC
except (ImportError, OSError):
pass
#from pyscf.dft import xc
Expand Down
2 changes: 1 addition & 1 deletion pyscf/dmrgscf/dmrgci.py
Expand Up @@ -55,7 +55,7 @@
settings.BLOCKVERSION = getattr(__config__, 'dmrgscf_BLOCKVERSION', None)
if (settings.BLOCKEXE is None or settings.BLOCKSCRATCHDIR is None):
import sys
sys.stderr.write('settings.py not found. Please create %s\n'
sys.stderr.write('settings.py not found for module dmrgci. Please create %s\n'
% os.path.join(os.path.dirname(__file__), 'settings.py'))
raise ImportError('settings.py not found')

Expand Down
2 changes: 1 addition & 1 deletion pyscf/fciqmcscf/fciqmc.py
Expand Up @@ -31,7 +31,7 @@
try:
from pyscf.fciqmcscf import settings
except ImportError:
msg = '''settings.py not found. Please create %s
msg = '''settings.py not found for module fciqmcscf. Please create %s
''' % os.path.join(os.path.dirname(__file__), 'settings.py')
sys.stderr.write(msg)

Expand Down

0 comments on commit ab7f66e

Please sign in to comment.