
     i	9                     ,   d Z ddlZ G d de          Z eddddd	d
          Zddddddddddd
ZddddddZddddddded         z  z  dded         z  ed         z  ed         z  z  dded         z  ed         z  ed         z  z  dded         z  ed         z  ed         z  z  dded         z  ed         z  ed         z  z  d 
Zddddd!d!d"d"d#d#d#d$d$d$d%d&Zi d'dd(dd)dd*dd+dd,d!d-d!d.d!d/d!d0d!d1d!d2dd3dd4dd5dd6dd7d8i d9d8d:d8d;d8d<d8d=d8d>d8d?d8d@d8dAdBdCdBdDdBdEdBdFdBdGdBdHdIdJdIdKdddddddLZ	ddedM         z  ded         z  ded         edN         z  z  dOZ
ddddPdQed         z  dQed         z  dQed         z  dedM         z  dRZddSedN         edN         dTZeeeee	ee
dUZi Ze                                D ]'\  ZZe                                D ]ZeevsJ eee<   (dVdWdXdYdZd(d[Zd\ Zd] ZdS )^u_  
Constants and unit conversion --- :mod:`MDAnalysis.units`
===============================================================

The base units of MDAnalysis trajectories are the **Å** (**ångström**) for
**length** and **ps** (**pico second**) for **time**. By default, all positions
are in Å and all times are in ps, regardless of how the MD code stored
trajectory data. By default, MDAnalysis converts automatically to the
MDAnalysis units when reading trajectories and converts back when writing. This
makes it possible to write scripts that can be agnostic of the specifics of how
a particular MD code stores trajectory data. Other base units are listed in the
table on :ref:`table-baseunits`.

.. _table-baseunits:

.. Table:: Base units in MDAnalysis as encoded in :data:`MDANALYSIS_BASE_UNITS`

   =========== ============== ===============================================
   quantity    unit            SI units
   =========== ============== ===============================================
   length       Å              :math:`10^{-10}` m
   time         ps             :math:`10^{-12}` s
   energy       kJ/mol         :math:`1.66053892103219 \times 10^{-21}` J
   charge       :math:`e`      :math:`1.602176565 \times 10^{-19}` As
   force        kJ/(mol·Å)     :math:`1.66053892103219 \times 10^{-11}` J/m
   speed        Å/ps           :math:`100` m/s
   =========== ============== ===============================================

Implementation notes
--------------------

All conversions with :func:`convert` are carried out in a simple fashion: the
conversion factor :math:`f_{b,b'}` from the base unit :math:`b` to another unit
:math:`b'` is precomputed and stored (see :ref:`Data`). The numerical value of
a quantity in unit :math:`b` is :math:`X/b` (e.g. for :math:`X =
1.23\,\mathrm{ps}`, the numerical value is :math:`X/\mathrm{ps} =
1.23`). [#funits]_

The new numerical value :math:`X'/b'` of the quantity (in units of :math:`b'`)
is then

.. math::

   X'/b' = f_{b,b'} X/b

The function :func:`get_conversion_factor` returns the appropriate factor
:math:`f_{b,b'}`.

Conversion between different units is always carried out via the base unit as
an intermediate step::

    x is in u1: from u1 to b:  x'  = x  / factor[u1]
                from b  to u2: x'' = x' * factor[u2]
    so f[u1,u2] = factor[u2]/factor[u1]


Conversions
~~~~~~~~~~~

Examples for how to calculate some of the conversion factors that are
hard-coded in :mod:`~MDAnalysis.units` (see :ref:`Data`).

density:
  Base unit is :math:`\mathrm{Å}^{-3}`::

     n/x = n/A**3 * densityUnit_factor[x]

  Example for how to calculate the conversion factor
  :math:`f_{\mathrm{Å}^{-3},\mathrm{nm}^{-3}}` from :math:`\mathrm{Å}^{-3}` to
  :math:`\mathrm{nm}^{-3}`:

  .. math::

     f_{\mathrm{Å}^{-3},\mathrm{nm}^{-3}}
           = \frac{1\,\mathrm{nm}^{-3}}{1\,\mathrm{Å}^{-3}}
           = \frac{(10\,\mathrm{Å})^{-3}}{1\,\mathrm{Å}^{-3}}
           = 10^{-3}

concentration:
  Example for how to convert the conversion factor to Molar (mol/l)::

     factor = 1 A**-3 / (N_Avogadro * (10**-9 dm)**-3)

  relative to a density rho0 in :math:`g/cm^3`::

    M(H2O) = 18 g/mol   Molar mass of water

    factor = 1/(1e-24 * N_Avogadro / M(H2O))

  from :math:`\rho/\rho_0 = n/(N_A * M^{-1}) / \rho_0`

  where :math:`[n] = 1/Volume`, :math:`[\rho] = mass/Volume`


Note
----
In the future we might move towards using the Quantities_ package or
:mod:`scipy.constants`.


.. _Quantities: http://packages.python.org/quantities/

Functions
---------

.. autofunction:: get_conversion_factor
.. autofunction:: convert

.. _Data:

Data
----

.. autodata:: MDANALYSIS_BASE_UNITS
.. autodata:: constants
.. autodata:: lengthUnit_factor
.. autodata:: water
.. autodata:: densityUnit_factor
.. autodata:: timeUnit_factor
.. autodata:: speedUnit_factor
.. autodata:: forceUnit_factor
.. autodata:: chargeUnit_factor
.. autodata:: conversion_factor
.. autodata:: unit_types


References and footnotes
------------------------

.. footbibliography::

.. _AKMA: http://www.charmm.org/documentation/c37b1/usage.html#%20AKMA
.. _electron charge: http://physics.nist.gov/cgi-bin/cuu/Value?e
.. _`Avogadro's constant`: http://physics.nist.gov/cgi-bin/cuu/Value?na

.. Rubric:: Footnotes

.. [#funits] One can also consider the conversion factor to carry
   units :math:`b'/b`, in which case the conversion formula would
   become

   .. math::

      X' = f_{b,b'} X

    Nc                   "     e Zd ZdZ fdZ xZS )DeprecatedKeyAccessDictBoltzman_constantc                     || j         k    rd}t          j        |t                     d}t	                                          |          S )Nz{Please use 'Boltzmann_constant' henceforth. The key 'Boltzman_constant' was a typo and will be removed in MDAnalysis 2.8.0.Boltzmann_constant)deprecated_kBwarningswarnDeprecationWarningsuper__getitem__)selfkeywmsg	__class__s      Z/srv/www/vhosts/g4struct/public_html/venv/lib/python3.11/site-packages/MDAnalysis/units.pyr   z#DeprecatedKeyAccessDict.__getitem__   sM    $$$$' 
 M$ 2333&Cww""3'''    )__name__
__module____qualname__r   r   __classcell__)r   s   @r   r   r      s=        'M	( 	( 	( 	( 	( 	( 	( 	( 	(r   r   gjDgQڤ<g#~j@g?1t8,?gBH̢v?)
N_Avogadroelementary_chargecalorier   electric_constantg      ?g?g      Y@g     j@)
AngstromAangstromu   Ånm	nanometerpm	picometerfm
femtometergCl?gQ?gx&1?gjt?gjt2@)expSPCTIP3PTIP4P	MolarMassg     @@   g<6S:r   gW:r&   r)   r'   r(   r%   )
zAngstrom^{-3}zA^{-3}u   Å^{-3}znm^{-3}znanometer^{-3}Molarr&   r'   r(   watergMbP?g&.>gư>g-q=g9ot4@)ps
picosecondfsfemtosecondns
nanosecondmsmillisecondusmicrosecondu   μssecondsecsAKMAzAngstrom/pszA/psu   Å/pszAngstrom/picosecondzangstrom/picosecondzAngstrom/fszAngstrom/femtosecondzangstrom/femtosecondzangstrom/fszA/fsu   Å/fszAngstrom/nszA/nsu   Å/nszAngstrom/nanosecondzangstrom/nanosecondzAngstrom/usg    .Azangstrom/uszA/usu   A/μsu   Å/μszAngstrom/microsecondzangstrom/microsecondu   Angstrom/μsu   angstrom/μszAngstrom/msg    eAzAngstrom/millisecondzangstrom/millisecondzangstrom/mszA/msu   Å/mszAngstrom/AKMAgRO8?zA/AKMAznm/ps)znanometer/psznanometer/picosecondznm/nszpm/pszm/sr   r   )kJ/molzkcal/molJeVg      $@g  @0B)zkJ/(mol*Angstrom)
kJ/(mol*A)u   kJ/(mol*Å)zkJ/(mol*nm)NewtonNzJ/mzkcal/(mol*Angstrom)g82@)eAmberCAs)lengthdensitytimechargespeedforceenergyr   r-   r;   rA   r>   )rE   rG   rK   rH   rJ   rI   c                 P    t           |          |         t           |          |         z  S )zgenerate the conversion factor u1 -> u2 by using the base unit as an intermediate

    f[u1 -> u2] = factor[u2]/factor[u1]

    Conversion of :math:`X` (in u1) to :math:`X'` (in u2):

    :math:`X'` = conversion_factor * :math:`X`
    )conversion_factor)	unit_typeu1u2s      r   get_conversion_factorrQ     s$     Y'+.?	.J2.NNNr   c                    	 t           |         }n?# t          $ r2 d| dd                    t                      d}t          |          dw xY w	 t           |         }n?# t          $ r2 d| dd                    t                      d}t          |          dw xY w||k    r#t          d                    ||                    | t          |||          z  S )zConvert value *x* in unit *u1* to new value in *u2*.

    Returns
    -------
    float
        Converted value.

    Raises
    ------
    ValueError
        The units are not known or if one attempts to convert between
        incompatible units.
    zunit 'z$' not recognized.
It must be one of z, .Nz-Cannot convert between unit types {0} --> {1})
unit_typesKeyErrorjoin
ValueErrorformatrQ   )xrO   rP   ut1errmsgut2s         r   convertr]     s.   +n + + +:R : :!%:!6!6: : : 	   d*++n + + +:R : :!%:!6!6: : : 	   d*+ czz>EEb"MM
 
 	
 $S"b1111s    <AA <B)__doc__r	   dictr   	constantslengthUnit_factorr,   densityUnit_factortimeUnit_factorspeedUnit_factorenergyUnit_factorforceUnit_factorchargeUnit_factorrM   rT   itemsutypeufactorkeysunitMDANALYSIS_BASE_UNITSrQ   r]    r   r   <module>ro      s'  0Q Qf ( ( ( ( (d ( ( (@ $##,,(  	  	


  4 	 	 %)L112y&&u5k8JJLy&&w7%:LLNy&&w7%:LLNy&&u5k8JJL  * 



	 ((3(
C( ( 3	(
 3( :( J( J( :( J( ( 9( I( ( 9(  9!(" 9#( ($ 9%(& I'(( )(* i+(, I-(. I/(0 	1(2 	3(4 95(6 I7(8 I9(: 9;(< I=(> ?(@ [A(B kC(D SE( (F O( ( ( Z Ii((	y&	&
<(95H+II
J	   Y|,,		,'	')L))y33	 	 . 
	&	'
'
(	    !   
'--// ! !NE7 ! !:%%%% 
4!   O O O#2 #2 #2 #2 #2r   