o
    Rŀg                     @   s:   d Z ddlmZ ddlmZ ddlmZ G dd dZdS )zHMap residues of two structures to each other based on a FASTA alignment.    )PDBData)	Selection)is_aac                   @   s2   e Zd ZdZdddZdd Zdd	 Zd
d ZdS )StructureAlignmentzGClass to align two structures based on an alignment of their sequences.r      c                 C   s0  z|  }W n ty   |j\}}Y nw t|d}t|d}	d}
d}i }i }g }t|D ]]}|dd|f }|| }|| }|dkr[	 ||
 }|
d }
t|rSnqF| || nd}|dkrw	 |	| }|d }t|ronqb| || nd}|r|||< |r|||< |||f q/|| _	|| _
|| _dS )zInitialize.

        Attributes:
         - fasta_align - Alignment object
         - m1, m2 - two models
         - si, sj - the sequences in the Alignment object that
           correspond to the structures

        Rr   N-Tr   )get_alignment_lengthAttributeErrorshaper   unfold_entitiesranger   _test_equivalenceappendmap12map21duos)selffasta_alignm1m2sisjncolumnsnrowsrl1rl2p1p2r   r   r   icolumnaa1aa2r1r2 r%   N/var/www/html/myenv/lib/python3.10/site-packages/Bio/PDB/StructureAlignment.py__init__   sT   

zStructureAlignment.__init__c                 C   s"   |  }tj| }||ksJ dS )z6Test if aa in sequence fits aa in structure (PRIVATE).N)get_resnamer   protein_letters_3to1_extended)r   r#   r!   resnamer%   r%   r&   r   Q   s   
z$StructureAlignment._test_equivalencec                 C   s   | j | jfS )zMap residues between the structures.

        Return two dictionaries that map a residue in one structure to
        the equivealent residue in the other structure.
        )r   r   )r   r%   r%   r&   get_mapsW   s   zStructureAlignment.get_mapsc                 c   s&    t t| jD ]}| j| V  qdS )z*Create an iterator over all residue pairs.N)r   lenr   )r   r   r%   r%   r&   get_iterator_   s   zStructureAlignment.get_iteratorN)r   r   )__name__
__module____qualname____doc__r'   r   r+   r-   r%   r%   r%   r&   r      s    
?r   N)r1   Bio.Datar   Bio.PDBr   Bio.PDB.Polypeptider   r   r%   r%   r%   r&   <module>   s
   