
     i                         d Z ddlZddlmZmZ ddlmZ ddlm	Z	m
Z
 ddlmZ  e	j         e
d          dd	d
           [
 G d de          ZdS )z
Dielectric --- :mod:`MDAnalysis.analysis.dielectric`
===========================================================

:Authors: Mattia Felice Palermo, Philip Loche
:Year: 2022
:Copyright: Lesser GNU Public License v2.1+
    N)	constantsconvert)AnalysisBase)dueDoi)NoDataErrorz10.1080/00268978300102721zDielectric analysiszMDAnalysis.analysis.dielectricT)descriptionpathcite_modulec                   6     e Zd ZdZd fd	Zd Zd Zd Z xZS )	DielectricConstantu
  
    Computes the average dipole moment

    .. math::
        \boldsymbol M = \sum_i q_i \boldsymbol r_i


    where :math:`q_i` is the charge and :math:`\boldsymbol r_i` the position of
    atom :math:`i` in the given :class:`MDAnalysis.core.groups.AtomGroup`.
    Also, the static dielectric constant

    .. math::
        \varepsilon = 1 + \frac{\langle M^2 \rangle - \langle M \rangle^2}
                              {3 \varepsilon_ 0 V k_B T}


    is calculated for a system in tin foil boundary conditions, which is
    the usual case if electrostatics are handled with a Ewald summation
    technique. See [Neumann1983]_ for details on the derivation.

    .. warning::
      Applying this class requires that no free charges, such as ions or
      charged fragments, are present in the simulation.

    Parameters
    ----------
    atomgroup : MDAnalysis.core.groups.AtomGroup
      Atomgroup on which the analysis is executed
    temperature : float
      Temperature (Kelvin) at which the system has been simulated
    make_whole : bool
      Make molecules whole; If the input already contains whole molecules
      this can be disabled to gain speedup
    verbose : bool
      Show detailed progress of the calculation

    Attributes
    ----------
    results.M : numpy.ndarray
      Directional dependant dipole moment
      :math:`\langle \boldsymbol M \rangle` in :math:`eÅ`.
    results.M2 : numpy.ndarray
      Directional dependant squared dipole moment
      :math:`\langle \boldsymbol M^2 \rangle` in :math:`(eÅ)^2`
    results.fluct : float
      Directional dependant dipole moment fluctuation
      :math:`\langle \boldsymbol M^2 \rangle - \langle \boldsymbol M \rangle^2`
      in :math:`(eÅ)^2`
    results.eps : numpy.ndarray
      Directional dependant static dielectric constant
    results.eps_mean : float
      Static dielectric constant

    Example
    -------
    Create a :class:`DielectricConstant` instance by supplying an
    :class:`~MDAnalysis.core.groups.AtomGroup`,
    then use the :meth:`run` method::

      import MDAnalysis as mda
      from MDAnalysis.analysis.dielectric import DielectricConstant
      from MDAnalysisTests.datafiles import PSF_TRICLINIC, DCD_TRICLINIC

      # Load a pure water system
      universe = mda.Universe(PSF_TRICLINIC, DCD_TRICLINIC)

      diel = DielectricConstant(universe.atoms)
      diel.run()
      print(diel.results)

    The static dielectric constant of the provided atomgroup is saved
    within the :class:`~MDAnalysis.analysis.base.Results` attribute.


    .. versionadded:: 2.1.0
    ,  Tc                      t          t          |           j        |j        j        fi | || _        || _        || _        d S N)superr   __init__universe
trajectory	atomgrouptemperature
make_whole)selfr   r   r   kwargs	__class__s        h/srv/www/vhosts/g4struct/public_html/venv/lib/python3.11/site-packages/MDAnalysis/analysis/dielectric.pyr   zDielectricConstant.__init__   sW    0 $''0)	
 	
-3	
 	
 	
 #&$    c                    t          | j        d          st          d          t          j        | j                            d          dd          st          d          d	| _        t          j        d
          | j	        _
        t          j        d
          | j	        _        t          j        d
          | j	        _        t          j        d
          | j	        _        d	| j	        _        d S )Nchargesz#No charges defined given atomgroup.	fragments)compoundg        gh㈵>)atolzPAnalysis for non-neutral systems or systems with free charges are not available.r      )hasattrr   r   npallclosetotal_chargeNotImplementedErrorvolumezerosresultsMM2fluctepseps_meanr   s    r   _preparezDielectricConstant._prepare   s    t~y11 	ECDDD{N'''==s
 
 
 	 &   !(1++Xa[[8A;; !r   c                 D   | j         r| j                                         | xj        | j        j        j        j        j        z  c_        t          j        | j        j	        | j        j
                  }| j        xj        |z  c_        | j        xj        ||z  z  c_        d S r   )r   r   unwrapr(   r   r   tsr$   dotr   	positionsr*   r+   r,   )r   r+   s     r   _single_framez DielectricConstant._single_frame   s    ? 	$N!!###t~.9<CCF4>)4>+CDD!1q5 r   c                 >   | j         xj        | j        z  c_        | j         xj        | j        z  c_        | xj        | j        z  c_        | j         j        | j         j        | j         j        z  z
  | j         _        | j         j        t          t          d         dd          | j        z  | j        z  t          d         z  z  | j         _	        | j         j	        
                                | j         _        | j         xj	        dz  c_	        | j         xj        dz  c_        d S )NBoltzmann_constantzkJ/moleVelectric_constant   )r*   r+   n_framesr,   r(   r-   r   r   r   r.   meanr/   r0   s    r   	_concludezDielectricConstant._conclude   s    $-'4=(t}$!\_t|~/NN<-I23XtDDk +,-
 !% 0 5 5 7 7A"r   )r   T)	__name__
__module____qualname____doc__r   r1   r7   r?   __classcell__)r   s   @r   r   r   1   sw        K KZ% % % % % %" " "(! ! !# # # # # # #r   r   )rC   numpyr$   MDAnalysis.unitsr   r   MDAnalysis.analysis.baser   MDAnalysis.duer   r   MDAnalysis.exceptionsr   citer    r   r   <module>rL      s   0      / / / / / / / / 1 1 1 1 1 1 # # # # # # # # - - - - - - C#$$%	)	    E# E# E# E# E# E# E# E# E# E#r   