Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding isort for the formatting #99

Merged
merged 3 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"files.trimTrailingWhitespace": true,
"[python]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.organizeImports": "explicit"
},
"editor.defaultFormatter": "charliermarsh.ruff"
},
"python.testing.pytestArgs": [
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,17 @@ select = [
"E", # pycodestyle
"W", # pycodestyle
"PL", # pylint
"F", # Pyflakes
"UP", # pyupgrade
"I", # isort
]

ignore = [
"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
Expand Down
7 changes: 3 additions & 4 deletions src/nomad_simulations/schema_packages/atoms_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,20 @@
# limitations under the License.
#

from typing import TYPE_CHECKING, Any, Dict, Optional, Union
from typing import TYPE_CHECKING, Any, Optional, Union

import ase
import numpy as np
import pint

from nomad.datamodel.data import ArchiveSection
from nomad.datamodel.metainfo.annotations import ELNAnnotation
from nomad.datamodel.metainfo.basesections import Entity
from nomad.metainfo import MEnum, Quantity, SubSection
from nomad.units import ureg

if TYPE_CHECKING:
from nomad.metainfo import Section, Context
from nomad.datamodel.datamodel import EntryArchive
from nomad.metainfo import Context, Section
from structlog.stdlib import BoundLogger

from nomad_simulations.schema_packages.utils import RussellSaundersState
Expand Down Expand Up @@ -154,7 +153,7 @@ def __init__(self, m_def: 'Section' = None, m_context: 'Context' = None, **kwarg
)
),
}
self._orbitals_map: Dict[str, Any] = {
self._orbitals_map: dict[str, Any] = {
'l_symbols': self._orbitals[-1],
'ml_symbols': {i: self._orbitals[i] for i in range(4)},
'ms_symbols': dict(zip((-0.5, 0.5), ('down', 'up'))),
Expand Down
13 changes: 6 additions & 7 deletions src/nomad_simulations/schema_packages/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
# limitations under the License.
#

from typing import TYPE_CHECKING, List
from typing import TYPE_CHECKING

import numpy as np

from nomad.config import config
from nomad.datamodel.data import Schema
from nomad.datamodel.metainfo.annotations import ELNAnnotation
Expand Down Expand Up @@ -204,15 +203,15 @@ def resolve_composition_formula(self, system_parent: ModelSystem) -> None:
"""

def set_composition_formula(
system: ModelSystem, subsystems: List[ModelSystem], atom_labels: List[str]
system: ModelSystem, subsystems: list[ModelSystem], atom_labels: list[str]
) -> None:
"""Determine the composition formula for `system` based on its `subsystems`.
If `system` has no children, the atom_labels are used to determine the formula.

Args:
system (ModelSystem): The system under consideration.
subsystems (List[ModelSystem]): The children of system.
atom_labels (List[str]): The global list of atom labels corresponding
subsystems (list[ModelSystem]): The children of system.
atom_labels (list[str]): The global list of atom labels corresponding
to the atom indices stored in system.
"""
if not subsystems:
Expand All @@ -236,13 +235,13 @@ def set_composition_formula(
children_names=subsystem_labels
)

def get_composition_recurs(system: ModelSystem, atom_labels: List[str]) -> None:
def get_composition_recurs(system: ModelSystem, atom_labels: list[str]) -> None:
"""Traverse the system hierarchy downward and set the branch composition for
all (sub)systems at each level.

Args:
system (ModelSystem): The system to traverse downward.
atom_labels (List[str]): The global list of atom labels corresponding
atom_labels (list[str]): The global list of atom labels corresponding
to the atom indices stored in system.
"""
subsystems = system.model_system
Expand Down
35 changes: 17 additions & 18 deletions src/nomad_simulations/schema_packages/model_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@
#

import re
from typing import TYPE_CHECKING, List, Optional
from typing import TYPE_CHECKING, Optional

import numpy as np

from nomad.datamodel.data import ArchiveSection
from nomad.datamodel.metainfo.annotations import ELNAnnotation
from nomad.metainfo import MEnum, Quantity, SubSection, URL, Section
from nomad.metainfo import URL, MEnum, Quantity, Section, SubSection

if TYPE_CHECKING:
from nomad.metainfo import Context
from nomad.datamodel.datamodel import EntryArchive
from nomad.metainfo import Context
from structlog.stdlib import BoundLogger

from nomad_simulations.schema_packages.atoms_state import CoreHole, OrbitalsState
Expand Down Expand Up @@ -302,16 +301,16 @@ def __init__(self, m_def: 'Section' = None, m_context: 'Context' = None, **kwarg
}

def resolve_libxc_names(
self, xc_functionals: List[XCFunctional]
) -> Optional[List[str]]:
self, xc_functionals: list[XCFunctional]
) -> Optional[list[str]]:
"""
Resolves the `libxc_names` and sorts them from the list of `XCFunctional` sections.

Args:
xc_functionals (List[XCFunctional]): The list of `XCFunctional` sections.
xc_functionals (list[XCFunctional]): The list of `XCFunctional` sections.

Returns:
(Optional[List[str]]): The resolved and sorted `libxc_names`.
(Optional[list[str]]): The resolved and sorted `libxc_names`.
"""
return sorted(
[
Expand All @@ -323,13 +322,13 @@ def resolve_libxc_names(

def resolve_jacobs_ladder(
self,
libxc_names: List[str],
libxc_names: list[str],
) -> str:
"""
Resolves the `jacobs_ladder` from the `libxc_names`. The mapping (libxc -> NOMAD) is set in `self._jacobs_ladder_map`.

Args:
libxc_names (List[str]): The list of `libxc_names`.
libxc_names (list[str]): The list of `libxc_names`.

Returns:
(str): The resolved `jacobs_ladder`.
Expand All @@ -356,14 +355,14 @@ def resolve_jacobs_ladder(
return self._jacobs_ladder_map.get(highest_rung_abbrev, 'unavailable')

def resolve_exact_exchange_mixing_factor(
self, xc_functionals: List[XCFunctional], libxc_names: List[str]
self, xc_functionals: list[XCFunctional], libxc_names: list[str]
) -> Optional[float]:
"""
Resolves the `exact_exchange_mixing_factor` from the `xc_functionals` and `libxc_names`.

Args:
xc_functionals (List[XCFunctional]): The list of `XCFunctional` sections.
libxc_names (List[str]): The list of `libxc_names`.
xc_functionals (list[XCFunctional]): The list of `XCFunctional` sections.
libxc_names (list[str]): The list of `libxc_names`.

Returns:
(Optional[float]): The resolved `exact_exchange_mixing_factor`.
Expand All @@ -373,7 +372,7 @@ def resolve_exact_exchange_mixing_factor(
if functional.name == 'hybrid':
return functional.parameters.get('exact_exchange_mixing_factor')

def _scan_patterns(patterns: List[str], xc_name: str) -> bool:
def _scan_patterns(patterns: list[str], xc_name: str) -> bool:
return any(x for x in patterns if re.search('_' + x + '$', xc_name))

for xc_name in libxc_names:
Expand Down Expand Up @@ -496,20 +495,20 @@ def resolve_type(self) -> Optional[str]:

def resolve_orbital_references(
self,
model_systems: List[ModelSystem],
model_systems: list[ModelSystem],
logger: 'BoundLogger',
model_index: int = -1,
) -> Optional[List[OrbitalsState]]:
) -> Optional[list[OrbitalsState]]:
"""
Resolves the references to the `OrbitalsState` sections from the child `ModelSystem` section.

Args:
model_systems (List[ModelSystem]): The list of `ModelSystem` sections.
model_systems (list[ModelSystem]): The list of `ModelSystem` sections.
logger (BoundLogger): The logger to log messages.
model_index (int, optional): The `ModelSystem` section index from which resolve the references. Defaults to -1.

Returns:
Optional[List[OrbitalsState]]: The resolved references to the `OrbitalsState` sections.
Optional[list[OrbitalsState]]: The resolved references to the `OrbitalsState` sections.
"""
try:
model_system = model_systems[model_index]
Expand Down
18 changes: 7 additions & 11 deletions src/nomad_simulations/schema_packages/model_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
#

import re
from typing import TYPE_CHECKING, Optional, Tuple
from typing import TYPE_CHECKING, Optional

import ase
import numpy as np

from matid import Classifier, SymmetryAnalyzer # pylint: disable=import-error
from matid.classification.classifications import (
Atom,
Expand All @@ -32,18 +31,17 @@
Material2D,
Surface,
)

from nomad.config import config
from nomad.atomutils import Formula, get_normalized_wyckoff, search_aflow_prototype
from nomad.config import config
from nomad.datamodel.data import ArchiveSection
from nomad.datamodel.metainfo.annotations import ELNAnnotation
from nomad.datamodel.metainfo.basesections import Entity, System
from nomad.metainfo import MEnum, Quantity, SectionProxy, SubSection
from nomad.units import ureg

if TYPE_CHECKING:
from nomad.metainfo import Section, Context
from nomad.datamodel.datamodel import EntryArchive
from nomad.metainfo import Context, Section
from structlog.stdlib import BoundLogger

from nomad_simulations.schema_packages.atoms_state import AtomsState
Expand Down Expand Up @@ -541,7 +539,7 @@ def resolve_analyzed_atomic_cell(

def resolve_bulk_symmetry(
self, original_atomic_cell: AtomicCell, logger: 'BoundLogger'
) -> Tuple[Optional[AtomicCell], Optional[AtomicCell]]:
) -> tuple[Optional[AtomicCell], Optional[AtomicCell]]:
"""
Resolves the symmetry of the material being simulated using MatID and the
originally parsed data under original_atomic_cell. It generates two other
Expand All @@ -553,8 +551,7 @@ def resolve_bulk_symmetry(
uses to in MatID.SymmetryAnalyzer().
logger (BoundLogger): The logger to log messages.
Returns:
primitive_atomic_cell (Optional[AtomicCell]): The primitive `AtomicCell` section.
conventional_atomic_cell (Optional[AtomicCell]): The standarized `AtomicCell` section.
primitive_atomic_cell, conventional_atomic_cell (tuple[Optional[AtomicCell], Optional[AtomicCell]]): The primitive and standardized `AtomicCell` sections.
"""
symmetry = {}
try:
Expand Down Expand Up @@ -945,7 +942,7 @@ class ModelSystem(System):

def resolve_system_type_and_dimensionality(
self, ase_atoms: ase.Atoms, logger: 'BoundLogger'
) -> Tuple[str, int]:
) -> tuple[str, int]:
"""
Resolves the `ModelSystem.type` and `ModelSystem.dimensionality` using `MatID` classification analyzer:

Expand All @@ -954,8 +951,7 @@ def resolve_system_type_and_dimensionality(
Args:
ase.Atoms: The ASE Atoms structure to analyse.
Returns:
system_type (str): The system type as determined by MatID.
dimensionality (str): The system dimensionality as determined by MatID.
system_type, dimensionality (tuple[str]): The system type and dimensionality as determined by MatID.
"""
classification = None
system_type, dimensionality = self.type, self.dimensionality
Expand Down
Loading