ó
Æ™xTc           @   s�  d  d l  m Z d  d l Z d  d l Z i i e d 6e d 6e d 6e d 6e d 6e d 6e d	 6e d
 6e d 6e d 6e d 6e d 6e d 6e d 6e d 6e d 6e d 6e d 6e d 6e d 6e d 6e d 6e d 6e d 6d 6i e d 6e d 6e d 6e d 6e d  6e d! 6e d" 6e d# 6e d$ 6e d% 6e d& 6e d' 6e d( 6e d) 6e d* 6e d+ 6e d, 6e d- 6d. 6i e d 6e d/ 6e d0 6e d1 6e d" 6e d$ 6e d+ 6d2 6i e d 6e d 6e d3 6e d4 6e d5 6d6 6i e d 6e d 6e d3 6e d4 6e d7 6d8 6Z d9 e f d: „  ƒ  YZ	 d; „  Z
 d< „  Z e d= k r‰d  d l Z d  d l Z e e j d> ƒ Z x9 e D]. Z d? d@ GHe GHx e e D] Z e GHqsWqTWn  d S(A   iÿÿÿÿ(   t   divisionNt   idt   namet   typet	   pdbx_typet   formulat   mon_nstd_parent_comp_idt   pdbx_synonymst   pdbx_formal_charget   pdbx_initial_datet   pdbx_modified_datet   pdbx_ambiguous_flagt   pdbx_release_statust   pdbx_replaced_byt   pdbx_replacest   formula_weightt   one_letter_codet   three_letter_codet   pdbx_model_coordinates_detailst#   pdbx_model_coordinates_missing_flagt   pdbx_ideal_coordinates_detailst#   pdbx_ideal_coordinates_missing_flagt   pdbx_model_coordinates_db_codet   pdbx_processing_sitet   pdbx_subcomponent_listt
   _chem_compt   comp_idt   atom_idt   alt_atom_idt   type_symbolt   charget
   pdbx_alignt   pdbx_aromatic_flagt   pdbx_leaving_atom_flagt   pdbx_stereo_configt   model_Cartn_xt   model_Cartn_yt   model_Cartn_zt   pdbx_model_Cartn_x_idealt   pdbx_model_Cartn_y_idealt   pdbx_model_Cartn_z_idealt   pdbx_ordinalt   pdbx_component_atom_idt   pdbx_component_comp_idt   _chem_comp_atomt	   atom_id_1t	   atom_id_2t   value_ordert   _chem_comp_bondt   programt   program_versiont
   descriptort   _pdbx_chem_comp_descriptort
   identifiert   _pdbx_chem_comp_identifiert   emptyc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s;   d } x. |  j  D]# } | d | t |  | ƒ f 7} q W| S(   Ns   
Objects
   
  %s : %s(   t   __dict__t   getattr(   t   selft   outlt   attr(    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/chemical_components/cif_parser.pyt   __repr__J   s    !c         C   s   t  |  j j ƒ  ƒ S(   N(   t   lenR8   t   keys(   R:   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/chemical_components/cif_parser.pyt   __len__P   s    (   t   __name__t
   __module__R=   R@   (    (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/chemical_components/cif_parser.pyR7   I   s   	c         C   s0  d |  }  g  } d d d g } x
|  r+d } |  d | k rK |  d } n  |  j  | ƒ } |  j  | | d ƒ } |  j | ƒ } t d  | ƒ } | s˜ Pn  | d } | j | ƒ | d k rå t | ƒ d k rá | j | d ƒ n  Pn  | d k r|  t | ƒ d j ƒ  }  q" |  t | ƒ d	 j ƒ  }  q" W| S(
   Ns    %s t    t   't   "i    i   iÿÿÿÿi   i   (   t   findt   splitt   filtert   Nonet   appendR>   t   strip(   t   linet   tmpt
   delimiterst	   delimitert   startt   finisht   itemst   item(    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/chemical_components/cif_parser.pyt   smart_split_cif_lineS   s.    
	 
c         C   s  t  j j |  ƒ s d  St |  ƒ j ƒ  j ƒ  } t } xä| rg  } x0t | ƒ D]"\ } } | j	 d ƒ d k r� | | k rr| j
 | ƒ qrqP | j	 d ƒ d k rÄ | | k rr| j
 | ƒ qrqP | j	 d ƒ d k rt | j ƒ  ƒ d k rr| d | k r| j
 | d ƒ qqrqP | j	 d ƒ d k rP t | j ƒ  ƒ d k rr| d | k ro| j
 | d ƒ qoqrqP qP W| r7 | j ƒ  xŽ | D]ƒ } | | d j ƒ  r	| | d d k rä| | d c d | | d j ƒ  7<q	| | d c d | | j ƒ  7<n  | | =q�Wq7 q7 Wt | ƒ } i  } g  } i  } d }	 t }
 i  } d } xŸ| D]—} | j d	 d ƒ } | j	 d ƒ d k r‹qXn  | j	 d ƒ d k r©t }
 n  d | } t rÓx„ | j	 d ƒ d k r?| j	 d ƒ } | j	 d | d ƒ } | d k rPn  d | |  | | d | !j d
 d ƒ | | d f } q¼W|
 rÓx‡ | j	 d ƒ d k rÌ| j	 d ƒ } | j	 d | d ƒ } | d k r“Pn  d | |  | | d | !j d
 d ƒ | | d f } qIWqÓn  | j	 d ƒ d k rúg  } d } qXn  | j	 d ƒ d k rqXn  | j	 d ƒ d k r<xt D]´ } | j	 | ƒ d k rRq1n  xw t | D]k } d | | f } | j	 | ƒ d k r]| j
 | ƒ t | j ƒ  ƒ d k rÄ| j ƒ  d | | <n  Pq]q]W| j	 | ƒ d k r1Pq1q1W| j ƒ  d } | j d ƒ \ } } | j | g  ƒ | | j
 | ƒ | d 7} qX| rX|	 rc| j	 |	 ƒ d k rcqXn  t ƒ  } d } x t t | ƒ ƒ D]\ } } | | j | g  ƒ k r¯q…n  t | ƒ | k rÖd GH| GH| GHq…n  | | d k rï| }	 n  | d k rt | | | | ƒ } n  t | ƒ t d ƒ k rs| d d k r^| d d k r^| d d !} n  | j d d
 ƒ } n  t | | | | ƒ | d 7} q…W| j | g  ƒ t | d ƒ rÛt | j ƒ d k rÛd sØt ‚ qÛn  | | j
 | ƒ qXqXWxt D]} t ƒ  } xé | D]á } | j	 d | ƒ d k rt | | ƒ d k rV| | d } n d
 j | | ƒ } | j d ƒ d j ƒ  } | d  k rÞy t | | | ƒ } WqÞt k
 rÚ| GH| GH| GHt | j ƒ  GH‚  qÞXn  t | | | ƒ qqWt | ƒ rú| g | | <qúqúW| S(!   Nt   ;i    RE   s   _chem_comp.namei   s   _chem_comp.pdbx_synonymss    "%s"t    s   	RC   i   t   #t   _pdbxs   %s  iÿÿÿÿs   %s%s%st   _space_RD   t   loop_t   _s   %s.%s t   .s   Problem with CIF line parsingR   t   ?R   i   s   %s.(   RU   s           (   R]   R\   (   R]   R\   (   t   ost   patht   existsRI   t   opent   readt
   splitlinest   Truet	   enumerateRF   RJ   R>   RG   t   reverseRK   t   itert   Falset   replacet   cif_keyword_dictionaryt
   setdefaultR7   RT   t   getR   t   setattrt   hasattrR   t   AssertionErrort   joint	   ExceptionR?   (   t   filenamet   linest   merget   iRL   t	   line_itert   complete_cif_datat	   loop_listt   non_loopt   codet   pdbx_readingt   remove_loop_fieldst
   loop_indexRP   RQ   t   cif_keyR<   t   testRM   t   objt   ptrRS   t   keyt   sk(    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/chemical_components/cif_parser.pyt   runl   s    	
)%  	
 
 
    	  	  	 
t   __main__i   R[   iP   (   t
   __future__R    R^   t   syst   strt   intt   floatRj   t   objectR7   RT   R„   RA   t   argvt   cifR‚   RS   (    (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/chemical_components/cif_parser.pyt   <module>   s�   





		…	