From 224024b3efd852213d51b753fe8ed67da5ff6bb5 Mon Sep 17 00:00:00 2001 From: "T.Tian" Date: Thu, 21 Nov 2024 18:14:00 +0800 Subject: [PATCH] add example run results --- doc/examples/geopt_compare.md | 24 +++++++++++++++++++- doc/examples/simple_dft.md | 9 ++++++++ examples/simple_examples/ex1-ase-optimize.py | 21 +++++++++-------- 3 files changed, 43 insertions(+), 11 deletions(-) diff --git a/doc/examples/geopt_compare.md b/doc/examples/geopt_compare.md index ffb35349..8fefec60 100644 --- a/doc/examples/geopt_compare.md +++ b/doc/examples/geopt_compare.md @@ -14,7 +14,7 @@ from ase.build import molecule from ase.constraints import FixAtoms from sparc import SPARC -nh3 = molecule("NH3", cell=(8, 8, 8), pbc=False) +nh3 = molecule("NH3", cell=(8, 8, 8), pbc=False, center=True) # Fix the N center nh3.constraints = [FixAtoms([0])] nh3.rattle() @@ -98,3 +98,25 @@ def optimize_ase_bfgs_socket(): print(f"Final fmax: {np.max(np.abs(f_fin))} eV/Ang") print(f"N steps: {nsteps}") ``` + +Possible outputs +```{raw} +SPARC internal LBFGS: +Final energy: -330.8388527992713 eV +Final fmax: 0.014610782237434465 eV/Ang +N steps: 23 +``` + +```{raw} +ASE LBFGS +Final energy: -330.8460713860338 eV +Final fmax: 0.008090338967301871 eV/Ang +N steps: 21 +``` + +```{raw} +ASE LBFGS (socket mode) +Final energy: -330.8356141220578 eV +Final fmax: 0.015431850436823448 eV/Ang +N steps: 18 +``` diff --git a/doc/examples/simple_dft.md b/doc/examples/simple_dft.md index d38c2ed5..9b119920 100644 --- a/doc/examples/simple_dft.md +++ b/doc/examples/simple_dft.md @@ -60,6 +60,15 @@ if __name__ == "__main__": main() ``` +The output from the above example may look like: +```{raw} +Fitted volume (Ang^3), energy (eV), modulus (eV/Ang^3) +65.97840834969949 -253.07755156337953 2.9095110471623173 +Optimal cell length (cubic): 4.040799280428726 Ang +Energy calculated by SPARC: -253.0552324051582 eV +Energy diff 0.02231915822133601 eV +``` + ```{note} This example uses file I/O mode for demonstration purpose only. Consider choosing the [socket mode](../advanced_socket.md) if you need more flexibility. ``` diff --git a/examples/simple_examples/ex1-ase-optimize.py b/examples/simple_examples/ex1-ase-optimize.py index 750286cf..77cb06fe 100644 --- a/examples/simple_examples/ex1-ase-optimize.py +++ b/examples/simple_examples/ex1-ase-optimize.py @@ -7,11 +7,12 @@ import numpy as np from ase.build import molecule from ase.constraints import FixAtoms -from ase.optimize.bfgs import BFGS +from ase.optimize.lbfgs import LBFGS from sparc import SPARC nh3 = molecule("NH3", cell=(8, 8, 8), pbc=False) +nh3.center() # Fix the N center nh3.constraints = [FixAtoms([0])] nh3.rattle() @@ -20,7 +21,7 @@ def optimize_sparc_internal(): atoms = nh3.copy() calc = SPARC( - h=0.25, + h=0.18, kpts=(1, 1, 1), xc="pbe", convergence={"forces": 0.02}, @@ -41,14 +42,14 @@ def optimize_sparc_internal(): def optimize_ase_bfgs(): atoms = nh3.copy() - calc = SPARC(h=0.25, kpts=(1, 1, 1), xc="pbe", directory="ex1-ase") + calc = SPARC(h=0.18, kpts=(1, 1, 1), xc="pbe", directory="ex1-ase") atoms.calc = calc - opt = BFGS(atoms) + opt = LBFGS(atoms) opt.run(fmax=0.02) e_fin = atoms.get_potential_energy() f_fin = atoms.get_forces() nsteps = opt.nsteps - print("ASE LBFGS") + print("ASE LBFGS (file I/O mode)") print(f"Final energy: {e_fin} eV") print(f"Final fmax: {np.max(np.abs(f_fin))} eV/Ang") print(f"N steps: {nsteps}") @@ -57,7 +58,7 @@ def optimize_ase_bfgs(): def optimize_ase_bfgs_socket(): atoms = nh3.copy() calc = SPARC( - h=0.25, + h=0.18, kpts=(1, 1, 1), xc="pbe", print_forces=True, @@ -66,18 +67,18 @@ def optimize_ase_bfgs_socket(): ) atoms.calc = calc with calc: - opt = BFGS(atoms) + opt = LBFGS(atoms) opt.run(fmax=0.02) e_fin = atoms.get_potential_energy() f_fin = atoms.get_forces() nsteps = opt.nsteps - print("ASE LBFGS") + print("ASE LBFGS (socket mode)") print(f"Final energy: {e_fin} eV") print(f"Final fmax: {np.max(np.abs(f_fin))} eV/Ang") print(f"N steps: {nsteps}") if __name__ == "__main__": - optimize_sparc_internal() - optimize_ase_bfgs() + # optimize_sparc_internal() + # optimize_ase_bfgs() optimize_ase_bfgs_socket()