IMLCV.base.bias
===============

.. py:module:: IMLCV.base.bias


Exceptions
----------

.. autoapisummary::

   IMLCV.base.bias.EnergyError
   IMLCV.base.bias.BiasError


Classes
-------

.. autoapisummary::

   IMLCV.base.bias.EnergyResult
   IMLCV.base.bias.Energy
   IMLCV.base.bias.EnergyFn
   IMLCV.base.bias.PlumedEnerg
   IMLCV.base.bias.Bias
   IMLCV.base.bias.CompositeBias
   IMLCV.base.bias.BiasModify
   IMLCV.base.bias.BiasF
   IMLCV.base.bias.NoneBias


Functions
---------

.. autoapisummary::

   IMLCV.base.bias._zero_fun
   IMLCV.base.bias._constant


Module Contents
---------------

.. py:class:: EnergyResult(*args, **kwargs)

   Bases: :py:obj:`IMLCV.base.datastructures.MyPyTreeNode`


   Base class for dataclasses that should act like a JAX pytree node.


   .. py:attribute:: energy
      :type:  jax.Array


   .. py:attribute:: gpos
      :type:  jax.Array | None


   .. py:attribute:: vtens
      :type:  jax.Array | None


   .. py:method:: __add__(other: EnergyResult) -> EnergyResult


.. py:exception:: EnergyError

   Bases: :py:obj:`Exception`


   Common base class for all non-exit exceptions.


.. py:class:: Energy

   .. py:attribute:: external_callback
      :value: True



   .. py:attribute:: manual_vtens
      :value: False



   .. py:property:: nl
      :type: IMLCV.base.CV.NeighbourList | None



   .. py:property:: cell
      :type: jax.Array | None

      :abstractmethod:



   .. py:property:: coordinates
      :type: jax.Array | None

      :abstractmethod:



   .. py:property:: sp
      :type: IMLCV.base.CV.SystemParams | None



   .. py:method:: _compute_coor(sp: IMLCV.base.CV.SystemParams, nl: IMLCV.base.CV.NeighbourList | None, gpos=False, vir=False) -> EnergyResult
      :abstractmethod:



   .. py:method:: _handle_exception(e=None)


   .. py:method:: get_vtens_finite_difference(sp: IMLCV.base.CV.SystemParams, nl: IMLCV.base.CV.NeighbourList | None, eps=1e-05, gpos=False)


   .. py:method:: compute_from_system_params(sp: IMLCV.base.CV.SystemParams, gpos=False, vir=False, nl: IMLCV.base.CV.NeighbourList | None = None, manual_vir=None, shmap=False, shmap_kwarg=ShmapKwargs.create()) -> EnergyResult


   .. py:method:: save(filename: str | pathlib.Path)


   .. py:method:: load(filename) -> Energy
      :staticmethod:



.. py:class:: EnergyFn(*args, **kwargs)

   Bases: :py:obj:`Energy`, :py:obj:`IMLCV.base.datastructures.MyPyTreeNode`


   Base class for dataclasses that should act like a JAX pytree node.


   .. py:attribute:: external_callback
      :value: False



   .. py:attribute:: f
      :type:  Callable


   .. py:attribute:: _sp
      :type:  IMLCV.base.CV.SystemParams | None
      :value: None



   .. py:attribute:: _nl
      :type:  IMLCV.base.CV.NeighbourList | None
      :value: None



   .. py:attribute:: kwargs
      :type:  dict


   .. py:attribute:: static_kwargs
      :type:  dict


   .. py:property:: nl


   .. py:property:: cell
      :type: jax.Array | None



   .. py:property:: coordinates
      :type: jax.Array | None



   .. py:property:: sp
      :type: IMLCV.base.CV.SystemParams | None



   .. py:method:: _compute_coor(sp: IMLCV.base.CV.SystemParams, nl: IMLCV.base.CV.NeighbourList | None, gpos=False, vir=False) -> EnergyResult


.. py:class:: PlumedEnerg

   Bases: :py:obj:`Energy`


.. py:exception:: BiasError

   Bases: :py:obj:`Exception`


   Common base class for all non-exit exceptions.


.. py:class:: Bias(*args, **kwargs)

   Bases: :py:obj:`abc.ABC`, :py:obj:`IMLCV.base.datastructures.MyPyTreeNode`


   base class for biased MD runs.


   .. py:attribute:: collective_variable
      :type:  IMLCV.base.CV.CollectiveVariable


   .. py:attribute:: start
      :type:  int | None


   .. py:attribute:: step
      :type:  int | None


   .. py:attribute:: finalized
      :type:  bool


   .. py:attribute:: slice_exponent
      :type:  float


   .. py:attribute:: log_exp_slice
      :type:  bool


   .. py:attribute:: slice_mean
      :type:  bool


   .. py:method:: create(*args, **kwargs)
      :staticmethod:

      :abstractmethod:



   .. py:method:: update_bias(md: IMLCV.base.MdEngine.MDEngine) -> Bias

      update the bias.

      Can only change the properties from _get_args



   .. py:method:: _update_bias() -> tuple[bool, typing_extensions.Self]

      update the bias.

      Can only change the properties from _get_args



   .. py:method:: compute_from_system_params(sp: IMLCV.base.CV.SystemParams, nl: IMLCV.base.CV.NeighbourList | None = None, gpos=False, vir=False, chunk_size: int | None = None, shmap=False, use_jac=False, push_jac=False, rel=False, shmap_kwargs=ShmapKwargs.create()) -> tuple[IMLCV.base.CV.CV, EnergyResult]

      Computes the bias, the gradient of the bias wrt the coordinates and
      the virial.



   .. py:method:: compute_from_cv(cvs: IMLCV.base.CV.CV, diff=False, chunk_size=None, shmap=False, shmap_kwargs=ShmapKwargs.create()) -> tuple[jax.Array, IMLCV.base.CV.CV | None]

      compute the energy and derivative.

      If map==False, the cvs are assumed to be already mapped



   .. py:method:: _compute(cvs) -> jax.Array
      :abstractmethod:


      function that calculates the bias potential.



   .. py:method:: plot(name: str | None = None, traj: list[IMLCV.base.CV.CV] | None = None, dlo_kwargs=None, dlo=None, vmax=100 * kjmol, map=False, inverted=False, margin=0.1, dpi=300, T=300 * kelvin, **kwargs)


   .. py:method:: resample(cv_grid: IMLCV.base.CV.CV | None = None, n=40, margin=0.3) -> Bias


   .. py:method:: save(filename: str | pathlib.Path, cv_file: pathlib.Path | None = None)


   .. py:method:: load(filename) -> Bias
      :staticmethod:



   .. py:method:: __getstate__()


   .. py:method:: __setstate__(statedict: dict)


   .. py:method:: bounds_from_bias(T, sign=1.0, margin=1e-10, n=50)


   .. py:method:: kl_divergence(other: Bias, T: float, symmetric=True, margin=0.2, sign=1.0, n=100)


   .. py:method:: slice(T, inverted=True, vmax=None, n_max_bias=100000.0, margin=0.2, macro_chunk=10000, offset=True) -> dict[int, dict[tuple[int], Bias]]


   .. py:method:: apply(cvs: list[IMLCV.base.CV.CV], shmap=False, macro_chunk_size=10000)


.. py:class:: CompositeBias(*args, **kwargs)

   Bases: :py:obj:`Bias`


   Class that combines several biases in one single bias.


   .. py:attribute:: biases
      :type:  list[Bias]


   .. py:attribute:: fun
      :type:  Callable


   .. py:method:: create(biases: list[Bias], fun=jnp.sum) -> CompositeBias
      :classmethod:



   .. py:method:: _compute(cvs)

      function that calculates the bias potential.



   .. py:method:: update_bias(md: IMLCV.base.MdEngine.MDEngine) -> Bias

      update the bias.

      Can only change the properties from _get_args



.. py:function:: _zero_fun(cvs: IMLCV.base.CV.CV)

.. py:function:: _constant(cvs: IMLCV.base.CV.CV, val: float = 0.0)

.. py:class:: BiasModify(*args, **kwargs)

   Bases: :py:obj:`Bias`


   Bias according to CV.


   .. py:attribute:: fun
      :type:  Callable


   .. py:attribute:: bias
      :type:  Bias


   .. py:attribute:: kwargs
      :type:  dict


   .. py:attribute:: static_kwargs
      :type:  dict


   .. py:method:: create(fun: Callable, bias: Bias, kwargs: dict = {}, static_kwargs: dict = {}) -> BiasModify
      :classmethod:



   .. py:method:: _compute(cvs)

      function that calculates the bias potential.



   .. py:method:: update_bias(md: IMLCV.base.MdEngine.MDEngine) -> Bias

      update the bias.

      Can only change the properties from _get_args



   .. py:method:: __getstate__()


   .. py:method:: __setstate__(statedict: dict)


.. py:class:: BiasF(*args, **kwargs)

   Bases: :py:obj:`Bias`


   Bias according to CV.


   .. py:attribute:: g
      :type:  Callable


   .. py:attribute:: static_kwargs
      :type:  dict


   .. py:attribute:: kwargs
      :type:  dict


   .. py:method:: create(cvs: IMLCV.base.CV.CollectiveVariable, g: Callable = _constant, kwargs: dict = {}, static_kwargs: dict = {}) -> BiasF
      :staticmethod:



   .. py:method:: _compute(cvs)

      function that calculates the bias potential.



.. py:class:: NoneBias(*args, **kwargs)

   Bases: :py:obj:`BiasF`


   Bias according to CV.


   .. py:method:: create(collective_variable: IMLCV.base.CV.CollectiveVariable) -> NoneBias
      :staticmethod:



