Skip to content

Commit

Permalink
Prepare properties
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinfriede committed Jul 26, 2023
1 parent c51d16b commit 8026187
Show file tree
Hide file tree
Showing 9 changed files with 335 additions and 47 deletions.
8 changes: 4 additions & 4 deletions src/dxtb/constants/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

from . import defaults, xtb
from .chemistry import ATOMIC_NUMBER, PSE
from .torch import FLOAT32, FLOAT64, UINT8
from .units import AA2AU, AU2KCAL, CAL2J, EV2AU, K2AU
from .xtb import KA, KB, KCN, NCOORD_DEFAULT_CUTOFF, R_SHIFT
from .chemistry import *
from .getters import *
from .units import *
from .xtb import *
103 changes: 103 additions & 0 deletions src/dxtb/constants/chemistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
"""
from __future__ import annotations

import torch

__all__ = ["ATOMIC_MASSES", "ATOMIC_NUMBER", "PSE"]


PSE = {
0: "X",
1: "H",
Expand Down Expand Up @@ -126,3 +131,101 @@
}

ATOMIC_NUMBER = {sym: num for num, sym in PSE.items()}
"""Atomic symbol to atomic number."""


ATOMIC_MASSES = torch.tensor(
[
0.0, # dummy
1.00797,
4.00260,
6.941,
9.01218,
10.81,
12.011,
14.0067,
15.9994,
18.998403,
20.179,
22.98977,
24.305,
26.98154,
28.0855,
30.97376,
32.06,
35.453,
39.948,
39.0983,
40.08,
44.9559,
47.90,
50.9415,
51.996,
54.9380,
55.847,
58.9332,
58.70,
63.546,
65.38,
69.72,
72.59,
74.9216,
78.96,
79.904,
83.80,
85.4678,
87.62,
88.9059,
91.22,
92.9064,
95.94,
98.0,
101.07,
102.9055,
106.4,
107.868,
112.41,
114.82,
118.69,
121.75,
126.9045,
127.60,
131.30,
132.9054,
137.33,
138.9055,
140.12,
140.9077,
144.24,
145,
150.4,
151.96,
157.25,
158.9254,
162.50,
164.9304,
167.26,
168.9342,
173.04,
174.967,
178.49,
180.9479,
183.85,
186.207,
190.2,
192.22,
195.09,
196.9665,
200.59,
204.37,
207.2,
208.9804,
209,
210,
222,
]
)
"""
Isotope-averaged atom masses in g/mol from
https://www.angelo.edu/faculty/kboudrea/periodic/structure_mass.htm
"""
44 changes: 44 additions & 0 deletions src/dxtb/constants/getters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""
Getter functions for constants
==============================
This module only contains some convenience functions for collecting constants.
"""
from __future__ import annotations

import torch

from .._types import Tensor
from .chemistry import ATOMIC_MASSES
from .defaults import TORCH_DTYPE
from .units import GMOL2AU

__all__ = ["get_atomic_masses"]


def get_atomic_masses(
numbers: Tensor,
atomic_units: bool = True,
device: torch.device | None = None,
dtype: torch.dtype = TORCH_DTYPE,
) -> Tensor:
"""
Get isotope-averaged atomic masses for all `numbers`.
Parameters
----------
numbers : Tensor
Atomic numbers in the system.
atomic_units : bool, optional
Flag for unit conversion. If `True` (default), the atomic masses will
be returned in atomic units. If `False`, the unit remains g/mol.
device : torch.device | None, optional
Device to store the tensor. If `None` (default), the default device is used.
dtype : torch.dtype, optional
Data type of the tensor. If none is given, it defaults to float32.
Returns
-------
Tensor
Atomic masses.
"""
m = ATOMIC_MASSES[numbers].to(device).type(dtype)
return m * GMOL2AU if atomic_units is True else m
27 changes: 0 additions & 27 deletions src/dxtb/constants/torch.py

This file was deleted.

130 changes: 123 additions & 7 deletions src/dxtb/constants/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,66 @@
Unit conversion factors.
"""

AA2AU = 1.8897261246204404
"""Factor for conversion from angstrom to atomic units."""
from scipy.constants import physical_constants


def get_constant(constant_name: str) -> float:
if constant_name not in physical_constants:
raise KeyError(f"Constant '{constant_name}' not found.")
return physical_constants[constant_name][0]


class CODATA:
"""CODATA values for various physical constants"""

h = get_constant("Planck constant")
"""Planck's constant"""

c = get_constant("speed of light in vacuum")
"""Speed of light in vacuum (m/s)"""

kb = get_constant("Boltzmann constant")
"""Boltzmann's constant"""

na = get_constant("Avogadro constant")
"""Avogadro's number (mol^-1)"""

e = get_constant("elementary charge")
"""Elementary charge"""

alpha = get_constant("fine-structure constant")
"""Fine structure constant (CODATA2018)"""

me = get_constant("electron mass")
"""Rest mass of the electron (kg)"""

bohr = get_constant("Bohr radius")
"""Bohr radius (m)"""


PI = 3.1415926535897932384626433832795029

# LENGTH

AU2METER = CODATA.bohr
"""
Conversion from bohr (a.u.) to meter.
This equals: 1 bohr = 5.29177210903e-11 m.
"""

METER2AU = 1.0 / AU2METER
"""Conversion from meter to atomic units."""

AA2METER = 1e-10
"""Factor for conversion from Angstrom to meter (1e-10)."""

AA2AU = AA2METER * METER2AU
"""
Factor for conversion from angstrom to atomic units.
This equals: 1 Angstrom = 1.8897261246204404 a.u.
"""

# ENERGY

EV2AU = 1.0 / 27.21138505
"""Factor for conversion from eletronvolt to atomic units."""
Expand All @@ -17,11 +75,69 @@
CAL2J = 4.184
"""Factor for conversion from Calorie to Joule"""

C2AU = 1.0 / 1.60217653e-19
"""Factor for conversion from Coulomb to to atomic units"""
AU2COULOMB = CODATA.e
"""
Factor for conversion from atomic units to Coulomb.
This equals the elementary charge.
"""

COULOMB2AU = 1.0 / AU2COULOMB
"""Factor for conversion from Coulomb to atomic units."""

AU2JOULE = get_constant("atomic unit of energy")
"""Factor for conversion from atomic units to Joule (J = kg·m²·s⁻²)."""

J2AU = 1.0 / 4.3597441775e-18
"""Factor for conversion from Joule to atomic units"""
JOULE2AU = 1.0 / AU2JOULE
"""
Factor for conversion from Joule (J = kg·m²·s⁻²) to atomic units.
This equals: 1 Joule = 2.294e+17 Hartree.
Could also be calculated as: CODATA.me * CODATA.c**2 * CODATA.alpha**2
"""

VAA2AU = J2AU / (C2AU * AA2AU)
VAA2AU = JOULE2AU / (COULOMB2AU * AA2AU)
"""Factor for conversion from V/Å = J/(C·Å) to atomic units"""


AU_KG = CODATA.me
KG_AU = 1.0 / AU_KG

AMU_KG = get_constant("unified atomic mass unit")
KG_AMU = 1.0 / AMU_KG

AMU_AU = AMU_KG * KG_AU
AU_AMU = AU_KG * KG_AU


AU2GMOL = 1e3 * CODATA.me * CODATA.na
"""Electron mass (a.u.) to molecular mass per mole (g/mol)"""

GMOL2AU = 1.0 / AU2GMOL
"""Molecular mass per mole (g/mol) to electron mass (a.u.)"""


AU2RCM = AU2JOULE / (CODATA.h * CODATA.c) * 1e-2
"""Conversion from hartree to reciprocal centimeters"""

RCM2AU = 1.0 / AU2RCM
"""Conversion from reciprocal centimeters to hartree"""


DEBYE2AU = 1e-21 / CODATA.c * COULOMB2AU * METER2AU
"""
Conversion from Debye to atomic units.
This equals: 1 Debye in SI units (C m) = 0.393430 a.u.
"""

AU2DEBYE = 1.0 / DEBYE2AU
"""Conversion from atomic units to Debye."""

AMU = 5.485799090649e-4
AU2KMMOL = (DEBYE2AU / AA2AU) ** 2 / AMU * 42.256

# TIME

AU2SECOND = get_constant("atomic unit of time")
"""Conversion from atomic units to second. Atomic unit of time (s)."""

SECOND2AU = 1.0 / AU2SECOND
"""Conversion from second to atomic units."""
11 changes: 6 additions & 5 deletions src/dxtb/coulomb/secondorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@
from ..utils import batch, cdist, real_pairs
from .average import AveragingFunction, averaging_function, harmonic_average

__all__ = ["ES2", "new_es2"]
__all__ = ["ES2", "LABEL_ES2", "new_es2"]


LABEL_ES2 = "ES2"
"""Label for the 'ES2' interaction, coinciding with the class name."""


class ES2(Interaction):
Expand Down Expand Up @@ -156,10 +160,7 @@ def __init__(
self.shell_resolved = shell_resolved and lhubbard is not None

def get_cache(
self,
numbers: Tensor,
positions: Tensor,
ihelp: IndexHelper,
self, numbers: Tensor, positions: Tensor, ihelp: IndexHelper
) -> ES2.Cache:
"""
Obtain the cache object containing the Coulomb matrix.
Expand Down
6 changes: 5 additions & 1 deletion src/dxtb/coulomb/thirdorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@
from ..interaction import Interaction
from ..param import Param, get_elem_param

__all__ = ["ES3", "new_es3"]
__all__ = ["ES3", "LABEL_ES3", "new_es3"]


LABEL_ES3 = "ES3"
"""Label for the 'ES3' interaction, coinciding with the class name."""


class ES3(Interaction):
Expand Down
Loading

0 comments on commit 8026187

Please sign in to comment.