Ejemplo n.º 1
0
def analyze_dist_1D(list_x,nstep,outdir,dtc):
    """Take the average over the D estimates in each of these x-arrays"""
    # fit range = [0,nstep*dtc[
    assert len(list_x) > 0
    nfiles = len(list_x)
    t = np.arange(0,nstep*dtc,dtc)

    alldist2 = np.zeros((nstep,nfiles),float)
    allD = np.zeros((nfiles),float)

    print "="*5
    print "Results"
    print "making %i fits" %nfiles
    print "fit from %i steps, i.e. time %f ps, actually time %f ps" %(nstep,nstep*dtc,(nstep-1)*dtc)
    for i in range(nfiles):
        dist2 = calc_dist_1D(np.array(list_x[i]))
        # only fit the first nstep time steps (use all atoms)
        average = np.mean(dist2[:nstep,:],1)  # average over the atoms
        alldist2[:,i] = average

        p = np.polyfit(t,average,1)
        allD[i] = p[0]   # a_1 this is in angstrom**2/ps = 1e-20/1e-12 meter**2/second
                                # = 1e-8 meter**2/second = 1e-4 cm**2/s
        # if I want many figures:
        #fit_sqrt_vs_time(np.mean(dist_xy,1),dtc,outdir+"/fig_dist.xy.%i.png"%i,title=str(i))
        #fit_sqrt_vs_time(np.mean(dist_z,1), dtc,outdir+"/fig_dist.z.%i.png"%i,title=str(i))
        #fit_sqrt_vs_time(np.mean(dist_r,1), dtc,outdir+"/fig_dist.r.%i.png"%i,title=str(i))

    # extra figures
    m2 = np.mean(alldist2,axis=1)
    #s2 = np.std(alldist2,axis=1)
    fit_sqrt_vs_time(np.sqrt(m2),dtc,outdir+"/fig_dist.average.png",title="average of %i"%nfiles)

    print_output_D_ave_1D(allD)
Ejemplo n.º 2
0
def analyze_matrixdist(list_x,
                       list_y,
                       list_z,
                       dn1,
                       outdir,
                       dtc,
                       dn2=None,
                       ddn=1,
                       unitcell=None,
                       npt=False):
    "Take the average over the D estimates in each of these xyz trajectories" ""
    assert len(list_x) > 0
    assert len(list_x) == len(list_y)
    assert len(list_x) == len(list_z)
    nfiles = len(list_x)
    """Conditional Mean Square Distance
    dn1  --  start shift
    dn2  --  end shift
    ddn  --  range(dn1,dn2,ddn)

    Example
      dn1=3, dn2=7, ddn=2
      then dns=[3,5,7], nlags=3, ntime should be 8 or more
    """
    if dn2 is None:
        dn2 = dn1
    assert dn2 >= dn1
    assert ddn >= 1
    lt1 = dn1 * dtc
    lt2 = dn2 * dtc  # I will fit in region lagtime1 to lagtime2
    dns = np.arange(dn1, dn2 + 1, ddn)
    lagtimes = dns * dtc
    nlags = len(lagtimes)

    ntime = list_x[0].shape[0]
    natom = list_x[0].shape[1]
    if dns[-1] >= ntime:
        raise ValueError("asking for too many shifts, max dn > ntime: %i,%i" %
                         (dns[-1], ntime))

    #if nstep: lagtimes = np.arange(0,nstep*dtc,dtc)

    alldist2 = np.zeros((nlags, nfiles, 6), float)
    allD = np.zeros((nfiles, 6), float)

    print "=" * 5
    print "Results"
    print "making %i fits" % nfiles, "(number of trajectories)"
    print "fit from %i lagtimes, i.e. time %f ps to time %f ps, actually time %f ps" % (
        nlags, lagtimes[0], lagtimes[-1], (dn2 - dn1) * dtc)
    print "calculating..."
    for i in range(nfiles):
        print "file", i
        # matrix A contains 6 components of correlation matrix
        if unitcell is None:
            A, weight = calc_dist(list_x[i],
                                  list_y[i],
                                  list_z[i],
                                  shifts=dns,
                                  matrix=True)
        else:
            A, weight = calc_dist_folded(list_x[i],
                                         list_y[i],
                                         list_z[i],
                                         unitcell,
                                         shifts=dns,
                                         matrix=True,
                                         npt=npt)
        for k, dist2 in enumerate(A):
            average = np.mean(dist2, 1)  # average over the atoms
            alldist2[:, i, k] = average
            #print i,list_x[i],it,average[:10]

            p = np.polyfit(lagtimes, average, 1)
            allD[i, k] = p[
                0]  # a_1 this is in angstrom**2/ps = 1e-20/1e-12 meter**2/second
            # = 1e-8 meter**2/second = 1e-4 cm**2/s
        # if I want many figures:
        #fit_sqrt_vs_time(np.mean(dist_xy,1),dtc,outdir+"/fig_dist.xy.%i.png"%i,title=str(i))
        #fit_sqrt_vs_time(np.mean(dist_z,1), dtc,outdir+"/fig_dist.z.%i.png"%i,title=str(i))
        #fit_sqrt_vs_time(np.mean(dist_r,1), dtc,outdir+"/fig_dist.r.%i.png"%i,title=str(i))

    # extra figures
    means = np.mean(alldist2, axis=1)  # nlags x 6
    stds = np.std(alldist2, axis=1)  # nlags x 6
    mean_r = np.mean(alldist2[:, :, 0] + alldist2[:, :, 1] + alldist2[:, :, 2],
                     axis=1)
    std_r = np.std(alldist2[:, :, 0] + alldist2[:, :, 1] + alldist2[:, :, 2],
                   axis=1)

    verbose = False
    labs = ["xx", "yy", "zz", "xy", "xz", "yz"]
    for i in range(6):
        fit_sqrt_vs_time(means[:, i],
                         dtc * ddn,
                         outdir + "/fig_dist.%s.average.png" % (labs[i]),
                         title="average of %i" % nfiles,
                         t0=lagtimes[0],
                         std=stds[:, i],
                         verbose=verbose,
                         sqrt=False)
    fit_sqrt_vs_time(mean_r,
                     dtc * ddn,
                     outdir + "/fig_dist.r.average.png",
                     title="average of %i" % nfiles,
                     t0=lagtimes[0],
                     std=std_r,
                     verbose=verbose,
                     sqrt=False)
    # write files
    for i in range(6):
        store_msd(lagtimes,
                  means[:, i],
                  outdir + "/fig_dist.%s.average.txt" % (labs[i]),
                  error=stds[:, i])
    store_msd(lagtimes,
              mean_r,
              outdir + "/fig_dist.%s.average.txt" % ("r"),
              error=std_r)

    print_output_matrixD_ave(allD)
Ejemplo n.º 3
0
def analyze_dist(list_x,list_y,list_z,dn1,outdir,dtc,dn2=None,ddn=1,unitcell=None):
    "Take the average over the D estimates in each of these xyz trajectories"""
    assert len(list_x) > 0
    assert len(list_x) == len(list_y)
    assert len(list_x) == len(list_z)
    nfiles = len(list_x)
    """Conditional Mean Square Distance
    dn1  --  start shift
    dn2  --  end shift
    ddn  --  range(dn1,dn2,ddn)

    Example
      dn1=3, dn2=7, ddn=2
      then dns=[3,5,7], nlags=3, ntime should be 8 or more
    """
    if dn2 is None:
        dn2 = dn1
    assert dn2 >= dn1
    assert ddn >= 1
    lt1 = dn1*dtc
    lt2 = dn2*dtc  # I will fit in region lagtime1 to lagtime2
    dns = np.arange(dn1,dn2+1,ddn)
    lagtimes = dns*dtc
    nlags = len(lagtimes)

    ntime = list_x[0].shape[0]
    natom = list_x[0].shape[1]
    if dns[-1]>=ntime:
        raise ValueError("asking for too many shifts, max dn > ntime: %i,%i"%(dns[-1],ntime))

    #if nstep: lagtimes = np.arange(0,nstep*dtc,dtc)

    alldist2 = np.zeros((nlags,nfiles,3),float)
    allD = np.zeros((nfiles,3),float)

    print "="*5
    print "Results"
    print "making %i fits" %nfiles, "(number of trajectories)"
    print "fit from %i lagtimes, i.e. time %f ps to time %f ps, actually time %f ps" %(
             nlags,lagtimes[0],lagtimes[-1],(dn2-dn1)*dtc)
    print "calculating..."
    for i in range(nfiles):
        print "file",i
        if unitcell is None:
            dist2_xy,dist2_z,dist2_r,weight = calc_dist(list_x[i],list_y[i],list_z[i],shifts=dns)
        else:
            dist2_xy,dist2_z,dist2_r,weight = calc_dist_folded(list_x[i],list_y[i],list_z[i],unitcell,shifts=dns,)
        for k,dist2 in enumerate([dist2_xy,dist2_z,dist2_r]):
            average = np.mean(dist2,1)  # average over the atoms
            alldist2[:,i,k] = average
            #print i,list_x[i],it,average[:10]

            p = np.polyfit(lagtimes,average,1)
            allD[i,k] = p[0]   # a_1 this is in angstrom**2/ps = 1e-20/1e-12 meter**2/second
                                # = 1e-8 meter**2/second = 1e-4 cm**2/s
        # if I want many figures:
        #fit_sqrt_vs_time(np.mean(dist_xy,1),dtc,outdir+"/fig_dist.xy.%i.png"%i,title=str(i))
        #fit_sqrt_vs_time(np.mean(dist_z,1), dtc,outdir+"/fig_dist.z.%i.png"%i,title=str(i))
        #fit_sqrt_vs_time(np.mean(dist_r,1), dtc,outdir+"/fig_dist.r.%i.png"%i,title=str(i))

    # extra figures
    m2_xy = np.mean(alldist2[:,:,0],1)
    s_xy = np.std(alldist2[:,:,0],1)
    m2_z  = np.mean(alldist2[:,:,1],1)
    s_z  = np.std(alldist2[:,:,1],1)
    m2_r  = np.mean(alldist2[:,:,2],1)
    s_r  = np.std(alldist2[:,:,1],1)
    verbose=False
    fit_sqrt_vs_time(np.sqrt(m2_xy),dtc*ddn,
            outdir+"/fig_dist.xy.average.png",title="average of %i"%nfiles,
            t0=lagtimes[0],std=np.sqrt(s_xy),verbose=verbose)
    fit_sqrt_vs_time(np.sqrt(m2_z), dtc*ddn,
            outdir+"/fig_dist.z.average.png",title="average of %i"%nfiles,
            t0=lagtimes[0],std=np.sqrt(s_z))
    fit_sqrt_vs_time(np.sqrt(m2_r), dtc*ddn,
            outdir+"/fig_dist.r.average.png",title="average of %i"%nfiles,
            t0=lagtimes[0],std=np.sqrt(s_r))

    store_msd(lagtimes,m2_xy,outdir+"/fig_dist.xy.average.txt",error=s_xy)
    store_msd(lagtimes,m2_z ,outdir+"/fig_dist.z.average.txt", error=s_z)
    store_msd(lagtimes,m2_r ,outdir+"/fig_dist.r.average.txt", error=s_r)

    print_output_D_ave(allD)