<commit_before>"""The WaveBlocks Project

Compute some observables like norm, kinetic and potential energy
of Hagedorn wavepackets. This class implements the mixed case
where the bra does not equal the ket.

@author: <NAME>
@copyright: Copyright (C) 2014 <NAME>
@license: Modified BSD License
"""

from functools import partial
from numpy import squeeze, sum

from Observables import Observables
from GradientHAWP import GradientHAWP

__all__ = ["ObservablesMixedHAWP"]


class ObservablesMixedHAWP(Observables):
    r"""This class implements the mixed case observable computation
    :math:`\langle \Psi | \cdot | \Psi^\prime \rangle` for Hagedorn
    wavepackets :math:`\Psi` where the bra :math:`\Psi` does not equal
    the ket :math:`\Psi^\prime`.

    .. warning:: Wavepackets consisting of multiple components are not yet supported.
    """

    # TODO: Support multi-component wavepackets

    def __init__(self, innerproduct=None):
        r"""Initialize a new :py:class:`ObservablesMixedHAWP` instance for observable computation of
        Hagedorn wavepackets.

        :param innerproduct: An inner product for computing the integrals. The inner product is used
                             for the computation of all brakets
                             :math:`\langle \Psi | \cdot | \Psi^\prime \rangle`.
        :type innerproduct: A :py:class:`InnerProduct` subclass instance.

        .. note:: Make sure to use an inhomogeneous inner product here.
        """
        # A innerproduct to compute the integrals
        if innerproduct is not None:
            self._innerproduct = innerproduct

        self._gradient = GradientHAWP()


    def set_innerproduct(self, innerproduct):
        r"""Set the innerproduct.

        :param innerproduct: An inner product for computing the integrals. The inner product is used
                             for the computation of all brakets
                             :math:`\langle \Psi | \cdot | \Psi^\prime \rangle`.
        :type innerproduct: A :py:class:`InnerProduct` subclass instance.

        .. note:: Make sure to use an inhomogeneous inner product here.
        """
        self._innerproduct = innerproduct


    def overlap(self, pacbra, packet, componentbra=None, componentket=None, summed=False):
        r"""Calculate the overlap :math:`\langle \Psi | \Psi^\prime \rangle` of the wavepackets
        :math:`\Psi` and :math:`\Psi^\prime`.

        :param pacbra: The wavepacket :math:`\Psi` which takes part in the overlap integral.
        :type pacbra: A :py:class:`HagedornWavepacketBase` subclass instance.
        :param packet: The wavepacket :math:`\Psi^\prime` which takes part in the overlap integral.
        :type packet: A :py:class:`HagedornWavepacketBase` subclass instance.
        :param componentbra: The index :math:`i` of the component :math:`\Phi_i` of :math:`\Psi`
                             whose overlap is computed. The default value is ``None`` which means
                             to compute the overlaps with all :math:`N` components of :math:`\Psi`.
        :type componentbra: Integer or ``None``.
        :param componentket: The index :math:`i` of the component :math:`\Phi_i^\prime` of :math:`\Psi^\prime`
                             whose overlap is computed. The default value is ``None`` which means
                             to compute the overlaps with all :math:`N^\prime` components of :math:`\Psi^\prime`.
        :type componentket: Integer or ``None``.
        :param summed: Whether to sum up the overlaps :math:`\langle \Phi_i | \Phi_i^\prime \rangle`
                       of the individual components :math:`\Phi_i` and :math:`\Phi_i^\prime`.
        :type summed: Boolean, default is ``False``.
        :return: The overlap of :math:`\Psi` with :math:`\Psi^\prime` or the overlap of :math:`\Phi_i`
                 with :math:`\Phi_i^\prime` or a list with the :math:`N` overlaps of all components.
                 (Depending on the optional arguments.)
        """
        return self._innerproduct.quadrature(pacbra, packet, component=0, summed=summed)


    def norm(self, wavepacket, component=None, summed=False):
        r"""Calculate the :math:`L^2` norm :math:`\langle \Psi | \Psi \rangle` of the wavepacket :math:`\Psi`.

        :param wavepacket: The wavepacket :math:`\Psi` of which we compute the norm.
        :type wavepacket: A :py:class:`HagedornWavepacketBase` subclass instance.
        :param component: The index :math:`i` of the component :math:`\Phi_i` whose norm is computed.
                          The default value is ``None`` which means to compute the norms of all :math:`N` components.
        :type component: int or ``None``.
        :param summed: Whether to sum up the norms :math:`\langle \Phi_i | \Phi_i \rangle` of the
                       individual components :math:`\Phi_i`.
        :type summed: Boolean, default is ``False``.
        :return: The norm of :math:`\Psi` or the norm of :math:`\Phi_i` or a list with the :math:`N`
                 norms of all components. (Depending on the optional arguments.)

        .. note:: This method just expands to a call of the :py:meth:`ObservablesMixedHAWP.overlap`
                  method. Better use :py:meth:`ObservablesHAWP.norm`.
        """
        return self.overlap(wavepacket, wavepacket, componentbra=component, componentket=component, summed=summed)


    def kinetic_overlap_energy(self, pacbra, packet, componentbra=None, componentket=None, summed=False):
        r"""Compute the kinetic energy overlap :math:`\langle \Psi | T | \Psi^\prime \rangle`
        of the different components :math:`\Phi_i` and :math:`\Phi_i^\prime` of the
        wavepackets :math:`\Psi` and :math:`\Psi^\prime`.

        :param pacbra: The wavepacket :math:`\Psi` which takes part in the kinetic energy integral.
        :type pacbra: A :py:class:`HagedornWavepacketBase` subclass instance.
        :param packet: The wavepacket :math:`\Psi^\prime` which takes part in the kinetic energy integral.
        :type packet: A :py:class:`HagedornWavepacketBase` subclass instance.
        :param componentbra: The index :math:`i` of the component :math:`\Phi_i` of :math:`\Psi`
                             which takes part in the kinetic energy integral. If set to ``None`` the
                             computation is performed for all :math:`N` components of :math:`\Psi`.
        :type componentbra: Integer or ``None``.
        :param componentket: The index :math:`i` of the component :math:`\Phi_i^\prime` of :math:`\Psi^\prime`
                             which takes part in the kinetic energy integral. If set to ``None`` the
                             computation is performed for all :math:`N^\prime` components of :math:`\Psi^\prime`.
        :type componentket: Integer or ``None``.
        :param summed: Whether to sum up the kinetic energies :math:`E_i` of the individual
                       components :math:`\Phi_i` and :math:`\Phi_i^\prime`.
        :type summed: Boolean, default is ``False``.
        :return: A list of the kinetic energy overlap integrals of the individual components or
                 the overall kinetic energy overlap of the wavepackets. (Depending on the optional arguments.)
        """
        if componentbra is None:
            Nbra = pacbra.get_number_components()
            componentsbra = xrange(Nbra)
        else:<commit_msg>Enable mixed overlap for wavepackets of multiple components<commit_after>"""The WaveBlocks Project

Compute some observables like norm, kinetic and potential energy
of Hagedorn wavepackets. This class implements the mixed case
where the bra does not equal the ket.

@author: <NAME>
@copyright: Copyright (C) 2014 <NAME>
@license: Modified BSD License
"""

from functools import partial
from numpy import squeeze, sum

from Observables import Observables
from GradientHAWP import GradientHAWP

__all__ = ["ObservablesMixedHAWP"]


class ObservablesMixedHAWP(Observables):
    r"""This class implements the mixed case observable computation
    :math:`\langle \Psi | \cdot | \Psi^\prime \rangle` for Hagedorn
    wavepackets :math:`\Psi` where the bra :math:`\Psi` does not equal
    the ket :math:`\Psi^\prime`.

    .. warning:: Wavepackets consisting of multiple components are not yet supported.
    """

    # TODO: Support multi-component wavepackets

    def __init__(self, innerproduct=None):
        r"""Initialize a new :py:class:`ObservablesMixedHAWP` instance for observable computation of
        Hagedorn wavepackets.

        :param innerproduct: An inner product for computing the integrals. The inner product is used
                             for the computation of all brakets
                             :math:`\langle \Psi | \cdot | \Psi^\prime \rangle`.
        :type innerproduct: A :py:class:`InnerProduct` subclass instance.

        .. note:: Make sure to use an inhomogeneous inner product here.
        """
        # A innerproduct to compute the integrals
        if innerproduct is not None:
            self._innerproduct = innerproduct

        self._gradient = GradientHAWP()


    def set_innerproduct(self, innerproduct):
        r"""Set the innerproduct.

        :param innerproduct: An inner product for computing the integrals. The inner product is used
                             for the computation of all brakets
                             :math:`\langle \Psi | \cdot | \Psi^\prime \rangle`.
        :type innerproduct: A :py:class:`InnerProduct` subclass instance.

        .. note:: Make sure to use an inhomogeneous inner product here.
        """
        self._innerproduct = innerproduct


    def overlap(self, pacbra, packet, component=None, summed=False):
        r"""Calculate the overlap :math:`\langle \Psi | \Psi^\prime \rangle` of the wavepackets
        :math:`\Psi` and :math:`\Psi^\prime`.

        :param pacbra: The wavepacket :math:`\Psi` which takes part in the overlap integral.
        :type pacbra: A :py:class:`HagedornWavepacketBase` subclass instance.
        :param packet: The wavepacket :math:`\Psi^\prime` which takes part in the overlap integral.
        :type packet: A :py:class:`HagedornWavepacketBase` subclass instance.
        :param component: The index :math:`i` of the components :math:`\Phi_i` of :math:`\Psi`
                          and :math:`\Phi_i^\prime` of :math:`\Psi^\prime` whose overlap is
                          computed. The default value is ``None`` which means to compute the
                          overlaps with all :math:`N` components involved.
        :type component: Integer or ``None``.
        :param summed: Whether to sum up the overlaps :math:`\langle \Phi_i | \Phi_i^\prime \rangle`
                       of the individual components :math:`\Phi_i` and :math:`\Phi_i^\prime`.
        :type summed: Boolean, default is ``False``.
        :return: The overlap of :math:`\Psi` with :math:`\Psi^\prime` or the overlap of :math:`\Phi_i`
                 with :math:`\Phi_i^\prime` or a list with the :math:`N` overlaps of all components.
                 (Depending on the optional arguments.)
        """
        return self._innerproduct.quadrature(pacbra, packet, component=component, summed=summed)


    def norm(self, wavepacket, component=None, summed=False):
        r"""Calculate the :math:`L^2` norm :math:`\langle \Psi | \Psi \rangle` of the wavepacket :math:`\Psi`.

        :param wavepacket: The wavepacket :math:`\Psi` of which we compute the norm.
        :type wavepacket: A :py:class:`HagedornWavepacketBase` subclass instance.
        :param component: The index :math:`i` of the component :math:`\Phi_i` whose norm is computed.
                          The default value is ``None`` which means to compute the norms of all :math:`N` components.
        :type component: int or ``None``.
        :param summed: Whether to sum up the norms :math:`\langle \Phi_i | \Phi_i \rangle` of the
                       individual components :math:`\Phi_i`.
        :type summed: Boolean, default is ``False``.
        :return: The norm of :math:`\Psi` or the norm of :math:`\Phi_i` or a list with the :math:`N`
                 norms of all components. (Depending on the optional arguments.)

        .. note:: This method just redirects to a call to :py:meth:`HagedornWavepacketBase.norm`.
        """
        return wavepacket.norm(component=component, summed=summed)


    def kinetic_overlap_energy(self, pacbra, packet, componentbra=None, componentket=None, summed=False):
        r"""Compute the kinetic energy overlap :math:`\langle \Psi | T | \Psi^\prime \rangle`
        of the different components :math:`\Phi_i` and :math:`\Phi_i^\prime` of the
        wavepackets :math:`\Psi` and :math:`\Psi^\prime`.

        :param pacbra: The wavepacket :math:`\Psi` which takes part in the kinetic energy integral.
        :type pacbra: A :py:class:`HagedornWavepacketBase` subclass instance.
        :param packet: The wavepacket :math:`\Psi^\prime` which takes part in the kinetic energy integral.
        :type packet: A :py:class:`HagedornWavepacketBase` subclass instance.
        :param componentbra: The index :math:`i` of the component :math:`\Phi_i` of :math:`\Psi`
                             which takes part in the kinetic energy integral. If set to ``None`` the
                             computation is performed for all :math:`N` components of :math:`\Psi`.
        :type componentbra: Integer or ``None``.
        :param componentket: The index :math:`i` of the component :math:`\Phi_i^\prime` of :math:`\Psi^\prime`
                             which takes part in the kinetic energy integral. If set to ``None`` the
                             computation is performed for all :math:`N^\prime` components of :math:`\Psi^\prime`.
        :type componentket: Integer or ``None``.
        :param summed: Whether to sum up the kinetic energies :math:`E_i` of the individual
                       components :math:`\Phi_i` and :math:`\Phi_i^\prime`.
        :type summed: Boolean, default is ``False``.
        :return: A list of the kinetic energy overlap integrals of the individual components or
                 the overall kinetic energy overlap of the wavepackets. (Depending on the optional arguments.)
        """
        if componentbra is None:
            Nbra = pacbra.get_number_components()
            componentsbra = xrange(Nbra)
        else:
{'fraction_non_alphanumeric': 0.1043502393672379, 'fraction_numerical': 0.000763199888989107, 'mean_word_length': 2.608913370055083, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3212027', 'n_tokens_mistral': 3938, 'n_tokens_neox': 3745, 'n_words': 1461}