コード例 #1
0
ファイル: IO.py プロジェクト: 1041176461/ABACUSkit
def read_kpt(kpt_file: str_PathLike) -> Kpt:
    """Read k-points file

    :params kpt_file: absolute path of k-points file
    """
    number = 0
    with open(kpt_file, "r") as file:
        if search_sentence(file, ["K_POINTS", "KPOINTS", "K"]):
            number = int(file.readline())
        mode = search_sentence(file, ["Gamma", "MP", "Line"])
        if mode in ["Gamma", "MP"]:
            line = skip_notes(file.readline()).split()
            numbers = list_elem_2int(line[:3])
            offset = list_elem_2float(line[3:])
            return Kpt(mode, numbers, special_k=[], offset=offset)
        elif mode == "Line":
            special_k = []
            numbers = []
            klabel = []
            for k in range(number):
                line = file.readline()
                if re.match("#", line):
                    continue
                else:
                    linesplit = line.split(maxsplit=4)
                special_k.append(list_elem_2float(linesplit[:3]))
                numbers.append(int(linesplit[3]))
                if len(linesplit) == 5:
                    klabel.append(linesplit[4].strip('#\n '))
            return Kpt(mode, numbers, special_k, offset=[], klabel=klabel)
コード例 #2
0
 def cal_ground_cell_relax(self,
                           knum,
                           mpi=28,
                           openmp=1,
                           num_machines=1,
                           num_mpiprocs_per_machine=28,
                           max_wallclock_seconds=86400,
                           queue_name='gold5120'):
     stru = read_stru(self.input_dict["ntype"], "STRU")
     kpt = Kpt('Gamma', knum)
     os.mkdir('ground')
     os.chdir('ground')
     command = Code(
         code_name=self.code_name,
         cmdline_params=[f"-n {mpi}", f"-env OMP_NUM_THREADS={openmp}"],
         stdout_name="job.log",
         stderr_name="job.err",
         withmpi="mpirun")
     submit_command = set_scheduler(
         'torque', [command],
         num_machines=num_machines,
         num_mpiprocs_per_machine=num_mpiprocs_per_machine,
         run_mode='p',
         max_wallclock_seconds=max_wallclock_seconds,
         queue_name=queue_name)
     self.ground_cell_relax(stru, kpt)
     os.system(submit_command)
     os.chdir('../')
コード例 #3
0
 def cal_excite_relax(self,
                      knum,
                      ocp_set,
                      mpi=28,
                      openmp=1,
                      num_machines=1,
                      num_mpiprocs_per_machine=28,
                      max_wallclock_seconds=86400,
                      queue_name='gold5120'):
     strufile = extract_largest_number_file()
     stru = read_stru(self.input_dict["ntype"], glob(strufile))
     for elem in stru.orbitals.keys():
         stru.orbitals[elem] = os.path.basename(stru.orbitals[elem])
     kpt = Kpt('Gamma', knum)
     os.mkdir('excite')
     os.chdir('excite')
     command = Code(
         code_name=self.code_name,
         cmdline_params=[f"-n {mpi}", f"-env OMP_NUM_THREADS={openmp}"],
         stdout_name="job.log",
         stderr_name="job.err",
         withmpi="mpirun")
     submit_command = set_scheduler(
         'torque', [command],
         num_machines=num_machines,
         num_mpiprocs_per_machine=num_mpiprocs_per_machine,
         run_mode='p',
         max_wallclock_seconds=max_wallclock_seconds,
         queue_name=queue_name)
     self.excite_relax(ocp_set, stru, kpt)
     os.system(submit_command)
     os.chdir('../')
コード例 #4
0
 def cal_phono(self,
               dim=[1, 1, 1],
               mpi=28,
               openmp=1,
               num_machines=1,
               num_mpiprocs_per_machine=28,
               max_wallclock_seconds=86400,
               queue_name='gold5120'):
     strufile = extract_largest_number_file()
     stru = read_stru(self.input_dict["ntype"], strufile)
     for elem in stru.orbitals.keys():
         stru.orbitals[elem] = os.path.basename(stru.orbitals[elem])
     self.input_dict['gamma_only'] = 1
     kpt = Kpt('Gamma', [1, 1, 1])
     command = Code(
         code_name=self.code_name,
         cmdline_params=[f"-n {mpi}", f"-env OMP_NUM_THREADS={openmp}"],
         stdout_name="job.log",
         stderr_name="job.err",
         withmpi="mpirun")
     os.mkdir('phonon_ground')
     os.chdir('phonon_ground')
     stru.write_stru()
     with open("setting.conf", 'w') as f:
         f.write(
             dedent(f"""\
              DIM = {' '.join(list_elem2str(dim))}
              ATOM_NAME = {' '.join(stru.elements)}
             """))
     os.system('phonopy setting.conf --abacus -d')
     disp_list = glob('STRU-*')
     for i in disp_list:
         dst = 'disp-' + i.split('-')[-1]
         os.mkdir(dst)
         shutil.move(i, dst)
         os.chdir(dst)
         disp_stru = read_stru(self.input_dict["ntype"], i)
         submit_command = set_scheduler(
             'torque', [command],
             num_machines=num_machines,
             num_mpiprocs_per_machine=num_mpiprocs_per_machine,
             run_mode='p',
             max_wallclock_seconds=max_wallclock_seconds,
             queue_name=queue_name)
         self.ground_scf(disp_stru, kpt)
         os.system(submit_command)
         os.chdir('../')
     os.chdir('../')
コード例 #5
0
ファイル: symmetry.py プロジェクト: 1041176461/ABACUSkit
    def get_kpath(self,
                  numbers: list = [],
                  with_time_reversal: bool = True,
                  recipe: str = 'hpkot',
                  threshold: float = 1e-7,
                  symprec: float = 1e-5,
                  angle_tolerance: float = -1) -> Tuple[Stru, Kpt]:
        """Obtain primitive cell and its band paths in the Brillouin zone of crystal structures.

        :params numbers: list of number of k points between two adjacent special k points.
        :params with_time_reversal: if time-reversal symmetry is present or not. Default: True
        :params recipe: currently only the string 'hpkot' is supported. Default: 'hpkot'
        :params threshold: numerical threshold. Default: 1e-7
        :params symprec: distance tolerance in Cartesian coordinates to find crystal symmetry. Default: 1e-5
        :params angle_tolerance: tolerance of angle between basis vectors in degrees to be tolerated in the symmetry finding. Default: -1
        """
        import seekpath

        if numbers:
            set_already = True
        else:
            set_already = False

        res = seekpath.get_path(self.spgcell, with_time_reversal, recipe,
                                threshold, symprec, angle_tolerance)
        newcell = (res['primitive_lattice'], res['primitive_positions'],
                   res['primitive_types'])
        stru = self.modified_stru(newcell)
        klabel = []
        special_k = []
        for k_tuple in res['path']:
            klabel.append(k_tuple[0])
            if not set_already:
                numbers.append(20)
        klabel.append(k_tuple[1])
        if not set_already:
            numbers.append(1)
        for label in klabel:
            special_k.append(res['point_coords'][label])
        kpt = Kpt(mode='Line',
                  numbers=numbers,
                  special_k=special_k,
                  klabel=klabel)

        return stru, kpt