ó
ůxTc           @   s;   d  d l  m Z d   Z e d  Z d   Z d   Z d S(   i˙˙˙˙(   t   divisionc         C   s   d d l  } t | j |    S(   sx    Load the string and return the models.

  Params:
      string The JSON string to load

  Returns:
      The models

  i˙˙˙˙N(   t   jsont	   from_dictt   loads(   t   stringR   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/serialize/crystal.pyt   from_string   s    
c         C   sq   d d l  } d d l m } | t k rR | j t |   d d } | |  } n | j t |   d d	 } | S(
   s    Dump the given object to string.

  Params:
      obj The crystal model
      compact Write in compact representation

  Returns:
      The JSON string

  i˙˙˙˙N(   t   compact_simple_listst   indenti   t
   separatorst   ,t   :(   R	   R
   (   R   t   dxtbx.serialize.dumpR   t   Falset   dumpst   to_dict(   t   objt   compactR   R   R   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/serialize/crystal.pyt	   to_string   s    c         C   s-  d d l  m } |  j   j   } | d | d | d f } | d | d | d f } | d	 | d
 | d f } |  j   j   j   j   } |  j   } | d d | f d | f d | f d | f d | f g  } |  j	 d k r)t
 g  t |  j	  D] }	 |  j |	  j ^ qű  }
 |
 | d <n  | S(   s    Convert the crystal model to a dictionary

  Params:
      crystal The crystal model

  Returns:
      A dictionary of the parameters

  i˙˙˙˙(   t   OrderedDicti    i   i   i   i   i   i   i   i   t   __id__t   crystalt   real_space_at   real_space_bt   real_space_ct   space_group_hall_symbolt	   mosaicityt   A_at_scan_points(   R   s   crystal(   t   collectionsR   t   get_At   inverset   get_space_groupt   infot   typet   hall_symbolt   get_mosaicityt   num_scan_pointst   tuplet   ranget   get_A_at_scan_pointt   elems(   R   R   t   AR   R   R   t   hallR   t   xl_dictt   iR   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/serialize/crystal.pyR   9   s&    
				.c   	      C   sŇ   d d l  m } |  d k r  d St |  d  d k rE t d   n  |  d } |  d } |  d } t d	 |  d
  } |  d } | | | | d | d | } y |  d } | j |  Wn t k
 rÍ n X| S(   s    Convert the dictionary to a crystal model

  Params:
      d The dictionary of parameters

  Returns:
      The crystal model

  i˙˙˙˙(   t   crystal_modelR   R   s!   "__id__" does not equal "crystal"R   R   R   s   Hall:R   R   t   space_group_symbolR   N(   t   dxtbx.model.crystalR,   t   Nonet   strt
   ValueErrort   set_A_at_scan_pointst   KeyError(	   t   dR,   R   R   R   t   space_groupR   t   xlR   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/serialize/crystal.pyR   c   s&    




	
N(   t
   __future__R    R   R   R   R   R   (    (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/serialize/crystal.pyt   <module>   s   		*