def test_decimation(self): fs = FermiSurface.from_band_structure(self.band_structure, self.kpoint_dim) n_faces_orig = len(fs.isosurfaces[Spin.up][0][1]) fs = FermiSurface.from_band_structure( self.band_structure, self.kpoint_dim, decimate_factor=0.8 ) n_faces_new = len(fs.isosurfaces[Spin.up][0][1]) self.assertLess(n_faces_new, n_faces_orig)
def test_integration_wigner_seitz(self): interpolater = Interpolater(self.band_structure) new_bs, kpoint_dim = interpolater.interpolate_bands(1) fs = FermiSurface.from_band_structure(new_bs, kpoint_dim) plotter = FermiSurfacePlotter(fs) plotter.plot(plot_type="mpl", interactive=False, filename=self.output_file)
def fsplot( filename: Optional[Union[Path, str]] = None, interpolate_factor: int = 8, mu: float = 0.0, wigner_seitz: bool = True, spin: Optional[Spin] = None, plot_type: str = "plotly", interactive: bool = False, prefix: Optional[str] = None, directory: Optional[Union[Path, str]] = None, image_format: str = "png", dpi: float = 400, ): """Plot Fermi surfaces from a vasprun.xml file. Args: filename: Path to input vasprun file. interpolate_factor: The factor by which to interpolate the bands. mu: The level above the Fermi energy at which the isosurfaces are to be plotted. wigner_seitz: Controls whether the cell is the Wigner-Seitz cell or the reciprocal unit cell parallelepiped. spin: The spin channel to plot. By default plots both spin channels. plot_type: Method used for plotting. Valid options are: "matplotlib", "plotly", "mayavi". interactive: Whether to enable interactive plots. prefix: Prefix for file names. directory: The directory in which to save files. image_format: The image file format. dpi: The dots-per-inch (pixel density) for the image. Returns: The filename written to disk. """ from ifermi.fermi_surface import FermiSurface from ifermi.interpolator import Interpolater from ifermi.plotter import FSPlotter if not filename: filename = find_vasprun_file() vr = Vasprun(filename) bs = vr.get_band_structure() interpolater = Interpolater(bs) interp_bs, kpoint_dim = interpolater.interpolate_bands(interpolate_factor) fs = FermiSurface.from_band_structure( interp_bs, kpoint_dim, mu=mu, wigner_seitz=wigner_seitz, spin=spin, ) plotter = FSPlotter(fs) directory = directory if directory else "." prefix = "{}_".format(prefix) if prefix else "" output_filename = "{}fermi_surface.{}".format(prefix, image_format) output_filename = Path(directory) / output_filename plotter.plot(plot_type=plot_type, interactive=interactive, filename=output_filename)
from pathlib import Path from monty.serialization import dumpfn from ifermi.fermi_surface import FermiSurface from ifermi.interpolator import Interpolater from pymatgen.io.vasp.outputs import Vasprun if __name__ == "__main__": example_dir = Path("../../examples") vr = Vasprun(example_dir / "MgB2/vasprun.xml") bs = vr.get_band_structure() dumpfn(bs.structure, "structure.json.gz") interpolater = Interpolater(bs) new_bs, kpoint_dim = interpolater.interpolate_bands(1) bs_data = {"bs": new_bs, "dim": kpoint_dim, "structure": bs.structure} dumpfn(bs_data, "bs_BaFe2As2.json.gz") fs = FermiSurface.from_band_structure(new_bs, kpoint_dim, wigner_seitz=True) dumpfn(fs, "fs_BaFe2As2_wigner.json.gz") dumpfn(fs.reciprocal_space, "rs_wigner.json.gz") fs = FermiSurface.from_band_structure(new_bs, kpoint_dim, wigner_seitz=False) dumpfn(fs, "fs_BaFe2As2_reciprocal.json.gz") dumpfn(fs.reciprocal_space, "rs_reciprocal.json.gz")
def test_reciprocal_cell(self): fs = FermiSurface.from_band_structure(self.band_structure, self.kpoint_dim, wigner_seitz=False) self.assert_fs_equal(fs, self.ref_fs_reciprocal)
def test_wigner_seitz_cell(self): fs = FermiSurface.from_band_structure(self.band_structure, self.kpoint_dim, wigner_seitz=True) self.assert_fs_equal(fs, self.ref_fs_wigner)
def fsplot2d( filenames=None, code="vasp", prefix=None, directory=None, interpolate_factor=8, mu=0.0, image_format="pdf", dpi=400, plt=None, fonts=None, plane_orig=(0.0, 0.0, 0.5), plane_norm=(0, 0, 1), ): """Plot electronic band structure diagrams from vasprun.xml files. Args: filenames (:obj:`str` or :obj:`list`, optional): Path to input files. Vasp: Use vasprun.xml or vasprun.xml.gz file. If no filenames are provided, ifermi will search for vasprun.xml or vasprun.xml.gz files in folders named 'split-0*'. Failing that, the code will look for a vasprun in the current directory. code (:obj:`str`, optional): Calculation type. Default is 'vasp' prefix (:obj:`str`, optional): Prefix for file names. directory (:obj:`str`, optional): The directory in which to save files. interpolate_factor (float, optional): The factor by which to interpolate the bands mu (float, optional): The level above the Fermi energy at which the isosurfaces are to be plotted. image_format (:obj:`str`, optional): The image file format. dpi (:obj:`int`, optional): The dots-per-inch (pixel density) for the image. plt (:obj:`matplotlib.pyplot`, optional): A :obj:`matplotlib.pyplot` object to use for plotting. Returns: If ``plt`` set then the ``plt`` object will be returned. Otherwise, the method will return a :obj:`list` of filenames written to disk. """ from ifermi.fermi_surface import FermiSurface from ifermi.interpolator import Interpolater from ifermi.plotter import FSPlotter, FSPlotter2D if not filenames: filenames = find_vasprun_files() elif isinstance(filenames, str): filenames = [filenames] # # don't save if pyplot object provided # save_files = False if plt else True vr = Vasprun(filenames) bs = vr.get_band_structure() if not interpolate: interpolate_factor = 1 interpolater = Interpolater(bs) new_bs, hdims, rlattvec = interpolater.interpolate_bands(interpolate_factor) fs = FermiSurface(new_bs, hdims, rlattvec, mu=mu, plot_wigner_seitz=False) if plot_wigner_seitz: bz = WignerSeitzCell(rlattvec) rc = None else: bz = None rc = RecipCell(rlattvec) plotter = FSPlotter2D(fs, plane_orig=plane_orig, plane_norm=plane_norm) plotter.fs2d_plot_data(plot_type="mpl")
def test_spin_up(self): fs = FermiSurface.from_band_structure( self.band_structure, self.kpoint_dim, spin=Spin.up ) self.assert_fs_equal(fs, self.ref_fs_spin_up)
def fsplot( filename: Optional[Union[Path, str]] = None, interpolate_factor: int = 8, mu: float = 0.0, wigner_seitz: bool = True, spin: Optional[Spin] = None, plot_type: str = "plotly", interactive: bool = False, slice_info: Optional[Tuple[float, float, float, float]] = None, prefix: Optional[str] = None, directory: Optional[Union[Path, str]] = None, image_format: str = "png", dpi: float = 400, ): """Plot Fermi surfaces from a vasprun.xml file. Args: filename: Path to input vasprun file. interpolate_factor: The factor by which to interpolate the bands. mu: The level above the Fermi energy at which the isosurfaces are to be plotted. wigner_seitz: Controls whether the cell is the Wigner-Seitz cell or the reciprocal unit cell parallelepiped. spin: The spin channel to plot. By default plots both spin channels. plot_type: Method used for plotting. Valid options are: "matplotlib", "plotly", "mayavi". interactive: Whether to enable interactive plots. prefix: Prefix for file names. slice_info: Slice through the Brillouin zone. Given as the plane normal and distance form the plane in fractional coordinates: E.g., ``[1, 0, 0, 0.2]`` where ``(1, 0, 0)`` are the miller indices and ``0.2`` is the distance from the Gamma point. directory: The directory in which to save files. image_format: The image file format. dpi: The dots-per-inch (pixel density) for the image. Returns: The filename written to disk. """ from ifermi.fermi_surface import FermiSurface from ifermi.interpolator import Interpolater from ifermi.plotter import FermiSurfacePlotter if not filename: filename = find_vasprun_file() vr = Vasprun(filename) bs = vr.get_band_structure() interpolater = Interpolater(bs) interp_bs, kpoint_dim = interpolater.interpolate_bands(interpolate_factor) fs = FermiSurface.from_band_structure( interp_bs, kpoint_dim, mu=mu, wigner_seitz=wigner_seitz ) directory = directory if directory else "." prefix = "{}_".format(prefix) if prefix else "" if slice_info: plane_normal = slice_info[:3] distance = slice_info[3] fermi_slice = fs.get_fermi_slice(plane_normal, distance) plotter = FermiSlicePlotter(fermi_slice) output_filename = "{}fermi_slice.{}".format(prefix, image_format) output_filename = Path(directory) / output_filename plotter.plot(filename=output_filename, spin=spin) else: plotter = FermiSurfacePlotter(fs) output_filename = "{}fermi_surface.{}".format(prefix, image_format) output_filename = Path(directory) / output_filename plotter.plot( plot_type=plot_type, interactive=interactive, filename=output_filename, spin=spin, )