From 2233f348c75b379b91d759990be72e6f5060cc76 Mon Sep 17 00:00:00 2001 From: JosePizarro3 Date: Tue, 27 Aug 2024 10:39:41 +0200 Subject: [PATCH] Fix ruff --- pyproject.toml | 3 +- .../properties/greens_function.py | 48 ++++++++++++++++--- tests/conftest.py | 1 - tests/test_atoms_state.py | 1 - tests/test_band_gap.py | 1 - tests/test_band_structure.py | 1 - tests/test_fermi_surface.py | 1 - tests/test_general.py | 1 - tests/test_greens_function.py | 28 ++++++++--- tests/test_hopping_matrix.py | 1 - tests/test_model_method.py | 1 - tests/test_model_system.py | 1 - tests/test_numerical_settings.py | 1 - tests/test_outputs.py | 1 - tests/test_permittivity.py | 1 - tests/test_physical_properties.py | 1 - tests/test_spectral_profile.py | 1 - tests/test_utils.py | 1 - tests/test_variables.py | 1 - 19 files changed, 64 insertions(+), 31 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 117c62f6..da497aba 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -84,7 +84,6 @@ indent-width = 4 [tool.ruff.lint] select = [ "E", # pycodestyle - "W", # pycodestyle "PL", # pylint "F", # Pyflakes "UP", # pyupgrade @@ -92,11 +91,11 @@ select = [ ] ignore = [ + "F401", # Module imported but unused "E501", # Line too long ({width} > {limit} characters) "E701", # Multiple statements on one line (colon) "E731", # Do not assign a lambda expression, use a def "E402", # Module level import not at top of file - "F401", "PLR0911", # Too many return statements "PLR0912", # Too many branches "PLR0913", # Too many arguments in function definition diff --git a/src/nomad_simulations/schema_packages/properties/greens_function.py b/src/nomad_simulations/schema_packages/properties/greens_function.py index c4788c7e..51928a84 100644 --- a/src/nomad_simulations/schema_packages/properties/greens_function.py +++ b/src/nomad_simulations/schema_packages/properties/greens_function.py @@ -54,6 +54,7 @@ class BaseGreensFunction(PhysicalProperty): Further information in M. Wallerberger et al., Comput. Phys. Commun. 235, 2 (2019). """ + # ! we use `atoms_state_ref` and `orbitals_state_ref` to enforce order in the matrices n_atoms = Quantity( @@ -108,7 +109,22 @@ class BaseGreensFunction(PhysicalProperty): ) space_id = Quantity( - type=MEnum('r', 'rt', 'rw', 'rit', 'riw', 'k', 'kt', 'kw', 'kit', 'kiw', 't', 'it', 'w', 'iw'), + type=MEnum( + 'r', + 'rt', + 'rw', + 'rit', + 'riw', + 'k', + 'kt', + 'kw', + 'kit', + 'kiw', + 't', + 'it', + 'w', + 'iw', + ), description=""" String used to identify the space in which the Green's function property is represented. The spaces are: @@ -136,7 +152,10 @@ def __init__( ) -> None: super().__init__(m_def, m_context, **kwargs) # ! n_orbitals need to be set up during initialization of the class - self.rank = [int(kwargs.get('n_atoms')), int(kwargs.get('n_correlated_orbitals'))] + self.rank = [ + int(kwargs.get('n_atoms')), + int(kwargs.get('n_correlated_orbitals')), + ] def resolve_space_id(self) -> str: """ @@ -167,7 +186,9 @@ def find_space_id(space_map: dict) -> str: str: _description_ """ for space_id, variable_cls in space_map.items(): - space_variable = get_variables(variables=self.variables, variable_cls=variable_cls) + space_variable = get_variables( + variables=self.variables, variable_cls=variable_cls + ) if len(space_variable) > 0: return space_id return '' @@ -179,12 +200,13 @@ def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None: super().normalize(archive, logger) space_id = self.resolve_space_id() - if (self.space_id is not None and self.space_id != space_id): + if self.space_id is not None and self.space_id != space_id: logger.warning( f'The stored `space_id`, {self.space_id}, does not coincide with the resolved one, {space_id}. We will update it.' ) self.space_id = space_id + class ElectronicGreensFunction(BaseGreensFunction): """ Charge-charge correlation functions. @@ -271,12 +293,18 @@ class QuasiparticleWeight(PhysicalProperty): electron-electron interactions and takes values between 0 and 1, with Z = 1 representing a non-correlated system, and Z = 0 the Mott state. """ + # ! we use `atoms_state_ref` and `orbitals_state_ref` to enforce order in the matrices iri = 'http://fairmat-nfdi.eu/taxonomy/HybridizationFunction' system_correlation_strengths = Quantity( - type=MEnum('non-correlated metal', 'strongly-correlated metal', 'OSMI', 'Mott insulator'), + type=MEnum( + 'non-correlated metal', + 'strongly-correlated metal', + 'OSMI', + 'Mott insulator', + ), description=""" String used to identify the type of system based on the strength of the electron-electron interactions. @@ -338,7 +366,10 @@ def __init__( ) -> None: super().__init__(m_def, m_context, **kwargs) # ! n_orbitals need to be set up during initialization of the class - self.rank = [int(kwargs.get('n_atoms')), int(kwargs.get('n_correlated_orbitals'))] + self.rank = [ + int(kwargs.get('n_atoms')), + int(kwargs.get('n_correlated_orbitals')), + ] self.name = self.m_def.name def is_valid_quasiparticle_weight(self) -> bool: @@ -380,7 +411,10 @@ def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None: return system_correlation_strengths = self.resolve_system_correlation_strengths() - if (self.system_correlation_strengths is not None and self.system_correlation_strengths != system_correlation_strengths): + if ( + self.system_correlation_strengths is not None + and self.system_correlation_strengths != system_correlation_strengths + ): logger.warning( f'The stored `system_correlation_strengths`, {self.system_correlation_strengths}, does not coincide with the resolved one, {system_correlation_strengths}. We will update it.' ) diff --git a/tests/conftest.py b/tests/conftest.py index 097298c2..c4a5a798 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -23,7 +23,6 @@ import pytest from nomad.datamodel import EntryArchive from nomad.units import ureg - from nomad_simulations.schema_packages.atoms_state import AtomsState, OrbitalsState from nomad_simulations.schema_packages.general import Simulation from nomad_simulations.schema_packages.model_method import ModelMethod diff --git a/tests/test_atoms_state.py b/tests/test_atoms_state.py index dd2aa70c..65a1e3d0 100644 --- a/tests/test_atoms_state.py +++ b/tests/test_atoms_state.py @@ -22,7 +22,6 @@ import pytest from nomad.datamodel import EntryArchive from nomad.units import ureg - from nomad_simulations.schema_packages.atoms_state import ( AtomsState, CoreHole, diff --git a/tests/test_band_gap.py b/tests/test_band_gap.py index 8d8a6b53..b47abe1b 100644 --- a/tests/test_band_gap.py +++ b/tests/test_band_gap.py @@ -22,7 +22,6 @@ import pytest from nomad.datamodel import EntryArchive from nomad.units import ureg - from nomad_simulations.schema_packages.properties import ElectronicBandGap from nomad_simulations.schema_packages.variables import Temperature diff --git a/tests/test_band_structure.py b/tests/test_band_structure.py index 1e81aab5..4dd72ecd 100644 --- a/tests/test_band_structure.py +++ b/tests/test_band_structure.py @@ -21,7 +21,6 @@ import numpy as np import pytest from nomad.datamodel import EntryArchive - from nomad_simulations.schema_packages.properties import ElectronicEigenvalues from . import logger diff --git a/tests/test_fermi_surface.py b/tests/test_fermi_surface.py index 05c7206b..dde4ce1f 100644 --- a/tests/test_fermi_surface.py +++ b/tests/test_fermi_surface.py @@ -19,7 +19,6 @@ from typing import Optional import pytest - from nomad_simulations.schema_packages.properties import FermiSurface diff --git a/tests/test_general.py b/tests/test_general.py index 06a360c9..e722e03e 100644 --- a/tests/test_general.py +++ b/tests/test_general.py @@ -19,7 +19,6 @@ import numpy as np import pytest from nomad.datamodel import EntryArchive - from nomad_simulations.schema_packages.general import Simulation from nomad_simulations.schema_packages.model_system import ( AtomicCell, diff --git a/tests/test_greens_function.py b/tests/test_greens_function.py index 3dae739b..e7b90f00 100644 --- a/tests/test_greens_function.py +++ b/tests/test_greens_function.py @@ -20,7 +20,6 @@ import pytest from nomad.datamodel import EntryArchive - from nomad_simulations.schema_packages.properties import ( QuasiparticleWeight, ) @@ -64,7 +63,15 @@ class TestBaseGreensFunction: ([KMesh(), MatsubaraFrequency()], 'kiw'), ], ) - def test_resolve_space_id(self, variables: list[Union[WignerSeitz, KMesh, Time, ImaginaryTime, Frequency, MatsubaraFrequency]], result: str): + def test_resolve_space_id( + self, + variables: list[ + Union[ + WignerSeitz, KMesh, Time, ImaginaryTime, Frequency, MatsubaraFrequency + ] + ], + result: str, + ): """ Test the `resolve_space_id` method of the `BaseGreensFunction` class. """ @@ -94,7 +101,16 @@ def test_resolve_space_id(self, variables: list[Union[WignerSeitz, KMesh, Time, ('', [KMesh(), MatsubaraFrequency()], 'kiw'), ], ) - def test_normalize(self, space_id: str, variables: list[Union[WignerSeitz, KMesh, Time, ImaginaryTime, Frequency, MatsubaraFrequency]], result: Optional[str]): + def test_normalize( + self, + space_id: str, + variables: list[ + Union[ + WignerSeitz, KMesh, Time, ImaginaryTime, Frequency, MatsubaraFrequency + ] + ], + result: Optional[str], + ): """ Test the `normalize` method of the `BaseGreensFunction` class. """ @@ -105,7 +121,6 @@ def test_normalize(self, space_id: str, variables: list[Union[WignerSeitz, KMesh assert gfs.space_id == result - class TestQuasiparticleWeight: """ Test the `QuasiparticleWeight` class defined in `properties/greens_function.py`. @@ -127,7 +142,6 @@ def test_is_valid_quasiparticle_weight(self, value: list[float], result: bool): quasiparticle_weight.value = value assert quasiparticle_weight.is_valid_quasiparticle_weight() == result - @pytest.mark.parametrize( 'value, result', [ @@ -138,7 +152,9 @@ def test_is_valid_quasiparticle_weight(self, value: list[float], result: bool): ([[1.0, 0.8, 0.2]], None), ], ) - def test_resolve_system_correlation_strengths(self, value: list[float], result: Optional[str]): + def test_resolve_system_correlation_strengths( + self, value: list[float], result: Optional[str] + ): """ Test the `resolve_system_correlation_strengths` method of the `QuasiparticleWeight` class. """ diff --git a/tests/test_hopping_matrix.py b/tests/test_hopping_matrix.py index b7cf43d7..cfe6ada2 100644 --- a/tests/test_hopping_matrix.py +++ b/tests/test_hopping_matrix.py @@ -19,7 +19,6 @@ from typing import Optional import pytest - from nomad_simulations.schema_packages.properties import ( CrystalFieldSplitting, HoppingMatrix, diff --git a/tests/test_model_method.py b/tests/test_model_method.py index 7e51e22d..b66c5e25 100644 --- a/tests/test_model_method.py +++ b/tests/test_model_method.py @@ -20,7 +20,6 @@ import pytest from nomad.datamodel import EntryArchive - from nomad_simulations.schema_packages.atoms_state import AtomsState, OrbitalsState from nomad_simulations.schema_packages.general import Simulation from nomad_simulations.schema_packages.model_method import ( diff --git a/tests/test_model_system.py b/tests/test_model_system.py index 6ead47e8..ecb67a76 100644 --- a/tests/test_model_system.py +++ b/tests/test_model_system.py @@ -21,7 +21,6 @@ import numpy as np import pytest from nomad.datamodel import EntryArchive - from nomad_simulations.schema_packages.model_system import ( ChemicalFormula, ModelSystem, diff --git a/tests/test_numerical_settings.py b/tests/test_numerical_settings.py index 70ab30da..aab071ce 100644 --- a/tests/test_numerical_settings.py +++ b/tests/test_numerical_settings.py @@ -22,7 +22,6 @@ import pytest from nomad.datamodel import EntryArchive from nomad.units import ureg - from nomad_simulations.schema_packages.numerical_settings import ( KLinePath, KMesh, diff --git a/tests/test_outputs.py b/tests/test_outputs.py index a63a1f23..b3e81d48 100644 --- a/tests/test_outputs.py +++ b/tests/test_outputs.py @@ -20,7 +20,6 @@ import pytest from nomad.datamodel import EntryArchive - from nomad_simulations.schema_packages.model_method import ModelMethod from nomad_simulations.schema_packages.model_system import ModelSystem from nomad_simulations.schema_packages.numerical_settings import SelfConsistency diff --git a/tests/test_permittivity.py b/tests/test_permittivity.py index f6955f97..9cb58fbc 100644 --- a/tests/test_permittivity.py +++ b/tests/test_permittivity.py @@ -20,7 +20,6 @@ import numpy as np import pytest - from nomad_simulations.schema_packages.properties import Permittivity from nomad_simulations.schema_packages.variables import Frequency, KMesh, Variables diff --git a/tests/test_physical_properties.py b/tests/test_physical_properties.py index b9e9e1bf..12191221 100644 --- a/tests/test_physical_properties.py +++ b/tests/test_physical_properties.py @@ -23,7 +23,6 @@ from nomad.datamodel import EntryArchive from nomad.metainfo import Quantity from nomad.units import ureg - from nomad_simulations.schema_packages.physical_property import ( PhysicalProperty, validate_quantity_wrt_value, diff --git a/tests/test_spectral_profile.py b/tests/test_spectral_profile.py index 4184bbb7..003bd029 100644 --- a/tests/test_spectral_profile.py +++ b/tests/test_spectral_profile.py @@ -22,7 +22,6 @@ import pytest from nomad.datamodel import EntryArchive from nomad.units import ureg - from nomad_simulations.schema_packages.atoms_state import AtomsState from nomad_simulations.schema_packages.general import Simulation from nomad_simulations.schema_packages.model_system import AtomicCell, ModelSystem diff --git a/tests/test_utils.py b/tests/test_utils.py index 3d3e69cf..8cf7512a 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -17,7 +17,6 @@ # import pytest - from nomad_simulations.schema_packages.model_system import ( AtomicCell, ModelSystem, diff --git a/tests/test_variables.py b/tests/test_variables.py index c64faf91..2fd63a00 100644 --- a/tests/test_variables.py +++ b/tests/test_variables.py @@ -18,7 +18,6 @@ import pytest from nomad.datamodel import EntryArchive - from nomad_simulations.schema_packages.variables import Variables from . import logger