Esempio n. 1
0
def main(argv):
    '''
    Thetrahedral Order Parameter calculation for a statefile produced with LAMMPS.
    The state file has to be consisting of water only. The program will search for 
    atoms of type = Type only, and calculate the orderparameter according to the four
    nearest atoms of type = Type.
    TetrahedralParameter is dependent on os,numpy and displacement (made by goran)
    '''
    
    filetoread, Type, showplot,saveplot, outputfilename, temperature = cmdinfo(argv)
    

    t, Natoms, system_size, matrix, readstructure, entries,types = readfile(filetoread)
    
    today = datetime.date.today() 
    writetofile = outputfilename + "_plotdate_" + str(today) + ".dat"
    
    ofile = open(writetofile,'w')
    fourNearest(ofile,Natoms,matrix,Type,outputfilename,temperature,showplot,saveplot)
Esempio n. 2
0
def storefileinfo(Time,Natoms,frontname,pathtodatabase):
    print "##############################################################"
    print "# Processing input files. Storing information in grand matrix"
    print "#\n"
    grandmatrix = []
    for time in Time:
        path = frontname + '.%r.txt' % (time)
        print "# Processing file: %s " % path
        filename = os.path.abspath(os.path.join(pathtodatabase,path))
        t, Natoms, system_size, matrix, readstructure, entries, types = readfile(filename) # this takes time processing !!
        info = []
        for i in range(Natoms):
            atom = [matrix['id'][i],matrix['type'][i], matrix['x'][i],matrix['y'][i],matrix['z'][i]]
            info.append(atom)
            
        grandmatrix.append(info)
    
    print "##############################################################"
    print "# Done processing..."
    return grandmatrix
Esempio n. 3
0
def simplecalc(frontname, database, initialmx, Natoms, Time, systemsize):

    Lx = systemsize[1] - systemsize[0]
    Ly = systemsize[3] - systemsize[2]
    Lz = systemsize[5] - systemsize[4]

    halfsystemsize = 0.5 * (Lx + Ly + Lz) / 3.0  # half of average system size

    rsquared = 0
    msd = []
    for t in Time:
        name = frontname + '.%r.txt' % t
        filename = os.path.abspath(os.path.join(database, name))
        time, Natoms, system_size, mx, readstructure, entries, types = readfile(
            filename)
        Noxygen = 0
        for i in range(Natoms):
            if (mx['type'][i] == 1):
                for j in range(Natoms):
                    if (initialmx['id'][j] == mx['id'][i]):
                        dx = mx['x'][i] - initialmx['x'][j]
                        dy = mx['y'][i] - initialmx['y'][j]
                        dz = mx['z'][i] - initialmx['z'][j]
                        ########################################
                        #        MINIMUM IMAGE CONVENTION      #
                        if (dx < -halfsystemsize): dx = dx + Lx
                        if (dx > halfsystemsize): dx = dx - Lx
                        if (dy < -halfsystemsize): dy = dy + Ly
                        if (dy > halfsystemsize): dy = dy - Ly
                        if (dz < -halfsystemsize): dz = dz + Lz
                        if (dz > halfsystemsize): dz = dz - Lz
                        ########################################
                        dr2 = dx * dx + dy * dy + dz * dz
                        Noxygen += 1
                        rsquared += dr2

        msd.append(rsquared / Noxygen)

    plt.figure()
    plt.plot(Time, msd)
    plt.show()
Esempio n. 4
0
def main(argv):
    '''
    Thetrahedral Order Parameter calculation for a statefile produced with LAMMPS.
    The state file has to be consisting of water only. The program will search for 
    atoms of type = Type only, and calculate the orderparameter according to the four
    nearest atoms of type = Type.
    TetrahedralParameter is dependent on os,numpy and displacement (made by goran)
    '''

    filetoread, Type, showplot, saveplot, outputfilename, temperature = cmdinfo(
        argv)

    t, Natoms, system_size, matrix, readstructure, entries, types = readfile(
        filetoread)

    today = datetime.date.today()
    writetofile = outputfilename + "_plotdate_" + str(today) + ".dat"

    ofile = open(writetofile, 'w')
    fourNearest(ofile, Natoms, matrix, Type, outputfilename, temperature,
                showplot, saveplot)
Esempio n. 5
0
def simplecalc(frontname,database,initialmx,Natoms,Time,systemsize):

    Lx = systemsize[1] -systemsize[0]    
    Ly = systemsize[3] -systemsize[2]
    Lz = systemsize[5] -systemsize[4]
    
    halfsystemsize = 0.5*(Lx+Ly+Lz)/3.0   # half of average system size
    
    rsquared = 0
    msd = []
    for t in Time:
        name = frontname + '.%r.txt' % t
        filename = os.path.abspath(os.path.join(database,name))
        time,Natoms,system_size,mx,readstructure,entries,types = readfile(filename)
        Noxygen = 0
        for i in range(Natoms):
            if (mx['type'][i] == 1):
                for j in range(Natoms):
                    if (initialmx['id'][j] == mx['id'][i]):
                        dx = mx['x'][i] - initialmx['x'][j]
                        dy = mx['y'][i] - initialmx['y'][j]
                        dz = mx['z'][i] - initialmx['z'][j]
                        ########################################
                        #        MINIMUM IMAGE CONVENTION      #
                        if (dx < -halfsystemsize): dx = dx + Lx
                        if (dx > halfsystemsize): dx = dx - Lx
                        if (dy < -halfsystemsize): dy = dy + Ly
                        if (dy > halfsystemsize): dy = dy - Ly
                        if (dz < -halfsystemsize): dz = dz + Lz
                        if (dz > halfsystemsize): dz = dz - Lz
                        ########################################
                        dr2 = dx*dx + dy*dy + dz*dz
                        Noxygen += 1
                        rsquared += dr2
    
        msd.append(rsquared/Noxygen)
        
    plt.figure()
    plt.plot(Time,msd)
    plt.show()
Esempio n. 6
0
def storefileinfo(Time, Natoms, frontname, pathtodatabase):
    print "##############################################################"
    print "# Processing input files. Storing information in grand matrix"
    print "#\n"
    grandmatrix = []
    for time in Time:
        path = frontname + '.%r.txt' % (time)
        print "# Processing file: %s " % path
        filename = os.path.abspath(os.path.join(pathtodatabase, path))
        t, Natoms, system_size, matrix, readstructure, entries, types = readfile(
            filename)  # this takes time processing !!
        info = []
        for i in range(Natoms):
            atom = [
                matrix['id'][i], matrix['type'][i], matrix['x'][i],
                matrix['y'][i], matrix['z'][i]
            ]
            info.append(atom)

        grandmatrix.append(info)

    print "##############################################################"
    print "# Done processing..."
    return grandmatrix
Esempio n. 7
0
def displacement(ofile,timestep,Natoms,matrix0,Type,Time,frontname,pathtodatabase,systemsize):
    '''
    timestep,system_size,matrix0 contain the initial information about the system.
    we have to go through sortedfiles to find information about the particles at
    later timesteps.
    '''
    factor = 10**(-8)                                               # conversionfactor from [A^2/ps] -> [m^2/s]

    Lx = systemsize[1] -systemsize[0]    
    Ly = systemsize[3] -systemsize[2]
    Lz = systemsize[5] -systemsize[4]
    halfsystemsize = 0.5*(Lx+Ly+Lz)/3.0   # half of average system size
    
    time = []
    for t in Time:
        time.append(timestep*t/1000.0)   # to picoseconds
        #time.append(t)
        
    MSDX = [];MSDY = [];MSDZ = [];MSD = [];D_local = []
    dt = (time[1]-time[0])
    for T in Time:
        path = frontname + '.%r.txt' % (T)
        print path
        msdx = 0; msdy = 0; msdz = 0; msd = 0
        filename = os.path.abspath(os.path.join(pathtodatabase,path))
        t, Natoms, system_size, matrix, readstructure, entries, types = readfile(filename)
        counter = 0
        for i in range(Natoms):
            if (matrix['type'][i] == Type):
                ID = matrix['id'][i]
                initial_index = None
                for j in range(Natoms):
                    k = matrix0['id'][j]
                    if (k == ID):
                        initial_index = j
                        break
                
                dx = matrix['x'][i] - matrix0['x'][initial_index]
                dy = matrix['y'][i] - matrix0['y'][initial_index]
                dz = matrix['z'][i] - matrix0['z'][initial_index]
                msdx += (dx)**2
                msdy += (dy)**2
                msdz += (dz)**2
                ########################################
                #        MINIMUM IMAGE CONVENTION      #
                if (dx < -halfsystemsize): dx = dx + Lx
                if (dx > halfsystemsize): dx = dx - Lx
                if (dy < -halfsystemsize): dy = dy + Ly
                if (dy > halfsystemsize): dy = dy - Ly
                if (dz < -halfsystemsize): dz = dz + Lz
                if (dz > halfsystemsize): dz = dz - Lz
                ########################################
                msd += dx**2 + dy**2 + dz**2
                counter += 1
    
        D_local.append((msd/(counter*6*T)))
        MSDX.append(msdx/(6*counter));MSDY.append(msdy/(6*counter));MSDZ.append(msdz/(6*counter));MSD.append(msd/(6*counter))
        

    # ballistic_end = 100ps
    degree = 1
    start = int(round(len(MSD)/5.0))
    p = np.polyfit(time[start:],MSD[start:],degree)   # last 4/5 of the dataset
    f = np.polyval(p,time)    
    d_mean_lastpart = p[0]#*10**(-8)        # to get [m^2/s]. [A^2/ps] = 10**(-8)[m^2/s]

    p1 = np.polyfit(time[0:start],MSD[0:start],degree)
    f1 = np.polyval(p1,time)    
    d_mean_firstpart = p1[0]#*10**(8)       # to get [m^2/s]. [A^2/ps] = 10**(-8)[m^2/s]

    p2 = np.polyfit(time[0:int(round(start/2.0))],MSD[0:int(round(start/2.0))],degree)
    f2 = np.polyval(p2,time)    
    d_mean_initpart = p2[0]#*10**(8)        # to get [m^2/s]. [A^2/ps] = 10**(-8)[m^2/s]
    
    p3 = np.polyfit(time[0:100],MSD[0:100],degree)
    f3 = np.polyval(p3,time)
    d_mean_actual = p3[0]#*10**(8)          # to get [m^2/s]. [A^2/ps] = 10**(-8)[m^2/s]

    print "#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#"
    print " Nvalues in estimate 1 = 100"
    print " Nvalues in estimate 2 = %g" % (int(round(start/2.0)))
    print " Nvalues in estimate 3 = %g" % (int(round(start)))
    print " Nvalues in estimate 4 = %g" % (len(time[start:]))
    
    ###############################################################################
    #                             plotting
    #plt.close('all')
    plt.figure()                                                                # Figure 1
    Title = 'Mean square displacement'
    legends = ['$msd_{x}$','$msd_{y}$','$msd_{z}$','$msd$']#['$msd$']#
    Ylabel = 'mean square displacement $ [A^2] $'
    Xlabel = 'time $ [ps] $'
    pltname = 'MSD_bulkwater'
    linestyles = ['--r','--y','--k','o-b']#['--r'] #
    plt.hold(True)
    plt.plot(time,MSDX,linestyles[0])
    plt.plot(time,MSDY,linestyles[1])
    plt.plot(time,MSDZ,linestyles[2])
    plt.plot(time,MSD,linestyles[3],markevery=10)
    plt.title(Title)
    plt.xlabel(Xlabel)
    plt.ylabel(Ylabel)
    plt.legend(legends,loc='lower right')
    plt.hold(False)
    write_to_file(ofile,Title,Xlabel,Ylabel,pltname,legends,linestyles,[time],[MSDX,MSDY,MSDZ,MSD])
    
    
    from mpl_toolkits.axes_grid.inset_locator import zoomed_inset_axes, inset_axes, mark_inset

    plt.figure()
    ax = plt.axes()                                                             # Figure 2
    Title = 'Mean square displacement'
    legends = ['MSD','$f_1 %.3f $' % (d_mean_actual),'$f_2 %.3f $' % (d_mean_initpart),'$f_3 %.3f $' % (d_mean_firstpart),'$f_4 %.3f $' % (d_mean_lastpart)]
    pltname = 'MSD_bulkwater_mean'
    Xlabel = 'time $ [ps] $'
    Ylabel = 'mean square displacement $ [A^2] $'
    linestyles = ['b-','--y','--r','--m','--y']
    
    plt.hold(True)
    plt.plot(time,MSD,linestyles[0])
    plt.plot(time[0:int(round(len(f)/8.0))],f3[0:int(round(len(f)/8.0))],linestyles[1])  # very first part
    plt.plot(time[0:int(round(len(f)/6.0))],f2[0:int(round(len(f)/6.0))],linestyles[2])  # initpart
    plt.plot(time[0:int(round(len(f)/5.0))],f1[0:int(round(len(f)/5.0))],linestyles[3])  # firstpart
    plt.plot(time,f,linestyles[4])                                                       # lastpart

    plt.hold(False)
    plt.xlabel(Xlabel)
    plt.ylabel(Ylabel)
    plt.legend(legends,loc='lower right')
    plt.title(Title)
    
    ax.spines['top'].set_visible(False)
    ax.spines['right'].set_visible(False)
    ax.get_xaxis().tick_bottom()
    ax.get_yaxis().tick_left()
    
    axin = inset_axes(ax, width="30%", height="35%", loc=8)
    plt.hold(True)
    axin.plot(time,MSD,linestyles[0])
    axin.plot(time,f3,linestyles[1],linewidth=3.0)
    axin.plot(time,f2,linestyles[2])
    #axin.plot(time,f1,linestyles[3])
    plt.hold(False)
    axin.set_xlim(500, 520)
    ya = 0.0
    yb = 4.0
    Npoints = 4
    points = np.linspace(ya,yb,Npoints)
    axin.set_ylim(ya, yb)
    axin.set_xticks([])
    axin.set_yticks(points)
    mark_inset(ax, axin, loc1=3, loc2=4, fc="none", ec="0.5")    
    
    write_to_file(ofile,Title,Xlabel,Ylabel,pltname,legends,linestyles,[time],[MSD,f])
    
    print "#################################################################"
    print "# Diffusion estimate f1   : D = %.10f " % (d_mean_actual)    
    print "# Diffusion estimate f2   : D = %.10f " % (d_mean_initpart)
    print "# Diffusion estimate f3   : D = %.10f " % (d_mean_firstpart) 
    print "# Diffusion estimate f4   : D = %.10f " % (d_mean_lastpart)

    plt.figure()                                                                # Figure 3
    Title = 'Time evolution of the local diffusion constant. $ D=(msd/6dt) $'
    legends = ['$D(t)$']; linestyles = ['-y']
    pltname = 'Diffusion_bulkwater'
    Ylabel = 'displacement $ [ %g m^2/s]$' % factor
    plt.hold(True)
    plt.plot(time,D_local,linestyles[0])    
    plt.hold(False)
    plt.legend(legends,loc='upper right')
    plt.title(Title)
    plt.xlabel(Xlabel)
    plt.ylabel(Ylabel)
    write_to_file(ofile,Title,Xlabel,Ylabel,pltname,legends,linestyles,[time],[D_local])

    plt.show()
Esempio n. 8
0
def main():
    
    #calculation = "TraPPE"       # diffusion calc for the TraPPE co2 system
    #calculation = "EMP2"         # diffusion calc for the EMP2 co2 system
    #calculation = "FPF"          # diffusion calc for the FPF co2 system
    calculation = "Bulk water"   # diffusion for bulk water
    #calculation = "Portlandite"  # diffusion for Portlandite cube
    
    Nstatefiles = 100           # Number of statefiles to use in every estimate
    timestep = 2.0              # timestep used in MD simulation. [fsec]
    
    if (calculation == "Bulk water"):
        print " Running for bulk water!!!"
        '''
        startingtime = 200000
        pathtodatabase = '/home/goran/lammps-28Jun14/examples/Abel_runs/water/pure_H2O/Small_bulk_system' # bulk water
        initialfile = 'dump.water_nvt_fromRestart.250000.txt'
        frontname = "dump.water_nvt_fromRestart"
        arg = "water_nvt_fromRestart"
        outputfilename = 'diffusion_bulkwater_plotshit.dat'
        Type = 1                    # What atom type to follow
        '''
        startingtime = 250100
        pathtodatabase = "/home/goran/lammps-28Jun14/theproject/water/run3_300K_100ps_nvt" # Bulk water
        initialfile = "dump.water_nvt.250100.txt" # Filename of initial state
        frontname = "dump.water_nvt"
        arg = None
        outputfilename = "diffusion_bulkwater_plotshit.data"
        Type = 1

    if (calculation == "TraPPE"):
        last_timestep = 250000
        startingtime = 200000
        Nsteps = last_timestep - startingtime
        pathtodatabase = '/home/goran/lammps-28Jun14/theproject/carbondioxide/TraPPE/run_2015_02_27'         # bulk carbon dioxide, TraPPE model
        initialfile = 'dump.bulk_carbondioxide_TraPPE.0.txt'
        frontname = "dump.bulk_carbondioxide_TraPPE"
        arg = "bulk_carbondioxide_TraPPE"
        outputfilename = "diffusion_TraPPE_co2_plotshit.dat"
        Type = 1                    # What atom type to follow

    if (calculation == "EMP2"):
        last_timestep = 250000
        startingtime = 200000
        Nsteps = last_timestep - startingtime
        pathtodatabase = '/home/goran/lammps-28Jun14/theproject/carbondioxide/emp2/run_2015_02_27'         # bulk carbon dioxide, EMP2 model
        initialfile = "dump.bulk_carbondioxide_EMPtwo.0.txt"
        frontname = "dump.bulk_carbondioxide_EMPtwo"
        arg = "bulk_carbondioxide_EMPtwo"
        outputfilename = "diffusion_EMP2_co2_plotshit.dat"
        Type = 1                    # What atom type to follow
    
    if (calculation == "FPF"):
        last_timestep = 250000
        startingtime = 200000
        Nsteps = last_timestep - startingtime
        pathtodatabase = '/home/goran/lammps-28Jun14/theproject/carbondioxide/FPF/run_2015_02_26'         # bulk carbon dioxide, FPF model
        initialfile = 'dump.bulk_carbondioxide_FPF.0.txt'
        frontname = "dump.bulk_carbondioxide_FPF"
        arg = "bulk_carbondioxide_FPF"
        outputfilename = 'FPF_co2_diffusion_plotshit.dat'
        outputfilename = "diffusion_FPF_co2_plotshit.dat"
        Type = 1                    # What atom type to follow
        
    if (calculation == "Portlandite"):
        pathtodatabase = '/home/goran/lammps-28Jun14/examples/Abel_runs/portlandite/oldrun'
        initialfile = "dump.portlandite.250000.txt"
        frontname = "dump.portlandite"
        arg = "portlandite"
        outputfilename = "diffusion_Portlandite_co2_plotshit.dat"
        Type = 1                    # What atom type to follow
        
    initialfile = os.path.join(pathtodatabase,initialfile)
    
    
    notsortedfiles, Time = gothroughfiles(pathtodatabase,arg)  # the files are not well enough sorted!
    t0, Natoms, system_size, matrix0, readstructure, entries, types = readfile(initialfile)

    ofile = open(outputfilename,'w')

    #print len(Time), Time[-1]
    #print Time
    #Time = Time[0:1000]
    #print "system size:\n", system_size
    time = []
    start = 0; k = 0;
    for t in Time:
        if t == startingtime:
            start = k
        time.append(t*timestep/1000.0) # convert to pico-seconds
        k += 1
    #######################################################
    #               DENSITY
    
    oxygen = 15.9994                         # g/mol
    hydrogen = 1.00794                       # g/mol
    carbon = 12.0107                         # g/mol
    calcium = 40.078                         # g/mol
    silicon = 28.0855                        # g/mol
    
    if ('water' in initialfile):
        mass = (oxygen + 2*hydrogen)*Natoms/3.0   # g/mol (system)
        Type = 1 # follow oxygen
        system = 'water'
    elif ('carbondioxide' in initialfile):
        mass = (carbon + 2*oxygen)*Natoms/3.0     # g/mol (system)
        Type = 1 # follow carbon
        system = 'water'
    elif ('portlandite' in initialfile):
        mass = (calcium + (oxygen + hydrogen)*2)*Natoms/5.0  # g/mol (system)
        system = 'portlandite'
    elif ('quartz' in initialfile):
        mass = (silicon + 2*oxygen)*Natoms/3.0   # g/mol (system)
        system = 'alpha-quartz'
    else:
        print "failed to characterize system"
    
    #==========================================================================
    #=============== MSD for system, one estimate
    #displacement(ofile,timestep,Natoms,matrix0,Type,Time[start:],frontname,pathtodatabase,system_size)
    
    #==========================================================================
    #=============== MSD for system, len(time)/Nstatefiles estimates
    lTime = len(Time)
    stop = lTime - 1
    stop = start + 500
    print "len(Time) = %g " % (len(Time))
    if (stop > lTime):
        print "Error! stop > len(Time)\n setting stop=len(Time)"
        stop = lTime-1    
    print "start time index = %g" % start
    print "stop time index  = %g" % stop
    GM = storefileinfo(Time,Natoms,frontname,pathtodatabase)                # store fileinfo to a grand matrix
    diffusion(ofile,timestep,Natoms,Nstatefiles,GM,Type,time,system_size)
    
    #==========================================================================
    #====================== Radial Distribution ===============================
    #Carbon Dioxide:
    #Type1 = [1,'C',216] # molID,type,Nmolec
    #Type2 = [2,'O',432] # molID,type,Nmolec

    # Water:
    #Type1 = [1,'O',216] # molID,type,Nmolec
    #Type2 = [2,'H',432] # molID,type,Nmolec

    # Portlandite:
    #Type1 = [1,'Ca',1344]
    #Type2 = [2,'O',2688]

    # Alpha-quartz:
    #Type1 = [1,'O',72] # molID,type,Natoms
    #Type2 = [2,'Si',36] # molID,type,Natoms
    #RDF(ofile,Time[start:],Natoms,system_size,GM,Type1,Type1,pathtodatabase)    # RDF type1 - type1
    #RDF(ofile,Time[start:],Natoms,system_size,GM,Type2,Type2,pathtodatabase)    # RDF type2 - type2
    #RDF(ofile,Time[start:],Natoms,system_size,GM,Type1,Type2,pathtodatabase)    # RDF type1 - type2

    #==========================================================================  
    #======================= Bulk Density =====================================
    #notsort, Time = gothroughfiles(pathtodatabase,arg)
    #bulkdensity(ofile,timestep,mass,Time[start:],frontname,pathtodatabase)
    print "##############################################################"
    print "# Starting timestep:             %g" % Time[start]
    print "# Last timestep:                 %g" % Time[stop]
    print "# Number of files:               %g" % len(time)
    print "# Number of files in estimates:  %g" % Nstatefiles
    print "# Number of estimates:           %g" % (int(np.floor(len(time)/float(Nstatefiles))))
    print "##############################################################"

    ofile.close()
Esempio n. 9
0
def bulkdensity(ofile,timestep,mass_of_system,Time,frontname,pathtodatabase):
    '''
    masses[i] contains the mass of atom in types[i].
    systemSize = [xlo xhi ylo yhi zlo zhi]
    GM is a grand matrix containing all atom IDs, types and positions.
    The bulkdensity function calculates the density of a bulk system
    at every timestep, and plots the density as a function of time
    mass_of_system
    '''
    avogadro_aangstrom_relation = 10.0/6.022
    density = []; volume = []
    i = 0
    for time in Time:
        path = frontname + '.%r.txt' % (time)
        print "# Processing file: %s " % path
        filename = os.path.abspath(os.path.join(pathtodatabase,path))
        t, Natoms, system_size, matrix, readstructure, entries, types = readfile(filename) # this takes time processing !!
        dx = system_size[1] - system_size[0]  # Aangstrom
        dy = system_size[3] - system_size[2]  # Aangstrom
        dz = system_size[5] - system_size[4]  # Aangstrom
        vol = dx*dy*dz                        # volume of system [Aangstrom^3]
        volume.append(vol)
        density.append((mass_of_system/vol)*avogadro_aangstrom_relation)
        i += 1
    
    t = []
    for time in Time:
        t.append(time*timestep/1000.0) # converts to pico-seconds
    
    if "carb" in frontname:
        dens = 1.7966*10**(-3)                                    # g/cm^3
        benchmarkline = np.linspace(dens,dens,5)        # carbon dioxide benchmarkline for density
        pltname = "Density_cardondioxide"
    elif "water" in frontname:
        dens = 0.998                                              # g/cm^3
        benchmarkline = np.linspace(dens,dens,5)          # water benchmarkline for density
        pltname = "Density_water"
    elif "quartz" in frontname:
        dens = 2.648                                              # g/cm^3
        benchmarkline = np.linspace(dens,dens,5)
        pltname = "Density_quartz"
    elif "portlandite" in frontname:
        dens = 2.24      # g/cm^3
        benchmarkline = np.linspace(dens,dens,5)
        pltname = "Density_portlandite" 
    else:
        print "ERRORERRORERRORERRORERRORERRORERRORERRORERRORERRORERRORERRORERROR"
        print "Error!\n Could not recognize either 'carb', 'water', 'quartz or 'portlandite' in frontname"

    
    start = int(round(0.1*len(density)))    
    meanDens = np.mean(density[start:]); stdDens = np.std(density[start:])
    line = np.linspace(meanDens,meanDens,6)
    Title = 'Density profile\\newline$\\rho = %.4g \\pm %.5g [g/cm^3]$' % (meanDens,stdDens)
    Xlabel = 'time $ [ps] $'; Ylabel = 'density $ [g/cm^3] $'
    legends = ['$\\rho$','$\\rho_{avg}$','$\\rho_{exp}$']; linestyles = ['g--','b-d','r-o']
    tstop = t[-1]
    tstart = t[0]
    dt = tstop - tstart
    line_points = [tstart,(tstart + dt/5), (tstart + 2*dt/5), (tstart + 3*dt/5), (tstart + 4*dt/5), tstop]
    benchmarkline_points = [tstart,(tstart + dt/4), (tstart + dt/2), (tstart + 3*dt/4), tstop]
    plt.figure()
    plt.hold(True)
    plt.plot(t,density,'g--')
    plt.plot(line_points,line,'b-d', linewidth=3.0)
    plt.plot(benchmarkline_points,benchmarkline,'r-o',linewidth=2.0)
    plt.hold(False)
    plt.title(Title)
    plt.legend(legends)
    plt.xlabel(Xlabel); plt.ylabel(Ylabel)

    meanVol = np.mean(volume); stdVol = np.std(volume)
    Title = '$V_{system} = %g \\pm %g A^3$' % (meanVol,stdVol)
    Xlabel = 'time [ps]'; Ylabel = 'volume'
    plt.figure()
    plt.plot(t,volume,'-b')
    plt.title(Title); plt.xlabel(Xlabel);plt.ylabel(Ylabel)
    plt.legend(['volume'],loc='upper left')
        
    plt.show()
    write_to_file(ofile,Title,Xlabel,Ylabel,pltname,legends,linestyles,[t,line_points,benchmarkline_points],[density,line,benchmarkline])
Esempio n. 10
0
def main():

    #calculation = "TraPPE"       # diffusion calc for the TraPPE co2 system
    #calculation = "EMP2"         # diffusion calc for the EMP2 co2 system
    #calculation = "FPF"          # diffusion calc for the FPF co2 system
    calculation = "Bulk water"  # diffusion for bulk water
    #calculation = "Portlandite"  # diffusion for Portlandite cube

    Nstatefiles = 100  # Number of statefiles to use in every estimate
    timestep = 2.0  # timestep used in MD simulation. [fsec]

    if (calculation == "Bulk water"):
        print " Running for bulk water!!!"
        '''
        startingtime = 200000
        pathtodatabase = '/home/goran/lammps-28Jun14/examples/Abel_runs/water/pure_H2O/Small_bulk_system' # bulk water
        initialfile = 'dump.water_nvt_fromRestart.250000.txt'
        frontname = "dump.water_nvt_fromRestart"
        arg = "water_nvt_fromRestart"
        outputfilename = 'diffusion_bulkwater_plotshit.dat'
        Type = 1                    # What atom type to follow
        '''
        startingtime = 250100
        pathtodatabase = "/home/goran/lammps-28Jun14/theproject/water/run3_300K_100ps_nvt"  # Bulk water
        initialfile = "dump.water_nvt.250100.txt"  # Filename of initial state
        frontname = "dump.water_nvt"
        arg = None
        outputfilename = "diffusion_bulkwater_plotshit.data"
        Type = 1

    if (calculation == "TraPPE"):
        last_timestep = 250000
        startingtime = 200000
        Nsteps = last_timestep - startingtime
        pathtodatabase = '/home/goran/lammps-28Jun14/theproject/carbondioxide/TraPPE/run_2015_02_27'  # bulk carbon dioxide, TraPPE model
        initialfile = 'dump.bulk_carbondioxide_TraPPE.0.txt'
        frontname = "dump.bulk_carbondioxide_TraPPE"
        arg = "bulk_carbondioxide_TraPPE"
        outputfilename = "diffusion_TraPPE_co2_plotshit.dat"
        Type = 1  # What atom type to follow

    if (calculation == "EMP2"):
        last_timestep = 250000
        startingtime = 200000
        Nsteps = last_timestep - startingtime
        pathtodatabase = '/home/goran/lammps-28Jun14/theproject/carbondioxide/emp2/run_2015_02_27'  # bulk carbon dioxide, EMP2 model
        initialfile = "dump.bulk_carbondioxide_EMPtwo.0.txt"
        frontname = "dump.bulk_carbondioxide_EMPtwo"
        arg = "bulk_carbondioxide_EMPtwo"
        outputfilename = "diffusion_EMP2_co2_plotshit.dat"
        Type = 1  # What atom type to follow

    if (calculation == "FPF"):
        last_timestep = 250000
        startingtime = 200000
        Nsteps = last_timestep - startingtime
        pathtodatabase = '/home/goran/lammps-28Jun14/theproject/carbondioxide/FPF/run_2015_02_26'  # bulk carbon dioxide, FPF model
        initialfile = 'dump.bulk_carbondioxide_FPF.0.txt'
        frontname = "dump.bulk_carbondioxide_FPF"
        arg = "bulk_carbondioxide_FPF"
        outputfilename = 'FPF_co2_diffusion_plotshit.dat'
        outputfilename = "diffusion_FPF_co2_plotshit.dat"
        Type = 1  # What atom type to follow

    if (calculation == "Portlandite"):
        pathtodatabase = '/home/goran/lammps-28Jun14/examples/Abel_runs/portlandite/oldrun'
        initialfile = "dump.portlandite.250000.txt"
        frontname = "dump.portlandite"
        arg = "portlandite"
        outputfilename = "diffusion_Portlandite_co2_plotshit.dat"
        Type = 1  # What atom type to follow

    initialfile = os.path.join(pathtodatabase, initialfile)

    notsortedfiles, Time = gothroughfiles(
        pathtodatabase, arg)  # the files are not well enough sorted!
    t0, Natoms, system_size, matrix0, readstructure, entries, types = readfile(
        initialfile)

    ofile = open(outputfilename, 'w')

    #print len(Time), Time[-1]
    #print Time
    #Time = Time[0:1000]
    #print "system size:\n", system_size
    time = []
    start = 0
    k = 0
    for t in Time:
        if t == startingtime:
            start = k
        time.append(t * timestep / 1000.0)  # convert to pico-seconds
        k += 1
    #######################################################
    #               DENSITY

    oxygen = 15.9994  # g/mol
    hydrogen = 1.00794  # g/mol
    carbon = 12.0107  # g/mol
    calcium = 40.078  # g/mol
    silicon = 28.0855  # g/mol

    if ('water' in initialfile):
        mass = (oxygen + 2 * hydrogen) * Natoms / 3.0  # g/mol (system)
        Type = 1  # follow oxygen
        system = 'water'
    elif ('carbondioxide' in initialfile):
        mass = (carbon + 2 * oxygen) * Natoms / 3.0  # g/mol (system)
        Type = 1  # follow carbon
        system = 'water'
    elif ('portlandite' in initialfile):
        mass = (calcium +
                (oxygen + hydrogen) * 2) * Natoms / 5.0  # g/mol (system)
        system = 'portlandite'
    elif ('quartz' in initialfile):
        mass = (silicon + 2 * oxygen) * Natoms / 3.0  # g/mol (system)
        system = 'alpha-quartz'
    else:
        print "failed to characterize system"

    #==========================================================================
    #=============== MSD for system, one estimate
    #displacement(ofile,timestep,Natoms,matrix0,Type,Time[start:],frontname,pathtodatabase,system_size)

    #==========================================================================
    #=============== MSD for system, len(time)/Nstatefiles estimates
    lTime = len(Time)
    stop = lTime - 1
    stop = start + 500
    print "len(Time) = %g " % (len(Time))
    if (stop > lTime):
        print "Error! stop > len(Time)\n setting stop=len(Time)"
        stop = lTime - 1
    print "start time index = %g" % start
    print "stop time index  = %g" % stop
    GM = storefileinfo(Time, Natoms, frontname,
                       pathtodatabase)  # store fileinfo to a grand matrix
    diffusion(ofile, timestep, Natoms, Nstatefiles, GM, Type, time,
              system_size)

    #==========================================================================
    #====================== Radial Distribution ===============================
    #Carbon Dioxide:
    #Type1 = [1,'C',216] # molID,type,Nmolec
    #Type2 = [2,'O',432] # molID,type,Nmolec

    # Water:
    #Type1 = [1,'O',216] # molID,type,Nmolec
    #Type2 = [2,'H',432] # molID,type,Nmolec

    # Portlandite:
    #Type1 = [1,'Ca',1344]
    #Type2 = [2,'O',2688]

    # Alpha-quartz:
    #Type1 = [1,'O',72] # molID,type,Natoms
    #Type2 = [2,'Si',36] # molID,type,Natoms
    #RDF(ofile,Time[start:],Natoms,system_size,GM,Type1,Type1,pathtodatabase)    # RDF type1 - type1
    #RDF(ofile,Time[start:],Natoms,system_size,GM,Type2,Type2,pathtodatabase)    # RDF type2 - type2
    #RDF(ofile,Time[start:],Natoms,system_size,GM,Type1,Type2,pathtodatabase)    # RDF type1 - type2

    #==========================================================================
    #======================= Bulk Density =====================================
    #notsort, Time = gothroughfiles(pathtodatabase,arg)
    #bulkdensity(ofile,timestep,mass,Time[start:],frontname,pathtodatabase)
    print "##############################################################"
    print "# Starting timestep:             %g" % Time[start]
    print "# Last timestep:                 %g" % Time[stop]
    print "# Number of files:               %g" % len(time)
    print "# Number of files in estimates:  %g" % Nstatefiles
    print "# Number of estimates:           %g" % (int(
        np.floor(len(time) / float(Nstatefiles))))
    print "##############################################################"

    ofile.close()
Esempio n. 11
0
def displacement(ofile, timestep, Natoms, matrix0, Type, Time, frontname,
                 pathtodatabase, systemsize):
    '''
    timestep,system_size,matrix0 contain the initial information about the system.
    we have to go through sortedfiles to find information about the particles at
    later timesteps.
    '''
    factor = 10**(-8)  # conversionfactor from [A^2/ps] -> [m^2/s]

    Lx = systemsize[1] - systemsize[0]
    Ly = systemsize[3] - systemsize[2]
    Lz = systemsize[5] - systemsize[4]
    halfsystemsize = 0.5 * (Lx + Ly + Lz) / 3.0  # half of average system size

    time = []
    for t in Time:
        time.append(timestep * t / 1000.0)  # to picoseconds
        #time.append(t)

    MSDX = []
    MSDY = []
    MSDZ = []
    MSD = []
    D_local = []
    dt = (time[1] - time[0])
    for T in Time:
        path = frontname + '.%r.txt' % (T)
        print path
        msdx = 0
        msdy = 0
        msdz = 0
        msd = 0
        filename = os.path.abspath(os.path.join(pathtodatabase, path))
        t, Natoms, system_size, matrix, readstructure, entries, types = readfile(
            filename)
        counter = 0
        for i in range(Natoms):
            if (matrix['type'][i] == Type):
                ID = matrix['id'][i]
                initial_index = None
                for j in range(Natoms):
                    k = matrix0['id'][j]
                    if (k == ID):
                        initial_index = j
                        break

                dx = matrix['x'][i] - matrix0['x'][initial_index]
                dy = matrix['y'][i] - matrix0['y'][initial_index]
                dz = matrix['z'][i] - matrix0['z'][initial_index]
                msdx += (dx)**2
                msdy += (dy)**2
                msdz += (dz)**2
                ########################################
                #        MINIMUM IMAGE CONVENTION      #
                if (dx < -halfsystemsize): dx = dx + Lx
                if (dx > halfsystemsize): dx = dx - Lx
                if (dy < -halfsystemsize): dy = dy + Ly
                if (dy > halfsystemsize): dy = dy - Ly
                if (dz < -halfsystemsize): dz = dz + Lz
                if (dz > halfsystemsize): dz = dz - Lz
                ########################################
                msd += dx**2 + dy**2 + dz**2
                counter += 1

        D_local.append((msd / (counter * 6 * T)))
        MSDX.append(msdx / (6 * counter))
        MSDY.append(msdy / (6 * counter))
        MSDZ.append(msdz / (6 * counter))
        MSD.append(msd / (6 * counter))

    # ballistic_end = 100ps
    degree = 1
    start = int(round(len(MSD) / 5.0))
    p = np.polyfit(time[start:], MSD[start:],
                   degree)  # last 4/5 of the dataset
    f = np.polyval(p, time)
    d_mean_lastpart = p[
        0]  #*10**(-8)        # to get [m^2/s]. [A^2/ps] = 10**(-8)[m^2/s]

    p1 = np.polyfit(time[0:start], MSD[0:start], degree)
    f1 = np.polyval(p1, time)
    d_mean_firstpart = p1[
        0]  #*10**(8)       # to get [m^2/s]. [A^2/ps] = 10**(-8)[m^2/s]

    p2 = np.polyfit(time[0:int(round(start / 2.0))],
                    MSD[0:int(round(start / 2.0))], degree)
    f2 = np.polyval(p2, time)
    d_mean_initpart = p2[
        0]  #*10**(8)        # to get [m^2/s]. [A^2/ps] = 10**(-8)[m^2/s]

    p3 = np.polyfit(time[0:100], MSD[0:100], degree)
    f3 = np.polyval(p3, time)
    d_mean_actual = p3[
        0]  #*10**(8)          # to get [m^2/s]. [A^2/ps] = 10**(-8)[m^2/s]

    print "#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#"
    print " Nvalues in estimate 1 = 100"
    print " Nvalues in estimate 2 = %g" % (int(round(start / 2.0)))
    print " Nvalues in estimate 3 = %g" % (int(round(start)))
    print " Nvalues in estimate 4 = %g" % (len(time[start:]))

    ###############################################################################
    #                             plotting
    #plt.close('all')
    plt.figure()  # Figure 1
    Title = 'Mean square displacement'
    legends = ['$msd_{x}$', '$msd_{y}$', '$msd_{z}$', '$msd$']  #['$msd$']#
    Ylabel = 'mean square displacement $ [A^2] $'
    Xlabel = 'time $ [ps] $'
    pltname = 'MSD_bulkwater'
    linestyles = ['--r', '--y', '--k', 'o-b']  #['--r'] #
    plt.hold(True)
    plt.plot(time, MSDX, linestyles[0])
    plt.plot(time, MSDY, linestyles[1])
    plt.plot(time, MSDZ, linestyles[2])
    plt.plot(time, MSD, linestyles[3], markevery=10)
    plt.title(Title)
    plt.xlabel(Xlabel)
    plt.ylabel(Ylabel)
    plt.legend(legends, loc='lower right')
    plt.hold(False)
    write_to_file(ofile, Title, Xlabel, Ylabel, pltname, legends, linestyles,
                  [time], [MSDX, MSDY, MSDZ, MSD])

    from mpl_toolkits.axes_grid.inset_locator import zoomed_inset_axes, inset_axes, mark_inset

    plt.figure()
    ax = plt.axes()  # Figure 2
    Title = 'Mean square displacement'
    legends = [
        'MSD',
        '$f_1 %.3f $' % (d_mean_actual),
        '$f_2 %.3f $' % (d_mean_initpart),
        '$f_3 %.3f $' % (d_mean_firstpart),
        '$f_4 %.3f $' % (d_mean_lastpart)
    ]
    pltname = 'MSD_bulkwater_mean'
    Xlabel = 'time $ [ps] $'
    Ylabel = 'mean square displacement $ [A^2] $'
    linestyles = ['b-', '--y', '--r', '--m', '--y']

    plt.hold(True)
    plt.plot(time, MSD, linestyles[0])
    plt.plot(time[0:int(round(len(f) / 8.0))], f3[0:int(round(len(f) / 8.0))],
             linestyles[1])  # very first part
    plt.plot(time[0:int(round(len(f) / 6.0))], f2[0:int(round(len(f) / 6.0))],
             linestyles[2])  # initpart
    plt.plot(time[0:int(round(len(f) / 5.0))], f1[0:int(round(len(f) / 5.0))],
             linestyles[3])  # firstpart
    plt.plot(time, f, linestyles[4])  # lastpart

    plt.hold(False)
    plt.xlabel(Xlabel)
    plt.ylabel(Ylabel)
    plt.legend(legends, loc='lower right')
    plt.title(Title)

    ax.spines['top'].set_visible(False)
    ax.spines['right'].set_visible(False)
    ax.get_xaxis().tick_bottom()
    ax.get_yaxis().tick_left()

    axin = inset_axes(ax, width="30%", height="35%", loc=8)
    plt.hold(True)
    axin.plot(time, MSD, linestyles[0])
    axin.plot(time, f3, linestyles[1], linewidth=3.0)
    axin.plot(time, f2, linestyles[2])
    #axin.plot(time,f1,linestyles[3])
    plt.hold(False)
    axin.set_xlim(500, 520)
    ya = 0.0
    yb = 4.0
    Npoints = 4
    points = np.linspace(ya, yb, Npoints)
    axin.set_ylim(ya, yb)
    axin.set_xticks([])
    axin.set_yticks(points)
    mark_inset(ax, axin, loc1=3, loc2=4, fc="none", ec="0.5")

    write_to_file(ofile, Title, Xlabel, Ylabel, pltname, legends, linestyles,
                  [time], [MSD, f])

    print "#################################################################"
    print "# Diffusion estimate f1   : D = %.10f " % (d_mean_actual)
    print "# Diffusion estimate f2   : D = %.10f " % (d_mean_initpart)
    print "# Diffusion estimate f3   : D = %.10f " % (d_mean_firstpart)
    print "# Diffusion estimate f4   : D = %.10f " % (d_mean_lastpart)

    plt.figure()  # Figure 3
    Title = 'Time evolution of the local diffusion constant. $ D=(msd/6dt) $'
    legends = ['$D(t)$']
    linestyles = ['-y']
    pltname = 'Diffusion_bulkwater'
    Ylabel = 'displacement $ [ %g m^2/s]$' % factor
    plt.hold(True)
    plt.plot(time, D_local, linestyles[0])
    plt.hold(False)
    plt.legend(legends, loc='upper right')
    plt.title(Title)
    plt.xlabel(Xlabel)
    plt.ylabel(Ylabel)
    write_to_file(ofile, Title, Xlabel, Ylabel, pltname, legends, linestyles,
                  [time], [D_local])

    plt.show()
Esempio n. 12
0
def bulkdensity(ofile, timestep, mass_of_system, Time, frontname,
                pathtodatabase):
    '''
    masses[i] contains the mass of atom in types[i].
    systemSize = [xlo xhi ylo yhi zlo zhi]
    GM is a grand matrix containing all atom IDs, types and positions.
    The bulkdensity function calculates the density of a bulk system
    at every timestep, and plots the density as a function of time
    mass_of_system
    '''
    avogadro_aangstrom_relation = 10.0 / 6.022
    density = []
    volume = []
    i = 0
    for time in Time:
        path = frontname + '.%r.txt' % (time)
        print "# Processing file: %s " % path
        filename = os.path.abspath(os.path.join(pathtodatabase, path))
        t, Natoms, system_size, matrix, readstructure, entries, types = readfile(
            filename)  # this takes time processing !!
        dx = system_size[1] - system_size[0]  # Aangstrom
        dy = system_size[3] - system_size[2]  # Aangstrom
        dz = system_size[5] - system_size[4]  # Aangstrom
        vol = dx * dy * dz  # volume of system [Aangstrom^3]
        volume.append(vol)
        density.append((mass_of_system / vol) * avogadro_aangstrom_relation)
        i += 1

    t = []
    for time in Time:
        t.append(time * timestep / 1000.0)  # converts to pico-seconds

    if "carb" in frontname:
        dens = 1.7966 * 10**(-3)  # g/cm^3
        benchmarkline = np.linspace(
            dens, dens, 5)  # carbon dioxide benchmarkline for density
        pltname = "Density_cardondioxide"
    elif "water" in frontname:
        dens = 0.998  # g/cm^3
        benchmarkline = np.linspace(dens, dens,
                                    5)  # water benchmarkline for density
        pltname = "Density_water"
    elif "quartz" in frontname:
        dens = 2.648  # g/cm^3
        benchmarkline = np.linspace(dens, dens, 5)
        pltname = "Density_quartz"
    elif "portlandite" in frontname:
        dens = 2.24  # g/cm^3
        benchmarkline = np.linspace(dens, dens, 5)
        pltname = "Density_portlandite"
    else:
        print "ERRORERRORERRORERRORERRORERRORERRORERRORERRORERRORERRORERRORERROR"
        print "Error!\n Could not recognize either 'carb', 'water', 'quartz or 'portlandite' in frontname"

    start = int(round(0.1 * len(density)))
    meanDens = np.mean(density[start:])
    stdDens = np.std(density[start:])
    line = np.linspace(meanDens, meanDens, 6)
    Title = 'Density profile\\newline$\\rho = %.4g \\pm %.5g [g/cm^3]$' % (
        meanDens, stdDens)
    Xlabel = 'time $ [ps] $'
    Ylabel = 'density $ [g/cm^3] $'
    legends = ['$\\rho$', '$\\rho_{avg}$', '$\\rho_{exp}$']
    linestyles = ['g--', 'b-d', 'r-o']
    tstop = t[-1]
    tstart = t[0]
    dt = tstop - tstart
    line_points = [
        tstart, (tstart + dt / 5), (tstart + 2 * dt / 5),
        (tstart + 3 * dt / 5), (tstart + 4 * dt / 5), tstop
    ]
    benchmarkline_points = [
        tstart, (tstart + dt / 4), (tstart + dt / 2), (tstart + 3 * dt / 4),
        tstop
    ]
    plt.figure()
    plt.hold(True)
    plt.plot(t, density, 'g--')
    plt.plot(line_points, line, 'b-d', linewidth=3.0)
    plt.plot(benchmarkline_points, benchmarkline, 'r-o', linewidth=2.0)
    plt.hold(False)
    plt.title(Title)
    plt.legend(legends)
    plt.xlabel(Xlabel)
    plt.ylabel(Ylabel)

    meanVol = np.mean(volume)
    stdVol = np.std(volume)
    Title = '$V_{system} = %g \\pm %g A^3$' % (meanVol, stdVol)
    Xlabel = 'time [ps]'
    Ylabel = 'volume'
    plt.figure()
    plt.plot(t, volume, '-b')
    plt.title(Title)
    plt.xlabel(Xlabel)
    plt.ylabel(Ylabel)
    plt.legend(['volume'], loc='upper left')

    plt.show()
    write_to_file(ofile, Title, Xlabel, Ylabel, pltname, legends, linestyles,
                  [t, line_points, benchmarkline_points],
                  [density, line, benchmarkline])