Skip to content

Commit 92719fc

Browse files
authored
Unifying Position/PositionModel (#173)
* got rid of core_types file and moved Orientation/Reflection into response models file. Changed these so they rely on the existing PositionModel class, instead of creating a new Position object * added space to make it pass the black test...
1 parent d18f008 commit 92719fc

File tree

4 files changed

+47
-59
lines changed

4 files changed

+47
-59
lines changed

src/diffcalc_api/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""API to expose diffcalc-core methods."""
22

3-
from . import config, core_types, database, openapi, server
3+
from . import config, database, openapi, server
44
from ._version_git import __version__
55

6-
__all__ = ["__version__", "server", "config", "database", "core_types", "openapi"]
6+
__all__ = ["__version__", "server", "config", "database", "openapi"]

src/diffcalc_api/core_types.py

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/diffcalc_api/models/response.py

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
"""Pydantic models relating to all endpoint responses."""
2-
from typing import Dict, List
2+
from dataclasses import dataclass
3+
from typing import Dict, List, Optional
34

45
from pydantic import BaseModel
56

6-
from diffcalc_api.core_types import Orientation, Reflection
7-
from diffcalc_api.models.ub import HklModel, MiscutModel, SphericalCoordinates, XyzModel
7+
from diffcalc_api.models.ub import (
8+
HklModel,
9+
MiscutModel,
10+
PositionModel,
11+
SphericalCoordinates,
12+
XyzModel,
13+
)
814

915

1016
class InfoResponse(BaseModel):
@@ -83,6 +89,38 @@ class MiscutResponse(BaseModel):
8389
payload: MiscutModel
8490

8591

92+
@dataclass
93+
class Orientation:
94+
"""Reference orientation of the sample.
95+
96+
Similar to diffcalc.ub.reference.Orientation
97+
"""
98+
99+
h: float
100+
k: float
101+
l: float
102+
x: float
103+
y: float
104+
z: float
105+
pos: PositionModel
106+
tag: Optional[str]
107+
108+
109+
@dataclass
110+
class Reflection:
111+
"""Reference reflection of the sample.
112+
113+
Similar to diffcalc.ub.reference.Reflection
114+
"""
115+
116+
h: float
117+
k: float
118+
l: float
119+
pos: PositionModel
120+
energy: float
121+
tag: Optional[str]
122+
123+
86124
class ReflectionResponse(BaseModel):
87125
"""Response for any operation returning a reflection."""
88126

src/diffcalc_api/routes/ub.py

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

55
from fastapi import APIRouter, Body, Depends, Query
66

7-
from diffcalc_api.core_types import Orientation, Position, Reflection
87
from diffcalc_api.errors.ub import (
98
BothTagAndIdxProvidedError,
109
InvalidSetLatticeParamsError,
@@ -15,8 +14,10 @@
1514
ArrayResponse,
1615
InfoResponse,
1716
MiscutResponse,
17+
Orientation,
1818
OrientationResponse,
1919
ReciprocalSpaceResponse,
20+
Reflection,
2021
ReflectionResponse,
2122
SphericalResponse,
2223
StringResponse,
@@ -100,7 +101,7 @@ async def get_reflection(
100101
ref.h,
101102
ref.k,
102103
ref.l,
103-
Position(**ref.pos.asdict),
104+
PositionModel(**ref.pos.asdict),
104105
ref.energy,
105106
ref.tag,
106107
)
@@ -246,7 +247,7 @@ async def get_orientation(
246247
orient.x,
247248
orient.y,
248249
orient.z,
249-
Position(**orient.pos.asdict),
250+
PositionModel(**orient.pos.asdict),
250251
orient.tag if orient.tag is not None else "",
251252
)
252253
return OrientationResponse(payload=orientation)

0 commit comments

Comments
 (0)