# NOTE the DMRG-NEVPT2 is expensive, it requires about 8 GB memory per processor
#
#from pyscf.dmrgscf import settings
#settings.MPIPREFIX = 'srun'
#settings.BLOCKSCRATCHDIR = '/scratch'

from pyscf.dmrgscf.dmrgci import DMRGCI, DMRGSCF
from pyscf.mrpt.nevpt2 import sc_nevpt

#
# Redirect output to another file
#
mol.build_(verbose=7, output = 'hs_dmrg.out')

mf = scf.sfx2c1e(scf.RHF(mol))
mc = DMRGSCF(mf, norb, [nalpha,nbeta])
mc.chkfile = 'hs_mc.chk'
mc.max_memory = 30000
mc.fcisolver.maxM = 1000
mc.fcisolver.tol = 1e-6
orbs = mc.sort_mo(caslst, coeff, base=0)
mc.mc1step(orbs)


#
# CASCI-NEVPT2
#
# If DMRG-CASSCF was finished without any problems (eg convergence, wall time
# limits on cluster etc),  one can simply continue with DMRG-NEVPT2 like
#       sc_nevpt(mc)
#
m = scf.sfx2c1e(scf.RHF(mol)).run(conv_tol=1e-9, chkfile='hf_chk-%s'%b, level_shift=0.5)
#
# Note: stream operations are used here.  This one line code is equivalent to
# the following serial statements.
#
#m = scf.sfx2c1e(scf.RHF(mol))
#m.conv_tol = 1e-9
#m.chkfile = 'hf_chk-%s'%b
#m.level_shift = 0.5
#m.kernel()

dm = m.make_rdm1()
m.level_shift = 0
m.scf(dm)

mc = DMRGSCF(m, 20, 28)  # 20o, 28e
mc.fcisolver.maxM = 1000
mc.fcisolver.tol = 1e-6

mc.chkfile = 'mc_chk_18o-%s'%b
cas_occ = {'A1g':4, 'A1u':4,
           'E1ux':2, 'E1uy':2, 'E1gx':2, 'E1gy':2,
           'E2ux':1, 'E2uy':1, 'E2gx':1, 'E2gy':1}
mo = mc.sort_mo_by_irrep(cas_occ)
mc.kernel(mo)

#
# DMRG-NEVPT2
#
sc_nevpt(mc)