ó
šxTc           @   sN  d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l	 Z	 d  d l
 Z
 d  d l Z d  d l Z d  d l Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d	 „  ƒ  YZ d
 e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d  e f d! „  ƒ  YZ d" e f d# „  ƒ  YZ  d$ e f d% „  ƒ  YZ! d& e f d' „  ƒ  YZ" d S((   iÿÿÿÿNt   ProxyExceptionc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyR       s   t   DownloaderBasec           B   s/   e  Z d  Z d Z d „  Z d „  Z d „  Z RS(   s   Accept-encodings   Content-Encodingc         C   s+   | j  j |  j d ƒ j ƒ  } |  j | ƒ S(   Nt    (   t   headerst   gett   STREAM_HEADERt   lowert   interpretable_encoding(   t   selft   data_streamt   encoding(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyt   handles   s    c         C   s   | |  j  k S(   N(   t   ENCODING(   R
   R   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyR	   $   s    c         C   sg   | j  |  j ƒ } | rM |  j | k rc | j |  j d | |  j f ƒ qc n | j |  j |  j ƒ d  S(   Ns   %s, %s(   t
   get_headert   REQUEST_HEADERR   t
   add_header(   R
   t   requestt   settings(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyt   enable_encoding)   s    (   R   R   R   R   R   R	   R   (    (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyR      s
   		t   SimpleDownloaderc           B   s    e  Z d  Z d „  Z d „  Z RS(   t   identityc         C   s
   | j  ƒ  S(   N(   t   read(   R
   R   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyt   fetch<   s    c         C   s   | p | |  j  k S(   N(   R   (   R
   R   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyR	   A   s    (   R   R   R   R   R	   (    (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyR   8   s   	t   GzipDownloaderc           B   s   e  Z d  Z d „  Z RS(   t   gzipc         C   sX   | j  ƒ  } y% t j d t j | ƒ ƒ j  ƒ  } Wn  t k
 rS } t d | ‚ n X| S(   Nt   fileobjs   Bad encoding: error '%s'(   R   R   t   GzipFilet   StringIOt   IOErrorR    (   R
   R   t   compressed_datat   datat   e(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyR   J   s    	(   R   R   R   R   (    (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyR   F   s   t   HTTPInterfacec           B   s_   e  Z d  Z d Z e ƒ  e ƒ  g Z e j ƒ  Z	 e
 d d d d d g ƒ Z d „  Z d „  Z RS(	   s3   
    Mixin class to provide HTTP functionality
    s2   HTTPInterface/0.0.1 +http://www.phenix-online.org/t   urlR    R   t   origin_req_hostt   unverifiablec   	      C   s†  t  | t ƒ s t d ‚ n  | j ƒ  } d | k s\ t g  | D] } | |  j k ^ q= ƒ rh t d ‚ n  d | k r­ t  | d t ƒ s“ t d ‚ n  t j | d ƒ | d <n  d | k rÛ t  | d t ƒ så t d ‚ qå n
 i  | d <|  j | d d <t	 j
 | �  } y |  j j | ƒ } Wn t	 j k
 r<} t | ‚ n Xd  } x< |  j D]( } | j | ƒ rM| j | ƒ } PqMqMWt d ‚ | S(   Ns   Badly formed queryR#   R    R   s
   User-Agents   Cannot interpret encoding(   t
   isinstancet   dictt
   ValueErrort   copyt   allt   REQUEST_KEYSt   urllibt	   urlencodet
   USER_AGENTt   urllib2t   Requestt   OPENERt   opent   URLErrorR    t   Nonet   DOWNLOADERSR   R   (	   R
   R   t   request_dictt   keyt   http_requestR   R!   R    t
   downloader(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyt	   http_callm   s6    )
	c         C   s2   y |  j  j | ƒ } Wn t j k
 r- t SXt S(   N(   R1   R2   R/   R3   t   Falset   True(   R
   R#   R   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyt   resource_onlineœ   s
    (   R   R   t   __doc__R.   R   R   R5   R/   t   build_openerR1   t   setR+   R:   R=   (    (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyR"   Z   s   	/t   OCAHTTPc           B   sG   e  Z d  Z d Z e j d e j ƒ Z d „  Z d d „ Z	 d „  Z
 RS(   s1   
    Interface to EBI OCA service using HTTP
    s0   http://www.ebi.ac.uk/msd-srv/oca/oca-bin/ocamains   <pre>(.*)</pre>c         C   s%   |  j  d |  j ƒ s! t d ‚ n  d  S(   NR#   s   Cannot contact service(   R=   t   URLR    (   R
   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyt   __init__¯   s    t   seqc         C   sj   i d | j  ƒ  | f d 6} |  j d | ƒ } |  j j | ƒ } | s] t d t |  ƒ ‚ n  | j d ƒ S(   Ns3   http://www.ebi.ac.uk/msd-srv/oca/oca-bin/send-%s?%sR#   R   s   Unexpected response from %si   (   R   R:   t   REGEXt   searchR    t   strt   group(   R
   t
   identifiert   formatR   t   rawt   match(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyR   µ   s    	c         C   s   d S(   Ns   OCA service at EBI(    (   R
   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyt   __str__Ç   s    (   R   R   R>   RB   t   ret   compilet   DOTALLRE   RC   R   RM   (    (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRA   §   s   	t   DbfetchHTTPc           B   s5   e  Z d  Z d Z d „  Z d d d „ Z d „  Z RS(   s5   
    Interface to EBI Dbfetch service using HTTP
    s$   http://www.ebi.ac.uk/cgi-bin/dbfetchc         C   s%   |  j  d |  j ƒ s! t d ‚ n  d  S(   NR#   s   Cannot contact service(   R=   RB   R    (   R
   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRC   Ó   s    t   pdbc         C   s6   i d | j  ƒ  | | j  ƒ  f d 6} |  j d | ƒ S(   Ns<   http://www.ebi.ac.uk/Tools/webservices/rest/dbfetch/%s/%s/%sR#   R   (   R   R:   (   R
   RI   t   databaseRJ   R   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyR   Ù   s    	c         C   s   d S(   Ns   Dbfetch service at EBI(    (   R
   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRM   æ   s    (   R   R   R>   RB   RC   R   RM   (    (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRQ   Ì   s
   	t   RCSBHTTPc           B   s5   e  Z d  Z d Z d „  Z d e d „ Z d „  Z RS(   s.   
    Interface to RCSB service using HTTP
    s$   http://www.rcsb.org/pdb/home/home.doc         C   s%   |  j  d |  j ƒ s! t d ‚ n  d  S(   NR#   s   Cannot contact service(   R=   RB   R    (   R
   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRC   ò   s    RR   c         C   se   | r& i d | | j  ƒ  f d 6} n/ i d d 6i | j  ƒ  d 6d d 6| d 6d 6} |  j d	 | ƒ S(
   Ns&   http://www.rcsb.org/pdb/files/%s.%s.gzR#   s0   http://www.rcsb.org/pdb/download/downloadFile.dot
   fileFormatt   NOt   compressiont   structureIdR    R   (   R   R:   (   R
   RI   RJ   RW   R   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyR   ø   s    c         C   s   d S(   Ns   PDB service at RCSB(    (   R
   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRM     s    (   R   R   R>   RB   RC   R;   R   RM   (    (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRT   ë   s
   	t   NCBIBlastHTTPc           B   sò   e  Z d  Z d Z e j d ƒ Z e j d ƒ Z e j d ƒ Z d „  Z	 d d d d d d d d	 d
 d d d d d „ Z d d d d d d d d d d d d d d d d d d d d d d d d d d d d d „ Z d „  Z d „  Z d „  Z RS(   s,   
    Interface to NCBI Blast using HTTP
    s'   http://blast.ncbi.nlm.nih.gov/Blast.cgis<   QBlastInfoBegin\s+RID\s*=(.*)\s+RTOE\s*=(.*)\s+QBlastInfoEnds-   QBlastInfoBegin\s+Status=(.*)\s+QBlastInfoEnds'   <strong>\s*Format\s+Request\s*</strong>c         C   s%   |  j  d |  j ƒ s! t d ‚ n  d  S(   NR#   s   Cannot contact service(   R=   RB   R    (   R
   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRC   &  s    iô  t   Pairwisei    t	   Alignmentt   HTMLt   not   plaint   yesc         C   s’  | r d | f f n d | r- d | f f n d | rE d | f f n d | r] d | f f n d | ru d | f f n d | r� d | f f n d | r¥ d | f f n d |	 r½ d |	 f f n d |
 rÕ d	 |
 f f n d | rí d
 | f f n d | rd | f f n d | rd | f f n d | r5d | f f n d  | rMd | f f n d! d# g } i |  j  d 6t t t j | ƒ ƒ d 6} |  j d | ƒ S($   Nt
   ALIGNMENTSt   ALIGNMENT_VIEWt   DESCRIPTIONSt   ENTREZ_LINKS_NEW_WINDOWt
   EXPECT_LOWt   EXPECT_HIGHt   FORMAT_ENTREZ_QUERYt   FORMAT_OBJECTt   FORMAT_TYPEt   NCBI_GIt   RESULTS_FILEt   RIDt   SERVICEt   SHOW_OVERVIEWt   CMDt   GetR#   R    R   (    (    (    (    (    (    (    (    (    (    (    (    (    (    (   Rn   Ro   (   (   Rn   Ro   (   RB   R'   t   reducet   operatort   addR:   (   R
   t   ridt
   alignmentst   alignment_viewt   descriptionst   entrez_links_new_windowt
   expect_lowt   expect_hight   format_entrez_queryt   format_objectt   format_typet   ncbi_git   results_filet   servicet   show_overviewR    R   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyR   ,  s&    	
t   Offi   g      $@gü©ñÒMbP?t	   OneWindowt   BLOSUM62iýÿÿÿic   c    #   !   C   s]  | r d | f f n d( | r- d | f f n d) d | f f | rQ d | f f n d* | ri d | f f n d+ | r� d | f f n d, |	 r™ d |	 f f n d- |
 r± d |
 f f n d. | rÉ d	 | f f n d/ | rá d
 | f f n d0 | rù d | f f n d1 | rd | f f n d2 | r)d | f f n d3 | rAd | f f n d4 | rYd | f f n d5 | rqd | f f n d6 | r‰d | f f n d7 | r¡d | f f n d8 | r¹d | f f n d9 | rÑd | f f n d: d | f f d | f f | rd | f f n d; | rd | f f n d< | r1d | f f n d= | rId | f f n d> | rad | f f n d? | ryd | f f n d@ | r‘d | f f n dA | r©d | f f n dB | rÁd | f f n dC dE g  }  i |  j  d" 6t t t j |  ƒ ƒ d# 6}! |  j d$ |! ƒ }  |  j j |  ƒ }" |" s,t d% ‚ n  |  j	 j |  ƒ }" |" sPt d& ‚ n  |" j
 d' ƒ S(F   Nt   AUTO_FORMATt   COMPOSITION_BASED_STATISTICSt   DATABASEt   DB_GENETIC_CODEt	   ENDPOINTSt   ENTREZ_QUERYt   EXPECTt   FILTERt   GAPCOSTSt   GENETIC_CODEt   HITLIST_SIZEt   I_THRESHt   LAYOUTt
   LCASE_MASKt   MATRIX_NAMEt   NUCL_PENALTYt   NUCL_REWARDt   OTHER_ADVANCEDt
   PERC_IDENTt   PHI_PATTERNt   PROGRAMt   QUERYt
   QUERY_FILEt   QUERY_BELIEVE_DEFLINEt
   QUERY_FROMt   QUERY_TOt   SEARCHSP_EFFRl   t	   THRESHOLDt   UNGAPPED_ALIGNMENTt	   WORD_SIZERn   t   PutR#   R    R   s$   Error in parameters, job not starteds   Unexpected response from serveri   (    (    (    (    (    (    (    (    (    (    (    (    (    (    (    (    (    (    (    (    (    (    (    (    (    (    (    (    (   s   CMDR¢   (   (   s   CMDR¢   (   RB   R'   Rp   Rq   Rr   R:   t   SUBMISSION_PAGE_EXTRACTRF   R    t   RID_EXTRACTRH   (#   R
   t   programRS   t   queryt   auto_formatt   composition_based_statisticst   db_genetic_codet	   endpointst   entrez_queryt   expectt   filtert   gapcostst   genetic_codet   hitlist_sizet   I_thresht   layoutt
   lcase_maskt   matrix_namet   nucl_penaltyt   nucl_rewardt   other_advancedt
   perc_identt   phi_patternt
   query_filet   query_believe_deflinet
   query_fromt   query_tot   searchsp_effR   t	   thresholdt   ungapped_alignmentt	   word_sizeR    R   t   result(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyt   putX  sV    $	
c         C   sC   |  j  d | ƒ } |  j j | ƒ } | s6 t d ‚ n  | j d ƒ S(   NRs   s   Unexpected response from serveri   (   R   t   STATUS_EXTRACTRF   t
   ProxyErrorRH   (   R
   Rs   R    RÂ   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyt   status±  s
    c         C   s=   i |  j  d 6t d | f d g ƒ d 6} |  j d | ƒ d  S(   NR#   Rk   Rn   t   DeleteR    R   (   s   CMDRÇ   (   RB   R'   R:   (   R
   Rs   R   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyt   delete½  s    
c         C   s   d S(   Ns   BLAST service at NCBI(    (   R
   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRM   Æ  s    N(   R   R   R>   RB   RN   RO   R¤   RÄ   R£   RC   R4   R   RÃ   RÆ   RÈ   RM   (    (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRY     sj   					"9			t   NCBIBlastStandalonec           B   s_   e  Z d  Z d e d „ Z d „  Z d d d d d „ Z d „  Z d	 „  Z	 d
 „  Z
 d „  Z RS(   s1   
    Interface to NCBI Blast running locally
    t   blastallc         C   sÜ   | |  _  t | ƒ d k r' t d ‚ n  y. t j | d |  j  d t j d t j ƒ} Wn* t k
 r� } t d | d | f ‚ n X| j ƒ  \ } } | r· | r· t d | | f ‚ n  | |  _ t	 j
 ƒ  |  _ i  |  _ d  S(   Ni    s   Empty command linet   shellt   stdoutt   stderrs   Cannot find '%s': %ss!   Error from executable: '%s', '%s'(   t	   osdepboolt   lenR    t
   subprocesst   Popent   PIPEt   OSErrort   communicatet   command_linet	   itertoolst   countt   job_countert   results_for(   R
   RÕ   RÎ   t   processR!   t   outt   err(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRC   Ð  s$    				c         C   s   |  j  j | d ƒ S(   NR   (   RÙ   R   (   R
   t   jobid(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyt   resultsí  s    g      $@Rƒ   i   c	         C   sî   |  j  j ƒ  }	 d | d | d t | ƒ d | d t | ƒ d t | ƒ d t | ƒ f }
 |  j |
 } | d  k r’ d t j | ƒ d	 | | d
 <n  t j | d |  j d t j	 d t j	 d t j
 ƒ} | j d | ƒ \ } } | |  j |	 <|	 S(   Ns   -ps   -ds   -es   -Ms   -ms   -vs   -bs   Executing: t    i    RË   t   stdinRÌ   RÍ   t   input(   RØ   t   nextRG   RÕ   R4   RÐ   t   list2cmdlineRÑ   RÎ   RÒ   t   STDOUTRÔ   RÙ   (   R
   R¥   RS   R¦   t
   maxresultst   expectationt   matrixRu   t   pcmdstrt   jobnamet   job_datat   cmdlineRÚ   RÛ   RÜ   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyt   submitò  s(    "			c         C   s   | |  j  k r d Sd S(   Nt   UNKNOWNt   FINISHED(   RÙ   (   R
   RÝ   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRÆ     s    c         C   s*   |  j  d | ƒ d k r d  S|  j | =d  S(   NRÝ   Rí   (   RÆ   RÙ   (   R
   RÝ   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyt   cleanup%  s    c         C   s   |  j  j ƒ  S(   N(   RÙ   t   keys(   R
   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyt   existing_jobs-  s    c         C   s   d S(   Ns   BLAST standalone executable(    (   R
   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRM   2  s    (   RÊ   N(   R   R   R>   R<   RC   RÞ   R4   Rì   RÆ   Rï   Rñ   RM   (    (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRÉ   Ë  s   	"			t   ClustalWLocalc           B   sª   e  Z d  Z d Z d Z d Z d Z d d „ Z d d d d d d d d d d d d d d d d d „ Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z RS(   s/   
    Interface to clustalw running locally
    s   clustal.inps   clustal.outs   clustal.logs   clustal.errt	   clustalw2c         C   sÎ   t  j d	 k r d } n d } y/ t j | | d g d t j d t j ƒ} Wn& t k
 ru } t d | | f ‚ n X| j ƒ  \ } } t  j j	 | ƒ s¦ t d ‚ n  | |  _
 | |  _ | |  _ i  |  _ d  S(
   Nt   ntt   /t   -t   helpRÌ   RÍ   s   Cannot find '%s': %ss   Job data folder unavailable(   s   nt(   t   ost   nameRÐ   RÑ   RÒ   RÓ   R    RÔ   t   patht   existst   job_data_dirt
   executablet   command_line_arg_leadt   process_data_for(   R
   Rü   Rý   Rþ   RÚ   R!   RÛ   t   error(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRC   A  s"    					c         C   s¨  t  j j |  j ƒ s! t d ‚ n  t j d |  j ƒ } t  j j | |  j ƒ } t	 | d ƒ } | j
 | ƒ | j ƒ  t  j j | |  j ƒ } t	 t  j j | |  j ƒ d ƒ } t	 t  j j | |  j ƒ d ƒ } d | f d | f | rõ d | f n d | rd | f n d | r!d | f n d | r7d	 | f n d | rMd
 | f n d | d  k	 rbd n d | rxd | f n d  |	 rŽd |	 f n d! |
 r¤d |
 f n d" | rºd | f n d# | rÐd | f n d$ | ræd | f n d% | rüd | f n d& | d  k	 rd' n d( | r'd | f n d) | r=d | f n d* g } t j |  j g g  t t j | ƒ D] } d |  j | f ^ qhd | d | ƒ} | |  j | <| S(+   Ns   Job data folder unavailablet   dirt   ws	   infile=%ss
   outfile=%ss   type=%ss	   output=%ss   iteration=%ss
   numiter=%ss   outorder=%st	   quicktrees	   ktuple=%ss	   window=%ss
   pairgap=%ss   topdiags=%ss   score=%ss
   gapopen=%ss	   gapext=%st   endgapss
   gapdist=%ss	   matrix=%ss   %s%sRÌ   RÍ   (    (    (    (    (    (   s	   quicktree(    (    (    (    (    (    (    (    (   s   endgaps(    (    (    (   Rø   Rú   Rû   Rü   R    t   tempfilet   mkdtempt   joint   INPt   filet   writet   closet   OUTt   LOGt   ERRR4   RÐ   RÑ   Rý   Rp   Rq   Rr   Rþ   Rÿ   (   R
   t	   sequencest   typet   outputt	   iterationt   numitert   outorderR  t   ktuplet   windowt   pairgapt   topdiagst   scoret   gapopent   gapextR  t   gapdistRç   t   tmp_dirt   infile_namet   infilet   outfile_namet   logfilet   errfileR    t   dRÚ   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyt   run^  sF    
!!

0	c         C   s   |  j  d | d |  j ƒ S(   NRÝ   R7   (   t
   fetch_fileR  (   R
   RÝ   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyt	   fetch_aln£  s    c         C   s   |  j  d | d |  j ƒ S(   NRÝ   R7   (   R%  R  (   R
   RÝ   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyt	   fetch_log¨  s    c         C   s   |  j  d | d |  j ƒ S(   NRÝ   R7   (   R%  R  (   R
   RÝ   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyt	   fetch_err­  s    c         C   sW   |  j  d | ƒ d k r d St j j | | ƒ } t j j | ƒ rS t | ƒ j ƒ  Sd S(   NRÝ   Rî   R   (   RÆ   Rø   Rú   R  Rû   R	  R   (   R
   RÝ   R7   t	   file_name(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyR%  ²  s    c         C   sP   | |  j  k r d S|  j  | } | rL | j ƒ  d  k r< d Sd  |  j  | <n  d S(   NRí   t   RUNNINGRî   (   Rÿ   t   pollR4   (   R
   RÝ   RÚ   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRÆ   ¿  s    c         C   s¢   |  j  d | ƒ d k r d  S|  j | } | r< | j ƒ  n  t j j | ƒ r” x3 t j | ƒ D]" } t j t j j | | ƒ ƒ q^ Wt j	 | ƒ n  |  j | =d  S(   NRÝ   Rí   (
   RÆ   Rÿ   t   killRø   Rú   Rû   t   listdirt   removeR  t   rmdir(   R
   RÝ   RÚ   R)  (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRï   Ð  s     c         C   s   |  j  j ƒ  S(   N(   Rÿ   Rð   (   R
   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRñ   ã  s    N(   R   R   R>   R  R  R  R  RC   R4   R$  R&  R'  R(  R%  RÆ   Rï   Rñ   (    (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRò   7  s:    3						t   ClustalWSynchronousc           B   s_   e  Z d  Z d Z d Z d d d d d d d d d d d d d d d d d d „ Z d „  Z RS(   s/   
    Interface to clustalw running locally
    s   clustal.inps   clustal.outRó   c         C   s  t  j d k r d } n d } y/ t j | | d g d t j d t j ƒ} Wn& t k
 ru } t d | | f ‚ n X| j ƒ  \ } } | |  _ | |  _	 | r­ d | f n d | rÃ d	 | f n d | rÙ d
 | f n d | rï d | f n d | rd | f n d | d  k	 rd n d | r0d | f n d  |	 rFd |	 f n d! |
 r\d |
 f n d" | rrd | f n d# | rˆd | f n d$ | ržd | f n d% | r´d | f n d& | d  k	 rÉd' n d( | rßd | f n d) | rõd | f n d* g |  _ d  S(+   NRô   Rõ   Rö   R÷   RÌ   RÍ   s   Cannot find '%s': %ss   type=%ss	   output=%ss   iteration=%ss
   numiter=%ss   outorder=%sR  s	   ktuple=%ss	   window=%ss
   pairgap=%ss   topdiags=%ss   score=%ss
   gapopen=%ss	   gapext=%sR  s
   gapdist=%ss	   matrix=%s(   s   nt(    (    (    (    (    (   s	   quicktree(    (    (    (    (    (    (    (    (   s   endgaps(    (    (    (   Rø   Rù   RÐ   RÑ   RÒ   RÓ   R    RÔ   Rý   Rþ   R4   t   options(   R
   Rý   R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  Rç   Rþ   RÚ   R!   RÛ   R   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRC   ð  s:    				c         C   sE  t  j ƒ  } t j j | |  j ƒ } t | d ƒ } | j | ƒ | j ƒ  t j j | |  j	 ƒ } d | f d | f g } t
 j |  j g g  t t j | |  j ƒ D] } d |  j | f ^ q¥ d t d t ƒ} | j ƒ  \ }	 }
 t j j | |  j	 ƒ } t j j | ƒ r%t | ƒ j ƒ  } n d } t j | ƒ | |	 |
 f S(   NR  s	   infile=%ss
   outfile=%ss   %s%sRÌ   RÍ   R   (   R  R  Rø   Rú   R  R  R	  R
  R  R  RÐ   RÑ   Rý   Rp   Rq   Rr   R1  Rþ   R!  R"  RÔ   Rû   R   t   shutilst   rmtree(   R
   R  R  R  R  R   t   filesR#  RÚ   t   logRÜ   t   aln_file_namet   aln(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyR$  -  s(    

7	N(   R   R   R>   R  R  R4   RC   R$  (    (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyR0  è  s*   +t   PhaserOpenMPc           B   s•   e  Z d  Z d Z d Z d Z d „  Z d „  Z d d d d e	 d d „ Z
 d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s   
    Runs phaser
    Rî   Rí   R*  c         C   s.   t  j ƒ  |  _ i  |  _ i  |  _ t |  _ d  S(   N(   RÖ   R×   RØ   t   tempdir_forRÙ   R;   t   debug(   R
   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRC   [  s    		c         C   s.   |  j  d | ƒ |  j k r d  S|  j | Sd  S(   Nt   job_name(   RÆ   t   STATUS_FINISHEDR4   RÙ   (   R
   R;  (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRÞ   c  s    i   c         C   s�  |  j  ƒ  } t j ƒ  |  j | <t j ƒ  } | j t j j	 |  j | d ƒ ƒ | j
 | ƒ | j |  j ƒ | j | | | ƒ | j | ƒ | j | ƒ | j | d ƒ xH | D]@ } x7 t | | ƒ D]% \ } \ } } | j | | | ƒ qÇ Wq° Wx$ | D] \ } } | j | | ƒ qû W|
 r1| j |
 ƒ n  | r`| rP| j | | ƒ q`| j | ƒ n  | rs| j ƒ  n  |  j d | d | ƒ | S(   Nt   PHASERi   R;  Rá   (   t   get_next_job_nameR  R  R9  t   phasert   InputMR_AUTOt   setROOTRø   Rú   R  t   setJOBSt   setMUTER:  t   setREFLt   setSPAC_NAMEt   setCELL6t   addCOMP_PROT_MW_NUMt	   enumeratet   addENSE_PDB_IDt   addSEAR_ENSE_NUMt   setSOLUt   setRESOt   setHIRESt   setMACA_OFFt   start_mr_auto_job(   R
   t   hklt   fpt   sigfpt   space_groupt	   unit_cellt
   asu_weightt
   models_fort   search_ensemblest   search_numbert   partial_structuret   high_resolutiont   low_resolutiont   skip_anisotropy_correctiont   jobsR;  Rá   t   idt   indexR)  R   t   ensemble_idt   number(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyt   submit_mr_auto_jobl  s2    ##c         C   s`   |  j  ƒ  } t j ƒ  } | j | ƒ | j | | ƒ | j |  j ƒ |  j d | d | ƒ | S(   NR;  Rá   (   R>  R?  t   InputMR_DATt   setHKLIt   setLABIRC  R:  t   start_mr_dat_job(   R
   t   hkl_filet   fp_labelt   sigfp_labelR;  Rá   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyt   submit_mr_dat_job®  s    c         C   s”   | |  j  k rt xA t j |  j  | ƒ D]) } t j t j j |  j  | | ƒ ƒ q& Wt j |  j  | ƒ |  j  | =n  | |  j k r� |  j | =n  d  S(   N(   R9  Rø   R-  R.  Rú   R  R/  RÙ   (   R
   R;  R)  (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRï   ¼  s    !c         C   s!   | |  j  k r |  j S|  j Sd  S(   N(   RÙ   R<  t   STATUS_UNKNOWN(   R
   R;  (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRÆ   Í  s    c         C   s   |  j  | ƒ |  j k S(   N(   RÆ   R<  (   R
   R;  (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyt   finishedÖ  s    c         C   s   |  j  j ƒ  S(   N(   R9  Rð   (   R
   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRñ   Û  s    c         C   s2   t  j | ƒ } | j ƒ  | j ƒ  f |  j | <d  S(   N(   R?  t
   runMR_AUTOt   Successt	   getDotSolRÙ   (   R
   R;  Rá   RÂ   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRO  á  s    c         C   sV   t  j | ƒ } | j ƒ  | j ƒ  | j ƒ  | j ƒ  | j ƒ  | j ƒ  f |  j | <d  S(   N(	   R?  t	   runMR_DATRn  t	   getMillert   getFt   getSIGFt   getSpaceGroupNamet   getUnitCellRÙ   (   R
   R;  Rá   RÂ   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRf  ç  s    					c         C   s   t  |  j j ƒ  ƒ S(   N(   RG   RØ   Râ   (   R
   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyR>  ô  s    N(   R   R   R>   R<  Rk  t   STATUS_RUNNINGRC   RÞ   R4   R;   Rb  Rj  Rï   RÆ   Rl  Rñ   RO  Rf  R>  (    (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyR8  R  s(   		3								t   PhaserMultiprocessingc           B   sD   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s   
    Runs phaser
    c         C   s‹   d d  l  } | j j ƒ  d d  l } | j |  _ | j ƒ  |  _ d d  l } | j d ƒ t	 t
 |  ƒ j ƒ  |  j j ƒ  |  _ i  |  _ d  S(   Niÿÿÿÿi   (   t   phaser.pickle_supportt   pickle_supportt   enablet   multiprocessingt   Processt   Managert   managert   omptbxt   omp_set_num_threadst   superRw  RC   R'   RÙ   t   process_for(   R
   R?  R{  R  (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRC   þ  s    c         C   s:   |  j  ƒ  | |  j k r  |  j St t |  ƒ j | ƒ Sd  S(   N(   t	   poll_jobsR‚  Rv  R�  Rw  RÆ   (   R
   R;  (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRÆ     s    
c         C   sX   | |  j  k r> |  j  | j ƒ  |  j  | j ƒ  |  j  | =n  t t |  ƒ j | ƒ d  S(   N(   R‚  t	   terminateR  R�  Rw  Rï   (   R
   R;  (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRï     s
    c         C   sR   | j  d ƒ |  j d t t |  ƒ j d | | f ƒ } | j ƒ  | |  j | <d  S(   Ni   t   targett   args(   RB  R|  R�  Rw  RO  t   startR‚  (   R
   R;  Rá   t   pr(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRO  (  s    	
c         C   s0   | j  d ƒ t t |  ƒ j d | d | ƒ d  S(   Ni   R;  Rá   (   RB  R�  Rw  Rf  (   R
   R;  Rá   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRf  7  s    c         C   sO   xH |  j  j ƒ  D]7 } |  j  | j ƒ  s |  j  | j ƒ  |  j  | =q q Wd  S(   N(   R‚  Rð   t   is_aliveR  (   R
   R;  (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRƒ  @  s    (	   R   R   R>   RC   RÆ   Rï   RO  Rf  Rƒ  (    (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRw  ù  s   						t   SuperposePdbsc           B   s    e  Z d  Z d „  Z d „  Z RS(   s$   
    Runs phenix.superpose_pdbs
    c         C   s   d d  l  } | j j |  _ d  S(   Niÿÿÿÿ(   t"   phenix.command_line.superpose_pdbsRÕ   t   superpose_pdbst   _module(   R
   t   phenix(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRC   M  s    c   	   	   C   s®   d d  l  } | j j d | ƒ | j j d | ƒ g } |  j j j d | ƒ } | j ƒ  } t j ƒ  } |  j j d | d | d t	 d t
 ƒ } | j sž t ‚ | j | j f S(	   Niÿÿÿÿs   input.pdb_file_name_fixed=%ss   input.pdb_file_name_moving=%st   sourcest   paramsR5  t   write_outputt   save_lsq_fit_obj(   t   libtbx.philt   philt   parseR�  t   master_paramsR   t   extractR   R~  R;   R<   t   lsq_fit_objt   AssertionErrort   rmsd(	   R
   t   fixedt   movingt   libtbxt   working_philt   merged_philR�  R5  R~  (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyR$  S  s    	(   R   R   R>   RC   R$  (    (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRŠ  H  s   	t   LsqmanAlignc           B   so   e  Z d  Z d Z d Z e j d e j e j Bƒ Z	 e j d ƒ Z
 d e d „ Z d „  Z d „  Z d	 „  Z RS(
   s6   
    Runs Lsqman to create a structural alignment
    s¶  
!
! align.lsqmac - Gerard Kleywegt @ 2001-11-22/2002-03-06,09-24,25/
!                                  2006-08-01/2007-07-06
!
! LSQMAN macro with Gerard's favourite recipe for superimposing
! just about any two protein structures from scratch
!
! note: only works with LSQMAN version 9.3 or newer !
!
! ==> PDB file of first structure ?
& pdb1 %s
! ==> chain to use in first structure (use _underscore_ for blank) ?
& chn1 %s
!
! ==> PDB file of second structure ?
& pdb2 %s
! ==> chain to use in second structure (use _underscore_ for blank) ?
& chn2 %s
!
! => No modification needed from here...
! initial cut-off (A)
& cutforce 5.0
!
! final cut-off (A)
& cutdist 3.5
!
! nr of DP cycles
& numdp 10
!
! fast_force frag_length
& fffl 30
!
! fast_force frag_step
& fffs 15
!
! fast_force min_match
& ffmm 0.9
!
! fast_force slide_step
& fsli 2
!
echo on
hetatm strip
hydrogen strip
set reset
nmr_mode first
chain_mode non-blank
!
! change the following line for nucleic acids !
atom_type ca
!
delete gmod1
read gmod1 $pdb1
!
delete gmod2
read gmod2 $pdb2
!
set coarse
set optim nmatch
set dist $cutforce
fast_force gmod1 $chn1 gmod2 $chn2 $fffl $fffs $ffmm $fsli
!
!set intermediate
!improve gmod1 $chn1 gmod2 $chn2
!
!set reset
!improve gmod1 $chn1 gmod2 $chn2
!
! optimise operator by dynamic programming; optimise SAS(1) score
set optim s1
dp gmod1 $chn1 gmod2 $chn2 sq $cutdist $numdp
!
!
global gmod1 $chn1 gmod2 $chn2 $cutdist
!
! ALL DONE !!!!
!
quit
s%	  
!
! align_long.lsqmac - Gerard Kleywegt @ 2005-04-27/2006-08-01
!
! LSQMAN macro for aligning larger numbers of residues than with
!        the align.lsqmac macro (the latter would be favoured by
!        most crystallographers; the present by bioinformaticians)
!
! note: only works with LSQMAN version 9.3 or newer !
!
! see: http://xray.bmc.uu.se/usf/lsqman_man.html
!
! this macro derived from Gerard's "crystallographer's" macro
! at: ftp://xray.bmc.uu.se/pub/gerard/omac/align.lsqmac
!
! --------------------------------------------------------------
!
! ------------- define which structures and chains to use ------
!
& pdb1 %s
! ==> PDB file of first structure ?
& chn1 %s
! ==> chain to use in first structure (use _underscore_ for blank) ?
& pdb2 %s
! ==> PDB file of second structure ?
& chn2 %s
! ==> chain to use in second structure (use _underscore_ for blank) ?
!
! ------------------------ end of "user input" -----------------
!
! --------------------------------------------------------------
!
! atom type CA for proteins (change for RNA, DNA, sugars, etc.)
& mytype CA
!
! distance cut-off (A) (very critical)
& cutdist 8.0
!
! max nr of DP cycles (rarely critical)
& numdp 10
!
! fast_force frag_length (influences brute-force step)
& fffl 30
!
! fast_force frag_step (influences brute-force step)
& fffs 10
!
! fast_force min_match ("0.8" means: stop when you have found
! an alignment involving at least 80%% of the residues in the
! shortest protein - obviously the higher this value, the more
! likely that the longest possible alignment will be found,
! but also the more CPU time will be required)
& ffmm 0.8
!
! fast_force slide_step (set to 1 or 2 for "normal" structures, or to
! 5 or 10 when comparing biiiig molecules)
& fsli 2
!
echo off
hetatm strip
hydrogen strip
set reset
nmr_mode first
chain_mode non-blank
!
atom_type $mytype
!
delete gmod1
read gmod1 $pdb1
!
delete gmod2
read gmod2 $pdb2
!
! get initial operator by brute force; optimise nr of aligned residues
set coarse
set optim nmatch
set dist $cutdist
fast_force gmod1 $chn1 gmod2 $chn2 $fffl $fffs $ffmm
!
! optimise operator by dynamic programming; optimise SAS(1) score
set optim s1
dp gmod1 $chn1 gmod2 $chn2 sq $cutdist $numdp
!
! derive structure-based sequence alignment
global gmod1 $chn1 gmod2 $chn2 $cutdist
!
! ALL DONE !!!!
!
quit
s-   ^ \s* Sequence \s+ (\d+) \s+ ([\w\-\?]+) \s*$s   \?t   lsqmanc         C   sV   | |  _  y |  j d d ƒ Wn) t k
 rH } t d |  j  | f ‚ n X| |  _ d  S(   NRá   t   quits   Cannot find '%s': %s(   Rý   t   executeRÓ   R    t   macro(   R
   Rý   R¤  R!   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRC     s    	c   
      C   s¬   |  j  d |  j | | | | f ƒ \ } } |  j j | ƒ } |  j d | d d ƒ } |  j d | d d ƒ }	 | sŒ t | ƒ t |	 ƒ k r¢ t d | | f ‚ n  | |	 f S(   NRá   t   matchesRI   t   1t   2s   Error in LSQMAN:
%s
%s(   R£  R¤  t   EXTRACTt   findallt   reconstructRÏ   R    (
   R
   t   pdb1t   chain1t   pdb2t   chain2RÛ   RÜ   R¥  t   ali1t   ali2(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyR$  ,  s    	"c         C   s_   g  | D] } | d | k r | ^ q } |  j  j d t t j g  | D] } | d ^ qE ƒ ƒ S(   Ni    t   Xi   (   t   UNKOWNt   subRp   Rq   Rr   (   R
   R¥  RI   t   mt   lines(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRª  <  s    )c         C   sR   t  j |  j g d t  j d t  j d t  j ƒ} | j d | ƒ \ } } | | f S(   NRà   RÌ   RÍ   Rá   (   RÐ   RÑ   Rý   RÒ   RÔ   (   R
   Rá   RÚ   RÛ   R   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyR£  B  s    		(   R   R   R>   t   LSQMAN_MACROt   BIOLSQMAN_MACRORN   RO   t   VERBOSEt	   MULTILINER¨  R²  RC   R$  Rª  R£  (    (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyR   h  s   Q[		t	   FFASAlignc           B   s   e  Z d  Z RS(   s   
    Alignment from FFAS
    (   R   R   R>   (    (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRº  O  s   t   DSSPInterfacec           B   s;   e  Z d  Z d Z d Z d „  Z d „  Z e d „  ƒ Z RS(   s   
    Runs DSSP
    t   helixt   sheetc         C   s®   d d  l  } | j j j ƒ  |  _ | j j j ƒ  |  _ |  j j |  j ƒ | j j j ƒ  |  _ |  j j |  j ƒ d d  l } d d  l	 } | j
 j |  _ | j j
 j |  _ d  S(   Niÿÿÿÿ(   t   iotbx.pdb.hierarchyRR   t	   hierarchyt   roott   modelt   append_modelt   chaint   append_chaint   iotbx.pdb.secondary_structuret   mmtbx.secondary_structuret   secondary_structuret   run_ksdssp_directt   _runt   process_recordst   _process(   R
   t   iotbxt   mmtbx(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRC   ]  s    c         C   s…  z^ xH t  | ƒ D]: \ } } | j ƒ  } | | _ d | _ |  j j | ƒ q W|  j j ƒ  } Wd  x' |  j j ƒ  D] } |  j j	 | ƒ qq WX|  j
 | ƒ \ } } | rº | rº t | ‚ n  |  j d | ƒ } d  g t | ƒ }	 xD | j D]9 }
 |  j d |
 ƒ \ } } |  j g | | |	 | | +qé WxX | j D]M } xD | j D]9 } |  j d | ƒ \ } } |  j g | | |	 | | +q@Wq0W|	 S(   NR   t   recordst   sec_str(   RH  t   detached_copyt   resseqt   icodeRÃ  t   append_residue_groupRÀ  t   as_pdb_stringt   residue_groupst   remove_residue_groupRÉ  R(   RË  R4   RÏ   t   helicest   limitst   HELIXt   sheetst   strandst   SHEET(   R
   RÕ  R_  t   rgR)   R    RÎ  t   errorst   annt
   assignmentR¼  R‡  t   endR½  t   strand(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyR$  n  s,    		#c         C   sR   |  j  d k r |  j d k s$ t ‚ |  j } |  j } | | k sH t ‚ | | f S(   NR   (   t   start_icodet	   end_icodeR™  t   start_resseqt
   end_resseq(   RÏ  R‡  Rá  (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRØ  ‘  s
    $		(	   R   R   R>   RÙ  RÜ  RC   R$  t   staticmethodRØ  (    (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyR»  U  s   		#t   CATHc           B   s/   e  Z d  Z d Z d „  Z d „  Z d „  Z RS(   s&   
    Interface to CATH using HTTP
    s   http://http://www.cathdb.infoc         C   s%   |  j  d |  j ƒ s! t d ‚ n  d  S(   NR#   s   Cannot contact service(   R=   RB   R    (   R
   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRC   ¢  s    c         C   s'   i d | d 6} |  j  d | ƒ } | S(   Ns&   http://www.cathdb.info/pdb/%s?view=xmlR#   R   (   R:   (   R
   RI   R   RK   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyR   ¨  s    c         C   s   d S(   Ns   CATH database(    (   R
   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRM   ³  s    (   R   R   R>   RB   RC   R   RM   (    (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyRè  ›  s
   		(#   R?  R,   R/   R   R   Rq   RN   t   timeRÐ   Rø   R  t   globRÖ   t   shutilt	   ExceptionR    t   objectR   R   R   R"   RA   RQ   RT   RY   RÉ   Rò   R0  R8  Rw  RŠ  R   Rº  R»  Rè  (    (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/proxies.pyt   <module>   s@   !M%*¶l±j§O çF