PhysicalConstant

class sisl.constant.PhysicalConstant

Bases: float

Class to create a physical constant with unit-conversion capability, works exactly like a float.

To change the units simply call it like a method with the desired unit:

>>> m = PhysicalConstant(1., 'm')
>>> m.unit
'm'
>>> m2nm = m('nm')
>>> m2nm
1000000000.0 nm
>>> m2nm.unit
'nm'
>>> m2nm * 2
1000000000.0

Attributes

__doc__

__module__

__slots__

_unit

imag

the imaginary part of a complex number

real

the real part of a complex number

unit

Unit of constant

Methods

__abs__

abs(self)

__add__

Return self+value.

__bool__

self != 0

__call__([unit])

Return the value for the constant in the given unit, otherwise will return the units in SI units

__delattr__

Implement delattr(self, name).

__dir__

Default dir() implementation.

__divmod__

Return divmod(self, value).

__eq__

Return self==value.

__float__

float(self)

__floordiv__

Return self//value.

__format__

Formats the float according to format_spec.

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__getformat__

You probably don’t want to use this function.

__getnewargs__

__gt__

Return self>value.

__hash__

Return hash(self).

__init__

Initialize self.

__init_subclass__

This method is called when a class is subclassed.

__int__

int(self)

__le__

Return self<=value.

__lt__

Return self<value.

__mod__

Return self%value.

__mul__

Return self*value.

__ne__

Return self!=value.

__neg__

-self

__new__(cls, value, unit)

Create and return a new object.

__pos__

+self

__pow__

Return pow(self, value, mod).

__radd__

Return value+self.

__rdivmod__

Return divmod(value, self).

__reduce__

Helper for pickle.

__reduce_ex__

Helper for pickle.

__repr__

Return repr(self).

__rfloordiv__

Return value//self.

__rmod__

Return value%self.

__rmul__

Return value*self.

__round__

Return the Integral closest to x, rounding half toward even.

__rpow__

Return pow(value, self, mod).

__rsub__

Return value-self.

__rtruediv__

Return value/self.

__set_format__

You probably don’t want to use this function.

__setattr__

Implement setattr(self, name, value).

__sizeof__

Size of object in memory, in bytes.

__str__()

Return str(self).

__sub__

Return self-value.

__subclasshook__

Abstract classes can override this to customize issubclass().

__truediv__

Return self/value.

__trunc__

Return the Integral closest to x between 0 and x.

as_integer_ratio

Return integer ratio.

conjugate

Return self, the complex conjugate of any float.

fromhex

Create a floating-point number from a hexadecimal string.

hex

Return a hexadecimal representation of a floating-point number.

is_integer

Return True if the float is an integer.

as_integer_ratio()

Return integer ratio.

Return a pair of integers, whose ratio is exactly equal to the original float and with a positive denominator.

Raise OverflowError on infinities and a ValueError on NaNs.

>>> (10.0).as_integer_ratio()
(10, 1)
>>> (0.0).as_integer_ratio()
(0, 1)
>>> (-.25).as_integer_ratio()
(-1, 4)
conjugate()

Return self, the complex conjugate of any float.

fromhex()

Create a floating-point number from a hexadecimal string.

>>> float.fromhex('0x1.ffffp10')
2047.984375
>>> float.fromhex('-0x1p-1074')
-5e-324
hex()

Return a hexadecimal representation of a floating-point number.

>>> (-0.1).hex()
'-0x1.999999999999ap-4'
>>> 3.14159.hex()
'0x1.921f9f01b866ep+1'
imag

the imaginary part of a complex number

is_integer()

Return True if the float is an integer.

real

the real part of a complex number

property unit

Unit of constant