ó
Ï™xTc           @   s¢   d  d l  m Z d  d l m Z d  d l m Z d  d l Z d  d l Z d  d l	 Z
 d  d l Z
 d  d l m Z d  d l Z d  d l Z d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   division(   t   flex(   t   adopt_init_argsN(   t   RotamerEvalt   managerc           B   sY   e  Z d  d  e e e d d d d d d d
 d „ Z d „  Z d
 e e d
 d
 d
 d	 „ Z RS(   gš™™™™™é?i    ih  i   iÎÿÿÿi2   i   c      	   C   sv  t  |  t ƒ  ƒ |  j d  k r. t j |  _ n  |  j j j ƒ  |  _ t	 ƒ  |  _
 d  |  _ |  j j j j ƒ  d k r d |  _ n	 d |  _ |  j j d k |  _ t j ƒ  |  _ x9 |  j j D]+ } | j d  k	 r¹ |  j j | j ƒ q¹ q¹ W|  j ƒ  |  j j ƒ  } | j ƒ  d k r;|  j d | d t ƒ |  j j ƒ  } n  | j ƒ  d k rr|  j d | d t d t d	 t ƒ n  d  S(
   Ng      @g       @g      ø?gš™™™™™é?i    t
   iselectiont   use_clash_filtert   use_torsion_searcht   use_rotamer_iterator(   R   t   localst   logt   Nonet   syst   stdoutt   structure_monitort   xray_structuret   special_position_indicesR   t   rotamer_managert    atom_radius_to_negate_map_withint   target_map_objectt   miller_arrayt   d_mint   map_cc_per_atomt   selection_goodR   t   size_tt   iselection_backbonet   residue_monitorst   selection_backbonet   extendt   loop_over_residuest   find_sidechain_clashest   sizet   Truet   False(   t   selfR   t   mon_lib_srvt   map_cc_all_thresholdt   map_cc_sidechain_thresholdt	   use_slopeR   R   t   torsion_search_all_startt   torsion_search_all_stopt   torsion_search_all_stept   torsion_search_local_startt   torsion_search_local_stopt   torsion_search_local_stepR
   t   rt
   clash_list(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/real_space/fit_residues.pyt   __init__   s,     		
c         C   sD   |  j  j ƒ  d k r t Sx$ | j D] } | |  j  k r# t Sq# Wt S(   Ni    (   R   R   R!   t   selection_allR    (   R"   t
   sm_residuet   i_seq(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/real_space/fit_residues.pyt   on_special_position;   s      c      &   C   sþ  | d  k r |  j } n  | d  k r0 |  j } n  | d  k rH |  j } n  |  j } | j j ƒ  } | j j ƒ  }	 t j	 j
 }
 xft | j ƒ D]U\ } } | d  k	 rµ | | k rµ q‹ n  |
 | j j ƒ d k rÓ q‹ n  | j d k p	| j |  j k  p	| j |  j k  p	| } | r‹ |  j d | ƒ r*q‹ n  d  } d  } | d k r†| t | j ƒ d k r†| j | d j } | j | d j } n} | d k r¾t | j ƒ d k r¾| j | d j } nE | t | j ƒ d k rt | j ƒ d k r| j | d j } n  t j j j d | d d d	 | j j ƒ  j ƒ  d
 |  j d |  j d | d | ƒ } t j j j  d | d | j! j" j# ƒ  d | d |  j$ ƒ } | rýt j% j& d d d | j j' ƒ  d | j j( ƒ  d d, d t) | j! j* j+ ƒ  ƒ d | d t, j- d g ƒ ƒ n  t j j j. j/ d | d |  j0 d | j1 ƒ  d | j d |	 d |  j2 d | d  | d! | d" | d# | d$ |  j3 d% |  j4 d& |  j5 d' |  j6 d( |  j7 d) |  j8 d* |  j9 ƒ |	 j: | j j ƒ  j ƒ  | j j ƒ  j; ƒ  ƒ }	 | j< |	 ƒ q‹ q‹ W| j= d | d+ t> ƒ d  S(-   Nt   common_amino_acidt   OUTLIERR1   i    i   R   t   selection_within_radiusi   R   R   R   t   iselection_n_externalt   iselection_c_externalt   map_datat   negate_selectiont   atom_radiust	   file_names   AMap.mapt	   unit_cellt   space_groupt   gridding_firstt   gridding_lastt   labelst   DEBUGt
   target_mapR#   t   special_position_settingst   residuet   sites_cart_allR   R   t   debugR&   R   R   R'   R(   R)   R*   R+   R,   R
   t   accept_as_is(   i    i    i    (?   R   R&   R   R   R   R   t   deep_copy_scattererst
   sites_cartt   iotbxt   pdbt   common_residue_names_get_classt	   enumerateR   RE   t   resnamet   rotamer_statust
   map_cc_allR$   t   map_cc_sidechainR%   R3   t   lent   selection_ct   selection_nt   mmtbxt
   refinementt
   real_spacet   selection_around_to_negatet   atomst   extract_i_seqR   R   t6   negate_map_around_selected_atoms_except_selected_atomsR   t   datat	   deep_copyR   t   ccp4_mapt   write_ccp4_mapR=   R>   t   tuplet   crystal_griddingt   n_realR   t
   std_stringt   fit_residueR   R#   RD   R   R'   R(   R)   R*   R+   R,   R
   t   set_selectedt   extract_xyzt   set_sites_cartt   updateR!   (   R"   R   R   RG   R&   R   R   t   smt   xrsRJ   t	   get_classt   i_resR-   t   goR7   R8   R:   t   target_map_(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/real_space/fit_residues.pyR   A   s˜       	   %!.												
N(   t   __name__t
   __module__R    R   R/   R3   R!   R   (    (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/real_space/fit_residues.pyR      s&   !	(   t
   __future__R    t   cctbx.array_familyR   t   libtbxR   t	   iotbx.pdbRK   t   iotbx.ccp4_mapt   mmtbx.refinement.real_spaceRV   t'   mmtbx.refinement.real_space.fit_residuet   mmtbx.rotamer.rotamer_evalR   t   timeR   t   objectR   (    (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/real_space/fit_residues.pyt   <module>   s   