Source code for pyH2A.Utilities.Energy_Conversion
from scipy import constants as con
[docs]class Energy:
'''Energy class to convert between different energy units.
Parameters
----------
value : float
Input energy value.
unit : function
Unit name which corresponds to the one of the functions defined
outside of the class. This function is used to convert
the input energy value to Joule.
Notes
-----
Input value in either nm, eV, kcal/mol, J/mol, kJ/mol, kWh or J.
Available units: J, eV, nm, kcal/mol, J/mol, kWh, kJ/mol.
Once an Energy class object has been generated, the energy
value in the desired unit can be retrieved using the appropriate class
attribute.
'''
def __init__(self, value, unit):
self.unit = unit.__name__
self.value = value
self.J = unit(self.value)
self.eV = self.convert_J_to_eV()
self.nm = self.convert_J_to_nm()
self.kcalmol = self.convert_J_to_kcalmol()
self.Jmol = self.convert_J_to_Jmol()
self.kWh = self.convert_J_to_kWh()
self.kJmol = self.convert_J_to_kJmol()
[docs] def convert_J_to_kcalmol(self):
'''Convert J to kcal/mol'''
return (self.J * con.Avogadro)/4186.798188
[docs] def convert_J_to_kJmol(self):
'''Convert to J to kJ/mol'''
return (self.J * con.Avogadro) / 1e3