def debye_find(self): hit = [] phases = [] count = [] for i in self.items: mm = i['metadata'] if mm in hit: count[hit.index(mm)] += 1 else: hit.append(mm) count.append(1) structure = Structure.from_dict(i['structure']) formula_pretty = structure.composition.reduced_formula try: formula2composition(formula_pretty) except: formula_pretty = reduced_formula( structure.composition.alphabetical_formula) sa = SpacegroupAnalyzer(structure) phasename = formula_pretty+'_'\ + sa.get_space_group_symbol().replace('/','.')+'_'+str(sa.get_space_group_number()) if phasename in phases: for jj in range(10000): nphasename = phasename + "#" + str(jj) if nphasename in phases: continue phasename = nphasename break phases.append(phasename) print("\nfound complete calculations in the collection:", self.qhamode, "\n") all_static_calculations = list((self.vasp_db).db['tasks'].\ find({'$and':[{'metadata': { "$exists": True }}, {'adopted': True} ]},\ {'metadata':1, 'output':1, 'input':1, 'orig_inputs':1})) for i, m in enumerate(hit): if self.skipby(phases[i], m['tag']): continue static_calculations = [ f for f in all_static_calculations if f['metadata']['tag'] == m['tag'] ] for ii, calc in enumerate(static_calculations): potsoc = get_used_pot(calc) if self.qhamode == 'qha': potsoc += "_debye" pname = phases[i].split('#') if len(pname) > 1: phases[i] = pname[0] + potsoc + '#' + pname[1] else: phases[i] = pname[0] + potsoc break print(m, ":", phases[i]) self.tags.append({'tag': m['tag'], 'phasename': phases[i]})
def debye_find(self): hit = [] phases = [] count = [] for i in self.items: """ try: ii = len(i['debye']) mm = i['metadata'] except: continue if ii < 6: continue """ mm = i['metadata'] if mm in hit: count[hit.index(mm)] += 1 else: hit.append(mm) count.append(1) structure = Structure.from_dict(i['structure']) formula_pretty = structure.composition.reduced_formula try: formula2composition(formula_pretty) except: formula_pretty = reduced_formula( structure.composition.alphabetical_formula) sa = SpacegroupAnalyzer(structure) phasename = formula_pretty+'_'\ + sa.get_space_group_symbol().replace('/','.')+'_'+str(sa.get_space_group_number()) if phasename in phases: for jj in range(10000): nphasename = phasename + "#" + str(jj) if nphasename in phases: continue phasename = nphasename break phases.append(phasename) print("\nfound complete calculations in the collection:", self.qhamode, "\n") for i, m in enumerate(hit): if self.skipby(phases[i], m['tag']): continue print(m, ":", phases[i]) self.tags.append({'tag': m['tag'], 'phasename': phases[i]})
def check_find(self): """ hit = [] relaxations_collection = (self.vasp_db).db['relaxations'].find({}) for i in relaxations_collection: try: mm = i['metadata']['tag'] hit.append(mm) except: continue lastupdated = [None] * len(hit) for i,mm in enumerate(hit): static_calc = (self.vasp_db).collection.\ find({'$and':[ {'metadata.tag': mm} ]}) for calc in static_calc: lnew = calc['last_updated'] if lastupdated[i]!=None: lold = lastupdated[i] if lnew > lold: lastupdated[i] = lnew else: lastupdated[i] = lnew """ print( "\nfinding tags for complete calculations in the static collection\n" ) hit = [] lastupdated = [] static_collection = (self.vasp_db).collection.find({}) for i in static_collection: try: mm = i['metadata']['tag'] except: continue if mm in hit: idx = hit.index(mm) lold = lastupdated[idx] lnew = i['last_updated'] if lnew > lold: lastupdated[idx] = lnew else: lastupdated.append(i['last_updated']) hit.append(mm) print("\nfinding complete calculations in the phonon collection\n") phases = [""] * len(hit) supercellsize = [0] * len(hit) phonon_count = [0] * len(hit) #phonon_calc = (self.vasp_db).db['phonon'].find({},{'metadata':1}) phonon_calc = list((self.vasp_db).db['phonon'].find({"S_vib": { "$exists": True } },\ {'metadata':1, 'unitcell':1, 'supercell_matrix':1})) for i, mm in enumerate(hit): #print ('eeeeeeeeee', mm) #phonon_calc = (self.vasp_db).db['phonon'].\ # find({'$and':[ {'metadata.tag': mm} ]}) for calc in phonon_calc: if calc['metadata']['tag'] != mm: continue #print (calc['metadata']['tag']) phonon_count[i] += 1 if phonon_count[i] == 1: structure = Structure.from_dict(calc['unitcell']) natoms = len(structure.sites) supercell_matrix = calc['supercell_matrix'] supercellsize[i] = ( natoms * int(np.linalg.det(np.array(supercell_matrix)) + .5)) formula_pretty = structure.composition.reduced_formula try: formula2composition(formula_pretty) except: formula_pretty = reduced_formula( structure.composition.alphabetical_formula) sa = SpacegroupAnalyzer(structure) phasename = formula_pretty+'_'\ + sa.get_space_group_symbol().replace('/','.')+'_'+str(sa.get_space_group_number()) if phasename in phases: for jj in range(10000): nphasename = phasename + "#" + str(jj) if nphasename in phases: continue phasename = nphasename break phases[i] = phasename print("\nfinding complete calculations in the static collection\n") static_count = [0] * len(hit) for i, mm in enumerate(hit): if self.skipby(phases[i], mm): continue static_calc = (self.vasp_db).collection.\ find({'$and':[ {'metadata.tag': mm} ]}) for calc in static_calc: static_count[i] += 1 print("\nfinding complete calculations in the qha collection\n") qha_count = [0] * len(hit) for i, mm in enumerate(hit): qha_calc = (self.vasp_db).db['qha'].\ find({'$and':[ {'metadata.tag': mm} ]}) for calc in qha_calc: qha_count[i] += 1 print("\nfinding complete calculations in the qha_phonon collection\n") qha_phonon_count = [0] * len(hit) for i, mm in enumerate(hit): try: qha_phonon_calculations = self.vasp_db.db['qha_phonon'].find( {'metadata.tag': mm}) T = qha_phonon_calculations[0]['phonon']['temperatures'] qha_phonon_count[i] += 1 except: try: qha_phonon_calculations = self.vasp_db.db['qha'].find( {'metadata.tag': mm}) T = qha_phonon_calculations[0]['phonon']['temperatures'] qha_phonon_count[i] += 1 except: pass print( "\nfinding complete calculations in the relaxations collection\n") relaxations_count = [0] * len(hit) for i, mm in enumerate(hit): relaxations_calc = (self.vasp_db).db['relaxations'].\ find({'$and':[ {'metadata.tag': mm} ]}) for calc in relaxations_calc: relaxations_count[i] += 1 nTBD = 0 for i, mm in enumerate(hit): #dd = datetime.datetime.strptime(lastupdated[i], '%Y-%m-%d %H:%M:%S.%f').date() dd = lastupdated[i].date() now = datetime.datetime.now().date() #if supercellsize[i]>=16 and phonon_count[i]>=5: continue if supercellsize[i] >= self.supercellN and phonon_count[ i] >= self.nV: continue if dd > now - datetime.timedelta(days=7): continue nTBD += 1 sys.stdout.write( '[{:>04}] relax: {:>2}, static: {:>2}, qha: {:>2}, qha_phonon: {:>2}, phonon: {:>2}, SN: {:>3}, phases: {}, {}\n' .format(i, relaxations_count[i], static_count[i], qha_count[i], qha_phonon_count[i], phonon_count[i], supercellsize[i], phases[i], dd)) #sys.stdout.write('{}, static: {:>2}, qha: {:>2}, qha_phonon: {:>2}, phonon: {:>2}, SN: {:>3}, phases: {}, date: {}\n'.format(mm['tag'], static_count[i], qha_count[i], qha_phonon_count[i], phonon_count[i], supercellsize[i], phases[i], lastupdated[i])) self.tags.append({'tag': mm, 'phasename': phases[i]}) print("\n", nTBD, "/", len(hit), "recs to be removed\n") for t in self.tags: print(t)
def phonon_find(self): hit = [] count = [] phases = [] volumes = [] ITEMS = [] self.supercellsize = [] for i in self.items: """ try: ii = len(i['S_vib']) mm = i['metadata'] except: continue if ii <= 0: continue """ mm = i['metadata'] if mm in hit: if i['volume'] not in volumes[hit.index(mm)]: volumes[hit.index(mm)].append(i['volume']) count[hit.index(mm)] += 1 else: ITEMS.append(i) hit.append(mm) count.append(1) volumes.append([i['volume']]) structure = Structure.from_dict(i['unitcell']) natoms = len(structure.sites) supercell_matrix = i['supercell_matrix'] self.supercellsize.append( natoms * int(np.linalg.det(np.array(supercell_matrix)) + .5)) formula_pretty = structure.composition.reduced_formula try: formula2composition(formula_pretty) except: formula_pretty = reduced_formula( structure.composition.alphabetical_formula) sa = SpacegroupAnalyzer(structure) phasename = formula_pretty+'_'\ + sa.get_space_group_symbol().replace('/','.')+'_'+str(sa.get_space_group_number()) if phasename in phases: for jj in range(10000): nphasename = phasename + "#" + str(jj) if nphasename in phases: continue phasename = nphasename break phases.append(phasename) print("\nfound complete calculations in the collection:", self.qhamode, "\n") total = 0 total_qha_phonon = 0 all_static_calculations = list((self.vasp_db).db['tasks'].\ find({'$and':[{'metadata': { "$exists": True }}, {'adopted': True} ]},\ {'metadata':1, 'output':1, 'input':1, 'orig_inputs':1})) all_qha_calculations = list((self.vasp_db).db['qha'].\ find({'$and':[{'metadata': { "$exists": True }},{'has_phonon':True}]}, {'metadata':1, 'temperatures':1})) all_qha_phonon_calculations = list((self.vasp_db).db['qha_phonon'].\ find({'$and':[{'metadata': { "$exists": True }},{'has_phonon':True}]}, {'metadata':1, 'temperatures':1})) for i, m in enumerate(hit): if self.skipby(phases[i], m['tag']): continue total += 1 static_calculations = [ f for f in all_static_calculations if f['metadata']['tag'] == m['tag'] ] qha_calculations = [ f for f in all_qha_calculations if f['metadata']['tag'] == m['tag'] ] qha_phonon_calculations = [ f for f in all_qha_phonon_calculations if f['metadata']['tag'] == m['tag'] ] qha_phonon_success = True if len(qha_calculations) > 0: total_qha_phonon += 1 elif len(qha_phonon_calculations) > 0: total_qha_phonon += 1 else: qha_phonon_success = False nS = 0 gapfound = False potsoc = "" for calc in static_calculations: vol = calc['output']['structure']['lattice']['volume'] if potsoc == "": pot = calc['input']['pseudo_potential'][ 'functional'].upper() if pot == "": pot = calc['orig_inputs']['potcar'][ 'functional'].upper() if pot == 'Perdew-Zunger81'.upper(): pot = "LDA" try: pot += "+" + calc['input']['incar']['GGA'] except: pass if calc['input']['is_hubbard']: pot += '+U' try: if calc['input']['incar']['LSORBIT']: potsoc = pot + "+SOC" except: potsoc = pot pname = phases[i].split('#') if len(pname) > 1: phases[i] = pname[0] + potsoc + '#' + pname[1] else: phases[i] = pname[0] + potsoc nS += 1 bandgap = calc['output']['bandgap'] if not gapfound: gapfound = float(bandgap) > 0.0 #print("eeeeeeee", self.findbandgap) if self.findbandgap: #if gapfound: print ("eeeeee", gapfound, bandgap, phases[i]) if gapfound: sys.stdout.write( '{}, phonon: {:>2}, static: {:>2}, supercellsize: {:>3}, {}\n' .format(m, count[i], nS, self.supercellsize[i], phases[i])) else: if count[i] < self.nV: continue if self.supercellsize[i] < self.supercellN: continue jobpath = findjobdir(self.jobpath, m['tag']) if jobpath == None: sys.stdout.write('{}, phonon: {:>2}, static: {:>2}, SN: {:>3}, qha_phonon: {:<1.1s}, {}\n'\ .format(m, count[i], nS, self.supercellsize[i], str(qha_phonon_success), phases[i])) else: sys.stdout.write('{}, phonon: {:>2}, static: {:>2}, SN: {:>3}, qha_phonon: {:<1.1s}, {},{}\n'\ .format(m, count[i], nS, self.supercellsize[i], str(qha_phonon_success), phases[i],jobpath)) #if count[i]>=5: self.tags.append({'tag':m['tag'],'phasename':phases[i]}) if count[i] >= self.nV: self.tags.append({'tag': m['tag'], 'phasename': phases[i]}) sys.stdout.write ('\n{}/{} qha_phonon successful under the given searching conditions.\n'\ .format(total_qha_phonon, total))
def EV_find(self): evdirhome = 'E-V' if not os.path.exists(evdirhome): os.mkdir(evdirhome) hit = [] count = [] phases = [] volumes = [] ITEMS = [] potname = [] fp_ev = open(os.path.join(evdirhome, "E-V.dat"), "w") for i in self.items: mm = i['metadata']['tag'] els = i['elements'] if self.skipby("", mm, els=els): continue if self.hit_condition is not None: if mm not in self.hit_condition: continue if mm in hit: volume = i['output']['structure']['lattice']['volume'] if volume not in volumes[hit.index(mm)]: volumes[hit.index(mm)].append(volume) count[hit.index(mm)] += 1 else: ITEMS.append(i) hit.append(mm) count.append(1) volumes.append([i['output']['structure']['lattice']['volume']]) potsoc = get_used_pot(i) structure = Structure.from_dict(i['output']['structure']) formula_pretty = structure.composition.reduced_formula try: formula2composition(formula_pretty) except: formula_pretty = reduced_formula( structure.composition.alphabetical_formula) sa = SpacegroupAnalyzer(structure) phasename = formula_pretty+'_'\ + sa.get_space_group_symbol().replace('/','.')+'_'+str(sa.get_space_group_number()) potname.append(potsoc) if phasename in phases: for jj in range(10000): nphasename = phasename + "#" + str(jj) if nphasename in phases: continue phasename = nphasename break phases.append(phasename) blank_lines = False for i, mm in enumerate(hit): if self.hit_condition is not None: if mm not in self.hit_condition: continue if self.qhamode == 'phonon': if self.hit_count[mm] < self.nV: continue if count[i] < self.nV: continue if self.skipby(phases[i], mm): continue EV, POSCAR, INCAR = get_rec_from_metatag(self.vasp_db, mm) metadata = {'tag': mm} pname = phases[i].split('#') if len(pname) > 1: phases[i] = pname[0] + potname[i] + EV[ 'MagState'] + '#' + pname[1] else: phases[i] = pname[0] + potname[i] + EV['MagState'] if EV['natoms'] < self.natoms: continue sys.stdout.write('{}, static: {:>2}, natoms: {:>3}, {}\n'.format( metadata, count[i], EV['natoms'], phases[i])) folder = os.path.join(evdirhome, phases[i]) if not os.path.exists(folder): os.mkdir(folder) with open(os.path.join(folder, 'POSCAR'), 'w') as fp: fp.write(POSCAR) readme = {} readme['E-V'] = EV readme['INCAR'] = INCAR readme['POSCAR'] = POSCAR natoms = readme['E-V']['natoms'] with open(os.path.join(folder, 'readme'), 'w') as fp: myjsonout(readme, fp, indent="", comma="") i_energies = np.array(EV['energies']) / natoms i_volumes = np.array(EV['volumes']) / natoms val, idx = min((val, idx) for (idx, val) in enumerate(i_energies)) if blank_lines: print("\n", file=fp_ev) blank_lines = True print("#phase:", phases[i], file=fp_ev) print("#metadata:", mm, file=fp_ev) print("#natoms:", natoms, file=fp_ev) elist = ['Fe', 'Cu', 'Se', 'Al', 'Ni', 'Co', 'Pt', 'Ta', 'O'] el = [] nel = [] if len(EV['magmoms']) > 0: fp_ev.write("#magmoms:") magmoms = EV['magmoms'][idx] m0 = magmoms[0] n0 = 1 for j in range(1, len(magmoms)): if magmoms[j] == m0: n0 += 1 else: if n0 == 1: fp_ev.write('{},'.format(m0)) else: fp_ev.write('{}*{},'.format(n0, m0)) idx = len(el) % len(elist) el.append(elist[idx]) nel.append(n0) n0 = 1 m0 = magmoms[j] if n0 == 1: fp_ev.write('{}\n'.format(m0)) else: fp_ev.write('{}*{}\n'.format(n0, m0)) idx = len(el) % len(elist) el.append(elist[idx]) nel.append(n0) lines = [l for l in POSCAR.split('\n') if l != ""] with open(os.path.join(folder, phases[i] + '.VASP'), 'w') as fp: for j in range(0, 5): print(lines[j], file=fp) for j in range(len(el)): fp.write(' {}'.format(el[j])) fp.write('\n') for j in range(len(nel)): fp.write(' {}'.format(nel[j])) fp.write('\n') print(lines[7], file=fp) for j in range(8, len(lines)): print(lines[j], float(list(magmoms[j - 8].values())[0]), file=fp) for j in range(len(i_volumes)): print(i_volumes[j], i_energies[j], file=fp_ev) thermoplot(folder, "0 K total energies (eV/atom)", i_volumes, i_energies)
def ext_thelec(args, plotfiles=None, vasp_db=None): global no_MongoDB print ("Postprocess for thermodynamic properties, Seebeck, Lorenz number etc. Yi Wang\n") """ Postprocess for thermodynamic properties, Seebeck, Lorenz number etc Parameters STR_FOLDER = args.STRUCTURE_FOLDER folder/file containing structures MATCH_PATTERN = args.MATCH_PATTERN Match patterns for structure file, e.g. *POSCAR RECURSIVE = args.RECURSIVE recursive or not WORKFLOW = args.WORKFLOW workflow, current only get_wf_gibbs LAUNCH = args.LAUNCH Launch to lpad or not MAX_JOB = args.MAX_JOB Max job to submit SETTINGS = args.SETTINGS Settings file WRITE_OUT_WF = args.WRITE_OUT_WF Write out wf file or not """ t0 = args.t0 t1 = args.t1 td = args.td xdn = args.xdn xup = args.xup ndosmx = args.ndosmx natom = args.natom gaussian = args.gaussian dope = args.dope doscar = args.doscar outf = args.outf qhamode = args.qhamode eqmode = args.eqmode elmode = args.elmode metatag = args.metatag everyT = args.everyT noel = args.noel smooth = args.smooth expt = args.expt xlim = args.xlim if abs(dope)<5.e-9: ndosmx = max(100001, int(ndosmx)) gaussian = max(10000., float(gaussian)) formula = None if args.local != "": print("\nRun using local data\n") readme = {} record_cmd(readme) proc = thelecMDB(t0, t1, td, xdn, xup, dope, ndosmx, gaussian, natom, outf, noel=noel, qhamode=qhamode, eqmode=eqmode, elmode=elmode, smooth=smooth, debug=args.debug, phasename=args.local, pyphon=True, renew=args.renew, fitF=args.fitF, args=args) volumes, energies, thermofile, comments = proc.run_console() if comments!=None: readme.update(comments) else: return if "ERROR" in readme.keys(): record_cmd_print(thermofile, readme, dir=args.phasename) return print("\nFull thermodynamic properties have outputed into:", thermofile) #print(args.plot, "eeeeeeeee", volumes, energies, thermofile, comments) if args.plot==None: print("\nSupply '-plot phasename' for plot\n") else: from dfttk.analysis.ywplot import plotAPI #print("xxxxxxx",proc.get_formula()) if plotAPI(readme, thermofile, volumes, energies, expt=expt, xlim=xlim, _fitCp=args.SGTEfitCp, formula = proc.get_formula(), debug=args.debug, plotlabel=args.plot, local=args.local): #print ("xxxxxxx",proc.get_formula()) vtof = proc.get_free_energy_for_plot(readme) if vtof is not None: plotAPI(readme, thermofile, volumes, energies, expt=expt, xlim=xlim, _fitCp=args.SGTEfitCp, formula = proc.get_formula(), vtof=vtof, plotlabel=args.plot) """ """ #print("xxxxxxxxxxxx",readme) record_cmd_print(thermofile, readme) elif no_MongoDB: print("\n*********WARNING: CANNOT get MongoDB service, so I will proceed using local data") print("*********WARNING: CANNOT get MongoDB service, so I will proceed using local data") print("*********WARNING: CANNOT get MongoDB service, so I will proceed using local data\n") elif not args.plotonly: #if True: try: if vasp_db is None: db_file = loadfn(config_to_dict()["FWORKER_LOC"])["env"]["db_file"] vasp_db = VaspCalcDb.from_db_file(db_file, admin=False) static_calculations = vasp_db.collection.\ find({'$and':[ {'metadata.tag': metatag}, {'adopted': True} ]}) structure = Structure.from_dict(static_calculations[0]['output']['structure']) formula = reduced_formula(structure.composition.alphabetical_formula) except: no_MongoDB = True print("\n*********WARNING: CANNOT get MongoDB service, so I will proceed using local data") print("*********WARNING: CANNOT get MongoDB service, so I will proceed using local data") print("*********WARNING: CANNOT get MongoDB service, so I will proceed using local data\n") """ """ #call API if args.plotonly and plotfiles!=None: metatag, thermofile, volumes, energies, dir, formula = plotfiles sys.stdout.write('Processing {}, dir: {}, formula: {}\n'.format(metatag, dir, formula)) #print(thermofile, volumes, energies, formula) #print(thermofile, dir, formula) readme={} from dfttk.analysis.ywplot import plotAPI plotAPI(readme, thermofile, None, energies, expt=expt, xlim=xlim, _fitCp=args.SGTEfitCp, formula = formula, vtof=None, plotlabel=args.plot) elif vasp_db==None and plotfiles!=None: metatag, thermofile, volumes, energies, dir, formula = plotfiles sys.stdout.write('Processing {}, dir: {}, formula: {}\n'.format(metatag, dir, formula)) #print("xxxxxxxxxx", plotfiles) if expt!=None: _t1 = get_melting_temperature(expt, formula) if _t1!=None: t1 = _t1 readme = {} record_cmd(readme) proc = thelecMDB(t0, t1, td, xdn, xup, dope, ndosmx, gaussian, natom, outf, vasp_db=vasp_db, noel=noel, metatag=metatag, qhamode=qhamode, eqmode=eqmode, elmode=elmode, everyT=everyT, smooth=smooth, debug=args.debug, phasename=dir, pyphon=args.pyphon, renew=args.renew, fitF=args.fitF, args=args) volumes, energies, thermofile, comments = proc.run_console() #print ("xxxxxxx", comments) if comments!=None: readme.update(comments) else: return if "ERROR" in readme.keys(): #record_cmd_print(thermofile, readme, dir=args.phasename) return print("\nFull thermodynamic properties have outputed into:", thermofile) #print(args.plot, "eeeeeeeee", volumes, energies, thermofile, comments) if args.plot==None: print("\nSupply '-plot phasename' for plot\n") else: from dfttk.analysis.ywplot import plotAPI if plotAPI(readme, thermofile, volumes, energies, expt=expt, xlim=xlim, _fitCp=args.SGTEfitCp, formula = proc.get_formula(), debug=args.debug, plotlabel=args.plot): vtof = proc.get_free_energy_for_plot(readme) if vtof is not None: plotAPI(readme, thermofile, volumes, energies, expt=expt, xlim=xlim, _fitCp=args.SGTEfitCp, formula = proc.get_formula(), vtof=vtof, plotlabel=args.plot) """ """ record_cmd_print(thermofile, readme) elif metatag != None: if expt!=None: _t1 = get_melting_temperature(expt, formula) if _t1!=None: t1 = _t1 readme = {} record_cmd(readme) proc = thelecMDB(t0, t1, td, xdn, xup, dope, ndosmx, gaussian, natom, outf, vasp_db=vasp_db, noel=noel, metatag=metatag, qhamode=qhamode, eqmode=eqmode, elmode=elmode, everyT=everyT, smooth=smooth, debug=args.debug, phasename=args.phasename, pyphon=args.pyphon, renew=args.renew, fitF=args.fitF, args=args) volumes, energies, thermofile, comments = proc.run_console() if comments!=None: readme.update(comments) else: return if "ERROR" in readme.keys(): record_cmd_print(thermofile, readme, dir=args.phasename) return print("\nFull thermodynamic properties have outputed into:", thermofile) #print(args.plot, "eeeeeeeee", volumes, energies, thermofile, comments) if args.plot==None: print("\nSupply '-plot phasename' for plot\n") else: from dfttk.analysis.ywplot import plotAPI if plotAPI(readme, thermofile, volumes, energies, expt=expt, xlim=xlim, _fitCp=args.SGTEfitCp, formula = proc.get_formula(), debug=args.debug, plotlabel=args.plot): vtof = proc.get_free_energy_for_plot(readme) if vtof is not None: plotAPI(readme, thermofile, volumes, energies, expt=expt, xlim=xlim, _fitCp=args.SGTEfitCp, formula = proc.get_formula(), vtof=vtof, plotlabel=args.plot) """ """ record_cmd_print(thermofile, readme) elif args.vdos is not None: readme = {} record_cmd(readme) proc = thelecMDB(t0, t1, td, xdn, xup, dope, ndosmx, gaussian, natom, outf, renew=True, args=args) thermofile, comments, natoms = proc.run_single() if thermofile is None: return readme.update(comments) #record_cmd(thermofile, readme) print("\nFull thermodynamic properties have outputed into:", thermofile) if args.plot!=None: from dfttk.analysis.ywplot import plotAPI if plotAPI(readme, thermofile, None, None, expt=expt, xlim=xlim, _fitCp=args.SGTEfitCp, formula = proc.get_formula(), debug=args.debug, poscar=args.poscar,vdos=args.vdos, doscar=args.doscar, natoms=natoms, plotlabel=args.plot): record_cmd_print(thermofile, readme) elif args.local == "": pythelec.thelecAPI(t0, t1, td, xdn, xup, dope, ndosmx, gaussian, natom, outf, doscar)
def EV_find(self): hit = [] count = [] phases = [] volumes = [] ITEMS = [] for i in self.items: try: mm = i['metadata']['tag'] except: continue if mm in hit: volume = i['output']['structure']['lattice']['volume'] if volume not in volumes[hit.index(mm)]: volumes[hit.index(mm)].append(volume) count[hit.index(mm)] += 1 #if mm=='5252ccc3-e8da-499f-bb9e-9cf7eb1c5370': print("eeeeeeeee",mm, pot) else: ITEMS.append(i) hit.append(mm) count.append(1) volumes.append([i['output']['structure']['lattice']['volume']]) pot = i['input']['pseudo_potential']['functional'].upper() #if mm=='5252ccc3-e8da-499f-bb9e-9cf7eb1c5370': print("eeeeeeeee",mm, pot) if pot == "": pot = i['orig_inputs']['potcar']['functional'].upper() if pot == 'Perdew-Zunger81'.upper(): pot = "LDA" try: pot += "+" + i['input']['GGA'] except: pass if i['input']['is_hubbard']: pot += '+U' try: if i['input']['incar']['LSORBIT']: potsoc = pot + "SOC" except: potsoc = pot structure = Structure.from_dict(i['output']['structure']) natoms = len(structure.sites) formula_pretty = structure.composition.reduced_formula try: formula2composition(formula_pretty) except: formula_pretty = reduced_formula( structure.composition.alphabetical_formula) sa = SpacegroupAnalyzer(structure) phasename = formula_pretty+'_'\ + sa.get_space_group_symbol().replace('/','.')+'_'+str(sa.get_space_group_number())+potsoc if phasename in phases: for jj in range(10000): nphasename = phasename + "#" + str(jj) if nphasename in phases: continue phasename = nphasename break phases.append(phasename) for i, m in enumerate(hit): if count[i] < self.nV: continue if self.skipby(phases[i]): continue sys.stdout.write('{}, static: {:>2}, {}\n'.format( m, count[i], phases[i])) EV, POSCAR, INCAR = get_rec_from_metatag(self.vasp_db, m) evdir = './E-V/' if not os.path.exists(evdir): os.mkdir(evdir) folder = evdir + phases[i] if not os.path.exists(folder): os.mkdir(folder) with open(folder + '/POSCAR', 'w') as fp: fp.write(POSCAR) readme = {} readme['E-V'] = EV readme['INCAR'] = INCAR readme['POSCAR'] = POSCAR with open(folder + '/readme', 'w') as fp: myjsonout(readme, fp, indent="", comma="") thermoplot(folder, "0 K total energies (eV/atom)", EV['volumes'], EV['energies'])
def qha_renew(self): hit = [] phases = [] static_collection = (self.vasp_db).collection.find({'$and':[{'metadata': { "$exists": True }}, \ {'adopted': True} ]}) for i in static_collection: mm = i['metadata'] if mm in hit: continue if len(mm) > 1: continue else: hit.append(mm) structure = Structure.from_dict(i['output']['structure']) formula_pretty = structure.composition.reduced_formula try: formula2composition(formula_pretty) except: formula_pretty = reduced_formula( structure.composition.alphabetical_formula) sa = SpacegroupAnalyzer(structure) phasename = formula_pretty+'_'\ + sa.get_space_group_symbol().replace('/','.')+'_'+str(sa.get_space_group_number()) if phasename in phases: for jj in range(10000): nphasename = phasename + "#" + str(jj) if nphasename in phases: continue phasename = nphasename break phases.append(phasename) print("\nfound complete calculations in the task collection:\n") total = 0 total_qha = 0 total_qha_phonon = 0 all_static_calculations = list((self.vasp_db).db['tasks'].\ find({'$and':[{'metadata': { "$exists": True }}, {'adopted': True} ]},\ {'metadata':1, 'output':1, 'input':1, 'orig_inputs':1})) all_qha_calculations = list((self.vasp_db).db['qha'].\ find({'$and':[{'metadata': { "$exists": True }},{'has_phonon':True}]}, {'metadata':1, 'temperatures':1})) all_qha_phonon_calculations = list((self.vasp_db).db['qha_phonon'].\ find({'$and':[{'metadata': { "$exists": True }},{'has_phonon':True}]}, {'metadata':1, 'temperatures':1})) for i, m in enumerate(hit): if self.skipby(phases[i], m['tag']): continue total += 1 static_calculations = [ f for f in all_static_calculations if f['metadata']['tag'] == m['tag'] ] qha_calculations = [ f for f in all_qha_calculations if f['metadata']['tag'] == m['tag'] ] qha_phonon_calculations = [ f for f in all_qha_phonon_calculations if f['metadata']['tag'] == m['tag'] ] qha_phonon_success = len(qha_phonon_calculations) > 0 if qha_phonon_success: total_qha_phonon += 1 if len(qha_calculations) > 0 or qha_phonon_success: total_qha += 1 potsoc = None volumes = [] energies = [] for ii, calc in enumerate(static_calculations): vol = calc['output']['structure']['lattice']['volume'] if vol in volumes: if len(calc['metadata']) > 1: continue else: ix = volumes.index(vol) volumes.pop(ix) energies.pop(ix) volumes.append( calc['output']['structure']['lattice']['volume']) energies.append(calc['output']['energy']) if potsoc is None: potsoc = get_used_pot(calc) pname = phases[i].split('#') if len(pname) > 1: phases[i] = pname[0] + potsoc + '#' + pname[1] else: phases[i] = pname[0] + potsoc nS = len(volumes) if nS < 6: continue if qha_phonon_success and not self.db_renew: continue energies = sort_x_by_y(energies, volumes) volumes = sorted(volumes) volumes = np.array(volumes) energies = np.array(energies) val, idx = min((val, idx) for (idx, val) in enumerate(energies)) if idx < 2 or idx > nS - 2: continue jobpath = findjobdir(self.jobpath, m['tag']) if jobpath == None: sys.stdout.write('{}, static: {:>2}, qha_phonon: {:<1.1s}, {}\n'\ .format(m, nS, str(qha_phonon_success), phases[i])) else: sys.stdout.write('{}, static: {:>2}, qha_phonon: {:<1.1s}, {},{}\n'\ .format(m, nS, str(qha_phonon_success), phases[i],jobpath)) self.tags.append({'tag': m['tag'], 'phasename': phases[i]}) sys.stdout.write ('\n({},{})/{} (qha, qha_phonon) entries returned under the given searching conditions.\n'\ .format(total_qha, total_qha_phonon, total))
def phonon_find(self): hit = [] count = [] phases = [] volumes = [] ITEMS = [] self.supercellsize = [] for i in self.items: mm = i['metadata'] if mm in hit: if i['volume'] not in volumes[hit.index(mm)]: volumes[hit.index(mm)].append(i['volume']) count[hit.index(mm)] += 1 else: ITEMS.append(i) hit.append(mm) count.append(1) volumes.append([i['volume']]) structure = Structure.from_dict(i['unitcell']) natoms = len(structure.sites) supercell_matrix = i['supercell_matrix'] self.supercellsize.append( natoms * int(np.linalg.det(np.array(supercell_matrix)) + .5)) formula_pretty = structure.composition.reduced_formula try: formula2composition(formula_pretty) except: formula_pretty = reduced_formula( structure.composition.alphabetical_formula) sa = SpacegroupAnalyzer(structure) phasename = formula_pretty+'_'\ + sa.get_space_group_symbol().replace('/','.')+'_'+str(sa.get_space_group_number()) if phasename in phases: for jj in range(10000): nphasename = phasename + "#" + str(jj) if nphasename in phases: continue phasename = nphasename break phases.append(phasename) print("\nfound complete calculations in the collection:", self.qhamode, "\n") total = 0 total_qha_phonon = 0 all_static_calculations = list((self.vasp_db).db['tasks'].\ find({'$and':[{'metadata': { "$exists": True }}, {'adopted': True} ]},\ {'metadata':1, 'output':1, 'input':1, 'orig_inputs':1})) all_qha_calculations = list((self.vasp_db).db['qha'].\ find({'$and':[{'metadata': { "$exists": True }},{'has_phonon':True}]}, {'metadata':1, 'temperatures':1})) all_qha_phonon_calculations = list((self.vasp_db).db['qha_phonon'].\ find({'$and':[{'metadata': { "$exists": True }},{'has_phonon':True}]}, {'metadata':1, 'temperatures':1})) for i, m in enumerate(hit): if self.skipby(phases[i], m['tag']): continue total += 1 static_calculations = [ f for f in all_static_calculations if f['metadata']['tag'] == m['tag'] ] qha_calculations = [ f for f in all_qha_calculations if f['metadata']['tag'] == m['tag'] ] qha_phonon_calculations = [ f for f in all_qha_phonon_calculations if f['metadata']['tag'] == m['tag'] ] """ static_calculations = [f for f in all_static_calculations if f['metadata']==m] qha_calculations = [f for f in all_qha_calculations if f['metadata']==m] qha_phonon_calculations = [f for f in all_qha_phonon_calculations if f['metadata']==m] """ qha_phonon_success = True if len(qha_calculations) > 0: total_qha_phonon += 1 elif len(qha_phonon_calculations) > 0: total_qha_phonon += 1 else: qha_phonon_success = False gapfound = False potsoc = None _volumes = [] emin = 1.e36 for ii, calc in enumerate(static_calculations): vol = calc['output']['structure']['lattice']['volume'] ene = calc['output']['energy'] if ene < emin: _calc = calc if vol not in _volumes: _volumes.append(vol) bandgap = calc['output']['bandgap'] if not gapfound: gapfound = float(bandgap) > 0.0 potsoc = get_used_pot(_calc) Mag_State = get_Magnetic_State(_calc) pname = phases[i].split('#') if len(pname) > 1: phases[i] = pname[0] + potsoc + Mag_State + '#' + pname[1] else: phases[i] = pname[0] + potsoc + Mag_State nS = len(_volumes) if self.findbandgap: if gapfound: sys.stdout.write( '{}, phonon: {:>2}, static: {:>2}, supercellsize: {:>3}, {}\n' .format(m, count[i], nS, self.supercellsize[i], phases[i])) else: if count[i] < self.nV: continue if self.db_repair: if qha_phonon_success and not self.db_renew: continue if self.supercellsize[i] < self.supercellN: continue jobpath = findjobdir(self.jobpath, m['tag']) if self.remove: sys.stdout.write('dfttk db_remove --force -m all -tag {} phonon: {:>2}, static: {:>2}, SN: {:>3}, qha_phonon: {:<1.1s}, {}\n'\ .format(m['tag'], count[i], nS, self.supercellsize[i], str(qha_phonon_success), phases[i])) elif jobpath == None: sys.stdout.write('{}, phonon: {:>2}, static: {:>2}, SN: {:>3}, qha_phonon: {:<1.1s}, {}\n'\ .format(m, count[i], nS, self.supercellsize[i], str(qha_phonon_success), phases[i])) else: sys.stdout.write('{}, phonon: {:>2}, static: {:>2}, SN: {:>3}, qha_phonon: {:<1.1s}, {},{}\n'\ .format(m, count[i], nS, self.supercellsize[i], str(qha_phonon_success), phases[i],jobpath)) #if count[i]>=5: self.tags.append({'tag':m['tag'],'phasename':phases[i]}) self.tags.append({'tag': m['tag'], 'phasename': phases[i]}) #print(sorted(volumes[i])) sys.stdout.write ('\n{}/{} qha_phonon successful under the given searching conditions.\n'\ .format(total_qha_phonon, total))