|
12 | 12 | from datetime import datetime |
13 | 13 | from pathlib import Path |
14 | 14 | from typing import Iterator, Optional |
| 15 | +import pydantic |
15 | 16 |
|
16 | 17 | import gemmi |
17 | 18 | import numpy as np |
@@ -43,7 +44,21 @@ class PiaRequest(BaseModel): |
43 | 44 | detector_distance: float |
44 | 45 | d_min: float | None = None |
45 | 46 | d_max: float | None = None |
46 | | - cell: tuple[float, float, float, float, float, float] | None = None |
| 47 | + unit_cell: tuple[float, float, float, float, float, float] | None = None |
| 48 | + |
| 49 | + @pydantic.validator("unit_cell", pre=True) |
| 50 | + def check_unit_cell(cls, v): |
| 51 | + if not v: |
| 52 | + return None |
| 53 | + orig_v = v |
| 54 | + if isinstance(v, str): |
| 55 | + v = v.replace(",", " ").split() |
| 56 | + v = [float(v) for v in v] |
| 57 | + try: |
| 58 | + assert len(v) == 6 |
| 59 | + except Exception: |
| 60 | + raise ValueError(f"Invalid unit_cell {orig_v}") |
| 61 | + return v |
47 | 62 |
|
48 | 63 |
|
49 | 64 | class DetectorGeometry(BaseModel): |
@@ -223,9 +238,9 @@ def gpu_per_image_analysis( |
223 | 238 | f"Rejecting PIA request for {parameters.dcgid}/{parameters.message_index}({parameters.dcid}): Invalid detector parameters \n{e}" |
224 | 239 | ) |
225 | 240 |
|
226 | | - if self.indexer and parameters.cell and parameters.wavelength: |
| 241 | + if self.indexer and parameters.unit_cell and parameters.wavelength: |
227 | 242 | ## We have all we need to index, so make up to date models. |
228 | | - cell = gemmi.UnitCell(*parameters.cell) |
| 243 | + cell = gemmi.UnitCell(*parameters.unit_cell) |
229 | 244 | self.indexer.cell = np.reshape( |
230 | 245 | np.array(cell.orth.mat, dtype="float32"), (3, 3) |
231 | 246 | ) ## Cell as an orthogonalisation matrix |
|
0 commit comments