Source code for molfoundry.charge

[docs] class Charge: """Representation of the charge of an atom.""" def __init__(self, charge: int = 0): self._charge = charge def __int__(self) -> int: return self._charge def __str__(self) -> str: return str(self._charge) def __eq__(self, other: object) -> bool: if isinstance(other, Charge): return self._charge == other._charge if isinstance(other, int): return self._charge == other return NotImplemented def __hash__(self) -> int: # Defining ``__eq__`` otherwise makes the type unhashable; hash on the # underlying value so a Charge and the equal plain int hash alike. return hash(self._charge)