Skip to content

Commit 9d40a32

Browse files
committed
polish: Add chart labels and use library for SG naming conventions
1 parent 3a51164 commit 9d40a32

2 files changed

Lines changed: 47 additions & 19 deletions

File tree

src/ui/app/model_inference.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from typing import Dict, List, Tuple, Optional
77
import torch
88
import numpy as np
9+
import spglib
910

1011

1112
class XRDModelInference:
@@ -32,7 +33,7 @@ def load_model(self):
3233
from .model import AlphaDiffractMultiscaleLightning
3334

3435
# Load checkpoint
35-
checkpoint = torch.load(self.model_path, map_location=self.device)
36+
checkpoint = torch.load(self.model_path, map_location=self.device, weights_only=False)
3637

3738
# Initialize model (you may need to adjust hyperparameters based on your checkpoint)
3839
# For now, using placeholder values - these should match your trained model
@@ -243,20 +244,19 @@ def _process_model_output(self, output) -> Dict:
243244
}
244245

245246
def _get_space_group_symbol(self, sg_number: int) -> str:
246-
"""Get space group symbol from number (simplified mapping)"""
247-
# Common space group symbols - this is a simplified mapping
248-
# In production, you'd want a complete lookup table
249-
symbols = {
250-
1: "P1", 2: "P-1", 3: "P2", 4: "P21", 5: "C2",
251-
10: "P2/m", 15: "C2/c", 16: "P222", 19: "P212121",
252-
38: "Amm2", 47: "Pmmm", 62: "Pnma", 63: "Cmcm",
253-
71: "Immm", 74: "Imma", 82: "I-4", 87: "I4/m",
254-
123: "P4/mmm", 129: "P4/nmm", 139: "I4/mmm", 148: "R-3",
255-
160: "R3m", 162: "P-31m", 164: "P-3m1", 166: "R-3m",
256-
167: "R-3c", 186: "P63mc", 194: "P63/mmc", 221: "Pm-3m",
257-
225: "Fm-3m", 227: "Fd-3m", 229: "Im-3m", 230: "Ia-3d"
258-
}
259-
return symbols.get(sg_number, f"SG{sg_number}")
247+
"""Get space group symbol from number using spglib"""
248+
if sg_number < 1 or sg_number > 230:
249+
return f"SG{sg_number}"
250+
251+
try:
252+
# Get space group type information from spglib
253+
sg_type = spglib.get_spacegroup_type(sg_number)
254+
if sg_type is not None:
255+
# Use the international short symbol (Hermann-Mauguin notation)
256+
return sg_type['international_short']
257+
return f"SG{sg_number}"
258+
except Exception:
259+
return f"SG{sg_number}"
260260

261261
def _dummy_predictions(self) -> Dict:
262262
"""Return dummy predictions when model is not available"""

src/ui/frontend/src/components/XRDGraph.jsx

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,14 @@ const XRDGraph = () => {
4747
// Layout for raw data graph
4848
const rawLayout = {
4949
xaxis: {
50-
title: '2θ (degrees)',
50+
title: {
51+
text: '2θ (degrees)',
52+
font: {
53+
size: 14,
54+
color: '#333',
55+
},
56+
standoff: 10,
57+
},
5158
gridcolor: 'rgba(128, 128, 128, 0.2)',
5259
showline: true,
5360
linewidth: 1,
@@ -56,7 +63,14 @@ const XRDGraph = () => {
5663
range: [Math.min(...rawData.x) - 0.5, Math.max(...rawData.x) + 0.5],
5764
},
5865
yaxis: {
59-
title: 'Intensity (a.u.)',
66+
title: {
67+
text: 'Intensity (a.u.)',
68+
font: {
69+
size: 14,
70+
color: '#333',
71+
},
72+
standoff: 10,
73+
},
6074
gridcolor: 'rgba(128, 128, 128, 0.2)',
6175
showline: true,
6276
linewidth: 1,
@@ -79,7 +93,14 @@ const XRDGraph = () => {
7993
// Layout for processed data graph
8094
const processedLayout = {
8195
xaxis: {
82-
title: '2θ (degrees)',
96+
title: {
97+
text: '2θ (degrees)',
98+
font: {
99+
size: 14,
100+
color: '#333',
101+
},
102+
standoff: 10,
103+
},
83104
gridcolor: 'rgba(128, 128, 128, 0.2)',
84105
range: [MODEL_MIN_2THETA - 0.5, MODEL_MAX_2THETA + 0.5],
85106
showline: true,
@@ -88,7 +109,14 @@ const XRDGraph = () => {
88109
mirror: true,
89110
},
90111
yaxis: {
91-
title: 'Standardized Intensity (0-100)',
112+
title: {
113+
text: 'Normalized Intensity',
114+
font: {
115+
size: 14,
116+
color: '#333',
117+
},
118+
standoff: 10,
119+
},
92120
gridcolor: 'rgba(128, 128, 128, 0.2)',
93121
range: [-5, 105],
94122
showline: true,

0 commit comments

Comments
 (0)