ó
Š™xTc           @   sŽ   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 m	 Z	 d  d l
 Z
 d e f d „  ƒ  YZ d S(	   iÿÿÿÿ(   t   division(   t$   insure_identity_is_in_transform_info(   t   crystal_symmetry_from_anyN(   t   Sorry(   t   pdbt   multimerc           B   s\   e  Z d  Z d d
 d
 e d e d „ Z d „  Z d „  Z d d
 d „ Z d „  Z	 d	 „  Z
 RS(   s”  
  Reconstruction of either the biological assembly or the crystallographic asymmetric unit

  Reconstruction of the biological assembly multimer by applying
  BIOMT transformation, from the pdb file, to all chains.

  Reconstruction of the crystallographic asymmetric unit by applying
  MTRIX transformations, from the pdb file, to all chains.

  self.assembled_multimer is a pdb.hierarchy object with the multimer information

  The method write generates a PDB file containing the multimer

  since chain names string length is limited to two, this process does not maintain any
  referance to the original chain names.

  Several useful attributes:
  --------------------------
  self.write() : To write the new object to a pdb file
  self.assembled_multimer : The assembled or reconstructed object is in
  self.number_of_transforms : Number of transformations that where applied

  @author: Youval Dar (LBL )
  t   caugü©ñÒMbP?c   
      C   s¶  | s | s t  ‚ | rK | |  _ t j j d | ƒ } t j d | ƒ } n6 d |  _ t j j d | ƒ } t j d | d d ƒ } | d k r± | j d | d | ƒ }	 d	 |  _ no | d
 k r| j d | d | ƒ }	 |	 j	 ƒ  d k rð d }	 n t
 |	 ƒ }	 d |  _ n t d d d d ƒ ‚ t | j j ƒ  ƒ d k rNt d d ƒ ‚ n  t j j j ƒ  |  _ |  j j d |	 d | ƒ t |  j j ƒ |  _ |  j j d | j d | ƒ |  _ d S(   sS  
    Arguments:
    reconstruction_type -- 'ba' or 'cau'
                           'ba': biological assembly
                           'cau': crystallographic asymmetric unit
    file_name -- the name of the pdb file we want to process.
                 a string such as 'pdb_file_name.pdb'
    pdb_str -- a string containing pdb information, when not using a pdb file
    error_handle -- True: will stop execution on improper rotation matrices
                    False: will continue execution but will replace the values
                          in the rotation matrix with [0,0,0,0,0,0,0,0,0]
    eps -- Rounding accuracy for avoiding numerical issue when when testing
           proper rotation
    round_coordinates -- round coordinates of new NCS copies, for sites_cart
                         constancy

    @author: Youval Dar (2013)
    t	   file_names   complete_reconstructed_unit.pdbt
   pdb_stringt   linest   source_infot   bat   error_handlet   epst   biological_assemblyR   t    t   crystall_asymmetric_units+   Sorry, wrong reconstruction type is given 
s   Reconstruction type can be: 
s   'ba': biological assembly 
s)   'cau': crystallographic asymmetric unit 
i   s8   Sorry, this feature currently supports on single models t   hierarchiest   transform_infot   pdb_hierarchy_inpt   pdb_hierarchyt   round_coordinatesN(   t   AssertionErrort   pdb_input_file_nameR   t	   hierarchyt   inputt   Nonet   process_BIOMT_recordst   transform_typet   process_mtrix_recordst   as_pdb_stringR   R   t   lent   modelst   iotbxt   ncst   ncs_preprocesst   ncs_group_objectt   transforms_objt   build_ncs_obj_from_pdb_ncst   transform_to_be_usedt   number_of_transformst   build_asu_hierarchyt   assembled_multimer(
   t   selft   reconstruction_typeR   t   pdb_strR   R   R   t   pdb_objt   pdb_inpR   (    (    sO   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/pdb/multimer_reconstruction.pyt   __init__$   sF    						 	
	c         C   s   |  j  j } |  j j | ƒ S(   s:   
    Retrieve the Original PDB hierarchy from the ASU
    (   R%   t   ncs_atom_selectionR*   t   select(   R+   t   ncs_selection(    (    sO   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/pdb/multimer_reconstruction.pyt   get_ncs_hierarchyj   s    c         C   s   |  j  j ƒ  j ƒ  S(   s[    () -> flex.vec3
    Returns the reconstructed hierarchy sites cart (atom coordinates)
    (   R*   t   atomst   extract_xyz(   R+   (    (    sO   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/pdb/multimer_reconstruction.pyt
   sites_cartq   s    R   c         C   s§   t  j j |  j ƒ } | d k r* | } n  | | k rM |  j d | |  _ n	 | |  _ | r‡ t  j j |  j ƒ r‡ t j |  j ƒ } n  |  j	 j
 d |  j d | ƒ d S(   sV   (string) -> text file
    Writes the modified protein, with the added chains, obtained by the BIOMT/MTRIX
    reconstruction, to a text file in a pdb format.
    self.assembled_multimer is the modified pdb object with the added chains

    Argumets:
    pdb_output_file_name -- string. 'name.pdb'
    if no pdn_output_file_name is given pdb_output_file_name=file_name

    >>> v = multimer('name.pdb','ba')
    >>> v.write('new_name.pdb')
    Write a file 'new_name.pdb' to the current directory
    >>> v.write(v.pdb_input_file_name)
    Write a file 'copy_name.pdb' to the current directory
    R   t   _R   t   crystal_symmetryN(   t   ost   patht   basenameR   R   t   pdb_output_file_namet   isfileR   t   extract_fromR*   t   write_pdb_file(   R+   R=   R9   t   input_file_name(    (    sO   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/pdb/multimer_reconstruction.pyt   writex   s    		c         C   s   |  j  j ƒ  S(   N(   R%   t   get_ncs_restraints_group_list(   R+   (    (    sO   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/pdb/multimer_reconstruction.pyRC   š   s    c         C   s
   |  j  j S(   N(   R%   t   total_asu_length(   R+   (    (    sO   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/pdb/multimer_reconstruction.pyRD   �   s    N(   t   __name__t
   __module__t   __doc__R   t   TrueR0   R4   R7   RB   RC   RD   (    (    (    sO   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/pdb/multimer_reconstruction.pyR      s   @		"	(   t
   __future__R    t   iotbx.ncs.ncs_preprocessR   R!   R   t   iotbx.pdb.hierarchyt   libtbx.utilsR   R   R:   t   objectR   (    (    (    sO   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/pdb/multimer_reconstruction.pyt   <module>   s   