sponge.function.Units

View Source On Gitee
class sponge.function.Units(length_unit: str = None, energy_unit: str = None, **kwargs)[source]

Unit class to record and convert the length and energy units.

Parameters
  • length_unit (str) – Length unit. Default: None

  • energy_unit (str) – Energy unit. Default: None

  • kwargs – other arguments.

Supported Platforms:

Ascend GPU CPU

Examples

>>> from sponge.function import Units
>>> unit = Units(length_unit='nm', energy_unit='kj/mol')
>>> unit.convert_energy_to('kcal/mol')
0.2390057361376673
>>> unit.convert_energy_from('kcal/mol')
4.184
>>> unit.convert_length_to('A')
10.0
>>> unit.convert_length_from('A')
0.1
property acceleration_ref: float

reference value of acceleration.

Returns

float, reference value of acceleration.

property avogadro: float

Avogadro number.

Returns

float, Avogadro number.

property boltzmann: float

Boltzmann constant in current unit.

Returns

float, Boltzmann constant in current unit.

property boltzmann_def: float

Boltzmann constant in kJ/mol.

Returns

float, Boltzmann constant in kJ/mol.

convert_energy_from(unit)[source]

returns a scale factor that converts the energy from a specified unit.

Parameters

unit (Union[str, Units, Energy, float, int]) – Energy unit.

Returns

float, energy according from a specified units.

convert_energy_to(unit)[source]

returns a scale factor that converts the energy to a specified unit.

Parameters

unit (Union[str, Units, Energy, float, int]) – Energy unit.

Returns

float, energy according to a specified units.

convert_length_from(unit)[source]

returns a scale factor that converts the length from a specified unit.

Parameters

unit (Union[str, Units, Length, float, int]) – Length unit.

Returns

float, length according from a specified units.

convert_length_to(unit)[source]

returns a scale factor that converts the length to a specified unit.

Parameters

unit (Union[str, Units, Length, float, int]) – Length unit.

Returns

float, length according to a specified units.

property coulomb: float

Coulomb constant in current unit.

Returns

float, Coulomb constant in current unit.

energy(value: float, unit=None)[source]

return the energy value of the specified unit.

Parameters
Returns

float, the energy value.

property energy_ref: float

reference value of energy.

Returns

float, reference value of energy.

property energy_unit: str

energy unit.

Returns

str, length unit

property energy_unit_name: str

name of energy unit.

Returns

str, name of energy unit.

property force_ref: float

reference value of force.

Returns

float, reference value of force.

property force_unit: str

force unit.

Returns

str, force unit.

property force_unit_name: str

name of force unit.

Returns

str, name of force unit.

property gas_constant: float

gas constant.

Returns

float, gas constant.

get_boltzmann(energy_unit: str = None)[source]

get the Boltzmann constant for a specific unit

Parameters

energy_unit (str) – Energy unit. Default: None .

get_coulomb(length_unit: str = None, energy_unit: str = None)[source]

get the Coulomb constant for a specific unit

Parameters
  • length_unit (str) – Length unit. Default: None .

  • energy_unit (str) – Energy unit. Default: None .

property kinetic_ref: float

reference value of kinetic.

Returns

float, reference value of kinetic.

length(value: float, unit=None)[source]

return the length value of the specified unit.

Parameters
Returns

float, the length value.

property length_ref: float

reference value of length.

Returns

float, reference value of length.

property length_unit: str

length unit.

Returns

str, length unit

property length_unit_name: str

name of length unit.

Returns

str, name of length unit.

property pressure_ref: float

reference value of pressure.

Returns

float, reference value of pressure.

set_energy_unit(unit: str = None)[source]

set energy unit.

Parameters

unit (str) – Energy unit.

set_length_unit(unit: str = None)[source]

set length unit.

Parameters

unit (str) – Length unit.

set_units(length_unit: str = None, energy_unit: str = None, units=None)[source]

set units.

Parameters
  • length_unit (str) – Length unit. Only valid when units is None. Default: None.

  • energy_unit (str) – Energy unit. Only valid when units is None. Default: None.

  • units (Units) – Units object. Default: None.

property velocity_unit: str

velocity unit.

Returns

str, velocity unit.

property velocity_unit_name: str

name of velocity unit.

Returns

str, name of velocity unit.

property volume_unit: str

velocity unit.

Returns

str, velocity unit.

property volume_unit_name: str

velocity unit name.

Returns

str, velocity unit name.