
     i?                         d Z ddlZddlZddl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mZ ddlZ ej        d	          Z G d
 dej                  ZdS )a  GROMOS11 trajectory reader --- :mod:`MDAnalysis.coordinates.TRC`
====================================================================

Reads coordinates, timesteps and box-sizes from GROMOS11 TRC trajectories.

To load the trajectory into :class:`~MDAnalysis.core.universe.Universe`,
you need to provide topology information using a topology file such as
a PDB::

    import MDAnalysis as mda
    u = mda.Universe("topology.pdb", ["md_1.trc.gz","md_2.trc.gz"],
    continuous=True)

.. Note::
   The GROMOS trajectory format organizes its data in blocks. A block starts
   with a blockname in capital letters (example: POSITIONRED) and ends with
   a line containing only ''END''. Only the TITLE-block at the beginning of
   each file is mandatory, others blocks can be chosen depending on the task.

   The trajectory format as well as all permitted blocks and their data are
   documented in the GROMOS Manual Vol. 4, chapter 2 and 4.
   The manual can be downloaded here:
   https://gromos.net/gromos11_pdf_manuals/vol4.pdf

This reader is designed to read the blocks "TIMESTEP", "POSITIONRED" and
"GENBOX" from the trajectory which covers the standard trajectories of most
simulations . If a trajectory includes other blocks, a warning is served
and the blocks are ignored.

.. Note::
   MDAnalysis requires the blocks to be in the same order for each frame
   and ignores non-supported blocks.



Classes
-------

.. autoclass:: TRCReader
   :members:

    N   )base)Timestep   )util)cachedstore_init_argumentszMDAnalysis.coordinates.GROMOS11c                        e Zd ZdZdZdddZeZg dZg dZ	e
d fd		            Ze ed
          d                         Ze ed          d                         Zd Zd Zd Zd Zd Zd Zd Zd Z xZS )	TRCReaderz)Coordinate reader for the GROMOS11 formatTRCpsnm)timelength)TITLETIMESTEPPOSITIONREDGENBOX)POSITIONREFPOSITIONVELOCITYVELOCITYRED	FREEFORCEFREEFORCERED	CONSFORCECONSFORCEREDSHAKEFAILPOSITIONSHAKEFAILPREVPOSITIONLATTICESHIFTSCOSDISPLACEMENTSSTOCHINTNHCVARIABLESROTTRANSREFPOSPERTDATADISRESEXPAVEJVALUERESEXPAVEJVALUERESEPSJVALUEPERSCALEORDERPARAMRESEXPAVEXRAYRESEXPAVELEUSBIASLEUSBIASBASENERGY03VOLUMEPRESSURE03FREEENERGYDERIVS03BFACTORAEDSSTc                 0    t          t          |           j        |fi | t          j        | j                  j        }|dd          dk    s|dd          dk    rd | _        n|dd          | _        t          j	        | j                  | _
        || _        |                                 | _        i | _         | j        | j        fi | j        | _        |                                  | j        d         | j        _        |                     d           d S )Nr   trctrjdtr   )superr   __init__pathlibPathfilenamesuffix
compressedr   anyopentrcfileconvert_units_read_traj_propertiestraj_properties_cache	_Timestepn_atoms
_ts_kwargsts_reopenr5   _read_frame)selfr:   r?   kwargsext	__class__s        d/srv/www/vhosts/g4struct/public_html/venv/lib/python3.11/site-packages/MDAnalysis/coordinates/TRC.pyr7   zTRCReader.__init__{   s
   'i';;F;;; l4=))0Gu#abb'U"2"2"DOO!!""gDO|DM22*  $99;; $.AAAA)$/
    rD   c                     | j         d         S )z!The number of atoms in one frame.rD   rA   rI   s    rM   rD   zTRCReader.n_atoms   s     #I..rN   n_framesc                     | j         d         S )z'The number of frames in the trajectory.rR   rP   rQ   s    rM   rR   zTRCReader.n_frames   s     #J//rN   c                 N   | j         |_        |d         |_        |d         |j        d<   |d         |j        d<   |d         |_        |d         |_        | j        rJ|j        r|                     |j                   |j        "|                     |j        dd                    |S )z&Convert a frame to a :class:`TimeStep`r   step
dimensions	positionsN   )	_frameframer   datarV   rW   r?   has_positionsconvert_pos_from_native)rI   frameDatrF   s      rM   _frame_to_tszTRCReader._frame_to_ts   s    ;6""6*"6* .,  	@ ;,,R\:::}(,,R]2A2->???	rN   c                 Z   i }d}t          j        | j                  5 }t          |j        d          D ].}|                                }|t          j        v r
|dk    r|} n/ddd           n# 1 swxY w Y   d}d}i }d|d<   d}	g }
g }t          j        | j                  5 }t          |j        d          D ]}|                                }||k    r<|
                    |	                                t          |          z
             |dz  }d|k    r~|                    t          |                                                                d                              |d	k    r,|                                                                }|d	k    ,d|k    r|dk    r|	                                t          |          z
  }|d	k    rX|                                }|                                }t          |                                          d
k    r|dz  }|d	k    X|	                                t          |          z
  }||z
  |d<   |	r4|d	k    r,|                                                                }|d	k    ,|	                                t          |          z
  }|                    |	                                t          |          z
  |d         z              |                                                                d	k    rVd}	d|j         d}t          j        |t"                     t$                              |           |                    |           	 ddd           n# 1 swxY w Y   |dk    r+d}t$                              |           t+          |          ||d<   ||d<   |
|d<   t          |          dk    r|d         |d         z
  |d<   n;d|d<   d}t          j        |t"                     t$                              |           |S )z
        * Reads the number of atoms per frame (n_atoms)
        * Reads the number of frames (n_frames)
        * Reads the startposition of the timestep block
          for each frame (l_blockstart_offset)
        N r   r   r   Fr   r   ENDrX   Tz,Inconsistent POSITIONRED block size in file z. Falling back to slow reader.z<No supported blocks were found within the GROMOS trajectory!rD   rR   l_blockstart_offsetr   r5   z0The trajectory does not contain TIMESTEP blocks!)r   r=   r:   iterreadlinestripr   SUPPORTED_BLOCKSappendtelllenfloatsplitseeknamewarningswarnUserWarningloggerwarningerror
ValueError)rI   rA   first_blockflinestripped_linerD   frame_counter
block_sizeinconsistent_sizerc   l_timestep_timevaluesstartendcurrent_poswarnmsgerrormsgs                    rM   r@   zTRCReader._read_traj_properties   s    
 \$-(( 		AQZ,,   $

 I$>>>!W,, #0KE		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 
$(
=!!  "\$-(( A	0AQZ,, @0 @0 $

 -//'..qvvxx#d))/CDDD!Q&M
 ..)00ajjll00221566   (500()

(:(:(<(< (500
 !M11 !|| !3t99 4+u44#$::<<D,0JJLLM"=#6#6#8#899Q>> '1	 ,u44
  ffhhT247%K
=11* 0+u44,-JJLL,>,>,@,@M ,u44 '(ffhhT&:FFHHs4yy0:m3LL   ::<<--//58804-&{UVU[&{&{&{G$M';???"NN7333FF;///A@0A	0 A	0 A	0 A	0 A	0 A	0 A	0 A	0 A	0 A	0 A	0 A	0 A	0 A	0 A	0F AN  LL"""X&&&%,	"&3
#1D-.$%%**%a(+@+CC D!! %&OD!HGM';///NN7###s%   AA//A36A3$KM==NNc                 V   i }t          | j                  |d<   t          d          |d<   t          j        | j        d         dft          j                  |d<   d |d<   d	| _        | j        }t          |j
        d
          D ]                                }d|k    rN|
                                                                \  }}t          |          |d<   t          |          |d<   kd|k    rd}g }	 |
                                }d|v rd|v rn|                    |           |dz  }9t          j        d
                    |          dt          j        | j        dz            }	|	                    dd          |d<   || j        d         k    rDd| d| j         d| j        d          }
t$                              |
           t)          |
          \d|k    rt          |
                                          }|dk    rd |d<   d	| _        n|dv ret+          t          |
                                                                          \  }}}t+          t          |
                                                                          \  }}}||||||g|d<   d| _        t-          d |
                                                                D                       dk    r+d}
t$                              |
           t)          |
          t-          d |
                                                                D                       dk    r+d}
t$                              |
           t)          |
          n+d}
t$                              |
           t)          |
           nut/          fd t0          j        D                       rNt0          j        D ]A}||k    r9|d!z   }t5          j        |t8                     t$                              |           B|S )"NrU   g        r   rD   rX   )dtyperW   rV   Fra   r   r   r   T#rb   r    )sepr   countzFound z atoms in step z, but expected r   )r   r   c              3   N   K   | ] }t          t          |                    V  !d S Nabsrk   .0vs     rM   	<genexpr>z6TRCReader._read_GROMOS11_trajectory.<locals>.<genexpr>y  .      HHaCaMMHHHHHHrN   g|=z.This reader doesnt't support a shifted origin!c              3   N   K   | ] }t          t          |                    V  !d S r   r   r   s     rM   r   z6TRCReader._read_GROMOS11_trajectory.<locals>.<genexpr>  r   rN   z<This reader doesnt't support yawed, pitched or rolled boxes!zLThis reader does't support truncated-octahedral periodic boundary conditionsc              3       K   | ]}|v V  	d S r    )r   non_supp_bnrx   s     rM   r   z6TRCReader._read_GROMOS11_trajectory.<locals>.<genexpr>  s<         t#     rN   z block is not supported!)intrY   rk   npzerosrA   float64periodicr>   rd   re   rf   rl   rh   
fromstringjoinrD   reshaperr   rt   ru   mapsumanyr   NOT_SUPPORTED_BLOCKSro   rp   rq   rs   )rI   r^   rw   ry   tmp_steptmp_timeibuffer
coords_strr[   r   ntb_settingtmp_atmp_btmp_c	tmp_alphatmp_beta	tmp_gammar   r   rx   s                       @rM   _read_GROMOS11_trajectoryz#TRCReader._read_GROMOS11_trajectory4  s`   t{++ :: "!),a0
!
 !
 !
 "& LR(( Y	0 Y	0D JJLLM]**%&ZZ\\%7%7%9%9"(#&x== #(??  -//!"Jj(( *,,j111Q }GGFOO*,*	   )-R(;(;%,Y777www$+wwVZVjktVuwwHLL***$X... 8
 ]**!!**,,//!##-1H\*$)DMM F***-eQZZ\\5G5G5I5I*J*J'E5%58qzz||11336 62Ix ! !.H\* %)DM HH1::<<3E3E3G3GHHHHH    M ! X...(222 HH1::<<3E3E3G3GHHHHH    $bX...(222   nHLL***$X...    #,#A     0 $-#A 0 0K"m33"-0J"J g{;;;w///rN   c                     |dz
  | _         | j                            | j        d         |         dz
  d           |                                 S )zread frame ir   rc   r   r   )rY   r>   rm   rA   _read_next_timestep)rI   r   s     rM   rH   zTRCReader._read_frame  sU    !e 	 !67:Q>	
 	
 	
 '')))rN   c                    | xj         dz  c_         | j         | j        k    r+d}t                              |           t	          |          |                                 }|                     || j                   | j        S )Nr   z"Trying to go over trajectory limit)rY   rR   rr   rt   IOErrorr   r_   rF   )rI   r   raw_framedatas      rM   r   zTRCReader._read_next_timestep  sv    q;$-'';HLL"""(###6688-111wrN   c                 V    |                                   |                                  dS )zClose and reopen the trajectoryN)closeopen_trajectoryrQ   s    rM   rG   zTRCReader._reopen  s'    

rN   c                    | j         =t          j        d| j        f}t                              |           t          |          t          j        | j                  | _          | j	        | j
        fi | j        | _        d| _        | j         S )NzTRC file already openedr   )r>   errnoEALREADYr:   rr   rt   r   r   r=   rC   rD   rE   rF   rY   )rI   r   s     rM   r   zTRCReader.open_trajectory  s    <#~'@$-OHLL"""(### |DM22 !$.AAAA |rN   c                 X    | j         "| j                                          d| _         dS dS )z-Close the trc trajectory file if it was open.N)r>   r   rQ   s    rM   r   zTRCReader.close  s1    <#L   DLLL $#rN   )T)__name__
__module____qualname____doc__formatunitsr   rC   rg   r   r	   r7   propertyr   rD   rR   r_   r@   r   rH   r   rG   r   r   __classcell__)rL   s   @rM   r   r   S   sf       33FT**EIEEE  @      2 VI/ /  X/ VJ0 0  X0  (} } }~g g gR	* 	* 	*
 
 
  
  "             rN   r   )r   r8   r   ro   numpyr   ra   r   timestepr   libr   lib.utilr   r	   logging	getLoggerrr   
ReaderBaser   r   rN   rM   <module>r      s   2) )V                          3 3 3 3 3 3 3 3 		<	=	={  {  {  {  {  {  {  {  {  { rN   