Skip to content

Commit

Permalink
Linting and mypy fix
Browse files Browse the repository at this point in the history
  • Loading branch information
munrojm committed May 21, 2021
1 parent 7acbbad commit 83ce09e
Showing 1 changed file with 28 additions and 79 deletions.
107 changes: 28 additions & 79 deletions src/mp_api/routes/electronic_structure/query_operators.py
@@ -1,4 +1,4 @@
from typing import Optional, Union, Literal
from typing import Optional, Union, Literal # type: ignore
from fastapi import Query, HTTPException
from pymatgen.analysis.magnetism.analyzer import Ordering
from pymatgen.electronic_structure.core import Spin, OrbitalType
Expand All @@ -17,27 +17,13 @@ class ESSummaryDataQuery(QueryOperator):

def query(
self,
band_gap_max: Optional[float] = Query(
None, description="Maximum value for the band gap energy in eV."
),
band_gap_min: Optional[float] = Query(
None, description="Minimum value for the band gap energy in eV."
),
efermi_max: Optional[float] = Query(
None, description="Maximum value for the fermi energy in eV."
),
efermi_min: Optional[float] = Query(
None, description="Minimum value for the fermi energy in eV."
),
magnetic_ordering: Optional[Ordering] = Query(
None, description="Magnetic ordering associated with the data."
),
is_gap_direct: Optional[bool] = Query(
None, description="Whether a band gap is direct or not."
),
is_metal: Optional[bool] = Query(
None, description="Whether the material is considered a metal."
),
band_gap_max: Optional[float] = Query(None, description="Maximum value for the band gap energy in eV."),
band_gap_min: Optional[float] = Query(None, description="Minimum value for the band gap energy in eV."),
efermi_max: Optional[float] = Query(None, description="Maximum value for the fermi energy in eV."),
efermi_min: Optional[float] = Query(None, description="Minimum value for the fermi energy in eV."),
magnetic_ordering: Optional[Ordering] = Query(None, description="Magnetic ordering associated with the data."),
is_gap_direct: Optional[bool] = Query(None, description="Whether a band gap is direct or not."),
is_metal: Optional[bool] = Query(None, description="Whether the material is considered a metal."),
) -> STORE_PARAMS:

crit = defaultdict(dict) # type: dict
Expand Down Expand Up @@ -82,38 +68,21 @@ def query(
path_type: Optional[BSPathType] = Query(
None, description="k-path selection convention for the band structure.",
),
band_gap_max: Optional[float] = Query(
None, description="Maximum value for the band gap energy in eV."
),
band_gap_min: Optional[float] = Query(
None, description="Minimum value for the band gap energy in eV."
),
efermi_max: Optional[float] = Query(
None, description="Maximum value for the fermi energy in eV."
),
efermi_min: Optional[float] = Query(
None, description="Minimum value for the fermi energy in eV."
),
magnetic_ordering: Optional[Ordering] = Query(
None, description="Magnetic ordering associated with the data."
),
is_gap_direct: Optional[bool] = Query(
None, description="Whether a band gap is direct or not."
),
is_metal: Optional[bool] = Query(
None, description="Whether the material is considered a metal."
),
band_gap_max: Optional[float] = Query(None, description="Maximum value for the band gap energy in eV."),
band_gap_min: Optional[float] = Query(None, description="Minimum value for the band gap energy in eV."),
efermi_max: Optional[float] = Query(None, description="Maximum value for the fermi energy in eV."),
efermi_min: Optional[float] = Query(None, description="Minimum value for the fermi energy in eV."),
magnetic_ordering: Optional[Ordering] = Query(None, description="Magnetic ordering associated with the data."),
is_gap_direct: Optional[bool] = Query(None, description="Whether a band gap is direct or not."),
is_metal: Optional[bool] = Query(None, description="Whether the material is considered a metal."),
) -> STORE_PARAMS:

crit = defaultdict(dict) # type: dict

if path_type is not None:

d = {
f"bandstructure.{path_type.value}.band_gap": [
band_gap_min,
band_gap_max,
],
f"bandstructure.{path_type.value}.band_gap": [band_gap_min, band_gap_max,],
f"bandstructure.{path_type.value}.efermi": [efermi_min, efermi_max],
}

Expand All @@ -125,9 +94,7 @@ def query(
crit[entry]["$lte"] = d[entry][1]

if magnetic_ordering:
crit[
f"bandstructure.{path_type.value}.magnetic_ordering"
] = magnetic_ordering.value
crit[f"bandstructure.{path_type.value}.magnetic_ordering"] = magnetic_ordering.value

if is_gap_direct is not None:
crit[f"bandstructure.{path_type.value}.is_gap_direct"] = is_gap_direct
Expand Down Expand Up @@ -159,30 +126,15 @@ def query(
None, description="Projection type for the density of states data.",
),
spin: Optional[Union[Literal["1", "-1"], Spin]] = Query(
None,
description="Spin channel for density of states data. '1' corresponds to spin up.",
),
element: Optional[Element] = Query(
None, description="Element type for projected density of states data.",
),
orbital: Optional[OrbitalType] = Query(
None, description="Orbital type for projected density of states data.",
),
band_gap_max: Optional[float] = Query(
None, description="Maximum value for the band gap energy in eV."
),
band_gap_min: Optional[float] = Query(
None, description="Minimum value for the band gap energy in eV."
),
efermi_max: Optional[float] = Query(
None, description="Maximum value for the fermi energy in eV."
),
efermi_min: Optional[float] = Query(
None, description="Minimum value for the fermi energy in eV."
),
magnetic_ordering: Optional[Ordering] = Query(
None, description="Magnetic ordering associated with the data."
),
None, description="Spin channel for density of states data. '1' corresponds to spin up.",
),
element: Optional[Element] = Query(None, description="Element type for projected density of states data.",),
orbital: Optional[OrbitalType] = Query(None, description="Orbital type for projected density of states data.",),
band_gap_max: Optional[float] = Query(None, description="Maximum value for the band gap energy in eV."),
band_gap_min: Optional[float] = Query(None, description="Minimum value for the band gap energy in eV."),
efermi_max: Optional[float] = Query(None, description="Maximum value for the fermi energy in eV."),
efermi_min: Optional[float] = Query(None, description="Minimum value for the fermi energy in eV."),
magnetic_ordering: Optional[Ordering] = Query(None, description="Magnetic ordering associated with the data."),
) -> STORE_PARAMS:

crit = defaultdict(dict) # type: dict
Expand All @@ -193,8 +145,7 @@ def query(
if projection_type is not None:
if spin is None:
raise HTTPException(
status_code=400,
detail="Must specify a spin channel for querying dos summary data.",
status_code=400, detail="Must specify a spin channel for querying dos summary data.",
)
else:

Expand Down Expand Up @@ -230,9 +181,7 @@ def query(
key_prefix = f"element.{str(element.value)}.{str(orbital.name)}.{str(spin.value)}"

else:
key_prefix = (
f"element.{str(element.value)}.total.{str(spin.value)}"
)
key_prefix = f"element.{str(element.value)}.total.{str(spin.value)}"

key = f"dos.{key_prefix}.{entry}"

Expand Down

0 comments on commit 83ce09e

Please sign in to comment.