-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This reverts commit 1dffb90.
- Loading branch information
Showing
73 changed files
with
3,595 additions
and
1,520 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
110 changes: 110 additions & 0 deletions
110
emmet-api/emmet/api/routes/molecules/electric/query_operators.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
from typing import Any, Literal, Optional, Dict | ||
from fastapi import Query | ||
from maggma.api.query_operator import QueryOperator | ||
from maggma.api.utils import STORE_PARAMS | ||
|
||
|
||
allowed_components = { | ||
"dipole": {"X", "Y", "Z"}, | ||
"resp_dipole": {"X", "Y", "Z"}, | ||
"quadrupole": {"XX", "XY", "YY", "XZ", "YZ", "ZZ"}, | ||
"octopole": {"XXX", "XXY", "XYY", "YYY", "XXZ", "XYZ", "YYZ", "XZZ", "YZZ", "ZZZ"}, | ||
"hexadecapole": { | ||
"XXXX", | ||
"XXXY", | ||
"XXYY", | ||
"XYYY", | ||
"YYYY", | ||
"XXXZ", | ||
"XXYZ", | ||
"XYYZ", | ||
"YYYZ", | ||
"XXZZ", | ||
"XYZZ", | ||
"YYZZ", | ||
"XZZZ", | ||
"YZZZ", | ||
"ZZZZ", | ||
}, | ||
} | ||
|
||
|
||
class MultipoleMomentComponentQuery(QueryOperator): | ||
""" | ||
Method to generate a query on components of electric multipole moments. | ||
""" | ||
|
||
def query( | ||
self, | ||
moment_type: Optional[ | ||
Literal["dipole", "resp_dipole", "quadrupole", "octopole", "hexadecapole"] | ||
] = Query( | ||
None, | ||
description=( | ||
"Type of multipole moment. Allowed values: 'dipole', 'resp_dipole', 'quadrupole', 'octopole', and " | ||
"'hexadecapole'" | ||
), | ||
), | ||
component: Optional[str] = Query( | ||
None, | ||
description="Component to query on, i.e. 'X', 'Y', or 'Z' for dipole moments", | ||
), | ||
component_value_min: Optional[float] = Query( | ||
None, description="Minimum value for the multipole moment component" | ||
), | ||
component_value_max: Optional[float] = Query( | ||
None, description="Maximum value for the multipole moment component" | ||
), | ||
) -> STORE_PARAMS: | ||
self.moment_type = moment_type | ||
self.component = component | ||
self.min_value = component_value_min | ||
self.max_value = component_value_max | ||
|
||
if self.moment_type is None or self.component is None: | ||
return {"criteria": dict()} | ||
|
||
allowed = allowed_components[self.moment_type] | ||
|
||
if self.component not in allowed: | ||
raise ValueError( | ||
f"Improper component! Allowed components for {self.moment_type} are {allowed}!" | ||
) | ||
|
||
key_prefix = self.moment_type + "_moment" | ||
|
||
if self.moment_type in ["dipole", "resp_dipole"]: | ||
mapping = {"X": "0", "Y": "1", "Z": "2"} | ||
key_suffix = mapping[self.component] | ||
else: | ||
key_suffix = self.component | ||
|
||
key = key_prefix + "." + key_suffix | ||
|
||
crit: Dict[str, Any] = {key: dict()} # type: ignore | ||
|
||
if self.min_value is not None and isinstance(self.min_value, float): | ||
crit[key]["$gte"] = self.min_value | ||
if self.max_value is not None and isinstance(self.max_value, float): | ||
crit[key]["$lte"] = self.max_value | ||
|
||
if not isinstance(self.min_value, float) and not isinstance( | ||
self.max_value, float | ||
): | ||
crit[key]["$exists"] = True | ||
|
||
return {"criteria": crit} | ||
|
||
def ensure_indexes(self): | ||
# Right now, indexing on all sub-fields of all electric multipole moments | ||
# TODO: is this necessary? Is this the best way to do this? | ||
indexes = list() | ||
for dp in ["dipole_moment", "resp_dipole_moment"]: | ||
for index in range(3): | ||
indexes.append((f"{dp}.{index}", False)) | ||
|
||
for mp in ["quadrupole", "octopole", "hexadecapole"]: | ||
for valid_key in allowed_components[mp]: | ||
indexes.append((f"{mp}_moment.{valid_key}", False)) | ||
|
||
return indexes |
64 changes: 64 additions & 0 deletions
64
emmet-api/emmet/api/routes/molecules/electric/resources.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from maggma.api.resource import ReadOnlyResource | ||
from emmet.core.molecules.electric import ElectricMultipoleDoc | ||
|
||
from maggma.api.query_operator import ( | ||
PaginationQuery, | ||
SparseFieldsQuery, | ||
NumericQuery, | ||
) | ||
|
||
from emmet.api.routes.molecules.electric.query_operators import ( | ||
MultipoleMomentComponentQuery, | ||
) | ||
from emmet.api.routes.molecules.molecules.query_operators import ( | ||
MultiMPculeIDQuery, | ||
ExactCalcMethodQuery, | ||
FormulaQuery, | ||
ChemsysQuery, | ||
CompositionElementsQuery, | ||
ChargeSpinQuery, | ||
) | ||
from emmet.api.routes.molecules.utils import MultiPropertyIDQuery | ||
from emmet.api.core.settings import MAPISettings | ||
from emmet.api.core.global_header import GlobalHeaderProcessor | ||
|
||
|
||
def electric_multipole_resource(multipole_store): | ||
resource = ReadOnlyResource( | ||
multipole_store, | ||
ElectricMultipoleDoc, | ||
query_operators=[ | ||
MultiMPculeIDQuery(), | ||
ExactCalcMethodQuery(), | ||
FormulaQuery(), | ||
ChemsysQuery(), | ||
CompositionElementsQuery(), | ||
ChargeSpinQuery(), | ||
MultiPropertyIDQuery(), | ||
MultipoleMomentComponentQuery(), | ||
PaginationQuery(), | ||
NumericQuery( | ||
model=ElectricMultipoleDoc, | ||
fields=[ | ||
"total_dipole", | ||
"resp_total_dipole", | ||
], | ||
), | ||
SparseFieldsQuery( | ||
ElectricMultipoleDoc, | ||
default_fields=[ | ||
"molecule_id", | ||
"property_id", | ||
"solvent", | ||
"last_updated", | ||
], | ||
), | ||
], | ||
header_processor=GlobalHeaderProcessor(), | ||
tags=["Molecules Electric Dipoles and Multipoles"], | ||
sub_path="/multipoles/", | ||
disable_validation=True, | ||
timeout=MAPISettings().TIMEOUT, | ||
) | ||
|
||
return resource |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.