Coverage for /builds/kinetik161/ase/ase/calculators/lammps/unitconvert.py: 100.00%
14 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-12-10 11:04 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-12-10 11:04 +0000
1"""LAMMPS has the options to use several internal units (which can be different
2from the ones used in ase). Mapping is therefore necessary.
4See: https://lammps.sandia.gov/doc/units.html
5 """
7from ase import units
9from . import unitconvert_constants as u
11# !TODO add reduced Lennard-Jones units?
13# NOTE: We assume a three-dimensional simulation here!
14DIM = 3.0
16UNITSETS = {}
18UNITSETS["ASE"] = dict(
19 mass=1.0 / units.kg,
20 distance=1.0 / units.m,
21 time=1.0 / units.second,
22 energy=1.0 / units.J,
23 velocity=units.second / units.m,
24 force=units.m / units.J,
25 pressure=1.0 / units.Pascal,
26 charge=1.0 / units.C,
27)
29UNITSETS["real"] = dict(
30 mass=u.gram_per_mole_si,
31 distance=u.angstrom_si,
32 time=u.femtosecond_si,
33 energy=u.kcal_per_mole_si,
34 velocity=u.angstrom_per_femtosecond_si,
35 force=u.kcal_per_mole_angstrom_si,
36 torque=u.kcal_per_mole_si,
37 temperature=u.kelvin_si,
38 pressure=u.atmosphere_si,
39 dynamic_viscosity=u.poise_si,
40 charge=u.e_si,
41 dipole=u.electron_angstrom_si,
42 electric_field=u.volt_per_angstrom_si,
43 density=u.gram_si / u.centimeter_si ** DIM,
44)
46UNITSETS["metal"] = dict(
47 mass=u.gram_per_mole_si,
48 distance=u.angstrom_si,
49 time=u.picosecond_si,
50 energy=u.ev_si,
51 velocity=u.angstrom_per_picosecond_si,
52 force=u.ev_per_angstrom_si,
53 torque=u.ev_si,
54 temperature=u.kelvin_si,
55 pressure=u.bar_si,
56 dynamic_viscosity=u.poise_si,
57 charge=u.e_si,
58 dipole=u.electron_angstrom_si,
59 electric_field=u.volt_per_angstrom_si,
60 density=u.gram_si / u.centimeter_si ** DIM,
61)
63UNITSETS["si"] = dict(
64 mass=u.kilogram_si,
65 distance=u.meter_si,
66 time=u.second_si,
67 energy=u.joule_si,
68 velocity=u.meter_per_second_si,
69 force=u.newton_si,
70 torque=u.joule_si,
71 temperature=u.kelvin_si,
72 pressure=u.pascal_si,
73 dynamic_viscosity=u.pascal_si * u.second_si,
74 charge=u.coulomb_si,
75 dipole=u.coulomb_meter_si,
76 electric_field=u.volt_per_meter_si,
77 density=u.kilogram_si / u.meter_si ** DIM,
78)
80UNITSETS["cgs"] = dict(
81 mass=u.gram_si,
82 distance=u.centimeter_si,
83 time=u.second_si,
84 energy=u.erg_si,
85 velocity=u.centimeter_per_second_si,
86 force=u.dyne_si,
87 torque=u.dyne_centimeter_si,
88 temperature=u.kelvin_si,
89 pressure=u.dyne_per_centimetersq_si, # or barye =u. 1.0e-6 bars
90 dynamic_viscosity=u.poise_si,
91 charge=u.statcoulomb_si, # or esu (4.8032044e-10 is a proton)
92 dipole=u.statcoulomb_centimeter_si, # =u. 10^18 debye,
93 electric_field=u.statvolt_per_centimeter_si, # or dyne / esu
94 density=u.gram_si / (u.centimeter_si ** DIM),
95)
97UNITSETS["electron"] = dict(
98 mass=u.amu_si,
99 distance=u.bohr_si,
100 time=u.femtosecond_si,
101 energy=u.hartree_si,
102 velocity=u.bohr_per_atu_si,
103 force=u.hartree_per_bohr_si,
104 temperature=u.kelvin_si,
105 pressure=u.pascal_si,
106 charge=u.e_si, # multiple of electron charge (1.0 is a proton)
107 dipole=u.debye_si,
108 electric_field=u.volt_per_centimeter_si,
109)
111UNITSETS["micro"] = dict(
112 mass=u.picogram_si,
113 distance=u.micrometer_si,
114 time=u.microsecond_si,
115 energy=u.picogram_micrometersq_per_microsecondsq_si,
116 velocity=u.micrometer_per_microsecond_si,
117 force=u.picogram_micrometer_per_microsecondsq_si,
118 torque=u.picogram_micrometersq_per_microsecondsq_si,
119 temperature=u.kelvin_si,
120 pressure=u.picogram_per_micrometer_microsecondsq_si,
121 dynamic_viscosity=u.picogram_per_micrometer_microsecond_si,
122 charge=u.picocoulomb_si, # (1.6021765e-7 is a proton),
123 dipole=u.picocoulomb_micrometer_si,
124 electric_field=u.volt_per_micrometer_si,
125 density=u.picogram_si / (u.micrometer_si) ** DIM,
126)
128UNITSETS["nano"] = dict(
129 mass=u.attogram_si,
130 distance=u.nanometer_si,
131 time=u.nanosecond_si,
132 energy=u.attogram_nanometersq_per_nanosecondsq_si,
133 velocity=u.nanometer_per_nanosecond_si,
134 force=u.attogram_nanometer_per_nanosecondsq_si,
135 torque=u.attogram_nanometersq_per_nanosecondsq_si,
136 temperature=u.kelvin_si,
137 pressure=u.attogram_per_nanometer_nanosecondsq_si,
138 dynamic_viscosity=u.attogram_per_nanometer_nanosecond_si,
139 charge=u.e_si, # multiple of electron charge (1.0 is a proton)
140 dipole=u.electron_nanometer_si,
141 electric_field=u.volt_si / u.nanometer_si,
142 density=u.attogram_si / u.nanometer_si ** DIM,
143)
146def convert(value, quantity, fromunits, tounits):
147 """Convert units between LAMMPS and ASE.
149 :param value: converted value
150 :param quantity: mass, distance, time, energy, velocity, force, torque,
151 temperature, pressure, dynamic_viscosity, charge, dipole,
152 electric_field or density
153 :param fromunits: ASE, metal, real or other (see lammps docs).
154 :param tounits: ASE, metal, real or other
155 :returns: converted value
156 :rtype:
157 """
158 return UNITSETS[fromunits][quantity] / UNITSETS[tounits][quantity] * value