Esempio n. 1
0
 def _init_common(self, **kwargs):
     self.position = None
     self.parent_molecule = None
     self._cartesian_units = kwargs.pop('units', DistanceUnit.default)
     if type_checking_enabled:
         if not isunit(self.cartesian_units) or self.cartesian_units.genre is not DistanceUnit:
             raise ValueError("Invalid units for Atom constructor: {}".format(self.cartesian_units))
Esempio n. 2
0
 def __div__(self, other):
     if isinstance(other, ValueWithUnits):
         return ValueWithUnits(self.value.__div__(other.value), self.units / other.units)
     elif isunit(other):
         return ValueWithUnits(self.value, self.units / other)
     else:
         return ValueWithUnits(self.value.__div__(other), self.units)
Esempio n. 3
0
 def __div__(self, other):
     if isinstance(other, ValueWithUnits):
         return ValueWithUnits(self.value.__div__(other.value),
                               self.units / other.units)
     elif isunit(other):
         return ValueWithUnits(self.value, self.units / other)
     else:
         return ValueWithUnits(self.value.__div__(other), self.units)
Esempio n. 4
0
 def __new__(cls, value, units):
     if not isinstance(value, complex):
         ret_val = float.__new__(ValueWithUnits, value)
     else:
         # Ignore units, we've got bigger problems
         return complex.__new__(complex, value)
     if type_checking_enabled and not isunit(units):
         raise UnknownUnitError(units)
     ret_val.units = units
     return ret_val
Esempio n. 5
0
 def __new__(cls, value, units):
     if not isinstance(value, complex):
         ret_val = float.__new__(ValueWithUnits, value)
     else:
         # Ignore units, we've got bigger problems
         return complex.__new__(complex, value)
     if type_checking_enabled and not isunit(units):
         raise UnknownUnitError(units)
     ret_val.units = units
     return ret_val
Esempio n. 6
0
 def _init_common(self, **kwargs):
     self.position = None
     self.parent_molecule = None
     self._cartesian_units = kwargs.pop('units', DistanceUnit.default)
     if type_checking_enabled:
         if not isunit(self.cartesian_units
                       ) or self.cartesian_units.genre is not DistanceUnit:
             raise ValueError(
                 "Invalid units for Atom constructor: {}".format(
                     self.cartesian_units))
Esempio n. 7
0
 def get_value_for_molecule(self, property, file_contents):
     representation = self.representation_getter(file_contents,
                                                 property.molecule)
     gotten_val = self.getter(file_contents)
     tens = RepresentationDependentTensor(gotten_val,
                                          representation=representation,
                                          units=gotten_val.units)
     if isunit(property.units):
         tens = tens.in_units(property.units)
     # Now transform to the relevant representation of the molecule
     new_tens = tens.in_representation(property.representation)
     property.value = new_tens
     return property.value
Esempio n. 8
0
 def get_value_for_molecule(self, property, file_contents):
     representation = self.representation_getter(file_contents, property.molecule)
     gotten_val = self.getter(file_contents)
     tens = RepresentationDependentTensor(
         gotten_val,
         representation=representation,
         units=gotten_val.units
     )
     if isunit(property.units):
         tens = tens.in_units(property.units)
     # Now transform to the relevant representation of the molecule
     new_tens=tens.in_representation(property.representation)
     property.value = new_tens
     return property.value
Esempio n. 9
0
 def in_units(self, units):
     if not isunit(units):
         raise UnknownUnitError(units)
     return ValueWithUnits(self.value * self.units.to(units), units)
Esempio n. 10
0
 def in_units(self, units):
     if not isunit(units):
         raise UnknownUnitError(units)
     return ValueWithUnits(self.value * self.units.to(units), units)