From e6db01dedf61327617ed50b7c784611058b31230 Mon Sep 17 00:00:00 2001 From: Matthew Welborn Date: Sun, 19 Jan 2020 13:28:22 +0100 Subject: [PATCH] Units: add atomic unit of time --- qcelemental/info/cpu_info.py | 2 +- qcelemental/physical_constants/ureg.py | 3 +++ qcelemental/tests/test_units.py | 11 +++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/qcelemental/info/cpu_info.py b/qcelemental/info/cpu_info.py index 427c5ca9..5be86d0f 100644 --- a/qcelemental/info/cpu_info.py +++ b/qcelemental/info/cpu_info.py @@ -5,8 +5,8 @@ import difflib import re from enum import Enum -from typing import List, Optional from functools import lru_cache +from typing import List, Optional from pydantic import Field diff --git a/qcelemental/physical_constants/ureg.py b/qcelemental/physical_constants/ureg.py index 3e000e7a..b82af0da 100644 --- a/qcelemental/physical_constants/ureg.py +++ b/qcelemental/physical_constants/ureg.py @@ -43,6 +43,9 @@ def build_units_registry(context): ureg.define("wavenumber = 1 / centimeter") ureg.define("Angstrom = angstrom") + # Time + ureg.define(f"au_time = {phys_const['atomic unit of time']['value']} * {phys_const['atomic unit of time']['unit']}") + # Masses ureg.define( "atomic_mass_unit = {} * kilogram = u = amu = dalton = Da".format(phys_const["atomic mass constant"]["value"]) diff --git a/qcelemental/tests/test_units.py b/qcelemental/tests/test_units.py index 0b19334b..b1cabbfb 100644 --- a/qcelemental/tests/test_units.py +++ b/qcelemental/tests/test_units.py @@ -78,3 +78,14 @@ def test_quantities_smoke(): Smoke test to ensure Quantities are correctly returned """ assert 5 == qcelemental.constants.Quantity("5 kcal").magnitude + + +def test_speed_of_light(): + assert ( + pytest.approx( + qcelemental.constants.speed_of_light_in_vacuum + * qcelemental.constants.conversion_factor("m/s", "bohr/au_time"), + 1e-8, + ) + == qcelemental.constants.c_au + )