Example #1
0
    def write_twinboundary_shear_cells(self,
                                       is_original_frame: bool = True,
                                       is_relax: bool = True,
                                       header: str = 'twinboundary_shear'):
        """
        write twinboundary shear cells to POSCAR.

        Args:
            is_original_frame: If True, returns cells in original frame.
            is_relax: If True, return relax cells.
            header: File header.
        """
        cells = self.get_twinboundary_shear_cells(
            is_original_frame=is_original_frame, is_relax=is_relax)
        for i, cell in enumerate(cells):
            ratio = self._twinboundary_shear_analyzer.shear_strain_ratios[i]
            filename = header + '_%1.2f.poscar' % ratio
            write_poscar(cell=cell, filename=filename)
Example #2
0
    def write_shear_cells(self,
                          is_original_frame: bool = True,
                          is_relax: bool = True,
                          header: str = 'shear'):
        """
        Write shear cells to POSCAR.

        Args:
            is_original_frame: If True, returns cells in original frame.
            is_relax: If True, return relax cells.
            header: File header.
        """
        cells = self.get_shear_cells(is_original_frame=is_original_frame,
                                     is_relax=is_relax)
        ratios = self._shear_analyzer.shear_strain_ratios
        for cell, ratio in zip(cells, ratios):
            filename = header + '_%1.2f.poscar' % ratio
            write_poscar(cell=cell, filename=filename)
Example #3
0
    def write(self,
              filename="MPOSCAR",
              multiply: float = 1.,
              origin_shift=[0, 0, 0]):
        """
        Write modulated cells.

        Args:
            filename: Cell filename header.
            multiply: Displacements are multiplied.
        """
        num = len(self._modulation._u)
        deltas = []
        for i, u in enumerate(self._modulation._u):
            cell = get_cell_from_phonopy_structure(
                self._modulation._get_cell_with_modulation(u * multiply))
            cell = list(cell)
            cell[1] = (cell[1] + np.array(origin_shift)) % 1
            filename_ = filename + "-%03d" % (i + 1)
            write_poscar(cell=cell, filename=filename_)
Example #4
0
def main(
    twinboundary_relax_pk: int,
    additional_relax_pks: list = None,
    twinboundary_phonon_pk: int = None,
    hexagonal_relax_pk: int = None,
    hexagonal_phonon_pk: int = None,
    plot_plane_diff: bool = False,
    plot_band: bool = False,
    show_band_points: bool = False,
    write_cell_in_original_frame: bool = False,
):

    twinpy = Twinpy.initialize_from_aiida_twinboundary(
        twinboundary_relax_pk=twinboundary_relax_pk,
        additional_relax_pks=additional_relax_pks,
        twinboundary_phonon_pk=twinboundary_phonon_pk,
        hexagonal_relax_pk=hexagonal_relax_pk,
        hexagonal_phonon_pk=hexagonal_phonon_pk,
    )

    # plot plane interval
    if plot_plane_diff:
        fig = twinpy.twinboundary_analyzer.plot_plane_diff()
        plt.show()

    # show band points
    if show_band_points:
        twinpy.show_twinboundary_reciprocal_high_symmetry_points()

    # plot band structure
    if plot_band:
        twinpy.plot_twinboundary_shear_bandstructure()

    # write out relax cell in original frame
    if write_cell_in_original_frame:
        rlx_analyzer = twinpy.twinboundary_analyzer.relax_analyzer
        rlx_cell_orig = rlx_analyzer.final_cell_in_original_frame
        write_poscar(cell=rlx_cell_orig, filename='rlx_cell_orig.poscar')
Example #5
0
def main(
    a: float,
    c: float,
    symbol: str,
    twinmode: str,
    layers: float,
    expansion_ratios: np.array,
    make_tb_flat: bool,
    xshifts: list,
    yshifts: list,
    pair_style: str,
    pot_file: str,
    twintype: int = 1,
    is_run_hexagonal_relax: bool = True,
    is_relax_lattice: bool = False,
):
    lattice = get_hexagonal_lattice_from_a_c(a=a, c=c)
    scaled_positions = get_hcp_atom_positions(wyckoff='c')
    symbols = [symbol] * 2
    hex_cell = (lattice, scaled_positions, symbols)
    hex_lmp_stc = get_lammps_relax(
        cell=hex_cell,
        pair_style=pair_style,
        pot_file=pot_file,
        is_relax_lattice=is_run_hexagonal_relax,
    )
    hex_rlx_analyzer = get_relax_analyzer_from_lammps_static(
        lammps_static=hex_lmp_stc,
        no_standardize=True,
    )

    itr = itertools.product(xshifts, yshifts)
    data = []
    os.makedirs("./poscar")
    os.makedirs("./joblib")
    for i, xy in enumerate(itr):
        xshift, yshift = xy

        twinpy = Twinpy(lattice=lattice,
                        twinmode=twinmode,
                        symbol=symbol,
                        wyckoff='c')
        twinpy.set_twinboundary(
            layers=layers,
            twintype=twintype,
            xshift=xshift,
            yshift=yshift,
            shear_strain_ratio=0.,
            expansion_ratios=expansion_ratios,
            make_tb_flat=make_tb_flat,
        )
        twinpy.set_twinboundary_analyzer_from_lammps(
            pair_style=pair_style,
            pot_file=pot_file,
            is_relax_lattice=is_relax_lattice,
            is_run_phonon=False,
            hexagonal_relax_analyzer=hex_rlx_analyzer,
        )
        num = "%03d" % i
        filename = "./joblib/{}_xshift-{}_yshift-{}.joblib".format(
            num, xshift, yshift)
        joblib.dump(twinpy, filename)
        rlx_cell = twinpy.twinboundary_analyzer.relax_analyzer.final_cell
        posname = "./poscar/{}_xshift-{}_yshift-{}.poscar".format(
            num, xshift, yshift)
        write_poscar(rlx_cell, posname)
        formation_energy = twinpy.twinboundary_analyzer.get_formation_energy()
        data.append([xshift, yshift, formation_energy])

    data = np.array(data)
    print(data)

    # plot plane interval
    im = plt.scatter(data[:, 0], data[:, 1], c=data[:, 2], cmap=cm.jet)
    plt.colorbar(im)
    plt.show()
Example #6
0
def main(
    structure,
    shear_strain_ratio,
    twinmode,
    twintype,
    xshift,
    yshift,
    dim,
    layers,
    delta,
    expansion_ratios,
    no_make_tb_flat,
    posfile,
    get_poscar,
    get_lattice,
    output,
    is_primitive,
    get_primitive_standardized,
    get_conventional_standardized,
    dump,
    show_nearest_distance,
):

    move_atoms_into_unitcell = True
    symprec = 1e-5
    no_idealize = False
    no_sort = True
    get_sort_list = False

    if posfile is None:
        print("Warning:")
        print("    POSCAR file did not specify")
        print("    Set automatically, a=2.93, c=4.65, symbol='Ti', "
              "wyckoff='c'")
        lattice = get_hexagonal_lattice_from_a_c(a=2.93, c=4.65)
        symbol = 'Ti'
        wyckoff = 'c'
    else:
        poscar = Poscar.from_file(posfile)
        pmgstructure = poscar.structure
        cell = get_cell_from_pymatgen_structure(pmgstructure)
        lattice = cell[0]
        symbol = cell[2][0]
        wyckoff = get_wyckoff_from_hcp(cell)

    twinpy = Twinpy(lattice=lattice,
                    twinmode=twinmode,
                    symbol=symbol,
                    wyckoff=wyckoff)

    if get_poscar:
        if output is None:
            output = _get_output_name(structure=structure,
                                      get_lattice=get_lattice,
                                      shear_strain_ratio=shear_strain_ratio,
                                      twinmode=twinmode)

    if structure == 'shear':
        twinpy.set_shear(xshift=xshift,
                         yshift=yshift,
                         dim=dim,
                         shear_strain_ratio=shear_strain_ratio,
                         expansion_ratios=expansion_ratios,
                         is_primitive=is_primitive)
        std = twinpy.get_shear_standardize(
            get_lattice=get_lattice,
            move_atoms_into_unitcell=move_atoms_into_unitcell,
        )

    else:
        make_tb_flat = not no_make_tb_flat
        twinpy.set_twinboundary(twintype=twintype,
                                xshift=xshift,
                                yshift=yshift,
                                layers=layers,
                                delta=delta,
                                shear_strain_ratio=shear_strain_ratio,
                                expansion_ratios=expansion_ratios,
                                make_tb_flat=make_tb_flat)
        std = twinpy.get_twinboundary_standardize(
            get_lattice=get_lattice,
            move_atoms_into_unitcell=move_atoms_into_unitcell,
        )

        if show_nearest_distance:
            from twinpy.structure.twinboundary \
                    import plot_nearest_atomic_distance_of_twinboundary
            plot_nearest_atomic_distance_of_twinboundary(
                lattice=lattice,
                symbol=symbol,
                twinmode=twinmode,
                layers=layers,
                wyckoff=wyckoff,
                delta=delta,
                twintype=twintype,
                shear_strain_ratio=shear_strain_ratio,
                expansion_ratios=expansion_ratios,
                make_tb_flat=make_tb_flat,
            )

    if get_primitive_standardized:
        to_primitive = True
    elif get_conventional_standardized:
        to_primitive = False
    else:
        to_primitive = None

    if to_primitive is None:
        out_cell = std.cell
    else:
        out_cell = std.get_standardized_cell(
            to_primitive=to_primitive,
            no_idealize=no_idealize,
            symprec=symprec,
            no_sort=no_sort,
            get_sort_list=get_sort_list,
        )

    if output is not None:
        write_poscar(cell=out_cell, filename=output)

    if dump:
        twinpy.dump_yaml()