def PPCheck(xc, element, pp_file_str, **kwargs): if xc == 'lda': xc = 'pade' ne = qtk.n2ve(element) try: if 'dcacp' in kwargs and kwargs['dcacp']: pp_path = os.path.join(xc.upper(), "%s_DCACP_%s" %\ (element, xc.upper())) if element in qtk.setting.dcacp_dict: pp_path = pp_path + "_%s" % qtk.setting.dcacp_dict[element] pp_file = os.path.join(qtk.setting.cpmd_dcacp_url, pp_path) else: pp_path = os.path.join(xc, element + '-q' + str(qtk.n2ve(element))) pp_file = os.path.join(qtk.setting.cpmd_pp_url, pp_path) saved_pp_path = os.path.join(qtk.setting.cpmd_pp, pp_file_str) if not os.path.exists(saved_pp_path) \ and qtk.setting.download_pp: if pp_file: new_pp = os.path.join(qtk.setting.cpmd_pp, pp_file_str) pp_content = urllib2.urlopen(pp_file).read() qtk.report('PPCheck', 'pp file %s not found in %s, ' \ % (pp_file_str, qtk.setting.cpmd_pp) + \ 'but found on internet, download now...') new_pp_file = open(new_pp, 'w') new_pp_file.write(pp_content) new_pp_file.close() pp_file = new_pp return saved_pp_path except: qtk.warning('something wrong with pseudopotential')
def PPName(**kwargs): element = kwargs['element'].title() if 'vdw' in kwargs: PPvdw = '_dcacp_' else: PPvdw = '' if 'd_shell' in kwargs: nve = qtk.n2ve(element) + 10 else: nve = qtk.n2ve(element) PPStr = element + PPvdw + '_q%d_' % nve +\ self.setting['xc'].lower() + '.psp' return PPStr, element
def alchemyPP(xc, pp_file_str): pp_path = os.path.join(qtk.setting.cpmd_pp, pp_file_str) if not os.path.exists(pp_path): root, _ = os.path.splitext(pp_file_str) element_str = re.sub('_.*', '', root) fraction = float(re.sub('.*_', '', root)) / 100 element1 = re.sub('2.*', '', element_str) element2 = re.sub('.*2', '', element_str) str1 = element1 + "_q" + str(qtk.n2ve(element1)) +\ "_" + xc + '.psp' str2 = element2 + "_q" + str(qtk.n2ve(element2)) +\ "_" + xc + '.psp' pp1 = PP(PPCheck(xc, element1, str1)) pp2 = PP(PPCheck(xc, element2, str2)) pp = mutatePP(pp1, pp2, fraction) pp.write(pp_path)
def alchemyPP(xc, pp_file_str): pp_path = os.path.join(qtk.setting.cpmd_pp, pp_file_str) if not os.path.exists(pp_path): root, _ = os.path.splitext(pp_file_str) element_str = re.sub('_.*', '', root) fraction = float(re.sub('.*_', '', root))/100 element1 = re.sub('2.*', '', element_str) element2 = re.sub('.*2', '', element_str) str1 = element1 + "_q" + str(qtk.n2ve(element1)) +\ "_" + xc + '.psp' str2 = element2 + "_q" + str(qtk.n2ve(element2)) +\ "_" + xc + '.psp' pp1 = PP(PPCheck(xc, element1, str1)) pp2 = PP(PPCheck(xc, element2, str2)) pp = mutatePP(pp1, pp2, fraction) pp.write(pp_path)
def PPName(inp, mol, i, n): if 'vdw' in inp.setting\ and inp.setting['vdw'].lower == 'dcacp': PPvdw = '_dcacp_' else: PPvdw = '' element = mol.type_list[i].title() if 'valence_electrons' in inp.setting\ and element in inp.setting['valence_electrons']: nve = inp.setting['valence_electrons'][element] elif 'd_shell' in inp.setting\ and element in inp.setting['d_shell']: nve = qtk.n2ve(element) + 10 else: nve = qtk.n2ve(element) PPStr = element + PPvdw + '_q%d_' % nve +\ inp.setting['pp_theory'].lower() + '.psp' return PPStr
def PPCheck(xc, element, pp_file_str, **kwargs): ne = qtk.n2ve(element) try: pp_path = os.path.join(xc, element + '-q' + str(qtk.n2ve(element))) pp_file = os.path.join(qtk.setting.cpmd_pp_url, pp_path) saved_pp_path = os.path.join(qtk.setting.cpmd_pp, pp_file_str) if not os.path.exists(saved_pp_path) and qtk.setting.download_pp: if pp_file: new_pp = os.path.join(qtk.setting.cpmd_pp, pp_file_str) pp_content = urllib2.urlopen(pp_file).read() qtk.report('', 'pp file %s not found in %s. ' \ % (pp_file_str, qtk.setting.cpmd_pp) + \ 'but found in cp2k page, download now...') new_pp_file = open(new_pp, 'w') new_pp_file.write(pp_content) new_pp_file.close() pp_file = new_pp return saved_pp_path except: qtk.warning('something wrong with pseudopotential')
def PPCheck(xc, pp_theory, pp_path, element): theory_dict = { 'lda': 'pade', 'pbe0': 'pbe', 'pbesol': 'pbe', 'hse06': 'pbe', } name = '%s_%s_%s' % (element, xc, pp_theory) pp_file = os.path.join(pp_path, name) if not os.path.exists(pp_file) and qtk.setting.download_pp: if pp_theory != 'nlcc': if pp_theory in theory_dict.keys(): pp_theory = theory_dict[pp_theory] url_root = qtk.setting.bigdft_pp_url element_str = element + '-q%d' % qtk.n2ve(element) url = url_root + '%s/%s' % (pp_theory, element_str) page = False try: page = urllib2.urlopen(url).readlines() pattern = re.compile(r'^.*</*pre>.*$') pp_se = filter(pattern.match, page) pp_start = page.index(pp_se[0]) pp_end = page.index(pp_se[1]) page = page[pp_start:pp_end] page[0] = page[0].split('>')[-1] except: qtk.warning('something wrong with url:%s' % url) pp = ''.join(page) else: url = qtk.setting.bigdft_pp_nlcc_url page = urllib2.urlopen(url).readlines() string = filter(lambda x: '"psppar.%s' % element in x, page)[-1] index = page.index(string) + 2 pp = [] itr = 0 while '</pre>' not in page[index + itr] \ and index + itr < len(page)\ and itr < 20: pp.append(page[index + itr]) itr = itr + 1 pp = ''.join(pp) if pp: qtk.report('', 'pp file %s not found in %s.' %\ (name, pp_path) +\ ' But found in cp2k page, download now...') new_pp_file = open(pp_file, 'w') new_pp_file.write(pp) new_pp_file.close() return pp_file
def PPCheck(xc, pp_theory, pp_path, element): theory_dict = { 'lda': 'pade', } name = '%s_%s_%s' % (element, xc, pp_theory) pp_file = os.path.join(pp_path, name) if not os.path.exists(pp_file) and qtk.setting.download_pp: if pp_theory != 'nlcc': if pp_theory in theory_dict.keys(): pp_theory = theory_dict[pp_theory] url_root = qtk.setting.bigdft_pp_url element_str = element + '-q%d' % qtk.n2ve(element) url = url_root + '%s/%s' % (pp_theory, element_str) page = False try: page = urllib2.urlopen(url).readlines() pattern = re.compile(r'^.*</*pre>.*$') pp_se = filter(pattern.match, page) pp_start = page.index(pp_se[0]) pp_end = page.index(pp_se[1]) page = page[pp_start:pp_end] page[0] = page[0].split('>')[-1] except: qtk.warning('something wrong with url:%s' % url) pp = ''.join(page) else: url = qtk.setting.bigdft_pp_nlcc_url page = urllib2.urlopen(url).readlines() string = filter(lambda x: '"psppar.%s' % element in x, page)[-1] index = page.index(string) + 2 pp = [] itr = 0 while '</pre>' not in page[index + itr] \ and index + itr < len(page)\ and itr < 20: pp.append(page[index + itr]) itr = itr + 1 pp = ''.join(pp) if pp: qtk.report('', 'pp file %s not found in %s.' %\ (name, pp_path) +\ ' But found in cp2k page, download now...') new_pp_file = open(pp_file, 'w') new_pp_file.write(pp) new_pp_file.close() return pp_file
def PPCheck(xc, element, pp_file_str, **kwargs): ne = qtk.n2ve(element) saved_pp_path = os.path.join(qtk.setting.espresso_pp, pp_file_str) if not os.path.exists(saved_pp_path) and qtk.setting.download_pp: qtk.status("PPCheck", pp_file_str) url = os.path.join(qtk.setting.espresso_pp_url, pp_file_str) try: pp_content = urllib2.urlopen(url).read() qtk.report('', 'pp file %s not found in %s. ' \ % (pp_file_str, qtk.setting.espresso_pp) + \ 'but found in espresso page, download now...') new_pp_file = open(saved_pp_path, 'w') new_pp_file.write(pp_content) new_pp_file.close() except: qtk.warning('something wrong with pseudopotential')
def PPString(inp, mol, i, n, outFile): """ append PP file names to inp.pp_files """ alchemy = re.compile('^\w*2\w*_\d\d\d$') ppstr = re.sub('\*', '', mol.string[i]) dcacp_flag = False if ppstr: PPStr = '*' + ppstr pp_root, pp_ext = os.path.split(ppstr) if pp_ext != 'psp': PPStr = PPStr + '.psp' elif 'vdw' in inp.setting\ and inp.setting['vdw'].lower() == 'dcacp': # PPStr: Element_qve_dcacp_theory.psp PPStr = '*'+mol.type_list[i] + '_dcacp_' +\ inp.setting['pp_theory'].lower() + '.psp' dcacp_flag = True else: # PPStr: Element_qve_theory.psp element = mol.type_list[i] if 'valence_electrons' in inp.setting\ and element in inp.setting['valence_electrons']: nve = inp.setting['valence_electrons'][element] else: nve = qtk.n2ve(element) PPStr = '*'+mol.type_list[i] + '_q%d_' % nve +\ inp.setting['pp_theory'].lower() + '.psp' outFile.write(PPStr + '\n') pp_file_str = re.sub('\*', '', PPStr) xc = inp.setting['pp_theory'].lower() if not mol.string[i]: PPCheck(xc, mol.type_list[i].title(), pp_file_str, dcacp=dcacp_flag, pp_type = inp.setting['pp_type']) elif alchemy.match(mol.string[i]): alchemyPP(xc, pp_file_str) pp_file = os.path.join(qtk.setting.cpmd_pp, pp_file_str) if inp.setting['pp_type'].title() == 'Goedecker': lmax = 'F' outFile.write(' LMAX=%s\n %3d\n' % (lmax, n)) inp.pp_files.append(re.sub('\*', '', PPStr))
def ESP(self, coord=None, **kwargs): """ method for electron density Note: CUBE file is assumed to be orthorohmbic """ data = self.data grid = self.grid if 'molecule' not in kwargs: mol = self.molecule else: try: mol = copy.deepcopy(qtk.toMolecule(kwargs['molecule'])) except: qtk.exit("error when loading molecule:%s" % \ str(kwargs['molecule'])) N = mol.N Q = self.integrate() Z_sum = sum(mol.Z) ne_diff = abs(Q - Z_sum) ve_diff = abs(Q - mol.getValenceElectrons()) if min(ne_diff, ve_diff) > 1E-2: qtk.warning("charge not conserved... ESP is wrong!") qtk.warning("charge integrate to %.2f, " % Q + \ "while nuclear charge adds to %.2f" % Z_sum) if ve_diff < ne_diff: Z = [qtk.n2ve(qtk.Z2n(z)) for z in mol.Z] Z = np.array(Z).reshape(N, 1) else: Z = mol.Z.reshape(N, 1) structure = np.hstack([Z, mol.R * 1.889725989]) if coord is not None: x, y, z = np.array(coord) * 1.889725989 V = ESP_c.esp_point(grid, structure, data, x, y, z) return V else: qtk.warning("known issue: unidentifed memory leak") out = copy.deepcopy(self) out.molecule = mol out.data = np.nan_to_num( ESP_cube_c.esp_cube(grid, structure, data) ) return out
def ESP(self, coord=None, **kwargs): """ method for electron density Note: CUBE file is assumed to be orthorohmbic """ data = self.data grid = self.grid if 'molecule' not in kwargs: mol = self.molecule else: try: mol = copy.deepcopy(qtk.toMolecule(kwargs['molecule'])) except: qtk.exit("error when loading molecule:%s" % \ str(kwargs['molecule'])) N = mol.N Q = self.integrate() Z_sum = sum(mol.Z) ne_diff = abs(Q - Z_sum) ve_diff = abs(Q - mol.getValenceElectrons()) if min(ne_diff, ve_diff) > 1E-2: qtk.warning("charge not conserved... ESP is wrong!") qtk.warning("charge integrate to %.2f, " % Q + \ "while nuclear charge adds to %.2f" % Z_sum) if ve_diff < ne_diff: Z = [qtk.n2ve(qtk.Z2n(z)) for z in mol.Z] Z = np.array(Z).reshape(N, 1) else: Z = mol.Z.reshape(N, 1) structure = np.hstack([Z, mol.R * 1.889725989]) if coord is not None: x, y, z = np.array(coord) * 1.889725989 V = ESP_c.esp_point(grid, structure, data, x, y, z) return V else: qtk.warning("known issue: unidentifed memory leak") out = copy.deepcopy(self) out.molecule = mol out.data = np.nan_to_num(ESP_cube_c.esp_cube( grid, structure, data)) return out
def PPCheck(xc, element, pp_file_str, **kwargs): pp_file = None pp_content = None if xc == 'lda': xc = 'pade' elif xc == 'pbe0': xc = 'pbe' ne = qtk.n2ve(element) try: if 'dcacp' in kwargs and kwargs['dcacp']\ and element in qtk.setting.dcscp_list: pp_path = os.path.join(xc.upper(), "%s_DCACP_%s" %\ (element, xc.upper())) if element in qtk.setting.dcacp_dict: pp_path = pp_path + "_%s" % qtk.setting.dcacp_dict[element] #pp_file = os.path.join(qtk.setting.cpmd_dcacp_url, pp_path) else: pp_path = os.path.join(xc, element + '-q' + str(qtk.n2ve(element))) pp_file = os.path.join(qtk.setting.cpmd_pp_url, pp_path) saved_pp_path = os.path.join(qtk.setting.cpmd_pp, pp_file_str) if not os.path.exists(saved_pp_path) and qtk.setting.download_pp: new_pp = os.path.join(qtk.setting.cpmd_pp, pp_file_str) if 'dcacp' in kwargs and kwargs['dcacp']\ and element in qtk.setting.dcscp_list: root_list = filter(None, qtk.setting.cpmd_dcacp_url.split('/')) root = '//'.join(root_list[:2]) url = qtk.setting.cpmd_dcacp_url html = ''.join(urllib2.urlopen(url).readlines()) pp_links = BeautifulSoup(html).body.findAll( 'a', attrs={'class': 'table'} ) if kwargs['pp_type'].title() == 'Goedecker': pp_flag = r'/SG/' elif kwargs['pp_type'].upper() == 'MT': pp_flag = r'/MT/' pp_path = filter(lambda x: xc.upper() in x and pp_flag in x, [l['href'] for l in pp_links if l.text == element.title()]) pp_content = urllib2.urlopen(root + pp_path[0]).readlines() elif pp_file: pp_content = urllib2.urlopen(pp_file).readlines() pattern = re.compile(r'^.*</*pre>.*$') pp_se = filter(pattern.match, pp_content) pp_start = pp_content.index(pp_se[0]) pp_end = pp_content.index(pp_se[1]) pp_content = pp_content[pp_start:pp_end] pp_content[0] = pp_content[0].split('>')[-1] if pp_content: for i in range(len(pp_content)): pp_str = pp_content[i] pp_content[i] = pp_str.replace('&', '&') qtk.report('PPCheck', 'pp file %s not found in %s, ' \ % (pp_file_str, qtk.setting.cpmd_pp) + \ 'download now...') new_pp_file = open(new_pp, 'w') new_pp_file.write(''.join(pp_content)) new_pp_file.close() pp_file = new_pp return saved_pp_path except Exception as e: qtk.warning('something wrong with pseudopotential with error: '+\ str(e))
def writeInp(name=None, **setting): self.setting.update(setting) self.setting['no_molecule'] = False inp, molecule = \ super(PlanewaveInput, self).write(name, **self.setting) molecule.sort() type_index = molecule.index type_list = molecule.type_list self.pp_path = qtk.setting.bigdft_pp if 'pp_path' in self.setting: self.pp_path = self.setting['pp_path'] if 'pp_theory' not in self.setting: self.setting['pp_theory'] = self.setting['theory'] pp_files = [] typat = [] for a in range(len(type_index) - 1): start = type_index[a] end = type_index[a + 1] for i in range(end - start): typat.append(a + 1) for i in range(molecule.N): pp_file = 'psppar.' + molecule.type_list[i] pp_list = set([pp[1] for pp in pp_files]) if pp_file not in pp_list: pp_src = PPCheck(self.setting['theory'], self.setting['pp_theory'], self.pp_path, molecule.type_list[i]) pp_files.append([pp_src, pp_file]) ################## # scf section # ################## self.content['scf'] = odict() # restart check # if 'restart' in self.setting and self.setting['restart']\ and 'band_scan' not in self.setting\ and 'dos_mesh' not in self.setting: self.content['scf']['irdwfk'] = 1 self.content['scf']['getwfk'] = -1 if 'restart_density' in self.setting \ and self.setting['restart_density']\ and 'band_scan' not in self.setting\ and 'dos_mesh' not in self.setting: self.content['scf']['irdden'] = 1 self.content['scf']['getden'] = -1 if 'kmesh' not in self.setting: self.setting['kmesh'] = [1, 1, 1] if 'kshift' not in self.setting: self.setting['kshift'] = [0.0, 0.0, 0.0] # kpoints check # if 'kpoints' in self.setting: self.content['scf']['kptopt'] = 0 self.content['scf']['nkpt'] = len(self.setting['kpoints']) self.content['scf']['kpt'] = self.setting['kpoints'] else: if self.setting['full_kmesh']: self.content['scf']['kptopt'] = 3 self.content['scf']['ngkpt'] = self.setting['kmesh'] if len(np.array(self.setting['kshift']).shape) > 1: self.content['scf']['nshiftk'] = len( self.setting['kshift']) self.content['scf']['shiftk'] = self.setting['kshift'] nbnd = None if 'ks_states' in self.setting and self.setting['ks_states']: vs = int(round(molecule.getValenceElectrons() / 2.0)) nbnd = self.setting['ks_states'] + vs if 'd_shell' in self.setting: for a in molecule.type_list: if a in self.setting['d_shell'] and qtk.n2ve(a) < 10: nbnd += 5 if 'band_scan' not in self.setting \ and 'dos_mesh' not in self.setting: self.content['scf']['nband'] = nbnd # system setup # if molecule.charge != 0: self.content['scf']['charge='] = molecule.charge if molecule.multiplicity != 1: self.content['scf']['nsppol'] = 2 self.content['scf']['occopt'] = 7 if 'save_restart' not in self.setting \ or not self.setting['save_restart']: if 'restart' in self.setting and self.setting['restart']\ and ('band_scan' not in self.setting\ and 'dos_mesh' not in self.setting): self.content['scf']['prtwf'] = 0 #if 'wf_convergence' in self.setting: if 'band_scan' in self.setting\ or 'dos_mesh' in self.setting: if 'restart' not in self.setting\ or not self.setting['restart']: self.content['scf']['tolwfr'] = \ self.setting['wf_convergence'] else: self.content['scf']['tolwfr'] = \ self.setting['wf_convergence'] # clean up for the case of restart if 'restart' in self.setting and self.setting['restart']\ and ('band_scan' in self.setting or 'dos_mesh' in self.setting): keep_lst = [ 'nband', 'tolwfr', 'nstep', 'ecut', 'irdwfk', 'irdden', 'getwfk', 'getden', ] for key in self.content['scf'].iterkeys(): if key not in keep_lst and 'prt' not in key: self.content['scf'].pop(key) ###################### # additional setting # ###################### if 'abinit_setting' in self.setting: self.content['additional'] = odict([]) for item in self.setting['abinit_setting']: self.content['additional'][item] = ' ' def is_strnum(q): if isinstance(q, Number) or type(q) is str: return True else: return False ################# # bandstructure # ################# if 'band_scan' in self.setting and self.setting['band_scan']: if molecule.symmetry and molecule.symmetry.lower() == 'fcc': if 'kshift' not in self.setting: self.setting['kshift'] = [ [0.5, 0.5, 0.5], [0.5, 0.0, 0.0], [0.0, 0.5, 0.0], [0.0, 0.0, 0.5], ] bnds = self.setting['band_scan'] if len(bnds) != 2 \ or is_strnum(bnds[0]) \ or len(bnds[0]) != len(bnds[1]) - 1: qtk.exit('band_scan format: [lst_div, lst_coord]') bnd_content = odict([ ('iscf', -2), ('getden', -1), ('kptopt', -len(bnds[0])), ('tolwfr', self.setting['wf_convergence']), ('ndivk', bnds[0]), ('kptbounds', bnds[1]), ]) if nbnd: bnd_content['nband'] = nbnd if 'save_restart' not in self.setting \ or not self.setting['save_restart']: bnd_content['prtwf'] = 0 else: bnd_content['prtwf'] = 1 if 'save_density' not in self.setting \ or not self.setting['save_density']: bnd_content['prtden'] = 0 else: bnd_content['prtden'] = 1 if 'dos_mesh' in self.setting: bnd_content['prtden'] = 1 if 'restart' in self.setting and self.setting['restart']: bnd_content['irdden'] = 1 bnd_content['irdwfk'] = 1 bnd_content['getwfk'] = -1 self.content['band_scan'] = bnd_content ##################### # density of states # ##################### if 'dos_mesh' in self.setting and self.setting['dos_mesh']: dos_content = odict([ ('iscf', -3), ('ngkpt', self.setting['dos_mesh']), ('shiftk', [0.0, 0.0, 0.0]), ('tolwfr', self.setting['wf_convergence']), ('prtwf', 0), ]) if 'band_scan' in self.setting: dos_content['getden'] = -2 else: dos_content['getden'] = -1 if 'smearing' in self.setting: smr = self.setting['smearing'] smr_dict = { 'fermi': 3, 'marzari': 4, 'marzari_monotonic': 5, 'paxton': 6, 'gaussian': 7, } if smr in smr_dict: dos_content['occopt'] = smr_dict[smr] dos_content['prtdos'] = 1 else: qtk.warning("%s for occupation scheme not found" % smr) if nbnd: dos_content['nband'] = nbnd if 'save_restart' not in self.setting \ or not self.setting['save_restart']: dos_content['prtwf'] = 0 else: dos_content['prtwf'] = 1 if 'save_density' not in self.setting \ or not self.setting['save_density']: dos_content['prtden'] = 0 else: dos_content['prtden'] = 1 if 'restart' in self.setting and self.setting['restart']: dos_content['irdden'] = 1 dos_content['irdwfk'] = 1 dos_content['getwfk'] = -1 self.content['dos'] = dos_content ################ # cell section # ################ self.content['cell'] = odict([ ('ecut', float(self.setting['cutoff'] / 2.)), ('nstep', self.setting['scf_step']), ]) self.content['cell']['acell'] = '3*1.889726124993' self.celldm2lattice() if not molecule.symmetry: self.content['cell']['chkprim'] = 0 self.content['cell']['rprim'] = self.setting['lattice'] ################# # atoms section # ################# znucl = [] for a in range(len(type_index) - 1): symb = type_list[type_index[a]] znucl.append(int(qtk.n2Z(symb))) self.content['atoms'] = odict([ ('natom', molecule.N), ('ntypat', (len(type_index) - 1)), ('typat', typat), ('znucl', znucl), ]) if hasattr(molecule, 'scale') and molecule.scale: if hasattr(molecule, 'R_scale'): R_scale = molecule.R_scale.copy() for i in range(3): s = molecule.scale[i] if s > 0: R_scale[:, i] = R_scale[:, i] / s self.content['atoms']['xred'] = R_scale else: qtk.warning('R_scale not found but scale is set') self.content['atoms']['xangst'] = molecule.R else: self.content['atoms']['xangst'] = molecule.R ######################### # write content to file # ######################### datasets = 1 for key in ['band_scan', 'dos']: if key in self.content: datasets += 1 if self.setting['restart'] and datasets > 1: datasets -= 1 self.content['datasets']['ndtset'] = datasets inp.write('# abinit input generated by qctoolkit\n') ds_itr = 0 ds_str = '' if self.content['datasets']['ndtset'] == 1: self.content['datasets'].pop('ndtset') for section_key in self.content.iterkeys(): if len(self.content[section_key]) > 0: inp.write('\n# %s section\n' % section_key) if section_key in ['scf', 'band_scan', 'dos'] and datasets > 1: ds_itr += 1 ds_str = str(ds_itr) for key, value in self.content[section_key].iteritems(): if ds_str and section_key in ['scf', 'band_scan', 'dos']: key = key + ds_str if is_strnum(value): inp.write('%s %s\n' % (key, str(value))) else: inp.write('%s' % key) head = ''.join([' ' for _ in key]) if 'xangst' in key\ or 'xcart' in key\ or 'xred' in key: inp.write('\n\n') for vec in value: inp.write('%s' % head) for v in vec: inp.write(' %s' % str(v)) inp.write('\n') elif is_strnum(value[0]): for v in value: inp.write(' %s' % str(v)) inp.write('\n') else: for v in value[0]: inp.write(' %s' % str(v)) inp.write('\n') for vec in value[1:]: inp.write('%s' % head) for v in vec: inp.write(' %s' % str(v)) inp.write('\n') if 'restart_wavefunction_path' in self.setting: rstwf_path = self.setting['restart_wavefunction_path'] if os.path.exists(rstwf_path): wf_lst = sorted( glob.glob(os.path.join(rstwf_path, '*o_*WFK'))) assert len(wf_lst) > 0 wf_src = os.path.abspath(wf_lst[-1]) pp_files.append([wf_src, name + 'i_WFK']) else: qtk.warning('%s not found' % rstwf_path) if 'restart_wavefunction_file' in self.setting: rst_file = self.setting['restart_wavefunction_file'] if os.path.exists(rst_file): pp_files.append([rst_file, name + 'i_WFK']) else: qtk.warning('%s not found' % rst_file) if 'restart_density_path' in self.setting: rstdn_path = self.setting['restart_density_path'] if os.path.exists(rstdn_path): dn_lst = sorted( glob.glob(os.path.join(rstdn_path, '*o_*DEN'))) assert len(dn_lst) > 0 dn_src = os.path.abspath(dn_lst[-1]) pp_files.append([dn_src, name + 'i_DEN']) else: qtk.warning('%s not found' % rstdn_path) if 'restart_density_file' in self.setting: rst_file = self.setting['restart_density_file'] if os.path.exists(rst_file): pp_files.append([rst_file, name + 'i_DEN']) else: qtk.warning('%s not found' % rst_file) inp.close(dependent_files=pp_files) if hasattr(inp, 'final_name'): self.setting['no_molecule'] = True self.setting['root_dir'] = name files = \ super(PlanewaveInput, self).write(name, **self.setting) files.extension = 'files' files.write(inp.final_name + '\n') root = os.path.splitext(inp.final_name)[0] files.write(root + '.out\n') files.write(root + 'i\n') files.write(root + 'o\n') files.write(root + 'x\n') for pp in pp_files: files.write(pp[1] + '\n') files.close(no_cleanup=True) return inp
def writeInp(name=None, **setting): inp, molecule = \ PlanewaveInput.write(self, name, **setting) molecule.sort() type_index = molecule.index type_list = molecule.type_list pp_files = [] self.content['system']['nat'] = molecule.N self.content['system']['ntyp'] = len(type_index) - 1 if setting['full_kmesh']: self.content['system']['nosym'] = True self.content['system']['noinv'] = True if 'restart' in setting and setting['restart']: self.content['control']['restart_mode'] = 'restart' if 'save_density' in setting and setting['save_density']: self.content['control']['wf_collect'] = True if 'save_wf' in setting and setting['save_wf']: self.content['control']['wf_collect'] = True if 'print_force' not in setting or not setting['print_force']: self.content['control']['tprnfor'] = True if not setting['periodic']: self.content['system']['assume_isolated'] = 'mt' if 'exx' in setting and setting['exx'] == 'anisotropic': self.content['system']['exxdiv_treatment'] = 'vcut_ws' self.content['system']['ecutvcut'] = 0.7 self.content['system']['x_gamma_extrapolation'] = False if molecule.charge != 0: self.content['system']['tot_charge'] = molecule.charge if molecule.multiplicity != 1: self.content['system']['nspin'] = 2 diff = molecule.multiplicity - 1 self.content['system']['tot_magnetization'] = diff if 'theory' in setting: if self.setting['theory'] in dft_dict: self.content['system']['input_dft'] = \ dft_dict[self.setting['theory']] else: self.content['system']['input_dft'] = self.setting['theory'] if 'scf_step' in setting: self.content['electrons']['electron_maxstep'] =\ setting['scf_step'] if 'ks_states' in setting and setting['ks_states']: vs = int(round(self.molecule.getValenceElectrons() / 2.0)) self.content['system']['nbnd'] = setting['ks_states'] + vs if 'd_shell' in setting: for a in molecule.type_list: if a in setting['d_shell'] and qtk.n2ve(a) < 10: self.content['system']['nbnd'] += 5 if 'symmetry' in setting: if setting['symmetry'] == 'fcc': self.content['system']['ibrav'] = 2 setting['fractional_coordinate'] = True dm = ['A', 'B', 'C', 'cosBC', 'cosAC', 'cosAB'] for i in range(6): self.content['system'][dm[i]] = float(self .molecule.celldm[i]) for section_key in self.content.iterkeys(): section = '&' + section_key + '\n' inp.write(section) for key, value in self.content[section_key].iteritems(): if type(value) is str: entry = " %s = '%s',\n" % (key, value) elif type(value) is int: entry = ' %s = %d,\n' % (key, value) elif type(value) is float: entry = ' %s = %14.8E,\n' % (key, value) elif type(value) is bool: if value: entry = ' %s = .true.,\n' % key else: entry = ' %s = .false.,\n' % key inp.write(entry) inp.write('/\n') inp.write("ATOMIC_SPECIES\n") for a in range(len(type_index)-1): type_n = type_index[a+1] - type_index[a] PPStr = PPString(self, molecule, type_index[a], type_n, inp) stem, ext = os.path.splitext(PPStr) if ext != '.UPF': PPStr = PPStr + '.UPF' mass = qtk.n2m(type_list[type_index[a]]) inp.write(' %-3s % 6.3f %s\n' % \ (type_list[type_index[a]], mass, PPStr)) pp_files.append(PPStr) inp.write("\n") inp.write("ATOMIC_POSITIONS ") if self.content['system']['ibrav'] == 0: if not setting['fractional_coordinate']: inp.write("angstrom\n") R = molecule.R else: inp.write("crystal\n") R = molecule.R_scale else: inp.write("\n") R = molecule.R_scale for a in range(len(type_list)): inp.write(' %-3s' % type_list[a]) for i in range(3): inp.write(' % 12.8f' % R[a, i]) inp.write("\n") inp.write("\n") if 'kmesh' in setting and setting['kmesh']: inp.write("K_POINTS automatic\n") for k in setting['kmesh']: inp.write(" %d" % k) for s in range(3): inp.write(" 0") inp.write('\n\n') if 'save_restart' in setting and setting['save_restart']: inp.write("ALCHEMY reference\n\n") if 'restart' in setting and setting['restart']: if 'scf_step' in setting and setting['scf_step'] == 1: inp.write("ALCHEMY prediction\n\n") if self.content['system']['ibrav'] == 0: inp.write("CELL_PARAMETERS angstrom\n") if 'lattice' not in self.setting: self.celldm2lattice() lattice_vec = self.setting['lattice'] for vec in lattice_vec: for component in vec: inp.write(' % 11.6f' % component) inp.write('\n') for pp in pp_files: pp_file = os.path.join(qtk.setting.espresso_pp, pp) if pp not in inp.dependent_files: inp.dependent_files.append(pp_file) if 'no_cleanup' in setting and setting['no_cleanup']: inp.close(no_cleanup=True) else: inp.close() return inp
def write(self, name=None, **kwargs): self.setting.update(kwargs) self.setting['no_molecule'] = False inp, molecule = \ super(PlanewaveInput, self).write(name, **self.setting) molecule.sort() type_index = molecule.index type_list = molecule.type_list self.pp_path = qtk.setting.bigdft_pp if 'pp_path' in self.setting: self.pp_path = self.setting['pp_path'] if 'pp_theory' not in self.setting: self.setting['pp_theory'] = self.setting['theory'] pp_files = [] inp.write('# abinit input generated by qctoolkit\n') # restart section if 'restart' in self.setting and self.setting['restart']: inp.write('\n# restart, reading wavefunction from file\n') inp.write('irdwfk 1\n') inp.write('getwfk -1\n') # cell definition inp.write('\n# cell definition\n') # cell specified by Bohr if not molecule.symmetry: inp.write('# NOTE: cell defined by lattice vector, ') inp.write('NOT supported by abinit spacegroup detector!\n') inp.write('acell 3*1.889726124993\n') if 'lattice' not in self.setting: self.celldm2lattice() lattice_vec = self.setting['lattice'] inp.write('chkprim 0\n') elif molecule.symmetry.lower() == 'fcc': inp.write("# fcc primitive cell\n") a0 = molecule.celldm[0] * 1.889726124993 inp.write('acell 1 1 1\n') lattice_vec = 0.5 * a0 * np.array([ [0, 1, 1], [1, 0, 1], [1, 1, 0], ]) elif molecule.symmetry.lower() == 'bcc': inp.write("# bcc primitive cell\n") inp.write('acell 1 1 1\n') a0 = molecule.celldm[0] * 1.889726124993 lattice_vec = 0.5 * a0 * np.array([ [-1, 1, 1], [ 1,-1, 1], [ 1, 1,-1], ]) strList = ['rprim', '', ''] for i in range(3): vec = lattice_vec[i] inp.write('%5s % 11.6f % 11.6f % 11.6f\n' % ( strList[i], vec[0], vec[1], vec[2], )) # atom definition inp.write("\n# atom definition\n") inp.write('ntypat %d\n' % (len(type_index) - 1)) inp.write('znucl') for a in range(len(type_index)-1): symb = type_list[type_index[a]] Z = qtk.n2Z(symb) inp.write(' %d' % Z) inp.write('\n') # atom position inp.write("\n# atom position\n") inp.write("natom %d\n" % molecule.N) inp.write('typat') for a in range(len(type_index)-1): start = type_index[a] end = type_index[a+1] for i in range(end - start): inp.write(' %d' % (a+1)) inp.write('\nxangst\n\n') for i in range(molecule.N): inp.write(' ') for j in range(3): inp.write(' % 11.6f' % molecule.R[i][j]) inp.write('\n') # construct pp files depandency pp_file = 'psppar.' + molecule.type_list[i] pp_list = set([pp[1] for pp in pp_files]) if pp_file not in pp_list: pp_src = PPCheck(self.setting['theory'], self.setting['pp_theory'], self.pp_path, molecule.type_list[i]) pp_files.append([pp_src, pp_file]) inp.write('\n') # system setting inp.write("\n# system settings\n") # cutoff in Hartree inp.write('ecut %.2f\n' % float(self.setting['cutoff']/2.)) if 'kmesh' not in self.setting: self.setting['kmesh'] = [1,1,1] if self.setting['full_kmesh']: inp.write('kptopt 3\n') inp.write('ngkpt') for k in self.setting['kmesh']: inp.write(' %d' % k) if 'kshift' not in self.setting: inp.write('\nshiftk 0.0 0.0 0.0') if 'ks_states' in self.setting and self.setting['ks_states']: vs = int(round(molecule.getValenceElectrons() / 2.0)) nbnd = self.setting['ks_states'] + vs if 'd_shell' in self.setting: for a in molecule.type_list: if a in self.setting['d_shell'] and qtk.n2ve(a) < 10: nbnd += 5 inp.write('\nnband %d' % nbnd) inp.write('\nnstep %d\n' % self.setting['scf_step']) if 'wf_convergence' in self.setting: inp.write('toldfe %.2E\n' % self.setting['wf_convergence']) if molecule.charge != 0: inp.write('charge=%d\n' % molecule.charge) if molecule.multiplicity != 1: inp.write('nsppol 2 # for spin polarized\n') inp.write('occopt 7 # for relaxed occupation\n') if 'save_restart' in self.setting and self.setting['save_restart']: pass else: inp.write('prtwf 0\n') for item in self.content: inp.write(item) inp.close(dependent_files=pp_files) if hasattr(inp, 'final_name'): self.setting['no_molecule'] = True self.setting['root_dir'] = name files = \ super(PlanewaveInput, self).write(name, **self.setting) files.extension = 'files' files.write(inp.final_name + '\n') root = os.path.splitext(inp.final_name)[0] files.write(root + '.out\n') files.write(root + 'i\n') files.write(root + 'o\n') files.write(root + 'x\n') for pp in pp_files: files.write(pp[1] + '\n') files.close(no_cleanup = True) return inp
def PPString(inp, mol, i, n, outFile): """ append PP file names to inp.pp_files """ alchemy = re.compile('^\w*2\w*_\d\d\d$') ppstr = re.sub('\*', '', mol.string[i]) if ppstr: PPStr = ppstr pp_root, pp_ext = os.path.split(ppstr) else: if inp.setting['pp_type'] == 'geodecker': element = mol.type_list[i].title() if 'd_shell' in inp.setting: if type(inp.setting['d_shell']) is not list: inp.setting['d_shell'] = [inp.setting['d_shell']] if qtk.n2ve(mol.type_list[i].title()) > 10: shell = '-d' elif 'd_shell' in inp.setting \ and element in inp.setting['d_shell']: shell = '-d' else: element = qtk.element[mol.type_list[i].title()] if element.group < 3 and mol.Z[i] > 1: if mol.Z[i] != 3: shell = '-sp' else: shell = '-s' else: shell = '' pp_xc_dict = { 'lda': 'pz', 'pbe0': 'pbe', 'b3lyp': 'blyp', } pp_xc = inp.setting['pp_theory'].lower() if pp_xc in pp_xc_dict: pp_xc = pp_xc_dict[pp_xc] PPStr = ''.join([c for c in mol.type_list[i] if not c.isdigit()])\ + '.' + pp_xc + shell + '-hgh.UPF' elif inp.setting['pp_type'] == 'cpmd': PPStr = PPName(inp, mol, i, n) xc = inp.setting['pp_theory'].lower() if not mol.string[i]: if inp.setting['pp_type'] == 'geodecker': PPCheck(pp_xc, mol.type_list[i].title(), PPStr) elif inp.setting['pp_type'] == 'cpmd': saved_pp = PPCheck_cpmd(pp_xc, mol.type_list[i].title(), PPStr) new_pp1 = saved_pp + '.UPF' conv_pp = sp.Popen("%s %s" % \ (qtk.setting.espresso_cpmd2upf_exe, saved_pp), shell=True) conv_pp.wait() new_pp1_file = os.path.split(new_pp1)[1] new_pp1_trg = os.path.join(qtk.setting.espresso_pp, new_pp1_file) if not os.path.exists(new_pp1_trg): shutil.copy(new_pp1, qtk.setting.espresso_pp) PPStr = PPStr + '.UPF' elif alchemy.match(mol.string[i]): cpmd_pp = alchemyPP(xc, PPStr) new_pp1 = cpmd_pp + '.UPF' if not os.path.exists(new_pp1): qtk.report('espresso', "rewrite Goedecker's PP to UPF") conv_pp = sp.Popen("%s %s" % \ (qtk.setting.espresso_cpmd2upf_exe, cpmd_pp), shell=True) conv_pp.wait() if conv_pp.returncode != 0: # dirty fix for espresso alchemy conversion routine qtk.warning('conversion failed..., trying path end points') root, _ = os.path.splitext(PPStr) element_str = re.sub('_.*', '', root) element1 = re.sub('2.*', '', element_str) element2 = re.sub('.*2', '', element_str) fraction = float(re.sub('.*_', '', root))/100 if fraction == 0.0: strpp = element1 + "_q" + str(qtk.n2ve(element1)) +\ "_" + xc + '.psp' elif fraction == 1.0: strpp = element2 + "_q" + str(qtk.n2ve(element2)) +\ "_" + xc + '.psp' else: qtk.exit("PP conversion failed for intermediate lambda") strpp = os.path.join(qtk.setting.cpmd_pp, strpp) conv_pp = sp.Popen("%s %s" % \ (qtk.setting.espresso_cpmd2upf_exe, strpp), shell=True) conv_pp.wait() os.rename(strpp + '.UPF', new_pp1) new_pp1_file = os.path.split(new_pp1)[1] new_pp1_trg = os.path.join(qtk.setting.espresso_pp, new_pp1_file) if not os.path.exists(new_pp1_trg): shutil.copy(new_pp1, qtk.setting.espresso_pp) PPStr = PPStr + '.UPF' return PPStr
def writeInp(name=None, **setting): inp, molecule = \ PlanewaveInput.write(self, name, **setting) molecule.sort() type_index = molecule.index type_list = molecule.type_list pp_files = [] self.content['system']['nat'] = molecule.N self.content['system']['ntyp'] = len(type_index) - 1 if setting['full_kmesh']: self.content['system']['nosym'] = True self.content['system']['noinv'] = True if 'restart' in setting and setting['restart']: self.content['control']['restart_mode'] = 'restart' if 'save_density' in setting and setting['save_density']: self.content['control']['wf_collect'] = True if 'save_wf' in setting and setting['save_wf']: self.content['control']['wf_collect'] = True if 'print_force' not in setting or not setting['print_force']: self.content['control']['tprnfor'] = True if not setting['periodic']: self.content['system']['assume_isolated'] = 'mt' if 'exx' in setting and setting['exx'] == 'anisotropic': self.content['system']['exxdiv_treatment'] = 'vcut_ws' self.content['system']['ecutvcut'] = 0.7 self.content['system']['x_gamma_extrapolation'] = False if molecule.charge != 0: self.content['system']['tot_charge'] = molecule.charge if molecule.multiplicity != 1: self.content['system']['nspin'] = 2 diff = molecule.multiplicity - 1 self.content['system']['tot_magnetization'] = diff if 'theory' in setting: if self.setting['theory'] in dft_dict: self.content['system']['input_dft'] = \ dft_dict[self.setting['theory']] else: self.content['system']['input_dft'] = self.setting[ 'theory'] if 'scf_step' in setting: self.content['electrons']['electron_maxstep'] =\ setting['scf_step'] if 'ks_states' in setting and setting['ks_states']: vs = int(round(self.molecule.getValenceElectrons() / 2.0)) self.content['system']['nbnd'] = setting['ks_states'] + vs if 'd_shell' in setting: for a in molecule.type_list: if a in setting['d_shell'] and qtk.n2ve(a) < 10: self.content['system']['nbnd'] += 5 if 'symmetry' in setting: if setting['symmetry'] == 'fcc': self.content['system']['ibrav'] = 2 setting['fractional_coordinate'] = True dm = ['A', 'B', 'C', 'cosBC', 'cosAC', 'cosAB'] for i in range(6): self.content['system'][dm[i]] = float( self.molecule.celldm[i]) for section_key in self.content.iterkeys(): section = '&' + section_key + '\n' inp.write(section) for key, value in self.content[section_key].iteritems(): if type(value) is str: entry = " %s = '%s',\n" % (key, value) elif type(value) is int: entry = ' %s = %d,\n' % (key, value) elif type(value) is float: entry = ' %s = %14.8E,\n' % (key, value) elif type(value) is bool: if value: entry = ' %s = .true.,\n' % key else: entry = ' %s = .false.,\n' % key inp.write(entry) inp.write('/\n') inp.write("ATOMIC_SPECIES\n") for a in range(len(type_index) - 1): type_n = type_index[a + 1] - type_index[a] PPStr = PPString(self, molecule, type_index[a], type_n, inp) stem, ext = os.path.splitext(PPStr) if ext != '.UPF': PPStr = PPStr + '.UPF' mass = qtk.n2m(type_list[type_index[a]]) inp.write(' %-3s % 6.3f %s\n' % \ (type_list[type_index[a]], mass, PPStr)) pp_files.append(PPStr) inp.write("\n") inp.write("ATOMIC_POSITIONS ") if self.content['system']['ibrav'] == 0: if not setting['fractional_coordinate']: inp.write("angstrom\n") R = molecule.R else: inp.write("crystal\n") R = molecule.R_scale else: inp.write("\n") R = molecule.R_scale for a in range(len(type_list)): inp.write(' %-3s' % type_list[a]) for i in range(3): inp.write(' % 12.8f' % R[a, i]) inp.write("\n") inp.write("\n") if 'kmesh' in setting and setting['kmesh']: inp.write("K_POINTS automatic\n") for k in setting['kmesh']: inp.write(" %d" % k) for s in range(3): inp.write(" 0") inp.write('\n\n') if 'save_restart' in setting and setting['save_restart']: inp.write("ALCHEMY reference\n\n") if 'restart' in setting and setting['restart']: if 'scf_step' in setting: if setting['scf_step'] != 1: qtk.warning('alchemy with optimization...') inp.write("ALCHEMY prediction\n\n") if self.content['system']['ibrav'] == 0: inp.write("CELL_PARAMETERS angstrom\n") if 'lattice' not in self.setting: self.celldm2lattice() lattice_vec = self.setting['lattice'] for vec in lattice_vec: for component in vec: inp.write(' % 11.6f' % component) inp.write('\n') for pp in pp_files: pp_file = os.path.join(qtk.setting.espresso_pp, pp) if pp not in inp.dependent_files: inp.dependent_files.append(pp_file) if 'no_cleanup' in setting and setting['no_cleanup']: inp.close(no_cleanup=True) else: inp.close() return inp
def PPString(inp, mol, i, n, outFile): """ append PP file names to inp.pp_files """ alchemy = re.compile('^\w*2\w*_\d\d\d$') ppstr = re.sub('\*', '', mol.string[i]) if ppstr: PPStr = ppstr pp_root, pp_ext = os.path.split(ppstr) else: if inp.setting['pp_type'] == 'geodecker': element = mol.type_list[i].title() if 'd_shell' in inp.setting: if type(inp.setting['d_shell']) is not list: inp.setting['d_shell'] = [inp.setting['d_shell']] if qtk.n2ve(mol.type_list[i].title()) > 10: shell = '-d' elif 'd_shell' in inp.setting \ and element in inp.setting['d_shell']: shell = '-d' else: element = qtk.element[mol.type_list[i].title()] if element.group < 3 and mol.Z[i] > 1: if mol.Z[i] != 3: shell = '-sp' else: shell = '-s' else: shell = '' pp_xc_dict = { 'lda': 'pz', 'pbe0': 'pbe', 'b3lyp': 'blyp', } pp_xc = inp.setting['pp_theory'].lower() if pp_xc in pp_xc_dict: pp_xc = pp_xc_dict[pp_xc] PPStr = ''.join([c for c in mol.type_list[i] if not c.isdigit()])\ + '.' + pp_xc + shell + '-hgh.UPF' elif inp.setting['pp_type'] == 'cpmd': PPStr = PPName(inp, mol, i, n) xc = inp.setting['pp_theory'].lower() if not mol.string[i]: if inp.setting['pp_type'] == 'geodecker': PPCheck(pp_xc, mol.type_list[i].title(), PPStr) elif inp.setting['pp_type'] == 'cpmd': saved_pp = PPCheck_cpmd(pp_xc, mol.type_list[i].title(), PPStr) new_pp1 = saved_pp + '.UPF' conv_pp = sp.Popen("%s %s" % \ (qtk.setting.espresso_cpmd2upf_exe, saved_pp), shell=True) conv_pp.wait() new_pp1_file = os.path.split(new_pp1)[1] new_pp1_trg = os.path.join(qtk.setting.espresso_pp, new_pp1_file) if not os.path.exists(new_pp1_trg): shutil.copy(new_pp1, qtk.setting.espresso_pp) PPStr = PPStr + '.UPF' elif alchemy.match(mol.string[i]): cpmd_pp = alchemyPP(xc, PPStr) new_pp1 = cpmd_pp + '.UPF' if not os.path.exists(new_pp1): qtk.report('espresso', "rewrite Goedecker's PP to UPF") conv_pp = sp.Popen("%s %s" % \ (qtk.setting.espresso_cpmd2upf_exe, cpmd_pp), shell=True) conv_pp.wait() if conv_pp.returncode != 0: # dirty fix for espresso alchemy conversion routine qtk.warning('conversion failed..., trying path end points') root, _ = os.path.splitext(PPStr) element_str = re.sub('_.*', '', root) element1 = re.sub('2.*', '', element_str) element2 = re.sub('.*2', '', element_str) fraction = float(re.sub('.*_', '', root)) / 100 if fraction == 0.0: strpp = element1 + "_q" + str(qtk.n2ve(element1)) +\ "_" + xc + '.psp' elif fraction == 1.0: strpp = element2 + "_q" + str(qtk.n2ve(element2)) +\ "_" + xc + '.psp' else: qtk.exit("PP conversion failed for intermediate lambda") strpp = os.path.join(qtk.setting.cpmd_pp, strpp) conv_pp = sp.Popen("%s %s" % \ (qtk.setting.espresso_cpmd2upf_exe, strpp), shell=True) conv_pp.wait() os.rename(strpp + '.UPF', new_pp1) new_pp1_file = os.path.split(new_pp1)[1] new_pp1_trg = os.path.join(qtk.setting.espresso_pp, new_pp1_file) if not os.path.exists(new_pp1_trg): shutil.copy(new_pp1, qtk.setting.espresso_pp) PPStr = PPStr + '.UPF' return PPStr