def get_nebout_structures(): """ Extract structures from NEB results in the current directory. There must be: * neb.dat * pw_X.in, where X=(1,...,N) and N is the number of images. * pw.crd in which the final coordinates are written. """ from ase.atoms import Atoms fnebdat = 'neb.dat' fpwin = 'pw_1.in' fcrd = 'pw.crd' num_images = get_num_images(fnebdat) natm, cell, elems, pos, cell_unit, pos_unit = read_espresso_in(fpwin) list_pos = get_images(fcrd, natm, num_images) list_atoms = [] for i in range(num_images): atoms = Atoms(symbols=elems, cell=cell, scaled_positions=list_pos[i], pbc=[1, 1, 1]) list_atoms.append(atoms) return list_atoms
def get_nebout_structures(): """ Extract structures from NEB results in the current directory. There must be: * neb.dat * pw_X.in, where X=(1,...,N) and N is the number of images. * pw.crd in which the final coordinates are written. """ from ase.atoms import Atoms fnebdat = 'neb.dat' fpwin = 'pw_1.in' fcrd = 'pw.crd' num_images = get_num_images(fnebdat) natm,cell,elems,pos,cell_unit,pos_unit = read_espresso_in(fpwin) list_pos = get_images(fcrd,natm,num_images) list_atoms = [] for i in range(num_images): atoms = Atoms(symbols=elems, cell=cell, scaled_positions=list_pos[i], pbc=[1,1,1]) list_atoms.append(atoms) return list_atoms
def read_espresso_out(fname,): """ Read cell info, atom coordinates, energy, forces from Quantum Espresso output. """ f= open(fname,'r') lines = f.readlines() f.close() il_cell = -1 il_spcs = -1 il_forces = -1 il_pos = -1 il_stress = -1 infname = None nspcs = None for il in range(len(lines)): if ' atomic species ' in lines[il]: il_spcs = il elif '! total energy' in lines[il]: erg = float(lines[il].split()[4]) elif 'Forces acting on atoms' in lines[il]: il_forces= il elif 'CELL_PARAMETERS' in lines[il]: il_cell = il elif 'ATOMIC_POSITIONS' in lines[il]: il_pos = il elif 'number of atoms/cell' in lines[il]: natm = int(lines[il].split()[4]) elif 'number of atomic types' in lines[il]: nspcs = int(lines[il].split()[5]) elif 'total stress' in lines[il]: il_stress = il if ' Reading input from ' in lines[il]: infname = lines[il].split()[3] # some checks if infname is None: raise IOError('No input file read...') try: natm_in,cell_in,elems_in,pos_in,cell_unit,pos_unit = read_espresso_in(infname) if natm_in != natm: raise ValueError('natm_in != natm; natm_in,natm=',natm_in,natm) except: #print('Error: {} !!!'.format(e.message)) raise if il_cell == -1 and cell_in is None: raise IOError('No cell info in {} and {}.'.format(fname,infname)) if il_spcs == -1: raise IOError('No species info in the output file.') if nspcs == None: raise IOError('No atoimc-type info in the output file.') # read atom species il= il_spcs +1 spcs = [] for isp in range(nspcs): l = lines[il+isp].split() spcs.append(l[0]) # read cell parameters if il_cell == -1: cell = cell_in else: il= il_cell cell = np.zeros((3,3),dtype=float) ixyz = 0 while True: il += 1 l = lines[il].split() if len(l) == 0: break cell[:,ixyz] = [ float(x) for x in l ] ixyz += 1 # read atom coordinates if il_pos == -1: pos = pos_in elems = elems_in else: elems = [] pos = np.zeros((natm,3),dtype=float) il = il_pos + 1 for ia in range(natm): l = lines[il+ia].split() elems.append(l[0]) pos[ia,:] = [ float(x) for x in l[1:4] ] # read forces frcs = np.zeros((natm,3),dtype=float) if il_forces != -1: il = il_forces +2 for ia in range(natm): l = lines[il+ia].split() frcs[ia,:] = [ float(x) for x in l[6:9] ] #...read stress stnsr = np.zeros((3,3),dtype=float) strs = np.zeros(6,dtype=float) if il_stress != -1: il = il_stress +1 for iil in range(3): l = lines[il+iil].split() stnsr[iil,:] = [ float(x) for x in l[3:6] ] #...Reduce to 6 components in GPa and opposite sign strs[0] = stnsr[0,0] *(-0.1) strs[1] = stnsr[1,1] *(-0.1) strs[2] = stnsr[2,2] *(-0.1) strs[3] = stnsr[1,2] *(-0.1) strs[4] = stnsr[0,2] *(-0.1) strs[5] = stnsr[0,1] *(-0.1) return natm,nspcs,spcs,cell,pos,elems,erg,frcs,pos_unit,strs