gpridge.dimer ============= .. py:module:: gpridge.dimer .. autoapi-nested-parse:: GPDimer driver: atoms + oracle + a GP. Symmetric to GPNEB: the GP is supplied (not constructed) so it can be shared / warm-started across the NEB->Dimer pipeline. Classes ------- .. autoapisummary:: gpridge.dimer.GPDimer Package Contents ---------------- .. py:class:: GPDimer(atoms, *, oracle, gp, orient: Optional[numpy.ndarray] = None, seed: int = 42, verbose: bool = True, model_profile: Any = None, logfile: Any = None, trajectory: Any = None, convergence_force_norm: Any = None, init_data=None, vibrational_stencil: str = 'full') Bases: :py:obj:`gpridge._observers.ObservableDriver` GP-accelerated dimer search for a first-order saddle point. The search runs in C++ (``AtomicDimer``) on the Gaussian-process surrogate held by ``gp``. The ``oracle`` calculator is called only to measure the true energy and forces, and :attr:`oracle_calls` counts those calls. The constructor copies ``atoms``; the result is in :attr:`atoms` after :meth:`run`. :param atoms: Start geometry. A cold start can be any structure near the saddle point. A warm start from a GP-NEB run passes the climbing image. Only :class:`ase.constraints.FixAtoms` is supported: any other constraint raises ``ValueError``, and so does a start in which every atom is fixed. Fixed atoms keep their input coordinates exactly. :type atoms: :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. If it is already fit (for example after a GPNEB run), the dimer skips the cold-start fit and starts from its observations and hyperparameters. :type gp: :py:class:`gpridge.gp.GaussianProcess` :param orient: Initial dimer orientation, shape ``(n_atoms, 3)``. Rows of fixed atoms are ignored. The default is a random direction over the moving atoms, drawn from ``seed`` and scaled to norm 0.01. :type orient: :py:class:`numpy.ndarray`, *optional* :param seed: Seed of the random generator that draws the default orientation. :type seed: :py:class:`int`, *default* ``42`` :param verbose: Selects the C++ report level, 1 for ``True`` and 0 for ``False``. The report goes to standard error, and level 0 writes none of it. The one-shot diagnostics that the library prints with ``fprintf`` (the ``[hssvd]`` conditioning line) are not part of that report. :type verbose: :py:class:`bool`, *default* :py:obj:`True` :param vibrational_stencil: Coordinates the force-stop stencil displaces. ``"full"`` measures every Cartesian coordinate. ``"vibrational"`` measures only the vibrational directions and can call a borderline mode resolved where ``"full"`` calls it unresolved. A lone atom is measured in every coordinate either way. :type vibrational_stencil: ``{"full", "vibrational"}``, *default* ``"full"`` :param convergence_force_norm: Norm of the midpoint force that ``fmax`` is compared with. The default ``None`` keeps the L2 norm of the whole force vector. ``"linf"`` is the largest absolute component and ``"max_force_on_atom"`` the largest per-atom force magnitude. A :class:`~gpridge._core.ConvergenceNorm` member is accepted too. :type convergence_force_norm: ``{"l2", "linf", "max_force_on_atom"}``, *optional* :param model_profile: Forwarded to the dimer's GP with ``set_model_profile``. The default ``None`` keeps the library profile. ``"gprd_zbl"`` is the profile the Baker-24 board runs use. :type model_profile: :py:class:`str` or :py:class:`~gpridge._core.GPModelProfile` or :py:obj:`None` :param logfile: One line per oracle call, as an ASE optimizer logs its steps. A string or path-like object is a file name and ``"-"`` is standard output. An object with ``write`` is used as is. :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 that receives every oracle-evaluated geometry with its energy and forces, which needs the ``readcon`` package. An object with a ``write`` method may be passed instead. :type trajectory: :py:class:`str`, :py:class:`os.PathLike`, :py:class:`file-like` or :py:obj:`None` .. rubric:: Notes Energies inside the search are measured from the energy at the first oracle call, which is the start geometry. :attr:`energy_eV` is therefore relative to that level, not an absolute energy. :meth:`~gpridge._observers.ObservableDriver.attach` registers observers that run every ``interval`` oracle calls. The dimer loop runs in C++, so an oracle evaluation is the step unit; see :mod:`gpridge._observers`. .. py:attribute:: atoms Working copy of the start geometry. After :meth:`run` it holds the final midpoint geometry, without a calculator. .. py:attribute:: oracle The calculator that measures the true energy and forces. .. py:attribute:: gp The shared :class:`~gpridge.gp.GaussianProcess`. :meth:`run` adds the oracle observations to it and refits it. .. py:attribute:: seed :value: 42 .. py:attribute:: verbose :value: True .. py:attribute:: model_profile :value: None .. py:attribute:: convergence_force_norm :value: None .. py:attribute:: init_data :value: None .. py:attribute:: vibrational_stencil :value: '' .. py:attribute:: orient Initial orientation, shape ``(n_atoms, 3)``. .. py:attribute:: converged :value: False True when the true force at the final midpoint met ``fmax`` and the index stencil measured there found exactly one negative mode. A force stop the stencil does not certify reports False with :attr:`termination_reason` ``"uncertified_force_stop"``. .. py:attribute:: certified :value: False True when the index stencil at the force stop certified one negative mode. .. py:attribute:: n_certificate_calls :value: 0 True potential evaluations spent by the force-stop index stencil. .. py:attribute:: oracle_calls :value: 0 Evaluations of the true potential made by :meth:`run`. The surrogate is not counted. .. py:attribute:: outer_iterations :value: 0 Outer relaxation phases that :meth:`run` completed. .. py:attribute:: energy_eV Energy of the final midpoint in eV, relative to the energy at the first oracle call. ``nan`` until :meth:`run` has finished. .. py:attribute:: elapsed_s Wall-clock time of the C++ search in seconds. ``nan`` until :meth:`run` has finished. .. py:attribute:: termination_reason :value: 'not_run' Why the last search stopped, as a short name such as ``"force_converged"``, ``"iteration_budget"`` or ``"oracle_budget"``. ``"not_run"`` before :meth:`run`. .. py:property:: warm_started :type: bool True when the GP is fitted at the time of the call. A GP that a :class:`~gpridge.neb.GPNEB` run has fitted gives True before :meth:`run`. Read it before the search: :meth:`run` fits the GP, so the value is True afterwards for every GP. .. py:method:: run(fmax: float = 0.05, steps: int = 200, max_oracle_calls: Optional[int] = None, max_wall_seconds: Optional[float] = None) -> bool Run the dimer search until it converges or a limit is reached. The driver invokes the C++ ``AtomicDimer`` through the nanobind binding, seeds it with the observations of the shared GP, and applies the GP's layered-chain configuration to the dimer's internal model. After the search it writes the final midpoint into :attr:`atoms`, fills the result attributes and refits ``gp``. :param fmax: Force criterion in eV/Angstrom: the search stops as converged when the norm of the force on the dimer midpoint, the L2 norm unless ``convergence_force_norm`` selects another, is below it. :type fmax: :py:class:`float`, *default* ``0.05`` :param steps: Limit on the outer relaxation phases, the alternations between the surrogate and the oracle. :type steps: :py:class:`int`, *default* ``200`` :param max_oracle_calls: Limit on evaluations of the true potential, the index stencil included. The search stops before a call that would exceed it, so :attr:`oracle_calls` never ends above it. :type max_oracle_calls: :py:class:`int`, *optional* :returns: **converged** -- ``True`` when the true force criterion was met and the index stencil at that midpoint measured one negative mode. Otherwise the search hit a limit or another stopping rule, and :attr:`termination_reason` names the cause; a zero-force point that is not a saddle reports ``"uncertified_force_stop"``. :rtype: :py:class:`bool`