ó
—™xTc           @  s—   d  d l  m Z d  d l  m Z d e f d „  ƒ  YZ e d k r“ d Z d Z e e ƒ Z e	 e j
 ƒ e e ƒ Z e	 e j
 ƒ e	 e j ƒ  ƒ n  d S(	   iÿÿÿÿ(   t   division(   t   print_functiont
   pcr_parserc           B  s\   e  Z d
 d
 e d  „ Z e d „ Z d d „ Z d d „ Z d „  Z	 d d „ Z
 d	 „  Z RS(   c         C  sÖ   d d l  m } d |  _ | ƒ  |  _ | j ƒ  |  _ | |  _ x |  j D] } t | ƒ qG W|  j d j d ƒ sÈ |  j r‰ t	 d ƒ ‚ qÈ x< |  j j
 ƒ  D]( } | j d ƒ r™ |  j j | ƒ q™ q™ Wn  |  j ƒ  d S(   sF  Function to parse a FullProf command file into a ConfigObj

    It was modeled according to the FullProf manual and actual output
    files from FullProf and still far from being complete.

    :param inputstring: a string containing a whole commented pcr file like fp2k     would format it.
    :type inputstring: string
    iÿÿÿÿ(   t	   ConfigObji    i   t   !s{           This function only works with correctly commented FullProf files!
        Please run fp2k on your input file first.N(   t	   configobjR   t   LOt   cfgt
   splitlinest   linest   enforce_valid_commentst   printt
   startswitht
   ValueErrort   copyt   removet   _parse(   t   selft   inputstringt   pcrfileR
   R   t   line(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/fullprof/read_pcr.pyt   __init__   s    
			c         C  s;   |  j  d 7_  | r# |  j |  j  S|  j |  j  j ƒ  Sd  S(   Ni   (   R   R	   t   split(   R   t   raw(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/fullprof/read_pcr.pyt   __get_next_line"   s    t    c   	      C  sú   |  j  ƒ  } d } xá | j d ƒ D]Ð } t | ƒ d k  r> Pn  t | ƒ | k rc | | j ƒ  } n | d j ƒ  } | d k r¡ t | j d ƒ ƒ | | j ƒ  <nG | d k rÏ t | j d ƒ ƒ | | j ƒ  <n | j d ƒ | | j ƒ  <| d 7} q" Wd  S(   Ni    s   , i   iÿÿÿÿt   it   f(   t   _pcr_parser__get_next_lineR   t   lent   lowert   intt   popt   stript   float(	   R   t   dict_to_append_tot   KEYSt
   typeselectt   linevalsR   t   valt   typeselt   typsel(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/fullprof/read_pcr.pyt   __parse_line)   s     ""R   c         C  sY   |  j  rU |  j d 7_ |  j |  j } | j | ƒ sU t d j | | ƒ ƒ ‚ qU n  d  S(   Ni   sM   Expected to find comment '{comm}',                         but found '{line}'(   R
   R   R	   R   R   t   format(   R   t   expected_commentR   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/fullprof/read_pcr.pyt   __check_comment:   s    	c         C  sL   i  } x? t  t |  j d ƒ ƒ D]$ } |  j d | d ƒ | | d <q  W| S(   Nt   phasest   phase_nri   (   t   rangeR   R   t   extract_structure(   R   t
   structuresR   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/fullprof/read_pcr.pyt   extract_structuresB   s     "i   c         C  sI  d d l  m } d d l  m } d d l m } |  j d t | ƒ } | d } | d | d | d	 | d
 | d | d g } | j d | j d | d | d ƒ ƒ } g  }	 xf | j	 ƒ  D]X \ }
 } |	 j
 | j d | d d | d d | d | d | d f d | d ƒ ƒ q¼ W| j |	 ƒ } | j d | d | ƒ } | j ƒ  S(   s˜   This method tries to extract the crystal structure from the parsed pcrfile.

    :returns: the extracted structure
    :rtype: cctbx.xray.structure
    iÿÿÿÿ(   t   xray(   t   crystal(   t   flexR.   t   atomst   at   bt   ct   alphat   betat   gammat   crystal_symmetryt	   unit_cellt   space_group_symbolt   SYMBt   labelt   LABELt   scattering_typet   NTYPt   sitet   Xt   Yt   Zt   Bt   special_position_settingst
   scatterers(   t   cctbxR4   R5   t   cctbx.array_familyR6   R   t   strRK   t   symmetryt	   iteritemst   appendt	   scatterert   xray_scatterert	   structuret
   as_py_code(   R   R/   R4   R5   R6   t   pR7   R?   RK   RL   t   kR8   t   scatterers_flexRU   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/fullprof/read_pcr.pyR1   I   s(    
0		
	c         C  sf  |  j  d d j ƒ  |  j d <|  j r` x6 |  j  D]( } | j d ƒ rJ Pn  |  j d 7_ q1 Wn  |  j } |  j } |  j } | |  j d d ƒ |  j d d k rÀ t	 d	 j
 |  j d ƒ ƒ ‚ n  | d
 ƒ | d ƒ | |  j d d ƒ | d
 ƒ | d ƒ | |  j d d ƒ | d
 ƒ | d ƒ | |  j d d ƒ |  j d d k rä|  j d } | d k sm| d k  rä| d
 ƒ | d ƒ g  } xG t t | ƒ ƒ D]3 } | ƒ  } | t | d ƒ t | d ƒ f 7} qšW| |  j d <qän  | d
 ƒ | d
 ƒ t | ƒ  d ƒ |  j d <|  j d d k r| d
 ƒ | d ƒ | |  j d dM ƒ |  j d d k r“| d
 ƒ | d ƒ | d ƒ | |  j d  d ƒ n  | d! ƒ | ƒ  } | ƒ  }	 i  }
 d } x= t | |	 ƒ D], \ } } | | g |
 t | ƒ <| d 7} qËW|
 |  j d" <n  i  } xAt |  j d# ƒ D],} | d$ ƒ | d% ƒ | d$ ƒ i  } | ƒ  | d& <| d
 ƒ | d' ƒ | | d( d) ƒ | d* d k r“n  | d
 ƒ | d+ t ƒ d,  j ƒ  | d- <| d. d k rÍn  | d/ ƒ i  } xN t | d0 ƒ D]< } i  } | | d1 d2 ƒ | | d3 d ƒ | | t | ƒ <qîW| | d4 <| d5 ƒ | d6 ƒ | | d7 d8 ƒ | | d9 d ƒ | d: d; k rn* | d< ƒ | | d= d> ƒ | | d? d ƒ | d@ ƒ | | dA d ƒ | | dB d ƒ | dC ƒ | | dD d ƒ | | dE d ƒ |  j dF d k  r=| dG ƒ | | dH d ƒ | | dI d ƒ n  | | t | d ƒ <q%W| |  j dJ <dK S(N   s?   Function to parse a FullProf command file into a ConfigObj
    i    i   t   TITLEs   !Job i   sz   JOBTYP, NPROF, NPHASE, NBCKGD, NEXCRG, NSCAT, NORI, IDUM, IWGT,      ILOR, IASG, IRESO, ISTEP, NRELL, ICRYG, IXUNIT, ICORRR   t   IRESOs&   IRESO<>0 not supported (yet)! IRESO={}R   s   !Ipr sh   IOT, IPL, IPC, MAT, NXT, LST1, LST2, LST3, IPL1, IPL2, INSTRM,      JCIL, JSY, JLKH, JFOU, ISHOR, IANALYs
   ! Lambda1 s5   LAMDA1, LAMDA2, RATIO, BKPOS, WDT, CTHM, TMR, RLIM, KR   s   !NCY sR   MCYCLE, EPS, RELAX1, RELAX2, RELAX3, RELAX4, THMIN, STEP, THMAX,      ALPSD, SENT0t   ift   ICRYGt   NBCKGDi   iýÿÿÿs   ! 2Thetat
   backgroundt   MAXSs   !  Zero sA   ZER, FLGZER, SYCOS, FLCOS, SYSIN, FLSYN, LAMBDA, FLAMBDA, IGLMOREi   t   IGLMOREs   ! Microabsorptions   !   P0 s   CPO, Cp, CCp, Tau, CTaus   !   Backgroundt   backgroundpolyt   NPHASEs   !-------s   !  Data for PHASEt   PHSNMs   !Nat sa   NAT, NDIST, NMAGC, PREF1, PREF2, PREF3,        JBT, IRF, ISYM, ISTR, IFURT, ATZ, NVK, NPRO, IMOREt   iiifffiiiiifiiit   IMORER   i   RA   t   ISYMs   !Atom t   NATs1   LABEL, NTYP, X, Y, Z, B, N, IOPIN, IOPFIN, N_Typet
   ssfffffiiis!   CX, CY, CZ, CB, CN, CMx, CMy, CMzR7   s   !-------> Profile s	   !  Scale s,   S, GAM1, Bov, STR1, STR2, STR3, IstrainModelt   ffffffis%   CS, FLGAM1, CBov, CSTR1, CSTR2, CSTR3t   IRFi   s	   !       Us!   U, V, W, X, Y, IG, SZ, IsizeModelt   fffffffis   CU, CV, CW, CX, CY  CIG  CSZs   !     a s   a, b, c, alpha, beta, gammas   CA, CB, CC, CD, CE, CFs	   !  Pref1 s   G1, G2, Pas1, Pas2, Pas3, Pas4s$   CG1, CG2, CPas1, CPas2, CPas3, CPas4t   RATIOs   !Additional U,V,Ws
   U2, V2, W2s   CU2, CV2, CW2R.   Nt   fffffffft	   ffffffffi(   R	   R!   R   R
   R   R   R   t   _pcr_parser__parse_linet   _pcr_parser__check_commentR   R+   R0   t   absR"   R   t   zipRO   t   True(   R   R   t   get_next_linet
   parse_linet   check_commentR^   R_   R   R&   t	   lineflagsRb   t   vR   R.   RW   t   phaseR7   R8   t   atom(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/fullprof/read_pcr.pyR   d   sÒ    	 				


	


	


	


	(



	




		
















N(   t   __name__t
   __module__t   NoneRt   R   t   FalseR   Rp   Rq   R3   R1   R   (    (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/fullprof/read_pcr.pyR      s   	t   __main__s‘  COMM  CeO2 CSIRO Test 25-143
! Current global Chi2 (Bragg contrib.) =      11.67
! Files => DAT-file: ce1.dat,  PCR-file: ce1
!Job Npr Nph Nba Nex Nsc Nor Dum Iwg Ilo Ias Res Ste Nre Cry Uni Cor Opt Aut
   0   5   1   0   0   0   0   0   0   0   0   0   0   2   0   0   0   1   1
!
!Ipr Ppl Ioc Mat Pcr Ls1 Ls2 Ls3 NLI Prf Ins Rpa Sym Hkl Fou Sho Ana
   0   0   1   0   1   0   4   0   0   1   0   1   1   1   2   0   0
!
! Lambda1  Lambda2    Ratio    Bkpos    Wdt    Cthm     muR   AsyLim   Rpolarz  2nd-muR -> Patt# 1
 1.540560 1.544330 -0.50000   25.000 15.0000  0.9100  0.0000   30.00    0.0000  0.0000
!
!NCY  Eps  R_at  R_an  R_pr  R_gl     Thmin       Step       Thmax    PSD    Sent0
  6  0.10  1.00  1.00  1.00  1.00     25.0000   0.025000   143.0000   0.000   0.000
!
!
      20    !Number of refined parameters
!
!  Zero    Code    SyCos    Code   SySin    Code  Lambda     Code MORE ->Patt# 1
  0.02573   11.0  0.00000    0.0  0.00000    0.0 0.000000    0.00   1
!
! Microabsorption coefficients for Pattern#  1
!   P0    Cod_P0    Cp   Cod_Cp     Tau  Cod_Tau
  0.0000    0.00  1.2313  141.00  0.1340  151.00
!   Background coefficients/codes  for Pattern#  1  (Polynomial of 6th degree)
      24.538     -17.709       6.313      -0.604       0.000       0.000
       21.00       31.00       41.00       51.00        0.00        0.00
!-------------------------------------------------------------------------------
!  Data for PHASE number:   1  ==> Current R_Bragg for Pattern#  1:     0.00
!-------------------------------------------------------------------------------
  CeO2
!
!Nat Dis Ang Pr1 Pr2 Pr3 Jbt Irf Isy Str Furth       ATZ    Nvk Npr More
   2   0   0 1.0 1.0 1.0   0   0   0   0   0        688.480   0   5   0
!
F m 3 m                  <--Space group symbol
!Atom   Typ       X        Y        Z     Biso       Occ     In Fin N_t Spc /Codes
Ce     CE      0.00000  0.00000  0.00000  0.46033   0.02000   0   0   0    0  # color green conn O O 0.0 3.2
                  0.00     0.00     0.00   161.00      0.00
O      O       0.25000  0.25000  0.25000  0.92218   0.04000   0   0   0    0  # color blue
                  0.00     0.00     0.00   171.00      0.00
!-------> Profile Parameters for Pattern #  1
!  Scale        Shape1      Bov      Str1      Str2      Str3   Strain-Model
 0.10216E-02   0.36723   0.00000   0.00000   0.00000   0.00000       0
    61.00000    81.000     0.000     0.000     0.000     0.000
!       U         V          W           X          Y        GauSiz   LorSiz Size-Model
   0.007618  -0.008887   0.010210   0.003351   0.000000   0.000000   0.000000    0
    101.000     91.000    111.000    121.000      0.000      0.000      0.000
!     a          b         c        alpha      beta       gamma      #Cell Info
   5.412223   5.412223   5.412223  90.000000  90.000000  90.000000   #multiple box -1 1 -1 1 0 1
   71.00000   71.00000   71.00000    0.00000    0.00000    0.00000
!  Pref1    Pref2      Asy1     Asy2     Asy3     Asy4
  0.00000  0.00000  0.06233  0.00000  0.00000  0.00000
     0.00     0.00   131.00     0.00     0.00     0.00
!Additional U,V,W parameters for Lambda2
   0.007461  -0.005255   0.008197   <--  U2,V2,W2 for lambda(2)
 191.000000 201.000000 181.000000
! Limits for selected parameters :
  14      0.0010      2.0000      0.0000   0  Cp_mabs_pat1
  15      0.0010      2.0000      0.0000   0  Tau_mabs_pat1
!  2Th1/TOF1    2Th2/TOF2  Pattern # 1
      25.000     143.000       1
sÌ  COMM unnamed
! Files => DAT-file: rnd_27A_15L_10M_02H_P_1_25_,  PCR-file: rnd_27A_15L_10M_02H_P_1_25_
!Job Npr Nph Nba Nex Nsc Nor Dum Iwg Ilo Ias Res Ste Nre Cry Uni Cor Opt Aut
   2   0   1   0   0   0   0   1   0   0   0   0   0   0   0   0   0   0   1
!
!Ipr Ppl Ioc Mat Pcr Ls1 Ls2 Ls3 NLI Prf Ins Rpa Sym Hkl Fou Sho Ana
   2   0   1   1   1   0   4   0   0   1  10   0   1   4   2   0   0
!
! Lambda1  Lambda2    Ratio    Bkpos    Wdt    Cthm     muR   AsyLim   Rpolarz  2nd-muR -> Patt# 1
 1.541800 1.541800  1.00000   60.000  5.0000  0.0000  0.0000   50.00    0.0000  0.0000
!
!NCY  Eps  R_at  R_an  R_pr  R_gl     Thmin       Step       Thmax    PSD    Sent0
  1  0.01  1.00  1.00  1.00  1.00     10.0000   0.100000   100.0000   0.000   0.000
!
!
       0    !Number of refined parameters
!
!  Zero    Code    SyCos    Code   SySin    Code  Lambda     Code MORE ->Patt# 1
  0.00000    0.0  0.00000    0.0  0.00000    0.0 0.000000    0.00   0
!   Background coefficients/codes  for Pattern#  1  (Polynomial of 6th degree)
       0.000       0.000       0.000       0.000       0.000       0.000
        0.00        0.00        0.00        0.00        0.00        0.00
!-------------------------------------------------------------------------------
!  Data for PHASE number:   1  ==> Current R_Bragg for Pattern#  1:     0.00
!-------------------------------------------------------------------------------
 Phase_1
!
!Nat Dis Ang Pr1 Pr2 Pr3 Jbt Irf Isy Str Furth       ATZ    Nvk Npr More
  27   0   0 0.0 0.0 1.0   0   0   0   0   0        924.976   0   0   0
!
P 1                      <--Space group symbol
!Atom   Typ       X        Y        Z     Biso       Occ     In Fin N_t Spc /Codes
Cs1    Cs      0.25575  0.74218  0.01280  0.39478   1.00000   0   0   0    0
                  0.00     0.00     0.00     0.00      0.00
Cs2    Cs      0.76337  0.84611  0.64963  0.39478   1.00000   0   0   0    0
                  0.00     0.00     0.00     0.00      0.00
C1     C       0.80799  0.01687  0.87219  0.39478   1.00000   0   0   0    0
                  0.00     0.00     0.00     0.00      0.00
C2     C       0.95999  0.89218  0.97716  0.39478   1.00000   0   0   0    0
                  0.00     0.00     0.00     0.00      0.00
C3     C       0.61730  0.40423  0.22206  0.39478   1.00000   0   0   0    0
                  0.00     0.00     0.00     0.00      0.00
C4     C       0.96991  0.50496  0.26698  0.39478   1.00000   0   0   0    0
                  0.00     0.00     0.00     0.00      0.00
C5     C       0.27434  0.34505  0.32297  0.39478   1.00000   0   0   0    0
                  0.00     0.00     0.00     0.00      0.00
C6     C       0.51741  0.89889  0.90591  0.39478   1.00000   0   0   0    0
                  0.00     0.00     0.00     0.00      0.00
C7     C       0.28570  0.06143  0.11813  0.39478   1.00000   0   0   0    0
                  0.00     0.00     0.00     0.00      0.00
C8    C       0.85987  0.32773  0.87587  0.39478   1.00000   0   0   0    0
                  0.00     0.00     0.00     0.00      0.00
C9    C       0.57367  0.37951  0.94405  0.39478   1.00000   0   0   0    0
                  0.00     0.00     0.00     0.00      0.00
C10    C       0.74819  0.35206  0.92477  0.39478   1.00000   0   0   0    0
                  0.00     0.00     0.00     0.00      0.00
C11    C       0.11661  0.17692  0.48152  0.39478   1.00000   0   0   0    0
                  0.00     0.00     0.00     0.00      0.00
C12    C       0.68782  0.53267  0.57410  0.39478   1.00000   0   0   0    0
                  0.00     0.00     0.00     0.00      0.00
C13    C       0.35920  0.22199  0.20957  0.39478   1.00000   0   0   0    0
                  0.00     0.00     0.00     0.00      0.00
C14    C       0.54158  0.59845  0.57855  0.39478   1.00000   0   0   0    0
                  0.00     0.00     0.00     0.00      0.00
C15    C       0.10057  0.16401  0.79612  0.39478   1.00000   0   0   0    0
                  0.00     0.00     0.00     0.00      0.00
Ti1   Ti      0.42526  0.93883  0.93721  0.39478   1.00000   0   0   0    0
                  0.00     0.00     0.00     0.00      0.00
Ti2   Ti      0.81513  0.52398  0.20025  0.39478   1.00000   0   0   0    0
                  0.00     0.00     0.00     0.00      0.00
Ti3   Ti      0.51151  0.35888  0.34305  0.39478   1.00000   0   0   0    0
                  0.00     0.00     0.00     0.00      0.00
Ti4   Ti      0.43735  0.05657  0.82934  0.39478   1.00000   0   0   0    0
                  0.00     0.00     0.00     0.00      0.00
Ti5   Ti      0.96559  0.21095  0.23956  0.39478   1.00000   0   0   0    0
                  0.00     0.00     0.00     0.00      0.00
Ti6   Ti      0.59096  0.29067  0.09393  0.39478   1.00000   0   0   0    0
                  0.00     0.00     0.00     0.00      0.00
Ti7   Ti      0.24350  0.09520  0.50214  0.39478   1.00000   0   0   0    0
                  0.00     0.00     0.00     0.00      0.00
Ti8   Ti      0.60861  0.39336  0.54098  0.39478   1.00000   0   0   0    0
                  0.00     0.00     0.00     0.00      0.00
Ti9   Ti      0.80180  0.14419  0.13294  0.39478   1.00000   0   0   0    0
                  0.00     0.00     0.00     0.00      0.00
Ti10  Ti      0.49678  0.67274  0.97981  0.39478   1.00000   0   0   0    0
                  0.00     0.00     0.00     0.00      0.00
!-------> Profile Parameters for Pattern #  1
!  Scale        Shape1      Bov      Str1      Str2      Str3   Strain-Model
 0.10000E-01   0.00000   0.03837   0.00000   0.00000   0.00000       0
     0.00000     0.000     0.000     0.000     0.000     0.000
!       U         V          W           X          Y        GauSiz   LorSiz Size-Model
   1.706310  -1.179299   0.405540   0.000000   0.000000   0.000000   0.000000    0
      0.000      0.000      0.000      0.000      0.000      0.000      0.000
!     a          b         c        alpha      beta       gamma      #Cell Info
   9.422933  12.249814  16.018988  83.000000 109.000000 129.000000
    0.00000    0.00000    0.00000    0.00000    0.00000    0.00000
!  Pref1    Pref2      Asy1     Asy2     Asy3     Asy4
  0.00000  0.00000  0.00000  0.00000  0.00000  0.00000
     0.00     0.00     0.00     0.00     0.00     0.00
!  2Th1/TOF1    2Th2/TOF2  Pattern # 1
      10.000     100.000       1
N(   t
   __future__R    R   t   objectR   R|   t	   testfile1t	   testfile2t   xR   R   R1   (    (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/fullprof/read_pcr.pyt   <module>   s   ÛAh