
     ir                     J    d Z ddlZddlZddlZddlmZmZ d Z		 d	dZ
d
dZdS )a  
bootstrap procedures --- :mod:`MDAnalysis.analysis.ensemble.bootstrap`
======================================================================


The module contains functions for bootstrapping either ensembles (Universe
objects) or distance matrices, by resampling with replacement.

:Author: Matteo Tiberti, Wouter Boomsma, Tone Bengtsen

.. versionadded:: 0.16.0

.. deprecated:: 2.8.0
   This module is deprecated in favour of the 
   MDAKit `mdaencore <https://mdanalysis.org/mdaencore/>`_ and will be removed
   in MDAnalysis 3.0.0.

    N   )TriangularMatrixParallelCalculationc           	      H   t          j        |          }t          | j                  }g }|D ]}t          j        ||k              d         }|                    t           j                            t          j        |          t          j	        |          dz   |j
        d                              t          j        |          }t          |j                  D ]/}t          |          D ]}| ||         ||         f         |||f<   0t          j        d           |S )a9  
    Bootstrap an input square matrix. The resulting matrix will have the same
    shape as the original one, but the order of its elements will be drawn
    (with repetition). Separately bootstraps each ensemble.

    Parameters
    ----------

    matrix : encore.utils.TriangularMatrix
        similarity/dissimilarity matrix

    ensemble_assignment: numpy.array
        array of ensemble assignments. This array must be matrix.size long.

    Returns
    -------

    this_m : encore.utils.TriangularMatrix
        bootstrapped similarity/dissimilarity matrix
    )sizer   r   lowhighr   zMatrix bootstrapped.)npuniquer   r   whereappendrandomrandintminmaxshapehstackrangelogginginfo)	matrixensemble_assignmentensemble_identifiersthis_mindexesensold_indexesjks	            n/srv/www/vhosts/g4struct/public_html/venv/lib/python3.11/site-packages/MDAnalysis/analysis/encore/bootstrap.pybootstrapped_matrixr"   /   s1   * 9%8996;///FG# 
 
h2c9::1=IF;''VK((1, &q)   	
 	
 	
 	
 i  G6; : :q 	: 	:A!'!*gaj"89F1a4LL	: L'(((M    d   c                       fdt          |          D             }t          |t          |          }|                                }t	          t          |           d         }|S )a  
    Calculates distance matrices corresponding to bootstrapped ensembles, by
    resampling with replacement.

    Parameters
    ----------

    distance_matrix : encore.utils.TriangularMatrix
        Conformational distance matrix

    ensemble_assignment : str
        Mapping from frames to which ensemble they are from (necessary because
        ensembles are bootstrapped independently)

    samples : int, optional
        How many bootstrap samples to create.

    ncores : int, optional
        Maximum number of cores to be used (default is 1)

    Returns
    -------

    confdistmatrix : list of encore.utils.TriangularMatrix
    c                     g | ]}gS  r'   ).0idistance_matrixr   s     r!   
<listcomp>z9get_distance_matrix_bootstrap_samples.<locals>.<listcomp>w   s,       56/.	/  r#   r   )r   r   r"   runlistzip)r*   r   samplesncoresbs_argspc
pc_resultsbootstrap_matricess   ``      r!   %get_distance_matrix_bootstrap_samplesr5   Z   sv    :    :?..  G 
V%8'	B	BBJc:.//2r#   c                    |                                   g }t          |          D ]}t          j                            d| j                                        j        d         | j                                        j        d                   }|                    t          j
        | j        | j                            d          |ddddf         t          j        j        j                             |S )aB  
    Generates a bootstrapped ensemble by resampling with replacement.

    Parameters
    ----------

    ensemble : MDAnalysis.Universe
        Conformational distance matrix

    samples : int, optional
        How many bootstrap samples to create.

    Returns
    -------

    list of MDAnalysis.Universe objects
    r   r   r   fac)orderN)format)transfer_to_memoryr   r   r   r   
trajectory
timeseriesr   r   mdaUniversefilenamecoordinatesmemoryMemoryReader)ensembler/   	ensemblesr)   indicess        r!   get_ensemble_bootstrap_samplesrF      s    & !!!I7^^ 
 
)##$//117:$//117: $ 
 

 	L!#..U.;;GQQQMJ-:  	
 	
 	
 	
 r#   )r$   r   )r$   )__doc__numpyr   r   
MDAnalysisr=   utilsr   r   r"   r5   rF   r'   r#   r!   <module>rK      s   . $          8 8 8 8 8 8 8 8( ( (X ?@' ' ' 'T# # # # # #r#   