
     iw                     Z    d Z ddlmZmZ ddlmZ  G d d          Z G d d          Zd	S )
aW  AtomGroup accessors --- :mod:`MDAnalysis.core.accessors`
====================================================================

This module provides classes for accessing and converting :class:`~MDAnalysis.core.groups.AtomGroup`
objects. It is used for the :meth:`~MDAnalysis.core.groups.AtomGroup.convert_to`
method to make it usable in two different ways: ``ag.convert_to("PACKAGE")`` or
``ag.convert_to.package()``

Example
-------

.. code-block:: python

    >>> class SpeechWrapper:
    ...     def __init__(self, person):
    ...         self.person = person
    ...     def __call__(self, *args):
    ...         print(self.person.name, "says", *args)
    ...     def whoami(self):
    ...         print("I am %s" % self.person.name)
    ...
    >>> class Person:
    ...     def __init__(self, name):
    ...         self.name = name
    ...     say = Accessor("say", SpeechWrapper)
    ...
    >>> bob = Person("Bob")
    >>> bob.say("hello")
    Bob says hello
    >>> bob.say.whoami()
    I am Bob

Classes
-------

.. autoclass:: Accessor
   :members:

.. autoclass:: ConverterWrapper
   :members:

    )partialupdate_wrapper   )_CONVERTERSc                       e Zd ZdZd Zd ZdS )Accessora  Used to pass data between two classes

    Parameters
    ----------
    name : str
        Name of the property in the parent class
    accessor : class
        A class that needs access to its parent's instance

    Example
    -------
    If you want the property to be named "convert_to" in the AtomGroup class,
    use:

    .. code-block:: python

        >>> class AtomGroup:
        >>>     # ...
        >>>     convert_to = Accessor("convert_to", ConverterWrapper)

    And when calling ``ag.convert_to.rdkit()``, the "rdkit" method of the
    ConverterWrapper will be able to have access to "ag"


    .. versionadded:: 2.0.0
    c                 "    || _         || _        d S N)	_accessor_name)selfnameaccessors      c/srv/www/vhosts/g4struct/public_html/venv/lib/python3.11/site-packages/MDAnalysis/core/accessors.py__init__zAccessor.__init__d   s    !


    c                     || j         S |                      |          }t                              || j        |           |S r
   )r   object__setattr__r   )r   objclswrappeds       r   __get__zAccessor.__get__h   sA    ;>!..%% 	3
G444r   N)__name__
__module____qualname____doc__r   r    r   r   r   r   H   s<         6  
 
 
 
 
r   r   c                   "    e Zd ZdZi Zd Zd ZdS )ConverterWrappera  Convert :class:`AtomGroup` to a structure from another Python
    package.

    The converters are accessible to any AtomGroup through the ``convert_to``
    property. `ag.convert_to` will return this ConverterWrapper, which can be
    called directly with the name of the destination package as a string
    (similarly to the old API), or through custom methods named after the
    package (in lowercase) that are automatically constructed thanks to
    metaclass magic.

    Example
    -------
    The code below converts a Universe to a :class:`parmed.structure.Structure`

    .. code-block:: python

        >>> import MDAnalysis as mda
        >>> from MDAnalysis.tests.datafiles import GRO
        >>> u = mda.Universe(GRO)
        >>> parmed_structure = u.atoms.convert_to('PARMED')
        >>> parmed_structure
        <Structure 47681 atoms; 11302 residues; 0 bonds; PBC (triclinic); NOT parametrized>

    You can also directly use ``u.atoms.convert_to.parmed()``

    Parameters
    ----------
    package: str
        The name of the package to convert to, e.g. ``"PARMED"``
    *args:
        Positional arguments passed to the converter
    **kwargs:
        Keyword arguments passed to the converter

    Returns
    -------
    output:
        An instance of the structure type from another package.

    Raises
    ------
    ValueError:
        No converter was found for the required package


    .. versionadded:: 1.0.0
    .. versionchanged:: 2.0.0
        Moved the ``convert_to`` method to its own class. The old API is still
        available and is now case-insensitive to package names, it also accepts
        positional and keyword arguments. Each converter function can also
        be accessed as a method with the name of the package in lowercase, i.e.
        `convert_to.parmed()`
    c                 J   || _         t          j                    D ]\  }}|                                }	 | j        |         }n)# t          $ r  |            j        }|| j        |<   Y nw xY wt          || j                   }t          ||           t          | ||           dS )zk
        Parameters
        ----------
        ag : AtomGroup
            The AtomGroup to convert
        N)	_agr   itemslowerKeyErrorconvertr   r   setattr)r   aglibconverter_clsmethod_name	converterr&   s          r   r   zConverterWrapper.__init__   s     "-"3"5"5 	0 	0C))++K: ,[9		 : : :)MOO3	09 ---:
 i22G 7I...D+w////	0 	0s   A#A)(A)c           
          	 t          | |                                          }nN# t          $ rA t          d|dd                    | j                                                             d w xY w ||i |S )NzNo z converter found. Available:  )getattrr$   AttributeError
ValueErrorjoinr   keys)r   packageargskwargsr&   s        r   __call__zConverterWrapper.__call__   s    	dGMMOO44GG 	 	 	7g 7 788D,1133447 7  	
 w''''s
   "% AA0N)r   r   r   r   r   r   r7   r   r   r   r    r    u   sD        4 4l K0 0 02( ( ( ( (r   r    N)r   	functoolsr   r    r   r   r    r   r   r   <module>r:      s   0) )V . - - - - - - -      * * * * * * * *ZZ( Z( Z( Z( Z( Z( Z( Z( Z( Z(r   