def my_cp2k_run(suf='2', ot_or_diag='ot'): cp2k_run(input_file=my_inp_file(suf, ot_or_diag), output_file=my_out_file(suf, ot_or_diag), xyz_file=xyz_file_name, run_type=my_run_type, np=threads, cp2k_executable=cp2k_exe_path, execution_directory=sim_folder_scratch, type_mpi=mpi)
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)
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_
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}")
from cp2k_run.cp2k_run import cp2k_run comm = MPI.COMM_WORLD rank = comm.Get_rank() size = comm.Get_size() parser = argparse.ArgumentParser(description='rank and num of cpus') parser.add_argument('-rank') parser.add_argument('-num_cpus') args = parser.parse_args() print(f'the following argument is passed: {args.rank}') print('Now I will be doing cp2k...') run_folder = f'{args.rank}' # will be created to copy there input_from_yaml file and run cp2k if not os.path.exists(run_folder): os.mkdir(run_folder) cp2k_run( cp2k_executable='cp2k.popt', run_type='mpi', np=args.num_cpus, xyz_file='input_from_yaml.inp', output_file=f'out_{args.rank}.out', error_file=f'err_{args.rank}.err', execution_directory=f'{args.rank}', )
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")
def main(): scratch = os.environ['SCRATCH'] # SCRATCH has to be in the env var dict. Normally, it is. # 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 parser.add_argument('-i') # input_from_yaml yaml file args = parser.parse_args() # parser end # yaml file yaml_file_name = args.i with open(yaml_file_name) as stream: input = yaml.load(stream=stream) # end: yaml file # todo: think over because it is imported twice # end: run-or-check settings debug = input['debug'] dummy_run = input['dummy_run'] # if not at cluster: test # debug = True # dummy_run = True # end: if not at cluster # folders names sim = input['folder_names']['simulations'] db = input['folder_names']['database'] bh5670 = input['folder_names'][ 'scratch'] # the outermost folder in the scratch folder where all other data are put prefix_xyz_file_name = input['prefix_xyz_file_name'] my_offset = input['molecule_vacuum_offset'] try: type_mpi = input['mpi'] except: type_mpi = 'openmpi' # parsing input_from_yaml threads = int(args.num_cpus) # cpus used to compute. I do not subtract 1. This does not help rank = '{:0>6}'.format(args.rank) # transform rank from '1' to '000001' format. This is not a general thing xyz_file_name = f'{prefix_xyz_file_name}_{rank}.xyz' xyz_file_location = f'{prefix_xyz_file_name}/{xyz_file_name}' db_record_path = f'{db}/DB_{rank}.yaml' # file where the results will be saved todo: raeum es alles auf! # check is the output exists if os.path.exists(db_record_path): print(f'The simulation results of mol. {rank} is already in the folder of reference') exit() # end: check if the output exists if True: #not dummy_run: sim_folder_scratch = f'{scratch}/{bh5670}/{sim}/{rank}' else: 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 try: my_xyz_file_obj = XYZ.from_file(xyz_file_location) # object created using the file from home except: # test my_xyz_file_obj = XYZ.from_file('H2O.xyz') # 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] input['my_abc'] = my_abc input['xyz_file_name'] = xyz_file_name # misc wf_corr_num_proc = 0 # 16 in the ref paper; -1 to use all inp_file_name = 'test_2344.inp' # base file name ######################################## 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' cp2k_exe_path = input['cp2k_exe_path'] my_run_type = 'mpi' suffix = input['basis_set_suffix'] # todo: fix DZ --> 2, TZ --> 3, QZ --> 4 InputFactory.set_constants(input_from_yaml=input) for i_bs, suffix in enumerate(suffix): # start: ot dft # I/O output_file = f'out_{suffix}.out' ot_file_name = 'OT_' + f'{suffix}_' + inp_file_name # for DFT (OT) diag_file_name = 'DIAG_' + f'{suffix}_' + inp_file_name # for GW (DIAG) # end: I/O # OT dft simulation to converge quickly: create the simulation object dft_ot_simulation = InputFactory.new_dft_ot(i_bs) # OT dft: write input file dft_ot_simulation.write_input_file(sim_folder_scratch + '/' + ot_file_name) # OT dft run below ... # ... but before, we copy the RESTART from the previous basis set (it exists unless for the smallest basis set) if i_bs != 0: 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: pass # 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, type_mpi=type_mpi) # end: first run print(f"I have finished cp2k with OT (basis set = {suffix})") # DIAGONALIZATION RUN to reliably compute H**O and then GW # gw: create the simulation object gw_diag_simulations = InputFactory.new_gw(i_bs) # gw: write the input file gw_diag_simulations.write_input_file(sim_folder_scratch + '/' + diag_file_name) # gw 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, type_mpi=type_mpi) 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 # the method to extract? # 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 orbitals 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 dft_ot_simulation, gw_diag_simulations # 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() # level up? db_record = my_new_mol.yield_dict() # this dict will be written into yaml. it will be a record in the global library # ######################################## END: RUN CP2K TWO TIMES ####################################################### print("\nI am done\n") if not dummy_run: print('saving to DB...') with open(f'{db}/DB_{rank}.yaml', 'w') as stream: yaml.safe_dump(db_record, stream) print(f"saved to {db}/DB_{rank}.yaml") print('I will remove the content of 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, dirs_exist_ok=True) # 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 try: copytree(sim_folder_scratch, sim_folder_home) # will rewrite the folder? print(f"I have copied {sim_folder_scratch} to {sim_folder_home}") except: print(f"I could not copy {sim_folder_scratch} to {sim_folder_home}") try_to_remove_folder(sim_folder_scratch)