Skip to content

Commit

Permalink
ruff . --fix
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed Oct 19, 2023
1 parent 5197f09 commit 419e82e
Show file tree
Hide file tree
Showing 57 changed files with 310 additions and 185 deletions.
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
from __future__ import annotations

import os
import sys
Expand Down
1 change: 1 addition & 0 deletions src/atomate2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Atomate2 is a library of computational materials science workflows."""
from __future__ import annotations

from atomate2._version import __version__
from atomate2.settings import Atomate2Settings
Expand Down
2 changes: 2 additions & 0 deletions src/atomate2/_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from importlib.metadata import version

__version__ = version("atomate2")
13 changes: 8 additions & 5 deletions src/atomate2/amset/schemas.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
"""Module defining amset document schemas."""
from __future__ import annotations

import logging
import re
from pathlib import Path
from typing import Any, Union
from typing import TYPE_CHECKING, Any

import numpy as np
from emmet.core.math import Matrix3D, Vector3D
from emmet.core.structure import StructureMetadata
from monty.dev import requires
from monty.serialization import loadfn
from pydantic import BaseModel, Field
from pymatgen.core import Structure

from atomate2 import __version__
from atomate2.utils.datetime import datetime_str
from atomate2.utils.path import get_uri

if TYPE_CHECKING:
from emmet.core.math import Matrix3D, Vector3D
from pymatgen.core import Structure

try:
import amset
except ImportError:
Expand Down Expand Up @@ -141,10 +144,10 @@ class AmsetTaskDocument(StructureMetadata):
@requires(amset, "amset must be installed to create an AmsetTaskDocument.")
def from_directory(
cls,
dir_name: Union[Path, str],
dir_name: Path | str,
additional_fields: dict[str, Any] = None,
include_mesh: bool = False,
) -> "AmsetTaskDocument":
) -> AmsetTaskDocument:
"""
Create a task document from a directory containing VASP files.
Expand Down
1 change: 1 addition & 0 deletions src/atomate2/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module containing the atomate2 command-line interface."""
from __future__ import annotations

import click

Expand Down
1 change: 1 addition & 0 deletions src/atomate2/cli/dev.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module containing command line scripts for developers."""
from __future__ import annotations

import click

Expand Down
2 changes: 2 additions & 0 deletions src/atomate2/common/jobs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
"""DFT code agnostic jobs."""
from __future__ import annotations

from .utils import structure_to_conventional, structure_to_primitive
27 changes: 15 additions & 12 deletions src/atomate2/common/schemas/cclib.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Core definition of a cclib-generated task document."""
from __future__ import annotations

import logging
import os
from pathlib import Path
from typing import Any, Optional, TypeVar, Union
from typing import TYPE_CHECKING, Any, TypeVar

from emmet.core.structure import MoleculeMetadata
from monty.dev import requires
Expand All @@ -16,6 +16,9 @@
from atomate2.utils.datetime import datetime_str
from atomate2.utils.path import find_recent_logfile, get_uri

if TYPE_CHECKING:
from pathlib import Path

try:
import cclib
except ImportError:
Expand Down Expand Up @@ -62,13 +65,13 @@ class TaskDocument(MoleculeMetadata, extra="allow"): # type: ignore[call-arg]
@requires(cclib, "The cclib TaskDocument requires cclib to be installed.")
def from_logfile(
cls: type[_T],
dir_name: Union[str, Path],
logfile_extensions: Union[str, list[str]],
dir_name: str | Path,
logfile_extensions: str | list[str],
store_trajectory: bool = False,
additional_fields: Optional[dict[str, Any]] = None,
analysis: Optional[Union[str, list[str]]] = None,
proatom_dir: Optional[Union[Path, str]] = None,
) -> "TaskDocument":
additional_fields: dict[str, Any] | None = None,
analysis: str | list[str] | None = None,
proatom_dir: Path | str | None = None,
) -> TaskDocument:
"""
Create a TaskDocument from a log file.
Expand Down Expand Up @@ -252,9 +255,9 @@ def from_logfile(
def cclib_calculate(
cclib_obj,
method: str,
cube_file: Union[Path, str],
proatom_dir: Union[Path, str],
) -> Optional[dict[str, Any]]:
cube_file: Path | str,
proatom_dir: Path | str,
) -> dict[str, Any] | None:
"""
Run a cclib population analysis.
Expand Down Expand Up @@ -352,7 +355,7 @@ def cclib_calculate(

def _get_homos_lumos(
moenergies: list[list[float]], homo_indices: list[int]
) -> tuple[list[float], Optional[list[float]], Optional[list[float]]]:
) -> tuple[list[float], list[float] | None, list[float] | None]:
"""
Calculate the HOMO, LUMO, and HOMO-LUMO gap energies in eV.
Expand Down
27 changes: 15 additions & 12 deletions src/atomate2/common/schemas/defects.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
"""General schemas for defect workflow outputs."""
from __future__ import annotations

import logging
from typing import Any, Callable, Optional, Union
from typing import TYPE_CHECKING, Any, Callable

import numpy as np
from emmet.core.tasks import TaskDoc
from pydantic import BaseModel, Field
from pymatgen.analysis.defects.core import Defect
from pymatgen.analysis.defects.thermo import DefectEntry, FormationEnergyDiagram
from pymatgen.core import Structure
from pymatgen.entries.computed_entries import ComputedEntry, ComputedStructureEntry

if TYPE_CHECKING:
from pymatgen.analysis.defects.core import Defect
from pymatgen.core import Structure

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -58,7 +61,7 @@ class FormationEnergyDiagramDocument(BaseModel):
None, description="The directory names of the charged defect calculations."
)

dielectric: Union[float, list[list[float]]] = Field(
dielectric: float | list[list[float]] = Field(
None,
description="The dielectric constant or tensor, can be used to compute "
"finite-size corrections.",
Expand All @@ -67,7 +70,7 @@ class FormationEnergyDiagramDocument(BaseModel):
@classmethod
def from_formation_energy_diagram(
cls, fed: FormationEnergyDiagram, **kwargs
) -> "FormationEnergyDiagramDocument":
) -> FormationEnergyDiagramDocument:
"""Create a document from a `FormationEnergyDiagram` object.
Args:
Expand All @@ -87,7 +90,7 @@ def from_formation_energy_diagram(
)

def as_formation_energy_diagram(
self, pd_entries: Optional[list[ComputedEntry]] = None
self, pd_entries: list[ComputedEntry] | None = None
) -> FormationEnergyDiagram:
"""Create a `FormationEnergyDiagram` object from the document.
Expand Down Expand Up @@ -150,13 +153,13 @@ class CCDDocument(BaseModel):
"in charge state (q2).",
)

static_uuids1: Optional[list[str]] = Field(
static_uuids1: list[str] | None = Field(
None,
description="UUIDs of distorted calculations for the defect (supercell) in "
"charge state (q1).",
)

static_uuids2: Optional[list[str]] = Field(
static_uuids2: list[str] | None = Field(
None,
description="UUIDs of distorted calculations for the defect (supercell) in "
"charge state (q2).",
Expand Down Expand Up @@ -187,7 +190,7 @@ def from_task_outputs(
static_uuids2: list[str],
relaxed_uuid1: str,
relaxed_uuid2: str,
) -> "CCDDocument":
) -> CCDDocument:
"""Create a CCDDocument from a lists of structures and energies.
The directories and the UUIDs of the static calculations are also provided as
Expand Down Expand Up @@ -246,9 +249,9 @@ def from_entries(
cls,
entries1: list[ComputedStructureEntry],
entries2: list[ComputedStructureEntry],
relaxed_uuid1: Optional[str] = None,
relaxed_uuid2: Optional[str] = None,
) -> "CCDDocument":
relaxed_uuid1: str | None = None,
relaxed_uuid2: str | None = None,
) -> CCDDocument:
"""
Create a CCDTaskDocument from a list of distorted calculations.
Expand Down
20 changes: 12 additions & 8 deletions src/atomate2/common/schemas/elastic.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""Schemas for elastic tensor fitting and related properties."""
from __future__ import annotations

from copy import deepcopy
from typing import Optional
from typing import TYPE_CHECKING

import numpy as np
from emmet.core.math import Matrix3D, MatrixVoigt
from emmet.core.structure import StructureMetadata
from pydantic import BaseModel, Field
from pymatgen.analysis.elasticity import (
Expand All @@ -13,12 +14,15 @@
Strain,
Stress,
)
from pymatgen.core import Structure
from pymatgen.core.tensors import TensorMapping
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer

from atomate2 import SETTINGS

if TYPE_CHECKING:
from emmet.core.math import Matrix3D, MatrixVoigt
from pymatgen.core import Structure


class DerivedProperties(BaseModel):
"""Properties derived from an elastic tensor."""
Expand Down Expand Up @@ -61,7 +65,7 @@ class DerivedProperties(BaseModel):
snyder_total: float = Field(
None, description="Synder's total sound velocity (SI units)."
)
clark_thermalcond: Optional[float] = Field(
clark_thermalcond: float | None = Field(
None, description="Clarke's thermal conductivity (SI units)."
)
cahill_thermalcond: float = Field(
Expand Down Expand Up @@ -111,7 +115,7 @@ class ElasticDocument(StructureMetadata):
elastic_tensor: ElasticTensorDocument = Field(
None, description="Fitted elastic tensor."
)
eq_stress: Optional[Matrix3D] = Field(
eq_stress: Matrix3D | None = Field(
None, description="The equilibrium stress of the structure."
)
derived_properties: DerivedProperties = Field(
Expand All @@ -136,11 +140,11 @@ def from_stresses(
uuids: list[str],
job_dirs: list[str],
fitting_method: str = SETTINGS.ELASTIC_FITTING_METHOD,
order: Optional[int] = None,
equilibrium_stress: Optional[Matrix3D] = None,
order: int | None = None,
equilibrium_stress: Matrix3D | None = None,
symprec: float = SETTINGS.SYMPREC,
allow_elastically_unstable_structs: bool = True,
) -> "ElasticDocument":
) -> ElasticDocument:
"""
Create an elastic document from strains and stresses.
Expand Down
Loading

0 comments on commit 419e82e

Please sign in to comment.