ó
¥™xTc           @   sµ  d  Z  d d l m Z d d l m Z m Z d d l m Z d d l m Z d d l m Z d d l m	 Z	 d d l m
 Z
 d d	 l m Z d d
 l m Z d d l m Z d d l m Z d d l m Z m Z m Z d d l m Z m Z d d l m Z m Z d d l Z d d l Z d d l Z d d l Z d Z d „  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 S(   s’   
Classes for MolProbity validation, combining all other analyses in
mmtbx.validation, which use the same APIs for storing and displaying results.
iÿÿÿÿ(   t   division(   t
   validationt   residue(   t   model_properties(   t   experimental(   t   rna_validate(   t
   clashscore(   t
   restraints(   t   ramalyze(   t   rotalyze(   t   cbetadev(   t   waters(   t   make_headert   make_sub_headert   format_value(   t   slots_getstate_setstatet+   slots_getstate_setstate_default_initializer(   t   null_outt   SorryNsŒ  
clashscore = True
  .type = bool
ramalyze = True
  .type = bool
rotalyze = True
  .type = bool
cbetadev = True
  .type = bool
nqh = True
  .type = bool
rna = True
  .type = bool
model_stats = True
  .type = bool
restraints = True
  .type = bool
rfactors = True
  .type = bool
real_space = True
  .type = bool
waters = True
  .type = bool
seq = True
  .type = bool
xtriage = False
  .type = bool
c           C   s   t  j j t ƒ j ƒ  S(   s7   
  Default flags for analyses to perform (all True).
  (   t   libtbxt   philt   parset   master_phil_strt   extract(    (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt   molprobity_flags:   s    t
   molprobityc           B   sÖ  e  Z d  Z d: Z d d d d d d d	 d
 d d d d d d d d d d d d g Z d „  Z d; d; d; d; d; d; d; d; d; d; d; e e d; e d d e e e d; d; d d „ Z	 d „  Z
 e j e e e d „ Z d „  Z d „  Z e d  „ Z e d! „ Z d" „  Z e d# „ Z d$ „  Z d% „  Z d& „  Z d' „  Z d( „  Z d) „  Z d* „  Z d+ „  Z d, „  Z d- „  Z d. „  Z d/ „  Z d0 „  Z  d1 „  Z! d2 „  Z" e d3 „ Z# d4 „  Z$ d5 „  Z% d6 „  Z& d7 „  Z' d8 „  Z( d9 „  Z) RS(<   sc  
  Comprehensive validation.  At a minimum this performs the standard MolProbity
  analyses (ramalyze, rotalyze, cbetadev, clashscore).  If a geometry
  restraints manager is available, the deviations from standard covalent
  geometry will also be displayed.  Passing an fmodel object enables the
  re-calculation of R-factors and real-space correlation.

  :param pdb_hierarchy: model PDB hierarchy (required)
  :param xray_structure: model X-ray scatterers
  :param fmodel: mmtbx.f_model.manager object, after bulk solvent/scaling
  :param fmodel_neutron: separate Fmodel manager for neutron data (used in
                         phenix.refine for join X/N refinement)
  :param geometry_restraints_manager: geometry restraints extracted by                                       mmtbx.monomer_library.pdb_interpretation
  :param sequences: parsed sequence objects (from iotbx.bioinformatics)
  :param crystal_symmetry: cctbx.crystal.symmetry object
  :param flags: object containing boolean flags for analyses to perform
  :param header_info: extracted statistics from PDB file header
  :param raw_data: input data before French-Wilson treatment, etc.
  :param unmerged_data: separate unmerged intensities for merging statistics
  :param all_chain_proxies: object containing restraints information and       advanced selections from mmtbx.monomer_library.pdb_interpretation
  :param keep_hydrogens: don't discard and replace existing hydrogens for       clashscore calculation
  :param nuclear: use nuclear hydrogen distances (for neutron experiments)
  :param save_probe_unformatted_file: file name for Probe output suitable for       display in Coot
  :param show_hydrogen_outliers: show geometry outliers for hydrogen atoms
  :param min_cc_two_fofc: Fo-Fc map cutoff for real-space outliers
  :param n_bins_data: Number of resolution bins for data statistics
  :param count_anomalous_pairs_separately: count F+ and F- as separate       reflections (default=False)
  :param outliers_only: only display validation outliers
  :param use_pdb_header_resolution_cutoffs: use resolution cutoff(s)       specified in PDB header for data statistics
  i   i   R   R	   R
   t   clashest	   nqh_flipst   rnaR   t   missing_atomst
   data_statst   neutron_statst
   real_spacet   crystal_symmetryt   model_statsR   t   header_infot   mergingt   sequencet   xtriaget   _multi_criteriont	   file_namec         C   sg   x* | j  ƒ  D] \ } } t |  | | ƒ q Wx3 |  j D]( } t |  | ƒ s7 t |  | d  ƒ q7 q7 Wd  S(   N(   t   itemst   setattrt	   __slots__t   hasattrt   None(   t   selft   statet   namet   value(    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt   __setstate__‚   s
      gš™™™™™é?i
   t   500c         C   s\  x! |  j  D] } t |  | d  ƒ q
 W| j ƒ  j ƒ  | d  k r| | d  k	 rX | j } q| | d  k	 r| | j d | ƒ } q| n  | |  _ | d  k rµ | d  k	 rµ | j ƒ  j ƒ  |  _ n  |	 |  _	 | d  k rÖ t
 ƒ  } n  | j ƒ  r®| j rt j d | d | d t ƒ  d t ƒ |  _ n  | j rTt j d | d | d | d t ƒ  d t ƒ |  _ n  | j rŠt j d | d | d t ƒ  d t ƒ |  _ n  | j r®t j d | ƒ |  _ q®n  | j ƒ  r| j rt j j d d ƒ r| d  k	 rt j d | d	 | d | d
 d  ƒ |  _ qn  | j rSt j d | d | d | d | d t ƒ  d t ƒ |  _ n  | j r™| d  k	 r™t j d | d | d | d | d | ƒ |  _ n  | d  k	 rý| j  rý| d  k	 sÀt! ‚ t  j" d | d | d	 | d | d t# | d d  ƒ ƒ |  _  n  | d  k	 rE| j$ rEt% j& d | d | d t ƒ  d t d t ƒ |  _% n  | d  k	 rþ| r„|	 d  k	 r„| j' d |	 j( d |	 j) ƒ } n  | j* r´t+ j, | d |
 d | d | ƒ|  _- n  | j. rçt. j. d | d | d | d t ƒ |  _. n  | j/ rt+ j/ d | d | d  | ƒ |  _/ n  | d  k	 rht+ j0 d! | j ƒ  d" | j1 ƒ  d# | j2 ƒ  d$ | d% | d | ƒ |  _3 n  | j4 rþd& d  l5 } t6 | j1 ƒ  ƒ j7 ƒ  } |
 d  k	 r¼| j8 d' |
 ƒ \ } } n | j ƒ  } | j9 j4 j: d( | d) | d* | d+ t ƒ  ƒ |  _4 qþn  | d  k	 r4| j* r4t+ j, | d | d t ƒ|  _; n  | j< ƒ  d, k rXt= | ƒ |  _> n  d  S(-   NR!   t   pdb_hierarchyt   outliers_onlyt   outt   quiett   data_versionR0   t	   suitenamet   geometry_restraints_managert   paramst   save_probe_unformatted_filet   nucleart   keep_hydrogenst   verboset   xray_structuret   all_chain_proxiest	   ignore_hdt   ligand_selectiont   cdlt   use_cdlt	   sequencest   logt   include_secondary_structuret   extract_coordinatest   d_mint   d_maxt   raw_datat   n_binst    count_anomalous_pairs_separatelyt   fmodelt   collect_allt   cc_mint   f_obst   f_modelt   r_free_flagst   unmerged_i_obst	   anomalousiÿÿÿÿt   othert
   miller_obst   miller_calct   unmerged_obst   text_outi   (?   R+   R*   R-   t   atomst   reset_i_seqR@   t   extract_xray_structureR!   RR   R#   R   t   contains_proteinR   R   t   TrueR	   R
   t   nqhR   R   t   contains_rnaR   R   t   envt
   has_moduleR   t   rna_validationt   FalseR   R"   R   t   model_statisticsR   t   AssertionErrort   combinedt   getattrt   seqR%   R   t   resolution_filterRJ   RK   t   rfactorsR   t   data_statisticsR   R   R    t   merging_and_model_statisticsRS   RT   R$   R&   t   mmtbx.scaling.xtriaget   abst#   set_observation_type_xray_amplitudet   common_setst   scalingt   xtriage_analysesR   t   models_sizet   multi_criterion_viewR'   (   R.   R4   R@   RO   t   fmodel_neutronR:   R!   RF   t   flagsR#   RL   t   unmerged_dataRA   R>   R=   R<   t   show_hydrogen_outlierst   min_cc_two_fofct   n_bins_dataRN   R5   t!   use_pdb_header_resolution_cutoffsR(   RC   t   rotamer_libraryR0   t   mmtbxRS   t   obs(    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt   __init__‡   sô    																															c         C   sc   d |  j |  j |  j g k r" d Sd d l m } | j d |  j j ƒ  d |  j j d |  j j	 ƒ S(   sö   
    Compute overall measure of (protein!) structure quality based on an
    empirical formula combining clashscore, rotamer outliers, and Ramachandran
    favored statistics.  The result is on approximately the same scale as
    resolution.
    iÿÿÿÿ(   t   utilsR   t   rota_outt   rama_favN(
   R-   R   R	   R   t   mmtbx.validationRƒ   t   molprobity_scoret   get_clashscoret   out_percentt   fav_percent(   R.   Rƒ   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyR‡     s    	c         C   s  |  j  d k	 r+ |  j  j ƒ  j d | ƒ n  |  j d k	 rÜ t d d | ƒ|  j j d | d d ƒ |  j d k	 rž t d d | ƒ|  j j d | d d ƒ n  |  j d k	 rÜ t d d | ƒ|  j j d | d d ƒ qÜ n  |  j	 d k	 rt d d | ƒ|  j	 j d d d | ƒ n  |  j
 d k	 rRt d d | ƒ|  j
 j d | d d ƒ n  t d	 d | ƒ|  j d k	 r£t d
 d | ƒ|  j j d | d d d | ƒ n  |  j d k	 rät d d | ƒ|  j j d | d d d | ƒ n  |  j d k	 r%t d d | ƒ|  j j d | d d d | ƒ n  |  j d k	 r`t d d | ƒ|  j j d | d d ƒ n  |  j d k	 r›t d d | ƒ|  j j d | d d ƒ n  |  j d k	 rÜt d d | ƒ|  j j d | d d d | ƒ n  | st d d | ƒ|  j d | d d d | ƒ n  |  S(   sK   
    Comprehensive output with individual outlier lists, plus summary.
    R6   s   Experimental datat   prefixs     s    Residues with poor real-space CCs   Suspicious water moleculess   Model propertiess   Geometry restraintss   Molprobity validations   Ramachandran anglesR5   s   Sidechain rotamerss   C-beta deviationss   Bad clashess   Asn/Gln/His flipss   RNA validationt   Summaryt   show_percentilesN(   R&   R-   t   summarize_issuest   showR   R   R    R   R   R"   R   R   R	   R
   R   R   R   t   show_summary(   R.   R6   R5   t   suppress_summaryR�   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyR�   ,  sR    """"
c         C   s   d } } } } } } |  j d k	 r; |  j j ƒ  } n  |  j d k	 rb |  j j ƒ  \ } } n  |  j d k	 r™ |  j j |  j j } } |  j j } na |  j	 d k	 rú |  j	 j |  j	 j } } |  j	 j } |  j d k rú |  j	 j
 } |  j	 j } qú n  |  j ƒ  } t d t |  j d d ƒ d t |  j d d ƒ d t |  j d d ƒ d t |  j d d ƒ d | d	 | d
 | d | d | d | d | d t |  j	 d d ƒ ƒ S(   sž   
    Condense results into a compact object - for compatibility with
    (now obsolete) mmtbx.validation_summary, and use in high-throughput
    analyses
    t   rama_outliersR‰   t   rama_favoredRŠ   t   rotamer_outlierst   c_beta_deviationst
   n_outliersR   t	   bond_rmsdt
   angle_rmsdt   mpscoreRJ   t   r_workt   r_freet   programt   refinement_programN(   R-   R   Rˆ   R   t   get_bonds_angles_rmsdsR   Rš   R›   RJ   R#   t	   rms_bondst
   rms_anglesR‡   t   summaryRj   R   R	   R
   (   R.   R   Rš   R›   RŸ   R    RJ   R™   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt	   summarize[  s8    c         O   s   |  j  ƒ  j | | Ž  S(   s@   
    Print summary of outliers or scores for each analysis.
    (   R¢   R�   (   R.   t   argst   kwds(    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyR�   ~  s    c         C   s?   | r t  |  j d d  ƒ St  |  j d t  |  j d d  ƒ ƒ Sd  S(   Nt   r_work_outerRš   (   Rj   R   R-   R#   (   R.   t   outer_shell(    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyRš   „  s    c         C   s?   | r t  |  j d d  ƒ St  |  j d t  |  j d d  ƒ ƒ Sd  S(   Nt   r_free_outerR›   (   Rj   R   R-   R#   (   R.   R¦   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyR›   ‹  s    c         C   s6   |  j  d  k	 r |  j  j S|  j d  k	 r2 |  j j Sd  S(   N(   R   R-   RJ   R#   (   R.   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyRJ   ’  s    
c         C   sH   |  j  d  k	 rD | r+ |  j  j |  j  j f S|  j  j |  j  j f Sn  d  S(   N(   R   R-   t   d_max_outert   d_min_outerRK   RJ   (   R.   R¦   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt	   d_max_min˜  s    c         C   s,   |  j  d  k	 r( |  j  j ƒ  \ } } | Sd  S(   N(   R   R-   Rž   (   R.   RŸ   R    (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyRŸ   Ÿ  s    c         C   s,   |  j  d  k	 r( |  j  j ƒ  \ } } | Sd  S(   N(   R   R-   Rž   (   R.   RŸ   R    (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyR    ¤  s    c         C   s   t  |  j d d  ƒ S(   NRŠ   (   Rj   R   R-   (   R.   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyR“   ©  s    c         C   s   t  |  j d d  ƒ S(   NR‰   (   Rj   R   R-   (   R.   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyR’   ¬  s    c         C   s   |  j  d  k	 r |  j  j Sd  S(   N(   R   R-   t   percent_allowed(   R.   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt   rama_allowed¯  s    
c         C   s   t  |  j d d  ƒ S(   NR‰   (   Rj   R	   R-   (   R.   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt   rota_outliers´  s    c         C   s   t  |  j d d  ƒ S(   NR–   (   Rj   R
   R-   (   R.   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt   cbeta_outliers·  s    c         C   s   t  |  j d d „  ƒ ƒ  S(   NRˆ   c           S   s   d  S(   N(   R-   (    (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt   <lambda>»  s    (   Rj   R   (   R.   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyR   º  s    c         C   s%   t  |  j d d  ƒ } t  | d d  ƒ S(   Nt   allt   b_mean(   Rj   R"   R-   (   R.   t   overall_stats(    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt
   b_iso_mean½  s    c         C   s   t  |  j d d „  ƒ ƒ  S(   Nt   space_groupc           S   s   d  S(   N(   R-   (    (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyR¯   Â  s    (   Rj   R!   (   R.   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyR´   Á  s    c         C   s   t  |  j d d „  ƒ ƒ  S(   Nt   space_group_infoc           S   s   d  S(   N(   R-   (    (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyR¯   Å  s    (   Rj   R!   (   R.   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyRµ   Ä  s    c         C   s   t  |  j d d „  ƒ ƒ  S(   Nt	   unit_cellc           S   s   d  S(   N(   R-   (    (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyR¯   È  s    (   Rj   R!   (   R.   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyR¶   Ç  s    c         C   s   t  |  j d d  ƒ S(   Nt   twin_law(   Rj   R   R-   (   R.   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyR·   Ê  s    c         C   s%   t  |  j d d ƒ } t  | d d ƒ S(   sm   
    Returns the resolution bins containing F(model) statistics; see
    mmtbx.f_model_info for details.
    t   infot   binsN(   Rj   R   R-   (   R.   t   fmodel_info(    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt   fmodel_statistics_by_resolutionÍ  s    c         C   s6   |  j  ƒ  } | d k	 r2 d d l m } | | ƒ Sd S(   sq   
    Wrapper for fmodel_statistics_by_resolution(), returns object suitable for
    routines in wxtbx.plots.
    iÿÿÿÿ(   t   export_bins_table_dataN(   R»   R-   t   mmtbx.f_model_infoR¼   (   R.   R¹   R¼   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt   fmodel_statistics_graph_dataÕ  s
    
c         C   sK   |  j  j } | r% | |  j  j 8} n  |  j j } | d k sC t ‚ | | S(   Ni    (   R"   t   n_atomst   n_hydrogensR   t   n_reflRh   (   R.   t   assume_riding_hydrogensR¿   RÁ   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt   atoms_to_observations_ratioà  s    c         C   s   t  ƒ  ‚ d  S(   N(   t   NotImplementedError(   R.   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt   as_mmcif_recordsè  s    c         C   s  |  j  d  k r d  S|  j  j s|  j d  k	 rG |  j  j |  j j ƒ n  |  j d  k	 ro |  j  j |  j j ƒ n  |  j d  k	 r— |  j  j |  j j ƒ n  |  j d  k	 r¿ |  j  j |  j j ƒ n  |  j	 d  k	 rç |  j  j |  j	 j ƒ n  |  j
 d  k	 r|  j  j |  j
 j ƒ qn  |  j  S(   N(   R'   R-   t   is_populatedR    t   process_outlierst   resultsR   R   R	   R
   R   (   R.   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt   as_multi_criterion_viewë  s     c         C   sX   |  j  d  k	 r |  j  j ƒ  n  |  j d  k	 r> |  j j ƒ  n  |  j ƒ  } | j ƒ  d  S(   N(   R   R-   t   display_wx_plotsR	   RÉ   (   R.   t   mc(    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyRÊ   ý  s    c         C   sœ  t  j j d d d t j j ƒ } | d k r< t d ƒ ‚ n  t | d ƒ } | j	 d ƒ | j	 d ƒ | j	 t | ƒ j
 ƒ  ƒ | j	 d ƒ | j	 d ƒ |  j d k	 rÄ | j	 d	 |  j j ƒ  ƒ n  |  j d k	 rð | j	 d
 |  j j ƒ  ƒ n  |  j d k	 r| j	 d |  j j ƒ  ƒ n  |  j d k	 r�| j	 d |  j j ƒ  ƒ |  j j d k	 r�| j	 d |  j j ƒ | j	 d ƒ q�n  | j	 d ƒ | j ƒ  d S(   s`   
    Write a Python script for displaying outlier lists with click-to-recenter
    enabled.
    t   relative_paths(   cctbx_project/cootbx/validation_lists.pyt   tests+   Can't find template Python script for Coot.t   ws-   # script auto-generated by phenix.molprobity
s   
s
   data = {}
s   data['rama'] = %s
s   data['rota'] = %s
s   data['cbeta'] = %s
s   data['probe'] = %s
s4   handle_read_draw_probe_dots_unformatted("%s", 0, 0)
s   show_probe_dots(True, True)
s/   gui = coot_molprobity_todo_list_gui(data=data)
N(   R   Rc   t   find_in_repositoriest   ost   patht   isfileR-   R   t   opent   writet   readR   t   as_coot_dataR	   R
   R   t
   probe_filet   close(   R.   R(   t   coot_scriptt   f(    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt   write_coot_script  s2    	c         C   s-  i  } x | D]} d  } | d k r4 |  j ƒ  } nç | d k rO |  j ƒ  } nÌ | d k r^ n½ | d k ry |  j ƒ  } n¢ | d k r” |  j ƒ  } n‡ | d k r¯ |  j ƒ  } nl | d k rÊ |  j ƒ  } nQ | d k rå |  j ƒ  } n6 | d	 k r |  j ƒ  } n | d
 k r|  j	 ƒ  } n  | | | <q W| S(   NRš   R›   t   wilson_bR“   R’   R”   R   R—   R˜   t   adp_mean_all(
   R-   Rš   R›   R“   R’   R­   R   RŸ   R    R³   (   R.   t
   stat_namest   statsR0   t   val(    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt   get_polygon_statistics$  s2              c      	   C   sï   |  } d t  d | j ƒ  ƒ f d t  d | j ƒ  ƒ f d t  d | j ƒ  ƒ f d t  d | j ƒ  ƒ f d t  d | j ƒ  ƒ f d	 t  d | j ƒ  ƒ f g } |  j d  k	 rë | j	 d
 t  d |  j j ƒ f d t  d |  j j ƒ f g ƒ n  | S(   Ns   R-works   %.4fs   R-frees
   RMS(bonds)s   %.3fs   RMS(angles)t
   Clashscores   %.2fs   MolProbity scores   R-work (neutron)s   R-free (neutron)(
   R   Rš   R›   RŸ   R    R   R‡   R   R-   t   extend(   R.   t   mpRß   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt   get_statistics_for_phenix_gui5  s    "(   i   i   N(*   t   __name__t
   __module__t   __doc__t   molprobity_version_numberR+   R2   R-   R`   Rf   R‚   R‡   t   syst   stdoutR�   R¢   R�   Rš   R›   RJ   Rª   RŸ   R    R“   R’   R¬   R­   R®   R   R³   R´   Rµ   R¶   R·   R»   R¾   RÃ   RÅ   RÉ   RÊ   RÛ   Rá   Rå   (    (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyR   @   sš   $		~	.	#																						R¡   c           B   sª   e  Z d  Z d d d d d d d d d	 d
 d d g Z d d d d d d d d d d d d g Z d d d d d d d d d d d d g Z e j d e d „ Z	 d „  Z
 RS(    sô   
  Simplified container for overall statistics; replaces class of the same
  name in mmtbx.command_line.validation_summary.  The more complete molprobity
  class is prefered when analyzing a single structure, but it is considerably
  larger.
  R’   R“   R”   R•   R   R—   R˜   R™   RJ   Rš   R›   Rœ   s   Ramachandran outlierss                 favoreds   Rotamer outlierss   C-beta deviationsRâ   s
   RMS(bonds)s   RMS(angles)s   MolProbity scoret
   Resolutions   R-works   R-frees   Refinement programs   %6.2fs   %5ds   %8.4fs   %ss     c      	   C   s�  d „  } t  g  |  j D] } t | ƒ ^ q ƒ } i  } | r¢ d d d d g } t g  | D] }	 |	 t |  |	 ƒ f ^ qY ƒ }
 d d l m } | |  j |
 ƒ } n  xç t |  j	 ƒ D]Ö \ } }	 d | } | d	 k  rá | d
 7} n  d } | r/| j
 |	 d  ƒ } | d  k	 r"| d 7} d | } q9| d 7} n
 | d 7} t |  |	 ƒ } | d  k	 r² | | | |  j | | |  j | | ƒ | f IJq² q² W|  S(   Nc         S   s   t  |  | d d ƒS(   Nt   replace_none_withs   (none)(   R   (   t   formatR1   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt   fso  s    R   R™   Rš   R›   iÿÿÿÿ(   t   get_statistics_percentiless   %%s%%-%ds = %%si   s    %%t    s    (percentile: %s)s   %.1fs   %s(   t   maxt   labelst   lent   dictRj   t   mmtbx.polygonRð   RJ   t	   enumerateR+   t   getR-   t   formats(   R.   R6   R‹   R�   Rï   t   labelt   maxlent   percentilest	   perc_attrR0   Rß   Rð   t   kRî   t   percentile_infot
   percentileR1   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyR�   n  s2    	(.


!c         c   s°   d d |  j  d d d f d d |  j d  d  d f d d |  j d	 d
 d f d d |  j d	 d d f d d |  j d d d  f d d |  j d  d  d  f g } x | D] } | Vq� Wd  S(   Ns   Ramachandran outlierss   %6.2f%%g      à?gš™™™™™É?s   < 0.2%s   Ramachandran favoreds   > 98%s   Rotamer outliersi   i   s   1%s   C-beta outlierss   %3d   i    t   0Râ   s   %6.2fi(   i   s   Overall score(   R’   R“   R-   R”   R•   R   R™   (   R.   Rß   t	   stat_info(    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt   iter_molprobity_gui_fieldsŒ  s    (   Ræ   Rç   Rè   R+   Ró   Rù   Rê   Rë   Rf   R�   R  (    (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyR¡   F  s:   		t   pdb_header_infoc           B   sY   e  Z d  Z d d d d d d d d g Z d d	 „ Z d
 „  Z e j d e	 e	 d „ Z
 RS(   sM   
  Container for information extracted from the PDB header (if available).
  RJ   RK   Rš   R›   RŸ   R    R�   t   n_tls_groupsc         C   s�  x! |  j  D] } t |  | d  ƒ q
 W| d  k	 r‰d d  l } d d l m } | j j j d | ƒ } | j	 d | j j
 ƒ  d d  ƒ } | d  k	 rÄ | j |  _ | j |  _ | j |  _ | j |  _ n  | j j ƒ  |  _ t | ƒ j ƒ  } xY | D]Q }	 |	 j d ƒ rï |	 j ƒ  j ƒ  }
 t |
 d ƒ |  _ t |
 d ƒ |  _ Pqï qï W| d  k	 r‰| j j | ƒ j } | d  k	 r†t | ƒ |  _ q†q‰n  d  S(   Niÿÿÿÿ(   t"   extract_rfactors_resolutions_sigmaR(   t
   file_liness   REMARK Final:iüÿÿÿ(   R+   R*   R-   t   iotbx.pdb.hierarchyt	   iotbx.pdbR  t   pdbt	   hierarchyt   inputR   t   remark_sectionRš   R›   t   highRJ   t   lowRK   t   get_program_nameR�   RÓ   t	   readlinest
   startswitht   stript   splitt   floatRŸ   R    t   extract_tls_paramst
   tls_paramsRô   R  (   R.   t   pdb_fileR4   R0   t   iotbxR  t   pdb_int   published_resultst   linest   linet   fieldst
   tls_groups(    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyR‚      s2    	c         C   s"   |  j  d  k	 o! d |  j  j ƒ  k S(   Nt   phenix(   R�   R-   t   lower(   R.   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt   is_phenix_refinement¼  s    Rñ   c         C   s  |  j  d  k	 r) | d | |  j  f IJn  | r­ |  j d  k	 rX | d | |  j f IJn  |  j d  k	 r� | d | |  j f IJn  |  j d  k	 r­ | d | |  j f IJq­ n  | r|  j d  k	 rÜ | d | |  j f IJn  |  j d  k	 r| d | |  j f IJqn  d  S(   Ns   %sRefinement program    = %ss   %sHigh resolution       = %6.2fs   %sR-work                = %8.4fs   %sR-free                = %8.4fs   %sRMS(bonds)            = %8.4fs   %sRMS(angles)           = %6.2f(   R�   R-   RJ   Rš   R›   RŸ   R    (   R.   R6   R‹   t   include_r_factorst   include_rms_geom(    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyR�   À  s"    


N(   Ræ   Rç   Rè   R+   R-   R‚   R"  Rê   Rë   R`   R�   (    (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyR  š  s   	t   residue_multi_criterionc           B   s´   e  Z d  Z e j d d d g Z d „  Z d „  Z d d e d „ Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z e d „ Z d d „ Z e d „ Z RS(   sÉ   
  Container for multiple outliers associated with a single residue.  If data
  are used, this may include real-space statistics regardless of whether the
  residue is technically an outlier or not.
  t   outlierst   n_confst   i_seqc         K   s   t  j |  | � g  |  _ d  S(   N(   R   R‚   R&  (   R.   R¤   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyR‚   Û  s    c         C   s;   t  | t ƒ r' |  j | ƒ s' t ‚ n  |  j j | ƒ d  S(   N(   t
   isinstanceR   t   is_same_residue_groupRh   R&  t   append(   R.   t   outlier(    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt   add_outlierß  s    c         C   s�   | d  k	 s$ t | ƒ d k s$ t ‚ xV |  j D]K } | j ƒ  rN | rN q. n  t | ƒ j } | | k su | | k r. t Sq. Wt S(   Ni    (	   R-   Rô   Rh   R&  t
   is_outliert   typeRæ   R`   Rf   (   R.   t   outlier_typet   outlier_typest   retrieve_allR,  t   otype(    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt   _find_outlier_typeä  s    $c         C   s   |  j  d ƒ S(   Nt   ramachandran(   R4  (   R.   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt   is_ramachandran_outlierï  s    c         C   s   |  j  d ƒ S(   Nt   rotamer(   R4  (   R.   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt   is_rotamer_outlierò  s    c         C   s   |  j  d ƒ S(   Nt   cbeta(   R4  (   R.   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt   is_cbeta_outlierõ  s    c         C   s   |  j  d ƒ S(   Nt   clash(   R4  (   R.   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt   is_clash_outlierø  s    c         C   s   |  j  d d d d d d g ƒ S(   NR1  t   bondt   anglet   dihedralt	   chiralityt	   planarity(   R4  (   R.   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt   is_geometry_outlierû  s    	c         C   sÍ   g  } |  j  ƒ  r" | j d ƒ n  |  j ƒ  r> | j d ƒ n  |  j ƒ  rZ | j d ƒ n  |  j ƒ  rv | j d ƒ n  |  j ƒ  r’ | j d ƒ n  t | ƒ d k r° d g } n  d |  j ƒ  d	 j | ƒ f S(
   Nt   ramat   rotat   cbR;  t   geoi    s   ---s   %s  %st   ,(	   R6  R+  R8  R:  R<  RB  Rô   t   id_strt   join(   R.   R&  (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt   __str__ÿ  s          c         C   s   |  j  ƒ  j ƒ  S(   N(   t   residue_group_id_strt   __hash__(   R.   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyRL  	  s    c         C   s   t  |  j | j ƒ S(   N(   t   cmpR(  (   R.   RW   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt   __cmp__  s    c         C   sz   xH |  j  D]= } t | ƒ j d k r
 | j | j | j | j g } | Sq
 W| rk d d  l } | j g d Sd  g d Sd  S(   Nt   residue_real_spaceiÿÿÿÿi   (
   R&  R/  Ræ   t   b_isot   cct   two_fofcRO   t   numpyt   NaNR-   (   R.   t   use_numpy_NaNR,  t   valuesRS  (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt   get_real_space_plot_values  s    gš™™™™™é?c         C   s?   |  j  t ƒ \ } } } } | d  k r+ d  S| | k  r; t St S(   N(   RW  Rf   R-   R`   (   R.   RQ   RP  RQ  RR  RO   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt   is_map_outlier  s    c         C   s  g  } |  j  ƒ  r" | j d ƒ n | j d  ƒ |  j ƒ  rK | j d ƒ n | j d  ƒ |  j ƒ  rt | j d ƒ n | j d  ƒ |  j ƒ  r� | j d ƒ n | j d  ƒ | rd d  l } g  } x: | D]2 } | d  k rî | j | j ƒ qÉ | j | ƒ qÉ W| S| S(   Ni   iÿÿÿÿ(   R6  R+  R-   R8  R:  R<  RS  RT  (   R.   RU  t   yRS  t   y_t   yval(    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt   get_outlier_plot_values"  s,         N(    (   Ræ   Rç   Rè   R   R+   R‚   R-  R-   Rf   R4  R6  R8  R:  R<  RB  RJ  RL  RN  R`   RW  RX  R\  (    (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyR%  Ô  s"   		
						
		Rw   c           B   sb   e  Z d  Z d d g Z e d „ Z e j d „ Z d „  Z	 d „  Z
 d „  Z d „  Z d	 „  Z RS(
   sb   
  Container for generating multi-criterion plots and tables from separate lists
  of outliers.
  t   residuesRÆ   c   	      C   s  t  |  _ i  |  _ d } x÷ | j ƒ  j ƒ  D]ã } | sZ | j ƒ  rZ | j ƒ  rZ q+ qZ n  x± | j ƒ  D]£ } | j ƒ  d j	 } | d k r’ qg n  t
 d | j d | j d | j d | j ƒ  d j	 d d d	 | d
 t | j ƒ  ƒ ƒ } | j ƒ  } | |  j | <| d 7} qg Wq+ Wd  S(   Ni    t   HOHt   chain_idt   resseqt   icodet   resnamet   altlocRñ   R(  R'  i   (   Rf   RÆ   R]  t
   only_modelt   chainst
   is_proteint   is_nat   residue_groupst   atom_groupsRb  R%  t   idR`  Ra  Rô   RK  (	   R.   R4   t   include_allR(  t   chaint   residue_groupRb  Ri   RH  (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyR‚   ;  s,    			 			c         C   s  t  |  _ x | D]ø } | j ƒ  rz | j d k r7 q n  | j ƒ  } | |  j k ri |  j | j | ƒ q| d | IJq t g  ƒ } x | j D]t } | j ƒ  } | j d k s� | | k rÃ q� n  | |  j k rö |  j | j | ƒ | j	 | ƒ q� | d | IJq� Wq Wd  S(   NR^  s   missing residue group '%s'(
   R`   RÆ   t   is_single_residue_objectRb  RK  R]  R-  t   sett
   atoms_infot   add(   R.   R&  RG   R,  RH  t   have_idst   atom(    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyRÇ   R  s$    	  c         C   sD   |  j  j | j ƒ  d  ƒ } | d  k r@ t d | j ƒ  ƒ ‚ n  | S(   Ns   Can't find residue '%s'(   R]  Rø   RH  R-   t   RuntimeError(   R.   Rm  t   residue_validation(    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt   get_residue_group_datag  s    c         C   s   t  |  j j ƒ  ƒ S(   N(   t   sortedR]  RV  (   R.   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt   datam  s    c         C   s#   d d l  m } | j |  j ƒ  ƒ S(   Niÿÿÿÿ(   t   graphics(   R†   Ry  t   residue_binnerRx  (   R.   Ry  (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt   binned_datap  s    c         C   sê   d d  l  } g  } x' |  j ƒ  D] } | j | j ƒ  ƒ q W| j | ƒ j ƒ  } t t | d ƒ t | d ƒ ƒ } t t | d ƒ t | d ƒ ƒ } i | | f d 6t | d ƒ t | d ƒ f d 6t | d ƒ t | d ƒ f d 6S(	   Niÿÿÿÿi   i   t   rhoi    t   bi   RQ  (   RS  Rx  R+  RW  t   arrayt	   transposet   minRò   (   R.   RS  RV  R,  t   rho_mint   rho_max(    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt   get_y_limitst  s    ##!c         C   s>   d d  l  } | j j j d d  d d d |  ƒ } | j ƒ  d  S(   Niÿÿÿÿt   parentt   titles   MolProbity multi-criterion plotR   (   t   wxtbx.plots.molprobityt   plotsR   t   multi_criterion_frameR-   t   Show(   R.   t   wxtbxt   frame(    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyRÊ   ‚  s    	(   Ræ   Rç   Rè   R+   Rf   R‚   Rê   t   stderrRÇ   Rv  Rx  R{  Rƒ  RÊ   (    (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyRw   5  s   				(%   Rè   t
   __future__R    R†   R   R   R   R   R   R   R   R   R	   R
   R   t   libtbx.str_utilsR   R   R   R   R   R   t   libtbx.utilsR   R   t   libtbx.load_envt   libtbx.philt   os.pathRÐ   Rê   R   R   R   R¡   R  R%  Rw   (    (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/validation/molprobity/__init__.pyt   <module>   s6   	ÿ ÿ T:a