
     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  
XTC trajectory files --- :mod:`MDAnalysis.coordinates.XTC`
==========================================================

Read and write GROMACS XTC trajectories.

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

    XTC is a compressed trajectory format from Gromacs. The trajectory is saved
    with reduced precision (3 decimal places by default) compared to other
    lossless formarts like TRR and DCD. The main advantage of XTC files is that
    they require significantly less disk space and the loss of precision is
    usually not a problem.
    XTCTpsnmtimelengthN   c                 `     t          t          |           j        ||f||d| || _        dS )aR  
        Parameters
        ----------
        filename : str
            filename of the trajectory
        n_atoms : int
            number of atoms to write
        convert_units : bool (optional)
            convert into MDAnalysis units
        dt : float (optional)
            timestep in MDAnalysis units to write trajectory with;
            if `dt` is ``None``, time for a frame is set from the timestep;
            else, the time for a frame is `dt` * frame
        precision : float (optional)
            set precision of saved trjactory to this number of decimal places.
        )convert_unitsdtN)superr   __init__	precision)selffilenamen_atomsr   r   r   kwargs	__class__s          d/srv/www/vhosts/g4struct/public_html/venv/lib/python3.11/site-packages/MDAnalysis/coordinates/XTC.pyr   zXTCWriter.__init__9   sO    2 	(i'g	
-:r	
 	
EK	
 	
 	
 #    c                 (   	 |j         }n># t          $ r1 	 |j        j         }n # t          $ r d}t          |          dw xY wY nw xY w|j                                        }| j        |j        }n| j        |j        z  }|j	        
                    d|j                  }|j        }| j        r.|                     |d          }|                     |d          }t          |          }d| j        z  }	| j                            |||||	           dS )a5  Write information associated with ``ag`` at current frame into trajectory

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

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


        .. versionchanged:: 1.0.0
           Added ability to use either AtomGroup or Universe.
        .. versionchanged:: 2.0.0
           Deprecated support for Timestep argument has now been removed.
           Use AtomGroup or Universe as an input instead.
        z-Input obj is neither an AtomGroup or UniverseNstepF)inplaceg      $@)tsAttributeError
trajectory	TypeError	positionscopy_dtr   framedataget
dimensions_convert_unitsconvert_pos_to_nativeconvert_dimensions_to_unitcellr	   r   _xdrwrite)
r   agr$   errmsgxyzr   r"   r.   boxr   s
             r   _write_next_framezXTCWriter._write_next_frameW   s>   &		2BB 	2 	2 	22]%! 2 2 2H''T12 	2 l!!87DD8bh&Dw{{628,,]
 	P,,S%,@@C<<R<OOJ
++ $.(		S$i88888s!   
 
A"A?AA)TNr   )__name__
__module____qualname____doc__format
multiframeunitsr   _filer   r8   __classcell__)r   s   @r   r   r   *   s          FJT**EE # # # # # #</9 /9 /9 /9 /9 /9 /9r    r   c                   6    e Zd ZdZdZdddZeZeZ	d	dZ
d ZdS )
	XTCReadera  Reader for the Gromacs XTC trajectory format.

    XTC is a compressed trajectory format from Gromacs. The trajectory is saved
    with reduced precision (3 decimal places) compared to other lossless
    formarts like TRR and DCD. The main advantage of XTC files is that they
    require significantly less disk space and the loss of precision is usually
    not a problem.

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



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

        versionadded:: 2.4.0
            XTCReader implements this method so that it can use
            read_direct_x method of XTCFile to read the data directly
            into the timestep rather than copying it from a temporary array.
        r   z"trying to go over trajectory limit)_framen_framesIOErrorerrnoEIOr$   has_positionsr2   read_direct_xr(   read_frame_to_ts)r   r$   r+   s      r   _read_next_timestepzXTCReader._read_next_timestep   s     ;$-!+++%)%IJJJ:B 	%I++BL99EEINN$$Eq%$$$	r    c                    | j         |_        | j        d         }||j        |_        n| j         |z  |_        |j        |j        d<   t          |j         |_        | j	        |j
        | j	                 |_        n|j
        |_        | j        rC|                     |j                   |j        "|                     |j        dd                    |S )z%convert a xtc-frame to a mda TimeStepr   Nr"   r   )rE   r+   _kwargsr   r"   r,   r
   r7   r.   _subxr(   r   convert_pos_from_native)r   r+   r$   r   s       r   rM   zXTCReader._frame_to_ts   s    ;\$:jBGGkB&BG*%uy19  749-BLL 7BL 	@((666}(,,R]2A2->???	r    )N)r9   r:   r;   r<   r=   r?   r   _writerr   r@   rN   rM    r    r   rC   rC      s_         " FT**EGE   *    r    rC   )r<   rH    r   XDRr   r   lib.formats.libmdaxdrr   lib.mdamathr	   r
   r   rC   rU   r    r   <module>rZ      s   .
 
        - - - - - - - - + + + + + + : : : : : : : :\9 \9 \9 \9 \9 \9 \9 \9~@ @ @ @ @ @ @ @ @ @r    