
     i%                         d Z ddlmc m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mZmZmZmZmZmZmZmZmZmZ  G d	 d
e
          ZdS )a  
HOOMD XML topology parser
=========================

.. versionadded:: 0.11.0

The :class:`HoomdXMLParser` generates a topology from files for the HOOMD_ code.

Read a list of atoms from a `HOOMD XML`_ file to build a basic topology.
Masses and charges are set to zero if not present in the XML file.
Hoomd XML does not identify molecules or residues, so placeholder values
are used for residue numbers.
Bonds and angles are read if present.

.. _HOOMD: http://codeblue.umich.edu/hoomd-blue/index.html
.. _HOOMD XML: http://codeblue.umich.edu/hoomd-blue/doc/page_xml_file_format.html

Classes
-------

.. autoclass:: HoomdXMLParser
   :members:
   :inherited-members:

    N   )openany   )TopologyReaderBase)Topology)	AtomtypesAtomidsAnglesBondsCharges	Dihedrals	ImpropersMassesRadiiResidsResnumsSegidsc                       e Zd ZdZdZd ZdS )HoomdXMLParserzParses a Hoomd XML file to create a Topology

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

    XMLc                    t          | j                  5 }t          j        |          }ddd           n# 1 swxY w Y   |                                }|                    d          }t          |                    d                    }i }|                    d          }|j        	                                
                    d          }	t          |	          |k    rt          d          t          t          j        |	t                               |d<   d	t"          d
 t          j        fdt&          t(          t          j        fdt,          t(          t          j        ffD ]}\  }
}}	 |                    |
          }fd|j        	                                
                                D             } |t          j        ||                    ||
<   w#  Y {xY wdt.          fdt0          fdt2          fdt4          ffD ]i\  }
}	 |                    |
          }d |j        	                                
                    d          D             }n	#  g }Y nxY w ||          ||
<   jd|vr$t'          t          j        |                    |d<   d|vr0t-          t          j        |t          j                            |d<   t9          |                                          }|                    t?          t          j         |          dz                        |                    tC          t          j        dg                               |                    tE          t          j        dg                               |                    tG          t          j        dgt                                          tI          |dd|          }|S )a  Parse Hoomd XML file

        Hoomd XML format does not contain a node for names. The parser will
        look for a name node anyway, and if it doesn't find one, it will use
        the atom types as names. If the Hoomd XML file doesn't contain a type
        node (it should), then all atom types will be 'none'. Similar to the
        names, the parser will try to read atom type, mass, and charge from the XML
        file, but it will use placeholder values if they are not present.

        Because Hoomd uses unitless mass, charge, etc., if they are not present
        they will not be guessed - they will be set to zero.


        .. versionadded:: 0.11.0
        Nconfigurationnatomstype
z&Number of types does not equal natoms.)dtypetypesdiameterc                 &    t          |           dz  S )Ng       @)float)xs    l/srv/www/vhosts/g4struct/public_html/venv/lib/python3.11/site-packages/MDAnalysis/topology/HoomdXMLParser.py<lambda>z&HoomdXMLParser.parse.<locals>.<lambda>v   s    %((S.     masschargec                 &    g | ]} |          S  r(   ).0elmappers     r"   
<listcomp>z(HoomdXMLParser.parse.<locals>.<listcomp>|   s!    FFFrr

FFFr$   bondangledihedralimproperc                     g | ]I}|                                 t          d  |                                dd         D                       JS )c              3   4   K   | ]}t          |          V  d S )N)int)r)   r*   s     r"   	<genexpr>z2HoomdXMLParser.parse.<locals>.<listcomp>.<genexpr>   s(      ==b#b''======r$   r   N)striptuplesplit)r)   lines     r"   r,   z(HoomdXMLParser.parse.<locals>.<listcomp>   s^       zz||==DJJLL,<=====  r$   r   SYSTEM)attrs)%r   filenameETparsegetrootfindr3   gettextr5   r7   lenIOErrorr   nparrayobjectr   float32r   r    float64r   r   r
   r   r   zeroslistvaluesappendr	   aranger   r   r   r   )selfkwargsstreamtreerootr   r   r:   atypeatypesattrnameattrr   valvalstopr+   s                   @r"   r=   zHoomdXMLParser.parseW   s     T]## 	$v8F##D	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$||~~		/22]&&x0011""6**!!##))$//v;;&  BCCC"28F&#A#A#ABBg  8 8"*EVUBJ/wrz2.
 	D 	D)HdFE
D#((22FFFFSX^^-=-=-C-C-E-EFFF #'$rxE'B'B'B"C"Ch UOf##	
	) 	) 
#((22  # 0 0 6 6t < <  
"d4jjE(OO"28F#3#344E&M5  %bhvRZ&H&H&HIIE(OU\\^^$$WRYv..233444VBHaSMM**+++WRXqc]]++,,,VBHhZv>>>??@@@vq!5111
s&   7;;.AGG!AIIN)__name__
__module____qualname____doc__formatr=   r(   r$   r"   r   r   G   s9          FL L L L Lr$   r   )r]   xml.etree.ElementTreeetreeElementTreer<   numpyrD   lib.utilr   baser   core.topologyr   core.topologyattrsr   r	   r
   r   r   r   r   r   r   r   r   r   r   r(   r$   r"   <module>rg      s9  0 2 # " " " " " " " "           $ $ $ $ $ $ $ $ $ $ $ $                            \ \ \ \ \' \ \ \ \ \r$   