import numpy as np
import math
from pyscf import gto, scf, ao2mo, mcscf, tools, lib
from pyscf.shciscf import shci
import NEVPT2Helper as nev
import os, sys

# make your molecule here
r = 2.5 * 0.529177
atomstring = "N 0 0 0; N 0 0 %g"%(r)
mol = gto.M(
    atom = atomstring,
    basis = {'N': gto.basis.parse('''
N    S
      4.323000E+05           5.590000E-06          -1.230000E-06           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      6.470000E+04           4.351000E-05          -9.580000E-06           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      1.472000E+04           2.289300E-04          -5.051000E-05           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      4.170000E+03           9.650200E-04          -2.126400E-04           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      1.361000E+03           3.502190E-03          -7.753400E-04           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      4.912000E+02           1.129212E-02          -2.506240E-03           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      1.916000E+02           3.261283E-02          -7.365290E-03           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      7.941000E+01           8.329727E-02          -1.930167E-02           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      3.453000E+01           1.799857E-01          -4.471738E-02           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      1.558000E+01           3.050035E-01          -8.606647E-02           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      7.232000E+00           3.411593E-01          -1.332963E-01           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      3.382000E+00           1.774827E-01          -1.059655E-01           1.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      1.369000E+00           1.988409E-02           1.346673E-01           0.000000E+00           1.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      6.248000E-01          -1.246630E-03           4.339401E-01           0.000000E+00           0.000000E+00           1.000000E+00           0.000000E+00           0.000000E+00
      2.747000E-01           1.040110E-03           4.529490E-01           0.000000E+00           0.000000E+00           0.000000E+00           1.000000E+00           0.000000E+00
      1.192000E-01          -1.265900E-04           1.340216E-01           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           1.000000E+00
N    S
      0.04714                1.0000
N    P
      4.159000E+02           1.484100E-04           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      9.861000E+01           1.276340E-03           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      3.192000E+01           6.702420E-03           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      1.200000E+01           2.526170E-02           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      4.919000E+00           7.518943E-02           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      2.148000E+00           1.740151E-01           1.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      9.696000E-01           2.927921E-01           0.000000E+00           1.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      4.399000E-01           3.482648E-01           0.000000E+00           0.000000E+00           1.000000E+00           0.000000E+00           0.000000E+00
      1.978000E-01           2.559365E-01           0.000000E+00           0.000000E+00           0.000000E+00           1.000000E+00           0.000000E+00
      8.603000E-02           6.947929E-02           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           1.000000E+00
N    P
      0.03150                1.0000
N    D
      6.717000E+00           1.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      2.896000E+00           0.000000E+00           1.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      1.249000E+00           0.000000E+00           0.000000E+00           1.000000E+00           0.000000E+00           0.000000E+00
      5.380000E-01           0.000000E+00           0.000000E+00           0.000000E+00           1.000000E+00           0.000000E+00
      2.320000E-01           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           1.000000E+00
N    D
      0.0874                 1.0000
N    F
      3.829000E+00           1.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      1.795000E+00           0.000000E+00           1.000000E+00           0.000000E+00           0.000000E+00
      8.410000E-01           0.000000E+00           0.000000E+00           1.000000E+00           0.000000E+00
      3.940000E-01           0.000000E+00           0.000000E+00           0.000000E+00           1.000000E+00
N    F
      0.1510                 1.0000
N    G
      3.856000E+00           1.000000E+00           0.000000E+00           0.000000E+00
      1.702000E+00           0.000000E+00           1.000000E+00           0.000000E+00
      7.510000E-01           0.000000E+00           0.000000E+00           1.000000E+00
N    G
      0.3260                 1.0000
N    H
      2.875000E+00           1.000000E+00           0.000000E+00
      1.170000E+00           0.000000E+00           1.000000E+00
N    H
      0.5870                 1.0000
N    I
      2.099000E+00           1.0000000
N    I
      1.0410                 1.0000
'''),
},
    verbose=4,
    symmetry=0,
    spin = 0)

mf = scf.RHF(mol)
chkfile = 'N2_HF.chk'
mf.__dict__.update(scf.chkfile.load(chkfile, 'scf'))

norbAct = 8
nelecAct = 10
norbFrozen = 0

mc = shci.SHCISCF(mf, norbAct, nelecAct)
chkfile = 'N2_SHCISCF.chk'
mc.__dict__.update( lib.chkfile.load(chkfile, 'mcscf') )

#this is the scratch file for writing potentially larger integral files
intfolder = "int/"
os.system("mkdir -p "+intfolder)

dm2a = np.zeros((norbAct, norbAct, norbAct, norbAct))
file2pdm = "spatialRDM.0.0.txt"
file2pdm = file2pdm.encode()  # .encode for python3 compatibility
shci.r2RDM(dm2a, norbAct, file2pdm)
dm1 = np.einsum('ikjj->ki', dm2a)
dm1 /= (nelecAct - 1)
#dm1, dm2a = mc.fcisolver.make_rdm12(0, mc.ncas, mc.nelecas)
dm2 = np.einsum('ijkl->ikjl', dm2a)

np.save(intfolder+"E2.npy", np.asfortranarray(dm2))
np.save(intfolder+"E1.npy", np.asfortranarray(dm1))

print ("trace of 2rdm", np.einsum('ijij',dm2))
print ("trace of 1rdm", np.einsum('ii',dm1))

nfro = 0
E1eff = dm1 # for state average
nev.writeNEVPTIntegrals(mc, dm1, dm2, E1eff, nfro, intfolder)
nev.write_ic_inputs(mc.nelecas[0]+mc.nelecas[1], mc.ncore, mc.ncas, nfro, mc.nelecas[0]-mc.nelecas[1],
                   'NEVPT2')

726fe58b935a4bf17e2843b0a44c530c127cac64
<mask token>

<mask token>
mf.__dict__.update(scf.chkfile.load(chkfile, 'scf'))
<mask token>
mc.__dict__.update(lib.chkfile.load(chkfile, 'mcscf'))
<mask token>
os.system('mkdir -p ' + intfolder)
<mask token>
shci.r2RDM(dm2a, norbAct, file2pdm)
<mask token>
dm1 /= nelecAct - 1
<mask token>
np.save(intfolder + 'E2.npy', np.asfortranarray(dm2))
np.save(intfolder + 'E1.npy', np.asfortranarray(dm1))
print('trace of 2rdm', np.einsum('ijij', dm2))
print('trace of 1rdm', np.einsum('ii', dm1))
<mask token>
nev.writeNEVPTIntegrals(mc, dm1, dm2, E1eff, nfro, intfolder)
nev.write_ic_inputs(mc.nelecas[0] + mc.nelecas[1], mc.ncore, mc.ncas, nfro,
    mc.nelecas[0] - mc.nelecas[1], 'NEVPT2')

<mask token>
r = 2.5 * 0.529177
atomstring = 'N 0 0 0; N 0 0 %g' % r
mol = gto.M(atom=atomstring, basis={'N': gto.basis.parse(
    """
N    S
      4.323000E+05           5.590000E-06          -1.230000E-06           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      6.470000E+04           4.351000E-05          -9.580000E-06           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      1.472000E+04           2.289300E-04          -5.051000E-05           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      4.170000E+03           9.650200E-04          -2.126400E-04           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      1.361000E+03           3.502190E-03          -7.753400E-04           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      4.912000E+02           1.129212E-02          -2.506240E-03           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      1.916000E+02           3.261283E-02          -7.365290E-03           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      7.941000E+01           8.329727E-02          -1.930167E-02           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      3.453000E+01           1.799857E-01          -4.471738E-02           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      1.558000E+01           3.050035E-01          -8.606647E-02           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      7.232000E+00           3.411593E-01          -1.332963E-01           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      3.382000E+00           1.774827E-01          -1.059655E-01           1.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      1.369000E+00           1.988409E-02           1.346673E-01           0.000000E+00           1.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      6.248000E-01          -1.246630E-03           4.339401E-01           0.000000E+00           0.000000E+00           1.000000E+00           0.000000E+00           0.000000E+00
      2.747000E-01           1.040110E-03           4.529490E-01           0.000000E+00           0.000000E+00           0.000000E+00           1.000000E+00           0.000000E+00
      1.192000E-01          -1.265900E-04           1.340216E-01           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           1.000000E+00
N    S
      0.04714                1.0000
N    P
      4.159000E+02           1.484100E-04           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      9.861000E+01           1.276340E-03           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      3.192000E+01           6.702420E-03           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      1.200000E+01           2.526170E-02           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      4.919000E+00           7.518943E-02           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      2.148000E+00           1.740151E-01           1.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      9.696000E-01           2.927921E-01           0.000000E+00           1.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      4.399000E-01           3.482648E-01           0.000000E+00           0.000000E+00           1.000000E+00           0.000000E+00           0.000000E+00
      1.978000E-01           2.559365E-01           0.000000E+00           0.000000E+00           0.000000E+00           1.000000E+00           0.000000E+00
      8.603000E-02           6.947929E-02           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           1.000000E+00
N    P
      0.03150                1.0000
N    D
      6.717000E+00           1.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      2.896000E+00           0.000000E+00           1.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      1.249000E+00           0.000000E+00           0.000000E+00           1.000000E+00           0.000000E+00           0.000000E+00
      5.380000E-01           0.000000E+00           0.000000E+00           0.000000E+00           1.000000E+00           0.000000E+00
      2.320000E-01           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           1.000000E+00
N    D
      0.0874                 1.0000
N    F
      3.829000E+00           1.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      1.795000E+00           0.000000E+00           1.000000E+00           0.000000E+00           0.000000E+00
      8.410000E-01           0.000000E+00           0.000000E+00           1.000000E+00           0.000000E+00
      3.940000E-01           0.000000E+00           0.000000E+00           0.000000E+00           1.000000E+00
N    F
      0.1510                 1.0000
N    G
      3.856000E+00           1.000000E+00           0.000000E+00           0.000000E+00
      1.702000E+00           0.000000E+00           1.000000E+00           0.000000E+00
      7.510000E-01           0.000000E+00           0.000000E+00           1.000000E+00
N    G
      0.3260                 1.0000
N    H
      2.875000E+00           1.000000E+00           0.000000E+00
      1.170000E+00           0.000000E+00           1.000000E+00
N    H
      0.5870                 1.0000
N    I
      2.099000E+00           1.0000000
N    I
      1.0410                 1.0000
"""
    )}, verbose=4, symmetry=0, spin=0)
mf = scf.RHF(mol)
chkfile = 'N2_HF.chk'
mf.__dict__.update(scf.chkfile.load(chkfile, 'scf'))
norbAct = 8
nelecAct = 10
norbFrozen = 0
mc = shci.SHCISCF(mf, norbAct, nelecAct)
chkfile = 'N2_SHCISCF.chk'
mc.__dict__.update(lib.chkfile.load(chkfile, 'mcscf'))
intfolder = 'int/'
os.system('mkdir -p ' + intfolder)
dm2a = np.zeros((norbAct, norbAct, norbAct, norbAct))
file2pdm = 'spatialRDM.0.0.txt'
file2pdm = file2pdm.encode()
shci.r2RDM(dm2a, norbAct, file2pdm)
dm1 = np.einsum('ikjj->ki', dm2a)
dm1 /= nelecAct - 1
dm2 = np.einsum('ijkl->ikjl', dm2a)
np.save(intfolder + 'E2.npy', np.asfortranarray(dm2))
np.save(intfolder + 'E1.npy', np.asfortranarray(dm1))
print('trace of 2rdm', np.einsum('ijij', dm2))
print('trace of 1rdm', np.einsum('ii', dm1))
nfro = 0
E1eff = dm1
nev.writeNEVPTIntegrals(mc, dm1, dm2, E1eff, nfro, intfolder)
nev.write_ic_inputs(mc.nelecas[0] + mc.nelecas[1], mc.ncore, mc.ncas, nfro,
    mc.nelecas[0] - mc.nelecas[1], 'NEVPT2')

import numpy as np
import math
from pyscf import gto, scf, ao2mo, mcscf, tools, lib
from pyscf.shciscf import shci
import NEVPT2Helper as nev
import os, sys
r = 2.5 * 0.529177
atomstring = 'N 0 0 0; N 0 0 %g' % r
mol = gto.M(atom=atomstring, basis={'N': gto.basis.parse(
    """
N    S
      4.323000E+05           5.590000E-06          -1.230000E-06           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      6.470000E+04           4.351000E-05          -9.580000E-06           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      1.472000E+04           2.289300E-04          -5.051000E-05           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      4.170000E+03           9.650200E-04          -2.126400E-04           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      1.361000E+03           3.502190E-03          -7.753400E-04           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      4.912000E+02           1.129212E-02          -2.506240E-03           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      1.916000E+02           3.261283E-02          -7.365290E-03           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      7.941000E+01           8.329727E-02          -1.930167E-02           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      3.453000E+01           1.799857E-01          -4.471738E-02           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      1.558000E+01           3.050035E-01          -8.606647E-02           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      7.232000E+00           3.411593E-01          -1.332963E-01           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      3.382000E+00           1.774827E-01          -1.059655E-01           1.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      1.369000E+00           1.988409E-02           1.346673E-01           0.000000E+00           1.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      6.248000E-01          -1.246630E-03           4.339401E-01           0.000000E+00           0.000000E+00           1.000000E+00           0.000000E+00           0.000000E+00
      2.747000E-01           1.040110E-03           4.529490E-01           0.000000E+00           0.000000E+00           0.000000E+00           1.000000E+00           0.000000E+00
      1.192000E-01          -1.265900E-04           1.340216E-01           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           1.000000E+00
N    S
      0.04714                1.0000
N    P
      4.159000E+02           1.484100E-04           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      9.861000E+01           1.276340E-03           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      3.192000E+01           6.702420E-03           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      1.200000E+01           2.526170E-02           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      4.919000E+00           7.518943E-02           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      2.148000E+00           1.740151E-01           1.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      9.696000E-01           2.927921E-01           0.000000E+00           1.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      4.399000E-01           3.482648E-01           0.000000E+00           0.000000E+00           1.000000E+00           0.000000E+00           0.000000E+00
      1.978000E-01           2.559365E-01           0.000000E+00           0.000000E+00           0.000000E+00           1.000000E+00           0.000000E+00
      8.603000E-02           6.947929E-02           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           1.000000E+00
N    P
      0.03150                1.0000
N    D
      6.717000E+00           1.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      2.896000E+00           0.000000E+00           1.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      1.249000E+00           0.000000E+00           0.000000E+00           1.000000E+00           0.000000E+00           0.000000E+00
      5.380000E-01           0.000000E+00           0.000000E+00           0.000000E+00           1.000000E+00           0.000000E+00
      2.320000E-01           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           1.000000E+00
N    D
      0.0874                 1.0000
N    F
      3.829000E+00           1.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      1.795000E+00           0.000000E+00           1.000000E+00           0.000000E+00           0.000000E+00
      8.410000E-01           0.000000E+00           0.000000E+00           1.000000E+00           0.000000E+00
      3.940000E-01           0.000000E+00           0.000000E+00           0.000000E+00           1.000000E+00
N    F
      0.1510                 1.0000
N    G
      3.856000E+00           1.000000E+00           0.000000E+00           0.000000E+00
      1.702000E+00           0.000000E+00           1.000000E+00           0.000000E+00
      7.510000E-01           0.000000E+00           0.000000E+00           1.000000E+00
N    G
      0.3260                 1.0000
N    H
      2.875000E+00           1.000000E+00           0.000000E+00
      1.170000E+00           0.000000E+00           1.000000E+00
N    H
      0.5870                 1.0000
N    I
      2.099000E+00           1.0000000
N    I
      1.0410                 1.0000
"""
    )}, verbose=4, symmetry=0, spin=0)
mf = scf.RHF(mol)
chkfile = 'N2_HF.chk'
mf.__dict__.update(scf.chkfile.load(chkfile, 'scf'))
norbAct = 8
nelecAct = 10
norbFrozen = 0
mc = shci.SHCISCF(mf, norbAct, nelecAct)
chkfile = 'N2_SHCISCF.chk'
mc.__dict__.update(lib.chkfile.load(chkfile, 'mcscf'))
intfolder = 'int/'
os.system('mkdir -p ' + intfolder)
dm2a = np.zeros((norbAct, norbAct, norbAct, norbAct))
file2pdm = 'spatialRDM.0.0.txt'
file2pdm = file2pdm.encode()
shci.r2RDM(dm2a, norbAct, file2pdm)
dm1 = np.einsum('ikjj->ki', dm2a)
dm1 /= nelecAct - 1
dm2 = np.einsum('ijkl->ikjl', dm2a)
np.save(intfolder + 'E2.npy', np.asfortranarray(dm2))
np.save(intfolder + 'E1.npy', np.asfortranarray(dm1))
print('trace of 2rdm', np.einsum('ijij', dm2))
print('trace of 1rdm', np.einsum('ii', dm1))
nfro = 0
E1eff = dm1
nev.writeNEVPTIntegrals(mc, dm1, dm2, E1eff, nfro, intfolder)
nev.write_ic_inputs(mc.nelecas[0] + mc.nelecas[1], mc.ncore, mc.ncas, nfro,
    mc.nelecas[0] - mc.nelecas[1], 'NEVPT2')

import numpy as np
import math
from pyscf import gto, scf, ao2mo, mcscf, tools, lib
from pyscf.shciscf import shci
import NEVPT2Helper as nev
import os, sys

# make your molecule here
r = 2.5 * 0.529177
atomstring = "N 0 0 0; N 0 0 %g"%(r)
mol = gto.M(
    atom = atomstring,
    basis = {'N': gto.basis.parse('''
N    S
      4.323000E+05           5.590000E-06          -1.230000E-06           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      6.470000E+04           4.351000E-05          -9.580000E-06           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      1.472000E+04           2.289300E-04          -5.051000E-05           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      4.170000E+03           9.650200E-04          -2.126400E-04           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      1.361000E+03           3.502190E-03          -7.753400E-04           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      4.912000E+02           1.129212E-02          -2.506240E-03           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      1.916000E+02           3.261283E-02          -7.365290E-03           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      7.941000E+01           8.329727E-02          -1.930167E-02           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      3.453000E+01           1.799857E-01          -4.471738E-02           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      1.558000E+01           3.050035E-01          -8.606647E-02           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      7.232000E+00           3.411593E-01          -1.332963E-01           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      3.382000E+00           1.774827E-01          -1.059655E-01           1.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      1.369000E+00           1.988409E-02           1.346673E-01           0.000000E+00           1.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      6.248000E-01          -1.246630E-03           4.339401E-01           0.000000E+00           0.000000E+00           1.000000E+00           0.000000E+00           0.000000E+00
      2.747000E-01           1.040110E-03           4.529490E-01           0.000000E+00           0.000000E+00           0.000000E+00           1.000000E+00           0.000000E+00
      1.192000E-01          -1.265900E-04           1.340216E-01           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           1.000000E+00
N    S
      0.04714                1.0000
N    P
      4.159000E+02           1.484100E-04           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      9.861000E+01           1.276340E-03           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      3.192000E+01           6.702420E-03           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      1.200000E+01           2.526170E-02           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      4.919000E+00           7.518943E-02           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      2.148000E+00           1.740151E-01           1.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      9.696000E-01           2.927921E-01           0.000000E+00           1.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      4.399000E-01           3.482648E-01           0.000000E+00           0.000000E+00           1.000000E+00           0.000000E+00           0.000000E+00
      1.978000E-01           2.559365E-01           0.000000E+00           0.000000E+00           0.000000E+00           1.000000E+00           0.000000E+00
      8.603000E-02           6.947929E-02           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           1.000000E+00
N    P
      0.03150                1.0000
N    D
      6.717000E+00           1.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      2.896000E+00           0.000000E+00           1.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      1.249000E+00           0.000000E+00           0.000000E+00           1.000000E+00           0.000000E+00           0.000000E+00
      5.380000E-01           0.000000E+00           0.000000E+00           0.000000E+00           1.000000E+00           0.000000E+00
      2.320000E-01           0.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00           1.000000E+00
N    D
      0.0874                 1.0000
N    F
      3.829000E+00           1.000000E+00           0.000000E+00           0.000000E+00           0.000000E+00
      1.795000E+00           0.000000E+00           1.000000E+00           0.000000E+00           0.000000E+00
      8.410000E-01           0.000000E+00           0.000000E+00           1.000000E+00           0.000000E+00
      3.940000E-01           0.000000E+00           0.000000E+00           0.000000E+00           1.000000E+00
N    F
      0.1510                 1.0000
N    G
      3.856000E+00           1.000000E+00           0.000000E+00           0.000000E+00
      1.702000E+00           0.000000E+00           1.000000E+00           0.000000E+00
      7.510000E-01           0.000000E+00           0.000000E+00           1.000000E+00
N    G
      0.3260                 1.0000
N    H
      2.875000E+00           1.000000E+00           0.000000E+00
      1.170000E+00           0.000000E+00           1.000000E+00
N    H
      0.5870                 1.0000
N    I
      2.099000E+00           1.0000000
N    I
      1.0410                 1.0000
'''),
},
    verbose=4,
    symmetry=0,
    spin = 0)

mf = scf.RHF(mol)
chkfile = 'N2_HF.chk'
mf.__dict__.update(scf.chkfile.load(chkfile, 'scf'))

norbAct = 8
nelecAct = 10
norbFrozen = 0

mc = shci.SHCISCF(mf, norbAct, nelecAct)
chkfile = 'N2_SHCISCF.chk'
mc.__dict__.update( lib.chkfile.load(chkfile, 'mcscf') )

#this is the scratch file for writing potentially larger integral files
intfolder = "int/"
os.system("mkdir -p "+intfolder)

dm2a = np.zeros((norbAct, norbAct, norbAct, norbAct))
file2pdm = "spatialRDM.0.0.txt"
file2pdm = file2pdm.encode()  # .encode for python3 compatibility
shci.r2RDM(dm2a, norbAct, file2pdm)
dm1 = np.einsum('ikjj->ki', dm2a)
dm1 /= (nelecAct - 1)
#dm1, dm2a = mc.fcisolver.make_rdm12(0, mc.ncas, mc.nelecas)
dm2 = np.einsum('ijkl->ikjl', dm2a)

np.save(intfolder+"E2.npy", np.asfortranarray(dm2))
np.save(intfolder+"E1.npy", np.asfortranarray(dm1))

print ("trace of 2rdm", np.einsum('ijij',dm2))
print ("trace of 1rdm", np.einsum('ii',dm1))

nfro = 0
E1eff = dm1 # for state average
nev.writeNEVPTIntegrals(mc, dm1, dm2, E1eff, nfro, intfolder)
nev.write_ic_inputs(mc.nelecas[0]+mc.nelecas[1], mc.ncore, mc.ncas, nfro, mc.nelecas[0]-mc.nelecas[1],
                   'NEVPT2')
