ó
×™xTc           @   s¿  d  d l  m 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
 m Z d  d l Z
 d  d l m Z d  d	 l
 m Z e
 j j d
 d e ƒZ d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e j d „ Z e e j d „ Z g  g  e d e j d „ Z e j d „ Z g  g  d e j d „ Z  d „  Z! d „  Z" e j d „ Z# e j d „ Z$ d „  Z% d „  Z& d „  Z' d  „  Z( d! „  Z) d S("   iÿÿÿÿ(   t   divisionN(   t   pdb(   t
   cablam_res(   t   cablam_math(   t   cablam_fingerprints(   t   easy_run(   t   file_reader(   t
   group_argss›  
cablam_training {
  file_or_dir = None
    .type = path
    .help = '''input pdb file or dir thereof'''
  separate_files = False
    .type = bool
    .help = '''Generate a separate, auto-named output file for each input file'''
  give_kin = False
    .type = bool
    .help = '''Print output to screen in .kin format (default is comma-separated .csv format)'''
  give_connections = False
    .type = bool
    .help = '''Add prevres and nextres columns to .csv output'''
  debug = False
    .type = bool
    .help = '''Adds some text printed to stderr for debugging esp. for fingerprints'''

  all_measures = False
    .type = bool
    .help = '''Does all measures'''
  cad = False
    .type = bool
    .help = '''2 CA pseudo dihedrals'''
  caa = False
    .type = bool
    .help = '''3 CA pseudo angles'''
  cod = False
    .type = bool
    .help = '''2 CO pseudo dihedrals'''
  rama = False
    .type = bool
    .help = '''2 Ramachandran dihedrals: phi, psi'''
  exrama = False
    .type = bool
    .help = '''4 Ramachandran dihedrals: psi-1, phi, psi, phi+1'''
  tau = False
    .type = bool
    .help = '''1 backbone angle: tau (defined by N-CA-C)'''
  omega = False
    .type = bool
    .help = '''1 backbone dihedral: omega (defined by CA_1-C_1-N_2-CA_2)'''
  cablam = False
    .type = bool
    .help = '''Shortcut for just cablam-relevant measures CA_d_in, CA_d_out, CO_in'''

  probe_motifs = None
    .type = strings
    .help = '''Activates hydrogen bonding analysis, probe=motif_name1,motif_name2,... use --listmotifs to list available fingerprints'''
  probe_path = None
    .type = path
    .help = '''Stores path to dir of probed files, probe will be called for each file if this is not provided'''
  probe_mode = *kin annote instance sequence superpose
    .type = choice
    .help = '''=kin for dotlist kins (default) =annote for ball on model, =instance for vectorlist kins'''
  list_motifs = False
    .type = bool
    .help = '''print motifs/fingerprints available to screen'''

  b_max = None
    .type = float
    .help = '''Set a max b factor, residues containing a backbone atom with higher b will be pruned, recommended: -b=30'''
  prune_alts = False
    .type = bool
    .help = '''Removes all residues with alternate conformations in relevant atoms'''
  prune = None
    .type = strings
    .help = '''List of restypes to be pruned, separated by commas, no spaces eg PRO'''
  skip_types = None
    .type = strings
    .help = '''List of restypes to be skipped during printing, separated by commas'''
  include_types = None
    .type = strings
    .help = '''List of restypes to be printed, all others will be skipped'''

  cis_or_trans = *both cis trans
    .type = choice
    .help = '''selects whether cis-peptides, trans-peptides, or both will be returned'''

  fear = False
    .type = bool
    .help = '''turns on fear-to-tread analysis (this is temporary)'''

  help = False
    .type = bool
    .help = '''print help text to screen'''
}
t   process_includesc           C   s   t  j j d ƒ d  S(   NsY  
phenix.cablam_training or cablam_training.py is a program intended for the
  exploration of protein structure datasets, the annotation of motifs of
  interest, and the training of reference datasets.  It was used in the
  construction of the reference contours used by cablam_validate.  It contains a
  number of features and modes and is intended primarily as a development tool
  rather than a utility for typical users.  However, anyone interested in
  exploring protein backboen geometry may find something of use here.

--------------------------------------------------------------------------------
file_or_dir=*path*
  Path to a pdb file or dir of pdb files to operate on, the only argument that
  doesn't need an explicit flag
--------------------------------------------------------------------------------

-----Basic Printing Options-----------------------------------------------------
separate_files=True/False
  Generate a separate, auto-named output file in the current dir for each input
  file, default output prints a single file to screen

give_kin=True/False
  Print output to screen in .kin format, may be combinded with separate_files,
  default output prints comma-separated .csv format

give_connections=True/False
  If set to True, adds prevres and nextres columns to .csv output

skip_types=restype1,restype2
include_types=restype3,restype4
  Together, these control which residue types are printed to screen or file.
  Default prints all residues.
  Residue types and relationships given to skip_types are excluded from printing
  If only include_types is used, only the listed restypes will be printed
  If include_types and skip_types are both used, then the types given to
  include_types will override those skipped by skip_types.

  List restypes by their 3-letter code and separated by commas withoug spaces,
  e.g. GLY,PRO,ALA,TRP
  Sequence relationships may be represented with underscores, e.g. _PRO is
  pre-proline, and GLY__ (2 underscores) is post-post-glycine

  examples:
  skip_types=PRO would print every residue except proline
  include_types=PRO,GLY would print *only* glycines and prolines
  skip_types=_PRO include_types=GLY would skip pre-prolines unless they were
  also glycines

cis_or_trans='cis' 'trans' 'both'
  Selects printing for cis-peptides or trans-peptides exclusively. The default
  is 'both' which will print all residues.  cis is defined as -60 to +60 degrees
  trans is defined as 120 to 180 and -120 to -180 degrees for the omega dihedral
  Note that selecting 'cis' or 'trans' will also stop printing for any residue
  for which omega cannot be calculated.
--------------------------------------------------------------------------------

-----Probe and Motif Search Options---------------------------------------------
This is an alternate mode which searches for hydrogen bonding patterns defined
  in fingerprints.

probe_motifs=motif_name1,motif_name2
  This flag activates hydrogen bonding pattern analysis, which will not run
  otherwise.  The flag accepts a spaceless string of comma-separated motif names
  to search for.  Use list_motifs=True to get a list of available motifs.

probe_path=*path*
  cablam_training can use precomputed probe results to speed up runs on large
  datasets. If a path to such prepared files is not provided, Reduce and Probe
  will be run on each pdb file, which may be time-consuming.

  Running:
  phenix.probe -u -condense -self -mc -NOVDWOUT -NOCLASHOUT MC filename.pdb > filename.probe
  Should produce appropriately formatted and named files for this option

probe_mode=kin/annote/instance/sequence
  These are printing options for hydrogen bond pattern analysis, which overrides
  the Basic Printing Options above.
Choose 1 of 3:
=kin returns automatically-named kinemage files, one for each unique member
  residue in each motif. The kins are high-dimensional dotlists containing the
  measures specified in the commandline (see below for options).  This is the
  default printing.
=annote returns an automatically-named kinemage file for each pdb file. These
  kins are balllists that highlight the selected motifs of interest if appended
  to existing kinemages of the structures.
=instance returns an automatically-named vectorlist kinemage file for each motif
  of interest.  Each kin is a high-dimensional vectorlist that shows the path of
  a multi-residue motif through the measures specified in the commandline
  (see below for options)
=sequence prints to screen the animo acid sequence of the motif of interest.
  Does not behave with multiple motifs.  Uses single-letter amino acid codes, if
  a residue type is unrecognized, will print 'X' followed by the 3-letter code.

list_motifs=True/False
  Prints to screen a list of all the motifs/"fingerprints" currently available
  for hydrogen bond pattern search
--------------------------------------------------------------------------------

-----Geometric Measures---------------------------------------------------------
All of these default to False, and some output modes will not function unless at
  least one of these options is turned on.  When in doubt, cablam=True and/or
  rama=True will provide relevant information.

cad=True/False
  For each residue, calculate the 2 C-alpha pseudo dihedrals

caa=True/False
  For each residue, calculate the 3 C-alpha pseudo angles

cod=True/False
  For each residue, calculate the 2 carbonyl oxygen pseudo dihedrals

rama=True/False
  For each residue, calculate Ramachandran dihedrals phi and psi

exrama=True/False
  For each residue, calculate Ramachandran dihedrals psi-1, phi, psi, phi+1

tau=True/False
  For each residue, calculate backbone angle tau, defined by N-NA-C

omega=True/False
  For each residue, calculate backbone peptide dihedral,
  defined by CA_1,C_1,N_2,CA_2

all_measures=True/False
  For each residue, calculate all of the above measures (may be overkill)

cablam=True/False
  Recommended, but not default behavior.
  For each residue calculate the measures most relevant to cablam analysis:
  CA_d_in, CA_d_out, CO_in
--------------------------------------------------------------------------------

-----Quality Control Options----------------------------------------------------
b_max=#.#
  Set a max b factor value. Residues containing a backbone atom with higher b
  will be pruned and excluded from all calculations. Note this may affect
  neighboring residues.  Strongly Recommenced: b_max=30.0

prune_alts=True/False
  Prune and excludes from calculations all residues with alternate conformations
  for backbone atoms. Note this may affect neighboring residues. Default is
  prune_alts=False, which results in only the first alternate position for each
  residue being reported on.

prune=restype1,restype2
  Prune  and exclude from calculations the selected list of residue types. Note
  this may affect neighboring residues. Restypes should be given as 3-letter
  codes, e.g. GLY,PRO, but this option does not yet support the sequence
  relationship that skip_types= and include_types= do.
--------------------------------------------------------------------------------

-----Help Options---------------------------------------------------------------
help=True/False
  Displays this help message.

list_motifs=True/False
  Prints to screen a list of all the motifs/"fingerprints" currently available
  for hydrogen bond pattern search

debug=True/False
  Activates print-to-stderr debugging notes for hydrogen bond pattern search.
  This may be valuable when trying to define a new pattern correctly and with
  proper format.
--------------------------------------------------------------------------------

Examples:
phenix.cablam_training cad=True cod=True skip_types=GLY,PRO,_PRO,ILE,VAL b_max=30.0 kin=True file_or_dir=path/pdbfilename.pdb

phenix.cablam_training cablam=True b_max=30.0 prune=GLY probe_motifs=parallel_beta,antiparallel_beta_cwc,antiparallel_beta_wcw probe_mode=kin probe_path=path/database/probefiles file_or_dir=path/database/pdbfiles

(   t   syst   stderrt   write(    (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/cablam/cablam_training.pyt   usageŽ   s    	«c         C   s§   |  j  ƒ  } x” | D]Œ } t } x} |  | j D]n } | r= Pn  x[ |  | j | D]H } |  | j | | | k rO |  | j ƒ  |  j | ƒ } t } PqO qO Wq- Wq Wd  S(   N(   t   keyst   Falset   altst   atombt   removelinkst   popt   True(   t   resdatat   bmaxt   reslistt   residt   deletedt   altt   atomt   trash(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/cablam/cablam_training.pyt   stripBE  s    c         C   s\   |  j  ƒ  } xI | D]A } |  | } t | j ƒ d k r | j ƒ  |  j | ƒ } q q Wd  S(   Ni   (   R   t   lenR   R   R   (   R   R   R   t   residueR   (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/cablam/cablam_training.pyt
   prune_alts]  s    

c         C   s`  | r t  } n | r t } n t  Sx| D]} |  } | j d ƒ rx | j d ƒ rx t j j d | d ƒ t j ƒ  n  x6 | j d ƒ r° | j r© | j } | d } q{ t Sq{ Wx6 | j d ƒ ré | j	 râ | j	 } | d  } q´ t Sq´ W| j
 d ƒ d  k	 r| j | j
 d ƒ d } n t S| | j ƒ  k r) t } q) q) Wx| D]} |  } | j d ƒ r•| j d ƒ r•t j j d | d ƒ t j ƒ  n  x6 | j d ƒ rÍ| j rÆ| j } | d } q˜t Sq˜Wx6 | j d ƒ r| j	 rÿ| j	 } | d  } qÑt SqÑW| j
 d ƒ d  k	 r9| j | j
 d ƒ d } n t S| | j ƒ  k rFt  } qFqFW| S(   Nt   _s'   
        Invalid --skip flag argument: s    has'_' on both sides

i   iÿÿÿÿt   CAt   resname(   R   R   t
   startswitht   endswithR	   R
   R   t   exitt   nextrest   prevrest   firstaltt   NoneR   t   upper(   R   t   skiplistt   inclistt   doskipt   skipt
   currentresR"   t   inc(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/cablam/cablam_training.pyt	   skipchecko  s`    												c         C   sž   t  } | d k r t } n d |  j k r3 t  } ng |  j d } | d k rm | d k rm | d k rm t } n  | d k rš | d k s‘ | d k rš t } n  | S(	   Nt   botht   omegat   cisiÄÿÿÿi<   t   transix   iˆÿÿÿ(   R   R   t   measures(   R   t   cis_or_transR-   R3   (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/cablam/cablam_training.pyt   fails_cis_check»  s    		$	$	c         C   sõ   d } d } d } x' t  |  j ƒ  ƒ D] \ } } | } Pq% Wt j j ƒ  } | j ƒ  } | j | ƒ t j j	 d ƒ t
 j | d | j ƒ  ƒ}	 t j j	 d ƒ t
 j | d |	 j ƒ}
 d j |
 j ƒ } t j j	 d ƒ t
 j | d | ƒ} | j S(	   Ns   phenix.reduce -quiet -trim -s5   phenix.reduce -oh -his -flip -pen9999 -keep -allalt -s?   phenix.probe -u -condense -self -mc -NOVDWOUT -NOCLASHOUT ALL -s     cleaning . . .
t   stdin_liness     reducing . . .
s   
s     probing . . .
(   t	   enumeratet   modelsR   t	   hierarchyt   roott   detached_copyt   append_modelR	   R
   R   R   t   fully_bufferedt   as_pdb_stringt   stdout_linest   join(   R<   t   trim_commandt   build_commandt   probe_commandt   it   mt   modelt   rt   mdct	   clean_outt	   build_outt	   input_strt	   probe_out(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/cablam/cablam_training.pyt   make_probe_dataÑ  s"    c         C   s‰  |  j  ƒ  } xv| D]n} | j ƒ  s+ q n  | j d ƒ } | d } | d } | d } | d k sj q n  | d } | d d !j ƒ  }	 t | d d !j ƒ  ƒ }
 | d d !} | d d	 !j ƒ  } | d
 k rÒ q n  | d d !} | d d !j ƒ  } | d } | d d !j ƒ  } t | d d !j ƒ  ƒ } | d d !} | d d !} | d d	 !j ƒ  } | d d !} | d d !j ƒ  } | d } | d } d j d |	 d |
 | g ƒ } | |  j  ƒ  k rÀq n  |  | } d j d | d | | g ƒ } | |  j  ƒ  k rq n |  | } | j ƒ  | } t d | d | d | d | d | j | ƒ ƒ } | | j j  ƒ  k rpi  | j | <n  | | j | | <q Wd  S(   Nt   :i    i   i   t   hbi   i   i   i
   t   HOHi   i   i   i   i   t    t    s   %04iR   R   t   dotcountt   mingapt   seqdist(	   R   t   stript   splitt   intRC   t   id_with_resnameR   t   seq_distt   probe(   R   t   open_probe_filet   reskeyst   linet   bnanat   namet   patternt   interactiontypet   srcAtomt   srcChaint   srcNumt   srcInst
   srcResnamet   srcAtomnamet   srcAltt   trgAtomt   trgChaint   trgNumt	   trgNumStrt   trgInst
   trgResnamet   trgAtomnamet   trgAltRV   RW   t   src_keyt
   srcResiduet   targ_keyt
   trgResiduet	   recordkeyt   record(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/cablam/cablam_training.pyt   add_probe_dataö  s\     


 
 


 


c         C   s   |  j  d ƒ d  S(   Ns]  
@group {Rama Frame}
@dotlist {center} color= yellow off
0 0 0
@vectorlist {frame_xy} color= yellow
P -180 -180 0
180 -180 0
180 180 0
-180 180 0
-180 -180 0
@vectorlist {frame_xz} color= yellow
P -180 0 -180
180 0 -180
180 0 180
-180 0 180
-180 0 -180
@vectorlist {frame_yz} color= yellow
P 0 -180 -180
0 180 -180
0 180 180
0 -180 180
0 -180 -180

(   R   (   t   writeto(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/cablam/cablam_training.pyt	   kin_frame[  s    c         C   sJ   | j  d ƒ | j  d j |  ƒ ƒ | r9 | j  d ƒ n  | j  d ƒ d  S(   Ns$   ,pdb:model:chain:resnum:ins:resname,t   ,s   ,prevres,nextress   
(   R   RC   (   t   kinordert   doconnectionsR|   (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/cablam/cablam_training.pyt
   csv_header{  s
    R2   c   	      C   sq   |  j  ƒ  } | j ƒ  xT | D]L } t |  | | | ƒ r< q t |  | | ƒ rR q |  | j | | | ƒ q Wd  S(   N(   R   t   sortR1   R8   t
   printtocsv(	   t   proteinR   R+   R,   R€   R7   R|   R   R   (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/cablam/cablam_training.pyt	   csv_print‡  s    
c         C   sù   t  |  ƒ d k r? t j j d ƒ t j j d ƒ t j ƒ  n  | j d ƒ x" t j D] } | j | d ƒ qV W| j d ƒ | j d d j |  ƒ d	 ƒ | j d
 d j | ƒ d ƒ t d | ƒ | j d ƒ | j d t t  |  ƒ ƒ d ƒ d  S(   Ni    s1   
No geometric measures (e.g. rama=True) specifieds   
Exiting . . .
s   @text
s     s   

@kinemage
s   @dimensions {s   } {s   }
s   @dimminmax RT   s   
R|   s   @group {points}
s%   @dotlist {points} nobutton dimension=(	   R   R	   R
   R   R%   t   argvRC   R}   t   str(   R   t	   kinrangesR|   t   arg(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/cablam/cablam_training.pyt
   kin_headerš  s    c         C   s­   t  | ƒ d k r? t j j d ƒ t j j d ƒ t j ƒ  n  |  j ƒ  } | j ƒ  xQ | D]I } t |  | | | ƒ r{ q\ t |  | | ƒ r‘ q\ |  | j	 | | ƒ q\ Wd  S(   Ni    s1   
No geometric measures (e.g. rama=True) specifieds   
Exiting . . .
(
   R   R	   R
   R   R%   R   R‚   R1   R8   t
   printtokin(   R„   R   R+   R,   R7   R|   R   R   (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/cablam/cablam_training.pyt	   kin_print¬  s    
c         C   s  t  | ƒ d k r? t j j d ƒ t j j d ƒ t j ƒ  n  i  } xÀ |  D]¸ } t | d d ƒ | | <| | j d ƒ | | j d d j | ƒ d	 ƒ | | j d
 d j | ƒ d ƒ t d | | ƒ | | j d | d | d t t  | ƒ ƒ d ƒ qL W| S(   Ni    s1   
No geometric measures (e.g. rama=True) specifieds   
Exiting . . .
s   .kint   as   
@kinemage
s   @dimensions {s   } {s   }
s   @dimminmax RT   s   
R|   s   @group {s   } dominant animate
@dotlist {s   } dimension=(	   R   R	   R
   R   R%   t   openRC   R}   R‡   (   t   full_label_listR   Rˆ   t   outfilest   label(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/cablam/cablam_training.pyt   kin_print_probe_headerÂ  s    ""
/c         C   sœ   x• |  D]� } x„ |  | D]x } | j  | ƒ sK t j j d | d ƒ q n  xB | j D]7 } | j | } | j | } | j | d | | ƒqU Wq Wq Wd  S(   Ns     s0    has incomplete measures, probably due to b_max
R|   (   t   has_all_measuresR	   R
   R   t   namest   residuesR‹   (   t   motif_instancesR   R�   t
   motif_namet   instancet   indexR   Rc   (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/cablam/cablam_training.pyt   kin_print_probeÖ  s    	c         C   sL  xE|  D]=} |  | r | j  d | d ƒ |  | d } | j j ƒ  } | j ƒ  xî | D]ã } | j  d | j | d ƒ x¾ |  | D]² } | j | } | j d ƒ } | j | d }	 | j d | j d t	 | j
 ƒ d | j | }
 | j  d |
 d t	 |	 d ƒ d t	 |	 d	 ƒ d t	 |	 d
 ƒ d ƒ q‡ WqZ Wq q Wd  S(   Ns   @group {s   }
i    s   @balllist {R!   RT   s   { s    } i   i   s   
(   R   R•   R   R‚   R”   R(   t   atomxyzt   pdbidt   chainR‡   t   resnum(   R–   R|   R—   t   ref_instancet   indicesR™   R˜   R   R(   t   CAxyzt   pointid(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/cablam/cablam_training.pyt   kin_print_probe_annoteê  s    

4c         C   sF  |  j  ƒ  } | j ƒ  t j | ƒ } x| D]} | j d | j d ƒ xñ | j j ƒ  D]à } | j d | d ƒ xÂ | D]º } |  | } | | j k r| | j	 d ƒ }	 | j
 |	 d }
 | j d | j d t | j ƒ d | } | j d | d t |
 d ƒ d t |
 d	 ƒ d t |
 d
 ƒ d ƒ q| q| WqZ Wq, Wd  S(   Ns   @group {s   }
s   @balllist {R!   RT   s   { s    } i    i   i   s   
(   R   R‚   R   t   fetch_fingerprintsR   R—   t   residue_namest   valuest   motifsR(   R›   Rœ   R�   R‡   Rž   (   R   t
   motif_listR|   R`   R§   t   motifR‘   R   R   R(   R¡   R¢   (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/cablam/cablam_training.pyt   old_kin_print_probe_annoteû  s    

-c         C   s)  t  | ƒ d k r? t j j d ƒ t j j d ƒ t j ƒ  n  i  } t j |  ƒ } xÎ | D]Æ } | j } t | d d ƒ | | <| | j d ƒ x& t j	 D] } | | j | d ƒ qœ W| | j d ƒ | | j d	 d
 j
 | ƒ d ƒ | | j d d j
 | ƒ d ƒ t d | | ƒ q[ W| S(   Ni    s1   
No geometric measures (e.g. rama=True) specifieds   
Exiting . . .
s   _instances.kint   ws   @text
s     s   
@kinemage
s   @dimensions {s   } {s   }
s   @dimminmax RT   s   
R|   (   R   R	   R
   R   R%   R   R¤   R—   RŽ   R†   RC   R}   (   R¨   R   Rˆ   R�   R§   R©   R—   R‰   (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/cablam/cablam_training.pyt   kin_print_by_instance_header  s"    	""c         C   si  xb|  D]Z} xQ|  | D]E} | j  | ƒ sK t j j d | d ƒ q n  | j j ƒ  } | j ƒ  | j | d } | | j d | j j	 d ƒ d t
 | j ƒ d | d t
 t | ƒ ƒ d	 ƒ x“ | j D]ˆ } | j | } | j | }	 d
 | j ƒ  d |	 d g }
 x( | D]  } |
 j t
 | j | ƒ ƒ qW| | j d j |
 ƒ d	 ƒ qÑ Wq Wq Wd  S(   Ns     s0    has incomplete measures, probably due to b_max
i    s   @group {s   .pdbRT   s    } dominant animate
@vectorlist {s   } dimension=s   
t   {R    t   }(   R“   R	   R
   R   R”   R   R‚   R•   Rœ   t   rstripR‡   Rž   R   R\   t   appendR6   RC   (   R–   R¨   R   R�   R—   R˜   R    R   R™   Rc   t   outlinet   order(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/cablam/cablam_training.pyt   kin_print_by_instance(  s$    	

Hc   	      C   s”  i d d 6d d 6d d 6d d 6d	 d
 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d  6d! d" 6d# d$ 6d% d& 6d' d( 6d d) 6d d* 6d% d+ 6d% d, 6d% d- 6d% d. 6d% d/ 6d! d0 6} xÃ |  D]» } x² |  | D]¦ } | j  j ƒ  } | j ƒ  g  } xX | D]P } | j  | j ƒ  d1 d2 !} | | k rG| | } n
 d3 | } | j | ƒ qW| j d4 ƒ t j j d5 j | ƒ ƒ qâ WqÑ Wd  S(6   Nt   Gt   GLYt   At   ALAt   Vt   VALt   It   ILEt   Lt   LEUt   Ft   PHEt   Wt   TRPt   Mt   METt   Et   GLUt   Qt   GLNt   Dt   ASPt   Nt   ASNt   St   SERt   Tt   THRt   Yt   TYRt   Ht   HISt   Kt   LYSt   Pt   PROt   Ct   CYSt   Rt   ARGt   MSEt   SMEt   CSOt   OCSt   CSXt   CMEt   YCMt   MLYi    i   t   Xs   
RU   (	   R•   R   R‚   R\   R°   R	   t   stdoutR   RC   (	   R–   t   reshashR—   R˜   R    t
   seq_stringR™   R"   t   code(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/cablam/cablam_training.pyt   res_seq_by_instance@  s$    -111


c         C   sÆ  t  j ƒ  } x³|  D]«} t  j j | ƒ r. n t  j | ƒ t  j | ƒ d } x`|  | D]T} | d 7} t  j j | ƒ d t | ƒ d } g  } x3 | j j	 ƒ  D]" }	 t |	 j
 ƒ }
 | j |
 ƒ q£ Wd d j | ƒ } d | d | d	 | } t j | ƒ } | | k r,i | d
 6| d 6| | <qY t j j d ƒ | | } d | d d | d | d
 j d | j d	 | } t j j | ƒ t j j d ƒ t j | ƒ } qY Wt  j | ƒ q W| S(   Ni    i   R    s   .pdbs   resseq s    or resseq s5   phenix.pdbtools stop_for_unknowns=False modify.keep="s   " s    output.file_name=R©   t   filenames   trying to superpose
s   phenix.superpose_pdbs RT   s    selection_default_fixed=s    selection_default_moving=s   
(   t   ost   getcwdt   patht   isdirt   mkdirt   chdirt   basenameR‡   R•   R¦   Rž   R°   RC   R   R@   R	   R
   R   t   superpose_thus(   R–   Rê   t   superpose_refst   pwdR—   t   instance_numR˜   t
   outputfilet   resnumsR   Rž   t	   selectiont   commandt   runthist   ref(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/cablam/cablam_training.pyt   trim_motifs^  s6     
$
8c   #   
   C   s  t  j j j d t ƒ } g  } xÔ |  D]Ì } t j j | ƒ r  t j	 | ƒ } | j
 d k r{ | j | j d d | ƒ ƒ qñ | j
 d k rñ | j | j ƒ qñ q% t j j | ƒ rÒ | j | j d d | ƒ ƒ q% | j d | ƒ } | j | ƒ q% Wt j d | ƒ } | j ƒ  } | j } | j } | j rBt ƒ  t j ƒ  n  | j rÜt j j d ƒ t j t  j j d ƒ ƒ }	 xV |	 D]N }
 |
 j d	 ƒ r}t j j t j j |
 ƒ ƒ d
 } t j j | d ƒ q}q}Wt j ƒ  n  | j sùt ƒ  t j ƒ  n  t j j | j ƒ r,t j | j ƒ }	 | j } nK t j j | j ƒ rV| j g }	 d  } n! t j! j d ƒ t ƒ  t j ƒ  | j" r¹t# | _$ t# | _% t# | _& t# | _' t# | _( t# | _) n  g  g  } } | j$ r
| j d ƒ | j d ƒ f | j d ƒ | j d ƒ f n  | j& rN| j d ƒ | j d ƒ f | j d ƒ | j d ƒ f n  | j* s`| j' r| j' rÜ| j d ƒ | j d ƒ f | j d ƒ | j d ƒ f | j d ƒ | j d ƒ f | j d ƒ | j d ƒ f q| j d ƒ | j d ƒ f | j d ƒ | j d ƒ f n  | j% rw| j d ƒ | j d ƒ f | j d ƒ | j d ƒ f | j d ƒ | j d ƒ f n  | j( rŸ| j d ƒ | j d ƒ f n  | j) rÇ| j d ƒ | j d ƒ f n  | j+ rTd | k rû| j d ƒ | j d ƒ f n  d | k r&| j d ƒ | j d ƒ f n  d | k rT| j d ƒ | j d ƒ f qTn  d d d d g } i  } i  } | j, r| j, d
 j- d ƒ } | j. r¯t j | j. ƒ } n  | j/ d  k rÜt0 t1 j2 | ƒ | | ƒ } q| j/ d! k rt3 | | | ƒ } qn  g  } | j4 rJ| j4 d
 j- d ƒ } g  | D] } | j5 ƒ  ^ q/} n  g  } g  } | j6 rx| j6 d
 j- d ƒ } n  | j7 rš| j7 d
 j- d ƒ } n  | j8 r¦n5 | j9 r¿t: | | ƒ n | j, rËn t; | | j< ƒ xø|	 D]ð}
 | rt j j= | |
 ƒ }
 n  t j j |
 ƒ } t j j |
 ƒ s0qân  t j	 |
 ƒ } | j
 d k rht j! j |
 d" ƒ qân  t j! j | d ƒ t> j? |
 ƒ } | j@ ƒ  } tA jB | | | ƒ } | s¸qân  tA jC | d# ƒ x | D] } tA jC | | ƒ qÏW| jD rtE | | jD ƒ n  | jF rtF | ƒ n  | j$ rI| j% rItG jH | d$ t# d% t# ƒnJ | j$ rntG jH | d$ t# d% tI ƒn% | j% r“tG jH | d$ tI d% t# ƒn  | j& r¬tG jJ | ƒ n  | j* s¾| j' rÎtG jK | ƒ n  | j( rçtG jL | ƒ n  | j) sÿ| jM d& k r	tG jN | ƒ n  | j+ r(	tG jO | ƒ n  | j, r�	| j. r�	| jP d' ƒ d( } | | k rât j j= | j. | ƒ } tQ | ƒ }  tR | |  ƒ |  jS ƒ  q¼	qân | j, r¼	tR | tT | ƒ ƒ n  | j, rÚ	t1 jU | | ƒ }! n  | j, rÏ
| j/ d  k r
tV |! | | ƒ n¾ | j/ d) k rD
tQ | d* d+ ƒ }" tW |! d, |" ƒ|" jS ƒ  n | j/ d! k ri
tX |! | | | ƒ nZ | j/ d- k r…
tY |! ƒ n> | j/ d. k r©
tZ |! |
 | ƒ } n t j! j d/ ƒ t j ƒ  t j }" qâ| j9 rO| j8 r3tQ | d0 d+ ƒ }" t: | | d, |" ƒt[ | | | | | jM d, |" ƒ|" jS ƒ  qÒt[ | | | | | jM ƒ qâ| j8 r³tQ | d1 d+ ƒ }" t; | | j< d, |" ƒt\ | | | | | j< | jM d, |" ƒ|" jS ƒ  qât\ | | | | | j< | jM ƒ qâW| rþx | D] }
 | |
 jS ƒ  qãWn  d  S(2   Nt   master_philR   R‰   s   file_or_dir="%s"t   philt   sourcess   
s'   cctbx_project/mmtbx/cablam/fingerprintss   .picklei    s-   Could not identify valid target file or dir.
t   CA_d_ins   -180 180t   CA_d_outt   CO_d_int   CO_d_outs   psi-1t   phit   psis   phi+1t   CA_a_ins   0 180t   CA_at   CA_a_outt   tauR3   R!   t   ORØ   RÊ   R~   t   kinR˜   s    not id'd as readable file
RS   t   dodihedralst   doanglesR2   s   .pdbs   .probet   annotes   cablam_motifs.kinR«   R|   t   sequencet	   superposes"   

Unrecognized probemode request

s   _cablam.kins   _cablam.csv(]   t   libtbxRþ   t   command_linet   argument_interpreterRý   Rë   Rí   t   isfileR   t   any_filet	   file_typeR°   t   processt   file_objectRî   t   fetcht   extractt   cablam_trainingt   helpR   R	   R%   t   list_motifsRå   R   t   listdirt   envt   find_in_repositoriesR$   t   splitextRñ   t   file_or_dirR)   R
   t   all_measuresR   t   cadt   caat   codt   exramaR	  R3   t   ramat   cablamt   probe_motifsRZ   t
   probe_patht
   probe_modeR’   R   t   get_all_labelsR¬   t   pruneR*   t
   skip_typest   include_typest   separate_filest   give_kinRŠ   R�   t   give_connectionsRC   R   t   inputt   construct_hierarchyR   t   construct_linked_residuest   prunerestypet   b_maxR   R   R   t	   CApseudosR   t   COpseudodihedralst   phipsit   taucalcR7   t	   omegacalct   cablam_measuresR¯   RŽ   R{   t   closeRP   t   check_proteinRš   R£   R³   Ré   Rü   RŒ   R…   (#   t   argst   interpreterRÿ   R‰   t
   input_filet   arg_philt	   work_philt   work_paramst   paramst   filesetRê   t	   motifnamet   dirpathR   Rˆ   t   targetatomsRó   R�   R¨   t   probefilelistt	   prunelistt   resR+   R,   Rœ   t   pdb_int   pdb_ioR<   R   t   restypet   probefilenamet   probefilepathR_   t   found_motifst   outfile(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/cablam/cablam_training.pyt   runŠ  sz     				"		
													"			"					 											
				%#(*   t
   __future__R    Rë   R	   t   iotbxR   t   mmtbx.cablamR   R   R   R  R   t   libtbx.phil.command_lineR   R   Rþ   t   parseR   Rý   R   R   R   R1   R8   RP   R{   Rå   R}   R   R�   R…   RŠ   RŒ   R’   Rš   R£   Rª   R¬   R³   Ré   Rü   RV  (    (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/cablam/cablam_training.pyt   <module>   sD   	W	·			L		%	e 							,