예제 #1
0
    def STRU_to_POSCAR(cls, srcfile: str_PathLike, tofile: str_PathLike,
                       ntype: int) -> None:
        """Convert STRU of ABACUS to POSCAR of VASP

        :params srcfile: str_PathLike, source file
        :params tofile: str_PathLike, converted file
        """
        def convert_pos(elements: list, positions: dict):
            newpos = []
            for elem in elements:
                for pos in positions[elem]:
                    newpos.append(' ' + ''.ljust(20).join(list_elem2str(pos)))
            return newpos

        stru = read_stru(ntype, srcfile)
        line = [f"From {srcfile}"]
        line.append(str(stru.lat0 * BOHR_TO_A))
        for i in stru.cell:
            line.append('\t' + '\t'.join(list_elem2str(i)))
        line.append(' ' + ''.ljust(10).join(stru.elements))
        line.append(' ' +
                    ''.ljust(10).join(list_elem2str(stru.numbers.values())))
        line.append(stru._ctype)
        if stru._ctype == "Direct":
            line.append('\n'.join(
                convert_pos(stru.elements, stru.scaled_positions)))
        if stru._ctype == "Cartesian":
            line.append('\n'.join(convert_pos(stru.elements, stru.positions)))
        else:
            ValueError(f"Type {stru._ctype} is not supported for VASP.")
        with open(tofile, 'w') as file:
            file.write('\n'.join(line))
예제 #2
0
    def get_kpt(self) -> str:
        """Return the `KPT` file as a string"""

        line = []
        line.append("K_POINTS")
        if self.mode in ["Gamma", "MP"]:
            line.append("0")
            line.append(self.mode)
            line.append(" ".join(list_elem2str(self.numbers + self.offset)))
        elif self.mode == "Line":
            line.append(str(len(self.special_k)))
            line.append(self.mode)
            for i, k in enumerate(self.special_k):
                if self.klabel:
                    line.append(" ".join(list_elem2str(k +
                                                       [self.numbers[i]])) +
                                '\t#' + self.klabel[i])
                else:
                    line.append(" ".join(list_elem2str(k + [self.numbers[i]])))

        return '\n'.join(line)
예제 #3
0
    def _prepare(self, **kwargs):
        """Prepare input files for optimizing ABFs e.g. input.json"""

        self.folder_opt = Path("opt_orb_" + "-".join(list_elem2str(self.Nu)))
        self.folder_opt.mkdir(exist_ok=False)

        if not Path("folders").exists():
            raise FileNotFoundError(
                "'folders' which is a out file of `SetDimers` calculations not found."
            )

        with open(self.folder_opt / "input.json", 'w') as file:
            json.dump(self.set_input(), file, indent=4)
예제 #4
0
    def get_stru(self) -> str:
        """Return the `STRU` file as a string"""

        empty_line = ''
        line = []
        line.append("ATOMIC_SPECIES")
        for elem in self.elements:
            line.append(f"{elem}\t{self.masses[elem]}\t{self.pps[elem]}")
        line.append(empty_line)

        if self.orbitals:
            line.append("NUMERICAL_ORBITAL")
            for elem in self.elements:
                line.append(f"{self.orbitals[elem]}")
            line.append(empty_line)

        if self.abfs:
            line.append("ABFS_ORBITAL")
            for elem in self.elements:
                line.append(f"{self.abfs[elem]}")
            line.append(empty_line)

        line.append("LATTICE_CONSTANT")
        line.append(str(self.lat0))
        line.append(empty_line)

        line.append("LATTICE_VECTORS")
        for i in range(3):
            line.append(" ".join(list_elem2str(self.cell[i])))
        line.append(empty_line)

        line.append("ATOMIC_POSITIONS")
        line.append(self._ctype)
        line.append(empty_line)
        for elem in self.elements:
            line.append(f"{elem}\n{self.magmoms[elem]}\n{self.numbers[elem]}")
            for j in range(self.numbers[elem]):
                if self._ctype == "Cartesian":
                    line.append(
                        " ".join(list_elem2str(self.positions[elem][j])) +
                        " " + " ".join(list_elem2str(self.move[elem][j])))
                elif self._ctype == "Direct":
                    line.append(" ".join(
                        list_elem2str(self.scaled_positions[elem][j])) + " " +
                                " ".join(list_elem2str(self.move[elem][j])))
                elif self._ctype == "Cartesian_angstrom":
                    line.append(" ".join(
                        list_elem2str(self.positions_angstrom_lat0[elem][j])) +
                                " " +
                                " ".join(list_elem2str(self.move[elem][j])))
            line.append(empty_line)

        return '\n'.join(line)
예제 #5
0
 def convert_pos(elements: list, positions: dict):
     newpos = []
     for elem in elements:
         for pos in positions[elem]:
             newpos.append(' ' + ''.ljust(20).join(list_elem2str(pos)))
     return newpos
예제 #6
0
def convert_path_to_string(path=[[]]):
    line = []
    for i in path:
        line.append(' '.join(list_elem2str(i)))
    return '\t'.join(line)