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 __init__(self, trajectory_dir='./', lattice_poscar='', follow_atom=0, step_size=200): # Read reference lattice: pp = PoscarParser(lattice_poscar) self.lattice = pp.get_positions(coordinates='direct') self.nsites = self.lattice.shape[0] print "Reference POSCAR contains %d lattice sites" % (self.nsites) # Get occupancies self.traj_dir = trajectory_dir self.lattice_poscar = lattice_poscar self.traj = self.read_trajectory(traj_dir=trajectory_dir) self.occ, self.inhabitants = self.traj.get_occupancies( lattice=self.lattice, step_size=step_size) self.time = self.traj.time[::step_size] / 1.e3
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' }
traj = p.get_all_trajectories() traj.save(npz) fac = 8 * 2 * np.pi nsteps = traj.length natoms = traj.num_atoms lambda_x = np.zeros((nsteps)) lambda_y = np.zeros((nsteps)) lambda_z = np.zeros((nsteps)) ### <!-- Test begin --> from oppvasp.vasp.parsers import PoscarParser ps = PoscarParser( '/Users/danmichael/master/notur/hipersol/templates/si64/POSCAR' ).get_structure() r = ps.get_positions('direct') # Shift all positions r += -0.01 + np.random.rand(64, 3) * 0.02 natoms = r.shape[0] test1 = 1. / 3 * (np.sum(np.cos(fac * r[:, 0])) / natoms + np.sum(np.cos(fac * r[:, 1])) / natoms + np.sum(np.cos(fac * r[:, 2])) / natoms) kvec = np.array((8, 0, 0)) # 2**3 for 2x2x2 supercell s = 2 * np.pi * np.dot(r, kvec) test2 = np.sum(np.exp(np.complex(0, 1) * s)).real / natoms
help='Max displacement, in Angstrom') #parser.add_argument('--no_wrap', '-n', action='store_true', help='Don\'t wrap coordinates back into unit cell' ) parser.add_argument('infile', nargs='?', type=oppvasp.util.FileType('r'), default='POSCAR', help='Input filename (defaults to POSCAR)') parser.add_argument('outfile', nargs='?', type=oppvasp.util.FileType('w'), default=sys.stdout, help='Output filename (defaults to stdout)') args = parser.parse_args() # Read atoms from POSCAR: structure1 = PoscarParser(args.infile, silent=True).get_structure() pos = structure1.get_positions(coords='cart') #print "Max displacement: %.3f Angstrom" % args.max # find random displacements using spherical coordinates: rnd = np.random.random(pos.shape) r = rnd[:, 0] * args.max azimuth = rnd[:, 1] * 2 * np.pi zenith = rnd[:, 1] * np.pi # convert to cartesian coordinates: rnd[:, 0] = r * np.cos(azimuth) * np.sin(zenith) rnd[:, 1] = r * np.sin(azimuth) * np.sin(zenith) rnd[:, 2] = r * np.cos(zenith) structure1.set_positions(pos + rnd, coords='cart')
def read_trajectory(dir='', unwrap_pbcs=True, xml_file='vasprun.xml', orig_file='traj_orig.h5', unwrapped_file='traj_unwrapped.h5', poscar_file='POSCAR'): """ Convenience function for reading trajectory data from vasprun.xml. - The first time a trajectory is read, the trajectory data is read from vasprun.xml using lxml, and saved in a HDF5 binary file using PyTables. - The next time the trajectory is read, the HDF5 file is read directly. This is much faster. If `unwrap_pbcs' is set to True, periodic boundary conditions (PBCs) will be unwrapped, using initial positions from a specified POSCAR file. Initial positions are taken from a POSCAR file instead of the initial positions in the vasprun.xml file, because the latter are wrapped into the cell, making visual comparison with the original structure difficult if the POSCAR file contained coordinates out of the cell, such as may result from a cell where the atoms were relaxed from initial positions at the edge of the cell. Parameters ---------- dir : str Directory to read files from Default is current directory unwrap_pbcs : bool Set to True to unwrap the periodic boundary conditions (PBCs) or False to leave them. Default is True xml_file : str Name of the vasprun.xml file, default is "vasprun.xml" orig_file : str Name of the HDF5 file unwrapped_file : str Name of the HDF5 file containing unwrapped PBCs. Only used if unwrap_pbcs is set to True """ if not os.path.isfile(dir + orig_file): p = IterativeVasprunParser(dir + xml_file) traj = p.get_trajectory() traj.save(dir + orig_file) if not unwrap_pbcs: return traj elif not unwrap_pbcs: return Trajectory(filename=dir + orig_file) if os.path.isfile(dir + unwrapped_file): return Trajectory(filename=dir + unwrapped_file) else: poscar = PoscarParser(dir + poscar_file) pos = poscar.get_positions(coords='direct') try: t = traj except: t = Trajectory(filename=dir + orig_file) print "Unwrapping using initial pos from POSCAR" t.unwrap_pbc(init_pos=pos) t.save(dir + unwrapped_file) return t
help='Print radial displacements (displacement vector norms) for all atoms' ) parser.add_argument( '--no_unwrap', '-n', action='store_true', help='Don\'t try to unwrap motion over periodic boundaries.') parser.add_argument('infile', nargs='?', default='POSCAR', type=argparse.FileType('r'), help='POSCAR filename') args = parser.parse_args() # Read atoms from POSCAR: poscar1 = PoscarParser(args.infile).get_structure() pos = poscar1.get_positions(coords='direct') natoms = pos.shape[0] # Build array of pair indices: pairs = get_pairs(natoms) npairs = pairs.shape[0] print "%d atoms, %d pairs" % (natoms, npairs) # Find displacement vectors for all atoms: x = pos[pairs[:, 0]] - pos[pairs[:, 1]] # Use minimum image convention to threat bonds over PBCs # Note: This will not work with *very* tilted unit cells x = x - (2 * x).astype('int')
import sys, os import numpy as np from oppvasp.vasp.parsers import PoscarParser from oppvasp.structure import Structure from oppvasp.utils import query_yes_no ## Parameters infile = 'CONTCAR.1' outfile = 'CONTCAR-222' px = [-1, 0] py = [-1, 0] pz = [-1, 0] try: pp = PoscarParser(infile) except: print "Failed to read %s" % (infile) sys.exit(1) s = pp.get_structure() p = s.get_positions('d') a = s.get_atomtypes() c = s.get_cell() nx = len(px) ny = len(py) nz = len(pz) singlesize = p.shape[0] totalsize = singlesize * len(px) * len(py) * len(pz) print "Original unit cell contained %d atoms. New cell will contain %d atoms" % (
y = self.y[:mp] return float(y[y < treshold].shape[0]) / y.shape[0] #print y[not y>treshold].shape if __name__ == "__main__": from oppvasp import read_trajectory from oppvasp.vasp.parsers import PoscarParser #atom = 42 atom = 0 traj = read_trajectory( './', unwrap_pbcs = False ) poscar = '/Users/danmichael/Documents/Studier/Master/notur/hipersol/templates/si64/POSCAR' pl = DistanceFromLatticeSites(trajectory = traj, lattice = PoscarParser(poscar).get_structure(), atom = atom, nn = 1, step = 50 ) first = True def on_enter_site(obj): global first if first: sys.stdout.write('\033[31;1mEntered lattice site at %.2f\033[0m\n' % obj['x']) first = False pl.entered_site.subscribe(on_enter_site) pl.plot_to_file('%s_%s.pdf' % (os.getcwd().split('/').pop(), 'dist_from_lattice' ), verbose = False) #dp.analyse()