
     i52                         d Z ddlZddlZddlZddlmZ ddlmZ  G d dej	                  Z
 G d	 d
ej                  ZdS )u  
PQR file format --- :mod:`MDAnalysis.coordinates.PQR`
=====================================================

Read atoms with charges from a PQR_ file (as written by PDB2PQR_). The
following is adopted from the description of the PQR_ format as used by APBS_:

*MDAnalysis* reads very loosely-formatted PQR files: all fields are
**whitespace-delimited** rather than the strict column formatting mandated
by the PDB_ format. This more liberal formatting allows coordinates
which are larger/smaller than ±999 Å.

MDAnalysis reads data on a per-line basis from PQR files using the following format::

   recordName serial atomName residueName chainID residueNumber X Y Z charge radius

If this fails it is assumed that the *chainID* was omitted and the shorter
format is read::

   recordName serial atomName residueName residueNumber X Y Z charge radius

Anything else will raise a :exc:`ValueError`.

The whitespace is the most important feature of this format: fields
*must* be separated by at least one space or tab character. The fields
are:

*recordName*
    A string which specifies the type of PQR entry and should either be ATOM or
    HETATM.
*serial*
    An integer which provides the atom index (but note that MDAnalysis renumbers
    atoms so one cannot rely on the *serial*)
*atomName*
    A string which provides the atom name.
*residueName*
    A string which provides the residue name.
*chainID*
    An optional string which provides the chain ID of the atom.
*residueNumber*
    An integer which provides the residue index.
*X Y Z*
    Three floats which provide the atomic coordiantes.
*charge*
    A float which provides the atomic charge (in electrons).
*radius*
    A float which provides the atomic radius (in Å).

Clearly, this format can deviate wildly from PDB_ due to the use of whitespaces
rather than specific column widths and alignments. This deviation can be
particularly significant when large coordinate values are used.

Output should look like this (although the only real requirement is
*whitespace* separation between *all* entries). The chainID is optional
and can be omitted::

  ATOM      1  N    MET     1     -11.921   26.307   10.410 -0.3000 1.8500
  ATOM     36  NH1  ARG     2      -6.545   25.499    3.854 -0.8000 1.8500
  ATOM     37 HH11  ARG     2      -6.042   25.480    4.723  0.4600 0.2245


.. Warning:: Fields *must be white-space separated* or data are read
             incorrectly. PDB formatted files are *not* guaranteed to be
             white-space separated so extra care should be taken when quickly
             converting PDB files into PQR files using simple scripts.

For example, PQR files created with PDB2PQR_ and the `--whitespace`
option are guaranteed to conform to the above format::

   pdb2pqr --ff=charmm --whitespace 4ake.pdb 4ake.pqr


Notes
-----
The PQR format does not provide a means by which to provide box information.
In all cases the `dimensions` attribute will be set to `None`.


.. _PQR:     https://apbs.readthedocs.io/en/latest/formats/pqr.html
.. _APBS:    https://apbs.readthedocs.io/en/latest/
.. _PDB2PQR: https://pdb2pqr.readthedocs.io/en/latest/
.. _PDB:     http://www.wwpdb.org/documentation/file-format
    N   )util   )basec                   8    e Zd ZdZdZdddZddddZd	 Zd
 ZdS )	PQRReaderzRead a PQR_ file into MDAnalysis.

    .. _PQR:
        https://apbs.readthedocs.io/en/latest/formats/pqr.html

    .. versionchanged:: 0.11.0
       Frames now 0-based instead of 1-based
    PQRNAngstromtimelength))i)ORIGINAL
NO_CHAINIDGROMACSc                 ,   ddl m} d }g }t          j        | j                  5 }|D ]o}|                    d          rX|%|                    |          }| j        |         \  }}|                                }|	                    |||                    p	 d d d            n# 1 swxY w Y   t          |          | _         | j        j        |fi | j        | _        d| j        _        | j        r!|                     | j        j                   d S d S )Nr   )	PQRParser)ATOMHETATMr   )topology.PQRParserr   r   openanyfilename
startswithguess_flavour_SLICE_INDICESsplitappendlenn_atoms	_Timestepfrom_coordinates
_ts_kwargstsframeconvert_unitsconvert_pos_from_native_pos)	selfr   flavourcoordspqrfilelinexyfieldss	            d/srv/www/vhosts/g4struct/public_html/venv/lib/python3.11/site-packages/MDAnalysis/coordinates/PQR.py_read_first_framezPQRReader._read_first_frame   sg   222222\$-(( 		/G / /??#566 /"+"9"9$"?"?#27;1!ZZ\\FMM&1+.../		/ 		/ 		/ 		/ 		/ 		/ 		/ 		/ 		/ 		/ 		/ 		/ 		/ 		/ 		/ 6{{1$.1&LLDOLL 	7((66666	7 	7s   A3B$$B(+B(c                     t          |fi |S )zReturns a PQRWriter for *filename*.

        Parameters
        ----------
        filename : str
            filename of the output PQR file

        Returns
        -------
        :class:`PQRWriter`
        )	PQRWriter)r*   r   kwargss      r2   WriterzPQRReader.Writer   s     ,,V,,,    )	__name__
__module____qualname____doc__formatunitsr   r3   r7    r8   r2   r   r   t   sg          FZ00E  N7 7 70- - - - -r8   r   c                   8    e Zd ZdZdZdddZdZdZdd	Zdd
Z	dS )r5   a  Write a single coordinate frame in whitespace-separated PQR format.

    Charges ("Q") are taken from the
    :attr:`MDAnalysis.core.groups.Atom.charge` attribute while
    radii are obtaine from the
    :attr:`MDAnalysis.core.groups.Atom.radius` attribute.

    * If the segid is 'SYSTEM' then it will be set to the empty
      string. Otherwise the first letter will be used as the chain ID.
    * The serial number always starts at 1 and increments sequentially
      for the atoms.

    The output format is similar to ``pdb2pqr --whitespace``.


    .. versionadded:: 0.9.0
    .. versionchanged:: 2.6.0
       Files are now written in `wt` mode, and keep extensions, allowing
       for files to be written under compressed formats
    r	   Nr
   r   zATOM {serial:6d} {name:<4}  {resname:<3} {chainid:1.1} {resid:4d}   {pos[0]:-8.3f} {pos[1]:-8.3f} {pos[2]:-8.3f} {charge:-7.4f} {radius:6.4f}
zREMARK   {0} {1}
Tc                     t          j        |dd          | _        || _        |                    dd          | _        dS )a  Set up a PQRWriter with full whitespace separation.

        Parameters
        ----------
        filename : str
             output filename
        convert_units: bool (optional)
            units are converted to the MDAnalysis base format; [``True``]
        remarks : str (optional)
             remark lines (list of strings) or single string to be added to the
             top of the PQR file
        pqrT)extkeepremarkszPQR file written by MDAnalysisN)r   r   r'   poprE   )r*   r   r'   r6   s       r2   __init__zPQRWriter.__init__   sC     hEEEE 	 zz)-MNNr8   c                 d   	 |j         }n # t          $ r d}t          |          dw xY w||j        |          n%	 |j        j        j        }n# t          $ r d}Y nw xY w|j        }|j        }| j        r| 	                    |           i }g }dt          j        d          fdt          j        d          fdt          j        d	          fd
t          j        d          fdt          j        d          ffD ]C\  }	}
	 t          ||	          ||	<   # t          $ r |
||	<   |                    |	           Y @w xY w	 |j        |d<   n,# t          $ r 	 |j        |d<   n# t          $ r Y nw xY wY nw xY wd|vst!          |d         dk              rt          j        d          |d<   d
|v rd}n|                                }|r;t%          j        d                    d                    |                               t-          j        | j        d          5 }t-          j        | j                  D ]0}|                    | j                            |d                     1|                    | j                            d                    ||j        j                  d                     |                    | j                            d                    |          d                     t;          t=          ||d         |d         |d         |d         |d
         |d                   d          D ]\\  }\  }}}}}}}t?          |          dk     rd|z   n|}|                    | j                             ||||||||                     ]	 ddd           dS # 1 swxY w Y   dS )a  Write selection at current trajectory frame to file.

        Parameters
        ----------
        selection : AtomGroup or Universe
            MDAnalysis AtomGroup or Universe
        frame : int (optional)
            optionally move to frame index `frame`; by default, write the
            current frame


        .. versionchanged:: 0.11.0
           Frames now 0-based instead of 1-based

        z-Input obj is neither an AtomGroup or UniverseNr   names)Xresnames)UNKresids)r   charges)        radii)g      ?chainidsSYSTEM) rO   zlSupplied AtomGroup was missing the following attributes: {miss}. These will be written with default values. z, )misswtr   zInput: frame {0} of {1}   ztotal charge: {0:+8.4f} e   )start   rS   )serialnameresnamechainidresidposchargeradius)!universeAttributeError	TypeError
trajectoryr%   r&   atoms	positionsr'   convert_pos_to_native	itertoolscyclegetattrr   rQ   segidsalltotal_chargewarningswarnr=   joinr   r   r   
asiterablerE   write
fmt_remark	enumeratezipr    fmt_ATOM)r*   	selectionr&   uerrmsgrf   coordinatesattrsmissing_topologyattrdfltrn   r-   rem
atom_indexr_   r[   r\   r]   r^   r`   ra   s                         r2   rs   zPQRWriter.write   s   "	."AA 	. 	. 	.DFF##-	. L-!    O 	  	&&   iof--.223yt,,-	//0iof--.
 	. 	.JD$.%eT22d! . . ."d ''-----.	 %E* 	 	 	$)Lj!!!   	
 U""c%
*;x*G&H&H" ) 7 7E*(((LL --//L 	M6tyy)9::6;;   \$-.. 7	' t|44 > >do44S!<<====MM&&-44q|4  	    MM&&/66|DDa    'N*%*%(O)$'N    " " 
  &)YY]]sTzzM(()! ' '#%% ) 	 	   /"+7	 7	 7	 7	 7	 7	 7	 7	 7	 7	 7	 7	 7	 7	 7	 7	 7	 7	st   
 'A AA>D$D98D9=
E 
E1
EE1
E+(E1*E++E10E1E=N%%N),N))T)N)
r9   r:   r;   r<   r=   r>   rw   rt   rG   rs   r?   r8   r2   r5   r5      su         * FZ00E	9 
 &JO O O O&Q Q Q Q Q Qr8   r5   )r<   ri   numpynpro   libr    r   SingleFrameReaderBaser   
WriterBaser5   r?   r8   r2   <module>r      s   2R Rf                     8- 8- 8- 8- 8-* 8- 8- 8-vE E E E E E E E E Er8   