Skip to content

Commit

Permalink
1. Fixed README.md 2. Modified Example
Browse files Browse the repository at this point in the history
  • Loading branch information
BowenD-UCB committed Apr 7, 2023
1 parent 1aea1fc commit 2d262e0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 34 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ pip install -e ./chgnet

### Direct Inference (Static Calculation)

Pretrained `CHGNet` can predict the energy (eV/atom), force (eV/$\dot{\text A}$), stress (GPa) and magmom ($\mu_B$) of a given structure.
Pretrained `CHGNet` can predict the energy (eV/atom), force (eV/$\AA$), stress (GPa) and
magmom ($\mu_B$) of a given structure.

```python
from chgnet.model.model import CHGNet
Expand Down
76 changes: 43 additions & 33 deletions examples/CHGNet_examples.ipynb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"id": "f8c75a16",
"metadata": {},
Expand Down Expand Up @@ -36,7 +35,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "16eeae1e",
"metadata": {},
Expand Down Expand Up @@ -89,7 +87,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "abcc09b4",
"metadata": {},
Expand All @@ -114,12 +111,11 @@
"source": [
"chgnet = CHGNet.load()\n",
"\n",
"# Or you can read your own model\n",
"# model = CHGNet.from_file(model_path)"
"# Alternatively you can read your own model\n",
"# chgnet = CHGNet.from_file(model_path)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "961d51fc",
"metadata": {},
Expand All @@ -143,18 +139,18 @@
"text": [
"CHGNet-predicted energy=-7.371591567993164\n",
"\n",
"CHGNet-predicted forces=[[ 4.4703484e-08 -2.7939677e-08 2.4071123e-02]\n",
" [ 1.4901161e-08 -2.9918738e-08 -2.4071217e-02]\n",
" [-1.1920929e-07 1.0244548e-08 2.5402993e-02]\n",
" [-0.0000000e+00 -2.3283064e-08 -2.5402665e-02]\n",
" [-1.7881393e-07 6.6356733e-08 -2.1660209e-02]\n",
" [ 2.4139881e-06 -7.9928432e-06 9.5508099e-03]\n",
" [-2.2053719e-06 7.9749152e-06 -9.5512867e-03]\n",
" [-5.9604645e-08 -0.0000000e+00 2.1660507e-02]]\n",
"CHGNet-predicted forces=[[ 4.4703484e-08 -4.2840838e-08 2.4071064e-02]\n",
" [-4.4703484e-08 -1.4551915e-08 -2.4071217e-02]\n",
" [-1.7881393e-07 1.0244548e-08 2.5402933e-02]\n",
" [ 5.9604645e-08 -2.3283064e-08 -2.5402665e-02]\n",
" [-1.1920929e-07 6.6356733e-08 -2.1660209e-02]\n",
" [ 2.3543835e-06 -8.0077443e-06 9.5508099e-03]\n",
" [-2.2947788e-06 7.9898164e-06 -9.5513463e-03]\n",
" [-5.9604645e-08 -0.0000000e+00 2.1660626e-02]]\n",
"\n",
"CHGNet-predicted stress=[[ 3.3677614e-01 -1.9665707e-07 -5.6416429e-06]\n",
" [ 4.9939729e-07 2.4675032e-01 1.8549043e-05]\n",
" [-4.0414070e-06 1.9096897e-05 4.0323928e-02]]\n",
"CHGNet-predicted stress=[[ 3.3677638e-01 -3.7330341e-07 -5.1117036e-06]\n",
" [ 1.0701370e-06 2.4674933e-01 1.8477700e-05]\n",
" [-4.4460303e-06 1.9265182e-05 4.0324528e-02]]\n",
"\n",
"CHGNet-predicted magmom=[0.00521556 0.0052153 3.8572898 3.8572903 0.02538028 0.03706942\n",
" 0.03706949 0.02538028]\n",
Expand All @@ -164,12 +160,13 @@
],
"source": [
"prediction = chgnet.predict_structure(structure)\n",
"for key in (\"energy\", \"forces\", \"stress\", \"magmom\"):\n",
"for key, _unit in zip(\n",
" (\"energy\", \"forces\", \"stress\", \"magmom\"), (\"eV/atom\", \"eV/A\", \"GPa\", \"mu_B\")\n",
"):\n",
" print(f\"CHGNet-predicted {key}={prediction[key[0]]}\\n\")"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "2258f2f5",
"metadata": {},
Expand Down Expand Up @@ -205,24 +202,38 @@
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"CHGNet took 29 steps. Relaxed structure:\n",
"Full Formula (Li2 Mn2 O4)\n",
"Reduced Formula: LiMnO2\n",
"abc : 2.865864 4.648716 5.827764\n",
"angles: 89.917211 90.239405 89.975425\n",
"pbc : True True True\n",
"Sites (8)\n",
" # SP a b c magmom\n",
"--- ---- --------- --------- -------- ----------\n",
" 0 Li+ 0.494018 0.479737 0.387171 0.00498427\n",
" 1 Li+ 0.008464 0.006131 0.625817 0.00512926\n",
" 2 Mn3+ 0.50073 0.502478 0.869608 3.85374\n",
" 3 Mn3+ 0.997815 -0.000319 0.139344 3.859\n",
" 4 O2- 0.502142 0.009453 0.363411 0.0253105\n",
" 5 O2- 1.00293 0.502592 0.104559 0.0366638\n",
" 6 O2- 0.493749 0.998092 0.903592 0.0365367\n",
" 7 O2- -0.002278 0.495108 0.645655 0.0248522\n"
]
}
],
"source": [
"result = relaxer.relax(structure)\n",
"structure.perturb(0.1)\n",
"result = relaxer.relax(structure, verbose=False)\n",
"print(f\"\\nCHGNet took {len(result['trajectory'])} steps. Relaxed structure:\")\n",
"print(result[\"final_structure\"])"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "06f7e84c",
"metadata": {},
Expand Down Expand Up @@ -271,7 +282,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "c6a10ec8",
"metadata": {},
Expand Down Expand Up @@ -1806,9 +1816,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "py310",
"display_name": "Python (tf)",
"language": "python",
"name": "python3"
"name": "myenv"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -1820,7 +1830,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.0"
"version": "3.9.10"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 2d262e0

Please sign in to comment.