Beispiel #1
0
def calc_bondacf(args):
    """
    calculates persitence length using bond correlation function
    bondacf: bond correlation function analysis for L_p, when this
                parameter is provided, then program analyzes first points
                and fits them, to understand persistance length.
                C(n) = <u_0 u_n >
    method: create an array C,
    loop trajectory:
        loop residues:
            loop bonds:
                analyze angle between first bond vector and i
    average results
    plot using save_plots
    """
    psffile = get_path_names.get_filename(args.psffile)
    u = MDAnalysis.Universe(psffile + '.psf', args.traj)
    Nbonds = len(u.residues[0]) - 1
    Nres = len(u.residues)
    print "Nres = %r" % Nres
    print "Nbonds = %r" % Nbonds
    bonds = np.array((Nbonds, 3))
    C = np.zeros(Nbonds)
    k = 0
    for ts in u.trajectory[args.startframe:args.endframe:args.trajskip]:
        print "time = %r" % ts.frame
        for res in u.residues:
            bonds = AnalyzeChain.get_bondlist_coords(res)
            k += 1
            for ui in range(0, Nbonds):
                C[ui] += np.dot(bonds[0], bonds[ui])
    C /= float(k)
    ui_array = np.arange(Nbonds)
    save_plots.save_plot(ui_array, C, plotname='bondacf')
def get_seg_cryst(i, bonds, threshold=0.7, neigh=4):
    nleft, nright = int(neigh) / 2, int(neigh) / 2
    cos2_local = 0.
    AlignVec = AnalyzeChain.moving_average(bonds, neigh)
    cos2_local = np.dot(AlignVec[i - nleft, :], bonds[i, :])
    # cos2_local += np.dot(AlignVec[i+nright, :], bonds[i, :])
    # cos2_local /= 2.
    P2 = (3. * cos2_local**2.0 - 1.) / 2.
    return P2
def analyze_chain_hist(u, args):
    """
    loops through residues, finds crystallinity of each chain, and writes
    an array of chainlengths and chaing2s(chain crystallinities)
    input: Universe (MDAnalysis)
    output: chainlengths, chaing2s
    part of that_calculates_everything
    """
    chainlengths, chaing2s = [], []

    for res in u.residues:
        chords = AnalyzeChain.get_bondlist_coords(res)
        resid_cryst = AnalyzeChain.get_chain_crystallinity(chords)
        # all_g2 += resid_cryst
        chainlengths.append(len(res))
        chaing2s.append(resid_cryst)
    chainlengths = np.array(chainlengths)
    chaing2s = np.array(chaing2s)
    return chainlengths, chaing2s
def main(args):
    """main func"""
    psffile = get_path_names.get_filename(args.psffile)
    u = MDAnalysis.Universe(psffile + '.psf', args.traj)

    bonds = AnalyzeChain.get_bondlist_coords(u.residues[0])
    L = 0.  # number of lamellae
    # the skip on the left and on the right,
    nleft, nright = int(args.neigh) / 2, int(args.neigh) / 2
    Nbonds = len(bonds)
    Nres = len(u.residues)
    timeframes, L_array = [], []

    if args.filedumpskip:
        dumpskip = AnalyzeLog.get_dumpskip(filename='dumpskip.txt',
                                           keyparameter="dump" +
                                           args.keyparameter + "skip")
        timestep = AnalyzeLog.get_timestep(filename='dumpskip.txt',
                                           keyparameter="time" +
                                           args.keyparameter + "step")
    else:
        print "using given parameters"
        dumpskip = args.dumpskip
        timestep = args.timestep

    for ts in u.trajectory[args.startframe:args.endframe:args.trajskip]:
        print "frame = {frame}, percent of lamellae={num_of_lam}"\
               .format(frame=ts.frame,
                       num_of_lam=L/float(Nres))
        timeframes.append(ts.frame)
        L = 0.
        for myres in u.residues:
            bonds = AnalyzeChain.get_bondlist_coords(myres)
            Flag = True  # assume we hit the straight segment of the chain
            atom_indices = []  # indices of atoms in the current lamellae
            for i in xrange(nleft, Nbonds - nright - 1):
                if not Flag:  # if we ended a straight segment, check the len
                    Nlam = len(atom_indices)
                    if Nlam > 9:
                        L += 1.


# print colored( 'lamellae size is %d ' % Nlam, 'green')
# start looking for a new lamellae
                    atom_indices = []
                    Flag = True
                else:
                    # if we still are hitting straight segments
                    ci = get_seg_cryst(i,
                                       bonds,
                                       threshold=args.threshold,
                                       neigh=args.neigh)
                    if ci > args.threshold:
                        # print "segment = %d, | ci = %4.3f" % (i,ci)
                        Flag = True
                        atom_indices.append(i)
                    elif ci > 0.0:
                        # print "segment = %d, > ci = %4.3f" % (i,ci)
                        Flag = False
                    else:
                        ValueError("crystallinity is negative")
        L_array.append(L / float(Nres))
    timeframes = np.array(timeframes)
    L_array = np.array(L_array)
    save_plots.save_plot(timeframes,
                         L_array,
                         plotname='lamellae',
                         name=psffile,
                         logplot=args.logplot,
                         dumpskip=dumpskip,
                         timestep=timestep,
                         ylabel='frac{N_{stems}}{N_{chains}}')
def main():
    args = read_parameters.read_traj_vmd()
    print args
    u = MDAnalysis.Universe(args.psffile, args.traj)
    psffile = get_path_names.get_filename(u.filename)
    n_atoms_per_box = args.nAtomsPerBox
    Natoms = u.trajectory.numatoms
    Nx_atoms = Natoms**(1./3.) # how many atoms in a line
    Nsub = int(Nx_atoms / float(n_atoms_per_box)) # how many segements of 3 atoms
    cryst_all = 0.0
    # box = u.trajectory.ts.dimensions[:-3]
    # length_x = box[-1]
    u.SYSTEM.packIntoBox()
    a = u.selectAtoms("all")
    c = a.coordinates()
    print c
    length_x = a.bbox().max()
    grid_1d = np.linspace(0.0, length_x, Nsub+1, endpoint=True)
    delta = grid_1d[1] - grid_1d[0]
    frame = []
    g2 = []

    if args.filedumpskip:
        dumpskip = AnalyzeLog.get_dumpskip(filename='dumpskip.txt',
                                           keyparameter="dump" +
                                           args.keyparameter+"skip")
        # dumpskip = args.dumpskip
        timestep = AnalyzeLog.get_timestep(filename='dumpskip.txt',
                                           keyparameter="time" +
                                           args.keyparameter
                                           + "step")
    else:
        print "using given parameters"
        dumpskip = args.dumpskip
        timestep = args.timestep

    # decide the skipping information
    if args.auto_traj_skip:
        trajskip = int(u.trajectory.numframes/120.)
        if trajskip < 1:
            trajskip = 1
    elif args.auto_traj_skip:
        trajskip = args.trajskip
    else:
        raise ValueError("trajskip needs to be provided")
    for ts in u.trajectory[args.startframe:args.endframe:trajskip]:
        # ar_z is a planar selection
        u.SYSTEM.packIntoBox()
        for i, z in enumerate(grid_1d[0:-1]):
            ar_z = u.selectAtoms("prop  z >= "
                                 + str(z) +
                                 "  and  prop z < "
                                 + str(z+delta))
            # print " I am in z ", z
            # print len(ar_z)
            # ater this step ar_y is a line
            for j, y in enumerate(grid_1d[0:-1]):
                ar_y = ar_z.selectAtoms("prop  y >= "
                                        + str(y) +
                                        "  and  prop y < "
                                        + str(y+delta))
                # print " I am in y ", y
                # print len(ar_y)
                # ater this step ar_x is a dot
                for k, x in enumerate(grid_1d[0:-1]):
                    ar_x = ar_y.selectAtoms("prop  x >= "
                                            + str(x)
                                            + "  and  prop x < "
                                            + str(x+delta))
                    # print " I am in x ", x
                    # print len(ar_x)
                    bonds = AnalyzeChain.get_bondlist_coords(ar_x)
                    cryst_all += get_cryst(bonds, get_eigvec(bonds),
                                           threshold=args.threshold)
        frame.append(ts.frame)
        cryst_all /= float(Nsub**3.0)

        g2.append(cryst_all)
        print "frame ", ts.frame, " cryst = ", cryst_all
    frame = np.array(frame)
    g2 = np.array(g2)
    # os.system("convert -delay ")

    save_plots.save_plot(frame, g2,
                         plotname='YC',
                         name=psffile,
                         logplot=args.logplot,
                         dumpskip=dumpskip,
                         timestep=timestep)
    return None