def POSCAR_writer(self,fname="/POSCAR"): vac = 15 # vacuum spacing c = vac + np.sum(self.dz) + np.sum(self.zsep) c = self.nlayers * 6 + 10 a0 = np.mean(self.a0) # let the combined lattice constant be the averaged value A0 = [[1*a0, 0, 0], [-0.5*a0, sqrt(3)/2*a0, 0], [0, 0, c]] # relax the atomic positions in the z direction relax = [[False, False, True] for x in range(self.nlayers*3)] # create atomic positions for all layers in Cartesian coordinate coords = np.zeros([self.nlayers*3,3]) z_here = 0 for l in range(self.nlayers): relax[l*3][2]=False # do not relax the z position of the metal z_here = z_here + self.dz[l] if l > 0: z_here = z_here + self.zsep[l] if self.alignment[l] == 0: # 0 deg. coords_here = np.array([[0, 0, 0], [1./3, 2./3, -self.zsep[l]], [1./3, 2./3, self.zsep[l]]]) else: # 180 deg. coords_here = [[1./3, 2./3, 0], [0, 0, -self.zsep[l]], [0, 0, self.zsep[l]]] coords[l*3:(l+1)*3][:] = coords_here coords[l*3:(l+1)*3,2] += z_here coords[l*3:(l+1)*3,2] = coords[l*3:(l+1)*3,2] / c for i in range(3): if coords[l*3+i,2] < 0: coords[l*3+i,2] += 1 # For 0 deg. stacking, the AB stacking is the stable stacking config. # Need to shift by (1/3,1/3,0) for every for l in range(self.nlayers): if self.alignment[l] == 0: coords[l*3:,0] += 1./3 coords[l*3:,1] -= 1./3 layers = struct.Structure(A0,self.mat,coords,coords_are_cartesian=False) out = inputs.Poscar(layers) out.selective_dynamics=relax out.write_file(os.getcwd()+fname)
def export_dict(self, format="poscar", filename="./POSCAR"): """ Export edited structure. Arguments --------- fortmat: str Format of export data (default: "poscar"). filename: str File name (directory) of exported file (default: "./POSCAR"). """ struct = pymatgen.Structure.from_dict(self.struct_dict) if format is "poscar": with open(filename, mode="w") as file: file.writelines(str(vasp_inputs.Poscar(struct))) else: raise UndefinedFormatError(format)
def __init__(self, struct, format="structure", filename="undefined", atom_num_limit=0, output_original_struct_if_modified="True", output_format="poscar", output_path="./"): """ Arguments --------- struct: (Structure data) Original structure data, which can be pymatgen.Structure, poscar, cif, or any other what pymatgen can handle. format: str Format of read data. filename: str File name of read data. atom_num_limit: int The lower limit of the number of atoms in the unit cell. output_original_struct_if_modified: bool If this flag is True, output original structure if it is modified in make_supercell_enough_large method. output_format: str Format of output data of modified original structure. output_path: str Path to the output file. """ if format is "structure": self.struct = struct else: self.struct = pymatgen.Structure.from_str(open(struct).read(), fmt=format) self.filename = filename struct_if_modified = self.make_supercell_enough_large(atom_num_limit) if output_original_struct_if_modified and struct_if_modified: if output_format is "poscar": with open(output_path + "POSCAR_" + filename + "_modified", mode="w") as file: file.writelines(str(vasp_inputs.Poscar(self.struct))) else: raise UndefinedFormatError(format) self.struct_dict = self.struct.as_dict()
cell = Structure( lattice=np.array([[lattice_parameter[i, 9], 0, 0], [0, lattice_parameter[i, 10], 0], [0, 0, lattice_parameter[i, 11]]]) * j, species=[ 'Rh', 'Rh', 'Rh', 'Rh', 'Rh', 'Rh', 'Rh', 'Rh', 'Fe', 'Fe', 'Fe', 'Fe', z_atoms[i], z_atoms[i], z_atoms[i], z_atoms[i] ], coords=[(0.25, 0.25, 0.25), (0.75, 0.25, 0.75), (0.25, 0.75, 0.75), (0.75, 0.75, 0.25), (0.5, 0.5, 0.0), (0.0, 0.0, 0.0), (0.5, 0.0, 0.5), (0.0, 0.5, 0.5), (0.5, 0.0, 0.0), (0.0, 0.5, 0.0), (0.0, 0.0, 0.5), (0.5, 0.5, 0.5), (0.25, 0.75, 0.25), (0.75, 0.25, 0.25), (0.25, 0.25, 0.75), (0.75, 0.75, 0.75)], ) poscar = inputs.Poscar(cell) potcar = inputs.Potcar(symbols=['Rh_pv', 'Fe', z_potentials[i]], functional="PBE_54") kpoints = inputs.Kpoints(kpts=[[7, 7, 7]]) incar = inputs.Incar({ 'LCHARG': True, 'LWAVE': True, 'ICHARG': 1, 'IBRION': 2, 'ISIF': 3, 'POTIM': 0.1, 'PREC': 'Accurate', 'ENCUT': 460,
slabgen = SlabGenerator(structure, (0, 0, 1), size * structure.lattice.c, 15, center_slab=True) slabs = slabgen.get_slabs(symmetrize=True) print("Number of slabs:", len(slabs)) for i in range(len(slabs)): if not os.path.isdir('slab/ION/regular/{}/{:.0f}/{}'.format( z_atoms[k], size, i)): os.makedirs('slab/ION/regular/{}/{:.0f}/{}'.format( z_atoms[k], size, i)) poscar = inputs.Poscar(slabs[i], sort_structure=True) paw = [z_potentials[s.symbol] for s in slabs[i].types_of_species] potcar = inputs.Potcar(symbols=paw, functional="PBE_54") kpoints = inputs.Kpoints.automatic_density(slabs[i], 5000) incar = inputs.Incar({ 'LCHARG': True, 'LWAVE': True, 'ICHARG': 1, 'IBRION': 2, 'ISIF': 2, 'POTIM': 0.1, 'PREC': 'Accurate', 'ENCUT': 460,
for i in range(len(z_atoms)): for key in magmoms.keys(): for j in np.arange(0.8, 1.425, 0.025): if not os.path.isdir('ca/regular/{}/{}/{:.3f}'.format(z_atoms[i], key, j)): os.makedirs('ca/regular/{}/{}/{:.3f}'.format(z_atoms[i], key, j)) structure = Structure.from_file('{}/ION/isif7/regular/{}/{}/CONTCAR'.format(os.getcwd(), z_atoms[i], key)) D = np.array([[(j)**(-1.0/3.0), 0, 0], [0, (j)**(-1.0/3.0), 0], [0, 0, (j)**(2.0/3.0)]]) structure.lattice = np.dot(structure.lattice.matrix, D) poscar = inputs.Poscar(structure) potcar = inputs.Potcar(symbols=['Rh_pv', 'Fe', z_potentials[i]], functional="PBE_54") kpoints = inputs.Kpoints(kpts = [[7, 7, 7]]) incar = inputs.Incar({'LCHARG' : True, 'LWAVE' : True, 'ICHARG' : 1, 'IBRION' : 2, 'ISIF' : 2, 'POTIM' : 0.1, 'PREC' : 'Accurate', 'ENCUT' : 460, 'EDIFF' : 1e-7, 'EDIFFG' : 1e-3,
slabgen = SlabGenerator(structure, (0, 0, 1), size * structure.lattice.c, 10, center_slab=True) slabs = slabgen.get_slabs(symmetrize=True) print("Number of slabs:", len(slabs)) for i in range(len(slabs)): if not os.path.isdir('slab/test_distance/regular/Al/{:.0f}/{}'.format( size, i)): os.makedirs('slab/test_distance/regular/Al/{:.0f}/{}'.format( size, i)) poscar = inputs.Poscar(slabs[i]) paw = [z_potentials[s.symbol] for s in slabs[i].types_of_species] potcar = inputs.Potcar(symbols=paw, functional="PBE_54") kpoints = inputs.Kpoints.automatic_density(slabs[i], 5000) incar = inputs.Incar({ 'LCHARG': True, 'LWAVE': True, 'ICHARG': 1, 'IBRION': 2, 'ISIF': 2, 'POTIM': 0.1, 'PREC': 'Accurate', 'ENCUT': 460,
def relax_off(self,fname="./POSCAR-unit"): # turn off selective dynamics relax_struct=struct.Structure.from_file(fname) relax_poscar=inputs.Poscar(relax_struct,selective_dynamics=None) relax = [[False, False, False] for x in range(self.nlayers*3)] relax_poscar.write_file(fname)