Skip to content

Commit

Permalink
rename Structure->PymatgenStructure
Browse files Browse the repository at this point in the history
add .env.example showing how to store MP API key
  • Loading branch information
janosh committed Apr 26, 2023
1 parent b2484ed commit 2009670
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_MP_API_KEY=length-32-alpha-numeric
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ dist
# screen recordings
*.mp4
coverage

# secrets
.env

# needs server
/src/routes/api
9 changes: 7 additions & 2 deletions src/lib/Structure.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
<script lang="ts">
import { Canvas, OrbitControls, T } from '@threlte/core'
import { atomic_colors, atomic_radii, get_elements, type Structure } from './structure'
import {
atomic_colors,
atomic_radii,
get_elements,
type PymatgenStructure,
} from './structure'
// output of pymatgen.core.Structure.as_dict()
export let structure: Structure | undefined = undefined
export let structure: PymatgenStructure | undefined = undefined
// scale factor for atomic radii
export let atom_radius: number = 0.5
// whether to use the same radius for all atoms. if not, the radius will be
Expand Down
4 changes: 2 additions & 2 deletions src/lib/StructureCard.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script lang="ts">
import { pretty_num } from './labels'
import { alphabetical_formula, density, type Structure } from './structure'
import { alphabetical_formula, density, type PymatgenStructure } from './structure'
export let structure: Structure
export let structure: PymatgenStructure
export let title: string = ''
export let fallback: string = ''
Expand Down
10 changes: 5 additions & 5 deletions src/lib/structure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ export type Lattice = {
volume: number
}

export type Structure = {
export type PymatgenStructure = {
charge: number
lattice: Lattice
sites: Site[]
}

export function get_elem_amount(structure: Structure) {
export function get_elem_amount(structure: PymatgenStructure) {
const elements: Record<ElementSymbol, number> = {}
for (const site of structure.sites) {
for (const species of site.species) {
Expand All @@ -50,7 +50,7 @@ export function get_elem_amount(structure: Structure) {
return elements
}

export function alphabetical_formula(structure: Structure) {
export function alphabetical_formula(structure: PymatgenStructure) {
// concatenate elements in a pymatgen Structure followed by their amount in alphabetical order
const elements = get_elem_amount(structure)
const formula = []
Expand All @@ -76,7 +76,7 @@ export const atomic_weights = Object.fromEntries(
element_data.map((el) => [el.symbol, el.atomic_mass])
)

export function get_elements(structure: Structure): ElementSymbol[] {
export function get_elements(structure: PymatgenStructure): ElementSymbol[] {
const elems = structure.sites.flatMap((site) =>
site.species.map((sp) => sp.element)
)
Expand All @@ -87,7 +87,7 @@ export function get_elements(structure: Structure): ElementSymbol[] {
// to grams per cubic centimeter (g/cm^3)
const uA3_to_gcm3 = 1.66053907

export function density(structure: Structure, prec = `.2f`) {
export function density(structure: PymatgenStructure, prec = `.2f`) {
// calculate the density of a pymatgen Structure in
const elements = get_elem_amount(structure)
let mass = 0
Expand Down

0 comments on commit 2009670

Please sign in to comment.