From bd94475fb3938088bb0163ab600c08d5ceff18a4 Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Mon, 26 Jun 2023 08:00:39 -0700 Subject: [PATCH 01/18] clean up gitignore --- .gitignore | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/.gitignore b/.gitignore index 8eb0ec33..5adaf13b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,49 +6,15 @@ __pycache__/ *.so # Distribution / packaging -bin/ build/ -develop-eggs/ dist/ -eggs/ -lib/ -lib64/ -parts/ sdist/ -var/ *.egg-info/ -.installed.cfg -*.egg - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt # Unit test / coverage reports -.tox/ .coverage -.cache -nosetests.xml coverage.xml -# Translations -*.mo - -# Mr Developer -.mr.developer.cfg -.project -.pydevproject - -# Rope -.ropeproject - -# Django stuff: -*.log -*.pot - -# Sphinx documentation -docs/_build/ - # Extras *.traj *.xml From a3c475496b2493bb91b709ee61ba7feddb5b7311 Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Mon, 26 Jun 2023 15:05:44 -0700 Subject: [PATCH 02/18] add sveltekit site deployed to GitHub Pages with auto-generated api docs --- .github/workflows/gh-pages.yml | 18 ++ README.md | 6 +- site/.eslintrc.yml | 28 +++ site/.gitignore | 7 + site/make_docs.py | 39 +++++ site/package.json | 54 ++++++ site/src/app.css | 163 ++++++++++++++++++ site/src/app.d.ts | 5 + site/src/app.html | 48 ++++++ site/src/routes/+error.svelte | 48 ++++++ site/src/routes/+layout.svelte | 75 ++++++++ site/src/routes/+layout.ts | 10 ++ site/src/routes/+page.svelte | 22 +++ site/src/routes/api/+page.svelte | 21 +++ .../static/chgnet-logo.png | Bin site/static/prism-vsc-dark-plus.css | 141 +++++++++++++++ site/svelte.config.js | 52 ++++++ site/tsconfig.json | 16 ++ site/vite.config.ts | 15 ++ 19 files changed, 766 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/gh-pages.yml create mode 100644 site/.eslintrc.yml create mode 100644 site/.gitignore create mode 100644 site/make_docs.py create mode 100644 site/package.json create mode 100644 site/src/app.css create mode 100644 site/src/app.d.ts create mode 100644 site/src/app.html create mode 100644 site/src/routes/+error.svelte create mode 100644 site/src/routes/+layout.svelte create mode 100644 site/src/routes/+layout.ts create mode 100644 site/src/routes/+page.svelte create mode 100644 site/src/routes/api/+page.svelte rename chgnet-logo.png => site/static/chgnet-logo.png (100%) create mode 100644 site/static/prism-vsc-dark-plus.css create mode 100644 site/svelte.config.js create mode 100644 site/tsconfig.json create mode 100644 site/vite.config.ts diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml new file mode 100644 index 00000000..df857d46 --- /dev/null +++ b/.github/workflows/gh-pages.yml @@ -0,0 +1,18 @@ +name: GitHub Pages + +on: + pull_request: + branches: [main] + push: + branches: [main] + workflow_dispatch: + +jobs: + build: + uses: janosh/workflows/.github/workflows/nodejs-gh-pages.yml@main + with: + python-version: "3.11" + working-directory: site + pre-build: | + pip install '..[gh-pages]' + python make_docs.py diff --git a/README.md b/README.md index a845f4a1..cb3ea741 100755 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ A pretrained universal neural network potential for **charge**-informed atomistic modeling -![chgnet](chgnet-logo.png) +![chgnet](https://raw.github.com/CederGroupHub/chgnet/main/site/static/chgnet-logo.png) **C**rystal **H**amiltonian **G**raph neural **Net**work is pretrained on the GGA/GGA+U static and relaxation trajectories from Materials Project, a comprehensive dataset consisting of 1.5 Million structures from 146k compounds spanning the whole periodic table. @@ -25,7 +25,7 @@ DFT magnetic moments, which carry rich information about both local ionic enviro | Notebooks | Links       | Descriptions | | ------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | -| [**CHGNet Basics**](https://github.com/CederGroupHub/chgnet/blob/main/examples/basics.ipynb) | [![Open in Google Colab]](https://colab.research.google.com/github/CederGroupHub/chgnet/blob/main/examples/basics.ipynb) | Examples for loading pre-trained CHGNet, predicting energy, force, stress, magmom as well as running structure optimization and MD. | +| [**CHGNet Basics**](https://github.com/CederGroupHub/chgnet/blob/main/examples/basics.ipynb) | [![Open in Google Colab]](https://colab.research.google.com/github/CederGroupHub/chgnet/blob/main/examples/basics.ipynb) | Examples for loading pre-trained CHGNet, predicting energy, force, stress, magmom as well as running structure optimization and MD. | | [**Tuning CHGNet**](https://github.com/CederGroupHub/chgnet/blob/main/examples/fine_tuning.ipynb) | [![Open in Google Colab]](https://colab.research.google.com/github/CederGroupHub/chgnet/blob/main/examples/fine_tuning.ipynb) | Examples of fine tuning the pretrained CHGNet to your system of interest. | | [**Visualize Relaxation**](https://github.com/CederGroupHub/chgnet/blob/main/examples/crystaltoolkit_relax_viewer.ipynb) | [![Open in Google Colab]](https://colab.research.google.com/github/CederGroupHub/chgnet/blob/main/examples/crystaltoolkit_relax_viewer.ipynb) | Crystal Toolkit that visualizes atom positions, energies and forces of a structure during CHGNet relaxation. | @@ -39,6 +39,8 @@ You can install `chgnet` through `pip`: pip install chgnet ``` + + ## Usage ### Direct Inference (Static Calculation) diff --git a/site/.eslintrc.yml b/site/.eslintrc.yml new file mode 100644 index 00000000..409b7ea3 --- /dev/null +++ b/site/.eslintrc.yml @@ -0,0 +1,28 @@ +root: true +env: + browser: true + es2020: true + node: true +parser: '@typescript-eslint/parser' +parserOptions: + sourceType: module + ecmaVersion: latest +plugins: [svelte3, '@typescript-eslint'] +extends: + - eslint:recommended + - plugin:@typescript-eslint/recommended +overrides: + - files: ['*.svelte'] + processor: svelte3/svelte3 +settings: + svelte3/typescript: true +rules: + indent: [error, 2, SwitchCase: 1] + '@typescript-eslint/quotes': [error, backtick, avoidEscape: true] + semi: [error, never] + linebreak-style: [error, unix] + no-console: [error, allow: [warn, error]] + no-var: error + # allow triple slash for typescript file referencing https://git.io/JCeqO + spaced-comment: [error, always, { markers: [/] }] + '@typescript-eslint/no-inferrable-types': off diff --git a/site/.gitignore b/site/.gitignore new file mode 100644 index 00000000..bded1f72 --- /dev/null +++ b/site/.gitignore @@ -0,0 +1,7 @@ +# dependencies +node_modules + +# production build +.svelte-kit +build +src/routes/api/*.md diff --git a/site/make_docs.py b/site/make_docs.py new file mode 100644 index 00000000..aa44c4d6 --- /dev/null +++ b/site/make_docs.py @@ -0,0 +1,39 @@ +"""This script auto-generates markdown files from Python docstrings using lazydocs +and tweaks the output for +- prettier badges linking to source code on GitHub +- remove bold tags since they break inline code. +""" +from __future__ import annotations + +import json +import os +import subprocess +from glob import glob + +ROOT = os.path.dirname(os.path.dirname(__file__)) +os.chdir(ROOT) +with open("site/package.json") as file: + pkg = json.load(file) +route = "site/src/routes/api" + +for path in glob(f"{route}/*.md"): + os.remove(path) + +subprocess.run( + f"lazydocs {pkg['name']} --output-path {route} " + f"--no-watermark --src-base-url {pkg['repository']}/blob/main", + shell=True, +) + +for path in glob(f"{route}/*.md"): + with open(path) as file: + markdown = file.read() + # remove tags from generated markdown as they break inline code + markdown = markdown.replace("", "").replace("", "") + # improve style of badges linking to source code on GitHub + markdown = markdown.replace( + 'src="https://img.shields.io/badge/-source-cccccc?style=flat-square"', + 'src="https://img.shields.io/badge/source-blue?style=flat" alt="source link"', + ) + with open(path, "w") as file: + file.write(markdown) diff --git a/site/package.json b/site/package.json new file mode 100644 index 00000000..f54e515d --- /dev/null +++ b/site/package.json @@ -0,0 +1,54 @@ +{ + "name": "chgnet", + "description": "Universal neural network potential for charge-informed atomistic modeling", + "author": "Deng et al.", + "homepage": "https://CederGroupHub.github.io/chgnet", + "repository": "https://github.com/CederGroupHub/chgnet", + "license": "MIT", + "type": "module", + "bugs": "https://github.com/CederGroupHub/chgnet/issues", + "scripts": { + "dev": "vite dev", + "build": "vite build", + "preview": "vite preview", + "serve": "vite build && vite preview", + "changelog": "npx auto-changelog --package --output ../changelog.md --unreleased-only --hide-credit --commit-limit false" + }, + "devDependencies": { + "@sveltejs/adapter-static": "^2.0.2", + "@sveltejs/kit": "^1.20.5", + "@sveltejs/vite-plugin-svelte": "^2.4.2", + "@typescript-eslint/eslint-plugin": "^5.60.1", + "@typescript-eslint/parser": "^5.60.1", + "eslint": "^8.43.0", + "eslint-plugin-svelte3": "^4.0.0", + "hastscript": "^7.2.0", + "mdsvex": "^0.11.0", + "prettier": "^2.8.8", + "prettier-plugin-svelte": "^2.10.1", + "rehype-autolink-headings": "^6.1.1", + "rehype-slug": "^5.1.0", + "svelte": "^4.0.0", + "svelte-check": "^3.4.4", + "svelte-multiselect": "^9.0.0", + "svelte-preprocess": "^5.0.4", + "svelte-toc": "^0.5.5", + "svelte-zoo": "^0.4.8", + "svelte2tsx": "^0.6.16", + "tslib": "^2.5.3", + "typescript": "^5.1.3", + "vite": "^4.3.9" + }, + "prettier": { + "semi": false, + "singleQuote": true, + "overrides": [ + { + "files": "*.svelte", + "options": { + "printWidth": 90 + } + } + ] + } +} diff --git a/site/src/app.css b/site/src/app.css new file mode 100644 index 00000000..af065bee --- /dev/null +++ b/site/src/app.css @@ -0,0 +1,163 @@ +:root { + --night: #061e25; + --blue: cornflowerblue; + --text-color: rgb(208, 208, 208); + + --toc-mobile-bg: #0d1a1d; + --toc-mobile-shadow: 0 0 1em 0 black; + --toc-title-padding: 0 0 0 3pt; + --toc-li-padding: 2pt 1ex; + --toc-mobile-btn-color: white; + --toc-mobile-btn-bg: teal; + --toc-mobile-btn-padding: 1pt 2pt; + --toc-desktop-nav-margin: 0 0 0 1em; + --toc-min-width: 15em; + --toc-active-border: solid cornflowerblue; + --toc-active-border-width: 0 0 0 2pt; + --toc-active-bg: none; + --toc-active-border-radius: 0; + + --zoo-github-corner-color: var(--night); + --zoo-github-corner-bg: white; + + --sms-options-bg: rgb(50, 48, 66); + --sms-active-color: cornflowerblue; +} +body { + background: var(--night); + font-family: -apple-system, BlinkMacSystemFont, Roboto, sans-serif; + color: var(--text-color); + line-height: 1.5; + margin: 0; +} +body > div { + display: flex; + min-height: 100vh; + flex-direction: column; +} +main { + padding: calc(1ex + 2vw); + flex: 1; + margin: auto; + box-sizing: border-box; + width: 100%; + max-width: 50em; +} +button { + color: var(--text-color); + cursor: pointer; + border: none; + border-radius: 3pt; + background: teal; + padding: 2pt 4pt; +} +a { + color: var(--blue); + text-decoration: none; + transition: 0.2s; +} +a:hover { + color: orange; +} +a.link { + padding: 0 4pt; + background-color: rgba(255, 255, 255, 0.1); + border-radius: 3pt; + transition: 0.2s; +} +a.link[aria-current='page'] { + color: mediumseagreen; +} +code { + overflow-wrap: break-word; + padding: 1pt 3pt; + border-radius: 2pt; + font-size: 1.2em; + background-color: rgba(0, 255, 255, 0.1); +} +pre code { + background-color: transparent; + display: inline-block; + font-size: 10pt; +} +pre { + position: relative; + border-radius: 4pt; + background-color: rgba(255, 255, 255, 0.05); + overflow-x: auto; + padding: 6pt 8pt; + margin: 1em auto; +} +ul { + padding-left: 1em; +} +label { + font-weight: bold; + cursor: pointer; +} + +table { + border-collapse: collapse; + width: 100%; +} +table :is(td, th) { + border: 1px solid gray; + padding: 5pt 9pt; +} +img { + max-width: 100%; +} +tbody tr:nth-child(odd) { + background: black; +} +h1 { + text-align: center; +} +.hide-in-docs { + display: none; +} + +:where(h2, h3, h4, h5, h6) { + scroll-margin-top: 50px; + transition: 0.3s; +} +:where(h2, h3, h4, h5, h6).toc-clicked { + color: orange; +} +/* style heading anchors added by rehype-autolink-headings, see svelte.config.js */ +:where(h2, h3, h4, h5, h6) a[aria-hidden='true'] { + transition: 0.3s; + margin-left: 4pt; + opacity: 0; +} +:where(h2, h3, h4, h5, h6):hover a[aria-hidden='true'] { + opacity: 1; +} + +blockquote { + border-left: 3pt solid var(--blue); + padding: 4pt 2pt 4pt 9pt; + margin: 1em auto; + background-color: rgba(255, 255, 255, 0.1); +} +blockquote p:last-child { + margin-bottom: 0; +} +blockquote p:first-child { + margin-top: 0; +} + +/* for /api/[slug] */ +kbd { + padding: 0 1ex 0 0; +} +aside.toc.desktop { + position: fixed; + top: 3em; + left: calc(50vw + 45em / 2); + max-width: 16em; +} + +caption { + display: block; +} diff --git a/site/src/app.d.ts b/site/src/app.d.ts new file mode 100644 index 00000000..42353ad4 --- /dev/null +++ b/site/src/app.d.ts @@ -0,0 +1,5 @@ +/// +/// + +declare module '*.md' +declare module '*package.json' diff --git a/site/src/app.html b/site/src/app.html new file mode 100644 index 00000000..1302341b --- /dev/null +++ b/site/src/app.html @@ -0,0 +1,48 @@ + + + + CHGNet + + + + + + + + + + + + + + + + + + + + + + %sveltekit.head% + + + + + + + + + + +
%sveltekit.body%
+ + diff --git a/site/src/routes/+error.svelte b/site/src/routes/+error.svelte new file mode 100644 index 00000000..0fc5d615 --- /dev/null +++ b/site/src/routes/+error.svelte @@ -0,0 +1,48 @@ + + + + Error {$page.status} • {name} + + + + +
+

Error {String($page.status).replace(`0`, `😵`)}: {$page.error?.message}

+ {#if $page.status >= 500} +

+ If page reloading doesn't help, please raise an issue on + GitHub. Thanks! 🙏 +

+ {/if} + {#if online === false} + Looks like you're offline. If you think your connection is fine, check the + GitHub status page + as this site is hosted by GitHub Pages. + {/if} + +

+ Back to + {name} + landing page + . +

+
+ + diff --git a/site/src/routes/+layout.svelte b/site/src/routes/+layout.svelte new file mode 100644 index 00000000..5bf26e36 --- /dev/null +++ b/site/src/routes/+layout.svelte @@ -0,0 +1,75 @@ + + + + + + + + +{#if $page.url.pathname !== `/`} + « home +{/if} + + + + + + + + diff --git a/site/src/routes/+layout.ts b/site/src/routes/+layout.ts new file mode 100644 index 00000000..fb9ec5a9 --- /dev/null +++ b/site/src/routes/+layout.ts @@ -0,0 +1,10 @@ +import { redirect } from '@sveltejs/kit' + +export const prerender = true + +export const load = ({ url }) => { + if (url.pathname.match(`^/(examples|pymatviz)`)) { + const gh_file_url = `https://github.com/janosh/pymatviz/blob/-/${url.pathname}` + throw redirect(307, gh_file_url) + } +} diff --git a/site/src/routes/+page.svelte b/site/src/routes/+page.svelte new file mode 100644 index 00000000..c1871abe --- /dev/null +++ b/site/src/routes/+page.svelte @@ -0,0 +1,22 @@ + + +
+ + +

Docs

+ View CHGNet API docs +
+
+
+ + diff --git a/site/src/routes/api/+page.svelte b/site/src/routes/api/+page.svelte new file mode 100644 index 00000000..b5ac1ebe --- /dev/null +++ b/site/src/routes/api/+page.svelte @@ -0,0 +1,21 @@ +
+

API

+ + {#each Object.values(import.meta.glob(`./*.md`, { eager: true })) as file} + + {/each} +
+ + diff --git a/chgnet-logo.png b/site/static/chgnet-logo.png similarity index 100% rename from chgnet-logo.png rename to site/static/chgnet-logo.png diff --git a/site/static/prism-vsc-dark-plus.css b/site/static/prism-vsc-dark-plus.css new file mode 100644 index 00000000..e6fb6e3d --- /dev/null +++ b/site/static/prism-vsc-dark-plus.css @@ -0,0 +1,141 @@ +/** + * MIT License + * Copyright (c) 2018 Sarah Drasner + * Sarah Drasner's[@sdras] Night Owl + * Ported by Sara vieria [@SaraVieira] + * Added by Souvik Mandal [@SimpleIndian] + */ + +code[class*='language-'], +pre[class*='language-'] { + color: #d6deeb; + font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; + text-align: left; + white-space: pre; + word-spacing: normal; + word-break: normal; + word-wrap: normal; + line-height: 1.5; + + -moz-tab-size: 4; + -o-tab-size: 4; + tab-size: 4; + + -webkit-hyphens: none; + -moz-hyphens: none; + -ms-hyphens: none; + hyphens: none; +} + +pre[class*='language-']::selection, +pre[class*='language-'] ::selection, +code[class*='language-']::selection, +code[class*='language-'] ::selection { + text-shadow: none; + background: rgba(29, 59, 83, 0.99); +} + +@media print { + code[class*='language-'], + pre[class*='language-'] { + text-shadow: none; + } +} + +:not(pre) > code[class*='language-'], +pre[class*='language-'] { + color: white; +} + +:not(pre) > code[class*='language-'] { + padding: 0.1em; + border-radius: 0.3em; + white-space: normal; +} + +.token.comment, +.token.prolog, +.token.cdata { + color: rgb(99, 119, 119); + font-style: italic; +} + +.token.punctuation { + color: rgb(199, 146, 234); +} + +.namespace { + color: rgb(178, 204, 214); +} + +.token.deleted { + color: rgba(239, 83, 80, 0.56); + font-style: italic; +} + +.token.symbol, +.token.property { + color: rgb(128, 203, 196); +} + +.token.tag, +.token.operator, +.token.keyword { + color: rgb(127, 219, 202); +} + +.token.boolean { + color: rgb(255, 88, 116); +} + +.token.number { + color: rgb(247, 140, 108); +} + +.token.constant, +.token.function, +.token.builtin, +.token.char { + color: rgb(130, 170, 255); +} + +.token.selector, +.token.doctype { + color: rgb(199, 146, 234); + font-style: italic; +} + +.token.attr-name, +.token.inserted { + color: rgb(173, 219, 103); + font-style: italic; +} + +.token.string, +.token.url, +.token.entity, +.language-css .token.string, +.style .token.string { + color: rgb(173, 219, 103); +} + +.token.class-name, +.token.atrule, +.token.attr-value { + color: rgb(255, 203, 139); +} + +.token.regex, +.token.important, +.token.variable { + color: rgb(214, 222, 235); +} + +.token.important, +.token.bold { + font-weight: bold; +} + +.token.italic { + font-style: italic; +} diff --git a/site/svelte.config.js b/site/svelte.config.js new file mode 100644 index 00000000..4c205807 --- /dev/null +++ b/site/svelte.config.js @@ -0,0 +1,52 @@ +import adapter from '@sveltejs/adapter-static' +import { s } from 'hastscript' +import { mdsvex } from 'mdsvex' +import link_headings from 'rehype-autolink-headings' +import heading_slugs from 'rehype-slug' +import preprocess from 'svelte-preprocess' + +const rehypePlugins = [ + heading_slugs, + [ + link_headings, + { + behavior: `append`, + test: [`h2`, `h3`, `h4`, `h5`, `h6`], // don't auto-link

+ content: s( + `svg`, + { width: 16, height: 16, viewBox: `0 0 16 16` }, + // symbol #octicon-link defined in app.html + s(`use`, { 'xlink:href': `#octicon-link` }) + ), + }, + ], +] + +const { default: pkg } = await import(`./package.json`, { + assert: { type: `json` }, +}) + +/** @type {import('@sveltejs/kit').Config} */ +export default { + extensions: [`.svelte`, `.svx`, `.md`], + + preprocess: [ + // replace readme links to docs with site-internal links + // (which don't require browser navigation) + preprocess({ replace: [[pkg.homepage, ``]] }), + mdsvex({ + rehypePlugins, + extensions: [`.svx`, `.md`], + }), + ], + + kit: { + adapter: adapter(), + + alias: { + $src: `./src`, + $site: `.`, + $root: `..`, + }, + }, +} diff --git a/site/tsconfig.json b/site/tsconfig.json new file mode 100644 index 00000000..6b5192c8 --- /dev/null +++ b/site/tsconfig.json @@ -0,0 +1,16 @@ +{ + "extends": "./.svelte-kit/tsconfig.json", + "compilerOptions": { + "strict": true, + "module": "esnext", + "target": "esnext", + "moduleResolution": "bundler", + + // To have warnings/errors of the Svelte compiler at the correct position, + // enable source maps by default. + "sourceMap": true, + + "forceConsistentCasingInFileNames": true, + "resolveJsonModule": true + } +} diff --git a/site/vite.config.ts b/site/vite.config.ts new file mode 100644 index 00000000..7765a169 --- /dev/null +++ b/site/vite.config.ts @@ -0,0 +1,15 @@ +import { sveltekit } from '@sveltejs/kit/vite' +import type { UserConfig } from 'vite' + +export default { + plugins: [sveltekit()], + + server: { + fs: { allow: [`../..`] }, // needed to import from $root + port: 3000, + }, + + preview: { + port: 3000, + }, +} satisfies UserConfig From 606eca0af7453cc06f80053d8fbd2f3abbcc2cea Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Mon, 26 Jun 2023 15:06:20 -0700 Subject: [PATCH 03/18] add prettier + eslint commit hooks --- .pre-commit-config.yaml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 71ca4cd0..3e20e72c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -43,3 +43,27 @@ repos: hooks: - id: nbstripout args: [--drop-empty-cells, --keep-output] + + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v3.0.0-alpha.6 + hooks: + - id: prettier + args: [--write] # edit files in-place + additional_dependencies: + - prettier + - prettier-plugin-svelte + - svelte + + - repo: https://github.com/pre-commit/mirrors-eslint + rev: v8.41.0 + hooks: + - id: eslint + types: [file] + args: [--fix, --plugin, "svelte3, @typescript-eslint"] + files: \.(js|ts|svelte)$ + additional_dependencies: + - eslint + - typescript + - eslint-plugin-svelte3 + - "@typescript-eslint/eslint-plugin" + - "@typescript-eslint/parser" From 0d2db8d81b2b5554c43d429694f8e6adf950d860 Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Mon, 26 Jun 2023 15:07:18 -0700 Subject: [PATCH 04/18] fix parse error from curly brackets in doc str --- chgnet/utils/vasp_utils.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/chgnet/utils/vasp_utils.py b/chgnet/utils/vasp_utils.py index cd5dc69d..3e5540b2 100644 --- a/chgnet/utils/vasp_utils.py +++ b/chgnet/utils/vasp_utils.py @@ -134,17 +134,17 @@ def solve_charge_by_mag( Args: structure: input pymatgen structure default_ox (dict[str, float]): default oxidation state for elements. - Default = {"Li": 1, "O": -2} - ox_ranges (dict[str, dict[tuple[float, float], int]]): user defined range to + Default = dict(Li=1, O=-2) + ox_ranges (dict[str, dict[tuple[float, float], int]]): user-defined range to convert magmoms into formal valence. Example for Mn (Default): - {"Mn": { - (0.5, 1.5): 2, - (1.5, 2.5): 3, - (2.5, 3.5): 4, - (3.5, 4.2): 3, - (4.2, 5): 2 - }} + ("Mn": ( + (0.5, 1.5): 2, + (1.5, 2.5): 3, + (2.5, 3.5): 4, + (3.5, 4.2): 3, + (4.2, 5): 2 + )) """ ox_list = [] solved_ox = True From 6e9450161cdf3109ec1466798a91b57181950dd2 Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Mon, 26 Jun 2023 15:07:29 -0700 Subject: [PATCH 05/18] refactor solve_charge_by_mag --- chgnet/utils/vasp_utils.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/chgnet/utils/vasp_utils.py b/chgnet/utils/vasp_utils.py index 3e5540b2..170c1382 100644 --- a/chgnet/utils/vasp_utils.py +++ b/chgnet/utils/vasp_utils.py @@ -153,17 +153,15 @@ def solve_charge_by_mag( "Mn": {(0.5, 1.5): 2, (1.5, 2.5): 3, (2.5, 3.5): 4, (3.5, 4.2): 3, (4.2, 5): 2} } - mag_key = ( - "final_magmom" if "final_magmom" in structure.site_properties else "magmom" + mag = structure.site_properties.get( + "final_magmom", structure.site_properties.get("magmom") ) - mag = structure.site_properties[mag_key] - - for site_i, site in enumerate(structure.sites): + for idx, site in enumerate(structure): assigned = False if site.species_string in ox_ranges: for (minmag, maxmag), magox in ox_ranges[site.species_string].items(): - if mag[site_i] >= minmag and mag[site_i] < maxmag: + if mag[idx] >= minmag and mag[idx] < maxmag: ox_list.append(magox) assigned = True break From b800f68ad538c0b1bb41bc14d50ddbc7c97d2617 Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Mon, 26 Jun 2023 15:07:55 -0700 Subject: [PATCH 06/18] tweak 'mps' backend not supported yet error message --- chgnet/model/dynamics.py | 6 ++---- tests/test_relaxation.py | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/chgnet/model/dynamics.py b/chgnet/model/dynamics.py index 54f5375e..3b9c4ecb 100644 --- a/chgnet/model/dynamics.py +++ b/chgnet/model/dynamics.py @@ -71,16 +71,14 @@ def __init__( # mps is disabled before stable version of pytorch on apple mps is released if use_device == "mps": - raise NotImplementedError("mps is not supported yet") + raise NotImplementedError("'mps' backend is not supported yet") # elif torch.backends.mps.is_available(): # self.device = 'mps' # Determine the device to use self.device = use_device or ("cuda" if torch.cuda.is_available() else "cpu") # Move the model to the specified device - if model is None: - model = CHGNet.load() - self.model = model.to(self.device) + self.model = (model or CHGNet.load()).to(self.device) self.stress_weight = stress_weight print(f"CHGNet will run on {self.device}") diff --git a/tests/test_relaxation.py b/tests/test_relaxation.py index d79dab5d..4f51407d 100644 --- a/tests/test_relaxation.py +++ b/tests/test_relaxation.py @@ -48,4 +48,4 @@ def test_structure_optimizer_passes_kwargs_to_model(use_device) -> None: assert relaxer.calculator.device == use_device except NotImplementedError as exc: # TODO: remove try/except once mps is supported - assert str(exc) == "mps is not supported yet" # noqa: PT017 + assert str(exc) == "'mps' backend is not supported yet" # noqa: PT017 From 1a82774f72cf654dde1dc45fe4171f811b14d108 Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Mon, 26 Jun 2023 15:11:03 -0700 Subject: [PATCH 07/18] prettier auto-format readme --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index cb3ea741..8a2359b5 100755 --- a/README.md +++ b/README.md @@ -154,15 +154,15 @@ trainer.train(train_loader, val_loader, test_loader) 1. The energy used for training should be energy/atom if you're fine-tuning the pretrained `CHGNet`. 2. The pretrained dataset of `CHGNet` comes from GGA+U DFT with [`MaterialsProject2020Compatibility`](https://github.com/materialsproject/pymatgen/blob/v2023.2.28/pymatgen/entries/compatibility.py#L826-L1102). -The parameter for VASP is described in [`MPRelaxSet`](https://github.com/materialsproject/pymatgen/blob/v2023.2.28/pymatgen/io/vasp/sets.py#L862-L879). -If you're fine-tuning with [`MPRelaxSet`](https://github.com/materialsproject/pymatgen/blob/v2023.2.28/pymatgen/io/vasp/sets.py#L862-L879), it is recommended to apply the [`MP2020`](https://github.com/materialsproject/pymatgen/blob/v2023.2.28/pymatgen/entries/compatibility.py#L826-L1102) -compatibility to your energy labels so that they're consistent with the pretrained dataset. + The parameter for VASP is described in [`MPRelaxSet`](https://github.com/materialsproject/pymatgen/blob/v2023.2.28/pymatgen/io/vasp/sets.py#L862-L879). + If you're fine-tuning with [`MPRelaxSet`](https://github.com/materialsproject/pymatgen/blob/v2023.2.28/pymatgen/io/vasp/sets.py#L862-L879), it is recommended to apply the [`MP2020`](https://github.com/materialsproject/pymatgen/blob/v2023.2.28/pymatgen/entries/compatibility.py#L826-L1102) + compatibility to your energy labels so that they're consistent with the pretrained dataset. 3. If you're fine-tuning to functionals other than GGA, we recommend you refit the [`AtomRef`](https://github.com/CederGroupHub/chgnet/blob/main/chgnet/model/composition_model.py). 4. `CHGNet` stress is in unit GPa, and the unit conversion has already been included in -[`dataset.py`](https://github.com/CederGroupHub/chgnet/blob/main/chgnet/data/dataset.py). So `VASP` stress can be directly fed to `StructureData` + [`dataset.py`](https://github.com/CederGroupHub/chgnet/blob/main/chgnet/data/dataset.py). So `VASP` stress can be directly fed to `StructureData` 5. To save time from graph conversion step for each training, we recommend you use [`GraphData`](https://github.com/CederGroupHub/chgnet/blob/main/chgnet/data/dataset.py) defined in -[`dataset.py`](https://github.com/CederGroupHub/chgnet/blob/main/chgnet/data/dataset.py), which reads graphs directly from saved directory. To create saved graphs, -see [`examples/make_graphs.py`](https://github.com/CederGroupHub/chgnet/blob/main/examples/make_graphs.py). + [`dataset.py`](https://github.com/CederGroupHub/chgnet/blob/main/chgnet/data/dataset.py), which reads graphs directly from saved directory. To create saved graphs, + see [`examples/make_graphs.py`](https://github.com/CederGroupHub/chgnet/blob/main/examples/make_graphs.py). 6. Apple’s Metal Performance Shaders `MPS` is currently disabled until a stable version of `pytorch` for `MPS` is released. ## Reference From 0262b75594391aae2765fe655196bf4112142d42 Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Mon, 26 Jun 2023 15:39:00 -0700 Subject: [PATCH 08/18] pin pymatgen<2023.06.23 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 06a7b6fd..dc554a05 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ license = { text = "Modified BSD" } dependencies = [ "ase>=3.22.0", "numpy>=1.21.6", - "pymatgen>=2022.4.19", + "pymatgen>=2022.4.19,<2023.06.23", "torch>=1.11.0", ] classifiers = [ From 7badd12e602f6ee4678a687f9653a4ed88bbd8af Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Mon, 26 Jun 2023 15:42:01 -0700 Subject: [PATCH 09/18] gh-pages.yml set required permissions for deploy --- .github/workflows/gh-pages.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index df857d46..75328aba 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -7,6 +7,12 @@ on: branches: [main] workflow_dispatch: +# set permissions of GITHUB_TOKEN to allow deployment to GitHub Pages +permissions: + contents: read + pages: write + id-token: write + jobs: build: uses: janosh/workflows/.github/workflows/nodejs-gh-pages.yml@main From a14c031aa3338077b3386827f16dfb1652f28cee Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Mon, 26 Jun 2023 15:44:38 -0700 Subject: [PATCH 10/18] force npm install to fix resolve error --- .github/workflows/gh-pages.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index 75328aba..a5e5b65e 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -19,6 +19,7 @@ jobs: with: python-version: "3.11" working-directory: site + install-cmd: npm install --force pre-build: | pip install '..[gh-pages]' python make_docs.py From 789e7eacadf6bed7d2920755e6b2eed33157394d Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Mon, 26 Jun 2023 15:45:21 -0700 Subject: [PATCH 11/18] revert pymatgen pin --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index dc554a05..06a7b6fd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ license = { text = "Modified BSD" } dependencies = [ "ase>=3.22.0", "numpy>=1.21.6", - "pymatgen>=2022.4.19,<2023.06.23", + "pymatgen>=2022.4.19", "torch>=1.11.0", ] classifiers = [ From 00f7350b632a77735c6cd4e9475b12f0af9891dc Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Mon, 26 Jun 2023 15:49:46 -0700 Subject: [PATCH 12/18] remove pymatviz copy-paste vestiges --- site/src/app.html | 6 +++--- site/src/routes/+layout.ts | 10 ---------- site/src/routes/+page.svelte | 2 +- 3 files changed, 4 insertions(+), 14 deletions(-) delete mode 100644 site/src/routes/+layout.ts diff --git a/site/src/app.html b/site/src/app.html index 1302341b..7390dc9d 100644 --- a/site/src/app.html +++ b/site/src/app.html @@ -17,12 +17,12 @@ - - + + diff --git a/site/src/routes/+layout.ts b/site/src/routes/+layout.ts deleted file mode 100644 index fb9ec5a9..00000000 --- a/site/src/routes/+layout.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { redirect } from '@sveltejs/kit' - -export const prerender = true - -export const load = ({ url }) => { - if (url.pathname.match(`^/(examples|pymatviz)`)) { - const gh_file_url = `https://github.com/janosh/pymatviz/blob/-/${url.pathname}` - throw redirect(307, gh_file_url) - } -} diff --git a/site/src/routes/+page.svelte b/site/src/routes/+page.svelte index c1871abe..4f023bba 100644 --- a/site/src/routes/+page.svelte +++ b/site/src/routes/+page.svelte @@ -1,5 +1,5 @@
From fb98c2a5d8475533f9e12df3352a399242e8f2bb Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Mon, 26 Jun 2023 16:10:17 -0700 Subject: [PATCH 13/18] add favicon.svg and chgnet-logo.svg --- site/src/routes/+layout.ts | 1 + site/static/chgnet-logo.svg | 1 + site/static/favicon.svg | 1 + 3 files changed, 3 insertions(+) create mode 100644 site/src/routes/+layout.ts create mode 100644 site/static/chgnet-logo.svg create mode 100644 site/static/favicon.svg diff --git a/site/src/routes/+layout.ts b/site/src/routes/+layout.ts new file mode 100644 index 00000000..176ae642 --- /dev/null +++ b/site/src/routes/+layout.ts @@ -0,0 +1 @@ +export const prerender = true diff --git a/site/static/chgnet-logo.svg b/site/static/chgnet-logo.svg new file mode 100644 index 00000000..2f8727e3 --- /dev/null +++ b/site/static/chgnet-logo.svg @@ -0,0 +1 @@ ++-+--+CHGNet diff --git a/site/static/favicon.svg b/site/static/favicon.svg new file mode 100644 index 00000000..4927ad91 --- /dev/null +++ b/site/static/favicon.svg @@ -0,0 +1 @@ +CHGNet From a7e2ddd5107f36353ee8f506a972e2e01799e9b3 Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Mon, 26 Jun 2023 16:29:57 -0700 Subject: [PATCH 14/18] add optional dep lazydocs --- .github/workflows/gh-pages.yml | 2 +- pyproject.toml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index a5e5b65e..7a2d997b 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -21,5 +21,5 @@ jobs: working-directory: site install-cmd: npm install --force pre-build: | - pip install '..[gh-pages]' + pip install '..[docs]' python make_docs.py diff --git a/pyproject.toml b/pyproject.toml index 06a7b6fd..83ea8fd7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,6 +33,7 @@ classifiers = [ test = ["pytest", "pytest-cov"] # needed to run interactive example notebooks crystal-toolkit = ["crystal-toolkit"] +docs = ["lazydocs"] [project.urls] Source = "https://github.com/CederGroupHub/chgnet" From 0d1b2c8ef2fd01755a320969a74165deb23ce9db Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Mon, 26 Jun 2023 16:43:09 -0700 Subject: [PATCH 15/18] fix site description --- chgnet/data/dataset.py | 2 +- site/src/app.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/chgnet/data/dataset.py b/chgnet/data/dataset.py index 53f43d81..b8fdff8b 100644 --- a/chgnet/data/dataset.py +++ b/chgnet/data/dataset.py @@ -669,7 +669,7 @@ def get_train_val_test_loader( def collate_graphs(batch_data: list): - """Collate of list of (graph, target) into batch data,. + """Collate of list of (graph, target) into batch data. Args: batch_data (list): list of (graph, target(dict)) diff --git a/site/src/app.html b/site/src/app.html index 7390dc9d..0ed99a6b 100644 --- a/site/src/app.html +++ b/site/src/app.html @@ -9,7 +9,7 @@ From ead78427ac27d614d3cd8a81008bb5108db55ca4 Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Mon, 26 Jun 2023 18:02:28 -0700 Subject: [PATCH 16/18] drop empty Variables sections from /api --- site/make_docs.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/site/make_docs.py b/site/make_docs.py index aa44c4d6..d9253d28 100644 --- a/site/make_docs.py +++ b/site/make_docs.py @@ -35,5 +35,9 @@ 'src="https://img.shields.io/badge/-source-cccccc?style=flat-square"', 'src="https://img.shields.io/badge/source-blue?style=flat" alt="source link"', ) + # remove "Global Variables" section if only contains TYPE_CHECKING + markdown = markdown.replace( + "\n**Global Variables**\n---------------\n- **TYPE_CHECKING**\n\n", "" + ) with open(path, "w") as file: file.write(markdown) From bd48c76d75e8277bb4da62d0e487d16722cba005 Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Mon, 26 Jun 2023 18:03:12 -0700 Subject: [PATCH 17/18] fix relative path issues from not being served on root domain --- site/src/app.css | 1 + site/src/app.html | 6 +++--- site/src/routes/+layout.svelte | 16 ++++++++-------- site/src/routes/+page.svelte | 3 ++- site/static/prism-vsc-dark-plus.css | 1 - site/svelte.config.js | 4 ++++ 6 files changed, 18 insertions(+), 13 deletions(-) diff --git a/site/src/app.css b/site/src/app.css index af065bee..af4d95df 100644 --- a/site/src/app.css +++ b/site/src/app.css @@ -81,6 +81,7 @@ pre code { font-size: 10pt; } pre { + line-height: 1.6; position: relative; border-radius: 4pt; background-color: rgba(255, 255, 255, 0.05); diff --git a/site/src/app.html b/site/src/app.html index 0ed99a6b..73847169 100644 --- a/site/src/app.html +++ b/site/src/app.html @@ -16,7 +16,7 @@ - + @@ -26,8 +26,8 @@ src="https://plausible.io/js/plausible.js" > - - + + %sveltekit.head% diff --git a/site/src/routes/+layout.svelte b/site/src/routes/+layout.svelte index 5bf26e36..d0857af3 100644 --- a/site/src/routes/+layout.svelte +++ b/site/src/routes/+layout.svelte @@ -1,5 +1,6 @@ @@ -6,7 +7,7 @@

Docs

- View CHGNet API docs + View CHGNet API docs
diff --git a/site/static/prism-vsc-dark-plus.css b/site/static/prism-vsc-dark-plus.css index e6fb6e3d..20d9052d 100644 --- a/site/static/prism-vsc-dark-plus.css +++ b/site/static/prism-vsc-dark-plus.css @@ -15,7 +15,6 @@ pre[class*='language-'] { word-spacing: normal; word-break: normal; word-wrap: normal; - line-height: 1.5; -moz-tab-size: 4; -o-tab-size: 4; diff --git a/site/svelte.config.js b/site/svelte.config.js index 4c205807..5577cfd0 100644 --- a/site/svelte.config.js +++ b/site/svelte.config.js @@ -48,5 +48,9 @@ export default { $site: `.`, $root: `..`, }, + + paths: { + base: process.env.NODE_ENV === `production` ? `/chgnet` : ``, + }, }, } From cb6a22a47e87b456b96189db0170fe69be8d4850 Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Mon, 26 Jun 2023 18:13:54 -0700 Subject: [PATCH 18/18] remove unused global CSS --- site/src/app.css | 1 - site/src/routes/api/+page.svelte | 4 ---- 2 files changed, 5 deletions(-) diff --git a/site/src/app.css b/site/src/app.css index af4d95df..af065bee 100644 --- a/site/src/app.css +++ b/site/src/app.css @@ -81,7 +81,6 @@ pre code { font-size: 10pt; } pre { - line-height: 1.6; position: relative; border-radius: 4pt; background-color: rgba(255, 255, 255, 0.05); diff --git a/site/src/routes/api/+page.svelte b/site/src/routes/api/+page.svelte index b5ac1ebe..b1e3dadb 100644 --- a/site/src/routes/api/+page.svelte +++ b/site/src/routes/api/+page.svelte @@ -14,8 +14,4 @@ :global(hr) { border: none; } - :global(code) { - line-height: 1em; - border-radius: 4pt; - }