Skip to content

Commit e4f2cc9

Browse files
authored
Merge branch 'master' into molextras
2 parents 35bbd94 + 7cb0fc8 commit e4f2cc9

20 files changed

+255
-163
lines changed

qcelemental/__init__.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,23 @@
33
"""
44

55
from . import models, molparse, molutil, util
6-
from .covalent_radii import CovalentRadii, covalentradii
76
from .datum import Datum
87
from .exceptions import ChoicesError, DataUnavailableError, MoleculeFormatError, NotAnElementError, ValidationError
98
# Handle versioneer
109
from .extras import get_information
1110
# Handle singletons, not their classes or modules
12-
from .periodic_table import periodictable
13-
from .physical_constants import PhysicalConstantsContext, constants
11+
from . import covalent_radii, periodic_table, physical_constants
12+
# from .physical_constants import PhysicalConstantsContext, constants
1413
from .testing import compare, compare_recursive, compare_values
1514

15+
# Expose singletons from the modules
16+
periodictable = periodic_table.periodictable
17+
PhysicalConstantsContext = physical_constants.PhysicalConstantsContext
18+
constants = physical_constants.constants
19+
CovalentRadii = covalent_radii.CovalentRadii
20+
covalentradii = covalent_radii.covalentradii
21+
22+
# Remove singleton-providing modules from known imported objects
1623
del periodic_table
1724
del physical_constants
1825
del covalent_radii

qcelemental/covalent_radii.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import collections
66
from decimal import Decimal
7-
from typing import Union
7+
from typing import Union, Dict
88

99
from .datum import Datum, print_variables
1010
from .exceptions import DataUnavailableError
@@ -38,21 +38,22 @@ class CovalentRadii:
3838
3939
"""
4040
def __init__(self, context: str = "ALVAREZ2008"):
41-
self.cr = collections.OrderedDict()
41+
self.cr: Dict[str, Datum] = collections.OrderedDict()
4242

4343
from .data import alvarez_2008_covalent_radii
4444

4545
if context == "ALVAREZ2008":
4646
self.doi = alvarez_2008_covalent_radii["doi"]
4747
self.native_units = alvarez_2008_covalent_radii["units"]
4848

49-
for cr in alvarez_2008_covalent_radii["covalent_radii"]:
49+
# TypedDict wont be in until 3.8, have to ignore heterogeneous dicts for now
50+
for cr in alvarez_2008_covalent_radii["covalent_radii"]: # type: ignore
5051
self.cr[cr[0]] = Datum(cr[0], self.native_units, Decimal(cr[1]), comment=cr[2], doi=self.doi)
5152
else:
5253
raise KeyError("Context set as '{}', only contexts {'ALVAREZ2008', } are currently supported")
5354

5455
self.name = context
55-
self.year = int(alvarez_2008_covalent_radii["date"][:4])
56+
self.year = int(alvarez_2008_covalent_radii["date"][:4]) # type: ignore
5657

5758
# Extra relationships
5859
aliases = [
@@ -116,6 +117,7 @@ def get(self, atom: Union[int, str], *, return_tuple: bool = False, units: str =
116117
identifier = periodictable.to_E(atom)
117118

118119
try:
120+
assert isinstance(identifier, str) # Should be string by now
119121
qca = self.cr[identifier]
120122
except KeyError as e:
121123
if missing is not None and return_tuple is False:

qcelemental/models/align.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ class AlignmentMill(ProtoModel):
1717
then molecular system can be substantively changed by procedure.
1818
1919
"""
20-
shift: Array[float]
21-
rotation: Array[float]
22-
atommap: Array[int]
20+
shift: Array[float] # type: ignore
21+
rotation: Array[float] # type: ignore
22+
atommap: Array[int] # type: ignore
2323
mirror: bool = False
2424

2525
@validator('shift', whole=True)

qcelemental/models/basemodels.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ class Config:
2424
allow_mutation = False
2525
extra = "forbid"
2626
json_encoders = {np.ndarray: lambda v: v.flatten().tolist()}
27-
serialize_default_excludes = set()
27+
serialize_default_excludes: Set = set()
2828
serialize_skip_defaults = False
2929
force_skip_defaults = False
3030
canonical_repr = False
3131

3232
@classmethod
33-
def parse_raw(cls, data: Union[bytes, str], *, encoding: str = None) -> 'Model':
33+
def parse_raw(cls, data: Union[bytes, str], *, encoding: str = None) -> 'ProtoModel': # type: ignore
3434
"""
3535
Parses raw string or bytes into a Model object.
3636
@@ -65,7 +65,7 @@ def parse_raw(cls, data: Union[bytes, str], *, encoding: str = None) -> 'Model':
6565
return cls.parse_obj(obj)
6666

6767
@classmethod
68-
def parse_file(cls, path: Union[str, Path], *, encoding: str = None) -> 'Model':
68+
def parse_file(cls, path: Union[str, Path], *, encoding: str = None) -> 'ProtoModel': # type: ignore
6969
"""Parses a file into a Model object.
7070
7171
Parameters
@@ -95,15 +95,16 @@ def parse_file(cls, path: Union[str, Path], *, encoding: str = None) -> 'Model':
9595

9696
return cls.parse_raw(path.read_bytes(), encoding=encoding)
9797

98-
def dict(self, *args, **kwargs) -> Dict[str, Any]:
98+
def dict(self, **kwargs) -> Dict[str, Any]:
9999
encoding = kwargs.pop("encoding", None)
100100

101-
kwargs["exclude"] = (kwargs.get("exclude", None) or set()) | self.__config__.serialize_default_excludes
102-
kwargs.setdefault("skip_defaults", self.__config__.serialize_skip_defaults)
103-
if self.__config__.force_skip_defaults:
101+
kwargs["exclude"] = (
102+
(kwargs.get("exclude", None) or set()) | self.__config__.serialize_default_excludes) # type: ignore
103+
kwargs.setdefault("skip_defaults", self.__config__.serialize_skip_defaults) # type: ignore
104+
if self.__config__.force_skip_defaults: # type: ignore
104105
kwargs["skip_defaults"] = True
105106

106-
data = super().dict(*args, **kwargs)
107+
data = super().dict(**kwargs)
107108

108109
if encoding is None:
109110
return data
@@ -140,7 +141,7 @@ def serialize(self,
140141

141142
return serialize(data, encoding=encoding)
142143

143-
def compare(self, other: 'Model', **kwargs) -> bool:
144+
def compare(self, other: Union['ProtoModel', BaseModel], **kwargs) -> bool:
144145
"""Compares the current object to the provided object recursively.
145146
146147
Parameters
@@ -158,7 +159,7 @@ def compare(self, other: 'Model', **kwargs) -> bool:
158159
return compare_recursive(self, other, **kwargs)
159160

160161
def __str__(self) -> str: # lgtm: [py/inheritance/incorrect-overridden-signature]
161-
if self.__config__.canonical_repr:
162+
if self.__config__.canonical_repr: # type: ignore
162163
return super().to_string()
163164
else:
164165
return f"{self.__class__.__name__}(ProtoModel)"

qcelemental/models/common_models.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ class Model(ProtoModel):
2424
"""
2525
The quantum chemistry model specification for a given operation to compute against
2626
"""
27-
method: str = Schema(..., description="The quantum chemistry method to evaluate (e.g., B3LYP, PBE, ...).")
28-
basis: Optional[str] = Schema(
27+
method: str = Schema( # type: ignore
28+
..., description="The quantum chemistry method to evaluate (e.g., B3LYP, PBE, ...).")
29+
basis: Optional[str] = Schema( # type: ignore
2930
None,
3031
description="The quantum chemistry basis set to evaluate (e.g., 6-31g, cc-pVDZ, ...). Can be ``None`` for "
3132
"methods without basis sets.")
@@ -53,15 +54,15 @@ def derivative_int(self):
5354

5455
class ComputeError(ProtoModel):
5556
"""The type of error message raised"""
56-
error_type: str = Schema( # Error enumeration not yet strict
57-
...,
57+
error_type: str = Schema( # type: ignore
58+
..., # Error enumeration not yet strict
5859
description="The type of error which was thrown. Restrict this field short classifiers e.g. 'input_error'.")
59-
error_message: str = Schema(
60+
error_message: str = Schema( # type: ignore
6061
...,
6162
description="Text associated with the thrown error, often the backtrace, but can contain additional "
6263
"information as well.")
63-
extras: Optional[Dict[str, Any]] = Schema(None,
64-
description="Additional data to ship with the ComputeError object.")
64+
extras: Optional[Dict[str, Any]] = Schema( # type: ignore
65+
None, description="Additional data to ship with the ComputeError object.")
6566

6667
def __str__(self) -> str:
6768
return f"{self.__class__.__name__}(error_type={self.error_type} error_message:\n{self.error_message}\n)"
@@ -73,25 +74,25 @@ class FailedOperation(ProtoModel):
7374
input data which generated the failure.
7475
7576
"""
76-
id: str = Schema(
77+
id: str = Schema( # type: ignore
7778
None,
7879
description="A unique identifier which links this FailedOperation, often of the same Id of the operation "
7980
"should it have been successful. This will often be set programmatically by a database such as "
8081
"Fractal.")
81-
input_data: Any = Schema(
82+
input_data: Any = Schema( # type: ignore
8283
None,
8384
description="The input data which was passed in that generated this failure. This should be the complete "
8485
"input which when attempted to be run, caused the operation to fail.")
85-
success: bool = Schema(
86+
success: bool = Schema( # type: ignore
8687
False,
8788
description="A boolean indicator that the operation failed consistent with the model of successful operations. "
8889
"Should always be False. Allows programmatic assessment of all operations regardless of if they failed or "
8990
"succeeded")
90-
error: ComputeError = Schema(
91+
error: ComputeError = Schema( # type: ignore
9192
...,
9293
description="A container which has details of the error that failed this operation. See the "
9394
":class:`ComputeError` for more details.")
94-
extras: Optional[Dict[str, Any]] = Schema(
95+
extras: Optional[Dict[str, Any]] = Schema( # type: ignore
9596
None,
9697
description="Additional information to bundle with this Failed Operation. Details which pertain specifically "
9798
"to a thrown error should be contained in the `error` field. See :class:`ComputeError` for details.")

0 commit comments

Comments
 (0)