
     in                     Z   d Z ddlZddlZddlmZ ddlmZmZm	Z	 ddl
mZmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlZdddddZ G d dej                  Z G d dej                  Z G d dej                  Z G d dej                  Z G d dej                  ZdS )u  LAMMPS DCD trajectory and DATA I/O  --- :mod:`MDAnalysis.coordinates.LAMMPS`
===============================================================================

Classes to read and write LAMMPS_ DCD binary trajectories, LAMMPS DATA files
and LAMMPS dump files.  Trajectories can be read regardless of
system-endianness as this is auto-detected.

LAMMPS can `write DCD`_ trajectories but unlike a `CHARMM trajectory`_
(which is often called a DCD even though CHARMM itself calls them
"trj") the time unit is not fixed to be the AKMA_ time unit (20 AKMA
is 0.978 picoseconds or 1 AKMA = 4.888821e-14 s) but can depend on
settings in LAMMPS. The most common case for biomolecular simulations
appears to be that the time step is recorded in femtoseconds (command
`units real`_ in the input file) and lengths in ångströms. Other cases
are unit-less Lennard-Jones time units.

This presents a problem for MDAnalysis because it cannot autodetect
the unit from the file. By default we are assuming that the unit for
length is the ångström and for the time is the femtosecond. If this is
not true then the user *should supply the appropriate units* in the
keywords *timeunit* and/or *lengthunit* to :class:`DCDWriter` and
:class:`~MDAnalysis.core.universe.Universe` (which then calls
:class:`DCDReader`).

Data file formats
-----------------

By default either the `atomic` or `full` atom styles are expected,
however this can be customised, see :ref:`atom_style_kwarg`.

Dump files
----------

The DumpReader expects ascii dump files written with the default
`LAMMPS dump format`_ of 'atom'


Example: Loading a LAMMPS simulation
------------------------------------

To load a LAMMPS simulation from a LAMMPS data file (using the
:class:`~MDAnalysis.topology.LAMMPSParser.DATAParser`) together with a
LAMMPS DCD with "*real*" provide the keyword *format="LAMMPS*"::

    >>> import MDAnalysis
    >>> from MDAnalysis.tests.datafiles import LAMMPSdata2, LAMMPSdcd2
    >>> u = MDAnalysis.Universe(LAMMPSdata2, LAMMPSdcd2, format="LAMMPS")

If the trajectory uses *units nano* then use

    >>> import MDAnalysis
    >>> from MDAnalysis.tests.datafiles import LAMMPSdata2, LAMMPSdcd2
    >>> u = MDAnalysis.Universe(LAMMPSdata2, LAMMPSdcd2, format="LAMMPS",
    ...                          lengthunit="nm", timeunit="ns")

To scan through a trajectory to find a desirable frame and write to a LAMMPS
data file,

   >>> import MDAnalysis
   >>> from MDAnalysis.tests.datafiles import LAMMPSdata2, LAMMPSdcd2
   >>> u = MDAnalysis.Universe(LAMMPSdata2, LAMMPSdcd2, format="LAMMPS",
   ...                          lengthunit="nm", timeunit="ns")
   >>> take_this_frame = False
   >>> for ts in u.trajectory:
   ...     # analyze frame
   ...     if ts.frame == 4:
   ...         take_this_frame = True
   ...     if take_this_frame == True:
   ...         with MDAnalysis.Writer('frame.data') as W:
   ...             W.write(u.atoms)
   ...         break

Note
----
Lennard-Jones units are not implemented. See :mod:`MDAnalysis.units`
for other recognized values and the documentation for the LAMMPS
`units command`_.

See Also
--------

   For further discussion follow the reports for `Issue 84`_ and `Issue 64`_.

.. _LAMMPS: https://www.lammps.org/
.. _write DCD: https://docs.lammps.org/dump.html
.. _CHARMM trajectory:
   http://www.charmm.org/documentation/c36b1/dynamc.html#%20Trajectory
.. _AKMA: http://www.charmm.org/documentation/c36b1/usage.html#%20AKMA
.. _units real: https://docs.lammps.org/units.html
.. _units command: https://docs.lammps.org/units.html
.. _`Issue 64`: https://github.com/MDAnalysis/mdanalysis/issues/64
.. _`Issue 84`: https://github.com/MDAnalysis/mdanalysis/issues/84
.. _`LAMMPS dump format`: https://docs.lammps.org/dump.html

Classes
-------

.. autoclass:: DCDReader
   :members:
   :inherited-members:
.. autoclass:: DCDWriter
   :members:
   :inherited-members:
.. autoclass:: DATAReader
   :members:
   :inherited-members:
.. autoclass:: DATAWriter
   :members:
   :inherited-members:
.. autoclass:: DumpReader
   :members:
   :inherited-members:

    N   )requires)utilmdamath	distances)cachedstore_init_arguments   )DCD)units)
DATAParser)NoDataError)baseBondsAngles	Dihedrals	Impropers)bondangledihedralimproperc                   .     e Zd ZdZdZdZdZ fdZ xZS )	DCDWriterzWrite a LAMMPS_ DCD trajectory.

    The units can be set from the constructor with the keyword
    arguments *timeunit* and *lengthunit*. The defaults are "fs" and
    "Angstrom". See :mod:`MDAnalysis.units` for other recognized
    values.
    LAMMPSTc                    ddd| _         |                    d| j         d                   | j         d<   |                    d| j         d                   | j         d<   | j                                         D ]T\  }}	 t           j        |         |k    rt	          d| d	|           2# t
          $ r d
| }t          |          d w xY w t          t          |           j	        |i | d S )NfsAngstromtimelengthtimeunitr   
lengthunitr    zLAMMPS DCDWriter: wrong unit  for unit type zLAMMPS DCDWriter: unknown unit )
r   popitems
unit_types	TypeErrorKeyError
ValueErrorsuperr   __init__)selfargskwargs	unit_typeuniterrmsg	__class__s         g/srv/www/vhosts/g4struct/public_html/venv/lib/python3.11/site-packages/MDAnalysis/coordinates/LAMMPS.pyr+   zDCDWriter.__init__   s-    
 

 $ZZ
DJv4FGG
6%zz,
88LMM
8#z//11 		3 		3OIt3#D)Y66#1 1 1%.1 1   7
  3 3 3A4AA ((d23 	(i'888888s   =+B)) C	)	__name__
__module____qualname____doc__format
multiframeflavorr+   __classcell__r2   s   @r3   r   r      sS          FJF9 9 9 9 9 9 9 9 9    r   c                   :     e Zd ZdZdZdZe fd            Z xZS )	DCDReaderaa  Read a LAMMPS_ DCD trajectory.

    The units can be set from the constructor with the keyword
    arguments *timeunit* and *lengthunit*. The defaults are "fs" and
    "Angstrom", corresponding to LAMMPS `units style`_ "**real**". See
    :mod:`MDAnalysis.units` for other recognized values.

    .. _units style: https://docs.lammps.org/units.html
    r   c                    ddd| _         |                    d| j         d                   | j         d<   |                    d| j         d                   | j         d<   | j                                         D ]Q\  }}	 t           j        |         |k    rt	          d| d	|           2# t
          $ r t          d
|           w xY w t          t          |           j	        |fi | d S )Nr   r   r   r!   r   r"   r    zLAMMPS DCDReader: wrong unit r#   zLAMMPS DCDReader: unknown unit )
r   r$   r%   r&   r'   r(   r)   r*   r?   r+   )r,   dcdfilenamer.   r/   r0   r2   s        r3   r+   zDCDReader.__init__   s1     
 

 $ZZ
DJv4FGG
6%zz,
88LMM
8#z//11 	K 	KOItK#D)Y66#1 1 1%.1 1   7
  K K K !I4!I!IJJJK'i'>>v>>>>>s   =+B))C)	r4   r5   r6   r7   r8   r:   r	   r+   r;   r<   s   @r3   r?   r?      sY          FF? ? ? ? ? ? ? ? ?r=   r?   c                   H     e Zd ZdZdZddddZe fd            Zd Z xZ	S )	
DATAReaderzReads a single frame of coordinate information from a LAMMPS DATA file.

    .. versionadded:: 0.9.0
    .. versionchanged:: 0.11.0
       Frames now 0-based instead of 1-based
    DATANr   zAngstrom/fs)r   r    velocityc                     |                     dd           }|t          d          |                     dd           | _         t          t          |           j        |fd|i| d S )Nn_atomsz#DATAReader requires n_atoms keyword
atom_style)r$   r)   rH   r*   rC   r+   )r,   filenamer.   rG   r2   s       r3   r+   zDATAReader.__init__   so    **Y--?BCCC **\488(j$(MM7MfMMMMMr=   c                    t          | j                  5 }|                    | j        | j        | j        | j                  | _        d d d            n# 1 swxY w Y   d| j        _        | j	        rR| 
                    | j        j                   	 |                     | j        j                   d S # t          $ r Y d S w xY wd S )Nr   )r   rI   read_DATA_timesteprG   	_Timestep
_ts_kwargsrH   tsframeconvert_unitsconvert_pos_from_native_posconvert_velocities_from_native_velocitiesAttributeError)r,   ps     r3   _read_first_framezDATAReader._read_first_frame   s   && 	!**dndot DG	 	 	 	 	 	 	 	 	 	 	 	 	 	 	
  	((66633G'     "   	 	s#   2AAAB2 2
C ?C )
r4   r5   r6   r7   r8   r   r	   r+   rW   r;   r<   s   @r3   rC   rC      sw          FZ]KKEN N N N N      r=   rC   c                   h    e Zd ZdZdZddZd Zd Zd Zd Z	d	 Z
 ed
d          dd            ZdS )
DATAWritera  Write out the current time step as a LAMMPS DATA file.

    This writer supports the sections Atoms, Masses, Velocities, Bonds,
    Angles, Dihedrals, and Impropers. This writer will write the header
    and these sections (if applicable). Atoms section is written in the
    "full" sub-style if charges are available or "molecular" sub-style
    if they are not. Molecule id is set to 0 for all atoms.

    Note
    ----
    This writer assumes "conventional" or "real" LAMMPS units where length
    is measured in Angstroms and velocity is measured in Angstroms per
    femtosecond. To write in different units, specify `lengthunit`

    If atom types are not already positive integers, the user must set them
    to be positive integers, because the writer will not automatically
    assign new types.

    To preserve numerical atom types when writing a selection, the Masses
    section will have entries for each atom type up to the maximum atom type.
    If the universe does not contain atoms of some type in
    {1, ... max(atom_types)}, then the mass for that type will be set to 1.

    In order to write bonds, each selected bond type must be explicitly set to
    an integer >= 1.

    rD   Tc                 x   t          j        |dd          | _        || _        ddd| _        |                    d| j        d                   | j        d<   |                    d	| j        d
                   | j        d
<   |                    d| j        d         dz   | j        d
         z             | j        d<   dS )zSet up a DATAWriter

        Parameters
        ----------
        filename : str
            output filename
        convert_units : bool, optional
            units are converted to the MDAnalysis base format; [``True``]
        dataT)extkeepr   r   r   r"   r    r!   r   velocityunit/rE   N)r   rI   rP   r   r$   )r,   rI   rP   r.   s       r3   r+   zDATAWriter.__init__&  s     hFFFF*"j99
%zz,
88LMM
8#ZZ
DJv4FGG
6!'DJx036F9KK"
 "

:r=   c                 `   | j                             d           | j                             d           | j                             d           	 |j        }d}n# t          t          f$ r d}Y nw xY w|j        dz   }|j                            t          j	                  }|
                    dt          j        t          |          t                              }| j        r|                     |j        d          }|rZt#          |||||          D ]D\  }	}
}}}|\  }}}| j                             |	d	d
|
d	d
|d	d
|dd
|dd
|dd
|dd           Ed S t#          ||||          D ]?\  }	}
}}|\  }}}| j                             |	d	d
|
d	d
|d	d
|dd
|dd
|dd           @d S )N
zAtoms
TFr
   molecule_tagdtypeinplaced fz.10f)ri   writechargesr   rU   indicestypesastypenpint32getzeroslenintrP   convert_pos_to_native	positionszip)r,   atomsr[   rk   has_chargesrl   rm   moltagscoordinatesindexmoltagatypechargecoordsxyzs                    r3   _write_atomszDATAWriter._write_atoms;  s}   TYT	mG KK ^, 	  	  	 KKK	 
 -!#""28,,((>28CJJc+J+J+JKK 	44 5  K  	8;%+9 9  4vuff !1a@ 5 5@ 5 5E@ 5 5f@ 5 545 5!"45 5*+45 5 5   	  14%1 1  ,vuf !1aRRRRRRERRRaRRRqRRRRRRR   	 s   A A0/A0c           
         | j                             d           | j                             d           | j                             d           |j        dz   }|                     |j        d          }t          ||          D ]H\  }}| j                             d                    ||d         |d         |d         	                     Id S )
Nra   zVelocities
r
   Fre   z!{i:d} {x:.10f} {y:.10f} {z:.10f}
r   r   )ir   r   r   )ri   rj   rl   convert_velocities_to_native
velocitiesrw   r8   )r,   rx   rl   r   r|   vels         r3   _write_velocitieszDATAWriter._write_velocitiesc  s    T^$$$T-!#66e 7 
 

 gz22 	 	JE3FLL4;;s1vQ3q6 <     	 	r=   c                    | j                             d           | j                             d           | j                             d           i }t          |j                            t
          j                            }t          d|dz             D ]}t          |j	        j
                            d                    |                    j                  }t          |          dk    rd||<   n|                                ||<   |rt!          d          |                                D ]3\  }}| j                             d                    ||                     4d S )	Nra   zMasses
r
   z	type {:d}r   g      ?zOLAMMPS DATAWriter: to write data file, atoms with same type must have same massz
{:d} {:f}
)ri   rj   maxrm   rn   ro   rp   rangesetuniverserx   select_atomsr8   massesrs   r$   r)   r%   )r,   rx   	mass_dictmax_typer~   r   masss          r3   _write_masseszDATAWriter._write_massesr  sa   TZ   T	u{))"(33441hl++ 	 	E$11&&u--  F
 6{{a#&	%  #)::<<	%   A  
 %??,, 	< 	<KE4FLL--eT::;;;;	< 	<r=   c           	         | j                             d           | j                             d                    t          |j                                      | j                             d           t          |t          dt          |          dz                       D ]\  }}	 | j                             d                    |t          |j	                            d
                    |j        j        dz                       t                              z   dz              # t          $ r d|j	         d}t          |          d w xY wd S )Nra   z{}
r
   z
{:d} {:d} rh   z7LAMMPS DATAWriter: Trying to write bond, but bond type z is not numerical.)ri   rj   r8   btype_sectionsbtyperw   r   rs   rt   typejoinrx   rl   rn   strr'   )r,   bondsr   r   r1   s        r3   _write_bondszDATAWriter._write_bonds  sK   TV]]>%+#>??@@@T5%3u::>":":;; 	2 	2GD!2 ''3ty>>::hh
 2Q 6>>sCCDDE   
  2 2 2: I: : :   ''T12	2 	2s   &A>D%%&Ec                 >   | j         r)|                     t          j        |          d          }| j                            d           | j                            d                    d|d         d                              | j                            d                    d|d         d                              | j                            d	                    d|d
         d
                              t          |d         d         |d
         d         |d
         d         g          rT| j                            d                    |d         d         |d
         d         |d
         d                              | j                            d           dS )zConvert dimensions to triclinic vectors, convert lengths to native
        units and then write the dimensions section
        Fre   ra   z{:f} {:f} xlo xhi
        r   z{:f} {:f} ylo yhi
r
   z{:f} {:f} zlo zhi
r   z{xy:f} {xz:f} {yz:f} xy xz yz
)xyxzyzN)rP   ru   r   triclinic_vectorsri   rj   r8   any)r,   
dimensionstrivs      r3   _write_dimensionszDATAWriter._write_dimensions  sp     	--)*55u .  D 	T*11#tAwqzBBCCC*11#tAwqzBBCCC*11#tAwqzBBCCCQ
DGAJQ
344 	FLL188Awqzd1gajT!WQZ 9    
 	Tr=   rm   r   Nc           
         |j         }||j        |          n|j        j        j        }|j        }	 |j                            t          j                   n # t          $ r d}t          |          dw xY w	 |j
        }d}n# t          t          f$ r d}Y nw xY wi }t          j        | j        d          5 | _        | j                            d           | j                            d           | j                            d                    t'          |                               g d	}	|	D ]~\  }
}|                    |          ||
<   | j                            d
                    t'          ||
                   |                     ||
                             |d          ||
<   | j                            d           | j                            d                    t-          |j                            t          j                                                 |                                D ]R\  }
}| j                            d                    t'          |                                          |
                     S|                     |j                   |                     |           |                     ||j        j        j                   |                                D ]-}|t'          |          dk    r|                     |           .|r|                     |           ddd           dS # 1 swxY w Y   dS )a  Write selection at current trajectory frame to file.

        The sections for Atoms, Masses, Velocities, Bonds, Angles,
        Dihedrals, and Impropers (if these are defined) are
        written. The Atoms section is written in the "full" sub-style
        if charges are available or "molecular" sub-style if they are
        not. Molecule id in atoms section is set to to 0.

        No other sections are written to the DATA file.
        As of this writing, other sections are not parsed into the topology
        by the :class:`DATAReader`.

        Note
        ----
        If the selection includes a partial fragment, then only the bonds,
        angles, etc. whose atoms are contained within the selection will be
        included.

        Parameters
        ----------
        selection : AtomGroup or Universe
            MDAnalysis AtomGroup (selection or Universe.atoms) or also Universe
        frame : int (optional)
            optionally move to frame number `frame`

        Nz=LAMMPS.DATAWriter: atom types must be convertible to integersTFwtz LAMMPS data file via MDAnalysis
ra   z{:>12d}  atoms
))r   r   )r   angles)r   	dihedrals)r   	impropersz{:>12d}  {}
)strictz{:>12d}  atom types
z{:>12d}  {} types
r   ) r   
trajectoryrN   rO   rx   rm   rn   ro   rp   r)   r   r   rU   r   openanyrI   ri   rj   r8   rs   __getattribute__atomgroup_intersectionr   r%   r   r   r   r   r[   valuesr   r   )r,   	selectionrO   urx   r1   r   has_velocitiesfeaturesattrsr   	attr_nameattrs                r3   rj   zDATAWriter.write  s   8 LLO)E 	/Krx(((( 	/ 	/ 	/  V$$$.	/	")J "NN ^, 	# 	# 	#"NNN	#
 \$-.. +	.$&FLL<===FLLFLL+223u::>>???  E %*   y"'"8"8"C"C#**3x+?+?KK   #+5/"H"H$ #I # # FLLFLL'..**284455     (~~//  t)00TZZ\\1B1BEJJ    ""5#3444u%%%eQ\_%9::: )) ( (<3t99>>!!$'''' .&&u---W+	. +	. +	. +	. +	. +	. +	. +	. +	. +	. +	. +	. +	. +	. +	. +	. +	. +	.s0   $A A37B BB6JMM
M
)TN)r4   r5   r6   r7   r8   r+   r   r   r   r   r   r   rj    r=   r3   rY   rY     s         8 F
 
 
 
*& & &P  < < <22 2 2$  ( Xgx  a. a. a. ! a. a. a.r=   rY   c                   8    e Zd ZdZdZg dZg dg dg dg ddZg d	Ze                                D ]Z	eee	         z  Ze
	 	 	 d fd	            Zd Ze ed          d                         Ze ed          d                         Zd Zd Zd Z xZS )
DumpReaderu@  Reads the default `LAMMPS dump format
    <https://docs.lammps.org/dump.html>`__

    Supports coordinates in the LAMMPS "unscaled" (x,y,z), "scaled" (xs,ys,zs),
    "unwrapped" (xu,yu,zu) and "scaled_unwrapped" (xsu,ysu,zsu) coordinate
    conventions (see https://docs.lammps.org/dump.html for more details).
    If `lammps_coordinate_convention='auto'` (default),
    one will be guessed. Guessing checks whether the coordinates fit each
    convention in the order "unscaled", "scaled", "unwrapped",
    "scaled_unwrapped" and whichever set of coordinates is detected first will
    be used. If coordinates are given in the scaled coordinate convention
    (xs,ys,zs) or scaled unwrapped coordinate convention (xsu,ysu,zsu) they
    will automatically be converted from their scaled/fractional representation
    to their real values.

    Supports both orthogonal and triclinic simulation box dimensions (for more
    details see https://docs.lammps.org/Howto_triclinic.html). In either case,
    MDAnalysis will always use ``(*A*, *B*, *C*, *alpha*, *beta*, *gamma*)``
    to represent the unit cell. Lengths *A*, *B*, *C* are in the MDAnalysis
    length unit (Å), and angles are in degrees.

    By using the keyword `additional_columns`, you can specify arbitrary data
    to be read. The keyword expects a list of the names of the columns or
    `True` to read all additional columns. The results are saved to
    :attr:`Timestep.data`. For example, if your LAMMPS dump looks like this

    .. code-block::

        ITEM: ATOMS id x y z q l
        1 2.84 8.17 -25 0.00258855 1.1
        2 7.1 8.17 -25 6.91952e-05 1.2

    Then you may parse the additional columns `q` and `l` via:

    .. code-block:: python

        u = mda.Universe('structure.data', 'traj.lammpsdump',
                         additional_columns=['q', 'l'])

    The additional data is then available for each time step via:

    .. code-block:: python

        for ts in u.trajectory:
            charges = ts.data['q'] # Access additional data, sorted by the id
            ls = ts.data['l']
        ...

    Parameters
    ----------
    filename : str
        Filename of LAMMPS dump file
    lammps_coordinate_convention : str (optional) default="auto"
        Convention used in coordinates, can be one of the following according
        to the `LAMMPS documentation <https://docs.lammps.org/dump.html>`__:

         - "auto" - Detect coordinate type from file column header. If auto
           detection is used, the guessing checks whether the coordinates
           fit each convention in the order "unscaled", "scaled", "unwrapped",
           "scaled_unwrapped" and whichever set of coordinates is detected
           first will be used.
         - "scaled" - Coordinates wrapped in box and scaled by box length (see
            note below), i.e., xs, ys, zs
         - "scaled_unwrapped" - Coordinates unwrapped and scaled by box length,
           (see note below) i.e., xsu, ysu, zsu
         - "unscaled" - Coordinates wrapped in box, i.e., x, y, z
         - "unwrapped" - Coordinates unwrapped, i.e., xu, yu, zu

        If coordinates are given in the scaled coordinate convention (xs,ys,zs)
        or scaled unwrapped coordinate convention (xsu,ysu,zsu) they will
        automatically be converted from their scaled/fractional representation
        to their real values.
    unwrap_images : bool (optional) default=False
        If `True` and the dump file contains image flags, the coordinates
        will be unwrapped. See `read_data
        <https://docs.lammps.org/read_data.html>`__  in the lammps
        documentation for more information.
    **kwargs
       Other keyword arguments used in
       :class:`~MDAnalysis.coordinates.base.ReaderBase`


    .. versionchanged:: 2.8.0
       Reading of arbitrary, additional columns is now supported.
       (Issue `#3504 <https://github.com/MDAnalysis/mdanalysis/issues/3504>`__)
    .. versionchanged:: 2.4.0
       Now imports velocities and forces, translates the box to the origin,
       and optionally unwraps trajectories with image flags upon loading.
    .. versionchanged:: 2.2.0
       Triclinic simulation boxes are supported.
       (Issue `#3383 <https://github.com/MDAnalysis/mdanalysis/issues/3383>`__)
    .. versionchanged:: 2.0.0
       Now parses coordinates in multiple lammps conventions (x,xs,xu,xsu)
    .. versionadded:: 0.19.0
    
LAMMPSDUMP)autounscaledscaled	unwrappedscaled_unwrapped)r   r   r   )xsyszs)xuyuzu)xsuysuzsu)r   r   r   r   )idvxvyvzfxfyfzr   FNc                     t          t          |           j        |fi | t          j                            | j                  \  }}|| j        v r|| _        n5dd	                    | j                  z   dz   }t          d| d|           || _        t          j        |          s||du r|| _        nt          d| d          i | _        |                                  |                                  d S )N'z', 'zlammps_coordinate_convention='z.' is not a valid option. Please choose one of Tzadditional_columns=z[ is not a valid option. Please provide an iterable containing the additionalcolumn headers.)r*   r   r+   ospathsplitextrI   _conventionslammps_coordinate_conventionr   r)   _unwrapr   iterable_additional_columns_cache_reopen_read_next_timestep)
r,   rI   r   unwrap_imagesadditional_columnsr.   rootr\   option_stringr2   s
            r3   r+   zDumpReader.__init__  s@    	)j$(<<V<<<G$$T]33	c'4+<<<0LD--&++d.?"@"@@3FM808 8 )68 8   % M,--	!)!T))'9D$$"&8 " " "     """""r=   c                     |                                   t          j        | j                  | _         | j        | j        fi | j        | _        d| j        _	        d S )N)
closer   anyopenrI   _filerL   rG   rM   rN   rO   r,   s    r3   r   zDumpReader._reopen  sN    

\$-00
 $.AAAAr=   rG   c                 "   t          j        | j                  5 }|                                 |                                 |                                 t	          |                                          }d d d            n# 1 swxY w Y   |S r   )r   r   rI   readlinert   )r,   ri   rG   s      r3   rG   zDumpReader.n_atoms  s     \$-(( 	(AJJLLLJJLLLJJLLL!**,,''G		( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(
 s   ABBBn_framesc                 \   | j         dz   }g }d}t          j        | j                  5 }d}|rG||z  s'|                    |                                           |                                }|dz  }|Gd d d            n# 1 swxY w Y   |d d         | _        t          | j                  S )N	   r   Tr
   r   )	rG   r   r   rI   appendtellr   _offsetsrs   )r,   lines_per_frameoffsetscounterri   lines         r3   r   zDumpReader.n_frames  s     ,*\$-(( 	AD 0 -NN16688,,,zz||1	  	 	 	 	 	 	 	 	 	 	 	 	 	 	 	  4=!!!s   AB  BBc                 \    t          | d          r| j                                         d S d S )Nr   )hasattrr   r   r   s    r3   r   zDumpReader.close  s8    4!! 	J	 	r=   c                     | j                             | j        |                    |dz
  | j        _        |                                 S )Nr
   )r   seekr   rN   rO   r   )r,   rO   s     r3   _read_framezDumpReader._read_frame  s<    
e,---	'')))r=   c                   +,- | j         }| j        }|xj        dz  c_        |j        t          |           k    rt          |                                 t          |                                          }||j        d<   ||j        z  |j        d<   |                                 t          |                                          }|| j	        k    rt          d          t          |                                                                          dk    }|rdt          t          |                                                                          \  }}}t          t          |                                                                          \  }	}
}t          t          |                                                                          \  }}}|t          d||||z             z
  }|t          d||||z             z
  }|	t          d|          z
  }|
t          d|          z
  }t!          j        dt           j                  }||z
  ddf|d	<   |||z
  df|d<   ||||z
  f|d
<   t'          j        | \  }}}}}}nt          t          |                                                                          \  }}t          t          |                                                                          \  }}t          t          |                                                                          \  }}||z
  }||z
  }||z
  }dx}x}}||||||f|_        t!          j        | j	        t                    }|                                }|                                d
d          ,d t-          ,          D             +i }| j                                        D ]'\  }}	 +fd|D             ||<   # t2          $ r Y $w xY w| j        r$	 +fddD             }n#  t          d          xY wt7          +fddD                       | _        | j        rd|_        +fddD             } t7          +fddD                       | _        | j        rd|_        +fddD             }!| j         dk    r9	 tC          |          d	         | _         n># tD          $ r t          d          w xY w| j         |vrt          d| j          d          || j                  }"| j        r|"#                    |           d+v }#| j$        du r(tK          ,          &                    | j'                  }$nQ| j$        rHt7          ,fd| j$        D                       stQ          j)        d           ,fd| j$        D             }$ng }$|$D ]#}%t!          j*        | j	                  |j        |%<   $tW          | j	                  D ]}&|                                                                -|#r-+d                  ||&<   t!          j,        -fd |"D             t           j-                  }'| j        r*|'d!d          }(|'d d!         }'|'|(|j        d d!         z  z  }'n
|'d d!         }'|'|j.        |&<   | j        r-fd"| D             |j/        |&<   | j        r-fd#|!D             |j0        |&<   |$D ]})-+|)                  |j        |)         |&<   
t!          j1        |          }*|j.        |*         |_.        | j        r|j/        |*         |_/        | j        r|j0        |*         |_0        |$D ]})|j        |)         |*         |j        |)<   | j         2                    d$          r$tg          j4        |j.        |j                  |_.        |xj.        t!          j,        |||g          d d d f         z  c_.        |S )%Nr
   stepr   zINumber of atoms in trajectory changed this is not supported in MDAnalysisr   r   )   r   rc   r   r   g     V@c                     i | ]\  }}||	S r   r   ).0r   r   s      r3   
<dictcomp>z2DumpReader._read_next_timestep.<locals>.<dictcomp>  s    <<<41a!Q<<<r=   c                      g | ]
}|         S r   r   r   r   attr_to_col_ixs     r3   
<listcomp>z2DumpReader._read_next_timestep.<locals>.<listcomp>  s+     1 1 1*+N1%1 1 1r=   c                      g | ]
}|         S r   r   r  s     r3   r  z2DumpReader._read_next_timestep.<locals>.<listcomp>$  s    LLLAnQ/LLLr=   )ixiyizz3Trajectory must have image flag in order to unwrap.c              3       K   | ]}|v V  	d S r   r   r  s     r3   	<genexpr>z1DumpReader._read_next_timestep.<locals>.<genexpr>*  s(      MMQQ.0MMMMMMr=   )r   r   r   Tc                      g | ]
}|         S r   r   r  s     r3   r  z2DumpReader._read_next_timestep.<locals>.<listcomp>-  s    FFFaq)FFFr=   c              3       K   | ]}|v V  	d S r   r   r  s     r3   r  z1DumpReader._read_next_timestep.<locals>.<genexpr>.  s(      OOqqN2OOOOOOr=   )r   r   r   c                      g | ]
}|         S r   r   r  s     r3   r  z2DumpReader._read_next_timestep.<locals>.<listcomp>1  s    HHH.+HHHr=   r   z"No coordinate information detectedz$No coordinates following convention z found in timestepr   c                     g | ]}|v S r   r   r   keyr   s     r3   r  z2DumpReader._read_next_timestep.<locals>.<listcomp>R  s    IIIuIIIr=   zPSome of the additional columns are not present in the file, they will be ignoredc                     g | ]}|v |	S r   r   r  s     r3   r  z2DumpReader._read_next_timestep.<locals>.<listcomp>W  s%       3%<<<<<r=   c                      g | ]
}|         S r   r   r   dimfieldss     r3   r  z2DumpReader._read_next_timestep.<locals>.<listcomp>e  s    333333r=   r   c                      g | ]
}|         S r   r   r  s     r3   r  z2DumpReader._read_next_timestep.<locals>.<listcomp>q  s    #D#D#DCF3K#D#D#Dr=   c                      g | ]
}|         S r   r   r  s     r3   r  z2DumpReader._read_next_timestep.<locals>.<listcomp>s  s    BBBsBBBr=   r   )5r   rN   rO   rs   EOFErrorr   rt   r[   dtrG   r)   splitmapfloatminr   ro   rr   float64r   triclinic_boxr   	enumerate_coordtype_column_namesr%   r(   r   all	_has_velsr   _has_forces
has_forcesr   list
IndexErrorextendr   r   
difference_parsable_columnswarningswarnemptyr   arrayfloat32rv   r   forcesargsort
startswithr   transform_StoR).r,   ri   rN   step_numrG   	triclinic	xlo_bound	xhi_boundr   	ylo_bound	yhi_boundr   zlozhir   xloxhiyloyhiboxxlenylenzlenalphabetagammarl   atomlineconvention_to_col_ixcv_namecv_col_names
image_colsvel_cols
force_cols
coord_colsidsadditional_keysr  r   r   imagesattribute_keyorderr  r   r  s.                                              @@@r3   r   zDumpReader._read_next_timestep  s   JW
A8s4yy  N	

qzz||$$""RU*	

ajjll##dl""6  
 

**,,--2	 	('*5!**,,2D2D2F2F'G'G$Iy"'*5!**,,2D2D2F2F'G'G$Iy"uajjll&8&8&:&:;;LCb c#r2rBw777Cc#r2rBw777Cc#rll*Cc#rll*C(6444C3YS(CFsC'CFS3Y&CF3:3H#3N0D$eT555!**,,"4"4"6"677HC5!**,,"4"4"6"677HC5!**,,"4"4"6"677HC9D9D9D#''E'D5dD%u<(4<s333::<<  $<<9U+;+;<<<!%)%A%G%G%I%I 	 	!G\1 1 1 1/;1 1 1$W--     < 	LLLL9KLLL

 L   MMMM:LMMMMM> 	G $BFFFF3EFFFHOOOO<NOOOOO 	I BMHHHH5GHHHJ
 ,66G 599M4N4N511  G G G !EFFFG26JJJI4I I I  
 *$*KL
< 	*j)))n$ #t++ "%jj33D4JKKOO% 
	!IIII0HIIIJJ 8     #7  OO !O" 	2 	2C8DL11BGCLL t|$$ 	 	AZZ\\''))F :#N4$89
X3333
3332:  F | $&2=!#444$BLO~ E#D#D#D#D8#D#D#Da  CBBBBzBBB	! "1  ,2"=1-&q))
 
7##|E*> 	1M%0BM 	)	%(BI - 	C 	CM%'W]%;E%BBGM"",77AA 	$3bm BL 	#sC11$'::	s*   O11
O>=O>	P P)0S S%)r   FN)r4   r5   r6   r7   r8   r   r"  r+  keysr  r	   r+   r   propertyr   rG   r   r   r   r   r;   r<   s   @r3   r   r     s       ^ ^@ F  L $OO$$$'''111	  CBB&++-- : :4S99 &,*# *# *# *# *# *#X   VI   X VJ" "  X"  * * *k k k k k k kr=   r   )r7   r   numpyro   core.groupsr   libr   r   r   lib.utilr   r	    r   r   topology.LAMMPSParserr   
exceptionsr   r   r,  r   r   r?   SingleFrameReaderBaserC   
WriterBaserY   
ReaderBaser   r   r=   r3   <module>ra     s  2q qd 
			     " " " " " " * * * * * * * * * * 3 3 3 3 3 3 3 3             . . . . . . $ $ $ $ $ $        	 9 9 9 9 9 9 9 9B? ? ? ? ? ? ? ?D! ! ! ! !+ ! ! !HL. L. L. L. L. L. L. L.^x x x x x x x x x xr=   