
     id                     b    d Z ddlZddlmZ ddlmZ  G d de          Z G d d	e          ZdS )
a  Trajectory translation --- :mod:`MDAnalysis.transformations.translate`
======================================================================

Translate the coordinates of a given trajectory by a given vector.
The vector can either be user defined, using the function :func:`translate`
or defined by centering an AtomGroup in the unit cell using the function
:func:`center_in_box`

.. autoclass:: translate

.. autoclass:: center_in_box


    N)partial   )TransformationBasec                   *     e Zd ZdZd fd	Zd Z xZS )	translatea  
    Translates the coordinates of a given :class:`~MDAnalysis.coordinates.timestep.Timestep`
    instance by a given vector.

    Example
    -------
    .. code-block:: python

        ts = MDAnalysis.transformations.translate([1,2,3])(ts)

    Parameters
    ----------
    vector: array-like
        coordinates of the vector to which the coordinates will be translated

    Returns
    -------
    :class:`~MDAnalysis.coordinates.timestep.Timestep` object


    .. versionchanged:: 2.0.0
       The transformation was changed from a function/closure to a class
       with ``__call__``.
    .. versionchanged:: 2.0.0
       The transformation was changed to inherit from the base class for
       limiting threads and checking if it can be used in parallel analysis.
    NTc                    t                                          ||           || _        t          | j                  dk    r t	          j        | j                  | _        d S t          d                    | j                            )Nmax_threadsparallelizable   z{} vector is too short)super__init__vectorlennpfloat32
ValueErrorformat)selfr   r
   r   	__class__s       n/srv/www/vhosts/g4struct/public_html/venv/lib/python3.11/site-packages/MDAnalysis/transformations/translate.pyr   ztranslate.__init__J   s}    #N 	 	
 	
 	
 t{a*T[11DKKK5<<T[IIJJJ    c                 0    |xj         | j        z  c_         |S )N)	positionsr   )r   tss     r   
_transformztranslate._transformV   s    
#	r   )NT__name__
__module____qualname____doc__r   r   __classcell__r   s   @r   r   r   -   s\         8
K 
K 
K 
K 
K 
K      r   r   c                   4     e Zd ZdZ	 	 	 	 	 d fd	Zd Z xZS )	center_in_boxa  
    Translates the coordinates of a given :class:`~MDAnalysis.coordinates.timestep.Timestep`
    instance so that the center of geometry/mass of the given :class:`~MDAnalysis.core.groups.AtomGroup`
    is centered on the unit cell. The unit cell dimensions are taken from the input Timestep object.
    If a point is given, the center of the atomgroup will be translated to this point instead.

    Example
    -------

    .. code-block:: python

        ag = u.residues[1].atoms
        ts = MDAnalysis.transformations.center(ag,center='mass')(ts)

    Parameters
    ----------
    ag: AtomGroup
        atom group to be centered on the unit cell.
    center: str, optional
        used to choose the method of centering on the given atom group. Can be 'geometry'
        or 'mass'
    point: array-like, optional
        overrides the unit cell center - the coordinates of the Timestep are translated so
        that the center of mass/geometry of the given AtomGroup is aligned to this position
        instead. Defined as an array of size 3.
    wrap: bool, optional
        If `True`, all the atoms from the given AtomGroup will be moved to the unit cell
        before calculating the center of mass or geometry. Default is `False`, no changes
        to the atom coordinates are done before calculating the center of the AtomGroup.

    Returns
    -------
    :class:`~MDAnalysis.coordinates.timestep.Timestep` object


    .. versionchanged:: 2.0.0
        The transformation was changed from a function/closure to a class
        with ``__call__``.
    .. versionchanged:: 2.0.0
       The transformation was changed to inherit from the base class for
       limiting threads and checking if it can be used in parallel analysis.
    geometryNFTc                    t                                          ||           || _        || _        || _        || _        | j        }| j        rpt          j        | j        t          j                  | _        | j        j	        dk    r7| j        j	        dk    r't          d                    | j                            	 | j        dk    r"t          | j        j        |          | _        d S | j        dk    r"t          | j        j        |          | _        d S t          | j         d          # t           $ r> | j        dk    r| j         d	}t!          |          d t          | j         d
          d w xY w)Nr	   )   )r   r(   z{} is not a valid pointr&   )wrapmassz is valid for centerz' is not an AtomGroup object with massesz is not an AtomGroup object)r   r   agcenterpointr)   r   asarrayr   shaper   r   r   center_of_geometrycenter_methodcenter_of_massAttributeError)
r   r+   r,   r-   r)   r
   r   pbc_argerrmsgr   s
            r   r   zcenter_in_box.__init__   s    	#N 	 	
 	
 	
 
	): 	ODJ
;;DJz4''DJ,<,F,F !:!A!A$*!M!MNNN	{j((%,G.W& & &""" &&%,G*& & &""" !DK!E!E!EFFF 	 	 	{f$$ GLLL$V,,$6 w;;; 	s    +D1 -+D1 D1 1AE9c                     | j         5|j        t          d          t          j        |j        d          dz  }n| j         }|                                 }||z
  }|xj        |z  c_        |S )NzBox is Noner   )axisr   )r-   
dimensionsr   r   sumtriclinic_dimensionsr1   r   )r   r   	boxcenter	ag_centerr   s        r   r   zcenter_in_box._transform   su    :}$ ///r6Q???!CII
I&&((	Y&
	r   )r&   NFNTr   r#   s   @r   r%   r%   [   si        ) )\ ) ) ) ) ) )V      r   r%   )	r!   numpyr   	functoolsr   baser   r   r%    r   r   <module>rA      s   0            $ $ $ $ $ $+ + + + +" + + +\d d d d d& d d d d dr   