Skip to content

Commit

Permalink
Csse pyd2 502 (#345)
Browse files Browse the repository at this point in the history
* move models to models/v1

* fix up imports. tests clean

* check pre-commit on full repo

* dummy
  • Loading branch information
loriab authored Sep 4, 2024
1 parent 2966142 commit dcfcfba
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 56 deletions.
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
# will fail with git < 1.8.5
rev: v4.4.0
hooks:
- id: check-yaml
Expand All @@ -12,6 +13,7 @@ repos:
hooks:
- id: detect-secrets
stages: [commit]
exclude: "raw_data/nist_data/"
# TODO: Update to 5.12.x once we drop Python3.7 support
# https://levelup.gitconnected.com/fix-runtimeerror-poetry-isort-5db7c67b60ff
- repo: https://github.com/PyCQA/isort
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Changelog
.. +++++
0.28.0 / 2024-06-21
-------------------

Expand Down
2 changes: 1 addition & 1 deletion docs/model_molecule.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ database.
>>> mol = qcel.models.Molecule(**{"symbols": ["He", "He"], "geometry": [0, 0, -3, 0, 0, 3]})
>>> mol.get_hash()
'84872f975d19aafa62b188b40fbadaf26a3b1f84'
'84872f975d19aafa62b188b40fbadaf26a3b1f84' # pragma: allowlist secret
Molecular Formula
+++++++++++++++++
Expand Down
33 changes: 1 addition & 32 deletions qcelemental/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,32 +1 @@
try:
import pydantic
except ImportError: # pragma: no cover
raise ImportError(
"Python module pydantic not found. Solve by installing it: "
"`conda install pydantic -c conda-forge` or `pip install pydantic`"
)

from . import types
from .align import AlignmentMill
from .basemodels import AutodocBaseSettings # remove when QCFractal merges `next`
from .basemodels import ProtoModel
from .basis import BasisSet
from .common_models import ComputeError, DriverEnum, FailedOperation, Provenance
from .molecule import Molecule
from .procedures import Optimization # scheduled for removal
from .procedures import OptimizationInput, OptimizationResult
from .results import Result # scheduled for removal
from .results import ResultInput # scheduled for removal
from .results import ResultProperties # scheduled for removal
from .results import AtomicInput, AtomicResult, AtomicResultProperties


def qcschema_models():
return [
AtomicInput,
AtomicResult,
AtomicResultProperties,
BasisSet,
Molecule,
Provenance,
]
from .v1 import *
32 changes: 32 additions & 0 deletions qcelemental/models/v1/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
try:
import pydantic
except ImportError: # pragma: no cover
raise ImportError(
"Python module pydantic not found. Solve by installing it: "
"`conda install pydantic -c conda-forge` or `pip install pydantic`"
)

from . import types
from .align import AlignmentMill
from .basemodels import AutodocBaseSettings # remove when QCFractal merges `next`
from .basemodels import ProtoModel
from .basis import BasisSet
from .common_models import ComputeError, DriverEnum, FailedOperation, Provenance
from .molecule import Molecule
from .procedures import Optimization # scheduled for removal
from .procedures import OptimizationInput, OptimizationResult
from .results import Result # scheduled for removal
from .results import ResultInput # scheduled for removal
from .results import ResultProperties # scheduled for removal
from .results import AtomicInput, AtomicResult, AtomicResultProperties


def qcschema_models():
return [
AtomicInput,
AtomicResult,
AtomicResultProperties,
BasisSet,
Molecule,
Provenance,
]
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
except ImportError: # Will also trap ModuleNotFoundError
from pydantic import Field, validator

from ..util import blockwise_contract, blockwise_expand
from ...util import blockwise_contract, blockwise_expand
from .basemodels import ProtoModel
from .types import Array

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
except ImportError: # Will also trap ModuleNotFoundError
from pydantic import ConstrainedInt, Field, constr, validator

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


Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
from pydantic import ConstrainedFloat, ConstrainedInt, Field, constr, validator

# molparse imports separated b/c https://github.com/python/mypy/issues/7203
from ..molparse.from_arrays import from_arrays
from ..molparse.from_schema import from_schema
from ..molparse.from_string import from_string
from ..molparse.to_schema import to_schema
from ..molparse.to_string import to_string
from ..periodic_table import periodictable
from ..physical_constants import constants
from ..testing import compare, compare_values
from ..util import deserialize, measure_coordinates, msgpackext_loads, provenance_stamp, which_import
from ...molparse.from_arrays import from_arrays
from ...molparse.from_schema import from_schema
from ...molparse.from_string import from_string
from ...molparse.to_schema import to_schema
from ...molparse.to_string import to_string
from ...periodic_table import periodictable
from ...physical_constants import constants
from ...testing import compare, compare_values
from ...util import deserialize, measure_coordinates, msgpackext_loads, provenance_stamp, which_import
from .basemodels import ProtoModel, qcschema_draft
from .common_models import Provenance, qcschema_molecule_default
from .types import Array
Expand Down Expand Up @@ -831,7 +831,7 @@ def get_molecular_formula(self, order: str = "alphabetical") -> str:
"""

from ..molutil import molecular_formula_from_symbols
from ...molutil import molecular_formula_from_symbols

return molecular_formula_from_symbols(symbols=self.symbols, order=order)

Expand Down Expand Up @@ -1209,7 +1209,7 @@ def align(
from `concern_mol` and the optimally aligned geometry.
"""
from ..molutil.align import B787
from ...molutil.align import B787

rgeom = np.array(ref_mol.geometry)
runiq = np.asarray(
Expand Down Expand Up @@ -1358,7 +1358,7 @@ def scramble(
transformations.
"""
from ..molutil.align import compute_scramble
from ...molutil.align import compute_scramble

ref_mol = self
rgeom = ref_mol.geometry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
except ImportError: # Will also trap ModuleNotFoundError
from pydantic import Field, conlist, constr, validator

from ..util import provenance_stamp
from ...util import provenance_stamp
from .basemodels import ProtoModel
from .common_models import (
ComputeError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
except ImportError: # Will also trap ModuleNotFoundError
from pydantic import Field, constr, validator

from ..util import provenance_stamp
from ...util import provenance_stamp
from .basemodels import ProtoModel, qcschema_draft
from .basis import BasisSet
from .common_models import ComputeError, DriverEnum, Model, Provenance, qcschema_input_default, qcschema_output_default
Expand Down
File renamed without changes.
14 changes: 10 additions & 4 deletions qcelemental/molutil/align.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import collections
import itertools
import time
from typing import List, Optional, Union
from typing import TYPE_CHECKING, List, Optional, Union

import numpy as np

from ..exceptions import ValidationError
from ..models import AlignmentMill
from ..physical_constants import constants
from ..testing import compare_values
from ..util import distance_matrix, linear_sum_assignment, random_rotation_matrix, uno, which_import

if TYPE_CHECKING:
from qcelemental.models import AlignmentMill # TODO: recheck if .v1 needed


def _nre(Z, geom):
"""Nuclear repulsion energy"""
Expand Down Expand Up @@ -100,11 +102,13 @@ def B787(
float, AlignmentMill
First item is RMSD [A] between `rgeom` and the optimally aligned
geometry computed.
Second item is a AlignmentMill with fields
Second item is an AlignmentMill with fields
(shift, rotation, atommap, mirror) that prescribe the transformation
from `cgeom` and the optimally aligned geometry.
"""
from qcelemental.models import AlignmentMill

# validation
if rgeom.shape != cgeom.shape or rgeom.shape[1] != 3:
raise ValidationError("""natom doesn't match: {} != {}""".format(rgeom.shape, cgeom.shape))
Expand Down Expand Up @@ -564,7 +568,7 @@ def compute_scramble(
do_rotate: Union[bool, List, np.ndarray] = True,
deflection: float = 1.0,
do_mirror: bool = False,
) -> AlignmentMill:
) -> "AlignmentMill":
r"""Generate a random or directed translation, rotation, and atom shuffling.
Parameters
Expand Down Expand Up @@ -595,6 +599,8 @@ def compute_scramble(
as requested: identity, random, or specified.
"""
from qcelemental.models import AlignmentMill

rand_elord = np.arange(nat)
if do_resort is True:
np.random.shuffle(rand_elord)
Expand Down
5 changes: 3 additions & 2 deletions qcelemental/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import pprint
import sys
from typing import Callable, Dict, List, Tuple, Union
from typing import TYPE_CHECKING, Callable, Dict, List, Tuple, Union

import numpy as np

Expand All @@ -11,7 +11,8 @@
except ImportError: # Will also trap ModuleNotFoundError
from pydantic import BaseModel

from qcelemental.models.basemodels import ProtoModel
if TYPE_CHECKING:
from qcelemental.models import ProtoModel # TODO: recheck if .v1 needed

pp = pprint.PrettyPrinter(width=120)

Expand Down
2 changes: 1 addition & 1 deletion qcelemental/tests/test_model_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pytest

import qcelemental as qcel
from qcelemental.models import basis
from qcelemental.models.v1 import basis # TODO: generalize at parameterize v1/v2 stage

from .addons import drop_qcsk

Expand Down

0 comments on commit dcfcfba

Please sign in to comment.