def __init__(self, Z, n, l, order=1, min_contrast=1., epsilon=1, xc='PBE'): check_valid_quantum_number(Z, n, l) self._n = n self._l = l self._order = order self._min_contrast = min_contrast self._epsilon = epsilon self._xc = xc self._bound_cache = Cache(1) self._continuum_cache = Cache(1) super().__init__(Z)
def __init__(self, inner: float = None, outer: float = None, radial_steps: float = 1., azimuthal_steps: float = None, offset: Tuple[float, float] = None, rotation: float = 0., save_file: str = None): self._inner = inner self._outer = outer self._radial_steps = radial_steps if azimuthal_steps is None: azimuthal_steps = 2 * np.pi self._azimuthal_steps = azimuthal_steps self._rotation = rotation self._offset = offset self.cache = Cache(1) self.changed = Event() super().__init__(max_detected_angle=outer, save_file=save_file)
def __init__(self, function: Callable, r: np.ndarray, max_interval, cutoff: float = None, cache_size: int = 4096, cache_key_decimals: int = 2, tolerance: float = 1e-6): self._function = function self._r = r if cutoff is None: self._cutoff = r[-1] else: self._cutoff = cutoff self._cache = Cache(cache_size) self._cache_key_decimals = cache_key_decimals self._tolerance = tolerance def f(z): return self._function( np.sqrt(self.r[0]**2 + (z * max_interval / 2 + max_interval / 2)**2)) value, error_estimate, step_size, order = integrate( f, -1, 1, self._tolerance) self._xk, self._wk = tanh_sinh_nodes_and_weights(step_size, order)
def __init__(self, transitions, atoms=None, slice_thickness=None, gpts: Union[int, Sequence[float]] = None, sampling: Union[float, Sequence[float]] = None, energy: float = None, min_contrast=.95): if isinstance(transitions, (SubshellTransitions, SubshellTransitionsArrays)): transitions = [transitions] self._slice_thickness = slice_thickness self._grid = Grid(gpts=gpts, sampling=sampling) self.atoms = atoms self._transitions = transitions self._accelerator = Accelerator(energy=energy) self._sliced_atoms = SlicedAtoms( atoms, slice_thicknesses=self._slice_thickness) self._potentials_cache = Cache(1)
def __init__(self, Z: int, bound_wave: callable, continuum_wave: callable, bound_state: Tuple[int, int], continuum_state: Tuple[int, int], energy_loss: float = 1., extent: Union[float, Sequence[float]] = None, gpts: Union[int, Sequence[float]] = None, sampling: Union[float, Sequence[float]] = None, energy: float = None): self._bound_wave = bound_wave self._continuum_wave = continuum_wave self._bound_state = bound_state self._continuum_state = continuum_state self._energy_loss = energy_loss self._cache = Cache(1) super().__init__(Z, extent, gpts, sampling, energy)
def __init__(self, potential_unit: AbstractPotential, repetitions: Tuple[int, int, int], num_frozen_phonon_configs: int = 1): self._potential_unit = potential_unit self.repetitions = repetitions self._num_frozen_phonon_configs = num_frozen_phonon_configs if (potential_unit.num_frozen_phonon_configs == 1) & (num_frozen_phonon_configs > 1): warnings.warn( '"num_frozen_phonon_configs" is greater than one, but the potential unit does not have' 'frozen phonons') if (potential_unit.num_frozen_phonon_configs > 1) & (num_frozen_phonon_configs == 1): warnings.warn( 'the potential unit has frozen phonons, but "num_frozen_phonon_configs" is set to 1' ) self._cache = Cache(1) self._changed = Event() gpts = (self._potential_unit.gpts[0] * self.repetitions[0], self._potential_unit.gpts[1] * self.repetitions[1]) extent = (self._potential_unit.extent[0] * self.repetitions[0], self._potential_unit.extent[1] * self.repetitions[1]) self._grid = Grid(extent=extent, gpts=gpts, sampling=self._potential_unit.sampling, lock_extent=True) self._grid.changed.register(self._changed.notify) self._changed.register(cache_clear_callback(self._cache)) super().__init__(precalculate=False)
def test_cache(): cache = Cache(2) with pytest.raises(KeyError): cache.retrieve('a') cache.insert('a', 'a') assert cache.retrieve('a') == 'a' cache.insert('b', 'b') assert cache.retrieve('b') == 'b' assert cache.retrieve('a') == 'a' cache.insert('c', 'c') with pytest.raises(KeyError): cache.retrieve('a') cache.clear() with pytest.raises(KeyError): cache.retrieve('b')
def __init__(self): self.cache = Cache(2) self.call_count = 0