matterviz 0.1.12 → 0.1.13
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/dist/ContextMenu.svelte +1 -1
- package/dist/ContextMenu.svelte.d.ts +3 -3
- package/dist/DraggablePane.svelte +10 -5
- package/dist/DraggablePane.svelte.d.ts +3 -3
- package/dist/FilePicker.svelte.d.ts +3 -3
- package/dist/Icon.svelte.d.ts +3 -3
- package/dist/Nav.svelte +76 -31
- package/dist/SettingsSection.svelte.d.ts +3 -3
- package/dist/Spinner.svelte +18 -29
- package/dist/Spinner.svelte.d.ts +3 -3
- package/dist/app.css +4 -0
- package/dist/bands/Bands.svelte +216 -0
- package/dist/bands/Bands.svelte.d.ts +16 -0
- package/dist/bands/BandsAndDos.svelte +26 -0
- package/dist/bands/BandsAndDos.svelte.d.ts +16 -0
- package/dist/bands/Dos.svelte +124 -0
- package/dist/bands/Dos.svelte.d.ts +18 -0
- package/dist/bands/helpers.d.ts +11 -0
- package/dist/bands/helpers.js +195 -0
- package/dist/bands/index.d.ts +5 -0
- package/dist/bands/index.js +6 -0
- package/dist/bands/types.d.ts +54 -0
- package/dist/bands/types.js +2 -0
- package/dist/brillouin/BrillouinZone.svelte +373 -0
- package/dist/brillouin/BrillouinZone.svelte.d.ts +57 -0
- package/dist/brillouin/BrillouinZoneControls.svelte +88 -0
- package/dist/brillouin/BrillouinZoneControls.svelte.d.ts +14 -0
- package/dist/brillouin/BrillouinZoneExportPane.svelte +129 -0
- package/dist/brillouin/BrillouinZoneExportPane.svelte.d.ts +15 -0
- package/dist/brillouin/BrillouinZoneInfoPane.svelte +115 -0
- package/dist/brillouin/BrillouinZoneInfoPane.svelte.d.ts +13 -0
- package/dist/brillouin/BrillouinZoneScene.svelte +180 -0
- package/dist/brillouin/BrillouinZoneScene.svelte.d.ts +34 -0
- package/dist/brillouin/compute.d.ts +7 -0
- package/dist/brillouin/compute.js +215 -0
- package/dist/brillouin/index.d.ts +7 -0
- package/dist/brillouin/index.js +7 -0
- package/dist/brillouin/types.d.ts +23 -0
- package/dist/brillouin/types.js +1 -0
- package/dist/composition/BarChart.svelte.d.ts +3 -3
- package/dist/composition/BubbleChart.svelte +7 -6
- package/dist/composition/BubbleChart.svelte.d.ts +3 -3
- package/dist/composition/Composition.svelte.d.ts +3 -3
- package/dist/composition/PieChart.svelte +1 -1
- package/dist/composition/PieChart.svelte.d.ts +3 -3
- package/dist/composition/parse.d.ts +3 -3
- package/dist/coordination/CoordinationBarPlot.svelte +241 -0
- package/dist/coordination/CoordinationBarPlot.svelte.d.ts +29 -0
- package/dist/coordination/calc-coordination.d.ts +15 -0
- package/dist/coordination/calc-coordination.js +66 -0
- package/dist/coordination/index.d.ts +8 -0
- package/dist/coordination/index.js +7 -0
- package/dist/element/BohrAtom.svelte.d.ts +3 -3
- package/dist/element/ElementHeading.svelte.d.ts +3 -3
- package/dist/element/ElementPhoto.svelte.d.ts +3 -3
- package/dist/element/ElementStats.svelte.d.ts +3 -3
- package/dist/element/ElementTile.svelte +1 -1
- package/dist/element/ElementTile.svelte.d.ts +4 -4
- package/dist/element/Nucleus.svelte.d.ts +3 -3
- package/dist/icons.d.ts +4 -0
- package/dist/icons.js +4 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +5 -1
- package/dist/io/export.d.ts +1 -6
- package/dist/io/export.js +12 -12
- package/dist/labels.d.ts +19 -0
- package/dist/labels.js +59 -0
- package/dist/math.d.ts +7 -2
- package/dist/math.js +24 -12
- package/dist/periodic-table/PeriodicTable.svelte.d.ts +3 -3
- package/dist/periodic-table/PeriodicTableControls.svelte.d.ts +3 -3
- package/dist/periodic-table/PropertySelect.svelte +1 -1
- package/dist/periodic-table/PropertySelect.svelte.d.ts +5 -4
- package/dist/periodic-table/TableInset.svelte.d.ts +3 -3
- package/dist/phase-diagram/PhaseDiagram2D.svelte +44 -107
- package/dist/phase-diagram/PhaseDiagram2D.svelte.d.ts +7 -27
- package/dist/phase-diagram/PhaseDiagram3D.svelte +67 -170
- package/dist/phase-diagram/PhaseDiagram3D.svelte.d.ts +7 -31
- package/dist/phase-diagram/PhaseDiagram4D.svelte +87 -145
- package/dist/phase-diagram/PhaseDiagram4D.svelte.d.ts +5 -28
- package/dist/phase-diagram/PhaseDiagramControls.svelte +9 -9
- package/dist/phase-diagram/PhaseDiagramControls.svelte.d.ts +6 -6
- package/dist/phase-diagram/PhaseDiagramInfoPane.svelte +4 -4
- package/dist/phase-diagram/PhaseDiagramInfoPane.svelte.d.ts +5 -5
- package/dist/phase-diagram/PhaseDiagramStats.svelte +9 -16
- package/dist/phase-diagram/PhaseDiagramStats.svelte.d.ts +3 -3
- package/dist/phase-diagram/StructurePopup.svelte.d.ts +3 -3
- package/dist/phase-diagram/barycentric-coords.js +13 -24
- package/dist/phase-diagram/helpers.d.ts +12 -14
- package/dist/phase-diagram/helpers.js +70 -23
- package/dist/phase-diagram/index.d.ts +58 -0
- package/dist/phase-diagram/index.js +44 -0
- package/dist/phase-diagram/thermodynamics.js +2 -3
- package/dist/phase-diagram/types.d.ts +3 -8
- package/dist/plot/BarPlot.svelte +474 -240
- package/dist/plot/BarPlot.svelte.d.ts +16 -37
- package/dist/plot/BarPlotControls.svelte +33 -201
- package/dist/plot/BarPlotControls.svelte.d.ts +11 -22
- package/dist/plot/ColorBar.svelte.d.ts +3 -3
- package/dist/plot/ColorScaleSelect.svelte +1 -1
- package/dist/plot/ColorScaleSelect.svelte.d.ts +3 -3
- package/dist/plot/ElementScatter.svelte +5 -5
- package/dist/plot/ElementScatter.svelte.d.ts +8 -8
- package/dist/plot/Histogram.svelte +318 -170
- package/dist/plot/Histogram.svelte.d.ts +21 -41
- package/dist/plot/HistogramControls.svelte +115 -347
- package/dist/plot/HistogramControls.svelte.d.ts +13 -28
- package/dist/plot/Line.svelte +1 -1
- package/dist/plot/Line.svelte.d.ts +4 -4
- package/dist/plot/PlotControls.svelte +280 -0
- package/dist/plot/PlotControls.svelte.d.ts +4 -0
- package/dist/plot/PlotLegend.svelte +9 -24
- package/dist/plot/PlotLegend.svelte.d.ts +3 -3
- package/dist/plot/ScatterPlot.svelte +536 -571
- package/dist/plot/ScatterPlot.svelte.d.ts +18 -90
- package/dist/plot/ScatterPlotControls.svelte +108 -316
- package/dist/plot/ScatterPlotControls.svelte.d.ts +11 -38
- package/dist/plot/ScatterPoint.svelte +1 -1
- package/dist/plot/ScatterPoint.svelte.d.ts +5 -5
- package/dist/plot/SpacegroupBarPlot.svelte +235 -0
- package/dist/plot/SpacegroupBarPlot.svelte.d.ts +9 -0
- package/dist/plot/data-transform.d.ts +2 -2
- package/dist/plot/data-transform.js +1 -5
- package/dist/plot/index.d.ts +12 -200
- package/dist/plot/index.js +14 -6
- package/dist/plot/layout.d.ts +10 -16
- package/dist/plot/layout.js +40 -25
- package/dist/plot/scales.d.ts +7 -8
- package/dist/plot/scales.js +22 -7
- package/dist/plot/types.d.ts +303 -0
- package/dist/plot/types.js +1 -0
- package/dist/rdf/RdfPlot.svelte +156 -0
- package/dist/rdf/RdfPlot.svelte.d.ts +20 -0
- package/dist/rdf/calc-rdf.d.ts +4 -0
- package/dist/rdf/calc-rdf.js +107 -0
- package/dist/rdf/index.d.ts +22 -0
- package/dist/rdf/index.js +2 -0
- package/dist/settings.d.ts +86 -75
- package/dist/settings.js +257 -155
- package/dist/structure/Bond.svelte +126 -110
- package/dist/structure/Bond.svelte.d.ts +7 -20
- package/dist/structure/CanvasTooltip.svelte.d.ts +4 -4
- package/dist/structure/Cylinder.svelte +29 -0
- package/dist/structure/Cylinder.svelte.d.ts +10 -0
- package/dist/structure/Lattice.svelte +1 -2
- package/dist/structure/Lattice.svelte.d.ts +3 -3
- package/dist/structure/Structure.svelte +23 -8
- package/dist/structure/Structure.svelte.d.ts +10 -7
- package/dist/structure/StructureControls.svelte +25 -134
- package/dist/structure/StructureControls.svelte.d.ts +4 -9
- package/dist/structure/StructureExportPane.svelte +188 -0
- package/dist/structure/StructureExportPane.svelte.d.ts +17 -0
- package/dist/structure/StructureInfoPane.svelte.d.ts +3 -3
- package/dist/structure/StructureLegend.svelte +91 -27
- package/dist/structure/StructureLegend.svelte.d.ts +5 -4
- package/dist/structure/StructureScene.svelte +93 -100
- package/dist/structure/StructureScene.svelte.d.ts +15 -12
- package/dist/structure/Vector.svelte +19 -25
- package/dist/structure/Vector.svelte.d.ts +3 -3
- package/dist/structure/bonding.d.ts +16 -14
- package/dist/structure/bonding.js +207 -216
- package/dist/structure/export.d.ts +3 -0
- package/dist/structure/export.js +120 -0
- package/dist/structure/index.d.ts +15 -1
- package/dist/structure/index.js +2 -0
- package/dist/symmetry/WyckoffTable.svelte.d.ts +3 -3
- package/dist/symmetry/index.d.ts +1 -0
- package/dist/symmetry/index.js +1 -0
- package/dist/symmetry/spacegroups.d.ts +9 -0
- package/dist/symmetry/spacegroups.js +397 -0
- package/dist/theme/ThemeControl.svelte.d.ts +3 -3
- package/dist/theme/themes.js +2 -16
- package/dist/trajectory/Trajectory.svelte +52 -78
- package/dist/trajectory/Trajectory.svelte.d.ts +5 -5
- package/dist/trajectory/TrajectoryError.svelte.d.ts +3 -3
- package/dist/trajectory/TrajectoryExportPane.svelte +1 -1
- package/dist/trajectory/TrajectoryExportPane.svelte.d.ts +5 -5
- package/dist/trajectory/TrajectoryInfoPane.svelte +1 -1
- package/dist/trajectory/TrajectoryInfoPane.svelte.d.ts +3 -3
- package/dist/trajectory/extract.js +2 -1
- package/dist/trajectory/index.d.ts +1 -1
- package/dist/trajectory/index.js +1 -1
- package/dist/trajectory/parse.js +21 -14
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +17 -0
- package/dist/xrd/XrdPlot.svelte +14 -11
- package/dist/xrd/XrdPlot.svelte.d.ts +6 -5
- package/package.json +20 -12
- package/readme.md +1 -1
- package/dist/material/MaterialCard.svelte +0 -123
- package/dist/material/MaterialCard.svelte.d.ts +0 -9
- package/dist/material/index.d.ts +0 -1
- package/dist/material/index.js +0 -1
- package/dist/plot/formatting.d.ts +0 -7
- package/dist/plot/formatting.js +0 -53
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
<script lang="ts">import { DraggablePane } from '..';
|
|
2
|
+
import { format_num } from '../labels';
|
|
3
|
+
import { analyze_structure_symmetry } from '../symmetry';
|
|
4
|
+
let { pane_open = $bindable(false), structure, bz_data, pane_props = {}, } = $props();
|
|
5
|
+
let sym_data = $state(null);
|
|
6
|
+
$effect(() => {
|
|
7
|
+
sym_data = null;
|
|
8
|
+
if (!pane_open || !structure || !(`lattice` in structure))
|
|
9
|
+
return;
|
|
10
|
+
analyze_structure_symmetry(structure)
|
|
11
|
+
.then((data) => (sym_data = data))
|
|
12
|
+
.catch(console.error);
|
|
13
|
+
});
|
|
14
|
+
let pane_data = $derived.by(() => {
|
|
15
|
+
if (!structure || !bz_data)
|
|
16
|
+
return [];
|
|
17
|
+
const sections = [];
|
|
18
|
+
// Brillouin Zone section
|
|
19
|
+
const bz_order_suffix = [`st`, `nd`, `rd`][bz_data.order - 1] ?? `th`;
|
|
20
|
+
sections.push({
|
|
21
|
+
title: `Brillouin Zone`,
|
|
22
|
+
items: [
|
|
23
|
+
{
|
|
24
|
+
label: `Order`,
|
|
25
|
+
value: `${bz_data.order}${bz_order_suffix}`,
|
|
26
|
+
key: `bz-order`,
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
label: `Volume`,
|
|
30
|
+
value: `${format_num(bz_data.volume, `.3f`)} Å⁻³`,
|
|
31
|
+
key: `bz-volume`,
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
label: `Vertices / Faces`,
|
|
35
|
+
value: `${bz_data.vertices.length} / ${bz_data.faces.length}`,
|
|
36
|
+
key: `bz-vertices`,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
label: `Space Group`,
|
|
40
|
+
value: `${sym_data?.number ?? ``} ${sym_data?.hm_symbol ? `(${sym_data.hm_symbol})` : ``}`.trim(),
|
|
41
|
+
key: `space-group`,
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
});
|
|
45
|
+
// Real Lattice section
|
|
46
|
+
sections.push({
|
|
47
|
+
title: `Real Lattice`,
|
|
48
|
+
items: [
|
|
49
|
+
{
|
|
50
|
+
label: `a, b, c`,
|
|
51
|
+
value: `${[structure.lattice.a, structure.lattice.b, structure.lattice.c]
|
|
52
|
+
.map((v) => format_num(v, `.3~f`))
|
|
53
|
+
.join(`, `)} Å`,
|
|
54
|
+
key: `real-lattice-abc`,
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
label: `α, β, γ`,
|
|
58
|
+
value: `${[structure.lattice.alpha, structure.lattice.beta, structure.lattice.gamma]
|
|
59
|
+
.map((v) => format_num(v, `.2~f`))
|
|
60
|
+
.join(`, `)}°`,
|
|
61
|
+
key: `real-lattice-angles`,
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
});
|
|
65
|
+
// Reciprocal Lattice section
|
|
66
|
+
const k_lattice_items = bz_data.k_lattice.map((vec, idx) => ({
|
|
67
|
+
label: [`b₁`, `b₂`, `b₃`][idx],
|
|
68
|
+
value: `(${vec.map((x) => format_num(x, `.3~f`)).join(`, `)})`,
|
|
69
|
+
key: `reciprocal-${[`b1`, `b2`, `b3`][idx]}`,
|
|
70
|
+
}));
|
|
71
|
+
sections.push({ title: `Reciprocal Lattice (Å⁻¹)`, items: k_lattice_items });
|
|
72
|
+
return sections;
|
|
73
|
+
});
|
|
74
|
+
</script>
|
|
75
|
+
|
|
76
|
+
{#if structure && bz_data}
|
|
77
|
+
<DraggablePane
|
|
78
|
+
bind:show={pane_open}
|
|
79
|
+
closed_icon="Info"
|
|
80
|
+
open_icon="Cross"
|
|
81
|
+
toggle_props={{ class: `bz-info-toggle`, title: `Brillouin zone info` }}
|
|
82
|
+
pane_props={{ ...pane_props, class: `bz-info-pane ${pane_props?.class ?? ``}` }}
|
|
83
|
+
>
|
|
84
|
+
{#each pane_data as section, sec_idx (section.title)}
|
|
85
|
+
{#if sec_idx > 0}<hr />{/if}
|
|
86
|
+
<section>
|
|
87
|
+
<h4>{section.title}</h4>
|
|
88
|
+
{#each section.items as item (item.key ?? item.label)}
|
|
89
|
+
<div class="info-item">
|
|
90
|
+
<span>{item.label}</span>
|
|
91
|
+
<span>{@html item.value}</span>
|
|
92
|
+
</div>
|
|
93
|
+
{/each}
|
|
94
|
+
</section>
|
|
95
|
+
{/each}
|
|
96
|
+
</DraggablePane>
|
|
97
|
+
{/if}
|
|
98
|
+
|
|
99
|
+
<style>
|
|
100
|
+
section div.info-item {
|
|
101
|
+
display: flex;
|
|
102
|
+
justify-content: space-between;
|
|
103
|
+
gap: 6pt;
|
|
104
|
+
padding: 1pt;
|
|
105
|
+
line-height: 1.5;
|
|
106
|
+
}
|
|
107
|
+
h4 {
|
|
108
|
+
margin: 0.5em 0;
|
|
109
|
+
}
|
|
110
|
+
hr {
|
|
111
|
+
border: none;
|
|
112
|
+
border-top: 1px solid var(--divider-color, rgba(128, 128, 128, 0.2));
|
|
113
|
+
margin: 0.5em 0;
|
|
114
|
+
}
|
|
115
|
+
</style>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DraggablePane } from '..';
|
|
2
|
+
import type { PymatgenStructure } from '../structure';
|
|
3
|
+
import type { ComponentProps } from 'svelte';
|
|
4
|
+
import type { BrillouinZoneData } from './types';
|
|
5
|
+
type $$ComponentProps = {
|
|
6
|
+
pane_open?: boolean;
|
|
7
|
+
structure?: PymatgenStructure;
|
|
8
|
+
bz_data?: BrillouinZoneData;
|
|
9
|
+
pane_props?: ComponentProps<typeof DraggablePane>[`pane_props`];
|
|
10
|
+
};
|
|
11
|
+
declare const BrillouinZoneInfoPane: import("svelte").Component<$$ComponentProps, {}, "pane_open">;
|
|
12
|
+
type BrillouinZoneInfoPane = ReturnType<typeof BrillouinZoneInfoPane>;
|
|
13
|
+
export default BrillouinZoneInfoPane;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
<script lang="ts">import { axis_colors, neg_axis_colors } from '..';
|
|
2
|
+
import { DEFAULTS } from '../settings';
|
|
3
|
+
import { Cylinder, Vector } from '../structure';
|
|
4
|
+
import { T, useThrelte } from '@threlte/core';
|
|
5
|
+
import * as extras from '@threlte/extras';
|
|
6
|
+
import { BufferAttribute, BufferGeometry } from 'three';
|
|
7
|
+
let { bz_data = $bindable(undefined), camera_position = $bindable(undefined), camera_projection = $bindable(`perspective`), surface_color = $bindable(`#4488ff`), surface_opacity = $bindable(0.3), edge_color = $bindable(`#000000`), edge_width = $bindable(0.05), show_vectors = $bindable(true), vector_scale = $bindable(1.0), rotation_damping = DEFAULTS.structure.rotation_damping, max_zoom = DEFAULTS.structure.max_zoom, min_zoom = DEFAULTS.structure.min_zoom, zoom_speed = DEFAULTS.structure.zoom_speed, pan_speed = DEFAULTS.structure.pan_speed, fov = DEFAULTS.structure.fov, initial_zoom = DEFAULTS.structure.initial_zoom, ambient_light = DEFAULTS.structure.ambient_light, directional_light = DEFAULTS.structure.directional_light, gizmo = DEFAULTS.structure.show_gizmo, auto_rotate = DEFAULTS.structure.auto_rotate, camera_is_moving = $bindable(false), scene = $bindable(undefined), camera = $bindable(undefined), } = $props();
|
|
8
|
+
const threlte = useThrelte();
|
|
9
|
+
$effect(() => {
|
|
10
|
+
scene = threlte.scene;
|
|
11
|
+
camera = threlte.camera.current;
|
|
12
|
+
});
|
|
13
|
+
extras.interactivity();
|
|
14
|
+
const rotation_target = [0, 0, 0];
|
|
15
|
+
// BZ size for camera positioning: average magnitude of k-vectors
|
|
16
|
+
const bz_size = $derived.by(() => {
|
|
17
|
+
if (!bz_data?.k_lattice)
|
|
18
|
+
return 10;
|
|
19
|
+
const mags = bz_data.k_lattice.map((v) => Math.sqrt(v[0] ** 2 + v[1] ** 2 + v[2] ** 2));
|
|
20
|
+
return mags.reduce((sum, mag) => sum + mag, 0) / 3;
|
|
21
|
+
});
|
|
22
|
+
const computed_camera_position = $derived.by(() => camera_position || [10, 3, 8].map((x) => x * Math.max(1, bz_size)));
|
|
23
|
+
const gizmo_props = $derived.by(() => ({
|
|
24
|
+
background: { enabled: false },
|
|
25
|
+
className: `responsive-gizmo`,
|
|
26
|
+
...Object.fromEntries([...axis_colors, ...neg_axis_colors].map(([axis, color, hover]) => [
|
|
27
|
+
axis,
|
|
28
|
+
{
|
|
29
|
+
color,
|
|
30
|
+
labelColor: `#111`,
|
|
31
|
+
opacity: axis.startsWith(`n`) ? 0.9 : 0.8,
|
|
32
|
+
hover: {
|
|
33
|
+
color: hover,
|
|
34
|
+
labelColor: `#222`,
|
|
35
|
+
opacity: axis.startsWith(`n`) ? 1 : 0.9,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
])),
|
|
39
|
+
...(typeof gizmo === `object` ? gizmo : {}),
|
|
40
|
+
offset: { left: 5, bottom: 5 },
|
|
41
|
+
}));
|
|
42
|
+
const is_ortho = $derived(camera_projection === `orthographic`);
|
|
43
|
+
const orbit_controls_props = $derived({
|
|
44
|
+
position: [0, 0, 0],
|
|
45
|
+
target: rotation_target,
|
|
46
|
+
enableZoom: zoom_speed > 0,
|
|
47
|
+
zoomSpeed: is_ortho ? zoom_speed * 2 : zoom_speed,
|
|
48
|
+
enablePan: pan_speed > 0,
|
|
49
|
+
panSpeed: pan_speed,
|
|
50
|
+
maxZoom: is_ortho ? max_zoom || 200 : max_zoom,
|
|
51
|
+
minZoom: is_ortho ? min_zoom || 0.1 : min_zoom,
|
|
52
|
+
autoRotate: Boolean(auto_rotate),
|
|
53
|
+
autoRotateSpeed: auto_rotate,
|
|
54
|
+
enableDamping: Boolean(rotation_damping),
|
|
55
|
+
dampingFactor: rotation_damping,
|
|
56
|
+
onstart: () => (camera_is_moving = true),
|
|
57
|
+
onend: () => (camera_is_moving = false),
|
|
58
|
+
});
|
|
59
|
+
const vector_colors = [`red`, `green`, `blue`];
|
|
60
|
+
const vector_labels = [`b₁`, `b₂`, `b₃`];
|
|
61
|
+
// Create BZ mesh geometry from faces with fan triangulation
|
|
62
|
+
const bz_geometry = $derived.by(() => {
|
|
63
|
+
if (!bz_data || bz_data.faces.length === 0)
|
|
64
|
+
return null;
|
|
65
|
+
const positions = [];
|
|
66
|
+
const normals = [];
|
|
67
|
+
for (const face of bz_data.faces) {
|
|
68
|
+
if (face.length < 3)
|
|
69
|
+
continue;
|
|
70
|
+
for (let i = 1; i < face.length - 1; i++) {
|
|
71
|
+
const indices = [face[0], face[i], face[i + 1]];
|
|
72
|
+
if (indices.some((idx) => idx < 0 || idx >= bz_data.vertices.length))
|
|
73
|
+
continue;
|
|
74
|
+
const [v0, v1, v2] = indices.map((idx) => bz_data.vertices[idx]);
|
|
75
|
+
positions.push(...v0, ...v1, ...v2);
|
|
76
|
+
// Compute normal via cross product
|
|
77
|
+
const [e1, e2] = [[v1[0] - v0[0], v1[1] - v0[1], v1[2] - v0[2]], [
|
|
78
|
+
v2[0] - v0[0],
|
|
79
|
+
v2[1] - v0[1],
|
|
80
|
+
v2[2] - v0[2],
|
|
81
|
+
]];
|
|
82
|
+
const n = [
|
|
83
|
+
e1[1] * e2[2] - e1[2] * e2[1],
|
|
84
|
+
e1[2] * e2[0] - e1[0] * e2[2],
|
|
85
|
+
e1[0] * e2[1] - e1[1] * e2[0],
|
|
86
|
+
];
|
|
87
|
+
const len = Math.sqrt(n[0] ** 2 + n[1] ** 2 + n[2] ** 2);
|
|
88
|
+
const norm = len > 1e-10 ? n.map((x) => x / len) : [0, 0, 0];
|
|
89
|
+
normals.push(...norm, ...norm, ...norm);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const geometry = new BufferGeometry();
|
|
93
|
+
geometry.setAttribute(`position`, new BufferAttribute(new Float32Array(positions), 3));
|
|
94
|
+
geometry.setAttribute(`normal`, new BufferAttribute(new Float32Array(normals), 3));
|
|
95
|
+
geometry.computeBoundingSphere();
|
|
96
|
+
return geometry;
|
|
97
|
+
});
|
|
98
|
+
$effect(() => {
|
|
99
|
+
return () => bz_geometry?.dispose();
|
|
100
|
+
});
|
|
101
|
+
</script>
|
|
102
|
+
|
|
103
|
+
{#if camera_projection === `perspective`}
|
|
104
|
+
<T.PerspectiveCamera makeDefault position={computed_camera_position} {fov}>
|
|
105
|
+
<extras.OrbitControls {...orbit_controls_props}>
|
|
106
|
+
{#if gizmo}<extras.Gizmo {...gizmo_props} />{/if}
|
|
107
|
+
</extras.OrbitControls>
|
|
108
|
+
</T.PerspectiveCamera>
|
|
109
|
+
{:else}
|
|
110
|
+
<T.OrthographicCamera
|
|
111
|
+
makeDefault
|
|
112
|
+
position={computed_camera_position}
|
|
113
|
+
zoom={initial_zoom}
|
|
114
|
+
near={-100}
|
|
115
|
+
>
|
|
116
|
+
<extras.OrbitControls {...orbit_controls_props}>
|
|
117
|
+
{#if gizmo}<extras.Gizmo {...gizmo_props} />{/if}
|
|
118
|
+
</extras.OrbitControls>
|
|
119
|
+
</T.OrthographicCamera>
|
|
120
|
+
{/if}
|
|
121
|
+
|
|
122
|
+
<T.DirectionalLight position={[3, 10, 10]} intensity={directional_light} />
|
|
123
|
+
<T.AmbientLight intensity={ambient_light} />
|
|
124
|
+
|
|
125
|
+
<T.Group position={rotation_target}>
|
|
126
|
+
{#if bz_data}
|
|
127
|
+
<!-- Brillouin zone surface mesh -->
|
|
128
|
+
{#if bz_geometry}
|
|
129
|
+
<T.Mesh geometry={bz_geometry}>
|
|
130
|
+
<T.MeshStandardMaterial
|
|
131
|
+
color={surface_color}
|
|
132
|
+
transparent
|
|
133
|
+
opacity={surface_opacity}
|
|
134
|
+
side={2}
|
|
135
|
+
depthWrite={false}
|
|
136
|
+
/>
|
|
137
|
+
</T.Mesh>
|
|
138
|
+
{/if}
|
|
139
|
+
|
|
140
|
+
<!-- BZ edges -->
|
|
141
|
+
{#each bz_data.edges as edge_segment (edge_segment.map((v) => v.join(`,`)).join(`-`))}
|
|
142
|
+
<Cylinder
|
|
143
|
+
from={edge_segment[0]}
|
|
144
|
+
to={edge_segment[1]}
|
|
145
|
+
thickness={edge_width}
|
|
146
|
+
color={edge_color}
|
|
147
|
+
/>
|
|
148
|
+
{/each}
|
|
149
|
+
|
|
150
|
+
<!-- Reciprocal lattice vectors -->
|
|
151
|
+
{#if show_vectors && bz_data.k_lattice}
|
|
152
|
+
{#each bz_data.k_lattice as vec, idx (idx)}
|
|
153
|
+
{@const scaled_vec = vec.map((x) => x * vector_scale) as Vec3}
|
|
154
|
+
{@const label_position = scaled_vec.map((x) => x * 1.15) as Vec3}
|
|
155
|
+
<Vector
|
|
156
|
+
position={[0, 0, 0]}
|
|
157
|
+
vector={scaled_vec}
|
|
158
|
+
color={vector_colors[idx]}
|
|
159
|
+
scale={1}
|
|
160
|
+
/>
|
|
161
|
+
<!-- Vector label beyond tip -->
|
|
162
|
+
<extras.HTML center position={label_position}>
|
|
163
|
+
<span
|
|
164
|
+
style:color={vector_colors[idx]}
|
|
165
|
+
style:font-size="1.2em"
|
|
166
|
+
>
|
|
167
|
+
{vector_labels[idx]}
|
|
168
|
+
</span>
|
|
169
|
+
</extras.HTML>
|
|
170
|
+
{/each}
|
|
171
|
+
{/if}
|
|
172
|
+
{/if}
|
|
173
|
+
</T.Group>
|
|
174
|
+
|
|
175
|
+
<style>
|
|
176
|
+
:global(.brillouin-zone .responsive-gizmo) {
|
|
177
|
+
width: clamp(70px, 18cqmin, 100px) !important;
|
|
178
|
+
height: clamp(70px, 18cqmin, 100px) !important;
|
|
179
|
+
}
|
|
180
|
+
</style>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Vec3 } from '..';
|
|
2
|
+
import { type CameraProjection } from '../settings';
|
|
3
|
+
import * as extras from '@threlte/extras';
|
|
4
|
+
import type { ComponentProps } from 'svelte';
|
|
5
|
+
import { type Camera, type Scene } from 'three';
|
|
6
|
+
import type { BrillouinZoneData } from './types';
|
|
7
|
+
type $$ComponentProps = {
|
|
8
|
+
bz_data?: BrillouinZoneData;
|
|
9
|
+
camera_position?: Vec3 | undefined;
|
|
10
|
+
camera_projection?: CameraProjection;
|
|
11
|
+
surface_color?: string;
|
|
12
|
+
surface_opacity?: number;
|
|
13
|
+
edge_color?: string;
|
|
14
|
+
edge_width?: number;
|
|
15
|
+
show_vectors?: boolean;
|
|
16
|
+
vector_scale?: number;
|
|
17
|
+
rotation_damping?: number;
|
|
18
|
+
max_zoom?: number;
|
|
19
|
+
min_zoom?: number;
|
|
20
|
+
zoom_speed?: number;
|
|
21
|
+
pan_speed?: number;
|
|
22
|
+
fov?: number;
|
|
23
|
+
initial_zoom?: number;
|
|
24
|
+
ambient_light?: number;
|
|
25
|
+
directional_light?: number;
|
|
26
|
+
gizmo?: boolean | ComponentProps<typeof extras.Gizmo>;
|
|
27
|
+
auto_rotate?: number;
|
|
28
|
+
camera_is_moving?: boolean;
|
|
29
|
+
scene?: Scene;
|
|
30
|
+
camera?: Camera;
|
|
31
|
+
};
|
|
32
|
+
declare const BrillouinZoneScene: import("svelte").Component<$$ComponentProps, {}, "camera" | "camera_position" | "camera_projection" | "scene" | "camera_is_moving" | "surface_color" | "surface_opacity" | "edge_color" | "edge_width" | "show_vectors" | "bz_data" | "vector_scale">;
|
|
33
|
+
type BrillouinZoneScene = ReturnType<typeof BrillouinZoneScene>;
|
|
34
|
+
export default BrillouinZoneScene;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Matrix3x3, Vec3 } from '..';
|
|
2
|
+
import type { BrillouinZoneData, ConvexHullData } from './types';
|
|
3
|
+
export declare function reciprocal_lattice(real_lattice: Matrix3x3): Matrix3x3;
|
|
4
|
+
export declare function generate_bz_vertices(k_lattice: Matrix3x3, order?: 1 | 2 | 3, max_planes_by_order?: Record<1 | 2 | 3, number>): Vec3[];
|
|
5
|
+
export declare function compute_convex_hull(vertices: Vec3[], edge_sharp_angle_deg?: number): ConvexHullData;
|
|
6
|
+
export declare function compute_brillouin_zone(k_lattice: Matrix3x3, order?: 1 | 2 | 3, edge_sharp_angle_deg?: number, // Angle threshold for edge extraction (default 5°, increase for fewer edges, decrease for more)
|
|
7
|
+
max_planes_by_order?: Record<number, number>): BrillouinZoneData;
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
// Brillouin zone generation via convex hull
|
|
2
|
+
import * as math from '../math';
|
|
3
|
+
import { Vector3 } from 'three';
|
|
4
|
+
import { ConvexGeometry } from 'three/examples/jsm/geometries/ConvexGeometry.js';
|
|
5
|
+
const normalize = (vec) => {
|
|
6
|
+
const mag = Math.sqrt(vec[0] ** 2 + vec[1] ** 2 + vec[2] ** 2);
|
|
7
|
+
return mag < 1e-10 ? [0, 0, 0] : [vec[0] / mag, vec[1] / mag, vec[2] / mag];
|
|
8
|
+
};
|
|
9
|
+
// Compute reciprocal lattice: k = inv(real).T * 2π
|
|
10
|
+
export function reciprocal_lattice(real_lattice) {
|
|
11
|
+
const inv = math.matrix_inverse_3x3(real_lattice);
|
|
12
|
+
const transposed = math.transpose_3x3_matrix(inv);
|
|
13
|
+
return transposed.map((row) => math.scale(row, 2 * Math.PI));
|
|
14
|
+
}
|
|
15
|
+
// Generate k-space grid with size based on BZ order
|
|
16
|
+
function generate_k_space_grid(k_lattice, order) {
|
|
17
|
+
const points = [];
|
|
18
|
+
// For order n, we need to include points up to ±n to capture all nearest neighbors
|
|
19
|
+
const range = Math.max(1, order);
|
|
20
|
+
for (let idx_i = -range; idx_i <= range; idx_i++) {
|
|
21
|
+
for (let idx_j = -range; idx_j <= range; idx_j++) {
|
|
22
|
+
for (let idx_k = -range; idx_k <= range; idx_k++) {
|
|
23
|
+
const point = math.add(math.scale(k_lattice[0], idx_i), math.scale(k_lattice[1], idx_j), math.scale(k_lattice[2], idx_k));
|
|
24
|
+
points.push(point);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return points;
|
|
29
|
+
}
|
|
30
|
+
const TOL = 1e-8;
|
|
31
|
+
// O(1) duplicate vertex detection using spatial hashing
|
|
32
|
+
class VertexDeduplicator {
|
|
33
|
+
grid = new Map();
|
|
34
|
+
cell_size;
|
|
35
|
+
constructor(cell_size) {
|
|
36
|
+
this.cell_size = cell_size;
|
|
37
|
+
}
|
|
38
|
+
has_duplicate(vertex) {
|
|
39
|
+
const [base_x, base_y, base_z] = vertex.map((val) => Math.floor(val / this.cell_size));
|
|
40
|
+
for (let dx = -1; dx <= 1; dx++) {
|
|
41
|
+
for (let dy = -1; dy <= 1; dy++) {
|
|
42
|
+
for (let dz = -1; dz <= 1; dz++) {
|
|
43
|
+
const neighbors = this.grid.get(`${base_x + dx},${base_y + dy},${base_z + dz}`);
|
|
44
|
+
if (neighbors?.some((v) => Math.abs(v[0] - vertex[0]) < TOL &&
|
|
45
|
+
Math.abs(v[1] - vertex[1]) < TOL &&
|
|
46
|
+
Math.abs(v[2] - vertex[2]) < TOL))
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
add(vertex) {
|
|
54
|
+
const key = vertex.map((v) => Math.floor(v / this.cell_size)).join(`,`);
|
|
55
|
+
const cell = this.grid.get(key);
|
|
56
|
+
if (cell)
|
|
57
|
+
cell.push(vertex);
|
|
58
|
+
else
|
|
59
|
+
this.grid.set(key, [vertex]);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// Find intersection of three Bragg planes by solving N·v = d
|
|
63
|
+
function intersect_planes(p1, p2, p3) {
|
|
64
|
+
try {
|
|
65
|
+
const matrix = [p1.normal, p2.normal, p3.normal];
|
|
66
|
+
const distances = [p1.dist, p2.dist, p3.dist];
|
|
67
|
+
return math.mat3x3_vec3_multiply(math.matrix_inverse_3x3(matrix), distances);
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// Generate BZ vertices for nth-order zone via three-plane intersections
|
|
74
|
+
export function generate_bz_vertices(k_lattice, order = 1,
|
|
75
|
+
// Maximum number of Bragg planes to consider for each BZ order.
|
|
76
|
+
// Limits the number of three-plane intersections tested (O(n³) operation).
|
|
77
|
+
// Higher values give more accurate zones but increase computation time significantly.
|
|
78
|
+
// Default values: 26 (1st order), 80 (2nd order), 150 (3rd+ order)
|
|
79
|
+
max_planes_by_order = { 1: 26, 2: 80, 3: 150 }) {
|
|
80
|
+
if (order > 3)
|
|
81
|
+
order = 3; // Performance limit
|
|
82
|
+
const k_points = generate_k_space_grid(k_lattice, order);
|
|
83
|
+
const center_idx = Math.floor(k_points.length / 2);
|
|
84
|
+
// Determine max planes for this order (default to highest value for orders > 3)
|
|
85
|
+
const max_planes = max_planes_by_order[order] ?? 150;
|
|
86
|
+
// Create Bragg planes (perpendicular bisectors of k-points)
|
|
87
|
+
const planes = k_points
|
|
88
|
+
.map((pt, idx) => {
|
|
89
|
+
if (idx === center_idx)
|
|
90
|
+
return null;
|
|
91
|
+
const dist_sq = pt[0] ** 2 + pt[1] ** 2 + pt[2] ** 2;
|
|
92
|
+
return { normal: normalize(pt), dist: Math.sqrt(dist_sq) / 2, dist_sq };
|
|
93
|
+
})
|
|
94
|
+
.filter((p) => p !== null)
|
|
95
|
+
.sort((a, b) => a.dist_sq - b.dist_sq)
|
|
96
|
+
.slice(0, max_planes);
|
|
97
|
+
// Pre-compute plane data for fast access
|
|
98
|
+
const normals = planes.map((p) => p.normal);
|
|
99
|
+
const distances = planes.map((p) => p.dist);
|
|
100
|
+
const dedup = new VertexDeduplicator(TOL * 10);
|
|
101
|
+
const vertices = [];
|
|
102
|
+
// Test all three-plane intersections
|
|
103
|
+
for (let idx_i = 0; idx_i < planes.length; idx_i++) {
|
|
104
|
+
for (let idx_j = idx_i + 1; idx_j < planes.length; idx_j++) {
|
|
105
|
+
for (let idx_k = idx_j + 1; idx_k < planes.length; idx_k++) {
|
|
106
|
+
const vertex = intersect_planes(planes[idx_i], planes[idx_j], planes[idx_k]);
|
|
107
|
+
if (!vertex)
|
|
108
|
+
continue;
|
|
109
|
+
// Count how many planes this vertex is beyond (with early termination)
|
|
110
|
+
let beyond_count = 0;
|
|
111
|
+
for (let p_idx = 0; p_idx < normals.length; p_idx++) {
|
|
112
|
+
const dot = vertex[0] * normals[p_idx][0] + vertex[1] * normals[p_idx][1] +
|
|
113
|
+
vertex[2] * normals[p_idx][2];
|
|
114
|
+
if (dot > distances[p_idx] + TOL) {
|
|
115
|
+
beyond_count++;
|
|
116
|
+
if (beyond_count >= order)
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// Vertex belongs to nth BZ if it's beyond fewer than n planes
|
|
121
|
+
if (beyond_count < order && !dedup.has_duplicate(vertex)) {
|
|
122
|
+
vertices.push(vertex);
|
|
123
|
+
dedup.add(vertex);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return vertices;
|
|
129
|
+
}
|
|
130
|
+
// Build convex hull from vertices and extract topology
|
|
131
|
+
export function compute_convex_hull(vertices, edge_sharp_angle_deg = 5) {
|
|
132
|
+
if (vertices.length < 4) {
|
|
133
|
+
throw new Error(`Need ≥4 vertices for convex hull, got ${vertices.length}`);
|
|
134
|
+
}
|
|
135
|
+
const geometry = new ConvexGeometry(vertices.map((v) => new Vector3(...v)));
|
|
136
|
+
const pos = geometry.getAttribute(`position`);
|
|
137
|
+
const idx = geometry.index;
|
|
138
|
+
// Deduplicate vertices from Three.js geometry
|
|
139
|
+
const unique_verts = [];
|
|
140
|
+
const vert_map = new Map();
|
|
141
|
+
for (let idx_vertex = 0; idx_vertex < pos.count; idx_vertex++) {
|
|
142
|
+
const vert = [pos.getX(idx_vertex), pos.getY(idx_vertex), pos.getZ(idx_vertex)];
|
|
143
|
+
const existing_idx = unique_verts.findIndex((u) => Math.abs(u[0] - vert[0]) < TOL && Math.abs(u[1] - vert[1]) < TOL &&
|
|
144
|
+
Math.abs(u[2] - vert[2]) < TOL);
|
|
145
|
+
vert_map.set(idx_vertex, existing_idx === -1 ? (unique_verts.push(vert) - 1) : existing_idx);
|
|
146
|
+
}
|
|
147
|
+
// Build faces with deduplicated vertex indices
|
|
148
|
+
const faces = [];
|
|
149
|
+
const n_faces = idx ? idx.count / 3 : pos.count / 3;
|
|
150
|
+
for (let idx_face = 0; idx_face < n_faces; idx_face++) {
|
|
151
|
+
const tri = idx
|
|
152
|
+
? [idx.getX(idx_face * 3), idx.getX(idx_face * 3 + 1), idx.getX(idx_face * 3 + 2)]
|
|
153
|
+
: [idx_face * 3, idx_face * 3 + 1, idx_face * 3 + 2];
|
|
154
|
+
faces.push(tri.map((j) => {
|
|
155
|
+
const mapped = vert_map.get(j);
|
|
156
|
+
if (mapped === undefined)
|
|
157
|
+
throw new Error(`Vertex ${j} not mapped`);
|
|
158
|
+
return mapped;
|
|
159
|
+
}));
|
|
160
|
+
}
|
|
161
|
+
// Compute face normals and build edge-to-face adjacency
|
|
162
|
+
const face_normals = faces.map((face) => {
|
|
163
|
+
const [v0, v1, v2] = face.slice(0, 3).map((vi) => unique_verts[vi]);
|
|
164
|
+
return normalize(math.cross_3d(math.subtract(v1, v0), math.subtract(v2, v0)));
|
|
165
|
+
});
|
|
166
|
+
const edge_to_faces = new Map();
|
|
167
|
+
faces.forEach((face, face_idx) => {
|
|
168
|
+
face.forEach((v1, idx) => {
|
|
169
|
+
const v2 = face[(idx + 1) % face.length];
|
|
170
|
+
const key = v1 < v2 ? `${v1},${v2}` : `${v2},${v1}`;
|
|
171
|
+
const adj = edge_to_faces.get(key);
|
|
172
|
+
if (adj)
|
|
173
|
+
adj.push(face_idx);
|
|
174
|
+
else
|
|
175
|
+
edge_to_faces.set(key, [face_idx]);
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
// Extract edges: keep boundary edges or sharp angles
|
|
179
|
+
const cos_threshold = Math.cos((edge_sharp_angle_deg * Math.PI) / 180);
|
|
180
|
+
const edges = [];
|
|
181
|
+
for (const [key, adj] of edge_to_faces) {
|
|
182
|
+
const is_sharp = adj.length === 1 ||
|
|
183
|
+
(adj.length === 2 &&
|
|
184
|
+
math.dot(face_normals[adj[0]], face_normals[adj[1]]) < cos_threshold);
|
|
185
|
+
if (is_sharp)
|
|
186
|
+
edges.push(key.split(`,`).map(Number));
|
|
187
|
+
}
|
|
188
|
+
geometry.dispose();
|
|
189
|
+
return { vertices: unique_verts, faces, edges };
|
|
190
|
+
}
|
|
191
|
+
// Compute complete Brillouin zone with topology and volume
|
|
192
|
+
export function compute_brillouin_zone(k_lattice, order = 1, edge_sharp_angle_deg = 5, // Angle threshold for edge extraction (default 5°, increase for fewer edges, decrease for more)
|
|
193
|
+
max_planes_by_order = { 1: 26, 2: 80, 3: 150 }) {
|
|
194
|
+
const vertices = generate_bz_vertices(k_lattice, order, max_planes_by_order);
|
|
195
|
+
if (vertices.length < 4) {
|
|
196
|
+
throw new Error(`Insufficient vertices for BZ (got ${vertices.length}, need ≥4)`);
|
|
197
|
+
}
|
|
198
|
+
const hull = compute_convex_hull(vertices, edge_sharp_angle_deg);
|
|
199
|
+
// Compute volume via divergence theorem (sum of signed tetrahedral volumes)
|
|
200
|
+
const volume = Math.abs(hull.faces.reduce((sum, face) => {
|
|
201
|
+
if (face.length < 3)
|
|
202
|
+
return sum;
|
|
203
|
+
const [v0, v1, v2] = face.slice(0, 3).map((idx) => hull.vertices[idx]);
|
|
204
|
+
const area_normal = math.scale(math.cross_3d(math.subtract(v1, v0), math.subtract(v2, v0)), 0.5);
|
|
205
|
+
return sum + math.dot(v0, area_normal) / 3;
|
|
206
|
+
}, 0));
|
|
207
|
+
return {
|
|
208
|
+
order,
|
|
209
|
+
vertices: hull.vertices,
|
|
210
|
+
faces: hull.faces,
|
|
211
|
+
edges: hull.edges.map(([i1, i2]) => [hull.vertices[i1], hull.vertices[i2]]),
|
|
212
|
+
k_lattice,
|
|
213
|
+
volume,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { default as BrillouinZone } from './BrillouinZone.svelte';
|
|
2
|
+
export { default as BrillouinZoneControls } from './BrillouinZoneControls.svelte';
|
|
3
|
+
export { default as BrillouinZoneExportPane } from './BrillouinZoneExportPane.svelte';
|
|
4
|
+
export { default as BrillouinZoneInfoPane } from './BrillouinZoneInfoPane.svelte';
|
|
5
|
+
export { default as BrillouinZoneScene } from './BrillouinZoneScene.svelte';
|
|
6
|
+
export * from './compute';
|
|
7
|
+
export * from './types';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { default as BrillouinZone } from './BrillouinZone.svelte';
|
|
2
|
+
export { default as BrillouinZoneControls } from './BrillouinZoneControls.svelte';
|
|
3
|
+
export { default as BrillouinZoneExportPane } from './BrillouinZoneExportPane.svelte';
|
|
4
|
+
export { default as BrillouinZoneInfoPane } from './BrillouinZoneInfoPane.svelte';
|
|
5
|
+
export { default as BrillouinZoneScene } from './BrillouinZoneScene.svelte';
|
|
6
|
+
export * from './compute';
|
|
7
|
+
export * from './types';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Matrix3x3, PymatgenStructure, Vec3 } from '..';
|
|
2
|
+
export type BrillouinZoneData = {
|
|
3
|
+
order: number;
|
|
4
|
+
vertices: Vec3[];
|
|
5
|
+
faces: number[][];
|
|
6
|
+
edges: Vec3[][];
|
|
7
|
+
k_lattice: Matrix3x3;
|
|
8
|
+
volume: number;
|
|
9
|
+
};
|
|
10
|
+
export type BrillouinZoneProps = {
|
|
11
|
+
structure: PymatgenStructure;
|
|
12
|
+
bz_order?: number;
|
|
13
|
+
surface_color?: string;
|
|
14
|
+
surface_opacity?: number;
|
|
15
|
+
edge_color?: string;
|
|
16
|
+
edge_width?: number;
|
|
17
|
+
show_vectors?: boolean;
|
|
18
|
+
};
|
|
19
|
+
export type ConvexHullData = {
|
|
20
|
+
vertices: Vec3[];
|
|
21
|
+
faces: number[][];
|
|
22
|
+
edges: [number, number][];
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -12,7 +12,7 @@ type BarSegmentData = ChartSegmentData & {
|
|
|
12
12
|
label_x: number;
|
|
13
13
|
label_y: number;
|
|
14
14
|
};
|
|
15
|
-
|
|
15
|
+
type $$ComponentProps = SVGAttributes<SVGSVGElement> & {
|
|
16
16
|
composition: CompositionType;
|
|
17
17
|
size?: number;
|
|
18
18
|
bar_height?: number;
|
|
@@ -29,7 +29,7 @@ interface Props extends SVGAttributes<SVGSVGElement> {
|
|
|
29
29
|
segment_content?: Snippet<[BarSegmentData]>;
|
|
30
30
|
interactive?: boolean;
|
|
31
31
|
svg_node?: SVGSVGElement | null;
|
|
32
|
-
}
|
|
33
|
-
declare const BarChart: import("svelte").Component
|
|
32
|
+
};
|
|
33
|
+
declare const BarChart: import("svelte").Component<$$ComponentProps, {}, "svg_node">;
|
|
34
34
|
type BarChart = ReturnType<typeof BarChart>;
|
|
35
35
|
export default BarChart;
|
|
@@ -9,19 +9,20 @@ let bubbles = $derived.by(() => {
|
|
|
9
9
|
const element_entries = Object.entries(composition).filter(([_, amount]) => amount && amount > 0);
|
|
10
10
|
if (element_entries.length === 0)
|
|
11
11
|
return [];
|
|
12
|
-
// Create hierarchy data structure for D3 pack
|
|
13
12
|
const hierarchy_data = {
|
|
14
13
|
children: element_entries.map(([element, amount]) => ({
|
|
15
14
|
element,
|
|
16
|
-
amount: amount,
|
|
15
|
+
amount: amount ?? 0,
|
|
17
16
|
color: element_colors[element] || `#cccccc`,
|
|
18
17
|
})),
|
|
19
18
|
};
|
|
20
19
|
// Use D3's pack layout for proper circle packing
|
|
21
|
-
const pack_layout = pack()
|
|
22
|
-
|
|
20
|
+
const pack_layout = pack().size([
|
|
21
|
+
size - 2 * padding,
|
|
22
|
+
size - 2 * padding,
|
|
23
|
+
])
|
|
23
24
|
.padding(padding * 0.1); // Small padding between circles
|
|
24
|
-
const root = pack_layout(hierarchy(hierarchy_data).sum((d) =>
|
|
25
|
+
const root = pack_layout(hierarchy(hierarchy_data).sum((d) => (`amount` in d ? d.amount : 0)));
|
|
25
26
|
// Get max radius for font scaling
|
|
26
27
|
const max_radius = Math.max(...root.leaves().map((d) => d.r || 0));
|
|
27
28
|
const total_atoms = get_total_atoms(composition);
|
|
@@ -39,7 +40,7 @@ let bubbles = $derived.by(() => {
|
|
|
39
40
|
return {
|
|
40
41
|
element: data.element,
|
|
41
42
|
amount: data.amount,
|
|
42
|
-
|
|
43
|
+
fraction: total_atoms > 0 ? data.amount / total_atoms : 0,
|
|
43
44
|
radius,
|
|
44
45
|
x: (node.x || 0) + padding, // Offset by padding
|
|
45
46
|
y: (node.y || 0) + padding,
|