
     i]                     ^    d Z ddlZddlmZ ddlmZ ddlmZ ddl	m
Z
  G d	 d
e
          ZdS )zTrajectory rotation --- :mod:`MDAnalysis.transformations.rotate`
================================================================

Rotates the coordinates by a given angle arround an axis formed by a direction
and a point.

.. autoclass:: rotateby

    N)partial   )rotation_matrix)get_weights   )TransformationBasec                   6     e Zd ZdZ	 	 	 	 	 	 d fd	Zd Z xZS )	rotatebya  
    Rotates the trajectory by a given angle on a given axis. The axis is defined by
    the user, combining the direction vector and a point. This point can be the center
    of geometry or the center of mass of a user defined AtomGroup, or an array defining
    custom coordinates.

    Note
    ----
    ``max_threads`` is set to 1 for this transformation
    with which it performs better.

    Examples
    --------

    e.g. rotate the coordinates by 90 degrees on a axis formed by the [0,0,1] vector and
    the center of geometry of a given AtomGroup:

    .. code-block:: python

        from MDAnalysis import transformations

        ts = u.trajectory.ts
        angle = 90
        ag = u.atoms
        d = [0,0,1]
        rotated = transformations.rotate.rotateby(angle, direction=d, ag=ag)(ts)

    e.g. rotate the coordinates by a custom axis:

    .. code-block:: python

        from MDAnalysis import transformations

        ts = u.trajectory.ts
        angle = 90
        p = [1,2,3]
        d = [0,0,1]
        rotated = transformations.rotate.rotateby(angle, direction=d, point=p)(ts)

    Parameters
    ----------
    angle: float
        rotation angle in degrees
    direction: array-like
        vector that will define the direction of a custom axis of rotation from the
        provided point. Expected shapes are (3, ) or (1, 3).
    ag: AtomGroup, optional
        use the weighted center of an AtomGroup as the point from where the rotation axis
        will be defined. If no AtomGroup is given, the `point` argument becomes mandatory
    point: array-like, optional
        list of the coordinates of the point from where a custom axis of rotation will
        be defined. Expected shapes are (3, ) or (1, 3). If no point is given, the
        `ag` argument becomes mandatory.
    weights: {"mass", ``None``} or array_like, optional
        define the weights of the atoms when calculating the center of the AtomGroup.
        With ``"mass"`` uses masses as weights; with ``None`` weigh each atom equally.
        If a float array of the same length as `ag` is provided, use each element of
        the `array_like` as a weight for the corresponding atom in `ag`. Default is
        None.
    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
    -------
    MDAnalysis.coordinates.timestep.Timestep

    Warning
    -------
    Wrapping/unwrapping the trajectory or performing PBC corrections may not be possible
    after rotating the trajectory.


    .. 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.
    NFr   Tc	                     t                                          ||           || _        || _        || _        || _        || _        || _        t          j	        | j                  | _        	 t          j
        | j        t          j                  | _        | j        j        dk    r7| j        j        dk    r't          d                    | j                            | j                            d          | _        n&# t          $ r t          | j         d          d w xY w| j        t          j
        | j        t          j                  | _        | j        j        dk    r7| j        j        dk    r't          d                    | j                            | j                            d          | _        d S | j        r	 | j        j        | _        	 t#          | j        | j                  | _        nM# t          t$          f$ r d	}	t%          |	          d w xY w# t&          $ r t          | j         d
          d w xY wt)          | j        j        | j        | j                  | _        d S t          d          )N)max_threadsparallelizable)   )r   r   z{} is not a valid directionr   z is not a valid directionz{} is not a valid point)weightszPweights must be {'mass', None} or an iterable of the same size as the atomgroup.z is not an AtomGroup object)wrapz)A point or an AtomGroup must be specified)super__init__angle	directionpointagr   r   npdeg2radasarrayfloat32shape
ValueErrorformatreshapeatomsr   	TypeErrorAttributeErrorr   centercenter_method)selfr   r   r   r   r   r   r   r   errmsg	__class__s             k/srv/www/vhosts/g4struct/public_html/venv/lib/python3.11/site-packages/MDAnalysis/transformations/rotate.pyr   zrotateby.__init__~   s    	#N 	 	
 	
 	
 
"
	Z
++
	Z
CCDN~#t++0D0N0N 188HH   "^33 DNN  	 	 	><<< 	 :!DJ
;;DJz4''DJ,<,F,F !:!A!A$*!M!MNNN++ DJJJ W 	J6!W]
	6#.
DL$ $ $DLL #I. 6 6 6=  $F++56 "    w;;;  ")
!4<di" " "D HIIIs%   .BC> >#D!H  G7 7$H#Ic                    | j         |                                 }n| j         }t          | j        | j        |          }|d dd df         j        }|d ddf         }t          j        |j        |          |_        |xj        |z  c_        |S )Nr   )	r   r#   r   r   r   Tr   dot	positions)r$   tspositionmatrixrotationtranslations         r'   
_transformzrotateby._transform   s    :))++HHzH T^XFF"1"bqb&>#RaRUmvblH55
#	    )NNNFr   T)__name__
__module____qualname____doc__r   r1   __classcell__)r&   s   @r'   r
   r
   +   sz        P Pl AJ AJ AJ AJ AJ AJF
 
 
 
 
 
 
r2   r
   )r6   numpyr   	functoolsr   lib.transformationsr   lib.utilr   baser   r
    r2   r'   <module>r>      s   0	 	           1 1 1 1 1 1 " " " " " " $ $ $ $ $ $` ` ` ` `! ` ` ` ` `r2   