def prep_run_file(self, next_run='next_run.sh'): """ run_fileを修正してnext_run.shを作成 run_listの実行したjobをコメントアウト """ work_path, fname_exe = self.run_list[0] key = "cd $PBS_O_WORKDIR\n" # work_pathが相対pathの場合、絶対pathに修正する if work_path[0] == '/': alt = "cd {0}\n".format(os.path.join(work_path)) else: alt = "cd {0}\n".format(os.path.join(os.getcwd(), work_path)) lines = Cabinet.read_file(fname_exe) # $PBS_O_WORKDIRの記述が無い場合errorメッセージを出力 try: pos = lines.index(key) except ValueError: print("{0}に'cd $PBS_O_WORKDIR'の記述がありません".format(fname_exe)) exit() lines[pos] = alt Cabinet.write_file(next_run, lines) finished = self.run_list.pop(0) finished[0] = '#' + finished[0] self.finished_list.append(finished) tmp_list = self.finished_list + self.run_list all_list = [" ".join(x) + "\n" for x in tmp_list] Cabinet.write_file(self.list_run_file, all_list)
def write_potcar(self, path, fname='POTCAR'): """ Make a combined single POTCAR file """ fname = os.path.join(path, fname) out_lines = [x for y in self.potentials_lines for x in y] Cabinet.write_file(fname, out_lines)
def write_poscar(self, poscar='POSCAR'): """ write_poscar(path) Make a 'POSCAR' file at 'path' """ Cabinet.reserve_file(poscar) Cabinet.write_file(poscar, str(self))
def make_list_run(self, run_file): """ next.py用のlist_run.txtを作成 """ lines = "" for param in self.series: path = param['path'] run_file = os.path.abspath(run_file) lines += "{0} {1}\n".format(path, run_file) Cabinet.write_file('list_run', lines)
def run_job_and_get_id(self, fname_exe='next_run.sh'): """ jobを走らせる 走らせるファイルはnext_run.sh """ cmd = ['qsub', fname_exe] job_id = Popen(cmd, stdout=PIPE).communicate()[0] add_line = job_id.split('.')[0] + b'\n' self.running_jobs.append(add_line) Cabinet.write_file(self.running_jobs_file, self.running_jobs)
def write_kpoints(self, fname='KPOINTS', mode='M'): """Write KPOINTS file using self.kpoints""" if mode == 'M': mline = "Monkhorst Pack" elif mode == 'G': mline = "Gamma" kp_lines = ("Automatic mesh\n0\n{0}\n" " {1[0]} {1[1]} {1[2]}\n 0. 0. 0.\n" .format(mline, self.kpoints)) Cabinet.write_file(fname, kp_lines)
def plt_double(self, combipara, in_dir1, in_dir2, out_dir): """2種の結果のlattice依存性をプロット""" combi = Combinatorial(*combipara) combi.set_formula(2, 1) for composition in combi.compositions: formula = composition['formula'] formula = ''.join(formula.split('2')) total_elem = ['Fe'] + composition['elements'] total_num_atoms = [1] + composition['num_atoms'] print(formula) all_dir_list = glob.glob(os.path.join(in_dir1, formula, 'fixed_*')) regular = collect_vasp.Energy(all_dir_list, 'POSCAR', 'OSZICAR') regular['c/a'] /= 2 ** 0.5 fixed_elem = [total_elem[1], total_elem[0], total_elem[2]] fixed_elem = np.array([fixed_elem] * len(regular['elements'])) regular['elements'] = fixed_elem regular.set_enthalpy() regular.set_mae('OSZICAR_SOC001', 'OSZICAR_SOC100') all_dir_list = glob.glob(os.path.join(in_dir2, formula, 'fixed_*')) inverse = collect_vasp.Energy(all_dir_list, 'POSCAR', 'OSZICAR') inverse['c/a'] /= 2 ** 0.5 inverse['elements'] = fixed_elem inverse.set_enthalpy() inverse.set_mae('OSZICAR_SOC001', 'OSZICAR_SOC100') rlines = [str(regular)] ilines = [str(inverse)] fname_reg = "Fe2{0[0]}{0[1]}_reg.txt".format(composition['elements']) fname_inv = "Fe2{0[0]}{0[1]}_inv.txt".format(composition['elements']) Cabinet.write_file(os.path.join(out_dir, 'text', fname_reg), rlines) Cabinet.write_file(os.path.join(out_dir, 'text', fname_inv), ilines) def plot(): plt = grapy.Vertical(3) plt.set_title("Heusler Fe$_2${0[0]}{0[1]}" .format(composition['elements'])) plt.set_style('blue') plt.set123(regular, 'c/a', 'enthalpy', 'mag', 'mae') plt.set_style('magenta') plt.set123(inverse, 'c/a', 'enthalpy', 'mag', 'mae') plt.adjust_auto() plt.ax2.set_ylim(-0.5, 3) plt.plot('show') #fname = "Fe2{0[0]}{0[1]}.eps".format(composition['elements']) #plt.plot(os.path.join(out_dir, fname)) plot()
def change_conc(): """ concを変更する """ list1 = [str(i*0.1) for i in range(0, 11)] list2 = ['001', '100'] list3 = ['0.950', '1.000', '1.050', '1.100', '1.150', '1.200', '1.250', '1.300', '1.350', '1.400', '1.450', '1.500'] combi = Combinatorial(list1, list2, list3) # print(combi.compositions) comp_list = [x['elements'] for x in combi.compositions] lines = "" for comp in comp_list: lines += "/".join(comp) + " run.sh\n" print(lines) Cabinet.write_file('list_run.txt', lines)
def is_running(self): """ jobが動作中かどうかcheckする 終了していた場合、running_jobsから削除 """ cmd = ['qstat'] jobs = Popen(cmd, stdout=PIPE).communicate()[0].split(b'\n') uname = getpass.getuser() still_run = [] for job_id in self.running_jobs: key = r"{0}.*{1}.*".format(job_id[:-1], uname) meta = re.compile(key) judge = True for job in jobs: if meta.match(job): judge = None if not judge: still_run.append(job_id) self.running_jobs = still_run Cabinet.write_file(self.running_jobs_file, self.running_jobs)
def write_incar(self, fname): """Write INCAR file""" Cabinet.write_file(fname, str(self))
def write_kpoints(self, fname='KPOINTS'): """Write KPOINTS file using self.kpoints""" kp_lines = ('Automatic mesh\n0\nMonkhorst Pack\n' ' {0[0]} {0[1]} {0[2]}\n 0. 0. 0.\n' .format(self.kpoints)) Cabinet.write_file(fname, kp_lines)