
     ib3                         d Z ddlZddlZddl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mZmZmZmZ ddlmZmZ  ej        d          Zd Z G d	 d
e          Z dS )a  
RDKit topology parser --- :mod:`MDAnalysis.converters.RDKitParser`
==================================================================

Converts an `RDKit <https://www.rdkit.org/docs/source/rdkit.Chem.rdchem.html#rdkit.Chem.rdchem.Mol>`_ :class:`rdkit.Chem.rdchem.Mol` into a :class:`MDAnalysis.core.Topology`.


See Also
--------
:mod:`MDAnalysis.converters.RDKit`


Classes
-------

.. autoclass:: RDKitParser
   :members:
   :inherited-members:

    N   )Topology)AltLocsAromaticitiesAtomids	Atomnames	AtomtypesBondsChainIDsChargesElementsICodesMassesOccupanciesResidsResnamesResnumsRSChiralitySegidsTempfactors)TopologyReaderBasechange_squashz!MDAnalysis.converters.RDKitParserc                 P    	 |                      d          S # t          $ r Y dS w xY w)zFetches RDKit chiral tags_CIPCode )GetPropKeyError)atoms    k/srv/www/vhosts/g4struct/public_html/venv/lib/python3.11/site-packages/MDAnalysis/converters/RDKitParser.py_rdkit_atom_to_RSr    L   s;    ||J'''   rrs    
%%c                   2    e Zd ZdZdZed             Zd ZdS )RDKitParserao  
    For RDKit structures

    Creates the following Attributes:
     - Atomids
     - Atomnames
     - Aromaticities
     - Elements
     - Types
     - Masses
     - Bonds
     - Resids
     - Resnums
     - RSChirality
     - Segids

    Depending on RDKit's input, the following Attributes might be present:
     - Charges
     - Resnames
     - AltLocs
     - ChainIDs
     - ICodes
     - Occupancies
     - Tempfactors

    Attributes table:

    +---------------------------------------------+-------------------------+
    | RDKit attribute                             | MDAnalysis equivalent   |
    +=============================================+=========================+
    | atom.GetMonomerInfo().GetAltLoc()           | altLocs                 |
    +---------------------------------------------+-------------------------+
    | atom.GetIsAromatic()                        | aromaticities           |
    +---------------------------------------------+-------------------------+
    | atom.GetMonomerInfo().GetChainId()          | chainIDs                |
    +---------------------------------------------+-------------------------+
    | atom.GetDoubleProp('_GasteigerCharge')      | charges                 |
    | atom.GetDoubleProp('_TriposPartialCharge')  |                         |
    +---------------------------------------------+-------------------------+
    | atom.GetSymbol()                            | elements                |
    +---------------------------------------------+-------------------------+
    | atom.GetMonomerInfo().GetInsertionCode()    | icodes                  |
    +---------------------------------------------+-------------------------+
    | atom.GetIdx()                               | indices                 |
    +---------------------------------------------+-------------------------+
    | atom.GetMass()                              | masses                  |
    +---------------------------------------------+-------------------------+
    | atom.GetMonomerInfo().GetName()             | names                   |
    | atom.GetProp('_TriposAtomName')             |                         |
    +---------------------------------------------+-------------------------+
    | atom.GetProp('_CIPCode')                    | chiralities             |
    +---------------------------------------------+-------------------------+
    | atom.GetMonomerInfo().GetOccupancy()        | occupancies             |
    +---------------------------------------------+-------------------------+
    | atom.GetMonomerInfo().GetResidueName()      | resnames                |
    +---------------------------------------------+-------------------------+
    | atom.GetMonomerInfo().GetResidueNumber()    | resnums                 |
    +---------------------------------------------+-------------------------+
    | atom.GetMonomerInfo().GetTempFactor()       | tempfactors             |
    +---------------------------------------------+-------------------------+
    | atom.GetProp('_TriposAtomType')             | types                   |
    +---------------------------------------------+-------------------------+

    Raises
    ------
    ValueError
        If only part of the atoms have MonomerInfo available


    .. versionadded:: 2.0.0
    .. versionchanged:: 2.1.0
       Added R/S chirality support
    .. versionchanged:: 2.8.0
       Removed type guessing (attributes guessing takes place now
       through universe.guess_TopologyAttrs() API). If atoms types is not
       present in the input rdkit molecule as a _TriposAtomType property,
       the type attribute get the same values as the element attribute.

    RDKITc                 ^    	 ddl m} n# t          $ r Y dS w xY wt          | |j                  S )z$Can this Parser read object *thing*?r   )ChemF)rdkitr%   ImportError
isinstanceMol)thingr%   s     r   _format_hintzRDKitParser._format_hint   sP    	""""""" 	 	 	55	%***s   	 
c           	      j   | j         }g }g }g }g }g }g }g }	g }
g }g }g }g }g }g }g }g }	 |                    d          }n'# t          $ r t          dddddd          }|cY S w xY w|                    d          r)|                    d          rt          j        d           |                                D ]i}|                    |	                                           |                    |
                                           |                    |                                           |
                    |                                           |                    t          |                     |                                }|r|                    |                                                                           |                    |                                           |                    |                                           |                    |                                           |                    |                                                                           |                    |                                                                           |                    |                                                                           |                    |                                           |                    |                                           	 |                    |                    d                     n# t4          $ r Y nw xY w	 |                    |                    d                     n# t4          $ r Y nw xY w	 |	                    |                    d                      # t4          $ r> 	 |	                    |                    d                     n# t4          $ r Y nw xY wY gw xY wg }t9          |          }|r"t9          |          |k    rt;          d	          |t<          t>          j         f|tB          tD          f|tF          t>          j$        f|
tJ          tL          f|tN          d
ffD ]8\  }}}|                     |t?          j(        ||                               9g }g }g }|)                                D ]}|                    |*                                |+                                f           |                    |,                                           |                    t[          |.                                                     |                    t_          |||                     |r<|                    ta          t?          j(        |tD                                         n|                                D ]A}|
                                 |	                                 }|                    |           B|                    ta          t?          j(        |tD                                         |r<|                    tc          t?          j(        |tD                                         nt>          j2        3                    |          }|	rA|                    ti          t?          j(        |	t>          j$                                       n	 |tj          tD          f|tl          tD          f|tn          t>          j$        f|tp          t>          j$        ffD ]:\  }}}|r2|                     |t?          j(        ||                               ;ts          |          rJts          d |D                       s0t?          j(        |t>          j                   }t?          j(        |tD                    }t?          j(        |tD                    }t?          j(        |tD                    }tu          ||||f||||f          \  } \  }}}}t9          |          }!|tv          t>          j         f|<                                tz          t>          j         f|t|          tD          f|t~          tD          ffD ]8\  }}}|                     |t?          j(        ||                               9nn|                    tw          t?          j(        dg                               |                    t{          t?          j(        dg                               d} d}!ts          |          rbts          d |D                       sItu          |f|f          \  }"\  }t9          |          }#|                    t          |                     n@d}#|                    t          t?          j(        dgtD                                         d}"t          ||!|#|| |"          }|S )zfParse RDKit into Topology

        Returns
        -------
        MDAnalysis Topology object
        r   N)n_atomsn_resn_segattrsatom_resindexresidue_segindex_GasteigerCharge_TriposPartialChargezjBoth _GasteigerCharge and _TriposPartialCharge properties are present. Using Gasteiger charges by default._TriposAtomName_TriposAtomTypezResidueInfo is only partially available in the molecule. If you have added hydrogens to the input RDKit molecule with `Chem.AddHs(mol)`, consider using `Chem.AddHs(mol, addResidueInfo=True)` insteadU1)dtype)typesorderc              3      K   | ]}|d u V  	d S N .0vals     r   	<genexpr>z$RDKitParser.parse.<locals>.<genexpr>P  s&      #C#CCC4K#C#C#C#C#C#C       c              3      K   | ]}|d u V  	d S r<   r=   r>   s     r   rA   z$RDKitParser.parse.<locals>.<genexpr>h  s&      "A"A33$;"A"A"A"A"A"ArB   SYSTEM)r0   r1   r2   )AfilenameGetAtomWithIdxRuntimeErrorr   HasPropwarningswarnGetAtomsappendGetIdx	GetSymbolGetMassGetIsAromaticr    GetMonomerInfoGetNamestripGetResidueNumberGetResidueNameGetSegmentNumber	GetAltLoc
GetChainIdGetInsertionCodeGetOccupancyGetTempFactorr   r   GetDoubleProplen
ValueErrorr   npint32r   objectr   float32r   boolr   arrayGetBondsGetBeginAtomIdxGetEndAtomIdxGetBondTypeAsDoublestrGetBondTyper
   r   r	   charupperr   r   r   r   r   anyr   r   copyr   r   r   r   )$selfkwargsmolnameschiralitiesresnumsresnameselementsmassescharges	aromaticsids	atomtypessegidsaltlocschainidsicodesoccupanciestempfactorsr   topmir0   r-   valsAttrr8   bonds
bond_typesbond_ordersbondnameresidx
n_residuessegidx
n_segmentss$                                       r   parsezRDKitParser.parse   s	    m 			%%a((DD 		 		 		"!%  C JJJ		 <<*++ 	LL/00	 MC  
 LLNN (	 (	DJJt{{}}%%%OODNN,,---MM$,,..)))T//11222066777$$&&B !RZZ\\//11222r2244555 1 1 3 3444b1133444r||~~3355666 5 5 7 7888b113399;;<<<""2??#4#4555""2#3#3#5#56666LL.?!@!@AAAA   D$$T\\2C%D%DEEEE   D
	NN4#5#56H#I#IJJJJ    ../EFF    $    c(( 	G//A   '28$x(VRZ(t,+t,"
 	< 	<D$ LLbht5999::;;;; 
LLNN 	7 	7DLL$..00$2D2D2F2FGHHHt7799:::c$"2"2"4"4556666U5
+FFFGGG
  	CLL28E#@#@#@AABBBB # #..**;DKKMM;;T""""LL28E#@#@#@AABBB  	0LL28IV#D#D#DEEFFFFh//I  	LL'!D!D!DEEFFFF gv&x(+rz2+rz2	"
 	@ 	@D$  @TT"(4u"="="=>>??? w<< 	#C#C7#C#C#C C C 	hwbh777Gx777HXfF333FXfF333F:G(FF3(FF3; ;7F7Wh WJ&"(+"(38V,(	& @ @!dE TT"(4u"="="=>>????@ LL!..///LL1#//000FJ v;; 	s"A"A&"A"A"AAA 	 -vi& C CFIVVJLL((((JLL(6 B B BCCDDDF  #
 
 
 
si   ? !A#"A#:(M##
M0/M04(N
N*)N*.(O
P #(PP 
PP PP P N)__name__
__module____qualname____doc__formatstaticmethodr+   r   r=   rB   r   r"   r"   T   sU        N N` F+ + \+K K K K KrB   r"   )!r   loggingrJ   numpyr`   core.topologyr   core.topologyattrsr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   topology.baser   r   	getLoggerloggerr    r"   r=   rB   r   <module>r      s  0 *       $ $ $ $ $ $                                       ( > = = = = = = =		>	?	?  g g g g g$ g g g g grB   