ó
®™xTc           @   s-  d  d l  m Z d  d l m Z d  d l m 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 m Z d  d	 l m Z d  d l Z e j j d
 ƒ Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d d e  d d „ Z! d  „  Z" d! „  Z# d" „  Z$ d# „  Z% d$ „  Z& e  e j' d% „ Z( e  e j' d d& „ Z) e  e j' d' „ Z* d d( „ Z+ d) e f d* „  ƒ  YZ, d+ e f d, „  ƒ  YZ- d S(-   iÿÿÿÿ(   t   division(   t   easy_mp(   t   make_header(   t
   pad_stringN(   t   null_out(   t   approx_equal(   t   adopt_init_argst
   group_args(   t   sqrts¡  
  restraint_type = *Auto simple lennard_jones implicit
    .type = choice
    .short_caption = Hydrogen bond restraint type
    .caption = Automatic Simple_(H-O) Simple_(N-O) Angle-dependent_(N-O)
    .style = hidden
  include_side_chains = True
    .type = bool
  optimize_hbonds = False
    .type = bool
  optimize_hbonds_thorough = False
    .type = bool
  optimize_mode = *first last every_macro_cycle
    .type = choice
    .expert_level = 3
  restraints_weight = 1.0
    .type = float
  falloff_distance = 0.05
    .type = float
  exclude_nonbonded = True
    .type = bool
  distance_ideal_h_o = 1.975
    .type = float
  distance_cut_h_o = 2.5
    .type = float
  distance_ideal_n_o = 2.9
    .type = float
  distance_cut_n_o = 3.5
    .type = float
  implicit
    .short_caption = Implicit hydrogens
    .help = Based on H-bond potential for CNS by Chapman lab
    .style = box auto_align
  {
    theta_high = 155
      .type = float
    theta_low = 115
      .type = float
    theta_cut = 90
      .type = float
  }
  explicit
    .short_caption = Explicit hydrogens
    .help = Similar to Rosetta H-bond energy (Kortemme & Baker)
    .style = hidden noauto
  {
    theta_ideal = 180
      .type = float
    theta_sigma = 5
      .type = float
    psi_ideal = 155
      .type = float
    psi_sigma = 5
      .type = float
    relative_weights = 1.0 1.0 1.0
      .type = floats(size=3)
  }
  lennard_jones
    .style = hidden noauto
  {
    potential = *4_6 6_12
      .type = choice
  }
  simple
    .short_caption = Simple distance-based potentials
    .help = Pseudo-bond restraints
    .style = hidden
  {
    sigma = 0.05
      .type = float
    slack = 0.0
      .type = float
  }
t   corec           B   s   e  Z d  „  Z d „  Z RS(   c         C   s   g  |  _  g  |  _ d  S(   N(   t   proxiest   exclude_nb_list(   t   self(    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry_restraints/hbond.pyt   __init__[   s    	c         C   s   |  j  j | | f ƒ d  S(   N(   R   t   append(   R   t   i_seqt   j_seq(    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry_restraints/hbond.pyt   add_nonbonded_exclusion_   s    (   t   __name__t
   __module__R   R   (    (    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry_restraints/hbond.pyR	   Z   s   	t   build_proxiesc           B   s&   e  Z d Z d Z d  „  Z d „  Z RS(   c         C   sY   t  j |  ƒ d d  l } d d  l } | j j d ƒ |  _ t |  j |  j ƒ ƒ  |  _	 d  S(   Niÿÿÿÿt   mmtbx_hbond_restraints_ext(
   R	   R   t   cctbx.geometry_restraintst   boost.pythont   pythont
   import_extt   extt   getattrt   proxy_array_typeR
   (   R   t   cctbxt   boost(    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry_restraints/hbond.pyR   e   s
    c         K   s5   t  |  j |  j ƒ } | | �  } |  j j | ƒ d  S(   N(   R   R   t
   proxy_typeR
   R   (   R   t   kwdst   proxy_classt   proxy(    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry_restraints/hbond.pyt	   add_proxyl   s    N(   R   R   t   NoneR   R   R   R#   (    (    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry_restraints/hbond.pyR   b   s   	t   build_simple_hbond_proxiesc           B   s   e  Z d  Z d Z RS(   t   shared_h_bond_simple_proxyt   h_bond_simple_proxy(   R   R   R   R   (    (    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry_restraints/hbond.pyR%   q   s   t   build_lennard_jones_proxiesc           B   s   e  Z d  Z d Z RS(   t!   shared_h_bond_lennard_jones_proxyt   h_bond_lj_proxy(   R   R   R   R   (    (    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry_restraints/hbond.pyR(   u   s   t   build_implicit_hbond_proxiesc           B   s   e  Z d  Z d Z RS(   t   shared_h_bond_implicit_proxyt   h_bond_implicit_proxy(   R   R   R   R   (    (    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry_restraints/hbond.pyR+   {   s   t   explicit_proxyc           B   s   e  Z d  d d „ Z RS(   g      ð?c         C   sb   t  | ƒ d k s t ‚ t  | ƒ d k s0 t ‚ | d  k sN | | k sN t ‚ t |  t ƒ  ƒ d  S(   Ni   i   (   t   lent   AssertionErrorR$   R   t   locals(   R   t   i_seqst   distance_idealt   distance_cutt   theta_idealt	   psi_idealt   weightt   relative_weights(    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry_restraints/hbond.pyR   €   s    (   g      ð?g      ð?g      ð?(   R   R   R   (    (    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry_restraints/hbond.pyR.      s   t   build_explicit_hbond_proxiesc           B   s   e  Z d  „  Z RS(   c         K   s    t  | �  } |  j j | ƒ d  S(   N(   R.   R
   R   (   R   R    R"   (    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry_restraints/hbond.pyR#   Ž   s    (   R   R   R#   (    (    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry_restraints/hbond.pyR9   �   s   t   distance_proxyc           B   s   e  Z RS(    (   R   R   (    (    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry_restraints/hbond.pyR:   ”   s   t   build_distance_proxiesc           B   s   e  Z d  „  Z RS(   c         K   s    t  | �  } |  j j | ƒ d  S(   N(   R:   R
   R   (   R   R    R"   (    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry_restraints/hbond.pyR#   ˜   s    (   R   R   R#   (    (    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry_restraints/hbond.pyR;   —   s   gš™™™™™©?t   4_6c         C   s…  d d l  m } d d  l } | j j d ƒ } | d  k rU | j | j ƒ  d ƒ } n  d }	 t |  ƒ j	 d k r‘ | j
 d | d |  d	 | ƒ }	 nð t |  ƒ j	 d
 k r9| d k rÍ d }
 d } d } d } n' | d k rô d }
 d } d } d } n  | j d | d |  d	 | d | d | d | d |
 d | d | ƒ 	}	 nH t |  ƒ j	 d k ru| j d | d |  d	 | d | ƒ }	 n d s�t ‚ |	 S(   Niÿÿÿÿ(   t   flexR   i    g        R&   t
   sites_cartR
   t   gradient_arrayR)   R<   i�  i   i   g>,p½ ê?t   6_12iú   i   g)ÁN>‚ì?t   falloff_distancet   at   bt   scalet
   sigma_baset   use_finite_differencesR,   (   i    i    i    (   t   scitbx.array_familyR=   R   R   R   R$   t   vec3_doublet   sizet   typeR   t   h_bond_simple_residual_sumt!   h_bond_lennard_jones_residual_sumt   h_bond_implicit_residual_sumR0   (   R
   R>   R?   RA   RF   t   lennard_jones_potentialR=   R   R   t   sumt   weight_scaleRB   RC   RE   (    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry_restraints/hbond.pyt   target_and_gradientsœ   sP    					c         C   sÆ   d d l  m } d d  l } | j j d ƒ } t |  ƒ j d k rP | j |  ƒ St |  ƒ j d k rr | j |  ƒ St |  ƒ j d k r” | j	 |  ƒ St
 |  t ƒ r¶ | j t |  ƒ ƒ Sd sÂ t ‚ d  S(   Niÿÿÿÿ(   t   sharedR   R&   R)   R,   i    (   RG   RR   R   R   R   RJ   R   t   simple_hbonds_as_simple_bondst   lj_hbonds_as_simple_bondst   implicit_hbonds_as_simple_bondst
   isinstancet   listt   stl_set_unsignedt   get_simple_bond_equivalentsR0   (   R
   RR   R   R   (    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry_restraints/hbond.pyt   get_simple_bondsÌ   s    c         C   s.   g  } x! |  D] } | j  t | ƒ ƒ q W| S(   sÉ   
Given a list of proxies, extract the pair of atom indices representing the
actual "bond", e.g. H-O or N-O.  These are used to exclude the atom pair from
the nonbonded interaction restraints function.
(   R   t   _get_simple_bond(   R
   t
   bond_pairsR"   (    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry_restraints/hbond.pyRY   Û   s    c         C   sH   d d  l  } t |  t ƒ r8 |  j d |  j d f } n d sD t ‚ | S(   Niÿÿÿÿi    i   (   RG   RV   R:   R2   R0   (   R"   t   scitbxt   pair(    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry_restraints/hbond.pyR[   æ   s
    c   
      C   sV   |  | \ } } } |  | \ } } } t  | | d | | d | | d ƒ }	 |	 S(   Ni   (   R   (
   R>   R   R   t   x1t   y1t   z1t   x2t   y2t   z2t   dist(    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry_restraints/hbond.pyt	   _distanceî   s    ,c         C   sp   g  } xc |  D][ } t  | ƒ \ } } t | | | ƒ } | j d k r[ | | j k r[ q n  | j | ƒ q W| S(   Ni    (   R[   Rf   R4   R   (   R
   R>   t   filtered_proxiesR"   R   R   t   distance(    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry_restraints/hbond.pyt   filter_excessive_distancesô   s    c         C   sÉ   | j  ƒ  } | j ƒ  } | r0 t |  | ƒ }  n  x’ |  D]Š } t | ƒ \ } } | | j ƒ  }	 | | j ƒ  }
 d } | |	 j |	 j |	 j f } | |
 j |
 j |
 j f } | d | | f IJq7 Wd  S(   Ns"   chain "%s" and resi %s and name %ss   dist %s, %s(   t   atomst   extract_xyzRi   R[   t   fetch_labelst   chain_idt   resseqt   name(   R
   t   pdb_hierarchyt   filtert   outt	   pdb_atomsR>   R"   R   R   t   atom1t   atom2t	   base_selet   sele1t   sele2(    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry_restraints/hbond.pyt   as_pymol_dashesþ   s    c      
   C   s¼   | j  ƒ  } | j ƒ  } | r0 t |  | ƒ }  n  x… |  D]} } t | ƒ \ } }	 | | j ƒ  }
 | |	 j ƒ  } d d |
 j |
 j |
 j | j | j | j | j d f } | | IJq7 Wd  S(   Ns,   exte dist first chain %s residue %s atom %s s8   second chain %s residue %s atom %s value %.3f sigma %.2fgš™™™™™©?(	   Rj   Rk   Ri   R[   Rl   Rm   Rn   Ro   R3   (   R
   Rp   Rq   Rr   t   sigmaRs   R>   R"   R   R   Rt   Ru   t   cmd(    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry_restraints/hbond.pyt   as_refmac_restraints  s    c         C   sL  | j  ƒ  } | j ƒ  } | d IJ| r: t |  | ƒ }  n  x|  D]} t | ƒ \ } } | | j }	 | | j }
 |
 d |	 d |
 d |	 d |
 d |	 d f } | d IJx‘ t d d ƒ D]€ } t | ƒ d } |	 d | d | |	 d | d | |	 d | d | f } | d k r2| d | IJqÀ | d | IJqÀ WqA Wd  S(	   Ns8   @group {PHENIX H-bonds}
@subgroup {H-bond dots} dominanti    i   i   s"   @dotlist {Drawn dots} color= greeni   s   {drawn} %.4f %.4f %.4fs   {''} %.4f %.4f %.4f(   Rj   Rk   Ri   R[   t   xyzt   ranget   float(   R
   Rp   Rq   Rr   Rs   R>   R"   R   R   RB   RC   t   abt   xt   fact   vec(    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry_restraints/hbond.pyt   as_kinemage  s$    3
?c   (      C   sH  | d  k r t ƒ  } n  d } | j rH | d d d d d d 7} n  d } | j rl | d	 d
 d 7} n  d } | j r� | d d d 7} n  |  j ƒ  } | j | ƒ } | j | ƒ }	 | j | ƒ }
 | j } | d k rê t ƒ  } n | d" k sü t ‚ t ƒ  } t	 | ƒ d k s;t	 |	 ƒ d k s;t	 |
 ƒ d k r?| S| j
 d | j ƒ } | j d t ƒ } |  j ƒ  } | j ƒ  } | j ƒ  } | j ƒ  } xŠt | ƒ D]|\ } } |	 | s¿q£n  | | } | | } | j ƒ  } | j ƒ  } | j } | } d  } } xü | j ƒ  D]î \ } } | | r9|
 | r9qn  | | } | | }  | j ƒ  }! |! j ƒ  }" |! j }# | | r–| |" k r–| |# k r–qn  xf | D]^ }$ |$ j ƒ  r�|
 | rò| j | |  ƒ }% | d  k	 rÚqø|% d k  rø| } qøqû| } q�q�WqWd  | | g k r£| | | g }& | j | |& d | |& d | |& d ƒ }' |' | j j k r| d k r½| j d | | g d | j d | j d | j | j j  d d | j j! ƒ nL | j d | | | g d | j d | j d | j j" d | j j# d | j ƒ | j$ | | ƒ qq£q£W| d  IJ| d! t	 | j% ƒ IJ| S(#   Ns"   name N or (resname HOH and name O)s"    or (resname ASN and name ND2) or s<   (resname GLN and name NE2) or (resname TRP and name NE1) or s;   (resname HIS and name NE2) or (resname LYS and name NZ) or s:   (resname ARG and name N*) or (resname TYR and name OH) or s;   (resname SER and name OG) or (resname THR and name OG1) or s   (resname HOH and name O)s   name Os!    or (resname SER and name OG) or s;   (resname THR and name OG1) or (resname TYR and name OH) or s8   (resname ASN and name OD1) or (resname GLN and name OE1)s   name Cs!    or (resname SER and name CB) or s:   (resname THR and name CB) or (resname TYR and name CZ) or s6   (resname ASN and name CG) or (resname GLN and name CD)t   simplet   Autot   impliciti    t   distance_cutofft   skip_j_seq_less_than_i_seqg       @i   i   R2   R3   R4   R7   t   slackt	   theta_lowt
   theta_hight    s(     %d hydrogen bond restraints generated.(   R†   s   implicit(&   R$   R   t   include_side_chainst   atom_selection_cachet	   selectiont   restraint_typeR%   R0   R+   R/   t   pair_asu_tablet   distance_cut_n_ot   extract_pair_sym_tablet   FalseRj   t	   unit_cellt
   sites_fracR>   t	   enumerateRl   t   residRm   t   itemst
   is_unit_mxRh   t   angleR‡   t	   theta_cutR#   t   distance_ideal_n_ot   restraints_weightR…   Rz   RŠ   R‹   RŒ   R   R
   ((   Rp   t   xray_structuret   paramst   logt   donor_selectiont   acceptor_selectiont   acceptor_base_selectiont   selection_cachet   donorst	   acceptorst   acceptor_basesR‘   R   R’   t   pair_sym_tableRj   R–   R—   R>   R   t   pair_sym_dictt   site_jt   atom_jt   atom_labels_jt   resid_jt   chain_jt   acceptor_i_seqt   donor_i_seqt   acceptor_base_i_seqt   k_seqt   sym_opst   atom_kt   site_kt   atom_labels_kt   resid_kt   chain_kt   sym_opRh   R2   Rœ   (    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry_restraints/hbond.pyt   find_implicit_hydrogen_bonds2  s²    					6			


	


	"
'						

t   optimize_hbond_restraintsc           B   sD   e  Z d  „  Z e d „ Z d „  Z e d „ Z d „  Z d „  Z	 RS(   c         C   s  t  |  t ƒ  ƒ | j s( | j s( t ‚ | j j } | d  k	 rO | j d  k	 sU t ‚ | j |  _	 d d l
 m }	 |	 j d |  j j ƒ  j d |  j j ƒ |  j j ƒ  j j ƒ  j ƒ  |  _ t d d |  j ƒ| j ƒ  t |  j j ƒ  j ƒ  |  j j d t ƒ j ƒ  ƒ st ‚ g  }
 g  } x% t d ƒ D] } | j d	 | ƒ q)Wd
 d d d d g } d d d d d g } d d d d d g } d d d d g } d d d g } xi | D]a } |
 j t d |  j j  d | d  |  j j! d! |  j j" j# d" |  j j" j$ d# |  j j" j% ƒ ƒ q«Wt& j' d$ |  j( d% |
 d& d' ƒ } g  | D] \ } } | ^ q8} |  j t) d( d) ƒ IJ|  j t) d* ƒ IJ|  j* | | j ƒ |  j+ t, ƒ | j ƒ  |  j t) d+ ƒ IJg  }
 xn | D]f } x] | D]U } |
 j t d |  j j  d |  j j- d  |  j j! d! | d" | d# |  j j" j% ƒ ƒ qÒWqÅWt& j' d$ |  j( d% |
 d& d' ƒ } g  | D] \ } } | ^ qW} |  j t) d, ƒ IJ|  j* | | j ƒ | j ræ|  j+ t, ƒ |  j t) d+ ƒ IJ| j ƒ  g  }
 x| | D]t } xk | D]c } xZ | D]R } |
 j t d | d |  j j- d  | d! |  j j" j# d" |  j j" j$ d# | ƒ ƒ qðWqãWqÖWt& j' d$ |  j( d% |
 d& d' ƒ } g  | D] \ } } | ^ qv} |  j t) d- ƒ IJ|  j* | t ƒ |  j+ t, ƒ |  j t) d+ ƒ IJ| j ƒ  g  }
 |  j j- } g  t d. d/ ƒ D] } | | d0 ^ qý} xi | D]a } |
 j t d |  j j  d | d  |  j j! d! |  j j" j# d" |  j j" j$ d# |  j j" j% ƒ ƒ qWt& j' d$ |  j( d% |
 d& d' ƒ } g  | D] \ } } | ^ q«} |  j t) d* ƒ IJ|  j* | ƒ n  |  j t) d( d) ƒ IJd  S(1   Niÿÿÿÿ(   t   utilsR_   Rb   s   Optimizing H-bond refinementRr   t   compute_gradientsi   g      Ð?gffffff@gÍÌÌÌÌÌ@g333333@gš™™™™™@g      @i–   i›   i    i¥   iª   i_   id   ii   in   is   g333333@g      @gÍÌÌÌÌÌ@gš™™™™™@iZ   Rž   RŸ   R“   RŒ   R‹   R�   t
   fixed_funct   argst   func_wrappert   buffer_stdout_stderrt   -iF   s    Weight:R�   s    Theta high vs. theta low:s3    N-O distance vs. distance cutoff vs. angle cutoff:iöÿÿÿi   gš™™™™™©?(.   R   R1   t   optimize_hbondst   optimize_hbonds_thoroughR0   t   restraints_managert   geometryR$   t   generic_restraints_managert   rmt   mmtbxR¾   t   assert_xray_structures_equalt   fmodelst   fmodel_xrayR    t   modelt   deep_copy_scattererst
   scattererst   save_scatterersR   R¢   t   create_target_functorsR   t   target_wt   target_functor_result_xrayR•   t   target_workR~   R   R   R¡   Rž   R“   R‡   RŒ   R‹   R�   R   t   pool_mapt   _trial_minimizationt   pst   process_resultst   reset_sitest   TrueRŸ   (   R   RÏ   RÍ   t   monitorst   target_weightsR¡   t   nprocR¢   t   grmR¾   t   trial_settingst   weightst   it	   distancest   thetas_hight
   thetas_lowt   distance_cutoffst   theta_cutoffst   wt   stdout_and_resultst   sot   rt   resultst   theta1t   theta2Rh   t   cutofft   thetaR�   (    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry_restraints/hbond.pyR   ¡  sÐ    !	!
			
				
			
*			c         C   s\  g  } d  } t j } xK | D]C } | d  k	 r | j | ƒ | j | k  r_ | j } | } q_ q q Wt | ƒ d k rS|  j t d ƒ IJ|  j t d d d ƒ IJxI | D]A } | | k rØ | j d |  j d d ƒ qª | j d |  j ƒ qª W|  j	 | j
 ƒ |  j j ƒ  j j | d	 j ƒ |  j j d
 |  j j ƒ  j d t d t ƒ |  j j ƒ  j |  j _ |  j t d d d ƒ IJ| rX|  j t d ƒ IJ|  j t d |  j j ƒ IJ|  j t d |  j j ƒ IJ|  j t d |  j j ƒ IJ|  j t d |  j j j ƒ IJ|  j t d |  j j j ƒ IJ|  j t d |  j j j ƒ IJqXn d GHd  S(   Ni    s<         wt  dist   cut theta1 theta2 cut2 r_work r_free  r_gaps      RÄ   i<   Rr   t   marks   <<<iÿÿÿÿR    t   update_f_calct   update_f_masks        Optimized H-bond parameters:s.               Weight (restraints_weight) = %4.2fs.        N-O distance (distance_ideal_n_o) = %5.3fs.                Cutoff (distance_cut_n_o) = %5.3fs.                  High angle (theta_high) = %3.0ds.                    Low angle (theta_low) = %3.0ds.                 Angle cutoff (theta_cut) = %3.0ds?     No hydrogen bonds found (works for proteins only at present).(   R$   t   syst   maxintR   t   r_gapR/   R¢   RÙ   t   showt   copy_settingst   settingsRÍ   RÎ   R    t   set_sites_fracR—   t   update_xray_structureRÜ   RÏ   R¡   RŸ   Rž   R“   R‡   RŒ   R‹   R�   (   R   Rí   t   print_final_paramst   results_finalt   best_resultt
   best_r_gapt   result(    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry_restraints/hbond.pyRÚ     sP    		c         C   sg   | j  |  j _  | j |  j _ | j |  j _ | j |  j j _ | j |  j j _ | j |  j j _ d  S(   N(   Rž   R¡   RŸ   R“   RŒ   R‡   R‹   R�   (   R   Rú   (    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry_restraints/hbond.pyRù   C  s    c      	   C   sW   |  j  j ƒ  j j |  j j ƒ  ƒ |  j  j d |  j  j ƒ  j d t d | d | ƒ d  S(   NR    Ró   Rô   t   force_update_f_mask(   RÍ   RÎ   R    t   replace_scatterersRÒ   t	   deep_copyRü   RÜ   (   R   Rô   (    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry_restraints/hbond.pyRÛ   K  s    c      	   C   s¹   |  j  | ƒ |  j j d |  j j ƒ  d |  j j d |  j d t ƒ  ƒ |  j j ƒ  } | d k rf d  S|  j
 ƒ  |  j ƒ  } t d |  j j ƒ  j ƒ  d |  j j ƒ  j ƒ  d | d	 | ƒ S(
   NRp   R    R¡   R¢   i    t   r_workt   r_freeRú   R—   (   Rù   RÊ   t   update_hydrogen_bondsRÏ   Rp   R    R¡   R   t   get_n_hbondsR$   RÛ   t   minimizet   trial_resultRÍ   RÎ   R  R  (   R   Rú   t   n_hbondst	   new_sites(    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry_restraints/hbond.pyRØ   T  s     	

c         C   sû   d d  l  } d d l m } d d  l } | j d |  j j ƒ  j d |  j j ƒ |  j j	 ƒ  | j
 j j d |  j j d |  j d |  j d t d	 |  j ƒ } |  j j ƒ  j |  j _ | j |  j j k sÏ t ‚ | j d | j d |  j j ƒ | j j ƒ  S(
   Niÿÿÿÿ(   R¾   R_   Rb   RÇ   RÍ   RÏ   t
   refine_xyzRÞ   (   t   mmtbx.refinement.minimizationRË   R¾   t   scitbx.lbfgsRÌ   RÍ   RÎ   R    RÏ   t   set_refine_individual_sitest
   refinementt   minimizationt   lbfgsRÇ   RÜ   RÞ   R0   R—   (   R   RË   R¾   R]   t	   minimized(    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry_restraints/hbond.pyR	  f  s&    					(
   R   R   R   RÜ   RÚ   Rù   R•   RÛ   RØ   R	  (    (    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry_restraints/hbond.pyR½      s   	v,			R
  c           B   s    e  Z d  „  Z d d d „ Z RS(   c         C   s!   t  |  t ƒ  ƒ | | |  _ d  S(   N(   R   R1   R÷   (   R   R  R  Rú   R—   (    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry_restraints/hbond.pyR   |  s    R�   c         C   s�   | d  k r t ƒ  } n  d } | t | |  j j |  j j |  j j |  j j |  j j |  j j	 |  j
 |  j |  j | f
 ƒ IJd  S(   Ns7       %4.2f %4.3f %4.3f %6d %6d %4d %6.4f %6.4f %6.4f %3s(   R$   R   RÙ   Rú   RŸ   Rž   R“   RŒ   R‹   R�   R  R  R÷   (   R   Rr   Rò   t   fs(    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry_restraints/hbond.pyRø   €  s     N(   R   R   R   R$   Rø   (    (    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry_restraints/hbond.pyR
  {  s   	(.   t
   __future__R    t   libtbxR   t   libtbx.str_utilsR   R   RÙ   t   libtbx.philt   libtbx.utilsR   t   libtbx.test_utilsR   R   R   t   mathR   Rõ   t   philt   parset   master_philt   objectR	   R   R%   R(   R+   R.   R9   R:   R;   R$   RÜ   RQ   RZ   RY   R[   Rf   Ri   t   stdoutRy   R|   R„   R¼   R½   R
  (    (    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry_restraints/hbond.pyt   <module>   sH   	I	+					
	kÛ