o
    Rŀgg/                     @   s   d Z ddlZddlmZ ddlZddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ dedefddZG dd dZdS )zgConsumer class that builds a Structure object.

This is used by the PDBParser and MMCIFparser classes.
    N)Optional)Atom)DisorderedAtom)Chain)Model)PDBConstructionException)PDBConstructionWarning)DisorderedResidue)Residue)	Structureresiduereturnc                 C   s,   |   }|D ]}| }|dkr dS qdS )zJReturn whether all atoms in the residue have a non-blank altloc (PRIVATE). FT)get_unpacked_list
get_altloc)r   	atom_listatomaltloc r   L/var/www/html/myenv/lib/python3.10/site-packages/Bio/PDB/StructureBuilder.py_is_completely_disordered   s   r   c                   @   s   e Zd ZdZdd Zdd ZdefddZd	efd
dZ	d4dede
e fddZdefddZdefddZdedededefddZ					d5dedejd ed!ed"ed#ed$e
e d%e
e d&e
e d'efd(d)Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 ZdS )6StructureBuilderzDeals with constructing the Structure object.

    The StructureBuilder class is used by the PDBParser classes to
    translate a file to a Structure object.
    c                 C   s4   d| _ d| _i | _d| _d| _d| _d| _d| _dS )zInitialize this instance.Nr   )r   chainheaderline_countermodelr   segid	structureselfr   r   r   __init__0   s   
zStructureBuilder.__init__c                 C   
   || _ dS )zSet header.N)r   )r   r   r   r   r   
set_header=   s   
zStructureBuilder.set_headerr   c                 C   r!   )zmTracks line in the PDB file that is being parsed.

        Arguments:
         - line_counter - int

        N)r   )r   r   r   r   r   set_line_counterA   s   
z!StructureBuilder.set_line_counterstructure_idc                 C   s   t || _dS )znInitialize a new Structure object with given id.

        Arguments:
         - structure_id - string
        N)r   r   )r   r$   r   r   r   init_structureJ   s   zStructureBuilder.init_structureNmodel_id
serial_numc                 C   s   t ||| _| j| j dS )zuCreate a new Model object with given id.

        Arguments:
         - id - int
         - serial_num - int
        N)r   r   r   add)r   r&   r'   r   r   r   
init_modelR   s   zStructureBuilder.init_modelchain_idc                 C   sN   | j |r| j | | _td|| jf t dS t|| _| j | j dS )zbCreate a new Chain object with given id.

        Arguments:
         - chain_id - string
        z.WARNING: Chain %s is discontinuous at line %i.N)	r   has_idr   warningswarnr   r   r   r(   )r   r*   r   r   r   
init_chain\   s   
zStructureBuilder.init_chainr   c                 C   r!   )zNFlag a change in segid.

        Arguments:
         - segid - string
        N)r   )r   r   r   r   r   init_segm   s   
zStructureBuilder.init_segresnamefieldresseqicodec           	      C   sj  |dkr|dkrd| }|||f}|dkr| j |rtd|||| jf t | j | }| dkrR||rA|| _|	| nct
||| j}|| || _dS ||jkrjtd||||| jf t || _dS t|s~d| _td||||| j jf | j | t
||| j}t|}| j | || || || _dS t
||| j| _| j | j dS )	a  Create a new Residue object.

        Arguments:
         - resname - string, e.g. "ASN"
         - field - hetero flag, "W" for waters, "H" for
           hetero residues, otherwise blank.
         - resseq - int, sequence identifier
         - icode - string, insertion code

        r   HH_z7WARNING: Residue ('%s', %i, '%s') redefined at line %i.   NzVWARNING: Residue ('%s', %i, '%s','%s') already defined with the same name at line  %i.zDBlank altlocs in duplicate residue %s ('%s', %i, '%s') of chain '%s')r   r+   r,   r-   r   r   is_disordereddisordered_has_idr   disordered_selectr
   r   disordered_addr0   r   r   iddetach_childr	   r(   )	r   r0   r1   r2   r3   res_idduplicate_residuenew_residuedisordered_residuer   r   r   init_residueu   s^   






zStructureBuilder.init_residueFnamecoordb_factor	occupancyr   fullnameelement
pqr_chargeradiusis_pqrc                 C   sJ  | j }|du r	dS ||r(|| }| }||kr(|}td||| jf t |r9t||dd|||||	|

| _nt||||||||| _|dkr||r|| }|	 dkr`|
| j dS || t|}|| |
| j |
| |  td| j t dS t|}|| |
| j |  dS || j dS )a  Create a new Atom object.

        Arguments:
         - name - string, atom name, e.g. CA, spaces should be stripped
         - coord - NumPy array (Float0, length 3), atomic coordinates
         - b_factor - float, B factor
         - occupancy - float
         - altloc - string, alternative location specifier
         - fullname - string, atom name including spaces, e.g. " CA "
         - element - string, upper case, e.g. "HG" for mercury
         - pqr_charge - float, atom charge (PQR format)
         - radius - float, atom radius (PQR format)
         - is_pqr - boolean, flag to specify if a .pqr file is being parsed
        Nz6Atom names %r and %r differ only in spaces at line %i.r   r6   zAWARNING: disordered atom found with blank altloc before line %i.
)r   r+   get_fullnamer,   r-   r   r   r   r   r7   r:   r<   r   r(   flag_disordered)r   rB   rC   rD   rE   r   rF   serial_numberrG   rH   rI   rJ   r   duplicate_atomduplicate_fullnamedisordered_atomr   r   r   	init_atom   sv   







zStructureBuilder.init_atomc                 C      | j | dS )z)Set anisotropic B factor of current Atom.N)r   
set_anisou)r   anisou_arrayr   r   r   rS   ,     zStructureBuilder.set_anisouc                 C   rR   )z?Set standard deviation of anisotropic B factor of current Atom.N)r   
set_siguij)r   siguij_arrayr   r   r   rV   0  rU   zStructureBuilder.set_siguijc                 C   rR   )z8Set standard deviation of atom position of current Atom.N)r   
set_sigatm)r   sigatm_arrayr   r   r   rX   4  rU   zStructureBuilder.set_sigatmc                 C   s   | j | j_ | jS )zReturn the structure.)r   r   r   r   r   r   get_structure8  s   
zStructureBuilder.get_structurec                 C   s   dS )zSet symmetry.Nr   )r   
spacegroupcellr   r   r   set_symmetry@  s    zStructureBuilder.set_symmetry)N)NNNNF)__name__
__module____qualname____doc__r    r"   intr#   strr%   r   r)   r.   r/   rA   npndarrayfloatboolrQ   rS   rV   rX   rZ   r]   r   r   r   r   r   )   sR    	
P	

or   )ra   r,   typingr   numpyrd   Bio.PDB.Atomr   r   Bio.PDB.Chainr   Bio.PDB.Modelr   Bio.PDB.PDBExceptionsr   r   Bio.PDB.Residuer	   r
   Bio.PDB.Structurer   rg   r   r   r   r   r   r   <module>   s   