
     iO                     r    d dl mZ d dlZd dlZd dlZd dlZd Zd Zd Zd Z	d Z
d Zd	 Zd
 ZddZddZdS )    )divisionNc                    g }t          t          |           |z            D ]_}| ||z  ||z  |z            }t          j        t          j        j        j        |         |          }|                    |d                    `|S )zConvert a byte array into an integer array. The number of bytes forming an integer
    is defined by num
    :param in_bytes: the input bytes
    :param num: the number of bytes per int
    :return the integer arrayr   )	rangelenstructunpackmmtfutils	constantsNUM_DICTappend)in_bytesnumout_arrivalunpackeds         d/srv/www/vhosts/g4struct/public_html/venv/lib/python3.11/site-packages/mmtf/converters/converters.pyconvert_bytes_to_intsr   	   s     G3x==#%&& $ $q3wq3w},-=!5!>s!CSIIx{####N    c                 x    d}| D ]4}|t          j        t          j        j        j        |         |          z  }5|S )zConvert an integer array into a byte arrays. The number of bytes forming an integer
    is defined by num

    :param in_ints: the input integers
    :param num: the number of bytes per int
    :return the integer arrayr   )r   packr	   r
   r   r   )in_intsr   	out_bytesr   s       r   convert_ints_to_bytesr      sE     I H H6;tz3<SA3GGG		r   c                    t          |           t          j        j        j        z  }g }t          |          D ]}| |t          j        j        j        z  |t          j        j        j        z  t          j        j        j        z            }|                    |                    d                              t          j        j        j	                             |S )zConvert a list of bytes to a list of strings. Each string is of length mmtf.CHAIN_LEN

    :param in_bytes: the input bytes
    :return the decoded list of stringsascii)
r   r	   r
   r   	CHAIN_LENr   r   decodestrip	NULL_BYTE)r   tot_stringsout_stringsr   out_ss        r   decode_chain_listr%   "   s    
 h--4:#7#AAKK; X XTZ1;;A
@T@^<^aeakaua<  A5<<0066tz7K7UVVWWWWr   c                    d}| D ]|}||                     d          z  }t          t          j        j        j        t          |          z
            D ].}|t          j        j        j                             d          z  }/}|S )zConvert a list of strings to a list of byte arrays.

    :param in_strings: the input strings
    :return the encoded list of byte arraysr   r   )encoder   r	   r
   r   r   r   r!   )
in_stringsr   in_sr   s       r   encode_chain_listr*   /   s    
 I G G4;;w'''	tz+5s4yy@AA 	G 	GA
,6==gFFFII	Gr   c                      fd| D             S )zConvert integers to floats by division.

    :param in_ints: the integer array
    :param divider: the divider
    :return the array of floats producedc                     g | ]}|z  S  r-   ).0xdividers     r   
<listcomp>z*convert_ints_to_floats.<locals>.<listcomp>A   s    '''!AgI'''r   r-   )r   r0   s    `r   convert_ints_to_floatsr2   ;   s     ('''w''''r   c                     d | D             S )zhConvert integers to chars.

    :param in_ints: input integers
    :return the character array convertedc                 ,    g | ]}t          |          S r-   )chrr.   r/   s     r   r1   z)convert_ints_to_chars.<locals>.<listcomp>H   s    $$$qCFF$$$r   r-   )r   s    r   convert_ints_to_charsr7   C   s    
 %$G$$$$r   c                      fd| D             S )zConvert floating points to integers using a multiplier.

    :param in_floats: the input floats
    :param multiplier: the multiplier to be used for conversion. Corresponds to the precisison.
    :return the array of integers encodedc                 N    g | ]!}t          t          |z                      "S r-   )intround)r.   r/   
multipliers     r   r1   z*convert_floats_to_ints.<locals>.<listcomp>P   s-    :::1Ca*n%%&&:::r   r-   )	in_floatsr<   s    `r   convert_floats_to_intsr>   J   s     ;:::	::::r   c                     d | D             S )z{Convert an array of chars to an array of ints.

    :param in_chars: the input characters
    :return the array of integersc                 ,    g | ]}t          |          S r-   )ordr6   s     r   r1   z)convert_chars_to_ints.<locals>.<listcomp>X   s    %%%qCFF%%%r   r-   )in_charss    r   convert_chars_to_intsrC   S   s    
 &%H%%%%r      c                 "   g }| D ]}|dk    r'||k    r |                     |           ||z  }||k     nE||k    r?|                     |           |t          t          j        |                    z  }||k    ?|                     |           |S )zPack an integer array using recursive indexing.

    :param int_array: the input array of integers
    :param max: the maximum integer size
    :param min: the minimum integer size
    :return the array of integers after recursive index encodingr   )r   r:   mathfabs)	int_arraymaxminr   currs        r   recursive_index_encoderM   Z   s     G 	 	199#++s### #++ #++s###DIcNN+++ #++ 	tNr   c                 B   g }d}|t          |           k     rd}| |         |k    s| |         |k    r5|| |         z  }|dz  }| |         dk    rn| |         |k    )| |         |k    5|| |         z  }|dz  }|                    |           |t          |           k     |S )zUnpack an array of integers using recursive indexing.
    :param int_array: the input array of integers
    :param max: the maximum integer size
    :param min: the minimum integer size
    :return the array of integers after recursive index decodingr      )r   r   )rI   rJ   rK   r   encoded_inddecoded_vals         r   recursive_index_decoderR   n   s     GK
I
&
&$c))Y{-CS-H-H9[11KNK%q((	 $c))Y{-CS-H-H
 	y--Q{### I
&
& Nr   )rD   rE   )
__future__r   r   r	   rG   mmtf.utils.constantsr   r   r%   r*   r2   r7   r>   rC   rM   rR   r-   r   r   <module>rU      s                  
 
 

 
 

 
 
( ( (% % %; ; ;& & &   (     r   