
     i                         d 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mZmZmZmZmZmZmZmZmZmZmZ 	 ddlZdZn# e$ r d	ZY nw xY w G d
 de          ZdS )a)  GSD topology parser
=========================

.. versionadded:: 0.17.0

The :class:`GSDParser` generates a topology from HOOMD_ GSD topology/trajectory
files. The GSD file stores information on both the topology and the trajectory
in the same file, and allows for varying atom numbers/identities and topologies
during the course of the simulation. At the moment MDAnalysis can deal only
with the case in which there is no variation. The trajectory data are read with
the :class:`~MDAnalysis.coordinates.GSD.GSDReader` class.

.. _HOOMD: http://codeblue.umich.edu/hoomd-blue/index.html
.. _HOOMD GSD: https://github.com/glotzerlab/gsd


To load a GSD HOOMD file::

   import MDAnalysis as mda
   u = mda.Universe("example.gsd")


Classes
-------

.. autoclass:: GSDParser
   :members:
   :inherited-members:

    N   )TopologyReaderBase   )Topology)	Atomtypes	AtomnamesAtomidsAnglesBondsCharges	Dihedrals	ImpropersMassesRadiiResidsResnumsResnamesSegidsTFc                   ,     e Zd ZdZdZ fdZd Z xZS )	GSDParsera  Parses a Hoomd GSD file to create a Topology

    Reads the following Attributes:
     - Atomtypes
     - Bonds
     - Angles
     - Dihedrals
     - Impropers
     - Radii
     - Masses

    The GSD file also stores a `body` property in the particles, and the parser
    uses this information to set the residue names and indices.

    NOTE: if the `body` index of any particle is negative, the parser will add
    an integer number (the absolute value of the minimum of all the body
    indices) to all the body indices. This is because MDAnalysis cannot handle
    negative residue indices. This means that in that case the residue index in
    the MDAnalysis.Universe will not correspond to the body index stored in the
    GSD file.

    GSDc                     t           sd}t          |          t          t          |                               |           d S )NzGGSDParser: To read a Topology from a Hoomd GSD file, please install gsd)HAS_GSDImportErrorsuperr   __init__)selffilenameerrmsg	__class__s      g/srv/www/vhosts/g4struct/public_html/venv/lib/python3.11/site-packages/MDAnalysis/topology/GSDParser.pyr   zGSDParser.__init__n   sI     	&+  f%%%i''11111    c                    i }t           j                            | j        d          5 }|d         }|j        j        }|j        j        fd|j        j        D             }t          |          |k    rt          d          t          t          j        |t                              |d<   |j        }t          t          j        |j        dz  t          j                            |d	<   t#          t          j        |j        t          j                            |d
<   t)          t          j        |j        t          j                            |d<   dt,          fdt.          fdt0          fdt2          ffD ]?\  }}		 t5          ||          }
d |
j        D             }n	#  g }Y nxY w |	|          ||<   @|j        j                            t          j                  }t          j        |                              t          j                   }|dk     !                                r&|"                                }|tG          |          z  }t          j        |                              t          j                   }|j$        }ddd           n# 1 swxY w Y   tK          |&                                          }|'                    tQ          t          j        |t                                         |'                    tS          t          j*        |          dz                        |'                    tW          |                     |'                    tY          |                     |'                    t[          |                     |'                    t]          t          j        dgt                                         t_          ||d||          }|S )z?Parse Hoomd GSD file

        .. versionadded:: 0.17.0
        r)moder   c                      g | ]
}|         S  r'   ).0idxptypess     r!   
<listcomp>z#GSDParser.parse.<locals>.<listcomp>   s    CCCcfSkCCCr"   z&Number of types does not equal natoms.)dtypetypesg       @diametermasschargebondsangles	dihedrals	impropersc                 ,    g | ]}t          |          S r'   )tuple)r(   
b_instances     r!   r+   z#GSDParser.parse.<locals>.<listcomp>   s     JJJ*E*--JJJr"   Nr   SYSTEM)attrsatom_resindex)0gsdhoomdopenr   	particlesNr-   typeidlenIOErrorr   nparrayobjectr   r.   float32r   r/   float64r   r0   r   r
   r   r   getattrgroupbodyastypeint64uniqueint32anyminabssizelistvaluesappendr   r	   aranger   r   r   r   r   )r   kwargsr9   tsnapnatomsatypespattrnameattrvalvalsblistbodiesmnbodiestopr*   s                    @r!   parsezGSDParser.parsex   s   
 Y^^DM^44 /	" Q4D^%F^)FCCCCT^-BCCCF6{{f$$FGGG&rxf'E'E'EFFE'N A %c)<<<! !E* #28AF"*#E#E#EFFE&M%bhqxrz&J&J&JKKE(O % 6"i(i(	- - !$11CJJ	JJJDDDDD"&$t**h N'..rx88EYu%%,,RX66F 	    IIKKQYu%%,,RX66FkG_/	" /	" /	" /	" /	" /	" /	" /	" /	" /	" /	" /	" /	" /	" /	"b U\\^^$$Yrxf===>>???WRYv..233444VF^^$$$WV__%%%Xf%%&&&VBHhZv>>>??@@@vweLLL
s+   EJ!F#"J#F)'C$JJJ)__name__
__module____qualname____doc__formatr   rf   __classcell__)r    s   @r!   r   r   T   s_         . F2 2 2 2 2B B B B B B Br"   r   )rj   osnumpyrC   baser   core.topologyr   core.topologyattrsr   r   r	   r
   r   r   r   r   r   r   r   r   r   r   	gsd.hoomdr;   r   r   r   r'   r"   r!   <module>rs      si  0 < 
			     $ $ $ $ $ $ $ $ $ $ $ $                               " GG    GGGf f f f f" f f f f fs   ? A	A	