| 1 |
#!/usr/bin/python |
| 2 |
|
| 3 |
"""Vibrational frequency scaling factors from the Truhlar group database. |
| 4 |
|
| 5 |
Frequency scaling factors taken from version 5 of the Truhlar group database |
| 6 |
(https://comp.chem.umn.edu/freqscale/). |
| 7 |
|
| 8 |
Alecu, I. M.; Zheng, J.; Zhao, Y.; Truhlar, D. G. J. Chem. Theory Comput. |
| 9 |
2010, 6, 2872-2887. |
| 10 |
|
| 11 |
The data is stored in scaling_factors.json alongside this module. Each entry |
| 12 |
contains scaling factors for ZPEs, harmonic frequencies, and fundamentals. |
| 13 |
|
| 14 |
Methods: |
| 15 |
D: Directly obtained from the ZPVE15/10 or F38/10 databases (Ref. 1). |
| 16 |
C: Obtained by applying a systematic correction of -0.0025 to preexisting |
| 17 |
scale factor. |
| 18 |
R: Obtained via the Reduced Scale Factor Optimization Model (Ref. 1). |
| 19 |
|
| 20 |
Public API: |
| 21 |
scaling_data_dict -- dict mapping canonicalized level/basis -> ScalingData |
| 22 |
scaling_refs -- list of reference citation strings |
| 23 |
ScalingData -- namedtuple for scaling factor data |
| 24 |
canonicalize_level -- normalize level/basis strings for lookup |
| 25 |
FUNCTIONAL_ALIASES -- dict of known functional name aliases |
| 26 |
""" |
| 27 |
|
| 28 |
import json |
| 29 |
import os |
| 30 |
from collections import namedtuple |
| 31 |
|
| 32 |
ScalingData = namedtuple("ScalingData", [ |
| 33 |
'level_basis', 'zpe_fac', 'zpe_ref', 'zpe_meth', |
| 34 |
'harm_fac', 'harm_ref', 'harm_meth', |
| 35 |
'fund_fac', 'fund_ref', 'fund_meth', |
| 36 |
]) |
| 37 |
|
| 38 |
# Maps non-canonical functional names to the canonical name used in the |
| 39 |
# database. All keys must be UPPERCASE. This handles differences between |
| 40 |
# quantum chemistry programs (e.g. Gaussian's PBE1PBE vs ORCA's PBE0). |
| 41 |
FUNCTIONAL_ALIASES = { |
| 42 |
# Gaussian uses PBE1PBE internally; database has PBE0 |
| 43 |
"PBE1PBE": "PBE0", |
| 44 |
# Gaussian archive PBEPBE -> PBE (the pure GGA) |
| 45 |
"PBEPBE": "PBE", |
| 46 |
# HSE06 is the same as HSEh1PBE |
| 47 |
"HSE06": "HSEH1PBE", |
| 48 |
# Minnesota functionals: ORCA uses hyphens, database does not |
| 49 |
"M06-2X": "M062X", |
| 50 |
"M06-L": "M06L", |
| 51 |
"M06-HF": "M06HF", |
| 52 |
"M05-2X": "M052X", |
| 53 |
"M08-HX": "M08HX", |
| 54 |
"M08-SO": "M08SO", |
| 55 |
# omega-B97 variants: database has wB97XD (no hyphen) |
| 56 |
"WB97X-D": "WB97XD", |
| 57 |
"WB97X-D3": "WB97XD", |
| 58 |
"WB97XD3": "WB97XD", |
| 59 |
# B97-3 -> B973 |
| 60 |
"B97-3": "B973", |
| 61 |
# CAM-B3LYP without hyphen |
| 62 |
"CAMB3LYP": "CAM-B3LYP", |
| 63 |
"TPSS": "TPSSTPSS", # Database uses TPSS/TPSS for the meta-GGA, so canonicalize to match |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
def canonicalize_level(level_basis): |
| 68 |
""" |
| 69 |
Normalize a level/basis string to a canonical form suitable for dictionary lookup. |
| 70 |
|
| 71 |
Parameters: |
| 72 |
level_basis (str): Level and optional basis separated by '/', e.g. "b3lyp/6-31g*". |
| 73 |
|
| 74 |
Returns: |
| 75 |
str: Canonicalized "FUNCTIONAL" or "FUNCTIONAL/BASIS" string where the functional name has been normalized (aliases resolved and case-normalized) and formatted for consistent lookup. |
| 76 |
""" |
| 77 |
s = level_basis.strip().upper() |
| 78 |
if '/' in s: |
| 79 |
functional, basis = s.split('/', 1) |
| 80 |
else: |
| 81 |
functional = s |
| 82 |
basis = None |
| 83 |
functional = FUNCTIONAL_ALIASES.get(functional, functional) |
| 84 |
if basis is not None: |
| 85 |
return functional + '/' + basis |
| 86 |
return functional |
| 87 |
|
| 88 |
|
| 89 |
def _load_scaling_data(): |
| 90 |
""" |
| 91 |
Load scaling-factor references and a mapping of canonicalized level/basis strings to ScalingData from the module's scaling_factors.json. |
| 92 |
|
| 93 |
Returns: |
| 94 |
refs (list[str]): Reference citation strings extracted from the JSON file. |
| 95 |
entries (dict[str, ScalingData]): Mapping from canonicalized `LEVEL/BASIS` keys to `ScalingData` instances built from each JSON entry. |
| 96 |
""" |
| 97 |
json_path = os.path.join(os.path.dirname(__file__), 'scaling_factors.json') |
| 98 |
with open(json_path, 'r') as f: |
| 99 |
data = json.load(f) |
| 100 |
|
| 101 |
refs = data['references'] |
| 102 |
entries = {} |
| 103 |
for entry in data['entries']: |
| 104 |
sd = ScalingData( |
| 105 |
level_basis=entry['level_basis'], |
| 106 |
zpe_fac=entry['zpe_fac'], |
| 107 |
zpe_ref=entry['zpe_ref'], |
| 108 |
zpe_meth=entry['zpe_meth'], |
| 109 |
harm_fac=entry['harm_fac'], |
| 110 |
harm_ref=entry['harm_ref'], |
| 111 |
harm_meth=entry['harm_meth'], |
| 112 |
fund_fac=entry['fund_fac'], |
| 113 |
fund_ref=entry['fund_ref'], |
| 114 |
fund_meth=entry['fund_meth'], |
| 115 |
) |
| 116 |
key = canonicalize_level(entry['level_basis']) |
| 117 |
entries[key] = sd |
| 118 |
|
| 119 |
return refs, entries |
| 120 |
|
| 121 |
|
| 122 |
scaling_refs, scaling_data_dict = _load_scaling_data() |