Пример #1
0
    def __common_plotting(self,
                        fermi_surface,
                        plotter: pv.Plotter,
                        mode:str, 
                        text:str,
                        spin_texture:bool=False,
                        
                        camera_pos:List[float]=[1, 1, 1],
                        background_color:str or Tuple[float,float,float,float]="white",
                        perspective:bool=True,

                        show:bool=False,
                        save_2d:bool=None,
                        save_gif:str=None,
                        save_mp4:str=None,
                        save_3d:str=None):

        if mode != "plain" or spin_texture:
            plotter.add_scalar_bar(
                title=text,
                n_labels=6,
                italic=False,
                bold=False,
                title_font_size=None,
                label_font_size=None,
                position_x=0.4,
                position_y=0.01,
                color="black",)

        plotter.add_axes(
            xlabel="Kx", 
            ylabel="Ky", 
            zlabel="Kz", 
            line_width=6, 
            labels_off=False)

        if not perspective:
            plotter.enable_parallel_projection()

        plotter.set_background(background_color)
        if not show:
            plotter.show(cpos=camera_pos, screenshot=save_2d)
        if save_gif is not None:
            path = plotter.generate_orbital_path(n_points=36)
            plotter.open_gif(save_gif)
            plotter.orbit_on_path(path) 
        if save_mp4:
            path = plotter.generate_orbital_path(n_points=36)
            plotter.open_movie(save_mp4)
            plotter.orbit_on_path(path) 

        if save_3d is not None:
            plotter.save_meshio(save_3d,  fermi_surface)
Пример #2
0
def plot_mesh_pyvista(
    plotter: pv.Plotter,
    polydata: pv.PolyData,
    # vertices: np.ndarray,
    # triangles: np.ndarray,
    rotations: List[Tuple[int, int, int]] = [(0, 0, 0)],
    vertexcolors: List[int] = [],
    vertexscalar: str = '',
    cmap: str = 'YlGnBu',
    title: str = '',
    scalar_bar_idx: int = 0,
    **mesh_kwargs,
):
    shape = plotter.shape
    if len(shape) == 1:
        assert shape[0] > 0
        assert shape[0] == len(rotations)
        subp_idx = [(x, ) for x in range(shape[0])]
    else:
        assert shape[0] > 0 and shape[1] > 0
        assert shape[0] * shape[1] == len(rotations)
        subp_idx = product(range(shape[0]), range(shape[1]))

    if vertexscalar and vertexcolors is not None:
        polydata[vertexscalar] = vertexcolors

    cmap = plt.cm.get_cmap(cmap)

    mesh_kwargs = {
        'cmap': cmap,
        'flip_scalars': True,
        'show_scalar_bar': False,
        **mesh_kwargs,
    }
    if vertexscalar and vertexcolors is not None:
        mesh_kwargs['scalars'] = vertexscalar

    for i, (subp, rots) in enumerate(zip(subp_idx, rotations)):
        x, y, z = rots
        plotter.subplot(*subp)
        poly_copy = polydata.copy()
        poly_copy.rotate_x(x)
        poly_copy.rotate_y(y)
        poly_copy.rotate_z(z)
        plotter.add_mesh(
            poly_copy,
            **mesh_kwargs,
        )
        if i == 0:
            plotter.add_title(title, font_size=5)
        if i == scalar_bar_idx:
            plotter.add_scalar_bar(label_font_size=10, position_x=0.85)
Пример #3
0
        def create_mesh(plotter:pv.Plotter,
                        value:float, 
                        ):
            res = int(value)
            closest_idx = find_nearest(energy_values, res)
            options_dict = self.__plot_options_helper(mode=mode,
                                                calculate_fermi_speed=calculate_fermi_speed,
                                                calculate_fermi_velocity=calculate_fermi_velocity,
                                                calculate_effective_mass=calculate_effective_mass)

            plotter.add_mesh(e_surfaces[closest_idx], 
                            name='iso_surface', 
                            scalars = options_dict['scalars'], 
                            show_scalar_bar=False)

            if mode != "plain" or spin_texture:
                plotter.add_scalar_bar(
                    title=options_dict['text'],
                    n_labels=6,
                    italic=False,
                    bold=False,
                    title_font_size=None,
                    label_font_size=None,
                    position_x=0.4,
                    position_y=0.01,
                    color="black",)
            
            if options_dict['scalars'] == "spin" or options_dict['scalars'] == "Fermi Velocity Vector_magnitude":
                if arrow_color is None:
                    arrows=e_surfaces[closest_idx].glyph(
                                                        orient=options_dict['vector_name'], 
                                                        scale=False ,
                                                        factor=arrow_size)

                    # To update arrows. First ininitialize actor(There will already be a iso_surface actor), then remove, then add
                    arrow_actor = [value for key, value in plotter.renderer.actors.items() if 'PolyData' in key]
                    if len(arrow_actor) != 0:
                        plotter.remove_actor(arrow_actor[0])
                    
                    plotter.add_mesh(arrows, 
                                    scalars = options_dict['scalars'],
                                    cmap=cmap,
                                    show_scalar_bar=False)
                else:
                    plotter.add_mesh(arrows, color=arrow_color,show_scalar_bar=False)

            return None
Пример #4
0
def plot_meshes_pyvista(
        plotter: pv.Plotter,
        polydatas: List[pv.PolyData],
        rotations: List[Tuple[int, int, int]],
        vertexcolors: np.ndarray = None,
        vertexscalar: str = '',
        cmap: str = 'YlGnBu',
        titles: str = '',
        scalar_bar_idx: int = -1,
        scalar_bar_kwargs: dict = dict(label_font_size=15, position_x=0.85),
        mesh_kwargs: dict = dict(),
        title_kwargs: dict = dict(),
):
    """
    Plot multiple meshes, each with their own rotation.
    
    Need a separate matrix of colours for each polydata.
    Should be one colour per vertex of the mesh.
    """
    shape = plotter.shape
    if len(shape) == 1:
        assert shape[0] > 0
        assert shape[0] == len(polydatas)
        subp_idx = [(x, ) for x in range(shape[0])]
    else:
        assert shape[0] > 0 and shape[1] > 0
        assert shape[0] * shape[1] == len(polydatas)
        subp_idx = product(range(shape[0]), range(shape[1]))

    if vertexscalar and vertexcolors is not None:
        assert vertexcolors.shape[0] == len(polydatas)

    cmap = plt.cm.get_cmap(cmap)

    mesh_kwargs = {
        'cmap': cmap,
        'flip_scalars': True,
        'show_scalar_bar': False,
        **mesh_kwargs,
    }
    if vertexscalar and vertexcolors is not None:
        mesh_kwargs['scalars'] = vertexscalar
        if 'clim' not in mesh_kwargs:
            mesh_kwargs['clim'] = [vertexcolors.min(), vertexcolors.max()]

    if isinstance(titles, str):
        titles = [titles] * len(polydatas)
    elif isinstance(titles, list):
        assert len(titles) == len(polydatas)

    for i, (subp, rots,
            polydata) in enumerate(zip(subp_idx, rotations, polydatas)):
        x, y, z = rots
        plotter.subplot(*subp)
        poly_copy = polydata.copy()
        if vertexscalar and vertexcolors is not None:
            poly_copy[vertexscalar] = vertexcolors[i]
        poly_copy.rotate_x(x)
        poly_copy.rotate_y(y)
        poly_copy.rotate_z(z)
        plotter.add_mesh(poly_copy, **mesh_kwargs)
        if titles[i]:
            plotter.add_title(titles[i],
                              **title_kwargs)  # font_size=10, font='arial')
        if i == scalar_bar_idx:
            plotter.add_scalar_bar(**scalar_bar_kwargs)