From 7ca8d98f93969cfe0defba5510ca4d5868e5b78b Mon Sep 17 00:00:00 2001 From: "nathan.daelman@physik.hu-berlin.de" Date: Wed, 21 Feb 2024 15:15:15 +0100 Subject: [PATCH] - Apply `ruff format .`: -- affected: testers + phonopy/calculator.py -- local tests all pass --- tests/conftest.py | 3 +- tests/test_aflowparser.py | 44 +++++--- tests/test_asrparser.py | 18 +-- tests/test_atomateparser.py | 12 +- tests/test_elasticparser.py | 52 +++++---- tests/test_fhivibesparser.py | 70 +++++++----- tests/test_lobsterparser.py | 143 ++++++++++++++---------- tests/test_phonopyparser.py | 10 +- tests/test_quantum_espresso_epw.py | 4 +- tests/test_quantum_espresso_phonon.py | 4 +- tests/test_quantum_espresso_xspectra.py | 42 ++++--- workflowparsers/phonopy/calculator.py | 76 +++++++------ 12 files changed, 288 insertions(+), 190 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index f66c4c8..db67f96 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -18,8 +18,9 @@ # import os import pytest + # Set up pytest to pass control to the debugger on an exception. -if os.getenv('_PYTEST_RAISE', "0") != "0": +if os.getenv("_PYTEST_RAISE", "0") != "0": @pytest.hookimpl(tryfirst=True) def pytest_exception_interact(call): diff --git a/tests/test_aflowparser.py b/tests/test_aflowparser.py index 1f5545f..eea5ec5 100644 --- a/tests/test_aflowparser.py +++ b/tests/test_aflowparser.py @@ -26,37 +26,41 @@ def approx(value, abs=0, rel=1e-6): return pytest.approx(value, abs=abs, rel=rel) -@pytest.fixture(scope='module') +@pytest.fixture(scope="module") def parser(): return AFLOWParser() def test_aflowlib(parser): archive = EntryArchive() - parser.parse('tests/data/aflow/Ag1Co1O2_ICSD_246157/aflowlib.json', archive, None) + parser.parse("tests/data/aflow/Ag1Co1O2_ICSD_246157/aflowlib.json", archive, None) assert len(archive.run) == 3 - assert archive.run[0].program.version == 'aflow30847' - assert archive.run[0].x_aflow_auid == 'aflow:fbc2cf03b9659c90' + assert archive.run[0].program.version == "aflow30847" + assert archive.run[0].x_aflow_auid == "aflow:fbc2cf03b9659c90" sec_system = archive.run[0].system[0] assert sec_system.atoms.lattice_vectors[1][0].magnitude == approx(-1.45323479e-10) - assert sec_system.x_aflow_Pearson_symbol_superlattice == 'hP8' - assert list(sec_system.x_aflow_Wyckoff_letters_orig) == [['c'], ['a'], ['f']] + assert sec_system.x_aflow_Pearson_symbol_superlattice == "hP8" + assert list(sec_system.x_aflow_Wyckoff_letters_orig) == [["c"], ["a"], ["f"]] sec_method = archive.run[0].method[0] assert sec_method.x_aflow_delta_electronic_energy_convergence == approx(3.06569e-05) sec_calculation = archive.run[0].calculation[0] assert sec_calculation.energy.total.value.magnitude == approx(-5.58872856e-18) assert sec_calculation.forces.total.value[0][1].magnitude == approx(-2.14691669e-13) - assert sec_calculation.thermodynamics[0].enthalpy.magnitude == approx(-5.58872856e-18) + assert sec_calculation.thermodynamics[0].enthalpy.magnitude == approx( + -5.58872856e-18 + ) assert sec_calculation.x_aflow_pressure_residual == approx(2.95) run = archive.run[1] assert len(run.system) == len(run.calculation) == 24 - assert run.system[7].atoms.labels[6] == 'O' - assert run.system[21].atoms.lattice_vectors[0][1].magnitude == approx(-2.5241880209758e-10) + assert run.system[7].atoms.labels[6] == "O" + assert run.system[21].atoms.lattice_vectors[0][1].magnitude == approx( + -2.5241880209758e-10 + ) assert run.calculation[15].energy.total.value.magnitude == approx(-6.9854741e-19) - assert run.calculation[9].stress.total.value[2][2].magnitude == approx(-1.594e+08) + assert run.calculation[9].stress.total.value[2][2].magnitude == approx(-1.594e08) # TODO currently workflow is not a repeating section # assert archive.workflow.results.n_deformations == 3 # assert archive.workflow.results.strain_maximum == pytest.approx(0.01) @@ -68,7 +72,7 @@ def test_aflowlib(parser): run = archive.run[2] assert len(run.system) == len(run.calculation) == 28 assert run.system[3].atoms.positions[3][2].magnitude == approx(5.53515521e-10) - assert run.calculation[19].thermodynamics[0].pressure.magnitude == (-1.6886e+09) + assert run.calculation[19].thermodynamics[0].pressure.magnitude == (-1.6886e09) sec_thermo = archive.workflow2.results assert sec_thermo.temperature[12].magnitude == 120 # assert sec_thermo.thermal_conductivity[18].magnitude == approx(4.924586) @@ -79,24 +83,30 @@ def test_aflowlib(parser): def test_aflowin(parser): archive = EntryArchive() - parser.parse('tests/data/aflow/MgO/aflow.in', archive, None) + parser.parse("tests/data/aflow/MgO/aflow.in", archive, None) assert len(archive.run) == 2 - assert archive.run[0].program.version == '3.2.1' + assert archive.run[0].program.version == "3.2.1" sec_system = archive.run[0].system[0] assert sec_system.atoms.lattice_vectors[1][2].magnitude == approx(2.1277509e-10) assert sec_system.atoms.positions[1][1].magnitude == approx(2.1277509e-10) sec_scc = archive.run[1].calculation[0] assert sec_scc.dos_phonon[0].energies[80].magnitude == approx(5.71011064e-22) - assert sec_scc.dos_phonon[0].total[0].value[1866].magnitude == approx(2.06688135e+20) + assert sec_scc.dos_phonon[0].total[0].value[1866].magnitude == approx(2.06688135e20) assert len(sec_scc.band_structure_phonon[0].segment) == 10 - assert sec_scc.band_structure_phonon[0].segment[3].kpoints[7][1] == approx(1.02984830) - assert sec_scc.band_structure_phonon[0].segment[9].energies[0][10][3].magnitude == approx(1.92480691e-21) + assert sec_scc.band_structure_phonon[0].segment[3].kpoints[7][1] == approx( + 1.02984830 + ) + assert sec_scc.band_structure_phonon[0].segment[9].energies[0][10][ + 3 + ].magnitude == approx(1.92480691e-21) assert archive.workflow2.results.qpoints[9249][0] == approx(-4.7619047619e-02) - assert archive.workflow2.results.group_velocity[234][2][0].magnitude == approx(-133.348333) + assert archive.workflow2.results.group_velocity[234][2][0].magnitude == approx( + -133.348333 + ) # TODO currently workflow is not a repeating section # assert archive.workflow.results.temperature[161].magnitude == approx(1610) diff --git a/tests/test_asrparser.py b/tests/test_asrparser.py index 9cad6ad..088217a 100644 --- a/tests/test_asrparser.py +++ b/tests/test_asrparser.py @@ -28,7 +28,7 @@ # TODO this does not work for the current version of ASR -tests_path = 'tests/data/asr' +tests_path = "tests/data/asr" def approx(value, abs=0, rel=1e-6): @@ -37,21 +37,25 @@ def approx(value, abs=0, rel=1e-6): def clear_database(): try: - subprocess.Popen('rm -rf %s/.asr' % tests_path) + subprocess.Popen("rm -rf %s/.asr" % tests_path) except Exception: pass -@pytest.fixture(scope='module') +@pytest.fixture(scope="module") def test_database(): # TODO not sure how to do this properly cwd = os.getcwd() try: os.chdir(tests_path) - subprocess.Popen(['asr', 'init'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) subprocess.Popen( - ['asr', 'run', 'asr.c2db.relax -a Si.json -c {"name":"emt"}'], - stdout=subprocess.PIPE, stderr=subprocess.PIPE) + ["asr", "init"], stdout=subprocess.PIPE, stderr=subprocess.PIPE + ) + subprocess.Popen( + ["asr", "run", 'asr.c2db.relax -a Si.json -c {"name":"emt"}'], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) except Exception: pass finally: @@ -60,7 +64,7 @@ def test_database(): def test_parsing(test_database): asr_to_archives(tests_path) - archive_files = [f for f in os.listdir(tests_path) if f.startswith('archive_')] + archive_files = [f for f in os.listdir(tests_path) if f.startswith("archive_")] # assert len(archive_files) > 0 for f in archive_files: data = json.load(open(os.path.join(tests_path, f))) diff --git a/tests/test_atomateparser.py b/tests/test_atomateparser.py index 03ef487..12cf822 100644 --- a/tests/test_atomateparser.py +++ b/tests/test_atomateparser.py @@ -27,27 +27,27 @@ def approx(value, abs=0, rel=1e-6): return pytest.approx(value, abs=abs, rel=rel) -@pytest.fixture(scope='module') +@pytest.fixture(scope="module") def parser(): return AtomateParser() def test_all(parser): archive = EntryArchive() - parser.parse('tests/data/atomate/mp-149/mp-149_materials.json', archive, None) + parser.parse("tests/data/atomate/mp-149/mp-149_materials.json", archive, None) run = archive.run[0] - assert run.program.name == 'MaterialsProject' + assert run.program.name == "MaterialsProject" sec_system = run.system[0] - assert sec_system.atoms.labels == ['Si', 'Si'] + assert sec_system.atoms.labels == ["Si", "Si"] assert sec_system.atoms.lattice_vectors[1][2].magnitude == approx(2.734364e-10) assert sec_system.atoms.positions[0][0].magnitude == approx(1.367182e-10) assert sec_system.x_mp_composition_reduced[0].x_mp_value == approx(1.0) assert sec_system.x_mp_symmetry[0].x_mp_symprec == approx(0.1) - assert sec_system.x_mp_elements[0] == 'Si' + assert sec_system.x_mp_elements[0] == "Si" assert sec_system.x_mp_volume == approx(40.88829284866483) - assert sec_system.x_mp_formula_anonymous == 'A' + assert sec_system.x_mp_formula_anonymous == "A" # TODO currently, workflow2 is not repeating # TODO error loading metainfo in github action diff --git a/tests/test_elasticparser.py b/tests/test_elasticparser.py index 2028390..aa60032 100644 --- a/tests/test_elasticparser.py +++ b/tests/test_elasticparser.py @@ -27,14 +27,14 @@ def approx(value, abs=0, rel=1e-6): return pytest.approx(value, abs=abs, rel=rel) -@pytest.fixture(scope='module') +@pytest.fixture(scope="module") def parser(): return ElasticParser() def test_2nd(parser): archive = EntryArchive() - parser.parse('tests/data/elastic/2nd/INFO_ElaStic', archive, None) + parser.parse("tests/data/elastic/2nd/INFO_ElaStic", archive, None) sec_system = archive.run[0].system[0] assert np.shape(sec_system.atoms.positions) == (8, 3) @@ -46,34 +46,36 @@ def test_2nd(parser): sec_fit_parameters = sec_method.x_elastic_section_fitting_parameters[0] assert sec_fit_parameters.x_elastic_fitting_parameters_eta[0] == 0.05 - assert archive.workflow2.method.energy_stress_calculator == 'exciting' + assert archive.workflow2.method.energy_stress_calculator == "exciting" results = archive.workflow2.results - assert results.deformation_types[2][5] == '2eta' + assert results.deformation_types[2][5] == "2eta" sec_strain = results.strain_diagrams assert len(sec_strain) == 7 assert sec_strain[0].eta[1][3] == -0.02 assert sec_strain[0].value[2][5] == approx(-3.30877062e-16) - assert sec_strain[3].type == 'cross-validation' + assert sec_strain[3].type == "cross-validation" assert sec_strain[2].eta[1][2] == 0.03 - assert sec_strain[6].value[2][4] == approx(6.8708895e+12) + assert sec_strain[6].value[2][4] == approx(6.8708895e12) assert sec_strain[4].polynomial_fit_order == 6 - assert results.elastic_constants_notation_matrix_second_order[1][2] == 'C12' - assert results.elastic_constants_matrix_second_order[0][2].magnitude == approx(1.008e+11) + assert results.elastic_constants_notation_matrix_second_order[1][2] == "C12" + assert results.elastic_constants_matrix_second_order[0][2].magnitude == approx( + 1.008e11 + ) assert results.compliance_matrix_second_order[3][3].magnitude == approx(1.75e-12) - assert results.bulk_modulus_voigt.magnitude == approx(4.4937e+11) - assert results.shear_modulus_voigt.magnitude == approx(5.3074e+11) - assert results.bulk_modulus_reuss.magnitude == approx(4.4937e+11) - assert results.shear_modulus_reuss.magnitude == approx(5.2574e+11) - assert results.bulk_modulus_hill.magnitude == approx(4.4937e+11) - assert results.shear_modulus_hill.magnitude == approx(5.2824e+11) - assert results.young_modulus_voigt.magnitude == approx(1.14245e+12) + assert results.bulk_modulus_voigt.magnitude == approx(4.4937e11) + assert results.shear_modulus_voigt.magnitude == approx(5.3074e11) + assert results.bulk_modulus_reuss.magnitude == approx(4.4937e11) + assert results.shear_modulus_reuss.magnitude == approx(5.2574e11) + assert results.bulk_modulus_hill.magnitude == approx(4.4937e11) + assert results.shear_modulus_hill.magnitude == approx(5.2824e11) + assert results.young_modulus_voigt.magnitude == approx(1.14245e12) assert results.poisson_ratio_voigt == 0.08 - assert results.young_modulus_reuss.magnitude == approx(1.1347e+12) + assert results.young_modulus_reuss.magnitude == approx(1.1347e12) assert results.poisson_ratio_reuss == 0.08 - assert results.young_modulus_hill.magnitude == approx(1.13858e+12) + assert results.young_modulus_hill.magnitude == approx(1.13858e12) assert results.poisson_ratio_hill == 0.08 - assert results.eigenvalues_elastic[1].magnitude == approx(1.3481e+12) + assert results.eigenvalues_elastic[1].magnitude == approx(1.3481e12) sec_scc = archive.run[0].calculation[0] assert len(sec_scc.calculations_path) == 33 @@ -83,7 +85,7 @@ def test_2nd(parser): def test_3rd(parser): archive = EntryArchive() - parser.parse('tests/data/elastic/3rd/INFO_ElaStic', archive, None) + parser.parse("tests/data/elastic/3rd/INFO_ElaStic", archive, None) # The strain diagram data cannot be parsed because of the inhomogeneous shape probably # due to error in output. @@ -94,9 +96,15 @@ def test_3rd(parser): # assert sec_strain[3].value[8][7] == approx(2.06899957e-23) results = archive.workflow2.results - assert results.elastic_constants_matrix_third_order[3][1][3].magnitude == approx(1.274e+10) - assert results.elastic_constants_matrix_third_order[5][2][5].magnitude == approx(1.2825e+10) - assert results.elastic_constants_matrix_third_order[0][0][1].magnitude == approx(-1.18334e+12) + assert results.elastic_constants_matrix_third_order[3][1][3].magnitude == approx( + 1.274e10 + ) + assert results.elastic_constants_matrix_third_order[5][2][5].magnitude == approx( + 1.2825e10 + ) + assert results.elastic_constants_matrix_third_order[0][0][1].magnitude == approx( + -1.18334e12 + ) def test_stress(parser): diff --git a/tests/test_fhivibesparser.py b/tests/test_fhivibesparser.py index 2672bcc..f7caf24 100644 --- a/tests/test_fhivibesparser.py +++ b/tests/test_fhivibesparser.py @@ -27,7 +27,7 @@ def approx(value, abs=0, rel=1e-6): return pytest.approx(value, abs=abs, rel=rel) -@pytest.fixture(scope='module') +@pytest.fixture(scope="module") def parser(): return FHIVibesParser() @@ -35,45 +35,53 @@ def parser(): # TODO find out why tests fail on github def _test_singlepoint(parser): archive = EntryArchive() - parser.parse('tests/data/fhivibes/singlepoint.nc', archive, None) + parser.parse("tests/data/fhivibes/singlepoint.nc", archive, None) - assert archive.workflow2.m_def.name == 'SinglePoint' + assert archive.workflow2.m_def.name == "SinglePoint" sec_run = archive.run assert len(sec_run) == 10 assert len(sec_run[2].calculation) == 1 - assert sec_run[8].system[0].atoms.positions[3][2].magnitude == approx(5.30098546e-10) - assert sec_run[5].system[0].atoms.velocities[1][0].magnitude == approx(-2.18864066e+03) + assert sec_run[8].system[0].atoms.positions[3][2].magnitude == approx( + 5.30098546e-10 + ) + assert sec_run[5].system[0].atoms.velocities[1][0].magnitude == approx( + -2.18864066e03 + ) sec_scc = sec_run[9].calculation[0] assert len(sec_scc.energy.contributions) == 2 assert sec_scc.energy.contributions[1].value.magnitude == approx(-1.00925367e-14) sec_scc = sec_run[3].calculation[0] - assert sec_scc.stress.contributions[0].value[1][2].magnitude == approx(-1.42111377e+07) + assert sec_scc.stress.contributions[0].value[1][2].magnitude == approx( + -1.42111377e07 + ) sec_scc = sec_run[1].calculation[0] - assert sec_scc.stress.total.value[1][1].magnitude == approx(1.49076266e+08) + assert sec_scc.stress.total.value[1][1].magnitude == approx(1.49076266e08) sec_scc = sec_run[6].calculation[0] assert sec_scc.forces.total.value[5][2].magnitude == approx(-3.47924808e-10) sec_scc = sec_run[5].calculation[0] - assert sec_scc.thermodynamics[0].pressure.magnitude == approx(2.52108927e+07) + assert sec_scc.thermodynamics[0].pressure.magnitude == approx(2.52108927e07) sec_scc = sec_run[2].calculation[0] - assert sec_scc.x_fhi_vibes_pressure_kinetic.magnitude == approx(2.08283962e+08) + assert sec_scc.x_fhi_vibes_pressure_kinetic.magnitude == approx(2.08283962e08) sec_scc = sec_run[8].calculation[0] - assert sec_scc.x_fhi_vibes_energy_potential_harmonic.magnitude == approx(4.08242214e-20) + assert sec_scc.x_fhi_vibes_energy_potential_harmonic.magnitude == approx( + 4.08242214e-20 + ) def _test_relaxation(parser): archive = EntryArchive() - parser.parse('tests/data/fhivibes/relaxation.nc', archive, None) + parser.parse("tests/data/fhivibes/relaxation.nc", archive, None) - assert archive.workflow2.m_def.name == 'GeometryOptimization' + assert archive.workflow2.m_def.name == "GeometryOptimization" assert len(archive.run) == 1 @@ -88,46 +96,58 @@ def _test_relaxation(parser): sec_relaxation = sec_metadata.x_fhi_vibes_section_metadata_relaxation[0] assert sec_relaxation.x_fhi_vibes_relaxation_maxstep == 0.2 assert not sec_relaxation.x_fhi_vibes_relaxation_hydrostatic_strain - assert sec_relaxation.x_fhi_vibes_relaxation_type == 'optimization' + assert sec_relaxation.x_fhi_vibes_relaxation_type == "optimization" sec_sccs = archive.run[0].calculation assert len(sec_sccs) == 3 assert sec_sccs[2].thermodynamics[0].volume.magnitude == approx(3.97721030e-29) - assert sec_sccs[0].energy.contributions[1].value.magnitude == approx(-2.52313962e-15) + assert sec_sccs[0].energy.contributions[1].value.magnitude == approx( + -2.52313962e-15 + ) def _test_molecular_dynamics(parser): archive = EntryArchive() - parser.parse('tests/data/fhivibes/molecular_dynamics.nc', archive, None) + parser.parse("tests/data/fhivibes/molecular_dynamics.nc", archive, None) - assert archive.workflow2.m_def.name == 'MolecularDynamics' + assert archive.workflow2.m_def.name == "MolecularDynamics" sec_attrs = archive.run[0].method[0].x_fhi_vibes_section_attributes[0] - sec_md = sec_attrs.x_fhi_vibes_section_attributes_metadata[0].x_fhi_vibes_section_metadata_MD[0] - assert sec_md.x_fhi_vibes_MD_md_type == 'Langevin' + sec_md = sec_attrs.x_fhi_vibes_section_attributes_metadata[ + 0 + ].x_fhi_vibes_section_metadata_MD[0] + assert sec_md.x_fhi_vibes_MD_md_type == "Langevin" assert sec_md.x_fhi_vibes_MD_friction == 0.02 sec_systems = archive.run[0].system assert len(sec_systems) == 11 assert sec_systems[3].atoms.positions[6][1].magnitude == approx(1.39537854e-10) assert sec_systems[7].atoms.velocities[1][0].magnitude == approx(-249.97586102) - assert sec_systems[2].atoms.lattice_vectors[0][2].magnitude == approx(2.20004000e-21) + assert sec_systems[2].atoms.lattice_vectors[0][2].magnitude == approx( + 2.20004000e-21 + ) sec_sccs = archive.run[0].calculation - assert sec_sccs[4].x_fhi_vibes_heat_flux_0_harmonic[1].magnitude == approx(1.40863863e+13) - assert sec_sccs[5].x_fhi_vibes_atom_forces_harmonic[3][0].magnitude == approx(8.40976902e-10) + assert sec_sccs[4].x_fhi_vibes_heat_flux_0_harmonic[1].magnitude == approx( + 1.40863863e13 + ) + assert sec_sccs[5].x_fhi_vibes_atom_forces_harmonic[3][0].magnitude == approx( + 8.40976902e-10 + ) assert sec_sccs[6].x_fhi_vibes_momenta[7][2].magnitude == approx(-1.18929315e-24) def _test_phonon(parser): archive = EntryArchive() - parser.parse('tests/data/fhivibes/phonopy.nc', archive, None) + parser.parse("tests/data/fhivibes/phonopy.nc", archive, None) - assert archive.workflow2.m_def.name == 'Phonon' + assert archive.workflow2.m_def.name == "Phonon" sec_attrs = archive.run[0].method[0].x_fhi_vibes_section_attributes[0] - sec_phonon = sec_attrs.x_fhi_vibes_section_attributes_metadata[0].x_fhi_vibes_section_metadata_phonopy[0] - assert sec_phonon.x_fhi_vibes_phonopy_version == '2.6.1' + sec_phonon = sec_attrs.x_fhi_vibes_section_attributes_metadata[ + 0 + ].x_fhi_vibes_section_metadata_phonopy[0] + assert sec_phonon.x_fhi_vibes_phonopy_version == "2.6.1" sec_atoms = sec_phonon.x_fhi_vibes_section_phonopy_primitive[0] assert np.shape(sec_atoms.x_fhi_vibes_atoms_positions) == (2, 3) assert sec_atoms.x_fhi_vibes_atoms_cell[0][2].magnitude == approx(2.70925272e-10) diff --git a/tests/test_lobsterparser.py b/tests/test_lobsterparser.py index dfbefd6..2ceaf40 100644 --- a/tests/test_lobsterparser.py +++ b/tests/test_lobsterparser.py @@ -54,7 +54,7 @@ def test_Fe(parser): """ archive = EntryArchive() - parser.parse('tests/data/lobster/Fe/lobsterout', archive, logging) + parser.parse("tests/data/lobster/Fe/lobsterout", archive, logging) run = archive.run[0] assert run.program.name == "LOBSTER" @@ -84,25 +84,26 @@ def test_Fe(parser): assert len(cohp.x_lobster_cohp_atom2_labels) == 20 assert cohp.x_lobster_cohp_atom1_labels[3] == "Fe1" assert len(cohp.x_lobster_cohp_distances) == 20 - assert cohp.x_lobster_cohp_distances[0].magnitude == approx( - A_to_m(2.831775)) - assert cohp.x_lobster_cohp_distances[13].magnitude == approx( - A_to_m(2.45239)) - assert cohp.x_lobster_cohp_distances[19].magnitude == approx( - A_to_m(2.831775)) + assert cohp.x_lobster_cohp_distances[0].magnitude == approx(A_to_m(2.831775)) + assert cohp.x_lobster_cohp_distances[13].magnitude == approx(A_to_m(2.45239)) + assert cohp.x_lobster_cohp_distances[19].magnitude == approx(A_to_m(2.831775)) assert np.shape(cohp.x_lobster_cohp_translations) == (20, 3) assert (cohp.x_lobster_cohp_translations[0] == [0, 0, -1]).all() assert (cohp.x_lobster_cohp_translations[13] == [0, 0, 0]).all() assert (cohp.x_lobster_cohp_translations[19] == [0, 0, 1]).all() assert np.shape(cohp.x_lobster_integrated_cohp_at_fermi_level) == (2, 20) assert cohp.x_lobster_integrated_cohp_at_fermi_level[0, 0].magnitude == approx( - eV_to_J(-0.08672)) + eV_to_J(-0.08672) + ) assert cohp.x_lobster_integrated_cohp_at_fermi_level[0, 19].magnitude == approx( - eV_to_J(-0.08672)) + eV_to_J(-0.08672) + ) assert cohp.x_lobster_integrated_cohp_at_fermi_level[1, 19].magnitude == approx( - eV_to_J(-0.16529)) + eV_to_J(-0.16529) + ) assert cohp.x_lobster_integrated_cohp_at_fermi_level[1, 7].magnitude == approx( - eV_to_J(-0.48790)) + eV_to_J(-0.48790) + ) # COHPCAR.lobster assert len(cohp.x_lobster_cohp_energies) == 201 @@ -113,17 +114,21 @@ def test_Fe(parser): assert cohp.x_lobster_average_cohp_values[1][200] == approx(0.01816) assert np.shape(cohp.x_lobster_average_integrated_cohp_values) == (2, 201) assert cohp.x_lobster_average_integrated_cohp_values[0][200].magnitude == approx( - eV_to_J(-0.06616)) + eV_to_J(-0.06616) + ) assert cohp.x_lobster_average_integrated_cohp_values[1][200].magnitude == approx( - eV_to_J(-0.02265)) + eV_to_J(-0.02265) + ) assert np.shape(cohp.x_lobster_cohp_values) == (20, 2, 201) assert cohp.x_lobster_cohp_values[10][1][200] == approx(0.02291) assert cohp.x_lobster_cohp_values[19][0][200] == approx(0.01439) assert np.shape(cohp.x_lobster_integrated_cohp_values) == (20, 2, 201) assert cohp.x_lobster_integrated_cohp_values[10][0][200].magnitude == approx( - eV_to_J(-0.12881)) + eV_to_J(-0.12881) + ) assert cohp.x_lobster_integrated_cohp_values[19][1][200].magnitude == approx( - eV_to_J(-0.06876)) + eV_to_J(-0.06876) + ) # ICOOPLIST.lobster coop = scc.x_lobster_section_coop @@ -133,25 +138,26 @@ def test_Fe(parser): assert len(coop.x_lobster_coop_atom2_labels) == 20 assert coop.x_lobster_coop_atom1_labels[3] == "Fe1" assert len(coop.x_lobster_coop_distances) == 20 - assert coop.x_lobster_coop_distances[0].magnitude == approx( - A_to_m(2.831775)) - assert coop.x_lobster_coop_distances[13].magnitude == approx( - A_to_m(2.45239)) - assert coop.x_lobster_coop_distances[19].magnitude == approx( - A_to_m(2.831775)) + assert coop.x_lobster_coop_distances[0].magnitude == approx(A_to_m(2.831775)) + assert coop.x_lobster_coop_distances[13].magnitude == approx(A_to_m(2.45239)) + assert coop.x_lobster_coop_distances[19].magnitude == approx(A_to_m(2.831775)) assert np.shape(coop.x_lobster_coop_translations) == (20, 3) assert (coop.x_lobster_coop_translations[0] == [0, 0, -1]).all() assert (coop.x_lobster_coop_translations[13] == [0, 0, 0]).all() assert (coop.x_lobster_coop_translations[19] == [0, 0, 1]).all() assert np.shape(coop.x_lobster_integrated_coop_at_fermi_level) == (2, 20) assert coop.x_lobster_integrated_coop_at_fermi_level[0, 0].magnitude == approx( - eV_to_J(-0.06882)) + eV_to_J(-0.06882) + ) assert coop.x_lobster_integrated_coop_at_fermi_level[0, 19].magnitude == approx( - eV_to_J(-0.06882)) + eV_to_J(-0.06882) + ) assert coop.x_lobster_integrated_coop_at_fermi_level[1, 19].magnitude == approx( - eV_to_J(-0.11268)) + eV_to_J(-0.11268) + ) assert coop.x_lobster_integrated_coop_at_fermi_level[1, 7].magnitude == approx( - eV_to_J(-0.05179)) + eV_to_J(-0.05179) + ) # COOPCAR.lobster assert len(coop.x_lobster_coop_energies) == 201 @@ -162,17 +168,21 @@ def test_Fe(parser): assert coop.x_lobster_average_coop_values[1][200] == approx(-0.04542) assert np.shape(coop.x_lobster_average_integrated_coop_values) == (2, 201) assert coop.x_lobster_average_integrated_coop_values[0][200].magnitude == approx( - eV_to_J(-0.12265)) + eV_to_J(-0.12265) + ) assert coop.x_lobster_average_integrated_coop_values[1][200].magnitude == approx( - eV_to_J(-0.14690)) + eV_to_J(-0.14690) + ) assert np.shape(coop.x_lobster_coop_values) == (20, 2, 201) assert coop.x_lobster_coop_values[3][1][200] == approx(-0.01346) assert coop.x_lobster_coop_values[0][0][200] == approx(-0.04542) assert np.shape(coop.x_lobster_integrated_coop_values) == (20, 2, 201) assert coop.x_lobster_integrated_coop_values[10][0][199].magnitude == approx( - eV_to_J(-0.07360)) + eV_to_J(-0.07360) + ) assert coop.x_lobster_integrated_coop_values[19][1][200].magnitude == approx( - eV_to_J(-0.13041)) + eV_to_J(-0.13041) + ) # CHARGE.lobster charges = scc.charges @@ -210,12 +220,15 @@ def test_Fe(parser): # DOSCAR.lobster atom and lm-projected dos assert len(dos_up.atom_projected) == 12 and len(dos_down.atom_projected) == 12 - assert dos_up.atom_projected[0].atom_index == 0 and dos_up.atom_projected[6].atom_index == 1 - assert dos_up.atom_projected[0].m_kind == 'real_orbital' + assert ( + dos_up.atom_projected[0].atom_index == 0 + and dos_up.atom_projected[6].atom_index == 1 + ) + assert dos_up.atom_projected[0].m_kind == "real_orbital" assert (dos_up.atom_projected[4].lm == [2, 1]).all() assert np.shape(dos_up.atom_projected[11].value) == (201,) - assert dos_up.atom_projected[5].value[190].to('1/eV').magnitude == approx(0.00909) - assert dos_down.atom_projected[5].value[190].to('1/eV').magnitude == approx(0.29205) + assert dos_up.atom_projected[5].value[190].to("1/eV").magnitude == approx(0.00909) + assert dos_down.atom_projected[5].value[190].to("1/eV").magnitude == approx(0.29205) def test_NaCl(parser): @@ -224,7 +237,7 @@ def test_NaCl(parser): """ archive = EntryArchive() - parser.parse('tests/data/lobster/NaCl/lobsterout', archive, logging) + parser.parse("tests/data/lobster/NaCl/lobsterout", archive, logging) run = archive.run[0] assert run.program.name == "LOBSTER" @@ -261,9 +274,11 @@ def test_NaCl(parser): assert (cohp.x_lobster_cohp_translations[71] == [0, 1, 0]).all() assert np.shape(cohp.x_lobster_integrated_cohp_at_fermi_level) == (1, 72) assert cohp.x_lobster_integrated_cohp_at_fermi_level[0, 0].magnitude == approx( - eV_to_J(-0.02652)) + eV_to_J(-0.02652) + ) assert cohp.x_lobster_integrated_cohp_at_fermi_level[0, 71].magnitude == approx( - eV_to_J(-0.02925)) + eV_to_J(-0.02925) + ) # COHPCAR.lobster assert len(cohp.x_lobster_cohp_energies) == 201 @@ -274,17 +289,21 @@ def test_NaCl(parser): assert cohp.x_lobster_average_cohp_values[0][151] == approx(-0.03162) assert np.shape(cohp.x_lobster_average_integrated_cohp_values) == (1, 201) assert cohp.x_lobster_average_integrated_cohp_values[0][0].magnitude == approx( - eV_to_J(-0.15834)) + eV_to_J(-0.15834) + ) assert cohp.x_lobster_average_integrated_cohp_values[0][200].magnitude == approx( - eV_to_J(-0.24310)) + eV_to_J(-0.24310) + ) assert np.shape(cohp.x_lobster_cohp_values) == (72, 1, 201) assert cohp.x_lobster_cohp_values[1][0][200] == pytest.approx(0.0) assert cohp.x_lobster_cohp_values[71][0][140] == approx(-0.00403) assert np.shape(cohp.x_lobster_integrated_cohp_values) == (72, 1, 201) assert cohp.x_lobster_integrated_cohp_values[2][0][200].magnitude == approx( - eV_to_J(-0.02652)) + eV_to_J(-0.02652) + ) assert cohp.x_lobster_integrated_cohp_values[67][0][199].magnitude == approx( - eV_to_J(-0.04137)) + eV_to_J(-0.04137) + ) # ICOOPLIST.lobster coop = scc.x_lobster_section_coop @@ -303,9 +322,11 @@ def test_NaCl(parser): assert (coop.x_lobster_coop_translations[71] == [0, 1, 0]).all() assert np.shape(coop.x_lobster_integrated_coop_at_fermi_level) == (1, 72) assert coop.x_lobster_integrated_coop_at_fermi_level[0, 0].magnitude == approx( - eV_to_J(-0.00519)) + eV_to_J(-0.00519) + ) assert coop.x_lobster_integrated_coop_at_fermi_level[0, 71].magnitude == approx( - eV_to_J(-0.00580)) + eV_to_J(-0.00580) + ) # COOPCAR.lobster assert len(coop.x_lobster_coop_energies) == 201 @@ -316,17 +337,21 @@ def test_NaCl(parser): assert coop.x_lobster_average_coop_values[0][145] == approx(0.03178) assert np.shape(coop.x_lobster_average_integrated_coop_values) == (1, 201) assert coop.x_lobster_average_integrated_coop_values[0][0].magnitude == approx( - eV_to_J(0.00368)) + eV_to_J(0.00368) + ) assert coop.x_lobster_average_integrated_coop_values[0][200].magnitude == approx( - eV_to_J(0.00682)) + eV_to_J(0.00682) + ) assert np.shape(coop.x_lobster_coop_values) == (72, 1, 201) assert coop.x_lobster_coop_values[1][0][200] == pytest.approx(0.0) assert coop.x_lobster_coop_values[71][0][143] == approx(0.01862) assert np.shape(coop.x_lobster_integrated_coop_values) == (72, 1, 201) assert coop.x_lobster_integrated_coop_values[2][0][200].magnitude == approx( - eV_to_J(-0.00519)) + eV_to_J(-0.00519) + ) assert coop.x_lobster_integrated_coop_values[71][0][199].magnitude == approx( - eV_to_J(-0.00580)) + eV_to_J(-0.00580) + ) # CHARGE.lobster charges = scc.charges @@ -364,7 +389,7 @@ def test_NaCl(parser): assert len(dos.atom_projected) == 20 dos.atom_projected[0].atom_index == 0 dos.atom_projected[19].atom_index == 7 - assert dos.atom_projected[5].m_kind == 'real_orbital' + assert dos.atom_projected[5].m_kind == "real_orbital" assert (dos.atom_projected[17].lm == [1, 2]).all() assert np.shape(dos.atom_projected[13].value) == (201,) assert np.shape(dos.atom_projected[8].value) == (201,) @@ -381,7 +406,7 @@ def test_HfV(parser): """ archive = EntryArchive() - parser.parse('tests/data/lobster/HfV2/lobsterout', archive, logging) + parser.parse("tests/data/lobster/HfV2/lobsterout", archive, logging) run = archive.run[0] assert run.program.name == "LOBSTER" @@ -399,7 +424,9 @@ def test_HfV(parser): system = run.system assert len(system) == 1 assert len(system[0].atoms.species) == 12 - assert (system[0].atoms.species == [72, 72, 72, 72, 23, 23, 23, 23, 23, 23, 23, 23]).all() + assert ( + system[0].atoms.species == [72, 72, 72, 72, 23, 23, 23, 23, 23, 23, 23, 23] + ).all() assert system[0].atoms.periodic == [True, True, True] # method @@ -423,9 +450,11 @@ def test_HfV(parser): assert cohp.x_lobster_cohp_number_of_bonds[53] == 1 assert np.shape(cohp.x_lobster_integrated_cohp_at_fermi_level) == (1, 56) assert cohp.x_lobster_integrated_cohp_at_fermi_level[0, 0].magnitude == approx( - eV_to_J(-1.72125)) + eV_to_J(-1.72125) + ) assert cohp.x_lobster_integrated_cohp_at_fermi_level[0, 55].magnitude == approx( - eV_to_J(-1.62412)) + eV_to_J(-1.62412) + ) # ICOOPLIST.lobster coop = scc.x_lobster_section_coop @@ -444,9 +473,11 @@ def test_HfV(parser): assert coop.x_lobster_coop_number_of_bonds[53] == 1 assert np.shape(coop.x_lobster_integrated_coop_at_fermi_level) == (1, 56) assert coop.x_lobster_integrated_coop_at_fermi_level[0, 0].magnitude == approx( - eV_to_J(-0.46493)) + eV_to_J(-0.46493) + ) assert coop.x_lobster_integrated_coop_at_fermi_level[0, 55].magnitude == approx( - eV_to_J(-0.50035)) + eV_to_J(-0.50035) + ) def test_QE_Ni(parser): @@ -456,14 +487,14 @@ def test_QE_Ni(parser): """ archive = EntryArchive() - parser.parse('tests/data/lobster/Ni/lobsterout', archive, logging) + parser.parse("tests/data/lobster/Ni/lobsterout", archive, logging) run = archive.run[0] # QE system parsing system = run.system assert len(system) == 1 - assert system[0].atoms.labels == ['Ni'] + assert system[0].atoms.labels == ["Ni"] assert system[0].atoms.periodic == [True, True, True] assert len(system[0].atoms.positions) == 1 assert (system[0].atoms.positions[0].magnitude == [0, 0, 0]).all() @@ -492,7 +523,7 @@ def test_failed_case(parser): """ archive = EntryArchive() - parser.parse('tests/data/lobster/failed_case/lobsterout', archive, logging) + parser.parse("tests/data/lobster/failed_case/lobsterout", archive, logging) run = archive.run[0] assert run.clean_end is False diff --git a/tests/test_phonopyparser.py b/tests/test_phonopyparser.py index e528925..5eb0c66 100644 --- a/tests/test_phonopyparser.py +++ b/tests/test_phonopyparser.py @@ -27,14 +27,18 @@ def approx(value, abs=0, rel=1e-6): return pytest.approx(value, abs=abs, rel=rel) -@pytest.fixture(scope='module') +@pytest.fixture(scope="module") def parser(): return PhonopyParser() def test_basic(parser): archive = EntryArchive() - parser.parse('tests/data/phonopy/Ge/phonopy-FHI-aims-displacement-01/control.in', archive, None) + parser.parse( + "tests/data/phonopy/Ge/phonopy-FHI-aims-displacement-01/control.in", + archive, + None, + ) # need to assert values, no unbiased reference sec_thermo = archive.run[0].calculation[0].thermodynamics @@ -55,4 +59,4 @@ def test_basic(parser): def test_vasp(parser): archive = EntryArchive() - parser.parse('tests/data/phonopy/vasp/phonopy.yaml', archive, None) + parser.parse("tests/data/phonopy/vasp/phonopy.yaml", archive, None) diff --git a/tests/test_quantum_espresso_epw.py b/tests/test_quantum_espresso_epw.py index ce38023..a6bfb53 100644 --- a/tests/test_quantum_espresso_epw.py +++ b/tests/test_quantum_espresso_epw.py @@ -26,11 +26,11 @@ def approx(value, abs=0, rel=1e-6): return pytest.approx(value, abs=abs, rel=rel) -@pytest.fixture(scope='module') +@pytest.fixture(scope="module") def parser(): return QuantumEspressoEPWParser() def test_1(parser): archive = EntryArchive() - parser.parse('tests/data/quantum_espresso_epw/epw.out', archive, None) + parser.parse("tests/data/quantum_espresso_epw/epw.out", archive, None) diff --git a/tests/test_quantum_espresso_phonon.py b/tests/test_quantum_espresso_phonon.py index ffef3ab..a48fb35 100644 --- a/tests/test_quantum_espresso_phonon.py +++ b/tests/test_quantum_espresso_phonon.py @@ -26,11 +26,11 @@ def approx(value, abs=0, rel=1e-6): return pytest.approx(value, abs=abs, rel=rel) -@pytest.fixture(scope='module') +@pytest.fixture(scope="module") def parser(): return QuantumEspressoPhononParser() def test_1(parser): archive = EntryArchive() - parser.parse('tests/data/quantum_espresso_phonon/ph.out', archive, None) + parser.parse("tests/data/quantum_espresso_phonon/ph.out", archive, None) diff --git a/tests/test_quantum_espresso_xspectra.py b/tests/test_quantum_espresso_xspectra.py index 75d7f02..2cdecb9 100644 --- a/tests/test_quantum_espresso_xspectra.py +++ b/tests/test_quantum_espresso_xspectra.py @@ -26,40 +26,48 @@ def approx(value, abs=0, rel=1e-6): return pytest.approx(value, abs=abs, rel=rel) -@pytest.fixture(scope='module') +@pytest.fixture(scope="module") def parser(): return QuantumEspressoXSpectraParser() def test_1(parser): archive = EntryArchive() - parser.parse('tests/data/quantum_espresso_xspectra/ms-10734/Spectra-1-1-1/0/dipole1/xanes.out', archive, None) + parser.parse( + "tests/data/quantum_espresso_xspectra/ms-10734/Spectra-1-1-1/0/dipole1/xanes.out", + archive, + None, + ) sec_run = archive.run[0] - assert sec_run.m_xpath('x_qe_xspectra_input') + assert sec_run.m_xpath("x_qe_xspectra_input") # Program - assert sec_run.program.name == 'Quantum ESPRESSO XSPECTRA' - assert sec_run.program.version == '6.7MaX' + assert sec_run.program.name == "Quantum ESPRESSO XSPECTRA" + assert sec_run.program.version == "6.7MaX" # System sec_system = sec_run.system[0] assert sec_system.x_qe_xspectra_bravais_lattice_index == 0 - assert sec_system.x_qe_xspectra_unit_cell_volume.magnitude == approx(7.381107151717e-28) + assert sec_system.x_qe_xspectra_unit_cell_volume.magnitude == approx( + 7.381107151717e-28 + ) assert sec_system.x_qe_xspectra_n_atoms_cell == 72 - assert sec_system.atoms.labels[0] == 'Ti' - assert sec_system.atoms.labels[4] == 'O' + assert sec_system.atoms.labels[0] == "Ti" + assert sec_system.atoms.labels[4] == "O" assert sec_system.atoms.positions[0][0].magnitude == approx(1.8823018373897882e-10) # Method sec_method = sec_run.method assert len(sec_method) == 2 - assert sec_method[0].m_xpath('electronic') and sec_method[0].m_xpath('atom_parameters') - assert sec_method[0].m_xpath('photon') - assert sec_method[0].photon[0].multipole_type == 'dipole' + assert sec_method[0].m_xpath("electronic") and sec_method[0].m_xpath( + "atom_parameters" + ) + assert sec_method[0].m_xpath("photon") + assert sec_method[0].photon[0].multipole_type == "dipole" sec_core_hole = sec_method[1].core_hole - assert sec_core_hole.solver == 'Lanczos' - assert sec_core_hole.mode == 'absorption' + assert sec_core_hole.solver == "Lanczos" + assert sec_core_hole.mode == "absorption" assert sec_core_hole.broadening.magnitude == approx(0.89) # Calculation @@ -67,9 +75,11 @@ def test_1(parser): assert len(sec_scc) == 1 assert sec_scc[0].system_ref == sec_system assert sec_scc[0].method_ref == sec_method[1] - assert sec_scc[0].m_xpath('spectra') + assert sec_scc[0].m_xpath("spectra") sec_spectra = sec_scc[0].spectra[0] - assert sec_spectra.type == 'XANES' + assert sec_spectra.type == "XANES" assert sec_spectra.n_energies == 400 - assert sec_spectra.excitation_energies[22].magnitude == approx(-1.6523701378886513e-18) + assert sec_spectra.excitation_energies[22].magnitude == approx( + -1.6523701378886513e-18 + ) assert sec_spectra.intensities[22] == approx(2.905e-5) diff --git a/workflowparsers/phonopy/calculator.py b/workflowparsers/phonopy/calculator.py index 5b1a365..91eef3d 100644 --- a/workflowparsers/phonopy/calculator.py +++ b/workflowparsers/phonopy/calculator.py @@ -22,7 +22,12 @@ from ase import lattice as aselattice from ase.cell import Cell -from ase.dft.kpoints import special_paths, parse_path_string, get_special_points, sc_special_points +from ase.dft.kpoints import ( + special_paths, + parse_path_string, + get_special_points, + sc_special_points, +) from phonopy.phonon.band_structure import BandStructure from phonopy.units import EvTokJmol, VaspToTHz @@ -33,29 +38,29 @@ def generate_kpath_parameters(points, paths, npoints): for p in paths: k_points.append([points[k] for k in p]) for index in range(len(p)): - if p[index] == 'G': - p[index] = 'Γ' + if p[index] == "G": + p[index] = "Γ" parameters = [] for h, seg in enumerate(k_points): for i, path in enumerate(seg): parameter = {} - parameter['npoints'] = npoints - parameter['startname'] = paths[h][i] + parameter["npoints"] = npoints + parameter["startname"] = paths[h][i] if i == 0 and len(seg) > 2: - parameter['kstart'] = path - parameter['kend'] = seg[i + 1] - parameter['endname'] = paths[h][i + 1] + parameter["kstart"] = path + parameter["kend"] = seg[i + 1] + parameter["endname"] = paths[h][i + 1] parameters.append(parameter) elif i == (len(seg) - 2): - parameter['kstart'] = path - parameter['kend'] = seg[i + 1] - parameter['endname'] = paths[h][i + 1] + parameter["kstart"] = path + parameter["kend"] = seg[i + 1] + parameter["endname"] = paths[h][i + 1] parameters.append(parameter) break else: - parameter['kstart'] = path - parameter['kend'] = seg[i + 1] - parameter['endname'] = paths[h][i + 1] + parameter["kstart"] = path + parameter["kend"] = seg[i + 1] + parameter["endname"] = paths[h][i + 1] parameters.append(parameter) return parameters @@ -64,13 +69,13 @@ def read_kpath(filename): with open(filename) as f: string = f.read() - labels = re.search(r'BAND_LABELS\s*=\s*(.+)', string) + labels = re.search(r"BAND_LABELS\s*=\s*(.+)", string) try: labels = labels.group(1).strip().split() except Exception: return - points = re.search(r'BAND\s*=\s*(.+)', string) + points = re.search(r"BAND\s*=\s*(.+)", string) try: points = points.group(1) points = [float(Fraction(p)) for p in points.split()] @@ -79,7 +84,7 @@ def read_kpath(filename): except Exception: return - npoints = re.search(r'BAND_POINTS\s*\=\s*(\d+)', string) + npoints = re.search(r"BAND_POINTS\s*\=\s*(\d+)", string) if npoints is not None: npoints = int(npoints.group(1)) else: @@ -94,9 +99,9 @@ def generate_kpath_ase(cell, symprec, logger=None): paths = parse_path_string(lattice.special_path) points = lattice.get_special_points() except Exception: - logger.warning('Cannot resolve lattice paths.') - paths = special_paths['orthorhombic'] - points = sc_special_points['orthorhombic'] + logger.warning("Cannot resolve lattice paths.") + paths = special_paths["orthorhombic"] + points = sc_special_points["orthorhombic"] if points is None: try: points = get_special_points(cell) @@ -104,24 +109,24 @@ def generate_kpath_ase(cell, symprec, logger=None): return [] if isinstance(paths, str): - paths = [list(path) for path in paths.split(',')] + paths = [list(path) for path in paths.split(",")] return generate_kpath_parameters(points, paths, 100) -class PhononProperties(): +class PhononProperties: def __init__(self, phonopy_obj, logger, **kwargs): self.logger = logger self.phonopy_obj = phonopy_obj - self.t_max = kwargs.get('t_max', 1000) - self.t_min = kwargs.get('t_min', 0) - self.t_step = kwargs.get('t_step', 100) - self.band_conf = kwargs.get('band_conf') + self.t_max = kwargs.get("t_max", 1000) + self.t_min = kwargs.get("t_min", 0) + self.t_step = kwargs.get("t_step", 100) + self.band_conf = kwargs.get("band_conf") self.n_atoms = len(phonopy_obj.unitcell) - k_mesh = kwargs.get('k_mesh', 30) - mesh_density = (2 * k_mesh ** 3) / self.n_atoms - mesh_number = np.round(mesh_density**(1. / 3.)) + k_mesh = kwargs.get("k_mesh", 30) + mesh_density = (2 * k_mesh**3) / self.n_atoms + mesh_number = np.round(mesh_density ** (1.0 / 3.0)) self.mesh = [mesh_number, mesh_number, mesh_number] self.n_atoms_supercell = len(phonopy_obj.supercell) @@ -172,8 +177,11 @@ def get_bandstructure(self): bands_labels.append(label) bs_obj = BandStructure( - bands, phonopy_obj.dynamical_matrix, with_eigenvectors=is_eigenvectors, - factor=frequency_unit_factor) + bands, + phonopy_obj.dynamical_matrix, + with_eigenvectors=is_eigenvectors, + factor=frequency_unit_factor, + ) freqs = bs_obj.get_frequencies() @@ -193,7 +201,8 @@ def get_dos(self): max_freq = max(np.ravel(frequencies)) + max(np.ravel(frequencies)) * 0.05 phonopy_obj.set_total_DOS( - freq_min=min_freq, freq_max=max_freq, tetrahedron_method=True) + freq_min=min_freq, freq_max=max_freq, tetrahedron_method=True + ) f, dos = phonopy_obj.get_total_DOS() return f, dos @@ -203,7 +212,8 @@ def get_thermodynamical_properties(self): phonopy_obj.set_mesh(self.mesh, is_gamma_center=True) phonopy_obj.set_thermal_properties( - t_step=self.t_step, t_max=self.t_max, t_min=self.t_min) + t_step=self.t_step, t_max=self.t_max, t_min=self.t_min + ) T, fe, entropy, cv = phonopy_obj.get_thermal_properties() kJmolToEv = 1.0 / EvTokJmol fe = fe * kJmolToEv