ó
0™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 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 d  d l Z 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 m Z m Z m 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 d e$ f d „  ƒ  YZ% d e j& f d „  ƒ  YZ' d e$ f d „  ƒ  YZ( d e$ f d „  ƒ  YZ) d S(   iÿÿÿÿ(   t   division(   t   ext(   t   structure_factors(   t   miller(   t   crystal(   t   sgtbxN(   t   adptbx(   t   eltbx(   t   flex(   t   matrix(   t   math(   t   count(   t	   count_maxt   Sorryt   Keep(   t   approx_equal(   t
   group_args(   t	   is_string(   t   neutron_news_1992_tablet   scattering_type_registry_paramsc           B   s   e  Z d d d d d  „ Z RS(   c         C   s(   | |  _  | |  _ | |  _ | |  _ d  S(   N(   t   custom_dictt   d_mint   tablet'   types_without_a_scattering_contribution(   t   selfR   R   R   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   __init__   s    			N(   t   __name__t
   __module__t   NoneR   (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR      s   t	   structurec        	   B   sû  e  Z d  Z dœ dœ dœ e dœ dœ d „ Z d „  Z d „  Z d „  Z d „  Z	 e
 e
 e
 e
 d „ Z d „  Z d „  Z dœ dœ dœ d	 „ Z dœ dœ dœ d
 „ Z d „  Z dœ d „ Z dœ d „ Z d „  Z dœ d „ Z d „  Z d d d d „ Z dœ d „ Z dœ d „ Z dœ d „ Z dœ d „ Z dœ d „ Z dœ dœ d d e d dœ d „ Z d d „ Z d „  Z dœ d „ Z dœ d „ Z  dœ d  „ Z! d! „  Z" d" „  Z# d# „  Z$ d$ „  Z% d% „  Z& e d& „ Z' dœ dœ dœ e dœ d' „ Z( dœ d( „ Z) d) „  Z* d* „  Z+ d+ „  Z, d, „  Z- d- „  Z. d. „  Z/ d/ „  Z0 d0 „  Z1 d1 „  Z2 d2 „  Z3 d3 „  Z4 d4 „  Z5 d5 „  Z6 d6 „  Z7 d7 „  Z8 e e e d8 „ Z9 d9 d: d; d< g e e d= „ Z: d9 d: d; d< g e e d> „ Z; d9 d: d; d< d? g e e d@ „ Z< d9 d; d< g e e dA „ Z= dB „  Z> dC „  Z? dD „  Z@ dE „  ZA dœ eB dF „ ZC dG „  ZD dœ dH „ ZE dœ dI „ ZF dJ dœ e dK „ ZG dL „  ZH dM „  ZI dœ dœ dœ dœ e dN „ ZJ eB dO „ ZK eB dP dQ „ ZL dR „  ZM dS „  ZN e dT „ ZO dU „  ZP dœ dœ dV „ ZQ dœ e dW „ ZR dX „  ZS dY „  ZT dZ „  ZU d[ d\ „ ZV dœ dœ dœ e dœ dœ dœ dœ d] „ ZW dJ d^ „ ZX dœ dJ d_ „ ZY dœ e d` „ ZZ dœ dœ dœ dJ da „ Z[ dœ db „ Z\ dc e] j^ dd ƒ de df „ Z_ dœ dœ dœ dg „ Z` dœ dh „ Za di „  Zb dj „  Zc dk „  Zd dl „  Ze dm „  Zf dn „  Zg do „  Zh e e dp „ Zi dq „  Zj dr „  Zk e ds „ Zl dt du „ Zm dv e dw „ Zn dx „  Zo dy „  Zp dœ dz „ Zq dœ d{ „ Zr dœ d| „ Zs dœ d} „ Zt d~ „  Zu d „  Zv e d€ „ Zw d� „  Zx d‚ „  Zy dƒ „  Zz d„ „  Z{ d… „  Z| e dœ d† „ Z} e e e dœ d‡ „ Z~ dœ dˆ „ Z dœ dœ dœ d‰ dŠ „ Z€ dœ dœ dœ d‰ dœ e e dœ d‹ „ Z� dœ dœ dœ dœ e dœ dŒ „ Z‚ d� „  Zƒ dŽ „  Z„ d� „  Z… dœ d� „ Z† d‘ „  Z‡ d’ „  Zˆ dœ d“ d” „ Z‰ dœ dœ d• „ ZŠ dœ g  e dœ dœ d– „ Z‹ d— „  ZŒ e� eŒ ƒ ZŒ dœ dœ dœ d˜ „ ZŽ e� eŽ ƒ ZŽ dœ d™ „ Z� dš „  Z� d› „  Z‘ RS(�   s!  A class to describe and handle information related to a crystal structure.

  It offers various methods to modify the crystallographic information contained.

  Important members are:

  - .special_position_settings (base class)
  - .scatterers
  - .site_symmetry
  - .crystal_symmetry

  c         C   sÓ   | | g j  d  ƒ d k s! t ‚ | d  k	 s? | d  k s? t ‚ | d  k r` t j d | ƒ } n  t j j |  | ƒ |  j ƒ  | |  _ | |  _ | d  k	 r½ |  j	 d | d | d |  j ƒ n  d  |  _
 d  |  _ d  S(   Ni   t   crystal_symmetryt
   scattererst   site_symmetry_tablet6   non_unit_occupancy_implies_min_distance_sym_equiv_zero(   R   R   t   AssertionErrorR   t   special_position_settingst   _copy_constructort   erase_scattererst7   _non_unit_occupancy_implies_min_distance_sym_equiv_zerot   _scattering_type_registryt   add_scatterersR   t   inelastic_form_factors_source(   R   R#   R   R    R!   t   scattering_type_registryR   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR   3   s"    !		

				c         C   s_   t  j j |  t ƒ | j |  _ | j |  _ | j |  _ | j |  _ | j |  _ | j |  _ d  S(   N(	   R   R#   R$   t   _scattererst   _site_symmetry_tableR&   R'   t(   _scattering_type_registry_is_out_of_dateR)   (   R   t   other(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR$   N   s    	
c         C   s"   t  j d |  j ƒ  d |  j ƒ  ƒ S(   sz   Get crystal symmetry of the structure

    :returns: a new crystal symmetry object
    :rtype: cctbx.crystal.symmetry
    t	   unit_cellt   space_group_info(   R   t   symmetryR/   R0   (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR   Z   s    	c         C   s4   t  j ƒ  |  _ t j ƒ  |  _ t |  _ d |  _	 d S(   s=   Remove all scatterers from structure

    :returns: none
    N(
   R   t   xray_scattererR+   R   R    R,   t   TrueR-   R   R)   (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR%   d   s    	c         C   sF   t  |  d |  j d |  j ƒ} |  j j ƒ  | _ |  j j ƒ  | _ | S(   sŽ   Create a deep copy of the structure with all scatterers

    :returns: a new cctbx.xray.structure object
    :rtype: cctbx.xray.structure
    R*   R!   (   R   R'   R&   R+   t	   deep_copyR,   (   R   t   cp(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   deep_copy_scatterersn   s    		c         C   s©   | t  k r |  } n  t j j | d | d | ƒ} | t  k rK |  j } n  t d t j d | d |  j d |  j d |  j	 ƒ d |  j
 d	 | d
 |  j ƒ } |  j | _ | S(   NR/   R0   R#   R   t   min_distance_sym_equivt   u_star_tolerancet   assert_min_distance_sym_equivR   R!   R*   (   R   R   R1   t   customized_copyR&   R   R#   t   _min_distance_sym_equivt   _u_star_tolerancet   _assert_min_distance_sym_equivR+   R'   R)   (   R   R   R/   R0   R!   t   str(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR:   |   s&    							c         C   s   |  j  S(   sŠ   Get all scatterers of the structure

    :returns: a reference to an array of cctbx.xray.scatterer
    :rtype: cctbx.xray.scatterer[]
    (   R+   (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR   —   s    c         C   s   |  j  S(   N(   R&   (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR!   Ÿ   s    c         C   sä   | | g j  d ƒ d k s! t ‚ |  j } | d k rQ t j | j ƒ  t ƒ } n | j ƒ  | j ƒ  k so t ‚ | d k	 r© | j t j	 | j ƒ  | ƒ | |  j
 ƒ  ƒ n7 | j ƒ  | j ƒ  k sÇ t ‚ | j | | |  j
 ƒ  ƒ |  S(   sï  Set isotropic mean thermic displacements of scatterers

    :param value: a single double value to set all u_iso of selected     scatterers to
    :type value: double
    :param values: an array of double values to set all u_iso of selected     scatterers to
    :type values: double[]
    :param selection: an array of bools to select scatterers to be updated     with new u_iso values
    :type selection: boolean[]

    :returns: the modified base object
    :rtype: cctbx.xray.structure
    i   N(   R   R   R"   R+   R   t   boolt   sizeR3   t	   set_u_isot   doubleR/   (   R   t   valuet   valuest	   selectiont   s(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyRA   ¢   s    !	 .c         C   s©   | | g j  d ƒ d k s! t ‚ |  j } | d k	 rX |  j d t j | ƒ d | ƒ nM | j ƒ  | j ƒ  k sv t ‚ | } | t j d ƒ } |  j d | d | ƒ |  S(   s  Set isotropic Debye-Waller/temperature/B factors with automatic conversion
    to u_iso

    :param value: a single double value to set all b_iso of selected     scatterers to
    :type value: double
    :param values: an array of double values to set all b_iso of selected     scatterers to
    :type values: double[]
    :param selection: an array of bools to select scatterers to be updated with     new b_iso values
    :type selection: boolean[]

    :returns: the modified base object
    :rtype: cctbx.xray.structure
    i   RC   RE   RD   N(   R   R   R"   R+   RA   R   t   b_as_uR@   (   R   RC   RD   RE   RF   t   b_isot   u_iso_values(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt	   set_b_iso½   s    !	"c         C   s1  |  j  j ƒ  } t | d ƒ d k  r5 t j | t ƒ S| d k  sM | d k r\ t d ƒ ‚ n  d } d  } t | d d ƒ } t	 | d d ƒ } xœ t
 d	 ƒ D]Ž } x… | | k r(t j | ƒ | } | d k }	 t | |	 j t ƒ ƒ | }
 t | |
 ƒ | k  rt | |
 ƒ } |	 } n  | d
 7} q¤ Wq› W| S(   Ng        gü©ñÒMbP?g{®Gáz„?g®Gáz®ï?s'   fraction must be between 0.01 and 0.99.g     8�@gš™™™™™©?g      ð?i   g-Cëâ6?(   R+   R@   t   absR   R?   R3   t   RuntimeErrorR   t   maxt   mint   xranget   random_doublet   floatR   (   R   t   fractiont   scatterers_sizet   tolRE   t   lt   rt   it   arrt   selt   deleted(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   random_remove_sites_selectionÙ   s&    	c         C   s€   | d  k	 r' |  j ƒ  j | | ƒ } n  t |  d |  j d |  j ƒ} |  j j ƒ  } | j | ƒ | | _ |  j	 j ƒ  | _	 | S(   NR!   R*   (
   R   t
   sites_fract   set_selectedR   R&   R'   R+   R4   t	   set_sitesR,   (   R   t	   new_sitesRE   R5   t   new_scatterers(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   replace_sites_fracî   s    			c         C   s(   |  j  d |  j ƒ  j d | ƒ d | ƒ S(   NR_   t
   sites_cartRE   (   Ra   R/   t   fractionalize(   R   R_   RE   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   replace_sites_cartû   s    	c         C   s   |  j  j ƒ  d  S(   N(   R+   t   adjust_u_iso(   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyRe      s    c         C   sÊ   | d k	 rI d | j j d ƒ d k rI t j |  j j ƒ  | ƒ } qI n  |  j j ƒ  } | | k } | j | | ƒ } | | k } | j | | ƒ } | d k r³ |  j j	 | ƒ n |  j j	 | | ƒ d S(   sq  Adjust site occupancy factor for selected sites to be between occ_min and
    occ_max.

    :param occ_max: maximal site occupancy factor
    :type occ_max: float
    :param occ_min: minimal site occupancy factor
    :type occ_min: float
    :param selection: an array of bools to select scatterers to be adjusted
    :type selection: boolean[]

    :returns: none
    s   %ss   array_family_flex_ext.size_ti    N(
   R   t	   __class__R   R   R?   R+   R@   t   extract_occupanciesR]   t   set_occupancies(   R   t   occ_maxt   occ_minRE   t   occRY   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   adjust_occupancy  s    !c         C   s   t  j |  j j ƒ  t ƒ S(   s–   Get a selector array for all scatterers of the structure.

    :returns: an array to select all scatterers of the structure
    :rtype: boolean[]
    (   R   R?   R+   R@   R3   (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   all_selection  s    i    c      	   C   s–   |  j  ƒ  } t |  d |  j d |  j ƒ} |  j j ƒ  } | j |  j ƒ  j d | t	 j
 | j ƒ  | | | g ƒ ƒ ƒ | | _ |  j j ƒ  | _ | S(   sg  Translates all scatterers of this structure by x,y,z.

    :param x: x component of the translation vector
    :type x: float
    :param y: y component of the translation vector
    :type y: float
    :param z: z component of the translation vector
    :type z: float

    :returns: a new translated copy of the structure
    :rtype: cctbx.xray.structure
    R!   R*   Rb   (   Rb   R   R&   R'   R+   R4   R^   R/   Rc   R   t   vec3_doubleR@   R,   (   R   t   xt   yt   zRb   R5   R`   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt	   translate%  s    		)	c         C   s’   | d k r* t j |  j j ƒ  t ƒ } n  |  j ƒ  j | ƒ } | j ƒ  j | ƒ } | j ƒ  | j ƒ  k r{ t d ƒ ‚ n  t j	 | | j
 ƒ  ƒ S(   s£  Calculates pairwise distances between the atoms of this structure and
    another structure with the same number of scatterers.

    :param other: the other structure
    :type other: cctbx.xray.structure
    :param selection: an array of bools to select scatterers to be taken into     calculation
    :type selection: boolean[]

    :returns: an array of distances for the selected scatterers
    :rtype: float[]
    s   Models must be of equal size.N(   R   R   R?   R+   R@   R3   Rb   t   selectRL   t   sqrtt   dot(   R   R.   RE   t   s1t   s2(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt	   distances?  s     c         C   s   t  j |  j d | d | ƒ ƒ S(   sÒ  Calculates the maximum pairwise distance between the atoms of this
    structure and another structure with the same number of scatterers.

    :param other: the other structure
    :type other: cctbx.xray.structure
    :param selection: an array of bools to select scatterers to be taken into     calculation
    :type selection: boolean[]

    :returns: the maximum distance of two corresponding scatterers out of the     selected scatterers
    :rtype: float
    R.   RE   (   R   RM   Rx   (   R   R.   RE   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   max_distanceS  s    c         C   s   t  j |  j d | d | ƒ ƒ S(   sÒ  Calculates the minimum pairwise distance between the atoms of this
    structure and another structure with the same number of scatterers.

    :param other: the other structure
    :type other: cctbx.xray.structure
    :param selection: an array of bools to select scatterers to be taken into     calculation
    :type selection: boolean[]

    :returns: the minimum distance of two corresponding scatterers out of the     selected scatterers
    :rtype: float
    R.   RE   (   R   RN   Rx   (   R   R.   RE   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   min_distancec  s    c         C   s   t  j |  j d | d | ƒ ƒ S(   s¸  Calculates the arithmetic mean pairwise distance between the atoms
    of this structure and another structure with the same number of scatterers.

    :param other: the other structure
    :type other: cctbx.xray.structure
    :param selection: an array of bools to select scatterers to be taken into     calculation
    :type selection: boolean[]

    :returns: the mean pairwise distance of the selected scatterers
    :rtype: float
    R.   RE   (   R   t   meanRx   (   R   R.   RE   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   mean_distances  s    c         C   sü   | d k	 r0 | j ƒ  |  j j ƒ  k sK t ‚ n t j |  j j ƒ  t ƒ } xª t |  j | ƒ D]– \ } } | r^ | j j	 ƒ  r^ | j j
 ƒ  r¡ | j | | _ n  | j j ƒ  rô g  } x, t d ƒ D] } | j | j | | ƒ qÃ W| | _ qô q^ q^ Wd S(   sÀ  Scale the atomic displacement parameters of the selected scatterers
    of the structure with the specified factor.
    If no selection is given, all scatterers will be handled as if selected.

    :param factor: scale factor to apply to the adps of the selected scatterers
    :type factor: float
    :param selection: an array of bools to select the scatterers to have their     adps scaled
    :type selection: boolean[]

    :returns: none
    i   N(   R   R@   R+   R"   R   R?   R3   t   zipt   flagst   uset	   use_u_isot   u_isot   use_u_anisoRO   t   appendt   u_star(   R   t   factorRE   t   scRY   t   resultRW   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt	   scale_adp‚  s    $ g      $@gš™™™™™¹?g      ð?c         C   s—  | | g j  d  ƒ d k s! t ‚ | | g j  d  ƒ d k rQ | d k sQ t ‚ n  | | g j  d  ƒ d k rà |  j ƒ  j |  j ƒ  ƒ } | j ƒ  d k rà t j t	 j
 | ƒ ƒ }	 t |	 | ƒ } t t d |	 | ƒ ƒ } qà n  | | k st | | | |	 g ƒ ‚ | d  k	 r4| j ƒ  |  j j ƒ  k sOt ‚ n t	 j |  j j ƒ  t ƒ } |  j ƒ  j }
 x2t t  ƒ  |  j | ƒ D]\ } } } | rw| j j ƒ  rw| j j ƒ  ró| | k rót d t j | | d ƒ t j ƒ  ƒ } t j | ƒ | _ n  | j j ƒ  r�| r�g  } xG t d ƒ D]9 } | j | j | | j | t j | | f ƒ ƒ qW|
 d | ƒ r€|  j ƒ  j | ƒ } n  | | _ q�qwqwWd  S(   Ni    i   g        i   i   t   i_seq(   i    i   (    R   R   R"   t   extract_u_iso_or_u_equivRs   R€   R@   R   t   u_as_bR   R{   t   intRM   R+   R?   R3   R    t   is_special_positionR}   R~   R   t   randomt	   randrangeRG   R�   R‚   RO   Rƒ   R„   t   choicet   space_groupt   average_u_star(   R   t   b_maxt   b_mint   spreadt   aniso_spreadt   keep_anisotropict   random_u_cart_scaleRE   t   u_isost   b_meanR�   R‰   R†   RY   RV   R‡   RW   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt	   shake_adpœ  s6    ! $$(( c         C   s»   t  } |  j ƒ  j t ƒ d k r· |  j ƒ  } t j t j | ƒ ƒ } t j t j	 | ƒ ƒ } t j t j
 | ƒ ƒ } t | | ƒ | k r· t | | ƒ | k r· |  j ƒ  t } q· n  | S(   Ni    (   t   FalseR‚   R   R3   RŠ   R   R‹   R   RM   RN   R{   RK   R›   (   R   t   b_iso_tolerancet	   performedR™   R“   R”   Rš   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   shake_adp_if_all_equalº  s    
c         C   s•   |  j  j d |  j ƒ  ƒ } t j ƒ  } x^ t |  j  ƒ D]M \ } } | j j ƒ  sa | j j ƒ  r7 | j	 t
 t j | | ƒ ƒ ƒ q7 q7 Wt j
 | ƒ S(   NR/   (   R+   t   extract_u_cart_plus_u_isoR/   R   RB   t	   enumerateR~   R€   R‚   Rƒ   RN   R   t   eigenvalues(   R   t   u_cartsR‡   R‰   R†   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   min_u_cart_eigenvalueÇ  s    'c         C   sp   |  j  } t j | j ƒ  ƒ d } | d  k r> | j | ƒ n. | j ƒ  | j ƒ  k s\ t ‚ | j | | ƒ d  S(   Ng       @(   R+   R   RP   R@   R   Rh   R"   (   R   RE   RF   t   q_new(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   shake_occupanciesÐ  s    	c         C   sð   | d  k	 r< t | t j ƒ r< t j |  j j ƒ  | ƒ } n  |  j } t | d ƒ rŠ | } | d  k	 r¢ | j ƒ  | j ƒ  k s‡ t ‚ q¢ n t j	 | j ƒ  | ƒ } | d  k r¾ | j
 | ƒ n. | j ƒ  | j ƒ  k sÜ t ‚ | j
 | | ƒ |  S(   NR@   (   R   t
   isinstanceR   t   size_tR?   R+   R@   t   hasattrR"   RB   Rh   (   R   RC   RE   RF   RD   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyRh   Ù  s    	$c         C   s&  | d  k s- | j ƒ  |  j j ƒ  k s- t ‚ |  j } | j ƒ  j ƒ  |  j j ƒ  k s] t ‚ i d d 6d d 6d d 6| j ƒ  j ƒ  d 6} | d  k r´ | d c |  j j ƒ  7<n | d c | j t ƒ 7<xR | j ƒ  D]D } | d  k sö | | rÚ | | j	 | ƒ j
 ƒ  j ƒ  c d 7<qÚ qÚ W| S(   Ni    i   i   i   (   R   R@   R+   R"   R,   t   indicest   special_position_indicesR   R3   t   gett   site_constraintst   n_independent_params(   R   RE   R    R‡   RW   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt$   coordinate_degrees_of_freedom_countsê  s"    -	'	c         C   s—   d \ } } } t  } xV |  j ƒ  j ƒ  D]B } | t | j ƒ  ƒ 7} | t | j ƒ  ƒ 7} | | j ƒ  7} q( W| | d k r“ | d k r“ t } n  | S(   Ni    (   i    i    i    (   Rœ   R*   t   unique_gaussians_as_listt   lent
   array_of_at
   array_of_bt   cR3   (   R   t   act   bct   ccR‡   t   ugl(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   guess_scattering_type_neutronþ  s     	c         C   s–   t  } t  } x} |  j j ƒ  D]l } | d  k r4 q n  t | j ƒ  ƒ d k sd t | j ƒ  ƒ d k rm t } q | j ƒ  d k r t } q q W| o• | S(   Ni    (	   Rœ   R'   R°   R   R±   R²   R³   R3   R´   (   R   t   has_xrayt   has_neutronR¸   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt6   guess_scattering_type_is_a_mixture_of_xray_and_neutron  s    0	c         C   sÎ   d } |  j  d  k r | Sx® |  j  j ƒ  j ƒ  D]— } | d } | d } d } d } d } | d  k	 rŽ | j ƒ  } | j ƒ  } | j ƒ  } n  | d | d t | ƒ d t | ƒ d t | ƒ 7} q/ W| S(	   Nt    i    i   R   s   
  Element: s     a: s     b: s     c: (   R'   R   t   as_type_gaussian_dictt   itemsR²   R³   R´   R>   (   R   R‡   t   tgt   stypet   gaussiant   aat   abR´   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   scattering_dictionary_as_string  s    

<c         C   sÇ   g  } |  j  ƒ  } | j } t j | ƒ |  j j ƒ  k rH t d ƒ ‚ n  | j |  j ƒ } | j |  j ƒ } xT | j	 ƒ  j
 ƒ  D]@ \ } } | j t d | d | | d | | d | | ƒ ƒ q W| S(   Ns%   scattering_type_registry out of date.t   scattering_typeR   t   occupancy_sumt   unit_cell_occupancy_sum(   R*   t   unique_countsR   t   sumR+   R@   RL   t   occupancy_sumst   unit_cell_occupancy_sumst   type_index_pairs_as_dictR¿   Rƒ   R   (   R   R‡   t   regRÉ   RË   RÌ   RÆ   t   unique_index(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt*   scattering_types_counts_and_occupancy_sums%  s    	

c         C   sl   d d l  m } t g  |  j ƒ  D]% } | j | j ƒ j ƒ  | j ^ q  ƒ } |  j ƒ  j	 ƒ  } d | | S(   sÜ  Get the value of the diffraction-determined density for the crystal,
    suitable for the CIF item _exptl_crystal_density_diffrn

    Density values are calculated from the crystal cell and contents. The
    units are megagrams per cubic metre (=grams per cubic centimetre).

    Equivalent to:
      1.66042 * _chemical_formula_weight * _cell_formula_units_Z / _cell_volume

    :returns: chemical density in megagrams per cubic metre (=grams per cm^3)
    :rtype: float
    iÿÿÿÿ(   t   tiny_pseg7ýÙ�‘ú?(
   t   cctbx.eltbxRÑ   RÊ   RÐ   R   RÆ   t   weightRÈ   R/   t   volume(   R   RÑ   t   eltt	   numeratort   denominator(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   crystal_density5  s    8c         C   s:  d } |  j  ƒ  } | j } t j | ƒ |  j j ƒ  k rH t d ƒ ‚ n  | j |  j ƒ } | j d ƒ } x6 | j	 ƒ  j
 ƒ  D]" \ } } | | | | | 7} q| W| s¬ | Sd }	 d }
 xh |  j ƒ  D]Z } | j rõ |	 | j | j | j ƒ  7}	 n  | j rÅ |
 | j | j | j ƒ  7}
 qÅ qÅ Wt t | |	 |
 ƒ ƒ S(   s©  Get the effective number of electrons in the crystal unit cell
    contributing to F(000), suitable for the CIF item _exptl_crystal_F_000.

    According to the CIF definition, this item **may** contain dispersion
    contributions.

    :param include_inelastic_part: If 'True' contributions due to dispersion     are included in F(000).
    :type include_inelastic_part: boolean

    :returns: F(000)
    :rtype: float
    i    s%   scattering_type_registry out of date.(   R*   RÉ   R   RÊ   R+   R@   RL   RÌ   t    unique_form_factors_at_d_star_sqRÍ   R¿   R   t   fpt	   occupancyt   multiplicityt   fdpRK   t   complex(   R   t   include_inelastic_partt   elastic_partRÎ   RÉ   RÌ   t   unique_form_factors_at_originRÆ   RÏ   t   inelastic_part_realt   inelastic_part_imagR†   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   f_000I  s(    	
	!	%c         C   s¼  | | g j  d ƒ d k s! t ‚ | d k	 rH | d k s? t ‚ | } n | d k sZ t ‚ | } | d k rp d S|  j j ƒ  d k s‹ t ‚ |  j } | j ƒ  j ƒ  |  j j ƒ  k s» t ‚ | d k	 r| j ƒ  |  j j ƒ  k sè t ‚ | j  t ƒ } | d k rt d ƒ ‚ n  d }	 n |  j j ƒ  } d }	 t	 j
 ƒ  }
 x^ | j ƒ  D]P } | j | ƒ j ƒ  j ƒ  d k rI| d k s†| | r™|
 j | ƒ q™qIqIW| |
 j ƒ  8} | d k rÖ| rÃt St d |	 ƒ ‚ n  | |  j j ƒ  k rôd } n  |  j } |  j ƒ  j } |  j ƒ  j } | d k r3t	 j } n  xNt d d	 ƒ D]=} t	 j | d
 |  j j ƒ  d d d ƒ d ƒ } | d k	 r˜| j | d ƒ n  | j |
 d ƒ xw | j ƒ  D]i } t j | | j ƒ } | j | ƒ j ƒ  | t j | | | ƒ ƒ } | t j | ƒ | ƒ | | <qµW| d k	 rNt	 j | j ƒ  ƒ | d } n" t	 j t	 j | j ƒ  ƒ ƒ | } | d k rCPqCqCW| | | 9} |  j |  j  ƒ  |  j ƒ  j | ƒ ƒ t S(   s%  Shake the coordinates of the selected scatterers in this structure.

    :param rms_difference: radial mean square displacement (>=0) to apply to     selected scatterers
    :type rms_difference: float
    :param mean_distance: a mean distance shift (>=0) to apply to selected     scatterers
    :type mean_distance: float
    :param selection: an array of bools to select scatterers to be shaken
    :type selection: boolean[]
    :param allow_all_fixed: if set to 'True' shaking a structure with all     scatterers on fixed special positions will not cause an error
    :type allow_all_fixed: boolean
    :param random_double: "random" numbers to use for displacements
    :type random_double: float[]

    :returns: 'True' if at least one scatterer was moved, 'False' otherwise
    :rtype: boolean
    i   i    Ns   No scatterers selected.s	    selectedR½   s0   All%s scatterers are fixed on special positions.t   assert_less_thani
   R@   i   R…   i   g      à?g�íµ ÷Æ°>(   i    i    i    (   i    i    i    (!   R   R   R"   R+   R@   R,   Rª   R3   RL   R   R¨   R«   R¬   R­   R®   Rƒ   Rœ   R/   Rc   t   orthogonalizeRP   R   Rn   R]   R	   t   colt   sitet
   special_opRÊ   Ru   Rt   t   set_sites_fracR\   (   R   t   rms_differenceR|   RE   t   allow_all_fixedRP   t   target_differenceR    t
   n_variablet   allt   selection_fixedRW   R   t   fract   ortht   shifts_cartt   site_frac_origt	   site_fract
   difference(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   shake_sites_in_placel  st    !	 	'!				#! "  c            sl  ˆ d k r d Sˆ j  } | j ƒ  j ƒ  ˆ j j ƒ  k s@ t ‚ ˆ j ƒ  j ‰ ˆ j ƒ  j ‰ ˆ d k r t	 j
 d d ƒ ‰ n  t j ‰ xÝt ˆ j ƒ D]Ì\ } ‰ ˆ ˆ j ƒ ‰	 | j | ƒ ‰
 ˆ
 j ƒ  ‰ ˆ j ƒ  } | d k rì q˜ n  | d k r#‡ ‡ ‡ ‡ ‡ ‡ ‡	 f d †  } | ƒ  q˜ | d k r3g  } x’ d d d g D]� } xx d d d g D]g }	 t ˆ j ˆ	 ƒ ƒ }
 |
 d c | 7<|
 d c |	 7<| j ˆ ˆ ˆ ˆ j |
 ƒ ƒ ˆ	 ƒ ƒ ƒ q[WqEWt | ƒ d	 k sât ‚ d ‰  d } xˆ t d
 ƒ D]z } | | } xg t | d d	 ƒ D]R } | | } | j | ƒ } | j ƒ  } ˆ  d k sb| | k r| ‰  | } qqWqûWˆ  d k	 s‹t ‚ | d k s�t ‚ d } d } xA | D]9 ‰ ˆ j ƒ  } | d k sÚ| | k r°ˆ } | } q°q°W| d k	 sÿt ‚ ‡  ‡ ‡ ‡ ‡ ‡ ‡ ‡	 ‡
 ‡ f
 d †  } | ƒ  q˜ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡	 ‡
 f
 d †  } | ƒ  q˜ Wd S(   s1  Shifts the coordinates of all scatterers in this structure.

    :param shift_length: the distance to shift each scatterer with
    :type shift_length: float
    :param mersenne_twister: a mersenne twister to use as entropy source
    :type mersenne_twister: flex.mersenne_twister

    :returns: none
    i    Nt   seedi   c             s•   ˆ }  xˆ |  d k r� xk t  d ƒ D]] } ˆ  ˆ ˆ  ˆ j ƒ  ƒ |  ƒ ƒ } ˆ | } ˆ j d | ƒ } | j ƒ  r" | ˆ _ d  Sq" W|  d 9}  q	 Wd  S(   Ni    i
   Rè   g      à?(   RO   t   random_double_point_on_spheret   site_symmetryt   is_point_group_1Rè   (   t   slt   i_trialt
   shift_fract   site_modt   ss_mod(   Rç   Rñ   t   mersenne_twisterR†   R   t   shift_lengthRõ   (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   find_3Ü  s    
	i   iÿÿÿÿi   i	   i   c             sÅ   ˆ }  x¸ |  d k rÀ x› t  d d ƒ D]Š } ˆ  j d ˆ j ƒ  d t j ƒ } ˆ ˆ | ˆ	 j ƒ  |  ƒ ƒ } ˆ | } ˆ j d | ƒ } | j ƒ  ˆ j ƒ  k r% | ˆ _ d  Sq% W|  d 9}  q	 Wd  S(   Ni    Rå   i
   t   anglei   Rè   g      à?(	   R   t$   axis_and_angle_as_r3_rotation_matrixRP   R
   t   pit	   normalizeRú   Ré   Rè   (   Rü   Rý   RV   Rþ   Rÿ   R   (
   t   axisRç   Rñ   R  R†   R   R  Rõ   t   sst   v(    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   find_2  s    	 
	c             s$  ˆ }  x|  d k rˆ j  ƒ  d k  r6 d d g } n d d g } xÍ | D]Å } t ˆ j ˆ ƒ ƒ } | d c | 7<ˆ  ˆ ˆ  ˆ j | ƒ ƒ ˆ ƒ ƒ } | j ƒ  d k s± t ‚ ˆ  ˆ | j ƒ  ˆ ƒ ƒ } ˆ | } ˆ j d | ƒ } | j ƒ  ˆ	 j ƒ  k rI | ˆ _	 d  SqI W|  d 9}  q	 Wd  S(   Ni    g      à?i   iÿÿÿÿRè   (
   RP   t   listt   independent_paramst
   all_paramst   lengthR"   R  Rú   Ré   Rè   (   Rü   t   ust   ut   indepR
  Rþ   Rÿ   R   (
   Rç   t   constrRñ   R  Rò   R†   R   R  Rõ   R	  (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   find_1  s"    %
	(   R,   Rª   R@   R+   R"   R/   Rc   Ræ   R   R   R  R	   Rç   R¡   Rè   R¬   R­   R®   R  R  Rƒ   R  R±   RO   t   crossR  (   R   R  R  t   sstt   i_sct   npR  t   plane_vectorst   s0Rv   R  t   axis_lengthRW   t   vit   jt   vjR  R  t   v_maxt   l_maxRU   R  R  (    (   R  Rç   R  Rñ   R  Rò   R†   R   R  Rõ   R	  R
  sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   shift_sites_in_placeÂ  sl    
 	'	!
(

*
*c         C   sV   |  j  j ƒ  t j d ƒ } t j | ƒ } t j | ƒ } t j | ƒ } | | | f S(   sÔ   Get the minimal, maximal and mean isotropic Debye-Waller/temperature/B     factors of all scatterers in this structure.

    :returns: minimal b_iso, maximal b_iso, mean b_iso
    :rtype: float, float, float
    i   (   R+   t   extract_u_isoR   RG   R   RN   RM   R{   (   R   t   b_isosR”   R“   Rš   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   b_iso_min_max_mean,  s
    c         C   s   t  |  _ d  S(   N(   R3   R-   (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt    discard_scattering_type_registry9  s    c         C   s   t  j |  j ƒ S(   N(   R   t   n_undefined_multiplicitiesR+   (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR&  <  s    c         C   s   |  j  j ƒ  S(   N(   R+   t   extract_sites(   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR\   ?  s    c         C   s   |  j  j ƒ  S(   N(   R+   t   extract_use_u_iso(   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR€   B  s    c         C   s   |  j  j ƒ  S(   N(   R+   t   extract_use_u_aniso(   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR‚   E  s    c         C   s5   | j  ƒ  |  j j  ƒ  k s! t ‚ |  j j | ƒ d S(   sù   Set the the fractional coordinates of all sites of the structure to     'sites_frac'.

    :param sites_frac: a list of the fractional coordinates for all scatterers
    :type sites_frac: scitbx.array_family.flex.vec3_double

    :returns: none
    N(   R@   R+   R"   R^   (   R   R\   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyRê   H  s    	!c         C   s   |  j  ƒ  j d |  j ƒ  ƒ S(   sÃ   Get the the cartesian coordinates of all sites of the structure.

    :returns: a list of the sites of the structure in cartesian coordinates
    :rtype: scitbx.array_family.flex.vec3_double
    R\   (   R/   Ræ   R\   (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyRb   T  s    c         C   s#   |  j  |  j ƒ  j d | ƒ ƒ d S(   s÷   Set the the cartesian coordinates of all sites of the structure to     'sites_cart'.

    :param sites_cart: a list of the cartesian coordinates for all scatterers
    :type sites_cart: scitbx.array_family.flex.vec3_double

    :returns: none
    Rb   N(   Rê   R/   Rc   (   R   Rb   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   set_sites_cart\  s    	c         C   sC   t  j ƒ  } x0 |  j j ƒ  D] } | j | j ƒ  j ƒ  ƒ q W| S(   N(   R   t
   std_stringR+   t   extract_scattering_typesRƒ   t   stript   upper(   R   R‡   t   sct(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   scattering_typesg  s    c         C   s   |  j  j d |  j ƒ  ƒ S(   NR/   (   R+   R    R/   (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR    m  s    c         C   s   |  j  j d |  j ƒ  ƒ S(   NR/   (   R+   RŠ   R/   (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyRŠ   q  s    c         C   s   |  j  j | ƒ S(   N(   R+   t
   scale_adps(   R   t   scale_factor(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR1  u  s    c         C   s   |  j  d d ƒ j ƒ  S(   NR   t   neutron(   R*   R¾   (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt'   switch_to_neutron_scattering_dictionaryx  s    c         C   s_   |  j  j ƒ  } t j ƒ  } x= | D]5 } | j ƒ  d k rJ | j t ƒ q" | j t ƒ q" W| S(   sµ   Get a selector array for all hydrogen and deuterium scatterers of the structure.

    :returns: an array to select all H and D scatterers of the structure
    :rtype: boolean[]
    t   Ht   D(   R5  R6  (   R+   R,  R   R?   R-  Rƒ   R3   Rœ   (   R   R0  R‡   R/  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   hd_selection~  s     c   
      C   s‚  | r | r t  d ƒ ‚ n  |  j j ƒ  } |  j ƒ  } t j ƒ  } x9t | ƒ D]+\ } } | r‘ | | j d d !d k r‘ | j t	 ƒ qO q‘ n  | rÇ | | j d d !d k rÇ | j t	 ƒ qO qÇ n  | rKx{ d d d d d	 d
 d d d d d d d d d d d d d d g D]$ }	 | | j d d !|	 k rPqqW| j t	 ƒ qO n  | j
 ƒ  d k rm| j t	 ƒ qO | j t ƒ qO W| S(   s_  Get a selector array for heavy (= non H or D) scatterers of the structure.

    :param ignore_atoms_with_alternative_conformations: select normal atoms/conformations only
    :type ignore_atoms_with_alternative_conformations: boolean
    :param include_only_atoms_with_alternative_conformations: select only scatterers with alternative conformations
    :type include_only_atoms_with_alternative_conformations: boolean
    :param only_protein: select only protein scatterers
    :type only_protein: boolean

    :returns: an array to select the desired scatterers of the structure
    :rtype: boolean[]
    s/   Mutually exclusive alternative location optionsi	   i
   t    t   ALAt   CYSt   ASPt   GLUt   PHEt   GLYt   HISt   ILEt   LYSt   LEUt   METt   ASNt   PROt   GLNt   ARGt   SERt   THRt   VALt   TRPt   TYRi   R5  R6  (   R5  R6  (   R   R+   R,  R   R   R?   R¡   t   labelRƒ   Rœ   R-  R3   (
   R   t+   ignore_atoms_with_alternative_conformationst1   include_only_atoms_with_alternative_conformationst   only_proteinR0  R   R‡   RW   R/  t   resname(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   heavy_selectionŒ  sZ    		 t   Ct   Ot   CAt   Nc         C   sE  | r | r t  d ƒ ‚ n  |  j j ƒ  } t j ƒ  } x|  j ƒ  D]ú } | j j d ƒ d k rt | j t	 ƒ qC n  | r¦ | j d d !d k r¦ | j t	 ƒ qC q¦ n  | rØ | j d d !d k rØ | j t	 ƒ qC qØ n  xb | D]M } | j d d !j d | ƒ d k rß | j
 | d	 k rß | j t ƒ Pqß qß W| j t	 ƒ qC W| S(
   sc  Get a selector array for scatterers of the structure by "atom" names.

    :param atom_names: list of labels of scatterers to select
    :type atom_names: list(string)
    :param ignore_atoms_with_alternative_conformations: select normal atoms/conformations only
    :type ignore_atoms_with_alternative_conformations: boolean
    :param include_only_atoms_with_alternative_conformations: select only scatterers with alternative conformations
    :type include_only_atoms_with_alternative_conformations: boolean

    :returns: an array to select the desired scatterers of the structure
    :rtype: boolean[]
    s/   Mutually exclusive alternative location optionst   HOHiÿÿÿÿi	   i
   R8  i   s   %s i    (   R   R+   R,  R   R?   R   RM  t   findRƒ   Rœ   RÆ   R3   (   R   t
   atom_namesRN  RO  R0  R‡   R†   t   name(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   atom_names_selectionÎ  s0    		#c         C   s   |  j  d | d | d | ƒ S(   s™  Get a selector array for scatterers of the backbone of the structure.
    (This is just an alias for atom_names_selection.)

    :param atom_names: list of labels of scatterers to select
    :type atom_names: list(string)
    :param ignore_atoms_with_alternative_conformations: select normal atoms/conformations only
    :type ignore_atoms_with_alternative_conformations: boolean
    :param include_only_atoms_with_alternative_conformations: select only scatterers with alternative conformations
    :type include_only_atoms_with_alternative_conformations: boolean

    :returns: an array to select the desired scatterers of the structure
    :rtype: boolean[]
    RY  RN  RO  (   R[  (   R   RY  RN  RO  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   backbone_selectionû  s    	t   CBc         C   s   |  j  d | d | d | ƒ S(   s¾  Get a selector array for scatterers of the main chain of the structure.
    (This is just an alias for atom_names_selection with a different default selection.)

    :param atom_names: list of labels of scatterers to select
    :type atom_names: list(string)
    :param ignore_atoms_with_alternative_conformations: select normal atoms/conformations only
    :type ignore_atoms_with_alternative_conformations: boolean
    :param include_only_atoms_with_alternative_conformations: select only scatterers with alternative conformations
    :type include_only_atoms_with_alternative_conformations: boolean

    :returns: an array to select the desired scatterers of the structure
    :rtype: boolean[]
    RY  RN  RO  (   R[  (   R   RY  RN  RO  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   main_chain_selection  s    	c         C   s   |  j  d | d | d | ƒ S(   s½  Get a selector array for peptide dihedral scatterers of the structure.
    (This is just an alias for atom_names_selection with a different default selection.)

    :param atom_names: list of labels of scatterers to select
    :type atom_names: list(string)
    :param ignore_atoms_with_alternative_conformations: select normal atoms/conformations only
    :type ignore_atoms_with_alternative_conformations: boolean
    :param include_only_atoms_with_alternative_conformations: select only scatterers with alternative conformations
    :type include_only_atoms_with_alternative_conformations: boolean

    :returns: an array to select the desired scatterers of the structure
    :rtype: boolean[]
    RY  RN  RO  (   R[  (   R   RY  RN  RO  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   peptide_dihedral_selection+  s    	c         G   s8   t  j g  |  j ƒ  D] } | j ƒ  j ƒ  | k ^ q ƒ S(   s1  Get a selector array for scatterers of specified element type(s) of the structure.

    :param elements: tuple of element symbols to select
    :type elements: list(string) or set(string) or tuple(string)

    :returns: an array to select the desired scatterers of the structure
    :rtype: boolean[]
    (   R   R?   R   t   element_symbolR-  (   R   t   elementsR†   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   element_selectionC  s    		c         G   s/   t  j g  |  j ƒ  D] } | j | k ^ q ƒ S(   s'  Get a selector array for scatterers of specified labels from the structure.

    :param labels: tuple of scatterer labels to select
    :type labels: list(string) or set(string) or tuple(string)

    :returns: an array to select the desired scatterers of the structure
    :rtype: boolean[]
    (   R   R?   R   RM  (   R   t   labelsR†   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   label_selectionO  s    	c         C   sb   t  | ƒ r* d d l } | j | ƒ } n  t j g  |  j ƒ  D] } | j | j ƒ d k	 ^ q= ƒ S(   sC  Get a selector array for scatterers of specified labels (via regular
    expression) from the structure.

    :param label_regex: a regular expression matching scatterer labels to select
    :type label_regex: string or re

    :returns: an array to select the desired scatterers of the structure
    :rtype: boolean[]
    iÿÿÿÿN(	   R   t   ret   compileR   R?   R   t   searchRM  R   (   R   t   label_regexRe  R†   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   label_regex_selectionZ  s
    
	c         C   s`   t  j |  j j ƒ  t ƒ } y | j t  j | ƒ t ƒ Wn! t k
 r[ t	 d d ƒ ‚ n X| S(   sr  Get a selector array for scatterers with specified index from the
    structure. For example you can select scatterers 1,4 and 5 by passing
    (1,4,5) as argument.

    :param selected_scatterers: list of scatterers to select
    :type selected_scatterers: list(int)

    :returns: an array to select the desired scatterers of the structure
    :rtype: flex.bool[]
    s3   Tried to select a scatterer by index with index => s#   of scatterers for this structuture.(
   R   R?   R+   R@   Rœ   R]   R¨   R3   RL   t
   IndexError(   R   t   selected_scatterersR‡   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   by_index_selectionj  s    c         C   sÄ   | d  k r0 t j |  j j ƒ  t ƒ j ƒ  } n  |  j d |  j ƒ  d |  j	 ƒ  d | d | d | d |  j
 ƒ  d |  j ƒ  ƒ } |  j d | j	 ƒ | rÀ |  j ƒ  } |  j ƒ  |  j d | ƒ n  d  S(	   NRb   R\   t   rott   transRE   R/   t   atomic_weightsR   (   R   R   R?   R+   R@   R3   t
   iselectiont   apply_rigid_body_shift_objRb   R\   R/   Ro  Rê   R   R%   R(   (   R   Rm  Rn  RE   t   recompute_site_symmetriest   rbs_objR   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   apply_rigid_body_shift}  s    $	
c         C   s4   t  j d | d | d | d | d | d | d | ƒ S(   NRb   R\   Rm  Rn  Ro  R/   RE   (   R   Rt  (   R   Rb   R\   Rm  Rn  RE   R/   Ro  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyRq  �  s    c         C   sK   | d  k r( |  j j d |  j ƒ  ƒ n |  j j d |  j ƒ  d | ƒ d  S(   NR/   RE   (   R   R+   t   convert_to_isotropicR/   (   R   RE   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyRu  Ÿ  s    c         C   sK   | d  k r( |  j j d |  j ƒ  ƒ n |  j j d |  j ƒ  d | ƒ d  S(   NR/   RE   (   R   R+   t   convert_to_anisotropicR/   (   R   RE   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyRv  §  s    R½   c      
   C   sb  | d  k r t j } n  |  j j ƒ  } | rB t j | t ƒ } n |  j ƒ  } d t	 j
 d } |  j ƒ  j | ƒ } |  j ƒ  j | ƒ } | | B}	 | j t ƒ }
 | j t ƒ } |  j ƒ  j | ƒ } | j t ƒ } | j t ƒ } |  j ƒ  | j | ƒ j |	 ƒ } |  j ƒ  j ƒ  | j | ƒ j | ƒ } | j ƒ  d k rN| } n  d | } d } d t | | ƒ } | | d | | IJd t | d ƒ } | d	 | |
 | | f IJ| d
 t j | ƒ t j | ƒ t j | ƒ f d d IJ| d t j | ƒ t j | ƒ t j | ƒ f d d IJ| d d d d IJ| d IJ| d IJt j d | d d ƒ } | j ƒ  } t j d | d d ƒ } | j ƒ  } x© t t | j ƒ  ƒ t | j ƒ  ƒ ƒ D]€ \ \ } } \ } } | j ƒ  | j ƒ  | d } | j ƒ  | j ƒ  | d } | d | | | | | | f IJ| } | } qÄW| d d d d IJd  S(   Ni   i   i    s   |-s   -|iO   t   -t   |sK   | iso = %-5d   aniso = %-5d   pos. def. = %-5d   non-pos. def. = %-5d     |sL   | Total B(isotropic equivalent): min = %-6.2f   max = %-6.2f   mean = %-6.2fR8  sL   | Isotropic B only:              min = %-6.2f   max = %-6.2f   mean = %-6.2fs   | s   - i&   sO   |                     Distribution of isotropic B-factors:                    |sO   |            Isotropic                |             Total                     |t   datat   n_slotsi
   i   s5   |  %9.3f -%9.3f:%8d      |    %9.3f -%9.3f:%8d      |iM   s     s     (   R   t   syst   stdoutR+   R@   R   R?   R3   R7  R
   R  R‚   Rs   R€   R   t   is_positive_definite_uRœ   RŠ   R   R"  R±   RN   RM   R{   t	   histogramt   data_minR}   R¡   t   slotst
   slot_width(   R   t   textt   outt   use_hydrogensR@   R7  t   episR‚   R€   t   sel_usedt   n_anisotropict   n_isotropict   ipdt   npdt   nnpdt   beqt   bisost   part1t   part2t   nt   histogram_1t   low_cutoff_1t   histogram_2t   low_cutoff_2t   i_1t   n_1t   i_2t   n_2t   high_cutoff_1t   high_cutoff_2(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   show_u_statistics®  s\     
#) 	
66

+
c         C   s   |  j  S(   N(   R,   (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR    á  s    c         C   s   |  j  j ƒ  S(   N(   R,   R«   (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR«   ä  s    c      	   C   si  | d k s t ‚ | d k r? | d k s? | d k s? t ‚ n  | d k rl | d k sl | d k sl t ‚ n  | d k r™ | d k s™ | d k s™ t ‚ n  |  j sÒ | d  k	 sÒ | d  k	 sÒ | d  k	 sÒ | d  k	 r(t d | d | d | d | ƒ |  _ i t j j d ƒ d 6} i  } d  } |  j d  k	 rÀ|  j j ƒ  } |  j j	 ƒ  }	 |  j j
 ƒ  }
 x; |
 j ƒ  D]- \ } } |	 | d  k	 rd|	 | | | <qdqdW| d  k rÀ| d  k rÀ| j | ƒ qÀn  | d  k	 röx' | D] } t j j d ƒ | | <qÓWn  | d  k	 r| j | ƒ n  | d  k r'd } n  t j ƒ  |  _ |  j j |  j ƒ xÐ|  j j ƒ  D]¿} | j | d  ƒ } | d  k r¶t j j d | d t d t ƒ } | d  k	 r¶| d  k r¿| } n | } | d k rït j j | t ƒ j ƒ  } q³| d k rt j j | t ƒ j ƒ  } q³| d k rMd d l m } | d | d t ƒ } q³| d k rŒt | t ƒ } | j ƒ  } t j j | j ƒ } q³t j j | | d ƒ j ƒ  } d } q¶n  | d  k r×| j | d  ƒ } n  | d  k	 rY|  j j | | ƒ | d  k	 r|  j j | ƒ qqYqYWt  |  _ n  | sb|  j! ƒ  rbd } | |  j" ƒ  7} t# | ƒ ‚ qbn  |  j S(   Nt
   n_gaussiant   it1992t   wk1995t   xrayt   electronR3  i    i   g      @g      (@R   R   R   R   t   constRM  t   exactt   optionaliÿÿÿÿ(   t.   ito_vol_c_2011_table_4_3_2_2_entry_as_gaussians)   Mixed xray and neutron scattering table! (   NRœ  s   it1992s   wk1995s   xrayR   s   neutron(   i    Ng      Ð?(   i    NgUUUUUUµ?(   i    Ng      Ð?($   R   R"   R-   R   R   t   xray_scatteringRÂ   R'   t
   last_tableR°   RÍ   R¿   t   updateR   R*   t   processR+   t   unassigned_typesR¬   t   get_standard_labelR3   R�  t   fetchRž  t   cctbx.eltbx.e_scatteringR¤  R   t   bound_coh_scatt_lengtht   realt   n_gaussian_table_entryt   assignt   set_last_tableRœ   R¼   RÅ   RL   (   R   R   R   R   R   t   explicitly_allow_mixingt   new_dictt   old_dictt   last_used_scattering_tablet   ugst   tipt   tRW   t   t_undeft   valt   std_lblt   _t   scattering_infot   bt   errmsg(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR*   ç  s–     ! ! !	  			c         C   sc   | d k r t  j } n( | d k r0 t  j } n t d | ƒ ‚ | |  _ | |  j ƒ  | | ƒ d  S(   Nt   sasakit   henkes(   Unknown inelastic form factors table: %s(   R   t&   set_inelastic_form_factors_from_sasakit%   set_inelastic_form_factors_from_henkeRL   R)   R   (   R   t   photonR   t   set_use_fp_fdpt   set_inelastic_ff(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   set_inelastic_form_factors>  s    	t   customc         C   s–   x† |  j  ƒ  D]x } | j | j d ƒ } | d k rR d | _ d | _ t | _ q | d | _ | d | _ | r | j j	 t
 ƒ q q W| |  _ d S(   s¬    Expects a dictionary of tuples like 'C' : (fp, fdp). If an element is
    not in the dictionary, the fp and fdp are reset to 0 and the use_fp_fdp is
    set to false.
    i    i   N(   R   R¬   RÆ   R   RÚ   RÝ   Rœ   t
   use_fp_fdpR~   RÅ  R3   R)   (   R   R   RÅ  t   sourceR†   t   fp_fdp(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt!   set_custom_inelastic_form_factorsH  s    		c         C   s&   |  j  ƒ  } | j ƒ  |  j ƒ  j ƒ  S(   N(   R*   t0   sum_of_scattering_factors_at_diffraction_angle_0R/   RÔ   (   R   RV   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   mean_scattering_density[  s    	c      	   C   sŽ   t  | ƒ t j k s t ‚ |  j ƒ  d  k	 s3 t ‚ t j d |  j j	 ƒ  d | ƒ } t
 d |  d |  j j | ƒ d |  j j | ƒ d |  j ƒ S(   Nt
   array_sizet   python_sliceR#   R   R    R*   (   t   typet   typest	   SliceTypeR"   R   R   R   t   slice_indicesR+   R@   R   Rs   R,   R'   (   R   t   slice_objectRY   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   __getitem__`  s    		c      	   C   sb   |  j  ƒ  d  k	 s t ‚ | r( | } n  t d |  d |  j j | ƒ d |  j j | ƒ d |  j ƒ S(   NR#   R   R    R*   (   R   R   R"   R   R+   Rs   R,   R'   (   R   RE   t   negate(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyRs   l  s     
c         C   sO   |  j  ƒ  d  k	 s t ‚ |  j j | ƒ |  _ |  j j | ƒ |  _ t |  _ d  S(   N(   R   R   R"   R+   Rs   R,   R3   R-   (   R   RE   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   select_inplaceu  s    c         C   sØ   | d  k r |  j j ƒ  } n  |  j j | | ƒ | d  k r� |  j | j d |  j ƒ  d |  j ƒ  d |  j ƒ  d |  j ƒ  d |  j	 ƒ  ƒ } n# |  j | j d | d |  j ƒ  ƒ |  j
 j d | d | ƒ t |  _ d  S(   NR/   R‘   R7   R8   R9   t   site_symmetry_opst   insert_at_index(   R   R+   R@   t   insertt   apply_symmetryR/   R‘   R7   R8   R9   R,   R¨  R3   R-   (   R   t	   scattererRÙ  RÚ  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   add_scatterer{  s     c         C   sÍ   | d  k r t j ƒ  } n1 | j ƒ  j ƒ  | j ƒ  k s? t ‚ | sL t ‚ |  j j | ƒ t j	 d |  j
 ƒ  d |  j ƒ  d |  j d |  j d | d |  j ƒ  d |  j ƒ  d |  j ƒ  d	 | ƒ 	t |  _ d  S(
   NR/   R‘   R   R    t   site_symmetry_table_for_newR7   R8   R9   R!   (   R   R   R    Rª   R@   R"   R+   t   extendR   t   add_scatterers_extR/   R‘   R,   R7   R8   R9   R3   R-   (   R   R   R    R!   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR(   ‘  s     $			c         C   s,   |  j  ƒ  } | j d | j d | j ƒ | S(   NR   R    (   R6   R(   R+   R,   (   R   R.   R‡   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   concatenate¨  s
    		
c      	   C   sô  |  j  ƒ  j ƒ  } | j  ƒ  j ƒ  } x?t | j ƒ  | j ƒ  ƒ D]"\ } } xt | j ƒ  | j ƒ  ƒ D]ö \ } } | | k rh | d } | d }	 t }
 xA t | j ƒ  |	 j ƒ  ƒ D]$ \ } } t | | ƒ s¶ t }
 q¶ q¶ WxA t | j	 ƒ  |	 j	 ƒ  ƒ D]$ \ } } t | | ƒ sú t }
 qú qú Wt | j
 ƒ  |	 j
 ƒ  ƒ sFt }
 n  |
 r^t d ƒ ‚ q^qh qh Wq@ W|  j d | j d | j ƒ |  j } | j } |  j  d | j d | j d | j d | j ƒ |  j  d | j d | j d | j d | j ƒ d  S(	   Ni   s*   Cannot concatenate: conflicting scatterersR   R    R   R   R   R   (   R*   R¾   R}   t   keysR¿   Rœ   R²   R   R3   R³   R´   RL   R(   R+   R,   R   R   R   R   R   (   R   R.   t   d1t   d2t   key1t   item1t   key2t   item2t   i1t   i2t   problem_flagt   a1t   a2t   b1t   b2t   strp1t   strp2(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   concatenate_inplace¯  s@    ((

( (  	
						
				c         C   sj   | d k s t  ‚ |  j ƒ  d  k	 s* t  ‚ t j d |  j ƒ  j d | d |  j ƒ  ƒ d | ƒ j d | ƒ S(   Ni    t   asu_mappingst   buffer_thicknessRb   t   distance_cutofft   primary_selection(   R"   R#   R   R   t   neighbors_fast_pair_generatorRô  Rb   t   neighbors_of(   R   t   radiusRE   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   selection_withinÐ  s    	t   existingc         C   su   | d k r |  j  } n  | d  k	 rQ | j ƒ  j ƒ  |  j ƒ  j ƒ  k sQ t ‚ n  |  j ƒ  |  j d | d | ƒ d  S(   NRü  R   R    (   R,   R   Rª   R@   R   R"   R%   R(   (   R   R   R    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   replace_scatterersÚ  s    -
	c	   
      C   sÈ   | d k r6 |  j ƒ  j ƒ  d k r- t } qj t } n4 | sj |  j ƒ  j ƒ  d k rj t d d ƒ ‚ qj n  t j |  | | ƒ }	 t j	 d |  d | d | d | d | d	 | d
 | ƒ d |  d |	 d | ƒ S(   sÁ  
    Calculate structure factors for the current scatterers using either direct
    summation or FFT method; by default the appropriate method will be guessed
    automatically.

    :param anomalous_flag: toggles whether the returned structure factors are
      anomalous or not
    :type anomalous_flag: bool
    :param d_min: resolution cutoff (required)
    :type d_min: float
    :param algorithm: specifies 'direct' or 'fft', or if None (default), the
      algorithm will be chosen automatically
    :type algorithm: str or None
    :param cos_sin_table: if True, uses interpolation of values from a
      pre-calculated lookup table for trigonometric function calls in the
      structure factor calculations in preference to calling the system
      libraries
    :type cos_sin_table: bool
    :param quality_factor: determines accuracy of sampled density in fft method
    :type quality_factor: float
    :param u_base: additional smearing B-factor for scatterers which have too
      small Bs so they fall between the grid nodes
    :type u_base: float
    :param b_base: same as u_base (but 8*pi^2 larger)
    :type b_base: float
    :param wing_cutoff: is how far away from atomic center you sample density
      around atom
    :type wing_cutoff: float

    :returns: a custom Python object (exact type depends on method used), from
      which f_calc() may be called
    :rtype: derived from cctbx.xray.structure_factors.manager.managed_calculation_base
    i    s(   xray.structure with anomalous scattererss#    but miller.array is non-anomalous.R   R   t   cos_sin_tablet   quality_factort   u_baset   b_baset   wing_cutofft   xray_structuret
   miller_sett	   algorithmN(
   R   R   t   count_anomalousR3   Rœ   RL   R   t	   build_setR   t   from_scatterers(
   R   t   anomalous_flagR   R  Rþ  Rÿ  R   R  R  R  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR   ä  s*    (				c      	   C   s™   d | | |  j  ƒ  j d | d ƒ | f } g  } xO t |  j ƒ  ƒ D]; \ } } | j | d | j d | d d d | ƒ ƒ qE W| d j | ƒ d S(	   s¡   eval(self.as_py_code()) is similar (but sometimes not identical)
    to self and meant to enable quick formatting of self as Python code
    for unit tests.
    sP   %sxray.structure(
%s  crystal_symmetry=%s,
%s  scatterers=flex.xray_scatterer([
t   indents     s       t   comments    #%ds   ,
s   ]))(   R   t
   as_py_codeR¡   R   Rƒ   t   join(   R   R
  t   r0t   r1RW   R†   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR  #  s    
-c         C   sx   | d  k r t j } n  | | d I|  j ƒ  j ƒ  IJ| | d I|  j ƒ  j ƒ  IJt j j |  d | d | ƒ|  S(   Ns   Number of scatterers:s   At special positions:t   ft   prefix(	   R   R{  R|  R   R@   R«   R   R1   t   show_summary(   R   R  R  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR  6  s     c         C   s}   | d  k r t j } n  | d IJ|  j ƒ  } | rL | j |  j ƒ  ƒ } n  x* | D]" } | j d | d |  j ƒ  ƒ qS W|  S(   NsL   Label, Scattering, Multiplicity, Coordinates, Occupancy, Uiso, Ustar as UisoR  R/   (   R   R{  R|  R   Rs   R«   t   showR/   (   R   R  t   special_positions_onlyR   R†   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   show_scatterers?  s     
 c         C   sS   |  j  j d |  d |  j ƒ  j ƒ  d | d | d |  j ƒ  j ƒ  d | d | ƒ d  S(   NR#   t   site_labelst   sites_frac_originalt   sites_cart_originalt   sites_frac_exactRƒ  R  (   R,   t   show_special_position_shiftsR   t   extract_labelsR'  (   R   R  R  Rƒ  R  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR  J  s    c         C   sT   | d  k r+ t j d |  j d |  j ƒ  ƒ St j d |  j d |  j ƒ  d | ƒ Sd  S(   NR   R/   t   u_cart_tolerance(   R   R   R}  R+   R/   (   R   R  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR}  X  s    				g�íµ ÷Æ°>gR¸…ë?�@g      Ð?c         C   sP   | | k  s t  ‚ t j d |  j d |  j ƒ  d |  j d | d | d | ƒ d S(   sŒ   
    Clean up atomic displacements so they fall within a sensible range (this
    is especially important when writing out PDB format).
    R   R/   R    t   u_mint   u_maxt   anisotropy_minN(   R"   R   t   tidy_usR+   R/   R,   (   R   R  R  R  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR   c  s    			c      	   C   s¢   | | g j  d  ƒ d k s! t ‚ | d  k r? t j | ƒ } n  | d  k rs t j d |  j d |  j ƒ  d | ƒ n+ t j d |  j d |  j ƒ  d | d | ƒ d  S(   Ni   R   R/   t   u_shiftRE   (	   R   R   R"   R   RG   R   t   shift_usR+   R/   (   R   R!  t   b_shiftRE   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR"  r  s    !		
c         C   sK   | d  k	 r. t j d |  j d | d | ƒ n t j d |  j d | ƒ d  S(   NR   t   q_shiftRE   (   R   R   t   shift_occupanciesR+   (   R   R$  RE   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR%  �  s    
c         C   s    t  j d |  j d |  j ƒ d  S(   NR    R   (   R   t   apply_symmetry_sitesR,   R+   (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR&  Š  s    		c         C   s,   t  j d |  j d |  j d |  j ƒ  ƒ d  S(   NR    R   R8   (   R   t   apply_symmetry_u_starsR,   R+   R8   (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR'  �  s    			c         C   s3   |  j  | j d |  j j | ƒ d |  j ƒ  ƒ d  S(   NRÙ  R8   (   R+   RÜ  R,   R¬   R8   (   R   t   i_scatterer(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   re_apply_symmetry•  s    c         C   sl   xe |  j  ƒ  D]W } |  j j | ƒ j ƒ  } t j | j ƒ  j ƒ  ƒ } t j | | ƒ | j	 | | <q Wd  S(   N(
   R«   R,   R¬   Ré   R	   t   sqrRV   t	   as_doublet   rowt   elems(   R   t   d_target_d_siteRW   Ré   RV   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt*   apply_special_position_ops_d_target_d_siteš  s    c         C   sX   t  t j t j j |  ƒ ƒ d |  j ƒ} |  j ƒ  j ƒ  | _ |  j	 ƒ  j ƒ  | _
 | S(   NR*   (   R   R   R#   R1   t   cell_equivalent_p1R'   R   R4   R+   R    R,   (   R   t   new_structure(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   asymmetric_unit_in_p1   s    c      	   C   sv   t  | t ƒ r! t j | ƒ } n  t d t j j |  | ƒ d t j d |  j	 d | ƒ d |  j
 j d | ƒ d |  j ƒ S(   NR#   R   t   cb_opR    R*   (   R§   R>   R   t   change_of_basis_opR   R   R#   t   change_basisR   R+   R,   R'   (   R   R3  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR5  ©  s    c         C   s%   |  j  ƒ  j ƒ  j ƒ  } |  j | ƒ S(   N(   R0   RÑ  t   change_of_hand_opR5  (   R   t   ch_op(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   change_hand³  s    c         C   s‚   t  d t j t j j |  ƒ ƒ d t j d |  j ƒ  d |  j ƒ  d |  j	 d |  j
 d | ƒ d |  j ƒ } | r~ | j ƒ  } n  | S(   s4  Get the current structure expanded into spacegroup P1.
    This turns all symmetry induced scatterers into independent
    individual scatterers. The expanded structure may have sites
    with negative or > 1.0 coordinates. Use '.sites_mod_positive()'
    or '.sites_mod_short()' on the result, or alternatively
    set sites_mod_positive to 'True' in case you want to change this behaviour.

    :param append_number_to_labels: If set to 'True' scatterers generated from     symmetry will be labelled with a numerical suffix
    :type append_number_to_labels: boolean
    :param sites_mod_positive: If set to 'True' xyz coordinates of the     scatterers will be kept inside [0,1[
    :type sites_mod_positive: boolean

    :returns: a new instance of the structure expanded into P1
    :rtype: cctbx.xray.structure
    R#   R   R/   R‘   R    t   append_number_to_labelsR*   (   R   R   R#   R1   R0  R   t   expand_to_p1R/   R‘   R+   R,   R'   t   sites_mod_positive(   R   R9  R;  R‡   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR:  ·  s    				c         C   s(   t  d |  d |  j ƒ  j ƒ  d |  j ƒ S(   sö   Get the current structure converted into a structure with x,y,z of all
    scatterers in the interval [0,1[

    :returns: the same instance of the structure with only posive coordinates     of its scatterers
    :rtype: cctbx.xray.structure
    R#   R   R*   (   R   R   R;  R'   (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR;  Ú  s    c         C   s(   t  d |  d |  j ƒ  j ƒ  d |  j ƒ S(   sû   Get the current structure converted into a structure with short
    coordinates vectors of all scatterers

    :returns: the same instance of the structure with only short coordinates     vectors of its scatterers
    :rtype: cctbx.xray.structure
    R#   R   R*   (   R   R   t   sites_mod_shortR'   (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR<  ç  s    c      	   C   sc   |  j  ƒ  j ƒ  } | j | j ƒ  | ƒ | r8 d  } n	 |  j } t d |  d | d | d |  j ƒ S(   NR#   R   R    R*   (   R   R4   R^   R'  R   R,   R   R'   (   R   t   shiftRr  t   shifted_scatterersR    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   apply_shiftô  s    		gš™™™™™É?c         C   sS   t  j t  j |  j ƒ  j ƒ  d ƒ d d | ƒ } |  j |  j ƒ  j d | ƒ ƒ S(   Ni   i   i   Rb   (   R   Rn   RP   R   R@   R?  R/   Rc   (   R   t   max_shift_cartt   shifts(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   random_shift_sites  s    .RÛ   c      	   C   sˆ   | d k s t  ‚ | t t f k s* t  ‚ t j d |  j ƒ  j ƒ  d | ƒ } t d |  d |  j j	 | ƒ d |  j
 j	 | ƒ d |  j ƒ S(	   NRÛ   Ry  t   reverseR#   R   R    R*   (   s	   occupancy(   R"   Rœ   R3   R   t   sort_permutationR   Rg   R   R+   Rs   R,   R'   (   R   t   by_valueRC  t   p(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   sort  s    		c         C   s\   d d l  m } g  } x3 |  j ƒ  D]% } | j | j | j | j ƒ ƒ q# W| j |  | ƒ S(   Niÿÿÿÿ(   t   euclidean_model_matching(   t   cctbxRH  R   Rƒ   t   positionRM  Rè   t   model(   R   t   emmat	   positionsRÝ  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   as_emma_model  s
    #c         C   s™   d d l  m } t j ƒ  } xv |  j ƒ  D]h } t j j d | j d t	 d t	 ƒ } | d  k ru t d | j ƒ ‚ n  | j | j | ƒ j ƒ  ƒ q) W| S(   Niÿÿÿÿ(   RÑ   RM  R¢  R£  s   Unknown atomic weight: (   RÒ   RÑ   R   RB   R   R   R¥  Rª  RÆ   R3   R   RL   Rƒ   R   RÓ   (   R   RÑ   R‡   RÝ  R»  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyRo    s     c         C   s1   | d  k r |  j ƒ  } n  |  j ƒ  j d | ƒ S(   Nt   weights(   R   Ro  Rb   t   mean_weighted(   R   Ro  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   center_of_mass%  s    c         C   s:   | d  k r |  j ƒ  } n  t j j d |  j ƒ  d | ƒ S(   Nt   pointsRO  (   R   Ro  t   scitbxR
   t   principal_axes_of_inertiaRb   (   R   Ro  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyRT  *  s
    c         C   sx   |  j  j ƒ  | j ƒ  k s! t ‚ | d  k	 rU |  j  j d |  j ƒ  d | d | ƒ n |  j  j d |  j ƒ  d | ƒ d  S(   NR/   t   u_cartRE   (   R+   R@   R"   R   t
   set_u_cartR/   (   R   RU  RE   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyRV  1  s    !
c         C   sy  | d  k r t j } n  d } d } d } d } d } d } d } d }	 d }
 d } d } x.|  j ƒ  D] } | j } | j ƒ  r� | d 7} n  | j ƒ  | j ƒ  } } | rÁ | rÁ | d 7} n0 | rÔ | d 7} n | rç | d 7} n
 | d 7} | j ƒ  r
| d 7} n  | j	 ƒ  r#| d 7} n  | j
 ƒ  r<|	 d 7}	 n  | j ƒ  rU|
 d 7}
 n  | j ƒ  rn| d 7} n  | j ƒ  rg | d 7} qg qg W| d I| IJ| d k rº| d I| IJn  | d k rÙ| d I| IJn  | d I| IJ| d I| IJ| d I| IJ| d	 I| IJ| d
 I|	 IJ| d I|
 IJ| d I| IJ| d I| IJ| d I|  j ƒ  j ƒ  IJd  S(   Ni    i   s   n_use            = s   n_use_u_none     = s   n_use_u_both     = s   n_use_u_iso      = s   n_use_u_aniso    = s   n_grad_site      = s   n_grad_u_iso     = s   n_grad_u_aniso   = s   n_grad_occupancy = s   n_grad_fp        = s   n_grad_fdp       = s   total number of scatterers = (   R   R{  R|  R   R~   R   R€   R‚   t	   grad_sitet
   grad_u_isot   grad_u_anisot   grad_occupancyt   grad_fpt   grad_fdpR@   (   R   Rƒ  t   n_uset   n_use_u_botht   n_use_u_isot   n_use_u_anisot   n_use_u_nonet   n_grad_sitet   n_grad_u_isot   n_grad_u_anisot   n_grad_occupancyt	   n_grad_fpt
   n_grad_fdpRÝ  R~   RW   t   a(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   show_scatterer_flags_summary;  sf     	    
      c         C   s   t  j |  j ƒ  ƒ S(   N(   R   t   shared_scatterer_flagsR   (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   scatterer_flagsf  s    c         C   s   | j  |  j ƒ  ƒ d  S(   N(   t	   assign_toR   (   R   Rk  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   set_scatterer_flagsi  s    c         C   s‚  d } | r |  j  ƒ  } n d  } xZt |  j ƒ  ƒ D]F\ } } | j } | d  k r^ d  } n$ | j | ƒ } | j ƒ  r‚ d  } n  | j ƒ  rÀ | d  k r§ | d 7} qÀ | | j ƒ  j	 ƒ  7} n  | j
 ƒ  rå | j ƒ  rå | d 7} n  | j ƒ  r/| j ƒ  r/| d  k r| d 7} q/| | j ƒ  j	 ƒ  7} n  | j ƒ  rH| d 7} n  | j ƒ  ra| d 7} n  | j ƒ  r4 | d 7} q4 q4 W| S(   Ni    i   i   i   (   R    R   R¡   R   R~   R¬   Rû   RW  R­   R®   RX  R€   RY  R‚   t   adp_constraintsRZ  R[  R\  (   R   t%   considering_site_symmetry_constraintsR‡   t   sstabR  R†   R~   Rú   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   n_parametersl  s<    			    c         C   s   |  j  ƒ  j ƒ  S(   N(   R   Rc  (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyRc  �  s    c         C   s   |  j  ƒ  j ƒ  S(   N(   R   Rd  (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyRd  �  s    c         C   s   t  j j |  j ƒ  ƒ S(   N(   RI  RŸ  t   parameter_mapR   (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyRr  “  s    c         C   s4  |  j  ƒ  } | j } | j } x|  j ƒ  D]} | g  | | j ƒ D] } t d | ƒ ^ qD ƒ | _ | j d k r  t j t d t j	 | j ƒ ƒ ƒ | _ n  t d | j
 ƒ | _
 | j d k r+ g  t j | | j ƒ D] } t | d ƒ ^ qÛ } t j | g  | D] } t | ƒ d ^ qƒ | _ q+ q+ Wd  S(   Ns   %8.3fg      ð¿s   %6.2fs   %5.2fiÿÿÿÿi'  (   iÿÿÿÿiÿÿÿÿiÿÿÿÿiÿÿÿÿiÿÿÿÿiÿÿÿÿ(   R/   Rc   Ræ   R   Rè   RQ   R�   R   RG   R‹   RÛ   R„   t   u_star_as_u_cartRŒ   t   u_cart_as_u_star(   R   t   uct   frat   ortR†   RW   t   u_pdb(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt    truncate_at_pdb_format_precision–  s    		5+2c         C   sX   t  j d |  j ƒ  d |  j ƒ  d |  j ƒ  d |  j ƒ  d |  j ƒ  d | d | d | ƒ S(	   NR/   R‘   R   R*   R    t   miller_indicest   da_dbt   daa_dbb_dab(   R   t:   structure_factors_curvatures_simple_grads_and_curvs_targetR/   R‘   R   R*   R    (   R   Rz  R{  R|  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   grads_and_curvs_target_simple£  s    	c         C   s[   | r d  } n |  j ƒ  } | j d | d |  j ƒ  j ƒ  d | d |  j ƒ  d |  j ƒ  ƒ S(   NR  R  R    R\   R/   (   R   R    R  R   R  R\   R/   (   R   t   pair_sym_tablet   is_full_connectivityRƒ  R    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   pair_sym_table_show®  s    		c         C   sX   | j  d |  j ƒ  d |  j ƒ  d |  j ƒ  j ƒ  d |  j ƒ  d | d | d | d | ƒ S(	   NR/   R    R  R\   t   show_cartesiant   skip_j_seq_less_than_i_seqt   skip_sym_equivRƒ  (   t   show_distancesR/   R    R   R  R\   (   R   R  R‚  Rƒ  R„  Rƒ  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   pair_sym_table_show_distances½  s    	c         C   sD   t  j j |  d | d | ƒ} t j d | d |  j d |  j ƒ | S(   NRõ  t   asu_is_inside_epsilonRô  R   R    (   R   R1   Rô  R   t   asu_mappings_processR+   R,   (   R   Rõ  R‡  R‡   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyRô  Í  s    			
i   c         C   s†   | d  k	 s | d  k	 s t ‚ | d  k r3 | } n  |  j d | d | ƒ } t j d | ƒ } | d  k	 r‚ | j d | d | ƒ n  | S(   NRõ  R‡  Rô  Rö  t   min_cubicle_edge(   R   R"   Rô  R   t   pair_asu_tablet   add_all_pairs(   R   Rö  t   asu_mappings_buffer_thicknessR‡  R‰  Rô  RŠ  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyRŠ  ×  s    				
c	   	      C   sŽ   | | g j  d  ƒ d k s! t ‚ | d  k rT |  j d | d | d | d | ƒ } n  | j d |  j ƒ  j ƒ  d |  j ƒ  d | d	 | d
 | ƒ S(   Ni   Rö  RŒ  R‡  R‰  R  R\   R‚  t   keep_pair_asu_tableRƒ  (   R   R   R"   RŠ  R…  R   R  R\   (	   R   Rö  RŒ  R‡  R‰  RŠ  R‚  R�  Rƒ  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR…  ê  s    	!		c      	   C   s‚   | | g j  d  ƒ d k s! t ‚ | d  k rN |  j d | d | d | ƒ } n  | j d |  j ƒ  j ƒ  d |  j ƒ  d | d | ƒ S(	   Ni   Rö  RŒ  R‡  R  R\   R�  Rƒ  (   R   R   R"   RŠ  t   show_anglesR   R  R\   (   R   Rö  RŒ  R‡  RŠ  R�  Rƒ  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyRŽ    s    !		c         C   s   t  d |  d | d | ƒ S(   NR   t   bond_sym_tablet   conserve_angles(   t   conservative_pair_proxies(   R   R�  R�  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR‘    s    c         C   s   | j  ƒ  |  j  ƒ  S(   N(   Rb   (   R   R.   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   difference_vectors_cart  s    c         C   s   |  j  ƒ  j | j  ƒ  ƒ S(   N(   Rb   Rë   (   R   R.   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyRë     s    c            s†   d t  f ‡  f d †  ƒ  Y} | d  k	 rL | j ƒ  |  j j ƒ  k sg t ‚ n t j |  j j ƒ  t ƒ } | d |  d | d | ƒ } | S(   Nt,   map_next_to_model_and_find_closest_distancesc              s   e  Z ‡  f d  †  Z RS(   c            s:  | j  d ˆ  ƒ } | j | d | j ƒ  ƒt j d | d ˆ  ƒ } | j ƒ  j ƒ  } | j ƒ  } t j	 | j ƒ  ˆ  d d ƒ } t j
 | j ƒ  d ƒ }	 x<| D]4}
 |
 j | k  r$|
 j | k  rÊ q  n  | j |
 ƒ } | j |
 ƒ } | j ƒ  j | ƒ } |
 j | } | | | } |
 j } nl |
 j | k r9q  n  | j |
 ƒ } | j |
 ƒ } | j ƒ  j | ƒ } |
 j | } | | | } |
 j } | | r  | | |
 j k rÔ|
 j | | <| | | <| |	 | <qÔq  q  W| ˆ  d k |  _ | |  _ t j | ƒ j |  j d ƒ |  _ | j |  j d ƒ |  _ |	 |  _ d  S(   NRõ  R7   Rô  Rö  i   i   iÿÿÿÿ(   Rô  t   process_sites_fracR7   R   Rø  R   R@   R4   R   RB   RŒ   R‰   t   j_seqt   get_rt_mx_it   get_rt_mx_jt   inverset   multiplyt   dist_sqt   remove_selectionR\   Rt   R]   t   smallest_distancest   smallest_distances_sqt   i_seqs(   R   R  R\   t   use_selectionRô  t   pair_generatort   n_xrayt   new_sites_fracR�  Rž  t   pairt   rt_mx_it   rt_mx_jt   rt_mx_jit   i_seq_new_site_fract   new_site_fract   jnt   rt_mx_ij(   Rö  (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR   "  sR    			  	

	(   R   R   R   (    (   Rö  (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR“  !  s   R  R\   RŸ  (   t   objectR   R@   R+   R"   R   R?   R3   (   R   R\   Rö  RŸ  R“  R‡   (    (   Rö  sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   closest_distances   s    .$	c         C   s±   |  j  ƒ  } | j ƒ  } g  t | | j ƒ  ƒ D] \ } } d | | | ^ q. } | g  | D] } | | ^ q\ 7} t d t j d | d d ƒ d |  j ƒ  ƒ } | j | ƒ | S(   Ni   R   R/   t   space_group_symbolt   P1R   (	   Rb   RN   R}   RM   R   R   R1   R   R*  (   R   t   buffer_sizeRb   t   sites_cart_minRW   Rh  t   abcR‡   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt1   orthorhombic_unit_cell_around_centered_scatterersX  s    :!		c   	      C   sÝ   |  j  ƒ  } | j ƒ  } g  t | | j ƒ  ƒ D] \ } } | | ^ q. } t | ƒ d | } | g  t | | ƒ D] \ } } | | d | ^ qq 7} t d t j d | | | g d d ƒ d |  j ƒ  ƒ } | j | ƒ | S(   Ni   R   R/   R­  R®  R   (	   Rb   RN   R}   RM   R   R   R1   R   R*  (	   R   R¯  Rb   R°  RW   Rh  t   spanRF   R‡   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt*   cubic_unit_cell_around_centered_scattererse  s    28		t   globalc         C   sT   | d  k r t j } n  d d  l } | j j j ƒ  } |  j ƒ  | | <| | IJd  S(   Niÿÿÿÿ(   R   R{  R|  t	   iotbx.cift   cifRK  t   as_cif_block(   R   Rƒ  t	   data_namet   iotbxR·  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   as_cif_simples  s     c         C   s+   d d  l  } | j j |  d | d | ƒj S(   Niÿÿÿÿt   covariance_matrixt   cell_covariance_matrix(   R¶  R·  t   xray_structure_as_cif_blockt	   cif_block(   R   R¼  R½  Rº  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR¸  z  s    	c         C   s@   d d  l  } | j j j d |  d | d | d | d | d | ƒ S(   NiÿÿÿÿR   t   remarkt   remarkst   fractional_coordinatesRQ  t   connect(   t   iotbx.pdb.xray_structuret   pdbR  t   as_pdb_file(   R   RÀ  RÁ  RÂ  RQ  RÃ  Rº  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyRÆ  €  s    c         O   s"   d d  l  } | j j |  | | Ž S(   Niÿÿÿÿ(   t   iotbx.shelxt   shelxt   cctbx_xray_structure_from(   t   clst   argst   kwdsRº  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt
   from_shelx�  s    c      	   C   s†   d d  l  } d d l  m } | j j d | d | d | d | j ƒ } t | j ƒ rv | d  k	 rl | j | S| j Sn t d ƒ ‚ d  S(   Niÿÿÿÿ(   t   builderst   file_objectt	   file_patht   data_block_namet   data_structure_builders8   Could not extract an xray.structure from the given input(	   R¶  RÎ  R·  t   cctbx_data_structures_from_cift   crystal_structure_builderR±   t   xray_structuresR   R   (   RÊ  RÏ  RÐ  RÑ  Rº  RÎ  R‡   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   from_cif”  s    
c         C   sE   t  g  |  j ƒ  D]. } | s, | j | k r | j | j f ^ q ƒ S(   s4    The content of the unit cell as a chemical formula (   t   dictRÐ   RÆ   RÈ   (   R   t   omitRV   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   unit_cell_content¤  s    c            s]  g  ‰ d ‰ d ‰  ‡  ‡ f d †  } t  ƒ  ‰ ‡ ‡ ‡ f d †  ‰ x|  j ƒ  D]‰ ˆ j j ƒ  j d d ƒ j ƒ  ‰ | ˆ ƒ } ˆ ˆ k r¤ | r¤ ˆ d ˆ ƒ qO ‡ ‡ ‡ f d †  } ‡ ‡ ‡ f d	 †  } ‡ ‡ ‡ f d
 †  } | r+| d d ƒ rþ qO n  | d d ƒ rqO n  | d d ƒ r+qO q+n  | ƒ  r:qO n  | ƒ  rIqO n  t d ƒ ‚ qO Wˆ S(   Nt   ABCDEFGHIJKLMNOPQRSTUVWXYZt
   0123456789c            su   t  |  ƒ d k r t St  |  ƒ d k r, t S|  d ˆ k r@ t Sx. |  d D]" } | ˆ k rK | ˆ  k rK t SqK Wt S(   Ni    i   i   (   R±   Rœ   R3   (   t   lblR´   (   t   digitsR.  (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   is_useful_label®  s       c            sB   ˆ j  |  k r1 ˆ j ˆ j  |  f ƒ |  ˆ _  n  ˆ  j |  ƒ d  S(   N(   RM  Rƒ   t   add(   RM  (   t   lbl_setR‡   R†   (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   reset¸  s    R8  R½   RM  c            s]   xV t  d | ƒ D]E } |  | } ˆ  d t | ƒ  | } | ˆ k r ˆ d | ƒ t Sq Wt S(   Ni   i   RM  (   RO   R±   R3   Rœ   (   t   fmtR�  RW   RF   t   trial(   RÜ  Rà  Rá  (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   find_tail_replacementÃ  s    
c             sÞ   d d l  m }  |  d ˆ j d t ƒ \ } } t | ƒ d k rD t St | ƒ d k s\ t ‚ t | ƒ d k r} d \ } } n d \ } } | j ƒ  } xB t d | ƒ D]1 } | | | } | ˆ  k r¥ ˆ d | ƒ t Sq¥ Wt S(   Niÿÿÿÿ(   t   get_element_and_charge_symbolsRÆ   R¢  i    i   i   s   %03diè  s   %02did   RM  (   s   %03diè  (   s   %02did   (	   t   cctbx.eltbx.xray_scatteringRå  RÆ   Rœ   R±   R"   R.  RO   R3   (   Rå  t   eR¼  Râ  R�  RW   Rã  (   Rà  Rá  R†   (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt&   find_replacement_using_scattering_typeË  s"    	  c             sZ   xS ˆ D]K }  xB t  d d ƒ D]1 } |  d | } | ˆ  k r ˆ d | ƒ t Sq Wq Wt S(   Ni   iè  s   %03dRM  (   RO   R3   Rœ   (   R´   RW   Rã  (   Rà  Rá  R.  (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   find_complete_replacementÛ  s    s   %di
   s   %02did   s   %03diè  s7   Unable to find unused SHELX-compatible scatterer label.(   t   setR   RM  R-  t   replaceR.  RL   (   R   RÞ  t   lbl_is_usefulRä  Rè  Ré  (    (   RÝ  RÜ  Rà  Rá  R‡   R†   R.  sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt/   make_scatterer_labels_shelx_compatible_in_placeª  s8    		!   		 	 c         C   sœ   |  j  ƒ  | } |  j  ƒ  | } | j j ƒ  r; | j } n	 | j } | j j ƒ  r_ | j } n	 | j } t j d | d | d | j d | j d |  j ƒ  ƒ S(   s�   
    For a pair of scatterers, calculates their overlap given the coordinates
    and displacement parameters (using adptbx.intersection).
    t   u_1t   u_2t   site_1t   site_2R/   (	   R   R~   R‚   R„   R�   R   t   intersectionRè   R/   (   R   R‰   R•  t   sc1t   sc2t   u1t   u2(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   intersection_of_scatterersí  s    					N(’   R   R   t   __doc__R   Rœ   R   R$   R   R%   R6   R   R:   R   R!   RA   RJ   R[   Ra   Rd   Re   Rl   Rm   Rr   Rx   Ry   Rz   R|   Rˆ   R›   RŸ   R¤   R¦   Rh   R¯   R¹   R¼   RÅ   RÐ   RØ   Rä   R÷   R!  R$  R%  R&  R\   R€   R‚   Rê   Rb   R*  R0  R    RŠ   R1  R4  R7  RR  R[  R\  R^  R_  Rb  Rd  Ri  Rl  R3   Rt  Rq  Ru  Rv  R›  R    R«   R*   RÇ  RÌ  RÎ  RÖ  Rs   RØ  RÞ  R(   Râ  Ró  Rû  Rý  R   R  R  R  R  R}  R   RG   R   R"  R%  R&  R'  R)  R/  R2  R5  R8  R:  R;  R<  R?  RB  RG  RN  Ro  RQ  RT  RV  Ri  Rk  Rm  Rq  Rc  Rd  Rr  Ry  R~  R�  R†  Rô  RŠ  R…  RŽ  R‘  R’  Rë   R¬  R²  R´  R»  R¸  RÆ  RÍ  t   classmethodRÖ  RÙ  Rí  R÷  (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR   &   s˜  		
	
										
				$Qj															@+					3		R
						!	

9	
								
	!				
+		!								8		
		CR‘  c           B   s   e  Z d  „  Z RS(   c   	   	   C   så   d d l  m } t j d t j d | d | j ƒ  j ƒ  d | j ƒ  ƒ d d ƒ } | re | d	 9} n  | j	 d
 | ƒ } t j
 d | ƒ } | j d | ƒ | j d | ƒ |  _ | sÀ d  |  _ n! | j ƒ  } | j d | ƒ |  _ d  S(   Niÿÿÿÿ(   t   geometry_restraintsRD   R  t   orthogonalization_matrixR\   t   defaulti   i   Rõ  Rô  t	   sym_tableRŠ  (   RI  Rú  R   t   max_defaultR   t   get_distancesR/   Rû  R\   Rô  RŠ  t   add_pair_sym_tablet   bond_sorted_asu_proxiest   bondR   R  t   angle_pair_asu_table(	   R   R   R�  R�  Rú  Rõ  Rô  t   bond_pair_asu_tableR  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR   	  s&    			 		(   R   R   R   (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR‘  	  s   t    meaningful_site_cart_differencesc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   sw   Differences between the Cartesian coordinates of corresponding sites
  in two structures, cancelling continuous origin shifts if any.

  This is especially useful to compare a refined
  structure to a reference structure as the former may have drifted along
  a continuous shift direction during refinement, therefore spoiling
  a naive comparison of corresponding sites.
  c         C   sˆ  g  | j  ƒ  D] } | j ^ q |  _ | j ƒ  | j ƒ  |  _ } | j ƒ  | j ƒ  k r„t j | j ƒ  ƒ j d t	 ƒ } | j
 ƒ  r„g  | j ƒ  D]' } t j | j ƒ  j | j ƒ ƒ ^ q” } t | ƒ d k r| d j ƒ  } | j ƒ  }	 | j |	 ƒ }
 nˆ t | ƒ d k r`| d j ƒ  } | d } | d | j | ƒ | j ƒ  }	 | j |	 ƒ }
 n) t | ƒ d k r‰d d d } }	 }
 n  g  | |	 |
 f D] } | j | ƒ ^ q™} g  | D] } t j | ƒ ^ q»} t | ƒ d k rþ| d d d f } nM t | ƒ d k r*| d | d d f } n! t | ƒ d k rKt | ƒ } n  t j | d | d | d ƒ |  _ |  j | 8_ q„n  d  S(	   Nt   discretei   i    i   i   (   i   i    i    (   i    i   i    (   i    i    i   (   R   RM  Rc  Rb   t   deltaR‘   R   t   structure_seminvariantsRs   Rœ   R@   t   vectors_and_moduliR	   Rç   R/   Ræ   R
  R±   R  t   orthoR  Ru   R   R{   t   tupleRn   (   R   t   xs1t   xs2R†   t   canonical_deltat   ssit   vmRA  t   e0t   e1t   e2R
  Rç  t   deltast   dt   meanst   means_correction(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR   &	  s:    %	7
!+"$c         C   s   t  j |  j j ƒ  ƒ S(   N(   R   t   max_absoluteR  R+  (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR  E	  s    c         C   sI   d d  l  } x6 | j |  j |  j ƒ D] \ } } d | f | GHq% Wd  S(   Niÿÿÿÿs   %6s: (%.6f, %.6f, %.6f)(   t	   itertoolst   izipRc  R  (   R   R  RÜ  t   diff(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR  H	  s    %(   R   R   Rø  R   R  R  (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyR  	  s   		(*   t
   __future__R    t
   cctbx.xrayR   R   RI  R   R   R   Ræ  R   R   t   cctbx.array_familyR   t   scitbx.mathRS  R	   t   stdlibR
   R  R   RÒ  R{  RŽ   t   libtbx.utilsR   R   R   t   libtbx.test_utilsR   t   libtbxR   t   libtbx.assert_utilsR   t   cctbx.eltbx.neutronR   R«  R   R#   R   R‘  R  (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/xray/structure.pyt   <module>   sD   ÿ ÿ ÿ ÿ ÿ ÿ ÿ ÿ å