I want to define a system programmitcally. For example, once I define
"real": Units(
mass="g/mol",
distance="angstrom",
time="fs",
energy="kcal/mol",
charge="e",
velocity="angstrom/fs",
force="kcal/(mol*angstrom)",
torque="kcal/mol",
temperature="K",
pressure="atm",
dynamic_viscosity="poise",
electric_field="V/angstrom",
density="g/cm^3"
)
I can express any value with unit in this way
boltzmann: J/K -> kcal/mol/K
How should I do?
Another related question is, if I define fundational units, such as mass, length and energy, how to convert any value with unit to reduced/lj unit?
right now my solution is:
def reduce(self, value: float, unit: str) -> float:
origin = value * self.ureg(unit)
base_unit = origin.dimensionality
if "[length]" in base_unit:
origin /= self.fdistance
if "[mass]" in base_unit:
origin /= self.fmass
if "[energy]" in base_unit:
origin /= self.fenergy
if "[time]" in base_unit:
origin *= self.ftime
return origin.to("").magnitude
where unit startswith f is convert factor:
def set_fundamental(self, mass: str, distance: str, energy: str):
self.fmass = self.ureg(mass)
self.fdistance = self.ureg(distance)
self.fenergy = self.ureg(energy)
self.ftime = (self.fenergy / (self.fmass * self.fdistance**2))**0.5
which follows the rule from https://docs.lammps.org/units.html
I think those are same question maybe with similar solution.
I dont have any idea how to do that