
     i                         d Z ddlZddlmZ ddlmZmZ ddlmZ ddl	m
Z
mZ  G d	 d
e          Z G d de          ZdS )aA  
TRR trajectory files --- :mod:`MDAnalysis.coordinates.TRR`
==========================================================

Read and write GROMACS TRR trajectories.

See Also
--------
MDAnalysis.coordinates.XTC: Read and write GROMACS XTC trajectory files.
MDAnalysis.coordinates.XDR: BaseReader/Writer for XDR based formats
    N   )base)XDRBaseReaderXDRBaseWriter   )TRRFile)triclinic_vectorstriclinic_boxc                   2    e Zd ZdZdZdZdddddZeZd	 Z	d
S )	TRRWritera"  Writer for the Gromacs TRR format.

    The Gromacs TRR trajectory format is a lossless format. The TRR format can
    store *velocities* and *forces* in addition to the coordinates. It is also
    used by other Gromacs tools to store and process other data such as modes
    from a principal component analysis.

    If the data dictionary of a :class:`Timestep` contains the key
    'lambda' the corresponding value will be used as the lambda value
    for written TRR file.  If ``None`` is found the lambda is set to 0.

    If the data dictionary of a :class:`Timestep` contains the key
    'step' the corresponding value will be used as the step value for
    the written TRR file. If the dictionary does not contain 'step', then
    the step is set to the :class:`Timestep` frame attribute.

    TRRTpsnmnm/pskJ/(mol*nm)timelengthvelocityforcec           
      Z   	 |j         }n># t          $ r1 	 |j        j         }n # t          $ r d}t          |          dw xY wY nw xY wd}|j        r5|j                                        }| j        r|                     |           d}|j	        r5|j
                                        }| j        r|                     |           d}|j        r5|j                                        }| j        r|                     |           | j        |j        }n| j        |j        z  }|j                            d|j                  }| j        r|                     |d          }	t+          |	          }
d}d|j        v r|j        d         }| j                            ||||
|||| j                   dS )a  Write information associated with ``ag`` at current frame into trajectory

        Parameters
        ----------
        ag : AtomGroup or Universe

        See Also
        --------
        <FormatWriter>.write(AtomGroup/Universe/TimeStep)
        The normal write() method takes a more general input


        .. versionchanged:: 1.0.0
           Renamed from `write_next_timestep` to `_write_next_frame`.
        .. versionchanged:: 2.0.0
           Deprecated support for Timestep argument has now been removed.
           Use AtomGroup or Universe as an input instead.
        .. versionchanged:: 2.1.0
           When possible, TRRWriter assigns `ts.data['step']` to `step` rather
           than `ts.frame`.
        z-Input obj is neither an AtomGroup or UniverseNstepF)inplacer   lambda)tsAttributeError
trajectory	TypeErrorhas_positions	positionscopy_convert_unitsconvert_pos_to_nativehas_velocities
velocitiesconvert_velocities_to_native
has_forcesforcesconvert_forces_to_native_dtr   framedatagetconvert_dimensions_to_unitcellr	   _xdrwriten_atoms)selfagr   errmsgxyzvelor(   r   r   
dimensionsboxlmbdas               d/srv/www/vhosts/g4struct/public_html/venv/lib/python3.11/site-packages/MDAnalysis/coordinates/TRR.py_write_next_framezTRRWriter._write_next_frameF   s   ,	2BB 	2 	2 	22]%! 2 2 2H''T12 	2  	0,##%%C" 0**3/// 	8=%%''D" 811$777= 	6Y^^%%F" 6--f55587DD8bh&Dw{{628,, 	P<<R<OOJ
++rwGH%E	vsD$t|	
 	
 	
 	
 	
s!   
 
A"A?AAN)
__name__
__module____qualname____doc__format
multiframeunitsr   _filer;        r:   r   r   )   s]         $ FJ	 E EC
 C
 C
 C
 C
rE   r   c                   :    e Zd ZdZdZdddddZeZeZ	dd	Z
d
 ZdS )	TRRReadera	  Reader for the Gromacs TRR format.

    The Gromacs TRR trajectory format is a lossless format. The TRR format can
    store *velocities* and *forces* in addition to the coordinates. It is also
    used by other Gromacs tools to store and process other data such as modes
    from a principal component analysis.

    The lambda value is written in the data dictionary of the returned
    :class:`Timestep`

    Notes
    -----
    See :ref:`Notes on offsets <offsets-label>` for more information about
    offsets.

    r   r   r   r   r   r   Nc                 >   | j         | j        dz
  k    rt          t          j        d          || j        }d|_        d|_        d|_        | j	        
                    |j        |j        |j                  }| xj         dz  c_         |                     ||           |S )a  copy next frame into timestep

        versionadded:: 2.4.0
            TRRReader implements this method so that it can use
            read_direct_xvf to read the data directly into the timestep
            rather than copying it from a temporary array.
        r   z"trying to go over trajectory limitNT)_framen_framesIOErrorerrnoEIOr   r   r$   r'   r/   read_direct_xvfr    r%   r(   _frame_to_ts)r2   r   r+   s      r:   _read_next_timestepzTRRReader._read_next_timestep   s     ;$-!+++%)%IJJJ:B   	))L"-
 
 	q%$$$	rE   c                 p   | j         d         }||j        |_        n| j        |z  |_        | j        |_        |j        |j        d<   |j        |_        |j        |_	        |j
        |_        t          |j         |_        | j        r)|j        "|                     |j        dd                    |j        rL| j        |j        | j                 |_        n|j        |_        | j        r|                     |j                   |j	        rL| j        |j        | j                 |_        n|j        |_        | j        r|                     |j                   |j        rL| j        |j        | j                 |_        n|j        |_        | j        r|                     |j                   |j        |j        d<   |S )z%convert a trr-frame to a mda TimeStepdtNr      r   )_kwargsr   rI   r+   r   r,   hasxr   hasvr$   hasfr'   r
   r8   r7   convert_unitsconvert_pos_from_native_subxr    vr%   convert_velocities_from_nativefr(   convert_forces_from_nativer9   )r2   r+   r   rR   s       r:   rO   zTRRReader._frame_to_ts   s   \$:jBGGkB&BG;* :!J
%uy1 	@}(,,R]2A2->??? 	;y$$wty1$w! ;,,R\::: 	Cy$ %	 2 %! C33BMBBB= 	;y$!GDI.		!G	! ;//	:::!K	rE   )N)r<   r=   r>   r?   r@   rB   r   _writerr   rC   rP   rO   rD   rE   r:   rG   rG      sl         " F	 E GE   0- - - - -rE   rG   )r?   rL    r   XDRr   r   lib.formats.libmdaxdrr   lib.mdamathr	   r
   r   rG   rD   rE   r:   <module>re      s   .
 
        - - - - - - - - + + + + + + : : : : : : : :`
 `
 `
 `
 `
 `
 `
 `
Fa a a a a a a a a arE   