ó
šxTc           @   sû  d  d l  m Z d  d l m Z d  d l Z d  d l m Z d  d l Td  d l Z d  d l	 Z	 d  d l
 Z
 d  d l Z d  d l Z d  d l m Z d  d l m Z d  d l m Z d  d	 l m Z d  d l Z d  d l Z d  d l Z d  d
 l m Z d  d l m Z d  d l m Z d  d l Z d  d l Z d  d l Z d  d l m  Z  d  d l! m" Z" d  d l# Z# d  d l m$ Z$ d  d l% Z% d  d l& m' Z' d  d l( Td  d l) m* Z* d  d l+ Z+ d  d l, Z, d Z- d Z. d Z/ d „  Z0 e j1 d „ Z2 d „  Z3 e	 j4 d „ Z5 d e6 e7 e6 d e7 e8 e8 e6 e j9 d „
 Z: d „  Z; d „  Z< d „  Z= d „  Z> d  „  Z? d! „  Z@ d" „  ZA d# „  ZB d$ „  ZC d% „  ZD d& „  ZE d' „  ZF d( „  ZG d) „  ZH d* „  ZI d+ „  ZJ d, „  ZK d- „  ZL d. „  ZM eN d/ k r÷e2 e j1 ƒ n  d S(0   iÿÿÿÿ(   t   deepcopy(   t   FractionN(   t   rational(   t   *(   t   pdb(   t   mtz(   t   sgtbx(   t   flex(   t	   ensembler(   t	   tbx_utils(   t   amino_acid_codes(   t   phenix_interface(   t   parse(   t   golden_section_search(   t   Sorry(   t   sort_hetatmst   ABCDEFGHIJKLMNOPQRSTUVWXYZt   AltOrigSymMatesFilessø  
For different molecular replacement solutions from the same dataset %s
finds for each chain in the moving solution the copy closest to chains in the fixed solution with
respect to all symmetry operations and alternative origin shifts permitted by the
spacegroup of the crystal.

Usage:
    %s moving_pdb=pdbfile1 fixed_pdb=pdbfile2

or more generally

    %s input.txt

    where the content of input.txt file is in PHIL format:

%s


The PHIL input specifies the MR solution files either as "moving_pdb" and
"fixed_pdb" or as the scopes, "moving" and "fixed". Both of the scopes
"moving" and "fixed" must be valid. These two scopes hold the parameter
"xyzfname" and the scopes "mrsolution" and "pickle_solution". An MR solution
is specified by following only one of the procedures a, b and c:

    (a) Assign the "moving_pdb" or "fixed_pdb" parameter to the pdb file from one
    of the MR solutions in question. This is useful for simple cases such as when
    the solution comes from the PHENIX AutoMR GUI is or when it is from a different
    MR program other than Phaser.

    (b) Specify a Phaser MR solution by assigning the file name of the solution
    file to the "moving.mrsolution.solfname" or "fixed.mrsolution.solfname"
    parameter as well as assigning the IDs of the ensembles and the corresponding
    MR models to the parameters "moving.mrsolution.ensembles.name" or
    "fixed.mrsolution.ensembles.name" and "moving.mrsolution.ensembles.xyzfname"
    or "fixed.mrsolution.ensembles.xyzfname" respectively. Multiple components
    are specified as multiple ensembles. This way of specifying solutions is useful
    for solution files produced when Phaser is run from the command line.

    (c) Use a solution from the PhaserMR GUI in PHENIX. In that case the parameter
    "moving.pickle_solution.pklfname" or "fixed.pickle_solution.pklfname" is assigned
    to the solution file that is produced by PHENIX after an MR calculation. The
    "moving.pickle_solution.philfname" or "fixed.pickle_solution.philfname" is then
    assigned to the input file for the MR calculation. This way of specifying
    solutions is useful when MR solutions are available from having run Phaser
    through the PHENIX interface.

There is no restriction on what method to use for the fixed scope depending on
the method used on the moving scope, and vice versa. If space group and the unit
cell dimensions is not available when for instance (b) is used for both the moving
and the fixed scopes then these need to be specified by assigning the parameter,
"spacegroupfname", to a PDB file with a CRYST1 record or to an MTZ file with that
information. Typically this would be the data file used for the molecular replacement
calculation.

Output:
    The closest match between chains in the moving section to chains in the fixed
    section is saved with the name of the reference_pdb,
    concatenated with the name of the moving_pdb but prepended with "MinMLAD_".
    A log file with the name of the reference_pdb, concatenated with the name of the
    moving_pdb but prepended with "AltOrigSymMLAD_" contains all screen output.
    All files are saved in the folder containing reference_pdb. A good match
    between two chains usually have a MLAD value less than 1.5
    whereas a bad match usually have a value larger than 2. This is a rule of thumb
    and exceptions do occur.

If a Phaser MR solution or a pickle solution is supplied, %s
iterates through each solution and does the respective translation and rotation of
model_pdb as to realize each MR solution as a temporary pdb file. These are in turn
used as moving or as fixed pdb files.

For poor homologues or MR solutions try using "use_all_SSM=True".

Algorithm:
    %s computes configurations by looping over all
    symmetry operations and alternative origin shifts. These are computed using
    procedures outlined in R. W. Grosse-Kunstleve, Acta Cryst. 1999, A55, 383-395.
    An alignment between C-alpha atoms from moving_pdb and reference_pdb is
    computed using SSM (E. Krissinel* and K. Henrick, Acta Cryst. 2004. D60, 2256-2268).
    If SSM fails or if the MLAD score achieved with the SSM alignment  is larger
    than 2.0 then a sequence alignment algorithm in the CCTBX is used instead.
    To estimate the best match a distance measure between the aligned atoms is
    computed for each configuration. The mean log absolute deviation (MLAD) is
    defined as:

      MLAD(dR) = Sum( log(dr*dr/(|dr| + 0.9) + max(0.9, min(dr*dr,1)))),

    where dr is the difference vector between a pair of aligned C-alpha atoms and the sum
    is taken over all atom pairs in the alignment. MLAD is used as the distance measure.
    MLAD will downplay the contributions of spatially distant C-alpha atom pairs which
    may otherwise lead to incorrect matches when the space group has a floating origin
    and the chains tested against one another consists of large unaligned domains.

    %s will for each chain in reference_pdb find the
    smallest MLAD with a copy of each chain in moving_pdb for a given symmetry
    operation and alternative origin. When all chains in reference_pdb have been
    tested these copies will be saved to a file. A warning is issued if not all
    saved copies of chains in moving_pdb have the same origin.

    For spacegroups with floating origin the minimum MLAD is found
    by doing a Golden Sectioning minimization along the polar axis for each copy
    of chains in moving_pdb.

Debug mode:
    Invoking the debug flag produces individual pdb files of the C-alpha atoms used for
    each SSM alignment of moving_pdb for each permitted symmetry operation and alternative
    origin. A gold atom is placed at the centroid of the C-alpha atoms. Similar files are
    produced for the reference_pdb. These files are stored in a subfolder named
    "AltOrigSymMatesFiles".

    If a floating origin is present in the space group a table of MLAD values is produced by
    sliding a copy of moving_pdb along the polar axis in the fractional interval [-0.5, 0.5]
    for each permitted symmetry operation and alternative origin.

    c         C   s"   t  |  |  |  | |  |  |  f GHd  S(   N(   t   helpstr(   t   prognamet   mphilstr(    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/AlterOriginSymmate.pyt   usage¥   s    c   8      C   sp  |  j  | ƒ j } t j d |  j ƒ } g  } d } t | ƒ d k rSx | D] } | j d | ƒ qL W| j ƒ  } | j ƒ  j	 } | j
 ƒ  } | j }	 |	 r¤ | GHn  t }
 | j r¼ t }
 n  | j } t } | j rÝ t } n  | j } | j } d } | r#t j j t ƒ t k r#t j t ƒ n  | j | j | j g } d  g } d  } x@t | ƒ D]2\ } } | d  k r´| d k  r´t j d | ƒ } | j ƒ  | d <| d d  k r´Pq´n  | d  k rW| d k rWy) t  j! | ƒ } | j" ƒ  d j ƒ  } Wn„ t# k
 r{} y: t j d | ƒ } | j ƒ  } t$ | ƒ t% k s@t& ‚ Wq|t# k
 rw} d | } | | d	 7} t' | ‚ q|Xn X| | d <qWqWWt( | j) j* j+ | j) j* j, | j) j- j. | j) j- j/ | j | ƒ \ } } } } t( | j0 j* j+ | j0 j* j, | j0 j- j. | j0 j- j/ | j | ƒ \ } } } } | j g } t | ƒ d k rct1 | | d | d
 ƒ } n  | j g }  t | ƒ d k r�t1 | | d | d ƒ }  n  t2 t | ƒ ƒ }! t2 t |  ƒ ƒ }" d  }# d  }$ d }% d d g }& d }' d }( d }) d }* | d	 7} x|! D]\ } }+ x|" D]û \ }, }- d | |, f } | d t3 |+ ƒ d t3 |- ƒ 7} | | d	 7} t4 |- |+ | | | | d | d |
 d |	 d | ƒ\ }. }/ } | | 7} | j5 |/ ƒ xY |. D]Q \ }0 }1 }2 }3 }4 }5 |% |0 k rÁ|0 }% | }' |, }( |/ }$ |1 }) |2 }* |. }# qÁqÁWqWqW| d	 7} t |! ƒ d k sLt |" ƒ d k rªd GHxI |# D]A \ }0 }1 }2 }3 }4 }5 d |0 |1 |$ |( |2 |+ |' f } | | 7} qXW| d	 7} n  | d 7} t j j6 t j7 ƒ  d | | f ƒ }6 t8 |6 d ƒ }7 |7 j9 | j: d ƒ ƒ |7 j; ƒ  | GHd |6 GH|  d  g k s4| d  g k rlt< |  j= | j j
 ƒ  ƒ qln t< |  j= | j j
 ƒ  ƒ | S(   Nt   master_philt    i    t   accumulatorg       @i   t	   file_names8   %s is not an MTZ file or a PDB file with a CRYST1 records   
t   fix_t   mov_gŠIl;‚u°Ts7   
Testing %d. fixed solution against %d. moving solutions   
fixed_pdb = s   
moving_pdb = t   mediocre_mladt
   usebestSSMt   verboset   movehetatmsi   t    sZ   
Found best MLAD = %f for chain %s in %s of solution %d with chain %s in %s of solution %dsê   
A good match between two chains usually have a MLAD << 1.5
whereas a poor match usually have a MLAD > 2.
The alternate origin for superpositions of solutions with more chains
should be the same for all chain pairs with a good match.
s   AltOrigSymMLAD_%s_%s.logt   wbs   utf-8s   Logfile written to %s(>   t
   parse_argst   philsR	   t   PhilAccumulatorR   t   lent   processt   merget   extractt   AltOrigSymMatest   as_strR   t   Truet   use_all_SSMt   Falset   chosenorigint   no_symmetry_operationsR   t   debugt   ost   patht   existst   debugfoldert   mkdirt	   fixed_pdbt
   moving_pdbt   spacegroupfnamet   Nonet	   enumerateR   t   inputt   crystal_symmetryR   t   objectt   crystalst	   Exceptiont   typet   NoneTypet   AssertionErrorR   t   GetSolutionsAsPdbst   fixedt   pickle_solutiont	   philfnamet   pklfnamet
   mrsolutiont   solfnamet	   ensemblest   movingt   RealizePhaserSolutionst   listt   strt   GetAltOrigSymmatest   appendt   joint   getcwdt   opent   writet   encodet   closeR   t   prog(8   t   parsert   argst   philargst   accumt   output_file_namest   logstrt   argumentt   merged_philt   paramsR   R   R.   t	   usesymmopR   R0   R   t   xtaldimensionsourcest   pxtalsymt   xtalsymt   it   et   xtalt   mtzobjt   mt   outstrt
   fixsoltxtst   fixensmblspdbst   fixlogfnamet
   movsoltxtst   movensmblspdbst   movlogfnamet   fixpdbst   movpdbst   enumfixpdbst   enummovpdbst   minAllAltOrigPdbFnamest   minoutput_filet
   minsolmladt   minbestsolst   minit   minjt   minmovchainidt   minfixchainidt   fixpdbt   jt   movpdbt   AllAltOrigPdbFnamest   output_filet   mladt
   movchainidt
   fixchainidt   dummy1t   dummy2t   dummy3t   fnamet   logfile(    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/AlterOriginSymmate.pyt   RunFromCommandline©   sÞ    									
''
"	

$%
	c         C   sè  |  } | } g  } | }	 | }
 g  } | d  k	 rR t j j | ƒ j d ƒ d } n  |	 d  k r� |
 d  k r� | d  k s‚ | d  k r� t |	 d ƒ j ƒ  g } n  | d  k r| d  k r|	 d  k r|
 d  k rt | d ƒ j ƒ  } t | ƒ } t j	 ƒ  j
 d | g ƒ } | j ƒ  } | d d  k r]| j j } t j | ƒ } | j ƒ  d j ƒ  | d <n  xT | j j D]F } g  } x! | j D] } | j | j ƒ q€W| j | j | f ƒ qjWt j t | d ƒ ƒ } t j j | ƒ j d ƒ d } | j ƒ  } g  | j ƒ  D] } | j ƒ  ^ q} n  |	 d  k rØ|
 d  k rØ| d  k sO| d  k rØt j j t |	 ƒ ƒ } t j j |	 ƒ j d ƒ d } g  | j ƒ  D] } | j ƒ  ^ q“} x* | D] } | j | j  | j! f ƒ q²Wn  | | | | f S(   Nt   .i    t   rt   sourcest   rb("   R9   R1   R2   t   basenamet   splitRS   t   readR   R   R   t   fetchR(   t   phasert   hklinR   R=   R>   R<   t   ensemblet   coordinatesRP   R   t   model_idt   picklet   loadt   get_phaser_objectt	   getDotSolt   unparset   test_phaser_parserst   SolutionFileParsert   filet   get_dot_solt   namet   xyzfname(   RF   t   picklefnamet
   mrsolfnameRJ   R¢   Rc   t   philfilet   pklfilet   soltxtsRI   t   pdbfnamet   ensmblspdbst   halflogfnamet   mstrt	   user_philt   working_philt
   philsxtrctt   philmtzRh   t   enst   pdbst   coordt   pklt   resultt   st   mrparsert   sol(    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/AlterOriginSymmate.pyRC   <  sF    "00(0% c      
   C   sÿ  g  } t  |  ƒ t k sE t  | ƒ t k sE t | t j j ƒ t k rN t ‚ n  xªt |  ƒ D]œ\ } } g  } xË| D]Ã}	 |	 d }
 x°|	 d D]¤} | j	 d t
 j j ƒ } t j d | ƒ } t j d | t j ƒ } t j d |
 | t j ƒ } x=| D]5} t j d | t j ƒ d } t j d | t j ƒ d } t j j j t | d ƒ t | d ƒ t | d	 ƒ ƒ } t | d ƒ t | d ƒ t | d	 ƒ f } | j ƒ  j ƒ  } | j ƒ  } | | j ƒ  } | j ƒ  } | j d
 | ƒ } | | } | j | j d | ƒ ƒ | j | j ƒ  ƒ d |
 | f GHqú Wq� Wqt W| j t
 j j  t
 j j! | | d t" | ƒ d ƒ ƒ ƒ t j# j$ | d  ƒ } x7 t | j& ƒ  d j' ƒ  ƒ D] \ } } t( | | _) q§Wt* | d d ƒ } | j+ | j, | ƒ ƒ | j- ƒ  q[ W| S(   Ni    i   s   \R   s)   (SOLU SET.+\n(SOLU SPAC.+\n)*SOLU 6DIM.+)s   SOLU 6DIM\s+ENSE\s+%s (.+)sW   EULER\s+([-+]?[0-9]*\.?[0-9]+)\s+([-+]?[0-9]*\.?[0-9]+)\s+([-+]?[0-9]*\.?[0-9]+)\s+FRACsc   EULER\s+.+\s+FRAC\s+([-+]?[0-9]*\.?[0-9]+)\s+([-+]?[0-9]*\.?[0-9]+)\s+([-+]?[0-9]*\.?[0-9]+)\s+BFACi   t
   sites_cartt
   sites_fracs!   
Realizing MR solution for %s:
%st   sol_s   .pdbiÿÿÿÿt   w(.   R@   t   ListTypet
   isinstancet   cctbxt   crystalt   symmetryR-   R   R:   t   replaceR1   R2   t   sepR   R;   t   ret   findallt	   MULTILINEt   scitbxt   matht   euler_anglest
   zyz_matrixt   floatt   construct_hierarchyt	   deep_copyt   atomst   extract_xyzt	   unit_cellt   fractionalizet   set_xyzt   orthogonalizeRP   t   abspathRQ   RN   t	   hierarchyt
   join_rootsR9   t   modelst   chainst   chainidt   idRS   RT   t   as_pdb_stringRV   (   R§   t   symR©   t   prefixt   wpatht   fnamesRe   t   soltxtt   mrsolhierarchiest
   ensmblpdbst   ensemblenamet   pdbmodelfnamet   pdbmrsolt   solstrst   ensemblesolutionst   ensemblesolutiont   eulerst   fracst   rott   transt   mrsolhiearchyt
   modelatomst   rotatomsitest   ucellt   fracatomsitest
   mrsolsitest   jointhierarchyt   ciRÔ   t   mrsolpdbfile(    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/AlterOriginSymmate.pyRL   p  sJ    $	
		9-
:)t   Anyg       @c   ¯         sr  | r‡ t  j ƒ  } d j | j t j t j d ƒ ƒ } t j j	 |  ƒ d j	 d ƒ d d | d } t
 j d d	 |  d
 | g ƒ n |  } t j j	 |  ƒ d j	 d ƒ d } t j j	 | ƒ d j	 d ƒ d } | d } t j d | ƒ } t j d | ƒ } t j ƒ  } t j ƒ  } | j | ƒ | j ƒ  } | j ƒ  j ƒ  j ƒ  } | j ƒ  ‰ | j ƒ  } | j ƒ  } d } x@ | j ƒ  d j ƒ  D]( } | j ƒ  t k r©q‹n  | d 7} q‹Wd } x@ | j ƒ  d j ƒ  D]( } | j ƒ  t k ròqÔn  | d 7} qÔWd } d | | f } | d | | f 7} | d | | j ƒ  j ƒ  f 7} | | d 7} | | IJ| | k r™d } | d 7} | | d 7} | | IJn  g  }  g  g }! g  }" g  }# x½t | j ƒ  d j ƒ  ƒ D]Ÿ\ }$ }% |% j ƒ  t k rõqÑn  t j j  |% ƒ }& |& j ƒ  d j ƒ  d j! }' |& j" ƒ  }( t# |( ƒ }) |& j$ ƒ  }* |* j" ƒ  }+ ˆ j% d |+ j& ƒ  ƒ }, |+ j' |, ƒ ˆ j% d |( j& ƒ  ƒ }, |, j( ƒ  }- | j) ƒ  }. t* |. ƒ }/ t+ | ƒ d d }0 d d d g d d d g f g }1 | d k rt, | ƒ }1 n
g  | j	 d ƒ D] }2 |2 j- ƒ  ^ q}3 d „  }4 g  |3 D] }5 |4 |5 ƒ ^ q=}6 g  |6 D] }5 t. |5 ƒ ^ q\}7 g  t/ d d ƒ D]0 }8 t |0 |8 ƒ t0 k rª|0 |8 n |7 |8 ^ q„}9 g  t/ d d ƒ D]0 }8 t |0 |8 ƒ t0 k rð|0 |8 n |3 |8 ^ qÊ}: |9 |: f g }1 t* |1 ƒ }; d }< d }= d }> d }? d }@ d  }A x| j ƒ  d j ƒ  D]ö}% |% j ƒ  t k rtqVn  d }B t }C t }D d  }E | r§t2 |% j! | ƒ }F n  t j j  |% ƒ }G |G j ƒ  d j ƒ  d j! }H |G j" ƒ  j& ƒ  }I |G j ƒ  d j ƒ  d |& j ƒ  d j ƒ  d g }J g  }K g  }L z$yÖ t3 j4 d |J d d |J d ƒ }M |M j5 ƒ  }N g  t |N ƒ D] \ }8 }5 |8 |5 d f ^ qg}O t6 |O d d „  d t7 ƒ}L | r¹|L d g }L n  xD |L D]< }P |M j8 |P d ƒ |K j9 t3 j: j; d  |M ƒ j< |P f ƒ qÀWWnG t= k
 rJ}Q d! |' |H f } | | d 7} | | IJt7 }C t7 }D n XWd  t> |J d |J d ƒ }R |K j9 |R d_ f ƒ Xd$ |H | |' | f } | d% |/ |; t* |L ƒ f 7} | | d 7} | | IJxÙt |K ƒ D]Ë\ }S }T |C rÿ|S t* |K ƒ d k rÿPnI |C rH|S t* |K ƒ d k rH|D t k rHd& } | | d 7} | | IJn  d }U d }V |T d }P |P d d }W |P d' }X g  }Y d }Z d }[ d( |X |X f } | | d 7} | | IJ| r	d) | |U | |W f }\ t j j t? |\ ƒ }] d* |W |] f } | | d 7} | | IJt@ |] d+ ƒ }^ n  xe
t |. ƒ D]W
\ }_ }` | t k rP	|_ d k rP	Pn  |` jA ƒ  }a |` jB ƒ  }b d d d g }c t }d t }e t }f xó	t |1 ƒ D]å	\ }g }h t |h d d ƒ t0 k	 rÑ	|h d d |c d <n d |c d <t7 }d t |h d d ƒ t0 k	 r
|h d d |c d <n d |c d <t7 }e t |h d d' ƒ t0 k	 rO
|h d d' |c d' <n d |c d' <t7 }f |G j" ƒ  ‰ ˆ j' |I ƒ ˆ j% d ˆ j& ƒ  ƒ }i |a jC ƒ  |i |b jC ƒ  }j |j |c }k d }l d }m d }n x7 tD |k j( ƒ  |- ƒ d d, k rÿ
|k d` }k |l d 8}l qÉ
Wx7 tD |k j( ƒ  |- ƒ d d- k  r9|k da }k |l d 7}l qWx7 tD |k j( ƒ  |- ƒ d d, k rs|k db }k |m d 8}m q=Wx7 tD |k j( ƒ  |- ƒ d d- k  r­|k dc }k |m d 7}m qwWx7 tD |k j( ƒ  |- ƒ d' d, k rç|k dd }k |n d 8}n q±Wx7 tD |k j( ƒ  |- ƒ d' d- k  r!|k de }k |n d 7}n qëW|l |m |n f }o ˆ j' |k ƒ ˆ j' ˆ jE d. |k ƒ ƒ |T d }p tF jG |p d/ „  | ƒ }q tF jH |q | ƒ ‰  tI ˆ  Œ  }r t# |r d ƒ }s t# |r d ƒ }t ˆ j% |s ƒ }u ˆ j% |t ƒ }v tJ ˆ  ƒ }w tD |u |v ƒ }x d d d g }y d d d g ‰ |d r/|x d |y d <d" ˆ d <n  |e rP|x d |y d <d" ˆ d <n  |f rq|x d' |y d' <d" ˆ d' <n  ˆ jE |y ƒ }z ˆ j' ˆ j& ƒ  tK |z ƒ ƒ d }{ |d sµ|e sµ|f rˆ j& ƒ  ‰ ‡  ‡ ‡ ‡ ‡ f d0 †  }| | rid- }} |} }~ d1 |_ d |g d f g } d2 }€ d" |€ }� x= t/ d |€ ƒ D], }8 |~ |� }~ || |~ ƒ }w | jL |w g ƒ q)W|Y j9 | ƒ n  d3 }{ | s�tM jN || d- d, ƒ }{ ns tO jP ƒ  }‚ tM jN || d- d, d4 |‚ d5 t7 ƒ}{ |‚ jQ ƒ  }ƒ |‚ jR ƒ  d j |ƒ j	 d6 ƒ ƒ } | | 7} | d | IJ|| |{ ƒ }w tS jT |y d |y d |y d |y d |y d' |y d' ƒ }„ d7 |w |{ |„ f }… | r| |… d 7} | |… IJqn  ˆ d |{ |y d ˆ d |{ |y d ˆ d' |{ |y d' g }7 tU jV |c g ƒ tU jV |7 g ƒ }† |` |† tU jV |o g ƒ f }‡ tJ ˆ  ƒ }w |G j$ ƒ  }ˆ | rC|ˆ j ƒ  d j ƒ  d j! tW |V 7_! n  |` jX ƒ  }‰ d8 |h d d |h d d |h d d' f }= d9 |_ d |‰ |g d |= tY |o ƒ |W |P d' |P d |ˆ j ƒ  d j ƒ  d j! f	 }Š d: |_ d |‰ |g d |= tY |o ƒ |W |P d |ˆ j ƒ  d j ƒ  d j! |w f	 }‹ d tY |W ƒ d; tZ |q ƒ }Œ |[ |w k rS|w }[ |‹ }Z n  |B |w k r³|w }B |= }� |Š }< |d sƒ|e sƒ|f r˜|Š d |… d }< n  |ˆ j$ ƒ  }E t[ |‡ ƒ }Ž n  |‹ } | sÅ| rÖ| | d 7} n  | d< | d= I| r–	t# |r d ƒ }� t j j\ ƒ  }� |� j' |� d |� d |� d' f ƒ |� j] d> ƒ d? |� _^ t7 |� __ t` ta |r d ƒ |� g ƒ }‘ d@ | |W |_ d |g d f }\ t j j t? |\ ƒ }’ t@ |’ d+ ƒ }“ |“ jb |‘ jc | ƒ ƒ |“ jR ƒ  |^ jb |ˆ jc | ƒ ƒ |V d 7}V |V dA k r{|^ jR ƒ  |U d 7}U d }V d) | |U | |W f }\ t j j t? |\ ƒ }] dB |W |] f } | | d 7} | | IJt@ |] d+ ƒ }^ q{q–	q–	Wq(	W| t k r | |Z d 7} n  | dC IJ| ra|^ jR ƒ  t j j\ ƒ  }� |� j' |t d |t d |t d' f ƒ |� j] d> ƒ d? |� _^ t7 |� __ t` ta |r d ƒ |� g ƒ }” | dD tY |W ƒ d }\ t j j t? |\ ƒ }• t@ |• d+ ƒ }– |– jb |” jc | ƒ ƒ |– jR ƒ  |d s•|e s•|f ra|} }~ dE } xŸ t |Y d ƒ D]� \ }8 }w |8 d k rú| dF 7} xT |Y D] }— | dG |— |8 7} qÛWn1 | dH |~ 7} x  |Y D] }— | dI |— |8 7} qW| d 7} |~ |� }~ q²W| | d 7} | | IJqan  | r‚| |Œ 7} | d |Œ In  |B | k r—t7 }C qÒt }C qÒW|B }> |E j$ ƒ  }˜ |H }™ |< }? |� }@ t[ |Ž ƒ }š | r™t* |F j ƒ  ƒ d k r™|š \ }› }œ }� |F j" ƒ  }ž ˆ j% d |ž j& ƒ  ƒ }i |› jA ƒ  jC ƒ  |i |› jB ƒ  jC ƒ  |œ d |� d }j |ž j' |j ƒ |ž j' ˆ jE d. |ž j& ƒ  ƒ ƒ |˜ |F j$ ƒ  g }Ÿ n	 |˜ g }Ÿ |Ÿ d j ƒ  d j ƒ  d j! }H | rt* |F j ƒ  ƒ d k r|H |Ÿ d j ƒ  d j ƒ  d _! n  |™ |Ÿ d j ƒ  d j ƒ  d _! |! |$ j9 |> |™ |' |? |@ |Ÿ |š g ƒ qVW|$ | d k  rÑ|! j9 g  ƒ qÑqÑWdJ } | dK 7} dL „  }  | |  |! ƒ 7} g  }¡ x0 |! D]( }¢ t6 |¢ d dM „  ƒ}£ |¡ j9 |£ ƒ qªW| dN 7} | |  |¡ ƒ 7} t6 |¡ d dO „  ƒ}¤ | dP 7} | |  |¤ ƒ 7} t7 }¥ x‚ t |¤ ƒ D]t \ }8 }¢ xe t |¤ ƒ D]W \ }S }¦ |S t* |¢ ƒ d k rqPn  |¢ d d |¦ d d k rK|S |8 k rKt }¥ qKqKWq2Wxb|¥ t k rg  }¡ x0 |¤ D]( }¢ t6 |¢ d dQ „  ƒ}£ |¡ j9 |£ ƒ qÆW|¡ }¤ t6 |¡ d dR „  ƒ}¤ xp t |¤ ƒ D]b \ }8 }¢ xS t |¤ ƒ D]E \ }S }¦ |¢ d d |¦ d d k r3|S |8 k r3dS |¦ d d <q3q3WqWt7 }¥ x‚ t |¤ ƒ D]t \ }8 }¢ xe t |¤ ƒ D]W \ }S }¦ |S t* |¢ ƒ d k rÒPn  |¢ d d |¦ d d k r¬|S |8 k r¬t }¥ q¬q¬Wq“Wq­W| dT 7} | |  |¤ ƒ 7} | s5| rP| | d 7} | | IJn  x˜ t |¤ ƒ D]Š \ }8 }¢ |8 t* |¢ ƒ d k rƒPn  |  j9 |¢ d d |¢ d d |¢ d d' |¢ d d |¢ d dU |¢ d dV f ƒ |" jL |¢ d d ƒ q]W| d 7} | d IJt7 }§ t j j	 |  ƒ d j	 d ƒ d }¨ t j jd |" d  ƒ }© |	 }ª |	 d  k rbdW | |¨ f }ª n  t j je |ª ƒ }ª dX | | f }« x<|  D]4\ }w }¬ }' }­ }c }‡ dY |w |¬ |  |' | |­ f } | | 7} | | IJ|‡ \ }› }œ }� |« dZ tY tf |w dU ƒ ƒ |¬ |' |› jX ƒ  tf ta |œ d ƒ dU ƒ tf ta |� d ƒ dU ƒ f 7}« |w | k rfd[ } | | 7} | | IJn  xG |  D]? }¢ |c |¢ dU k rm|§ rmd\ } | | 7} | | IJt }§ qmqmWdC GH| d 7} q‹W| |« IJ| d] |ª 7} | |« 7} t@ |ª d+ ƒ }® t* | jg ƒ  ƒ d k r/|® jb d^ d j | jg ƒ  ƒ ƒ n  |® jb |© jc | ƒ ƒ |® jR ƒ  | ret jh | ƒ n  |  |ª | f S(f   NR   i   i   s   .pdbi    t   _s   _movhetatms.pdbRY   s
   file_name=s   output_file=R   s   %s has %d chain(s)s   
%s has %d chain(s)s   
Spacegroup in %s is %s

s   
sN   Warning: Ambiguous input. Not the same number of chains in the two PDB files.
s   Results may be unexpectedR¸   g        t   0Rõ   t   ,c         S   s*   y t  j |  ƒ SWn t k
 r% d SXd  S(   Ng        (   R   t   from_stringt
   ValueError(   t   v(    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/AlterOriginSymmate.pyt   zero_or_rational  s    i   gŠIl;‚u°TRK   t	   referencet   SSMt   keyc         S   s   |  d S(   Ni   (    (   t   Qvindx(    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/AlterOriginSymmate.pyt   <lambda>C  s    t   reverset   matchsI   SSM alignment of chains %s and %s failed. Trying mmtbx alignment instead.g      ð?t   MMTBXsD   
Identifying smallest MLAD between chain %s in %s and chain %s in %ssc   
for the %d allowed symmetry operations and %d allowed alternative origin(s) using %d alignment(s).s<   
Current best MLAD value is poor. Trying an mmtbx alignment.i   sM   #symm_op, symm_op, #alt_origin, alt_origin, UC_shift, #%s, %s(Q), label, mlads   %s_UC%d_%s_align%d.pdbs)   
Writing sites of the %d. alignment to %sR»   g      à?g      à¿R¹   c         S   s   |  j  d k S(   Ns    CA (   R¡   (   t   atom(    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/AlterOriginSymmate.pyR  È  s    c            sW   ˆ d |  ˆ d |  ˆ d |  g } ˆ j  | ƒ } ˆ j ˆ t | ƒ ƒ t ˆ  ƒ S(   Ni    i   i   (   RÒ   RÑ   t   tuplet   GetMLADfromAtoms(   RŒ   t   floatvect   cartfloatingoffset(   t   CAchainsRÍ   t   tmpsitest   uct   unitfloataxis(    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/AlterOriginSymmate.pyt   polaraxisoverlapë  s
    s   sym%dorig%diÈ   gŠIl;‚u°Ôt   outt   monitor_progresss   

s/   MLAD minimum= %f at fractional polar axis r= %fs   (%s, %s, %s)sD   %d. symm.op: (%s), %d. origin: %s, UC shift: %s, %d. %s Q: %2.3f, %ss*   %d. (%s), %d. %s, %s, %d. %2.3f, %s, %3.3fs   . alignment. s   s                      t   AUs     AUs   %s_Ca_ssm%d_sym%d_orig%d.pdbi   s3   
Writing remaining sites of the %d. alignment to %sR    t   _Ca_ssmsk   
MLAD values for all symmetry operations and alternative origins when sliding moving_pdb along polar axis

s   polar-axis s   %s s   %f s   %2.4f s�   Considering matrix of MLAD values between fixed and moving chains as to
ensure chain matching from fixed to moving pdb is an injective function:s   
Unsorted matrix:
c         S   so   d } xb |  D]Z } | | d d d 7} x1 | D]) } | d | d | d | d f 7} q0 W| d 7} q W| S(   NR   i    i   s   , s   %2.3f %s%s, i   s   
(    (   t   mtrxR«   t   ft   g(    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/AlterOriginSymmate.pyt   PrintColMatrix¹  s    'c         S   s   |  d S(   Ni    (    (   t   row(    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/AlterOriginSymmate.pyR  Ç  s    s   
Sorted matrix:
c         S   s   |  d d S(   Ni    (    (   R  (    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/AlterOriginSymmate.pyR  Í  s    s   
Column sorted matrix:
c         S   s   |  d S(   Ni    (    (   R  (    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/AlterOriginSymmate.pyR  Ü  s    c         S   s   |  d d S(   Ni    (    (   R  (    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/AlterOriginSymmate.pyR  à  s    g      Y@s   
Demoted column sorted matrix:
i   i   s   MinMLAD_%s_%s.pdbsK   
MLAD  	%s	%s	  Symmetry operation  	  Alternate origin  	 Unit cell shift
s;   
MLAD of %f for chain %s in %s with chain %s in %s using
%ss   %s	   %s	   %s	 %s	 %s	 %s
sB   These two chains are unlikely to represent the same MR solution.

sp   
WARNING! Not all chains are matched on the same origin. At least one of the matches between chains is spurious!s$   
Superposed MR solution saved in %s
s   %s
(   i    g      ð?R  (   i   i    i    (   i   i    i    (   i    i   i    (   i    i   i    (   i    i    i   (   i    i    i   (i   t   randomt   SystemRandomRQ   t   samplet   stringt   letterst   digitsR1   R2   R�   R   t   runR   R;   R	   t   NullHandlert   loggingt	   getLoggert
   addHandlert   space_groupt   space_group_infoR@   t   numberRÏ   RË   RÖ   R×   t
   is_proteinR-   t   symbol_and_numberR:   RÔ   t   new_hierarchy_from_chainRÙ   RÍ   t   GetCentreOfMoleculeRÌ   RÐ   RÎ   RÑ   t   meant   all_opsR%   t   list_originst   GetAllOriginsAsFloatsnStringst   stripRÊ   t   ranget
   StringTypeR9   t	   GetHETATMt   ccp4io_adaptbxt   SecondaryStructureMatchingt
   GetQvaluest   sortedR+   t   AlignSelectedMatchRP   t   SSMAlignmentt   residue_groupst   pairsR?   t
   mmtbxalignR4   RS   RŒ   t   tt	   as_doublet   DiffVecRÒ   R   t   to_atom_mappingt   intersect_selectiont   zipR  R  t   extendR   t   gsst	   cStringIOt   StringIOt   getvalueRV   RÇ   t   sqrtR   t   vec3_doubleRØ   t   as_xyzRN   t   MakeAlignstrR    R  t   set_namet   segidt   heterot	   atoms2pdbRM   RT   RÚ   RÕ   RÓ   t   Roundofft   remark_sectiont   remove(¯   t
   movingnamet   pdbfixedrefnameRc   R.   t   with_symm_operationst   DebugR   R   R   t   pdb_outt   log_outR   R  t   myrandt   randstrt   pdbxtalmovingnamet   xtalmovingnamet   fixedrefnameRd   t   pdbxtalt   pdbtestt   ht   loggert   sgt   sgnumbert   movinghierarchyt   fixedhierarchyt
   nmovchainst   chaint
   nfixchainsR]   t	   stdoutstrR€   t   AltOrigSymMLADst   pdbminmladmovhierarchiest   pdbminmladmovchainidst   ifixcht	   thischaint   testhierarchyt   fixed_chainidt	   testatomst
   testcentret   fractesthierarchyt   fractestatomst   testsites_fract   meantestsitesfract   symopst   nsymopt	   firstorigt   altorigsRµ   t   strvecRü   Rf   t   frcvcR  Re   t	   fvecpolart   strvec1t   norigt
   minmladstrt
   altorigstrt   movhierarchyminmladt   movminmladstrt   movminaltorigstrt   pdbminmladmovhierarchyt   minmladt   use_mmtbx_alignmentt   ssm_crashedt
   pdbminmladt   pdbhetatmhierarchyt   pdb_hierarchyt   pdb_chain_idt   original_sitest   mov_ref_chainst
   alignmentst	   sortQvalst   ssmt   Qvaluest
   Qvalsindext   qiRi   t   resmap2R~   t   alit   nRó   t   nssmt	   alimethodt   allmladst   minshortoutstrt   minaltorigsymopmladRˆ   t   allsitesfnamet   allsitest   symcountt   symopRê   Rë   t   altorigt   isFloatingXorigt   isFloatingYorigt   isFloatingZorigt   oct   genuninealtorigR¹   t	   new_sitest   altorig_new_sitest   nat   nbt   nct   unitcellshiftst   resmapt   atommapt
   CAchainzipt   xtalalignmentcentret   testalignmentcentret   xtalfraccentret   fractestcentreR‚   t   fracdifft   floatingoffsetR	  t	   rpolarminR  t   r_init   r1t   mladst   incrt   invincrt   dmpstrt   tmpstrt   floatoffsetlent   polaraxisminstrRû   t   altorigsymtranst   filepdbhiearchyt	   symopnameRj   t   shortoutstrt   alignstrt   minaltorigstrt   minmladaltorigsymtranst   newxtalalignmentcentret   matomt   CAxtalhierarchyt	   cntrfnamet   cntroutt   CAtesthierarchyt   refpdboutfnamet	   refpdboutt   onet   tmphierarchyt   minmladmovchainidt   movminmladaltorigsymtranst   symmt   altorgt   ucshiftt   hetatmst   pdbminmladmovhierarchylstR  t
   sortmatrixR  t   sortrowt   colsortmatrixt	   injectiveR  t
   notprintedt   movingnamebaset   jointpdbminmladmovt   altorigpdbfnamet   resultsmtrxstrRƒ   t   movstrt   pdbminRMSDfile(    (   R
  RÍ   R  R  R  sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/AlterOriginSymmate.pyRO   ¦  s¦   %/##
 

	)!(	FF4 .-

(







  "
"
"
"
"
"



	

5"*.!'$				






		



	
6	!$!
		

(((
O

#

%




#
c         C   s}   g  } x[ | j  ƒ  d j ƒ  D]C } | j ƒ  t k r | j |  k r | j t j j | ƒ ƒ q q Wt j j	 | d  ƒ } | S(   Ni    (   RÖ   R×   R&  R-   RÙ   RP   R   RÔ   R(  RÕ   R9   (   RÙ   t
   mhierarchyt   hetatmhierarchiest   chnt   hetatmhierarchy(    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/AlterOriginSymmate.pyR1  2  s    ! c         C   sS  g  } g  } x: |  j  ƒ  D], } | j t j j | j ƒ  d d ƒ ƒ q Wd j | ƒ } x: | j  ƒ  D], } | j t j j | j ƒ  d d ƒ ƒ qe Wd j | ƒ } t j j	 | | ƒ } | j
 ƒ  } g  } x� t | j ƒ D]p \ } }	 | j | }
 |	 d  k r|  j  ƒ  |	 n d  } |
 d  k r2| j  ƒ  |
 n d  } | j | | f ƒ qÛ W| S(   Ni    t   XR   (   R8  RP   R
   t   one_letter_given_three_lettert   gett   unique_resnamesRQ   t   mmtbxt	   alignmentt   alignt   extract_alignmentR:   t   i_seqs_at   i_seqs_bR9   (   t   movingchaint
   fixedchaint   movrest   fixrest   rgt   myalignt   mmtbxaliR“  Re   t   i_seq1t   i_seq2t   res1t   res2(    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/AlterOriginSymmate.pyR:  =  s"    **""c         C   s×  t  j j ƒ  } | j t  j j ƒ  ƒ | j ƒ  d j t  j j d d ƒ ƒ | j ƒ  d j ƒ  d j	 t  j j
 ƒ  ƒ | j ƒ  d j ƒ  d j ƒ  d j t  j j ƒ  ƒ x't |  ƒ D]\ } } | j ƒ  d j ƒ  d j ƒ  d j t  j j ƒ  ƒ | j ƒ  d j ƒ  d j ƒ  d j ƒ  | j | ƒ | j t k rw| j ƒ  j | j ƒ  d j ƒ  d j ƒ  d j ƒ  | _ n1 d | j ƒ  d j ƒ  d j ƒ  d j ƒ  | _ | | j ƒ  d j ƒ  d j ƒ  d _ q¶ W| S(   Ni    RÙ   t   At   HEM(   R   RÔ   t   roott   append_modelt   modelRÖ   t   append_chainRe  R×   t   append_residue_groupt   residue_groupR8  t   append_atom_groupt
   atom_groupR:   t   atom_groupst   append_atom_with_other_parentRL  R-   t   fetch_labelst   resnamet   resseq(   RÍ   RŒ   Re   t   atm(    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/AlterOriginSymmate.pyRM  X  s    &*445=1+c   
      C   sŒ  d } d } d } xô |  D]ì } yE t  | d ƒ t k	 rY | t j | d j ƒ  j 7} n
 | d 7} Wn+ t k
 r‘ } | d | 7} | d 7} n XyE t  | d ƒ t k	 rÌ | t j | d j ƒ  j 7} n
 | d 7} Wq t k
 r} | d | 7} | d 7} q Xq Wd } d } d } x\ t |  ƒ | k ry| | | | | !d 7} | | | | | !d 7} | d 7} | | 7} qWd	 | | }	 |	 S(
   NR   i    t   -s   Unknown residue: %s
t   ?i   iP   s   
s   Aligned residues:
(   R@   RA   R
   Ræ  t   parentR  R?   R%   (
   R
  t   Ca1rescodest   Ca2rescodest   errstrt   CapairRi   t	   niceprintR•  t   ncharRÂ  (    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/AlterOriginSymmate.pyRI  n  s8    !!
c         C   sU   d d d g } |  d | d | d <|  d | d | d <|  d | d | d <| S(   Ni    i   i   (    (   t   vec1t   vec2t   d(    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/AlterOriginSymmate.pyR=  •  s
    c         C   s²   t  |  ƒ } d } xŒ |  D]„ } | d j d | d j d } | d j d | d j d } | d j d | d j d } | | | | | | | 7} q Wt j | | ƒ S(   Ng        i    i   i   (   R%   t   xyzRÇ   RF  (   t	   atompairst   lnt   Dt   atompairt   dxt   dyt   dz(    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/AlterOriginSymmate.pyt   GetRMSDfromAtomsž  s       "c   	   	   C   sò   t  |  ƒ } d } d } xÂ |  D]º } | d j d | d j d } | d j d | d j d } | d j d | d j d } | | | | | | } | t j | t j | ƒ | t | t | d ƒ ƒ ƒ 7} q W| | t j | ƒ S(   Ng        gÍÌÌÌÌÌì?i    i   i   (   R%   R  RÇ   t   logRF  t   maxt   min(	   R  R  R  t   pR  R  R  R  t   sqrD(    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/AlterOriginSymmate.pyR  ­  s       >c         C   s½   d d d g } xe |  D]] } | d c t  | j d ƒ 7<| d c t  | j d ƒ 7<| d c t  | j d ƒ 7<q W| d c t |  ƒ :<| d c t |  ƒ :<| d c t |  ƒ :<| S(   Ng        i    i   i   (   RÊ   R  R%   (   RÍ   t   cR  (    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/AlterOriginSymmate.pyR)  ½  s    !c         C   sV   |  d k  r& |  | }  t  |  | ƒ n  |  | k rL |  | }  t  |  | ƒ n  |  | f S(   Ni    (   t	   make_nice(   R;  R  (    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/AlterOriginSymmate.pyR%  Î  s    

c   
      C   sÌ  d  d  d  g } d d d g } t } | d k rú d } x. t d ƒ D]  } |  | d k rC | } PqC qC Wx† t d ƒ D]x } |  | d k r— d | | <qt |  | d k rÄ t | | ƒ | | <t } qt t | | ƒ t |  | ƒ | | <t } qt W| | f SxÁ t d ƒ D]³ } |  | d k r*d | | <qt |  | | ƒ \ } } t | ƒ t k rjt j | d ƒ } n  t | ƒ t k r‘t j | d ƒ } n  | | }	 t	 |	 j
 ƒ  |	 j ƒ  ƒ | | <qW| | f Sd  S(   Nt   xt   yt   zi    i   i   (   R9   R-   R/  RN   R+   R%  R@   t   intR   R   t	   numeratort   denominator(
   Rû   Ri   t   resR  t   isfloatorigt   this_onet   iiR;  R  t   obj(    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/AlterOriginSymmate.pyt   translate_v_mÙ  s:    	"


#c         C   sü   t  j d |  d d ƒ } | j ƒ  j ƒ  } | j ƒ  } | j t t ƒ } g  } t | ƒ d k r¥ xB | D]7 } t	 | j
 | j ƒ } | | k rg | j | ƒ qg qg Wn  t } d d d g g }	 x2 | D]* }
 |
 d rÝ t } n  |	 j |
 d ƒ qÄ W|	 | f S(   Nt   symbolt   space_group_t_deni�   i    g        i   (   R   R$  t   structure_seminvariantst   vectors_and_moduliR@   t'   addl_generators_of_euclidean_normalizerR+   R-   R%   R1  Rû   Ri   RP   (   t   sgnumbersymbolt   sginfot   vecst   sg_typet   k2lt   resultsR/  RŒ   t   hasfloatingorigint   resultsoriginfR,  (    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/AlterOriginSymmate.pyR,    s$    
	c         C   s¬   t  |  ƒ } t | d ƒ t k	 r@ t | d d ƒ d | d <n  t | d ƒ t k	 rt t | d d ƒ d | d <n  t | d ƒ t k	 r¨ t | d d ƒ d | d <n  | S(   Ni    i   i   (   RM   R@   R0  t   divmod(   Rû   R;  (    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/AlterOriginSymmate.pyt	   RemainderD  s    c         C   s/  t  g  ƒ } x|  D]} t t | ƒ ƒ } d } xó | | k r&| j | ƒ d d d g } | d 7} t | d ƒ t k r� | d | d <n | | d | d <t | d ƒ t k rÆ | d | d <n | | d | d <t | d ƒ t k rÿ | d | d <n | | d | d <t t | ƒ ƒ } q4 Wq W| S(   Ni   i    i   (   t   setR  R@  t   addR@   R0  (   t   origvlstt
   alloriginst   origvt   modnewvR•  t   newv(    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/AlterOriginSymmate.pyt"   GenerateEquivalentOriginsForVectorP  s&    
c         C   s€  g  } xst  d t |  ƒ d ƒ D]X} t t j |  | ƒ ƒ } x7| D]/} d d d g } x
| D]} t | d ƒ t k rŽ | d | d <n- t | d ƒ t k	 r» | d c | d 7<n  t | d ƒ t k râ | d | d <n- t | d ƒ t k	 r| d c | d 7<n  t | d ƒ t k r6| d | d <qa t | d ƒ t k	 ra | d c | d 7<qa qa W| j | ƒ qE Wq  W| S(   Ni   i    i   (   R/  R%   RM   t	   itertoolst   combinationsR@   R0  RP   (   t
   originvlstt	   origvClstR•  t   Klstt   Kt   combinedorigvRû   (    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/AlterOriginSymmate.pyt   GetOriginVectorCombinationsp  s(     c         C   sÎ  g  } t  j d |  d d ƒ } | j ƒ  j ƒ  d d k re | j d t d d ƒ t d d ƒ g ƒ n  | j ƒ  j ƒ  d d	 k r¬ | j t d d ƒ d t d d ƒ g ƒ n  | j ƒ  j ƒ  d d	 k ró | j t d d ƒ t d d ƒ d g ƒ n  | j ƒ  j ƒ  d d
 k rC| j t d d ƒ t d d ƒ t d d ƒ g ƒ n  | j ƒ  j ƒ  d d k rÚ| j t d d ƒ t d d ƒ d g ƒ | j d t d d ƒ t d d ƒ g ƒ | j t d d ƒ d t d d ƒ g ƒ n  | j ƒ  j ƒ  d d k r[| j t d d ƒ t d d ƒ t d d ƒ g ƒ | j t d d ƒ t d d ƒ t d d ƒ g ƒ n  | j ƒ  j ƒ  d d k rÊ| j t d d ƒ t d d ƒ d g ƒ | j t d d ƒ t d d ƒ d g ƒ n  | S(   NR2  R3  i�   i    Rú  g        i   i   t   Ct   It   Ft   Ri   t   H(   R   R$  R@   t   lookup_symbolRP   R   (   Ra  t   cvecsR8  (    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/AlterOriginSymmate.pyt   GetCentringVectors–  s*    +++4((+14(+c         C   s  t  |  ƒ d } | j t |  ƒ ƒ t | ƒ } t } t } t } xY | D]Q } | d d k rg t } n  | d d k r€ t } n  | d d k rH t } qH qH Wx! | D] } | r¤ d | d <q¤ q¤ Wx! | D] } | rÈ d | d <qÈ qÈ Wx! | D] } | rì d | d <qì qì Wt | ƒ } t | ƒ S(   Ni    R&  i   R'  i   R(  (   R,  RA  RX  RP  R-   R+   RH  RM   (   Ra  t   origlstt   Coriglstt
   origfloatXt
   origfloatYt
   origfloatZt   elmt	   eqoriglst(    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/AlterOriginSymmate.pyt   GetAllOrigins½  s0      		c         C   sè   g  } xÛ |  D]Ó } d d d g } t  | d ƒ t k	 rO t | d ƒ | d <n | d | d <t  | d ƒ t k	 rŠ t | d ƒ | d <n | d | d <t  | d ƒ t k	 rÅ t | d ƒ | d <n | d | d <| j | ƒ q W| S(   Ni    i   i   (   R@   R0  RÊ   RP   (   t   vst   lfvRû   t   fv(    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/AlterOriginSymmate.pyt   ListAsFloatsÞ  s    c         C   sk   t  |  ƒ } t | ƒ } g  | D]3 } t | d ƒ t | d ƒ t | d ƒ g ^ q } t | | ƒ } | S(   Ni    i   i   (   R`  Rd  RN   R@  (   Ra  t   lstt   floatlstRf   t   strlstt   fslst(    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/AlterOriginSymmate.pyR-  ù  s
    @c         C   su   t  |  ƒ } g  | D]B } d t | d ƒ d t | d ƒ d t | d ƒ d ^ q } x | D] } | GHqb Wd  S(   Nt   (i    s   , i   i   t   )(   R`  RN   (   Ra  Re  Rf   Rg  t   l(    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/AlterOriginSymmate.pyt   PrettyPrintAllOrigins  s    Ot   __main__(O   t   copyR    t	   fractionsR   RI  t   boostR   t   typest   sysR1   RÇ   RÃ   t   mmtbx.alignmentRé  t   iotbxR   R   R¾   R   t   scitbx.array_familyR   R2  t   phaser.test_phaser_parsersR“   R   R	   t	   iotbx.pdbR
   t   scitbx.math.euler_anglesRÆ   R   R˜   R   t   libtbx.philR   t   getoptR   RC  t   libtbx.utilsR   t   phaser.utils2t   mmtbx.command_lineR   R  R  RØ   R4   R   R   t   argvRŠ   RC   t   curdirRL   R+   R-   R9   t   stdoutRO   R1  R:  RM  RI  R=  R  R  R)  R%  R1  R,  R@  RH  RP  RX  R`  Rd  R-  Rl  t   __name__(    (    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/AlterOriginSymmate.pyt   <module>   s†   
0
v	“	4:ÿ ÿ �				'							@	+		 	&	'	!		
		