Exemplo n.º 1
0
    def set_active_space(self, irreplist , exlist , senlist, detfile ):
        """
        Generates a determinantfile in a given active space determined by irreps. Remark at this moment the active space should be concatenated without gaps.
        """
        self.set_irrep_info() #to set the cumulative array of orbital indices where new irreps start.
        nup,  ndown, norb  = 0, 0 ,0
        activehf = [[],[]]
        for irrep in irreplist:
            nup += self.values['DOCC'][irrep]
            ndown += self.values['DOCC'][irrep]
            nup += self.values['SOCC'][irrep]
            norb += self.occurences[irrep]
            activehf[0] += [1]*self.values['DOCC'][irrep] + [0] * (self.occurences[irrep] - self.values['DOCC'][irrep])
            activehf[1] += [1]*self.values['DOCC'][irrep]  + [0] * (self.occurences[irrep] - self.values['DOCC'][irrep])

        activehf[0].reverse()
        activehf[1].reverse()
        activehf = ( ''.join(map(str,activehf[0]))  , ''.join(map(str, activehf[1]) )  )
            
        upstring , downstring = self.get_hf_orbs() #to determine the frozen orbitals
        frozen = upstring[-self.cum[irreplist[0]] :] #we presume that if there is an odd number of electrons, it is in the activespace.
        virtual = upstring[:-1*(self.cum[irreplist[-1] + 1 ] ) ]
        print 'frozen' , frozen , 'virtual' , virtual

        dw.cimain(nup,ndown ,norb , [range(1,nup+ndown+1), [] ] , senlist ,fname = detfile ,ref = [lambda x , y, z : activehf ], add_frozen = 0, frozenstring = frozen , virtualstring = virtual) 
Exemplo n.º 2
0
def main_opt(*args, **kwargs):
    ciflowoutputfile = "ciflowoutput2.txt"
    flowname = "flow.dat"
    detfile1 = "determinants1.dat"
    detfile2 = "determinants2.dat"
    detfile3 = "determinants3.dat"
    detfile4 = "determinants4.dat"
    detfile5 = "determinants5.dat"
    detfile6 = "determinants6.dat"
    detfile7 = "frozencisdpibenzene.dat"
    detfile8 = "cisdpibenzenesigma.dat"
    detfile9 = "CISDirrepref+cisd.dat"
    detfile10 = "CISDT(P).dat"
    detfile11 = "lin_hyb.dat"
    detfile12 = "ref2.dat"
    detfile20 = "sen0.dat"
    detfile21 = "sen2.dat"
    detfile22 = "sen4.dat"
    detfile23 = "sen6.dat"
    detfile24 = "sen8.dat"
    detfile25 = "sen10.dat"
    detfile30 = "sen0-4.dat"
    change_ints = False  # if you changed the standard psi4 integrals somewhere during the process
    psienergies = []  # provide here a list of energies to be calculated by psi.
    methods = ["file", detfile2, "mmind", "file", detfile3] + ["doci", "local", "file", detfile21, "file", detfile22]
    methods = ["file", detfile30]
    extra = None
    basissets = ["6-31g"]
    import numpy as np

    runlist = np.arange(5.1, 8.1, 0.01)
    # atoms = [6 , 8]
    # atoms = [4]
    # atoms = [1,1,1,1 , 1, 1]
    atoms = [4, 1, 1]
    # atoms = [4,1,1] #beh2
    # atoms = [7,7]
    # atoms = [7,8] #NO+
    # atoms = [6,6,6,6,6,6,1,1,1,1,1,1] #benzene
    # runlist = [x*math.pi/180. for x in range(55,61) ]#+ [59.5]] #, 60]  ] #angle between two triangles in benzene.
    name = "phdsenhierbeh2sen04cisdmmin"
    rootdir = "./results/phdsenhierbeh26-31g2"  # relative to the directory that contains this script
    # rootdir = './results/phdsenebeccpvdzfcimminc1' #relative to the directory that contains this script
    exe = "ciflow.x"
    elemdir = "matrixelements"
    # elemdir = 'matrixelements_otherbasis'
    # elemdir = 'random_hamiltonians'
    # elemdir = 'output_run'
    elemdir = "."

    # generate_dir(rootdir , exe  )
    # generate_dir(rootdir , exe , args= ["ni_system.dat"], prefix = r'./ham_patrick/hamnoplus')
    # generate_dir(rootdir , exe )
    # generate_dir(rootdir , exe , args= ["ni_system.dat"])
    shutil.copy(exe, rootdir)  # When the matrixelements are already present.
    os.chdir(rootdir)  # When the matrixelements are already present.
    # create_matrix_elements(elemdir , basissets, runlist, atoms, chmult = (0,1) , moltype = 'h6', package = 'psi' , units = 'angstrom', path_mo = '../../../../mointegrals/mointegrals.so' , DOCC = None, energies = psienergies, sym = 'c1', hdf5 = False, guess = 'read', extrapar = 0.741, ref = 'rhf', su = False, basispath = '../../../data/basissets/')#, extrapar = 1.398) #extrapar is size for benzene, and angle for c2v, benzene extrapar = 1.398 C-C distance , extrapar = 104.479848 for angle h2o, 0.741 = extrapar for h2 equilibrium geometry in but
    # create_matrix_elements(elemdir , basissets, runlist, atoms, chmult = (0,1) , moltype = 'atom', package = 'psi' , units = 'angstrom', path_mo = '../../../../mointegrals/mointegrals.so' , DOCC = None, energies = psienergies, sym = 'c1', hdf5 = False, guess = 'read', extrapar = 0.741, ref = 'rhf', su = False, basispath = '../../../data/basissets/')#, extrapar = 1.398) #extrapar is size for benzene, and angle for c2v, benzene extrapar = 1.398 C-C distance , extrapar = 104.479848 for angle h2o, 0.741 = extrapar for h2 equilibrium geometry in but

    outputfile = open(ciflowoutputfile, "w")
    # fileinfo = lambda x: float(re.search(r'([\-+]?\d+[\.,]?\d+[eEDd]?[\-+]?\d*)[-\w\d]*\.[m]?out' , x).group(1))
    fileinfo = lambda x: float(re.search(r"([\-+]?\d+[\.,]+\d+[eEd]?[\-+]?\d*)[-\w\d_]*\.[m]?dat", x).group(1))
    # fileinfo = lambda x: float(re.search(r'FCIunit(\d+)\.[m]?dat' , x).group(1))
    # fileinfo = lambda x: float(re.search(r'.*-[\w\d]*([\-+]?\d+[\.,]?\d+[eEDd]?[\-+]?\d*)orthon\.h5' , x).group(1))
    # fileinfo = lambda x: float(re.search(r'([\-+]?\d+[\.,]?\d+[eEDd]?[\-+]?\d*)[-\w\d]*\.out' , x).group(1))
    # fileinfo = lambda x: float(re.search(r'hamnoplussto-3gpatrick([\-+]?\d+[\.,]?\d+[eEDd]?[\-+]?\d*)new\.out' , x).group(1))

    hamfiles = {}
    # search = r'psi.+%s.+mout'
    search = r"hampsi0_%s.+2hmmin0.dat"
    # search = r'hampsi0_%s.+local2.dat'
    # search = 'hamnoplus.*%s.+out'
    # search = r'hampsi.+%s.+FCI.+hmmin0.dat'
    # search = r'randomham.+\d+\.dat'
    # search = r'ham.+%s.+out'
    # search = r'hampsi0.+%s.+smmind0.dat'
    # search = r'ham.+%s.+FCIunit\d+\.dat'
    # search = r'psi.+%s.+orthon.h5'
    for basis in basissets:
        hamfiles[basis] = fc.File_Collector(
            elemdir,
            search=search % basis,
            notsearch=r"(\.sw\w)|(unitary)",
            sortfunction=fileinfo,
            filterf=lambda x: fileinfo(x) >= 5.1 and fileinfo(x) <= 1000.0,
        )
        # hamfiles[basis] = fc.File_Collector( '.', search = search %basis ,notsearch = r'\.sw\w',sortfunction = fileinfo, filterf =  lambda x : fileinfo(x) <= 10. and fileinfo(x) >= 2  and fileinfo(x) in runlist  and not '.sw' in x  )
        # hamfiles[basis] = fc.File_Collector(elemdir , search = search ,notsearch = r'\.sw\w',sortfunction = fileinfo, filterf =  lambda x : fileinfo(x) >= -1 and fileinfo(x) < 1000. )

    # fileinfo2 = lambda x: float(re.search(r'psi0_sto-3g1.29outputfciunit(\d+).dat' , x).group(1))
    # search = r'psi.+outputfciunit\d+.dat'
    # outputfilesfci = fc.File_Collector('output_files', search = search  ,notsearch = r'\.sw\w',sortfunction = fileinfo2, filterf =  lambda x : fileinfo2(x) >= 0 and fileinfo2(x) < 10000. )
    # hamfiles[basissets[0]].plotfiles += ['ni_system.dat']
    # print hamfiles[basissets[0]]

    afh = "R"
    for basis in basissets:
        fname = name + "_" + basis + ".dat"
        psir = rp.PsiReader(
            hamfiles[basis].plotfiles[0], isbig=False, numorbs=-1, read_ints=False
        )  # just to get number of electrons and orbitals
        # dw.generate_all_ex(psir.values['nalpha'],psir.values['nbeta'],psir.values['norb'], ( psir.get_hf_orbs()[0][:], psir.get_hf_orbs()[1][:] )  , aname = 'determinants', addfrozen = 0)
        # dw.biggest_det_ex(outputfilesfci.plotfiles[index])
        # dw.generate_all_sen(psir.values['nalpha'],psir.values['nbeta'],psir.values['norb'], 'sen', addfrozen = 0)
        # reflist = dw.cimain(psir.values['nalpha'],psir.values['nbeta'] ,psir.values['norb'], [1] , [] , pairex = True)
        dw.cimain(
            psir.values["nalpha"] - 1,
            psir.values["nbeta"] - 1,
            psir.values["norb"] - 1,
            [[], []],
            [0, 4],
            fname=detfile30,
            ref=[lambda x, y, z: psir.get_hf_orbs()],
            add_frozen=1,
        )  # CISD
        # dw.cimain(psir.values['nalpha'],psir.values['nbeta'] ,psir.values['norb'],[[1,2,3] , []], [] ,fname = detfile14 ,ref =  [lambda x , y , z : psir.get_hf_orbs()] ) #CISD
        # dw.cimain(psir.values['nalpha'],psir.values['nbeta'] ,psir.values['norb'],[[1,2,3,4] , []], [] ,fname = detfile15 ,ref =  [lambda x , y , z : psir.get_hf_orbs()] ) #CISD
        # dw.cimain(psir.values['nalpha'],psir.values['nbeta'] ,psir.values['norb'],[[] ,[]], [0,2] ,fname = detfile2 ,ref = [lambda x , y , z : dw.get_hf_det(x,y,z)]) #SEN0-2
        with open(fname, "w") as f:
            header = create_header(afh, methods, psienergies, extra=extra)
            print header
            f.write(header)
            for index, matrixelements in enumerate(hamfiles[basis].plotfiles):
                print matrixelements
                if change_ints:  # True if you want to change the standard psi4 integrals.
                    psir = rp.PsiReader(matrixelements, isbig=True, numorbs=60, read_ints=True)  # for benzene.
                    if "1.05" not in matrixelements:
                        # psir.set_active_space([1,2] , [1,2] , [] , detfile7) #for pisystem of deformed benzene
                        psir.set_active_space([1], [[1, 2], []], [], detfile7)  # for pisystem of deformed benzene
                    else:
                        # psir.set_active_space([2,3,4,5] , [1,2] , [] , detfile7) #for pisystem of benzene
                        psir.set_active_space([1], [[1, 2], [2]], [], detfile7)  # for pisystem of benzene
                    # psir.set_active_space([0,1,2,3] , [1] , [] , detfile3) #for pisystem of deformed benzene
                    # psir.set_active_space([1,2] , [1,2] , [] , detfile4) #for pisystem of deformed benzene
                    # psir.keep_orbs(56)
                    newname = os.path.basename(matrixelements) + "new.dat"
                    psir.create_output(newname)
                    matrixelements = newname

                create_ciflow_input_file(matrixelements, methods, fname=flowname)
                ci_flow = ""
                if methods:
                    try:
                        ci_flow = ""
                        process = subprocess.Popen(["./ciflow.x"], stdin=open(flowname, "r"), stdout=subprocess.PIPE)
                        for line in iter(process.stdout.readline, ""):
                            sys.stdout.write(line)  # writes intermediate output to screen.
                            outputfile.write(line)
                            outputfile.flush()
                            ci_flow += line
                    except Exception as e:
                        print "Ciflow gave the following error", e
                        print ci_flow
                        pass
                energies = process_output(ci_flow)
                mullikencharge = process_output(
                    ci_flow, regexp="Mulliken[\s\w]+:\s*([\-+]?\d+[\.,]?\d*[eEDd]?[\-+]?\d*)"
                )
                if psienergies:  # True if the list is not empty
                    psir = rp.PsiReader(matrixelements, isbig=False, numorbs=-1, read_ints=False)
                    energies += [x[1] for x in psir.extract_energies()]

                print_output(matrixelements, energies, methods)
                f.write("%.15f\t%s\t%s\n" % (runlist[index], "\t".join(energies), "\t".join(mullikencharge)))
                if change_ints:
                    os.remove(matrixelements)

    shutil.copy("../../htest.py", ".")
    os.remove(exe)  # can be handy to keep it in the dir, to exactly reproduce results later. (but be warned its big.)
    outputfile.close()
    try:
        generate_dir("output_files", None, prefix=r"output[\w_]+.dat")
        os.chdir("..")
        generate_dir("unitaries", None, prefix="unitary_")
        os.chdir("..")
        generate_dir("matrixelements_otherbasis", None, prefix="hamp")
        os.chdir("..")
    except:
        pass

    if os.getenv("VSC_INSTITUTE_LOCAL") != "gent":
        plotter = pf.Plot_Files(fname)
        plotter.data[0].depvar["yas"] = "Energy"  # change the future y-axis label
        plotter.data[0].depvar["xas"] = "$R$"  # is normally set to the column header 0
        plotter.data[0].units["x"] = r"(\AA)"
        plotter.data[0].units["y"] = r"(E$_h$)"
        plotter.generate_plot(
            xlimg=None, ylimg=None, exname="", prefix=True, titel=name, name=fname, depcol=0, ylist=None
        )
Exemplo n.º 3
0
def main():
    name = 'beh2cc-pvdzcisddocidebug'
    hamdirname = "beh2ccpvdzham"
    pokemon = os.environ['VSC_INSTITUTE_CLUSTER']
    print 'we have run this script on cluster: ', pokemon
    active_space = False
    flowname = "flow.dat"
    detfile1 = "cisddeterminants.dat"
    detfile2 = "cisddocideterminants.dat"
    detfile3 = 'CIS(P)'
    detfile4 = 'CISD(P)'
    detfile6 = 'fcifile.dat'
    detfile7 = 'be_ccpv5z96100.txt'
    detfile10 = "linhyb23p.dat"
    detfile11 = "linhyb2p.dat"
    #methods = [ "big", detfile6, "loadham"] #everything on#everything on
    methods = ["file", detfile1, "hmmin", "file", detfile10,
               "loadham"]  #everything on#everything on
    methods = [
        "doci", "loadham", "file", detfile3, "loadham", "file", detfile4,
        "loadham"
    ]  #everything on#everything on
    #methods = []
    #psienergies = ['fci']
    psienergies = []
    basissets = ['cc-pvdz']
    #runlist = [ 3.4 , 3.5 ,  3.8 , 3.9 , 4. ,  4.5 ,4.8 ,  5., 5.6, 6.] #BeH2 (linear)
    #runlist = [1.81625952410, 1.97501269880, 2.13376587350, 2.29251904820, 2.45127222290, 2.61002539760, 2.76877857230, 2.92753174700, 3.08628492170, 3.1 , 3.2, 3.3 , 3.4 , 3.5 , 4. , 4.5 , 5.] #BeH2
    runlist = [
        0.7, 0.9, 1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.81625952410,
        1.97501269880, 2.13376587350, 2.29251904820, 2.45127222290,
        2.61002539760, 2.76877857230, 2.92753174700, 3.08628492170, 3.1, 3.2,
        3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4., 4.5, 5., 6.
    ]  #BeH2
    #runlist = [0.6402695456, 0.7 , 0.7461049954, 0.8 , 0.8519404452, 0.9 , 0.957775895, 1. , 1.0636113448, 1.1, 1.1694467946, 1.2 , 1.2752822444, 1.3, 1.3811176942, 1.4, 1.486953144, 1.5, 1.5927885938, 1.6, 1.6986240436 , 1.72 , 1.8 , 1.85 , 1.9 , 1.95 , 2. , 2.05, 2.2278012926, 2.4 , 2.6 , 3. , 3.5 , 4. , 4.5 , 5. ,6.]#, 2.1 , 2.15, 2.2278012926 ]#, 1.8044594934, 1.9102949432, 2.016130393, 2.1219658428, 2.2278012926, 2.3336367424 ] #H2O (c2v)
    #runlist = [2.3,2.4,2.5,2.6,2.7,2.8,2.9,3.,3.2,3.3, 3.5,3.8 , 4.]
    #runlist = [2.32,2.42,2.52,2.61,2.71,2.99,3.09,3.19,3.38,3.57, 3.76,4.05]
    #runlist = [1.9] +  runlist
    #runlist = [1.81625952410, 1.97501269880, 2.13376587350, 2.29251904820, 2.45127222290, 2.61002539760, 2.76877857230, 2.92753174700, 3.08628492170, 3.1 , 3.2, 3.3 , 3.4 , 3.5 , 4. , 4.5 , 5.] #BeH2
    #runlist = [2.45127222290, 2.61002539760, 2.76877857230, 2.92753174700, 3.08628492170, 3.1 , 3.2, 3.3 , 3.4 , 3.5 , 4. , 4.5 , 5.] #BeH2
    #runlist = []

    arrayid = 2
    #hereunder for array jobs for heavy calculations. But make sure it is always defined
    #arrayid =int(os.getenv('PBS_ARRAYID'))
    #arraystep = 1
    #name += str(arrayid)
    #try:
    #    runlist = runlist[(arrayid-1) * arraystep : arrayid *arraystep]
    #except:
    #    print 'encoutered exception in cut of runlist.'
    #    runlist = runlist[-4:-1]

    #runlist = [1.38, 1.4, 1.45, 1.5, 1.65750634940, 1.81625952410, 1.97501269880] #, 2.13376587350,2.2 ,  2.29251904820, 2.35 , 2.45127222290, 2.5 , 2.61002539760,2.7 ,  2.76877857230, 2.92753174700, 3.0 ,  3.08628492170, 3.1 , 3.2, 3.3 , 3.4 , 3.5 , 3.6 ,3.7 , 3.8 , 3.9 , 4. , 4.5 , 5. , 6.] #BeH2 (linear)
    #runlist = [2.13376587350,2.2 ,  2.29251904820, 2.35 , 2.45127222290, 2.5 ]# , 2.61002539760,2.7 ,  2.76877857230, 2.92753174700, 3.0 ,  3.08628492170, 3.1 , 3.2, 3.3 , 3.4 , 3.5 , 3.6 ,3.7 , 3.8 , 3.9 , 4. , 4.5 , 5. , 6.] #BeH2 (linear)
    #runlist = [ 3.08628492170, 3.1 , 3.2, 3.3 , 3.4 ,  4. ,   5. , 6.] #BeH2 (linear)

    #runlist = [0.86374047590, 1.02249365060, 1.18124682530, 1.34000000000, 1.49875317470, 1.65750634940, 1.81625952410, 1.97501269880, 2.13376587350, 2.29251904820, 2.45127222290, 2.61002539760, 2.76877857230, 2.92753174700, 3.08628492170 ] #BeH2
    #runlist = [0.6402695456, 0.7461049954, 0.8519404452, 0.957775895, 1.0636113448, 1.1694467946, 1.2752822444, 1.3811176942, 1.486953144, 1.5927885938, 1.6986240436 , 2.2278012926 ]#, 1.8044594934, 1.9102949432, 2.016130393, 2.1219658428, 2.2278012926, 2.3336367424 ] #H2O
    #runlist = [ 1.2 , 1.6] #[ 0.7,0.8 ,0.8519404452, 0.957775895, 1.1694467946, 1.2752822444, 1.3811176942]#, 1.8044594934, 1.9102949432, 2.016130393, 2.1219658428, 2.2278012926, 2.3336367424 ] #H2O
    #runlist = [0.848, 0.9 , 0.973, 1.0 , 1.098, 1.223, 1.3, 1.348, 1.4, 1.473,1.5,  1.598, 1.723,1.8 ,  1.848, 1.973] #N2
    #atoms = [7,7] # set DOCC = [3, 0 ,0, 0,0 , 2, 1 ,1]
    #atoms = [1, 1,1,1,1,1,1,1 ] #h8
    #atoms = [8, 1,1 ]
    atoms = [4, 1, 1]
    #atoms = [6,6,6,6,6,6,1,1,1,1,1,1] #benzene
    #import math
    #runlist = [x*math.pi/180. for x in range(55,60) + [59.9 , 60]  ] #angle between two triangles in benzene.

    print 'Start to load necessary modules.'
    os.system('module swap cluster/%s' % pokemon)
    os.system('module load PSI/4.0b6-20160201-intel-2016a-mt-Python-2.7.11')
    os.system('module load arpack-ng/3.3.0-intel-2016a')
    os.system('module load matplotlib')
    os.system('module load h5py')
    #os.system('module load Boost/1.55.0-ictce-7.1.2-Python-2.7.8')
    os.system('export MKL_NUM_THREADS=16')
    #os.system('export KMP_STACKSIZE=32m')

    ORIGDIR = os.getenv('HOME')
    mofile = os.path.join(ORIGDIR,
                          'devel/CIFlow/lib/mointegrals_%s.so' % pokemon)
    exefile = os.path.join(ORIGDIR, 'devel/CIFlow/bin/ciflow_%s.x' % pokemon)
    hamdir = os.path.join(ORIGDIR, hamdirname)
    #det_file = os.path.join(ORIGDIR, detfile10 )
    print 'We submitted the script in: ', ORIGDIR
    print 'Psi 4 plugin is at: ', mofile

    WORKDIR = os.path.join(os.getenv('VSC_SCRATCH_NODE'),
                           os.getenv('PBS_JOBID'))

    if os.path.isdir(WORKDIR):
        shutil.rmtree(WORKDIR)
    os.mkdir(WORKDIR)
    print 'Workdir is: ', WORKDIR

    shutil.copy(mofile, WORKDIR)
    shutil.copy(exefile, WORKDIR)
    hamdest = os.path.join(WORKDIR, hamdirname)
    shutil.copytree(hamdir, hamdest)
    #shutil.move(det_file,WORKDIR)

    os.chdir(WORKDIR)
    print 'We work on node: ', os.getenv('HOSTNAME')

    #PSIINPUT = os.path.join(os.getcwd() , 'output_run')
    #print 'We Start to create the outputdir ' ,PSIINPUT
    #if os.path.isdir(PSIINPUT):
    #    shutil.rmtree(PSIINPUT)
    #os.mkdir(PSIINPUT)

    #angle = 104.479848
    #for basis in basissets:
    #    for r in runlist:
    #        #positions = [[0,0,0],[0,0,r],[0,0,-1*r]] #for molecules like beh2
    #        #positions = [[0,0,0],[0,0,r]] #for molecules like n2
    #        #positions = [[0,0,0],[0,0,r],[0,0,2*r], [0,0,3*r], [0,0,4*r] , [0,0,5*r] , [0,0,6*r], [0,0,7*r]] #For H_8
    #        positions = [[''],[1, r],[1, r, 2 , angle]] #for molecules like h2o
    #        #positions = [[0,0,0]] #for an atom
    #        #positions = ht.benzene(r,  1.398) #REMARK we run over the angle -> r in runlist, and keep the radius of the circle on which all the C atoms are placed constant to extrapar, (extrapar = 1.398 A is standard)
    #        ht.input_psi(os.path.join('output_run' ,"psi%.2f" %(r) +"basis"+basis+  ".dat"), basis ,name= 'mol' , charge_mult = (0,1) , atomlist = atoms , positions = positions , units = 'angstrom' , ref = 'rhf', userbasis = False, path_to_plugin = './mointegrals_%s.so' %pokemon, DOCC = None, sym = None, energies = psienergies)

    print 'Contents of rundir before run are: ', os.listdir(os.getcwd())
    #for file in os.listdir(PSIINPUT):
    #    print 'processing psi input file: ' , file
    #    exfile = os.path.join('output_run',file)
    #    os.system('psi4 ' + exfile)

    #print 'Contents of rundir after run are: ', os.listdir(os.getcwd())
    #print 'Contents of inputdir are: ', os.listdir('./output_run')

    hamfiles = File_Collector(
        '.',
        search=r'psi.+out',
        notsearch=r'\.sw\w',
        sortfunction=lambda x: float(
            re.search(r'([\-+]?\d+[\.,]?\d+[eEDd]?).*\.m?out', x).group(1)),
        filterf=lambda x: (float(
            re.search(r'([\-+]?\d+[\.,]?\d+[eEDd]?[\-+]?\d*).*\.m?out', x).
            group(1)) == round(runlist[arrayid], 2)))
    #hamfiles =File_Collector('output_run', search = r'psi.+out' ,notsearch = r'\.sw\w', filterf = lambda x: float(re.search(r'([\-+]?\d+[\.,]?\d+[eEDd]?[\-+]?\d*).*\.m?out' , x).group(1)) > 1.1)

    psir = rp.PsiReader(hamfiles.plotfiles[0],
                        isbig=False,
                        numorbs=-1,
                        read_ints=False)

    #frozen = [1,0,0,0,0,1,0,0]  ; virtual = [1,1,1,1,1,2,0,0]; active = [5,0,2,2,0,4,3,3]
    #assert( sum(frozen) + sum(virtual) + sum(active) == psir.values['norb'])
    #dw.cimain(psir.values['nalpha'] - sum(frozen),psir.values['nbeta'] -sum(frozen)  ,psir.values['norb'] - sum(frozen) - sum(virtual) , [[1,2], []], [],fname = detfile1 ,ref = [lambda x , y , z : psir.get_hf_orbs(  frozen = frozen , virtual = virtual )] , active = active, frozen =  frozen, virtual = virtual ,add_frozen = 0, add_virtual = 0)
    #dw.cimain(psir.values['nalpha'] - sum(frozen),psir.values['nbeta'] -sum(frozen)  ,psir.values['norb'] - sum(frozen) - sum(virtual) , [[1,2], [2,3]], [],fname = detfile10 ,ref = [lambda x , y , z : psir.get_hf_orbs(  frozen = frozen , virtual = virtual )] , active = active, frozen =  frozen, virtual = virtual ,add_frozen = 0, add_virtual = 0)
    #dw.cimain(psir.values['nalpha'],psir.values['nbeta'], psir.values['norb'] , [[1,2],[2]], [] , fname = detfile11 ,add_frozen = 0, add_virtual = 0,ref =  [ lambda x , y , z : psir.get_hf_orbs()]   ) #CISDD
    #dw.cimain(psir.values['nalpha'],psir.values['nbeta'], psir.values['norb'] , [[1,2],[]], [0] , fname = detfile2 ,add_frozen = 0, add_virtual = 0,ref =  [ lambda x , y , z : psir.get_hf_orbs()]   ) #CISDDOCI
    dw.cimain(psir.values['nalpha'],
              psir.values['nbeta'],
              psir.values['norb'], [[], [1]], [],
              fname=detfile3,
              add_frozen=0,
              ref=[lambda x, y, z: psir.get_hf_orbs()])  #CIS(P)
    dw.cimain(psir.values['nalpha'],
              psir.values['nbeta'],
              psir.values['norb'], [[], [1, 2]], [],
              fname=detfile4,
              add_frozen=0,
              ref=[lambda x, y, z: psir.get_hf_orbs()])  #CISD(P)
    #dw.cimain(psir.values['nalpha'],psir.values['nbeta'], psir.values['norb'],[[1,2], [] ],[]  , fname = detfile1 ,add_frozen = 0, ref =  [lambda x , y , z : psir.get_hf_orbs()]) #CISD
    #dw.cimain(psir.values['nalpha']-1,psir.values['nbeta']-1, psir.values['norb']-1,[[1,2,3,4], [] ],[]  , fname = detfile6 ,add_frozen = 1, ref =  [lambda x , y , z : dw.get_hf_det(x,y,z)] ) #FCI
    #dw.cimain(psir.values['nalpha'],psir.values['nbeta'], psir.values['norb'],[range(1,psir.values['nbeta']*2 +1), [] ],[]  , fname = detfile6 ,add_frozen = 0, ref =  [lambda x , y , z : dw.get_hf_det(x,y,z)] ) #FCI
    afh = 'R'
    for basis in basissets:
        fname = "ciflowresults_" + basis + ".dat"
        with open(fname, 'w') as f:
            header = ht.create_header(afh, methods, psienergies)
            print header
            f.write(header)
            for index, matrixelements in enumerate(hamfiles.plotfiles):
                psir = rp.PsiReader(matrixelements,
                                    isbig=False,
                                    numorbs=-1,
                                    read_ints=False)
                if active_space:
                    psir.set_active_space(
                        [0], [[1, 2], []], [],
                        detfile1)  #for pisystem of deformed benzene
                    psir.set_active_space(
                        [0], [[1, 2], [2]], [],
                        detfile11)  #for pisystem of deformed benzene
                ht.create_ciflow_input_file(matrixelements,
                                            methods,
                                            fname=flowname)
                ci_flow = ""
                try:
                    process = subprocess.Popen(["./ciflow_%s.x" % pokemon],
                                               stdin=open(flowname, 'r'),
                                               stdout=subprocess.PIPE)
                    for line in iter(process.stdout.readline, ''):
                        sys.stdout.write(line)
                        ci_flow += line
                except Exception as e:
                    print 'Ciflow gave the following error', e
                    print ci_flow
                    pass
                """
                try:
                    ci_flow = subprocess.check_output(['./ciflow_%s.x' %pokemon ] , stdin =open(flowname , 'r') )
                except Exception as e:    
                    print 'Ciflow gave the following error', e
                    print ci_flow
                    pass
                """
                energies = ht.process_output(ci_flow) + [
                    x[1] for x in psir.extract_energies()
                ]
                ht.print_output(matrixelements, energies, methods)
                f.write("%.15f\t%s\n" % (runlist[index], '\t'.join(energies)))

    os.remove('./ciflow_%s.x' % pokemon)
    os.remove('./mointegrals.so')
    #os.remove(detfile1)
    ht.generate_dir('output_files', None, prefix=r'output[\w_]+.dat')
    os.chdir('..')
    ht.generate_dir('unitaries', None, prefix='unitary_')
    os.chdir('..')
    ht.generate_dir('matrixelements_otherbasis', None, prefix='hamp')
    os.chdir('..')

    OUTPUTDIR = os.path.join(ORIGDIR, name + str(arrayid))
    print 'We Start to create the outputdir ', OUTPUTDIR
    if os.path.isdir(OUTPUTDIR):
        shutil.rmtree(OUTPUTDIR)

    make_tarfile(OUTPUTDIR, WORKDIR)

    DATADIR = os.path.join(os.getenv('VSC_DATA'),
                           name + str(arrayid) + os.getenv('PBS_JOBID'))
    make_tarfile(DATADIR, WORKDIR)
    print 'We made a copy of the jobdata to: ', DATADIR
Exemplo n.º 4
0
def main_opt(*args, **kwargs):
    ciflowoutputfile = "ciflowoutput2.txt"
    flowname = "flow.dat"
    detfile1 = "determinants1.dat"
    detfile2 = "determinants2.dat"
    detfile3 = "determinants3.dat"
    detfile4 = "determinants4.dat"
    detfile5 = "determinants5.dat"
    detfile6 = "determinants6.dat"
    detfile7 = 'frozencisdpibenzene.dat'
    detfile8 = 'cisdpibenzenesigma.dat'
    detfile9 = 'CISDirrepref+cisd.dat'
    detfile10 = "CISDT(P).dat"
    detfile11 = "lin_hyb.dat"
    detfile12 = "ref2.dat"
    detfile20 = 'sen0.dat'
    detfile21 = 'sen2.dat'
    detfile22 = 'sen4.dat'
    detfile23 = 'sen6.dat'
    detfile24 = 'sen8.dat'
    detfile25 = 'sen10.dat'
    detfile30 = 'sen0-4.dat'
    change_ints = False  #if you changed the standard psi4 integrals somewhere during the process
    psienergies = []  #provide here a list of energies to be calculated by psi.
    methods = ["file", detfile2, "mmind", "file", detfile3
               ] + ["doci", "local", "file", detfile21, "file", detfile22]
    methods = ["file", detfile30]
    extra = None
    basissets = ['6-31g']
    import numpy as np
    runlist = np.arange(5.1, 8.1, 0.01)
    #atoms = [6 , 8]
    #atoms = [4]
    #atoms = [1,1,1,1 , 1, 1]
    atoms = [4, 1, 1]
    #atoms = [4,1,1] #beh2
    #atoms = [7,7]
    #atoms = [7,8] #NO+
    #atoms = [6,6,6,6,6,6,1,1,1,1,1,1] #benzene
    #runlist = [x*math.pi/180. for x in range(55,61) ]#+ [59.5]] #, 60]  ] #angle between two triangles in benzene.
    name = 'phdsenhierbeh2sen04cisdmmin'
    rootdir = './results/phdsenhierbeh26-31g2'  #relative to the directory that contains this script
    #rootdir = './results/phdsenebeccpvdzfcimminc1' #relative to the directory that contains this script
    exe = 'ciflow.x'
    elemdir = 'matrixelements'
    #elemdir = 'matrixelements_otherbasis'
    #elemdir = 'random_hamiltonians'
    #elemdir = 'output_run'
    elemdir = '.'

    #generate_dir(rootdir , exe  )
    #generate_dir(rootdir , exe , args= ["ni_system.dat"], prefix = r'./ham_patrick/hamnoplus')
    #generate_dir(rootdir , exe )
    #generate_dir(rootdir , exe , args= ["ni_system.dat"])
    shutil.copy(exe, rootdir)  #When the matrixelements are already present.
    os.chdir(rootdir)  #When the matrixelements are already present.
    #create_matrix_elements(elemdir , basissets, runlist, atoms, chmult = (0,1) , moltype = 'h6', package = 'psi' , units = 'angstrom', path_mo = '../../../../mointegrals/mointegrals.so' , DOCC = None, energies = psienergies, sym = 'c1', hdf5 = False, guess = 'read', extrapar = 0.741, ref = 'rhf', su = False, basispath = '../../../data/basissets/')#, extrapar = 1.398) #extrapar is size for benzene, and angle for c2v, benzene extrapar = 1.398 C-C distance , extrapar = 104.479848 for angle h2o, 0.741 = extrapar for h2 equilibrium geometry in but
    #create_matrix_elements(elemdir , basissets, runlist, atoms, chmult = (0,1) , moltype = 'atom', package = 'psi' , units = 'angstrom', path_mo = '../../../../mointegrals/mointegrals.so' , DOCC = None, energies = psienergies, sym = 'c1', hdf5 = False, guess = 'read', extrapar = 0.741, ref = 'rhf', su = False, basispath = '../../../data/basissets/')#, extrapar = 1.398) #extrapar is size for benzene, and angle for c2v, benzene extrapar = 1.398 C-C distance , extrapar = 104.479848 for angle h2o, 0.741 = extrapar for h2 equilibrium geometry in but

    outputfile = open(ciflowoutputfile, 'w')
    #fileinfo = lambda x: float(re.search(r'([\-+]?\d+[\.,]?\d+[eEDd]?[\-+]?\d*)[-\w\d]*\.[m]?out' , x).group(1))
    fileinfo = lambda x: float(
        re.search(r'([\-+]?\d+[\.,]+\d+[eEd]?[\-+]?\d*)[-\w\d_]*\.[m]?dat', x).
        group(1))
    #fileinfo = lambda x: float(re.search(r'FCIunit(\d+)\.[m]?dat' , x).group(1))
    #fileinfo = lambda x: float(re.search(r'.*-[\w\d]*([\-+]?\d+[\.,]?\d+[eEDd]?[\-+]?\d*)orthon\.h5' , x).group(1))
    #fileinfo = lambda x: float(re.search(r'([\-+]?\d+[\.,]?\d+[eEDd]?[\-+]?\d*)[-\w\d]*\.out' , x).group(1))
    #fileinfo = lambda x: float(re.search(r'hamnoplussto-3gpatrick([\-+]?\d+[\.,]?\d+[eEDd]?[\-+]?\d*)new\.out' , x).group(1))

    hamfiles = {}
    #search = r'psi.+%s.+mout'
    search = r'hampsi0_%s.+2hmmin0.dat'
    #search = r'hampsi0_%s.+local2.dat'
    #search = 'hamnoplus.*%s.+out'
    #search = r'hampsi.+%s.+FCI.+hmmin0.dat'
    #search = r'randomham.+\d+\.dat'
    #search = r'ham.+%s.+out'
    #search = r'hampsi0.+%s.+smmind0.dat'
    #search = r'ham.+%s.+FCIunit\d+\.dat'
    #search = r'psi.+%s.+orthon.h5'
    for basis in basissets:
        hamfiles[basis] = fc.File_Collector(
            elemdir,
            search=search % basis,
            notsearch=r'(\.sw\w)|(unitary)',
            sortfunction=fileinfo,
            filterf=lambda x: fileinfo(x) >= 5.1 and fileinfo(x) <= 1000.)
        #hamfiles[basis] = fc.File_Collector( '.', search = search %basis ,notsearch = r'\.sw\w',sortfunction = fileinfo, filterf =  lambda x : fileinfo(x) <= 10. and fileinfo(x) >= 2  and fileinfo(x) in runlist  and not '.sw' in x  )
        #hamfiles[basis] = fc.File_Collector(elemdir , search = search ,notsearch = r'\.sw\w',sortfunction = fileinfo, filterf =  lambda x : fileinfo(x) >= -1 and fileinfo(x) < 1000. )

    #fileinfo2 = lambda x: float(re.search(r'psi0_sto-3g1.29outputfciunit(\d+).dat' , x).group(1))
    #search = r'psi.+outputfciunit\d+.dat'
    #outputfilesfci = fc.File_Collector('output_files', search = search  ,notsearch = r'\.sw\w',sortfunction = fileinfo2, filterf =  lambda x : fileinfo2(x) >= 0 and fileinfo2(x) < 10000. )
    #hamfiles[basissets[0]].plotfiles += ['ni_system.dat']
    #print hamfiles[basissets[0]]

    afh = 'R'
    for basis in basissets:
        fname = name + "_" + basis + ".dat"
        psir = rp.PsiReader(
            hamfiles[basis].plotfiles[0],
            isbig=False,
            numorbs=-1,
            read_ints=False)  #just to get number of electrons and orbitals
        #dw.generate_all_ex(psir.values['nalpha'],psir.values['nbeta'],psir.values['norb'], ( psir.get_hf_orbs()[0][:], psir.get_hf_orbs()[1][:] )  , aname = 'determinants', addfrozen = 0)
        #dw.biggest_det_ex(outputfilesfci.plotfiles[index])
        #dw.generate_all_sen(psir.values['nalpha'],psir.values['nbeta'],psir.values['norb'], 'sen', addfrozen = 0)
        #reflist = dw.cimain(psir.values['nalpha'],psir.values['nbeta'] ,psir.values['norb'], [1] , [] , pairex = True)
        dw.cimain(psir.values['nalpha'] - 1,
                  psir.values['nbeta'] - 1,
                  psir.values['norb'] - 1, [[], []], [0, 4],
                  fname=detfile30,
                  ref=[lambda x, y, z: psir.get_hf_orbs()],
                  add_frozen=1)  #CISD
        #dw.cimain(psir.values['nalpha'],psir.values['nbeta'] ,psir.values['norb'],[[1,2,3] , []], [] ,fname = detfile14 ,ref =  [lambda x , y , z : psir.get_hf_orbs()] ) #CISD
        #dw.cimain(psir.values['nalpha'],psir.values['nbeta'] ,psir.values['norb'],[[1,2,3,4] , []], [] ,fname = detfile15 ,ref =  [lambda x , y , z : psir.get_hf_orbs()] ) #CISD
        #dw.cimain(psir.values['nalpha'],psir.values['nbeta'] ,psir.values['norb'],[[] ,[]], [0,2] ,fname = detfile2 ,ref = [lambda x , y , z : dw.get_hf_det(x,y,z)]) #SEN0-2
        with open(fname, 'w') as f:
            header = create_header(afh, methods, psienergies, extra=extra)
            print header
            f.write(header)
            for index, matrixelements in enumerate(hamfiles[basis].plotfiles):
                print matrixelements
                if change_ints:  #True if you want to change the standard psi4 integrals.
                    psir = rp.PsiReader(matrixelements,
                                        isbig=True,
                                        numorbs=60,
                                        read_ints=True)  #for benzene.
                    if '1.05' not in matrixelements:
                        #psir.set_active_space([1,2] , [1,2] , [] , detfile7) #for pisystem of deformed benzene
                        psir.set_active_space(
                            [1], [[1, 2], []], [],
                            detfile7)  #for pisystem of deformed benzene
                    else:
                        #psir.set_active_space([2,3,4,5] , [1,2] , [] , detfile7) #for pisystem of benzene
                        psir.set_active_space(
                            [1], [[1, 2], [2]], [],
                            detfile7)  #for pisystem of benzene
                    #psir.set_active_space([0,1,2,3] , [1] , [] , detfile3) #for pisystem of deformed benzene
                    #psir.set_active_space([1,2] , [1,2] , [] , detfile4) #for pisystem of deformed benzene
                    #psir.keep_orbs(56)
                    newname = os.path.basename(matrixelements) + 'new.dat'
                    psir.create_output(newname)
                    matrixelements = newname

                create_ciflow_input_file(matrixelements,
                                         methods,
                                         fname=flowname)
                ci_flow = ""
                if methods:
                    try:
                        ci_flow = ""
                        process = subprocess.Popen(["./ciflow.x"],
                                                   stdin=open(flowname, 'r'),
                                                   stdout=subprocess.PIPE)
                        for line in iter(process.stdout.readline, ''):
                            sys.stdout.write(
                                line)  #writes intermediate output to screen.
                            outputfile.write(line)
                            outputfile.flush()
                            ci_flow += line
                    except Exception as e:
                        print 'Ciflow gave the following error', e
                        print ci_flow
                        pass
                energies = process_output(ci_flow)
                mullikencharge = process_output(
                    ci_flow,
                    regexp=
                    "Mulliken[\s\w]+:\s*([\-+]?\d+[\.,]?\d*[eEDd]?[\-+]?\d*)")
                if psienergies:  #True if the list is not empty
                    psir = rp.PsiReader(matrixelements,
                                        isbig=False,
                                        numorbs=-1,
                                        read_ints=False)
                    energies += [x[1] for x in psir.extract_energies()]

                print_output(matrixelements, energies, methods)
                f.write("%.15f\t%s\t%s\n" %
                        (runlist[index], '\t'.join(energies),
                         '\t'.join(mullikencharge)))
                if change_ints:
                    os.remove(matrixelements)

    shutil.copy('../../htest.py', '.')
    os.remove(
        exe
    )  #can be handy to keep it in the dir, to exactly reproduce results later. (but be warned its big.)
    outputfile.close()
    try:
        generate_dir('output_files', None, prefix=r'output[\w_]+.dat')
        os.chdir('..')
        generate_dir('unitaries', None, prefix='unitary_')
        os.chdir('..')
        generate_dir('matrixelements_otherbasis', None, prefix='hamp')
        os.chdir('..')
    except:
        pass

    if (os.getenv('VSC_INSTITUTE_LOCAL') != 'gent'):
        plotter = pf.Plot_Files(fname)
        plotter.data[0].depvar[
            'yas'] = 'Energy'  #change the future y-axis label
        plotter.data[0].depvar[
            'xas'] = '$R$'  #is normally set to the column header 0
        plotter.data[0].units['x'] = r'(\AA)'
        plotter.data[0].units['y'] = r'(E$_h$)'
        plotter.generate_plot(xlimg=None,
                              ylimg=None,
                              exname='',
                              prefix=True,
                              titel=name,
                              name=fname,
                              depcol=0,
                              ylist=None)
Exemplo n.º 5
0
def main():
    name = 'beh2cc-pvdzcisddocidebug'
    hamdirname = "beh2ccpvdzham"
    pokemon = os.environ['VSC_INSTITUTE_CLUSTER']
    print 'we have run this script on cluster: ' , pokemon
    active_space = False
    flowname = "flow.dat"; detfile1 = "cisddeterminants.dat" ; detfile2 = "cisddocideterminants.dat" ; detfile3 = 'CIS(P)' ; detfile4 = 'CISD(P)' ; detfile6 = 'fcifile.dat' ; detfile7 = 'be_ccpv5z96100.txt'
    detfile10= "linhyb23p.dat"
    detfile11 = "linhyb2p.dat"
    #methods = [ "big", detfile6, "loadham"] #everything on#everything on
    methods = [ "file" , detfile1 , "hmmin", "file" ,detfile10 , "loadham"] #everything on#everything on
    methods = ["doci" , "loadham" , "file", detfile3 , "loadham" , "file" , detfile4 , "loadham" ] #everything on#everything on
    #methods = []
    #psienergies = ['fci']
    psienergies = []
    basissets = ['cc-pvdz']
    #runlist = [ 3.4 , 3.5 ,  3.8 , 3.9 , 4. ,  4.5 ,4.8 ,  5., 5.6, 6.] #BeH2 (linear)
    #runlist = [1.81625952410, 1.97501269880, 2.13376587350, 2.29251904820, 2.45127222290, 2.61002539760, 2.76877857230, 2.92753174700, 3.08628492170, 3.1 , 3.2, 3.3 , 3.4 , 3.5 , 4. , 4.5 , 5.] #BeH2
    runlist = [0.7, 0.9 , 1, 1.1 , 1.2 , 1.3 ,1.4 , 1.5 , 1.6 , 1.7, 1.81625952410, 1.97501269880, 2.13376587350, 2.29251904820, 2.45127222290, 2.61002539760, 2.76877857230, 2.92753174700, 3.08628492170, 3.1 , 3.2, 3.3 , 3.4 , 3.5 ,3.6,3.7,3.8,3.9 , 4. , 4.5 , 5., 6.] #BeH2
    #runlist = [0.6402695456, 0.7 , 0.7461049954, 0.8 , 0.8519404452, 0.9 , 0.957775895, 1. , 1.0636113448, 1.1, 1.1694467946, 1.2 , 1.2752822444, 1.3, 1.3811176942, 1.4, 1.486953144, 1.5, 1.5927885938, 1.6, 1.6986240436 , 1.72 , 1.8 , 1.85 , 1.9 , 1.95 , 2. , 2.05, 2.2278012926, 2.4 , 2.6 , 3. , 3.5 , 4. , 4.5 , 5. ,6.]#, 2.1 , 2.15, 2.2278012926 ]#, 1.8044594934, 1.9102949432, 2.016130393, 2.1219658428, 2.2278012926, 2.3336367424 ] #H2O (c2v)
    #runlist = [2.3,2.4,2.5,2.6,2.7,2.8,2.9,3.,3.2,3.3, 3.5,3.8 , 4.]
    #runlist = [2.32,2.42,2.52,2.61,2.71,2.99,3.09,3.19,3.38,3.57, 3.76,4.05]
    #runlist = [1.9] +  runlist
    #runlist = [1.81625952410, 1.97501269880, 2.13376587350, 2.29251904820, 2.45127222290, 2.61002539760, 2.76877857230, 2.92753174700, 3.08628492170, 3.1 , 3.2, 3.3 , 3.4 , 3.5 , 4. , 4.5 , 5.] #BeH2
    #runlist = [2.45127222290, 2.61002539760, 2.76877857230, 2.92753174700, 3.08628492170, 3.1 , 3.2, 3.3 , 3.4 , 3.5 , 4. , 4.5 , 5.] #BeH2
    #runlist = []

    arrayid = 2
    #hereunder for array jobs for heavy calculations. But make sure it is always defined
    #arrayid =int(os.getenv('PBS_ARRAYID'))
    #arraystep = 1
    #name += str(arrayid)
    #try:
    #    runlist = runlist[(arrayid-1) * arraystep : arrayid *arraystep]
    #except:
    #    print 'encoutered exception in cut of runlist.'
    #    runlist = runlist[-4:-1]

    #runlist = [1.38, 1.4, 1.45, 1.5, 1.65750634940, 1.81625952410, 1.97501269880] #, 2.13376587350,2.2 ,  2.29251904820, 2.35 , 2.45127222290, 2.5 , 2.61002539760,2.7 ,  2.76877857230, 2.92753174700, 3.0 ,  3.08628492170, 3.1 , 3.2, 3.3 , 3.4 , 3.5 , 3.6 ,3.7 , 3.8 , 3.9 , 4. , 4.5 , 5. , 6.] #BeH2 (linear)
    #runlist = [2.13376587350,2.2 ,  2.29251904820, 2.35 , 2.45127222290, 2.5 ]# , 2.61002539760,2.7 ,  2.76877857230, 2.92753174700, 3.0 ,  3.08628492170, 3.1 , 3.2, 3.3 , 3.4 , 3.5 , 3.6 ,3.7 , 3.8 , 3.9 , 4. , 4.5 , 5. , 6.] #BeH2 (linear)
    #runlist = [ 3.08628492170, 3.1 , 3.2, 3.3 , 3.4 ,  4. ,   5. , 6.] #BeH2 (linear)

    #runlist = [0.86374047590, 1.02249365060, 1.18124682530, 1.34000000000, 1.49875317470, 1.65750634940, 1.81625952410, 1.97501269880, 2.13376587350, 2.29251904820, 2.45127222290, 2.61002539760, 2.76877857230, 2.92753174700, 3.08628492170 ] #BeH2
    #runlist = [0.6402695456, 0.7461049954, 0.8519404452, 0.957775895, 1.0636113448, 1.1694467946, 1.2752822444, 1.3811176942, 1.486953144, 1.5927885938, 1.6986240436 , 2.2278012926 ]#, 1.8044594934, 1.9102949432, 2.016130393, 2.1219658428, 2.2278012926, 2.3336367424 ] #H2O
    #runlist = [ 1.2 , 1.6] #[ 0.7,0.8 ,0.8519404452, 0.957775895, 1.1694467946, 1.2752822444, 1.3811176942]#, 1.8044594934, 1.9102949432, 2.016130393, 2.1219658428, 2.2278012926, 2.3336367424 ] #H2O
    #runlist = [0.848, 0.9 , 0.973, 1.0 , 1.098, 1.223, 1.3, 1.348, 1.4, 1.473,1.5,  1.598, 1.723,1.8 ,  1.848, 1.973] #N2
    #atoms = [7,7] # set DOCC = [3, 0 ,0, 0,0 , 2, 1 ,1] 
    #atoms = [1, 1,1,1,1,1,1,1 ] #h8
    #atoms = [8, 1,1 ]
    atoms = [4,1,1]
    #atoms = [6,6,6,6,6,6,1,1,1,1,1,1] #benzene
    #import math
    #runlist = [x*math.pi/180. for x in range(55,60) + [59.9 , 60]  ] #angle between two triangles in benzene.

    print 'Start to load necessary modules.'
    os.system('module swap cluster/%s' %pokemon)
    os.system('module load PSI/4.0b6-20160201-intel-2016a-mt-Python-2.7.11')
    os.system('module load arpack-ng/3.3.0-intel-2016a')
    os.system('module load matplotlib')
    os.system('module load h5py')
    #os.system('module load Boost/1.55.0-ictce-7.1.2-Python-2.7.8')
    os.system('export MKL_NUM_THREADS=16')
    #os.system('export KMP_STACKSIZE=32m')

    ORIGDIR= os.getenv('HOME')
    mofile = os.path.join(ORIGDIR, 'devel/CIFlow/lib/mointegrals_%s.so' %pokemon)
    exefile = os.path.join(ORIGDIR, 'devel/CIFlow/bin/ciflow_%s.x' %pokemon )
    hamdir = os.path.join(ORIGDIR, hamdirname)
    #det_file = os.path.join(ORIGDIR, detfile10 )
    print 'We submitted the script in: ', ORIGDIR
    print 'Psi 4 plugin is at: ' , mofile

    WORKDIR= os.path.join(os.getenv('VSC_SCRATCH_NODE'),os.getenv('PBS_JOBID'))

    if os.path.isdir(WORKDIR):
        shutil.rmtree(WORKDIR)
    os.mkdir(WORKDIR)
    print 'Workdir is: ', WORKDIR

    shutil.copy(mofile,WORKDIR)
    shutil.copy(exefile,WORKDIR)
    hamdest = os.path.join(WORKDIR, hamdirname)
    shutil.copytree(hamdir,hamdest)
    #shutil.move(det_file,WORKDIR)

    os.chdir(WORKDIR)
    print 'We work on node: ' , os.getenv('HOSTNAME')

    #PSIINPUT = os.path.join(os.getcwd() , 'output_run')
    #print 'We Start to create the outputdir ' ,PSIINPUT
    #if os.path.isdir(PSIINPUT):
    #    shutil.rmtree(PSIINPUT)
    #os.mkdir(PSIINPUT)

    #angle = 104.479848 
    #for basis in basissets:
    #    for r in runlist:
    #        #positions = [[0,0,0],[0,0,r],[0,0,-1*r]] #for molecules like beh2
    #        #positions = [[0,0,0],[0,0,r]] #for molecules like n2
    #        #positions = [[0,0,0],[0,0,r],[0,0,2*r], [0,0,3*r], [0,0,4*r] , [0,0,5*r] , [0,0,6*r], [0,0,7*r]] #For H_8
    #        positions = [[''],[1, r],[1, r, 2 , angle]] #for molecules like h2o
    #        #positions = [[0,0,0]] #for an atom
    #        #positions = ht.benzene(r,  1.398) #REMARK we run over the angle -> r in runlist, and keep the radius of the circle on which all the C atoms are placed constant to extrapar, (extrapar = 1.398 A is standard)
    #        ht.input_psi(os.path.join('output_run' ,"psi%.2f" %(r) +"basis"+basis+  ".dat"), basis ,name= 'mol' , charge_mult = (0,1) , atomlist = atoms , positions = positions , units = 'angstrom' , ref = 'rhf', userbasis = False, path_to_plugin = './mointegrals_%s.so' %pokemon, DOCC = None, sym = None, energies = psienergies)

    print 'Contents of rundir before run are: ', os.listdir(os.getcwd())
    #for file in os.listdir(PSIINPUT):
    #    print 'processing psi input file: ' , file
    #    exfile = os.path.join('output_run',file)
    #    os.system('psi4 ' + exfile)

    #print 'Contents of rundir after run are: ', os.listdir(os.getcwd())
    #print 'Contents of inputdir are: ', os.listdir('./output_run')
    

    hamfiles = File_Collector('.', search = r'psi.+out' ,notsearch = r'\.sw\w',sortfunction = lambda x: float(re.search(r'([\-+]?\d+[\.,]?\d+[eEDd]?).*\.m?out' , x).group(1)) , filterf = lambda x: (float(re.search(r'([\-+]?\d+[\.,]?\d+[eEDd]?[\-+]?\d*).*\.m?out' , x).group(1)) == round(runlist[arrayid],2 ) )  )
    #hamfiles =File_Collector('output_run', search = r'psi.+out' ,notsearch = r'\.sw\w', filterf = lambda x: float(re.search(r'([\-+]?\d+[\.,]?\d+[eEDd]?[\-+]?\d*).*\.m?out' , x).group(1)) > 1.1)
                
    psir = rp.PsiReader(hamfiles.plotfiles[0], isbig = False, numorbs = -1 , read_ints = False)

    #frozen = [1,0,0,0,0,1,0,0]  ; virtual = [1,1,1,1,1,2,0,0]; active = [5,0,2,2,0,4,3,3]
    #assert( sum(frozen) + sum(virtual) + sum(active) == psir.values['norb'])
    #dw.cimain(psir.values['nalpha'] - sum(frozen),psir.values['nbeta'] -sum(frozen)  ,psir.values['norb'] - sum(frozen) - sum(virtual) , [[1,2], []], [],fname = detfile1 ,ref = [lambda x , y , z : psir.get_hf_orbs(  frozen = frozen , virtual = virtual )] , active = active, frozen =  frozen, virtual = virtual ,add_frozen = 0, add_virtual = 0)
    #dw.cimain(psir.values['nalpha'] - sum(frozen),psir.values['nbeta'] -sum(frozen)  ,psir.values['norb'] - sum(frozen) - sum(virtual) , [[1,2], [2,3]], [],fname = detfile10 ,ref = [lambda x , y , z : psir.get_hf_orbs(  frozen = frozen , virtual = virtual )] , active = active, frozen =  frozen, virtual = virtual ,add_frozen = 0, add_virtual = 0)
    #dw.cimain(psir.values['nalpha'],psir.values['nbeta'], psir.values['norb'] , [[1,2],[2]], [] , fname = detfile11 ,add_frozen = 0, add_virtual = 0,ref =  [ lambda x , y , z : psir.get_hf_orbs()]   ) #CISDD
    #dw.cimain(psir.values['nalpha'],psir.values['nbeta'], psir.values['norb'] , [[1,2],[]], [0] , fname = detfile2 ,add_frozen = 0, add_virtual = 0,ref =  [ lambda x , y , z : psir.get_hf_orbs()]   ) #CISDDOCI
    dw.cimain(psir.values['nalpha'],psir.values['nbeta'], psir.values['norb'],[[], [1]], [] , fname = detfile3 ,add_frozen = 0, ref =  [lambda x , y , z : psir.get_hf_orbs()]) #CIS(P)
    dw.cimain(psir.values['nalpha'],psir.values['nbeta'], psir.values['norb'],[[], [1,2]], [] , fname = detfile4 ,add_frozen = 0, ref =  [lambda x , y , z : psir.get_hf_orbs()]) #CISD(P)
    #dw.cimain(psir.values['nalpha'],psir.values['nbeta'], psir.values['norb'],[[1,2], [] ],[]  , fname = detfile1 ,add_frozen = 0, ref =  [lambda x , y , z : psir.get_hf_orbs()]) #CISD 
    #dw.cimain(psir.values['nalpha']-1,psir.values['nbeta']-1, psir.values['norb']-1,[[1,2,3,4], [] ],[]  , fname = detfile6 ,add_frozen = 1, ref =  [lambda x , y , z : dw.get_hf_det(x,y,z)] ) #FCI
    #dw.cimain(psir.values['nalpha'],psir.values['nbeta'], psir.values['norb'],[range(1,psir.values['nbeta']*2 +1), [] ],[]  , fname = detfile6 ,add_frozen = 0, ref =  [lambda x , y , z : dw.get_hf_det(x,y,z)] ) #FCI
    afh = 'R'
    for basis in basissets:
        fname = "ciflowresults_" + basis + ".dat"
        with open(fname , 'w') as f:
            header = ht.create_header(afh , methods,psienergies)
            print header
            f.write(header)
            for index , matrixelements in enumerate(hamfiles.plotfiles):
                psir = rp.PsiReader(matrixelements, isbig = False, numorbs = -1 , read_ints = False)
                if active_space:
                    psir.set_active_space([0] , [[1,2],[]] , [] , detfile1) #for pisystem of deformed benzene
                    psir.set_active_space([0] , [[1,2], [2]]  , [] , detfile11) #for pisystem of deformed benzene
                ht.create_ciflow_input_file(matrixelements , methods , fname = flowname)
                ci_flow =""
                try:
                    process = subprocess.Popen(["./ciflow_%s.x" %pokemon ] , stdin =open(flowname , 'r'), stdout = subprocess.PIPE)
                    for line in iter(process.stdout.readline, ''):
                        sys.stdout.write(line)
                        ci_flow += line
                except Exception as e:    
                    print 'Ciflow gave the following error', e
                    print ci_flow
                    pass

                """
                try:
                    ci_flow = subprocess.check_output(['./ciflow_%s.x' %pokemon ] , stdin =open(flowname , 'r') )
                except Exception as e:    
                    print 'Ciflow gave the following error', e
                    print ci_flow
                    pass
                """
                energies = ht.process_output(ci_flow) + [x[1] for x in psir.extract_energies()]
                ht.print_output(matrixelements, energies , methods)
                f.write("%.15f\t%s\n" %(runlist[index], '\t'.join(energies )) )
  
    os.remove('./ciflow_%s.x' %pokemon)
    os.remove('./mointegrals.so')
    #os.remove(detfile1)
    ht.generate_dir('output_files', None, prefix = r'output[\w_]+.dat')
    os.chdir('..')
    ht.generate_dir('unitaries', None, prefix = 'unitary_')
    os.chdir('..')
    ht.generate_dir('matrixelements_otherbasis', None, prefix = 'hamp')
    os.chdir('..')

    OUTPUTDIR = os.path.join(ORIGDIR, name+str(arrayid) )
    print 'We Start to create the outputdir ' , OUTPUTDIR
    if os.path.isdir(OUTPUTDIR):
        shutil.rmtree(OUTPUTDIR)

    make_tarfile(OUTPUTDIR , WORKDIR)


    DATADIR = os.path.join(os.getenv('VSC_DATA'), name + str(arrayid) + os.getenv('PBS_JOBID'))  
    make_tarfile(DATADIR, WORKDIR)
    print 'We made a copy of the jobdata to: ', DATADIR