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))
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)
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
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))
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
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
def in_units(self, units): if not isunit(units): raise UnknownUnitError(units) return ValueWithUnits(self.value * self.units.to(units), units)