Skip to content

Commit 95ea8be

Browse files
committed
Merge branch '1424-ngl-viewer-update' into 'develop'
Resolve "NGL viewer update" Closes #1424 See merge request nomad-lab/nomad-FAIR!1461
2 parents 68dc879 + 2826c7b commit 95ea8be

File tree

2 files changed

+238
-122
lines changed

2 files changed

+238
-122
lines changed

gui/src/components/visualization/StructureBase.js

+87-62
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@ import {
2525
Button,
2626
Menu,
2727
MenuItem,
28+
Tooltip,
2829
Typography,
29-
FormControlLabel
30+
FormControl,
31+
FormLabel,
32+
FormControlLabel,
33+
Radio,
34+
RadioGroup
3035
} from '@material-ui/core'
3136
import { Alert } from '@material-ui/lab'
3237
import {
@@ -47,6 +52,11 @@ import { withErrorHandler, withWebGLErrorHandler } from '../ErrorHandler'
4752
import { isNil } from 'lodash'
4853
import { Quantity } from '../../units'
4954

55+
export const WrapMode = {
56+
Original: "original",
57+
Wrap: "wrap",
58+
Unwrap: "unwrap"
59+
}
5060
/**
5161
* Used to control a 3D system visualization that is implemented in the
5262
* 'children' prop. This allows for an easier change of visualization
@@ -84,6 +94,11 @@ const useStyles = makeStyles((theme) => {
8494
title: {
8595
marginBottom: theme.spacing(1)
8696
},
97+
menuItem: {
98+
margin: theme.spacing(2),
99+
marginTop: theme.spacing(1),
100+
marginBottom: theme.spacing(1)
101+
},
87102
canvas: {
88103
position: 'relative',
89104
flex: 1,
@@ -94,9 +109,9 @@ const useStyles = makeStyles((theme) => {
94109
}
95110
})
96111
const StructureBase = React.memo(({
97-
wrap,
98-
onWrap,
99-
disableWrap,
112+
wrapMode,
113+
onWrapModeChange,
114+
disableWrapMode,
100115
showLatticeConstants,
101116
onShowLatticeConstants,
102117
disableShowLatticeConstants,
@@ -137,9 +152,9 @@ const StructureBase = React.memo(({
137152
onShowBonds && onShowBonds(value, render)
138153
}, [onShowBonds])
139154

140-
const handleWrap = useCallback((value, showBonds, render = false) => {
141-
onWrap && onWrap(value, showBonds, render)
142-
}, [onWrap])
155+
const handleWrapModeChange = useCallback((value, showBonds, render = false) => {
156+
onWrapModeChange && onWrapModeChange(value, showBonds, render)
157+
}, [onWrapModeChange])
143158

144159
const handleShowLatticeConstants = useCallback((value, render = false) => {
145160
onShowLatticeConstants && onShowLatticeConstants(value, render)
@@ -261,58 +276,68 @@ const StructureBase = React.memo(({
261276
open={open}
262277
onClose={closeMenu}
263278
>
264-
<MenuItem key='show-bonds'>
265-
<FormControlLabel
266-
control={
267-
<Checkbox
268-
checked={showBonds}
269-
disabled={disableShowBonds}
270-
onChange={(event) => { setShowBonds(!showBonds, true) }}
271-
color='primary'
272-
/>
273-
}
274-
label='Show bonds'
275-
/>
276-
</MenuItem>
277-
<MenuItem key='show-axis'>
278-
<FormControlLabel
279-
control={
280-
<Checkbox
281-
checked={showLatticeConstants}
282-
disabled={disableShowLatticeConstants}
283-
onChange={(event) => { handleShowLatticeConstants(!showLatticeConstants, true) }}
284-
color='primary'
285-
/>
286-
}
287-
label='Show lattice constants'
288-
/>
289-
</MenuItem>
290-
<MenuItem key='show-cell'>
291-
<FormControlLabel
292-
control={
293-
<Checkbox
294-
checked={showCell}
295-
disabled={disableShowCell}
296-
onChange={(event) => { setShowCell(!showCell, true) }}
297-
color='primary'
298-
/>
299-
}
300-
label='Show simulation cell'
301-
/>
302-
</MenuItem>
303-
<MenuItem key='wrap'>
304-
<FormControlLabel
305-
control={
306-
<Checkbox
307-
checked={wrap}
308-
disabled={disableWrap}
309-
onChange={(event) => { handleWrap(!wrap, showBonds, true) }}
310-
color='primary'
311-
/>
312-
}
313-
label='Wrap positions'
314-
/>
315-
</MenuItem>
279+
<MenuItem key='show-bonds'>
280+
<FormControlLabel
281+
control={
282+
<Checkbox
283+
checked={showBonds}
284+
disabled={disableShowBonds}
285+
onChange={(event) => { setShowBonds(!showBonds, true) }}
286+
color='primary'
287+
/>
288+
}
289+
label='Show bonds'
290+
/>
291+
</MenuItem>
292+
<MenuItem key='show-axis'>
293+
<FormControlLabel
294+
control={
295+
<Checkbox
296+
checked={showLatticeConstants}
297+
disabled={disableShowLatticeConstants}
298+
onChange={(event) => { handleShowLatticeConstants(!showLatticeConstants, true) }}
299+
color='primary'
300+
/>
301+
}
302+
label='Show lattice constants'
303+
/>
304+
</MenuItem>
305+
<MenuItem key='show-cell'>
306+
<FormControlLabel
307+
control={
308+
<Checkbox
309+
checked={showCell}
310+
disabled={disableShowCell}
311+
onChange={(event) => { setShowCell(!showCell, true) }}
312+
color='primary'
313+
/>
314+
}
315+
label='Show simulation cell'
316+
/>
317+
</MenuItem>
318+
<FormControl key='wrap' component="fieldset" className={styles.menuItem}>
319+
<FormLabel component="legend">Wrap mode</FormLabel>
320+
<RadioGroup
321+
value={wrapMode}
322+
onChange={handleWrapModeChange}
323+
>
324+
{Object.entries(WrapMode).map(([key, value]) =>
325+
<FormControlLabel
326+
key={key}
327+
value={value}
328+
control={<Radio color="primary" disabled={disableWrapMode}/>}
329+
label={<Tooltip
330+
title={{
331+
[WrapMode.Original]: 'Original positions',
332+
[WrapMode.Wrap]: 'Positions wrapped inside the cell respecting periodic boundary conditions',
333+
[WrapMode.Unwrap]: 'Reconstructs positions so that small structures are not split by periodic cell boundary.'
334+
}[value]}>
335+
<span>{key}</span>
336+
</Tooltip>}
337+
/>
338+
)}
339+
</RadioGroup>
340+
</FormControl>
316341
</Menu>
317342
</div>
318343
</div>
@@ -321,9 +346,9 @@ const StructureBase = React.memo(({
321346
})
322347

323348
StructureBase.propTypes = {
324-
wrap: PropTypes.bool,
325-
onWrap: PropTypes.func,
326-
disableWrap: PropTypes.bool,
349+
wrapMode: PropTypes.bool,
350+
onWrapModeChange: PropTypes.func,
351+
disableWrapMode: PropTypes.bool,
327352
showLatticeConstants: PropTypes.bool,
328353
onShowLatticeConstants: PropTypes.func,
329354
disableShowLatticeConstants: PropTypes.bool,

0 commit comments

Comments
 (0)