def test_if_cal_finish(): path = r'C:\Users\ccccc\PycharmProjects\Layer_Structure_Caculation\test_may\cluster\x_0\z_-0.106' job = Job(path) # job.method = 'avdz_iext1_lmp2' job.method = 'avdz_lmp2_cc' finished = Correction.if_cal_finish(job) print(finished)
def test_read_results(): path = r'C:\Users\ccccc\PycharmProjects\Layer_Structure_Caculation\Test\cluster\x_0\z_0' job = Job(path) job.method = 'avtz_iext1_rpa' Res = Correction.Result(job) Res.get_energy() print(Res.energy, Res.unit) Res.unit_transform() print(Res.energy, Res.unit)
def test_read_results(): path = r'C:\Users\ccccc\PycharmProjects\Layer_Structure_Caculation\test_may\cluster\x_0\z_-0.106' job = Job(path) job.method = 'avdz_iext1_lmp2' Res = Correction.Result(job, ll='lmp2') Res.get_energy() print(Res.energy, Res.unit) Res.unit_transform() print(Res.energy, Res.unit)
def test_if_finished(): path = os.getcwd() path = path + '/Test/rpa/x_-0.150/z_-0.106' job = Job(path) finished = submit_job_rpa.if_cal_finish(job) expected = True assert (finished == expected)
def test_data_saving(): path = 'C:\\Users\\ccccc\\Documents\\Theoritische Chemie\\Masterarbeit\\test\\geo_opt\\x_-0.150\\z_-0.106' energy = get_optimized_energy(path) job = Job(path) path = job.root_path creatxls_dis(path) read_and_record_result(2, job, 3.1)
def get_new_job(self): path_GeoOpt = self.job_GeoOpt.path path_hf1 = path_GeoOpt.replace('geo_opt', 'hf1') if self.layertype != 'bilayer': path_hf1 = os.path.join(path_hf1, self.layertype) job_hf1 = Job(path_hf1) return job_hf1
def get_jobs(path): path = os.path.join(path, 'rpa') walks = os.walk(path) jobs = [] for root, dirs, files in walks: if 'rpa.out' in files: new_job = Job(root) if if_cal_finish(new_job): jobs.append(new_job) # directly select job from geo_opt directory if len(jobs) == 0: path = path.replace('rpa', 'geo_opt') for root, dirs, files in os.walk(path): if 'geo_opt.out' in files or 'hf.out' in files: new_job = Job(root) jobs.append(new_job) return jobs
def test_Molpro_Bs(): path = r'C:\Users\ccccc\PycharmProjects\Layer_Structure_Caculation\Test\cluster\x_0\z_0' job = Job(path) xyz = r'C:\Users\ccccc\PycharmProjects\Layer_Structure_Caculation\Test\cluster\x_0\z_0\BlackP_Cluster_M.xyz' inp_name = 'per_bas_rpa_iext1.inp' MB = Correction.Molpro_Bs(job, inp_name) MB.get_molpro_bs() MB.write_bs()
def get_running_jobs(self): running_jobs = [] with open(self.status_file, 'r') as f: data = json.load(f) for job in data.keys(): if data[job]['status'] == 'running': curr_job = Job(data[job]['path']) running_jobs.append(curr_job) return running_jobs
def test_read_all_results(): path = r'C:\Users\ccccc\PycharmProjects\Layer_Structure_Caculation\Test' walks = os.walk(path) jobs = [] for root, dirs, files in walks: if 'geo_opt.out' in files: job = Job(root) jobs.append(job) read_all_results(jobs, 3.1)
def test_too_many_cycles(): job = r'C:\Users\ccccc\PycharmProjects\Layer_Structure_Caculation\Test\hf1\x_0.35\z_0' job2 = r'C:\Users\ccccc\PycharmProjects\Layer_Structure_Caculation\Test\hf1\x_0.35\z_0\underlayer' job = Job(job) e = HF1.read_results_hf1.get_energy(job.path) print(e) print('---'*20) e1 = HF1.read_results_hf1.get_energy(job2) print(e1)
def get_jobs(path): path = os.path.join(path, 'lmp2') walks = os.walk(path) jobs = [] for root, dirs, files in walks: if 'lmp2.out' in files and 'molpro.inp' in files: new_job = Job(root) if if_cal_finish(new_job): jobs.append(new_job) return jobs
def test_read_lowest_e(): #path = 'C:\\Users\\ccccc\\Documents\\Theoritische Chemie\\Masterarbeit\\test' path = r'/users/shch/project/Masterarbeit/Test/' walks = os.walk(path) jobs = [] for root, dirs, files in walks: if 'geo_opt.out' in files: job = Job(root) jobs.append(job) read_and_select_lowest_e(jobs)
def test_read_all_results(): path = 'C:\\Users\\ccccc\\Documents\\Theoritische Chemie\\Masterarbeit\\test\\hf_1' walks = os.walk(path) jobs = [] for root, dirs, files in walks: if 'hf.out' in files: job = Job(root) if if_cal_finish(job): jobs.append(job) read_all_results_hf1(jobs, init_dist=3.1)
def test_read_all_results(): path = os.getcwd() path = os.path.join(path, 'Test') path = os.path.join(path, 'rpa') walks = os.walk(path) jobs = [] for root, dirs, files in walks: if 'rpa.out' in files: job = Job(root) jobs.append(job) read_results_rpa.read_and_record_all_results(jobs)
def get_finished_jobs(job): path = os.path.join(job.root_path, job.method) walks = os.walk(path) jobs = [] for root, dirs, files in walks: if ('geo_opt.out' in files) and ('fort.9' in files): new_path = root new_job = Job(new_path) if if_cal_finish(new_job): jobs.append(new_job) return jobs
def get_jobs(path): path = os.path.join(path, 'hf1') walks = os.walk(path) jobs = [] for root, dirs, files in walks: if ('hf.out' in files) and ('fort.9' in files): new_path = root new_job = Job(new_path) if if_cal_finish(new_job): jobs.append(new_job) return jobs
def get_jobs(path): path = os.path.join(path, 'cluster') walks = os.walk(path) jobs = set() root_jobs = set() for root, dirs, files in walks: if len(files) > 0: for file in files: if os.path.splitext(file)[-1] == '.out': new_job = Job(root) new_job.method = os.path.splitext(file)[0] if if_cal_finish( new_job ) and new_job not in jobs and '20' not in new_job.method: jobs.add(new_job) root_jobs.add(Job(root)) # print(new_job) # print(root) jobs = list(jobs) root_jobs = list(root_jobs) return jobs, root_jobs
def factor_calculation(): # parameters input path = r'C:\Users\ccccc\Documents\Theoritische Chemie\Masterarbeit\test\geo_opt\x_1\z_2' name = 'MgO' center_upp = [25, 25] center_und = [9, 9] center = [center_upp, center_und] atom = (-2.99725, 0, 16.835625996) atom2 = (-1.498625, 5.352278396, 16.891833116) atom3 = (-2.99725, -2.99725, 19.963182233) atoms = [atom, atom2, atom3] #if needed dimen = 2 lattice_parameter = [] geometry = [] vector = [] dimen, lattice_parameter, geometry = read_infomation(path) #calculation part job = Job(path) json_path = os.path.join(job.root_path, 'cluster') if not os.path.exists(os.path.join(json_path, 'geometry.json')): ClusterCutter.creat_json_file(json_path) if lattice_parameter != [] and geometry != []: basic_info = [dimen, lattice_parameter, geometry] Clu = ClusterCutter(job, name=name, centre=center, basic_infos=basic_info) else: Clu = ClusterCutter(job, name=name, centre=center) Fac = FactorCalculator(Clu) for atom in atoms: dis_fac = Fac.get_distance_to_center(atom, factor=True) print('---' * 20) print(atom) print('cluster factor of distance: ', dis_fac) if vector == []: print(Clu.centre) a_fac = Fac.get_distance_to_vector(atom, vec=1, factor=True) print('cluster factor of lattice vector 1: ', a_fac) b_fac = Fac.get_distance_to_vector(atom, vec=2, factor=True) print('cluster factor of lattice vector 2: ', b_fac) if Clu.dimensionality != 2: c_fac = Fac.get_distance_to_vector(atom, vec=3, factor=True) print('cluster factor of lattice vector 3: ', c_fac) else: fac = Fac.get_distance_to_vector(atom, vector, True)
def test_calculation(j, init_jobs, submitted_jobs, finished_jobs): # ----------------------------------------- test --------------------------------------------------- if j >= 2: # categorization of out jobs path = r'C:\Users\ccccc\Documents\Theoritische Chemie\Masterarbeit\BlackP\hf2' walks = os.walk(path) jobs = [] for root, dirs, files in walks: if 'hf2.out' in files: jobs.append(Job(root)) out_jobs = {} for job in jobs: if job.layertype not in out_jobs: out_jobs[job.layertype] = {} if job.x not in out_jobs[job.layertype]: out_jobs[job.layertype][job.x] = [job] else: out_jobs[job.layertype][job.x].append(job) for layertype, jobs_dict in out_jobs.items(): for key, value in jobs_dict.items(): sorted(value, key=lambda job: float(job.z)) # categorization of running jobs all_jobs = init_jobs + finished_jobs + submitted_jobs runing_jobs_dict = {} for job in all_jobs: if job.layertype not in runing_jobs_dict: runing_jobs_dict[job.layertype] = {} if job.x not in runing_jobs_dict[job.layertype]: runing_jobs_dict[job.layertype][job.x] = [job] else: runing_jobs_dict[job.layertype][job.x].append(job) # find corresponding jobs for layertype, jobs_dict in runing_jobs_dict.items(): for x, job_list in jobs_dict.items(): corr_list = out_jobs[layertype]['%.1f' % (float(x) * 10 + 2.5)] job_list = sorted(job_list, key=lambda job: float(job.z)) for i in range(len(job_list)): out_from = corr_list[i].path fort_from = os.path.join(out_from, 'fort.9') fort_78_from = os.path.join(out_from, 'fort.78') out_from = os.path.join(out_from, 'hf2.out') out_to = job_list[i].path fort_to = os.path.join(out_to, 'fort.9') fort_78_to = os.path.join(out_to, 'fort.78') out_to = os.path.join(out_to, 'hf2.out') shutil.copy(out_from, out_to) shutil.copy(fort_from, fort_to) shutil.copy(fort_78_from, fort_78_to)
def get_jobs(path): path = os.path.join(path, 'cluster') walks = os.walk(path) jobs = [] path_set = set() for root, dirs, files in walks: if len(files) > 0: for file in files: if os.path.splitext( file)[-1] == '.xyz' and root not in path_set: path_set.add(root) new_job = Job(root) jobs.append(new_job) return jobs
def test_write_geo_json(): path = r'C:\Users\ccccc\PycharmProjects\Layer_Structure_Caculation\Test' walks = os.walk(path) jobs = [] for root, dirs, files in walks: if 'geo_opt.out' in files: job = Job(root) jobs.append(job) for job in jobs: # if job.x == '0.10': # print(job) path = job.path lattice_para, geometry = get_optimized_geometry(path) write_geometry_json(job, geometry) write_latt_json(job, lattice_para)
def test_MgO(): path = r'C:\Users\ccccc\Documents\Theoritische Chemie\Masterarbeit\test\cluster' Cluster.creat_json_file(path) job = r'C:\Users\ccccc\Documents\Theoritische Chemie\Masterarbeit\test\geo_opt\x_1\z_2' dimen, lattice, geo = read_infomation(job) job = Job(job) center_upp = [25, 25] center_und = [9, 9] center = [center_upp, center_und] fixed_atoms = [13, 24] fac_upp = [0.3, 0.5, 0.5] fac_und = [0.4, 0.6, 0.6] factors = [fac_upp, fac_und] Clu = Cluster.ClusterCutter(job, name='MgO', centre=center, basic_infos=[dimen, lattice, geo], factors=factors, fixed_atoms=fixed_atoms) Clu.final_cluster = Clu.choose_atoms_from_distance() Clu.write_xyz(Clu.choosed_atoms)
def test_calculation(j, init_jobs, finished_jobs): # ----------------------------------------- test --------------------------------------------------- if j >= 2: from Common import Job # categorization of out jobs path = r'F:\BlackP\RPA' walks = os.walk(path) jobs = [] for root, dirs, files in walks: if 'rpa.out' in files: jobs.append(Job(root)) out_jobs = {} for job in jobs: if job.layertype not in out_jobs: out_jobs[job.layertype] = {} if job.x not in out_jobs[job.layertype]: out_jobs[job.layertype][job.x] = [job] else: out_jobs[job.layertype][job.x].append(job) for layertype, jobs_dict in out_jobs.items(): for key, value in jobs_dict.items(): sorted(value, key=lambda job: float(job.z)) # categorization of running jobs all_jobs = init_jobs + finished_jobs runing_jobs_dict = {} for job in all_jobs: if job.layertype not in runing_jobs_dict: runing_jobs_dict[job.layertype] = {} if job.x not in runing_jobs_dict[job.layertype]: runing_jobs_dict[job.layertype][job.x] = [job] else: runing_jobs_dict[job.layertype][job.x].append(job) # find corresponding jobs for layertype, jobs_dict in runing_jobs_dict.items(): for x, job_list in jobs_dict.items(): corr_list = out_jobs[layertype]['%.1f' % (float(x) * 10 + 2.5)] job_list = sorted(job_list, key=lambda job: float(job.z)) for i in range(len(job_list)): out_from = corr_list[i].path out_from = os.path.join(out_from, 'rpa.out') out_to = job_list[i].path out_to = os.path.join(out_to, 'rpa.out') shutil.copy(out_from, out_to)
def test_blackP(): path = r'C:\Users\ccccc\PycharmProjects\Layer_Structure_Caculation\Test\geo_opt' path = r'C:\Users\ccccc\Documents\Theoritische Chemie\Masterarbeit\job\geo_opt' walks = os.walk(path) jobs = [] for root, dirs, files in walks: if 'hf.out' in files: job = Job(root) jobs.append(job) path = r'C:\Users\ccccc\Documents\Theoritische Chemie\Masterarbeit\job\cluster' #path = r'C:\Users\ccccc\Documents\Theoritische Chemie\Masterarbeit\test\cluster' Cluster.creat_json_file(path) # job = r'C:\Users\ccccc\Documents\Theoritische Chemie\Masterarbeit\test\geo_opt\x_1\z_1' # job = jobs[0] # # print(job) # # # job = Job_path(job) # test_cut_cluster(job) for job in jobs: test_cut_cluster(job)
def select_jobs(path): # find all possible jobs walks = os.walk(path) jobs = [] for root, dirs, files in walks: if 'geo_opt.out' in files: jobs.append(root) jobs = [Job(job) for job in jobs] # categorization jobs according to x jobs_dict = {} for job in jobs: x = job.x if x in jobs_dict: jobs_dict[x].append(job) else: jobs_dict[x] = [job] # select jobs at each x selected_jobs = [] for key, value in jobs_dict.items(): if key == '0': new_list = value else: jobs_list = value[:] min_dist, min_job = read_and_select_lowest_e(value) # print(min_dist, min_job) jobs_list = sorted(jobs_list, key=lambda job: float(job.z)) # print(jobs_list) position = look_for_in_list(jobs_list, min_job) if len(jobs_list) > 3: new_list = [min_job] new_list.append(jobs_list[position - 1]) new_list.append(jobs_list[position + 1]) new_list.append(jobs_list[position + 2]) else: new_list = [job for job in jobs_list] # print(new_list) selected_jobs += new_list return selected_jobs
def test_SiO2(): path = r'C:\Users\ccccc\Documents\Theoritische Chemie\Masterarbeit\test\cluster' #path = r'/users/shch/project/Masterarbeit/Test/cluster' Cluster.creat_json_file(path) job = r'C:\Users\ccccc\Documents\Theoritische Chemie\Masterarbeit\test\geo_opt\x_1\z_1' #job = r'/users/shch/project/Masterarbeit/Test/geo_opt/x_1/z_1' dimen, lattice, geo = read_infomation(job) job = Job(job) #centre=[16, 16] centre = [2, 4] fac_upp = [0.85, 1.1, 1.1] fac_und = fac_upp factors = [fac_upp, fac_und] deleted_atoms = [54, 49] #deleted_atoms = [] #centre = [[2, 2], [13, 13]] Clu = Cluster.ClusterCutter(job, name='SiO2-H2O', centre=centre, basic_infos=[dimen, lattice, geo], factors=factors, size='M', fixed_atoms=[10, 17], deleted_atoms=deleted_atoms) original_atoms = Clu.original_atoms cnt = 1 Clu.write_xyz()
def lmp2(path, moni): rec = 'LMP2 Calculation begins.\n' rec += '---' * 25 print(rec) record(path, rec) init_dist = read_init_dis(path) # read basic computation information hf2_jobs = LMP2.get_jobs(path) Ini = ReadIni() nodes, cryscor_path = Ini.get_lmp2() cal_parameters = Ini.get_cal_parameters('LMP2') ll = Ini.ll if nodes == '' or nodes == 'default': nodes = 1 record_data_json(path, 'nodes', nodes, section='lmp2') # categorization bilayer = [] singlelayer = [] for job in hf2_jobs: if job.layertype == 'bilayer': bilayer.append(job) elif job.layertype == 'underlayer' or job.layertype == 'upperlayer': singlelayer.append(job) # generation of all input files and copy needed files lmp2_jobs = [] lmp2_jobs_finished = [] for job in bilayer: new_path = job.path new_path = new_path.replace('hf2', 'lmp2') new_job = Job(new_path) if not LMP2.if_cal_finish(new_job): Inp = LMP2.Lmp2Input(job, ll, cal_parameters) Inp.write_input() LMP2.copy_files(new_job, nodes, cryscor_path) lmp2_jobs.append(new_job) else: lmp2_jobs_finished.append(new_job) for job in singlelayer: new_path = job.path new_path = new_path.replace('hf2', 'lmp2') new_job = Job(new_path) if not LMP2.if_cal_finish(new_job): Inp = LMP2.Lmp2InputLayer(job, cal_parameters) Inp.write_input() LMP2.copy_files(new_job, nodes, cryscor_path) lmp2_jobs.append(new_job) else: lmp2_jobs_finished.append(new_job) # submit the jobs if len(lmp2_jobs) > 0: new_finished_jobs = LMP2.submit(lmp2_jobs, moni) lmp2_jobs_finished += new_finished_jobs # read calculation results # if len(lmp2_jobs_finished) > 0: # LMP2.read_all_results_lmp2(lmp2_jobs_finished, init_distance=init_dist) rec = 'LMP2 finished!\n' rec += '***' * 25 print(rec) record(path, rec)
def test_delete_guessp(): job = r'C:\Users\ccccc\PycharmProjects\Layer_Structure_Caculation\Test\hf1\x_0.35\z_0' job2 = r'C:\Users\ccccc\PycharmProjects\Layer_Structure_Caculation\Test\hf1\x_0.35\z_0\underlayer' job = Job(job) HF1.delete_guessp(job)
def test_if_finished(): path = r'C:\Users\ccccc\Documents\Theoritische Chemie\Masterarbeit\test\hf_1\x_-0.150\z_-0.106' job = Job(path) res = if_cal_finish(job) print(res)