Skip to content
Open
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
10 changes: 3 additions & 7 deletions qcelemental/models/basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@
from typing import Dict, List, Optional

try:
from pydantic.v1 import ConstrainedInt, Field, constr, validator
from pydantic.v1 import NonNegativeInt, Field, constr, validator
except ImportError: # Will also trap ModuleNotFoundError
from pydantic import ConstrainedInt, Field, constr, validator
from pydantic import NonNegativeInt, Field, constr, validator

from ..exceptions import ValidationError
from .basemodels import ProtoModel, qcschema_draft


class NonnegativeInt(ConstrainedInt):
ge = 0


class HarmonicType(str, Enum):
"""The angular momentum representation of a shell."""

Expand All @@ -24,7 +20,7 @@ class HarmonicType(str, Enum):
class ElectronShell(ProtoModel):
"""Information for a single electronic shell."""

angular_momentum: List[NonnegativeInt] = Field(
angular_momentum: List[NonNegativeInt] = Field(
..., description="Angular momentum for the shell as an array of integers.", min_items=1
)
harmonic_type: HarmonicType = Field(..., description=str(HarmonicType.__doc__))
Expand Down
17 changes: 6 additions & 11 deletions qcelemental/models/molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
import hashlib
import json
import warnings
from annotated_types import Ge, Le
from functools import partial
from pathlib import Path
from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Tuple, Union, cast
from typing import TYPE_CHECKING, Annotated, Any, Dict, Iterable, List, Optional, Tuple, Union, cast

import numpy as np

try:
from pydantic.v1 import ConstrainedFloat, ConstrainedInt, Field, constr, validator
from pydantic.v1 import Field, NonNegativeInt, constr, validator
except ImportError: # Will also trap ModuleNotFoundError
from pydantic import ConstrainedFloat, ConstrainedInt, Field, constr, validator
from pydantic import Field, NonNegativeInt, constr, validator

try:
import nglview
Expand Down Expand Up @@ -77,13 +78,7 @@ def float_prep(array, around):
return array


class NonnegativeInt(ConstrainedInt):
ge = 0


class BondOrderFloat(ConstrainedFloat):
ge = 0
le = 5
BondOrderFloat = Annotated[float, Ge(0), Le(5)]


class Identifiers(ProtoModel):
Expand Down Expand Up @@ -232,7 +227,7 @@ class Molecule(ProtoModel):
)

# Fragment and connection data
connectivity_: Optional[List[Tuple[NonnegativeInt, NonnegativeInt, BondOrderFloat]]] = Field( # type: ignore
connectivity_: Optional[List[Tuple[NonNegativeInt, NonNegativeInt, BondOrderFloat]]] = Field( # type: ignore
None,
description="A list of bonds within the molecule. Each entry is a tuple "
"of ``(atom_index_A, atom_index_B, bond_order)`` where the ``atom_index`` "
Expand Down
Loading