
     i\                         d 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
mZmZ ddlmZ  G d	 d
ej                  ZdS )a  
TXYZ file format --- :mod:`MDAnalysis.coordinates.TXYZ`
=======================================================

Coordinate reader for Tinker_ xyz files .txyz and trajectory .arc files.
Differences between Tinker format_ and normal xyz files:

- there is only one header line containing both the number of atoms and a comment
- column 1 contains atom numbers (starting from 1)
- column 6 contains atoms types
- the following columns indicate connectivity (atoms to which that particular atom is
  bonded, according to numbering in column 1)

.. _format: http://chembytes.wikidot.com/tnk-tut00#toc2
.. _Tinker: https://dasher.wustl.edu/tinker/


Classes
-------

.. autoclass:: TXYZReader
   :members:
   :inherited-members:

    N   )util   )base)openanycachedstore_init_arguments)Timestepc                        e Zd ZdZddgZdddZeZe fd            Z	e
 ed          d	                         Ze
 ed
          d                         Zd Zd ZddZd Zd Zd Z xZS )
TXYZReaderzReads from a TXYZ fileTXYZARCpsAngstrom)timelengthc                     t          t          |           j        |fi | t          j                            | j                  \  }}t          j        | j                  | _	        t                      | _        t          j        | j                  5 }|                                 |                                }	 t          |                                d                    d| _        n# t"          $ r
 d| _        Y nw xY wd d d            n# 1 swxY w Y    | j        | j        fi | j        | _        |                                  d S )Nr   TF)superr   __init__ospathsplitextfilenamer   anyopenxyzfiledict_cacher   readlinefloatsplitperiodic
ValueError	_Timestepn_atoms
_ts_kwargsts_read_next_timestep)selfr   kwargsrootextinpline	__class__s          e/srv/www/vhosts/g4struct/public_html/venv/lib/python3.11/site-packages/MDAnalysis/coordinates/TXYZ.pyr   zTXYZReader.__init__B   sl   (j$(<<V<<<
 G$$T]33	c|DM22ff\$-(( 		%CLLNNN<<>>D%djjll1o&&& !%  & & & %&		% 		% 		% 		% 		% 		% 		% 		% 		% 		% 		% 		% 		% 		% 		% !$.AAAA  """""s6   )D>'C-%D-D>D DDDDr$   c                     t          j        | j                  5 }|                                                                d         }ddd           n# 1 swxY w Y   t          |          S )znumber of atoms in a framer   N)r   r   r   r   r    int)r(   fns      r/   r$   zTXYZReader.n_atoms[   s     \$-(( 	(A

""$$Q'A	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 1vvs   -AAAn_framesc                 N    	 |                                  S # t          $ r Y dS w xY w)Nr   )_read_xyz_n_framesIOErrorr(   s    r/   r4   zTXYZReader.n_framesd   s;    	**,,, 	 	 	11	s    
$$c                 d   | j         dz   }| j        r|dz  }d}g }t          j        | j                  5 }d}|rG||z  s'|                    |                                           |                                }|dz  }|Gd d d            n# 1 swxY w Y   t          ||z            }|| _	        |S )Nr   r   T)
r$   r!   r   r   r   appendtellr   r1   _offsets)r(   linesPerFramecounteroffsetsr2   r-   r4   s          r/   r6   zTXYZReader._read_xyz_n_framesl   s    q(= 	QM\$-(( 	AD . -NN16688,,,zz||1	  	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 w.//s   ABBBc                     | j                             | j        |                    |dz
  | j        _        |                                 S )Nr   )r   seekr<   r&   framer'   )r(   rB   s     r/   _read_framezTXYZReader._read_frame   s>    $-.///	'')))    Nc                    || j         }| j        }	 |                                 | j        r+|                                                                |_        g }t          | j                  D ]C}|                    |                                                                dd                    D||_	        |xj
        dz  c_
        |S # t          t          f$ r}t          |          d d }~ww xY w)Nr      r   )r&   r   r   r!   r    
dimensionsranger$   r:   	positionsrB   r"   
IndexErrorEOFError)r(   r&   r2   tmp_bufierrs         r/   r'   zTXYZReader._read_next_timestep   s    :BL	*JJLLL} 5 !

 2 2 4 4G4<(( : :qzz||1133AaC89999"BLHHMHHIJ' 	* 	* 	*3--T)	*s   B8C C1C,,C1c                 V    |                                   |                                  d S N)closeopen_trajectoryr8   s    r/   _reopenzTXYZReader._reopen   s'    

rD   c                     | j          t          t          j        d| j                  t          j        | j                  | _         | j        }d|_        | j         S )NzTXYZ file already opened)	r   r7   errnoEALREADYr   r   r   r&   rB   )r(   r&   s     r/   rR   zTXYZReader.open_trajectory   sU    <# :DM   |DM22 W|rD   c                 X    | j         dS | j                                          d| _         dS )z)Close arc trajectory file if it was open.N)r   rQ   r8   s    r/   rQ   zTXYZReader.close   s.    <FrD   rP   )__name__
__module____qualname____doc__formatunitsr
   r#   r	   r   propertyr   r$   r4   r6   rC   r'   rS   rR   rQ   __classcell__)r.   s   @r/   r   r   :   s#         e_FZ00EI# # # # #0 VI   X VJ   X  ,* * *
* * * *,          rD   r   )r\   numpynpr   rV   libr    r   lib.utilr   r   r	   timestepr
   
ReaderBaser    rD   r/   <module>ri      s   . 2     				              < < < < < < < < < <      z z z z z z z z z zrD   