
     i%(                         d Z ddlZddlZddlmZ ddlmZ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 ddlmZ dd	lmZ ddlZ G d
 de          ZdS )a  
MOL2 file format --- :mod:`MDAnalysis.coordinates.MOL2`
========================================================

Classes to read Tripos_ molecule structure format (MOL2_) coordinate
and topology files. Used by the DOCK_ docking code.

.. _MOL2: http://www.tripos.com/data/support/mol2.pdf
.. _Tripos: http://www.tripos.com/
.. _DOCK: http://dock.compbio.ucsf.edu/


Classes
-------

.. autoclass:: MOL2Parser
   :members:
   :inherited-members:

    N   )openany   )TopologyReaderBase	squash_by)
Atomids	Atomnames	AtomtypesBondsChargesElementsResidsResnumsResnamesSegids)Topology)
SYBYL2SYMBc                       e Zd ZdZdZd ZdS )
MOL2Parsera	  Reads topology from a Tripos_ MOL2_ file.

    Creates the following Attributes:
     - Atomids
     - Atomnames
     - Atomtypes
     - Charges
     - Resids
     - Resnames
     - Bonds
     - Elements


    .. note::

        By default, masses will be guessed on Universe creation.
        This may change in release 3.0.
        See :ref:`Guessers` for more information.


    Notes
    -----
    Elements are obtained directly from the SYBYL atom types. If some atoms have
    unknown atom types, they will be assigned an empty element record. If all
    atoms have unknown atom types, the elements attribute will not be set.

    Dealing with optional fields:

      1. ``resid`` will set to 1 when not provided.

      2. If no atoms have ``resname`` field, resnames attribute will not be set;
         If some atoms have ``resname`` while some do not,
         :exc:`ValueError` will occur.

      3. If "NO_CHARGES" shows up in "@<TRIPOS>MOLECULE" section
         and no atoms have the ``charge`` field, charges attribute will not be set;
         If "NO_CHARGES" shows up while ``charge`` field appears,
         :exc:`ValueError` will occur;
         If a charge model is specified while some atoms don't have ``charge``,
         :exc:`ValueError` will occur as well.

    Raises
    ------
    ValueError
      If some atoms have the optional field ``resname`` (aka ``subst_name``)
      while some do not.

    ValueError
      If "NO_CHARGES" shows up in "@<TRIPOS>MOLECULE" section while
      some atoms have the optional field ``charge``.

    ValueError
      If a charge model is specified in "@<TRIPOS>MOLECULE" section while
      some atoms do not have the optional field ``charge``.


    .. versionchanged:: 0.9
       Now subclasses TopologyReaderBase
    .. versionchanged:: 0.20.0
       Allows for comments at the top of the file
       Ignores status bit strings
    .. versionchanged:: 2.0.0
       Bonds attribute is not added if no bonds are present in MOL2 file
    .. versionchanged:: 2.0.0
       Parse elements from atom types.
    .. versionchanged:: 2.2.0
       Read MOL2 files with optional columns omitted.
    .. versionchanged:: 2.8.0
        Removed mass guessing (attributes guessing takes place now
        through universe.guess_TopologyAttrs() API).

    MOL2c           
      >   g }t          | j                  5 }t          |          D ]b\  }}d|v r)t          |          r nI|                    |g d           t          |          r!|d         d                             |           cddd           n# 1 swxY w Y   t          |          s't          d                    | j                            |d         }i }d}|d         D ]}d|v rE|                    d          d	                                         	                                }g ||<   K|
                    d
          s|dk    rg||                             |           |d         |                    d          }
}	t          |	          sKt          d                    t          j                            | j                  |d                             g }g }g }g }g }g }|d         d                                         dk    }|	D ]}|                                }t          |          dk    r|dd         \	  }}}}}}}}}nt          |          dk     r5t          dt          j                            | j                   d          |dd         \  }}}}}}g d}t          dt          |                    D ]}||         ||dz
  <   |\  }}}|r,|)t          d| j         d|d         d          d|           n |t          d| j         d| d| d          |                    |           |                    |           |                    |           |                    |           |                    |           |                    |           t          |          }t!          j        |d          }t%                      } t          |          D ]9\  }}!|!t&          v rt&          |!         ||<   |                     |!           d ||<   :| rt+          j        d!|  d"           g }"|"                    t/          t!          j        |t           j                                       |"                    t5          t!          j        |t6                                         |"                    t9          t!          j        |t6                                         |r@|"                    t;          t!          j        |t           j                                       t!          j        |d k              s"|"                    tA          |                     t!          j        |t           j                  }t!          j        |t6                    }t!          j        |          rtC          ||          \  }#}\  }t          |          }$|"                    tE          |                     |"                    tG          |$                                                     |"                    tK          |                     nt!          j&        |          sytC          |          \  }#}}%t          |          }$|"                    tE          |                     |"                    tG          |$                                                     nt          d#| j         d$          |"                    tO          t!          j        d%gt6                                         |
rg }&g }'|
D ]}(|(                                dd&         \  })}*}+},tQ          |*          d	z
  tQ          |+          d	z
  }+}*tS          tU          |*|+g                    }-|'                    |,           |&                    |-           |"                    tW          |&|''                     tY          ||$d	|"|#(          }.|.S ))zParse MOL2 file *filename* and return the dict `structure`.

        Returns
        -------
        A MDAnalysis Topology object
        z@<TRIPOS>MOLECULE)
start_linelinesr   NzFThe mol2 file '{0}' needs to have at least one @<TRIPOS>MOLECULE blockr   z	@<TRIPOS>r   #
atombondz%The mol2 block ({0}:{1}) has no atomsr   molecule   
NO_CHARGES	      z%The @<TRIPOS>ATOM block in mol2 file z} should have at least 6 fields to be unpacked: atom_id atom_name x y z atom_type [subst_id[subst_name [charge [status_bit]]]])r   NNzThe mol2 file z indicates a charge modelz", but no charge provided in line: z" indicates no charges, but charge z provided in line: .U3)dtype z'Unknown elements found for some atoms: z0. These have been given an empty element record.zSome atoms in the mol2 file z# have subst_name while some do not.SYSTEM   )order)attrsatom_resindex)-r   filename	enumeratelenappend
ValueErrorformatsplitstriplower
startswithgetospathbasenamerangenpemptysetr   addwarningswarnr   arrayint32r	   objectr
   r   float32allr   r   r   r   copyr   anyr   inttuplesortedr   r   )/selfkwargsblocksfilineblocksectionscursor
atom_lines
bond_linesidsnamestypesresidsresnameschargeshas_chargesacolumnsaidnamexyz	atom_typeresidresnamechargeid_name_chargen_atomsvalidated_elementsinvalid_elementsatr+   residx
n_residues_bonds	bondorderbbida0a1	bond_typer   tops/                                                  h/srv/www/vhosts/g4struct/public_html/venv/lib/python3.11/site-packages/MDAnalysis/topology/MOL2Parser.pyparsezMOL2Parser.parse   s    T]## 	5q$Q<< 5 54&$..6{{ MMR"@"@AAAv;; 52Jw'..t444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 6{{ 	++16$-+@+@   q	'N 	* 	*Dd""K00399;;AACC#% %% V##D))))!)&!18<<3G3GJ
: 	7>>G$$T]33U<5H    z*1-3355E *	# *	#AggiiG7||q  BQBK FT1aIugvv W!! 0((770 0 0   18-T1aI!0q#g,,// 7 7A,3AJN1q5)))7&w >$< < <#J/2< < 9:< <   " %$< < <"< <78< < <   JJsOOOLLLL###MM%   OOG$$$NN6""""c((XgT:::55u%% 	+ 	+EArZ(22"1%% $$R((((*"1%%  	MA*A A A   WRXc:::;;<<<YrxV<<<==>>>YrxV<<<==>>> 	GLL'!D!D!DEEFFFv(B.// 	7LL"455666&1118HF3336( 	*3FH*E*E'FFKXVJLL(((LL//000LL(++,,,,!! 	 )! !FFA VJLL(((LL//00007t} 7 7 7  
 	VBHhZv>>>??@@@  	8EI # #)*2A2&RYR1c"ggkBVRH--..  +++T""""LLuI666777Z%v
 
 
 
s   A3BBBN)__name__
__module____qualname____doc__r2   rz        ry   r   r   C   s<        G GR Fi i i i ir   r   )r~   r8   numpyr<   lib.utilr   baser   r   core.topologyattrsr   r	   r
   r   r   r   r   r   r   r   core.topologyr   guesser.tablesr   r@   r   r   r   ry   <module>r      s6  0 ( 
			           / / / / / / / /                        % $ $ $ $ $ ' ' ' ' ' ' u u u u u# u u u u ur   