Skip to content

Commit

Permalink
test single-point energies with atomic units
Browse files Browse the repository at this point in the history
  • Loading branch information
berquist committed Apr 6, 2024
1 parent c4ae05a commit 9e1861b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 36 deletions.
30 changes: 6 additions & 24 deletions cclib/parser/xtbparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from datetime import timedelta
from typing import List, Optional, Tuple

from cclib.parser import logfileparser, utils
from cclib.parser import logfileparser
from cclib.parser.logfilewrapper import FileWrapper

import numpy as np
Expand Down Expand Up @@ -359,9 +359,7 @@ def _extract_final_energy(line: str) -> Optional[float]:
| HOMO-LUMO GAP 14.381252816459 eV |
-------------------------------------------------
"""
return (
utils.convertor(float(line.split()[3]), "hartree", "eV") if "TOTAL ENERGY" in line else None
)
return float(line.split()[3]) if "TOTAL ENERGY" in line else None


def _extract_geom_energy(line: str) -> Optional[float]:
Expand All @@ -386,11 +384,7 @@ def _extract_geom_energy(line: str) -> Optional[float]:
*** GEOMETRY OPTIMIZATION CONVERGED AFTER 1 ITERATIONS ***
"""

return (
utils.convertor(float(line.split()[4]), "hartree", "eV")
if "* total energy" in line
else None
)
return float(line.split()[4]) if "* total energy" in line else None


# TODO: Add support for POSCAR format.
Expand Down Expand Up @@ -636,22 +630,14 @@ def _extract_enthalpy(line: str) -> Optional[float]:
| HOMO-LUMO GAP 14.381259577706 eV |
-------------------------------------------------
"""
return (
utils.convertor(float(line.split()[3]), "hartree", "eV")
if "TOTAL ENTHALPY" in line
else None
)
return float(line.split()[3]) if "TOTAL ENTHALPY" in line else None


def _extract_free_energy(line: str) -> Optional[float]:
"""
Extract total free energy. See summary above.
"""
return (
utils.convertor(float(line.split()[4]), "hartree", "eV")
if "TOTAL FREE ENERGY" in line
else None
)
return float(line.split()[4]) if "TOTAL FREE ENERGY" in line else None


def _extract_zpve(line: str) -> Optional[float]:
Expand All @@ -669,11 +655,7 @@ def _extract_zpve(line: str) -> Optional[float]:
:: G(RRHO) contrib. 0.002493863951 Eh ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::
"""
return (
utils.convertor(float(line.split()[4]), "hartree", "eV")
if "zero point energy" in line
else None
)
return float(line.split()[4]) if "zero point energy" in line else None


def _extract_frequencies(line: str) -> Optional[List[float]]:
Expand Down
27 changes: 15 additions & 12 deletions test/data/testSP.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ class GenericSPTest:
# In STO-3G, H has 1, C has 5 (1 S and 4 SP).
nbasisdict = {1: 1, 6: 5}

# Approximate B3LYP energy of dvb after SCF in STO-3G.
b3lyp_energy = -10365
# Approximate B3LYP energy of dvb after SCF in STO-3G (Gaussian 16).
b3lyp_energy = -382.308266602

# Approximate energy of the innermost molecular orbital of DVB with
# B3LYP/STO-3G (from Q-Chem 5.4).
b3lyp_moenergy = -272.60365543
b3lyp_moenergy_delta = 7.55e-2
# B3LYP/STO-3G (from Q-Chem 5.4 fchk).
b3lyp_moenergy = -10.0179353
b3lyp_moenergy_delta = 2.0544595675

# Overlap first two atomic orbitals.
overlap01 = 0.24
Expand Down Expand Up @@ -582,11 +582,11 @@ def testmetadata_times(self, data) -> None:

class GenericHFSPTest(GenericSPTest):
# Approximate HF energy of dvb after SCF in STO-3G (from DALTON 2015).
hf_scfenergy = -10334.03948035995
hf_scfenergy = -379.7689629312

# Approximate energy of the innermost molecular orbital of DVB with
# HF/STO-3G (from Psi4 1.3.1).
hf_moenergy = -300.43401785663235
hf_moenergy = -11.0407466

@skipForParser("FChk", "Formatted Checkpoint files do not have a section for SCF energy")
@skipForParser("NBO", "attribute not implemented in this version")
Expand All @@ -609,8 +609,9 @@ class ADFSPTest(GenericSPTest):
foverlap11 = 1.02672
foverlap22 = 1.03585
num_scf_criteria = 2
b3lyp_energy = -140
b3lyp_moenergy = -269.6079423873336
# 2013.1/dvb_sp_b.adfout
b3lyp_energy = -5.162850967929650
b3lyp_moenergy = -9.9079095713775

def testfoverlaps(self, data) -> None:
"""Are the dims and values of the fragment orbital overlap matrix correct?"""
Expand Down Expand Up @@ -736,13 +737,14 @@ class XTBSPTest(GenericSPTest):

def testscfenergy(self, data) -> None:
"""Is the SCF energy within the target?"""
assert abs(data.scfenergies[-1] - -719.08641119) < 1.0e-6
assert abs(data.scfenergies[-1] - -26.425939358406) < 1.0e-6


class GenericDispersionTest:
"""Generic single-geometry dispersion correction unittest"""

dispersionenergy = -0.4005496
# Q-Chem 5.4
dispersionenergy = -0.0147199319

def testdispersionenergies(self, data) -> None:
"""Is the dispersion energy parsed correctly?"""
Expand All @@ -753,7 +755,8 @@ def testdispersionenergies(self, data) -> None:
class FireflyDispersionTest(GenericDispersionTest):
"""Customized single-geometry dispersion correction unittest"""

dispersionenergy = -0.4299821
# Firefly 8.1
dispersionenergy = -0.015801551434377520


class SolventMetadataTest:
Expand Down

0 comments on commit 9e1861b

Please sign in to comment.