From d4f0fb76986627262bb596bfe804fc42a7f216a0 Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Tue, 14 May 2024 13:42:29 -0500 Subject: [PATCH] add ruff formatter --- .ci_support/release.py | 37 +++-- .pre-commit-config.yaml | 10 ++ atomistics/calculators/__init__.py | 28 ++++ atomistics/calculators/interface.py | 2 +- atomistics/calculators/lammps/__init__.py | 17 ++ atomistics/calculators/lammps/helpers.py | 8 +- atomistics/calculators/lammps/potential.py | 10 +- atomistics/calculators/wrapper.py | 4 +- atomistics/workflows/__init__.py | 12 ++ atomistics/workflows/evcurve/fit.py | 5 +- atomistics/workflows/evcurve/thermo.py | 2 +- atomistics/workflows/evcurve/workflow.py | 1 - atomistics/workflows/phonons/units.py | 1 - setup.py | 2 +- tests/test_ase_interface/test_ase_md_mace.py | 13 +- tests/test_ase_interface/test_ase_md_matgl.py | 8 +- .../test_elastic_ase_gpaw.py | 20 ++- .../test_evcurve_ase_abinit.py | 28 ++-- .../test_evcurve_ase_gpaw.py | 30 ++-- .../test_evcurve_ase_mace.py | 36 ++-- .../test_evcurve_ase_matgl.py | 31 ++-- .../test_ase_interface/test_evcurve_ase_qe.py | 21 +-- .../test_evcurve_ase_siesta.py | 22 +-- .../test_phonons_ase_gpaw.py | 20 +-- .../test_phonons_ase_mace.py | 21 +-- .../test_phonons_ase_matgl.py | 16 +- .../test_quasiharmonic_ase_mace.py | 29 ++-- .../test_quasiharmonic_ase_matgl.py | 24 ++- tests/test_ase_md_emt.py | 14 +- tests/test_calc_stress_ase_emt.py | 6 +- tests/test_calc_stress_lammps.py | 10 +- tests/test_elastic_ase_emt.py | 4 +- tests/test_elastic_helper.py | 2 +- tests/test_elastic_lammps.py | 157 ++++++++++-------- tests/test_elastic_lammps_functional.py | 157 ++++++++++-------- tests/test_evcurve_ase_emt.py | 25 +-- tests/test_evcurve_ase_lammps.py | 30 ++-- tests/test_evcurve_eos.py | 56 ++++--- tests/test_evcurve_lammps.py | 29 ++-- tests/test_evcurve_lammps_functional.py | 21 +-- tests/test_evcurve_qe.py | 19 ++- tests/test_hessian_lammps.py | 12 +- tests/test_lammps_calculator.py | 12 +- tests/test_lammps_md.py | 45 ++--- tests/test_lammps_md_phonons.py | 8 +- tests/test_langevin_lammps.py | 6 +- ...cular_dynamics_thermal_expansion_lammps.py | 17 +- tests/test_optimize_positions_ase_emt.py | 13 +- tests/test_optimize_positions_lammps.py | 28 ++-- tests/test_phonons_ase_emt.py | 16 +- tests/test_phonons_lammps.py | 30 ++-- tests/test_phonons_lammps_functional.py | 35 ++-- tests/test_quasiharmonic_ase_emt.py | 27 +-- tests/test_quasiharmonic_lammps.py | 36 ++-- tests/test_quasiharmonic_lammps_functional.py | 49 ++++-- 55 files changed, 778 insertions(+), 544 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.ci_support/release.py b/.ci_support/release.py index a3edb012..cb90330c 100644 --- a/.ci_support/release.py +++ b/.ci_support/release.py @@ -1,12 +1,19 @@ def get_setup_version_and_pattern(setup_content): depend_lst, version_lst = [], [] for l in setup_content: - if '==' in l: - lst = l.split('[')[-1].split(']')[0].replace(' ', '').replace('"', '').replace("'", '').split(',') + if "==" in l: + lst = ( + l.split("[")[-1] + .split("]")[0] + .replace(" ", "") + .replace('"', "") + .replace("'", "") + .split(",") + ) for dep in lst: - if dep != '\n': - version_lst.append(dep.split('==')[1]) - depend_lst.append(dep.split('==')[0]) + if dep != "\n": + version_lst.append(dep.split("==")[1]) + depend_lst.append(dep.split("==")[0]) version_high_dict = {d: v for d, v in zip(depend_lst, version_lst)} return version_high_dict @@ -16,14 +23,14 @@ def get_env_version(env_content): read_flag = False depend_lst, version_lst = [], [] for l in env_content: - if 'dependencies:' in l: + if "dependencies:" in l: read_flag = True elif read_flag: - lst = l.replace('-', '').replace(' ', '').replace('\n', '').split("=") + lst = l.replace("-", "").replace(" ", "").replace("\n", "").split("=") if len(lst) == 2: depend_lst.append(lst[0]) version_lst.append(lst[1]) - return {d:v for d, v in zip(depend_lst, version_lst)} + return {d: v for d, v in zip(depend_lst, version_lst)} def update_dependencies(setup_content, version_low_dict, version_high_dict): @@ -35,27 +42,29 @@ def update_dependencies(setup_content, version_low_dict, version_high_dict): version_combo_dict[dep] = dep + "==" + ver setup_content_new = "" - pattern_dict = {d:d + "==" + v for d, v in version_high_dict.items()} + pattern_dict = {d: d + "==" + v for d, v in version_high_dict.items()} for l in setup_content: for k, v in pattern_dict.items(): if v in l: l = l.replace(v, version_combo_dict[k]) - setup_content_new +=l + setup_content_new += l return setup_content_new if __name__ == "__main__": - with open('pyproject.toml', "r") as f: + with open("pyproject.toml", "r") as f: setup_content = f.readlines() - with open('environment.yml', "r") as f: + with open("environment.yml", "r") as f: env_content = f.readlines() setup_content_new = update_dependencies( setup_content=setup_content[2:], version_low_dict=get_env_version(env_content=env_content), - version_high_dict=get_setup_version_and_pattern(setup_content=setup_content[2:]), + version_high_dict=get_setup_version_and_pattern( + setup_content=setup_content[2:] + ), ) - with open('pyproject.toml', "w") as f: + with open("pyproject.toml", "w") as f: f.writelines("".join(setup_content[:2]) + setup_content_new) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..d5aa1bf8 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,10 @@ +repos: + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.4.4 + hooks: + - id: ruff + name: ruff lint + args: ["--fix"] + files: ^atomistics/ + - id: ruff-format + name: ruff format diff --git a/atomistics/calculators/__init__.py b/atomistics/calculators/__init__.py index 77a25983..cd00fcc8 100644 --- a/atomistics/calculators/__init__.py +++ b/atomistics/calculators/__init__.py @@ -42,3 +42,31 @@ ) except ImportError: pass + + +__all__ = [ + calc_molecular_dynamics_langevin_with_ase, + calc_molecular_dynamics_npt_with_ase, + calc_molecular_dynamics_thermal_expansion_with_ase, + calc_static_with_ase, + evaluate_with_ase, + optimize_positions_with_ase, + optimize_positions_and_volume_with_ase, + evaluate_with_hessian, + calc_static_with_qe, + evaluate_with_qe, + optimize_positions_and_volume_with_qe, + calc_molecular_dynamics_thermal_expansion_with_lammps, + calc_molecular_dynamics_nph_with_lammps, + calc_molecular_dynamics_npt_with_lammps, + calc_molecular_dynamics_nvt_with_lammps, + calc_molecular_dynamics_langevin_with_lammps, + calc_static_with_lammps, + evaluate_with_lammps, + evaluate_with_lammps_library, + get_potential_dataframe, + get_potential_by_name, + optimize_positions_and_volume_with_lammps, + optimize_positions_with_lammps, + calc_molecular_dynamics_phonons_with_lammps, +] diff --git a/atomistics/calculators/interface.py b/atomistics/calculators/interface.py index 64d77b93..710ad7c1 100644 --- a/atomistics/calculators/interface.py +++ b/atomistics/calculators/interface.py @@ -1,5 +1,5 @@ from enum import Enum -from typing import NewType, Union, Any, TYPE_CHECKING +from typing import Union, Any, TYPE_CHECKING # best would be StrEnum from py3.11 import sys diff --git a/atomistics/calculators/lammps/__init__.py b/atomistics/calculators/lammps/__init__.py index bd5d2a79..54f7493b 100644 --- a/atomistics/calculators/lammps/__init__.py +++ b/atomistics/calculators/lammps/__init__.py @@ -21,3 +21,20 @@ ) except ImportError: pass + + +__all__ = [ + calc_molecular_dynamics_thermal_expansion_with_lammps, + calc_molecular_dynamics_nph_with_lammps, + calc_molecular_dynamics_npt_with_lammps, + calc_molecular_dynamics_nvt_with_lammps, + calc_molecular_dynamics_langevin_with_lammps, + calc_static_with_lammps, + evaluate_with_lammps, + evaluate_with_lammps_library, + optimize_positions_and_volume_with_lammps, + optimize_positions_with_lammps, + get_potential_dataframe, + get_potential_by_name, + calc_molecular_dynamics_phonons_with_lammps, +] diff --git a/atomistics/calculators/lammps/helpers.py b/atomistics/calculators/lammps/helpers.py index 78ce6129..ff2ad6c1 100644 --- a/atomistics/calculators/lammps/helpers.py +++ b/atomistics/calculators/lammps/helpers.py @@ -41,8 +41,8 @@ def lammps_run( lmp.interactive_lib_command(c) if input_template is not None: - for l in input_template.split("\n"): - lmp.interactive_lib_command(l) + for line in input_template.split("\n"): + lmp.interactive_lib_command(line) return lmp @@ -131,8 +131,8 @@ def lammps_thermal_expansion_loop( Pstop=Pstop, Pdamp=Pdamp, ) - for l in run_str_rendered.split("\n"): - lmp_instance.interactive_lib_command(l) + for line in run_str_rendered.split("\n"): + lmp_instance.interactive_lib_command(line) volume_md_lst.append(lmp_instance.interactive_volume_getter()) temperature_md_lst.append(lmp_instance.interactive_temperatures_getter()) lammps_shutdown(lmp_instance=lmp_instance, close_instance=lmp is None) diff --git a/atomistics/calculators/lammps/potential.py b/atomistics/calculators/lammps/potential.py index f54c8201..7312b23e 100644 --- a/atomistics/calculators/lammps/potential.py +++ b/atomistics/calculators/lammps/potential.py @@ -290,18 +290,18 @@ def update_potential_paths( ] potential_dict = {os.path.basename(f): f for f in potential_file_path_lst} potential_commands = [] - for l in row.Config: - l = l.replace("\n", "") + for line in row.Config: + line = line.replace("\n", "") for key, value in potential_dict.items(): - l = l.replace(key, value) - potential_commands.append(l) + line = line.replace(key, value) + potential_commands.append(line) config_lst.append(potential_commands) df_pot["Config"] = config_lst return df_pot def get_resource_path_from_conda( - env_variables: tuple[str] = ("CONDA_PREFIX", "CONDA_DIR") + env_variables: tuple[str] = ("CONDA_PREFIX", "CONDA_DIR"), ) -> str: env = os.environ for conda_var in env_variables: diff --git a/atomistics/calculators/wrapper.py b/atomistics/calculators/wrapper.py index fe48a179..64663994 100644 --- a/atomistics/calculators/wrapper.py +++ b/atomistics/calculators/wrapper.py @@ -5,7 +5,7 @@ from __future__ import annotations -from typing import NewType, Union, Any, TYPE_CHECKING +from typing import TYPE_CHECKING from atomistics.calculators.interface import TaskEnum, TaskOutputEnum @@ -13,9 +13,7 @@ from ase import Atoms from atomistics.calculators.interface import ( TaskName, - TaskSpec, TaskDict, - TaskResults, ResultsDict, SimpleEvaluator, ) diff --git a/atomistics/workflows/__init__.py b/atomistics/workflows/__init__.py index 4b3eb053..706d0594 100644 --- a/atomistics/workflows/__init__.py +++ b/atomistics/workflows/__init__.py @@ -14,3 +14,15 @@ from atomistics.workflows.quasiharmonic import QuasiHarmonicWorkflow except ImportError: pass + + +__all__ = [ + ElasticMatrixWorkflow, + EnergyVolumeCurveWorkflow, + LangevinWorkflow, + calc_molecular_dynamics_thermal_expansion, + optimize_positions, + optimize_positions_and_volume, + PhonopyWorkflow, + QuasiHarmonicWorkflow, +] diff --git a/atomistics/workflows/evcurve/fit.py b/atomistics/workflows/evcurve/fit.py index 78f7967d..002fc936 100644 --- a/atomistics/workflows/evcurve/fit.py +++ b/atomistics/workflows/evcurve/fit.py @@ -135,7 +135,8 @@ def fit_leastsq( """ # http://stackoverflow.com/questions/14581358/getting-standard-errors-on-fitted-parameters-using-the-optimize-leastsq-method-i - errfunc = lambda p, x, y, fittype: fitfunction(p, x, fittype) - y + def errfunc(p, x, y, fittype): + return fitfunction(p, x, fittype) - y pfit, pcov, infodict, errmsg, success = scipy.optimize.leastsq( errfunc, p0, args=(datax, datay, fittype), full_output=1, epsfcn=0.0001 @@ -153,7 +154,7 @@ def fit_leastsq( for i in range(len(pfit)): try: error.append(np.absolute(pcov[i][i]) ** 0.5) - except: + except TypeError: error.append(0.00) pfit_leastsq = pfit perr_leastsq = np.array(error) diff --git a/atomistics/workflows/evcurve/thermo.py b/atomistics/workflows/evcurve/thermo.py index 3c60ce25..aaa085e4 100644 --- a/atomistics/workflows/evcurve/thermo.py +++ b/atomistics/workflows/evcurve/thermo.py @@ -269,7 +269,7 @@ def get_minimum_energy_path(self, pressure: np.ndarray = None) -> np.ndarray: """ if pressure is not None: - raise NotImplemented() + raise NotImplementedError() v_min_lst = [] for c in self._coeff.T: v_min = np.roots(np.polyder(c, 1)) diff --git a/atomistics/workflows/evcurve/workflow.py b/atomistics/workflows/evcurve/workflow.py index 38ae8568..f8b856d5 100644 --- a/atomistics/workflows/evcurve/workflow.py +++ b/atomistics/workflows/evcurve/workflow.py @@ -9,7 +9,6 @@ OutputThermodynamic, ) from atomistics.workflows.evcurve.helper import ( - get_volume_lst, generate_structures_helper, analyse_structures_helper, ) diff --git a/atomistics/workflows/phonons/units.py b/atomistics/workflows/phonons/units.py index ea1baca5..7f5b8359 100644 --- a/atomistics/workflows/phonons/units.py +++ b/atomistics/workflows/phonons/units.py @@ -1,5 +1,4 @@ import scipy.constants -from phonopy.units import VaspToTHz, THzToEv, EvTokJmol kJ_mol_to_eV = 1000 / scipy.constants.Avogadro / scipy.constants.electron_volt kb = scipy.constants.physical_constants["Boltzmann constant in eV/K"][0] diff --git a/setup.py b/setup.py index edb08a34..fcbb31fa 100644 --- a/setup.py +++ b/setup.py @@ -5,4 +5,4 @@ setup( version=versioneer.get_version(), cmdclass=versioneer.get_cmdclass(), -) \ No newline at end of file +) diff --git a/tests/test_ase_interface/test_ase_md_mace.py b/tests/test_ase_interface/test_ase_md_mace.py index e42fda81..93c0ff63 100644 --- a/tests/test_ase_interface/test_ase_md_mace.py +++ b/tests/test_ase_interface/test_ase_md_mace.py @@ -19,10 +19,7 @@ class TestASEMD(unittest.TestCase): def test_ase_langevin(self): structure = bulk("Al", cubic=True).repeat([2, 2, 2]) ase_calculator = mace_mp( - model="medium", - dispersion=False, - default_dtype="float32", - device='cpu' + model="medium", dispersion=False, default_dtype="float32", device="cpu" ) result_dict = calc_molecular_dynamics_langevin_with_ase( structure=structure, @@ -37,9 +34,9 @@ def test_ase_langevin(self): self.assertEqual(result_dict["velocities"].shape, (10, 32, 3)) self.assertEqual(result_dict["cell"].shape, (10, 3, 3)) self.assertEqual(result_dict["forces"].shape, (10, 32, 3)) - self.assertEqual(result_dict["temperature"].shape, (10, )) - self.assertEqual(result_dict["energy_pot"].shape, (10, )) - self.assertEqual(result_dict["energy_tot"].shape, (10, )) + self.assertEqual(result_dict["temperature"].shape, (10,)) + self.assertEqual(result_dict["energy_pot"].shape, (10,)) + self.assertEqual(result_dict["energy_tot"].shape, (10,)) self.assertEqual(result_dict["pressure"].shape, (10, 3, 3)) self.assertTrue(result_dict["temperature"][-1] > 25) - self.assertTrue(result_dict["temperature"][-1] < 75) \ No newline at end of file + self.assertTrue(result_dict["temperature"][-1] < 75) diff --git a/tests/test_ase_interface/test_ase_md_matgl.py b/tests/test_ase_interface/test_ase_md_matgl.py index 054b22b2..46c9dacb 100644 --- a/tests/test_ase_interface/test_ase_md_matgl.py +++ b/tests/test_ase_interface/test_ase_md_matgl.py @@ -33,9 +33,9 @@ def test_ase_langevin(self): self.assertEqual(result_dict["velocities"].shape, (10, 32, 3)) self.assertEqual(result_dict["cell"].shape, (10, 3, 3)) self.assertEqual(result_dict["forces"].shape, (10, 32, 3)) - self.assertEqual(result_dict["temperature"].shape, (10, )) - self.assertEqual(result_dict["energy_pot"].shape, (10, )) - self.assertEqual(result_dict["energy_tot"].shape, (10, )) + self.assertEqual(result_dict["temperature"].shape, (10,)) + self.assertEqual(result_dict["energy_pot"].shape, (10,)) + self.assertEqual(result_dict["energy_tot"].shape, (10,)) self.assertEqual(result_dict["pressure"].shape, (10, 3, 3)) self.assertTrue(result_dict["temperature"][-1] > 25) - self.assertTrue(result_dict["temperature"][-1] < 75) \ No newline at end of file + self.assertTrue(result_dict["temperature"][-1] < 75) diff --git a/tests/test_ase_interface/test_elastic_ase_gpaw.py b/tests/test_ase_interface/test_elastic_ase_gpaw.py index dd6d6842..cc89644a 100644 --- a/tests/test_ase_interface/test_elastic_ase_gpaw.py +++ b/tests/test_ase_interface/test_elastic_ase_gpaw.py @@ -23,18 +23,20 @@ def test_calc_elastic(self): num_of_point=5, eps_range=0.05, sqrt_eta=True, - fit_order=2 + fit_order=2, ) task_dict = workflow.generate_structures() result_dict = evaluate_with_ase( task_dict=task_dict, - ase_calculator=GPAW( - xc="PBE", - mode=PW(300), - kpts=(3, 3, 3) - ) + ase_calculator=GPAW(xc="PBE", mode=PW(300), kpts=(3, 3, 3)), ) elastic_dict = workflow.analyse_structures(output_dict=result_dict) - self.assertTrue(np.isclose(elastic_dict["elastic_matrix"][0, 0], 125.66807354, atol=1e-04)) - self.assertTrue(np.isclose(elastic_dict["elastic_matrix"][0, 1], 68.41418321, atol=1e-04)) - self.assertTrue(np.isclose(elastic_dict["elastic_matrix"][3, 3], 99.29916329, atol=1e-04)) + self.assertTrue( + np.isclose(elastic_dict["elastic_matrix"][0, 0], 125.66807354, atol=1e-04) + ) + self.assertTrue( + np.isclose(elastic_dict["elastic_matrix"][0, 1], 68.41418321, atol=1e-04) + ) + self.assertTrue( + np.isclose(elastic_dict["elastic_matrix"][3, 3], 99.29916329, atol=1e-04) + ) diff --git a/tests/test_ase_interface/test_evcurve_ase_abinit.py b/tests/test_ase_interface/test_evcurve_ase_abinit.py index 2cee3879..654de35f 100644 --- a/tests/test_ase_interface/test_evcurve_ase_abinit.py +++ b/tests/test_ase_interface/test_evcurve_ase_abinit.py @@ -17,12 +17,12 @@ def validate_fitdict(fit_dict): lst = [ - fit_dict['bulkmodul_eq'] > 120, - fit_dict['bulkmodul_eq'] < 130, - fit_dict['energy_eq'] > -227, - fit_dict['energy_eq'] < -226, - fit_dict['volume_eq'] > 66, - fit_dict['volume_eq'] < 67, + fit_dict["bulkmodul_eq"] > 120, + fit_dict["bulkmodul_eq"] < 130, + fit_dict["energy_eq"] > -227, + fit_dict["energy_eq"] < -226, + fit_dict["volume_eq"] > 66, + fit_dict["volume_eq"] < 67, ] if not all(lst): print(fit_dict) @@ -37,30 +37,32 @@ def test_calc_evcurve(self): workflow = EnergyVolumeCurveWorkflow( structure=bulk("Al", a=4.045, cubic=True), num_points=11, - fit_type='polynomial', + fit_type="polynomial", fit_order=3, vol_range=0.05, - axes=('x', 'y', 'z'), + axes=("x", "y", "z"), strains=None, ) task_dict = workflow.generate_structures() result_dict = evaluate_with_ase( task_dict=task_dict, ase_calculator=Abinit( - label='abinit_evcurve', + label="abinit_evcurve", nbands=32, ecut=10 * Ry, kpts=(3, 3, 3), toldfe=1.0e-2, v8_legacy_format=False, - ) + ), ) fit_dict = workflow.analyse_structures(output_dict=result_dict) thermal_properties_dict = workflow.get_thermal_properties( - temperatures=[100, 1000], - output_keys=["temperatures", "volumes"] + temperatures=[100, 1000], output_keys=["temperatures", "volumes"] + ) + temperatures_ev, volumes_ev = ( + thermal_properties_dict["temperatures"], + thermal_properties_dict["volumes"], ) - temperatures_ev, volumes_ev = thermal_properties_dict["temperatures"], thermal_properties_dict["volumes"] self.assertTrue(all(validate_fitdict(fit_dict=fit_dict))) self.assertEqual(len(temperatures_ev), 2) self.assertEqual(len(volumes_ev), 2) diff --git a/tests/test_ase_interface/test_evcurve_ase_gpaw.py b/tests/test_ase_interface/test_evcurve_ase_gpaw.py index f124a055..4b3b49d5 100644 --- a/tests/test_ase_interface/test_evcurve_ase_gpaw.py +++ b/tests/test_ase_interface/test_evcurve_ase_gpaw.py @@ -22,30 +22,34 @@ def test_calc_evcurve(self): workflow = EnergyVolumeCurveWorkflow( structure=bulk("Al", a=4.05, cubic=True), num_points=11, - fit_type='polynomial', + fit_type="polynomial", fit_order=3, vol_range=0.05, - axes=('x', 'y', 'z'), + axes=("x", "y", "z"), strains=None, ) task_dict = workflow.generate_structures() result_dict = evaluate_with_ase( task_dict=task_dict, - ase_calculator=GPAW( - xc="PBE", - mode=PW(300), - kpts=(3, 3, 3) - ) + ase_calculator=GPAW(xc="PBE", mode=PW(300), kpts=(3, 3, 3)), ) fit_dict = workflow.analyse_structures(output_dict=result_dict) thermal_properties_dict = workflow.get_thermal_properties( - temperatures=[100, 1000], - output_keys=["temperatures", "volumes"] + temperatures=[100, 1000], output_keys=["temperatures", "volumes"] + ) + temperatures_ev, volumes_ev = ( + thermal_properties_dict["temperatures"], + thermal_properties_dict["volumes"], + ) + self.assertTrue( + np.isclose(fit_dict["volume_eq"], 66.44252286131331, atol=1e-04) + ) + self.assertTrue( + np.isclose(fit_dict["bulkmodul_eq"], 72.38919826652857, atol=1e-04) + ) + self.assertTrue( + np.isclose(fit_dict["b_prime_eq"], 4.453836551712821, atol=1e-04) ) - temperatures_ev, volumes_ev = thermal_properties_dict["temperatures"], thermal_properties_dict["volumes"] - self.assertTrue(np.isclose(fit_dict['volume_eq'], 66.44252286131331, atol=1e-04)) - self.assertTrue(np.isclose(fit_dict['bulkmodul_eq'], 72.38919826652857, atol=1e-04)) - self.assertTrue(np.isclose(fit_dict['b_prime_eq'], 4.453836551712821, atol=1e-04)) self.assertEqual(len(temperatures_ev), 2) self.assertEqual(len(volumes_ev), 2) self.assertTrue(volumes_ev[0] < volumes_ev[-1]) diff --git a/tests/test_ase_interface/test_evcurve_ase_mace.py b/tests/test_ase_interface/test_evcurve_ase_mace.py index 46d085ad..cbf3b131 100644 --- a/tests/test_ase_interface/test_evcurve_ase_mace.py +++ b/tests/test_ase_interface/test_evcurve_ase_mace.py @@ -4,7 +4,10 @@ import unittest from atomistics.calculators import evaluate_with_ase -from atomistics.workflows import optimize_positions_and_volume, EnergyVolumeCurveWorkflow +from atomistics.workflows import ( + optimize_positions_and_volume, + EnergyVolumeCurveWorkflow, +) try: @@ -22,25 +25,22 @@ class TestEvCurve(unittest.TestCase): def test_calc_evcurve(self): structure = bulk("Al", cubic=True) ase_calculator = mace_mp( - model="medium", - dispersion=False, - default_dtype="float32", - device='cpu' + model="medium", dispersion=False, default_dtype="float32", device="cpu" ) task_dict = optimize_positions_and_volume(structure=structure) result_dict = evaluate_with_ase( task_dict=task_dict, ase_calculator=ase_calculator, ase_optimizer=LBFGS, - ase_optimizer_kwargs={"fmax": 0.001} + ase_optimizer_kwargs={"fmax": 0.001}, ) workflow = EnergyVolumeCurveWorkflow( structure=result_dict["structure_with_optimized_positions_and_volume"], num_points=11, - fit_type='polynomial', + fit_type="polynomial", fit_order=3, vol_range=0.05, - axes=('x', 'y', 'z'), + axes=("x", "y", "z"), strains=None, ) task_dict = workflow.generate_structures() @@ -50,13 +50,21 @@ def test_calc_evcurve(self): ) fit_dict = workflow.analyse_structures(output_dict=result_dict) thermal_properties_dict = workflow.get_thermal_properties( - temperatures=[100, 1000], - output_keys=["temperatures", "volumes"] + temperatures=[100, 1000], output_keys=["temperatures", "volumes"] + ) + temperatures_ev, volumes_ev = ( + thermal_properties_dict["temperatures"], + thermal_properties_dict["volumes"], + ) + self.assertTrue( + np.isclose(fit_dict["volume_eq"], 66.94655948308437, atol=1e-04) + ) + self.assertTrue( + np.isclose(fit_dict["bulkmodul_eq"], 64.40241949760645, atol=1e-02) + ) + self.assertTrue( + np.isclose(fit_dict["b_prime_eq"], 4.460574503792641, atol=1e-02) ) - temperatures_ev, volumes_ev = thermal_properties_dict["temperatures"], thermal_properties_dict["volumes"] - self.assertTrue(np.isclose(fit_dict['volume_eq'], 66.94655948308437, atol=1e-04)) - self.assertTrue(np.isclose(fit_dict['bulkmodul_eq'], 64.40241949760645, atol=1e-02)) - self.assertTrue(np.isclose(fit_dict['b_prime_eq'], 4.460574503792641, atol=1e-02)) self.assertEqual(len(temperatures_ev), 2) self.assertEqual(len(volumes_ev), 2) self.assertTrue(volumes_ev[0] < volumes_ev[-1]) diff --git a/tests/test_ase_interface/test_evcurve_ase_matgl.py b/tests/test_ase_interface/test_evcurve_ase_matgl.py index 12947c0f..b94d756b 100644 --- a/tests/test_ase_interface/test_evcurve_ase_matgl.py +++ b/tests/test_ase_interface/test_evcurve_ase_matgl.py @@ -4,7 +4,10 @@ import unittest from atomistics.calculators import evaluate_with_ase -from atomistics.workflows import optimize_positions_and_volume, EnergyVolumeCurveWorkflow +from atomistics.workflows import ( + optimize_positions_and_volume, + EnergyVolumeCurveWorkflow, +) try: @@ -28,15 +31,15 @@ def test_calc_evcurve(self): task_dict=task_dict, ase_calculator=ase_calculator, ase_optimizer=LBFGS, - ase_optimizer_kwargs={"fmax": 0.001} + ase_optimizer_kwargs={"fmax": 0.001}, ) workflow = EnergyVolumeCurveWorkflow( structure=result_dict["structure_with_optimized_positions_and_volume"], num_points=11, - fit_type='polynomial', + fit_type="polynomial", fit_order=3, vol_range=0.05, - axes=('x', 'y', 'z'), + axes=("x", "y", "z"), strains=None, ) task_dict = workflow.generate_structures() @@ -46,13 +49,21 @@ def test_calc_evcurve(self): ) fit_dict = workflow.analyse_structures(output_dict=result_dict) thermal_properties_dict = workflow.get_thermal_properties( - temperatures=[100, 1000], - output_keys=["temperatures", "volumes"] + temperatures=[100, 1000], output_keys=["temperatures", "volumes"] + ) + temperatures_ev, volumes_ev = ( + thermal_properties_dict["temperatures"], + thermal_properties_dict["volumes"], + ) + self.assertTrue( + np.isclose(fit_dict["volume_eq"], 66.56048874824006, atol=1e-04) + ) + self.assertTrue( + np.isclose(fit_dict["bulkmodul_eq"], 50.96266448851179, atol=1e-02) + ) + self.assertTrue( + np.isclose(fit_dict["b_prime_eq"], 4.674534962000779, atol=1e-02) ) - temperatures_ev, volumes_ev = thermal_properties_dict["temperatures"], thermal_properties_dict["volumes"] - self.assertTrue(np.isclose(fit_dict['volume_eq'], 66.56048874824006, atol=1e-04)) - self.assertTrue(np.isclose(fit_dict['bulkmodul_eq'], 50.96266448851179, atol=1e-02)) - self.assertTrue(np.isclose(fit_dict['b_prime_eq'], 4.674534962000779, atol=1e-02)) self.assertEqual(len(temperatures_ev), 2) self.assertEqual(len(volumes_ev), 2) self.assertTrue(volumes_ev[0] < volumes_ev[-1]) diff --git a/tests/test_ase_interface/test_evcurve_ase_qe.py b/tests/test_ase_interface/test_evcurve_ase_qe.py index 67f1af61..fc8ac26f 100644 --- a/tests/test_ase_interface/test_evcurve_ase_qe.py +++ b/tests/test_ase_interface/test_evcurve_ase_qe.py @@ -17,12 +17,12 @@ def validate_fitdict(fit_dict): lst = [ - fit_dict['bulkmodul_eq'] > 50, - fit_dict['bulkmodul_eq'] < 80, - fit_dict['energy_eq'] > -2148.2, - fit_dict['energy_eq'] < -2148.1, - fit_dict['volume_eq'] > 70, - fit_dict['volume_eq'] < 72, + fit_dict["bulkmodul_eq"] > 50, + fit_dict["bulkmodul_eq"] < 80, + fit_dict["energy_eq"] > -2148.2, + fit_dict["energy_eq"] < -2148.1, + fit_dict["volume_eq"] > 70, + fit_dict["volume_eq"] < 72, ] if not all(lst): print(fit_dict) @@ -30,7 +30,8 @@ def validate_fitdict(fit_dict): @unittest.skipIf( - skip_quantum_espresso_test, "quantum_espresso is not installed, so the quantum_espresso tests are skipped." + skip_quantum_espresso_test, + "quantum_espresso is not installed, so the quantum_espresso tests are skipped.", ) class TestEvCurve(unittest.TestCase): def test_calc_evcurve(self): @@ -38,10 +39,10 @@ def test_calc_evcurve(self): workflow = EnergyVolumeCurveWorkflow( structure=bulk("Al", a=4.15, cubic=True), num_points=7, - fit_type='polynomial', + fit_type="polynomial", fit_order=3, vol_range=0.05, - axes=('x', 'y', 'z'), + axes=("x", "y", "z"), strains=None, ) task_dict = workflow.generate_structures() @@ -52,7 +53,7 @@ def test_calc_evcurve(self): tstress=True, tprnfor=True, kpts=(3, 3, 3), - ) + ), ) fit_dict = workflow.analyse_structures(output_dict=result_dict) self.assertTrue(all(validate_fitdict(fit_dict=fit_dict))) diff --git a/tests/test_ase_interface/test_evcurve_ase_siesta.py b/tests/test_ase_interface/test_evcurve_ase_siesta.py index 95d5f5ad..8a9c613d 100644 --- a/tests/test_ase_interface/test_evcurve_ase_siesta.py +++ b/tests/test_ase_interface/test_evcurve_ase_siesta.py @@ -19,14 +19,14 @@ def validate_fitdict(fit_dict): lst = [ - fit_dict['b_prime_eq'] > 14.0, - fit_dict['b_prime_eq'] < 15.0, - fit_dict['bulkmodul_eq'] > 42, - fit_dict['bulkmodul_eq'] < 44, - fit_dict['energy_eq'] > -281.0, - fit_dict['energy_eq'] < -280.9, - fit_dict['volume_eq'] > 74, - fit_dict['volume_eq'] < 75, + fit_dict["b_prime_eq"] > 14.0, + fit_dict["b_prime_eq"] < 15.0, + fit_dict["bulkmodul_eq"] > 42, + fit_dict["bulkmodul_eq"] < 44, + fit_dict["energy_eq"] > -281.0, + fit_dict["energy_eq"] < -280.9, + fit_dict["volume_eq"] > 74, + fit_dict["volume_eq"] < 75, ] if not all(lst): print(fit_dict) @@ -41,10 +41,10 @@ def test_calc_evcurve(self): workflow = EnergyVolumeCurveWorkflow( structure=bulk("Al", a=4.15, cubic=True), num_points=11, - fit_type='polynomial', + fit_type="polynomial", fit_order=3, vol_range=0.05, - axes=('x', 'y', 'z'), + axes=("x", "y", "z"), strains=None, ) task_dict = workflow.generate_structures() @@ -60,7 +60,7 @@ def test_calc_evcurve(self): fdf_arguments={"DM.MixingWeight": 0.1, "MaxSCFIterations": 100}, pseudo_path=os.path.abspath("tests/static/siesta"), pseudo_qualifier="", - ) + ), ) fit_dict = workflow.analyse_structures(output_dict=result_dict) self.assertTrue(all(validate_fitdict(fit_dict=fit_dict))) diff --git a/tests/test_ase_interface/test_phonons_ase_gpaw.py b/tests/test_ase_interface/test_phonons_ase_gpaw.py index 4372b507..81695e53 100644 --- a/tests/test_ase_interface/test_phonons_ase_gpaw.py +++ b/tests/test_ase_interface/test_phonons_ase_gpaw.py @@ -30,19 +30,15 @@ def test_calc_phonons(self): task_dict = workflow.generate_structures() result_dict = evaluate_with_ase( task_dict=task_dict, - ase_calculator=GPAW( - xc="PBE", - mode=PW(300), - kpts=(3, 3, 3) - ) + ase_calculator=GPAW(xc="PBE", mode=PW(300), kpts=(3, 3, 3)), ) phonopy_dict = workflow.analyse_structures(output_dict=result_dict) mesh_dict, dos_dict = phonopy_dict["mesh_dict"], phonopy_dict["total_dos_dict"] self.assertEqual((324, 324), workflow.get_hesse_matrix().shape) - self.assertTrue('qpoints' in mesh_dict.keys()) - self.assertTrue('weights' in mesh_dict.keys()) - self.assertTrue('frequencies' in mesh_dict.keys()) - self.assertTrue('eigenvectors' in mesh_dict.keys()) - self.assertTrue('group_velocities' in mesh_dict.keys()) - self.assertTrue('frequency_points' in dos_dict.keys()) - self.assertTrue('total_dos' in dos_dict.keys()) + self.assertTrue("qpoints" in mesh_dict.keys()) + self.assertTrue("weights" in mesh_dict.keys()) + self.assertTrue("frequencies" in mesh_dict.keys()) + self.assertTrue("eigenvectors" in mesh_dict.keys()) + self.assertTrue("group_velocities" in mesh_dict.keys()) + self.assertTrue("frequency_points" in dos_dict.keys()) + self.assertTrue("total_dos" in dos_dict.keys()) diff --git a/tests/test_ase_interface/test_phonons_ase_mace.py b/tests/test_ase_interface/test_phonons_ase_mace.py index bc66187f..fbe0815e 100644 --- a/tests/test_ase_interface/test_phonons_ase_mace.py +++ b/tests/test_ase_interface/test_phonons_ase_mace.py @@ -22,17 +22,14 @@ class TestPhonons(unittest.TestCase): def test_calc_phonons(self): structure = bulk("Al", cubic=True) ase_calculator = mace_mp( - model="medium", - dispersion=False, - default_dtype="float32", - device='cpu' + model="medium", dispersion=False, default_dtype="float32", device="cpu" ) task_dict = optimize_positions_and_volume(structure=structure) result_dict = evaluate_with_ase( task_dict=task_dict, ase_calculator=ase_calculator, ase_optimizer=LBFGS, - ase_optimizer_kwargs={"fmax": 0.001} + ase_optimizer_kwargs={"fmax": 0.001}, ) workflow = PhonopyWorkflow( structure=result_dict["structure_with_optimized_positions_and_volume"], @@ -51,10 +48,10 @@ def test_calc_phonons(self): phonopy_dict = workflow.analyse_structures(output_dict=result_dict) mesh_dict, dos_dict = phonopy_dict["mesh_dict"], phonopy_dict["total_dos_dict"] self.assertEqual((324, 324), workflow.get_hesse_matrix().shape) - self.assertTrue('qpoints' in mesh_dict.keys()) - self.assertTrue('weights' in mesh_dict.keys()) - self.assertTrue('frequencies' in mesh_dict.keys()) - self.assertTrue('eigenvectors' in mesh_dict.keys()) - self.assertTrue('group_velocities' in mesh_dict.keys()) - self.assertTrue('frequency_points' in dos_dict.keys()) - self.assertTrue('total_dos' in dos_dict.keys()) + self.assertTrue("qpoints" in mesh_dict.keys()) + self.assertTrue("weights" in mesh_dict.keys()) + self.assertTrue("frequencies" in mesh_dict.keys()) + self.assertTrue("eigenvectors" in mesh_dict.keys()) + self.assertTrue("group_velocities" in mesh_dict.keys()) + self.assertTrue("frequency_points" in dos_dict.keys()) + self.assertTrue("total_dos" in dos_dict.keys()) diff --git a/tests/test_ase_interface/test_phonons_ase_matgl.py b/tests/test_ase_interface/test_phonons_ase_matgl.py index 5950cd54..3d9f7101 100644 --- a/tests/test_ase_interface/test_phonons_ase_matgl.py +++ b/tests/test_ase_interface/test_phonons_ase_matgl.py @@ -28,7 +28,7 @@ def test_calc_phonons(self): task_dict=task_dict, ase_calculator=ase_calculator, ase_optimizer=LBFGS, - ase_optimizer_kwargs={"fmax": 0.001} + ase_optimizer_kwargs={"fmax": 0.001}, ) workflow = PhonopyWorkflow( structure=result_dict["structure_with_optimized_positions_and_volume"], @@ -47,10 +47,10 @@ def test_calc_phonons(self): phonopy_dict = workflow.analyse_structures(output_dict=result_dict) mesh_dict, dos_dict = phonopy_dict["mesh_dict"], phonopy_dict["total_dos_dict"] self.assertEqual((324, 324), workflow.get_hesse_matrix().shape) - self.assertTrue('qpoints' in mesh_dict.keys()) - self.assertTrue('weights' in mesh_dict.keys()) - self.assertTrue('frequencies' in mesh_dict.keys()) - self.assertTrue('eigenvectors' in mesh_dict.keys()) - self.assertTrue('group_velocities' in mesh_dict.keys()) - self.assertTrue('frequency_points' in dos_dict.keys()) - self.assertTrue('total_dos' in dos_dict.keys()) + self.assertTrue("qpoints" in mesh_dict.keys()) + self.assertTrue("weights" in mesh_dict.keys()) + self.assertTrue("frequencies" in mesh_dict.keys()) + self.assertTrue("eigenvectors" in mesh_dict.keys()) + self.assertTrue("group_velocities" in mesh_dict.keys()) + self.assertTrue("frequency_points" in dos_dict.keys()) + self.assertTrue("total_dos" in dos_dict.keys()) diff --git a/tests/test_ase_interface/test_quasiharmonic_ase_mace.py b/tests/test_ase_interface/test_quasiharmonic_ase_mace.py index 16d2ed42..ba1a3748 100644 --- a/tests/test_ase_interface/test_quasiharmonic_ase_mace.py +++ b/tests/test_ase_interface/test_quasiharmonic_ase_mace.py @@ -22,17 +22,14 @@ class TestPhonons(unittest.TestCase): def test_calc_phonons(self): structure = bulk("Al", cubic=True) ase_calculator = mace_mp( - model="medium", - dispersion=False, - default_dtype="float32", - device='cpu' + model="medium", dispersion=False, default_dtype="float32", device="cpu" ) task_dict = optimize_positions_and_volume(structure=structure) result_dict = evaluate_with_ase( task_dict=task_dict, ase_calculator=ase_calculator, ase_optimizer=LBFGS, - ase_optimizer_kwargs={"fmax": 0.001} + ase_optimizer_kwargs={"fmax": 0.001}, ) workflow = QuasiHarmonicWorkflow( structure=result_dict["structure_with_optimized_positions_and_volume"], @@ -50,20 +47,30 @@ def test_calc_phonons(self): task_dict=task_dict, ase_calculator=ase_calculator, ) - eng_internal_dict, phonopy_collect_dict = workflow.analyse_structures(output_dict=result_dict) - tp_collect_dict = workflow.get_thermal_properties(t_min=1, t_max=501, t_step=50, temperatures=None) + eng_internal_dict, phonopy_collect_dict = workflow.analyse_structures( + output_dict=result_dict + ) + tp_collect_dict = workflow.get_thermal_properties( + t_min=1, t_max=501, t_step=50, temperatures=None + ) thermal_properties_dict = workflow.get_thermal_properties( temperatures=[100, 500], output_keys=["temperatures", "volumes"], - quantum_mechanical=True + quantum_mechanical=True, + ) + temperatures_qh_qm, volumes_qh_qm = ( + thermal_properties_dict["temperatures"], + thermal_properties_dict["volumes"], ) - temperatures_qh_qm, volumes_qh_qm = thermal_properties_dict["temperatures"], thermal_properties_dict["volumes"] thermal_properties_dict = workflow.get_thermal_properties( temperatures=[100, 500], output_keys=["temperatures", "volumes"], - quantum_mechanical=False + quantum_mechanical=False, + ) + temperatures_qh_cl, volumes_qh_cl = ( + thermal_properties_dict["temperatures"], + thermal_properties_dict["volumes"], ) - temperatures_qh_cl, volumes_qh_cl = thermal_properties_dict["temperatures"], thermal_properties_dict["volumes"] self.assertEqual(len(eng_internal_dict.keys()), 11) self.assertEqual(len(tp_collect_dict.keys()), 5) self.assertEqual(len(temperatures_qh_qm), 2) diff --git a/tests/test_ase_interface/test_quasiharmonic_ase_matgl.py b/tests/test_ase_interface/test_quasiharmonic_ase_matgl.py index 910cf551..d319096c 100644 --- a/tests/test_ase_interface/test_quasiharmonic_ase_matgl.py +++ b/tests/test_ase_interface/test_quasiharmonic_ase_matgl.py @@ -28,7 +28,7 @@ def test_calc_phonons(self): task_dict=task_dict, ase_calculator=ase_calculator, ase_optimizer=LBFGS, - ase_optimizer_kwargs={"fmax": 0.001} + ase_optimizer_kwargs={"fmax": 0.001}, ) workflow = QuasiHarmonicWorkflow( structure=result_dict["structure_with_optimized_positions_and_volume"], @@ -46,20 +46,30 @@ def test_calc_phonons(self): task_dict=task_dict, ase_calculator=ase_calculator, ) - eng_internal_dict, phonopy_collect_dict = workflow.analyse_structures(output_dict=result_dict) - tp_collect_dict = workflow.get_thermal_properties(t_min=1, t_max=501, t_step=50, temperatures=None) + eng_internal_dict, phonopy_collect_dict = workflow.analyse_structures( + output_dict=result_dict + ) + tp_collect_dict = workflow.get_thermal_properties( + t_min=1, t_max=501, t_step=50, temperatures=None + ) thermal_properties_dict = workflow.get_thermal_properties( temperatures=[100, 500], output_keys=["temperatures", "volumes"], - quantum_mechanical=True + quantum_mechanical=True, + ) + temperatures_qh_qm, volumes_qh_qm = ( + thermal_properties_dict["temperatures"], + thermal_properties_dict["volumes"], ) - temperatures_qh_qm, volumes_qh_qm = thermal_properties_dict["temperatures"], thermal_properties_dict["volumes"] thermal_properties_dict = workflow.get_thermal_properties( temperatures=[100, 500], output_keys=["temperatures", "volumes"], - quantum_mechanical=False + quantum_mechanical=False, + ) + temperatures_qh_cl, volumes_qh_cl = ( + thermal_properties_dict["temperatures"], + thermal_properties_dict["volumes"], ) - temperatures_qh_cl, volumes_qh_cl = thermal_properties_dict["temperatures"], thermal_properties_dict["volumes"] self.assertEqual(len(eng_internal_dict.keys()), 11) self.assertEqual(len(tp_collect_dict.keys()), 5) self.assertEqual(len(temperatures_qh_qm), 2) diff --git a/tests/test_ase_md_emt.py b/tests/test_ase_md_emt.py index f4d65f74..d851eb78 100644 --- a/tests/test_ase_md_emt.py +++ b/tests/test_ase_md_emt.py @@ -29,9 +29,9 @@ def test_ase_langevin(self): self.assertEqual(result_dict["velocities"].shape, (10, 32, 3)) self.assertEqual(result_dict["cell"].shape, (10, 3, 3)) self.assertEqual(result_dict["forces"].shape, (10, 32, 3)) - self.assertEqual(result_dict["temperature"].shape, (10, )) - self.assertEqual(result_dict["energy_pot"].shape, (10, )) - self.assertEqual(result_dict["energy_tot"].shape, (10, )) + self.assertEqual(result_dict["temperature"].shape, (10,)) + self.assertEqual(result_dict["energy_pot"].shape, (10,)) + self.assertEqual(result_dict["energy_tot"].shape, (10,)) self.assertEqual(result_dict["pressure"].shape, (10, 3, 3)) self.assertTrue(result_dict["temperature"][-1] > 25) self.assertTrue(result_dict["temperature"][-1] < 75) @@ -45,9 +45,9 @@ def test_ase_npt(self): thermo=10, timestep=1 * units.fs, ttime=100 * units.fs, - pfactor=2e6 * units.GPa * (units.fs ** 2), + pfactor=2e6 * units.GPa * (units.fs**2), temperature=100, - externalstress=np.array([0., 0., 0., 0., 0., 0.]) * units.bar, + externalstress=np.array([0.0, 0.0, 0.0, 0.0, 0.0, 0.0]) * units.bar, ) self.assertEqual(result_dict["positions"].shape, (10, 32, 3)) self.assertEqual(result_dict["velocities"].shape, (10, 32, 3)) @@ -59,4 +59,6 @@ def test_ase_npt(self): self.assertEqual(result_dict["pressure"].shape, (10, 3, 3)) self.assertTrue(result_dict["temperature"][-1] > 50) self.assertTrue(result_dict["temperature"][-1] < 100) - self.assertTrue(get_volume(result_dict["cell"][0]) < get_volume(result_dict["cell"][-1])) + self.assertTrue( + get_volume(result_dict["cell"][0]) < get_volume(result_dict["cell"][-1]) + ) diff --git a/tests/test_calc_stress_ase_emt.py b/tests/test_calc_stress_ase_emt.py index 3c29fc42..420dd036 100644 --- a/tests/test_calc_stress_ase_emt.py +++ b/tests/test_calc_stress_ase_emt.py @@ -20,9 +20,11 @@ def test_calc_stress(self): task_dict=task_dict, ase_calculator=EMT(), ase_optimizer=LBFGS, - ase_optimizer_kwargs={"fmax": 0.000001} + ase_optimizer_kwargs={"fmax": 0.000001}, ) - task_dict = {"calc_stress": result_dict["structure_with_optimized_positions_and_volume"]} + task_dict = { + "calc_stress": result_dict["structure_with_optimized_positions_and_volume"] + } stress_post_dict = evaluate_with_ase( task_dict=task_dict, ase_calculator=EMT(), diff --git a/tests/test_calc_stress_lammps.py b/tests/test_calc_stress_lammps.py index c19f65f2..dcc93875 100644 --- a/tests/test_calc_stress_lammps.py +++ b/tests/test_calc_stress_lammps.py @@ -7,9 +7,7 @@ try: - from atomistics.calculators import ( - evaluate_with_lammps, get_potential_by_name - ) + from atomistics.calculators import evaluate_with_lammps, get_potential_by_name skip_lammps_test = False except ImportError: @@ -23,7 +21,7 @@ class TestStess(unittest.TestCase): def test_calc_stress(self): structure = bulk("Al", cubic=True) df_pot_selected = get_potential_by_name( - potential_name='1999--Mishin-Y--Al--LAMMPS--ipr1', + potential_name="1999--Mishin-Y--Al--LAMMPS--ipr1", resource_path=os.path.join(os.path.dirname(__file__), "static", "lammps"), ) task_dict = {"calc_stress": structure} @@ -36,7 +34,9 @@ def test_calc_stress(self): task_dict=task_dict, potential_dataframe=df_pot_selected, ) - task_dict = {"calc_stress": result_dict["structure_with_optimized_positions_and_volume"]} + task_dict = { + "calc_stress": result_dict["structure_with_optimized_positions_and_volume"] + } stress_post_dict = evaluate_with_lammps( task_dict=task_dict, potential_dataframe=df_pot_selected, diff --git a/tests/test_elastic_ase_emt.py b/tests/test_elastic_ase_emt.py index 95b27154..5bfe1216 100644 --- a/tests/test_elastic_ase_emt.py +++ b/tests/test_elastic_ase_emt.py @@ -16,14 +16,14 @@ def test_calc_elastic(self): task_dict=task_dict, ase_calculator=EMT(), ase_optimizer=LBFGS, - ase_optimizer_kwargs={"fmax": 0.000001} + ase_optimizer_kwargs={"fmax": 0.000001}, ) workflow = ElasticMatrixWorkflow( structure=result_dict["structure_with_optimized_positions_and_volume"], num_of_point=5, eps_range=0.005, sqrt_eta=True, - fit_order=2 + fit_order=2, ) task_dict = workflow.generate_structures() result_dict = evaluate_with_ase(task_dict=task_dict, ase_calculator=EMT()) diff --git a/tests/test_elastic_helper.py b/tests/test_elastic_helper.py index cf229904..25864307 100644 --- a/tests/test_elastic_helper.py +++ b/tests/test_elastic_helper.py @@ -93,4 +93,4 @@ def test_get_symmetry_family_from_SGN(self): LC = get_symmetry_family_from_SGN(SGN=207) self.assertEqual(LC, "CI") with self.assertRaises(ValueError): - get_symmetry_family_from_SGN(SGN=231) \ No newline at end of file + get_symmetry_family_from_SGN(SGN=231) diff --git a/tests/test_elastic_lammps.py b/tests/test_elastic_lammps.py index aa2fd85d..325de1f9 100644 --- a/tests/test_elastic_lammps.py +++ b/tests/test_elastic_lammps.py @@ -7,9 +7,7 @@ from atomistics.workflows import ElasticMatrixWorkflow, optimize_positions_and_volume try: - from atomistics.calculators import ( - evaluate_with_lammps, get_potential_by_name - ) + from atomistics.calculators import evaluate_with_lammps, get_potential_by_name skip_lammps_test = False except ImportError: @@ -23,7 +21,7 @@ class TestElastic(unittest.TestCase): def test_calc_elastic(self): structure = bulk("Al", cubic=True) df_pot_selected = get_potential_by_name( - potential_name='1999--Mishin-Y--Al--LAMMPS--ipr1', + potential_name="1999--Mishin-Y--Al--LAMMPS--ipr1", resource_path=os.path.join(os.path.dirname(__file__), "static", "lammps"), ) task_dict = optimize_positions_and_volume(structure=structure) @@ -36,7 +34,7 @@ def test_calc_elastic(self): num_of_point=5, eps_range=0.005, sqrt_eta=True, - fit_order=2 + fit_order=2, ) task_dict = workflow.generate_structures() result_dict = evaluate_with_lammps( @@ -44,68 +42,91 @@ def test_calc_elastic(self): potential_dataframe=df_pot_selected, ) elastic_dict = workflow.analyse_structures(output_dict=result_dict) - self.assertTrue(np.isclose(elastic_dict["elastic_matrix"], np.array( - [ - [114.10311701, 60.51102935, 60.51102935, 0., 0., 0.], - [60.51102935, 114.10311701, 60.51102935, 0., 0., 0.], - [60.51102935, 60.51102935, 114.10311701, 0., 0., 0.], - [0., 0., 0., 51.23853765, 0., 0.], - [0., 0., 0., 0., 51.23853765, 0.], - [0., 0., 0., 0., 0., 51.23853765] - ]) - ).all()) - self.assertEqual(workflow._data['SGN'], 225) - self.assertEqual(workflow._data['LC'], 'CI') - self.assertEqual(workflow._data['Lag_strain_list'], ['01', '08', '23']) - self.assertTrue(np.isclose(workflow._data['epss'], np.array([-0.005, -0.0025, 0., 0.0025, 0.005])).all()) + self.assertTrue( + np.isclose( + elastic_dict["elastic_matrix"], + np.array( + [ + [114.10311701, 60.51102935, 60.51102935, 0.0, 0.0, 0.0], + [60.51102935, 114.10311701, 60.51102935, 0.0, 0.0, 0.0], + [60.51102935, 60.51102935, 114.10311701, 0.0, 0.0, 0.0], + [0.0, 0.0, 0.0, 51.23853765, 0.0, 0.0], + [0.0, 0.0, 0.0, 0.0, 51.23853765, 0.0], + [0.0, 0.0, 0.0, 0.0, 0.0, 51.23853765], + ] + ), + ).all() + ) + self.assertEqual(workflow._data["SGN"], 225) + self.assertEqual(workflow._data["LC"], "CI") + self.assertEqual(workflow._data["Lag_strain_list"], ["01", "08", "23"]) + self.assertTrue( + np.isclose( + workflow._data["epss"], np.array([-0.005, -0.0025, 0.0, 0.0025, 0.005]) + ).all() + ) self.assertAlmostEqual(workflow._data["v0"], 66.43035441556098) - self.assertAlmostEqual(workflow._data["e0"], -13.439999952735112) - self.assertTrue(np.isclose(workflow._data['strain_energy'], np.array( - [ - [ - (-0.005, -13.436320248980278), - (-0.0025, -13.439079680886989), - (0.0, -13.439999952735112), - (0.0024999999999999996, -13.439084974614394), - (0.005, -13.436364320399795) - ], - [ - (-0.005, -13.43817471490433), - (-0.0025, -13.439544638502628), - (0.0, -13.439999952735112), - (0.0024999999999999996, -13.43954822781134), - (0.005, -13.438204192615181) - ], - [ - (-0.005, -13.436741954502294), - (-0.0025, -13.439195465714551), - (0.0, -13.439999952735112), - (0.0024999999999999996, -13.439213491269701), - (0.005, -13.436885713447486) - ] - ])).all() + self.assertAlmostEqual(workflow._data["e0"], -13.439999952735112) + self.assertTrue( + np.isclose( + workflow._data["strain_energy"], + np.array( + [ + [ + (-0.005, -13.436320248980278), + (-0.0025, -13.439079680886989), + (0.0, -13.439999952735112), + (0.0024999999999999996, -13.439084974614394), + (0.005, -13.436364320399795), + ], + [ + (-0.005, -13.43817471490433), + (-0.0025, -13.439544638502628), + (0.0, -13.439999952735112), + (0.0024999999999999996, -13.43954822781134), + (0.005, -13.438204192615181), + ], + [ + (-0.005, -13.436741954502294), + (-0.0025, -13.439195465714551), + (0.0, -13.439999952735112), + (0.0024999999999999996, -13.439213491269701), + (0.005, -13.436885713447486), + ], + ] + ), + ).all() + ) + self.assertTrue( + np.isclose( + workflow._data["A2"], np.array([2.20130388, 1.08985578, 1.91883479]) + ).all() + ) + self.assertAlmostEqual(elastic_dict["bulkmodul_voigt"], 78.37505857279467) + self.assertAlmostEqual(elastic_dict["shearmodul_voigt"], 41.46154012284969) + self.assertAlmostEqual(elastic_dict["youngsmodul_voigt"], 105.73882997912072) + self.assertAlmostEqual(elastic_dict["poissonsratio_voigt"], 0.2751435386362729) + self.assertTrue( + np.isclose( + elastic_dict["elastic_matrix_inverse"], + np.array( + [ + [0.01385733, -0.00480214, -0.00480214, 0.0, 0.0, 0.0], + [-0.00480214, 0.01385733, -0.00480214, 0.0, 0.0, 0.0], + [-0.00480214, -0.00480214, 0.01385733, 0.0, 0.0, 0.0], + [0.0, 0.0, 0.0, 0.01951656, 0.0, 0.0], + [0.0, 0.0, 0.0, 0.0, 0.01951656, 0.0], + [0.0, 0.0, 0.0, 0.0, 0.0, 0.01951656], + ] + ), + ).all() ) - self.assertTrue(np.isclose(workflow._data['A2'], np.array([2.20130388, 1.08985578, 1.91883479])).all()) - self.assertAlmostEqual(elastic_dict['bulkmodul_voigt'], 78.37505857279467) - self.assertAlmostEqual(elastic_dict['shearmodul_voigt'], 41.46154012284969) - self.assertAlmostEqual(elastic_dict['youngsmodul_voigt'], 105.73882997912072) - self.assertAlmostEqual(elastic_dict['poissonsratio_voigt'], 0.2751435386362729) - self.assertTrue(np.isclose(elastic_dict['elastic_matrix_inverse'], np.array( - [ - [0.01385733, -0.00480214, -0.00480214, 0., 0., 0.], - [-0.00480214, 0.01385733, -0.00480214, 0., 0., 0.], - [-0.00480214, -0.00480214, 0.01385733, 0., 0., 0.], - [0., 0., 0., 0.01951656, 0., 0.], - [0., 0., 0., 0., 0.01951656, 0.], - [0., 0., 0., 0., 0., 0.01951656] - ] - )).all()) - self.assertAlmostEqual(elastic_dict['bulkmodul_reuss'], 78.37505857279469) - self.assertAlmostEqual(elastic_dict['shearmodul_reuss'], 37.54104251720356) - self.assertAlmostEqual(elastic_dict['youngsmodul_reuss'], 97.11702764970639) - self.assertAlmostEqual(elastic_dict['poissonsratio_reuss'], 0.29347803281170937) - self.assertAlmostEqual(elastic_dict['bulkmodul_hill'], 78.37505857279467) - self.assertAlmostEqual(elastic_dict['shearmodul_hill'], 39.501291320026624) - self.assertAlmostEqual(elastic_dict['youngsmodul_hill'], 101.45869947879392) - self.assertAlmostEqual(elastic_dict['poissonsratio_hill'], 0.2842453510798992) - self.assertAlmostEqual(elastic_dict['AVR'], 4.962492964955925) + self.assertAlmostEqual(elastic_dict["bulkmodul_reuss"], 78.37505857279469) + self.assertAlmostEqual(elastic_dict["shearmodul_reuss"], 37.54104251720356) + self.assertAlmostEqual(elastic_dict["youngsmodul_reuss"], 97.11702764970639) + self.assertAlmostEqual(elastic_dict["poissonsratio_reuss"], 0.29347803281170937) + self.assertAlmostEqual(elastic_dict["bulkmodul_hill"], 78.37505857279467) + self.assertAlmostEqual(elastic_dict["shearmodul_hill"], 39.501291320026624) + self.assertAlmostEqual(elastic_dict["youngsmodul_hill"], 101.45869947879392) + self.assertAlmostEqual(elastic_dict["poissonsratio_hill"], 0.2842453510798992) + self.assertAlmostEqual(elastic_dict["AVR"], 4.962492964955925) diff --git a/tests/test_elastic_lammps_functional.py b/tests/test_elastic_lammps_functional.py index 3e58e2bb..e8ae5d50 100644 --- a/tests/test_elastic_lammps_functional.py +++ b/tests/test_elastic_lammps_functional.py @@ -6,13 +6,11 @@ from atomistics.workflows.elastic.workflow import ( analyse_structures_helper, - generate_structures_helper + generate_structures_helper, ) try: - from atomistics.calculators import ( - evaluate_with_lammps, get_potential_by_name - ) + from atomistics.calculators import evaluate_with_lammps, get_potential_by_name skip_lammps_test = False except ImportError: @@ -26,7 +24,7 @@ class TestElastic(unittest.TestCase): def test_calc_elastic_functions(self): structure = bulk("Al", cubic=True) df_pot_selected = get_potential_by_name( - potential_name='1999--Mishin-Y--Al--LAMMPS--ipr1', + potential_name="1999--Mishin-Y--Al--LAMMPS--ipr1", resource_path=os.path.join(os.path.dirname(__file__), "static", "lammps"), ) result_dict = evaluate_with_lammps( @@ -50,68 +48,91 @@ def test_calc_elastic_functions(self): fit_order=2, zero_strain_job_name="s_e_0", ) - self.assertTrue(np.isclose(elastic_dict["elastic_matrix"], np.array( - [ - [114.10311701, 60.51102935, 60.51102935, 0., 0., 0.], - [60.51102935, 114.10311701, 60.51102935, 0., 0., 0.], - [60.51102935, 60.51102935, 114.10311701, 0., 0., 0.], - [0., 0., 0., 51.23853765, 0., 0.], - [0., 0., 0., 0., 51.23853765, 0.], - [0., 0., 0., 0., 0., 51.23853765] - ]) - ).all()) - self.assertEqual(sym_dict['SGN'], 225) - self.assertEqual(sym_dict['LC'], 'CI') - self.assertEqual(sym_dict['Lag_strain_list'], ['01', '08', '23']) - self.assertTrue(np.isclose(sym_dict['epss'], np.array([-0.005, -0.0025, 0., 0.0025, 0.005])).all()) + self.assertTrue( + np.isclose( + elastic_dict["elastic_matrix"], + np.array( + [ + [114.10311701, 60.51102935, 60.51102935, 0.0, 0.0, 0.0], + [60.51102935, 114.10311701, 60.51102935, 0.0, 0.0, 0.0], + [60.51102935, 60.51102935, 114.10311701, 0.0, 0.0, 0.0], + [0.0, 0.0, 0.0, 51.23853765, 0.0, 0.0], + [0.0, 0.0, 0.0, 0.0, 51.23853765, 0.0], + [0.0, 0.0, 0.0, 0.0, 0.0, 51.23853765], + ] + ), + ).all() + ) + self.assertEqual(sym_dict["SGN"], 225) + self.assertEqual(sym_dict["LC"], "CI") + self.assertEqual(sym_dict["Lag_strain_list"], ["01", "08", "23"]) + self.assertTrue( + np.isclose( + sym_dict["epss"], np.array([-0.005, -0.0025, 0.0, 0.0025, 0.005]) + ).all() + ) self.assertAlmostEqual(sym_dict["v0"], 66.43035441556098) - self.assertAlmostEqual(sym_dict["e0"], -13.439999952735112) - self.assertTrue(np.isclose(sym_dict['strain_energy'], np.array( - [ - [ - (-0.005, -13.436320248980278), - (-0.0025, -13.439079680886989), - (0.0, -13.439999952735112), - (0.0024999999999999996, -13.439084974614394), - (0.005, -13.436364320399795) - ], - [ - (-0.005, -13.43817471490433), - (-0.0025, -13.439544638502628), - (0.0, -13.439999952735112), - (0.0024999999999999996, -13.43954822781134), - (0.005, -13.438204192615181) - ], - [ - (-0.005, -13.436741954502294), - (-0.0025, -13.439195465714551), - (0.0, -13.439999952735112), - (0.0024999999999999996, -13.439213491269701), - (0.005, -13.436885713447486) - ] - ])).all() + self.assertAlmostEqual(sym_dict["e0"], -13.439999952735112) + self.assertTrue( + np.isclose( + sym_dict["strain_energy"], + np.array( + [ + [ + (-0.005, -13.436320248980278), + (-0.0025, -13.439079680886989), + (0.0, -13.439999952735112), + (0.0024999999999999996, -13.439084974614394), + (0.005, -13.436364320399795), + ], + [ + (-0.005, -13.43817471490433), + (-0.0025, -13.439544638502628), + (0.0, -13.439999952735112), + (0.0024999999999999996, -13.43954822781134), + (0.005, -13.438204192615181), + ], + [ + (-0.005, -13.436741954502294), + (-0.0025, -13.439195465714551), + (0.0, -13.439999952735112), + (0.0024999999999999996, -13.439213491269701), + (0.005, -13.436885713447486), + ], + ] + ), + ).all() + ) + self.assertTrue( + np.isclose( + sym_dict["A2"], np.array([2.20130388, 1.08985578, 1.91883479]) + ).all() + ) + self.assertAlmostEqual(elastic_dict["bulkmodul_voigt"], 78.37505857279467) + self.assertAlmostEqual(elastic_dict["shearmodul_voigt"], 41.46154012284969) + self.assertAlmostEqual(elastic_dict["youngsmodul_voigt"], 105.73882997912072) + self.assertAlmostEqual(elastic_dict["poissonsratio_voigt"], 0.2751435386362729) + self.assertTrue( + np.isclose( + elastic_dict["elastic_matrix_inverse"], + np.array( + [ + [0.01385733, -0.00480214, -0.00480214, 0.0, 0.0, 0.0], + [-0.00480214, 0.01385733, -0.00480214, 0.0, 0.0, 0.0], + [-0.00480214, -0.00480214, 0.01385733, 0.0, 0.0, 0.0], + [0.0, 0.0, 0.0, 0.01951656, 0.0, 0.0], + [0.0, 0.0, 0.0, 0.0, 0.01951656, 0.0], + [0.0, 0.0, 0.0, 0.0, 0.0, 0.01951656], + ] + ), + ).all() ) - self.assertTrue(np.isclose(sym_dict["A2"], np.array([2.20130388, 1.08985578, 1.91883479])).all()) - self.assertAlmostEqual(elastic_dict['bulkmodul_voigt'], 78.37505857279467) - self.assertAlmostEqual(elastic_dict['shearmodul_voigt'], 41.46154012284969) - self.assertAlmostEqual(elastic_dict['youngsmodul_voigt'], 105.73882997912072) - self.assertAlmostEqual(elastic_dict['poissonsratio_voigt'], 0.2751435386362729) - self.assertTrue(np.isclose(elastic_dict['elastic_matrix_inverse'], np.array( - [ - [0.01385733, -0.00480214, -0.00480214, 0., 0., 0.], - [-0.00480214, 0.01385733, -0.00480214, 0., 0., 0.], - [-0.00480214, -0.00480214, 0.01385733, 0., 0., 0.], - [0., 0., 0., 0.01951656, 0., 0.], - [0., 0., 0., 0., 0.01951656, 0.], - [0., 0., 0., 0., 0., 0.01951656] - ] - )).all()) - self.assertAlmostEqual(elastic_dict['bulkmodul_reuss'], 78.37505857279469) - self.assertAlmostEqual(elastic_dict['shearmodul_reuss'], 37.54104251720356) - self.assertAlmostEqual(elastic_dict['youngsmodul_reuss'], 97.11702764970639) - self.assertAlmostEqual(elastic_dict['poissonsratio_reuss'], 0.29347803281170937) - self.assertAlmostEqual(elastic_dict['bulkmodul_hill'], 78.37505857279467) - self.assertAlmostEqual(elastic_dict['shearmodul_hill'], 39.501291320026624) - self.assertAlmostEqual(elastic_dict['youngsmodul_hill'], 101.45869947879392) - self.assertAlmostEqual(elastic_dict['poissonsratio_hill'], 0.2842453510798992) - self.assertAlmostEqual(elastic_dict['AVR'], 4.962492964955925) + self.assertAlmostEqual(elastic_dict["bulkmodul_reuss"], 78.37505857279469) + self.assertAlmostEqual(elastic_dict["shearmodul_reuss"], 37.54104251720356) + self.assertAlmostEqual(elastic_dict["youngsmodul_reuss"], 97.11702764970639) + self.assertAlmostEqual(elastic_dict["poissonsratio_reuss"], 0.29347803281170937) + self.assertAlmostEqual(elastic_dict["bulkmodul_hill"], 78.37505857279467) + self.assertAlmostEqual(elastic_dict["shearmodul_hill"], 39.501291320026624) + self.assertAlmostEqual(elastic_dict["youngsmodul_hill"], 101.45869947879392) + self.assertAlmostEqual(elastic_dict["poissonsratio_hill"], 0.2842453510798992) + self.assertAlmostEqual(elastic_dict["AVR"], 4.962492964955925) diff --git a/tests/test_evcurve_ase_emt.py b/tests/test_evcurve_ase_emt.py index 725a3b3c..36c2cde8 100644 --- a/tests/test_evcurve_ase_emt.py +++ b/tests/test_evcurve_ase_emt.py @@ -5,7 +5,10 @@ import unittest from atomistics.calculators import evaluate_with_ase -from atomistics.workflows import EnergyVolumeCurveWorkflow, optimize_positions_and_volume +from atomistics.workflows import ( + EnergyVolumeCurveWorkflow, + optimize_positions_and_volume, +) class TestEvCurve(unittest.TestCase): @@ -16,28 +19,30 @@ def test_calc_evcurve(self): task_dict=task_dict, ase_calculator=EMT(), ase_optimizer=LBFGS, - ase_optimizer_kwargs={"fmax": 0.000001} + ase_optimizer_kwargs={"fmax": 0.000001}, ) workflow = EnergyVolumeCurveWorkflow( structure=result_dict["structure_with_optimized_positions_and_volume"], num_points=11, - fit_type='polynomial', + fit_type="polynomial", fit_order=3, vol_range=0.05, - axes=('x', 'y', 'z'), + axes=("x", "y", "z"), strains=None, ) task_dict = workflow.generate_structures() result_dict = evaluate_with_ase(task_dict=task_dict, ase_calculator=EMT()) fit_dict = workflow.analyse_structures(output_dict=result_dict) thermal_properties_dict = workflow.get_thermal_properties( - temperatures=[100, 1000], - output_keys=["temperatures", "volumes"] + temperatures=[100, 1000], output_keys=["temperatures", "volumes"] ) - temperatures_ev, volumes_ev = thermal_properties_dict["temperatures"], thermal_properties_dict["volumes"] - self.assertAlmostEqual(fit_dict['volume_eq'], 63.72747170239313) - self.assertAlmostEqual(fit_dict['bulkmodul_eq'], 39.51954433668759) - self.assertAlmostEqual(fit_dict['b_prime_eq'], 2.148388436768747) + temperatures_ev, volumes_ev = ( + thermal_properties_dict["temperatures"], + thermal_properties_dict["volumes"], + ) + self.assertAlmostEqual(fit_dict["volume_eq"], 63.72747170239313) + self.assertAlmostEqual(fit_dict["bulkmodul_eq"], 39.51954433668759) + self.assertAlmostEqual(fit_dict["b_prime_eq"], 2.148388436768747) self.assertEqual(len(temperatures_ev), 2) self.assertEqual(len(volumes_ev), 2) self.assertTrue(volumes_ev[0] < volumes_ev[-1]) diff --git a/tests/test_evcurve_ase_lammps.py b/tests/test_evcurve_ase_lammps.py index 74f9c639..bc6880f8 100644 --- a/tests/test_evcurve_ase_lammps.py +++ b/tests/test_evcurve_ase_lammps.py @@ -5,7 +5,10 @@ import unittest from atomistics.calculators import evaluate_with_ase -from atomistics.workflows import EnergyVolumeCurveWorkflow, optimize_positions_and_volume +from atomistics.workflows import ( + EnergyVolumeCurveWorkflow, + optimize_positions_and_volume, +) try: @@ -21,10 +24,7 @@ ) class TestEvCurve(unittest.TestCase): def test_calc_evcurve(self): - cmds = [ - "pair_style morse/smooth/linear 9.0", - "pair_coeff * * 0.5 1.8 2.95" - ] + cmds = ["pair_style morse/smooth/linear 9.0", "pair_coeff * * 0.5 1.8 2.95"] structure = bulk("Al", cubic=True) task_dict = optimize_positions_and_volume(structure=structure) result_dict = evaluate_with_ase( @@ -35,15 +35,15 @@ def test_calc_evcurve(self): keep_alive=True, ), ase_optimizer=LBFGS, - ase_optimizer_kwargs={"fmax": 0.000001} + ase_optimizer_kwargs={"fmax": 0.000001}, ) workflow = EnergyVolumeCurveWorkflow( structure=result_dict["structure_with_optimized_positions_and_volume"], num_points=11, - fit_type='polynomial', + fit_type="polynomial", fit_order=3, vol_range=0.05, - axes=('x', 'y', 'z'), + axes=("x", "y", "z"), strains=None, ) task_dict = workflow.generate_structures() @@ -57,13 +57,15 @@ def test_calc_evcurve(self): ) fit_dict = workflow.analyse_structures(output_dict=result_dict) thermal_properties_dict = workflow.get_thermal_properties( - temperatures=[100, 1000], - output_keys=["temperatures", "volumes"] + temperatures=[100, 1000], output_keys=["temperatures", "volumes"] + ) + temperatures_ev, volumes_ev = ( + thermal_properties_dict["temperatures"], + thermal_properties_dict["volumes"], ) - temperatures_ev, volumes_ev = thermal_properties_dict["temperatures"], thermal_properties_dict["volumes"] - self.assertAlmostEqual(fit_dict['volume_eq'], 66.29753110818122) - self.assertAlmostEqual(fit_dict['bulkmodul_eq'], 218.25686471974936) - self.assertAlmostEqual(fit_dict['b_prime_eq'], 6.218603542219656) + self.assertAlmostEqual(fit_dict["volume_eq"], 66.29753110818122) + self.assertAlmostEqual(fit_dict["bulkmodul_eq"], 218.25686471974936) + self.assertAlmostEqual(fit_dict["b_prime_eq"], 6.218603542219656) self.assertEqual(len(temperatures_ev), 2) self.assertEqual(len(volumes_ev), 2) self.assertTrue(volumes_ev[0] < volumes_ev[-1]) diff --git a/tests/test_evcurve_eos.py b/tests/test_evcurve_eos.py index 32aff681..edef4e11 100644 --- a/tests/test_evcurve_eos.py +++ b/tests/test_evcurve_eos.py @@ -18,7 +18,7 @@ def setUp(self): 67.7589615038722, 68.42326504802779, 69.08756859218344, - 69.75187213633905 + 69.75187213633905, ] self.energies = [ -13.39817505470619, @@ -31,35 +31,47 @@ def setUp(self): -13.433605756604651, -13.42577121684493, -13.41495739484744, - -13.401227593921211 + -13.401227593921211, ] def test_birch(self): - fit_dict = fit_equation_of_state(volume_lst=self.volumes, energy_lst=self.energies, fittype='birch') - self.assertAlmostEqual(fit_dict['volume_eq'], 66.43027009811671) - self.assertAlmostEqual(fit_dict['bulkmodul_eq'], 77.7433780646763) - self.assertAlmostEqual(fit_dict['b_prime_eq'], 1.2836228593874182) + fit_dict = fit_equation_of_state( + volume_lst=self.volumes, energy_lst=self.energies, fittype="birch" + ) + self.assertAlmostEqual(fit_dict["volume_eq"], 66.43027009811671) + self.assertAlmostEqual(fit_dict["bulkmodul_eq"], 77.7433780646763) + self.assertAlmostEqual(fit_dict["b_prime_eq"], 1.2836228593874182) def test_birchmurnaghan(self): - fit_dict = fit_equation_of_state(volume_lst=self.volumes, energy_lst=self.energies, fittype='birchmurnaghan') - self.assertAlmostEqual(fit_dict['volume_eq'], 66.43027009811708) - self.assertAlmostEqual(fit_dict['bulkmodul_eq'], 77.74337806467966) - self.assertAlmostEqual(fit_dict['b_prime_eq'], 1.2836228593684815) + fit_dict = fit_equation_of_state( + volume_lst=self.volumes, energy_lst=self.energies, fittype="birchmurnaghan" + ) + self.assertAlmostEqual(fit_dict["volume_eq"], 66.43027009811708) + self.assertAlmostEqual(fit_dict["bulkmodul_eq"], 77.74337806467966) + self.assertAlmostEqual(fit_dict["b_prime_eq"], 1.2836228593684815) def test_murnaghan(self): - fit_dict = fit_equation_of_state(volume_lst=self.volumes, energy_lst=self.energies, fittype='murnaghan') - self.assertAlmostEqual(fit_dict['volume_eq'], 66.43035753542675) - self.assertAlmostEqual(fit_dict['bulkmodul_eq'], 77.60443933015738) - self.assertAlmostEqual(fit_dict['b_prime_eq'], 1.2716548170090776) + fit_dict = fit_equation_of_state( + volume_lst=self.volumes, energy_lst=self.energies, fittype="murnaghan" + ) + self.assertAlmostEqual(fit_dict["volume_eq"], 66.43035753542675) + self.assertAlmostEqual(fit_dict["bulkmodul_eq"], 77.60443933015738) + self.assertAlmostEqual(fit_dict["b_prime_eq"], 1.2716548170090776) def test_pouriertarantola(self): - fit_dict = fit_equation_of_state(volume_lst=self.volumes, energy_lst=self.energies, fittype='pouriertarantola') - self.assertAlmostEqual(fit_dict['volume_eq'], 66.43035598678892) - self.assertAlmostEqual(fit_dict['bulkmodul_eq'], 77.61743376692809) - self.assertAlmostEqual(fit_dict['b_prime_eq'], 1.272111993713677) + fit_dict = fit_equation_of_state( + volume_lst=self.volumes, + energy_lst=self.energies, + fittype="pouriertarantola", + ) + self.assertAlmostEqual(fit_dict["volume_eq"], 66.43035598678892) + self.assertAlmostEqual(fit_dict["bulkmodul_eq"], 77.61743376692809) + self.assertAlmostEqual(fit_dict["b_prime_eq"], 1.272111993713677) def test_vinet(self): - fit_dict = fit_equation_of_state(volume_lst=self.volumes, energy_lst=self.energies, fittype='vinet') - self.assertAlmostEqual(fit_dict['volume_eq'], 66.43032532814925) - self.assertAlmostEqual(fit_dict['bulkmodul_eq'], 77.61265363975706) - self.assertAlmostEqual(fit_dict['b_prime_eq'], 1.2734991618131122) + fit_dict = fit_equation_of_state( + volume_lst=self.volumes, energy_lst=self.energies, fittype="vinet" + ) + self.assertAlmostEqual(fit_dict["volume_eq"], 66.43032532814925) + self.assertAlmostEqual(fit_dict["bulkmodul_eq"], 77.61265363975706) + self.assertAlmostEqual(fit_dict["b_prime_eq"], 1.2734991618131122) diff --git a/tests/test_evcurve_lammps.py b/tests/test_evcurve_lammps.py index c47173d2..cebb5863 100644 --- a/tests/test_evcurve_lammps.py +++ b/tests/test_evcurve_lammps.py @@ -4,12 +4,13 @@ import numpy as np import unittest -from atomistics.workflows import EnergyVolumeCurveWorkflow, optimize_positions_and_volume +from atomistics.workflows import ( + EnergyVolumeCurveWorkflow, + optimize_positions_and_volume, +) try: - from atomistics.calculators import ( - evaluate_with_lammps, get_potential_by_name - ) + from atomistics.calculators import evaluate_with_lammps, get_potential_by_name skip_lammps_test = False except ImportError: @@ -23,7 +24,7 @@ class TestEvCurve(unittest.TestCase): def test_calc_evcurve(self): structure = bulk("Al", cubic=True) df_pot_selected = get_potential_by_name( - potential_name='1999--Mishin-Y--Al--LAMMPS--ipr1', + potential_name="1999--Mishin-Y--Al--LAMMPS--ipr1", resource_path=os.path.join(os.path.dirname(__file__), "static", "lammps"), ) task_dict = optimize_positions_and_volume(structure=structure) @@ -34,10 +35,10 @@ def test_calc_evcurve(self): workflow = EnergyVolumeCurveWorkflow( structure=result_dict["structure_with_optimized_positions_and_volume"], num_points=11, - fit_type='polynomial', + fit_type="polynomial", fit_order=3, vol_range=0.05, - axes=('x', 'y', 'z'), + axes=("x", "y", "z"), strains=None, ) task_dict = workflow.generate_structures() @@ -47,13 +48,15 @@ def test_calc_evcurve(self): ) fit_dict = workflow.analyse_structures(output_dict=result_dict) thermal_properties_dict = workflow.get_thermal_properties( - temperatures=[100, 1000], - output_keys=["temperatures", "volumes"] + temperatures=[100, 1000], output_keys=["temperatures", "volumes"] + ) + temperatures_ev, volumes_ev = ( + thermal_properties_dict["temperatures"], + thermal_properties_dict["volumes"], ) - temperatures_ev, volumes_ev = thermal_properties_dict["temperatures"], thermal_properties_dict["volumes"] - self.assertAlmostEqual(fit_dict['volume_eq'], 66.43019790724603) - self.assertAlmostEqual(fit_dict['bulkmodul_eq'], 77.72501703646152) - self.assertAlmostEqual(fit_dict['b_prime_eq'], 1.2795467367276832) + self.assertAlmostEqual(fit_dict["volume_eq"], 66.43019790724603) + self.assertAlmostEqual(fit_dict["bulkmodul_eq"], 77.72501703646152) + self.assertAlmostEqual(fit_dict["b_prime_eq"], 1.2795467367276832) self.assertEqual(len(temperatures_ev), 2) self.assertEqual(len(volumes_ev), 2) self.assertTrue(volumes_ev[0] < volumes_ev[-1]) diff --git a/tests/test_evcurve_lammps_functional.py b/tests/test_evcurve_lammps_functional.py index 60d1231f..d1235450 100644 --- a/tests/test_evcurve_lammps_functional.py +++ b/tests/test_evcurve_lammps_functional.py @@ -11,9 +11,7 @@ try: - from atomistics.calculators import ( - evaluate_with_lammps, get_potential_by_name - ) + from atomistics.calculators import evaluate_with_lammps, get_potential_by_name skip_lammps_test = False except ImportError: @@ -27,7 +25,7 @@ class TestEvCurve(unittest.TestCase): def test_calc_evcurve_functional(self): structure = bulk("Al", cubic=True) df_pot_selected = get_potential_by_name( - potential_name='1999--Mishin-Y--Al--LAMMPS--ipr1', + potential_name="1999--Mishin-Y--Al--LAMMPS--ipr1", resource_path=os.path.join(os.path.dirname(__file__), "static", "lammps"), ) result_dict = evaluate_with_lammps( @@ -39,7 +37,7 @@ def test_calc_evcurve_functional(self): vol_range=0.05, num_points=11, strain_lst=None, - axes=('x', 'y', 'z'), + axes=("x", "y", "z"), ) result_dict = evaluate_with_lammps( task_dict={"calc_energy": structure_dict}, @@ -49,7 +47,7 @@ def test_calc_evcurve_functional(self): output_dict=result_dict, structure_dict=structure_dict, fit_type="polynomial", - fit_order=3 + fit_order=3, ) thermal_properties_dict = get_thermal_properties( fit_dict=fit_dict, @@ -61,10 +59,13 @@ def test_calc_evcurve_functional(self): constant_volume=False, output_keys=["temperatures", "volumes"], ) - temperatures_ev, volumes_ev = thermal_properties_dict["temperatures"], thermal_properties_dict["volumes"] - self.assertAlmostEqual(fit_dict['volume_eq'], 66.43019790724685) - self.assertAlmostEqual(fit_dict['bulkmodul_eq'], 77.72501703646152) - self.assertAlmostEqual(fit_dict['b_prime_eq'], 1.2795467367276832) + temperatures_ev, volumes_ev = ( + thermal_properties_dict["temperatures"], + thermal_properties_dict["volumes"], + ) + self.assertAlmostEqual(fit_dict["volume_eq"], 66.43019790724685) + self.assertAlmostEqual(fit_dict["bulkmodul_eq"], 77.72501703646152) + self.assertAlmostEqual(fit_dict["b_prime_eq"], 1.2795467367276832) self.assertEqual(len(temperatures_ev), 2) self.assertEqual(len(volumes_ev), 2) self.assertTrue(volumes_ev[0] < volumes_ev[-1]) diff --git a/tests/test_evcurve_qe.py b/tests/test_evcurve_qe.py index 8328204d..5175e60c 100644 --- a/tests/test_evcurve_qe.py +++ b/tests/test_evcurve_qe.py @@ -15,12 +15,12 @@ def validate_fitdict(fit_dict): lst = [ - fit_dict['bulkmodul_eq'] > 50, - fit_dict['bulkmodul_eq'] < 80, - fit_dict['energy_eq'] > -2148.2, - fit_dict['energy_eq'] < -2148.1, - fit_dict['volume_eq'] > 70, - fit_dict['volume_eq'] < 72, + fit_dict["bulkmodul_eq"] > 50, + fit_dict["bulkmodul_eq"] < 80, + fit_dict["energy_eq"] > -2148.2, + fit_dict["energy_eq"] < -2148.1, + fit_dict["volume_eq"] > 70, + fit_dict["volume_eq"] < 72, ] if not all(lst): print(fit_dict) @@ -28,7 +28,8 @@ def validate_fitdict(fit_dict): @unittest.skipIf( - skip_quantum_espresso_test, "pwtools is not installed, so the pwtools based quantum espresso tests are skipped." + skip_quantum_espresso_test, + "pwtools is not installed, so the pwtools based quantum espresso tests are skipped.", ) class TestEvCurve(unittest.TestCase): def test_calc_evcurve(self): @@ -36,10 +37,10 @@ def test_calc_evcurve(self): workflow = EnergyVolumeCurveWorkflow( structure=bulk("Al", a=4.15, cubic=True), num_points=7, - fit_type='polynomial', + fit_type="polynomial", fit_order=3, vol_range=0.05, - axes=('x', 'y', 'z'), + axes=("x", "y", "z"), strains=None, ) task_dict = workflow.generate_structures() diff --git a/tests/test_hessian_lammps.py b/tests/test_hessian_lammps.py index 82365b8b..22619593 100644 --- a/tests/test_hessian_lammps.py +++ b/tests/test_hessian_lammps.py @@ -5,13 +5,19 @@ import unittest from atomistics.calculators import evaluate_with_hessian -from atomistics.workflows import optimize_positions_and_volume, LangevinWorkflow, PhonopyWorkflow +from atomistics.workflows import ( + optimize_positions_and_volume, + LangevinWorkflow, + PhonopyWorkflow, +) try: from pylammpsmpi import LammpsASELibrary from atomistics.calculators import ( - evaluate_with_lammps, evaluate_with_lammps_library, get_potential_by_name + evaluate_with_lammps, + evaluate_with_lammps_library, + get_potential_by_name, ) skip_lammps_test = False @@ -27,7 +33,7 @@ def test_langevin(self): steps = 10 structure = bulk("Al", cubic=True).repeat([3, 3, 3]) df_pot_selected = get_potential_by_name( - potential_name='1999--Mishin-Y--Al--LAMMPS--ipr1', + potential_name="1999--Mishin-Y--Al--LAMMPS--ipr1", resource_path=os.path.join(os.path.dirname(__file__), "static", "lammps"), ) task_dict = optimize_positions_and_volume(structure=structure) diff --git a/tests/test_lammps_calculator.py b/tests/test_lammps_calculator.py index 75b1228c..50a16a14 100644 --- a/tests/test_lammps_calculator.py +++ b/tests/test_lammps_calculator.py @@ -21,17 +21,13 @@ class TestPotential(unittest.TestCase): def test_validate_potential_dataframe(self): with self.assertRaises(ValueError): - _ = validate_potential_dataframe( - potential_dataframe=pandas.DataFrame({}) - ) + _ = validate_potential_dataframe(potential_dataframe=pandas.DataFrame({})) with self.assertRaises(ValueError): _ = validate_potential_dataframe( potential_dataframe=pandas.DataFrame({"a": [1, 2]}) ) with self.assertRaises(TypeError): - _ = validate_potential_dataframe( - potential_dataframe=0 - ) + _ = validate_potential_dataframe(potential_dataframe=0) series = validate_potential_dataframe( potential_dataframe=pandas.DataFrame({"a": [1]}) ) @@ -40,6 +36,8 @@ def test_validate_potential_dataframe(self): def test_get_potential_dataframe(self): df = get_potential_dataframe( structure=bulk("Al"), - resource_path=os.path.abspath(os.path.join("..", os.path.dirname(__file__), "static", "lammps")), + resource_path=os.path.abspath( + os.path.join("..", os.path.dirname(__file__), "static", "lammps") + ), ) self.assertEqual(len(df), 1) diff --git a/tests/test_lammps_md.py b/tests/test_lammps_md.py index 63d7acc6..eb08c558 100644 --- a/tests/test_lammps_md.py +++ b/tests/test_lammps_md.py @@ -11,7 +11,7 @@ calc_molecular_dynamics_npt_with_lammps, calc_molecular_dynamics_nph_with_lammps, calc_molecular_dynamics_langevin_with_lammps, - get_potential_by_name + get_potential_by_name, ) skip_lammps_test = False @@ -26,7 +26,7 @@ class TestLammpsMD(unittest.TestCase): def test_lammps_md_nvt_all(self): structure = bulk("Al", cubic=True).repeat([2, 2, 2]) df_pot_selected = get_potential_by_name( - potential_name='1999--Mishin-Y--Al--LAMMPS--ipr1', + potential_name="1999--Mishin-Y--Al--LAMMPS--ipr1", resource_path=os.path.join(os.path.dirname(__file__), "static", "lammps"), ) result_dict = calc_molecular_dynamics_nvt_with_lammps( @@ -46,9 +46,9 @@ def test_lammps_md_nvt_all(self): self.assertEqual(result_dict["velocities"].shape, (10, 32, 3)) self.assertEqual(result_dict["cell"].shape, (10, 3, 3)) self.assertEqual(result_dict["forces"].shape, (10, 32, 3)) - self.assertEqual(result_dict["temperature"].shape, (10, )) - self.assertEqual(result_dict["energy_pot"].shape, (10, )) - self.assertEqual(result_dict["energy_tot"].shape, (10, )) + self.assertEqual(result_dict["temperature"].shape, (10,)) + self.assertEqual(result_dict["energy_pot"].shape, (10,)) + self.assertEqual(result_dict["energy_tot"].shape, (10,)) self.assertEqual(result_dict["pressure"].shape, (10, 3, 3)) self.assertTrue(result_dict["temperature"][-1] > 90) self.assertTrue(result_dict["temperature"][-1] < 110) @@ -56,7 +56,7 @@ def test_lammps_md_nvt_all(self): def test_lammps_md_nvt_select(self): structure = bulk("Al", cubic=True).repeat([2, 2, 2]) df_pot_selected = get_potential_by_name( - potential_name='1999--Mishin-Y--Al--LAMMPS--ipr1', + potential_name="1999--Mishin-Y--Al--LAMMPS--ipr1", resource_path=os.path.join(os.path.dirname(__file__), "static", "lammps"), ) result_dict = calc_molecular_dynamics_nvt_with_lammps( @@ -74,14 +74,14 @@ def test_lammps_md_nvt_select(self): output_keys=("temperature",), ) self.assertEqual(len(result_dict.keys()), 1) - self.assertEqual(result_dict["temperature"].shape, (10, )) + self.assertEqual(result_dict["temperature"].shape, (10,)) self.assertTrue(result_dict["temperature"][-1] > 90) self.assertTrue(result_dict["temperature"][-1] < 110) def test_lammps_md_npt_all(self): structure = bulk("Al", cubic=True).repeat([2, 2, 2]) df_pot_selected = get_potential_by_name( - potential_name='1999--Mishin-Y--Al--LAMMPS--ipr1', + potential_name="1999--Mishin-Y--Al--LAMMPS--ipr1", resource_path=os.path.join(os.path.dirname(__file__), "static", "lammps"), ) result_dict = calc_molecular_dynamics_npt_with_lammps( @@ -104,9 +104,9 @@ def test_lammps_md_npt_all(self): self.assertEqual(result_dict["velocities"].shape, (10, 32, 3)) self.assertEqual(result_dict["cell"].shape, (10, 3, 3)) self.assertEqual(result_dict["forces"].shape, (10, 32, 3)) - self.assertEqual(result_dict["temperature"].shape, (10, )) - self.assertEqual(result_dict["energy_pot"].shape, (10, )) - self.assertEqual(result_dict["energy_tot"].shape, (10, )) + self.assertEqual(result_dict["temperature"].shape, (10,)) + self.assertEqual(result_dict["energy_pot"].shape, (10,)) + self.assertEqual(result_dict["energy_tot"].shape, (10,)) self.assertEqual(result_dict["pressure"].shape, (10, 3, 3)) self.assertTrue(result_dict["temperature"][-1] > 90) self.assertTrue(result_dict["temperature"][-1] < 110) @@ -114,7 +114,7 @@ def test_lammps_md_npt_all(self): def test_lammps_md_nph_all(self): structure = bulk("Al", cubic=True).repeat([2, 2, 2]) df_pot_selected = get_potential_by_name( - potential_name='1999--Mishin-Y--Al--LAMMPS--ipr1', + potential_name="1999--Mishin-Y--Al--LAMMPS--ipr1", resource_path=os.path.join(os.path.dirname(__file__), "static", "lammps"), ) result_dict = calc_molecular_dynamics_nph_with_lammps( @@ -135,9 +135,9 @@ def test_lammps_md_nph_all(self): self.assertEqual(result_dict["velocities"].shape, (10, 32, 3)) self.assertEqual(result_dict["cell"].shape, (10, 3, 3)) self.assertEqual(result_dict["forces"].shape, (10, 32, 3)) - self.assertEqual(result_dict["temperature"].shape, (10, )) - self.assertEqual(result_dict["energy_pot"].shape, (10, )) - self.assertEqual(result_dict["energy_tot"].shape, (10, )) + self.assertEqual(result_dict["temperature"].shape, (10,)) + self.assertEqual(result_dict["energy_pot"].shape, (10,)) + self.assertEqual(result_dict["energy_tot"].shape, (10,)) self.assertEqual(result_dict["pressure"].shape, (10, 3, 3)) self.assertTrue(result_dict["temperature"][-1] > 90) self.assertTrue(result_dict["temperature"][-1] < 110) @@ -145,7 +145,7 @@ def test_lammps_md_nph_all(self): def test_lammps_md_langevin_all(self): structure = bulk("Al", cubic=True).repeat([2, 2, 2]) df_pot_selected = get_potential_by_name( - potential_name='1999--Mishin-Y--Al--LAMMPS--ipr1', + potential_name="1999--Mishin-Y--Al--LAMMPS--ipr1", resource_path=os.path.join(os.path.dirname(__file__), "static", "lammps"), ) result_dict = calc_molecular_dynamics_langevin_with_lammps( @@ -165,16 +165,18 @@ def test_lammps_md_langevin_all(self): self.assertEqual(result_dict["velocities"].shape, (10, 32, 3)) self.assertEqual(result_dict["cell"].shape, (10, 3, 3)) self.assertEqual(result_dict["forces"].shape, (10, 32, 3)) - self.assertEqual(result_dict["temperature"].shape, (10, )) - self.assertEqual(result_dict["energy_pot"].shape, (10, )) - self.assertEqual(result_dict["energy_tot"].shape, (10, )) + self.assertEqual(result_dict["temperature"].shape, (10,)) + self.assertEqual(result_dict["energy_pot"].shape, (10,)) + self.assertEqual(result_dict["energy_tot"].shape, (10,)) self.assertEqual(result_dict["pressure"].shape, (10, 3, 3)) self.assertTrue(result_dict["temperature"][-1] > 90) self.assertTrue(result_dict["temperature"][-1] < 130) def test_calc_molecular_dynamics_signature(self): self.assertEqual( - inspect.signature(calc_molecular_dynamics_nvt_with_lammps).parameters["output_keys"].default, + inspect.signature(calc_molecular_dynamics_nvt_with_lammps) + .parameters["output_keys"] + .default, ( "positions", "cell", @@ -185,6 +187,5 @@ def test_calc_molecular_dynamics_signature(self): "pressure", "velocities", "volume", - ) - + ), ) diff --git a/tests/test_lammps_md_phonons.py b/tests/test_lammps_md_phonons.py index 89808b5f..56ccdc8a 100644 --- a/tests/test_lammps_md_phonons.py +++ b/tests/test_lammps_md_phonons.py @@ -9,7 +9,9 @@ try: from atomistics.calculators import ( - calc_molecular_dynamics_phonons_with_lammps, evaluate_with_lammps, get_potential_by_name + calc_molecular_dynamics_phonons_with_lammps, + evaluate_with_lammps, + get_potential_by_name, ) skip_lammps_test = False @@ -24,7 +26,7 @@ class TestLammpsMD(unittest.TestCase): def test_lammps_md_nvt_all(self): structure = bulk("Si", cubic=True) potential_dataframe = get_potential_by_name( - potential_name='1988--Tersoff-J--Si-c--LAMMPS--ipr1', + potential_name="1988--Tersoff-J--Si-c--LAMMPS--ipr1", resource_path=os.path.join(os.path.dirname(__file__), "static", "lammps"), ) workflow = PhonopyWorkflow( @@ -60,4 +62,4 @@ def test_lammps_md_nvt_all(self): ) self.assertEqual(trajectory.get_number_of_atoms(), 64) self.assertEqual(trajectory.velocity.shape, (20000, 64, 3)) - self.assertEqual(len(trajectory.get_time()), 20000) \ No newline at end of file + self.assertEqual(len(trajectory.get_time()), 20000) diff --git a/tests/test_langevin_lammps.py b/tests/test_langevin_lammps.py index ec3731ab..673cc881 100644 --- a/tests/test_langevin_lammps.py +++ b/tests/test_langevin_lammps.py @@ -9,7 +9,9 @@ try: from atomistics.calculators import ( - evaluate_with_lammps_library, get_potential_by_name, LammpsASELibrary + evaluate_with_lammps_library, + get_potential_by_name, + LammpsASELibrary, ) skip_lammps_test = False @@ -25,7 +27,7 @@ def test_langevin(self): steps = 300 structure = bulk("Al", cubic=True).repeat([2, 2, 2]) df_pot_selected = get_potential_by_name( - potential_name='1999--Mishin-Y--Al--LAMMPS--ipr1', + potential_name="1999--Mishin-Y--Al--LAMMPS--ipr1", resource_path=os.path.join(os.path.dirname(__file__), "static", "lammps"), ) workflow = LangevinWorkflow( diff --git a/tests/test_molecular_dynamics_thermal_expansion_lammps.py b/tests/test_molecular_dynamics_thermal_expansion_lammps.py index eaf3d43c..56727c0d 100644 --- a/tests/test_molecular_dynamics_thermal_expansion_lammps.py +++ b/tests/test_molecular_dynamics_thermal_expansion_lammps.py @@ -29,7 +29,7 @@ class TestMolecularDynamicsThermalExpansion(unittest.TestCase): def test_calc_thermal_expansion_using_evaluate(self): structure = bulk("Al", cubic=True) df_pot_selected = get_potential_by_name( - potential_name='1999--Mishin-Y--Al--LAMMPS--ipr1', + potential_name="1999--Mishin-Y--Al--LAMMPS--ipr1", resource_path=os.path.join(os.path.dirname(__file__), "static", "lammps"), ) task_dict = calc_molecular_dynamics_thermal_expansion(structure=structure) @@ -40,10 +40,10 @@ def test_calc_thermal_expansion_using_evaluate(self): "Tstart": 50, "Tstop": 500, "Tstep": 50, - } + }, ) - temperature_lst = result_dict['volume_over_temperature'][0] - volume_lst = result_dict['volume_over_temperature'][1] + temperature_lst = result_dict["volume_over_temperature"][0] + volume_lst = result_dict["volume_over_temperature"][1] self.assertTrue(all(np.array(temperature_lst) < 600)) self.assertTrue(all(np.array(temperature_lst) > 0)) self.assertTrue(volume_lst[0] < volume_lst[-1]) @@ -51,7 +51,7 @@ def test_calc_thermal_expansion_using_evaluate(self): def test_calc_thermal_expansion_using_calc(self): structure = bulk("Al", cubic=True) df_pot_selected = get_potential_by_name( - potential_name='1999--Mishin-Y--Al--LAMMPS--ipr1', + potential_name="1999--Mishin-Y--Al--LAMMPS--ipr1", resource_path=os.path.join(os.path.dirname(__file__), "static", "lammps"), ) results_dict = calc_molecular_dynamics_thermal_expansion_with_lammps( @@ -77,10 +77,7 @@ def test_calc_thermal_expansion_using_calc(self): def test_calc_thermal_expansion_using_ase(self): structure = bulk("Al", cubic=True) - cmds = [ - "pair_style morse/smooth/linear 9.0", - "pair_coeff * * 0.5 1.8 2.95" - ] + cmds = ["pair_style morse/smooth/linear 9.0", "pair_coeff * * 0.5 1.8 2.95"] results_dict = calc_molecular_dynamics_thermal_expansion_with_ase( structure=structure.copy(), ase_calculator=LAMMPSlib( @@ -95,7 +92,7 @@ def test_calc_thermal_expansion_using_ase(self): thermo=100, timestep=1 * units.fs, ttime=100 * units.fs, - pfactor=2e6 * units.GPa * (units.fs ** 2), + pfactor=2e6 * units.GPa * (units.fs**2), externalstress=np.array([0.0, 0.0, 0.0, 0.0, 0.0, 0.0]) * units.bar, ) self.assertTrue(all(np.array(results_dict["temperatures"]) < 600)) diff --git a/tests/test_optimize_positions_ase_emt.py b/tests/test_optimize_positions_ase_emt.py index 56b2c697..7a5c7abf 100644 --- a/tests/test_optimize_positions_ase_emt.py +++ b/tests/test_optimize_positions_ase_emt.py @@ -18,13 +18,14 @@ def test_optimize_positions(self): task_dict=task_dict, ase_calculator=EMT(), ase_optimizer=BFGS, - ase_optimizer_kwargs={"fmax": 0.000001} + ase_optimizer_kwargs={"fmax": 0.000001}, ) structure_optimized = result_dict["structure_with_optimized_positions"] self.assertTrue( - all(np.isclose( - positions_before_displacement, - structure_optimized.positions-structure_optimized.positions[0], - ).flatten()) + all( + np.isclose( + positions_before_displacement, + structure_optimized.positions - structure_optimized.positions[0], + ).flatten() + ) ) - diff --git a/tests/test_optimize_positions_lammps.py b/tests/test_optimize_positions_lammps.py index c7e62036..119652af 100644 --- a/tests/test_optimize_positions_lammps.py +++ b/tests/test_optimize_positions_lammps.py @@ -7,9 +7,7 @@ from atomistics.workflows import optimize_positions try: - from atomistics.calculators import ( - evaluate_with_lammps, get_potential_by_name - ) + from atomistics.calculators import evaluate_with_lammps, get_potential_by_name skip_lammps_test = False except ImportError: @@ -40,14 +38,16 @@ def test_optimize_positions_with_resource_path(self): structure.positions[0] += [0.01, 0.01, 0.01] structure_optimized = optimize_structure( structure=structure, - potential_name='1999--Mishin-Y--Al--LAMMPS--ipr1', + potential_name="1999--Mishin-Y--Al--LAMMPS--ipr1", resource_path=os.path.join(os.path.dirname(__file__), "static", "lammps"), ) self.assertTrue( - all(np.isclose( - positions_before_displacement, - structure_optimized.positions-structure_optimized.positions[0], - ).flatten()) + all( + np.isclose( + positions_before_displacement, + structure_optimized.positions - structure_optimized.positions[0], + ).flatten() + ) ) def test_optimize_positions_without_resource_path(self): @@ -56,12 +56,14 @@ def test_optimize_positions_without_resource_path(self): structure.positions[0] += [0.01, 0.01, 0.01] structure_optimized = optimize_structure( structure=structure, - potential_name='1999--Mishin-Y--Al--LAMMPS--ipr1', + potential_name="1999--Mishin-Y--Al--LAMMPS--ipr1", resource_path=None, ) self.assertTrue( - all(np.isclose( - positions_before_displacement, - structure_optimized.positions-structure_optimized.positions[0], - ).flatten()) + all( + np.isclose( + positions_before_displacement, + structure_optimized.positions - structure_optimized.positions[0], + ).flatten() + ) ) diff --git a/tests/test_phonons_ase_emt.py b/tests/test_phonons_ase_emt.py index ea4aa04f..440b5869 100644 --- a/tests/test_phonons_ase_emt.py +++ b/tests/test_phonons_ase_emt.py @@ -16,7 +16,7 @@ def test_calc_phonons(self): task_dict=task_dict, ase_calculator=EMT(), ase_optimizer=LBFGS, - ase_optimizer_kwargs={"fmax": 0.000001} + ase_optimizer_kwargs={"fmax": 0.000001}, ) workflow = PhonopyWorkflow( structure=result_dict["structure_with_optimized_positions_and_volume"], @@ -32,10 +32,10 @@ def test_calc_phonons(self): phonopy_dict = workflow.analyse_structures(output_dict=result_dict) mesh_dict, dos_dict = phonopy_dict["mesh_dict"], phonopy_dict["total_dos_dict"] self.assertEqual((324, 324), workflow.get_hesse_matrix().shape) - self.assertTrue('qpoints' in mesh_dict.keys()) - self.assertTrue('weights' in mesh_dict.keys()) - self.assertTrue('frequencies' in mesh_dict.keys()) - self.assertTrue('eigenvectors' in mesh_dict.keys()) - self.assertTrue('group_velocities' in mesh_dict.keys()) - self.assertTrue('frequency_points' in dos_dict.keys()) - self.assertTrue('total_dos' in dos_dict.keys()) + self.assertTrue("qpoints" in mesh_dict.keys()) + self.assertTrue("weights" in mesh_dict.keys()) + self.assertTrue("frequencies" in mesh_dict.keys()) + self.assertTrue("eigenvectors" in mesh_dict.keys()) + self.assertTrue("group_velocities" in mesh_dict.keys()) + self.assertTrue("frequency_points" in dos_dict.keys()) + self.assertTrue("total_dos" in dos_dict.keys()) diff --git a/tests/test_phonons_lammps.py b/tests/test_phonons_lammps.py index 7e1b451e..3ed8ee7b 100644 --- a/tests/test_phonons_lammps.py +++ b/tests/test_phonons_lammps.py @@ -7,9 +7,7 @@ from atomistics.workflows import PhonopyWorkflow, optimize_positions_and_volume try: - from atomistics.calculators import ( - evaluate_with_lammps, get_potential_by_name - ) + from atomistics.calculators import evaluate_with_lammps, get_potential_by_name skip_lammps_test = False except ImportError: @@ -23,7 +21,7 @@ class TestPhonons(unittest.TestCase): def test_calc_phonons(self): structure = bulk("Al", cubic=True) df_pot_selected = get_potential_by_name( - potential_name='1999--Mishin-Y--Al--LAMMPS--ipr1', + potential_name="1999--Mishin-Y--Al--LAMMPS--ipr1", resource_path=os.path.join(os.path.dirname(__file__), "static", "lammps"), ) task_dict = optimize_positions_and_volume(structure=structure) @@ -48,13 +46,13 @@ def test_calc_phonons(self): phonopy_dict = workflow.analyse_structures(output_dict=result_dict) mesh_dict, dos_dict = phonopy_dict["mesh_dict"], phonopy_dict["total_dos_dict"] self.assertEqual((324, 324), workflow.get_hesse_matrix().shape) - self.assertTrue('qpoints' in mesh_dict.keys()) - self.assertTrue('weights' in mesh_dict.keys()) - self.assertTrue('frequencies' in mesh_dict.keys()) - self.assertTrue('eigenvectors' in mesh_dict.keys()) - self.assertTrue('group_velocities' in mesh_dict.keys()) - self.assertTrue('frequency_points' in dos_dict.keys()) - self.assertTrue('total_dos' in dos_dict.keys()) + self.assertTrue("qpoints" in mesh_dict.keys()) + self.assertTrue("weights" in mesh_dict.keys()) + self.assertTrue("frequencies" in mesh_dict.keys()) + self.assertTrue("eigenvectors" in mesh_dict.keys()) + self.assertTrue("group_velocities" in mesh_dict.keys()) + self.assertTrue("frequency_points" in dos_dict.keys()) + self.assertTrue("total_dos" in dos_dict.keys()) thermal_dict = workflow.get_thermal_properties( t_min=1, t_max=1500, @@ -65,7 +63,13 @@ def test_calc_phonons(self): band_indices=None, is_projection=False, ) - for key in ["temperatures", "free_energy", "volumes", "entropy", "heat_capacity"]: + for key in [ + "temperatures", + "free_energy", + "volumes", + "entropy", + "heat_capacity", + ]: self.assertTrue(len(thermal_dict[key]), 31) self.assertEqual(thermal_dict["temperatures"][0], 1.0) self.assertEqual(thermal_dict["temperatures"][-1], 1501.0) @@ -94,7 +98,7 @@ def test_calc_phonons(self): pretend_real=False, band_indices=None, is_projection=False, - output_keys=["temperatures", "free_energy"] + output_keys=["temperatures", "free_energy"], ) self.assertEqual(len(thermal_dict.keys()), 2) self.assertEqual(thermal_dict["temperatures"][0], 1.0) diff --git a/tests/test_phonons_lammps_functional.py b/tests/test_phonons_lammps_functional.py index 5bc89d1b..66650330 100644 --- a/tests/test_phonons_lammps_functional.py +++ b/tests/test_phonons_lammps_functional.py @@ -12,9 +12,7 @@ ) try: - from atomistics.calculators import ( - evaluate_with_lammps, get_potential_by_name - ) + from atomistics.calculators import evaluate_with_lammps, get_potential_by_name skip_lammps_test = False except ImportError: @@ -28,7 +26,7 @@ class TestPhonons(unittest.TestCase): def test_calc_phonons(self): structure = bulk("Al", cubic=True) df_pot_selected = get_potential_by_name( - potential_name='1999--Mishin-Y--Al--LAMMPS--ipr1', + potential_name="1999--Mishin-Y--Al--LAMMPS--ipr1", resource_path=os.path.join(os.path.dirname(__file__), "static", "lammps"), ) result_dict = evaluate_with_lammps( @@ -54,14 +52,17 @@ def test_calc_phonons(self): number_of_snapshots=None, ) mesh_dict, dos_dict = phonopy_dict["mesh_dict"], phonopy_dict["total_dos_dict"] - self.assertEqual((324, 324), get_hesse_matrix(force_constants=phonopy_obj.force_constants).shape) - self.assertTrue('qpoints' in mesh_dict.keys()) - self.assertTrue('weights' in mesh_dict.keys()) - self.assertTrue('frequencies' in mesh_dict.keys()) - self.assertTrue('eigenvectors' in mesh_dict.keys()) - self.assertTrue('group_velocities' in mesh_dict.keys()) - self.assertTrue('frequency_points' in dos_dict.keys()) - self.assertTrue('total_dos' in dos_dict.keys()) + self.assertEqual( + (324, 324), + get_hesse_matrix(force_constants=phonopy_obj.force_constants).shape, + ) + self.assertTrue("qpoints" in mesh_dict.keys()) + self.assertTrue("weights" in mesh_dict.keys()) + self.assertTrue("frequencies" in mesh_dict.keys()) + self.assertTrue("eigenvectors" in mesh_dict.keys()) + self.assertTrue("group_velocities" in mesh_dict.keys()) + self.assertTrue("frequency_points" in dos_dict.keys()) + self.assertTrue("total_dos" in dos_dict.keys()) thermal_dict = get_thermal_properties( phonopy=phonopy_obj, t_min=1, @@ -73,7 +74,13 @@ def test_calc_phonons(self): band_indices=None, is_projection=False, ) - for key in ["temperatures", "free_energy", "volumes", "entropy", "heat_capacity"]: + for key in [ + "temperatures", + "free_energy", + "volumes", + "entropy", + "heat_capacity", + ]: self.assertTrue(len(thermal_dict[key]), 31) self.assertEqual(thermal_dict["temperatures"][0], 1.0) self.assertEqual(thermal_dict["temperatures"][-1], 1501.0) @@ -103,7 +110,7 @@ def test_calc_phonons(self): pretend_real=False, band_indices=None, is_projection=False, - output_keys=["temperatures", "free_energy"] + output_keys=["temperatures", "free_energy"], ) self.assertEqual(len(thermal_dict.keys()), 2) self.assertEqual(thermal_dict["temperatures"][0], 1.0) diff --git a/tests/test_quasiharmonic_ase_emt.py b/tests/test_quasiharmonic_ase_emt.py index e8e6df64..3b2074ad 100644 --- a/tests/test_quasiharmonic_ase_emt.py +++ b/tests/test_quasiharmonic_ase_emt.py @@ -16,7 +16,7 @@ def test_calc_phonons(self): task_dict=task_dict, ase_calculator=EMT(), ase_optimizer=LBFGS, - ase_optimizer_kwargs={"fmax": 0.000001} + ase_optimizer_kwargs={"fmax": 0.000001}, ) workflow = QuasiHarmonicWorkflow( structure=result_dict["structure_with_optimized_positions_and_volume"], @@ -30,24 +30,31 @@ def test_calc_phonons(self): number_of_snapshots=None, ) task_dict = workflow.generate_structures() - result_dict = evaluate_with_ase( - task_dict=task_dict, - ase_calculator=EMT() + result_dict = evaluate_with_ase(task_dict=task_dict, ase_calculator=EMT()) + eng_internal_dict, phonopy_collect_dict = workflow.analyse_structures( + output_dict=result_dict + ) + tp_collect_dict = workflow.get_thermal_properties( + t_min=1, t_max=1500, t_step=50, temperatures=None ) - eng_internal_dict, phonopy_collect_dict = workflow.analyse_structures(output_dict=result_dict) - tp_collect_dict = workflow.get_thermal_properties(t_min=1, t_max=1500, t_step=50, temperatures=None) thermal_properties_dict = workflow.get_thermal_properties( temperatures=[100, 1000], output_keys=["temperatures", "volumes"], - quantum_mechanical=True + quantum_mechanical=True, + ) + temperatures_qh_qm, volumes_qh_qm = ( + thermal_properties_dict["temperatures"], + thermal_properties_dict["volumes"], ) - temperatures_qh_qm, volumes_qh_qm = thermal_properties_dict["temperatures"], thermal_properties_dict["volumes"] thermal_properties_dict = workflow.get_thermal_properties( temperatures=[100, 1000], output_keys=["temperatures", "volumes"], - quantum_mechanical=False + quantum_mechanical=False, + ) + temperatures_qh_cl, volumes_qh_cl = ( + thermal_properties_dict["temperatures"], + thermal_properties_dict["volumes"], ) - temperatures_qh_cl, volumes_qh_cl = thermal_properties_dict["temperatures"], thermal_properties_dict["volumes"] self.assertEqual(len(eng_internal_dict.keys()), 11) self.assertEqual(len(tp_collect_dict.keys()), 5) self.assertEqual(len(temperatures_qh_qm), 2) diff --git a/tests/test_quasiharmonic_lammps.py b/tests/test_quasiharmonic_lammps.py index 1d1380b2..47e1a36a 100644 --- a/tests/test_quasiharmonic_lammps.py +++ b/tests/test_quasiharmonic_lammps.py @@ -7,9 +7,7 @@ from atomistics.workflows import QuasiHarmonicWorkflow, optimize_positions_and_volume try: - from atomistics.calculators import ( - evaluate_with_lammps, get_potential_by_name - ) + from atomistics.calculators import evaluate_with_lammps, get_potential_by_name skip_lammps_test = False except ImportError: @@ -23,7 +21,7 @@ class TestPhonons(unittest.TestCase): def test_calc_phonons(self): structure = bulk("Al", cubic=True) df_pot_selected = get_potential_by_name( - potential_name='1999--Mishin-Y--Al--LAMMPS--ipr1', + potential_name="1999--Mishin-Y--Al--LAMMPS--ipr1", resource_path=os.path.join(os.path.dirname(__file__), "static", "lammps"), ) task_dict = optimize_positions_and_volume(structure=structure) @@ -47,9 +45,19 @@ def test_calc_phonons(self): task_dict=task_dict, potential_dataframe=df_pot_selected, ) - eng_internal_dict, phonopy_collect_dict = workflow.analyse_structures(output_dict=result_dict) - tp_collect_dict = workflow.get_thermal_properties(t_min=1, t_max=1500, t_step=50, temperatures=None) - for key in ["temperatures", "free_energy", "volumes", "entropy", "heat_capacity"]: + eng_internal_dict, phonopy_collect_dict = workflow.analyse_structures( + output_dict=result_dict + ) + tp_collect_dict = workflow.get_thermal_properties( + t_min=1, t_max=1500, t_step=50, temperatures=None + ) + for key in [ + "temperatures", + "free_energy", + "volumes", + "entropy", + "heat_capacity", + ]: self.assertTrue(len(tp_collect_dict[key]), 31) self.assertEqual(tp_collect_dict["temperatures"][0], 1.0) self.assertEqual(tp_collect_dict["temperatures"][-1], 1501.0) @@ -72,15 +80,21 @@ def test_calc_phonons(self): thermal_properties_dict = workflow.get_thermal_properties( temperatures=[100, 1000], output_keys=["temperatures", "volumes"], - quantum_mechanical=True + quantum_mechanical=True, + ) + temperatures_qh_qm, volumes_qh_qm = ( + thermal_properties_dict["temperatures"], + thermal_properties_dict["volumes"], ) - temperatures_qh_qm, volumes_qh_qm = thermal_properties_dict["temperatures"], thermal_properties_dict["volumes"] thermal_properties_dict = workflow.get_thermal_properties( temperatures=[100, 1000], output_keys=["temperatures", "volumes"], - quantum_mechanical=False + quantum_mechanical=False, + ) + temperatures_qh_cl, volumes_qh_cl = ( + thermal_properties_dict["temperatures"], + thermal_properties_dict["volumes"], ) - temperatures_qh_cl, volumes_qh_cl = thermal_properties_dict["temperatures"], thermal_properties_dict["volumes"] self.assertEqual(len(eng_internal_dict.keys()), 11) self.assertEqual(len(tp_collect_dict.keys()), 5) self.assertEqual(len(temperatures_qh_qm), 2) diff --git a/tests/test_quasiharmonic_lammps_functional.py b/tests/test_quasiharmonic_lammps_functional.py index db3b2e36..a8adf9df 100644 --- a/tests/test_quasiharmonic_lammps_functional.py +++ b/tests/test_quasiharmonic_lammps_functional.py @@ -12,9 +12,7 @@ ) try: - from atomistics.calculators import ( - evaluate_with_lammps, get_potential_by_name - ) + from atomistics.calculators import evaluate_with_lammps, get_potential_by_name skip_lammps_test = False except ImportError: @@ -28,25 +26,30 @@ class TestPhonons(unittest.TestCase): def test_calc_phonons(self): structure = bulk("Al", cubic=True) df_pot_selected = get_potential_by_name( - potential_name='1999--Mishin-Y--Al--LAMMPS--ipr1', + potential_name="1999--Mishin-Y--Al--LAMMPS--ipr1", resource_path=os.path.join(os.path.dirname(__file__), "static", "lammps"), ) result_dict = evaluate_with_lammps( task_dict={"optimize_positions_and_volume": structure}, potential_dataframe=df_pot_selected, ) - phonopy_dict, repeat_vector, structure_energy_dict, structure_forces_dict = generate_structures_helper( - structure=result_dict["structure_with_optimized_positions_and_volume"], - vol_range=0.05, - num_points=11, - strain_lst=None, - displacement=0.01, - number_of_snapshots=None, - interaction_range=10, - factor=VaspToTHz, + phonopy_dict, repeat_vector, structure_energy_dict, structure_forces_dict = ( + generate_structures_helper( + structure=result_dict["structure_with_optimized_positions_and_volume"], + vol_range=0.05, + num_points=11, + strain_lst=None, + displacement=0.01, + number_of_snapshots=None, + interaction_range=10, + factor=VaspToTHz, + ) ) result_dict = evaluate_with_lammps( - task_dict={"calc_energy": structure_energy_dict, "calc_forces": structure_forces_dict}, + task_dict={ + "calc_energy": structure_energy_dict, + "calc_forces": structure_forces_dict, + }, potential_dataframe=df_pot_selected, ) eng_internal_dict, phonopy_collect_dict = analyse_structures_helper( @@ -67,7 +70,13 @@ def test_calc_phonons(self): t_step=50, temperatures=None, ) - for key in ["temperatures", "free_energy", "volumes", "entropy", "heat_capacity"]: + for key in [ + "temperatures", + "free_energy", + "volumes", + "entropy", + "heat_capacity", + ]: self.assertTrue(len(tp_collect_dict[key]), 31) self.assertEqual(tp_collect_dict["temperatures"][0], 1.0) self.assertEqual(tp_collect_dict["temperatures"][-1], 1501.0) @@ -98,7 +107,10 @@ def test_calc_phonons(self): output_keys=["free_energy", "temperatures", "volumes"], quantum_mechanical=True, ) - temperatures_qh_qm, volumes_qh_qm = thermal_properties_dict["temperatures"], thermal_properties_dict["volumes"] + temperatures_qh_qm, volumes_qh_qm = ( + thermal_properties_dict["temperatures"], + thermal_properties_dict["volumes"], + ) thermal_properties_dict = get_thermal_properties( eng_internal_dict=eng_internal_dict, phonopy_dict=phonopy_dict, @@ -110,7 +122,10 @@ def test_calc_phonons(self): output_keys=["temperatures", "volumes"], quantum_mechanical=False, ) - temperatures_qh_cl, volumes_qh_cl = thermal_properties_dict["temperatures"], thermal_properties_dict["volumes"] + temperatures_qh_cl, volumes_qh_cl = ( + thermal_properties_dict["temperatures"], + thermal_properties_dict["volumes"], + ) self.assertEqual(len(eng_internal_dict.keys()), 11) self.assertEqual(len(tp_collect_dict.keys()), 5) self.assertEqual(len(temperatures_qh_qm), 2)