
:>"^	                 @   ss   d  Z  d d l Z d d l Z d d l m Z d d l m Z e j d  Z Gd d   d e	  Z
 d d	   Z d S)
znCode for chopping up (dicing) a structure.

This module is used internally by the Bio.PDB.extract() function.
    N)PDBIO)BiopythonWarningz
[123 ]*H.*c               @   sU   e  Z d  Z d Z d d d  Z d d   Z d d   Z d	 d
   Z d d   Z d S)ChainSelectorzOnly accepts residues with right chainid, between start and end.

    Remove hydrogens, waters and ligands. Only use model 0 by default.
    r   c             C   s(   | |  _  | |  _ | |  _ | |  _ d S)zInitialize the class.N)chain_idstartendmodel_id)selfr   r   r   r    r
   1/tmp/pip-build-ww9dw3qa/biopython/Bio/PDB/Dice.py__init__   s    			zChainSelector.__init__c             C   s   | j    |  j k r d Sd S)z+Verify if model match the model identifier.   r   )get_idr   )r	   modelr
   r
   r   accept_model#   s    zChainSelector.accept_modelc             C   s   | j    |  j k r d Sd S)z'Verify if chain match chain identifier.r   r   )r   r   )r	   chainr
   r
   r   accept_chain*   s    zChainSelector.accept_chainc             C   su   | j    \ } } } | d k r% d S| d k rK t j d | | f t  |  j | k oh |  j k n rq d Sd S)zCVerify if a residue sequence is between the start and end sequence. r   z WARNING: Icode %s at position %sr   )r   warningswarnr   r   r   )r	   ZresidueZhetatm_flagZresseqZicoder
   r
   r   accept_residue0   s    "zChainSelector.accept_residuec             C   s'   | j    } t j |  r d Sd Sd S)z!Verify if atoms are not Hydrogen.r   r   N)r   	_hydrogenmatch)r	   Zatomnamer
   r
   r   accept_atom?   s    zChainSelector.accept_atomN)	__name__
__module____qualname____doc__r   r   r   r   r   r
   r
   r
   r   r      s   r   c             C   s<   t  | | |  } t   } | j |   | j | |  d S)z'Write out selected portion to filename.N)r   r   Zset_structuresave)Z	structurer   r   r   filenameselior
   r
   r   extractI   s    	r#   )r   rer   ZBio.PDB.PDBIOr   ZBior   compiler   objectr   r#   r
   r
   r
   r   <module>   s   3