ó
|™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 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 Z d  d
 l Z e d ƒ Z d e f d „  ƒ  YZ d „  Z  d „  Z! d „  Z" d „  Z# d d d „ Z$ d d d „ Z% d „  Z& d „  Z' d „  Z( d „  Z) d „  Z* d „  Z+ d „  Z, d  „  Z- d! „  Z. d" „  Z/ d# „  Z0 d$ „  Z1 d% „  Z2 e3 e3 e4 d& d' d( „ Z5 d) „  Z6 d* „  Z7 d+ „  Z8 d, „  Z9 d- „  Z: d. „  Z; d/ „  Z< d0 „  Z= d1 „  Z> d2 „  Z? d3 f  d4 „  ƒ  YZ@ d5 e f d6 „  ƒ  YZA d7 e f d8 „  ƒ  YZB d9 e f d: „  ƒ  YZC d; e f d< „  ƒ  YZD d
 S(=   iÿÿÿÿ(   t   division(   t   get_ncs_object_from_pdb(   t   apply_transforms(   t   eigensystem(   t   flex(   t	   superpose(   t
   ncs_search(   t   Sorry(   t   parseN(   t   ncs(   t   matrix(   t   pdbs0  
  ncs_group
    .multiple = True
    {
    master_selection = ''
      .type = str
      .help = 'Residue selection string for the complete master NCS copy'
    copy_selection = ''
      .type = str
      .help = 'Residue selection string for each NCS copy location in ASU'
      .multiple = True
  }
  t   ncs_group_objectc           B   sÙ  e  Z d  „  Z d! d! d! d! d! d! d! d! d d d d e d! d! e e e d e e d d d „ Z d! d! d! d „ Z d! d! d! e d d „ Z e e e d e d d d	 „ Z	 d
 „  Z
 d! d d d e d! g  e d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d d „ Z d „  Z d „  Z d „  Z e d „ Z d „  Z d! d „ Z d „  Z d „  Z d „  Z d! e d! d! d! d! d! d! e e j d „
 Z d! d! d! d! e j e e e d „ Z e e j d „ Z  e d  „ Z! RS("   c         C   sú   d |  _ i  |  _ i  |  _ i  |  _ i  |  _ i  |  _ d |  _ i  |  _ i  |  _	 g  |  _
 i  |  _ d |  _ d |  _ t j ƒ  |  _ t j ƒ  |  _ g  |  _ t ƒ  |  _ t ƒ  |  _ g  |  _ t ƒ  |  _ g  |  _ d |  _ i  |  _ t |  _ d |  _ d S(   s  
    process MTRIX, BOIMT and PHIL parameters and produce an object
    with information for NCS refinement

    Argument:
    transform_info:  an object produced from the PDB MTRIX or BIOMT records
    ncs_refinement_params: an object produced by the PHIL parameters
    i   t    N(   t   Nonet   total_asu_lengtht   ncs_to_asu_mapt   asu_to_ncs_mapt   ncs_to_asu_selectiont   ncs_copies_chains_namest   tr_id_to_selectiont   number_of_ncs_groupst   ncs_group_mapt   ncs_transformt   transform_chain_assignmentt   transform_to_ncst   ncs_atom_selectiont   ncs_selection_strR   t   size_tt   non_ncs_region_selectiont   all_master_ncs_selectionst   ncs_chain_selectiont   tuplet   model_unique_chains_idst   sett   selection_idst   model_order_chain_idst   transform_to_be_usedt   transform_ordert	   hierarchyt   common_res_dictt   Falset   found_ncs_transformst   messages(   t   self(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyt   __init__'   s2    																				R   g{®Gáz”?gš™™™™™É?i
   c         C   s  d } | r% t  j j | ƒ d } n  | rX d } t | t j j j ƒ s… t | ƒ ‚ n- | r… | j	 ƒ  } t j j j
 | | ƒ } n  | j ƒ  d# k r¯ t j j d | ƒ } n@ | rï | sÂ | rï | rÑ | } n | } t j j d	 | ƒ } n  | r;| r;| j j d
 d ƒ } | j ƒ  d k r,d" } q;t | ƒ } n  | sG| rÜt | ƒ sY| r~|  j d | d | d | d | ƒ q·| | g j t ƒ d k sŸt ‚ |  j d | d | d | d | d | d | d | d | ƒ nÛ | sè| r|  j d | d | d | d | ƒ nª | j ƒ  d k s1|
 s1| s1| rh|  j d | d |	 d |
 d | d | d | d | ƒ nO | r«|  j d | d | d | d | d | d | d | d | ƒ n t d  ƒ ‚ t |  j ƒ d k |  _ | r|  j d k rót d! ƒ ‚ n  |  j d k rt |  j ƒ ‚ qn  d" S($   s  
    Select method to build ncs_group_object

    order of implementation:
    1) rotations,translations
    2) transform_info
    3) ncs_selection_params
    4) ncs_phil_groups
    5) spec file
    6) iotbx.pdb.hierarchy.input object

    Args:
    -----
      pdb_hierarchy_inp: iotbx.pdb.hierarchy.input
      transform_info: object containing MTRIX or BIOMT transformation info
      rotations: matrix.sqr 3x3 object
      translations: matrix.col 3x1 object
      ncs_selection_params: Phil parameters
        Phil structure
           ncs_group (multiple)
           {
             master_selection = ''
             copy_selection = ''   (multiple)
           }
      ncs_phil_groups: a list of ncs_groups_container object, containing
        master NCS selection and a list of NCS copies selection
      file_name: (str) .ncs_spec or .mmcif  or .pdb file name
      file_path: (str)
      spec_file_str: (str) spec format data
      spec_source_info:
      quiet: (bool) When True -> quiet output when processing files
      spec_ncs_groups: ncs_groups object as produced by simple_ncs_from_pdb
      cif_string: (str) string of cif type data
      use_cctbx_find_ncs_tools: (bool) Enable using of chain base NCS search
      use_simple_ncs_from_pdb: (bool) Enable using use_simple_ncs_from_pdb
      use_minimal_master_ncs: (bool) use maximal or minimal common chains
        in master ncs groups
      rms_eps (float): limit of rms difference between chains to be considered
        as copies
      error_msg_on (bool): When True, raise error if chains that are
        nearly the same length (but not exactly the same) and are NCS related.
        Raise error if NCS relations are not found
      process_similar_chains (bool): When True, process chains that are close
        in length without raising errors
      min_fraction_domain (float): Threshold for similarity between chains
        similarity define as:
        (number of matching res) / (number of res in longer chain)
      min_contig_length (int): minimum length of matching chain segments
    R   i   s:   pdb_hierarchy_inp is not iotbx.pdb.hierarchy.input object
s   .pdbs   .cifs   .mmcifs   .gzt	   file_namet
   pdb_stringt   epsg{®Gáz„?t   pdb_hierarchy_inpt	   rotationst   translationst   transform_infoi    t   use_cctbx_find_ncs_toolst   use_simple_ncs_from_pdbt   use_minimal_master_ncst   process_similar_chainst   min_fraction_domaint   min_contig_lengtht   rms_epst   ncs_selection_paramst   ncs_phil_groupss	   .ncs_spect	   file_patht   file_strt   source_infot   spec_ncs_groupst   quiets)   Please provide one of the supported inputs   No NCS relation were found !!!N(   s   .pdbs   .cifs   .mmcifs   .gz(   t   ost   patht   splitextt
   isinstancet   iotbxR   R'   t   inputt   AssertionErrort   construct_hierarchyt   input_hierarchy_pairt   lowert   process_mtrix_recordst   as_pdb_stringR   t$   insure_identity_is_in_transform_infot   ncs_onlyt   build_ncs_obj_from_pdb_ncst   countt   Truet   build_ncs_obj_from_pdb_asut   build_ncs_obj_from_philt   build_ncs_obj_from_spec_fileR   t   lenR%   R*   R+   (   R,   R1   t   pdb_inpR4   R2   R3   R<   R=   R.   R>   t   spec_file_strt   spec_source_infot
   cif_stringRB   RA   R/   R5   R6   R7   R;   t   error_msg_onR8   R9   R:   t	   extensiont   msgt   pht	   input_str(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyt   preprocess_ncs_obj[   sŽ    I ' 	 		
!	
	
	
	
c   	      C   s  |  j  d | ƒ d } t | p( | o( | ƒ s: t | ƒ ‚ | rY |  j d | d | ƒ n |  j d | ƒ t |  j ƒ |  _ |  j d |  j d |  j	 ƒ |  _
 xi |  j D]^ } d |  j
 | } | j d	 ƒ d
 } | | f |  j | <t d |  j d | d | ƒ |  _ q¦ W|  j d | ƒ d S(   sg  
    Build transforms objects and NCS <-> ASU mapping using PDB file containing
    a single NCS copy and MTRIX  or BIOMT records

    Args:
      pdb_hierarchy_inp : iotbx.pdb.hierarchy.input
      transform_info : an object containing MTRIX or BIOMT transformation info
      rotations : matrix.sqr 3x3 object
      translations : matrix.col 3x1 object
    R1   s   No NCS transform information
R2   R3   R4   t   transform_assignmentt   unique_chain_namess   chain t   _i    t   dt   kt   vN(   t   collect_basic_info_from_pdbt   boolRI   t'   add_transforms_to_ncs_refinement_groupst   process_pdbt   get_transform_orderR   R   t   make_chains_namesR!   R   t   splitR   t   add_to_dictR   t   finalize_pre_process(	   R,   R1   R4   R2   R3   R^   Rf   t   selection_strt   key(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyRQ   î   s&    $	
		c         C   s‹  | rt t  | t ƒ r$ t | ƒ } n  t j d | d t ƒ } | d j ƒ  } | d g  k sh t d ƒ ‚ | j } n | d$ k	 s† t ‚ |  j
 d k s› t ‚ t ƒ  } d }	 d }
 xY| D]Q} | j } |  j j | ƒ t | | ƒ } t d | d | ƒ } |
 d 7}
 |	 d 7}	 |  j d	 | d
 |
 d |	 ƒ t |	 ƒ } |  j d | d | d | ƒ |  j | | | ƒ g  } x„| j D]y} t | | ƒ } t d | d | ƒ } t d | d | d d d | d | ƒ \ } } } } |  j | 7_ | j ƒ  röd } n  | j | ƒ |	 d 7}	 t |	 ƒ } |  j | | | ƒ t d | d | d |	 d t d
 |
 d | ƒ } |  j d | d | d | ƒ t d |  j d
 |
 d | d | ƒ |  _ |  j j | ƒ sµt ‚ | |  j | <|  j j  | ƒ |  j d | d | d | ƒ quW| |  j! | <|
 |  _" q· Wd  |  j d d! |  _
 x> t# d t$ |  j ƒ ƒ D]$ } |  j
 d" |  j | d! 7_
 q=Wt% |  j& ƒ |  _' |  j( d# | ƒ d$ S(%   s/  
    Build transforms objects and NCS <-> ASU mapping using phil selection
    strings and complete ASU

    Args:
      ncs_selection_params : Phil parameters
      pdb_hierarchy_inp : iotbx.pdb.hierarchy.input
      process_similar_chains (bool): When True, process chains that are close
        in length without raising errors
      min_fraction_domain (float): similarity between chains when looking for
        ncs relations

    Phil structure
    ncs_group (multiple)
    {
      master_selection = ''
      copy_selection = ''   (multiple)
    }
    t   sourcet   track_unused_definitionsi    i   s   Check phil parameters...
R   R_   Rq   t   ncs_selectiont   ncs_group_idt   transform_snt   masterst   copiest   tr_idt   master_ncs_pht   ncs_copy_phR;   id   R8   R9   s=   Master NCS and Copy are very poorly related, check selection.t   rotationt   translationt
   serial_numt   coordinates_presentt   rmsdt   transform_idt	   transformt   selection_idR   R#   t   (t   )s    or (R1   N()   RF   t   strR   t   master_philt   fetchRS   t   extractRI   t	   ncs_groupR   R   R"   t   master_selectionR   t   appendt   uniqueness_testt   get_pdb_selectiont   add_identity_transformt   format_num_as_strt   update_ncs_copies_chains_namest   update_tr_id_to_selectiont   copy_selectiont   get_rot_transR+   t   is_zeroRƒ   t   build_transform_dictt   update_ncs_group_mapR   R   t   has_keyR#   t   addR   R   t   rangeRW   Rl   R   R   Rp   (   R,   R<   R=   R1   R8   R9   t
   phil_paramt   working_philt   unique_selectionsRw   Rv   t   groupt   gnsR{   Rr   t   asu_locationst
   asu_selectR|   t   rt   tR�   R^   t   err_mt   trt   i(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyRU     s�    			

			
				"g      à?c	         C   s±   | r^ t  j d | j d | d | d | d | ƒ }	 | j j ƒ  j ƒ  |  _ |  j |	 | ƒ nO | r­ t d | j d | j ƒ }
 |
 r­ |
 j	 ƒ  } |  j
 d | d	 | ƒ q­ n  d
 S(   s½  
    Build transforms objects and NCS <-> ASU mapping from a complete ASU
    Note that the MTRIX record are ignored, they are produced in the
    process of identifying the master NCS

    Args::
      pdb_hierarchy_inp : iotbx.pdb.hierarchy.input
      use_cctbx_find_ncs_tools (bool): Enable using of chain base NCS search
      use_simple_ncs_from_pdb (bool): Enable using use_simple_ncs_from_pdb
      use_minimal_master_ncs (bool): indicate if using maximal or minimal NCS
        groups
      rms_eps (float): limit of rms difference between chains to be considered
        as copies
      process_similar_chains (bool): When True, process chains that are close
      in length without raising errors
      min_contig_length (int): minimum length of matching chain segments
      min_fraction_domain (float): Threshold for similarity between chains
        similarity define as:
        (number of matching res) / (number of res in longer chain)
    R_   R:   R9   R7   t   rmsd_epsRX   R'   R1   RA   N(   R   t   find_ncs_in_hierarchyR'   t   atomst   sizeR   t   build_ncs_obj_from_group_dictR   RH   t
   ncs_groupsRV   (   R,   R1   R5   R6   R7   R;   R8   R:   R9   t
   group_dictt
   ncs_objectRA   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyRT   €  s$    					c   "      C   s  | } t  j t g |  j ƒ |  _ t  j t g |  j ƒ } t | ƒ } xt | ƒ D]
\ } } | | } t ƒ  }	 g  | j d D] }
 t	 |
 ƒ D] } | ^ q‘ q� } | j
 ƒ  t  j | ƒ } t | | ƒ } g  |  j | <x€t t | j ƒ ƒ D]i} | j | } t | j ƒ } | |  j | <x¹t t | j | ƒ ƒ D]ž} | j d | } | j d | } t | | ƒ } | j | | } | j | | } t | | ƒ } |	 j | ƒ | } | d | } | |  j | <| |  j | <| | f |  j | <|  j j | ƒ |  j d | d | d | ƒ t d |  j d | d d	 | d
 | ƒ |  _ | d k r…t  j |  j | ƒ } |  j | B|  _ | | B} q:|  j j | j ƒ t d |  j d | d | ƒ |  _ t  j |  j | ƒ } | | B} q:W| d k rñ g  | j | D] }
 t	 |
 ƒ D] } | ^ qqö} | j
 ƒ  t  j | ƒ } t | | ƒ } |  j | j  | ƒ qñ qñ WqT Wt | ƒ |  _! g  } t |  j ƒ }  x# |  D] }! | j  d |! d ƒ q�Wd j" | ƒ |  _# t$ |  j ƒ |  _% |  j j& ƒ  |  _' |  j | B|  _ |  j( d | ƒ d S(   sÄ  
    Use group_dict to build ncs object

    Args:
      pdb_hierarchy_inp : iotbx.pdb.hierarchy.input
      group_dict (dict):
        keys: tuple of master chain IDs
        values: NCS_groups_container objects with Attributes:
          iselections (list of lists of flex.size_t):
            selection array for the
          complete ASU
          residue_index_list (list): list of list of matching residues indices
          copies (list of lists):List of lists of the ncs copies chain IDs
          transforms (list of transform objects):
            object with attributes:
              rotation : Rotation matrix object
              translation: Translation matrix object
              serial_num : (int) Transform serial number
              coordinates_present (bool): True when coordinates are presents
              ncs_group_id (int): group ID of the group containing this transform
              rmsd (float): RMS distance between ncs copies
    i    Rd   Rx   Ry   Rz   R   Rv   i   R#   R‚   Re   Rf   Rg   R…   R†   s    or R1   N()   R   Ri   R)   R   R   t   sortedt	   enumerateR"   t   iselectionst   listt   sortR   t   selection_string_from_selectionR   t   xrangeRW   Ry   t
   transformsR‘   R   R   Rš   R   R   R   R#   R’   R˜   R   R%   Ro   R   R�   R   t   joinR   Rl   R   t
   iselectionR   Rp   ("   R,   R®   R1   R_   t   ncs_related_atomst   sorted_group_keyst   gr_nRr   t   ncs_grR‚   t   ixt   xt
   m_all_listt
   m_all_iselt   all_m_select_strR§   R¦   Rz   t   jt   m_iselt   m_ch_idt   m_select_strt   c_ch_idt   c_iselt   c_select_strt   key1t   key2t
   master_selt   copy_selt
   c_all_listt
   c_all_iselt   ncs_selection_str_listR#   t   sel(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyR¬   ²  s€    
	3
 		
3
c	         C   sd  t  | ƒ r° | s | r° d }	 | d k	 rC t j j | | ƒ }	 n  | j ƒ  }
 |
 g  k ss t j j |	 ƒ ss t ‚ t j ƒ  } | j	 d |	 d |
 d | d | ƒ | j
 ƒ  } n  t | t j ƒ rÑ | j
 ƒ  } n  | r`d } d } xó| D]ë} t | j ƒ  ƒ } | d } | r3|  j | | ƒ } | r3qê q3n  | d 7} |  j j | ƒ g  } xrt | ƒ D]d\ } } | j ƒ  | } | j ƒ  | } t | | ƒ \ } } t | j ƒ  | d ƒ } | d 7} t | ƒ } |  j | | | ƒ t | | ƒ s| j | ƒ n  t d	 | d
 | d | d t d | d | ƒ } |  j d | d | d | ƒ t d |  j d | d | d | ƒ |  _ |  j j  | ƒ s‹t ‚ | |  j | <|  j! j" | ƒ |  j# d | d | d | ƒ q`W| |  j$ | <qê W| |  _% d |  j d d |  _& x> t' d t( |  j ƒ ƒ D]$ } |  j& d |  j | d 7_& qWt) |  j* ƒ |  _+ |  j, d | ƒ n  d S(   sv  
    read .spec files and build transforms object and NCS <-> ASU mapping

    Arguments:
    spec file information using a file, file_str (str) of a source_info (str)
    quite: (bool) quite output when True
    pdb_hierarchy_inp: pdb hierarchy input
    spec_ncs_groups: ncs_groups object
    join_same_spec_groups: (bool) True: combine groups with similar transforms
    R   R.   t   linesR@   RB   i    i   i   R}   R~   R   R€   Rv   R�   R‚   Rƒ   R„   R   R#   Rx   Ry   Rz   R…   R†   s    or (R1   N(-   Ri   R   RC   RD   R¸   t
   splitlinest   isfileRI   R	   t   read_ncsR­   RF   t   get_ncs_group_selectiont   chain_residue_idt   look_and_combine_groupsR   R�   R±   t   rota_matricest   translations_ortht   inverse_transformt   roundt	   rmsd_listR‘   R“   t   is_identityRƒ   RS   R—   R˜   R   R   R™   R#   Rš   R’   R   R   R   R›   RW   Rl   R   R   Rp   (   R,   R.   R>   R?   R@   RB   R1   RA   t   join_same_spec_groupst   fnRÒ   t   spec_objectRw   Rv   t   grt   ncs_group_selection_listt   gst   group_existR¡   R§   t   ncs_copy_selectR£   R¤   R�   Rr   R¦   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyRV     s~    $	
 	

					"c         C   sr  | d } t  } | j ƒ  } | j ƒ  } g  t | | ƒ D] \ } } t | | ƒ ^ q8 }	 x/|  j j ƒ  D]\ }
 \ } } t | ƒ t | ƒ k r™ qi n  d	 g t | ƒ } t	 | ƒ } | j
 ƒ  x£ | D]› } |  j | j } |  j | j } xr t |	 ƒ D]d \ } \ } } | | d	 k	 r$qü n  t | | | | ƒ \ } } | oI| } | rü | | | <Pqü qü WqÉ W| j d	 ƒ d k } | ri Pqi qi W| rn|  j j | ƒ g  } xœ | D]” } | | } | | } | d | } |  j d | d | d | ƒ |	 | \ } } t | | ƒ s®t d |  j d | d | ƒ |  _ | j | ƒ q®q®W| |  j | <|  j |
 d j | ƒ n  | S(
   s   
    i    Rd   Rx   Ry   Rz   Re   Rf   Rg   N(   R)   RÙ   RÚ   t   zipRÛ   R   t	   iteritemsRW   R   R³   R´   R   R£   R¤   R±   t   is_same_transformRR   R#   Rš   R’   RÞ   Ro   R   R�   R   (   R,   t   gr_newRã   t   gs_newt   found_same_groupt	   gr_r_listt	   gr_t_listR£   R¤   t   gr_new_listRf   Rä   t   tr_sett   same_transformst   tr_listt   tr_key1t   r1t   t1R§   t   r2t   t2t   samet	   transposet   testR¡   R‚   Ræ   Rr   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyRØ   j  sT    
1" 
 
 

	c         C   s]   t  | ƒ } t  | ƒ } x> t | | ƒ D]- \ } } | j d d ƒ |  j | d | <q( Wd  S(   Ns   chain R   Rd   (   t   get_list_of_chains_selectionRç   t   replaceR   (   R,   Rx   Ry   Rz   t   mt   c(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyR’   š  s    c         C   so   t  | ƒ } t | ƒ } t | ƒ } xD t | | | ƒ D]0 \ } } }	 | d | }
 |	 | f |  j |
 <q7 Wd S(   s©   
    Args:
      masters: (str) selection of master ncs
      copies: (str) selection of copy
      tr_id: (str) string like s_001 where 001 is the transform number
    Rd   N(   Rû   t   separate_selection_stringRç   R   (   R,   Rx   Ry   Rz   t   tr_keyst   master_selection_listt   copies_selection_listRf   Rþ   Rý   Rr   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyR“      s    "c   
      C   s�  t  | ƒ t  | ƒ k s t ‚ |  j s4 t d ƒ ‚ d h } |  j d |  j ƒ d } x$t | | ƒ D]\ } } t | | ƒ sf | d 7} | j | ƒ t | ƒ } t	 d | d | d | d t
 d d ƒ } |  j j | ƒ sä t ‚ | |  j | <xX |  j D]M }	 |  j d	 | d
 | d |	 ƒ |  j j |	 ƒ |	 |	 f |  j |	 d | <qû Wt d |  j d d d |  j d	 | ƒ |  _ qf qf Wd S(   sU   
    Add rotation matrices and translations vectors
    to ncs_refinement_groups
    s   ncs_transform should be empty
i   Ru   R}   R~   R   R€   Rv   R‚   Rƒ   R„   Rd   R   R#   N(   RW   RI   R   R�   R   Rç   RÞ   Rš   R‘   Rƒ   R)   R™   R   R—   R#   R   R˜   R   (
   R,   R2   R3   t   snt   nR£   R¤   Rr   R¦   t   select(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyRj   ®  s<    	
				c         C   s¢  | rž| j  j ƒ  d } d „  | j ƒ  Dƒ } t t | ƒ ƒ |  _ g  | j ƒ  D]! } | j | j ƒ  j ƒ  f ^ qQ } d „  |  j Dƒ } xi | D]a \ } } | | d k rÄ d | f g | | <q’ | | d \ }	 }
 | | j
 |
 |
 | f ƒ q’ Wx= | D]5 \ } } | | j d ƒ } |  j j
 | | f ƒ qþ Wd j |  j ƒ } d | |  _ |  j g  k skt ‚ g  |  j D] } d | ^ qu|  _ |  j j ƒ  n  d S(   su   
    Build chain selection string and collect chains IDs from pdb
    Consider that chains can be not continuous
    i    c         S   s   h  |  ] } | j  ’ q S(    (   t   id(   t   .0R¿   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pys	   <setcomp>Ú  s   	 c         S   s   i  |  ] } d  | “ q S(   N(   R   (   R  R¿   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pys
   <dictcomp>Þ  s   	 iÿÿÿÿs
    or chain s   chain N(   R'   t   modelst   chainsR    R°   R!   R  Rª   R«   R   R�   t   popR$   R¸   R   R   RI   R´   (   R,   R1   t   modelt	   chain_idsR¿   t   model_order_ch_idst
   ch_n_atomst   chR  Rd   t   last_nt   selection_ranget   s(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyRh   Ó  s&    4#c         C   sJ  t  |  j ƒ } t  |  j ƒ } t  |  j ƒ } | rF| rF| rF| j j ƒ  } t | j j ƒ  ƒ } | j |  j	 ƒ |  _ |  j j
 t ƒ } i  } | | k rì| |  _ t j  t g | ƒ }	 xÅ |  j D]º }
 |
 j d ƒ d } | j | ƒ } |  j j | ƒ s,d | | <|	 | B}	 | j ƒ  |  j | <n | | c d 7<|  j | | | } | j | ƒ } t |	 | ƒ }	 | j ƒ  |  j |
 <qÈ W|	 j ƒ  |  _ |  j j ƒ  |  _ |  j |	 B|  _ t |  j ƒ j t |  j ƒ ƒ t ƒ  k sCt ‚ qF| | k rF|  j | ƒ |  _ t g | t g |  j | } t j  | ƒ |  _ |  j j ƒ  |  _ t |  j ƒ } xä t | ƒ D]Ó \ } }
 |  j |
 } x· | D]¯ } | j d ƒ d } | j | ƒ } t j  |  j | j | ƒ ƒ } |  j j | ƒ s÷| j ƒ  |  j | <n  |  j | | d | } t j  |  j | ƒ } | j ƒ  |  j | <q‰WqiWqFn  d S(   sA    Calculates coordinates maps from ncs to asu and from asu to ncs Rd   i    i   N(   Ri   R   R   R   R'   t   atom_selection_cacheRW   Rª   t	   selectionR   RR   RS   R   R   R)   R   Rn   R™   R¹   R   t   update_selection_refR   R   R"   t   intersectionRI   t   get_asu_lengthR°   R   R±   (   R,   R1   Rõ   R÷   t   t3t   tempt
   pdb_lengtht
   ncs_lengtht
   copy_countt   selection_refRf   Rr   Ru   t   asu_copy_reft   asu_selectiont   nst   sorted_keysR§   Rg   t   transform_keyt   ncs_basic_selectiont   temp_iselection(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyt   compute_ncs_asu_coordinates_mapï  s\    	

$i   c         C   sÍ   t  d t j d d d d d d d d d g	 ƒ d t j d d d g ƒ d | d t d | ƒ } t | ƒ } | |  j | <|  j d | d	 | d
 | ƒ |  j j	 | ƒ t
 d |  j d | d | d | ƒ |  _ d S(   sÒ       Add identity transform
    Argument:

    ncs_selection: (str) selection string for the NCS master copy
    ncs_group_id: (int) the NCS group ID
    transform_sn: (int) Over all transform serial number
    R}   i   i    R~   R   R€   Rv   R‚   Rƒ   R„   R   R#   N(   Rƒ   R
   t   sqrt   colRS   R‘   R   R—   R#   Rš   R˜   R   (   R,   Ru   Rv   Rw   t   transform_objt   id_str(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyR�   *  s$    *			c         C   s5  t  | ƒ o t  | j ƒ } | r1| } xt | j | j | j | j ƒ D]á \ } } } } t | ƒ } t | ƒ } t d | d | d | d | d d ƒ }	 x= |  j	 D]2 }
 |  j
 d | d |	 d	 |
 ƒ |  j j |
 ƒ q¤ Wt d
 |  j d d d |  j	 d | ƒ |  _ |  j j | ƒ st ‚ |	 |  j | <qI Wn  d S(   sx  
    Process PDB Hierarchy object
    Args:
      transform_info

    Remarks:
    The information on a chain in a PDB file does not have to be continuous.
    Every time the chain name changes in the pdb file, a new chain is added
    to the model, even if the chain ID already exist. so there model.
    chains() might contain several chains that have the same chain ID
    R}   R~   R   R€   Rv   i   R‚   Rƒ   R„   R   R#   N(   Ri   R£   Rç   R¤   t   serial_numberR€   t   intR‘   Rƒ   R   R—   R#   Rš   R˜   R   R   R™   RI   (   R,   R4   t   transform_info_availablet   tiR£   R¤   R  t   cpRr   R¦   R  (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyRk   E  s2    4				c         C   sg   t  | j | j ƒ sc |  j j | j ƒ | d t | j ƒ } t d |  j d | d | ƒ |  _ n  d S(   s‘  
    Apply all non-identity transforms
    Build transform_to_ncs dictionary, which provides the location of the
    particular chains or selections in the NCS (example key: "s002")
    and updates transform_to_be_used set

    Args:
      transform_id (str): s001,s002...
      transform : transform object, containing information on transformation
      selection_id (str): NCS selection string
    Rd   Re   Rf   Rg   N(	   RÞ   R£   R¤   R%   Rš   R   R‘   Ro   R   (   R,   R‚   Rƒ   R„   Rr   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyR—   m  s
    c         C   s_   |  j  j t ƒ } xF |  j D]; } | j d ƒ d } | j | ƒ } | | j t ƒ 7} q W| S(   s'   " Collect the length of all ncs copies Rd   i    (   R   RR   RS   R   Rn   R  (   R,   R  t   asu_total_lengthRf   Rr   Ru   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyR  ƒ  s    c   
   
      sÀ   |  j  d k s t ‚ t j j j ƒ  } |  j ‰  t ˆ  d ‡  f d †  ƒ} xn | D]f } |  j | } | j } | j	 } t
 | | ƒ } | p� | }	 | j d | d | d |	 d | j ƒ qR W| S(   sI   
    Build a MTRIX object from ncs_group_object
    Used for testing
    i   Rr   c            s   ˆ  |  j  S(   N(   R   (   Rf   (   t   tr_dict(    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyt   <lambda>”  s    R£   R¤   R€   R*  (   R   RI   RG   R   Rd   t"   _mtrix_and_biomt_records_containerR   R°   R£   R¤   RÞ   Rš   R   (
   R,   RP   t   resultt	   tr_sortedRr   Rƒ   R£   R¤   t   identity_testR.  (    (   R0  sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyt   build_MTRIX_objectŒ  s     				c         C   s4  | s | r i  St  | ƒ } t t t j ƒ t | ƒ ƒ } t t t j ƒ t | ƒ ƒ } | j ƒ  | j ƒ  | | } t  | ƒ | k  rH| t  | ƒ } t t j	 | ƒ ƒ d } t t j ƒ t t j ƒ t t j
 ƒ }	 |	 |  }	 t g  |	 D] }
 |	 D] } |
 | ^ qü qò ƒ } t | t | ƒ ƒ } | j ƒ  | j | ƒ n  t  | ƒ | k s`t ‚ | |  } t | | ƒ } d „  | Dƒ } d „  |  j Dƒ } x‘ |  j j ƒ  D]€ \ } } | d | } t  | ƒ d k sÞt ‚ | j ƒ  } x? | d D]3 } d | k rõ| j d d ƒ | | d | <qõqõWq¬W| S(	   sg  
    Create a dictionary names for the new NCS copies
    keys: (str) chain_name + '_' + serial_num
    values: (str) (one or two chr long)

    Chain names might repeat themselves several times in a pdb file
    We want copies of chains with the same name to still have the
    same name after similar BIOMT/MTRIX transformation

    Arguments:
    transform_assignment : (list) transformation assignment order
    unique_chain_names : (tuple) a set of unique chain names

    Returns:
    new_names : a dictionary. {'A_1': 'G', 'A_2': 'H',....} map a chain
    name and a transform number to a new chain name
    i   c         S   s   i  |  ] \ } } | | “ q S(    (    (   R  R¿   t   y(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pys
   <dictcomp>Ô  s   	 c         S   s   h  |  ] } t  | ƒ ’ q S(    (   R‘   (   R  R¿   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pys	   <setcomp>Ö  s   	 i    s    or s   chain R   Rd   (   RW   R³   R"   t   stringt   ascii_uppercaset   ascii_lowercaseR´   R+  t   matht   sqrtt   digitst   extendRI   Rç   R%   R   Rè   R
  Rü   (   R,   Rb   Rc   t   total_chains_numbert	   chr_list1t	   chr_list2t   new_names_listt   n_namest
   chr_numbert   chr_listR¿   R7  t   extra_namest   dictionary_valuest   zippedlistst   new_names_dictionaryRð   Rf   Rg   t   tr_strt   ch_sel(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyRm   ¢  s>     



0

)c         C   sE   | r/ |  j  d | ƒ | j |  _ |  j ƒ  n  t |  j ƒ |  _ d S(   s@   
    Steps that are common to most method of transform info
    R1   N(   R%  R'   t   set_common_res_dictt   sort_dict_keysR   R&   (   R,   R1   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyRp   à  s
    c         C   s�  t  |  j ƒ } t } |  j j t ƒ |  j j ƒ  j ƒ  k rE t } n  |  j j	 ƒ  } i  } t
 |  j j ƒ  ƒ d k rÀ |  j j ƒ  d j ƒ  } x/ | D]$ } t d | d | j d | ƒ } q• Wn  xÖ| D]Î} |  j | } |  j j | ƒ s| j d ƒ d | j d ƒ d f |  j | <n  |  j | \ }	 }
 | rg| |	 j ƒ  d } | j |	 ƒ j ƒ  } d } nB | | } | j |
 ƒ j ƒ  } |  j | j d ƒ d } | j } g  } xÊ | D]Â } g  } x‹ | j ƒ  D]} } | j ƒ  j ƒ  } | j ƒ  } t | ƒ | k r| j | ƒ qÏd } | d 7} |  j | 7_ |  j rÏt | ƒ ‚ qÏqÏW| r¶| j t | ƒ t  | ƒ g ƒ q¶q¶W| | g | f |  j! | <qÇ Wd	 S(
   s•   
    Build common residues list and related RMSD
    for use when writing spec files list of common residues
    for each chain - transform pair
    i    Re   Rf   Rg   Rd   i   s-   Sequence may contain insertions and can't be s   represented using residue ID. 
N("   RM  R   R)   R   RR   RS   R'   Rª   R«   R  RW   R  R	  Ro   R  R   R™   Rn   R  R¹   R   R�   t   residue_groupst   residt   stript   resseq_as_intR‡   R�   R+   R\   R   t   mint   maxR(   (   R,   R!  t   only_master_ncs_in_hierarchyt   sct   chains_dictR	  t   chainRr   t   ncs_chain_namet   master_sel_strt   ncs_sel_strt   chain_residues_listt   copy_selection_indicesR�   R¦   t
   range_listt   res_idt   rsRO  RÃ   R^   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyRL  ì  sN    '	%0	
	
	&c      	   C   s_  g  } t  |  j ƒ } xC| D];} |  j | } t j ƒ  } xG t t | d ƒ ƒ D]/ } |  j j | ƒ rR | j |  j | ƒ qR qR Wt	 | ƒ } x¶ t t | d ƒ ƒ D]ž } |  j
 j | ƒ r¨ |  j | j }	 |  j | j }
 t j ƒ  } x) |  j
 | D] } | j |  j | ƒ qú Wt d | d |	 d |
 ƒ } | j j | ƒ q¨ q¨ W| j | ƒ q W| S(   s/   
    a list of ncs_restraint_group objects
    i    i   t   copy_iselectiont   rott   tran(   RM  R   R   R   R°   R³   R   R™   R>  t   ncs_restraint_groupR   R   R£   R¤   R   t   ncs_copyRy   R�   (   R,   t   ncs_restraints_group_listt   group_id_listRf   Rg   t   master_iselRr   t   new_nrgR¦   R£   R¤   t   ncs_iselRÑ   t   new_ncs_copy(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyt   get_ncs_restraints_group_list&  s(    c   
      C   s  t  | ƒ t  |  j ƒ k s! t ‚ t |  j ƒ } xå | D]Ý } |  j | } | j d ƒ } x¸ t t | d ƒ ƒ D]  } |  j j | ƒ rp | j	 j d ƒ } | j
 |  j | _
 | j |  j | _ t j ƒ  } x) |  j | D] }	 | j |  j |	 ƒ qÚ W| j | k st ‚ qp qp Wq7 Wd S(   s!  
    Update ncs_group_object rotations and transformations.

    Note that to insure proper assignment the ncs_restraints_group_list
    should be produced using the get_ncs_restraints_group_list method

    Args:
      ncs_restraints_group_list: a list of ncs_restraint_group objects
    i    i   N(   RW   R   RI   RM  R
  R°   R³   R   R™   Ry   R£   R   R¤   R   R   R>  R   R¹   (
   R,   Re  Rf  Rf   Rg   t   nrgR¦   Rd  Ri  RÑ   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyt&   update_using_ncs_restraints_group_listA  s    
!c         C   s§  | r | r t  } t } n  t | ƒ t | ƒ k s< t ‚ | rK t  } n  |  j d | ƒ } d } d } | r{ | j } n  | rI|  j rI| rI|  j } | j ƒ  } t | ƒ } | j	 ƒ  j
 ƒ  } | j ƒ  } | j ƒ  | j ƒ  k rt  } | j |  j j ƒ  ƒ } | j ƒ  } n  | j ƒ  | j ƒ  k s3t ‚ | j	 ƒ  j | ƒ n  | r | } | rj| j ƒ  } n  | j d | ƒ } | s‘t | ƒ } n  | r²| j |  j j ƒ  ƒ } n9 d } t |  j ƒ t | j	 ƒ  ƒ k såt | ƒ ‚ | } | j d d ƒ } n  | r| j ƒ  } n | r*| j ƒ  } n  |	 r‘| rpt | d ƒ } | | IJ| | IJ| | IJ| j ƒ  q‘|
 | IJ|
 | IJ|
 | IJn  d j | | | g ƒ S(   s	  
    Write to a file or prints transformation records.
    with or without PDB atoms and Cryst records.
    If no pdb_hierarchy, xray structure or fmodel are provided, the function
    will return only the MTRIX/BIOMT records

    Args:
      file_name: (str) output file name
      ncs_only: (bool) When False, the comple ASU will be printed (applicable
                only with MTRIX records)
      pdb_hierarchy: (pdb_hierarchy object)
      xrs: (xray structure) for crystal symmetry
      fmodel: (fmodel object)
      crystal_symmetry: crystal symmetry records
      mtrix: (bool) When True -> write MTRIX records
      biomt: (bool) When True -> write BIOMT records
      write: (bool) when False, will will not write to file or print

    Return:
      PDB string
    RP   R   t   crystal_symmetrys3   The complete ASU hierarchy need to be provided !!!
t   ws   
N(   RS   R)   Ri   RI   R6  t   xray_structureR'   t   as_pdb_filet   get_pdb_headerRª   t   extract_xyzt
   sites_cartR«   R  R   R¹   t   set_xyzRn  RN   RW   R   t   format_BOIMT_pdb_stringt   opent   closeR¸   (   R,   R.   RP   t   pdb_hierarchyt   xrst   fmodelRn  t   mtrixt   biomtt   writet   logt   mtrix_objectt   pdb_header_strt
   new_ph_strt   pdb_strt   xyzt   new_xyzR_   t   new_phR^   t   transform_rect   f(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyt   get_transform_records[  sf    	 		-




c	   &      C   s—  t  j  ƒ  }	 | r | j } n  | r: | r: | j ƒ  }
 n | j ƒ  j ƒ  }
 xó|  j j ƒ  D]â\ } } xÓ| d D]Ç} i  } xH t | ƒ D]: } x1 | d D]% } | d | } |  j | | | <q� WqŒ Wt	 | ƒ } g  } g  } g  } g  } g  } g  } g  } xý | D]õ } | | } | j
 | ƒ |  j | \ \ } } } | j
 | ƒ | j
 t |
 | ƒ ƒ | j d ƒ d } |  j | }  | j
 | ƒ t |  j |  j ƒ \ }! }" | j
 |! ƒ | j
 |" ƒ t g  | D] \ }# }$ |$ |# d ^ qÌƒ }% | j
 |% ƒ qW|	 j d | d | d | d | d | | g d	 | d
 d ƒ qs Wq\ W| r“| ra|	 j d | ƒ q“| rz|	 j d | ƒ q“|	 j d | d | ƒ n  |	 S(   sÝ  
    Returns ncs spec object and can prints ncs info in a ncs_spec,
    format_all_for_resolve or format_all_for_phenix_refine format

    Note that while ncs_groups can master ncs can be comprised from several
    chains, the spec groups can not. So groups with multiple chains in the
    master selection are splitted

    Args:
      file_name: (str) output file name
      pdb_hierarchy: (pdb_hierarchy object)
      xrs: (xray structure) for crystal symmetry
      fmodel: (fmodel object)
      write: (bool) when False, will not write to file or print
      format_for_resolve (bool): Select output format when writing
      format_for_phenix_refine (bool): Select output format when writing

    Return:
      spec_object
    i    i   Rd   t   center_ortht   ncs_rota_matrt
   trans_orthRÝ   R×   t   residues_in_common_listt   ncs_domain_pdbR  R.   N(   R	   Rp  Rt  Rª   Rs  R   Rè   Rû   R   RM  R�   R(   t   get_center_orthRn   R   RÛ   R£   R¤   t   sumt   import_ncs_groupR   t   format_all_for_resolvet   format_all_for_phenix_refinet"   format_all_for_group_specification(&   R,   t   pdb_hierarchy_asuRz  R{  R.   R  t   format_for_resolvet   format_for_phenix_refineR~  Rá   R„  t   gnRâ   t	   gr_chainst   gr_dictt   gr_chaint   s_strt   gr_keyR!  RŠ  R2   R3   t   chain_residue_id_listt   chain_residue_range_listRÝ   R�  Rf   t   chain_idR]  t   ncs_selR�   R"  R¦   R£   R¤   R¿   R7  t   res_num(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyt   get_ncs_info_as_spec²  sf    
-		c         C   sÅ   g  } xŒ |  j  j ƒ  D]{ \ } } t | ƒ } | j d ƒ | j d j | ƒ ƒ x0 | D]( } t | ƒ } | j d j | ƒ ƒ qX W| j d ƒ q Wd j | ƒ } | d 7} | rÁ | | IJn  | S(   s;  
    Prints NCS information in the phil parameters format
    lines longer that 80 characters are folded

    Phil structure example:
      ncs_group {
        master_selection = 'chain A'
        copy_selection = 'chain C'
        copy_selection = 'chain E'
      }
      ncs_group {
        master_selection = 'chain B'
        copy_selection = 'chain D'
        copy_selection = 'chain F'
      }

    Args:
      write (bool): when true, print to log
      log : location of output, an open file or sys.stdout

    Returns:
      (str): NCS phil parameter string
    s   ncs_group {s     master_selection = {}s     copy_selection = {}t   }s   
(   R   Rè   t	   format_80R�   t   formatR¸   (   R,   R~  R  t   groupst   masterRy   R.  Râ   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyt   print_ncs_phil_param  s    
c         C   s   |  j  d k s t ‚ | j ƒ  } |  j ƒ  } t d | j ƒ  j ƒ  d | d |  j d t j	 | j ƒ  j
 ƒ  ƒ d | ƒ } | j ƒ  d } g  } xp |  j D]e } x\ |  j D]Q \ }	 \ }
 } d |	 } | d	 | } |  j | |
 | !} | j | | g ƒ q¨ Wq˜ Wx… | D]} \ } } | j | ƒ j ƒ  } t j j j j ƒ  } |  j | | _ x' | j ƒ  D] } | j | j ƒ  ƒ q[W| j | ƒ qW| j ƒ  j | ƒ | S(
   sò   
    Build ASU hierarchy

    Arguments:
    pdb_hierarchy: pdb hierarchy of the master NCS
    round_coordinates: (bool) round coordinates of new NCS copies,
                        for sites_cart constancy
    Return:
    ASU hierarchy
    i   t   ncs_coordinatesRe  R   t   extended_ncs_selectiont   round_coordinatesi    s   chain Rd   (   R   RI   t	   deep_copyRk  R   Rª   Rs  R   R   t   size_t_rangeR«   R  R&   R$   R   R�   R  RG   R   R'   t   extRW  R   R  RN  t   append_residue_groupt   detached_copyt   append_chainRu  (   R,   Ry  R¬  R†  Re  t	   new_sitesR  t   tr_assignment_orderR¦   t   ch_idt	   sel_startt   sel_endRr   t   tr_keyRu   t   new_partt	   new_chaint   res(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyt   build_asu_hierarchy5  s4    		
N("   t   __name__t
   __module__R-   R   RS   R)   Ra   RQ   RU   RT   R¬   RV   RØ   R’   R“   Rj   Rh   R%  R�   Rk   R—   R  R6  Rm   Rp   RL  Rk  Rm  t   syst   stdoutR‰  R£  R©  R¼  (    (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyR   %   s¢   	5~$g+	d	P	0			%		;	(				>	:		PS)c         C   s4   |  j  | ƒ r# |  | j | ƒ n | g |  | <|  S(   N(   R™   R�   (   Re   Rf   Rg   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyRo   `  s    c         C   sT   d } d } xA |  D]9 } | | 7} | d 7} | d k r d } | d 7} q q W| S(   s…   
  Split string that is longer than 80 characters to several lines

  Args:
    s (str)

  Returns:
    ss (str): formatted string
  i    R   i   iP   s    \ 
(    (   R  R§   t   ssR¿   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyR¥  g  s    


c         C   sH  t  |  d ƒ r0 |  j | ƒ } |  j ƒ  j } n$ |  j j | ƒ } |  j j ƒ  j } t | t j ƒ ru | j ƒ  } n  t	 | ƒ } | j
 ƒ  d j ƒ  } g  } xD| D]<} d | j } t	 | | ƒ j ƒ  j ƒ  ƒ }	 |	 j | ƒ |	 k }
 g  } d } d } |
 rÄx¡| j ƒ  D]“} | j ƒ  } | d | } t	 | | ƒ j ƒ  j ƒ  ƒ }	 |	 j | ƒ |	 k } y t | ƒ } Wn t k
 r‹d } n X| r0| d k r| d k r¹| } | } q-| | d k rÖ| d 7} q-t | | ƒ } | j | ƒ | } | } q¢t | | | ƒ \ } } } | j d | ƒ qt | | | ƒ \ } } } d	 | d
 } g  | j ƒ  j ƒ  D] } | ^ ql} d j | ƒ } | j | | d ƒ qWt | | | ƒ \ } } } n  t | | ƒ } | j | ƒ q¤ Wg  } | j ƒ  x> | D]6 } t | ƒ d k r$d | d } n  | j | ƒ qûWd j | ƒ } | S(   sç   
  Convert a selection array to a selection string

  Args:
    pdb_hierarchy_inp : iotbx.pdb.hierarchy.input (or iotbx.pdb.hierarchy)
    selection (flex.bool or flex.size_t)

  Returns:
    sel_str (str): atom selection string
  R  i    s   chain iöÿÿÿs    and resid iÿÿÿÿi   s   resid s   (resid s    and (name s	    or name s   ))i   R…   R†   s    or N(   t   hasattrR  R  R  R'   RF   R   Ri   R¹   R"   R  R	  R  t   as_intR  R   t   residuesRO  R+  t
   ValueErrort   resseq_stringR�   t   update_res_selRª   t   extract_nameR¸   t   get_clean_selection_stringR´   RW   (   R1   R  R_   t
   atom_cahcet   selection_setR	  t   sel_listR  RK  t   a_selt   complete_ch_not_presentt   res_selt   first_nt	   pre_res_nR»  R^  t   test_sel_strt   all_atoms_presentR¢  t   res_seqR  R¿   t	   atom_namet   atom_strt   s_lt   sel_str(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyRµ   |  sp     
		%
c         C   sD   | d k r7 t  | | ƒ } d } d } |  j | ƒ n  |  | | f S(   sE    update the residue selection list and markers of continuous section iöÿÿÿN(   RÆ  R   R�   (   RÏ  t   first_res_nRÑ  RÔ  (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyRÇ  Î  s    gš™™™™™¹?i   c      
   C   sž   t  } d } x… | j ƒ  D]w \ } } t | d ƒ rI | j }	 | j }
 n | d \ }	 }
 t |  | |	 |
 d | d | ƒ\ } } | r | | f Sq W| | f S(   s(  
  Check if the rotation r and translation t exist in the transform dictionary.

  Comparing rotations and the result of applying rotation and translation on
  a test vector

  Args:
    r (matrix.sqr): rotation
    t (matrix.col): translation
    transforms (dict): dictionary of all transforms
    angle_eps (float): allowed difference in similar rotations
    eps (float): allowed difference in the average distance between

  Returns:
    tr_num: (str) transform serial number
    is_transpose: (bool) True if the matching transform is transpose
  R£   i   R0   t	   angle_epsN(   R)   R   Rè   RÂ  R£   R¤   Ré   (   R£   R¤   R·   R0   RÚ  t   is_transposet   tr_numRf   Rg   t   rrt   ttt   is_the_same(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyt   find_same_transformØ  s    	$c         C   s£  |  j  ƒ  r•| j  ƒ  r•|  j d d ƒ s2 t ‚ | j d d ƒ sJ t ‚ t j d d d g ƒ } |  j | | j ƒ  } t |  | ƒ \ } }	 | j | |	 j ƒ  }
 t |  ƒ } t | ƒ } | j | | j ƒ  } | | } | j	 | ƒ d | j
 ƒ  } |
 | } | j	 | ƒ d | j
 ƒ  } t | | ƒ } t | d | ƒ } | | k  rf| | k  rft t f S| | k  rˆ| | k  rˆt t f St t f Sn
 t t f Sd S(   s²   
  Args:
    r1, r2: Rotation matrices
    t1, t2: Translation vectors
    eps, angle_eps: allowed numerical difference

  Returns:
    (bool,bool) (is_the_same, is_transpose)
  t   rms_tolerancegü©ñÒMbP?i   ig   i  g     @Àg       @g      $@g        g     X€@g     ÀYÀg      à?i´   N(   i   ig   i  (   g     @Àg       @g      $@(   g        g     X€@g     ÀYÀ(   R–   t   is_r3_rotation_matrixRI   R   t   vec3_doublet   elemst	   as_doubleRÛ   t   get_rotation_vect   dotR«   t   angle_between_rotationsRR  RS   R)   (   Rô   Rõ   Rö   R÷   R0   RÚ  R„  t   a_reft   rtRÞ  t   a_ref_transposet   v1t   v2t   aRe   t   dtt   angt   d_ang(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyRé   ø  s,    



c         C   s!   |  j  ƒ  }  |  | } |  | f S(   N(   Rù   (   R£   R¤   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyRÛ     s    c         C   s²   |  j  d d ƒ } | j  d d ƒ } | j  d d ƒ d } g  t j d | ƒ D] } | j ƒ  ^ qM } g  | D] } | | | j d | ƒ !^ ql } g  | D] } d | ^ q˜ } | S(   s|   
  Args:
    selection_str: (str) selection string

  Returns:
    (list of str) of the format ['chain X', 'chain Y',...]
  R†   t    t   CHAINRW  t   Chains   chain (   Rü   t   ret   finditert   endt   find(   Rq   t   sstrR¿   t   pos_listR§   t
   ch_id_listt
   chain_list(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyRû   "  s    +,c         C   sï   |  j  d d ƒ |  j  d d ƒ |  j  d d ƒ |  j  d d ƒ |  j  d d ƒ |  d d k r} |  d	 d
 k r} |  d  }  n  |  j d ƒ }  g  } xV |  D]N } | j ƒ  } | j d ƒ rÇ | d  } n  | d k r™ | j d | ƒ q™ q™ W| S(   Ns   Chain s   chain s   CHAIN s
    or chain s   ) or (chain s
   )or(chain iÿÿÿÿR†   i    R…   s    oriýÿÿÿR   (   R   R…   (   Rü   Rn   RP  t   endswithR�   (   R  t   s_listRØ  (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyRÿ   2  s        c         C   sZ   t  j |  j ƒ  ƒ } | j ƒ  } | j ƒ  } t | j d ƒ ƒ j d ƒ } | | | d !S(   Ni   i   i   (   R   t   real_symmetrict   as_sym_mat3t   vectorst   valuesR³   RÜ   t   index(   R£   t   eigent   eigenvectorst   eigenvaluesR§   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyRæ  B  s
    c         C   s<   |  j  | ƒ } t j t d | ƒ ƒ } | d t j 9} | S(   Ni   i´   (   Rç  R;  t   acosRR  t   pi(   Rì  Rí  t	   cos_angleR3  (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyRè  J  s    c         C   sP   |  j  ƒ  }  g  } x. |  D]& } | j d ƒ r2 Pq | j | ƒ q Wd j | ƒ S(   s�   
  Collect CRYST and SCALE records

  Args:
    pdb_str: (str) pdb type string

  Returns:
    the portion of the pdb_str till the first ATOM
  t   ATOMs   
(   RÓ   t
   startswithR�   R¸   (   Rƒ  t   pdb_header_linesR¿   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyRr  Q  s    
 c         C   s   |  j  | ƒ } | j ƒ  S(   s»   
  Args:
    xyz:(flex.vec3_double) the complete asu sites cart (atoms coordinates)
    selection:

  Returns:
    (flex.vec3_double) center of coordinates for the selected coordinates
  (   R  t   mean(   R„  R  R…  (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyR�  b  s    	c         C   sk   |  d k s |  d k  r' t  d ƒ ‚ n@ |  d } |  d d } |  d } t | ƒ t | ƒ t | ƒ Sd S(   s      return a 3 digit string of n  iç  i    s   Input out of the range 0 - 999.id   i
   N(   t   IOErrorR‡   (   R  t   s1t   s2t   s3(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyR‘   n  s    

c         C   sp   t  } |  rk |  } xV t | j | j | j | j ƒ D]0 \ } } } } t | | ƒ s4 | p^ | } q4 q4 Wn  | S(   sÉ   
  Verify that all transforms are not present
  (excluding the identity transform)

  Args:
    transform_info: (transformation object)

  Returns:
    (bool): True if all transforms are not present
  (   R)   Rç   R£   R¤   R*  R€   RÞ   (   R4   t   presentR-  R£   R¤   R  R.  (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyRP   x  s    4c         C   s   |  j  ƒ  o | j ƒ  S(   sD    test if r, rotation matrix is identity, and t, translation is zero (   t   is_r3_identity_matrixt   is_col_zero(   R£   R¤   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyRÞ   ‹  s    c         C   s*   t  } x |  j D] } | o | } q W| S(   s£   
  Check if all transforms coordinates are present,
  if the complete ASU is present

  Args:
    transform_info: (transformation object)

  Returns:
    (bool)
  (   RS   R€   (   R4   Rú   R.  (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyt   all_ncs_copies_present�  s    c         C   s   t  |  d d „  ƒS(   s'    set transformation application order  Rr   c         S   s   t  |  d ƒ S(   Ni   (   R+  (   Rr   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyR1  ¡  s    (   R°   (   R   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyt   order_transformsŸ  s    c         C   s-   | |  k r t  d ‚ n |  j | ƒ |  Sd S(   sÞ   
  When processing phil parameters. Insert new item to set, if not there,
  raise an error if already in set

  Args:
    unique_selection_set: (set)
    new_item: (str)

  Returns:
    unique_selection_set: updated set
  s)   Phil selection strings are not unique !!!N(   R  Rš   (   t   unique_selection_sett   new_item(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyRŽ   £  s    g{®Gáz”?g      è?c      	   C   sd  d } t  j d g d ƒ } t  j d d d g ƒ } d } |  rP| rPt j |  ƒ \ }	 }
 t j | ƒ \ } } g  |
 D] \ } } | ^ qw } g  | D] \ } } | ^ q– } t j d | d | d d d d ƒ \ } } } | d k r÷ | | d d f S|  j ƒ  d j ƒ  d } | j ƒ  d j ƒ  d } t j |  | | | | | ƒ \ } } } } | j	 | ƒ j
 ƒ  j ƒ  } |  j	 | ƒ j
 ƒ  j ƒ  } | j ƒ  d k rût j d	 | d
 | ƒ } | j } | j } | j | j ƒ  ƒ } | | k rû| | d d f Sn  | | k  r7d } | j d d ƒ } | s7t | ƒ ‚ q7n  | | t | d ƒ | f S| | d d f Sd S(   s;  
  Get rotation and translation using superpose.
  Can raise "Sorry" if chains are not exactly the same length, but a large
  subset of them is NCS related. Return the subset of atoms indices used in
  such a case.
  Note that if the master and copy have the same length it will not check
  for similarity.

  Args:
    master_ncs_ph: pdb hierarchy input object
    ncs_copy_ph: pdb hierarchy input object
    process_similar_chains (bool): When True, process chains that are close
      in length without raising errors
    rms_eps (float): limit of rms difference between chains to be considered
      as copies
    min_fraction_domain (float): Threshold for similarity between chains

  Returns:
    r: rotation matrix
    t: translation vector
    rmsd (float): RMSD between master and copy
    msg (str): error messages
  R   i    i	   g        t   seq_at   seq_bR:   R9   t   reference_sitest   other_sitessB   Chains {0} and {1} appear to be NCS related but are dis-similar..
R¨  t   copyi   N(   R
   R&  R'  R   t   get_residue_sequencet   res_alignmentR  R	  t   get_matching_atomsR  Rª   Rs  R«   R   t   least_squares_fitR£   R¤   t   rms_differencet   other_sites_best_fitR¦  R   RÜ   (   R{   R|   R8   R;   R9   R^   t   r_zerot   t_zeroR�   t
   chain_id_mt   res_mt
   chain_id_ct   res_cR¿   R7  t   seq_mt   seq_ct	   res_sel_mt	   res_sel_ct
   similarityt   m_chaint   c_chaint   sel_mt   sel_ct	   ref_sitesR  t   lsq_fit_objR£   R¤   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyR•   µ  sH    	$				c         C   s´   t  j ƒ  } t  j ƒ  } |  rƒ t | ƒ rƒ | j ƒ  j } | d ƒ } | j | ƒ } | } | j ƒ  }  | j ƒ  } | j ƒ  } n$ |  r§ t  j t |  j	 ƒ  ƒ ƒ } n  |  | | f S(   s†  
  Get the atoms to compare. Exclude water and alternative locations

  Args:
    hierarchy: pdb hierarchy input object
    atoms: (flex.vec3_double) master atoms sites cart

  Returns:
     atoms (flex.vec3_double): coordinates of atoms in hierarchy
       (Exclude water and alternative locations)
     selection (flex.size_t): used atoms
     not_selection (flex.size_t): unused atoms
  s    (not resname hoh) and altloc " "(
   R   R   Ri   R  R  R  Rª   R¹   R›   R«   (   Rª   R'   R  t   not_selectiont
   atom_cacheR_   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyt	   get_atomsü  s    c         C   s�   |  d k	 rˆ |  j j ƒ  } | j d ƒ } t j ƒ  } x* | D]" } | j | j | ƒ j ƒ  ƒ q= Wt j t	 | ƒ ƒ } |  j j
 | ƒ Sd Sd S(   sœ   
  Args:
    ph: pdb hierarchy input object
    selection_str (str): selection string

  Returns:
    portion of the hierarchy according to the selection
  s    or N(   R   R'   R  Rn   R   R   R>  R  R¹   R°   R  (   R_   Rq   R  t   selection_str_listt   selection_indicesRØ  R  (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyR�     s    	 c         C   s3   |  | @j  t ƒ d k } | s+ t d ƒ ‚ |  | BS(   s”   
  Test for overlapping selection and then updates the selection_ref
  with the new_selection

  Both received and return arguments are flex.bool
  i    s5   Overlapping atom selection. Check phil parameters...
(   RR   RS   RI   (   R  t   new_selectionRú   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyR  ,  s    c   
      C   sê   |  d } |  d } t  | ƒ t  | ƒ k s2 t ‚ g  } x« t | | ƒ D]š \ } } | j ƒ  } | j d ƒ d k  s� t d ƒ ‚ d | } g  | D] \ } } d j | | ƒ ^ q’ }	 d d j |	 ƒ d	 }	 | j | d
 |	 ƒ qH W| S(   s¢   
  Args:
    chain_residue_id: [[chain id's],[[[residues range]],[[...]]]

  Returns:
    selection lists, with selection string for each ncs copy in the group
  i    i   Rò  s+   Multiple chains in a single spec ncs group
s   chain s   resseq {0}:{1}R…   s    or R†   s    and (   RW   RI   Rç   RP  Rø  R¦  R¸   R�   (
   R×   R	  t
   res_rangesRu   Rþ   RÝ  t   ch_selectionR  t   et	   res_range(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyRÖ   7  s    

!
+c         C   sI   t  |  ƒ } g  } x0 | D]( } x |  | D] } | j | ƒ q* Wq W| S(   s1    order transforms mainly for proper chain naming (   R  R�   (   R   R&   R   Rz   t   tr_selection(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyRl   L  s    c         C   sz   t  | t ƒ r | g } n  |  j | ƒ r] |  | d j t | ƒ ƒ |  | d j | ƒ n t | ƒ | h g |  | <|  S(   s�   
  Update ncs_group_map that maps a group ID to a list:
   [master selection,list of objects containing transforms and copies
   selections]
  i    i   (   RF   R‡   R™   t   updateR"   Rš   (   R   Rv   R#   R‚   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyR˜   U  s     c            s   t  ˆ  d ‡  f d †  ƒS(   NRr   c            s   ˆ  |  S(   N(    (   Rf   (   t   dict(    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyR1  e  s    (   R°   (   RA  (    (   RA  sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyRM  d  s    c         C   s4   | |  k r! d j  |  | ƒ } n d j  |  ƒ } | S(   Ns   resseq {}:{}s	   resseq {}(   R¦  (   t   first_res_numt   previous_res_numRÔ  (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyRÆ  g  s    c         C   sy   | rK t  | ƒ d k r6 |  d d j | ƒ d } qQ |  d | d } n |  } | j d d ƒ } | j d d ƒ } | S(	   sØ   
  Args:
    ch_sel (str): such as 'chain A'
    res_selection (list of str): such as ['resseq 1:10','resid 27c and name CA']

  Returns:
    s (str): such as 'chain A and (resseq 1:10 or (resid 27c and name CA))'
  i   s    and (s    or R†   s    and i    s     Rò  (   RW   R¸   Rü   (   RK  t   res_selectionR  (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyRÉ  n  s    	c         C   sÛ  |  } t  | j | j | j | j ƒ } g  } g  } g  } g  } xº t | ƒ D]¬ \ } \ } }	 }
 } t d | d |	 ƒ rÑ | j | |
 g ƒ | d k rø |
 d k rø | j | ƒ | j |	 ƒ | j | ƒ qø qL | j | ƒ | j |	 ƒ | j | ƒ qL W| d d g g k r|  S| j d t	 j
 d d d d d d d d d g	 ƒ ƒ | j d t	 j d d d g ƒ ƒ | j d t ƒ d } g  t t | ƒ ƒ D] } | j | d ƒ ^ q”} | | _ | | _ | | _ | | _ | S(   sQ  
  Add the identity matrix in cases where the pdb or mmcif files do not
  contain it

  Args:
    transform_info (transformation object): contain rotation, translation,
      serial number and indication if present

  Return:
    transform_info : Add or reorder the transform_info so that the
      identity matrix has serial number 1
  R£   R¤   i    i   s   {0:3d}(   Rç   R£   R¤   R*  R€   R±   RÞ   R�   t   insertR
   R&  R'  RS   R›   RW   R¦  (   R4   R-  t   ti_zipt   identity_snt   t_rt   t_tt   t_cpR§   R£   R¤   R  R.  R  t   t_sn(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyRO   ƒ  s8    !% 4"2				Rd  c           B   s   e  Z d  „  Z RS(   c         C   s   | |  _  | |  _ | |  _ d  S(   N(   R¹   R£   R¤   (   R,   R`  Ra  Rb  (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyR-   ²  s    		(   R½  R¾  R-   (    (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyRd  °  s   Rc  c           B   s   e  Z d  „  Z RS(   c         C   s   | |  _  g  |  _ d  S(   N(   t   master_iselectionRy   (   R,   RL  (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyR-   ¹  s    	(   R½  R¾  R-   (    (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyRc  ·  s   t   ncs_groups_containerc           B   s   e  Z d  „  Z RS(   c         C   s   d |  _  g  |  _ d  S(   NR   (   RŒ   R”   (   R,   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyR-   ¿  s    	(   R½  R¾  R-   (    (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyRM  ½  s   Rƒ   c           B   s#   e  Z d d d d d d  d „ Z RS(   i    c         C   s@   | |  _  | |  _ | |  _ t | ƒ |  _ | |  _ | |  _ d S(   s€  
    Basic transformation properties

    Argument:
    rotation : Rotation matrix object
    translation: Translation matrix object
    serial_num : (int) Transform serial number
    coordinates_present: equals 1 when coordinates are presents in PDB file
    ncs_group_id : (int) ncs groups in, all the selections that the same
                   transforms are being applied to
    N(   R£   R¤   R   Ri   R€   Rv   R�   (   R,   R}   R~   R   R€   Rv   R�   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyR-   Å  s    				N(   R½  R¾  R   R-   (    (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyRƒ   Ã  s   t
   selectionsc           B   sA   e  Z d  Z d d e j ƒ  e j ƒ  e j ƒ  e j ƒ  d „ Z RS(   sN    object for grouping multiple selection information for master ncs and
  copy R   c         C   s:   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ d S(   s  
    Arg:
      master_chain_id (str)
      opy_chain_id (str)
      master_sel (flex.size_t): master selection
      copy_sel (flex.size_t): copy selection
      not_in_master (flex.size_t): atoms in master to exclude
      not_in_copy (flex.size_t): atoms in copy to exclude
    N(   t   master_chain_idt   copy_chain_idRÌ   RÍ   t   not_in_mastert   not_in_copy(   R,   RO  RP  RÌ   RÍ   RQ  RR  (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyR-   â  s    					(   R½  R¾  t   __doc__R   R   R-   (    (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyRN  Þ  s   			(E   t
   __future__R    t   mmtbx.ncs.ncs_from_pdbR   t   mmtbx.ncs.ncs_utilsR   t   scitbx.linalgR   t   scitbx.array_familyR   t   scitbx.mathR   t	   mmtbx.ncsR   t   libtbx.utilsR   t   libtbx.philR   t   iotbx.pdb.hierarchyRG   R	   t   scitbxR
   R   R8  R;  Rõ  RC   R¿  Rˆ   t   objectR   Ro   R¥  Rµ   RÇ  Rà  Ré   RÛ   Rû   Rÿ   Ræ  Rè  Rr  R�  R‘   RP   RÞ   R  R  RŽ   R   R)   R•   R7  R�   R  RÖ   Rl   R˜   RM  RÆ  RÉ  RO   Rd  Rc  RM  Rƒ   RN  (    (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/ncs/ncs_preprocess.pyt   <module>   s€   	ÿ ÿ ÿ ÿ ÿ @			R	
 %								
					C											-