def plot_all_pdos_s(element_types=None, filename='DOSCAR', ispin=2, ymin=-2.0, ymax=2.0, xmin=-15.0, xmax=5.0): """ plot the local dos of all atoms. """ symdict = get_symdict() if element_types is not None: atom_nums = [ x for x in list(symdict.keys()) if symnum_to_sym(x) in element_types ] if ispin == 2: sites = ['s+', 's-'] else: sites = ['s'] if not os.path.exists('PDOS'): os.mkdir('PDOS') for atom_num in atom_nums: copyfile(filename, 'PDOS/DOSCAR') plotldos_group([atom_num], sites, ymin=ymin, ymax=ymax, xmin=xmin, xmax=xmax, special_location=None, output='PDOS/%s_s_dos.png' % atom_num)
def write_all_octahedra_info(atoms,center_symbol_list,vertex_symbol,max_distance,output='octa_info.csv',axis_type=None,x=(1,0,0),y=(0,1,0),z=(0,0,1), var_distance=False): """ write all octahedra info into a file. """ symdict=symbol_number(atoms) myfile=open(output,'w') for symnum in symdict: sym=symnum_to_sym(symnum) print(sym) if sym in center_symbol_list: print(sym) this_oct=get_octahedron(atoms,symnum,vertex_symbol,max_distance,axis_type=axis_type,x=x,y=y,z=z,var_distance=var_distance) avg_rotations=this_oct.get_avg_rotations() bond_lengths=this_oct.get_bond_lengths() avg_bond_length=np.average(bond_lengths) distortion_factor=this_oct.get_distortion() vertex_angles=this_oct.get_vertex_angles(target_symbol_list=center_symbol_list) myfile.write('Info of %s :\n'%symnum) myfile.write("avg_rot: %s\n"%('\t'.join([str(a) for a in avg_rotations]))) myfile.write("avg_bond: %s\n"%avg_bond_length) myfile.write("distrotion factor: %s\n"%distortion_factor) myfile.write("vertex lengths: %s\n"%('\t'.join([str(a) for a in bond_lengths]))) myfile.write("vertex angles: %s\n\n"%('\t'.join([str(a) for a in list(vertex_angles.values())]))) myfile.close()
def plot_pdos(sites, lsites=None, element_types=None, filename='DOSCAR', ispin=2, ymin=-2.0, ymax=2.0, xmin=-15.0, xmax=5.0, output_dir='PDOS'): """ plot the local dos of all atoms. """ symdict = get_symdict() if element_types is not None: atom_nums = [ x for x in list(symdict.keys()) if symnum_to_sym(x) in element_types ] else: atom_nums = list(symdict.keys()) if sites == 'eg': if ispin == 2: lsites = ['dx2+', 'dz2+', 'dx2-', 'dz2-'] else: lsites = ['dx2', 'dz2'] elif sites == 't2g': if ispin == 2: lsites = ['dxy+', 'dyz+', 'dxz+', 'dxy-', 'dyz-', 'dxz-'] else: lsites = ['dxy', 'dyz', 'dxz'] elif sites == 'p': if ispin == 2: lsites = ['px+', 'py+', 'pz+', 'px-', 'py-', 'pz-'] else: lsites = ['px', 'py', 'pz'] elif sites == 's': if ispin == 2: lsites = ['s+', 's-'] else: lsites = ['s'] else: lsites = lsites if not os.path.exists(output_dir): os.mkdir(output_dir) for atom_num in atom_nums: copyfile(filename, join(output_dir, 'DOSCAR')) plotldos_group([atom_num], lsites, ymin=ymin, ymax=ymax, xmin=xmin, xmax=xmax, special_location=None, output=join(output_dir, '%s_%s_dos.png' % (atom_num, sites)))
def even_or_odd_path(atoms,from_symnum,node_sym_list,to_symnum_list=None,first_neighbor_min=2.5,first_neighbor_max=4.5): """ Find whether the distance of the atoms with symnum in to_list to the atom(from_symnum) is even or odd. The distance to the first neighbor is 1. The 1st neighbor's 1st neighbor is 2. etc.... Args: atoms: from_symnum to_sym_list: The symbol of the atoms, eg:['Fe','Ni' ], Note the from_symnum should be start with the symbol in this list to_symnum_list: The symbol_number of the atoms, eg:['Fe1','Fe2','Ni1'].Only one of the to_sym_list and to_symnum_list should should be specified. first_neighbor_min/max: The min/max distance to the first neighbor Returns: a dict. The values are 1/-1. 1 is odd, -1: even eg {'Fe1':1,'Ni1':-1} """ #1. Get the first neighbor list symdict=symbol_number(atoms) symnums=list(symdict.keys()) node_list=[] for s in symnums: #print s if symnum_to_sym(s) in node_sym_list: node_list.append(s) if not from_symnum in node_list: raise Exception('from_symnum should be of one of the nodes') positions=atoms.get_positions() node_positions=[positions[symdict[i]] for i in node_list] from scipy.sparse import csr_matrix N=len(node_list) #dmat=csr_matrix((N,N)) row=[] col=[] val=[] dist=lambda pos1,pos2 :np.linalg.norm(np.asarray(pos1)-np.asarray(pos2)) for i,pi in enumerate(node_positions): for j,pj in enumerate(node_positions): if i==j: row.append(i) col.append(j) val.append(0) else: #print pi,pj #print dist(pi,pj) if first_neighbor_min <dist(pi,pj)<first_neighbor_max: row.append(i) col.append(j) val.append(1) dmat=csr_matrix((val,(row,col)),shape=(N,N)) #print dmat from scipy.sparse.csgraph import dijkstra path_mat=dijkstra(dmat,directed=False,unweighted=True) i_node=node_list.index(from_symnum) def even_odd(x): if int(x)%2==0: return 1 else: return -1 return node_list,[even_odd(x) for x in path_mat[i_node]]
start = True text = '' if start: text += line if line.startswith('tot'): start = False return text def check_converge(filename='log'): """ check the log file to see if the calculation is converged. If converged, return the number of steps of iteration, else return False. """ nstep = 0 with open(filename) as myfile: for line in myfile: l = line try: nstep = int(line.strip().split()[0]) except Exception: pass if l.strip().startswith('writing'): return nstep else: return False if __name__ == '__main__': print(symnum_to_sym('1'))