Skip to content

Commit

Permalink
Merge pull request #55 from WMD-group/youngwonwoo-DFTexample
Browse files Browse the repository at this point in the history
PyTASER DFT Workflow change in MAPI example
  • Loading branch information
kavanase authored Oct 2, 2023
2 parents d0d58bc + 2efa126 commit e4dee3c
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 120 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Change log
==========

v2.1.4
~~~~~~
- Addition of MAPI example outputs download instructions to DFT example by @youngwonwoo.
- Update to `from_dict()` method for `Tas` objects by @kavanase & @LucasGVerga

v2.1.3
~~~~~~
- Change of np.arange to np.linspace to avoid e_grid arrays with sizes different from NEDOS. (see the warning on numpy.arange documentation)
Expand Down
261 changes: 146 additions & 115 deletions examples/PyTASER_DFT_Example.ipynb

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions pytaser/tas.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,9 @@ def decode_dict(subdict):

d_dec = {k: convert_to_tuple(v) for k, v in d.items()}
d_decoded = {k: decode_dict(v) for k, v in d_dec.items()}

for monty_key in ["@module", "@class"]:
if monty_key in d_decoded.keys():
d_decoded.pop(monty_key)

return cls(**d_decoded)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
long_description = pathlib.Path("README.md").read_text()
setup(
name="pytaser",
version="2.1.3",
version="2.1.4",
description="TAS prediction tool",
url="https://pytaser.readthedocs.io/en/latest/",
author="Savyasanchi Aggarwal",
Expand Down
46 changes: 45 additions & 1 deletion tests/test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from monty.serialization import dumpfn, loadfn
from pymatgen.electronic_structure.core import Spin

from pytaser import generator
from pytaser import generator, tas


def test_gaussian(datapath_gaas):
Expand Down Expand Up @@ -307,6 +307,50 @@ def test_save_and_load_tas_to_json(
os.remove("tas.json") # cleanup


def test_save_and_load_tas_to_dict(
tas_object, cdte_tas_object, cdte_vasp_tas_object
):
for tas_object in [tas_object, cdte_tas_object, cdte_vasp_tas_object]:
tas_as_dict = tas_object.as_dict()
tas_object_loaded = tas.Tas.from_dict(tas_as_dict)

# assert attributes are equal:
np.testing.assert_array_almost_equal(
tas_object.tas_total, tas_object_loaded.tas_total, decimal=1
)
for dict_attribute in [
"jdos_diff_if",
"jdos_light_if",
"jdos_dark_if",
"alpha_light_dict",
"weighted_jdos_light_if",
"weighted_jdos_dark_if",
"weighted_jdos_diff_if",
]:
if getattr(tas_object, dict_attribute) is not None:
for key, array in getattr(tas_object, dict_attribute).items():
np.testing.assert_array_almost_equal(
array, getattr(tas_object_loaded, dict_attribute)[key]
)
np.testing.assert_array_almost_equal(
tas_object.jdos_light_total, tas_object_loaded.jdos_light_total
)
np.testing.assert_array_almost_equal(
tas_object.jdos_dark_total, tas_object_loaded.jdos_dark_total
)
np.testing.assert_array_almost_equal(
tas_object.energy_mesh_ev, tas_object_loaded.energy_mesh_ev
)
assert tas_object.bandgap == tas_object_loaded.bandgap
assert tas_object.temp == tas_object_loaded.temp
assert tas_object.conc == tas_object_loaded.conc

if tas_object.alpha_dark is not None:
np.testing.assert_array_almost_equal(
tas_object.alpha_dark, tas_object_loaded.alpha_dark
)


def test_generate_tas(generated_class, light, dark, tas_object, conditions):
energy_min = 0
energy_max = 4
Expand Down
6 changes: 3 additions & 3 deletions tests/test_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ def test_ev_to_lambda():
assert round(ev_to_lambda(input_ev), 2) == 495.94


def test_lamda_to_ev():
input_lamda = 495.94
assert round(lambda_to_ev(input_lamda), 2) == 2.5
def test_lambda_to_ev():
input_lambda = 495.94
assert round(lambda_to_ev(input_lambda), 2) == 2.5


def test_cutoff_transitions(plotter_gaas):
Expand Down

0 comments on commit e4dee3c

Please sign in to comment.