matterviz 0.1.0
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/BohrAtom.svelte +105 -0
- package/dist/BohrAtom.svelte.d.ts +21 -0
- package/dist/ControlPanel.svelte +158 -0
- package/dist/ControlPanel.svelte.d.ts +18 -0
- package/dist/Icon.svelte +23 -0
- package/dist/Icon.svelte.d.ts +8 -0
- package/dist/InfoCard.svelte +79 -0
- package/dist/InfoCard.svelte.d.ts +23 -0
- package/dist/Nucleus.svelte +64 -0
- package/dist/Nucleus.svelte.d.ts +16 -0
- package/dist/Spinner.svelte +44 -0
- package/dist/Spinner.svelte.d.ts +7 -0
- package/dist/api.d.ts +6 -0
- package/dist/api.js +30 -0
- package/dist/colors/alloy-colors.json +111 -0
- package/dist/colors/dark-mode-colors.json +111 -0
- package/dist/colors/index.d.ts +26 -0
- package/dist/colors/index.js +72 -0
- package/dist/colors/jmol-colors.json +111 -0
- package/dist/colors/muted-colors.json +111 -0
- package/dist/colors/pastel-colors.json +111 -0
- package/dist/colors/vesta-colors.json +111 -0
- package/dist/composition/BarChart.svelte +260 -0
- package/dist/composition/BarChart.svelte.d.ts +33 -0
- package/dist/composition/BubbleChart.svelte +166 -0
- package/dist/composition/BubbleChart.svelte.d.ts +30 -0
- package/dist/composition/Composition.svelte +73 -0
- package/dist/composition/Composition.svelte.d.ts +27 -0
- package/dist/composition/PieChart.svelte +236 -0
- package/dist/composition/PieChart.svelte.d.ts +36 -0
- package/dist/composition/index.d.ts +5 -0
- package/dist/composition/index.js +5 -0
- package/dist/composition/parse.d.ts +14 -0
- package/dist/composition/parse.js +307 -0
- package/dist/element/ElementHeading.svelte +21 -0
- package/dist/element/ElementHeading.svelte.d.ts +8 -0
- package/dist/element/ElementPhoto.svelte +56 -0
- package/dist/element/ElementPhoto.svelte.d.ts +9 -0
- package/dist/element/ElementStats.svelte +73 -0
- package/dist/element/ElementStats.svelte.d.ts +8 -0
- package/dist/element/ElementTile.svelte +449 -0
- package/dist/element/ElementTile.svelte.d.ts +25 -0
- package/dist/element/data.d.ts +4958 -0
- package/dist/element/data.js +5628 -0
- package/dist/element/index.d.ts +4 -0
- package/dist/element/index.js +4 -0
- package/dist/icons.d.ts +435 -0
- package/dist/icons.js +435 -0
- package/dist/index.d.ts +82 -0
- package/dist/index.js +43 -0
- package/dist/io/decompress.d.ts +16 -0
- package/dist/io/decompress.js +78 -0
- package/dist/io/export.d.ts +9 -0
- package/dist/io/export.js +205 -0
- package/dist/io/parse.d.ts +53 -0
- package/dist/io/parse.js +747 -0
- package/dist/labels.d.ts +31 -0
- package/dist/labels.js +209 -0
- package/dist/material/MaterialCard.svelte +135 -0
- package/dist/material/MaterialCard.svelte.d.ts +10 -0
- package/dist/material/SymmetryCard.svelte +23 -0
- package/dist/material/SymmetryCard.svelte.d.ts +9 -0
- package/dist/material/index.d.ts +2 -0
- package/dist/material/index.js +2 -0
- package/dist/math.d.ts +24 -0
- package/dist/math.js +216 -0
- package/dist/periodic-table/PeriodicTable.svelte +284 -0
- package/dist/periodic-table/PeriodicTable.svelte.d.ts +50 -0
- package/dist/periodic-table/PropertySelect.svelte +20 -0
- package/dist/periodic-table/PropertySelect.svelte.d.ts +13 -0
- package/dist/periodic-table/TableInset.svelte +18 -0
- package/dist/periodic-table/TableInset.svelte.d.ts +9 -0
- package/dist/periodic-table/index.d.ts +9 -0
- package/dist/periodic-table/index.js +3 -0
- package/dist/plot/ColorBar.svelte +414 -0
- package/dist/plot/ColorBar.svelte.d.ts +22 -0
- package/dist/plot/ColorScaleSelect.svelte +31 -0
- package/dist/plot/ColorScaleSelect.svelte.d.ts +15 -0
- package/dist/plot/ElementScatter.svelte +38 -0
- package/dist/plot/ElementScatter.svelte.d.ts +14 -0
- package/dist/plot/Line.svelte +42 -0
- package/dist/plot/Line.svelte.d.ts +15 -0
- package/dist/plot/PlotLegend.svelte +206 -0
- package/dist/plot/PlotLegend.svelte.d.ts +18 -0
- package/dist/plot/ScatterPlot.svelte +1753 -0
- package/dist/plot/ScatterPlot.svelte.d.ts +114 -0
- package/dist/plot/ScatterPlotControls.svelte +505 -0
- package/dist/plot/ScatterPlotControls.svelte.d.ts +33 -0
- package/dist/plot/ScatterPoint.svelte +72 -0
- package/dist/plot/ScatterPoint.svelte.d.ts +17 -0
- package/dist/plot/index.d.ts +168 -0
- package/dist/plot/index.js +46 -0
- package/dist/state.svelte.d.ts +12 -0
- package/dist/state.svelte.js +11 -0
- package/dist/structure/Bond.svelte +68 -0
- package/dist/structure/Bond.svelte.d.ts +13 -0
- package/dist/structure/Lattice.svelte +115 -0
- package/dist/structure/Lattice.svelte.d.ts +15 -0
- package/dist/structure/Structure.svelte +298 -0
- package/dist/structure/Structure.svelte.d.ts +28 -0
- package/dist/structure/StructureCard.svelte +26 -0
- package/dist/structure/StructureCard.svelte.d.ts +9 -0
- package/dist/structure/StructureControls.svelte +383 -0
- package/dist/structure/StructureControls.svelte.d.ts +23 -0
- package/dist/structure/StructureLegend.svelte +130 -0
- package/dist/structure/StructureLegend.svelte.d.ts +17 -0
- package/dist/structure/StructureScene.svelte +331 -0
- package/dist/structure/StructureScene.svelte.d.ts +47 -0
- package/dist/structure/bonding.d.ts +16 -0
- package/dist/structure/bonding.js +150 -0
- package/dist/structure/index.d.ts +98 -0
- package/dist/structure/index.js +114 -0
- package/dist/structure/pbc.d.ts +6 -0
- package/dist/structure/pbc.js +72 -0
- package/dist/trajectory/Sidebar.svelte +412 -0
- package/dist/trajectory/Sidebar.svelte.d.ts +14 -0
- package/dist/trajectory/Trajectory.svelte +1084 -0
- package/dist/trajectory/Trajectory.svelte.d.ts +49 -0
- package/dist/trajectory/TrajectoryError.svelte +120 -0
- package/dist/trajectory/TrajectoryError.svelte.d.ts +12 -0
- package/dist/trajectory/extract.d.ts +5 -0
- package/dist/trajectory/extract.js +157 -0
- package/dist/trajectory/index.d.ts +16 -0
- package/dist/trajectory/index.js +49 -0
- package/dist/trajectory/parse.d.ts +13 -0
- package/dist/trajectory/parse.js +1093 -0
- package/dist/trajectory/plotting.d.ts +12 -0
- package/dist/trajectory/plotting.js +148 -0
- package/license +21 -0
- package/package.json +131 -0
- package/readme.md +95 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AnyStructure } from '..';
|
|
2
|
+
import { WebGLRenderer } from 'three';
|
|
3
|
+
export interface CanvasWithRenderer extends HTMLCanvasElement {
|
|
4
|
+
__customRenderer?: WebGLRenderer;
|
|
5
|
+
}
|
|
6
|
+
export declare function generate_structure_filename(structure: AnyStructure | undefined, extension: string): string;
|
|
7
|
+
export declare function export_xyz(structure?: AnyStructure): void;
|
|
8
|
+
export declare function export_json(structure?: AnyStructure): void;
|
|
9
|
+
export declare function export_png(canvas: HTMLCanvasElement | null, structure: AnyStructure | undefined, png_dpi?: number): void;
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { electro_neg_formula } from '..';
|
|
2
|
+
import { download } from '../api';
|
|
3
|
+
import { Vector2, WebGLRenderer } from 'three';
|
|
4
|
+
// Generate a filename for structure exports based on structure metadata
|
|
5
|
+
export function generate_structure_filename(structure, extension) {
|
|
6
|
+
if (!structure)
|
|
7
|
+
return `structure.${extension}`;
|
|
8
|
+
const parts = [];
|
|
9
|
+
if (structure.id)
|
|
10
|
+
parts.push(structure.id); // Add ID if available
|
|
11
|
+
// Add formula
|
|
12
|
+
const formula = electro_neg_formula(structure);
|
|
13
|
+
if (formula && formula !== `Unknown`)
|
|
14
|
+
parts.push(formula);
|
|
15
|
+
// Add space group if available
|
|
16
|
+
if (`symmetry` in structure &&
|
|
17
|
+
structure.symmetry &&
|
|
18
|
+
typeof structure.symmetry === `object` &&
|
|
19
|
+
`space_group_symbol` in structure.symmetry)
|
|
20
|
+
parts.push(String(structure.symmetry.space_group_symbol));
|
|
21
|
+
// Add lattice system if available
|
|
22
|
+
if (`lattice` in structure &&
|
|
23
|
+
structure.lattice &&
|
|
24
|
+
typeof structure.lattice === `object` &&
|
|
25
|
+
`lattice_system` in structure.lattice)
|
|
26
|
+
parts.push(String(structure.lattice.lattice_system));
|
|
27
|
+
// Add number of sites
|
|
28
|
+
if (structure.sites?.length)
|
|
29
|
+
parts.push(`${structure.sites.length}sites`);
|
|
30
|
+
const base_name = parts.length > 0 ? parts.join(`_`) : `structure`;
|
|
31
|
+
return `${base_name}.${extension}`;
|
|
32
|
+
}
|
|
33
|
+
// Export structure as XYZ format. Format specification:
|
|
34
|
+
// - Line 1: Number of atoms
|
|
35
|
+
// - Line 2: Comment line (structure ID, formula, etc.)
|
|
36
|
+
// - Remaining lines: Element symbol followed by x, y, z coordinates (in Angstroms)
|
|
37
|
+
export function export_xyz(structure) {
|
|
38
|
+
try {
|
|
39
|
+
if (!structure?.sites) {
|
|
40
|
+
console.warn(`No structure or sites to download`);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const lines = [];
|
|
44
|
+
// First line: number of atoms
|
|
45
|
+
lines.push(String(structure.sites.length));
|
|
46
|
+
// Second line: comment (structure ID, formula, or default)
|
|
47
|
+
const comment_parts = [];
|
|
48
|
+
if (structure.id)
|
|
49
|
+
comment_parts.push(structure.id);
|
|
50
|
+
const formula = electro_neg_formula(structure);
|
|
51
|
+
if (formula && formula !== `Unknown`)
|
|
52
|
+
comment_parts.push(formula);
|
|
53
|
+
const comment = comment_parts.length > 0
|
|
54
|
+
? comment_parts.join(` `)
|
|
55
|
+
: `Generated from structure`;
|
|
56
|
+
lines.push(comment);
|
|
57
|
+
// Atom lines: element symbol followed by x, y, z coordinates
|
|
58
|
+
for (const site of structure.sites) {
|
|
59
|
+
// Extract element symbol from species
|
|
60
|
+
let element_symbol = `X`; // default fallback
|
|
61
|
+
if (site.species &&
|
|
62
|
+
Array.isArray(site.species) &&
|
|
63
|
+
site.species.length > 0) {
|
|
64
|
+
// species is an array of Species objects with element property
|
|
65
|
+
const first_species = site.species[0];
|
|
66
|
+
if (first_species && `element` in first_species) {
|
|
67
|
+
element_symbol = first_species.element;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// Get coordinates - prefer abc (fractional) converted to cartesian, fallback to xyz
|
|
71
|
+
let coords;
|
|
72
|
+
if (site.xyz && Array.isArray(site.xyz) && site.xyz.length >= 3) {
|
|
73
|
+
coords = site.xyz.slice(0, 3);
|
|
74
|
+
}
|
|
75
|
+
else if (site.abc &&
|
|
76
|
+
Array.isArray(site.abc) &&
|
|
77
|
+
site.abc.length >= 3 &&
|
|
78
|
+
`lattice` in structure &&
|
|
79
|
+
structure.lattice) {
|
|
80
|
+
// Convert fractional coordinates to cartesian
|
|
81
|
+
const [a, b, c] = site.abc;
|
|
82
|
+
const lattice = structure.lattice;
|
|
83
|
+
if (lattice.matrix &&
|
|
84
|
+
Array.isArray(lattice.matrix) &&
|
|
85
|
+
lattice.matrix.length >= 3) {
|
|
86
|
+
coords = [
|
|
87
|
+
a * lattice.matrix[0][0] +
|
|
88
|
+
b * lattice.matrix[1][0] +
|
|
89
|
+
c * lattice.matrix[2][0],
|
|
90
|
+
a * lattice.matrix[0][1] +
|
|
91
|
+
b * lattice.matrix[1][1] +
|
|
92
|
+
c * lattice.matrix[2][1],
|
|
93
|
+
a * lattice.matrix[0][2] +
|
|
94
|
+
b * lattice.matrix[1][2] +
|
|
95
|
+
c * lattice.matrix[2][2],
|
|
96
|
+
];
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
coords = [0, 0, 0]; // fallback
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
coords = [0, 0, 0]; // fallback
|
|
104
|
+
}
|
|
105
|
+
// Format coordinates to reasonable precision
|
|
106
|
+
const [x, y, z] = coords.map((coord) => coord.toFixed(6));
|
|
107
|
+
lines.push(`${element_symbol} ${x} ${y} ${z}`);
|
|
108
|
+
}
|
|
109
|
+
const xyz_content = lines.join(`\n`);
|
|
110
|
+
const filename = generate_structure_filename(structure, `xyz`);
|
|
111
|
+
download(xyz_content, filename, `text/plain`);
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
console.error(`Error exporting XYZ:`, error);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
// Export structure in pymatgen JSON format
|
|
118
|
+
export function export_json(structure) {
|
|
119
|
+
try {
|
|
120
|
+
if (!structure) {
|
|
121
|
+
console.warn(`No structure to download`);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const data = JSON.stringify(structure, null, 2);
|
|
125
|
+
const filename = generate_structure_filename(structure, `json`);
|
|
126
|
+
download(data, filename, `application/json`);
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
console.error(`Error exporting JSON:`, error);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// Export structure as PNG image from canvas
|
|
133
|
+
export function export_png(canvas, structure, png_dpi = 150) {
|
|
134
|
+
try {
|
|
135
|
+
if (!canvas) {
|
|
136
|
+
if (typeof window !== `undefined`)
|
|
137
|
+
console.warn(`Canvas not found for PNG export`);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
// Convert DPI to multiplier (72 DPI is baseline web resolution)
|
|
141
|
+
const resolution_multiplier = png_dpi / 72;
|
|
142
|
+
const renderer = canvas.__customRenderer;
|
|
143
|
+
if (resolution_multiplier <= 1.1 || !renderer) {
|
|
144
|
+
// Direct capture at current resolution (if DPI is close to 72 or renderer not available)
|
|
145
|
+
try {
|
|
146
|
+
canvas.toBlob((blob) => {
|
|
147
|
+
if (blob) {
|
|
148
|
+
const filename = generate_structure_filename(structure, `png`);
|
|
149
|
+
download(blob, filename, `image/png`);
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
if (typeof window !== `undefined`) {
|
|
153
|
+
console.warn(`Failed to generate PNG - canvas may be empty`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}, `image/png`);
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
console.error(`Error during PNG export:`, error);
|
|
160
|
+
}
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
// Temporarily modify the renderer's pixel ratio for high-res capture
|
|
164
|
+
const original_pixel_ratio = renderer.getPixelRatio();
|
|
165
|
+
const original_size = renderer.getSize(new Vector2());
|
|
166
|
+
try {
|
|
167
|
+
// Set higher pixel ratio to increase rendering resolution
|
|
168
|
+
renderer.setPixelRatio(resolution_multiplier);
|
|
169
|
+
// Force the canvas to update its resolution
|
|
170
|
+
renderer.setSize(original_size.width, original_size.height, false);
|
|
171
|
+
// Wait for the browser to complete painting at the new resolution
|
|
172
|
+
requestAnimationFrame(() => {
|
|
173
|
+
requestAnimationFrame(() => {
|
|
174
|
+
// Capture the high-resolution render after paint completion
|
|
175
|
+
canvas.toBlob((blob) => {
|
|
176
|
+
// Restore original settings immediately
|
|
177
|
+
renderer.setPixelRatio(original_pixel_ratio);
|
|
178
|
+
renderer.setSize(original_size.width, original_size.height, false);
|
|
179
|
+
if (blob) {
|
|
180
|
+
const filename = generate_structure_filename(structure, `png`);
|
|
181
|
+
download(blob, filename, `image/png`);
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
if (typeof window !== `undefined`) {
|
|
185
|
+
console.warn(`Failed to generate high-resolution PNG`);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}, `image/png`);
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
console.error(`Error during high-res rendering:`, error);
|
|
194
|
+
// Restore original settings
|
|
195
|
+
renderer.setPixelRatio(original_pixel_ratio);
|
|
196
|
+
renderer.setSize(original_size.width, original_size.height, false);
|
|
197
|
+
if (typeof window !== `undefined`) {
|
|
198
|
+
console.warn(`Failed to render at high resolution: ${error instanceof Error ? error.message : String(error)}`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
console.error(`Error exporting PNG:`, error);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type Site } from '..';
|
|
2
|
+
import type { Matrix3x3 } from '../math';
|
|
3
|
+
export interface ParsedStructure {
|
|
4
|
+
sites: Site[];
|
|
5
|
+
lattice?: {
|
|
6
|
+
matrix: Matrix3x3;
|
|
7
|
+
a: number;
|
|
8
|
+
b: number;
|
|
9
|
+
c: number;
|
|
10
|
+
alpha: number;
|
|
11
|
+
beta: number;
|
|
12
|
+
gamma: number;
|
|
13
|
+
volume: number;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export interface PhonopyCell {
|
|
17
|
+
lattice: number[][];
|
|
18
|
+
points: {
|
|
19
|
+
symbol: string;
|
|
20
|
+
coordinates: number[];
|
|
21
|
+
mass: number;
|
|
22
|
+
reduced_to?: number;
|
|
23
|
+
}[];
|
|
24
|
+
reciprocal_lattice?: number[][];
|
|
25
|
+
}
|
|
26
|
+
export interface PhonopyData {
|
|
27
|
+
phono3py?: {
|
|
28
|
+
version: string;
|
|
29
|
+
[key: string]: unknown;
|
|
30
|
+
};
|
|
31
|
+
phonopy?: {
|
|
32
|
+
version: string;
|
|
33
|
+
[key: string]: unknown;
|
|
34
|
+
};
|
|
35
|
+
space_group?: {
|
|
36
|
+
type: string;
|
|
37
|
+
number: number;
|
|
38
|
+
Hall_symbol: string;
|
|
39
|
+
};
|
|
40
|
+
primitive_cell?: PhonopyCell;
|
|
41
|
+
unit_cell?: PhonopyCell;
|
|
42
|
+
supercell?: PhonopyCell;
|
|
43
|
+
phonon_primitive_cell?: PhonopyCell;
|
|
44
|
+
phonon_supercell?: PhonopyCell;
|
|
45
|
+
phonon_displacements?: unknown[];
|
|
46
|
+
[key: string]: unknown;
|
|
47
|
+
}
|
|
48
|
+
export declare function parse_poscar(content: string): ParsedStructure | null;
|
|
49
|
+
export declare function parse_xyz(content: string): ParsedStructure | null;
|
|
50
|
+
export declare function parse_cif(content: string): ParsedStructure | null;
|
|
51
|
+
export type CellType = `primitive_cell` | `unit_cell` | `supercell` | `phonon_primitive_cell` | `phonon_supercell` | `auto`;
|
|
52
|
+
export declare function parse_phonopy_yaml(content: string, cell_type?: CellType): ParsedStructure | null;
|
|
53
|
+
export declare function parse_structure_file(content: string, filename?: string): ParsedStructure | null;
|