コード例 #1
0
    def b3lyp_prototype(cls, i_bs=0):

        #
        calc_b3lyp = CP2K()  # cp2k object
        calc_b3lyp.working_directory = './'

        # pycp2k objects: hierarchy
        CP2K_INPUT = calc_b3lyp.CP2K_INPUT  # CP2K_INPUT is what we need
        FORCE_EVAL = CP2K_INPUT.FORCE_EVAL_add()
        FORCE_EVAL.Method = 'QUICKSTEP'
        SUBSYS = FORCE_EVAL.SUBSYS
        DFT = FORCE_EVAL.DFT
        XC = DFT.XC
        SCF = DFT.SCF
        ####################################################################################################################
        # GLOBAL #
        # FORCE EVAL #
        set_global(CP2K_INPUT)
        ## SUBSYS ##
        set_unperiodic_cell(SUBSYS, abc=cls.my_abc)
        set_nonperiodic_poisson(DFT)
        set_topology(SUBSYS, xyz_file_name=cls.xyz_file_name)
        center_coordinates(SUBSYS)
        ## END SUBSYS ##

        ## DFT ##
        set_dft(DFT,
                potential_file_name=cls.potential_file_name,
                basis_set_file_name=cls.basis_set_file_name)
        set_cutoff(DFT, cutoff=cls.cutoff, rel_cutoff=cls.rel_cutoff, ngrids=5)
        # set_scf(DFT, eps_scf=cls.eps_scf_dft[i_bs], max_scf=1000, scf_guess='RESTART')
        # <-- even if no actual wfn saved, will not collapse, but start with ATOMIC guess
        # add_ot(SCF, stepsize=0.04)
        #
        # add_outer_scf(OUTER_SCF)
        # set_pbe(XC)  # we start with pbe
        # set_pbe0(XC) no pbe0 in the beginning
        set_qs(DFT,
               eps_default=1.0E-10,  # should be 4 order of magnitude lower w.r.t. diag
               eps_pgf_orb=np.sqrt(1.0E-20))  # --||-- 1E-20 helps to avoid in b3lyp
        ## END DFT ##
        #
        ################################################################################################################

        # todo probably let it converge with OT method
        # change calculations to a diagonalization
        add_diagonalization(SCF)
        # add_smear(SCF_)  # uses final T.
        add_mixing(SCF)  # add or not?
        add_mos(SCF, added_mos=1000)
        # plot h**o/lumo

        # set_pbe0(XC_)  # we want G0W0@PBE0. no pbe0 in the beginning
        print_mo_cubes(DFT.PRINT, nhomo=10, nlumo=10)  # all HOMOs are typicall plotted
        set_scf(DFT, eps_scf=1E-6, max_scf=100)  # I want it to end asap if not converged
        # add G0W0!

        add_b3lyp(XC)

        return calc_b3lyp
コード例 #2
0
    def __init__(self, start=None, stop: Union[dict, str] = None, atoms: ase.Atoms = None, template_file: str = None,
            tolerance: float = 0.002, cwd: str = './', project_name: str = 'optimization'):
        """
        Constructor for the cutoff optimizer class

        Parameters
        ----------
        start : dict
                Starting values to use in the analysis for the cutoff, rel_cutoff and ngrid optimization
        stop : Union[dict, str]
                Stop value to use in the analysis. If a float, the cutoff values will be taken between start and top, if
                the string auto is given, an automatic optimization method is implemented to find the optimal cutoff.
        template_file : str
                A cp2k input file to be read in as a template and modified during the analysis
                Note that you need not add the cutoff, rel cutoff, and monkhorst parameters need not be set here as they
                will be added at the appropriate stage of the analysis.
        atoms : ase.Atoms
                Ase atoms object on which the analysis should be performed. We ask for an ase atoms object over a
                coordinate file in order to avoid issues arising from file readers. If this is left empty, it is
                assumed that the cell is defined in the cp2k input file
        tolerance : float
                The delta value at which the cutoff should be considered converged.
        cwd : str
                Directory in which the analysis should run and files should be stored.
        project_name : str
                Name of the project.
        """
        if start is None:
            start = {'Cutoff': 100, 'Ngrids': 5, 'Rel_cutoff': 60}
        if stop is None:
            stop = {'Cutoff': 1500, 'Ngrids': 8, 'Rel_cutoff': 120}
        self.start = start
        self.stop = stop
        self.atoms = atoms
        self.template_file = template_file
        self.tolerance = tolerance
        self.cwd = cwd
        self.project_name = project_name

        self.calculator = CP2K()
        self.calculator.project_name = self.project_name
        self.calculator.working_directory = self.cwd
        self.calculator.parse(self.template_file)
        self.force_eval = self.calculator.CP2K_INPUT.FORCE_EVAL_list[0]
        self.force_eval.PRINT.FORCES.Section_parameters = "ON"
        self.m_grid = self.force_eval.DFT.MGRID
        self.loop_range = {}
        self.force_array = {'Cutoff': [], 'Ngrids': [], 'Rel_cutoff': []}
        self.energy_array = {'Cutoff': [], 'Ngrids': [], 'Rel_cutoff': []}
        self.optimized_cutoff: float
        self.optimized_rel_cutoff: float
        self.optimized_n_grids: float
        
        # Run checks
        if type(stop) is str:
            self._temp_operation_check()
        if template_file is None:
            print("You must give adequate calculator parameters")
            sys.exit(1)
コード例 #3
0
    def energy_cp2k(self):
        """Quick routine to calculate total energy using CP2K
        """
        from pycp2k import CP2K
        calc = CP2K()
        calc.working_directory = self.input.dict['working_directory']
        # Determine if using less than max_processers would be better
        if (int(self.input.dict['atoms_per_process']) != 0):
            natoms = len(self.config.atom)
            processes = natoms / float(self.input.dict['atoms_per_process'])
            if (processes <= 1.0):
                processes = 1
                printx("atoms_per_process may be set too high for system size")
                printx("Number of Atoms = " + str(natoms))
            elif (processes > int(self.input.dict['max_mpi_processes'])):
                processes = int(self.input.dict['max_mpi_processes'])
            else:
                processes = int(processes)
        else:
            processes = int(self.input.dict['max_mpi_processes'])
        calc.mpi_n_processes = processes
        self.config.atom.set_calculator(calc)
        # load in cp2k options
        execfile(self.input.dict['cp2k_input'])
        calc.project_name = self.config.file_name
        calc.write_input_file()
        # If we only want the input file written, then we stop here
        if (self.exetype == 'write'):
            energy_per_area = 2.0e10
            return energy_per_area
        # if print_debug is true, we run energy calc without "try" to
        # allow for better error message passing
        if (self.input.dict['print_debug'] != 'False'):
            calc.run()
        else:
            try:
                calc.run()
            except Exception as err:
                printx('error occured in the energy calculation.')
                energy_per_area = 1.0e10
                return energy_per_area

        # Read in the output file to find the final energy.
        with open(calc.output_path, "r") as fin:
            regex = re.compile(" ENERGY\| Total FORCE_EVAL \( QS \)"
                               " energy \(a\.u\.\):\s+(.+)\n")
            for line in fin:
                match = regex.match(line)
                if match:
                    printx("Final energy: {}".format(match.groups()[0]))
                    energy = match.groups()[0]
        area = self.config.atom.cell[0, 0] * self.config.atom.cell[1, 1]
        if (self.input.dict['print_debug'] != 'False'):
            printx('Area used for energy ' + self.config.file_name + 'is' +
                   str(area))
        energy_per_area = float(energy) / area

        return energy_per_area
コード例 #4
0
def createDefaultCp2kCalcObj(**kwargs):
    kwargs = {k.lower(): v for k, v in kwargs.items()}

    outDir = kwargs.get("outdir", None)
    projName = kwargs.get("projname", None)

    outObj = CP2K()
    outObj.working_directory = os.path.abspath(os.getcwd())
    outObj.project_name = "cp2k_file"

    #Shortcutrs for below
    cp2kInput = outObj.CP2K_INPUT
    globSect = cp2kInput.GLOBAL
    forceEval = cp2kInput.FORCE_EVAL_add(
    )  #Generally the main section (at least for a SPE calc). Can be given more than once hence the add
    subSys = forceEval.SUBSYS
    dft = forceEval.DFT

    #Defining tons of params here
    globSect.Run_type = "ENERGY"
    globSect.Print_level = "MEDIUM"
    forceEval.Method = "Quickstep"

    forceEval.PRINT.FORCES.Section_parameters = "On"

    dft.Basis_set_file_name = "BASIS_SET"
    dft.Potential_file_name = "GTH_POTENTIALS"

    dft.QS.Eps_default = "1.0E-10"
    dft.MGRID.Ngrids = "4"
    dft.MGRID.Cutoff = "[eV] 5000"
    dft.MGRID.Rel_cutoff = "[eV] 50000"

    dft.XC.XC_FUNCTIONAL.Section_parameters = "PBE"
    dft.KPOINTS.Scheme = "MONKHORST-PACK 1 1 1"

    dft.SCF.Scf_guess = "ATOMIC"
    dft.SCF.Eps_scf = "1.0E-7"
    dft.SCF.Max_scf = "300"
    dft.SCF.Added_mos = "4"
    dft.SCF.DIAGONALIZATION.Section_parameters = "ON"
    dft.SCF.DIAGONALIZATION.Algorithm = "Standard"
    dft.SCF.MIXING.Section_parameters = "T"
    dft.SCF.MIXING.Method = "BROYDEN_MIXING"
    dft.SCF.MIXING.Alpha = "0.4"
    dft.SCF.MIXING.Nbroyden = "8"
    dft.SCF.SMEAR.Section_parameters = "ON"
    dft.SCF.SMEAR.Method = "FERMI_DIRAC"
    dft.SCF.SMEAR.Electronic_temperature = "[K] 157.9"

    modCp2kObjBasedOnDict(outObj, kwargs)

    return outObj
コード例 #5
0
    def test_repeated_keywords(self):
        """Ensures that repeatable keywords are correctly handled.
        """

        # Test that input parser correctly reads repeated keywords
        calc = CP2K()
        calc.parse("./repeated_keywords/template.in")
        force_eval = calc.CP2K_INPUT.FORCE_EVAL_list[0]
        basis_files = force_eval.DFT.Basis_set_file_name
        self.assertEqual(len(basis_files), 2)

        # Test that non-repeatable keywords are replaced instead of repeated
        periodic = force_eval.SUBSYS.CELL.Periodic
        self.assertEqual(periodic, "XYZ")
コード例 #6
0
    def dft_prototype(cls, i_bs=0):
        #  creates CP2K object from scratch. Note that gw prototype takes dft_prototype as a starting point
        calc_dft = CP2K()  # cp2k object
        calc_dft.working_directory = './'

        # pycp2k objects: hierarchy
        CP2K_INPUT = calc_dft.CP2K_INPUT  # CP2K_INPUT is what we need
        FORCE_EVAL = CP2K_INPUT.FORCE_EVAL_add()
        FORCE_EVAL.Method = 'QUICKSTEP'
        SUBSYS = FORCE_EVAL.SUBSYS
        DFT = FORCE_EVAL.DFT
        XC = DFT.XC
        SCF = DFT.SCF
        ####################################################################################################################
        # GLOBAL #
        # FORCE EVAL #
        set_global(CP2K_INPUT)
        ## SUBSYS ##
        set_unperiodic_cell(SUBSYS, abc=cls.my_abc)
        set_nonperiodic_poisson(DFT)
        set_topology(SUBSYS, xyz_file_name=cls.xyz_file_name)
        center_coordinates(SUBSYS)
        ## END SUBSYS ##

        ## DFT ##
        set_dft(DFT,
                potential_file_name=cls.potential_file_name,
                basis_set_file_name=cls.basis_set_file_name)
        set_cutoff(DFT, cutoff=cls.cutoff, rel_cutoff=cls.rel_cutoff, ngrids=5)
        set_scf(DFT,
                eps_scf=cls.eps_scf_dft[i_bs],
                max_scf=1000,
                scf_guess='RESTART')
        # <-- even if no actual wfn saved, will not collapse, but start with ATOMIC guess
        add_ot(SCF, stepsize=0.04)
        #
        # add_outer_scf(OUTER_SCF)
        set_pbe(XC)  # we start with pbe
        # set_pbe0(XC) no pbe0 in the beginning
        set_qs(
            DFT,
            eps_default=1.0E-10,  # ad hoc
            eps_pgf_orb=np.sqrt(1.0E-10))  # ad hoc
        ## END DFT ##
        return calc_dft
コード例 #7
0
def main():

    #  main settings
    # todo: has to be inherited from the sh file:
    sim = 'sim'  # simulation folder name
    database_folder = 'db'
    # todo: this must be inherited
    bh5670 = 'bh5670'  # the outermost folder in the scratch where all other data are put
    # todo yaml or predict
    my_offset = 15  # from the molecule to a vacuum. 15-20 is recommended!
    cutoff = 500
    rel_cutoff = 50
    basis_set_file_name = 'BASIS_CC_AUG_RI_NEW'  # RI5, 2-5 cc, all aug-cc, RIFIT-all
    my_basis_sets = [
        'aug-cc-pVDZ', 'aug-cc-pVTZ', 'aug-cc-pVQZ', 'aug-cc-pV5Z'
    ]
    my_ri_basis_sets = [
        'aug-cc-pVDZ-RIFIT', 'aug-cc-pVTZ-RIFIT', 'aug-cc-pVQZ-RIFIT',
        'aug-cc-pV5Z-RIFIT'
    ]

    debug = True
    #  end: main settings

    dummy_run = False  # does not invoke cp2k if true

    #  parser begin
    parser = argparse.ArgumentParser(description='rank and num of cpus')
    parser.add_argument('-rank')  # array job number
    parser.add_argument(
        '-num_cpus')  # number of cpus you request for every array job
    args = parser.parse_args()
    #  parser end

    #  parsing input
    threads = int(args.num_cpus) - 1  # cpus used to compute
    rank = '{:0>6}'.format(
        args.rank)  # transform rank from '1' to '000001' format
    prefix_xyz_file_name = 'dsgdb9nsd'
    xyz_file_name = f'{prefix_xyz_file_name}_{rank}.xyz'
    xyz_file_location = f'{prefix_xyz_file_name}/{xyz_file_name}'
    sim_folder_scratch = f'/scratch/{bh5670}/{sim}/{rank}'
    sim_folder_home = f'{sim}/{rank}'  # sim folder at home exists. you create later {rank} folder
    if not os.path.exists(sim_folder_scratch):
        os.mkdir(sim_folder_scratch)
    else:
        rmtree(sim_folder_scratch
               )  # leftovers from previous simulations will be removed
        os.mkdir(sim_folder_scratch)  # and the new folder will be created

    # xyz object created, normal xyz file is created at scratch
    my_xyz_file_obj = XYZ.from_file(
        xyz_file_location)  # object created using the file from home
    xyz_at_scratch = sim_folder_scratch + '/' + xyz_file_name  #
    my_xyz_file_obj.write(xyz_at_scratch)  # writes a normal xyz (into scratch)

    # my molecule object is created. It will serve as a DB record
    my_new_mol = Cp2kOutput(rank)

    # rel_cutoff: 40; cutoff: 300; abc = 10
    my_abc = str(my_xyz_file_obj.compute_box_size(offset=my_offset))[1:-2]

    # GLOBAL SETTINGS
    #

    ## base settings ##
    my_potential_file_name = 'POTENTIAL'
    my_potential = 'ALL'
    my_project_name = "this_is_template"
    # my_ri_aux_basis_set = 'RI-5Z'  # often fails
    organic_elements = [
        'H', 'C', 'N', 'O', 'F', 'P', 'S', 'Cl', 'Br', 'B', 'I'
    ]
    my_elements = organic_elements
    inp_file_name = 'test_2345.inp'
    my_vdw_parameters_file = 'dftd3.dat'
    activate_vdw = False
    activate_outer_scf = False
    wf_corr_num_proc = 1  # 16 in the ref paper; -1 to use all

    ########################################### CREATE TEMPLATE FOR TWO RUNS ###########################################
    calc = CP2K()
    calc.working_directory = './'
    calc.project_name = 'artem_gw_project'
    calc.mpi_n_processes = 1

    # pycp2k objects
    CP2K_INPUT = calc.CP2K_INPUT
    FORCE_EVAL = CP2K_INPUT.FORCE_EVAL_add()
    FORCE_EVAL.Method = 'QUICKSTEP'
    SUBSYS = FORCE_EVAL.SUBSYS
    DFT = FORCE_EVAL.DFT
    XC = DFT.XC
    SCF = DFT.SCF
    OUTER_SCF = DFT.SCF.OUTER_SCF
    ####################################################################################################################

    # GLOBAL #
    # FORCE EVAL #
    set_global(CP2K_INPUT, project_name=my_project_name)

    ## SUBSYS ##
    set_unperiodic_cell(SUBSYS, abc=my_abc)
    set_nonperiodic_poisson(DFT)
    set_topology(SUBSYS, xyz_file_name=xyz_file_name)
    center_coordinates(SUBSYS)
    ## END SUBSYS ##

    ## DFT ##
    set_dft(DFT,
            potential_file_name=my_potential_file_name,
            basis_set_file_name=basis_set_file_name)
    set_cutoff(DFT, cutoff=cutoff, rel_cutoff=rel_cutoff, ngrids=5)
    set_scf(DFT, eps_scf=1.0E-9, max_scf=500, scf_guess='ATOMIC')
    add_ot(SCF, stepsize=0.05)
    #
    # add_outer_scf(OUTER_SCF)
    set_pbe(XC)  # we start with pbe
    # set_pbe0(XC) no pbe0 in the beginning
    set_qs(DFT, eps_default=1.0E-10, eps_pgf_orb=np.sqrt(1.0E-10))

    # print_mo(DFT.PRINT)
    if activate_vdw:
        add_vdw(XC, vdw_parameters_file=my_vdw_parameters_file)
    ## END DFT ##

######################################## END: CREATE TEMPLATE ##########################################################

######################################## BEGIN: RUN CP2K TWO TIMES #####################################################
    suffix = ['2', '3', '4']  # cardinal numbers of the database

    # begin: input_from_yaml
    # cp2k_exe_path = '/home/artem/soft/cp2k/cp2k-7.1/exe/local/cp2k.popt'
    cp2k_exe_path = '/home/ws/bh5670/cp2k/cp2k-7.1/exe/local/cp2k.popt'
    my_run_type = 'mpi'

    for i_bs, suffix in enumerate(suffix):
        # bs

        calc_ = deepcopy(calc)

        #
        CP2K_INPUT_ = calc_.CP2K_INPUT
        FORCE_EVAL_ = CP2K_INPUT_.FORCE_EVAL_list[0]
        SUBSYS_ = FORCE_EVAL_.SUBSYS
        DFT_ = FORCE_EVAL_.DFT
        XC_ = DFT_.XC
        SCF_ = DFT_.SCF
        OUTER_SCF_ = DFT_.SCF.OUTER_SCF
        #

        set_global(CP2K_INPUT_, project_name=suffix)
        add_elements(SUBSYS_,
                     elements=my_elements,
                     basis=my_basis_sets[i_bs],
                     aux_basis=my_ri_basis_sets[i_bs],
                     pot=my_potential)
        # bs
        output_file = f'out_{suffix}.out'
        ot_file_name = 'OT_' + f'{suffix}_' + inp_file_name
        diag_file_name = 'DIAG_' + f'{suffix}_' + inp_file_name
        # end: input

        if i_bs != 0:
            set_scf(DFT_, eps_scf=1.0E-8, max_scf=500, scf_guess='RESTART'
                    )  # TZ,QZ will start from RESTART of the DZ,QZ
            try:
                copy(sim_folder_scratch + '/' + f'{int(suffix)-1}-RESTART.wfn',
                     sim_folder_scratch + '/' + f'{suffix}-RESTART.wfn')
                print('copied restart file 2->3 or 3->4')
            except:
                print('not succesfull copy of the restart file')
        elif i_bs == 0:
            set_scf(DFT_, eps_scf=1.0E-8, max_scf=500,
                    scf_guess='ATOMIC')  # DZ with ATOMIC guess

        # OT run to converge quickly
        calc_.write_input_file(sim_folder_scratch + '/' + ot_file_name)
        # first run
        print(f"Running PBE with OT (basis set = {suffix})...")
        if not dummy_run:
            cp2k_run(input_file=ot_file_name,
                     xyz_file=xyz_file_name,
                     run_type=my_run_type,
                     np=threads,
                     output_file=f'out_ot_{suffix}.out',
                     cp2k_executable=cp2k_exe_path,
                     execution_directory=sim_folder_scratch)
            # end: first run
        print(f"I have finished cp2k with OT (basis set = {suffix})")

        # DIAGONALIZATION RUN to reliably compute H**O and then GW
        # remove the OT method
        remove_ot(SCF_)

        # change calculations to a diagonalization
        add_diagonalization(SCF_)
        # add_smear(SCF_)  # uses final T.
        add_mixing(SCF_)  # add or not?
        add_mos(SCF_, added_mos=1000)
        # plot h**o/lumo

        #set_pbe0(XC_)  # we want G0W0@PBE0. no pbe0 in the beginning
        print_mo_cubes(DFT_.PRINT, nhomo=10,
                       nlumo=10)  # all HOMOs are typicall plotted
        set_scf(DFT_, eps_scf=1E-6, max_scf=200)
        # add G0W0!
        add_gw_ver_0(XC_,
                     ev_sc_iter=1,
                     wf_corr_num_proc=wf_corr_num_proc,
                     rpa_num_quad_points=100,
                     max_memory_wf=4000,
                     max_memory_hf=500,
                     corr_occ=1,
                     corr_virt=1)  # GW!
        # it is important to keep WF memory smaller than HF memory, otherwise, it crashes
        calc_.write_input_file(sim_folder_scratch + '/' + diag_file_name)
        # second run
        print(f"Running G0W0 with DIAG (basis set = {suffix})...")
        my_out_file2 = f'out_diag_{suffix}.out'
        if not dummy_run:
            cp2k_run(input_file=diag_file_name,
                     xyz_file=xyz_file_name,
                     output_file=my_out_file2,
                     run_type=my_run_type,
                     np=threads,
                     cp2k_executable=cp2k_exe_path,
                     execution_directory=sim_folder_scratch)
            print(f"I have finished cp2k with DIAG (basis set = {suffix})")

            # extract h**o/lumo and gw h**o/lumo from the cp2k output file:
            path_to_out2_file = sim_folder_scratch + '/' + my_out_file2

            # extract from the output
            try:
                num_orb = extract_number_of_independent_orbital_function(
                    path_to_out2_file)
                print(
                    f'basis set = {suffix}, number of independent orbital functions: {num_orb}'
                )
            except:
                print('number of orbatals was not extracted')
                num_orb = 'not extracted'

            try:
                homos, lumos = [], []
                homos, lumos = return_homo_lumo(path_to_out2_file)
                print(f'basis set = {suffix} ', 'h**o = ',
                      homos[-1] * eV_to_Hartree(), ' eV')
                print(f'basis set = {suffix} ', 'lumo = ',
                      lumos[0] * eV_to_Hartree(), ' eV')
                h**o = homos[-1] * eV_to_Hartree()
                lumo = lumos[0] * eV_to_Hartree()
            except:
                print(f'H**o/Lumo were not extracted')
                h**o = 'not extracted'
                lumo = 'not extracted'

            try:
                gw_occ, gw_vir, homo_, lumo_ = return_gw_energies(
                    path_to_out2_file)
                if isinstance(h**o, str) and isinstance(lumo, str):
                    h**o = homo_
                    lumo = lumo_
                print(f'basis set = {suffix} ', 'h**o = ', h**o, ' eV')
                print(f'basis set = {suffix} ', 'lumo = ', lumo, ' eV')
                print(f'basis set = {suffix} ', 'gw h**o = ', gw_occ, ' eV')
                print(f'basis set = {suffix} ', 'gw lumo = ', gw_vir, ' eV')
            except:
                print("GW energies were not extracted")
                gw_occ = 'not extracted'
                gw_vir = 'not extracted'

            del calc_

            #  put computed data into the molecule object
            my_new_mol.add_energies(int(suffix), h**o, lumo, gw_occ, gw_vir)
            my_new_mol.add_num_orbitals(int(suffix), num_orb)
            my_new_mol.extrapolate_energy()
            db_record = my_new_mol.yield_dict(
            )  # this dict will be written into yaml. it will be a record in the global library
            #

    print("\nI am done\n")
    print('saving to DB...')

    with open(f'{database_folder}/DB_{rank}.yaml', 'w') as stream:
        yaml.safe_dump(db_record, stream)

    print(f"saved to {database_folder}/DB_{rank}.yaml")
    print('I will remove the content the sim folder')

    # Clean up before leave
    status = my_new_mol.status()
    if status == 'all_extracted':  # all quantities are extracted
        if debug:
            print(
                f'status: {status}, but debug is on ==> will move {sim_folder_scratch} to {sim_folder_home}'
            )
            copytree(sim_folder_scratch,
                     sim_folder_home)  # will rewrite the folder
        else:
            print(f'status: {status} ==> will remove {sim_folder_scratch}')
            try_to_remove_folder(sim_folder_scratch)
    else:
        print(f'status: {status} ==> will copy failed sim folder from scratch')
        #if not os.path.exists(sim_folder_home):
        #os.mkdir(sim_folder_home)   # will overwrite if exists
        copytree(sim_folder_scratch,
                 sim_folder_home)  # will rewrite the folder
        print(f"I have copied {sim_folder_scratch} to {sim_folder_home}")
        try_to_remove_folder(sim_folder_scratch)
コード例 #8
0
ファイル: 2345.py プロジェクト: ArtemFediai/mypycp2k
def main():
    # My input_from_yaml #

    # rel_cutoff: 40; cutoff: 300; abc = 10
    my_abc = '10.0 10.0 10.0'
    cutoff = 300
    rel_cutoff = 40

    # GLOBAL SETTINGS
    threads = 121  # cpus used to compute
    #

    ## base settings ##
    #basis_set_base_path = '/home/artem/soft/cp2k/cp2k-7.1/data/'
    basis_set_base_path = ''
    # my_basis_set_file_name = basis_set_base_path + 'BASIS_RI_cc-TZ'G
    #my_basis_set_file_name = basis_set_base_path + 'BASIS_def2_QZVP_RI_ALL'
    basis_set_file_name = 'BASIS_CC_AUG_RI'  # RI5, 2-5 cc, all aug-cc
    my_vdw_parameters_file = basis_set_base_path + 'dftd3.dat'
    #my_basis_set = 'def2-QZVP'  # not used
    # my_basis_sets = ['cc-pVDZ', 'cc-pVTZ', 'cc-pVQZ', 'cc-pV5Z']
    my_basis_sets = [
        'aug-cc-pVDZ', 'aug-cc-pVTZ', 'aug-cc-pVQZ', 'aug-cc-pV5Z'
    ]
    # my_potential_file_name = basis_set_base_path + 'POTENTIAL'
    my_potential_file_name = 'POTENTIAL'
    my_potential = 'ALL'
    my_project_name = "this_is_template"
    my_xyz_file_name = 'H2O.xyz'
    my_ri_aux_basis_set = 'RI-5Z'  #
    organic_elements = [
        'H', 'C', 'N', 'O', 'F', 'P', 'S', 'Cl', 'Br', 'B', 'I'
    ]
    my_elements = organic_elements
    inp_file_name = 'test_2345.inp'
    activate_vdw = False
    activate_outer_scf = False
    wf_corr_num_proc = 1  # 16 in the ref paper; -1 to use all

    ########################################### CREATE TEMPLATE FOR TWO RUNS ###########################################
    calc = CP2K()
    calc.working_directory = './'
    calc.project_name = 'artem_gw_project'
    calc.mpi_n_processes = 1

    # pycp2k objects
    CP2K_INPUT = calc.CP2K_INPUT
    FORCE_EVAL = CP2K_INPUT.FORCE_EVAL_add()
    FORCE_EVAL.Method = 'QUICKSTEP'
    SUBSYS = FORCE_EVAL.SUBSYS
    DFT = FORCE_EVAL.DFT
    XC = DFT.XC
    SCF = DFT.SCF
    OUTER_SCF = DFT.SCF.OUTER_SCF
    ####################################################################################################################

    # GLOBAL #
    # FORCE EVAL #
    set_global(CP2K_INPUT, project_name=my_project_name)
    #set_force_eval(FORCE_EVAL)

    ## SUBSYS ##
    set_unperiodic_cell(SUBSYS, abc=my_abc)
    set_nonperiodic_poisson(DFT)
    set_topology(SUBSYS, xyz_file_name=my_xyz_file_name)
    # add_elements(SUBSYS,
    #              elements=elements,
    #              basis=my_basis_set,
    #              aux_basis=my_ri_aux_basis_set,
    #              pot=my_potential)
    center_coordinates(SUBSYS)
    ## END SUBSYS ##

    ## DFT ##
    set_dft(DFT,
            potential_file_name=my_potential_file_name,
            basis_set_file_name=basis_set_file_name)
    set_cutoff(DFT, cutoff=cutoff, rel_cutoff=rel_cutoff, ngrids=5)
    set_scf(DFT, eps_scf=1.0E-8, max_scf=500)
    add_ot(SCF)
    #
    # add_outer_scf(OUTER_SCF)
    set_pbe(XC)  # we start with pbe
    # set_pbe0(XC) no pbe0 in the beginning
    set_qs(DFT, eps_default=1.0E-10, eps_pgf_orb=np.sqrt(1.0E-10))

    # print_mo(DFT.PRINT)
    if activate_vdw:
        add_vdw(XC, vdw_parameters_file=my_vdw_parameters_file)
    ## END DFT ##

######################################## END: CREATE TEMPLATE ##########################################################

######################################## BEGIN: RUN CP2K TWO TIMES #####################################################
    suffix = ['2', '3', '4', '5']  # of out folde

    # begin: input_from_yaml
    # cp2k_exe_path = '/home/artem/soft/cp2k/cp2k-7.1/exe/local/cp2k.popt'
    cp2k_exe_path = '/home/ws/bh5670/cp2k/cp2k-7.1/exe/local/cp2k.popt'
    run_folder = '2345_run_folder'
    if not os.path.exists(run_folder):
        os.mkdir(run_folder)
    my_xyz_file_name = 'H2O.xyz'
    my_run_type = 'mpi'

    for i_bs, suffix in enumerate(suffix):
        # bs

        calc_ = deepcopy(calc)

        #
        CP2K_INPUT_ = calc_.CP2K_INPUT
        FORCE_EVAL_ = CP2K_INPUT_.FORCE_EVAL_list[0]
        SUBSYS_ = FORCE_EVAL_.SUBSYS
        DFT_ = FORCE_EVAL_.DFT
        XC_ = DFT_.XC
        SCF_ = DFT_.SCF
        OUTER_SCF_ = DFT_.SCF.OUTER_SCF
        #

        set_global(CP2K_INPUT_, project_name=suffix)
        add_elements(SUBSYS_,
                     elements=my_elements,
                     basis=my_basis_sets[i_bs],
                     aux_basis=my_ri_aux_basis_set,
                     pot=my_potential)
        # bs
        output_file = f'out_{suffix}.out'
        ot_file_name = 'OT_' + f'{suffix}_' + inp_file_name
        diag_file_name = 'DIAG_' + f'{suffix}_' + inp_file_name
        # end: input_from_yaml

        # OT run to converge quickly
        calc_.write_input_file(run_folder + '/' + ot_file_name)
        # first run
        print(f"Running PBE with OT (basis set = {suffix})...")
        if True:
            cp2k_run(input_file=ot_file_name,
                     xyz_file=my_xyz_file_name,
                     run_type=my_run_type,
                     np=threads,
                     output_file=f'out_ot_{suffix}.out',
                     cp2k_executable=cp2k_exe_path,
                     execution_directory=run_folder)
            # end: first run
        print(f"I have finished cp2k with OT (basis set = {suffix})")

        # remove the OT method
        remove_ot(SCF_)

        # change calculations to a diagonalization
        add_diagonalization(SCF_)
        # add_smear(SCF)  # add or not?
        # add_mixing(SCF)  # add or not?
        # add_mos(SCF)  # add or not?
        # plot h**o/lumo

        set_pbe0(XC_)  # we want G-W0@PBE0. no pbe0 in the beginning
        print_mo_cubes(DFT_.PRINT, nhomo=10,
                       nlumo=10)  #  all HOMOs are typicall plotted
        set_scf(DFT_, eps_scf=1E-6)
        # add G0W0!
        add_gw_ver_0(
            XC_,
            ev_sc_iter=1,
            wf_corr_num_proc=wf_corr_num_proc,
            rpa_num_quad_points=100,
        )  # GW!

        # DIAGONALIZATION RUN to reliably compute H**O and then GW
        calc_.write_input_file(run_folder + '/' + diag_file_name)
        # second run
        print(f"Running G0W0 with DIAG (basis set = {suffix})...")
        my_out_file2 = f'out_diag_{suffix}.out'
        if True:
            cp2k_run(input_file=diag_file_name,
                     xyz_file=my_xyz_file_name,
                     output_file=my_out_file2,
                     run_type=my_run_type,
                     np=threads,
                     cp2k_executable=cp2k_exe_path,
                     execution_directory=run_folder)
            print(f"I have finished cp2k with DIAG (basis set = {suffix})")

            # extract h**o/lumo and gw h**o/lumo from the cp2k output file:
            path_to_out2_file = run_folder + '/' + my_out_file2

            try:

                homos, lumos = [], []
                homos, lumos = return_homo_lumo(path_to_out2_file)

                print('basis set = {suffix} ', 'h**o = ',
                      homos[-1] * eV_to_Hartree(), ' eV')
                print('basis set = {suffix} ', 'lumo = ',
                      lumos[0] * eV_to_Hartree(), ' eV')

                gw_occ, gw_vir = return_gw_energies(path_to_out2_file)

                print('basis set = {suffix} ', 'gw h**o = ', gw_occ, ' eV')
                print('basis set = {suffix} ', 'gw lumo = ', gw_vir, ' eV')
            except:
                print("H**O/LUMO and GW were not extracted")

        print("\nI am done")
        del calc_
コード例 #9
0
def main():
    # My input #

    # rel_cutoff: 40; cutoff: 300; abc = 10
    my_abc = '10.0 10.0 10.0'
    cutoff = 300
    rel_cutoff = 40

    ## base settings ##
    basis_set_base_path = '/home/artem/soft/cp2k/cp2k-7.1/data/'
    # my_basis_set_file_name = basis_set_base_path + 'BASIS_RI_cc-TZ'G
    my_basis_set_file_name = basis_set_base_path + 'BASIS_def2_QZVP_RI_ALL'
    my_vdw_parameters_file = basis_set_base_path + 'dftd3.dat'
    my_basis_set = 'def2-QZVP'
    my_potential_file_name = basis_set_base_path + 'POTENTIAL'
    my_potential = 'ALL'
    my_project_name = "methane_GW_PBE"
    my_xyz_file_name = 'methane.xyz'
    my_ri_aux_basis_set = 'RI-5Z'  #
    # organic_elements = ['H', 'C', 'N', 'O', 'F', 'P', 'S', 'Cl', 'Br', 'B', 'I']
    # my_elements = ['H', 'O']  # for test
    # my_element = ['H']  # for test
    my_elements = ['H', 'C']
    inp_file_name = 'GW_PBE_for_methane.inp'
    activate_vdw = False
    activate_outer_scf = False
    activate_ot = False
    activate_diagonalization = not activate_outer_scf
    wf_corr_num_proc = 4  # 16 in the ref paper; -1 to use all

    ####################################################################################################################
    calc = CP2K()
    calc.working_directory = './'
    calc.project_name = 'artem_gw_project'
    calc.mpi_n_processes = 1

    # pycp2k objects
    CP2K_INPUT = calc.CP2K_INPUT
    FORCE_EVAL = CP2K_INPUT.FORCE_EVAL_add()
    FORCE_EVAL.Method = 'QUICKSTEP'
    SUBSYS = FORCE_EVAL.SUBSYS
    DFT = FORCE_EVAL.DFT
    XC = DFT.XC
    SCF = DFT.SCF
    OUTER_SCF = DFT.SCF.OUTER_SCF
    ####################################################################################################################

    # GLOBAL #
    # FORCE EVAL #
    set_global(CP2K_INPUT, project_name=my_project_name)
    #set_force_eval(FORCE_EVAL)

    ## SUBSYS ##
    set_unperiodic_cell(SUBSYS, abc=my_abc)
    set_nonperiodic_poisson(DFT)
    set_topology(SUBSYS, xyz_file_name=my_xyz_file_name)
    add_elements(SUBSYS,
                 elements=my_elements,
                 basis=my_basis_set,
                 aux_basis=my_ri_aux_basis_set,
                 pot=my_potential)
    center_coordinates(SUBSYS)
    ## END SUBSYS ##

    ## DFT ##
    set_dft(DFT,
            potential_file_name=my_potential_file_name,
            basis_set_file_name=my_basis_set_file_name)
    set_cutoff(DFT, cutoff=cutoff, rel_cutoff=rel_cutoff, ngrids=5)
    set_scf(DFT, eps_scf=1.0E-10)
    if activate_ot:
        add_ot(SCF)
    else:
        add_diagonalization(SCF)
        add_smear(SCF)
        add_mixing(SCF)
        add_mos(SCF)
    #
    add_outer_scf(OUTER_SCF)
    set_pbe(XC)  # alter: set_pb0, etc.
    set_qs(DFT, eps_default=1.0E-15, eps_pgf_orb=1.0E-200)
    add_gw_ver_0(XC)  # GW!
    print_mo_cubes(DFT.PRINT)
    print_mo(DFT.PRINT)
    if activate_vdw:
        add_vdw(XC, vdw_parameters_file=my_vdw_parameters_file)
    ## END DFT ##

########################################################################################################################
    calc.write_input_file(inp_file_name)
    # calc.run()
    print("I am done")
コード例 #10
0
from pycp2k import CP2K
from ase.lattice.cubic import Diamond
from ase.visualize import view

#===============================================================================
# Create the Si lattice here
lattice = Diamond(directions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]],
                  symbol='Si',
                  latticeconstant=5.430697500,
                  size=(1, 1, 1))

# view(lattice)

#===============================================================================
# Setup directories and mpi
calc = CP2K()
calc.working_directory = "./"
calc.project_name = "si_bulk"
calc.mpi_n_processes = 2

#===============================================================================
# Create shortcuts for the most used subtrees of the input
CP2K_INPUT = calc.CP2K_INPUT
GLOBAL = CP2K_INPUT.GLOBAL
FORCE_EVAL = CP2K_INPUT.FORCE_EVAL_add()
SUBSYS = FORCE_EVAL.SUBSYS
DFT = FORCE_EVAL.DFT
SCF = DFT.SCF

#===============================================================================
# Fill input tree
コード例 #11
0
ファイル: 234.py プロジェクト: ArtemFediai/mypycp2k
def main():

    general_sim_folder = 'sim'
    database_file = 'db'
    my_offset = 10  # from the molecule to a vacuum. 15-20 is recommended!
    # it has to exist

    dummy_run = False  # does not invoke cp2k if true

    #  parser begin
    parser = argparse.ArgumentParser(description='rank and num of cpus')
    parser.add_argument('-rank')  # array job number
    parser.add_argument('-num_cpus')  # number of cpus you request for every array job
    args = parser.parse_args()
    #  parser end


    # My input #
    threads = args.num_cpus  # cpus used to compute
    rank = '{:0>6}'.format(args.rank)
    original_xyz_file_name = f'dsgdb9nsd_{rank}.xyz'

    db_xyz_file = f'dsgdb9nsd/{original_xyz_file_name}'
    sim_folder = f'{general_sim_folder}/{rank}'
    sim_folder_scratch = f'/scratch/bh5670/{rank}'
    if not os.path.exists(sim_folder):
        os.mkdir(sim_folder)
    if not os.path.exists(sim_folder_scratch):
        os.mkdir(sim_folder_scratch)

    # use scratch
    sim_folder = sim_folder_scratch
    #

    # xyz object, normal xyz file
    my_xyz_file_obj = XYZ.from_file(db_xyz_file)  # home
    my_xyz_file_to_write = sim_folder + '/' + original_xyz_file_name  # home
    my_xyz_file_obj.write(my_xyz_file_to_write)  # this written file will be called
    my_xyz_file = original_xyz_file_name  # just a name
    # scratch
    my_xyz_file_to_write_to_scratch = sim_folder_scratch + '/' + original_xyz_file_name
    my_xyz_file_obj.write(my_xyz_file_to_write_to_scratch)  # writes to scratch

    # End: My input_from_yaml

    # DB
    my_new_mol = Cp2kOutput(rank)

    # rel_cutoff: 40; cutoff: 300; abc = 10
    my_abc = str(my_xyz_file_obj.compute_box_size(offset=my_offset))[1:-2]
    print(my_abc)
    cutoff = 300
    rel_cutoff = 40

    # GLOBAL SETTINGS
    #

    ## base settings ##
    #my_basis_set_file_name = basis_set_base_path + 'BASIS_def2_QZVP_RI_ALL'
    basis_set_file_name = 'BASIS_CC_AUG_RI'  # RI5, 2-5 cc, all aug-cc
    my_vdw_parameters_file = 'dftd3.dat'
    # my_basis_sets = ['cc-pVDZ', 'cc-pVTZ', 'cc-pVQZ', 'cc-pV5Z']
    my_basis_sets = ['aug-cc-pVDZ', 'aug-cc-pVTZ', 'aug-cc-pVQZ', 'aug-cc-pV5Z']
    # my_potential_file_name = basis_set_base_path + 'POTENTIAL'
    my_potential_file_name = 'POTENTIAL'
    my_potential = 'ALL'
    my_project_name = "this_is_template"
    my_ri_aux_basis_set = 'RI-5Z'  #
    organic_elements = ['H', 'C', 'N', 'O', 'F', 'P', 'S', 'Cl', 'Br', 'B', 'I']
    my_elements = organic_elements
    inp_file_name = 'test_2345.inp'
    activate_vdw = False
    activate_outer_scf = False
    wf_corr_num_proc = 1  # 16 in the ref paper; -1 to use all

    ########################################### CREATE TEMPLATE FOR TWO RUNS ###########################################
    calc = CP2K()
    calc.working_directory = './'
    calc.project_name = 'artem_gw_project'
    calc.mpi_n_processes = 1

    # pycp2k objects
    CP2K_INPUT = calc.CP2K_INPUT
    FORCE_EVAL = CP2K_INPUT.FORCE_EVAL_add()
    FORCE_EVAL.Method = 'QUICKSTEP'
    SUBSYS = FORCE_EVAL.SUBSYS
    DFT = FORCE_EVAL.DFT
    XC = DFT.XC
    SCF = DFT.SCF
    OUTER_SCF = DFT.SCF.OUTER_SCF
    ####################################################################################################################

    # GLOBAL #
    # FORCE EVAL #
    set_global(CP2K_INPUT, project_name=my_project_name)
    #set_force_eval(FORCE_EVAL)

    ## SUBSYS ##
    set_unperiodic_cell(SUBSYS, abc=my_abc)
    set_nonperiodic_poisson(DFT)
    set_topology(SUBSYS, xyz_file_name=my_xyz_file)
    # add_elements(SUBSYS,
    #              elements=elements,
    #              basis=my_basis_set,
    #              aux_basis=my_ri_aux_basis_set,
    #              pot=my_potential)
    center_coordinates(SUBSYS)
    ## END SUBSYS ##

    ## DFT ##
    set_dft(DFT,
            potential_file_name=my_potential_file_name,
            basis_set_file_name=basis_set_file_name)
    set_cutoff(DFT, cutoff=cutoff, rel_cutoff=rel_cutoff, ngrids=5)
    set_scf(DFT, eps_scf=1.0E-10, max_scf=500)
    add_ot(SCF)
    #
    # add_outer_scf(OUTER_SCF)
    set_pbe(XC)  # we start with pbe
    # set_pbe0(XC) no pbe0 in the beginning
    set_qs(DFT,
           eps_default=1.0E-10,
           eps_pgf_orb=np.sqrt(1.0E-10))

    # print_mo(DFT.PRINT)
    if activate_vdw:
        add_vdw(XC, vdw_parameters_file=my_vdw_parameters_file)
    ## END DFT ##

######################################## END: CREATE TEMPLATE ##########################################################


######################################## BEGIN: RUN CP2K TWO TIMES #####################################################
    suffix = ['2', '3', '4']  # of out folde

    # begin: input
    # cp2k_exe_path = '/home/artem/soft/cp2k/cp2k-7.1/exe/local/cp2k.popt'
    cp2k_exe_path = '/home/ws/bh5670/cp2k/cp2k-7.1/exe/local/cp2k.popt' 
    my_run_type = 'mpi'

    for i_bs, suffix in enumerate(suffix):
        # bs

        calc_ = deepcopy(calc)

        #
        CP2K_INPUT_ = calc_.CP2K_INPUT
        FORCE_EVAL_ = CP2K_INPUT_.FORCE_EVAL_list[0]
        SUBSYS_ = FORCE_EVAL_.SUBSYS
        DFT_ = FORCE_EVAL_.DFT
        XC_ = DFT_.XC
        SCF_ = DFT_.SCF
        OUTER_SCF_ = DFT_.SCF.OUTER_SCF
        #

        set_global(CP2K_INPUT_, project_name=suffix)
        add_elements(SUBSYS_,
                     elements=my_elements,
                     basis=my_basis_sets[i_bs],
                     aux_basis=my_ri_aux_basis_set,
                     pot=my_potential)
        # bs
        output_file = f'out_{suffix}.out'
        ot_file_name = 'OT_' + f'{suffix}_' + inp_file_name
        diag_file_name = 'DIAG_' + f'{suffix}_' + inp_file_name
        # end: input

        # OT run to converge quickly
        calc_.write_input_file(sim_folder + '/' + ot_file_name)
        # first run
        print(f"Running PBE with OT (basis set = {suffix})...")
        if not dummy_run:
            cp2k_run(input_file=ot_file_name,
                     xyz_file=my_xyz_file,
                     run_type=my_run_type,
                     np=threads,
                     output_file=f'out_ot_{suffix}.out',
                     cp2k_executable=cp2k_exe_path,
                     execution_directory=sim_folder)
            # end: first run
        print(f"I have finished cp2k with OT (basis set = {suffix})")

        # remove the OT method
        remove_ot(SCF_)

        # change calculations to a diagonalization
        add_diagonalization(SCF_)
        add_smear(SCF_)  # add or not?
        add_mixing(SCF_)  # add or not?
        add_mos(SCF_)  # add or not?
        # plot h**o/lumo

        set_pbe0(XC_)  # we want G-W0@PBE0. no pbe0 in the beginning
        print_mo_cubes(DFT_.PRINT, nhomo=10, nlumo=10)  #  all HOMOs are typicall plotted
        set_scf(DFT_, eps_scf=1E-6)
        # add G0W0!
        add_gw_ver_0(XC_,
                     ev_sc_iter=1,
                     wf_corr_num_proc=wf_corr_num_proc,
                     rpa_num_quad_points=100,
                     )  # GW!

        # DIAGONALIZATION RUN to reliably compute H**O and then GW
        calc_.write_input_file(sim_folder + '/' + diag_file_name)
        # second run
        print(f"Running G0W0 with DIAG (basis set = {suffix})...")
        my_out_file2 = f'out_diag_{suffix}.out'
        if not dummy_run:
            cp2k_run(input_file=diag_file_name,
                     xyz_file=my_xyz_file,
                     output_file=my_out_file2,
                     run_type=my_run_type,
                     np=threads,
                     cp2k_executable=cp2k_exe_path,
                     execution_directory=sim_folder)
            print(f"I have finished cp2k with DIAG (basis set = {suffix})")

            # extract h**o/lumo and gw h**o/lumo from the cp2k output file:
            path_to_out2_file = sim_folder + '/' + my_out_file2

            try:
                num_orb = extract_number_of_independent_orbital_function(path_to_out2_file)
                print(f'basis set = {suffix}, number of independent orbital functions: {num_orb}')
            except:
                print('number of orbatals was not extracted')
                num_orb = 'not extracted'

            try:
                homos, lumos = [], []
                homos, lumos = return_homo_lumo(path_to_out2_file)
                print(f'basis set = {suffix} ', 'h**o = ', homos[-1]*eV_to_Hartree(), ' eV')
                print(f'basis set = {suffix} ', 'lumo = ', lumos[0]*eV_to_Hartree(), ' eV')
                h**o = homos[-1]*eV_to_Hartree()
                lumo = lumos[0]*eV_to_Hartree()
            except:
                print(f'H**o/Lumo were not extracted')
                h**o = 'not extracted'
                lumo = 'not extracted'

            try:
                gw_occ, gw_vir, homo_, lumo_ = return_gw_energies(path_to_out2_file)
                if isinstance(h**o, str) or isinstance(lumo, str):
                    h**o = homo_
                    lumo = lumo_
                print(f'basis set = {suffix} ', 'h**o = ', h**o, ' eV')
                print(f'basis set = {suffix} ', 'lumo = ', lumo, ' eV')
                print(f'basis set = {suffix} ', 'gw h**o = ', gw_occ, ' eV')
                print(f'basis set = {suffix} ', 'gw lumo = ', gw_vir, ' eV')
            except:
                print("GW energies were not extracted")
                gw_occ = 'not extracted'
                gw_vir = 'not extracted'

            del calc_

            #
            my_new_mol.add_energies(int(suffix), h**o, lumo, gw_occ, gw_vir)
            my_new_mol.add_num_orbitals(int(suffix), num_orb)
            my_new_mol.extrapolate_energy()
            db_record = my_new_mol.yield_dict()
            #

    print("\nI am done\n")
    print('saving to DB...')

    with open(f'{database_file}/DB_{rank}.yaml', 'w') as stream:
        yaml.safe_dump(db_record, stream)

    print(f"saved to DB_{rank}")
コード例 #12
0
def _createNearBlankCP2KObject():
    outObj = CP2K()
    outObj.working_directory = os.path.abspath(os.getcwd())
    outObj.project_name = "cp2k_file"
    return outObj
コード例 #13
0
def main():
    # My input_from_yaml #
    ## base settings ##
    basis_set_base_path = '/home/artem/soft/cp2k/cp2k-7.1/data/'
    my_abc = '16.0 16.0 16.0'
    # my_basis_set_file_name = basis_set_base_path + 'BASIS_RI_cc-TZ'G
    my_basis_set_file_name = basis_set_base_path + 'BASIS_def2_QZVP_RI_ALL'
    my_vdw_parameters_file = basis_set_base_path + 'dftd3.dat'
    my_basis_set = 'def2-QZVP'
    my_potential_file_name = basis_set_base_path + 'POTENTIAL'
    my_potential = 'ALL'
    my_project_name = "methane_GW_PBE"
    my_xyz_file_name = 'methane.xyz'
    my_ri_aux_basis_set = 'RI-5Z'  #
    # organic_elements = ['H', 'C', 'N', 'O', 'F', 'P', 'S', 'Cl', 'Br', 'B', 'I']
    # elements = ['H', 'O']  # for test
    # my_element = ['H']  # for test
    my_elements = ['H', 'C']
    activate_vdw = False

    ############################################# pycp2k ###############################################################
    calc = CP2K()
    calc.working_directory = './'
    calc.project_name = 'artem_gw_project'
    calc.mpi_n_processes = 1

    # pycp2k objects
    CP2K_INPUT = calc.CP2K_INPUT
    FORCE_EVAL = CP2K_INPUT.FORCE_EVAL_add()
    FORCE_EVAL.Method = 'QUICKSTEP'
    SUBSYS = FORCE_EVAL.SUBSYS
    DFT = FORCE_EVAL.DFT
    XC = DFT.XC
    SCF = DFT.SCF
    ################################################ mypycp2k ##########################################################

    # GLOBAL #
    # FORCE EVAL #
    set_global(CP2K_INPUT, project_name=my_project_name)
    #set_force_eval(FORCE_EVAL)

    ## SUBSYS ##
    set_unperiodic_cell(SUBSYS, abc=my_abc)
    set_nonperiodic_poisson(DFT)
    set_topology(SUBSYS, xyz_file_name=my_xyz_file_name)
    add_elements(SUBSYS,
                 elements=my_elements,
                 basis=my_basis_set,
                 aux_basis=my_ri_aux_basis_set,
                 pot=my_potential)
    center_coordinates(SUBSYS)
    ## END SUBSYS ##

    ## DFT ##
    set_dft(DFT,
            potential_file_name=my_potential_file_name,
            basis_set_file_name=my_basis_set_file_name)
    set_cutoff(DFT, cutoff=900, rel_cutoff=100, ngrids=5)
    set_scf(DFT, max_scf=1)
    add_ot(SCF)
    set_pbe(XC)  # alter: set_pb0, etc.
    set_qs(DFT,
           eps_default=1.0E-15,
           eps_pgf_orb=1.0E-200)
    # add_gw_ver_0(XC)  # GW!
    #print_mo_cubes(DFT.PRINT)
    #print_mo(DFT.PRINT)
    if activate_vdw:
        add_vdw(XC, vdw_parameters_file=my_vdw_parameters_file)
    ## END DFT ##

############################################### CHECK CONVERGENCE ######################################################

    my_target_accuracy_eV = 1.E-3
    if True:
        my_abcs = [8, 10, 12, 14, 16]
        my_cutoff = [100, 200, 300, 400, 500, 600, 700, 800, 900]
        my_rel_cutoff = [20, 40, 60, 70, 80, 90, 100]

    if False:
        my_abcs = [6, 8, 10]
        my_cutoff = [100, 200, 300]
        my_rel_cutoff = [40, 50, 60]

    print(f"Reference parameters are: \n "
          f"cutoff = {calc.CP2K_INPUT.FORCE_EVAL_list[0].DFT.MGRID.Cutoff},\n "
          f"rel_cut = {calc.CP2K_INPUT.FORCE_EVAL_list[0].DFT.MGRID.Rel_cutoff},\n "
          f"abc = {calc.CP2K_INPUT.FORCE_EVAL_list[0].SUBSYS.CELL.Abc}\n")

    # check abc (cell size) convergence
    general_convergence(calc=copy.deepcopy(calc),
                        params=my_abcs,
                        func_to_accept_param=change_calc_abc,
                        target_accuracy_eV=my_target_accuracy_eV,
                        param_name='abc')

    # check cutoff (absolute) convergence
    general_convergence(calc=copy.deepcopy(calc),
                        params=my_cutoff,
                        func_to_accept_param=change_calc_cutoff,
                        target_accuracy_eV=my_target_accuracy_eV,
                        param_name='cutoff')

    # check cutoff (relative) convergence
    general_convergence(calc=copy.deepcopy(calc),
                        params=my_rel_cutoff,
                        func_to_accept_param=change_calc_rel_cutoff,
                        target_accuracy_eV=my_target_accuracy_eV,
                        param_name='rel_cutoff')
コード例 #14
0
def main():
    # My input #

    # rel_cutoff: 40; cutoff: 300; abc = 10
    my_abc = '10.0 10.0 10.0'
    cutoff = 300
    rel_cutoff = 40

    ## base settings ##
    basis_set_base_path = '/home/artem/soft/cp2k/cp2k-7.1/data/'
    # my_basis_set_file_name = basis_set_base_path + 'BASIS_RI_cc-TZ'G
    my_basis_set_file_name = basis_set_base_path + 'BASIS_def2_QZVP_RI_ALL'
    my_vdw_parameters_file = basis_set_base_path + 'dftd3.dat'
    my_basis_set = 'def2-QZVP'
    my_potential_file_name = basis_set_base_path + 'POTENTIAL'
    my_potential = 'ALL'
    my_project_name = "methane_GW_PBE"
    my_xyz_file_name = 'methane.xyz'
    my_ri_aux_basis_set = 'RI-5Z'  #
    # organic_elements = ['H', 'C', 'N', 'O', 'F', 'P', 'S', 'Cl', 'Br', 'B', 'I']
    # my_elements = ['H', 'O']  # for test
    # my_element = ['H']  # for test
    my_elements = ['H', 'C']
    inp_file_name = 'GW_PBE_for_methane.inp'
    activate_vdw = False
    activate_outer_scf = False
    wf_corr_num_proc = 4  # 16 in the ref paper; -1 to use all

    ########################################### CREATE TEMPLATE FOR TWO RUNS ###########################################
    calc = CP2K()
    calc.working_directory = './'
    calc.project_name = 'artem_gw_project'
    calc.mpi_n_processes = 1

    # pycp2k objects
    CP2K_INPUT = calc.CP2K_INPUT
    FORCE_EVAL = CP2K_INPUT.FORCE_EVAL_add()
    FORCE_EVAL.Method = 'QUICKSTEP'
    SUBSYS = FORCE_EVAL.SUBSYS
    DFT = FORCE_EVAL.DFT
    XC = DFT.XC
    SCF = DFT.SCF
    OUTER_SCF = DFT.SCF.OUTER_SCF
    ####################################################################################################################

    # GLOBAL #
    # FORCE EVAL #
    set_global(CP2K_INPUT, project_name=my_project_name)
    #set_force_eval(FORCE_EVAL)

    ## SUBSYS ##
    set_unperiodic_cell(SUBSYS, abc=my_abc)
    set_nonperiodic_poisson(DFT)
    set_topology(SUBSYS, xyz_file_name=my_xyz_file_name)
    add_elements(SUBSYS,
                 elements=my_elements,
                 basis=my_basis_set,
                 aux_basis=my_ri_aux_basis_set,
                 pot=my_potential)
    center_coordinates(SUBSYS)
    ## END SUBSYS ##

    ## DFT ##
    set_dft(DFT,
            potential_file_name=my_potential_file_name,
            basis_set_file_name=my_basis_set_file_name)
    set_cutoff(DFT, cutoff=cutoff, rel_cutoff=rel_cutoff, ngrids=5)
    set_scf(DFT, eps_scf=1.0E-10)
    add_ot(SCF)
    #
    add_outer_scf(OUTER_SCF)
    set_pbe(XC)  # alter: set_pb0, etc.
    set_qs(DFT, eps_default=1.0E-15, eps_pgf_orb=1.0E-200)
    # add_gw_ver_0(XC)  # GW!
    print_mo_cubes(DFT.PRINT, nhomo=10,
                   nlumo=10)  #  all HOMOs are typicall plotted

    # print_mo(DFT.PRINT)
    if activate_vdw:
        add_vdw(XC, vdw_parameters_file=my_vdw_parameters_file)
    ## END DFT ##

######################################## END: CREATE TEMPLATE ##########################################################

# begin: input
    cp2k_exe_path = '/home/artem/soft/cp2k/cp2k-7.1/exe/local/cp2k.popt'
    run_folder = 'my_run_folder'
    output_file = 'out.out'
    ot_file_name = 'OT_' + inp_file_name
    diag_file_name = 'DIAG_' + inp_file_name
    my_xyz_file_name = 'methane.xyz'
    threads = 4
    my_run_type = 'mpi'
    # end: input

    if not os.path.exists(run_folder):
        os.mkdir(run_folder)

    # OT run to converge quickly
    calc.write_input_file(run_folder + '/' + ot_file_name)
    # first run
    print("Running cp2k with OT ...")
    cp2k_run(input_file=ot_file_name,
             xyz_file=my_xyz_file_name,
             run_type=my_run_type,
             np=threads,
             output_file='out1.out',
             cp2k_executable=cp2k_exe_path,
             execution_directory=run_folder)
    # end: first run
    print("I have finished cp2k with OT")

    # remove the OT method
    remove_ot(SCF)

    # change calculations to a diagonalization
    add_diagonalization(SCF)
    add_smear(SCF)
    add_mixing(SCF)
    add_mos(SCF)

    # DIAGONALIZATION RUN to reliably compute H**O
    calc.write_input_file(run_folder + '/' + diag_file_name)
    # second run
    print("Running cp2k with DIAG ...")
    my_out_file2 = 'out2.out'
    cp2k_run(input_file=diag_file_name,
             xyz_file=my_xyz_file_name,
             output_file=my_out_file2,
             run_type=my_run_type,
             np=threads,
             cp2k_executable=cp2k_exe_path,
             execution_directory=run_folder)
    print("I have finished cp2k with DIAG")

    homos, lumos = [], []
    homos, lumos = return_homo_lumo(run_folder + '/' + my_out_file2)

    print('h**o = ', homos[-1] * eV_to_Hartree(), ' eV')
    print('lumo = ', lumos[0] * eV_to_Hartree(), ' eV')

    print("\nI am done")