Пример #1
0
def GetMaxPart():
    print("Scanning trajectory for parameters...")
    with cd.TrajHandle(trajPath) as th:
        n = len(th.ReadFrame(th.maxFrames))
    print("Done!")
    print("System contains {0} particles".format(n * 180))
    return n * 180
Пример #2
0
    def __init__(self, fPath):
        self.filePath = fPath
        self.th = celldiv.TrajHandle(fPath)
        Visualizer.ind += 1
        self.ind = Visualizer.ind
        self.pF = None

        bpy.data.worlds["World"].horizon_color=[0.051, 0.051, 0.051]
        bpy.data.scenes["Scene"].render.alpha_mode='SKY'

        self.firstfaces = []

        with open("/home/pranav/dev/celldiv/C180_pentahexa.csv", newline='') as g:
            readerfaces = csv.reader(g, delimiter=",")
            for row in readerfaces:
                self.firstfaces.append([int(v) for v in row])
Пример #3
0
def flatten(trajPath, storePath, inc, name=None, f=False):
    if name == None:
        storePath += "/flattened.xvg"
    else:
        storePath += "/" + name + ".xvg"

    print("writing to %s" % storePath)

    if os.path.isfile(storePath):

        print("overwriting {0}".format(storePath))

    CMx = 0
    CMy = 0
    CMz = 0

    with open(storePath, "w") as outFileHandle:
        t = celldiv.TrajHandle(trajPath)
        try:
            c = 0
            while c < t.maxFrames:
                frame = t.ReadFrame(inc)
                c += 1
                nCells = len(frame)
                t.nCellsLastFrame
                print("frame ", t.currFrameNum, nCells, " cells")
                CM = np.vstack([np.mean(c, axis=1) for c in frame])

                outFileHandle.write("%s\n" %
                                    " ".join([str(a) for a in CM[:, 0]]))
                outFileHandle.write("%s\n" %
                                    " ".join([str(a) for a in CM[:, 1]]))
                if f:
                    outFileHandle.write("%s\n" %
                                        " ".join([str(a) for a in CM[:, 2]]))

        except celldiv.IncompleteTrajectoryError as e:
            print("broken", e)
Пример #4
0
    return n * 180


def WriteFrame(frame, n):
    nP = len(frame) * 180
    outHandle.write("%d\n" % n)
    outHandle.write("%d, t = %d\n" % (nP, th.currFrameNum))
    CoM = np.mean(np.vstack(frame), axis=0)
    for c in frame:
        c = c[:-12] - CoM
        for p in c.tolist():
            outHandle.write("C  ")
            outHandle.write("  ".join([str(a) for a in p]))
            outHandle.write("\n")

        if nP < n:
            for _ in range(n - nP):
                outHandle.write(filler)


n = GetMaxPart()
filler = "C  0.0  0.0  0.0\n"
with cd.TrajHandle(trajPath) as th, open(args.out, "w") as outHandle:
    if args.frame != -1:
        frame = th.ReadFrame(frameNum=args.frame)
        WriteFrame(frame, len(frame) * 180)
    else:
        for i in tqdm(range(min(args.max, int(th.maxFrames / args.skip)))):
            frame = th.ReadFrame(inc=args.skip)
            WriteFrame(frame, n)
Пример #5
0
def measurePacking(filePath, storePath, name=None):
    fileName = os.path.splitext(os.path.split(filePath)[1])[0]
    print("Processing %s" % filePath)
    if name == None:
        storePath += '/' + fileName + '/' + '3DPacking/'
    else:
        storePath += '/' + fileName + '/' + name + '/'

    try:
        os.makedirs(storePath)
    except:
        pass

    dataPath = storePath + "data_best.dat"
    # Now read trajectory file and get the centre of masses of
    # all cells at every time step
    if os.path.isfile(dataPath):
        if os.path.getmtime(dataPath) > os.path.getmtime(filePath):
            print("{0} already processed.".format(filePath))
            print("Skipping")
            return dataPath

    print("Generating cell CoMs...")

    with celldiv.TrajHandle(filePath) as s,\
         open(storePath + "data.dat", 'w') as f:

        while True:
            try:
                frame = s.ReadFrame(inc=aRate)
            except:
                break
            step = s.step
            if s.fatalError:
                break

            nCells = len(frame)

            frame = [cell[:180] for cell in frame]

            if nCells > 3:
                CoMs = np.array([np.mean(cell, axis=0) for cell in frame])
                sysCoM = np.mean(CoMs, axis=0)
                CoMs -= sysCoM

                if args.flat == True:
                    CoMs = CoMs[:, 0:2]

                print("Doing Del of", CoMs.shape[0], "cells at step", step)
                try:
                    d = Delaunay(CoMs)
                    indices, indptr = d.vertex_neighbor_vertices
                    count = []
                    for p in range(nCells):
                        n = len(indptr[indices[p]:indices[p + 1]])
                        if n > len(count):
                            for i in range(len(count), n):
                                count.append(0)
                        count[n - 1] += 1 / nCells

                    f.write(", ".join([str(c) for c in count]))
                    f.write("\n")

                except QhullError:
                    print("delaunay failed, skipping")
                    pass

    return dataPath
Пример #6
0
        cellNeighs = [list(set(n)) for n in cellNeighs]
        return cellNeighs

    neighCells = GenCellNeighs()
    neighs = [0 for _ in range(nCells)]
    #print("Doing neighbour search of {} particles in {} cells\n".format(nCells*180, nCells))
    for i in range(nCells):
        iCell = frame[i]
        for j in neighCells[i]:
            jCell = frame[j]
            dr = iCell - jCell[:, np.newaxis]
            r = np.linalg.norm(dr, axis=2)
            if ((r < 0.3)).sum() > 0:
                neighs[i] += 1

    return neighs


def WriteNeighs(f, step, neighs):
    f.write("{}\n".format(step))
    f.write(",".join([str(n) for n in neighs]) + "\n")


with cd.TrajHandle(trajFile) as tj, open(outputFile, "w") as f:
    if args.frame_num > 0:
        WriteNeighs(f, tj.currFrameNum,
                    GetNeighs(tj.ReadFrame(args.frame_num)))
    else:
        for i in tqdm(range(tj.maxFrames)):
            WriteNeighs(f, tj.currFrameNum, GetNeighs(tj.ReadFrame()))
Пример #7
0
outName = os.path.splitext(args.out)

fig, ax = plt.subplots()
fig.set_size_inches(10, 10)

ax.set_xlabel("$X$")
ax.set_ylabel("$Y$")

frames = []

maxes = []
mins = []

if args.set_limits:
    with cd.TrajHandle(trajPath) as th:
        print("Getting movie limits...")

        if args.last_frame > 0 and args.last_frame > th.maxFrames:
            print("Trajectory only has {0} frames".format(th.maxFrames))
            args.last_frame = -1

        if args.frame > 0 and args.frame > th.maxFrames:
            print("Trajectory only has {0} frames".format(th.maxFrames))
            args.frame = th.maxFrames

        if args.frame > 0:
            frame = np.vstack(th.ReadFrame(args.frame))
        elif args.last_frame > 0:
            frame = np.vstack(th.ReadFrame(args.last_frame))
        else:
Пример #8
0
if not noClear and os.path.exists(sPath):
    for f in os.listdir(sPath):
        os.remove(sPath + f)

cellInds = []
minInd = args.min_cells - 1
if len(args.inds) > 0:
    minInd = max(minInd, min(args.inds))

stopAt = args.num_frames

# Set material color
bpy.data.materials['Material'].diffuse_color = [(1 / 255.0) * c
                                                for c in args.cell_color]
bpy.data.materials['Material'].specular_intensity = args.specular_intensity
with celldiv.TrajHandle(filename) as th:
    frameCount = 1
    try:
        for i in range(int(th.maxFrames / nSkip)):

            frameCount += 1
            if frameCount > args.num_frames:
                break

            f = th.ReadFrame(inc=nSkip)

            if len(f) < minInd + 1:
                print("Only ", len(f), "cells in frame ", th.currFrameNum,
                      " skipping...")
                continue