gpridge.neb =========== .. py:module:: gpridge.neb .. autoapi-nested-parse:: GPNEB driver. Uses a ``GaussianProcess`` (does not own it). Pattern matches ``ase.mep.NEB(images, ...)``: takes a list of Atoms, exposes ``.run(fmax, steps)``, and surfaces the relaxed chain on ``.images``. The GP it consumes carries the layered-chain config; the driver itself just runs the outer loop and passes new observations back into the GP for warm-start handoff to a downstream Dimer refinement. Classes ------- .. autoapisummary:: gpridge.neb.GPNEB gpridge.neb.GPLocalBand Functions --------- .. autoapisummary:: gpridge.neb.search_local gpridge.neb.search_periodic Package Contents ---------------- .. py:class:: GPNEB(images: Sequence, *, oracle, gp, climb: bool = True, spring_constant: float = 5.0, seed: int = 42, use_idpp: bool = False, verbose: bool = True, acquisition: str = 'tpe', model_profile: Any = None, geometric_spring: bool = False, use_sidpp: bool = True, sidpp_alpha: float = 0.33, use_mmf: bool = False, rg_minmode_dimer: bool = False, rgsaddle_library: str = '', dimer_max_rot_iter: int = 0, dimer_eval_image1: bool = True, dimer_variance_tau_rel: float = 0.0, dimer_variance_tau_abs: float = 0.0, dimer_imspe_soft_threshold: float = 0.0, theta_shift_skip_tol: float = 0.0, theta_shift_skip_auto: bool = False, logfile: Any = None, trajectory: Any = None, init_data=None) Bases: :py:obj:`gpridge._observers.ObservableDriver` GP-accelerated NEB chain driver (ASE images + calculator + GP). Prefer :class:`~gpridge.session.GPNEBSession` when composing steps (interpolate / prepare / compute / apply) or overlaying pyeonclient Matter endpoints via ``GPNEBSession.from_matters``. :param images: Reactant, intermediate images and product, at least three images with the same atoms in the same order. The search starts from the geometries in ``images``, so fill the intermediate images first with :meth:`interpolate` or build the list with :meth:`from_endpoints`. The relaxed band is written back into these objects. :type images: :py:class:`sequence` of :py:class:`ase.Atoms` :param oracle: Provider of the true energy (eV) and forces (eV/Angstrom). :type oracle: :py:class:`ase.calculators.calculator.Calculator` :param gp: Shared surrogate. It holds the observations after the run, so it can be passed on to a :class:`~gpridge.dimer.GPDimer`. :type gp: :py:class:`gpridge.gp.GaussianProcess` :param climb: Let the highest image climb to the saddle point (``GPNEBConfig.climbing_image``). :type climb: :py:class:`bool`, *default* :py:obj:`True` :param spring_constant: NEB spring constant in eV/Angstrom^2. :type spring_constant: :py:class:`float`, *default* ``5.0`` :param seed: Random seed of the search. :type seed: :py:class:`int`, *default* ``42`` :param use_idpp: Lets the session seed the band with an IDPP-family path. It applies where the session builds the interior images: :meth:`interpolate` and ``from_endpoints`` or ``from_matters`` without an explicit ``method`` or ``path_method`` use ``"idpp"`` when it is ``True`` and ``"linear"`` when it is ``False``. :meth:`interpolate` with an explicit method uses that method even when it disagrees with this flag. ``from_endpoints`` still raises ``ValueError`` when an explicit ``path_method`` and this flag were both passed and they disagree: an IDPP-family name (``"idpp"``, ``"idpp_collective"``, ``"sidpp"`` or ``"sidpp_geodesic"``) with ``use_idpp=False``, or any other name with ``use_idpp=True``. The constructor takes ``images`` as given and searches that band, so ``prepare`` sets ``GPNEBConfig.use_idpp`` to ``False`` whatever this argument says. :type use_idpp: :py:class:`bool`, *default* :py:obj:`False` :param verbose: Write the C++ progress report to standard error. :type verbose: :py:class:`bool`, *default* :py:obj:`True` :param acquisition: Rule that picks the next image to measure: ``"ucb"``, ``"max_variance"``, ``"max_force"``, ``"thompson_sampling"``, ``"expected_improvement"``, ``"imspe"``, ``"tpe"`` or ``"psbax"``. Short forms such as ``"maxvar"``, ``"ts"`` and ``"ei"`` and the names of the ``AcquisitionType`` members (``"PriorityCascade"`` among them) are accepted, and an unknown name raises ``ValueError``. :type acquisition: :py:class:`str`, *default* ``"tpe"`` :param model_profile: GP model profile copied onto ``GPNEBConfig``. ``None`` keeps the library profile. Strings are ``"gprd_zbl"``, ``"chemgp"`` and ``"extended"``. :type model_profile: :py:class:`str` or :py:class:`~gpridge._core.GPModelProfile` or :py:obj:`None` :param geometric_spring: Use the geometric (cubic-potential) spring, which keeps dense bands from developing a stiff-spring instability (``GPNEBConfig.use_geometric_spring``). :type geometric_spring: :py:class:`bool`, *default* :py:obj:`False` :param use_sidpp: Forwarded to ``GPNEBConfig.use_sidpp``, the sequential-IDPP flag of the C++ path initialisation. :type use_sidpp: :py:class:`bool`, *default* :py:obj:`True` :param sidpp_alpha: Blend parameter of the sequential-IDPP path. It is used by :meth:`interpolate` and :meth:`from_endpoints` for the ``"sidpp"`` path methods and forwarded to ``GPNEBConfig.sidpp_alpha``. :type sidpp_alpha: :py:class:`float`, *default* ``0.33`` :param use_mmf: Run a minimum-mode-following dimer burst on the climbing image (``OCINEBConfig.use_mmf``, the master switch of the ``dimer_*`` options below). :type use_mmf: :py:class:`bool`, *default* :py:obj:`False` :param rg_minmode_dimer: Use the RgMinMode dimer for the climbing-image burst instead of ``AtomicDimer`` (``OCINEBConfig.rg_minmode_dimer``). :type rg_minmode_dimer: :py:class:`bool`, *default* :py:obj:`False` :param rgsaddle_library: Selection for the index test after convergence (``GPNEBConfig.rgsaddle_library``). Non-empty text turns the test on. The linked librgsaddle runs it. The empty string leaves the test off. :type rgsaddle_library: :py:class:`str`, *default* ``""`` :param dimer_max_rot_iter: Passed to ``OCINEBConfig.dimer_max_rot_iter``, the number of surrogate rotations per dimer translation in a climbing-image burst. The C++ default is 10. :type dimer_max_rot_iter: :py:class:`int`, *default* ``0`` :param dimer_eval_image1: Evaluate the forward dimer image with the oracle at each dimer phase (``OCINEBConfig.dimer_eval_image1``). :type dimer_eval_image1: :py:class:`bool`, *default* :py:obj:`True` :param dimer_variance_tau_rel: Relative variance gate for dimer oracle calls. When positive, a dimer phase whose candidate has a posterior variance below this fraction of the GP signal variance uses the GP mean instead of an oracle call. Zero disables it. :type dimer_variance_tau_rel: :py:class:`float`, *default* ``0.0`` :param dimer_variance_tau_abs: Absolute variance gate in eV^2. It takes precedence over ``dimer_variance_tau_rel`` when positive. :type dimer_variance_tau_abs: :py:class:`float`, *default* ``0.0`` :param dimer_imspe_soft_threshold: Soft gate on the IMSPE score of a dimer candidate; a score below it suppresses the oracle call. Zero disables it. :type dimer_imspe_soft_threshold: :py:class:`float`, *default* ``0.0`` :param theta_shift_skip_tol: Skip the hyperparameter optimisation when the scale-free MAP stationarity measure at the current parameters is below this tolerance. Zero disables the gate. :type theta_shift_skip_tol: :py:class:`float`, *default* ``0.0`` :param theta_shift_skip_auto: Use the GP optimiser's displacement tolerance as the stationarity threshold. :type theta_shift_skip_auto: :py:class:`bool`, *default* :py:obj:`False` :param logfile: One line per oracle call. A string or path-like object is a file name and ``"-"`` is standard output. :type logfile: :py:class:`str`, :py:class:`os.PathLike`, :py:class:`file-like` or :py:obj:`None` :param trajectory: A file name opens a readcon trajectory with every oracle-evaluated geometry, its energy and its forces, which needs the ``readcon`` package. An object with ``write`` may be passed instead. :type trajectory: :py:class:`str`, :py:class:`os.PathLike`, :py:class:`file-like` or :py:obj:`None` .. rubric:: Notes ``model_profile`` is forwarded to the session and then onto ``GPNEBConfig``. The Baker-24 board runs pass ``"gprd_zbl"`` and ``acquisition="max_variance"``; :func:`gpridge.baker_board.production_baker_high_level_kwargs` returns those settings as a dictionary. Like an ASE optimizer, the driver takes ``logfile`` and ``trajectory`` and offers :meth:`~gpridge._observers.ObservableDriver.attach`. A step is one oracle (true potential) evaluation, because the outer loop runs in C++. Every evaluated geometry, energy and force set reaches the log, the trajectory and the attached observers:: with GPNEB(images, oracle=calc, gp=gp, logfile="-", trajectory="oracle.con") as neb: neb.attach(lambda: print(neb.last_atoms.get_potential_energy())) neb.run(fmax=0.05) .. py:attribute:: images .. py:attribute:: oracle .. py:attribute:: gp .. py:attribute:: climb :value: True .. py:attribute:: spring_constant .. py:attribute:: seed :value: 42 .. py:attribute:: use_idpp :value: False .. py:attribute:: verbose :value: True .. py:attribute:: acquisition :value: '' .. py:attribute:: model_profile :value: None .. py:attribute:: geometric_spring :value: False .. py:attribute:: use_sidpp :value: True .. py:attribute:: sidpp_alpha .. py:attribute:: use_mmf :value: False .. py:attribute:: rg_minmode_dimer :value: False .. py:attribute:: rgsaddle_library :value: '' .. py:attribute:: dimer_max_rot_iter :value: 0 .. py:attribute:: dimer_eval_image1 :value: True .. py:attribute:: dimer_variance_tau_rel .. py:attribute:: dimer_variance_tau_abs .. py:attribute:: dimer_imspe_soft_threshold .. py:attribute:: theta_shift_skip_tol .. py:attribute:: theta_shift_skip_auto :value: False .. py:attribute:: converged :value: False True when the band met the force criterion ``fmax``. .. py:attribute:: dimer_oracle_calls :value: 0 Oracle calls spent in climbing-image dimer bursts. .. py:attribute:: mmf_bursts :value: 0 Number of minimum-mode-following bursts that ran. .. py:attribute:: oracle_calls :value: 0 All oracle calls of the run. They cover the endpoints, the initial design, the outer iterations and the final validation pass. .. py:attribute:: oracle_calls_endpoints :value: 0 Oracle calls that measured the two endpoints. .. py:attribute:: oracle_calls_initial :value: 0 Oracle calls of the initial design. .. py:attribute:: oracle_calls_outer :value: 0 Oracle calls made by the outer loop. An iteration can measure more than one geometry. .. py:attribute:: oracle_calls_validation :value: 0 Oracle calls of the post-convergence validation. They re-evaluate the band and run the index certificate when it is on, and are not part of :attr:`oracle_calls_to_convergence`. .. py:attribute:: oracle_calls_to_convergence :value: 0 Oracle calls of the search itself. They cover the endpoints, the initial design and the outer iterations, without the validation pass. .. py:attribute:: outer_iterations :value: 0 Outer iterations that the run completed. .. py:attribute:: max_energy_image :value: -1 Index of the highest-energy image, counting the reactant as 0. ``-1`` before the run. .. py:attribute:: barrier_eV Forward barrier in eV, the energy of the highest image minus the energy of the reactant. ``nan`` before the run. .. py:attribute:: reverse_barrier_eV Reverse barrier in eV, the energy of the highest image minus the energy of the product. ``nan`` before the run. .. py:attribute:: certified :value: False True when the band index certificate holds. .. py:attribute:: index :value: 0 Negative-mode count of the band index certificate. .. py:attribute:: n_certificate_calls :value: 0 True oracle evaluations spent by the band index certificate. .. py:attribute:: stop_reason :value: 'not_run' Terminal stop reason of the NEB search. .. py:attribute:: max_force_history :type: List[float] :value: [] Largest band force after each outer iteration, in eV/Angstrom. .. py:attribute:: elapsed_s Wall-clock time of the C++ search in seconds. .. py:method:: from_matters(initial, final, n_intermediate: int, **kwargs) :classmethod: Construct from pyeonclient Matter endpoints. .. py:method:: from_endpoints(reactant, product, n_intermediate: int, **kwargs) :classmethod: Construct from ASE endpoints + C++ path init. .. py:property:: observers The session's :class:`~gpridge._observers.OracleObservers`. .. py:property:: n_images :type: int Number of images, endpoints included. .. py:property:: n_intermediate :type: int Number of images between the two endpoints. .. py:method:: interpolate(method: Optional[str] = None) -> None C++ path-init step (nanobind free functions). ``method=None`` uses ``"idpp"``, or ``"linear"`` when ``use_idpp`` is ``False``. An explicit method is the seed even when it disagrees with ``use_idpp``. The constructor still rejects that pair when both ``path_method`` and ``use_idpp`` were passed. .. py:method:: prepare(fmax: float = 0.05, steps: int = 200, *, max_inner_iter_gp: int = 0, inner_conv_tol: float = 0.001, lbfgs_max_move: float = 0.1, lbfgs_memory: int = 20, band_engine=None, lbfgs_inverse_curvature: float = 0.01, lbfgs_finite_difference: float = 1e-06, lbfgs_auto_scale: bool = True, lbfgs_angle_reset: bool = True, lbfgs_distance_reset: bool = True, oie_hook_reparam: bool = True, reparam_period: int = 0, reparam_tol: float = -1.0, use_ocineb: bool = True) Step: build config + oracle. The parameters are those of :meth:`GPNEBSession.prepare `. .. py:method:: compute(fmax: float = 0.05, steps: int = 200, *, max_inner_iter_gp: int = 0, inner_conv_tol: float = 0.001, lbfgs_max_move: float = 0.1, lbfgs_memory: int = 20, band_engine=None, lbfgs_inverse_curvature: float = 0.01, lbfgs_finite_difference: float = 1e-06, lbfgs_auto_scale: bool = True, lbfgs_angle_reset: bool = True, lbfgs_distance_reset: bool = True, oie_hook_reparam: bool = True, reparam_period: int = 0, reparam_tol: float = -1.0, use_ocineb: bool = True, prepared=None, apply: bool = True, fit_gp: bool = True) -> bool Step: run_ocineb and apply results (pyeonclient-style compute). ``prepared``, ``apply`` and ``fit_gp`` are described in :meth:`GPNEBSession.compute `, and the remaining parameters in :meth:`GPNEBSession.prepare `. Returns whether the band converged. .. py:method:: run(fmax: float = 0.05, steps: int = 200, *, max_inner_iter_gp: int = 0, inner_conv_tol: float = 0.001, lbfgs_max_move: float = 0.1, lbfgs_memory: int = 20, band_engine=None, lbfgs_inverse_curvature: float = 0.01, lbfgs_finite_difference: float = 1e-06, lbfgs_auto_scale: bool = True, lbfgs_angle_reset: bool = True, lbfgs_distance_reset: bool = True, oie_hook_reparam: bool = True, reparam_period: int = 0, reparam_tol: float = -1.0) -> bool Run the GP-NEB outer loop; alias of :meth:`compute`. ``fmax`` is the force tolerance of the band in eV/Angstrom and ``steps`` the outer-iteration budget. The other parameters are described in :meth:`GPNEBSession.prepare `. ``run`` always uses ``run_ocineb``. Returns whether the band converged; the results are on :attr:`converged`, :attr:`barrier_eV` and the oracle-count attributes. .. py:method:: write_con(path) -> None Write the relaxed chain as CON frames without evaluating a calculator. .. py:class:: GPLocalBand(reactant: Any, product: Any, calculator: Any, *, n_images: Optional[int] = None, spring_constant: Optional[float] = None, climb: Optional[bool] = None, max_move: Optional[float] = None, initial: str = 'linear', periodic: Optional[bool] = None, seed: Optional[int] = None, verbose: Optional[bool] = None, **options: Any) Periodic band with fixed atoms, relaxed with the local band mode. :param reactant: ASE ``Atoms`` with the same atoms in the same order and the same cell. An atom is held fixed when a ``FixAtoms`` constraint holds it in both endpoints. :param product: ASE ``Atoms`` with the same atoms in the same order and the same cell. An atom is held fixed when a ``FixAtoms`` constraint holds it in both endpoints. :param calculator: ASE calculator of the true potential (the oracle). :param n_images: Number of images between the endpoints. ``None`` selects :func:`gpridge._core.periodic_band_defaults`. :param spring_constant: Spring constant in eV/A^2; the springs are uniform. ``None`` selects the shared default. :param climb: Let the highest image climb to the saddle. ``None`` selects the shared default. :param max_move: Largest displacement of an atom in one band step, in A. ``None`` selects the shared default. :param initial: ``"linear"`` interpolates between the endpoints; ``"idpp"`` and ``"sidpp"`` start from the image-dependent pair potential path. :param seed: Random seed of the search. ``None`` selects the shared default. :param verbose: Write the C++ progress report to standard error. ``None`` selects the shared default, which is off. :param periodic: Apply the minimum image in the endpoints' cell, in the band and in every geometry handed to the calculator. ``None`` follows the endpoints' ``pbc``. :meth:`from_con` reads ``.con`` endpoints with readcon, which keeps the file's cell, periodicity and fixed atoms; ASE's eOn reader leaves ``pbc`` False for the same file. :param options: Further ``GPNEBConfig`` fields by name, for example ``gp_local_pair_cutoff``. .. py:attribute:: calculator .. py:attribute:: n_images :value: 0 .. py:attribute:: spring_constant .. py:attribute:: climb :value: False .. py:attribute:: max_move .. py:attribute:: initial :value: 'linear' .. py:attribute:: periodic .. py:attribute:: seed :value: 0 .. py:attribute:: verbose :value: False .. py:attribute:: options .. py:attribute:: images :type: List[Any] :value: [] The relaxed band as ASE ``Atoms``, endpoints included, after :meth:`run`. Empty before. .. py:attribute:: energies :type: Optional[numpy.ndarray] :value: None Energy of every image in eV, endpoints included. ``None`` before :meth:`run`. .. py:attribute:: converged :value: False True when the band met the force criterion. .. py:attribute:: oracle_calls :value: 0 All oracle calls of the run. They cover the endpoints, the initial design, the outer iterations and the final validation, which includes the index certificate when it runs. .. py:attribute:: certified :value: False True when the band index certificate holds. The certificate is off unless ``force_stop_certificate=True`` is passed as an option. .. py:attribute:: index :value: 0 Negative-mode count of the band index certificate; 0 when no certificate was stored. .. py:attribute:: n_certificate_calls :value: 0 True oracle evaluations that the index certificate spent. They are included in :attr:`oracle_calls` and not in ``result.oracle_calls_to_convergence``. .. py:attribute:: barrier :type: Optional[float] :value: None Forward barrier in eV, the energy of the highest image minus the energy of the reactant. ``None`` before :meth:`run`. .. py:attribute:: max_energy_image :type: Optional[int] :value: None Index of the highest-energy image, counting the reactant as 0. ``None`` before :meth:`run`. .. py:attribute:: result :type: Any :value: None The raw ``GPNEBResult`` of the last run. .. py:method:: from_con(reactant: Any, product: Any, calculator: Any, **kwargs: Any) -> GPLocalBand :classmethod: Band between two ``.con`` files read with readcon. The first frame of each file is the endpoint; the fixed-atom flags become ``FixAtoms`` constraints and the cell is periodic along its nonzero vectors. .. py:method:: config(fmax: float, steps: int, norm: Optional[str]) -> Any The ``GPNEBConfig`` of a run; fields in ``options`` are set last. .. py:method:: run(fmax: Optional[float] = None, steps: Optional[int] = None, norm: Optional[str] = None) -> bool Relax the band until every image meets ``fmax`` (eV/A). ``steps`` bounds the rounds, each of which measures one image. ``norm`` selects the norm of the band force that ``fmax`` bounds (``"l2"`` over the moving atoms, ``"linf"``, or ``"max_force_on_atom"``); ``None`` keeps the library's choice. ``fmax`` and ``steps`` default to the shared periodic-band record. Returns whether the band converged. .. py:function:: search_local(oracle, initial, final, n_images: int = 8, *, fmax: float = 0.05, steps: int = 50, atoms_config=None, box=None, config=None, local_config=None, gp=None, init_data=None) Run the local band, the Python binding of ``gpr_neb_search_local``. .. py:function:: search_periodic(oracle, initial, final, n_images: int = 8, *, atoms_config=None, box=None, periodic_config=None, local_config=None, gp=None, init_data=None) Run the periodic local band, the Python binding of ``gpr_neb_search_periodic``.