ó
±™xTc           @   s  d  d l  m Z d  d l Z d  d l m Z m Z d  d l Z d  d l m	 Z	 m
 Z
 d  d l m Z d  d l Z d  d l Z e j j d d e ƒZ e Z e j d „ Z d	 „  Z d e e j d
 „ Z d „  Z d e j f d „  ƒ  YZ d „  Z e d k re e j  d ƒ n  d S(   iÿÿÿÿ(   t   divisionN(   t
   get_fp_fdpt   get_residues_and_ha(   t   Sorryt   null_out(   t   runtime_utilssy  
crystal_info {
  resolution = None
    .type = float
    .help = Optional high-resolution limit. If specified, the calculation             is only carried out at this resolution
    .short_caption = High-resolution limit
    .style = resolution
   .input_size = 64

  seq_file = None
    .type = path
    .help = "Optional sequence file (1-letter code)."
             "Separate chains with a blank line or line starting with &gt;."
    .short_caption = Sequence file
    .style = bold file_type:seq input_file

  chain_type = *PROTEIN RNA DNA
    .type = choice
    .short_caption = Chain type
    .help = Chain type (PROTEIN RNA DNA). This is used to estimate the             number of atoms from the number of residues

  solvent_fraction = 0.5
    .type = float
    .short_caption = Solvent fraction
    .help = Optional estimate of solvent fraction in your crystals
   .input_size = 64

  residues = None
    .type = int
    .short_caption = Number of residues
    .help = The number of residues in the molecule or asymmetric unit.           Note that it is the ratio of residues to anomalously-scattering           atoms that matters.
    .input_size = 64

  atom_type = None
    .type = str
    .short_caption = Anomalously-scattering atom
    .help = Optional name of anomalously-scattering atom.  If supplied,             you also need to supply the wavelength for X-ray data             collection.  If not supplied, then you need to supply a             value for f_double_prime.
    .style = renderer:draw_phaser_scatterer_widget
    .input_size = 64

  number_of_s = None
    .type = int
    .short_caption = Number of S atoms
    .help = You can specify the number of S atoms in the asymmetric unit.             Only used if include_weak_anomalous_scattering=True.  If not             set, the number is guessed from the sequence file if present.
  f_double_prime = None
    .type = float
    .short_caption = F-double-prime
    .help = F-double-prime value for the anomalously-scattering atom.             Alternatively you can specify the atom type and wavelength.
    .input_size = 64

  wavelength = None
    .type = float
    .short_caption = Wavelength
    .help = Wavelength for X-ray data collection.  If supplied, also             specify the atom_type.             Alternatively you can specify the value of f_double_prime
    .input_size = 64

  sites = None
    .type = int
    .short_caption = Number of anomalously-scattering atoms
    .help = The number of anomalously-scattering atoms in the molecule           or asymmetric unit.           Note that it is the ratio of residues to anomalously-scattering           atoms that matters.
    .input_size = 64

  occupancy = 1
    .type = float
    .short_caption = Occupancy of anomalously-scattering atoms
    .help = Estimate of occupancy of anomalously-scattering atoms


   }
   i_over_sigma = None
     .type = float
     .short_caption = I/sigI
     .help = Optional I/sigI.  If supplied and resolution is supplied,          the expected values of half-dataset correlation and cc*_ano based         on this I/sigI and resolution will be calculated.

   target_signal = 30.
       .type = float
       .short_caption = Target anomalous signal
       .help = The anomalous signal that you would like to obtain.                The value of I/sigma will be adjusted to obtain this signal.               Typically you will need a signal of 15-30 so solve the                substructure.
   min_cc_ano = 0.15
     .type = float
     .short_caption = Target minimum anomalous correlation
     .help = You can set the target minimum (true) anomalous correlation              (CC*_ano). This value affects the phasing accuracy after              the substructure is determined.

   ideal_cc_anom = 0.75
     .type = float
     .short_caption = Anomalous correlation with perfect data
     .help = The ideal_cc_anom is the expected anomalous              correlation between an accurate model with isotropic anomalous              scatterers and perfectly-measured data. The ideal_cc_anom is               determined empirically.  It is typically not unity because              anomalous scatterers may have multiple locations with low              occupancy or may be non-isotropic. A value of about 0.75              is a reasonable guess.

   include_weak_anomalous_scattering = True
     .type = bool
     .short_caption = Include weak anomalous scattering
     .help = At longer wavelengths the scattering of C, N, and O become              significant relative to S. Default is to consider the              scattering from C, N, O as noise.  Additionally,              (see intrinsic_scatterers_as_noise) if intrinsic              anomalous scatterers (P and S) are weak, they will be counted              as noise.  This weak anomalous scattering is effectively noise              and has the same effect as the ideal_cc_anom but it can be              calculated from the composition. Its effects are added to those              modeled by the ideal_cc_anom parameter.

   intrinsic_scatterers_as_noise = None
     .type = bool
     .short_caption = Intrinsic scatterers as noise
     .help = Applies if include_weak_anomalous_scattering=True.             You can choose to treat any intrinsic scatterers (S for              protein, P for nucleic acid) as noise, just like any              contributions from C, N, or O atoms. This is default if              anomalous scattering (f-double-prime) from these atoms is              less than half that of your specified anomalous scatterer.              Alternatively these atoms are excluded from the noise              calculation and are assumed to be included in the              number of sites you specify.

   control {
      show_summary = False
        .type = bool
        .help = Show summary only
        .short_caption = Show summary only

      verbose = False
        .type = bool
        .help = '''Verbose output'''
        .short_caption = Verbose output
   }
t   process_includesc         C   sZ   t  j j d |  d t d d ƒ } | j j ƒ  } | d IJt j d | ƒ j d | ƒ | S(   Nt   argst   master_philt   seq_file_defs   crystal_info.seq_files   
Plan a SAD experiment
t   python_objectt   out(   t   iotbxt   philt   process_command_line_with_filesR   t   workt   extractt   formatt   show(   R   R   t   command_linet   params(    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/plan_sad_experiment.pyt
   get_params¨   s    	
c         C   sƒ  |  j  j sB t d |  j  j d |  j  j d | ƒ j ƒ  |  j  _ n  |  j  j rt j j	 |  j  j ƒ rt
 |  j  j |  j  j |  j  j d | ƒ\ } } } |  j  j sÂ | d | IJ| |  j  _ n  |  j  j së | d | IJ| |  j  _ n  |  j  j sI| d d | IJ| |  j  _ qIn. |  j  j d  k rI|  j rIt d d	 ƒ ‚ n  |  j  j sdt d
 ƒ ‚ n  |  j  j st d ƒ ‚ n  d  S(   Nt	   atom_typet
   wavelengthR   s-   Number of residues based on sequence file: %ds,   Number of S atoms based on sequence file: %ds0   Number of sites for anomalously-scattering atom s   based on sequence file: %ds-   Sorry need a sequence file or number_of_s if s'   
include_weak_anomalous_scattering=Trues4   Please specify number of residues or a sequence files?   Please specify number of sites or a sequence file and atom_type(   t   crystal_infot   f_double_primeR   R   R   t   fdpt   seq_filet   ost   patht   isfileR   t
   chain_typet   residuest   number_of_st   sitest   Nonet!   include_weak_anomalous_scatteringR   (   R   R   R    R"   R!   (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/plan_sad_experiment.pyt   setup_params²   s>    $			c      !   C   s  | s t  |  d | ƒ} n  t | d | ƒt j j j d | j j d | j j d | j j	 d | j j
 d | j j d | j j d | j j d	 | j j d
 | j d | j d | j d | j j d | j j d | j d | j d | j ƒ } | j j r| j ƒ  n | j d | ƒ Sd  S(   NR   R   R    R!   t   solvent_fractiont   nsitesR   R   t   fppt   target_s_anot   i_over_sigmat
   min_cc_anot   dmint	   occupancyt   ideal_cc_anomR$   t   intrinsic_scatterers_as_noise(   R   R%   t   mmtbxt   scalingt   plan_sad_experimentt   estimate_necessary_i_sigiR   R   R    R!   R&   R"   R   R   R   t   target_signalR*   R+   t
   resolutionR-   R.   R$   R/   t   controlt   show_summaryR   (   R   R   t   return_planR   t   plan(    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/plan_sad_experiment.pyt   run×   s.    					c         C   s   t  |  d t ƒ  ƒS(   NR   (   R%   R   (   R   (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/plan_sad_experiment.pyt   validate_paramsô   s    t   launcherc           B   s   e  Z d  „  Z RS(   c         C   s   t  |  j d t j ƒS(   NR   (   R:   R   t   syst   stdout(   t   self(    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/plan_sad_experiment.pyR:   ø   s    (   t   __name__t
   __module__R:   (    (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/plan_sad_experiment.pyR<   ÷   s   c         C   s
   g  g  f S(   N(    (   t   result(    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/plan_sad_experiment.pyt
   finish_jobû   s    t   __main__i   (!   t
   __future__R    t!   mmtbx.scaling.plan_sad_experimentR0   R   R   t
   iotbx.philR   t   libtbx.utilsR   R   t   libtbxR   t   os.pathR   R=   R   t   parset   TrueR   t   master_paramsR>   R   R%   R#   t   FalseR:   R;   t   target_with_save_resultR<   RC   R@   t   argv(    (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/plan_sad_experiment.pyt   <module>   s$   	™
	%		