def get_final_properties(self, path): outputfile = get_final_abinit_out(path) if outputfile is None: raise ValueError("Not such dir: %s" % path) # Reading the OUTPUT abo = AbinitOutput(outputfile) dmatpawu = abo.get_dmatpawu() odmatpawu = np.array(dmatpawu).reshape(-1, self.ndim, self.ndim) oparams = dmatpawu2params(odmatpawu, self.ndim) if not abo.is_finished: print('This output is not finished') return None, None data = abo.get_energetics() nres2 = data['nres2'][-1] etot = data['etot'][-1] final_properties = None if etot is not None and oparams is not None: final_properties = { 'etot': etot, 'nres2': nres2, 'final_dmat': gs(oparams) } return final_properties, etot
def set_final_dmat(self, entry_id, abinitout): abo = AbinitOutput(abinitout) if not abo.is_finished: return None dmatpawu = abo.get_dmatpawu() if dmatpawu is None: return None odmatpawu = np.array(dmatpawu).reshape(-1, self.ndim, self.ndim) oparams = dmatpawu2params(odmatpawu, self.ndim) data = abo.get_energetics() if data is None: return None nres2 = data['nres2'][-1] etot = data['etot'][-1] if not np.all( np.sum(oparams['occupations'], axis=1) == np.array( self.num_electrons_dftu)): print( 'ERROR: Inconsistent number of DFT+U electrons for correlated orbitals: %s' % entry_id) print('From the population : %s ' % self.num_electrons_dftu) print('From %20s : %s ' % (abinitout, oparams['occupations'])) return self.pcdb.db.pychemia_entries.update({'_id': entry_id}, { '$set': { 'properties.etot': etot, 'properties.nres2': nres2, 'properties.final_dmat': gs(oparams) } })
def get_final_properties(self, path): outputfile = get_final_abinit_out(path) if outputfile is None: raise ValueError("Not such dir: %s" % path) # Reading the OUTPUT abo = AbinitOutput(outputfile) dmatpawu = abo.get_dmatpawu() odmatpawu = np.array(dmatpawu).reshape(-1, self.ndim, self.ndim) oparams = dmatpawu2params(odmatpawu, self.ndim) if not abo.is_finished: print('This output is not finished') return None, None data = abo.get_energetics() nres2 = data['nres2'][-1] etot = data['etot'][-1] final_properties = None if etot is not None and oparams is not None: final_properties = {'etot': etot, 'nres2': nres2, 'final_dmat': gs(oparams)} return final_properties, etot
def set_final_dmat(self, entry_id, abinitout): abo = AbinitOutput(abinitout) if not abo.is_finished: return None dmatpawu = abo.get_dmatpawu() if dmatpawu is None: return None odmatpawu = np.array(dmatpawu).reshape(-1, self.ndim, self.ndim) oparams = dmatpawu2params(odmatpawu, self.ndim) data = abo.get_energetics() if data is None: return None nres2 = data['nres2'][-1] etot = data['etot'][-1] if not np.all(np.sum(oparams['occupations'], axis=1) == np.array(self.num_electrons_dftu)): print('ERROR: Inconsistent number of DFT+U electrons for correlated orbitals: %s' % entry_id) print('From the population : %s ' % self.num_electrons_dftu) print('From %20s : %s ' % (abinitout, oparams['occupations'])) return self.pcdb.db.pychemia_entries.update({'_id': entry_id}, {'$set': {'properties.etot': etot, 'properties.nres2': nres2, 'properties.final_dmat': gs(oparams)}})
def get_final_abinit_out(path): if not os.path.isdir(path): raise ValueError("ERROR: Could not find folder: %s" % path) outputfile = None abos = [x for x in os.listdir(path) if x[-3:] in ['txt', 'out']] if len(abos) == 0: raise ValueError( "ERROR: Not suitable ABINIT output files were found ('*out' or '*txt') for path: %s" % path) # Most recent mtime mtime = 0 for ifile in abos: fpath = path + os.sep + ifile if os.path.getmtime(fpath) > mtime: abo = AbinitOutput(fpath) if abo.is_loaded and abo.is_finished: mtime = os.path.getmtime(fpath) outputfile = fpath if outputfile is None: print("WARNING: Could not find any good ABINIT output file: %s" % path) return outputfile
def evaluator(self, pbs_settings, basedir): print("Population size: %d" % len(self)) while True: # 1. Get actives no evaluated ane = self.actives_no_evaluated if len(ane) > 0: print("Candidates to be evaluated: %d" % len(ane)) else: print("No candidates to be evaluated") # 2. Get jobs in queue if 'user' not in pbs_settings: raise ValueError( "PBS settings must contain a keys 'user', 'ppn' and 'walltime'" ) username = pbs_settings['user'] jobs = get_jobs(username) jobnames = [jobs[x]['Job_Name'] for x in jobs] print("There are %d jobs in the system for user %s " % (len(jobnames), username)) check = False for entry_id in ane: if str(entry_id) not in jobnames: check = True else: jobids = [ jobs[x]['Job_Id'] for x in jobs if jobs[x]['Job_Name'] == str(entry_id) ] for jobid in jobids: check = True if jobs[jobid]['job_state'] != 'C': check = False break to_submit = False if check: to_submit = True if not os.path.isdir(basedir + os.sep + str(entry_id)): self.prepare_folder(entry_id, workdir=basedir, source_dir=basedir) elif os.path.isfile(basedir + os.sep + str(entry_id) + os.sep + 'COMPLETE'): abinitout = get_final_abinit_out(basedir + os.sep + str(entry_id)) if abinitout is not None: abo = AbinitOutput(abinitout) # check if finished if abo.is_finished: # Collect results self.collect(entry_id, basedir) to_submit = False if to_submit: self.submit(entry_id, basedir, pbs_settings) print('Sleeping for 20 minutes') time.sleep(1200)
def evaluator(self, username, basedir, queue, walltime, ppn, features=None): while True: # 1. Get actives no evaluated ane = self.actives_no_evaluated if len(ane) > 0: print("Candidates to be evaluated: %d" % len(ane)) else: print("No candidates to be evaluated") # 2. Get jobs in queue jobs = get_jobs(username) jobnames = [jobs[x]['Job_Name'] for x in jobs] check = False for entry_id in ane: if str(entry_id) not in jobnames: check = True else: jobids = [ jobs[x]['Job_Id'] for x in jobs if jobs[x]['Job_Name'] == str(entry_id) ] for jobid in jobids: check = True if jobs[jobid]['job_state'] != 'C': check = False break to_submit = False if check: to_submit = True if not os.path.isdir(basedir + os.sep + str(entry_id)): self.prepare_folder(entry_id, workdir=basedir, source_dir=basedir) elif os.path.isfile(basedir + os.sep + str(entry_id) + os.sep + 'COMPLETE'): abinitout = self.get_final_abinit_out(basedir + os.sep + str(entry_id)) if abinitout is not None: abo = AbinitOutput(abinitout) # check if finished if abo.is_finished: # Collect results self.collect(entry_id, basedir) to_submit = False if to_submit: self.submit(entry_id, basedir, queue, walltime, ppn, features) print('Sleeping for 10 minutes') time.sleep(600)
def collect_data(self, entry_id, workdir, filename='abinit.out'): if os.path.isfile(workdir + os.sep + filename): abo = AbinitOutput(workdir + os.sep + filename) dmatpawu = abo.get_dmatpawu() dmat = dmatpawu2params(dmatpawu, self.ndim) if 'etot' in abo.get_energetics(): etot = abo.get_energetics()['etot'][-1] nres2 = abo.get_energetics()['nres2'][-1] print('Uploading energy data for %s' % entry_id) self.set_final_results(entry_id, dmat, etot, nres2) return True else: return False else: return False
def collect_data(self, entry_id, workdir, filename='abinit.out'): if os.path.isfile(workdir + os.sep + filename): ao = AbinitOutput(workdir + os.sep + filename) dmatpawu = get_final_dmatpawu(workdir + os.sep + filename) dmat = dmatpawu2params(dmatpawu, self.ndim) if 'etot' in ao.get_energetics(): etot = ao.get_energetics()['etot'][-1] nres2 = ao.get_energetics()['nres2'][-1] print('Uploading energy data for %s' % entry_id) self.set_final_results(entry_id, dmat, etot, nres2) return True else: return False else: return False
def check_status(basepath): dirs = [x for x in os.listdir(basepath) if os.path.isdir(basepath + os.sep + x) and os.path.isfile(basepath + os.sep + x + os.sep + 'abinit.in')] print("%-40s %15s %15s %4s" % ("ABINIT output", "ETOT", 'nres2', 'nSCF')) for i in dirs: path = basepath + os.sep + i abinitout = get_final_abinit_out(path) if abinitout is None: continue abo = AbinitOutput(abinitout) if not abo.is_finished: continue try: nres2 = abo.get_energetics()['nres2'][-1] etot = abo.get_energetics()['etot'][-1] nscf = len(abo.get_energetics()['etot']) print("%-40s %15.6f %15.6e %4d" % (abinitout, etot, nres2, nscf)) except: print("ERROR: Could not get final energetics from %s" % abinitout)
def compare_params(path): if not os.path.isfile(path + os.sep + 'abinit.in'): print('ERROR: No abinit.in found at %s' % path) return # For making easier to see the values np.set_printoptions(linewidth=200, suppress=True) # Reading the INPUT abi = AbinitInput(path + os.sep + 'abinit.in') if 'lpawu' not in abi.variables: raise ValueError("Variable lpawu not found") ndim = 2 * max(abi['lpawu']) + 1 idmatpawu = np.array(abi['dmatpawu']).reshape(-1, ndim, ndim) iparams = dmatpawu2params(idmatpawu, ndim) # Reading the OUTPUT abinitout = get_final_abinit_out(path) abo = AbinitOutput(abinitout) dmatpawu = abo.get_final_dmatpawu() odmatpawu = np.array(dmatpawu).reshape(-1, ndim, ndim) oparams = dmatpawu2params(odmatpawu, ndim) print('DMATPAWU') print('input') print(idmatpawu) print('output') print(odmatpawu) print('PARAMETRIC REPRESENTATION found at %s' % abinitout) for i in sorted(list(iparams.keys())): print(i) print('input') print(iparams[i]) print('output') print(i) print(oparams[i]) abo = AbinitOutput(abinitout) if not abo.is_finished: print('This output is not finished') try: nres2 = abo.get_energetics()['nres2'][-1] etot = abo.get_energetics()['etot'][-1] nscf = len(abo.get_energetics()['etot']) print("%30s ETOT: %15.6f NRES2: %15.6e NumSCF: %3d" % (path, etot, nres2, nscf)) except: print("ERROR: Could not get energetics from %s" % abinitout)
def check_status(basepath): dirs = [ x for x in os.listdir(basepath) if os.path.isdir(basepath + os.sep + x) and os.path.isfile(basepath + os.sep + x + os.sep + 'abinit.in') ] print("%-40s %15s %15s %4s" % ("ABINIT output", "ETOT", 'nres2', 'nSCF')) for i in dirs: path = basepath + os.sep + i abinitout = get_final_abinit_out(path) if abinitout is None: continue abo = AbinitOutput(abinitout) if not abo.is_finished: continue try: nres2 = abo.get_energetics()['nres2'][-1] etot = abo.get_energetics()['etot'][-1] nscf = len(abo.get_energetics()['etot']) print("%-40s %15.6f %15.6e %4d" % (abinitout, etot, nres2, nscf)) except: print("ERROR: Could not get final energetics from %s" % abinitout)
print("Renaming abinit.err") os.rename('abinit.err', 'abinit_%02d.err' % index) if os.path.isfile('abinit-o_WFK'): print("Renaming abinit-o_WFK") os.rename('abinit-o_WFK', 'abinit-i_WFK') if os.path.isfile('abinit.out'): print("Renaming abinit.out") shutil.copy2('abinit.out', 'abinit_%02d.txt' % index) os.rename('abinit.out', 'abinit_%02d.out' % index) abiout = 'abinit_%02d.out' % index else: print("Could not find abinit.out") # Opening the output file print("Reading the output from 'abinit.out'...") abo = AbinitOutput(abiout) if not abo.is_finished: print( "abinit.out is truncated, discarting that output redoing the calculation" ) continue # The final density matrix is build from the outputi ndim = 2 * max(abi['lpawu']) + 1 params = dmatpawu2params(abi['dmatpawu'], ndim) print("Euler angles from 'abinit.in':") for i in params['euler_angles']: for j in i: print(" %7.3f" % j, end=' ') print("\n", end='')
def plot_status(basepath): dirs = [ x for x in os.listdir(basepath) if os.path.isdir(basepath + os.sep + x) and os.path.isfile(basepath + os.sep + x + os.sep + 'abinit.in') ] abi = AbinitInput(basepath + os.sep + 'abinit.in') nstep = abi['nstep'] print('Plotting Status...') xx = {} yy = {} # Get the data: max_nruns = 0 for path in dirs: xx[path] = np.array([]) yy[path] = {} yy[path]['nres2'] = np.array([]) yy[path]['etot'] = np.array([]) yy[path]['delta'] = np.array([]) for i in range(100): if os.path.isfile(basepath + os.sep + path + os.sep + 'abinit_%02d.txt' % i): abo = AbinitOutput(basepath + os.sep + path + os.sep + 'abinit_%02d.txt' % i) if not abo.is_finished: print('This output is not finished') continue if max_nruns < i: max_nruns = i try: energ = abo.get_energetics() except: raise RuntimeError("Failed procesing: %s" % (basepath + os.sep + path + os.sep + 'abinit_%02d.txt' % i)) nres2 = energ['nres2'][-1] etot = energ['etot'][-1] nscf = len(energ['etot']) x = np.arange(nstep * i, nstep * i + len(energ['nres2'])) yetot = np.array(energ['etot']) ynres2 = np.array(energ['nres2']) ydelta = np.array(np.abs(energ['deltaEh'])) xx[path] = np.concatenate((xx[path], x)) yy[path]['etot'] = np.concatenate((yy[path]['etot'], yetot)) yy[path]['nres2'] = np.concatenate((yy[path]['nres2'], ynres2)) yy[path]['delta'] = np.concatenate((yy[path]['delta'], ydelta)) print("%s ETOT:%15.6f NRES2=%15.6e Num SCF=%3d" % (path, etot, nres2, nscf)) # RESIDUAL plt.figure(figsize=(8, 11)) miny = 1E-1 maxy = 1E-16 plt.subplots_adjust(left=0.1, bottom=0.05, right=0.99, top=0.99, wspace=None, hspace=None) for path in dirs: if len(xx) > 0: plt.semilogy(xx[path], yy[path]['nres2'], label=path[-4:], lw=0.1) if miny > min(yy[path]['nres2']): miny = min(yy[path]['nres2']) if maxy < max(yy[path]['nres2']): maxy = max(yy[path]['nres2']) plt.ylim(miny, maxy) for i in nstep * np.arange(max_nruns + 1): plt.semilogy([i, i], [miny, maxy], '0.5', lw=0.1) plt.xlim(0, max([max(xx[path]) for path in dirs])) plt.legend() plt.xlabel("SCF iteration") plt.ylabel("Density Residual$^2$") plt.savefig('Orbital_Residual.pdf') # ETOT miny = 1E6 maxy = -1E6 avg = 0 minlen = 100 plt.figure(figsize=(8, 11)) for path in dirs: if len(xx) > 0: plt.plot(xx[path], yy[path]['etot'], label=path[-4:]) if len(yy[path]['etot']) < minlen: minlen = len(yy[path]['etot']) avg = np.average(yy[path]['etot'][-int(minlen / 2):]) if miny > min(yy[path]['etot'][-int(minlen / 2):]): miny = min(yy[path]['etot'][-int(minlen / 2):]) if maxy < max(yy[path]['etot'][-int(minlen / 2):]): maxy = max(yy[path]['etot'][-int(minlen / 2):]) plt.subplots_adjust(left=0.15, bottom=0.05, right=0.95, top=0.95, wspace=None, hspace=None) newminy = miny - 0.1 * (maxy - miny) newmaxy = maxy + 0.1 * (maxy - miny) miny = newminy maxy = newmaxy plt.ylim(miny, maxy) for i in nstep * np.arange(max_nruns + 1): plt.plot([i, i], [miny, maxy], '0.5', lw=0.1) plt.xlim(0, max([max(xx[path]) for path in dirs])) plt.legend() plt.xlabel("SCF iteration") plt.ylabel("Energy") plt.savefig('Orbital_ETotal.pdf') # deltaEh plt.figure(figsize=(8, 11)) miny = 1E-1 for path in dirs: if len(xx) > 0: plt.semilogy(xx[path], yy[path]['delta'], label=path[-4:], lw=0.1) if miny > min(yy[path]['delta']): miny = min(yy[path]['delta']) plt.subplots_adjust(left=0.1, bottom=0.05, right=0.99, top=0.99, wspace=None, hspace=None) for i in nstep * np.arange(max_nruns + 1): plt.semilogy([i, i], [miny, 1E3], '0.5', lw=0.1) plt.ylim(miny, 1E3) plt.xlim(0, max([max(xx[path]) for path in dirs])) plt.legend() plt.xlabel("SCF iteration") plt.ylabel("Delta Energy") plt.savefig('Orbital_deltaEh.pdf')
def plot_status(basepath): dirs = [x for x in os.listdir(basepath) if os.path.isdir(basepath + os.sep + x) and os.path.isfile(basepath + os.sep + x + os.sep + 'abinit.in')] abi = AbinitInput(basepath + os.sep + 'abinit.in') nstep = abi['nstep'] print('Plotting Status...') xx = {} yy = {} # Get the data: max_nruns = 0 for path in dirs: xx[path] = np.array([]) yy[path] = {} yy[path]['nres2'] = np.array([]) yy[path]['etot'] = np.array([]) yy[path]['delta'] = np.array([]) for i in range(100): if os.path.isfile(basepath + os.sep + path + os.sep + 'abinit_%02d.txt' % i): abo = AbinitOutput(basepath + os.sep + path + os.sep + 'abinit_%02d.txt' % i) if not abo.is_finished: print('This output is not finished') continue if max_nruns < i: max_nruns = i try: energ = abo.get_energetics() except: raise RuntimeError( "Failed procesing: %s" % (basepath + os.sep + path + os.sep + 'abinit_%02d.txt' % i)) nres2 = energ['nres2'][-1] etot = energ['etot'][-1] nscf = len(energ['etot']) x = np.arange(nstep * i, nstep * i + len(energ['nres2'])) yetot = np.array(energ['etot']) ynres2 = np.array(energ['nres2']) ydelta = np.array(np.abs(energ['deltaEh'])) xx[path] = np.concatenate((xx[path], x)) yy[path]['etot'] = np.concatenate((yy[path]['etot'], yetot)) yy[path]['nres2'] = np.concatenate((yy[path]['nres2'], ynres2)) yy[path]['delta'] = np.concatenate((yy[path]['delta'], ydelta)) print("%s ETOT:%15.6f NRES2=%15.6e Num SCF=%3d" % (path, etot, nres2, nscf)) # RESIDUAL plt.figure(figsize=(8, 11)) miny = 1E-1 maxy = 1E-16 plt.subplots_adjust(left=0.1, bottom=0.05, right=0.99, top=0.99, wspace=None, hspace=None) for path in dirs: if len(xx) > 0: plt.semilogy(xx[path], yy[path]['nres2'], label=path[-4:], lw=0.1) if miny > min(yy[path]['nres2']): miny = min(yy[path]['nres2']) if maxy < max(yy[path]['nres2']): maxy = max(yy[path]['nres2']) plt.ylim(miny, maxy) for i in nstep * np.arange(max_nruns + 1): plt.semilogy([i, i], [miny, maxy], '0.5', lw=0.1) plt.xlim(0, max([max(xx[path]) for path in dirs])) plt.legend() plt.xlabel("SCF iteration") plt.ylabel("Density Residual$^2$") plt.savefig('Orbital_Residual.pdf') # ETOT miny = 1E6 maxy = -1E6 avg = 0 minlen = 100 plt.figure(figsize=(8, 11)) for path in dirs: if len(xx) > 0: plt.plot(xx[path], yy[path]['etot'], label=path[-4:]) if len(yy[path]['etot']) < minlen: minlen = len(yy[path]['etot']) avg = np.average(yy[path]['etot'][-int(minlen / 2):]) if miny > min(yy[path]['etot'][-int(minlen / 2):]): miny = min(yy[path]['etot'][-int(minlen / 2):]) if maxy < max(yy[path]['etot'][-int(minlen / 2):]): maxy = max(yy[path]['etot'][-int(minlen / 2):]) plt.subplots_adjust(left=0.15, bottom=0.05, right=0.95, top=0.95, wspace=None, hspace=None) newminy = miny - 0.1 * (maxy - miny) newmaxy = maxy + 0.1 * (maxy - miny) miny = newminy maxy = newmaxy plt.ylim(miny, maxy) for i in nstep * np.arange(max_nruns + 1): plt.plot([i, i], [miny, maxy], '0.5', lw=0.1) plt.xlim(0, max([max(xx[path]) for path in dirs])) plt.legend() plt.xlabel("SCF iteration") plt.ylabel("Energy") plt.savefig('Orbital_ETotal.pdf') # deltaEh plt.figure(figsize=(8, 11)) miny = 1E-1 for path in dirs: if len(xx) > 0: plt.semilogy(xx[path], yy[path]['delta'], label=path[-4:], lw=0.1) if miny > min(yy[path]['delta']): miny = min(yy[path]['delta']) plt.subplots_adjust(left=0.1, bottom=0.05, right=0.99, top=0.99, wspace=None, hspace=None) for i in nstep * np.arange(max_nruns + 1): plt.semilogy([i, i], [miny, 1E3], '0.5', lw=0.1) plt.ylim(miny, 1E3) plt.xlim(0, max([max(xx[path]) for path in dirs])) plt.legend() plt.xlabel("SCF iteration") plt.ylabel("Delta Energy") plt.savefig('Orbital_deltaEh.pdf')