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
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(): # 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")
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}")
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')
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")