def __init__(self, trajectory_dir = './', lattice_poscar = ''): self.traj_dir = trajectory_dir self.lattice_poscar = lattice_poscar self.traj = read_trajectory( trajectory_dir, unwrap_pbcs = True ) self.pos = self.traj.get_all_trajectories( coords = 'cartesian' ) self.natoms = self.pos.shape[1] self.nsteps = self.pos.shape[0] self.poscar = PoscarParser( lattice_poscar ) # Read reference lattice: self.lattice = self.poscar.get_positions( coords = 'cartesian') self.nsites = self.lattice.shape[0] print "Reference POSCAR contains %d lattice sites" % (self.nsites) self.bottombar_height = .3 self.bottombar_colors = { 892: 'green', 860: 'yellow', 868: 'blue', 844: 'red' }
def __init__(self, trajectory_dir = './', lattice_poscar = '', atomid = 0): """ time_steps in ps """ self.traj_dir = trajectory_dir self.lattice_poscar = lattice_poscar self.traj = read_trajectory( dir = trajectory_dir, unwrap_pbcs = True ) self.time = self.traj.time/1000. self.pos = self.traj.get_all_trajectories( coords = 'cart' ) self.natoms = self.pos.shape[1] self.nsteps = self.pos.shape[0] #print "Generating symmetric running mean..." #self.pos[:,atomid] = symmetric_running_mean(self.pos[:,atomid],250) #pos[:,0] = symmetric_running_mean(pos[:,0],500) # Read reference lattice: pp = PoscarParser( lattice_poscar ) self.lattice = pp.get_positions( coords = 'cart') self.nsites = self.lattice.shape[0] #print "Reference POSCAR contains %d lattice sites" % (self.nsites) #import profile #profile.run('get_occupancies()') # Calculate occupancies, nearest site for atom x and distance to nearest site(s) self.nearest_site, self.nearest_site_r = self.find_nearest_sites( atomid = atomid)
def lindemann_index(trajectory_dir='./'): """ Calculates the Lindemann index \delta = \frac{2}{N(N-1)} \sum_{i<j} \frac{\sqrt{\langle r_{ij}^2\rangle_t - \langle r_{ij} \rangle^2_t }}{ \langle r_{ij} \rangle_t } """ # Import vasprun.xml: traj = read_trajectory( dir = trajectory_dir, unwrap_pbcs = False ) pos = traj.get_all_trajectories( coords = 'direct' ) nsteps = pos.shape[0] natoms = pos.shape[1] # Get all atom pairs: pairs = get_pairs(natoms) npairs = pairs.shape[0] print "%d steps, %d atoms, %d pairs" % (nsteps, natoms, npairs) stepsize = 50 samplesteps = np.arange(0,nsteps,stepsize) r = np.zeros((samplesteps.size, npairs)) # increase stepsize if we run out of memory r2 = np.zeros((samplesteps.size, npairs)) # increase stepsize if we run out of memory print "Allocated %.3f MB" % ((r.nbytes+r2.nbytes)/(1024.**2)) pbar = ProgressBar(widgets=['At step...',SimpleProgress()], maxval = samplesteps.size).start() for idx,s in enumerate(samplesteps): pbar.update(idx) x = pos[s,pairs[:,0]] - pos[s,pairs[:,1]] x = x - (2*x).astype('int') # minimum image convention r2[idx] = lensq(x) r[idx] = np.sqrt(r2[idx]) pbar.finish() meanr2 = np.mean(r2,axis=0) meanr = np.mean(r,axis=0) return np.sum(np.sqrt((meanr2 - meanr**2))/meanr)*2/(npairs*2)
def lindemann_index(trajectory_dir="./"): """ Calculates the Lindemann index \delta = \frac{2}{N(N-1)} \sum_{i<j} \frac{\sqrt{\langle r_{ij}^2\rangle_t - \langle r_{ij} \rangle^2_t }}{ \langle r_{ij} \rangle_t } """ # Import vasprun.xml: traj = read_trajectory(dir=trajectory_dir, unwrap_pbcs=False) pos = traj.get_all_trajectories(coords="direct") nsteps = pos.shape[0] natoms = pos.shape[1] # Get all atom pairs: pairs = get_pairs(natoms) npairs = pairs.shape[0] print "%d steps, %d atoms, %d pairs" % (nsteps, natoms, npairs) stepsize = 50 samplesteps = np.arange(0, nsteps, stepsize) r = np.zeros((samplesteps.size, npairs)) # increase stepsize if we run out of memory r2 = np.zeros((samplesteps.size, npairs)) # increase stepsize if we run out of memory print "Allocated %.3f MB" % ((r.nbytes + r2.nbytes) / (1024.0 ** 2)) pbar = ProgressBar(widgets=["At step...", SimpleProgress()], maxval=samplesteps.size).start() for idx, s in enumerate(samplesteps): pbar.update(idx) x = pos[s, pairs[:, 0]] - pos[s, pairs[:, 1]] x = x - (2 * x).astype("int") # minimum image convention r2[idx] = lensq(x) r[idx] = np.sqrt(r2[idx]) pbar.finish() meanr2 = np.mean(r2, axis=0) meanr = np.mean(r, axis=0) return np.sum(np.sqrt((meanr2 - meanr ** 2)) / meanr) * 2 / (npairs * 2)
def __init__(self, trajectory_dir='./', lattice_poscar=''): self.traj_dir = trajectory_dir self.lattice_poscar = lattice_poscar self.traj = read_trajectory(trajectory_dir, unwrap_pbcs=True) self.pos = self.traj.get_all_trajectories(coords='cartesian') self.natoms = self.pos.shape[1] self.nsteps = self.pos.shape[0] self.poscar = PoscarParser(lattice_poscar) # Read reference lattice: self.lattice = self.poscar.get_positions(coords='cartesian') self.nsites = self.lattice.shape[0] print "Reference POSCAR contains %d lattice sites" % (self.nsites) self.bottombar_height = .3 self.bottombar_colors = { 892: 'green', 860: 'yellow', 868: 'blue', 844: 'red' }
#from oppvasp.vasp.parsers import VasprunParser, IterativeVasprunParser, PoscarParser from progressbar import ProgressBar, Percentage, Bar, ETA, FileTransferSpeed, \ RotatingMarker, ReverseBar, SimpleProgress import psutil def norm(v): return np.sqrt(np.dot(v, v)) wdir = './' basename = os.path.splitext(os.path.basename(sys.argv[0]))[0] fig_filename = wdir + basename + '.pdf' traj = read_trajectory(wdir, unwrap_pbcs=True) poten = (traj.total_energy - traj.kinetic_energy) / traj.num_atoms t = traj.time / 1.e3 # -> ps poten_m = symmetric_running_mean(poten, 500) styles = [{'color': 'black', 'alpha': 0.2}, {'color': 'black', 'alpha': 1.}] fig = plt.figure() # Main plot: p = [0.15, 0.15, 0.05, 0.05] # margins: left, bottom, right, top. Height: 1-.15-.46 = .39 ax1 = fig.add_axes([p[0], p[1], 1 - p[2] - p[0], 1 - p[3] - p[1]]) ax1.grid(True, which='major', color='gray', alpha=0.5) #ax1.set_ylim((-.2,1.0)) ax1.set_xlabel('Time [ps]')
parser = OptionParser() pdf_file = os.path.splitext(os.path.basename(sys.argv[0]))[0] + '.pdf' parser.add_option('--pdf', dest = 'pdf_file', default = pdf_file, help = 'Destination PDF') parser.add_option('--xml', dest = 'xml_file', default = 'vasprun.xml', help = 'Input vasprun.xml') parser.add_option('--poscar', dest = 'poscar_file', default = 'POSCAR', help = 'Input POSCAR') parser.add_option('-f', '--firststep', metavar='STEP', dest = 'first_step', type='int', default = 1, help = 'First ion step to include') parser.add_option('-l', '--laststep', metavar='STEP', dest = 'last_step', type='int', default = -1, help = 'Last ion step to include') parser.add_option('-a', '--atom', metavar='ATOM', dest = 'atom_no', type='int', default = 0, help = 'Index of atom to watch (first index is 0)') (options, args) = parser.parse_args() print "Range: %i:%i. Atom: %i" % (options.first_step, options.last_step, options.atom_no) ############################## MAIN SCRIPT ###################################### # Read trajectory: traj = read_trajectory(xml_file = options.xml_file, unwrap_pbcs = True, poscar_file = options.poscar_file) traj.set_selection(options.first_step, options.last_step) # Make plot dp = DisplacementPlot(traj) dp.add_plot( what = 'r2', smoothen = True, style = { 'linestyle' : '--', 'dashes' : (3,1), 'color' : 'black' } ) # avg r^2 for all atoms #dp.add_plot( what = 'x', atom_no = 0, smoothen = True, linear_fit = True) dp.add_plot( what = 'r2', atom_no = 0, smoothen = True, linear_fit = False) #dp.add_plot( what = 'r', atom_no = 0, smoothen = True, linear_fit = True) #dp.add_plot( what = 'x', atom_no = 0, smoothen = False, style = { 'zorder' : -1, 'alpha': 0.4, 'color': 'gray' } ) ymax = 0 ymin = 0 for p in dp.plotdata: ymax_tmp = np.max(p['y']) if ymax_tmp > ymax:
from oppvasp.vasp.parsers import read_trajectory #from oppvasp.vasp.parsers import VasprunParser, IterativeVasprunParser, PoscarParser from progressbar import ProgressBar, Percentage, Bar, ETA, FileTransferSpeed, \ RotatingMarker, ReverseBar, SimpleProgress import psutil def norm(v): return np.sqrt(np.dot(v,v)) wdir = './' basename = os.path.splitext(os.path.basename(sys.argv[0]))[0] fig_filename = wdir + basename + '.pdf' traj = read_trajectory(wdir, unwrap_pbcs = True) poten = (traj.total_energy - traj.kinetic_energy)/traj.num_atoms t = traj.time/1.e3 # -> ps poten_m = symmetric_running_mean(poten, 500) styles = [ { 'color': 'black', 'alpha': 0.2 }, { 'color': 'black', 'alpha': 1. } ] fig = plt.figure() # Main plot: p = [0.15, 0.15, 0.05, 0.05] # margins: left, bottom, right, top. Height: 1-.15-.46 = .39 ax1 = fig.add_axes([ p[0], p[1], 1-p[2]-p[0], 1-p[3]-p[1] ]) ax1.grid(True, which='major', color = 'gray', alpha = 0.5)
#!/usr/bin/env python from oppvasp.plotutils import symmetric_running_median, prepare_canvas prepare_canvas('10 cm') from oppvasp.vasp.parsers import read_trajectory import numpy as np import matplotlib.pyplot as plt t = read_trajectory() ekin = t.kinetic_energy/t.num_atoms*1.e3 avgEkin = np.median(ekin) plt.plot(t.time/1000., ekin, color='blue', alpha=0.2, label = 'Raw data') plt.plot(t.time/1000., symmetric_running_median(ekin, 250), color='blue', alpha=1, label = '0.25 ps symmetric median') plt.xlabel("Time [ps]") plt.ylabel("Kinetic energy per atom [meV]") plt.axhline(y=avgEkin, color='black', linestyle='--', label = 'Whole run median (%.0f meV)' % avgEkin) plt.legend(frameon=False,loc='lower right') plt.savefig('plot_kinetic_energy.pdf')
import os, sys import numpy as np from oppvasp.vasp.parsers import read_trajectory from oppvasp.plotutils import DisplacementPlot first_step = 0 last_step = -1 if len(sys.argv) > 1: first_step= int(sys.argv[1]) print "Starting from step %i" % (first_step) if len(sys.argv) > 2: last_step = int(sys.argv[2]) print "Ending at step %i" % (last_step) # Read trajectory: traj = read_trajectory(unwrap_pbcs = True, poscar_file = 'POSCAR') traj.set_selection(first_step, last_step) # Make plot dp = DisplacementPlot(traj) dp.add_plot( what = 'D', atom_no = 0, smoothen = True, linear_fit = False) #dp.ax1.legend(('All atoms', 'P'), ncol = 1, loc = 'upper left', frameon = False) D = dp.get_diffusion_coeff([0])[0] td = np.zeros((D.shape[0],2)) td[:,0] = dp.trajs[0].time td[:,1] = D np.savetxt('out.csv',td, delimiter='\t')
import os, sys import numpy as np from oppvasp.vasp.parsers import read_trajectory from oppvasp.plotutils import DisplacementPlot first_step = 0 last_step = -1 if len(sys.argv) > 1: first_step = int(sys.argv[1]) print "Starting from step %i" % (first_step) if len(sys.argv) > 2: last_step = int(sys.argv[2]) print "Ending at step %i" % (last_step) # Read trajectory: traj = read_trajectory(unwrap_pbcs=True, poscar_file='POSCAR') traj.set_selection(first_step, last_step) # Make plot dp = DisplacementPlot(traj) dp.add_plot(what='D', atom_no=0, smoothen=True, linear_fit=False) #dp.ax1.legend(('All atoms', 'P'), ncol = 1, loc = 'upper left', frameon = False) D = dp.get_diffusion_coeff([0])[0] td = np.zeros((D.shape[0], 2)) td[:, 0] = dp.trajs[0].time td[:, 1] = D np.savetxt('out.csv', td, delimiter='\t') Ds = D[-1]
'--atom', metavar='ATOM', dest='atom_no', type='int', default=0, help='Index of atom to watch (first index is 0)') (options, args) = parser.parse_args() print "Range: %i:%i. Atom: %i" % (options.first_step, options.last_step, options.atom_no) ############################## MAIN SCRIPT ###################################### # Read trajectory: traj = read_trajectory(xml_file=options.xml_file, unwrap_pbcs=True, poscar_file=options.poscar_file) traj.set_selection(options.first_step, options.last_step) # Make plot dp = DisplacementPlot(traj) dp.add_plot(what='r2', smoothen=True, style={ 'linestyle': '--', 'dashes': (3, 1), 'color': 'black' }) # avg r^2 for all atoms #dp.add_plot( what = 'x', atom_no = 0, smoothen = True, linear_fit = True) dp.add_plot(what='r2', atom_no=0, smoothen=True, linear_fit=False) #dp.add_plot( what = 'r', atom_no = 0, smoothen = True, linear_fit = True)