def draw_displacement_wrapper(gf, dt, event_type, a, r0=None, sigma=None):
    if ((event_type == EventType.COM_ESCAPE or event_type == EventType.SINGLE_ESCAPE) and sigma == None) or (
        event_type == EventType.IV_ESCAPE and sigma != None
    ):
        # Escape through this coordinate. We already know the new r.
        # Todo. Let gf handle this.
        return a
    elif event_type == EventType.IV_REACTION and sigma != None:
        # Todo. Let gf handle this.
        return sigma

    rnd = myrandom.uniform()

    if __debug__:
        log.debug("        *drawR. " + gf.__class__.__name__)
    try:
        if r0 == None:
            r = gf.drawR(rnd, dt)
        else:
            r = gf.drawR(rnd, r0, dt)
        while r > a or r <= sigma:  # redraw; shouldn't happen often
            if __debug__:
                log.debug("        *drawR: redraw")
            rnd = myrandom.uniform()
            if r0 == None:
                r = gf.drawR(rnd, dt)
            else:
                r = gf.drawR(rnd, r0, dt)
    except Exception, e:
        raise Exception("gf.drawR() failed, " "%s, rnd = %g, r0 = %s, dt = %g, %s" % (str(e), rnd, r0, dt, gf.dump()))
Esempio n. 2
0
def draw_displacement_wrapper(gf, dt, event_type, a, r0=None, sigma=None):
    if(((event_type == EventType.COM_ESCAPE or
         event_type == EventType.SINGLE_ESCAPE) and sigma == None) or
       (event_type == EventType.IV_ESCAPE and sigma != None)):
        # Escape through this coordinate. We already know the new r.
        # Todo. Let gf handle this.
        return a
    elif event_type == EventType.IV_REACTION and sigma != None:
        # Todo. Let gf handle this.
        return sigma

    rnd = myrandom.uniform()

    if __debug__:
        log.debug('        *drawR. ' + gf.__class__.__name__)
    try:
        if r0 == None:
            r = gf.drawR(rnd, dt)
        else:
            r = gf.drawR(rnd, r0, dt)
        while r > a or r <= sigma: # redraw; shouldn't happen often
            if __debug__:
                log.debug('        *drawR: redraw')
            rnd = myrandom.uniform()
            if r0 == None:
                r = gf.drawR(rnd, dt)
            else:
                r = gf.drawR(rnd, r0, dt)
    except Exception, e:
        raise Exception('gf.drawR() failed, '
                        '%s, rnd = %g, r0 = %s, dt = %g, %s' %
                        (str(e), rnd, r0, dt, gf.dump()))
Esempio n. 3
0
def random_vector(r):
    v = [
        myrandom.uniform(-1, 1),
        myrandom.uniform(-1, 1),
        myrandom.uniform(-1, 1)
    ]
    return _gfrd.normalize(v, r)
Esempio n. 4
0
def random_vector2D(r):
    # Return a random 2D cartesian vector of length r.

    v = [myrandom.uniform(-1,1), myrandom.uniform(-1,1)]
    # Todo. return _gfrd.normalize(v, r)
    v = numpy.array(v)
    norm = numpy.linalg.norm(v)
    return v * (r / norm)
Esempio n. 5
0
def random_vector2D(r):
    # Return a random 2D cartesian vector of length r.

    v = [myrandom.uniform(-1, 1), myrandom.uniform(-1, 1)]
    # Todo. return _gfrd.normalize(v, r)
    v = numpy.array(v)
    norm = numpy.linalg.norm(v)
    return v * (r / norm)
Esempio n. 6
0
    def random_position(self):
        """Only uniform if vector_x and vector_y have same length.

        """
        return (
            self.shape.position
            + myrandom.uniform(-1, 1) * self.shape.unit_x * self.shape.extent[0]
            + myrandom.uniform(-1, 1) * self.shape.unit_y * self.shape.extent[1]
        )
Esempio n. 7
0
    def random_position(self):
        """Returns a random position equidistributed within
        the region in space defined by negative signed distance.
        See also signed_distance_to().

        """
        corner = self.shape.position - self.size / 2.
        return numpy.array([
            myrandom.uniform(corner[0], self.size[0]),
            myrandom.uniform(corner[1], self.size[1]),
            myrandom.uniform(corner[2], self.size[2])
        ])
Esempio n. 8
0
    def random_position(self):
        """Returns a random position equidistributed within
        the region in space defined by negative signed distance.
        See also signed_distance_to().

        """
        corner = self.shape.position - self.size / 2.0
        return numpy.array(
            [
                myrandom.uniform(corner[0], self.size[0]),
                myrandom.uniform(corner[1], self.size[1]),
                myrandom.uniform(corner[2], self.size[2]),
            ]
        )
def draw_r_wrapper(gf, dt, a, sigma=None):
    rnd = myrandom.uniform()

    if __debug__:
        log.debug('        *drawR. ' + gf.__class__.__name__)
    try:
        r = gf.drawR(rnd, dt)
        while r > a or r <= sigma: # redraw; shouldn't happen often
            if __debug__:
                log.debug('        *drawR: redraw')
            rnd = myrandom.uniform()
            r = gf.drawR(rnd, dt)
    except Exception, e:
        raise Exception('gf.drawR() failed, '
                        '%s, rnd = %.16g, dt = %.16g, %s' %
                        (str(e), rnd, dt, gf.dump()))
Esempio n. 10
0
def draw_r_wrapper(gf, dt, a, sigma=None):
    rnd = myrandom.uniform()

    if __debug__:
        log.debug('        *drawR. ' + gf.__class__.__name__)
    try:
        r = gf.drawR(rnd, dt)
        while r > a or r <= sigma:  # redraw; shouldn't happen often
            if __debug__:
                log.debug('        *drawR: redraw')
            rnd = myrandom.uniform()
            r = gf.drawR(rnd, dt)
    except Exception, e:
        raise Exception('gf.drawR() failed, '
                        '%s, rnd = %.16g, dt = %.16g, %s' %
                        (str(e), rnd, dt, gf.dump()))
Esempio n. 11
0
def random_vector2D(r):
    # Return a random 2D cartesian vector of length r.
    phi = myrandom.uniform(0, Pi2)
    v = [math.cos(phi), math.sin(phi)] # sincos

    # Todo. return _gfrd.normalize(v, r)
    v = numpy.array(v)
    norm = numpy.linalg.norm(v)
    return v * (r / norm)
Esempio n. 12
0
def random_vector(r):
    # v, s = [0.0, 0.0, 0.0], 2.0
    # while s > 1.0:
    #     v[0] = myrandom.uniform (-1, 1)
    #     v[1] = myrandom.uniform (-1, 1)
    #     s = v[0] * v[0] + v[1] * v[1]

    # v[2] = -1 + 2 * s
    # a = 2 * numpy.sqrt(1 - s)
    # v[0] *= a
    # v[1] *= a

    cos_theta = myrandom.uniform(-1, 1)
    sin_theta = numpy.sqrt(1 - cos_theta * cos_theta)
    phi = myrandom.uniform(0, Pi2)
    sin_phi, cos_phi = math.sin(phi), math.cos(phi) # sincos
    v = [sin_theta * cos_phi, sin_theta * sin_phi, cos_theta]
    return _gfrd.normalize(v, r)
Esempio n. 13
0
def random_vector(r):
    # v, s = [0.0, 0.0, 0.0], 2.0
    # while s > 1.0:
    #     v[0] = myrandom.uniform (-1, 1)
    #     v[1] = myrandom.uniform (-1, 1)
    #     s = v[0] * v[0] + v[1] * v[1]

    # v[2] = -1 + 2 * s
    # a = 2 * numpy.sqrt(1 - s)
    # v[0] *= a
    # v[1] *= a

    cos_theta = myrandom.uniform(-1, 1)
    sin_theta = numpy.sqrt(1 - cos_theta * cos_theta)
    phi = myrandom.uniform(0, Pi2)
    sin_phi, cos_phi = math.sin(phi), math.cos(phi)  # sincos
    v = [sin_theta * cos_phi, sin_theta * sin_phi, cos_theta]
    return _gfrd.normalize(v, r)
Esempio n. 14
0
def random_vector2D(r):
    # Return a random 2D cartesian vector of length r.
    phi = myrandom.uniform(0, Pi2)
    v = [math.cos(phi), math.sin(phi)]  # sincos

    # Todo. return _gfrd.normalize(v, r)
    v = numpy.array(v)
    norm = numpy.linalg.norm(v)
    return v * (r / norm)
Esempio n. 15
0
def draw_time_wrapper(gf):
    rnd = myrandom.uniform()

    if __debug__:
        log.debug('        *drawTime. ' + gf.__class__.__name__)
    try:
        dt = gf.drawTime(rnd)
    except Exception, e:
        raise Exception('gf.drawTime() failed, '
                        '%s, rnd = %.16g, %s' % (str(e), rnd, gf.dump()))
Esempio n. 16
0
def draw_event_type_wrapper(gf, dt):
    rnd = myrandom.uniform()

    if __debug__:
        log.debug('        *drawEventType. ' + gf.__class__.__name__)
    try:
        event_type = gf.drawEventType(rnd, dt)
    except Exception, e:
        raise Exception('gf.drawEventType() failed, '
                        '%s, rnd = %.16g, dt = %.16g, %s' %
                        (str(e), rnd, dt, gf.dump()))
Esempio n. 17
0
def draw_event_type_wrapper(gf, dt):
    rnd = myrandom.uniform()

    if __debug__:
        log.debug('        *drawEventType. ' + gf.__class__.__name__)
    try:
        event_type = gf.drawEventType(rnd, dt)
    except Exception, e:
        raise Exception('gf.drawEventType() failed, '
                        '%s, rnd = %.16g, dt = %.16g, %s' %
                        (str(e), rnd, dt, gf.dump()))
Esempio n. 18
0
def draw_time_wrapper(gf):
    rnd = myrandom.uniform()

    if __debug__:
        log.debug('        *drawTime. ' + gf.__class__.__name__)
    try:
        dt = gf.drawTime(rnd)
    except Exception, e:
        raise Exception('gf.drawTime() failed, '
                        '%s, rnd = %.16g, %s' %
                        (str(e), rnd, gf.dump()))
Esempio n. 19
0
def draw_eventtype_wrapper(gf, dt, r0):
    rnd = myrandom.uniform()

    if __debug__:
        log.debug("        *drawEventType. " + gf.__class__.__name__)
    try:
        event_type = gf.drawEventType(rnd, r0, dt)
    except Exception, e:
        raise Exception(
            "gf.drawEventType() failed, " "%s, rnd = %g, r0 = %g, dt = %g, %s" % (str(e), rnd, r0, dt, gf.dump())
        )
Esempio n. 20
0
def drawTime_wrapper(gf, r0=None):
    rnd = myrandom.uniform()

    if __debug__:
        log.debug("        *drawTime. " + gf.__class__.__name__)
    try:
        if r0 == None:
            # Todo. Let gf handle this.
            dt = gf.drawTime(rnd)
        else:
            dt = gf.drawTime(rnd, r0)
    except Exception, e:
        raise Exception("gf.drawTime() failed, " "%s, rnd = %g, %s" % (str(e), rnd, gf.dump()))
Esempio n. 21
0
def draw_theta_wrapper(gf, r, dt):
    """Draw theta for the inter-particle vector.

    """
    rnd = myrandom.uniform()

    if __debug__:
        log.debug('        *drawTheta. ' + gf.__class__.__name__)
    try:
        theta = gf.drawTheta(rnd, r, dt)
    except Exception, e:
        raise Exception('gf.drawTheta() failed, '
                        '%s, rnd = %.16g, r = %.16g, dt = %.16g' %
                        (str(e), rnd, r, dt))  #, gf.dump()))
Esempio n. 22
0
    def drawTheta_wrapper(gf, r, r0, dt):
        """Draw theta for the inter-particle vector.

        """
        rnd = myrandom.uniform()

        if __debug__:
            log.debug("        *drawTheta. " + gf.__class__.__name__)
        try:
            theta = gf.drawTheta(rnd, r, r0, dt)
        except Exception, e:
            raise Exception(
                "gf.drawTheta() failed, " "%s, rnd = %g, r = %g, r0 = %g, dt = %g" % (str(e), rnd, r, r0, dt)
            )  # , gf.dump()))
Esempio n. 23
0
def drawTime_wrapper(gf, r0=None):
    rnd = myrandom.uniform()

    if __debug__:
        log.debug('        *drawTime. ' + gf.__class__.__name__)
    try:
        if r0 == None:
            # Todo. Let gf handle this.
            dt = gf.drawTime(rnd)
        else:
            dt = gf.drawTime(rnd, r0)
    except Exception, e:
        raise Exception('gf.drawTime() failed, '
                        '%s, rnd = %g, %s' %
                        (str(e), rnd, gf.dump()))
Esempio n. 24
0
rr['k'] = '.01'
m.network_rules.add_reaction_rule(rr)

nrw = _gfrd.NetworkRulesWrapper(m.network_rules)

w = _gfrd.World(1., 10)
region = _gfrd._CuboidalRegion("default",
        _gfrd.Box((.5, .5, .5), (1., 0., 0.), (0., 1., 0.), (0., 0., 1.), 1., 1., .1))
w.add_surface(region)

for s in [S0, S1, S2]:
    w.add_species(_gfrd.SpeciesInfo(s.id, float(s['D']), float(s['radius']), s['surface']))

for i in xrange(0, 300):
    w.new_particle([S0, S1][i % 2],
                   [myrandom.uniform(), myrandom.uniform(), myrandom.uniform()])

wn = vtk.vtkRenderWindow()
int = wn.MakeRenderWindowInteractor()
int.Initialize()
int.SetRenderWindow(wn)
r = vtk.vtkRenderer()
wn.AddRenderer(r)

actors = {}

def create_actor(pp):
    s = vtk.vtkSphereSource()
    s.SetRadius(pp[1].radius)
    s.SetCenter(pp[1].position)
    m = vtk.vtkPolyDataMapper()
Esempio n. 25
0
def random_unit_vector_s():
    s = numpy.array([1.0, myrandom.uniform(0, Pi), myrandom.uniform(0, Pi2)])
    return s
Esempio n. 26
0
def rng_uniform():
    '''Returns a positive random number
    '''
    while True:
        rng = myrandom.uniform(0.0, 1.0)
        if rng > 0.0: return rng
Esempio n. 27
0
def rng_uniform():
    '''Returns a positive random number
    '''
    while True:
        rng = myrandom.uniform(0.0, 1.0)
        if rng > 0.0: return rng
Esempio n. 28
0
    def random_position(self):
        """Only uniform if vector_x and vector_y have same length.

        """
        return self.shape.position + myrandom.uniform(-1, 1) * self.shape.unit_x * self.shape.extent[0] + \
                             myrandom.uniform(-1, 1) * self.shape.unit_y * self.shape.extent[1]
Esempio n. 29
0
w = MyParticleContainer(1.0)
region = _gfrd._CuboidalRegion(
    "default",
    _gfrd.Box((.5, .5, .5), (1., 0., 0.), (0., 1., 0.), (0., 0., 1.), 1., 1.,
              .1))
w.add_surface(region)

for s in [S0, S1, S2]:
    w.add_species(
        _gfrd.SpeciesInfo(s.id, float(s['D']), float(s['radius']),
                          s['surface']))

for i in xrange(0, 300):
    w.new_particle(
        [S0, S1][i % 2],
        [myrandom.uniform(),
         myrandom.uniform(),
         myrandom.uniform()])

wn = vtk.vtkRenderWindow()
int = wn.MakeRenderWindowInteractor()
int.Initialize()
int.SetRenderWindow(wn)
r = vtk.vtkRenderer()
wn.AddRenderer(r)

actors = {}


def create_actor(pp):
    s = vtk.vtkSphereSource()
Esempio n. 30
0
 def random_position(self):
     return (self.shape.position +
             myrandom.uniform(-1, 1) * self.shape.unit_z * self.shape.size)
Esempio n. 31
0
 def random_position(self):
     return self.shape.position + myrandom.uniform(-1, 1) * self.shape.unit_z * self.shape.size
Esempio n. 32
0
def random_vector(r):
    v = [myrandom.uniform(-1,1), myrandom.uniform(-1,1), myrandom.uniform(-1,1)]
    return _gfrd.normalize(v, r)
Esempio n. 33
0
def random_unit_vector_s():
    s = numpy.array([1.0, myrandom.uniform(0, Pi), myrandom.uniform(0, Pi2)])
    return s