From c701e76d8edacb9a35f8d653fd3086f4a1084007 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Holger-Dietrich=20Sa=C3=9Fnick?= Date: Fri, 8 Dec 2023 07:29:35 +0100 Subject: [PATCH] Add tests for levelparser optimization. --- tests/outputs/cell_opt_snippet.out | 360 +++++++++++++++++++++++++++++ tests/outputs/geo_opt_snippet.out | 234 +++++++++++++++++++ tests/test_optimization.py | 170 ++++++++++++++ 3 files changed, 764 insertions(+) create mode 100644 tests/outputs/cell_opt_snippet.out create mode 100644 tests/outputs/geo_opt_snippet.out create mode 100644 tests/test_optimization.py diff --git a/tests/outputs/cell_opt_snippet.out b/tests/outputs/cell_opt_snippet.out new file mode 100644 index 0000000..f2d79f6 --- /dev/null +++ b/tests/outputs/cell_opt_snippet.out @@ -0,0 +1,360 @@ + DBCSR| CPU Multiplication driver XSMM + **** **** ****** ** PROGRAM STARTED AT 2022-01-04 08:15:18.617 + + ******************************************************************************* + *** STARTING CELL OPTIMIZATION *** + *** BFGS *** + ******************************************************************************* + + CELL| Volume [angstrom^3]: 204.400073 + CELL| Vector a [angstrom]: 6.612 0.000 0.000 |a| = 6.611987 + CELL| Vector b [angstrom]: 3.306 5.726 0.000 |b| = 6.611987 + CELL| Vector c [angstrom]: 3.306 1.909 5.399 |c| = 6.611987 + CELL| Angle (b,c), alpha [degree]: 60.000000 + CELL| Angle (a,c), beta [degree]: 60.000000 + CELL| Angle (a,b), gamma [degree]: 60.000000 + CELL| Numerically orthorhombic: NO + + Number of electrons: 32 + Number of occupied orbitals: 16 + Number of molecular orbitals: 16 + + Number of orbital functions: 55 + Number of independent orbital functions: 55 + + Extrapolation method: initial_guess + + SCF WAVEFUNCTION OPTIMIZATION + + Step Update method Time Convergence Total energy Change + ------------------------------------------------------------------------------ + 1 NoMix/Diag. 0.30E+00 0.7 0.67189130 -66.3586357464 -6.64E+01 + 2 Broy./Diag. 0.30E+00 1.0 0.17882655 -66.1732984538 1.85E-01 + 3 Broy./Diag. 0.30E+00 1.0 0.30212420 -66.1120561287 6.12E-02 + 4 Broy./Diag. 0.30E+00 1.0 0.10314316 -66.0396052328 7.25E-02 + 5 Broy./Diag. 0.30E+00 1.0 0.07263661 -65.9773953492 6.22E-02 + 6 Broy./Diag. 0.30E+00 1.0 0.00869464 -65.9801571152 -2.76E-03 + 7 Broy./Diag. 0.30E+00 1.0 0.00556617 -65.9867899352 -6.63E-03 + 8 Broy./Diag. 0.30E+00 1.0 0.00032478 -65.9877896992 -1.00E-03 + 9 Broy./Diag. 0.30E+00 1.0 0.00025348 -65.9872421704 5.48E-04 + 10 Broy./Diag. 0.30E+00 1.0 0.00000698 -65.9870636557 1.79E-04 + + *** SCF run converged in 10 steps *** + + + Electronic density on regular grids: -31.9999999948 0.0000000052 + Core density on regular grids: 31.9999994881 -0.0000005119 + Total charge density on r-space grids: -0.0000005066 + Total charge density g-space grids: -0.0000005066 + + Overlap energy of the core charge distribution: 0.00000000000000 + Self energy of the core charge distribution: -138.89582544120611 + Core Hamiltonian energy: 27.22305865194855 + Hartree energy: 56.70225640899466 + Exchange-correlation energy: -11.01655327543128 + + Total energy: -65.98706365569419 + + ENERGY| Total FORCE_EVAL ( QS ) energy [a.u.]: -65.987063970863261 + + -------- Informations at step = 0 ------------ + Optimization Method = BFGS + Total Energy = -65.9870639709 + Internal Pressure [bar] = 1407.5938745749 + Used time = 11.924 + --------------------------------------------------- + + -------------------------- + OPTIMIZATION STEP: 1 + -------------------------- + + CELL| Volume [angstrom^3]: 204.433884 + CELL| Vector a [angstrom]: 6.612 0.000 0.000 |a| = 6.612271 + CELL| Vector b [angstrom]: 3.306 5.726 0.000 |b| = 6.612274 + CELL| Vector c [angstrom]: 3.306 1.909 5.399 |c| = 6.612274 + CELL| Angle (b,c), alpha [degree]: 60.001888 + CELL| Angle (a,c), beta [degree]: 60.001414 + CELL| Angle (a,b), gamma [degree]: 60.001414 + CELL| Numerically orthorhombic: NO + + Number of electrons: 32 + Number of occupied orbitals: 16 + Number of molecular orbitals: 16 + + Number of orbital functions: 55 + Number of independent orbital functions: 55 + + Extrapolation method: initial_guess + + + SCF WAVEFUNCTION OPTIMIZATION + + Step Update method Time Convergence Total energy Change + ------------------------------------------------------------------------------ + 1 Broy./Diag. 0.30E+00 0.6 1.44229797 -66.3632083671 -6.64E+01 + 2 Broy./Diag. 0.30E+00 1.0 0.83085644 -66.7898367411 -4.27E-01 + 3 Broy./Diag. 0.30E+00 1.0 0.38596392 -66.3766143966 4.13E-01 + 4 Broy./Diag. 0.30E+00 1.0 0.06050568 -65.9970456474 3.80E-01 + 5 Broy./Diag. 0.30E+00 1.0 0.03858035 -65.9314554200 6.56E-02 + 6 Broy./Diag. 0.30E+00 1.0 0.00891794 -65.9706562037 -3.92E-02 + 7 Broy./Diag. 0.30E+00 1.0 0.00193520 -65.9860906608 -1.54E-02 + 8 Broy./Diag. 0.30E+00 1.0 0.00065333 -65.9875824012 -1.49E-03 + 9 Broy./Diag. 0.30E+00 1.0 0.00006695 -65.9873389351 2.43E-04 + + *** SCF run converged in 9 steps *** + + + Electronic density on regular grids: -31.9999898783 0.0000101217 + Core density on regular grids: 31.9999994892 -0.0000005108 + Total charge density on r-space grids: 0.0000096109 + Total charge density g-space grids: 0.0000096109 + + Overlap energy of the core charge distribution: 0.00000000000000 + Self energy of the core charge distribution: -138.89582544120611 + Core Hamiltonian energy: 27.22275912344059 + Hartree energy: 56.70220022668465 + Exchange-correlation energy: -11.01647284404767 + + Total energy: -65.98733893512855 + + ENERGY| Total FORCE_EVAL ( QS ) energy [a.u.]: -65.987065055552009 + + -------- Informations at step = 1 ------------ + Optimization Method = BFGS + Total Energy = -65.9870650556 + Internal Pressure [bar] = 1391.5823882786 + Real energy change = -0.0000010847 + Predicted change in energy = -0.0000005585 + Scaling factor = 0.0000000000 + Step size = 0.0006612580 + Trust radius = 0.4724315332 + Decrease in energy = YES + Used time = 11.068 + + Convergence check : + Max. step size = 0.0006612580 + Conv. limit for step size = 0.0100000000 + Convergence in step size = YES + RMS step size = 0.0002491177 + Conv. limit for RMS step = 0.0100000000 + Convergence in RMS step = YES + Max. gradient = 0.0006529337 + Conv. limit for gradients = 0.0100000000 + Conv. in gradients = YES + RMS gradient = 0.0002461910 + Conv. limit for RMS grad. = 0.0500000000 + Conv. in RMS gradients = YES + Pressure Deviation [bar] = 1424.4356736004 + Pressure Tolerance [bar] = 100.0000000000 + Conv. for PRESSURE = NO + --------------------------------------------------- + + -------------------------- + OPTIMIZATION STEP: 2 + -------------------------- + + CELL| Volume [angstrom^3]: 207.291619 + CELL| Vector a [angstrom]: 6.636 0.000 0.000 |a| = 6.636193 + CELL| Vector b [angstrom]: 3.306 5.754 0.000 |b| = 6.636448 + CELL| Vector c [angstrom]: 3.306 1.909 5.428 |c| = 6.636460 + CELL| Angle (b,c), alpha [degree]: 60.159492 + CELL| Angle (a,c), beta [degree]: 60.119661 + CELL| Angle (a,b), gamma [degree]: 60.119604 + CELL| Numerically orthorhombic: NO + + Number of electrons: 32 + Number of occupied orbitals: 16 + Number of molecular orbitals: 16 + + Number of orbital functions: 55 + Number of independent orbital functions: 55 + + Extrapolation method: initial_guess + + + SCF WAVEFUNCTION OPTIMIZATION + + Step Update method Time Convergence Total energy Change + ------------------------------------------------------------------------------ + 1 Broy./Diag. 0.30E+00 0.6 0.10201057 -65.9858929222 -6.60E+01 + 2 Broy./Diag. 0.30E+00 0.9 0.00690827 -66.0040038434 -1.81E-02 + 3 Broy./Diag. 0.30E+00 0.9 0.00557996 -65.9943182937 9.69E-03 + 4 Broy./Diag. 0.30E+00 0.9 0.00153829 -65.9875747545 6.74E-03 + 5 Broy./Diag. 0.30E+00 0.9 0.00004035 -65.9863085923 1.27E-03 + + *** SCF run converged in 5 steps *** + + + Electronic density on regular grids: -32.0000072648 -0.0000072648 + Core density on regular grids: 31.9999994863 -0.0000005137 + Total charge density on r-space grids: -0.0000077785 + Total charge density g-space grids: -0.0000077785 + + Overlap energy of the core charge distribution: 0.00000000000000 + Self energy of the core charge distribution: -138.89582544120611 + Core Hamiltonian energy: 27.20749465766189 + Hartree energy: 56.71104695531949 + Exchange-correlation energy: -11.00902476407980 + + Total energy: -65.98630859230452 + + ENERGY| Total FORCE_EVAL ( QS ) energy [a.u.]: -65.987107673981797 + + -------- Informations at step = 2 ------------ + Optimization Method = BFGS + Total Energy = -65.9871076740 + Internal Pressure [bar] = 89.8303996860 + Real energy change = -0.0000426184 + Predicted change in energy = -0.0000464395 + Scaling factor = 0.0000000000 + Step size = 0.0555865836 + Trust radius = 0.4724315332 + Decrease in energy = YES + Used time = 7.038 + + Convergence check : + Max. step size = 0.0555865836 + Conv. limit for step size = 0.0100000000 + Convergence in step size = NO + RMS step size = 0.0209591157 + Conv. limit for RMS step = 0.0100000000 + Convergence in RMS step = NO + Max. gradient = 0.0000692491 + Conv. limit for gradients = 0.0100000000 + Conv. in gradients = YES + RMS gradient = 0.0000352224 + Conv. limit for RMS grad. = 0.0500000000 + Conv. in RMS gradients = YES + Pressure Deviation [bar] = 122.6836850078 + Pressure Tolerance [bar] = 100.0000000000 + Conv. for PRESSURE = NO + --------------------------------------------------- + + -------------------------- + OPTIMIZATION STEP: 3 + -------------------------- + + CELL| Volume [angstrom^3]: 207.386966 + CELL| Vector a [angstrom]: 6.637 0.000 0.000 |a| = 6.637017 + CELL| Vector b [angstrom]: 3.306 5.755 0.000 |b| = 6.637262 + CELL| Vector c [angstrom]: 3.306 1.909 5.429 |c| = 6.637274 + CELL| Angle (b,c), alpha [degree]: 60.164238 + CELL| Angle (a,c), beta [degree]: 60.123286 + CELL| Angle (a,b), gamma [degree]: 60.123227 + CELL| Numerically orthorhombic: NO + + Number of electrons: 32 + Number of occupied orbitals: 16 + Number of molecular orbitals: 16 + + Number of orbital functions: 55 + Number of independent orbital functions: 55 + + Extrapolation method: initial_guess + + + SCF WAVEFUNCTION OPTIMIZATION + + Step Update method Time Convergence Total energy Change + ------------------------------------------------------------------------------ + 1 Broy./Diag. 0.30E+00 0.6 0.03949174 -65.9870656651 -6.60E+01 + 2 Broy./Diag. 0.30E+00 0.9 0.00018643 -65.9878339434 -7.68E-04 + 3 Broy./Diag. 0.30E+00 0.9 0.00016090 -65.9874134035 4.21E-04 + 4 Broy./Diag. 0.30E+00 0.9 0.00005462 -65.9871352547 2.78E-04 + + *** SCF run converged in 4 steps *** + + + Electronic density on regular grids: -32.0000195923 -0.0000195923 + Core density on regular grids: 31.9999994859 -0.0000005141 + Total charge density on r-space grids: -0.0000201064 + Total charge density g-space grids: -0.0000201064 + + Overlap energy of the core charge distribution: 0.00000000000000 + Self energy of the core charge distribution: -138.89582544120611 + Core Hamiltonian energy: 27.20670706730761 + Hartree energy: 56.71083177759095 + Exchange-correlation energy: -11.00884865841195 + + Total energy: -65.98713525471950 + + ENERGY| Total FORCE_EVAL ( QS ) energy [a.u.]: -65.987107704050743 + + -------- Informations at step = 3 ------------ + Optimization Method = BFGS + Total Energy = -65.9871077041 + Internal Pressure [bar] = 48.7985876322 + Real energy change = -0.0000000301 + Predicted change in energy = -0.0000000603 + Scaling factor = 0.0000000000 + Step size = 0.0018122576 + Trust radius = 0.4724315332 + Decrease in energy = YES + Used time = 6.043 + + Convergence check : + Max. step size = 0.0018122576 + Conv. limit for step size = 0.0100000000 + Convergence in step size = YES + RMS step size = 0.0006979853 + Conv. limit for RMS step = 0.0100000000 + Convergence in RMS step = YES + Max. gradient = 0.0000646603 + Conv. limit for gradients = 0.0100000000 + Conv. in gradients = YES + RMS gradient = 0.0000350991 + Conv. limit for RMS grad. = 0.0500000000 + Conv. in RMS gradients = YES + Pressure Deviation [bar] = 81.6518729540 + Pressure Tolerance [bar] = 100.0000000000 + Conv. for PRESSURE = YES + --------------------------------------------------- + + ******************************************************************************* + *** GEOMETRY OPTIMIZATION COMPLETED *** + ******************************************************************************* + + Reevaluating energy at the minimum + + CELL| Volume [angstrom^3]: 207.386966 + CELL| Vector a [angstrom]: 6.637 0.000 0.000 |a| = 6.637017 + CELL| Vector b [angstrom]: 3.306 5.755 0.000 |b| = 6.637262 + CELL| Vector c [angstrom]: 3.306 1.909 5.429 |c| = 6.637274 + CELL| Angle (b,c), alpha [degree]: 60.164238 + CELL| Angle (a,c), beta [degree]: 60.123286 + CELL| Angle (a,b), gamma [degree]: 60.123227 + CELL| Numerically orthorhombic: NO + + Number of electrons: 32 + Number of occupied orbitals: 16 + Number of molecular orbitals: 16 + + Number of orbital functions: 55 + Number of independent orbital functions: 55 + + Extrapolation method: initial_guess + + + SCF WAVEFUNCTION OPTIMIZATION + + Step Update method Time Convergence Total energy Change + ------------------------------------------------------------------------------ + 1 Broy./Diag. 0.30E+00 0.6 0.00000607 -65.9871077041 -6.60E+01 + + *** SCF run converged in 1 steps *** + + + Electronic density on regular grids: -31.9999999997 0.0000000003 + Core density on regular grids: 31.9999994859 -0.0000005141 + Total charge density on r-space grids: -0.0000005138 + Total charge density g-space grids: -0.0000005138 + + Overlap energy of the core charge distribution: 0.00000000000000 + Self energy of the core charge distribution: -138.89582544120611 + Core Hamiltonian energy: 27.20676302077408 + Hartree energy: 56.71080148590443 + Exchange-correlation energy: -11.00884676952314 + + Total energy: -65.98710770405074 + + ENERGY| Total FORCE_EVAL ( QS ) energy [a.u.]: -65.987107704050743 diff --git a/tests/outputs/geo_opt_snippet.out b/tests/outputs/geo_opt_snippet.out new file mode 100644 index 0000000..b7561cf --- /dev/null +++ b/tests/outputs/geo_opt_snippet.out @@ -0,0 +1,234 @@ + DBCSR| CPU Multiplication driver XSMM + **** **** ****** ** PROGRAM STARTED AT 2022-01-04 08:28:06.815 + + ******************************************************************************* + *** STARTING GEOMETRY OPTIMIZATION *** + *** BFGS *** + ******************************************************************************* + + Number of electrons: 2 + Number of occupied orbitals: 1 + Number of molecular orbitals: 1 + + Number of orbital functions: 10 + Number of independent orbital functions: 10 + + Extrapolation method: initial_guess + + + SCF WAVEFUNCTION OPTIMIZATION + + Step Update method Time Convergence Total energy Change + ------------------------------------------------------------------------------ + 1 P_Mix/Diag. 0.40E+00 0.0 0.58131095 -0.8981598355 -8.98E-01 + 2 P_Mix/Diag. 0.40E+00 0.0 0.34923638 -1.0032835431 -1.05E-01 + 3 P_Mix/Diag. 0.40E+00 0.0 0.20976519 -1.0663496478 -6.31E-02 + 4 P_Mix/Diag. 0.40E+00 0.0 0.12596517 -1.1041905509 -3.78E-02 + 5 P_Mix/Diag. 0.40E+00 0.0 0.07562951 -1.1268968171 -2.27E-02 + 6 DIIS/Diag. 0.53E-03 0.0 0.04542519 -1.1405215468 -1.36E-02 + 7 DIIS/Diag. 0.48E-04 0.0 0.00001007 -1.1609605153 -2.04E-02 + 8 DIIS/Diag. 0.76E-04 0.0 0.00000860 -1.1609605150 2.94E-10 + + *** SCF run converged in 8 steps *** + + + Electronic density on regular grids: -1.9999999991 0.0000000009 + Core density on regular grids: 1.9999999865 -0.0000000135 + Total charge density on r-space grids: -0.0000000126 + Total charge density g-space grids: -0.0000000126 + + Overlap energy of the core charge distribution: 0.00000060512959 + Self energy of the core charge distribution: -2.82094791773878 + Core Hamiltonian energy: 1.07883183764649 + Hartree energy: 1.30392537667707 + Exchange-correlation energy: -0.72277041674596 + + Total energy: -1.16096051503160 + + ENERGY| Total FORCE_EVAL ( QS ) energy [a.u.]: -1.160960515442514 + + -------- Informations at step = 0 ------------ + Optimization Method = BFGS + Total Energy = -1.1609605154 + Used time = 0.345 + --------------------------------------------------- + + -------------------------- + OPTIMIZATION STEP: 1 + -------------------------- + + Number of electrons: 2 + Number of occupied orbitals: 1 + Number of molecular orbitals: 1 + + Number of orbital functions: 10 + Number of independent orbital functions: 10 + + Extrapolation method: PS Nth order + Extrapolation order: 0 + + + SCF WAVEFUNCTION OPTIMIZATION + + Step Update method Time Convergence Total energy Change + ------------------------------------------------------------------------------ + 1 P_Mix/Diag. 0.40E+00 0.0 0.00061766 -1.1611751800 -1.16E+00 + 2 P_Mix/Diag. 0.40E+00 0.0 0.00038032 -1.1611771341 -1.95E-06 + 3 DIIS/Diag. 0.68E-04 0.0 0.00024387 -1.1611783375 -1.20E-06 + 4 DIIS/Diag. 0.45E-06 0.0 0.00000025 -1.1611801901 -1.85E-06 + + *** SCF run converged in 4 steps *** + + + Electronic density on regular grids: -1.9999999981 0.0000000019 + Core density on regular grids: 1.9999999854 -0.0000000146 + Total charge density on r-space grids: -0.0000000127 + Total charge density g-space grids: -0.0000000127 + + Overlap energy of the core charge distribution: 0.00000117383618 + Self energy of the core charge distribution: -2.82094791773878 + Core Hamiltonian energy: 1.08370607680208 + Hartree energy: 1.30183472840209 + Exchange-correlation energy: -0.72577425139609 + + Total energy: -1.16118019009451 + + ENERGY| Total FORCE_EVAL ( QS ) energy [a.u.]: -1.161180190094638 + + -------- Informations at step = 1 ------------ + Optimization Method = BFGS + Total Energy = -1.1611801901 + Real energy change = -0.0002196747 + Predicted change in energy = -0.0002539146 + Scaling factor = 0.0000000000 + Step size = 0.0178180522 + Trust radius = 0.4724315332 + Decrease in energy = YES + Used time = 0.184 + + Convergence check : + Max. step size = 0.0178180522 + Conv. limit for step size = 0.0030000000 + Convergence in step size = NO + RMS step size = 0.0102872569 + Conv. limit for RMS step = 0.0015000000 + Convergence in RMS step = NO + Max. gradient = 0.0022539257 + Conv. limit for gradients = 0.0004500000 + Conv. for gradients = NO + RMS gradient = 0.0013013046 + Conv. limit for RMS grad. = 0.0003000000 + Conv. for gradients = NO + --------------------------------------------------- + + -------------------------- + OPTIMIZATION STEP: 2 + -------------------------- + + Number of electrons: 2 + Number of occupied orbitals: 1 + Number of molecular orbitals: 1 + + Number of orbital functions: 10 + Number of independent orbital functions: 10 + + Extrapolation method: PS Nth order + Extrapolation order: 1 + + + SCF WAVEFUNCTION OPTIMIZATION + + Step Update method Time Convergence Total energy Change + ------------------------------------------------------------------------------ + 1 P_Mix/Diag. 0.40E+00 0.0 0.00070394 -1.1611788549 -1.16E+00 + 2 P_Mix/Diag. 0.40E+00 0.0 0.00043348 -1.1611813967 -2.54E-06 + 3 DIIS/Diag. 0.78E-04 0.0 0.00027802 -1.1611829621 -1.57E-06 + 4 DIIS/Diag. 0.54E-06 0.0 0.00000032 -1.1611853721 -2.41E-06 + + *** SCF run converged in 4 steps *** + + + Electronic density on regular grids: -1.9999999982 0.0000000018 + Core density on regular grids: 1.9999999871 -0.0000000129 + Total charge density on r-space grids: -0.0000000111 + Total charge density g-space grids: -0.0000000111 + + Overlap energy of the core charge distribution: 0.00000107320985 + Self energy of the core charge distribution: -2.82094791773878 + Core Hamiltonian energy: 1.08302261802369 + Hartree energy: 1.30210002419302 + Exchange-correlation energy: -0.72536116976372 + + Total energy: -1.16118537207594 + + ENERGY| Total FORCE_EVAL ( QS ) energy [a.u.]: -1.161185372076127 + + -------- Informations at step = 2 ------------ + Optimization Method = BFGS + Total Energy = -1.1611853721 + Real energy change = -0.0000051820 + Predicted change in energy = -0.0000054846 + Scaling factor = 0.0000000000 + Step size = 0.0024333339 + Trust radius = 0.4724315332 + Decrease in energy = YES + Used time = 0.290 + + Convergence check : + Max. step size = 0.0024333339 + Conv. limit for step size = 0.0030000000 + Convergence in step size = YES + RMS step size = 0.0014048858 + Conv. limit for RMS step = 0.0015000000 + Convergence in RMS step = YES + Max. gradient = 0.0001178849 + Conv. limit for gradients = 0.0004500000 + Conv. in gradients = YES + RMS gradient = 0.0000680609 + Conv. limit for RMS grad. = 0.0003000000 + Conv. in RMS gradients = YES + --------------------------------------------------- + + ******************************************************************************* + *** GEOMETRY OPTIMIZATION COMPLETED *** + ******************************************************************************* + + Reevaluating energy at the minimum + + Number of electrons: 2 + Number of occupied orbitals: 1 + Number of molecular orbitals: 1 + + Number of orbital functions: 10 + Number of independent orbital functions: 10 + + Extrapolation method: PS Nth order + Extrapolation order: 2 + + + SCF WAVEFUNCTION OPTIMIZATION + + Step Update method Time Convergence Total energy Change + ------------------------------------------------------------------------------ + 1 P_Mix/Diag. 0.40E+00 0.0 0.00079045 -1.1611771582 -1.16E+00 + 2 P_Mix/Diag. 0.40E+00 0.0 0.00048678 -1.1611803615 -3.20E-06 + 3 DIIS/Diag. 0.88E-04 0.0 0.00031222 -1.1611823345 -1.97E-06 + 4 DIIS/Diag. 0.53E-06 0.0 0.00000030 -1.1611853721 -3.04E-06 + + *** SCF run converged in 4 steps *** + + + Electronic density on regular grids: -1.9999999982 0.0000000018 + Core density on regular grids: 1.9999999871 -0.0000000129 + Total charge density on r-space grids: -0.0000000111 + Total charge density g-space grids: -0.0000000111 + + Overlap energy of the core charge distribution: 0.00000107320985 + Self energy of the core charge distribution: -2.82094791773878 + Core Hamiltonian energy: 1.08302280613915 + Hartree energy: 1.30209993233474 + Exchange-correlation energy: -0.72536126602091 + + Total energy: -1.16118537207595 + + ENERGY| Total FORCE_EVAL ( QS ) energy [a.u.]: -1.161185372075949 diff --git a/tests/test_optimization.py b/tests/test_optimization.py new file mode 100644 index 0000000..1abb40a --- /dev/null +++ b/tests/test_optimization.py @@ -0,0 +1,170 @@ +import pytest + +from cp2k_output_tools.levelparser import parse_all + +from . import TEST_DIR + +REF_VALUES = { + "geo": { + "opt": [ + { + "nspin": 1, + "nelec": 2, + "num_occ_orb": 1, + "num_mol_orb": 1, + "num_orb_func": 10, + "nsteps": 8, + "force_eval_energy": -1.16096052, + }, + { + "nspin": 1, + "nelec": 2, + "num_occ_orb": 1, + "num_mol_orb": 1, + "num_orb_func": 10, + "nsteps": 4, + "force_eval_energy": -1.16118019, + }, + { + "nspin": 1, + "nelec": 2, + "num_occ_orb": 1, + "num_mol_orb": 1, + "num_orb_func": 10, + "nsteps": 4, + "force_eval_energy": -1.16118537, + }, + { + "nspin": 1, + "nelec": 2, + "num_occ_orb": 1, + "num_mol_orb": 1, + "num_orb_func": 10, + "nsteps": 4, + "force_eval_energy": -1.16118537, + }, + ], + }, + "cell": { + "opt": [ + { + "nspin": 1, + "nelec": 32, + "num_occ_orb": 16, + "num_mol_orb": 16, + "num_orb_func": 55, + "nsteps": 10, + "force_eval_energy": -65.98706397, + }, + { + "nspin": 1, + "nelec": 32, + "num_occ_orb": 16, + "num_mol_orb": 16, + "num_orb_func": 55, + "nsteps": 9, + "force_eval_energy": -65.98706506, + }, + { + "nspin": 1, + "nelec": 32, + "num_occ_orb": 16, + "num_mol_orb": 16, + "num_orb_func": 55, + "nsteps": 5, + "force_eval_energy": -65.98710767, + }, + { + "nspin": 1, + "nelec": 32, + "num_occ_orb": 16, + "num_mol_orb": 16, + "num_orb_func": 55, + "nsteps": 4, + "force_eval_energy": -65.98710770, + }, + { + "nspin": 1, + "nelec": 32, + "num_occ_orb": 16, + "num_mol_orb": 16, + "num_orb_func": 55, + "nsteps": 1, + "force_eval_energy": -65.98710770, + }, + ], + "cell_infos": [ + { + "volume": 204.400073, + "numerically_orthorombic": False, + "periodicity": None, + "vectors": [[6.612, 0.0, 0.0], [3.306, 5.726, 0.000], [3.306, 1.909, 5.399]], + "vector_norms": [6.611987, 6.611987, 6.611987], + "angles": [60.0, 60.0, 60.0], + }, + { + "volume": 204.433884, + "numerically_orthorombic": False, + "periodicity": None, + "vectors": [[6.612, 0.0, 0.0], [3.306, 5.726, 0.000], [3.306, 1.909, 5.399]], + "vector_norms": [6.612271, 6.612274, 6.612274], + "angles": [60.001888, 60.001414, 60.001414], + }, + { + "volume": 207.291619, + "numerically_orthorombic": False, + "periodicity": None, + "vectors": [[6.636, 0.0, 0.0], [3.306, 5.754, 0.000], [3.306, 1.909, 5.428]], + "vector_norms": [6.636193, 6.636448, 6.636460], + "angles": [60.159492, 60.119661, 60.119604], + }, + { + "volume": 207.386966, + "numerically_orthorombic": False, + "periodicity": None, + "vectors": [[6.637, 0.0, 0.0], [3.306, 5.755, 0.000], [3.306, 1.909, 5.429]], + "vector_norms": [6.637017, 6.637262, 6.637274], + "angles": [60.164238, 60.123286, 60.123227], + }, + { + "volume": 207.386966, + "numerically_orthorombic": False, + "periodicity": None, + "vectors": [[6.637, 0.0, 0.0], [3.306, 5.755, 0.000], [3.306, 1.909, 5.429]], + "vector_norms": [6.637017, 6.637262, 6.637274], + "angles": [60.164238, 60.123286, 60.123227], + }, + ], + }, +} + + +@pytest.mark.parametrize("opt_type", ["geo", "cell"]) +def test_optimization(opt_type): + with open(TEST_DIR.joinpath(f"outputs/{opt_type}_opt_snippet.out"), "r") as fhandle: + result = parse_all(fhandle.read()) + ref = REF_VALUES[opt_type] + assert len(result.levels[0].sublevels[0].sublevels) == len(ref["opt"]) - 1 + opt_steps_scf = [step.sublevels[0] for step in result.levels[0].sublevels[0].sublevels] + for step_scf, opt_ref in zip(opt_steps_scf + [result.levels[0].sublevels[1]], ref["opt"]): + assert step_scf.converged + assert step_scf.sublevels[0].converged + assert abs(float(step_scf.force_eval_energy.magnitude) - opt_ref.pop("force_eval_energy")) < 1.0e-7 + assert step_scf.sublevels[0].nsteps == opt_ref.pop("nsteps") + for keyw, val in opt_ref.items(): + assert getattr(step_scf, keyw) == val + if opt_type == "cell": + print(result.levels[0].cell_infos) + assert len(result.levels[0].cell_infos) == len(ref["cell_infos"]) + for info, ref_info in zip(result.levels[0].cell_infos, ref["cell_infos"]): + assert abs(float(info.volume.magnitude) - ref_info.pop("volume")) < 1.0e-7 + for keyw in ["vector_norms", "angles"]: + ref0 = ref_info.pop(keyw) + for i0 in range(3): + assert abs(float(getattr(info, keyw)[i0].magnitude) - ref0[i0]) < 1.0e-7 + ref_vectors = ref_info.pop("vectors") + for i0 in range(3): + for i1 in range(3): + assert abs(float(info.vectors[i0][i1].magnitude) - ref_vectors[i0][i1]) < 1.0e-7 + for keyw, val in ref_info.items(): + assert getattr(info, keyw) == val