From d5d0f61fc869d0437ae37d646419f17c33b9dd46 Mon Sep 17 00:00:00 2001 From: Savya Aggarwal <44528580+savya10@users.noreply.github.com> Date: Tue, 13 Feb 2024 15:56:31 +0000 Subject: [PATCH] Linting error fixes --- pytaser/__init__.py | 5 ++- pytaser/das_generator.py | 13 ++++-- pytaser/generator.py | 8 ++-- pytaser/kpoints.py | 51 +++++++++++++++++++++++- pytaser/tas.py | 86 +++++++++++++++++++++++++++++++++++++--- setup.py | 4 +- tests/conftest.py | 4 +- 7 files changed, 149 insertions(+), 22 deletions(-) diff --git a/pytaser/__init__.py b/pytaser/__init__.py index 1873adb..81a4d74 100644 --- a/pytaser/__init__.py +++ b/pytaser/__init__.py @@ -1,2 +1,3 @@ -"""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 82c36bd..2310514 100644 --- a/pytaser/das_generator.py +++ b/pytaser/das_generator.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 """Created on Thu Aug 3 16:42:36 2023. @author: lucasverga @@ -32,6 +31,12 @@ def __init__( new_system, reference_system, ): + """ + + Args: + new_system: Internal_Abs object from internal_abs_generator for the new system + reference_system: Internal_Abs object from internal_abs_generator for the reference system. + """ self.new_system = new_system self.reference_system = reference_system @@ -55,7 +60,8 @@ def from_vasp_outputs( waveder_file_ref: The WAVEDER file for the reference system. Returns: - A DASGenerator object containing the Internal_Abs object for the new system and reference system. + A DASGenerator object containing the Internal_Abs object for the new system and reference + system. """ warnings.filterwarnings("ignore", category=UnknownPotcarWarning) warnings.filterwarnings("ignore", message="No POTCAR file with matching TITEL fields") @@ -91,7 +97,8 @@ def from_mpid( mpr_ref: An MPRester object for the reference system if already generated by user. Returns: - A DASGenerator object containing the Internal_Abs object for the new system and reference system. + A DASGenerator object containing the Internal_Abs object for the new system and reference + system. """ new_system = Internal_Abs.internal_from_mpid(mpid, bg=None, api_key=None, mpr=None) reference_system = Internal_Abs.internal_from_mpid(mpid_ref, bg_ref, api_key=None, mpr_ref=None) diff --git a/pytaser/generator.py b/pytaser/generator.py index af443f1..ba30f55 100644 --- a/pytaser/generator.py +++ b/pytaser/generator.py @@ -3,6 +3,7 @@ """ import warnings +from itertools import zip_longest from multiprocessing import Array, Pool, cpu_count import numpy as np @@ -211,7 +212,7 @@ def get_nonzero_band_transitions( ) return list( - zip( + zip_longest( ib_vals[condition].ravel(), jb_vals[condition].ravel(), ik_vals[condition].ravel(), @@ -221,13 +222,14 @@ def get_nonzero_band_transitions( [nedos] * np.sum(condition), [deltae] * np.sum(condition), [ismear] * np.sum(condition), + fillvalue=None, ) ) def _init_shared_memory(cder, occs, eigs_shifted, norm_kweights): - global _cder, _occs, _eigs_shifted, _norm_kweights - global _cder_shape, _occs_shape, _eigs_shifted_shape, _norm_kweights_shape + global _cder, _occs, _eigs_shifted, _norm_kweights # noqa: PLW0603 + global _cder_shape, _occs_shape, _eigs_shifted_shape, _norm_kweights_shape # noqa: PLW0603 _cder_shape = cder.shape _cder = Array("d", cder.ravel()) diff --git a/pytaser/kpoints.py b/pytaser/kpoints.py index 219b367..a0d5200 100644 --- a/pytaser/kpoints.py +++ b/pytaser/kpoints.py @@ -1,3 +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. +""" + import numpy as np from pymatgen.core import Structure from pymatgen.electronic_structure.bandstructure import BandStructureSymmLine @@ -8,7 +13,7 @@ def get_kpoint_weights(bandstructure, time_reversal=True, symprec=0.1): Args: bandstructure: PMG bandstructure object - time_reversal: + time_reversal: Time reversal operator, bool (True for +1, False for -1) symprec: Symmetry precision in Angstrom.(Lower value is more precise, but computationally more expensive) @@ -35,6 +40,15 @@ 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. + + Args: + bandstructure: PMG bandstructure object + cartesian: bool, indicate if cartesian or fractional coordinates used. + + Returns: + k-points + """ if cartesian: kpoints = np.array([k.cart_coords for k in bandstructure.kpoints]) else: @@ -50,6 +64,19 @@ def expand_kpoints( return_mapping=False, time_reversal=True, ): + """Function to expand the kpoints. + + Args: + structure: PMG structure object + kpoints: uniform mesh kpoints array. + symprec: Symmetry precision in Angstrom.(Lower value is more precise, but + computationally more expensive) + return_mapping: bool + time_reversal: Time reversal operator, bool (True for +1, False for -1) + + Returns: + full_kpoints, rotations, translations, is_tr, op_mapping, kp_mapping + """ kpoints = np.array(kpoints).round(8) # due to limited input precision of the k-points, the mesh is returned as a float @@ -90,7 +117,7 @@ def expand_kpoints( in_uniform_mesh = (np.abs(unique_addresses) < 1e-5).all(axis=1) n_mapped = int(np.sum(in_uniform_mesh)) - n_expected = int(np.product(mesh)) + n_expected = int(np.prod(mesh)) if n_mapped != n_expected: raise ValueError(f"Expected {n_expected} points but found {n_mapped}") @@ -107,6 +134,15 @@ def expand_kpoints( def get_mesh_from_kpoint_diff(kpoints, ktol=1e-5): + """Function to get the uniform mesh from kpoint differences. + + Args: + kpoints: uniform mesh kpoints array. + ktol: threshold for filtering changes in kpoint-mesh points. + + Returns: + np.array([na, nb, nc]), is_shifted + """ kpoints = np.array(kpoints) # whether the k-point mesh is shifted or Gamma centered mesh @@ -147,6 +183,17 @@ def get_reciprocal_point_group_operations( symprec: float = 0.01, time_reversal: bool = True, ): + """Function to get the reciprocal point group operations. + + Args: + structure: PMG structure object + symprec: Symmetry precision in Angstrom.(Lower value is more precise, but + computationally more expensive) + time_reversal: Time reversal operator, bool (True for +1, False for -1) + + Returns: + rotations[sort_idx], translations[sort_idx], is_tr[sort_idx] + """ from pymatgen.symmetry.analyzer import SpacegroupAnalyzer sga = SpacegroupAnalyzer(structure, symprec=symprec) diff --git a/pytaser/tas.py b/pytaser/tas.py index f40c3a1..a124c46 100644 --- a/pytaser/tas.py +++ b/pytaser/tas.py @@ -1,5 +1,6 @@ -"""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 @@ -7,19 +8,34 @@ def convert_to_tuple(subdict): + """Converts subdict representation to tuple. + + Args: + subdict: dict, + + Returns: + subdict: tuple + """ if isinstance(subdict, dict) and "@module" not in subdict: return {ast.literal_eval(k) if "(" in k and ")" in k else k: v for k, v in subdict.items()} return subdict def decode_dict(subdict): + """Decode subdict from a dict representation using MontyDecoder. + + Args: + subdict: dict + + Returns: + subdict: decoded dict + """ if isinstance(subdict, dict): if "@module" in subdict: return MontyDecoder().process_decoded(subdict) - else: - for k, v in subdict.items(): - if isinstance(v, dict) and "@module" in v: - subdict[k] = MontyDecoder().process_decoded(v) + for k, v in subdict.items(): + if isinstance(v, dict) and "@module" in v: + subdict[k] = MontyDecoder().process_decoded(v) return subdict @@ -73,6 +89,35 @@ def __init__( weighted_jdos_dark_if=None, weighted_jdos_diff_if=None, ): + """ + Args: + tas_total: overall TAS spectrum for a material under the specified conditions + jdos_diff_if: JDOS difference (from dark to light) across the energy mesh for a + specific band transition i (initial) -> f (final) [dict] + jdos_light_total: overall JDOS (pump-on) for a material under the specified + conditions + jdos_light_if: JDOS (pump-on) across the energy mesh for a specific band + transition i (initial) -> f (final) [dict] + jdos_dark_total: overall JDOS (pump-off) for a material under the specified + conditions + jdos_dark_if: JDOS (pump-off) across the energy mesh for a specific band + transition i (initial) -> f (final) [dict] + energy_mesh_ev: Energy mesh of spectra in eV, with an interval of 'step'. + bandgap: Bandgap of the system in electronvolts (eV). + temp: Temperature (K) of material we wish to investigate (affects the FD distribution) + conc: Carrier concentration (cm^-3) of holes and electrons (both are equivalent). + Inversely proportional to pump-probe time delay. + alpha_dark: Absorption coefficient of the material in the dark, in cm^-1. + alpha_light_dict: Dictionary of band-to-band absorption, stimulated emission and summed + contributions to the total overall absorption coefficient under illumination, in cm^-1. + weighted_jdos_light_if: JDOS weighted by the transition dipole matrix (TDM) (pump-on) + across the energy mesh for a specific band transition i (initial) -> f (final) [dict] + weighted_jdos_dark_if: JDOS weighted by the transition dipole matrix (TDM) (pump-off) + across the energy mesh for a specific band transition i (initial) -> f (final) [dict] + weighted_jdos_diff_if: Difference in JDOS weighted by the transition dipole matrix + (TDM) from dark to illumination across the energy mesh for a specific band transition + i (initial) -> f (final) [dict]. + """ self.tas_total = tas_total self.jdos_diff_if = jdos_diff_if self.jdos_light_total = jdos_light_total @@ -184,6 +229,35 @@ def __init__( weighted_jdos_new_sys_if=None, weighted_jdos_ref_if=None, ): + """ + Args: + das_total: overall DAS spectrum between new_system and reference system. + jdos_diff_if: JDOS difference (from reference to newsystem) across the energy mesh for a + specific band transition i (initial) -> f (final) [dict] + jdos_new_sys_total: overall JDOS for the new system under the specified + conditions + jdos_new_sys_if: JDOS for the new system across the energy mesh for a specific band + transition i (initial) -> f (final) [dict] + jdos_ref_total: overall JDOS for the reference system under the specified + conditions + jdos_ref_if: JDOS for the reference system across the energy mesh for a specific band + transition i (initial) -> f (final) [dict] + energy_mesh_ev: Energy mesh of spectra in eV, with an interval of 'step'. + bandgap_new_sys: Bandgap of the new system in electronvolts (eV). + bandgap_ref: Bandgap of the reference system in electronvolts (eV). + temp: Temperature (K) of material we wish to investigate (affects the FD distribution) + alpha_new_sys: Absorption coefficient of the new system in the dark, in cm^-1. + alpha_ref: Absorption coefficient of the reference system in the dark, in cm^-1. + weighted_jdos_new_sys_if: JDOS weighted by the transition dipole matrix (TDM) for the new + system across the energy mesh for a specific band transition i (initial) -> f (final) + [dict] + weighted_jdos_ref_if: JDOS weighted by the transition dipole matrix (TDM) for the reference + system across the energy mesh for a specific band transition i (initial) -> f (final) + [dict] + weighted_jdos_diff_if: Difference in JDOS weighted by the transition dipole matrix + (TDM) from reference to new system across the energy mesh for a specific band transition + i (initial) -> f (final) [dict]. + """ self.das_total = das_total self.jdos_new_sys_total = jdos_new_sys_total self.jdos_new_sys_if = jdos_new_sys_if diff --git a/setup.py b/setup.py index 05c25ac..ffd9ed0 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,4 @@ -"""" -PyTASER: transient absorption prediction tool. -""" +"""PyTASER: transient absorption prediction tool.""" import pathlib diff --git a/tests/conftest.py b/tests/conftest.py index 7c5846c..9617d90 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,4 @@ -""" -Setup for pytest. -""" +"""Setup for pytest.""" from pathlib import Path