B
    d(                 @   s   d dl mZmZmZ d dlZd dlZd dlZd dlm	  m
Z ed d dlZdd Zdd Zd dlT ee d	ZG d
d deZe ZdS )    )absolute_importdivisionprint_functionNscitbx_random_extc              C   sZ   yt  d t d  } W n0 tk
r2    Y n tk
rL   t } Y nX t| d S )Ni      i)osgetpidtimeKeyboardInterrupt	Exceptionint)result r   u/mnt/filia/a/genomebrowser/www/genomebrowser/fleming/tools/molprobity/modules/cctbx_project/scitbx/random/__init__.pyget_random_seed   s    
 r   c             C   s   t |  d S )N)mt19937seed)valuer   r   r   set_random_seed   s    r   )*)r   c               @   s4   e Zd ZdZdd Zdd Zdd Zefdd	Zd
S )variate_factorya  
  The corner stone of this package.

  Synopsis

    g = scitbx.random.variate(scitbx.random.normal_distribution(mean, sigma))

  How to use it from other modules?

    scitbx.random.variate.register(xxxx_ext)

  where xxxx_ext is a Boost.Python module featuring overloaded 'variate'
  functions, variate(engine, distribution), where engine is the like
  of mt19937 and distribution is the like of scitbx.random.normal_distribution.
  c             C   s
   g | _ d S )N)modules)selfr   r   r   __init__,   s    zvariate_factory.__init__c             C   s   | j | d S )N)r   append)r   moduler   r   r   register_module/   s    zvariate_factory.register_modulec             c   s$   t jV  x| jD ]}|jV  qW d S )N)r   variater   )r   r   r   r   r   variate_functions2   s     z!variate_factory.variate_functionsc             C   s   g }xz|   D ]V}y
|||S  tk
rb } z(t|jddkrP|| wn W d d }~X Y qX qW tddd |D d S )NzBoost.Python.ArgumentErrorr   
c             s   s   | ]}t |V  qd S )N)str).0er   r   r   	<genexpr>B   s    z+variate_factory.__call__.<locals>.<genexpr>)r   r   r    	__class__findr   RuntimeErrorjoin)r   distributionZengine
exceptionsr   r"   r   r   r   __call__6   s    

zvariate_factory.__call__N)	__name__
__module____qualname____doc__r   r   r   r   r*   r   r   r   r   r      s
   r   )
__future__r   r   r   r   r	   boost_adaptbx.boost.optionalboost_adaptbxboost_adaptbx.boost.pythonboostpythonbp
import_extr   r   r   Zmersenne_twister_19937r   objectr   r   r   r   r   r   <module>   s   
	*