ó
Ä™xTc           @   sß  d  d l  m Z d  d l m Z 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 m Z d  d l Z d  d l Z d  d l m Z d  d l Z d  d l Z d	 Z d
 Z d e j e j f Z d Z d e j j j e e e j f Z e j  j! e ƒ Z" e" j# ƒ  j$ ƒ  Z% d „  Z& e' e j( d „ Z) e* e* e' e j( d „ Z+ d „  Z, d „  Z- d e. f d „  ƒ  YZ/ e' d „ Z0 d „  Z1 d „  Z2 e j( d „ Z3 d „  Z4 d „  Z5 d „  Z6 d S(   iÿÿÿÿ(   t   division(   t   base_pairingt   proteinsN(   t   flex(   t   null_out(   t   easy_run(   t   adopt_init_args(   t   sqrtsŠ  
  verbose = False
    .type = bool
  substitute_n_for_h = None
    .type = bool
    .short_caption = Substitute N for H atoms
    .style = tribool
  restrain_helices = True
    .type = bool
  alpha_only = False
    .type = bool
    .short_caption = Use alpha helices only
  restrain_sheets = True
    .type = bool
  restrain_base_pairs = True
    .type = bool
  remove_outliers = True
    .type = bool
    .short_caption = Filter bond outliers
    .style = tribool
  distance_ideal_n_o = 2.9
    .type = float
    .short_caption = Ideal N-O distance
  distance_cut_n_o = 3.5
    .type = float
    .short_caption = N-O distance cutoff
  distance_ideal_h_o = 1.975
    .type = float
    .short_caption = Ideal H-O distance
  distance_cut_h_o = 2.5
    .type = float
    .short_caption = H-O distance cutoff
  sigma = 0.05
    .type = float
  slack = 0.0
    .type = float
  top_out = False
    .type = bool
s1     group_helix_backbone = False
    .style = bool
s   %s
%st    sÍ  
idealization
{
  enabled = False
    .type = bool
  restrain_torsion_angles = False
    .type = bool
  sigma_on_reference_non_ss = 1
    .type = float
  sigma_on_reference_helix = 1
    .type = float
  sigma_on_reference_sheet = 0.5
    .type = float
  sigma_on_torsion_ss = 5
    .type = float
  sigma_on_torsion_nonss = 5
    .type = float
  sigma_on_ramachandran = 1
    .type = float
  sigma_on_cbeta = 2.5
    .type = float
  n_macro=3
    .type = int
  n_iter=300
    .type = int
}
input
  .style = box auto_align
{
%s
  find_automatically = None
    .type = bool
    .style = bold tribool
  helices_from_phi_psi = False
    .type = bool
    .short_caption = Use phi/psi angles to identify helices
    .expert_level = 2
  force_nucleic_acids = False
    .type = bool
    .short_caption = Force base pair detection
    .help = This will ignore the automatic chain type detection and run       the base pair detection using PROBE even if no nucleic acids are found.       Useful for tRNAs which have a large number of modified bases.
  use_ksdssp = True
    .type = bool
    .help = Use KSDSSP program to annotate secondary structure.  If False, a       built-in DSSP method will be used instead.
    .expert_level = 3
}
h_bond_restraints
  .short_caption = Hydrogen bonding restraints
  .style = box auto_align
{
%s
}
%s
nucleic_acids
  .caption = If sigma and slack are not defined for nucleic acids, the     overall default settings for protein hydrogen bonds will be used     instead.
  .style = box auto_align noauto
{
  sigma = None
    .type = float
    .short_caption = Sigma for nucleic acid H-bonds
    .help = Defaults to global setting
  slack = None
    .type = float
    .short_caption = Slack for nucleic acid H-bonds
    .help = Defaults to global setting
  use_db_values = True
    .type = bool
    .short_caption = Use distances from Rutgers BPS database
#  planar = False
#    .type = bool
#    .short_caption = Use planar restraints by default
#    .style = noauto
  %s
}
c         C   s(   t  j j |  ƒ } t j d | ƒ j ƒ  S(   Nt   source(   t   iotbxt   philt   parset   sec_str_master_philt   fetcht   extract(   t   phil_strt   ss_phil(    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyt   sec_str_from_phil—   s    c         C   sØ  d  } | j r0 | d  k	 s! t ‚ | j ƒ  } n  | j } | j } | j } | j ri | j } | j	 } n  | j ƒ  } t
 j |  j d ƒ } | d IJ| j d | d d d d ƒ | d IJ| sÄ t Sx¢ t |  j ƒ D]‘ \ }	 }
 |
 | k rÔ t |  j |	 <| j re| d	 |
 IJ|  j |	 \ } } | d
 | | j ƒ  j ƒ  IJ| d
 | | j ƒ  j ƒ  IJqeqÔ qÔ W| d |  j j t ƒ IJ| d IJt
 j |  j j |  j ƒ d ƒ } | j d | d d d d ƒ | d IJt S(   Ni
   s:     Distribution of hydrogen bond lengths without filtering:t   ft   prefixs       t   format_cutoffss   %.4fR   s"   Excluding H-bond with length %.3fAs     %ss&     After filtering: %d bonds remaining.s>     Distribution of hydrogen bond lengths after applying cutoff:(   t   Nonet   verboset   AssertionErrort   atomst   remove_outlierst   h_o_distance_maxt   h_o_distance_idealt   substitute_n_for_ht   n_o_distance_maxt   n_o_distance_idealR   t	   histogramt   bond_lengthst   showt   Falset	   enumeratet   flag_use_bondt   bondst   fetch_labelst   id_strt   countt   Truet   select(   t   selft   paramst   pdb_hierarchyt   logR   R   t   distance_maxt   distance_idealt   histt   it   distancet   i_seqt   j_seq(    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyt   analyze_distances›   s@    						

	(
!
c         C   sÖ  d d l  m } d d l m } |  j ƒ  }	 | j |	 j ƒ  d ƒ }
 |  j ƒ  } | d  k rw | j	 |	 j ƒ  t
 ƒ } n! t | t ƒ r˜ | j | ƒ } n  | j } | j j } | j j } | j j } d } d  } } | rð | j } | j } n | j } | j } | j ƒ  } | r#| j ƒ  } n  | d  k r8d } n  | rx× | j D]É } | j } | d k r”| j j r”| d | IJ| d | j IJqHn  t j d	 | d
 |  d | d | d d d | d |
 d | d | d | d | d | d | ƒ } | d k rH| d | j IJqHqHqHWn  | rµx” t | j ƒ D]€ \ } } t j  d | d
 |  d | d d d | d |
 d | d | d | d | d | d | ƒ } | d k r.| d | IJq.q.q.Wn  | rÒt! | j" j# ƒ d k rÒ| j" j$ } | d  k r÷| j$ } n  | j" j% } | d  k r| j% } n  t& j' d | j" j# d
 |  d | d | d | j" j( oR| ƒ t& j) d | d | j" j# d
 |  d |
 d | d | d | d | d | d | d | j" j( d | ƒ } | d k rÒ| d IJqÒn  | S(   Niÿÿÿÿ(   t   hbond(   R   i    g      ð?t   alphas&     Skipping non-alpha helix (class %s):s       %sR-   R.   t   selection_cachet   build_proxiest   weightt   hbond_paramst   hbond_countsR1   t   distance_cutR   t   use_hydrogenst   master_selectionR/   s     No H-bonds generated for '%s't   sheet_paramss$     No H-bonds generated for sheet #%dt
   base_pairst   use_db_valuest   sigmat   slacks(     No H-bonds generated for nucleic acids(*   t   mmtbx.geometry_restraintsR8   t   scitbx.array_familyR   R   t   intt   sizet   atom_selection_cacheR   t   boolR*   t
   isinstancet   strt   seletiont   h_bond_restraintst   restrain_helicest   restrain_sheetst   restrain_base_pairst   distance_ideal_h_ot   distance_cut_h_ot   distance_ideal_n_ot   distance_cut_n_ot   build_simple_hbond_proxiest   build_distance_proxiest   helixt
   helix_typet
   alpha_onlyt	   selectionR   t"   create_helix_hydrogen_bond_proxiesR$   t   sheett"   create_sheet_hydrogen_bond_proxiest   lent   nucleic_acidst	   base_pairRE   RF   R   t   identify_base_pairsRD   t   create_hbond_proxies(   R.   R-   R@   t   as_python_objectsR   RA   R/   R8   R   R   R>   R:   R=   RQ   RR   RS   R<   R1   R?   R;   RZ   t   helix_classt	   n_proxiest   kR_   RE   RF   (    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyt%   hydrogen_bond_proxies_from_selections½   sÀ    	
												c         C   s›   t  j |  j ƒ  d ƒ } x| t |  ƒ D]n \ } \ } } | | \ } } } | | \ }	 }
 } t |	 | d |
 | d | | d ƒ } | | | <q% W| S(   Niÿÿÿÿi   (   R   t   doubleRJ   R$   R   (   R&   t
   sites_cartt	   distancesRi   R5   R6   t   x1t   y1t   z1t   x2t   y2t   z2t   dist(    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyt   _get_distances'  s    ,c         C   sF   t  j j d |  ƒ } t  j j d d  d t j | j ƒ ƒ } | j ƒ  S(   Nt
   file_namest   source_infot   lines(	   R
   t   pdbt   combine_unique_pdb_filest   inputR   R   t
   std_stringt   raw_recordst   construct_hierarchy(   Rv   t   pdb_combinedt   pdb_structure(    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyt   get_pdb_hierarchy0  s    t   managerc           B   s^  e  Z d d d d d  d „ Z e d „ Z e j d „ Z e j d „ Z	 e j d „ Z
 e j d „ Z e j d „ Z e j d „ Z e j e d	 „ Z e j e d
 „ Z d „  Z e j d e d d „ Z d d „ Z d „  Z e j d „ Z d e e d „ Z d „  Z d „  Z d „  Z d „  Z d e d „ Z d „  Z d e d „ Z d „  Z d „  Z RS(   iÿÿÿÿc   
      C   s  t  |  t ƒ  ƒ | j ƒ  } | j ƒ  } | j d ƒ rP | j ƒ  | j ƒ  } n  | j ƒ  |  _ t |  _	 |  j
 d  k r� t j ƒ  j ƒ  |  _
 n  |  j d  k r° t j ƒ  |  _ n  |  j d  k rð | j ƒ  j ƒ  }	 d |	 k pæ d |	 k |  _ n  | j ƒ  |  _ | |  _ d  S(   Ni    t   Ht   D(   R   t   localsR   t   extract_i_seqt   all_eqt   reset_i_seqRJ   t   n_atomsR#   t   _was_initializedR-   R   R   R   R   t   tmp_dirt   ost   getcwdt   assume_hydrogens_all_missingt   extract_elementt   stripRK   R:   t	   pdb_atoms(
   R,   R.   t   sec_str_from_pdb_fileR-   RŽ   R‹   R   R   t   i_seqst   elements(    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyt   __init__7  s$    
	c         C   s   | j  d |  j ƒ S(   Nt   python_object(   t   formatR-   (   R,   t   master_phil(    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyt   as_phil_strQ  s    c         C   s9   |  j  s5 |  j d | ƒ |  j d | ƒ t |  _  n  d  S(   NR/   t   out(   RŠ   t   find_automaticallyt   show_summaryR*   (   R,   R/   (    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyt
   initializeT  s    	c         C   sM  |  j  } | j j } t |  j j ƒ  ƒ } t j g  | D] } | j ^ q7 ƒ } | j	 d ƒ } t
 | j ƒ d k rè t
 | j ƒ d k rè |  j d k r¥ | d IJn  |  j d  k rè | t k rè |  j d k rÜ | d IJn  t } qè n  | r$| r|  j d | ƒ |  _ q$|  j d | ƒ |  _ n  |  j d  k	 rt |  j t ƒ r¾|  j d k ra| d IJn  g  } xB |  j D]7 \ }	 }
 |	 j d | d d d	 |
 ƒ } | j | ƒ qqWd
 j | ƒ } n7 |  j d k rÚ| d IJn  |  j j d | d d ƒ } |  j | d | ƒn  | rS|  j  j j rS|  j d | ƒ } | d  k	 rS| j |  j  _ qSn  t |  j ƒ sn| j j rI| j j rI| j j } t
 | j j  ƒ d k r¶| t k r¶t } q¶n  | rI| rã|  j! d | d | j j ƒ } n |  j" d | ƒ } | d  k	 rFt# j$ j% | ƒ } t& j' d | ƒ j( ƒ  } | j j  |  j  j _  qFqIn  d  S(   Ns       i    s2   No existing secondary structure definitions found.s,   No HELIX or SHEET records found in PDB file.R/   s<     Interpreting HELIX and SHEET records for individual chainst   prefix_scopeR   t	   add_segids   
s4     Interpreting HELIX and SHEET records from PDB filet   forceR	   ()   R-   R{   R›   t   listR.   t   atoms_with_labelsR   R|   t   segidR‡   Ra   RZ   R_   R   R’   R   R#   R*   t   find_sec_str_with_segidst   find_sec_strRM   t   as_restraint_groupst   appendt   joint   apply_phil_strt   helices_from_phi_psit   find_approximate_helicest   find_nucleic_acidst   force_nucleic_acidsRP   RS   Rb   Rc   t   find_base_pairs_with_segidst   find_base_pairsR
   R   R   R   R   R   (   R,   R/   R-   R›   t   atom_labelst   at   segidst	   use_segidt	   ss_paramst
   annotationR£   R   t   ss_params_strt   restraint_groupsRC   t   bp_philt	   bp_params(    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyR›   Z  sh    	%*		c         C   s•   |  j  j j rL |  j j ƒ  } t | ƒ \ } } t j j j	 d | d t
 ƒ Sd d l m } | d IJ| j d |  j d |  j d t ƒ  ƒ j ƒ  Sd  S(	   Nt   recordst
   allow_noneiÿÿÿÿ(   t   dssps     running mmtbx.dssp...R.   R‘   Rš   (   R-   R{   t
   use_ksdsspR.   t   as_pdb_stringt   run_ksdssp_directR
   Ry   t   secondary_structuret   process_recordsR*   t   mmtbx.secondary_structureR¼   R‘   R   t   get_annotation(   R,   R/   t   pdb_strRº   t   stderrR¼   (    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyR¥   –  s    
			c   
      C   sÐ   g  } xÃ |  j  j ƒ  d j ƒ  D]¨ } | j ƒ  d j ƒ  sB q  n  | j ƒ  d j } t j j	 j
 | ƒ } | j ƒ  } t | ƒ \ } } t j j j d | d t ƒ }	 |	 d  k	 r  | j |	 | f ƒ q  q  W| S(   Ni    Rº   R»   (   R.   t   modelst   chainst
   conformerst
   is_proteinR   R£   R
   Ry   t	   hierarchyt   new_hierarchy_from_chainR¾   R¿   RÀ   RÁ   R*   R   R§   (
   R,   R/   t   annotationst   chainR£   t   detached_hierarchyRÄ   Rº   RÅ   R’   (    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyR¤   ¥  s     	c         C   sF   | d IJ| d IJt  j |  j ƒ } | j d | ƒ | j ƒ  } | S(   Ns0     Looking for approximately helical regions. . .s:       warning: experimental, results not guaranteed to work!Rš   (   R   t   find_helices_simpleR.   R"   R¦   (   R,   R/   t   find_helicesR·   (    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyR«   µ  s    

c         C   s%   t  j d |  j d d  d | ƒ } | S(   NR.   R   R/   (   R   t   get_phil_base_pairsR.   R   (   R,   R/   RC   (    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyR¯   ½  s
    			c   	   
   C   sÏ   g  } x¹ |  j  j ƒ  d j ƒ  D]ž } | rJ | j ƒ  d j ƒ  rJ q  n  | j ƒ  d j } t j j	 j
 | ƒ } | j ƒ  } t j d | d d  d | d | ƒ } | d  k	 r  | j | ƒ q  q  Wd j | ƒ S(   Ni    R.   R   R/   RŸ   s   
(   R.   RÆ   RÇ   RÈ   t   is_naR   R£   R
   Ry   RÊ   RË   R¾   R   RÑ   R   R§   R¨   (	   R,   R/   R    RÌ   RÍ   R£   RÎ   RÄ   RC   (    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyR®   Ä  s     		c         C   sk   t  j d t j j | ƒ ƒ } | r= | j d | d d ƒ n  | j ƒ  } | j |  j _ | j	 |  j _	 d  S(   NR	   Rš   R   s       (
   R   R   R
   R   R   R"   R   RZ   R-   R_   (   R,   t   phil_stringR/   R   R   t   new_ss_params(    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyR©   Õ  s    c         C   s"   | j  |  j _  | j |  j _ d  S(   N(   RZ   R-   R_   (   R,   R-   (    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyt   apply_paramsÝ  s    c   
      C   sö   |  j  } |  j  j j } |  j  j j d  k r: |  j } n |  j  j j rR t } n t } t d |  j	 d | d | d | d | d | d | ƒ } t
 | j t ƒ r² t | j ƒ }	 n | j j ƒ  }	 | d IJ|	 d	 k rä | d
 IJn | d |	 IJ| S(   NR.   R-   R@   Rf   R   RA   R/   R   i    s     No hydrogen bonds defined.s     %d hydrogen bonds defined.(   R-   RP   R   R   R   RŽ   R#   R*   Rj   R.   RM   t   proxiesR¡   Ra   RJ   (
   R,   R/   R=   Rf   RA   R-   R   R@   R;   Rh   (    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyRe   á  s.    				
c         C   sÃ   | d  k	 rK t | t ƒ r0 t j j | ƒ } n  t j d | ƒ j ƒ  } n	 |  j	 } d d l
 m } t d |  j d | d |  j d t d |  j	 j j d	 d  d
 t j ƒ  ƒ } | j | j ƒ } | S(   NR	   iÿÿÿÿ(   R8   R.   R-   R@   Rf   R   RA   R/   (   R   RM   RN   R
   R   R   R   R   R   R-   RG   R8   Rj   R.   RŽ   R*   RP   R   t	   cStringIOt   StringIOt   get_simple_bondsRÖ   (   R,   t   selection_philR-   R8   R;   R&   (    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyRÙ     s     		
c         C   sš   |  j  j } | d ƒ } |  j d d d t ƒ } | j t ƒ } |  j d d d t ƒ } | j t ƒ } | j ƒ  d k r| d S| | j ƒ  | | j ƒ  f S(   Ns%   name N and (altloc ' ' or altloc 'A')t   limits   name Nt   main_conf_onlyi    g        (   g        g        (   R:   t
   iselectiont   alpha_selectionR*   R)   t   beta_selectionRJ   (   R,   t   iselt   calphat
   alpha_selet   n_alphat	   beta_selet   n_beta(    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyt   calculate_structure_content  s    c         C   st   |  j  ƒ  \ } } t |  j j ƒ } t |  j j ƒ } | d IJ| d | | f IJ| d | d | d f IJd  S(   Ns(   Secondary structure from input PDB file:s"     %d helices and %d sheets defineds     %.1f%% alpha, %.1f%% betaid   (   Ræ   Ra   R-   RZ   R_   (   R,   Rš   t
   frac_alphat	   frac_betat	   n_helicest   n_sheets(    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyRœ   "  s    
c   	      C   s×   |  j  j } g  } x¾ |  j j D]° } | j d  k	 r | rO | j d k rO q n  d | j g } | d  k	 r” t | t ƒ s€ t ‚ | j	 d | ƒ n  | rª | j	 d ƒ n  | d j
 | ƒ ƒ } | j	 | ƒ q q W| S(   NR9   s   (%s)s   (altloc ' ' or altloc 'A')s    and (   R:   R]   R-   RZ   R   R[   RM   RN   R   R§   R¨   (	   R,   RÛ   RÜ   R\   t   selet   all_selectionsRZ   t   clausest	   helix_sel(    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyt   helix_selections*  s    c         C   s    g  |  j  j D] } | j ^ q S(   N(   R-   RZ   R[   (   R,   RZ   (    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyt   get_helix_types<  s    c         K   s:   t  j |  j ƒ } x! |  j | �  D] } | | O} q" W| S(   N(   R   RL   R‰   Rï   (   R,   t   kwdst   whole_selectionRZ   (    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyt   helix_selection?  s    c         K   s   |  j  | �  S(   N(   Ró   (   R,   Rñ   (    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyRÞ   F  s    c         K   s   |  j  | �  S(   N(   Rï   (   R,   Rñ   (    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyt   alpha_selectionsI  s    c         C   s  |  j  j } g  } xþ |  j j D]ð } t j |  j ƒ } g  } | d  k	 rr t | t	 ƒ s^ t
 ‚ | j d | ƒ n  | rˆ | j d ƒ n  d | j g } | d j | | ƒ ƒ }	 | |	 O} xD | j D]9 }
 d |
 j g } | d j | | ƒ ƒ }	 | |	 O} qÅ W| j | ƒ q W| S(   Ns   (%s)s   (altloc ' ' or altloc 'A')s    and (   R:   R]   R-   R_   R   RL   R‰   R   RM   RN   R   R§   t   first_strandR¨   t   strand(   R,   RÛ   RÜ   Rë   Rì   R_   t   sheet_selectionRí   t   main_clauset
   strand_selRö   (    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyt   beta_selectionsL  s&    
c         K   s:   t  j |  j ƒ } x! |  j | �  D] } | | O} q" W| S(   N(   R   RL   R‰   Rú   (   R,   Rñ   Rò   R_   (    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyRß   a  s    c         C   sÂ   |  j  j } g  } x© |  j j j D]˜ } | j d  k	 r" | j d  k	 r" d | j | j f g } | d  k	 r | j d | ƒ n  | r• | j d ƒ n  | d j	 | ƒ ƒ } | j | ƒ q" q" W| S(   Ns   ((%s) or (%s))s   (%s)s   (altloc ' ' or altloc 'A')s    and (
   R:   R]   R-   Rb   Rc   t   base1R   t   base2R§   R¨   (   R,   RÛ   RÜ   Rë   Rì   t   bpRí   t   bp_sele(    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyt   base_pair_selectionsg  s    c         K   s:   t  j |  j ƒ } x! |  j | �  D] } | | O} q" W| S(   N(   R   RL   R‰   Rÿ   (   R,   Rñ   Rò   R_   (    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyt   base_pair_selectionu  s    c         C   s�   t  j |  j d ƒ } t  j |  j d ƒ } t  j |  j d ƒ } |  j ƒ  } |  j ƒ  } | j | | j | ƒ ƒ | j | | j | ƒ ƒ | S(   Ni    i   i   (   R   RI   R‰   RÞ   Rß   t   set_selectedR+   (   R,   t   sec_strt	   all_alphat   all_betat   helicest   sheets(    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyt   selections_as_ints{  s    N(    t   __name__t
   __module__R   R•   R   R™   t   syst   stdoutR�   R›   R¥   R¤   R«   R¯   R#   R®   R©   RÕ   Re   RÙ   Ræ   Rœ   Rï   Rð   Ró   RÞ   Rô   Rú   Rß   Rÿ   R   R  (    (    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyR‚   6  sB   <								c   	      C   sg   | j  } y | j ƒ  } Wn t k
 r2 d  } n X| j } t d | d | d |  d | d | ƒ } | S(   NR.   R’   R-   RŽ   R‹   (   t   all_chain_proxiest   extract_secondary_structuret	   ExceptionR   R.   R‚   (	   R-   t   processed_pdb_fileR‹   R/   RŽ   t   acpR’   R.   t   structure_manager(    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyt   process_structure…  s    	
		c         C   sY   xR |  j  ƒ  D]D } x; | j ƒ  D]- } x$ | j ƒ  D] } | j ƒ  r3 t Sq3 Wq  Wq Wt S(   N(   RÆ   RÇ   RÈ   RÒ   R*   R#   (   R.   t   modelRÍ   t	   conformer(    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyR¬   •  s    c          C   sw   t  j j d d ƒ s$ t d ƒ ‚ n  t  j j d ƒ }  t j d k rR |  d 7}  n  t j j |  ƒ ss t d ƒ ‚ n  |  S(   Nt   namet   ksdssps   ksdssp module is not configureds   ksdssp/exe/ksdsspt   nts   .exes"   ksdssp executable is not available(	   t   libtbxt   envt
   has_modulet   RuntimeErrort   under_buildRŒ   R  t   patht   isfile(   t   exe_path(    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyt   get_ksdssp_exe_path�  s    c         C   sW   t  j j |  ƒ s! t d ƒ ‚ n  t ƒ  } | d IJt j d d | |  f ƒ } | j S(   Ns   File %s not found.s4     Running KSDSSP to generate HELIX and SHEET recordst   commands   %s %s(   RŒ   R  R  R  R   R   t   fully_bufferedt   stdout_lines(   t	   file_nameR/   R  t
   ksdssp_out(    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyt
   run_ksdssp§  s    	
c         C   s1   t  ƒ  } t j d | d |  ƒ } | j | j f S(   NR!  t   stdin_lines(   R   R   R"  R#  t   stderr_lines(   RÄ   R  R%  (    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyR¿   ±  s    	c         C   sl   d d l  m } t j j |  ƒ s( t ‚ | j |  d d ƒ} | j j } | j	 ƒ  j
 ƒ  t d | ƒ } | S(   Niÿÿÿÿ(   t   file_readert
   force_typeRy   R.   (   R
   R)  RŒ   R  R  R   t   any_filet   file_objectRÊ   R   Rˆ   R‚   (   t   pdb_fileR)  t   pdb_inR.   t
   ss_manager(    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyt   manager_from_pdb_file¶  s    c         C   s    t  |  ƒ } | j ƒ  | j ƒ  S(   N(   R0  R›   Ræ   (   R-  R/  (    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyRæ   ¿  s    
(7   t
   __future__R    RÂ   R   R   t	   iotbx.pdbR
   t   iotbx.pdb.secondary_structuret
   iotbx.philRH   R   t   libtbx.utilsR   R  R   R   t   libtbx.load_envR×   t   mathR   R
  RŒ   t   ss_restraint_params_strt   ss_tardy_params_strt   helix_group_params_strt   sheet_group_params_strt   ss_group_params_strRy   RÀ   t   ss_input_params_strt   dna_rna_params_strt   sec_str_master_phil_strR   R   R   R   R   t   default_paramsR   R   R  R7   R#   Rj   Ru   R�   t   objectR‚   R  R¬   R   R&  R¿   R0  Ræ   (    (    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/secondary_structure/__init__.pyt   <module>   sN   (	Q	&c			ÿ Q		

			