def __init__(self, filename=None, pickleddata=None): """Initialize.""" self.poscar = poscar.POSCAR() self.grid = Grid3D() self.additional = [] if filename: self.load_file(open_by_suffix(filename), pickleddata)
def setup(self): datadir = os.path.abspath(os.path.dirname(__file__)) + "/data/" data_file = datadir + 'Graphene.wavecar' self.gr = wavecar.WAVECAR(data_file) self.gr_poscar = poscar.POSCAR(datadir + 'POSCAR.Graphene')
def setup(self): datadir = os.path.abspath(os.path.dirname(__file__)) + "/data/" data_file = datadir + 'Co.wavecar' self.co = wavecar.WAVECAR(data_file) self.co_poscar = poscar.POSCAR(datadir + 'Co.POSCAR')
def realspace_wfc(self, spin_i=0, k_i=0, band_i=0, gvec=None, ngrid=None, norm=False, poscar=poscar.POSCAR()): r"""Return the pseudo-wavefunction in real space. Calculate the pseudo-wavefunction of the KS states in the real space by using FFT transformation of the reciprocal space planewave coefficients. The 3D FE grid size is detemined by ngrid, which defaults to self.ngrid if it is not provided. GVectors of the KS states is used to put 1D plane wave coefficient back to 3D grid. Parameters ----------- spin_i: int, optional spin index (0 or 1). default is 0 k_i: int, optional k index :math:`k_i`. Starts with 0. default is 0 band_i: int, optional band index :math:`b_i`. starts with 0. default is 0. norm: bool, optional If true the Band coeffients are normliazed gvec: numpy.array, optional G-vector for calculation. (default is self.gvectors(k_i)) ngrid: numpy.array, optional Ngrid for calculation. (default is self.ngrid). poscar: vaspy.poscar.POSCAR, optional POSCAR object (defalut is blank POSCAR object) Returns ----------- numpy.array If poscar is not specified, for Collinear-wavecar file. data for the wavefunction in the real space. .T is due to the original data is made by fortran program (i.e. 'VASP', of course. tuple If poscar is not specified, for SOI-wavecar file. the first item is for 'up' wavefunction in real space. the second item is for 'down' wavefunction in real space. vaspy.mesh3d.VASPGrid Returns VASPGrid object, if poscar is specified. The former frame represents the real part of the wavefunction at :math:`k_i` and :math:`b_i` in the real space, the latter frame the imaginary part. For the SOI wavecar, 4 frames. The first and second are for the "up" wavefunction, and the third and fourth are "down" wavefunction. (Judging SOI by gvectors(k_i).shape[0] :math:`\neq` bandcoeff(k_i).size) """ if ngrid is None: ngrid = self.ngrid.copy() else: ngrid = np.array(ngrid, dtype=int) if gvec is None: gvec = self.gvectors(k_i) gvec %= ngrid[np.newaxis, :] if self.gamma and PARALLEL: phi_k = np.zeros((ngrid[0], ngrid[1], ngrid[2] // 2 + 1), dtype=np.complex128) elif self.gamma and not PARALLEL: phi_k = np.zeros((ngrid[0] // 2 + 1, ngrid[1], ngrid[2]), dtype=np.complex128) else: phi_k = np.zeros(ngrid, dtype=np.complex128) try: # Collininear phi_k[gvec[:, 0], gvec[:, 1], gvec[:, 2]] = self.bandcoeff(spin_i, k_i, band_i, norm) except ValueError: # SOI: bandcoeff = self.bandcoeff(spin_i, k_i, band_i, norm) phi_k = np.zeros((2, ngrid[0], ngrid[1], ngrid[2]), dtype=np.complex128) phi_k[0][gvec[:, 0], gvec[:, 1], gvec[:, 2]] = bandcoeff[:bandcoeff.size // 2] phi_k[1][gvec[:, 0], gvec[:, 1], gvec[:, 2]] = bandcoeff[bandcoeff.size // 2:] # if self.gamma: if PARALLEL: for ix in range(ngrid[0]): for iy in range(ngrid[1]): fx = ix if ix < ngrid[0] // 2 + 1 else ix - ngrid[0] fy = iy if iy < ngrid[1] // 2 + 1 else iy - ngrid[1] if (fy > 0) or (fy == 0 and fx >= 0): continue phi_k[ix, iy, 0] = phi_k[-ix, -iy, 0].conjugate() else: for iz in range(ngrid[2]): for iy in range(ngrid[1]): fz = iz if iz < ngrid[2] // 2 + 1 else iz - ngrid[2] fy = iy if iy < ngrid[1] // 2 + 1 else iy - ngrid[1] if (fy > 0) or (fy == 0 and fz >= 0): continue phi_k[0, iy, iz] = phi_k[0, -iy, -iz].conjugate() phi_k /= np.sqrt(2.0) phi_k[0, 0, 0] *= np.sqrt(2.) phi_k = restore_gamma_grid(phi_k) # self.phi_k = phi_k # For debug phi_r = ifftn(phi_k) if poscar.scaling_factor == 0.: if phi_r.ndim == 3: return phi_r.T else: # SOI return (phi_r[0] + phi_r[1]).T, (phi_r[0] - phi_r[1]).T else: vaspgrid = mesh3d.VASPGrid() vaspgrid.poscar = poscar vaspgrid.grid.shape = ngrid # checking consistency between POSCAR and WAVECAR np.testing.assert_array_almost_equal( poscar.scaling_factor * poscar.cell_vecs, self.realcell) re = np.real(phi_r) im = np.imag(phi_r) if phi_r.ndim == 3: vaspgrid.grid.data = np.concatenate( (re.flatten('F'), im.flatten('F'))) else: # SOI vaspgrid.grid.data = np.concatenate( ((re[0] + re[1]).flatten('F'), (im[0] + im[1]).flatten('F'), (re[0] - re[1]).flatten('F'), (im[0] - im[1]).flatten('F'))) return vaspgrid
dim = [int(x) for x in args.dim.split(',')] vsim_data = vsim_asc.VSIM_ASC(args.vsim) n_modes = len(vsim_data.freqs) positions = vsim_data.build_phono_motion(mode=args.mode, supercell=dim, n_frames=args.frames, magnitude=args.magnitude) ionnums, iontypes = vsim_asc.ions_to_iontypes_ionnums(vsim_data.ions) ionnums = [i * dim[0] * dim[1] * dim[2] for i in ionnums] motion_frames = [[p[frame] for p in positions] for frame in range(args.frames)] # supercell = vsim_asc.supercell_lattice_vectors(vsim_data.lattice_vectors, dim) # if args.poscar: for frame in range(args.frames): vasp_poscar = poscar.POSCAR() vasp_poscar.system_name = vsim_data.system_name vasp_poscar += '_mode_' + str(args.mode) + '_frame_' + str(frame) vasp_poscar.scaling_factor = 1.0 vasp_poscar.cell_vecs = supercell vasp_poscar.iontypes = iontypes vasp_poscar.ionnums = ionnums vasp_poscar.coordinate_type = 'CARTESIAN' vasp_poscar.positions = motion_frames[frame] vasp_poscar.save('POSCAR_mode_' + str(args.mode) + '_frame_' + str(frame) + '.vasp') else: xdatcar_str = vsim_data.system_name + '_mode_' + str(args.mode) + '\n' xdatcar_str += ' 1.00\n' for i in range(3): xdatcar_str += ' {:#.6f} {:#.6f} {:6f}\n'.format(