ó
…™xTc           @   sk  d  d l  m Z d  d l Z d  d l Z d  d l m Z d  d l m Z d  d l m	 Z	 d  d l m
 Z
 d  d l m Z m Z d  d l Z e j j d d	 ƒ r² d  d
 l m Z n d Z 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 e j j d d	 ƒ rgd  d l Tn  d S(   iÿÿÿÿ(   t   divisionN(   t   flex(   t   crystal(   t   xray(   t   sgtbx(   t   adp_restraintst   geometry_restraintst   namet   smtbx(   R   c         G   s   t  j t  |  | i  ƒ S(   sq    This function will make on-the-fly a builder class with the given
  name, that inherits from the given builders (   t   typet   __new__(   t
   mixin_namet   mixed_builders(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/builders.pyt   mixin_builder_class   s    t   crystal_symmetry_builderc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s1   t  j d | d | ƒ |  _ d |  j j ƒ  _ d  S(   Nt	   unit_cellt   space_groupi    i   (   i    (   i    i    i    i    i    i    (   R   t   symmetryt   crystal_symmetryR   t   parameter_sigmas(   t   selfR   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/builders.pyt   make_crystal_symmetry   s    c         C   s   | |  j  j ƒ  _ d  S(   N(   R   R   R   (   R   t   s(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/builders.pyt   set_unit_cell_parameter_sigmas   s    (   t   __name__t
   __module__R   R   (    (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/builders.pyR      s   	t   electron_density_peakc           B   s   e  Z d Z d „  Z RS(   t   sitet   heightc         C   s   | |  _  | |  _ d  S(   N(   R   R   (   R   R   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/builders.pyt   __init__'   s    	(   s   sites   height(   R   R   t	   __slots__R   (    (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/builders.pyR   #   s   t   crystal_structure_builderc           B   sG   e  Z e d  d „ Z d „  Z d „  Z d d d d d „ Z d „  Z RS(   g      à?c         C   s_   t  t |  ƒ j ƒ  | |  _ | |  _ d  |  _ d  |  _ g  |  _ i  |  _	 i  |  _
 i  |  _ d  S(   N(   t   superR   R   t   set_grad_flagst   min_distance_sym_equivt   Nonet   conformer_indicest   sym_excl_indicest   electron_density_peakst   index_of_scatterer_namedt   residue_class_of_residue_numbert   residue_numbers_having_class(   R   R!   R"   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/builders.pyR   .   s    							c         C   s1   t  j d t j d |  j d |  j ƒ ƒ |  _ d  S(   Nt   special_position_settingsR   R"   (   R   t	   structureR   R*   R   R"   (   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/builders.pyt   make_structure;   s    			c         C   s-   | |  j  | <|  j j | g  ƒ j | ƒ d  S(   N(   R(   R)   t
   setdefaultt   append(   R   t   residue_numbert   residue_class(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/builders.pyt   add_residueA   s    	c         C   sá  |  j  r› | j } t | d d !ƒ r5 | j t ƒ n  | d rO | j t ƒ n  | j ƒ  rx | d r˜ | j t ƒ q˜ q› t | d ƒ r› | j t ƒ q› n  |  j	 j
 | ƒ t |  j	 j ƒ  ƒ d }	 | rA|  j	 j ƒ  d }
 |
 j |
 j ƒ  _ t j j j |
 j d d ƒ} | j ƒ  } t | j ƒ  | j ƒ  d	 ƒ |
 _ n  | d
 k	 r�|  j d
 k rnt j ƒ  |  _ n  |  j j | ƒ n  | d
 k	 rÁ|  j d
 k r®t j ƒ  |  _ n  |  j j | ƒ n  |	 |  j | | j j ƒ  f <d
 S(   só    If the parameter set_grad_flags passed to the constructor was True,
        the scatterer.flags.grad_xxx() will be set to True
        if the corresponding variables have been found to be refined
        by the parser using this builder.
    i    i   i   iúÿÿÿi   iÿÿÿÿt   epsgñhãˆµøä>i   N(    R!   t   flagst   allt   set_grad_sitet   Truet   set_grad_occupancyt	   use_u_isot   set_grad_u_isot   set_grad_u_anisoR+   t   add_scatterert   lent
   scattererst	   occupancyt   weight_without_occupancyt   scitbxt   matht   continued_fractiont	   from_realt   as_rationalt   roundt	   numeratort   denominatorR#   R$   R   t   size_tR.   R%   R'   t   labelt   lower(   R   t	   scatterert
   is_refinedt"   occupancy_includes_symmetry_factort   conformer_indext   sym_excl_indexR/   R0   t   ft   scatterer_indext   sct   occt   r_occ(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/builders.pyR;   G   s8    		

%  c         C   s   |  j  j t | | ƒ ƒ d  S(   N(   R&   R.   R   (   R   R   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/builders.pyt   add_electron_density_peakr   s    N(	   R   R   R6   R   R,   R1   R#   R;   RU   (    (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/builders.pyR   ,   s   		&t$   restrained_crystal_structure_builderc           B   sþ   e  Z i e j d  6e j d 6e j d 6e j d 6e j d 6e j d 6Z	 e
 d k	 r³ i e
 j d 6e
 j d 6e
 j d 6e
 j d	 6e
 j d
 6e
 j d 6Z i e
 j d 6e
 j d 6Z n i  Z i  Z d „  Z d „  Z d „  Z d e j f d „  ƒ  YZ d „  Z RS(   t   bondt   anglet   dihedralt	   planarityt	   chiralityt   bond_similarityt   adp_similarityt
   rigid_bondt   isotropic_adpt   fixed_u_eq_adpt   adp_u_eq_similarityt   adp_volume_similarityc         O   s×   t  t |  ƒ j | | Ž  t } t } i  |  _ i t j ƒ  d 6t j ƒ  d 6t j ƒ  d 6t j	 ƒ  d 6t j
 ƒ  d 6t j ƒ  d 6t j ƒ  d 6t j ƒ  d 6t j ƒ  d	 6t j ƒ  d
 6t j ƒ  d 6t j ƒ  d 6|  _ d  S(   NRW   RX   RY   RZ   R[   R\   R]   R^   R_   R`   Ra   Rb   (   R    RV   R   R   R   t   _proxiest   shared_bond_simple_proxyt   shared_angle_proxyt   shared_dihedral_proxyt   shared_planarity_proxyt   shared_chirality_proxyt   shared_bond_similarity_proxyt   shared_adp_similarity_proxyt   shared_rigid_bond_proxyt   shared_isotropic_adp_proxyt   shared_fixed_u_eq_adp_proxyt    shared_adp_u_eq_similarity_proxyt"   shared_adp_volume_similarity_proxy(   R   t   argst   kwdst   geomt   adp(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/builders.pyR   ‘   s"    	c         O   s�   | |  j  k r_ |  j | | d <| |  j k s; d | k rK |  j | d <n  |  j  | | �  n- |  j | } | | �  } |  j | j | ƒ d  S(   Nt   proxiest   pair_sym_tablet   xray_structure(   t   adp_restraint_typesRc   t/   adp_restraint_types_requiring_connectivity_onlyR+   t   geometry_restraint_typesR.   (   R   t   restraint_typeRp   Rq   t
   proxy_typet   proxy(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/builders.pyt	   add_proxy¦   s    c         O   sd  d „  } d | k r*| d } xØ t  | ƒ D]Ê \ } } | d  k	 r, t | t j ƒ r, t | ƒ d k rà | d k s{ t ‚ | } xO t  | ƒ D]A \ }	 } | d  k	 rŽ t | t j ƒ rŽ t j | ƒ | |	 <qŽ qŽ W| | | <qö t j | ƒ | | <q, q, W| j d  ƒ t | ƒ k r| d =qP| d k rÕ| j d  ƒ d k rId  }
 nx | j d  ƒ d k r’| d }
 |
 d  k rÁ| d }
 | d j ƒ  qÁn/ | d } | d } | j	 ƒ  } | j
 | ƒ }
 |
 | d	 <| d =qP| d k rg  | d <xé t  | ƒ D]Û \ } } | d  k søt | t j ƒ r(qøn  | j d  ƒ d k rFd  }
 n| | j d  ƒ d k r“| d }
 |
 d  k rÂ| d }
 | d | j ƒ  qÂn/ | d } | d } | j	 ƒ  } | j
 | ƒ }
 | d j |
 ƒ qøW| d j d  ƒ t | ƒ k r | d =q'| | d ƒ | d <qP| | ƒ | d <n& d	 | k rP| d	 d  k rP| d	 =n  |  j | | � d  S(
   Nc         S   s@   x9 t  |  ƒ D]+ \ } } | d  k r t j ƒ  |  | <q q W|  S(   N(   t	   enumerateR#   R   t   rt_mx(   t   sym_opst   it   sym_op(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/builders.pyt   replace_None_with_unit_matrix³   s    R€   i   R\   RW   i   i    t   i_seqst   rt_mx_ji(   R~   R#   t
   isinstanceR   R   R<   t   AssertionErrort   countt   reverset   inverset   multiplyR.   R}   (   R   Rz   Rp   Rq   Rƒ   R€   R�   R‚   t   sym_op_pairt   jR…   t
   rt_mx_ji_1t
   rt_mx_ji_2t   rt_mx_ji_invt   sym_ops_(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/builders.pyt   process_restraint²   sj    	

	






 	





t   restraints_managerc           B   s   e  Z d  „  Z RS(   c         C   sU   d d l  m } t g  |  j ƒ  j ƒ  D] \ } } d | | f ^ q& ƒ } | | �  S(   Niÿÿÿÿ(   t   managers
   %s_proxies(   t   smtbx.refinement.restraintsR”   t   dictRt   t	   iteritems(   R   R”   R   t   valueRq   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/builders.pyt   fgetó   s    5(   R   R   R™   (    (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/builders.pyR“   ò   s   c         C   sD   t  g  |  j j ƒ  D]* \ } } t | ƒ d k r | | f ^ q ƒ S(   Ni    (   R–   Rc   R—   R<   (   R   R{   Rt   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/builders.pyRt   ù   s    N(   R   R   R   t   bond_simple_proxyt   angle_proxyt   dihedral_proxyt   planarity_proxyt   chirality_proxyt   bond_similarity_proxyRy   t   smtbx_adp_restraintsR#   t   adp_similarity_restraintst   rigid_bond_restraintst   isotropic_adp_restraintst   fixed_u_eq_adp_restraintst   adp_u_eq_similarity_restraintst    adp_volume_similarity_restraintsRw   Rx   R   R}   R’   t   libtbxt   propertyR“   Rt   (    (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/builders.pyRV   v   s2   










			@t   reflection_data_source_builderc           B   s    e  Z d  Z d d d d „ Z RS(   s   A builder which is passed the information about the reflections
  corresponding to the parsed

  Attributes:

    - reflection_file_format: a string to identify the format, compatible with
              iotbx.reflection_file_reader.any_reflection_file
    - data_change_of_basis_op: the instance of sgtbx.change_of_basis_op that
                          shall be applied to the Miller indices to match
                          the parsed model
    - data_scale: the scale of the data and their standard deviations
  i   c         C   s¡   | | g j  d ƒ d k s! t ‚ | d k r~ | j ƒ  rH t j ƒ  } q~ t j | j d ƒ j ƒ  ƒ } t j | ƒ j	 ƒ  } n  d | |  _
 | |  _ | |  _ d S(   sa    format is one of 3, 4, 5, etc.
    data_scale scales the data and their standard deviations
    i   i   s   hklf%iN(   Rˆ   R#   R‡   t
   is_unit_mxR   t   change_of_basis_opR   t   new_denominatort	   transposeRŠ   t   reflection_file_formatt   data_change_of_basis_opt
   data_scale(   R   t   formatt   indices_transformR«   R°   t   r(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/builders.pyt#   create_shelx_reflection_data_source  s    !	N(   R   R   t   __doc__R#   R´   (    (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/builders.pyR©   þ   s   t   twinning_builderc           B   s,   e  Z d  Z d Z d Z d „  Z d „  Z RS(   s¡   Construct twin components
      They come as a tuple of instances of xray.twin_component.
      If R is the twin law, the i-th component corresponds to the domain
      where Miller indices are to be transformed by R^(i+1). The domain
      with untransformed Miller indices is omitted as its fraction is just
      1 minus the sum of the listed fractions.
      As a result, the 0th component holds the twin law.
  c      	   C   s|   g  |  _  t | t j ƒ r* | j ƒ  } n  | } xE | D]= } |  j  j t j d | d | d t ƒ ƒ | j	 | ƒ } q7 Wd  S(   Nt   twin_lawR˜   t   grad(
   t   twin_componentsR†   R   R   R³   R.   R   t   twin_componentR6   R‹   (   R   R·   t	   fractionst   tRP   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/builders.pyt   make_merohedral_twinning,  s    	 
c         C   s   | |  _  d  S(   N(   t3   non_merohedral_twin_components_with_transformed_hkl(   R   R»   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/builders.pyt1   make_non_merohedral_twinning_with_transformed_hkl6  s    (    (    (   R   R   Rµ   R¹   R¾   R½   R¿   (    (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/builders.pyR¶     s
   	
(   t   *(   t
   __future__R    R§   t   scitbx.mathR@   t   cctbx.array_familyR   t   cctbxR   R   R   R   R   t   libtbx.load_envt   envt
   has_moduleR•   R    R#   R   t   objectR   R   R   RV   R©   R¶   t!   iotbx.builders_depending_on_smtbx(    (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/builders.pyt   <module>   s(   		Jˆ!