Skip to content

Commit

Permalink
Linting error fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
savya10 committed Feb 13, 2024
1 parent 7751409 commit d5d0f61
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 22 deletions.
5 changes: 3 additions & 2 deletions pytaser/__init__.py
Original file line number Diff line number Diff line change
@@ -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.
"""
13 changes: 10 additions & 3 deletions pytaser/das_generator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
"""Created on Thu Aug 3 16:42:36 2023.
@author: lucasverga
Expand Down Expand Up @@ -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

Expand All @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions pytaser/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import warnings
from itertools import zip_longest
from multiprocessing import Array, Pool, cpu_count

import numpy as np
Expand Down Expand Up @@ -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(),
Expand All @@ -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())
Expand Down
51 changes: 49 additions & 2 deletions pytaser/kpoints.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand All @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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}")

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
86 changes: 80 additions & 6 deletions pytaser/tas.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,41 @@
"""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

from monty.json import MontyDecoder


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


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
""""
PyTASER: transient absorption prediction tool.
"""
"""PyTASER: transient absorption prediction tool."""


import pathlib
Expand Down
4 changes: 1 addition & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Setup for pytest.
"""
"""Setup for pytest."""

from pathlib import Path

Expand Down

0 comments on commit d5d0f61

Please sign in to comment.