Ejemplo n.º 1
0
def RandomNonoverlappingListOfAtoms(L,
                                    neighborLocator,
                                    minDist=1.0,
                                    nAtoms=10,
                                    temperature=1.0,
                                    maxTriesQuiet=1000,
                                    mass=1.0,
                                    radius=0.5,
                                    color=vi.color.green):
    """
    Put atoms of given radius in box (0,L)^dim, at random except without
    overlaps less than minDist.
    """
    pos = RandomArray.uniform(radius, L - radius, (nAtoms, dim))
    vel = numpy.zeros((nAtoms, dim))
    atoms = ListOfAtoms(mass, radius, color, pos, vel)
    # Enforce no overlaps
    # neighborLocator.HalfNeighbors returns (n1, n2, r, dr)
    # with n1 > n2: remove n1 atoms
    overlappingAtoms = neighborLocator.HalfNeighbors(atoms, minDist)[0]
    nPairOverlap = len(overlappingAtoms)
    tries = 0
    while nPairOverlap > 0:
        tries += 1
        if tries % maxTriesQuiet == 0:
            print "After ", tries, "attempts, still have ", nPairOverlap, \
             "overlapping pairs of atoms: may need fewer atoms or larger box"
        posNew = [pos for n, pos in enumerate(atoms.positions) \
           if n not in overlappingAtoms]
        nOverlap = nAtoms - len(posNew)
        newAtomPositions = RandomArray.uniform(radius, L - radius,
                                               (nOverlap, dim))
        posNew.extend(newAtomPositions)
        atoms.positions = numpy.array(posNew)
        overlappingAtoms = neighborLocator.HalfNeighbors(atoms, minDist)[0]
        nPairOverlap = len(overlappingAtoms)
    ThermalizingTransformer(atoms, temperature)
    return atoms
Ejemplo n.º 2
0
def RandomListOfAtoms(L,
                      nAtoms=1000,
                      temperature=1.0,
                      mass=1.0,
                      radius=0.5,
                      color=vi.color.green):
    """
    Put atoms of radius r in box (0,L)^dim
    """
    positions = RandomArray.uniform(radius, L - radius, (nAtoms, dim))
    velocities = numpy.zeros((nAtoms, dim))
    atoms = ListOfAtoms(mass, radius, color, positions, velocities)
    ThermalizingTransformer(atoms, temperature)
    return atoms
Ejemplo n.º 3
0
    def __init__(self, *args):
        apply(QWidget.__init__, (self,) + args)

	# make a QwtPlot widget
	self.plot = QwtPlot('A PyQwt and MinPack Demonstration', self)

	# initialize the noisy data
        scatter = 0.05
        x = arrayrange(-5.0, 5.0, 0.1)
        y = RandomArray.uniform(1.0-scatter, 1.0+scatter, shape(x)) * \
            function([1.0, 1.0, -2.0, 2.0], x)

        # fit from a reasonable initial guess
        guess = asarray([0.5, 1.5, -1.0, 3.0])
        yGuess = function(guess, x)
        solution = leastsq(function, guess, args=(x, y))
        yFit = function(solution[0], x)
        print solution

	# insert a few curves
	c1 = self.plot.insertCurve('data')
	c2 = self.plot.insertCurve('guess')
        c3 = self.plot.insertCurve('fit')
        
	# set curve styles
	self.plot.setCurvePen(c1, QPen(Qt.black))
        self.plot.setCurvePen(c2, QPen(Qt.red))
	self.plot.setCurvePen(c3, QPen(Qt.green))

	# copy the data
	self.plot.setCurveData(c1, x, y)
        self.plot.setCurveData(c2, x, yGuess)
        self.plot.setCurveData(c3, x, yFit)
	
	# set axis titles
	self.plot.setAxisTitle(QwtPlot.xBottom, 'x -->')
	self.plot.setAxisTitle(QwtPlot.yLeft, 'y -->')

        self.plot.enableLegend(1)
        self.plot.replot()
Ejemplo n.º 4
0
        x = []
        y = []
        for l in yprof.readlines():
            l = l.split()
            x.append(float(l[0]))
            y.append(float(l[1]))
        i = 0
        while i * delta[1] <= x[0]:
            vartopg[0, i, :] = y[0]
            i = i + 1
            if i == numx:
                break
        for d in range(0, len(x) - 1):
            slope = (y[d + 1] - y[d]) / (x[d + 1] - x[d])
            if i == numx:
                break
            while i * delta[1] <= x[d + 1]:
                vartopg[0, i, :] = y[d] + (i * delta[1] - x[d]) * slope
                i = i + 1
                if i == numx:
                    break
        for i in range(i, numx):
            vartopg[0, i, :] = y[d]

    else:
        vartopg[0, :, :] = 0.0

    vartopg[0, :, :] = vartopg[0, :, :] + RandomArray.uniform(0.0, amplitude, (numy, numx)).astype(Numeric.Float32)

    cffile.close()
Ejemplo n.º 5
0
    def DrawTest(self, event=None):
        wx.GetApp().Yield()
        import random
        import RandomArray
        Range = (-10, 10)
        colors = self.colors

        #self.BindAllMouseEvents()
        Canvas = self.components.float

        Canvas.ClearAll()
        Canvas.SetProjectionFun(None)

        ## Random tests of everything:

        # Rectangles
        for i in range(3):
            x, y = (random.uniform(Range[0], Range[1]),
                    random.uniform(Range[0], Range[1]))
            lw = random.randint(1, 5)
            cf = random.randint(0, len(colors) - 1)
            h = random.randint(1, 5)
            w = random.randint(1, 5)
            Canvas.AddRectangle(x, y, h, w, LineWidth=lw, FillColor=colors[cf])

        # Ellipses
        for i in range(3):
            x, y = (random.uniform(Range[0], Range[1]),
                    random.uniform(Range[0], Range[1]))
            lw = random.randint(1, 5)
            cf = random.randint(0, len(colors) - 1)
            h = random.randint(1, 5)
            w = random.randint(1, 5)
            Canvas.AddEllipse(x, y, h, w, LineWidth=lw, FillColor=colors[cf])


##            # Dots -- Does anyone need this?
##            for i in range(5):
##                x,y = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
##                D = random.randint(1,50)
##                lw = random.randint(1,5)
##                cf = random.randint(0,len(colors)-1)
##                cl = random.randint(0,len(colors)-1)
##                Canvas.AddDot(x,y,D,LineWidth = lw,LineColor = colors[cl],FillColor = colors[cf])

# Circles
        for i in range(5):
            x, y = (random.uniform(Range[0], Range[1]),
                    random.uniform(Range[0], Range[1]))
            D = random.randint(1, 5)
            lw = random.randint(1, 5)
            cf = random.randint(0, len(colors) - 1)
            cl = random.randint(0, len(colors) - 1)
            Canvas.AddCircle(x,
                             y,
                             D,
                             LineWidth=lw,
                             LineColor=colors[cl],
                             FillColor=colors[cf])
            Canvas.AddText("Circle # %i" % (i),
                           x,
                           y,
                           Size=12,
                           BackgroundColor=None,
                           Position="cc")

            # Lines
        for i in range(5):
            points = []
            for j in range(random.randint(2, 10)):
                point = (random.randint(Range[0], Range[1]),
                         random.randint(Range[0], Range[1]))
                points.append(point)
            lw = random.randint(1, 10)
            cf = random.randint(0, len(colors) - 1)
            cl = random.randint(0, len(colors) - 1)
            Canvas.AddLine(points, LineWidth=lw, LineColor=colors[cl])

            # Polygons
        for i in range(3):
            points = []
            for j in range(random.randint(2, 6)):
                point = (random.uniform(Range[0], Range[1]),
                         random.uniform(Range[0], Range[1]))
                points.append(point)
            lw = random.randint(1, 6)
            cf = random.randint(0, len(colors) - 1)
            cl = random.randint(0, len(colors) - 1)
            Canvas.AddPolygon(points,
                              LineWidth=lw,
                              LineColor=colors[cl],
                              FillColor=colors[cf],
                              FillStyle='Solid')

        ## Pointset
        for i in range(4):
            points = []
            points = RandomArray.uniform(Range[0], Range[1], (100, 2))
            cf = random.randint(0, len(colors) - 1)
            D = random.randint(1, 4)
            Canvas.AddPointSet(points, Color=colors[cf], Diameter=D)

        # Text
        String = "Unscaled text"
        for i in range(3):
            ts = random.randint(10, 40)
            cf = random.randint(0, len(colors) - 1)
            x, y = (random.uniform(Range[0], Range[1]),
                    random.uniform(Range[0], Range[1]))
            Canvas.AddText(String,
                           x,
                           y,
                           Size=ts,
                           Color=colors[cf],
                           Position="cc")

        # Scaled Text
        String = "Scaled text"
        for i in range(3):
            ts = random.random() * 3 + 0.2
            cf = random.randint(0, len(colors) - 1)
            x, y = (random.uniform(Range[0], Range[1]),
                    random.uniform(Range[0], Range[1]))
            Canvas.AddScaledText(String,
                                 x,
                                 y,
                                 Size=ts,
                                 Color=colors[cf],
                                 Position="cc")

        Canvas.ZoomToBB()