ó
�™xTc           @   s•  d  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 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 e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ e d ƒ \ Z Z Z Z Z d d e d d „ Z  d e f d „  ƒ  YZ! d e e! f d „  ƒ  YZ" d e f d „  ƒ  YZ# d e f d „  ƒ  YZ$ d S(   s    Lexing of ins/res files iÿÿÿÿ(   t   divisionN(   t   rational(   t   uctbx(   t   sgtbx(   t   xray(   t   eltbx(   t   adptbx(   t   error(   t   tokenst   parserc           B   s   e  Z d d  „ Z d „  Z RS(   c         C   s   | |  _  | |  _ d  S(   N(   t   command_streamt   builder(   t   selfR
   R   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/shelx/parsers.pyt   __init__   s    	c         C   s!   x |  j  ƒ  D] \ } } q Wd  S(   N(   t   filtered_commands(   R   t   commandt   line(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/shelx/parsers.pyt   parse   s     N(   t   __name__t
   __module__t   NoneR   R   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/shelx/parsers.pyR	      s   t   instruction_parserc           B   s,   e  Z d  Z d d „ Z d „  Z d „  Z RS(   s|   A parser for extracting from the command stream miscellaneous
      shelxl commands that do not concern other parsers.

      If this parser is constructed with a real builder, the wt and m
      arguments to HKLF are not supported.

      This parser is unusual in that it does not rely entirely on its
      builder: it builds a dictionary containing the parsed information.
  c         C   sK   d d l  m } | d  k r+ | j ƒ  } n  t j |  | | ƒ i  |  _ d  S(   Niÿÿÿÿ(   t   object_oriented_patterns(   t   libtbxR   R   t   nullR	   R   t   instructions(   R   R
   R   t   oop(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/shelx/parsers.pyR   (   s
     c      	   c   s  d d l  m } d } xò|  j D]Ì\ } } | d | d } } t | ƒ } | d k r| d k r» t | d t ƒ r» |  j j d g  ƒ |  j d j g  | D] } t	 | ƒ ^ qŸ ƒ qì| d k r t | d t ƒ r i | d d	 6| d
 d 6|  j d <qì| | f Vq  | d k rT| rìi | d d 6}	 | d
 k rQ| d
 |	 d <qQqìq  | d k r}| rì| d |  j d <qìq  | d k rÙt | ƒ d
 k rªt
 d ƒ ‚ n  | r½| d } n  | |  j d <| |  j _ q  | d k r¤| d k rt
 d | | ƒ ‚ n  i d d 6d d 6d d 6d d 6d d 6d: d 6}
 t g  t j d | ƒ D]. \ } } | | d  k	 rn| pu|
 | f ^ qMƒ } | |  j d  <|  j j | �  q  | d! k r§d" |  j k sÅt ‚ i d
 d	 6t j ƒ  d# 6} | d | d$ <| d
 k r| d
 | d	 <| d k r| d% k s%t ‚ g  | d d& !D]! } | j | d' d( ƒj ƒ  ^ q3} t t j g  | D] } | j ƒ  ^ qjƒ } g  | D]  } | j ƒ  | | j ƒ  ^ qŒ} t j | | ƒ | d# <| d& k r| d& | d) <| d* k r| d+ | d, <qqqn  | |  j d" <|  j s=d) | k r7d, | k s=t ‚ |  j j d- | d$ d. | d# d/ | d	 ƒ d0 |  j k rì| d$ d1 k rì|  j j d2 |  j d0 ƒ qìq  | d3 k rtd4 |  j k sÈt ‚ i  } | d k rH| d5 k sìt ‚ t j t j g  | d d5 !D] } t	 | ƒ ^ qƒ ƒ | d# <| d5 k rH| d5 | d$ <qHn  | |  j d4 <d0 |  j k rì|  j ƒ  qìq  | d6 k r¬| |  j d0 <d4 |  j k rì|  j ƒ  qìq  | d7 k rát | ƒ d
 k rì| d |  j d8 <qìq  | | f Vq  Wd" |  j k st d9 ƒ ‚ d  S(;   Niÿÿÿÿ(   t   continued_fractioni   i    t   OMITi   t   omit_hkli   t   si   t	   two_thetat   omitt   SHELt   lowrest   highrest   MERGt   mergt   TEMPs   TEMP takes at most 1 argumentt   tempt   WGHTi   s   Too many argument for %sgš™™™™™¹?t   at   bt   ct   dt   et   ft   abcdeft   wghtt   HKLFt   hklft   matrixt   ni
   i   t   epsgü©ñÒMbP?t   wti   i   t   mt   formatt   indices_transformt
   data_scalet   basfi   t	   fractionst   TWINt   twini	   t   BASFt   EXTIt   extis   Missing HKLF instructiongUUUUUUÕ?(    t   scitbx.mathR   R
   t   lent
   isinstancet   floatR   t
   setdefaultt   appendt   intt   shelx_errorR   t   temperature_in_celsiust   dictt	   itertoolst   izip_longestR   t   make_shelx_weighting_schemet   AssertionErrorR   t   rot_mxt	   from_realt   as_rationalt   reduceR   t   lcmt   denominatort	   numeratort#   create_shelx_reflection_data_sourcet1   make_non_merohedral_twinning_with_transformed_hklt   rt_mxt   issue_merohedral_twinning(   R   R   t   temperatureR   R   t   cmdt   argst   n_argst   it   shelt   default_weighting_schemet   keyt   argt   weighting_schemeR2   R-   t   mxt   rt   dent   numsR>   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/shelx/parsers.pyR   .   s´    0 

G2+-(

6  c         C   s‚   |  j  d j d t j d ƒ ƒ } |  j  d j d d ƒ } | d t |  j  d ƒ k s^ t ‚ |  j j d |  j  d d	 | ƒ d  S(
   NR>   R3   s   -x,-y,-zR4   i   i   R;   R<   t   twin_law(   R   t   getR   RY   RC   RO   R   t   make_merohedral_twinning(   R   Ri   R4   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/shelx/parsers.pyRZ   �   s    #N(   R   R   t   __doc__R   R   R   RZ   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/shelx/parsers.pyR      s   		_t   crystal_symmetry_parserc           B   s    e  Z d  Z d „  Z d „  Z RS(   sF    A parser pulling out the crystal symmetry info from a command stream c         c   sÕ  d } d } t j ƒ  } x¶|  j D]«\ } } | d | d } } | d k r‚ | d k sa t ‚ t j | d ƒ } | | f Vq" | d k r¸ | d k s  t ‚ | d } | | f Vq" | d k r1t | ƒ d k sÜ t ‚ t | d ƒ } | d k r| j	 t j
 d ƒ ƒ n  d t | ƒ }	 | j |	 ƒ q" | d k rxt | ƒ d k sUt ‚ t j | d ƒ }
 | j |
 ƒ q" | d	 k rÂ| d k	 s–t ‚ |  j j d
 | d | ƒ |  j j | ƒ n  | | f Vq" Wd S(   sÔ    Yields those command in self.command_stream
        that this parser is not concerned with. On the contrary,
        LATT, SYMM are swallowed (CELL is yielded because it carries
        the wavelength too).
    i    iÿÿÿÿt   CELLi   t   ZERRt   LATTs   *PIRFABCt   SYMMt   SFACt	   unit_cellt   space_groupN(   i    i    i    (   R   R   Rt   R
   RO   R   Rs   RC   RH   t
   expand_invt   tr_vect   abst!   expand_conventional_centring_typeRY   t
   expand_smxR   t   make_crystal_symmetryt   set_unit_cell_parameter_sigmas(   R   Rs   t   unit_cell_param_sigmasRt   R   R   R\   R]   R4   t   zR   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/shelx/parsers.pyR   ›   s<    
c         C   s5   x. |  j  ƒ  D]  \ } } | d d k r Pq q Wd  S(   Ni    Rr   (   R   (   R   R   R   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/shelx/parsers.pyR   Á   s     (   R   R   Rl   R   R   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/shelx/parsers.pyRm   ˜   s   	&t   wavelength_parserc           B   s   e  Z d  Z d „  Z RS(   s@    A parser pulling out the wavelength info from a command stream c         c   s]   xV |  j  D]K \ } } | d | d } } | d k rJ | d |  j _ n  | | f Vq
 Wd  S(   Ni    iÿÿÿÿRn   (   R
   R   t   wavelength_in_angstrom(   R   R   R   R\   R]   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/shelx/parsers.pyR   É   s
    (   R   R   Rl   R   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/shelx/parsers.pyR~   Æ   s   i   c            s)  g  } g  } xt  | ƒ D]\ ‰ ‰  ‡  ‡ ‡ f d †  } y t j j ˆ  d ƒ \ }	 }
 Wn t k
 rs | ƒ  n X|	 d k r½ |	 d }	 | j |
 |  |	 d ƒ | j t |
 |	 f ƒ q |	 d k rr| d  k	 rUˆ | k rU|
 d k  rU| d  k	 sÿ t ‚ | j	 \ } } | j
 | j j j ƒ  ƒ } | j |
 | ƒ | j t |
 | f ƒ q| j |
 ƒ | j t ƒ q |	 d k r›| j |
 ƒ | j t ƒ q |	 d k rß|	 d }	 | j |
 |  |	 ƒ | j t |
 |	 f ƒ q |	 d k sñt ‚ | s| ƒ  n  | j d ƒ | j t ƒ q W| | f S(	   Nc              s   t  d ˆ ˆ d ˆ  ƒ ‚ d  S(   Ns   scatterer parameter #%d '%s'i   (   RI   (    (   t   coded_variablet   i_cvR   (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/shelx/parsers.pyt   raise_parameter_errorâ   s    i
   iþÿÿÿi   i    g      à¿i   iÿÿÿÿ(   t	   enumeratet   scitbxt   matht   divmodt   ArgumentErrorRG   t3   constant_times_independent_scalar_parameter_minus_1R   RO   t   scatterer_to_bind_u_eq_tot   u_iso_or_equivR   t   crystal_symmetryRs   t   constant_times_u_eqt   independent_parametert   constant_parametert+   constant_times_independent_scalar_parameter(   t   free_variablet   coded_variablest	   u_iso_idxR   t   strictly_shelxlt   variable_decodert   valuest
   behavioursR‚   R7   t   pt   scattt	   scatt_idxt   u_iso(    (   R€   R�   R   sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/shelx/parsers.pyt   decode_variablesØ   sJ    $

R”   c           B   s    e  Z d d  „ Z d d „ Z RS(   c         C   s4   t  d |  j d | d | d |  j d |  j d |  ƒ S(   NR�   R‘   R’   R   R“   R”   (   R›   R�   R   R“   (   R   R‘   R’   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/shelx/parsers.pyR›     s    			c         C   s-   |  j  | f | ƒ \ } } | d | d f S(   Ni    (   R›   (   R   R€   R’   R•   R–   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/shelx/parsers.pyt   decode_one_variable  s    N(   R   R   R   R›   Rœ   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/shelx/parsers.pyR”     s   	t   atom_parserc           B   sJ   e  Z d  Z d e d „ Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(   sÌ   A parser pulling out the scatterer info from a command stream.

      Since the SHELX format intertwine parameter values with some of the
      constrained on them, this parser does also handle those constraints,
      specifically constrained occupancies and u_iso bound to the u_eq of
      another scatterer. The parser tests whether the builder passed at
      construction time handles those constraints, and if it does not so,
      they get ignored.
  c         C   s—   t  j |  | | ƒ d  |  _ | |  _ y |  j j t } Wn t k
 rR t	 } n X| |  _
 y |  j j t } Wn t k
 r‰ t	 } n X| |  _ d  S(   N(   R	   R   R   R�   R“   R   t$   add_occupancy_pair_affine_constraintt   Truet   AttributeErrort   Falset-   builder_does_occupancy_pair_affine_constraintt$   add_u_iso_proportional_to_pivot_u_eqt-   builder_does_u_iso_proportional_to_pivot_u_eq(   R   R
   R   R“   t   flag(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/shelx/parsers.pyR   *  s    		


	


c         c   sµ  d  |  _ d  } d } d } d } d  } d } i  } t } i  }	 |  j }
 |  j r] i  |  _ n  xG|  j D]<\ } } | |  _ | d | d } } | d k rë |
 j ƒ  t	 | ƒ d k rÛ t
 | d t ƒ rÛ t d ƒ ‚ n  d | |  _ qg | d k r,| d  k r| d } | |  _ q£|  j | |  _ qg | d	 k rÄd  } d } d } d } | rit | d ƒ } n  t	 | ƒ d
 k r‘|  j | d ƒ } n  | d k r¦| } q£| d k  r£t | ƒ } q£qg | d k ré| } |  j j | Œ  qg | d k rR| s(|  j d  k rt d |  j ƒ ‚ n  t } n  |  j | | ƒ \ } } | \ } } | j j ƒ  } | j | | f ƒ } | d  k	 r¡t d | | | | f d d  ƒ‚ n  | | | | f <| s½| rÙ| rÙ| \ | _ | d <n  |
 j | | d t d | d | d | d | ƒ|
 j j ƒ  d } |  j | | | d ƒ |  j | | d ƒ | d 7} qg | d k r˜|  j stt d ƒ ‚ |
 j  d | d
 d !d | d ƒ qg | | f Vqg W|  j! ƒ  d  S(   Ni    iÿÿÿÿRr   i   i   s2   SFAC label a1 b1 a2 b2 a3 b3 a4 b4 c f' f" mu r wtt   *t   FVARt   PARTi   t   RESIt   __ATOM__sB   An instruction SFAC needs to appear before this point in the file,sm   Residue #%i has two scatterers named %s, (with perhaps a difference in letter case)defined at lines %i and %iR   i   t"   occupancy_includes_symmetry_factort   conformer_indext   sym_excl_indext   residue_numbert   residue_classi   t
   __Q_PEAK__s+   Q-peaks amidst atoms in strict ShelXL modelt   sitei   t   height(   NN(   R¦   ("   R   t   label_for_sfacR¡   R   R¢   t&   occupancies_depending_on_free_variableR
   R   t   make_structureRC   RD   RE   t   NotImplementedErrorR�   RH   Rœ   Rw   t   add_residueRI   RŸ   t   lex_scatterert   labelt   upperRj   t	   occupancyt   add_scatterert	   structuret
   scattererst&   process_possible_constrained_occupancyt"   process_possible_u_iso_constraintsR“   RO   t   add_electron_density_peakt.   process_occupancies_depending_on_free_variable(   R   t   overall_scalet   scatterer_indexR¬   R­   t   part_soft   current_residuet   line_of_scatterer_namedt   in_the_midst_of_atom_listt'   idx_assigned_by_builder_to_free_var_idxR   R   R   R\   R]   t   part_numbert	   scatterert   behaviour_of_variableR®   R¯   t   namet   line_1(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/shelx/parsers.pyR   ;  s¢    				
%
 	 				c         C   sS   |  j  rO y | \ } } } Wn t t f k
 r5 qO X|  j j | | | ƒ n  d  S(   N(   R¤   t	   TypeErrort
   ValueErrorR   R£   (   R   t   u_iso_scatterer_idxt   u_iso_behaviourt   kindt   coefft   u_eq_scatterer_idx(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/shelx/parsers.pyRÀ   –  s    		c         C   s  |  j  ry | \ } } } Wn t t f k
 r5 qX|  j sT t d |  j ƒ ‚ n  | | j ƒ  } t j j	 j
 | d d ƒj ƒ  } t | j ƒ  | j ƒ  d d ƒ} | t k rÛ |  j j | g  ƒ j | d | f ƒ q| t k r|  j j | g  ƒ j | d | f ƒ qn  d  S(   NsB   An instruction FVAR needs to appear before this point in the file,R5   gñhãˆµøä>t   ndigitsi   i    iÿÿÿÿ(   R¢   RÏ   RÐ   R�   RI   R   t   weight_without_occupancyR„   R…   R   RQ   RR   t   roundRV   RU   R�   R´   RF   RG   Rˆ   (   R   RÄ   RË   t   occupancy_behaviourRÓ   RÔ   t   free_var_idxt   r_coeff(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/shelx/parsers.pyR¿   ¤  s$    		"		c   	   	   C   sÊ   |  j  s d  Sx¶ |  j j ƒ  D]¥ \ } } t | ƒ d k rA q q x~ t t | ƒ d ƒ D]f } | | | d !\ \ } } } \ } } } |  j j d | | f d d | d | f | | f ƒ qX Wq Wd  S(   Ni   i   t   scatterer_indicest   linear_formiÿÿÿÿ(   R¢   R´   t	   iteritemsRC   t   xrangeR   Rž   (	   R   RÚ   t   affine_occupanciesR_   R)   R*   t   a1t   b1t   i1(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/shelx/parsers.pyRÂ   ½  s    	 )c         C   sº  | d } t  | d ƒ } t | ƒ d } | d k sL |  j r… | d k r… |  j | d d !d | d ƒ\ } } | d } t }	 nŠ | d	 k rý |  j j j ƒ  }
 |  j | d d
 !| d | d | d
 f d d  ƒ\ } } t	 j
 |
 | d ƒ } t }	 n t d |  j ƒ ‚ | d d !} | d } t j j |  j | d t ƒ} t j d | d | d | d | d | ƒ } |	 sžt | d t ƒ sž| d d t k r°| | f |  _ n  | | f S(   Ni    i   i   i   i   i   R’   i   i
   iýÿÿÿiÿÿÿÿiþÿÿÿiúÿÿÿs(   wrong number of parameters for scattereri   t   exactR¹   R±   R»   t   ut   scattering_type(   RH   RC   R“   R›   RŸ   R   R‹   Rs   R   R   t   u_cif_as_u_starR¡   RI   R   R   t   xray_scatteringt   get_standard_labelR³   R   RË   RD   t   tupleRŒ   R‰   (   R   R]   RÄ   RÍ   R4   t   n_varsR•   R–   Rå   t	   isotropicRs   R±   t   occRæ   RË   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/shelx/parsers.pyR¸   Ï  sD    
"
	&	
				N(   R   R   Rl   R   RŸ   R   R   RÀ   R¿   RÂ   R¸   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/shelx/parsers.pyR�     s   		[			t   afix_parserc           B   sc   e  Z d  Z i
 d d 6d d 6d d 6d d	 6d d 6d d 6d d 6d d 6d d 6d  d 6Z d „  Z RS(!   s"    It must be before an atom parser t   tertiary_xh_siteiÿÿÿÿi   t   secondary_xh2_sitesi   t(   staggered_terminal_tetrahedral_xh3_sitesi   t   secondary_planar_xh_sitei   t&   staggered_terminal_tetrahedral_xh_sitei   t   terminal_planar_xh2_sitesi	   t   terminal_tetrahedral_xh3_sitesi   t   terminal_tetrahedral_xh_sitei   t   polyhedral_bh_sitei   t   terminal_linear_ch_sitei   c         c   sŸ  t  } x’|  j D]‡\ } } | d | d } } | d k r| d k rb | rb t d | ƒ ‚ n  | r¢ | | k r† t d | ƒ ‚ n  |  j j ƒ  t  } d } n  | d k r¿ | | f Vq n  | d } | d k rÛ q n  t | d ƒ \ }	 }
 d \ } } } | d	 } | sn{ t | ƒ d	 k r1| d } n\ t | ƒ d k rV| d \ } } n7 t | ƒ d
 k r~| d \ } } } n t d | ƒ ‚ |  j j	 |	 ƒ } | d  k	 r—| \ } } |  j j
 | ƒ } |  j j d | d | d |
 d k d |
 d k d | ƒ | j } t } d } q—q | d k rŒ| r~| d  k	 rF| | d
 <n  | d  k	 rqt | ƒ d k rq| | d <n  | d	 7} n  | | f Vq | | f Vq Wd  S(   Ni    iÿÿÿÿt   AFIXR1   s   too few argumentss   wrong number of afixed atomsi
   i   i   i   s   too many argumentst   type_t   bond_lengtht   rotatingi   i   t
   stretchingt   pivot_relative_posRª   i   (   Rù   s   HKLF(   N(   NNN(   i   i   (   i   i   (   R¡   R
   RI   R   t   end_geometrical_constraintR†   R   RC   t   constraintsRj   t    make_geometrical_constraint_typet   start_geometrical_constraintt   n_constrained_sitesRŸ   (   R   t   active_afixR   R   R\   R]   t   n_afixedt   n_expected_afixedt   mnR7   R4   R,   t   sofRå   t   paramst   infot   constraint_nameRþ   t   constraint_type(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/shelx/parsers.pyR     sj    	
 
    			  (   Rï   iÿÿÿÿ(   Rð   iÿÿÿÿ(   Rñ   iÿÿÿÿ(   Rò   iÿÿÿÿ(   Ró   iÿÿÿÿ(   Rô   iÿÿÿÿ(   Rõ   iÿÿÿÿ(   Rö   iÿÿÿÿ(   R÷   iÿÿÿÿ(   Rø   iÿÿÿÿ(   R   R   Rl   R   R   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/shelx/parsers.pyRî   õ  s   
t   restraint_parserc           B   sp   e  Z d  Z i d d 6d d 6d d 6d d 6d d	 6d
 d 6d d 6d d 6Z d „  Z d „  Z d „  Z d „  Z RS(   s!    It must be after an atom parser t   bondt   DFIXt   DANGt	   planarityt   FLATt	   chiralityt   CHIVt   bond_similarityt   SADIt   adp_similarityt   SIMUt
   rigid_bondt   DELUt   isotropic_adpt   ISORc         c   sÑ   i  |  _  i  |  _ x® |  j D]£ \ } } | d | d } } t | ƒ d k r\ | d } n d  } | |  j k rŠ |  j | | | | ƒ q | d k r´ |  j j | d | d ƒ q | | f Vq W|  j ƒ  d  S(   Ni    iÿÿÿÿi   i   t   EQIV(	   t   cached_restraintst   symmetry_operationsR
   RC   R   t   restraint_typest   cache_restraintRF   t   parse_restraints(   R   R   R   R\   R]   t   cmd_residue(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/shelx/parsers.pyR   H  s    		c         C   s_   d d l  m } | |  j j ƒ  k r> |  j j | | ƒ  ƒ n  |  j | j | | | f ƒ d  S(   Niÿÿÿÿ(   t   OrderedDict(   t   libtbx.containersR$  R  t   keysRF   (   R   R\   R#  R   R]   R$  (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/shelx/parsers.pyR!  Y  s    c         C   s  g  } x| D]ÿ } | j  d k r\ | j t | d d t |  j j j ƒ  ƒ d ƒ ƒ q n  | j } | j d  k	 r² | j d  k s‰ t
 ‚ | j d k r¥ | d } q² | d } n  | d  k rÇ | } n  y# |  j j | | j  j ƒ  f } Wn t k
 rþ d  SX| j | ƒ q W| S(   Nt   LASTiÿÿÿÿi   t   +(   RÍ   t   extendRß   t   maxR   t   index_of_scatterer_namedR•   R®   t
   plus_minusR   RO   t   lowert   KeyErrorRG   (   R   t   atomsR®   t   i_seqst   atomt   atom_resnumt   i_seq(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/shelx/parsers.pyt   i_seqs_from_atoms_  s,     		c         C   sq  xjt  |  j j ƒ  ƒ D]S\ } } xD| j ƒ  D]6\ } } | d } | d  k r] d  g } ns | d } | t j k r† | d g } nJ | t j k r¬ |  j j	 | d } n$ | t j
 k rÐ |  j j j ƒ  } n  | d } g  } g  }	 g  }
 x | D]w } y | j t | ƒ ƒ Wqó t k
 ri} t | t j ƒ rD|	 j | ƒ qjt | t j ƒ rj|
 j | ƒ qjqó Xqó Wxô| D]ì} y¹|  j |	 | ƒ } | d  k r¢wun  |  j j | ƒ } | d k rt | ƒ d k sØt ‚ | d } t | ƒ d k r| d } n | d k rd } n d } t |	 ƒ d k s4t ‚ d | d } t |	 ƒ d d k s^t ‚ x£ t t |	 ƒ d ƒ D]ˆ } |	 | d | d d !} | | d | d d !} g  | D] } |  j j | j ƒ ^ q´} |  j j | d | d	 | d
 | d | ƒquWn  | d k rt | ƒ d k s(t ‚ t | ƒ rA| d } n d } g  } g  } x† t t |	 ƒ d ƒ D]n } |	 | d | d d !} | j | | d | d d !ƒ | j g  | D] } |  j j | j ƒ ^ q¶ƒ qjWd | d g t | ƒ } |  j j | d | d
 | d | ƒn| d k råt | ƒ d k s@t ‚ t | ƒ d k r_| d } n d } t |	 ƒ d k s}t ‚ g  |	 D] } |  j j | j ƒ ^ q„} d | d g t | ƒ } |  j j | d | d
 | d | ƒnN| d k rôn?| d k r3t | ƒ d k st ‚ d  } } } t | ƒ d k rE| d } n  t | ƒ d k rd| d } n  t | ƒ d k rƒ| d } n  t | ƒ d k ržd  } n  | d  k rÝ| d k r¿d } qÝ| d k rÔd } qÝd } n  | d k r|  j j | d | d | d
 | ƒq3|  j j | d | d | d
 | ƒn  Wqut t f k
 r`t d | | ƒ ‚ quXquWq/ Wq Wd  S(   Ni    i   R  R  i   g{®Gáz”?g{®Gáz¤?t   distance_idealt   weightR0  t   sym_opsR  t   weightsR  gš™™™™™¹?i   R  R  R  R  g{®Gáz„?t   sigma_12t   sigma_13t   sigmat   sigma_terminals   Invalid %s instruction(   R  R  (   i   i   (   R  R  R  (   t   sortedR  t   itemsRÞ   R   R   t   residue_number_tokt   residue_class_tokR   t   residue_numbers_having_classt   all_residues_tokt   residue_class_of_residue_numberR&  RG   RE   RÏ   RD   t   atomname_tokent   element_tokenR4  R   Rj   RC   RO   t   rangeR  t   symmetryt   process_restraintRI   (   R   R\   t
   restraintsR   R]   R#  t   residuest   tokt   floatsR/  t   elementsRc   R-   R®   R0  t   restraint_typeR5  R;  R6  R_   t	   atom_pairt
   i_seq_pairR1  R7  t   i_seq_pairsR8  t   s1t   s2t   dmax(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/shelx/parsers.pyR"  y  sà    "


 
 	% *
(
	 	 		

(   R   R   Rl   R   R   R!  R4  R"  (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/shelx/parsers.pyR  :  s   
			(%   Rl   t
   __future__R    RL   t   boostR   t   cctbxR   R   R   R   R   RB   R„   t   iotbx.shelx.errorsR   RI   t   iotbx.shelxR   t   objectR	   R   Rm   R~   Rß   RŽ   R�   Rˆ   R�   RŒ   R   RŸ   R›   R”   R�   Rî   R  (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/shelx/parsers.pyt   <module>   s0   
{.2ÖE