Exemple #1
0
def moves(fileNames):
    S = io_open(fileNames[0])
    V = viz.VizSystem(S)
    V.vizMakeBox()

    objs = []
    connMax = S.connMax
    frame_index = 0

    while True:
        print fileNames[frame_index][-20:],
        S = io_open(fileNames[frame_index])
        S.eddEnable()
        nMovesPerParticle = []

        for i in range(len(objs)):
            objs[-1].visible = 0
            del objs[-1]
        for i in range(S.N):
            nMovesPerParticle.append(0)
            pos = S.atompos[i]
            startCoords = S.coords(pos)
            for conni in range(connMax):
                if S.MLLr[pos * S.connMax + conni] == -1:
                    continue
                nMovesPerParticle[-1] += 1
                end = S.conn[pos, conni]
                endCoords = S.coords(end)

                axis = endCoords - startCoords
                if math.sqrt(numpy.sum(axis * axis)) > 5:
                    continue
                objs.append(visual.arrow(pos=startCoords, axis=axis, shaftwidth=0.1, headlength=1, fixedwidth=1))
        print "all: %.3f %.3f    mobile: %.3f %.3f " % (
            numpy.mean(nMovesPerParticle),
            numpy.std(nMovesPerParticle),
            numpy.mean([x for x in nMovesPerParticle if x > 0]),
            numpy.std([x for x in nMovesPerParticle if x > 0]),
        ),
        sys.stdout.flush()

        frame_index = getNewFrameIndex(frame_index, len(fileNames))
        if frame_index == None:
            break
    for i in range(len(objs)):
        objs[-1].visible = 0
        del objs[-1]
    visual.scene.visible = 0
    print
Exemple #2
0
def overlap(*fileNames):
    listOfFrames, listOfNames = openFiles(fileNames)
    frame0 = listOfFrames[0]

    if isinstance(frame0, str):
        frame0 = io_open(frame0)

    frame_index = 0
    V = viz.VizSystem(frame0)
    V.vizMakeBox()
    objs = []
    print frame0.lattSize
    while True:
        print "\r",
        print listOfNames[frame_index][-20:],
        frame = listOfFrames[frame_index]
        if isinstance(frame, str):
            frame = io_open(frame)
        # print frame, frame0
        if frame0.lattShape != frame.lattShape:
            raise Exception("different lattice shapes!")
        for i in range(len(objs)):
            objs[0].visible = 0
            del objs[0]
        usePersist = False

        if frame.persist is not None and usePersist:
            for pos in range(frame0.lattSize):
                if frame.persist[pos] != 0:
                    objs.append(visual.sphere(pos=vector(frame0.coords(i)), radius=0.25, color=visual.color.red))
        for pos in range(frame0.lattSize):
            if not (frame0.lattsite[pos] != saiga12.S12_EMPTYSITE) or not (
                frame.lattsite[pos] != saiga12.S12_EMPTYSITE
            ):
                continue
            objs.append(visual.sphere(pos=endCoords, radius=0.25, color=visual.color.white))

        sys.stdout.flush()
        frame_index = getNewFrameIndex(frame_index, len(listOfFrames), V=V, otherObjects=objs)
        if frame_index == None:
            break

    for i in range(len(objs)):
        objs[0].visible = 0
        del objs[0]
    visual.scene.visible = 0
    print
Exemple #3
0
def openFilesIter(arguments):
    # If it is a list, look at the objects
    # If it is a dict, look at the values
    # Otherwise, assume it's a S object in the filename itself.
    for fname in arguments:
        listOfFrames = []
        listOfNames = []
        data = pickle.load(open(fname))
        if isinstance(data, list):
            listOfFrames.extend(data)
            listOfNames.extend([fname + ":" + str(i) for i in range(len(data))])
        if isinstance(data, dict):
            sortedKeys = sorted(data.keys())
            listOfNames.extend(fname + ":" + str(x) for x in sortedKeys)
            listOfFrames.extend([data[name] for name in sortedKeys])
        else:
            # We have a big list of fnames
            listOfFrames.append(io_open(fname))
            listOfNames.append(fname)
        for frame, name in zip(listOfFrames, listOfNames):
            yield frame, name
Exemple #4
0
def diff(*fileNames):
    listOfFrames, listOfNames = openFiles(fileNames)
    frame0 = listOfFrames[0]

    if isinstance(frame0, str):
        frame0 = io_open(frame0)
    if frame0.cycleModeStr in ("fredricksonandersen", "east", "spiral", "spinmontecarlo"):
        difftype = "spin"
    else:
        difftype = "particle"

    frame_index = 0
    V = viz.VizSystem(frame0)
    V.vizMakeBox()
    objs = []
    print frame0.lattSize
    while True:
        print "\r",
        print listOfNames[frame_index][-20:],
        frame = listOfFrames[frame_index]
        if isinstance(frame, str):
            frame = io_open(frame)
        # print frame, frame0
        if frame0.lattShape != frame.lattShape:
            raise Exception("different lattice shapes!")
        for i in range(len(objs)):
            objs[0].visible = 0
            del objs[0]
        moveTypes = {}
        nMove = 0
        nMoved = 0
        moveDistance = 0.0
        moveDistances = []
        usePersist = False

        if difftype == "particle":
            if frame.persist is not None and usePersist:
                for i in range(frame0.lattSize):
                    if frame.persist[i] != 0 and frame.lattsite[i] == saiga12.S12_EMPTYSITE:
                        objs.append(visual.sphere(pos=vector(frame0.coords(i)), radius=0.25, color=visual.color.red))
            for n in range(frame0.N):
                if frame0.atompos[n] == frame.atompos[n]:
                    continue
                type_ = frame0.atomtype[n]
                moveTypes[type_] = moveTypes.get(type_, 0) + 1
                # old position - red
                startCoords = frame0.coords(frame0.atompos[n])
                if frame.lattsite[frame0.atompos[n]] == saiga12.S12_EMPTYSITE:
                    objs.append(visual.sphere(pos=vector(startCoords), radius=0.25, color=visual.color.red))
                # new position: whatever
                endCoords = frame0.coords(frame.atompos[n])
                objs.append(
                    visual.sphere(
                        pos=endCoords, radius=0.25, color=V.vizColors.get(frame0.atomtype[n], visual.color.white)
                    )
                )
                d = frame0.distance(frame0.atompos[n], frame.atompos[n])
                d_raw = endCoords - startCoords
                d_raw = math.sqrt(numpy.sum(d_raw * d_raw))
                if d_raw < 7.5:
                    objs.append(
                        visual.arrow(
                            pos=startCoords, axis=endCoords - startCoords, shaftwidth=0.1, headlength=1, fixedwidth=1
                        )
                    )
                moveDistance += d
                moveDistances.append(d)
            print moveTypes, "%.4f" % numpy.mean(moveDistances), "%.4f" % numpy.std(moveDistances), "%.4f" % (
                len(moveDistances) / frame0.lattSize
            ),
        if difftype == "spin":
            for i in range(frame0.lattSize):
                if frame.persist[i] != 0:
                    objs.append(visual.sphere(pos=vector(frame0.coords(i)), radius=1, color=visual.color.red))
                    nMoved += 1
                if frame.lattsite[i] != saiga12.S12_EMPTYSITE:
                    objs.append(
                        visual.sphere(
                            pos=vector(frame0.coords(i)),
                            radius=1,
                            color=V.vizColors.get(frame.atomtype[frame.lattsite[i]], visual.color.white),
                        )
                    )
                    nMove += 1

            print "%.4f" % (float(nMove) / frame.lattSize), "%.4f" % (float(nMoved) / frame.lattSize),
        sys.stdout.flush()
        frame_index = getNewFrameIndex(frame_index, len(listOfFrames), V=V, otherObjects=objs)
        if frame_index == None:
            break

    for i in range(len(objs)):
        objs[0].visible = 0
        del objs[0]
    visual.scene.visible = 0
    print
Exemple #5
0
        if part1 is not None:
            S.addParticle(site0, type1)
            # if S.orient: orient initialized randomly in C


if __name__ == "__main__":
    if len(sys.argv) == 1 or sys.argv[1] in ("--help", "-h", "help"):
        print """usage: util.py <command> <arguments>...

        commands are:
        hash -- print command line hashes of all filename arguments
        """

    elif sys.argv[1] == "hash":
        for name in sys.argv[2:]:
            S = io_open(name)
            print name, S.hash()

    elif sys.argv[1] == "diff":
        diff(*sys.argv[2:])

    elif sys.argv[1] == "moves":
        moves(sys.argv[2:])

    elif sys.argv[1] == "kvecs":
        visualizeKvectors(sys.argv[2:])
    elif sys.argv[1] == "kvecs-each":
        visualizeKvectors(sys.argv[2:], mode="each")
    elif sys.argv[1] == "kvecs-avg":
        visualizeKvectors(sys.argv[2:], mode="avg")