File size: 7,751 Bytes
6d08d46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
import React from 'react'
import { Grid, Card, Text, Title, Group, Box, Button, Stack, Progress } from '@mantine/core'
import { IconSearch, IconCube, IconGridPattern } from '@tabler/icons-react'
import { useXRD } from '../context/XRDContext'

const ResultsHero = () => {
  const { modelResults, setIsLogitDrawerOpen } = useXRD()
  
  // Animation styles
  const cardAnimation = {
    animation: 'slideIn 0.5s ease-out forwards',
    opacity: 0,
  }
  
  const keyframes = `
    @keyframes slideIn {
      from {
        opacity: 0;
        transform: translateY(20px);
      }
      to {
        opacity: 1;
        transform: translateY(0);
      }
    }
  `
  
  if (!modelResults || !modelResults.predictions?.phase_predictions) {
    return null
  }
  
  const predictions = modelResults.predictions.phase_predictions
  
  // Extract predictions by type
  const crystalSystem = predictions.find(p => p.phase === 'Crystal System')
  const spaceGroup = predictions.find(p => p.phase === 'Space Group')
  const latticeParams = predictions.find(p => p.is_lattice)
  
  const getConfidenceColor = (confidence) => {
    if (confidence >= 0.8) return 'green'
    if (confidence >= 0.5) return 'yellow'
    return 'orange'
  }
  
  return (
    <>
      <style>{keyframes}</style>
      <Grid gutter="md" mb="lg">
        {/* Card 1: Crystal System */}
        <Grid.Col span={{ base: 12, sm: 6, md: 3 }}>
          <Card 
            shadow="sm" 
            padding="lg" 
            radius="md" 
            withBorder 
            h="100%"
            style={{
              ...cardAnimation,
              animationDelay: '0.1s',
              borderLeft: '4px solid #9775fa',
              background: 'linear-gradient(135deg, #ffffff 0%, #f8f4ff 100%)'
            }}
          >
            <Stack gap="xs" align="center">
              <IconCube size={32} color="#9775fa" />
            <Text size="xs" c="dimmed" tt="uppercase" fw={600}>
              Crystal System
            </Text>
            <Title order={3} ta="center" style={{ fontWeight: 700 }}>
              {crystalSystem?.predicted_class || 'N/A'}
            </Title>
          </Stack>
        </Card>
      </Grid.Col>
      
        {/* Card 2: Space Group */}
        <Grid.Col span={{ base: 12, sm: 6, md: 3 }}>
          <Card 
            shadow="sm" 
            padding="lg" 
            radius="md" 
            withBorder 
            h="100%"
            style={{
              ...cardAnimation,
              animationDelay: '0.2s',
              borderLeft: '4px solid #1e88e5',
              background: 'linear-gradient(135deg, #ffffff 0%, #f0f7ff 100%)'
            }}
          >
            <Stack gap="xs" align="center">
              <IconGridPattern size={32} color="#1e88e5" />
            <Text size="xs" c="dimmed" tt="uppercase" fw={600}>
              Space Group
            </Text>
            <Title order={3} ta="center" style={{ fontWeight: 700 }}>
              {spaceGroup?.predicted_class || 'N/A'}
            </Title>
            {spaceGroup?.space_group_symbol && (
              <Text size="sm" c="dimmed" style={{ fontFamily: 'monospace' }}>
                {spaceGroup.space_group_symbol}
              </Text>
            )}
          </Stack>
        </Card>
      </Grid.Col>
      
        {/* Card 3: Lattice Parameters */}
        <Grid.Col span={{ base: 12, sm: 6, md: 3 }}>
          <Card 
            shadow="sm" 
            padding="lg" 
            radius="md" 
            withBorder 
            h="100%"
            style={{
              ...cardAnimation,
              animationDelay: '0.3s',
              borderLeft: '4px solid #00acc1',
              background: 'linear-gradient(135deg, #ffffff 0%, #f0fdff 100%)'
            }}
          >
            <Stack gap="xs">
            <Text size="xs" c="dimmed" tt="uppercase" fw={600} ta="center">
              Lattice Parameters
            </Text>
            {latticeParams?.lattice_params ? (
              <Box style={{ fontFamily: 'monospace', fontSize: '1.1rem' }}>
                <Group gap="lg" justify="center">
                  <Stack gap={4}>
                    <Text size="md">a = {latticeParams.lattice_params.a?.toFixed(3)} Å</Text>
                    <Text size="md">b = {latticeParams.lattice_params.b?.toFixed(3)} Å</Text>
                    <Text size="md">c = {latticeParams.lattice_params.c?.toFixed(3)} Å</Text>
                  </Stack>
                  <Stack gap={4}>
                    <Text size="md">α = {latticeParams.lattice_params['α']?.toFixed(2)}°</Text>
                    <Text size="md">β = {latticeParams.lattice_params['β']?.toFixed(2)}°</Text>
                    <Text size="md">γ = {latticeParams.lattice_params['γ']?.toFixed(2)}°</Text>
                  </Stack>
                </Group>
              </Box>
            ) : (
              <Text size="sm" c="dimmed" ta="center">N/A</Text>
            )}
          </Stack>
        </Card>
      </Grid.Col>
      
        {/* Card 4: Confidence & Inspection */}
        <Grid.Col span={{ base: 12, sm: 6, md: 3 }}>
          <Card 
            shadow="sm" 
            padding="lg" 
            radius="md" 
            withBorder 
            h="100%"
            style={{
              ...cardAnimation,
              animationDelay: '0.4s',
              borderLeft: '4px solid #fb8c00',
              background: 'linear-gradient(135deg, #ffffff 0%, #fff8f0 100%)'
            }}
          >
            <Stack gap="sm" align="center" justify="center" h="100%">
            <Text size="xs" c="dimmed" tt="uppercase" fw={600} ta="center">
              Confidence
            </Text>
            
            {/* CS and SG Confidences - Compact */}
            <Stack gap="xs" w="100%">
              {/* Crystal System Confidence */}
              {crystalSystem?.confidence && (
                <Box>
                  <Group justify="space-between" mb={4}>
                    <Text size="xs" fw={600}>CS</Text>
                    <Text size="sm" fw={700} c={getConfidenceColor(crystalSystem.confidence)}>
                      {(crystalSystem.confidence * 100).toFixed(0)}%
                    </Text>
                  </Group>
                  <Progress
                    value={crystalSystem.confidence * 100}
                    color={getConfidenceColor(crystalSystem.confidence)}
                    size="md"
                    radius="xl"
                  />
                </Box>
              )}
              
              {/* Space Group Confidence */}
              {spaceGroup?.confidence && (
                <Box>
                  <Group justify="space-between" mb={4}>
                    <Text size="xs" fw={600}>SG</Text>
                    <Text size="sm" fw={700} c={getConfidenceColor(spaceGroup.confidence)}>
                      {(spaceGroup.confidence * 100).toFixed(0)}%
                    </Text>
                  </Group>
                  <Progress
                    value={spaceGroup.confidence * 100}
                    color={getConfidenceColor(spaceGroup.confidence)}
                    size="md"
                    radius="xl"
                  />
                </Box>
              )}
            </Stack>
            
            <Button
              variant="subtle"
              leftSection={<IconSearch size={16} />}
              size="sm"
              onClick={() => setIsLogitDrawerOpen(true)}
              mt="xs"
              style={{
                border: '1px solid #1e88e5'
              }}
            >
              Inspect Logits
            </Button>
          </Stack>
          </Card>
        </Grid.Col>
      </Grid>
    </>
  )
}

export default ResultsHero