Ejemplo n.º 1
0
 def __mul__(self, other):
     # TODO Move this to unit and CompositeUnit __rmul__
     if isunit(other):
         ret_val = copy(self)
         if self.units:
             ret_val.units = self.units * other
         else:
             ret_val.units = other
         return ret_val
     else:
         return super(Tensor, self).__mul__(other)
Ejemplo n.º 2
0
 def _init_units(self, units):
     if isinstance(units, dict):
         if self.__class__.default_delta.units.genre is CompositeUnit:
             raise NotImplementedError
         else:
             units = units[self.__class__.default_delta.units.genre]
     if type_checking_enabled:
         if not isunit(units):
             raise UnknownUnitError(units)
     if sanity_checking_enabled:
         # try to convert the default_delta's units to these
         # units to see if they are compatible:
         if self.__class__.default_delta is not None:
             self.__class__.default_delta.units.to(units)
     self._units = units
Ejemplo n.º 3
0
 def __init__(self, molecule, units=None, details=None):
     self._value = None
     self.details = details
     self.molecule = molecule
     self.getter = None
     if type_checking_enabled:
         if not isinstance(self.molecule, Molecule):
             raise TypeError("MolecularProperty initialization parameter"
                             " 'molecule' must be of type "
                             "Molecule (got {0})".format(
                                 type(molecule).__name__))
         if units is not None and not isunit(units):
             raise TypeError("MolecularProperty initialization parameter"
                             " 'units' must be a unit or None")
     self.units = units or self.default_units
Ejemplo n.º 4
0
 def __truediv__(self, other):
     if isunit(other):
         ret_val = copy(self)
         if self.units:
             ret_val.units = self.units / other
         else:
             ret_val.units = other
         return ret_val
     else:
         if hasattr(other, 'units'):
             ret_val = super(Tensor, self).__truediv__(other)
             ret_val.units = self.__div_units__(other)
             return ret_val
         else:
             return super(Tensor, self).__truediv__(other)