ó
Í™xTc           @   sÃ   d  d l  m Z d  d l Z d  d l m Z d  d l Z d  d l m Z d  d l	 m
 Z
 d „  Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d e f d „  ƒ  YZ d „  Z d S(   iÿÿÿÿ(   t   divisionN(   t   flex(   t   matrix(   t   nested_loopc         C   sb   t  j | | ƒ } x. t |  ƒ D]  \ } } | j | | | ƒ q W| j | ƒ d k s^ t ‚ | S(   Ni    (   R   t   size_tt	   enumeratet   set_selectedt   countt   AssertionError(   t   indicest   x_n_seqt   related_x_i_seqst   resultt   i_seqt   i(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/orca.pyt!   expand_model_or_conformer_indices   s
    c         C   s•   t  j | | ƒ } x4 t |  j ƒ  ƒ D]  \ } } | j | | | ƒ q% W| j | ƒ d k sd t ‚ t j j	 d | d |  j
 ƒ  d | d k j ƒ  ƒ S(   Ni    R	   t   tablet   special_position_indices(   R   R   R   R	   R   R   R   t   cctbxt   sgtbxt   site_symmetry_tableR   t
   iselectionR   (   R   R
   R   t	   x_indicesR   R   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/orca.pyt   expand_site_symmetry_table   s    c         C   s  t  j j | ƒ } xê t |  ƒ D]Ü \ } } | | } xÃ | j ƒ  D]µ \ } } | | }	 | j d d t | ƒ t |	 ƒ ƒ }
 xv | D]n } xe |	 D]] } | | k rË | | | k sº t ‚ |
 | | | <q’ | | | k sá t ‚ |
 | | | <q’ Wq… WqB Wq W| S(   Nt   factori   (   R   t   geometry_restraintst   bond_params_tableR   t   itemst   scale_weightt   lenR   (   R   R
   R   R   R   t   bond_params_dictt   x_i_seqst   j_seqt   bond_paramst   x_j_seqst   bond_params_scaledt   x_i_seqt   x_j_seq(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/orca.pyt   expand_bond_params_table    s    

c         C   s  t  j j | ƒ } xü t |  ƒ D]î \ } } | | } xÕ | j ƒ  D]Ç \ } } | | }	 x® | D]¦ }
 x� |	 D]• } |
 | k r¾ | |
 j | t  j j ƒ  ƒ } xa | D] } | j | ƒ q¤ Wql | | j |
 t  j j ƒ  ƒ } x! | D] } | j | j	 ƒ  ƒ qä Wql Wq_ WqB Wq W| S(   N(
   R   t   crystalt   pair_sym_tableR   R   t
   setdefaultR   t   stl_vector_rt_mxt   appendt   inverse(   R(   R
   R   R   R   t   pair_sym_dictR   R    t   sym_opsR"   R$   R%   t	   x_sym_opst   sym_op(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/orca.pyt   expand_pair_sym_table5   s"    



'c         C   sD   t  j | ƒ } x. t |  ƒ D]  \ } } | j | | | ƒ q W| S(   N(   R   t
   std_stringR   R   (   t   nonbonded_typesR
   R   R   R   t   s(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/orca.pyt   expand_nonbonded_typesL   s    c      
   C   sè   t  j j ƒ  } t  j j } xÆ |  D]¾ } | j \ } } } | j d d t | | ƒ t | | ƒ t | | ƒ ƒ }	 xg | | D][ }
 xR | | D]F } x= | | D]1 } | j | d |
 | | f d |	 ƒ j ƒ  ƒ q£ Wq’ Wq� Wq" W| S(   NR   i   t   i_seqst   proxy(	   R   R   t   shared_angle_proxyt   angle_proxyR6   R   R   R+   t   sort_i_seqs(   t   angle_proxiesR
   R   R   t   angle_proxy_tR7   R   t   jt   kt   proxy_scaledt   x_it   x_jt   x_k(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/orca.pyt   expand_angle_proxiesU   s    0/c         C   sÿ   | ƒ  } xï |  D]ç } | j  \ } } }	 }
 | j d d t | | ƒ t | | ƒ t | |	 ƒ t | |
 ƒ ƒ } x | | D]s } xj | | D]^ } xU | |	 D]I } x@ | |
 D]4 } | j | d | | | | f d | ƒ j ƒ  ƒ q³ Wq¢ Wq‘ Wq€ Wq W| S(   NR   i   R6   R7   (   R6   R   R   R+   R:   (   t   proxiest
   proxy_typet   proxy_array_typeR
   R   R   R7   R   R=   R>   t   lR?   R@   RA   RB   t   x_l(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/orca.pyt$   expand_dihedral_or_chirality_proxiesh   s    	>6c      
   C   s  t  j j ƒ  } t  j j } xì |  D]ä } g  | j D] } t | | ƒ ^ q2 } g  | D] } t | ƒ ^ qU }	 | j }
 | j t	 j
 |	 ƒ j ƒ  } xq t |	 ƒ D]c } t j g  t | | ƒ D] \ } } | | ^ q» ƒ } | j | d | d |
 d | ƒ j ƒ  ƒ qŸ Wq" W| S(   NR6   R.   t   weights(   R   R   t   shared_planarity_proxyt   planarity_proxyR6   t   tupleR   R.   RJ   R   t   colt   productR   R   R   t   zipR+   R:   (   t   planarity_proxiesR
   R   R   t   planarity_proxy_tR7   R   t   x_i_seqs_listR   t   loop_nR.   RJ   t   loop_iR   R6   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/orca.pyt   expand_planarity_proxies~   s    &		,$t   expandc           B   s#   e  Z d  „  Z d „  Z d „  Z RS(   c   !   %   C   s¹  d d l  m } | j d d ƒ } t j j j d t | ƒ d | d | j d d	 ƒ ƒ } | j	 j
 d
 | j ƒ } t j ƒ  |  _ t j ƒ  |  _ t j ƒ  |  _ g  |  _ g  |  _ | j | j ƒ  ƒ |  _ d }	 xt | ƒ D]\ }
 } g  } xš | D]’ } t |  j ƒ } |  j | j | ƒ | j | ƒ |  j j d | | |
 f ƒ |  j j | | ƒ |  j j | | ƒ |  j j |
 | f ƒ qó W|  j j | ƒ t | ƒ d k r¸|	 d 7}	 qÚ t | ƒ d k r×|	 d 7}	 qÚ |	 d 7}	 qÚ Wd G| j ƒ  GHd G|  j j ƒ  GHd G| j ƒ  d GHd G|	 GHx2 t |  j ƒ D]! \ } } |  j t | ƒ _ q2Wg  } x” | D]Œ \ } } x} |  j | D]n } |  j | d }
 xT |  j | D]E } |  j | d } |
 | k r£| j t t | | f ƒ ƒ ƒ q£q£Wq~WqdWt j j j d |  j d | d |  j ƒ |  _ t d | j d |  j j ƒ  d |  j ƒ } t d | j d |  j j ƒ  d |  j ƒ } t d | j  d |  j j ƒ  d |  j ƒ } t! d | j" d |  j j ƒ  d |  j ƒ } g  } x? | j# D]4 } | j t$ d | d |  j j ƒ  d |  j ƒ ƒ qÙWt% d | j& d |  j j ƒ  d |  j ƒ } t' d | j( d |  j j ƒ  d |  j ƒ } t) d | j* d t+ j, j- d  t+ j, j. d |  j j ƒ  d |  j ƒ } t) d | j/ d t+ j, j0 d  t+ j, j1 d |  j j ƒ  d |  j ƒ } t2 d! | j3 d |  j j ƒ  d |  j ƒ }  t+ j, j4 j4 d" | j5 d# | d$ | d | d | d% | d& | j6 d | d' | j7 d( | j8 d) | j9 d | d* | d+ | d! |  d, | j: d- | j; d. | j< ƒ |  _= d  |  _? d  S(/   Niÿÿÿÿ(   t   sharedt   omit_slack_greater_thani    t
   n_verticest	   edge_listt   external_clusterst(   constrain_dihedrals_with_sigma_less_thani
   t	   edge_setss   %s:%di   i   i   i   i   s   sites_cart.size():s   O.sites_cart.size():s   original Cartesian dof:s	   orca dof:t   sitesR	   R
   R   R   R   R(   R3   R;   RD   RE   RF   RQ   t   crystal_symmetryt   model_indicest   conformer_indicest   shell_sym_tablest   nonbonded_paramst   nonbonded_functiont   nonbonded_distance_cutofft   nonbonded_buffert   dihedral_proxiest   chirality_proxiest   plain_pairs_radiust   max_reasonable_bond_distancet   min_cubicle_edge(@   t   scitbx.array_familyRX   t   simple_edge_listt   scitbxt   grapht
   tardy_treet	   constructR   t*   rigid_clusters_due_to_dihedrals_and_planest   cluster_managert   overlapping_rigid_clustersR^   R   R2   t   labelst   vec3_doublet
   sites_cartt   doublet   massesR	   R\   t   stl_vector_unsignedt   sizeR   R   R+   RM   t   sortedR   Ra   Rb   R   R   R&   R   Rc   R1   R5   R3   RC   R;   RI   Rh   R   R   t   dihedral_proxyt   shared_dihedral_proxyRi   t   chirality_proxyt   shared_chirality_proxyRV   RQ   t   managerR`   Rd   Re   Rf   Rg   Rj   Rk   Rl   t   geo_managert   Nonet   tardy_tree_rmsd_calculator(!   t   ORv   Rx   Rz   Rƒ   RX   R[   t   ttt   orcst   orca_doft   i_orct   orct   external_clusterR   R$   R   t   x_edge_listR   R=   R@   RA   t   j_orct   x_model_indicest   x_conformer_indicest   x_site_symmetry_tablet   x_bond_params_tablet   x_shell_sym_tablest   shell_sym_tablet   x_nonbonded_typest   x_angle_proxiest   x_dihedral_proxiest   x_chirality_proxiest   x_planarity_proxies(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/orca.pyt   __init__’   sè    				.																	c         C   s   | |  _  |  j S(   N(   R…   t   rmsd_calculation(   R†   R…   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/orca.pyt   rmsd_calculator
  s    	c         C   s4   |  j  t d |  j d | ƒ t d |  j d | ƒ ƒ S(   NR   t   x_sites_cart(   R…   t   average_sites_cartR   (   R†   t   sites_cart_1t   sites_cart_2(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/orca.pyR›     s
    (   t   __name__t
   __module__Rš   Rœ   R›   (    (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/orca.pyRW   �   s   	x	c         C   s=   t  j ƒ  } x* |  D]" } | j | j | ƒ j ƒ  ƒ q W| S(   N(   R   Rw   R+   t   selectt   mean(   R   R�   R   R   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/orca.pyRž     s     (   t
   __future__R    t   cctbx.geometry_restraintsR   t   cctbx.array_familyR   t   scitbx.graph.tardy_treeRo   R   t   libtbx.math_utilsR   R   R   R&   R1   R5   RC   RI   RV   t   objectRW   Rž   (    (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/orca.pyt   <module>   s   	
								…