B
    ‰°b¼-  ã               @   sz   d 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	m
Z
 ddlmZmZ ddlmZ dd	lm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)Ú	Structure)ÚModel)ÚChain)ÚResidueÚDisorderedResidue)ÚAtomÚDisorderedAtom)ÚPDBConstructionException)ÚPDBConstructionWarningc               @   sŒ   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zd"dd„Z	dd„ Z
dd„ Zdd„ Zd#dd„Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ ZdS )$ÚStructureBuilderz¢Deals with constructing the Structure object.

    The StructureBuilder class is used by the PDBParser classes to
    translate a file to a Structure object.
    c             C   s   d| _ i | _dS )zInitialize the class.r   N)Úline_counterÚheader)Úself© r   ú7lib/python3.7/site-packages/Bio/PDB/StructureBuilder.pyÚ__init__   s    zStructureBuilder.__init__c             C   s.   |  ¡ }x |D ]}| ¡ }|dkrdS qW dS )zGReturn 1 if all atoms in the residue have a non blank altloc (PRIVATE).ú r   é   )Zget_unpacked_listZ
get_altloc)r   ÚresidueZ	atom_listÚatomÚaltlocr   r   r   Ú_is_completely_disordered$   s    
z*StructureBuilder._is_completely_disorderedc             C   s
   || _ dS )zSet header.N)r   )r   r   r   r   r   Ú
set_header/   s    zStructureBuilder.set_headerc             C   s
   || _ dS )zmTracks line in the PDB file that is being parsed.

        Arguments:
         - line_counter - int

        N)r   )r   r   r   r   r   Úset_line_counter3   s    z!StructureBuilder.set_line_counterc             C   s   t |ƒ| _dS )zeInitialize a new Structure object with given id.

        Arguments:
         - id - string

        N)r   Ú	structure)r   Zstructure_idr   r   r   Úinit_structure<   s    zStructureBuilder.init_structureNc             C   s   t ||ƒ| _| j | j¡ dS )zvCreate a new Model object with given id.

        Arguments:
         - id - int
         - serial_num - int

        N)r   Úmodelr   Úadd)r   Zmodel_idZ
serial_numr   r   r   Ú
init_modelE   s    zStructureBuilder.init_modelc             C   sL   | j  |¡r0| j | | _t d|| jf t¡ nt|ƒ| _| j  | j¡ dS )zcCreate a new Chain object with given id.

        Arguments:
         - chain_id - string

        z.WARNING: Chain %s is discontinuous at line %i.N)	r   Úhas_idÚchainÚwarningsÚwarnr   r
   r   r   )r   Zchain_idr   r   r   Ú
init_chainP   s    

zStructureBuilder.init_chainc             C   s
   || _ dS )zOFlag a change in segid.

        Arguments:
         - segid - string

        N)Úsegid)r   r$   r   r   r   Úinit_segb   s    zStructureBuilder.init_segc       	      C   sl  |dkr|dkrd| }|||f}|dkrJ| j  |¡rJt d|||| jf t¡ | j | }| ¡ dkrª| |¡r†|| _| 	|¡ n"t
||| jƒ}| |¡ || _dS n ||jkrÚt d||||| jf t¡ || _dS |  |¡sþd| _td||||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   ÚHZ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.z6Blank altlocs in duplicate residue %s ('%s', %i, '%s'))r    r   r!   r"   r   r
   Úis_disorderedZdisordered_has_idr   Zdisordered_selectr   r$   Údisordered_addÚresnamer   r	   Údetach_childr   r   )	r   r*   ZfieldZresseqZicodeZres_idZduplicate_residueZnew_residueZdisordered_residuer   r   r   Úinit_residuek   sR    








zStructureBuilder.init_residueFc             C   sL  | j }|dkrdS | |¡rP|| }| ¡ }||krP|}t d||| jf t¡ |snt||||||||ƒ| _n |rŽt||dd|||||	|
ƒ
| _|dkr<| |¡r|| }| 	¡ dkrÆ| 
| j¡ nL| |¡ t|ƒ}| |¡ | 
| j¡ | 
|¡ | ¡  t d| j t¡ n&t|ƒ}| |¡ | 
| j¡ | ¡  n| | j¡ dS )a€  Create a new Atom object.

        Arguments:
         - name - string, atom name, e.g. CA, spaces should be stripped
         - coord - Numeric array (Float0, size 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   r'   zAWARNING: disordered atom found with blank altloc before line %i.
)r   r   Zget_fullnamer!   r"   r   r
   r   r   r(   r)   r+   r   r   Zflag_disordered)r   ÚnameZcoordZb_factorZ	occupancyr   ÚfullnameZserial_numberÚelementZ
pqr_chargeZradiusZis_pqrr   Zduplicate_atomZduplicate_fullnameZdisordered_atomr   r   r   Ú	init_atom³   sl    







zStructureBuilder.init_atomc             C   s   | j  |¡ dS )z)Set anisotropic B factor of current Atom.N)r   Ú
set_anisou)r   Zanisou_arrayr   r   r   r1   #  s    zStructureBuilder.set_anisouc             C   s   | j  |¡ dS )z?Set standard deviation of anisotropic B factor of current Atom.N)r   Ú
set_siguij)r   Zsiguij_arrayr   r   r   r2   '  s    zStructureBuilder.set_siguijc             C   s   | j  |¡ dS )z8Set standard deviation of atom position of current Atom.N)r   Ú
set_sigatm)r   Zsigatm_arrayr   r   r   r3   +  s    zStructureBuilder.set_sigatmc             C   s   | j | j_ | jS )zReturn the structure.)r   r   )r   r   r   r   Úget_structure/  s    
zStructureBuilder.get_structurec             C   s   dS )zSet symmetry.Nr   )r   Z
spacegroupZcellr   r   r   Úset_symmetry7  s    zStructureBuilder.set_symmetry)N)NNNNF)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r#   r%   r,   r0   r1   r2   r3   r4   r5   r   r   r   r   r      s(   		
	P    
dr   )r9   r!   ZBio.PDB.Structurer   ZBio.PDB.Modelr   ZBio.PDB.Chainr   ZBio.PDB.Residuer   r   ZBio.PDB.Atomr   r   ZBio.PDB.PDBExceptionsr	   r
   r   r   r   r   r   Ú<module>	   s   