mc-react-phonon-visualizer 0.1.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/dist/PhononVisualizer.css +1 -0
- package/dist/main.js +175269 -0
- package/package.json +16 -10
- package/.eslintrc.cjs +0 -18
- package/.github/workflows/release-and-publish.yml +0 -41
- package/.prettierignore +0 -4
- package/.prettierrc.json +0 -3
- package/data/test.json +0 -1
- package/declarations.d.ts +0 -55
- package/index.html +0 -13
- package/src/App.scss +0 -3
- package/src/App.tsx +0 -14
- package/src/components/BandsView.tsx +0 -160
- package/src/components/CellView.scss +0 -24
- package/src/components/CellView.tsx +0 -140
- package/src/components/ControlsPanel.scss +0 -19
- package/src/components/ControlsPanel.tsx +0 -234
- package/src/components/ParametersContext.ts +0 -7
- package/src/components/PhononVisualizer.scss +0 -15
- package/src/components/PhononVisualizer.tsx +0 -53
- package/src/components/types.ts +0 -21
- package/src/components/useParameters.ts +0 -37
- package/src/main.scss +0 -2
- package/src/main.tsx +0 -7
- package/src/vite-env.d.ts +0 -1
- package/tsconfig.app.json +0 -30
- package/tsconfig.json +0 -11
- package/tsconfig.node.json +0 -13
- package/vite.config.ts +0 -7
- /package/{public → dist}/favicon.png +0 -0
- /package/{public → dist}/react.svg +0 -0
- /package/{public → dist}/vite.svg +0 -0
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
import { memo, useContext } from "react";
|
|
2
|
-
import { Button, Card, Col, Form, Row } from "react-bootstrap";
|
|
3
|
-
|
|
4
|
-
import ParametersContext from "./ParametersContext";
|
|
5
|
-
|
|
6
|
-
import "./ControlsPanel.scss";
|
|
7
|
-
|
|
8
|
-
const ControlsPanel = () => {
|
|
9
|
-
const {
|
|
10
|
-
nx,
|
|
11
|
-
setNx,
|
|
12
|
-
ny,
|
|
13
|
-
setNy,
|
|
14
|
-
nz,
|
|
15
|
-
setNz,
|
|
16
|
-
setCameraDirection,
|
|
17
|
-
showCell,
|
|
18
|
-
setShowCell,
|
|
19
|
-
amplitude,
|
|
20
|
-
setAmplitude,
|
|
21
|
-
vectorLength,
|
|
22
|
-
setVectorLength,
|
|
23
|
-
showVectors,
|
|
24
|
-
setShowVectors,
|
|
25
|
-
speed,
|
|
26
|
-
setSpeed,
|
|
27
|
-
} = useContext(ParametersContext);
|
|
28
|
-
|
|
29
|
-
const updateCellRepetitions = (event: React.FormEvent<HTMLFormElement>) => {
|
|
30
|
-
event.preventDefault();
|
|
31
|
-
const x = parseInt((event.target as HTMLFormElement).cellRepetitionX.value);
|
|
32
|
-
const y = parseInt((event.target as HTMLFormElement).cellRepetitionY.value);
|
|
33
|
-
const z = parseInt((event.target as HTMLFormElement).cellRepetitionZ.value);
|
|
34
|
-
setNx(x);
|
|
35
|
-
setNy(y);
|
|
36
|
-
setNz(z);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const updateCamera = (event: React.MouseEvent<HTMLButtonElement>) => {
|
|
40
|
-
const camera = event.currentTarget.value;
|
|
41
|
-
switch (camera) {
|
|
42
|
-
case "x":
|
|
43
|
-
setCameraDirection([1, 0, 0]);
|
|
44
|
-
break;
|
|
45
|
-
case "y":
|
|
46
|
-
setCameraDirection([0, 1, 0]);
|
|
47
|
-
break;
|
|
48
|
-
case "z":
|
|
49
|
-
setCameraDirection([0, 0, 1]);
|
|
50
|
-
break;
|
|
51
|
-
default:
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const toggleCell = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
57
|
-
setShowCell(event.target.checked);
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const handleAmplitudeTextInput = (
|
|
61
|
-
event: React.FormEvent<HTMLFormElement>
|
|
62
|
-
) => {
|
|
63
|
-
event.preventDefault();
|
|
64
|
-
const textInput = event.currentTarget.querySelector("#amplitudeText");
|
|
65
|
-
if (!textInput) {
|
|
66
|
-
throw new Error("Text input not found");
|
|
67
|
-
}
|
|
68
|
-
const inputValue = parseFloat((textInput as HTMLInputElement).value);
|
|
69
|
-
updateAmplitude(inputValue);
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const handleAmplitudeSliderInput = (
|
|
73
|
-
event: React.ChangeEvent<HTMLInputElement>
|
|
74
|
-
) => {
|
|
75
|
-
if (event.target.value === "" || isNaN(parseFloat(event.target.value))) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
const inputValue = parseFloat(event.target.value);
|
|
79
|
-
updateAmplitude(inputValue);
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const updateAmplitude = (inputValue: number) => {
|
|
83
|
-
const value = inputValue < 0 ? 0 : inputValue > 1 ? 1 : inputValue;
|
|
84
|
-
setAmplitude(value);
|
|
85
|
-
const range = document.getElementById("amplitudeRange") as HTMLInputElement;
|
|
86
|
-
const text = document.getElementById("amplitudeText") as HTMLInputElement;
|
|
87
|
-
if (range && text) {
|
|
88
|
-
range.value = String(value);
|
|
89
|
-
text.value = String(value);
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
const updateVectors = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
94
|
-
setVectorLength(parseFloat(event.target.value));
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const toggleVectors = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
98
|
-
setShowVectors(event.target.checked);
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
const updateSpeed = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
102
|
-
setSpeed(parseFloat(event.target.value));
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
return (
|
|
106
|
-
<Card>
|
|
107
|
-
<Card.Header>Settings</Card.Header>
|
|
108
|
-
<Card.Body>
|
|
109
|
-
<Form onSubmit={updateCellRepetitions}>
|
|
110
|
-
<Form.Group as={Row} className="controls-group">
|
|
111
|
-
<Form.Label>Repetitions</Form.Label>
|
|
112
|
-
<Col xs="8" id="cellRepetitions">
|
|
113
|
-
<Form.Control
|
|
114
|
-
id="cellRepetitionX"
|
|
115
|
-
defaultValue={nx}
|
|
116
|
-
type="number"
|
|
117
|
-
min="1"
|
|
118
|
-
/>
|
|
119
|
-
<Form.Control
|
|
120
|
-
id="cellRepetitionY"
|
|
121
|
-
defaultValue={ny}
|
|
122
|
-
type="number"
|
|
123
|
-
min="1"
|
|
124
|
-
/>
|
|
125
|
-
<Form.Control
|
|
126
|
-
id="cellRepetitionZ"
|
|
127
|
-
defaultValue={nz}
|
|
128
|
-
type="number"
|
|
129
|
-
min="1"
|
|
130
|
-
/>
|
|
131
|
-
</Col>
|
|
132
|
-
<Col>
|
|
133
|
-
<Button type="submit">
|
|
134
|
-
<i className="bi bi-repeat" />
|
|
135
|
-
</Button>
|
|
136
|
-
</Col>
|
|
137
|
-
</Form.Group>
|
|
138
|
-
</Form>
|
|
139
|
-
<Form>
|
|
140
|
-
<Form.Group as={Row} id="cameraControls" className="controls-group">
|
|
141
|
-
<Col xs="3">
|
|
142
|
-
<Form.Label>Camera</Form.Label>
|
|
143
|
-
</Col>
|
|
144
|
-
<Col>
|
|
145
|
-
<Button variant="secondary" value="x" onClick={updateCamera}>
|
|
146
|
-
X
|
|
147
|
-
</Button>
|
|
148
|
-
<Button variant="secondary" value="y" onClick={updateCamera}>
|
|
149
|
-
Y
|
|
150
|
-
</Button>
|
|
151
|
-
<Button variant="secondary" value="z" onClick={updateCamera}>
|
|
152
|
-
Z
|
|
153
|
-
</Button>
|
|
154
|
-
</Col>
|
|
155
|
-
</Form.Group>
|
|
156
|
-
<Form.Group as={Row} className="controls-group">
|
|
157
|
-
<Col xs="3">
|
|
158
|
-
<Form.Label>Cell</Form.Label>
|
|
159
|
-
</Col>
|
|
160
|
-
<Col xs="1">
|
|
161
|
-
<Form.Check
|
|
162
|
-
label="On"
|
|
163
|
-
defaultChecked={showCell}
|
|
164
|
-
onChange={toggleCell}
|
|
165
|
-
/>
|
|
166
|
-
</Col>
|
|
167
|
-
</Form.Group>
|
|
168
|
-
</Form>
|
|
169
|
-
<Form id="amplitudeControls" onSubmit={handleAmplitudeTextInput}>
|
|
170
|
-
<Form.Group as={Row} className="controls-group">
|
|
171
|
-
<Form.Label>Amplitude</Form.Label>
|
|
172
|
-
<Col xs="8">
|
|
173
|
-
<Form.Range
|
|
174
|
-
id="amplitudeRange"
|
|
175
|
-
min="0"
|
|
176
|
-
max="1"
|
|
177
|
-
step="0.01"
|
|
178
|
-
defaultValue={amplitude}
|
|
179
|
-
onChange={handleAmplitudeSliderInput}
|
|
180
|
-
/>
|
|
181
|
-
</Col>
|
|
182
|
-
<Col>
|
|
183
|
-
<Form.Control
|
|
184
|
-
id="amplitudeText"
|
|
185
|
-
type="number"
|
|
186
|
-
min="0.01"
|
|
187
|
-
max="1"
|
|
188
|
-
step="0.001"
|
|
189
|
-
defaultValue={amplitude}
|
|
190
|
-
/>
|
|
191
|
-
</Col>
|
|
192
|
-
</Form.Group>
|
|
193
|
-
</Form>
|
|
194
|
-
<Form>
|
|
195
|
-
<Form.Group as={Row} className="controls-group">
|
|
196
|
-
<Form.Label>Vectors</Form.Label>
|
|
197
|
-
<Col xs="8">
|
|
198
|
-
<Form.Range
|
|
199
|
-
min="1"
|
|
200
|
-
max="5"
|
|
201
|
-
step="0.1"
|
|
202
|
-
defaultValue={vectorLength}
|
|
203
|
-
onChange={updateVectors}
|
|
204
|
-
/>
|
|
205
|
-
</Col>
|
|
206
|
-
<Col>
|
|
207
|
-
<Form.Check
|
|
208
|
-
label="On"
|
|
209
|
-
defaultChecked={showVectors}
|
|
210
|
-
onChange={toggleVectors}
|
|
211
|
-
/>
|
|
212
|
-
</Col>
|
|
213
|
-
</Form.Group>
|
|
214
|
-
<Form.Group as={Row} className="controls-group">
|
|
215
|
-
<Form.Label>Speed</Form.Label>
|
|
216
|
-
<Col xs="8">
|
|
217
|
-
<Form.Range
|
|
218
|
-
min="0.1"
|
|
219
|
-
max="1"
|
|
220
|
-
step="0.01"
|
|
221
|
-
defaultValue={speed}
|
|
222
|
-
onChange={updateSpeed}
|
|
223
|
-
/>
|
|
224
|
-
</Col>
|
|
225
|
-
</Form.Group>
|
|
226
|
-
</Form>
|
|
227
|
-
</Card.Body>
|
|
228
|
-
</Card>
|
|
229
|
-
);
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
const MemoizedControlsPanel = memo(ControlsPanel);
|
|
233
|
-
|
|
234
|
-
export default MemoizedControlsPanel;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { useCallback, useState } from "react";
|
|
2
|
-
import { Col, Container, Row } from "react-bootstrap";
|
|
3
|
-
|
|
4
|
-
import { PlotMouseEvent } from "plotly.js";
|
|
5
|
-
|
|
6
|
-
import ParametersContext from "./ParametersContext";
|
|
7
|
-
import { VisualizerProps } from "./types";
|
|
8
|
-
import useParameters from "./useParameters";
|
|
9
|
-
|
|
10
|
-
import MemoizedBandsView from "./BandsView";
|
|
11
|
-
import CellView from "./CellView";
|
|
12
|
-
import MemoizedControlsPanel from "./ControlsPanel";
|
|
13
|
-
|
|
14
|
-
import "./PhononVisualizer.scss";
|
|
15
|
-
|
|
16
|
-
const PhononVisualizer = ({ props }: { props: VisualizerProps }) => {
|
|
17
|
-
const parameters = useParameters(props.repetitions);
|
|
18
|
-
const [mode, setMode] = useState<number[]>([0, 0]);
|
|
19
|
-
|
|
20
|
-
const updateMode = useCallback(
|
|
21
|
-
(event: PlotMouseEvent) => {
|
|
22
|
-
const q = props.distances.indexOf(event.points[0].x as number);
|
|
23
|
-
const e = props.eigenvalues[q].indexOf(event.points[0].y as number);
|
|
24
|
-
setMode([q, e]);
|
|
25
|
-
},
|
|
26
|
-
[props]
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
return (
|
|
30
|
-
<ParametersContext.Provider value={parameters}>
|
|
31
|
-
<Container fluid>
|
|
32
|
-
<Row className="mb-xxl-4">
|
|
33
|
-
<Col xxl="3" className="visualizer-panel">
|
|
34
|
-
<MemoizedControlsPanel />
|
|
35
|
-
</Col>
|
|
36
|
-
<Col xxl="4" className="visualizer-panel">
|
|
37
|
-
<CellView props={props} mode={mode} />
|
|
38
|
-
</Col>
|
|
39
|
-
<Col xxl="5" className="visualizer-panel">
|
|
40
|
-
<MemoizedBandsView
|
|
41
|
-
distances={props.distances}
|
|
42
|
-
highSymPoints={props.highsym_qpts}
|
|
43
|
-
eigenvalues={props.eigenvalues}
|
|
44
|
-
updateMode={updateMode}
|
|
45
|
-
/>
|
|
46
|
-
</Col>
|
|
47
|
-
</Row>
|
|
48
|
-
</Container>
|
|
49
|
-
</ParametersContext.Provider>
|
|
50
|
-
);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export default PhononVisualizer;
|
package/src/components/types.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export type LatticeVector = [number, number, number];
|
|
2
|
-
export type Vector = [number, number, number];
|
|
3
|
-
export type HighSymPoint = [number, string];
|
|
4
|
-
|
|
5
|
-
export interface VisualizerProps {
|
|
6
|
-
title: string;
|
|
7
|
-
name: string;
|
|
8
|
-
natoms: number;
|
|
9
|
-
lattice: LatticeVector[];
|
|
10
|
-
atom_types: string[];
|
|
11
|
-
atom_numbers: number[];
|
|
12
|
-
formula: string;
|
|
13
|
-
qpoints: Vector[];
|
|
14
|
-
repetitions: number[];
|
|
15
|
-
atom_pos_car: Vector[];
|
|
16
|
-
atom_pos_red: Vector[];
|
|
17
|
-
eigenvalues: number[][];
|
|
18
|
-
distances: number[];
|
|
19
|
-
highsym_qpts: HighSymPoint[];
|
|
20
|
-
vectors: number[][][][][];
|
|
21
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { useState } from "react";
|
|
2
|
-
|
|
3
|
-
const useParameters = (repetitions: number[]) => {
|
|
4
|
-
const [Nx, Ny, Nz] = repetitions;
|
|
5
|
-
const [nx, setNx] = useState(Nx);
|
|
6
|
-
const [ny, setNy] = useState(Ny);
|
|
7
|
-
const [nz, setNz] = useState(Nz);
|
|
8
|
-
const [cameraDirection, setCameraDirection] = useState([0, 0, 1]);
|
|
9
|
-
const [showCell, setShowCell] = useState(true);
|
|
10
|
-
const [amplitude, setAmplitude] = useState(0.65);
|
|
11
|
-
const [vectorLength, setVectorLength] = useState(3.5);
|
|
12
|
-
const [showVectors, setShowVectors] = useState(true);
|
|
13
|
-
const [speed, setSpeed] = useState(0.25);
|
|
14
|
-
|
|
15
|
-
return {
|
|
16
|
-
nx,
|
|
17
|
-
setNx,
|
|
18
|
-
ny,
|
|
19
|
-
setNy,
|
|
20
|
-
nz,
|
|
21
|
-
setNz,
|
|
22
|
-
cameraDirection,
|
|
23
|
-
setCameraDirection,
|
|
24
|
-
showCell,
|
|
25
|
-
setShowCell,
|
|
26
|
-
amplitude,
|
|
27
|
-
setAmplitude,
|
|
28
|
-
vectorLength,
|
|
29
|
-
setVectorLength,
|
|
30
|
-
showVectors,
|
|
31
|
-
setShowVectors,
|
|
32
|
-
speed,
|
|
33
|
-
setSpeed,
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export default useParameters;
|
package/src/main.scss
DELETED
package/src/main.tsx
DELETED
package/src/vite-env.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/// <reference types="vite/client" />
|
package/tsconfig.app.json
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"composite": true,
|
|
4
|
-
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
|
5
|
-
"target": "ES2020",
|
|
6
|
-
"useDefineForClassFields": true,
|
|
7
|
-
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
8
|
-
"module": "ESNext",
|
|
9
|
-
"skipLibCheck": true,
|
|
10
|
-
|
|
11
|
-
/* Bundler mode */
|
|
12
|
-
"moduleResolution": "bundler",
|
|
13
|
-
"allowImportingTsExtensions": true,
|
|
14
|
-
"resolveJsonModule": true,
|
|
15
|
-
"isolatedModules": true,
|
|
16
|
-
"moduleDetection": "force",
|
|
17
|
-
"noEmit": true,
|
|
18
|
-
"jsx": "react-jsx",
|
|
19
|
-
|
|
20
|
-
/* Linting */
|
|
21
|
-
"strict": true,
|
|
22
|
-
"noUnusedLocals": true,
|
|
23
|
-
"noUnusedParameters": true,
|
|
24
|
-
"noFallthroughCasesInSwitch": true,
|
|
25
|
-
|
|
26
|
-
/* Types */
|
|
27
|
-
"typeRoots": ["./node_modules/@types", "./declarations.d.ts"]
|
|
28
|
-
},
|
|
29
|
-
"include": ["src", "declarations.d.ts"]
|
|
30
|
-
}
|
package/tsconfig.json
DELETED
package/tsconfig.node.json
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"composite": true,
|
|
4
|
-
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
|
5
|
-
"skipLibCheck": true,
|
|
6
|
-
"module": "ESNext",
|
|
7
|
-
"moduleResolution": "bundler",
|
|
8
|
-
"allowSyntheticDefaultImports": true,
|
|
9
|
-
"strict": true,
|
|
10
|
-
"noEmit": true
|
|
11
|
-
},
|
|
12
|
-
"include": ["vite.config.ts"]
|
|
13
|
-
}
|
package/vite.config.ts
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|