def findspg(atoms): spg0 = spglib.get_spacegroup(atoms, symprec=0.1) if spg0: spg1 = spg0.split() spg = [str(spg1[0]), int(spg1[1][1:-1])] else: spg = [] # print spg0, spg return spg
def test(): myatoms = gen_STO() print(find_sym(myatoms)) #print myatoms.get_chemical_symbols() #natoms,d=ref_atoms_mag(myatoms) ##print ref_atoms_mag(myatoms)[0].get_chemical_symbols() #old_atoms=rev_ref_atoms(natoms,d) #print old_atoms.get_chemical_symbols() #print get_prim_atoms(myatoms) new_atoms = find_primitive_mag(myatoms) #print new_atoms.get_chemical_symbols() print(new_atoms.get_cell()) print(new_atoms.get_scaled_positions()) print(new_atoms.get_volume()) print(spglib.get_spacegroup(new_atoms)) #write('POSCAR',new_atoms,sort=True,vasp5=True) natoms = normalize(new_atoms) print(natoms.get_positions()) print(natoms.get_volume()) print(cell_to_cellpar(natoms.get_cell()))
def get_spacegroup(filename=False, format=False): if filename: pass elif os.path.isfile('geometry.in'): filename='geometry.in' elif os.path.isfile('POSCAR'): filename='POSCAR' else: raise Exception('No input file!') if format: atoms = ase.io.read(filename, format=format) else: atoms = ase.io.read(filename) print("| Threshold / Å | Space group |") print("|---------------|-------------------|") for threshold in (1e-5, 1e-4, 5e-4, 1e-3, 5e-3, 1e-2, 5e-2, 1e-1): print("| {0:0.5f} | {1: <16} |".format( threshold, spglib.get_spacegroup(atoms, symprec=threshold)))
def find_sym(atoms): return spglib.get_spacegroup(atoms, symprec=5e-4)
def gen_distorted_perovskite(name, cell=[3.9, 3.9, 3.9], supercell_matrix=[[1, -1, 0], [1, 1, 0], [0, 0, 2]], out_of_phase_rotation=0.0, in_phase_rotation=0.0, in_phase_tilting=0.0, breathing=0.0, JT_d=0.0, JT_a=0.0): atoms = gen_primitive(name=name, mag_order='PM', latticeconstant=3.9) spos = atoms.get_scaled_positions() #atoms.set_cell([3.5,3.5,3.9,90,90,90]) atoms.set_cell(cell) atoms.set_scaled_positions(spos) #from ase.io import write #write('cubic_LaMnO3.cif',atoms) dcell = distorted_cell(atoms, supercell_matrix=supercell_matrix) eigvec = np.zeros(15) eig_breathing = np.array(perovskite_mode.R2p) eig_JT_d = np.array(perovskite_mode.M2) eig_in_phase_tilting = np.array(perovskite_mode.X5_3) eig_out_of_phase_rotation_x = np.array(perovskite_mode.R25_1) eig_out_of_phase_rotation_y = np.array(perovskite_mode.R25_2) eig_in_phase_rotation_z = np.array(perovskite_mode.M3) disp_br = dcell._get_displacements(eigvec=eig_breathing, q=[0.5, 0.5, 0.5], amplitude=breathing, argument=0) #disp2=dcell._get_displacements(eigvec=out_of_phase_rotation,q=[0.5,0.5,0.5],amplitude=0.55,argument=0) disp_jt = dcell._get_displacements(eigvec=eig_JT_d, q=[0.5, 0.5, 0.0], amplitude=JT_d, argument=0) disp_tilting = dcell._get_displacements(eigvec=eig_in_phase_tilting, q=[0.0, 0.0, 0.5], amplitude=in_phase_tilting, argument=0) disp_rotx = dcell._get_displacements(eigvec=eig_out_of_phase_rotation_x, q=[0.5, 0.5, 0.5], amplitude=out_of_phase_rotation, argument=0) disp_roty = dcell._get_displacements(eigvec=eig_out_of_phase_rotation_y, q=[0.5, 0.5, 0.5], amplitude=out_of_phase_rotation, argument=0) disp_rotz = dcell._get_displacements(eigvec=eig_in_phase_rotation_z, q=[0.5, 0.5, 0.0], amplitude=in_phase_rotation, argument=0) #print(out_of_phase_rotation) #print(disp_rotx) #print(disp_jt) #print disp.shape newcell = dcell._get_cell_with_modulation(disp_jt + disp_rotx + disp_roty + disp_rotz + disp_br + disp_tilting) newcell = Atoms(newcell) print(spglib.get_spacegroup(newcell)) #vesta_view(newcell) return newcell
def gen_P21c_perovskite( name, cell=[3.9, 3.9, 3.9], supercell_matrix=[[1, -1, 0], [1, 1, 0], [0, 0, 2]], modes=dict( R2_m_O1=0.0, # R2-[O1:c:dsp]A2u(a), O, breathing R3_m_O1= 0.0, # R3-[O1:c:dsp]A2u(a), O JT inplane-stagger, out-of-plane antiphase R3_m_O2= 0.0, # R3-[O1:c:dsp]A2u(b), O, out-of-plane-stagger, inplane antiphase, Unusual. R4_m_A1=0.0, # R4-[Nd1:a:dsp]T1u(a), A , Unusual R4_m_A2=0.0, # R4-[Nd1:a:dsp]T1u(b), A, Unusual R4_m_A3=0.0, # R4-[Nd1:a:dsp]T1u(c), A, Unusual R4_m_O1=0.0, # R4-[O1:c:dsp]Eu(a), O, Unusual R4_m_O2=0.0, # R4-[O1:c:dsp]Eu(b), O, Unusual R4_m_O3=0.0, # R4-[O1:c:dsp]Eu(c), O, Unusual R5_m_O1=0.0, # R5-[O1:c:dsp]Eu(a), O a- R5_m_O2=0.0, # R5-[O1:c:dsp]Eu(b), O b- R5_m_O3=0.0, # R5-[O1:c:dsp]Eu(c), O c- X3_m_A1=0.0, # X3-[Nd1:a:dsp]T1u(a), What's this.. X3_m_O1=0.0, # X3-[O1:c:dsp]A2u(a) #X5_m_A1=0.0, # [Nd1:a:dsp]T1u(a), A , Antiferro mode #X5_m_A2=0.0, # [Nd1:a:dsp]T1u(b), A , save as above #X5_m_O1=0.0, # [Nd1:a:dsp]T1u(a), O , Antiferro mode #X5_m_O2=0.0, # [Nd1:a:dsp]T1u(b), O , same as above #M2_p_O1=0.0, # M2+[O1:c:dsp]Eu(a), O, In phase rotation c+ Z5_m_A1=0.0, # [Nd1:a:dsp]T1u(a), A , Antiferro mode Z5_m_A2=0.0, # [Nd1:a:dsp]T1u(b), A , save as above Z5_m_O1=0.0, # [Nd1:a:dsp]T1u(a), O , Antiferro mode Z5_m_O2=0.0, # [Nd1:a:dsp]T1u(b), O , same as above M2_p_O1=0.0, # M2+[O1:c:dsp]Eu(a), O, In phase rotation M3_p_O1=0.0, # M3+[O1:c:dsp]A2u(a), O, D-type JT inplane stagger M5_p_O1=0.0, # M5+[O1:c:dsp]Eu(a), O, Out of phase tilting M5_p_O2=0.0, # M5+[O1:c:dsp]Eu(a), O, Out of phase tilting M4_p_O1=0.0, # M4+[O1:c:dsp]A2u(a), O, in-plane-breathing (not in P21/c) G_Ax=0.0, G_Ay=0.0, G_Az=0.0, G_Sx=0.0, G_Sy=0.0, G_Sz=0.0, G_Axex=0.0, G_Axey=0.0, G_Axez=0.0, G_Lx=0.0, G_Ly=0.0, G_Lz=0.0, G_G4x=0.0, G_G4y=0.0, G_G4z=0.0, )): atoms = gen_primitive(name=name, mag_order='PM', latticeconstant=cell[0]) spos = atoms.get_scaled_positions() atoms.set_cell(cell) atoms.set_scaled_positions(spos) dcell = distorted_cell(atoms, supercell_matrix=supercell_matrix) eigvec = np.zeros(15) mode_dict = { 'R2_m_O1': perovskite_mode.R2p, 'R3_m_O1': perovskite_mode. R12p_1, # R3-[O1:c:dsp]A2u(a), O JT inplane-stagger, out-of-plane antiphase 'R3_m_O2': perovskite_mode. R12p_2, # R3-[O1:c:dsp]A2u(b), O, out-of-plane-stagger, inplane antiphase 'R4_m_A1': perovskite_mode.R15_1, # R4-[Nd1:a:dsp]T1u(a), A 'R4_m_A2': perovskite_mode.R15_2, # R4-[Nd1:a:dsp]T1u(b), A 'R4_m_A3': perovskite_mode.R15_3, # R4-[Nd1:a:dsp]T1u(c), A 'R4_m_O1': perovskite_mode.R15_4, # R4-[O1:c:dsp]Eu(a), O 'R4_m_O2': perovskite_mode.R15_5, # R4-[O1:c:dsp]Eu(b), O 'R4_m_O3': perovskite_mode.R15_6, # R4-[O1:c:dsp]Eu(c), O 'R5_m_O1': perovskite_mode. R25_1, # R5-[O1:c:dsp]Eu(a), O, out-of-phase rotation a- 'R5_m_O2': perovskite_mode.R25_2, # R5-[O1:c:dsp]Eu(b), O, b- 'R5_m_O3': perovskite_mode. R25_3, # R5-[O1:c:dsp]Eu(c), O, c-. For Pnma. Do not use. #'X3_m_A1':perovskite_mode., # X3-[Nd1:a:dsp]T1u(a), What's this.. #'X3_m_O1':perovskite_mode., # X3-[O1:c:dsp]A2u(a) 'Z5_m_A1': perovskite_mode.Z5p_1, # [Nd1:a:dsp]T1u(a), A , Antiferro mode 'Z5_m_A2': perovskite_mode.Z5p_2, # [Nd1:a:dsp]T1u(b), A , save as above 'Z5_m_O1': perovskite_mode.Z5p_3, # [Nd1:a:dsp]T1u(b), O , same as above 'Z5_m_O2': perovskite_mode.Z5p_4, # [Nd1:a:dsp]T1u(b), O , same as above 'M2_p_O1': perovskite_mode.M3, # M2+[O1:c:dsp]Eu(a), O, In phase rotation 'M3_p_O1': perovskite_mode. M2, # M3+[O1:c:dsp]A2u(a), O, D-type JT inplane stagger 'M5_p_O1': perovskite_mode.M5_1, # M5+[O1:c:dsp]Eu(a), O, Out of phase tilting 'M5_p_O2': perovskite_mode. M5_2, # M5+[O1:c:dsp]Eu(b), O, Out of phase tilting, -above 'M4_p_O1': perovskite_mode. M4, # M4+[O1:c:dsp]A2u(a), O, in-plane-breathing (not in P21/c) } # add Gamma modes to mode_dict Gamma_mode_dict = Gamma_modes(atoms.get_chemical_symbols()) mode_dict.update(Gamma_mode_dict) mode_disps = {} qdict = { 'G': [0, 0, 0], #'X':[0,0.0,0.5], 'M': [0.5, 0.5, 0], 'R': [0.5, 0.5, 0.5], 'Z': [0.0, 0.0, 0.5] } disps = 0.0 #np.zeros(3,dtype='complex128') for name, amp in modes.items(): eigvec = np.array(mode_dict[name]) disp = dcell._get_displacements(eigvec=eigvec, q=qdict[name[0]], amplitude=amp, argument=0) disps += disp newcell = dcell._get_cell_with_modulation(disps) newcell = Atoms(newcell) print(spglib.get_spacegroup(newcell)) #vesta_view(newcell) return newcell
def get_primitive(input_file='POSCAR', input_format=None, output_file=None, output_format=None, threshold=1e-5, angle_tolerance=-1., verbose=False): if output_file is None: verbose = True if verbose: def vprint(*args): for arg in args: print(arg,) print("") else: def vprint(*args): pass try: if input_format is None: A = ase.io.read(input_file) else: A = ase.io.read(input_file, format=input_format) except IOError as e: raise Exception("I/O error({0}): {1}".format(e.errno, e.strerror)) vprint( "# Space group: ", str( spglib.get_spacegroup( A, symprec=threshold, angle_tolerance=angle_tolerance)), '\n') cell, positions, atomic_numbers = spglib.find_primitive( A, symprec=threshold, angle_tolerance=angle_tolerance) if positions is None: print("This space group doesn't have a more primitive unit cell.") else: vprint("Primitive cell vectors:") vprint(cell, '\n') vprint("Atomic positions and proton numbers:") for position, number in zip(positions, atomic_numbers): vprint(position, '\t', number) if output_file is None: pass else: atoms = ase.Atoms( scaled_positions=positions, cell=cell, numbers=atomic_numbers, pbc=True) if output_format is None: try: atoms.write(output_file, vasp5=True) except TypeError: atoms.write(output_file) elif output_format is "vasp": atoms.write(output_file, format="vasp", vasp5=True) else: atoms.write(output_file, format=output_format)
def get_primitive(input_file='POSCAR', input_format=None, output_file=None, output_format=None, threshold=1e-5, angle_tolerance=-1., verbose=False): if output_file is None: verbose = True if verbose: def vprint(*args): for arg in args: print(arg, ) print("") else: def vprint(*args): pass try: if input_format is None: A = ase.io.read(input_file) else: A = ase.io.read(input_file, format=input_format) except IOError as e: raise Exception("I/O error({0}): {1}".format(e.errno, e.strerror)) vprint( "# Space group: ", str( spglib.get_spacegroup(A, symprec=threshold, angle_tolerance=angle_tolerance)), '\n') cell, positions, atomic_numbers = spglib.find_primitive( A, symprec=threshold, angle_tolerance=angle_tolerance) if positions is None: print("This space group doesn't have a more primitive unit cell.") else: vprint("Primitive cell vectors:") vprint(cell, '\n') vprint("Atomic positions and proton numbers:") for position, number in zip(positions, atomic_numbers): vprint(position, '\t', number) if output_file is None: pass else: atoms = ase.Atoms(scaled_positions=positions, cell=cell, numbers=atomic_numbers, pbc=True) if output_format is None: try: atoms.write(output_file, vasp5=True) except TypeError: atoms.write(output_file) elif output_format is "vasp": atoms.write(output_file, format="vasp", vasp5=True) else: atoms.write(output_file, format=output_format)
def view_spacegroup(filename='POSCAR', symprec=1e-3): atoms = read(filename) print("SPACEGROUP: %s" % spglib.get_spacegroup(atoms, symprec=symprec))
def gen_RNiO3(a=3.709, c=3.709, rot_R=1.0, rot_M=1.0, jt=0.0, br=0.00): atoms = gen_primitive(name='YNiO3', mag_order='PM', latticeconstant=3.7094) spos = atoms.get_scaled_positions() atoms.set_cell([a, a, c, 90, 90, 90]) atoms.set_scaled_positions(spos) from ase.io import write dcell = distorted_cell(atoms, supercell_matrix=np.eye(3) * 2) dcell = distorted_cell(atoms, supercell_matrix=[[1, -1, 0], [1, 1, 0], [0, 0, 2]]) eigvec = np.zeros(15) eigvec[6] = 1 eigvec[10] = 1 breathing = np.array(perovskite_mode.R2p) JT_d = np.array(perovskite_mode.M2) in_phase_tilting_A1 = np.array(perovskite_mode.X5p_1) in_phase_tilting_A2 = np.array(perovskite_mode.X5p_2) in_phase_tilting_O1 = np.array(perovskite_mode.X5p_3) in_phase_tilting_O2 = np.array(perovskite_mode.X5p_4) in_phase_rotation = np.array(perovskite_mode.M3) out_of_phase_rotation_x = np.array(perovskite_mode.R25_1) out_of_phase_rotation_y = np.array(perovskite_mode.R25_2) # R2- breathing 0.1 disp_br = dcell._get_displacements(eigvec=breathing, q=[0.5, 0.5, 0.5], amplitude=br, argument=0) #disp2=dcell._get_displacements(eigvec=out_of_phase_rotation,q=[0.5,0.5,0.5],amplitude=0.55,argument=0) # M3+ JT 0.1 disp_jt = dcell._get_displacements(eigvec=JT_d, q=[0.5, 0.5, 0.0], amplitude=jt, argument=0) #disp4=dcell._get_displacements(eigvec=in_phase_tilting,q=[0.0,0.5,0.0],amplitude=0.5,argument=0) # R5- rotation out 1.07 disp_rotx = dcell._get_displacements(eigvec=out_of_phase_rotation_x, q=[0.5, 0.5, 0.5], amplitude=1.07 * rot_R, argument=0) disp_roty = dcell._get_displacements(eigvec=out_of_phase_rotation_y, q=[0.5, 0.5, 0.5], amplitude=-1.07 * rot_R, argument=0) # M2+ disp_rot_zin = dcell._get_displacements(eigvec=in_phase_rotation, q=[0.5, 0.5, 0.0], amplitude=0.525 * 2 * rot_M, argument=0) #X5- disp_tilting_A1 = dcell._get_displacements(eigvec=in_phase_tilting_A1, q=[0.0, 0.0, 0.5], amplitude=-0.485 * 2, argument=0) #print disp_tilting_A1 disp_tilting_A2 = dcell._get_displacements(eigvec=in_phase_tilting_A2, q=[0.0, 0.0, 0.5], amplitude=0.485 * 2, argument=0) #print disp_tilting_A2 disp_tilting_O1 = dcell._get_displacements(eigvec=in_phase_tilting_O1, q=[0.0, 0.5, 0.0], amplitude=-0.168 * 2, argument=0) disp_tilting_O2 = dcell._get_displacements(eigvec=in_phase_tilting_O2, q=[0.0, 0.5, 0.0], amplitude=0.168 * 2, argument=0) #print disp.shape newcell = dcell._get_cell_with_modulation( disp_rotx + disp_roty + disp_rot_zin + disp_br + disp_jt ) # +disp_tilting_A1)#+disp_tilting_A2)#+disp_tilting_O1+disp_tilting_O2) print(spglib.get_spacegroup(newcell)) #vesta_view(newcell) return newcell
def read_DDB(self, fname=None, do_label=True, workdir=None, phonon_output_dipdip='phonon_band_dipdip.png', phonon_output_nodipdip='phonon_band_nodipdip.png'): """ read phonon related properties from DDB file. """ self.has_phonon = True ddb = abiopen(fname) self.ddb_header = ddb.header self.atoms = ddb.structure.to_ase_atoms() self.natoms = len(self.atoms) self.cellpar = self.atoms.get_cell_lengths_and_angles() self.cell = self.atoms.get_cell().flatten() self.masses = self.atoms.get_masses() self.scaled_positions = self.atoms.get_scaled_positions() self.chemical_symbols = self.atoms.get_chemical_symbols() self.spgroup_name = spglib.get_spacegroup(self.atoms, symprec=1e-4) self.ixc = self.ddb_header['ixc'] self.XC = ixc_to_xc(self.ixc) self.ispin = self.ddb_header['nsppol'] self.spinat = self.ddb_header['spinat'] self.nband = self.ddb_header['nband'] self.ecut = self.ddb_header['ecut'] self.tsmear = self.ddb_header['tsmear'] self.usepaw = self.ddb_header['usepaw'] self.pawecutdg = self.ddb_header['tsmear'] self.nsppol = self.ddb_header['nsppol'] self.nspden = self.ddb_header['nspden'] self.species = [ chemical_symbols[int(i)] for i in self.ddb_header['znucl'] ] self.zion = [int(x) for x in self.ddb_header['zion']] self.znucl = [int(x) for x in self.ddb_header['znucl']] emacror, becsr = ddb.anaget_emacro_and_becs() emacro = emacror[0].cartesian_tensor becs_array = becsr.values becs = {} for i, bec in enumerate(becs_array): becs[str(i)] = bec nqpts = ddb._guess_ngqpt() qpts = tuple(ddb.qpoints.frac_coords) self.emacro = emacro self.becs = becs self.nqpts = nqpts self.qpts = qpts for qpt in qpts: qpt = tuple(qpt) m = ddb.anaget_phmodes_at_qpoint(qpt) #self.results['phonon'][qpt]['frequencies'] = m.phfreqs #self.results['phonon'][qpt][ # 'eigen_displacements'] = m.phdispl_cart qpoints, evals, evecs, edisps = self.phonon_band( ddb, lo_to_splitting=False, phonon_output_dipdip=phonon_output_dipdip, phonon_output_nodipdip=phonon_output_nodipdip) #for i in range(15): # print(evecs[0, :, i]) self.special_qpts = { 'X': (0, 0.5, 0.0), 'M': (0.5, 0.5, 0), 'R': (0.5, 0.5, 0.5) } zb_modes = self.label_zone_boundary_all(qpoints, evals, evecs, label=do_label) for qname in self.special_qpts: self.phonon_mode_freqs[qname] = zb_modes[qname][0] self.phonon_mode_names[qname] = zb_modes[qname][1] self.phonon_mode_evecs[qname] = zb_modes[qname][2] Gmodes = self.label_Gamma_all(qpoints, evals, evecs, label=do_label) self.phonon_mode_freqs['Gamma'] = Gmodes[0] self.phonon_mode_names['Gamma'] = Gmodes[1] self.phonon_mode_evecs['Gamma'] = Gmodes[2]
#!/usr/bin/env python import ase.io.vasp as io from spglib import spglib from optparse import OptionParser parser = OptionParser() parser.add_option("-f", "--file", action="store", type="string", dest="file", default="POSCAR", help="Path to input file [default: ./POSCAR]") parser.add_option("-p", "--prec", action="store", type="float", dest="prec", default=0.001, help="Precision for symmetry test [default: 0.001]") (options, args) = parser.parse_args() bulk = io.read_vasp(options.file) spacegroup = spglib.get_spacegroup(bulk, symprec=options.prec) print "Spacegroup information." print "-----------------------" print spacegroup print "-----------------------"