From af4e2b4ae24fc1e0f968af8138e29cd26b83faa2 Mon Sep 17 00:00:00 2001 From: Sean Kavanagh Date: Wed, 14 Feb 2024 13:37:13 +0000 Subject: [PATCH] Update linting and formatting --- .github/workflows/linting.yml | 2 +- .pre-commit-config.yaml | 13 ++++ docs/source/conf.py | 4 +- pyproject.toml | 9 ++- pytaser/__init__.py | 5 +- pytaser/das_generator.py | 16 +++-- pytaser/generator.py | 65 +++++++++++------- pytaser/internal_abs_generator.py | 23 ++++--- pytaser/kpoints.py | 22 +++++-- pytaser/plotter.py | 34 ++++++---- pytaser/tas.py | 32 ++++++--- setup.py | 4 +- tests/conftest.py | 24 +++++-- tests/test_generator.py | 12 ++-- tests/test_plotter.py | 106 +++++++++++++++++++++++------- 15 files changed, 262 insertions(+), 109 deletions(-) diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index f237cfc..a15c1bc 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -47,7 +47,7 @@ jobs: - name: check docstrings run: | pydocstyle --version - pydocstyle -e --count --convention=google + pydocstyle -e --count --convention=google --add-ignore=D400,D415,D200,D212,D205,D417,D107 - name: black run: | black --version diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 430b3f8..04b8867 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,10 @@ repos: + # Lint and format, isort, docstrings... + - repo: https://github.com/charliermarsh/ruff-pre-commit + rev: v0.0.270 + hooks: + - id: ruff + args: [ --fix ] - repo: https://github.com/timothycrosley/isort rev: "5.12.0" hooks: @@ -25,3 +31,10 @@ repos: hooks: - id: ruff args: [--fix] + # format docstring length: + - repo: https://github.com/PyCQA/docformatter + rev: v1.7.1 + hooks: + - id: docformatter + additional_dependencies: [ tomli ] + args: [ --in-place,--config,./pyproject.toml ] diff --git a/docs/source/conf.py b/docs/source/conf.py index c8b982e..6dab1c5 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -119,7 +119,9 @@ def setup(app): - """Add configuration for MyST parser.""" + """ + Add configuration for MyST parser. + """ app.add_config_value( "myst_parser_config", { diff --git a/pyproject.toml b/pyproject.toml index 9c5b456..d221c6a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,4 +54,11 @@ ignore = [ [tool.ruff.per-file-ignores] "tests/*" = ["D102", "D103"] -"docs/*" = ["D100"] \ No newline at end of file +"docs/*" = ["D100"] + +[tool.docformatter] +recursive = true +pre-summary-newline = true +make-summary-multi-line = true +wrap-summaries = 79 +wrap-descriptions = 79 \ No newline at end of file diff --git a/pytaser/__init__.py b/pytaser/__init__.py index 81a4d74..ed7cd2b 100644 --- a/pytaser/__init__.py +++ b/pytaser/__init__.py @@ -1,3 +1,4 @@ -"""PyTASER is a package for the generation, analysis and plotting of Transient Absorption Spectra of bulk -materials. +""" +PyTASER is a package for the generation, analysis and plotting of Transient +Absorption Spectra of bulk materials. """ diff --git a/pytaser/das_generator.py b/pytaser/das_generator.py index 2310514..53ddf64 100644 --- a/pytaser/das_generator.py +++ b/pytaser/das_generator.py @@ -1,4 +1,5 @@ -"""Created on Thu Aug 3 16:42:36 2023. +""" +Created on Thu Aug 3 16:42:36 2023. @author: lucasverga """ @@ -15,8 +16,9 @@ class DASGenerator: - """Class to generate a DAS spectrum (decomposed and cumulative) from a bandstructure and - dos object. + """ + Class to generate a DAS spectrum (decomposed and cumulative) from a + bandstructure and dos object. Args: new_system: Internal_Abs object from internal_abs_generator for the new system @@ -48,7 +50,8 @@ def from_vasp_outputs( waveder_file_new_system=None, waveder_file_ref=None, ): - """Create a DASGenerator object from VASP output files. + """ + Create a DASGenerator object from VASP output files. The user should provide the vasprun files for the new system and the reference system, followed by the waveder files for the new system and the reference system. @@ -82,8 +85,9 @@ def from_mpid( mpr=None, mpr_ref=None, ): - """Import the desired bandstructure and dos objects from the legacy Materials Project - database. + """ + Import the desired bandstructure and dos objects from the legacy + Materials Project database. Args: mpid: The Materials Project ID of the new system. diff --git a/pytaser/generator.py b/pytaser/generator.py index ba30f55..38cecd5 100644 --- a/pytaser/generator.py +++ b/pytaser/generator.py @@ -1,5 +1,6 @@ """ -This module contains the TASGenerator class, which is used to generate TAS spectra. +This module contains the TASGenerator class, which is used to generate TAS +spectra. """ import warnings @@ -23,8 +24,7 @@ def gaussian(x, width, center=0.0, height=None): """ - Returns Gaussian curve(s) centred at point(s) - x, where x is array-like. + Returns Gaussian curve(s) centred at point(s) x, where x is array-like. Args: x: Input array. @@ -40,8 +40,9 @@ def gaussian(x, width, center=0.0, height=None): def set_bandgap(bandstructure, dos, bandgap): - """Shifts all bands of a material to correct the DFT-underestimated bandgap according to - the input experimental bandgap. + """ + Shifts all bands of a material to correct the DFT-underestimated bandgap + according to the input experimental bandgap. Args: bandstructure: PMG bandstructure object @@ -90,7 +91,11 @@ def set_bandgap(bandstructure, dos, bandgap): def jdos(bs, f, i, occs, energies, kweights, gaussian_width, spin=Spin.up): - """Args: + """ + Obtains the cumulative JDOS value for a specific i->f transition, with + consideration of partial occupancy and spin polarisation. + + Args: bs: bandstructure object f: final band i: initial band @@ -118,7 +123,9 @@ def jdos(bs, f, i, occs, energies, kweights, gaussian_width, spin=Spin.up): def _calculate_oscillator_strength(args): - """Calculates the oscillator strength of a single band-band transition.""" + """ + Calculates the oscillator strength of a single band-band transition. + """ if len(args) == 9: # shared memory arrays ib, jb, ik, rspin, spin, sigma, nedos, deltae, ismear = args @@ -190,7 +197,9 @@ def get_nonzero_band_transitions( max_band, nk, ): - """Helper function to filter band transitions before (multi)processing.""" + """ + Helper function to filter band transitions before (multi)processing. + """ ispin_idx = 0 if spin == Spin.up else 1 ib_vals, jb_vals, ik_vals = np.meshgrid( @@ -250,8 +259,9 @@ def occ_dependent_alpha( processes=None, energy_max=6, ): - """Calculate the expected optical absorption given the groundstate orbital derivatives and - eigenvalues (via dfc) and specified band occupancies. + """ + Calculate the expected optical absorption given the groundstate orbital + derivatives and eigenvalues (via dfc) and specified band occupancies. Templated from pymatgen.io.vasp.optics.epsilon_imag(). Args: @@ -384,7 +394,8 @@ def occ_dependent_alpha( def get_cbm_vbm_index(bs): - """Args: + """ + Args: bs: bandstructure object. Returns: @@ -400,8 +411,8 @@ def get_cbm_vbm_index(bs): class TASGenerator: """ - Class to generate a TAS spectrum (decomposed and cumulative) from - a bandstructure and dos object. + Class to generate a TAS spectrum (decomposed and cumulative) from a + bandstructure and dos object. """ def __init__(self, bs, kpoint_weights, dos, dfc=None): @@ -435,7 +446,8 @@ def __init__(self, bs, kpoint_weights, dos, dfc=None): @classmethod def from_vasp_outputs(cls, vasprun_file, waveder_file=None, bg=None): - """Create a TASGenerator object from VASP output files. + """ + Create a TASGenerator object from VASP output files. Args: vasprun_file: Path to vasprun.xml file (to generate bandstructure object). @@ -489,7 +501,8 @@ def from_vasp_outputs(cls, vasprun_file, waveder_file=None, bg=None): ) def band_occupancies(self, temp, conc, dark=True): - """Gives band occupancies. + """ + Gives band occupancies. Args: temp: Temperature of material we wish to investigate (affects the FD @@ -548,12 +561,14 @@ def generate_tas( dark_occs=None, processes=None, ): - """Generates TAS spectra based on inputted occupancies, and a specified energy mesh. If the - TASGenerator has not been generated from VASP outputs (and thus does not have a dfc - attribute), then the output TAS is generated using the change in joint density of states - (JDOS) under illumination, with no consideration of oscillator strengths. - Otherwise, the output TAS is generated considering all contributions to the predicted TAS - spectrum. + """ + Generates TAS spectra based on inputted occupancies, and a specified + energy mesh. If the TASGenerator has not been generated from VASP + outputs (and thus does not have a dfc attribute), then the output TAS + is generated using the change in joint density of states (JDOS) under + illumination, with no consideration of oscillator strengths. Otherwise, + the output TAS is generated considering all contributions to the + predicted TAS spectrum. Args: temp: Temperature (K) of material we wish to investigate (affects the FD distribution) @@ -771,13 +786,13 @@ def generate_tas( @classmethod def from_mpid(cls, mpid, bg=None, api_key=None, mpr=None): """ - Import the desired bandstructure and dos objects from the - legacy Materials Project database. + Import the desired bandstructure and dos objects from the legacy + Materials Project database. Args: mpid: The Materials Project ID of the desired material. - bg: The experimental bandgap (eV) of the material. If None, the band gap - of the MP calculation will be used. + bg: The experimental bandgap (eV) of the material. If None, + the band gap of the MP calculation will be used. api_key: The user's Materials Project API key. mpr: An MPRester object if already generated by user. diff --git a/pytaser/internal_abs_generator.py b/pytaser/internal_abs_generator.py index 8a51e13..613066b 100644 --- a/pytaser/internal_abs_generator.py +++ b/pytaser/internal_abs_generator.py @@ -1,6 +1,7 @@ """ -This module contains the Internal_Abs class, which is used to generate an absorption spectrum -(decomposed and cumulative) from a bandstructure and dos object. +This module contains the Internal_Abs class, which is used to generate an +absorption spectrum (decomposed and cumulative) from a bandstructure and dos +object. """ import warnings @@ -21,8 +22,8 @@ class Internal_Abs: """ - Class to generate an absorption spectrum (decomposed and cumulative) - from a bandstructure and dos object. + Class to generate an absorption spectrum (decomposed and cumulative) from a + bandstructure and dos object. """ def __init__(self, bs, kpoint_weights, dos, dfc=None): @@ -58,7 +59,9 @@ def __init__(self, bs, kpoint_weights, dos, dfc=None): @classmethod def internal_from_vasp(cls, vasprun_file, waveder_file=None): - """Create an Internal_Abs object from VASP output files.""" + """ + Create an Internal_Abs object from VASP output files. + """ warnings.filterwarnings("ignore", category=UnknownPotcarWarning) warnings.filterwarnings("ignore", message="No POTCAR file with matching TITEL fields") vr = Vasprun(vasprun_file, parse_potcar_file=False, parse_projected_eigen=False) @@ -90,7 +93,8 @@ def internal_from_vasp(cls, vasprun_file, waveder_file=None): @classmethod def internal_from_mpid(cls, mpid, bg=None, api_key=None, mpr=None): - """Create an Internal_Abs object from a Materials Project ID. + """ + Create an Internal_Abs object from a Materials Project ID. Args: mpid: The Materials Project ID of the desired material. @@ -113,7 +117,8 @@ def internal_from_mpid(cls, mpid, bg=None, api_key=None, mpr=None): return cls(mp_bs, kweights, mp_dos, None) def band_occupancies(self, temp): - """Gives band occupancies. + """ + Gives band occupancies. Returns: A dictionary of {Spin: occ} for all bands across all k-points. @@ -146,7 +151,9 @@ def generate_abs( occs=None, processes=None, ): - """Generates absorption spectra based on inputted occupancies, and a specified energy mesh. + """ + Generates absorption spectra based on inputted occupancies, and a + specified energy mesh. Args: temp: Temperature (K) of material we wish to investigate (affects the FD distribution) diff --git a/pytaser/kpoints.py b/pytaser/kpoints.py index a0d5200..f2ea9e7 100644 --- a/pytaser/kpoints.py +++ b/pytaser/kpoints.py @@ -1,6 +1,8 @@ """ -This module generates kpoint-weights for uniform-mesh non-magnetic materials. This is vital when using -the Materials Project database to generate spectra in PyTASER. +This module generates kpoint-weights for uniform-mesh non-magnetic materials. + +This is vital when using the Materials Project database to generate spectra in +PyTASER. """ import numpy as np @@ -9,7 +11,9 @@ def get_kpoint_weights(bandstructure, time_reversal=True, symprec=0.1): - """Function to calculate the kpoint_weights for non-magnetic materials (non-metals). + """ + Function to calculate the kpoint_weights for non-magnetic materials (non- + metals). Args: bandstructure: PMG bandstructure object @@ -40,7 +44,8 @@ def get_kpoint_weights(bandstructure, time_reversal=True, symprec=0.1): def get_kpoints_from_bandstructure(bandstructure, cartesian=False): - """Function to pull the kpoint from the bandstructure. + """ + Function to pull the kpoint from the bandstructure. Args: bandstructure: PMG bandstructure object @@ -64,7 +69,8 @@ def expand_kpoints( return_mapping=False, time_reversal=True, ): - """Function to expand the kpoints. + """ + Function to expand the kpoints. Args: structure: PMG structure object @@ -134,7 +140,8 @@ def expand_kpoints( def get_mesh_from_kpoint_diff(kpoints, ktol=1e-5): - """Function to get the uniform mesh from kpoint differences. + """ + Function to get the uniform mesh from kpoint differences. Args: kpoints: uniform mesh kpoints array. @@ -183,7 +190,8 @@ def get_reciprocal_point_group_operations( symprec: float = 0.01, time_reversal: bool = True, ): - """Function to get the reciprocal point group operations. + """ + Function to get the reciprocal point group operations. Args: structure: PMG structure object diff --git a/pytaser/plotter.py b/pytaser/plotter.py index 8eda89b..6301026 100644 --- a/pytaser/plotter.py +++ b/pytaser/plotter.py @@ -16,18 +16,23 @@ def ev_to_lambda(ev): - """Convert photon energies from eV to a wavelength in nm.""" + """ + Convert photon energies from eV to a wavelength in nm. + """ return ((scpc.h * scpc.c) / (ev * scpc.electron_volt)) * 10e8 def lambda_to_ev(lambda_float): - """Convert photon energies from a wavelength in nm to eV.""" + """ + Convert photon energies from a wavelength in nm to eV. + """ return (10e8 * (scpc.h * scpc.c)) / (lambda_float * scpc.electron_volt) def cutoff_transitions(dictionary, cutoff, ind_xmin, ind_xmax): - """Output a list of transitions from a dict, with any that fall below a percentage cutoff of - the maximum value transition set to None. + """ + Output a list of transitions from a dict, with any that fall below a + percentage cutoff of the maximum value transition set to None. """ max_abs_val = {key: np.max(abs(val[ind_xmin:ind_xmax])) for key, val in dictionary.items()} max_val = max(max_abs_val.values()) @@ -41,8 +46,9 @@ def cutoff_transitions(dictionary, cutoff, ind_xmin, ind_xmax): class TASPlotter: - """Class to generate a matplotlib plot of the TAS, DAS, or JDOS spectra, with a specific energy - mesh, material, and conditions. + """ + Class to generate a matplotlib plot of the TAS, DAS, or JDOS spectra, with + a specific energy mesh, material, and conditions. """ def __init__( @@ -122,12 +128,16 @@ def get_plot( invert_axis=False, **kwargs, ): - """Plots TAS spectra using the data generated in the TAS container class as generated by - TASGenerator().generate_tas() or in the DAS container class generated by - DASGenerator().generate_das(). If the TASGenerator was not generated from VASP outputs, - then the output TAS is generated using the change in joint density of states (JDOS) under - illumination, with no consideration of oscillator strengths ("Total TAS (ΔJDOS only)") - - this behaviour can also be explicitly chosen by setting "yaxis" to "jdos_diff". + """ + Plots TAS spectra using the data generated in the TAS container class + as generated by TASGenerator().generate_tas() or in the DAS container + class generated by DASGenerator().generate_das(). If the TASGenerator + was not generated from VASP outputs, then the output TAS is generated + using the change in joint density of states (JDOS) under. + + illumination, with no consideration of oscillator strengths ("Total TAS + (ΔJDOS only)") - this behaviour can also be explicitly chosen by + setting "yaxis" to "jdos_diff". Otherwise, the output TAS is generated considering all contributions to the predicted TAS spectrum ("Total TAS (Δɑ)"). If only the contribution from the change in absorption is diff --git a/pytaser/tas.py b/pytaser/tas.py index a124c46..128ee8b 100644 --- a/pytaser/tas.py +++ b/pytaser/tas.py @@ -1,5 +1,7 @@ -"""This module generates container classes from the generator modules. These will be used to communicate -with the plotter module. +""" +This module generates container classes from the generator modules. + +These will be used to communicate with the plotter module. """ import ast @@ -8,7 +10,8 @@ def convert_to_tuple(subdict): - """Converts subdict representation to tuple. + """ + Converts subdict representation to tuple. Args: subdict: dict, @@ -22,7 +25,8 @@ def convert_to_tuple(subdict): def decode_dict(subdict): - """Decode subdict from a dict representation using MontyDecoder. + """ + Decode subdict from a dict representation using MontyDecoder. Args: subdict: dict @@ -40,7 +44,8 @@ def decode_dict(subdict): class Tas: - """A container class for the data from TASgenerator. + """ + A container class for the data from TASgenerator. Args: tas_total: overall TAS spectrum for a material under the specified conditions @@ -135,7 +140,9 @@ def __init__( self.weighted_jdos_diff_if = weighted_jdos_diff_if def as_dict(self): - """JSON-serializable dict representation of Tas.""" + """ + JSON-serializable dict representation of Tas. + """ json_dict = { "@module": type(self).__module__, "@class": type(self).__name__, @@ -164,7 +171,8 @@ def as_dict(self): @classmethod def from_dict(cls, d): - """Reconstructs Tas object from a dict representation of Tas created using + """ + Reconstructs Tas object from a dict representation of Tas created using Tas.as_dict(). Args: @@ -184,7 +192,8 @@ def from_dict(cls, d): class Das: - """A container class for the data from DASGenerator. + """ + A container class for the data from DASGenerator. Args: das_total: overall DAS spectrum between new_system and reference system. @@ -273,7 +282,9 @@ def __init__( self.weighted_jdos_ref_if = weighted_jdos_ref_if def as_dict(self): - """JSON-serializable dict representation of Das.""" + """ + JSON-serializable dict representation of Das. + """ json_dict = { "@module": type(self).__module__, "@class": type(self).__name__, @@ -300,7 +311,8 @@ def as_dict(self): @classmethod def from_dict(cls, d): - """Reconstructs Das object from a dict representation of Das created using + """ + Reconstructs Das object from a dict representation of Das created using Das.as_dict(). Args: diff --git a/setup.py b/setup.py index ffd9ed0..07d7058 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,6 @@ -"""PyTASER: transient absorption prediction tool.""" +""" +PyTASER: transient absorption prediction tool. +""" import pathlib diff --git a/tests/conftest.py b/tests/conftest.py index 9617d90..c0baecd 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,6 @@ -"""Setup for pytest.""" +""" +Setup for pytest. +""" from pathlib import Path @@ -12,31 +14,41 @@ @pytest.fixture(scope="package") def datapath_gaas(): - """Path to data_gaas folder.""" + """ + Path to data_gaas folder. + """ return Path(__file__).parent / "data_gaas" @pytest.fixture(scope="package") def datapath_cdte(): - """Path to data_cdte folder.""" + """ + Path to data_cdte folder. + """ return Path(__file__).parent / "data_cdte" @pytest.fixture(scope="package") def examplepath_cdte(): - """Path to CdTe examples folder.""" + """ + Path to CdTe examples folder. + """ return Path(__file__).parent.parent / "examples/CdTe" @pytest.fixture(scope="package") def examplepath_gaas(): - """Path to GaAs examples folder.""" + """ + Path to GaAs examples folder. + """ return Path(__file__).parent.parent / "examples/GaAs" @pytest.fixture(scope="package") def examplepath_tio2_das(): - """Path to TiO2_DAS examples folder.""" + """ + Path to TiO2_DAS examples folder. + """ return Path(__file__).parent.parent / "examples/TiO2-DAS" diff --git a/tests/test_generator.py b/tests/test_generator.py index 67c5f98..0a341c6 100644 --- a/tests/test_generator.py +++ b/tests/test_generator.py @@ -1,6 +1,6 @@ """ -Tests for the parsing/generation functionality of PyTASer (i.e. the generator.py, das_generator.py and -internal_abs_generator.py modules). +Tests for the parsing/generation functionality of PyTASer (i.e. the +generator.py, das_generator.py and internal_abs_generator.py modules). """ import os @@ -148,7 +148,9 @@ def test_occ_dependent_alpha( def test_symmetry_error(cdte_vasp_generated_class, datapath_cdte): - """Test that from_vasp_outputs raises informative errors when ISYM not 0/-1.""" + """ + Test that from_vasp_outputs raises informative errors when ISYM not 0/-1. + """ with pytest.raises( ValueError, match="ISYM must be set to 0 and ", # isym error, then followed by LVEL error @@ -160,7 +162,9 @@ def test_symmetry_error(cdte_vasp_generated_class, datapath_cdte): def test_LVEL_false_error(cdte_vasp_generated_class, datapath_cdte): - """Test that from_vasp_outputs raises informative errors when LVEL not True.""" + """ + Test that from_vasp_outputs raises informative errors when LVEL not True. + """ with pytest.raises( ValueError, match="LVEL must be set to True in the INCAR for the VASP optics calculation", diff --git a/tests/test_plotter.py b/tests/test_plotter.py index 5b41db4..c39f823 100644 --- a/tests/test_plotter.py +++ b/tests/test_plotter.py @@ -58,7 +58,9 @@ def test_get_plot(plotter_gaas): savefig_kwargs={"transparent": True, "bbox_inches": "tight", "dpi": 100}, ) def test_get_plot_das_ev(plotter_tio2_das): - """Test get_plot() DAS function for TiO2 with a electronvolts xaxis.""" + """ + Test get_plot() DAS function for TiO2 with a electronvolts xaxis. + """ return plotter_tio2_das.get_plot( xaxis="energy", transition_cutoff=0.01, @@ -75,7 +77,9 @@ def test_get_plot_das_ev(plotter_tio2_das): savefig_kwargs={"transparent": True, "bbox_inches": "tight", "dpi": 100}, ) def test_get_plot_das_nm(plotter_tio2_das): - """Test get_plot() DAS function for TiO2 with a wavelength xaxis.""" + """ + Test get_plot() DAS function for TiO2 with a wavelength xaxis. + """ return plotter_tio2_das.get_plot( xaxis="wavelength", transition_cutoff=0.01, @@ -92,7 +96,8 @@ def test_get_plot_das_nm(plotter_tio2_das): ) def test_get_plot_tas_ev(plotter_gaas): """ - Test get_plot() TAS function for GaAs with a 25% cutoff and electronvolts xaxis. + Test get_plot() TAS function for GaAs with a 25% cutoff and electronvolts + xaxis. """ return plotter_gaas.get_plot( relevant_transitions="auto", @@ -112,7 +117,10 @@ def test_get_plot_tas_ev(plotter_gaas): savefig_kwargs={"transparent": True, "bbox_inches": "tight"}, ) def test_get_plot_tas_lambda(plotter_gaas): - """Test get_plot() TAS function for GaAs with a 25% cutoff and a wavelength xaxis.""" + """ + Test get_plot() TAS function for GaAs with a 25% cutoff and a wavelength + xaxis. + """ return plotter_gaas.get_plot( relevant_transitions="auto", xaxis="wavelength", @@ -131,7 +139,10 @@ def test_get_plot_tas_lambda(plotter_gaas): savefig_kwargs={"transparent": True, "bbox_inches": "tight"}, ) def test_get_plot_jdos_ev(plotter_gaas): - """Test get_plot() JDOS function for GaAs with a 25% cutoff and a electronvolts xaxis.""" + """ + Test get_plot() JDOS function for GaAs with a 25% cutoff and a + electronvolts xaxis. + """ return plotter_gaas.get_plot( relevant_transitions="auto", xaxis="energy", @@ -150,7 +161,10 @@ def test_get_plot_jdos_ev(plotter_gaas): savefig_kwargs={"transparent": True, "bbox_inches": "tight"}, ) def test_get_plot_jdos_lambda(plotter_gaas): - """Test get_plot() JDOS function for GaAs with a 25% cutoff and a wavelength xaxis.""" + """ + Test get_plot() JDOS function for GaAs with a 25% cutoff and a wavelength + xaxis. + """ return plotter_gaas.get_plot( relevant_transitions="auto", xaxis="wavelength", @@ -175,7 +189,10 @@ def test_get_plot_cdte(plotter_cdte): savefig_kwargs={"transparent": True, "bbox_inches": "tight"}, ) def test_get_plot_tas_ev_cdte(plotter_cdte): - """Test get_plot() TAS function for CdTe with the default cutoff and electronvolts xaxis.""" + """ + Test get_plot() TAS function for CdTe with the default cutoff and + electronvolts xaxis. + """ return plotter_cdte.get_plot( relevant_transitions="auto", xaxis="energy", @@ -191,7 +208,10 @@ def test_get_plot_tas_ev_cdte(plotter_cdte): savefig_kwargs={"transparent": True, "bbox_inches": "tight"}, ) def test_get_plot_tas_lambda_cdte(plotter_cdte): - """Test get_plot() TAS function for CdTe with the default cutoff and wavelength xaxis.""" + """ + Test get_plot() TAS function for CdTe with the default cutoff and + wavelength xaxis. + """ return plotter_cdte.get_plot( relevant_transitions="auto", xaxis="wavelength", @@ -207,7 +227,10 @@ def test_get_plot_tas_lambda_cdte(plotter_cdte): savefig_kwargs={"transparent": True, "bbox_inches": "tight"}, ) def test_get_plot_jdos_ev_cdte(plotter_cdte): - """Test get_plot() JDOS function for CdTe with the default cutoff and electronvolts xaxis.""" + """ + Test get_plot() JDOS function for CdTe with the default cutoff and + electronvolts xaxis. + """ return plotter_cdte.get_plot( relevant_transitions="auto", xaxis="energy", @@ -223,7 +246,10 @@ def test_get_plot_jdos_ev_cdte(plotter_cdte): savefig_kwargs={"transparent": True, "bbox_inches": "tight"}, ) def test_get_plot_jdos_lambda_cdte(plotter_cdte): - """Test get_plot() JDOS function for CdTe with the default cutoff and wavelength xaxis.""" + """ + Test get_plot() JDOS function for CdTe with the default cutoff and + wavelength xaxis. + """ return plotter_cdte.get_plot( relevant_transitions="auto", xaxis="wavelength", @@ -234,8 +260,9 @@ def test_get_plot_jdos_lambda_cdte(plotter_cdte): def test_line_color_consistency(plotter_cdte): - """Test that the same transition has the same color in all plots, when transition_cutoff is - changed. + """ + Test that the same transition has the same color in all plots, when + transition_cutoff is changed. """ fig = plotter_cdte.get_plot() # with default transition_cutoff of 0.03 line = [_line for _line in fig.gca().lines if "(-2, 0)" in _line.get_label()][0] @@ -256,7 +283,10 @@ def test_line_color_consistency(plotter_cdte): def test_get_plot_alpha_cdte_no_waveder(plotter_cdte): - """Test informative error for get_plot() yaxis="alpha" when no WAVEDER was parsed.""" + """ + Test informative error for get_plot() yaxis="alpha" when no WAVEDER was + parsed. + """ with pytest.raises( ValueError, match="The `alpha` option for yaxis can only be chosen if the " @@ -272,7 +302,10 @@ def test_get_plot_alpha_cdte_no_waveder(plotter_cdte): def test_get_plot_tas_absorption_only_cdte_no_waveder(plotter_cdte): - """Test informative error for get_plot() yaxis="tas_absorption_only" when no WAVEDER was parsed.""" + """ + Test informative error for get_plot() yaxis="tas_absorption_only" when no + WAVEDER was parsed. + """ with pytest.raises( ValueError, match="The `tas_absorption_only` option for yaxis can only be chosen if the " @@ -293,7 +326,10 @@ def test_get_plot_tas_absorption_only_cdte_no_waveder(plotter_cdte): savefig_kwargs={"transparent": True, "bbox_inches": "tight"}, ) def test_get_plot_tas_cdte(plotter_cdte_vasp): - """Test get_plot() yaxis="tas" for CdTe with the default cutoff and electronvolts xaxis.""" + """ + Test get_plot() yaxis="tas" for CdTe with the default cutoff and + electronvolts xaxis. + """ return plotter_cdte_vasp.get_plot( relevant_transitions="auto", xaxis="energy", @@ -310,7 +346,8 @@ def test_get_plot_tas_cdte(plotter_cdte_vasp): ) def test_get_plot_jdos_diff_cdte_vasp(plotter_cdte_vasp): """ - Test get_plot() yaxis="jdos_diff" function for CdTe with the default cutoff and electronvolts xaxis. + Test get_plot() yaxis="jdos_diff" function for CdTe with the default cutoff + and electronvolts xaxis. """ return plotter_cdte_vasp.get_plot( relevant_transitions="auto", @@ -329,7 +366,10 @@ def test_get_plot_jdos_diff_cdte_vasp(plotter_cdte_vasp): savefig_kwargs={"transparent": True, "bbox_inches": "tight"}, ) def test_get_plot_jdos_diff_cdte_vasp_vr_only(plotter_cdte_vasp_vr_only): - """Test get_plot() yaxis="jdos_diff" for CdTe with the default cutoff and electronvolts xaxis.""" + """ + Test get_plot() yaxis="jdos_diff" for CdTe with the default cutoff and + electronvolts xaxis. + """ return plotter_cdte_vasp_vr_only.get_plot( relevant_transitions="auto", xaxis="energy", @@ -347,7 +387,10 @@ def test_get_plot_jdos_diff_cdte_vasp_vr_only(plotter_cdte_vasp_vr_only): savefig_kwargs={"transparent": True, "bbox_inches": "tight"}, ) def test_get_plot_jdos_diff_cdte(plotter_cdte_vasp_vr_only): - """Test get_plot() yaxis="tas" for CdTe with the default cutoff and electronvolts xaxis.""" + """ + Test get_plot() yaxis="tas" for CdTe with the default cutoff and + electronvolts xaxis. + """ return plotter_cdte_vasp_vr_only.get_plot( relevant_transitions="auto", xaxis="energy", @@ -363,7 +406,10 @@ def test_get_plot_jdos_diff_cdte(plotter_cdte_vasp_vr_only): savefig_kwargs={"transparent": True, "bbox_inches": "tight"}, ) def test_get_plot_alpha_cdte(plotter_cdte_vasp): - """Test get_plot() yaxis="alpha" for CdTe with the default cutoff and electronvolts xaxis.""" + """ + Test get_plot() yaxis="alpha" for CdTe with the default cutoff and + electronvolts xaxis. + """ return plotter_cdte_vasp.get_plot( relevant_transitions="auto", xaxis="energy", @@ -380,8 +426,8 @@ def test_get_plot_alpha_cdte(plotter_cdte_vasp): ) def test_get_plot_tas_absorption_only_cdte_vasp(plotter_cdte_vasp): """ - Test get_plot() yaxis="tas_absorption_only" function for CdTe - with the default cutoff and electronvolts xaxis. + Test get_plot() yaxis="tas_absorption_only" function for CdTe with the + default cutoff and electronvolts xaxis. """ return plotter_cdte_vasp.get_plot( relevant_transitions="auto", @@ -398,7 +444,10 @@ def test_get_plot_tas_absorption_only_cdte_vasp(plotter_cdte_vasp): savefig_kwargs={"transparent": True, "bbox_inches": "tight"}, ) def test_get_plot_jdos_cdte(plotter_cdte_vasp): - """Test get_plot() yaxis="jdos" function for CdTe with the default cutoff and electronvolts xaxis.""" + """ + Test get_plot() yaxis="jdos" function for CdTe with the default cutoff and + electronvolts xaxis. + """ return plotter_cdte_vasp.get_plot( relevant_transitions="auto", xaxis="energy", @@ -415,7 +464,10 @@ def test_get_plot_jdos_cdte(plotter_cdte_vasp): savefig_kwargs={"transparent": True, "bbox_inches": "tight"}, ) def test_get_plot_jdos_cdte_vasp_vr_only(plotter_cdte_vasp_vr_only): - """Test get_plot() yaxis="jdos" for CdTe with the default cutoff and electronvolts xaxis.""" + """ + Test get_plot() yaxis="jdos" for CdTe with the default cutoff and + electronvolts xaxis. + """ return plotter_cdte_vasp_vr_only.get_plot( relevant_transitions="auto", xaxis="energy", @@ -431,7 +483,9 @@ def test_get_plot_jdos_cdte_vasp_vr_only(plotter_cdte_vasp_vr_only): savefig_kwargs={"transparent": True, "bbox_inches": "tight"}, ) def test_get_plot_tas_cdte_custom_legend(plotter_cdte_vasp): - """Test get_plot() yaxis="tas" for CdTe with kwargs for plt.legend().""" + """ + Test get_plot() yaxis="tas" for CdTe with kwargs for plt.legend(). + """ return plotter_cdte_vasp.get_plot( relevant_transitions="auto", xaxis="energy", @@ -455,5 +509,7 @@ def test_get_plot_tas_cdte_custom_legend(plotter_cdte_vasp): savefig_kwargs={"transparent": True, "bbox_inches": "tight"}, ) def test_get_plot_tas_cdte_bandgap_scissor(plotter_cdte_bg_3_vasp): - """Test get_plot() for CdTe with scissored bandgap to 3 eV.""" + """ + Test get_plot() for CdTe with scissored bandgap to 3 eV. + """ return plotter_cdte_bg_3_vasp.get_plot(xaxis="energy")