ó
Î™xTc           @   sR   d  d l  m 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   flexNt   runc        	   B   s5   e  Z d
 d  d d d d d d d „ Z d d	 „ Z RS(   g¸…ëQ¸Ž?g       @g      ð?i   id   i
   i2   c         C   s‘  g  |  _  g  } x| j ƒ  D]ÿ } xö | j ƒ  D]è } | j ƒ  sM | j ƒ  r/ t j ƒ  } d } xx | j ƒ  D]j } | j ƒ  j	 ƒ  } | d 7} | d k  rª | j
 | ƒ ql | j | ƒ t j ƒ  } | j
 | ƒ d } ql Wt | ƒ d k r| j ƒ  d k st ‚ | j | ƒ qq/ q/ Wq W|  j  j d t | ƒ ƒ g  } t | ƒ d k r�x9 t | ƒ D]( } | j t j t t | ƒ ƒ ƒ ƒ q^Wn  |  j  j d | ƒ | j ƒ  } t j | j ƒ  j ƒ  t ƒ } | j | ƒ } t j j j j d | d | d | j d	 | d
 |	 d | ƒ } t j ƒ  } t | ƒ d k r@d g } n  xÄ | D]¼ } | d k rzt j | j ƒ  j ƒ  t ƒ } n( | | } t j | j ƒ  j ƒ  | ƒ } | j d | d | d | ƒ |  j  j d t  | ƒ | j! f ƒ | j! d k	 rG| j | j! ƒ qGqGWt j" | ƒ } | | d k  } | | | d k M} | j# t ƒ d k ra| j | ƒ } n  t j$ | | ƒ |  _% |  j  j d |  j% ƒ d S(   si   
Fast determination of optimal data/restraints weight for real-space refinement
of individual sites.
    i    i   i
   s   number of chunks: %ds   random chunks:t   xray_structuret
   target_mapt   geometry_restraints_managert   real_space_gradients_deltat   max_iterationst
   ncs_groupst	   selectiont   rms_bonds_limitt   rms_angles_limits   chunk %s optimal weight: %9.4fi   s   overall best weight: %9.4fN(&   t   msg_stringst   modelst   chainst
   is_proteint   is_naR   t   size_tt   residue_groupst   atomst   extract_i_seqt   extendt   appendt   lent   sizet   AssertionErrort   xranget   randomt   choicet   deep_copy_scattererst   boolt
   scattererst   Truet   selectt   mmtbxt
   refinementt
   real_spacet   individual_sitest   box_refinement_managert   geometryt   doublet   Nonet   refinet   strt   weight_optimalt   meant   countt   mean_defaultt   weight(   t   selft   map_dataR   t   pdb_hierarchyR   R   R
   R   R   R   t
   range_sizet   n_rangest   default_weightt   resultt   modelt   chaint   residue_range_selt   cntrt   rgt   i_seqst   random_chunkst   it   xrs_dct   sel_allt   grm_dct   rot   optimal_weightst   chunkt   selR-   (    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/real_space/weight.pyt   __init__   st    	

)		 !
	t    c         C   s,   x% |  j  D] } | d | | f IJq
 Wd  S(   Ns   %s %s(   R   (   R1   t   logt   prefixt   m(    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/real_space/weight.pyt   showZ   s    Ng      Ð?(   t   __name__t
   __module__R)   RG   RL   (    (    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/real_space/weight.pyR      s   F(	   t
   __future__R    t   cctbx.array_familyR   t,   mmtbx.refinement.real_space.individual_sitesR"   R   t   objectR   (    (    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/real_space/weight.pyt   <module>   s   