From 91385820a69f5873815e4a321b37a7a9af33be18 Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Sat, 15 Jul 2023 15:03:26 -0700 Subject: [PATCH] fix find_image_atoms() for non-cuboid lattices use shear matrix to render lattice (fixes rendering lattice as parallelepiped, i.e. when show_cell = 'surface') use + to render lattice vectors --- package.json | 2 +- src/lib/InfoCard.svelte | 9 ++- src/lib/material/MaterialCard.svelte | 48 +++++++---- src/lib/math.ts | 4 +- src/lib/structure/Bond.svelte | 7 +- src/lib/structure/Lattice.svelte | 81 ++++++++----------- src/lib/structure/Structure.svelte | 34 ++++---- src/lib/structure/StructureScene.svelte | 13 ++- src/lib/structure/index.ts | 26 +++--- .../(demos)/periodic-table/+page.svelte | 4 +- src/routes/api/+page.svelte | 2 +- src/routes/mp-[slug]/+page.svelte | 27 ++++--- 12 files changed, 141 insertions(+), 116 deletions(-) diff --git a/package.json b/package.json index d69cd3c..28126e3 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "jsdom": "^22.1.0", "mdsvex": "^0.11.0", "mdsvexamples": "^0.3.3", - "prettier": "^3.0.0", + "prettier": "^2.8.8", "prettier-plugin-svelte": "^2.10.1", "rehype-autolink-headings": "^6.1.1", "rehype-katex-svelte": "^1.2.0", diff --git a/src/lib/InfoCard.svelte b/src/lib/InfoCard.svelte index a787b79..748f228 100644 --- a/src/lib/InfoCard.svelte +++ b/src/lib/InfoCard.svelte @@ -1,12 +1,13 @@ @@ -54,20 +72,20 @@
Related materials IDs {#if material.task_ids?.length} -

- Task IDs: {#each material.task_ids as id} - {id} - {/each} -

-{/if} -{#if material.database_IDs.icsd?.length} - -

- ICSD IDs: {#each material.database_IDs.icsd as id} - {id} - {/each} -

-{/if} +

+ Task IDs: {#each material.task_ids as id} + {id} + {/each} +

+ {/if} + {#if material.database_IDs?.icsd?.length} +

+ ICSD IDs: {#each material.database_IDs.icsd as id} + {@const href = `https://ccdc.cam.ac.uk/structures/Search?Ccdcid=${id}&DatabaseToSearch=ICSD`} + {id} + {/each} +

+ {/if}

diff --git a/src/lib/math.ts b/src/lib/math.ts index 60a9991..f9ccdd2 100644 --- a/src/lib/math.ts +++ b/src/lib/math.ts @@ -5,7 +5,7 @@ export function norm(vec: NdVector): number { return Math.sqrt(vec.reduce((acc, val) => acc + val ** 2, 0)) } -export function scale(vec: NdVector, factor: number): NdVector { +export function scale(vec: T, factor: number): T { return vec.map((val) => val * factor) } @@ -13,7 +13,7 @@ export function euclidean_dist(vec1: Vector, vec2: Vector): number { return norm(add(vec1, scale(vec2, -1))) } -export function add(...vecs: NdVector[]): NdVector { +export function add(...vecs: T[]): T { // add up any number of same-length vectors const result = vecs[0].slice() for (const vec of vecs.slice(1)) { diff --git a/src/lib/structure/Bond.svelte b/src/lib/structure/Bond.svelte index c62bee5..c4044e6 100644 --- a/src/lib/structure/Bond.svelte +++ b/src/lib/structure/Bond.svelte @@ -1,9 +1,10 @@ {#if show_cell} - new Vector3(...p)))} - > - + - + {/if} {#if show_vectors} - {#each matrix as vec, idx} - {@const [x, y, z] = vec ?? []} - - - - {/each} + + + + + + {#each matrix as vec, idx} + + {/each} + + + + + + + {#each matrix as vec, idx} + + {/each} + + {/if} diff --git a/src/lib/structure/Structure.svelte b/src/lib/structure/Structure.svelte index 9b5ad43..c0b65fe 100644 --- a/src/lib/structure/Structure.svelte +++ b/src/lib/structure/Structure.svelte @@ -1,16 +1,17 @@