def file2Convert(fileName, style, header=False, newFile=None): ''' notes: fileName : the name of a eos file in the same directory as the script style : see 'convert' function for possible options header : Set to True if there is a header, else keep as False newFile : if None, the original file will be overwritten with the EoS if a string, a new file with a name equal to the string will be created and filled with the EoS if True, a list of the strings corrosponding to the EoS will be returned. ''' lines = iop.flat_file_intable(fileName, header=header, entete=True) if (header): modLines = convertFunc(lines[0][1:], convert=style, round_Value=4) modLines.insert(0, lines[0][0]) else: modLines = convertFunc(lines[0], convert=style, round_Value=4) lines[0] = modLines newLines = px.table_trans(lines) outLines = map(lambda x: strl.array_to_str(x, spc=' ', endline=True), newLines) if (newFile == None): iop.flat_file_write(fileName, outLines) elif (isinstance(newFile, str)): iop.flat_file_write(newFile, outLines) else: return outLines return True
test_line_seq = [ " ", str(basconv), str(partconv), str(totconv), str(v1), "v" + str(numgroup[i]) + '\n' ] except: sum_failure = True test_line_seq = [ " ", "Failed", "Failed", "Failed", "Failed", "v" + str(numgroup[i]) + '\n' ] output_lines.append(strl.array_to_str(test_line_seq, spc=' ')) # Consolidating Files cml.cmd('mv test.txt;test1.txt vincp') cml.cmd('cd vincp') new_fold_name = 'run_v' + str(numgroup[i]) cml.cmd('mkdir ' + new_fold_name) cml.cmd('mv test.txt;test1.txt ' + new_fold_name) cml.cmd('cd ..') lines_list.append(demark) iop.flat_file_write(in_path, lines_list) iop.flat_file_write('sum_test.txt', output_lines) tend = time.time()
def tabulate_vmed_all(jv_list, group_by_vindex=True, momenta=None, print_lines=True, momenta_units='invfm', pot_units='invmev2', round_value=None, digits=3, espace=3, pyver='2.6'): ''' Inputs: jv_list : 'jv' formatted list group_by_vindex : (True) If True, output table automatically arranged by vmed number (lowest to highest) momenta : (None), if momenta is an array of integers, these momenta values used in jsl search print_lines : (True), If true, outlines are printed to a file, either way the list of strings is returned momenta_units : ('invfm'), options are 'invfm' or 'mev' corrosponding to Inverse Fermi and MeV^2 respectively pot_units : ('fm'), options are 'fm' or 'invmev2' corrosponding to Fermi and MeV respectively ''' #Initialize internal command-line print("") cml = cmd.PathParse('linux') if (cml == False): return False # Get contents of vincp (contains the eff. potentials in question) Must run 'vmed_all.py' first! if ('vincp' not in cml.varPath_Folders): print("Error: no instance of 'vincp' in current (path) directory") return False vincp_path = cml.joinNode(cml.varPath, 'vincp') vincp_content = cml.contentPath( vincp_path, objType='file', ) # group by v# in order, set 'group_by_vindex = False' to ignore this command if (group_by_vindex): vincp_content = map( lambda x: (vmed_index_finder.findall(x.split('.')[0])[0], x), vincp_content) vincp_content.sort(key=lambda x: int(x[0])) # Set momenta values if (momenta == None): plist = strl.array_nth_index(vf.pf_vals_20, 5) elif (isinstance(momenta, (list, tuple))): plist = momenta else: print("Error: input variable, 'momenta', not recognized") return False jsl_list = [] for jv in jv_list: j = str(jv[0]) t = str(jv[1]) for p in plist: jsl_list.append(vf.jsl_entry(j, p, p, t)) outlines = [] if (isinstance(momenta_units, str)): if (momenta_units.lower() == 'invfm'): plist = map(lambda x: str(round(float(x) / vf.hc, 2)), plist) pstring = '' for entry in plist: pstring = pstring + mops.space_format(entry, 12, adjust='right') pline = mops.space_format('p', 14, adjust='right') heading = pline + pstring + '\n' outlines.append(heading) outlines.append('\n') for entry in vincp_content: vval = entry[0] filename = entry[1] filepath = cml.joinNode(vincp_path, filename) filetext = iop.flat_file_grab(filepath) matching_values = vf.grab_jsl(filetext, jsl_list, round_form=1) if (isinstance(matching_values, (list, tuple)) and isinstance(pot_units, str)): if (pot_units.lower() == 'invmev2'): pass else: if (not isinstance(round_value, int)): matching_values = map(lambda x: str(float(x) * vf.vmhc), matching_values) else: if (round_value > 2): matching_values = map( lambda x: str( round(float(x) * vf.vmhc, round_value)), matching_values) matching_values = mops.sci_space_format(matching_values, digi=digits, spacing=espace, pyver=pyver) outline = strl.array_to_str(matching_values, spc=' ') out_heading = 'vmed ' + str(vval) out_heading = mops.space_format(out_heading, 9, adjust='right') outline = out_heading + " " + outline + '\n' outlines.append(outline) elif (matching_values == False or matching_values == None): print(' ' + "Error: parsing partial wave value failed\n") continue else: print(' ' + "Error: unknown error when parsing partial wave\n") continue if (print_lines): iop.flat_file_write('table_vincp', outlines) return outlines
def gen_table_12_13(lines): list_12, list_13 = [], [] lines = strl.array_filter_spaces(lines) for i in xrange(len(pf_vals_20)): try: s_vals = grab_jsl(lines, s_jsl(pf_vals_20[i]), round_form=1) p_vals = grab_jsl(lines, p_jsl(pf_vals_20[i]), round_form=1) except: print( "[gen_fig_12_13] Error: an error occured while trying to parse jsl values form 'lines' input" ) return False if (s_vals != []): list_12.append(s_vals) if (p_vals != []): list_13.append(p_vals) val_table_12 = px.table_trans(list_12) val_table_13 = px.table_trans(list_13) if (val_table_12 == False or val_table_13 == False): print( "[gen_fig_12_13] Error: an error occured while trying to transpose jsl tables" ) return False for i in range(len(val_table_12)): val_table_12[i] = [float(j) * vmhc for j in val_table_12[i]] for i in range(len(val_table_13)): val_table_13[i] = [float(j) * vmhc for j in val_table_13[i]] val_table_12.insert(0, kf_vals_20) val_table_12 = px.table_trans(val_table_12) if (val_table_12 == False): print( "[gen_fig_12_13] Error: an error occured while trying to transpose table 12 after adding kfs" ) return False val_table_13.insert(0, kf_vals_20) val_table_13 = px.table_trans(val_table_13) if (val_table_13 == False): print( "[gen_fig_12_13] Error: an error occured while trying to transpose table 13 after adding kfs" ) return False for i in range(len(val_table_12)): try: val_table_12[i] = strl.array_to_str(val_table_12[i], spc=' ') except: print( "[gen_fig_12_13] Error: entries in table 12 could not be converted to strings" ) for i in range(len(val_table_13)): try: val_table_13[i] = strl.array_to_str(val_table_13[i], spc=' ') except: print( "[gen_fig_12_13] Error: entries in table 13 could not be converted to strings" ) return val_table_12, val_table_13
nqftest_txt + str(nqftest_list[i]) + '\n' ] iop.flat_file_replace('eff3nfn3lo1.f', nlines, clist) subp.call( "f90 $F90FLAGS -o xl -s -w cpot.f eff3nfn3lo1.f $LINK_FNL", shell=True) subp.call("./xl", shell=True) lines = iop.flat_file_grab('pot.d', scrub=True) vals = vf.grab_jsl(lines, jsls, 1) for k in xrange(len(vals)): vals[k] = str( mops.round_uniform(float(vals[k]) * vf.vmhc, pyver='2.6')) gp_vals.append( str(cqfi_list[j]) + ' ' + strl.array_to_str(vals, spc=' ')) mx_vals.append(gp_vals) gp_vals = [] else: clist = [nqftest_txt + str(nqftest_list[i]) + '\n'] iop.flat_file_replace('eff3nfn3lo1.f', [nlines[1]], clist) subp.call("f90 $F90FLAGS -o xl -s -w cpot.f eff3nfn3lo1.f $LINK_FNL", shell=True) subp.call("./xl", shell=True) lines = iop.flat_file_grab('pot.d', scrub=True) vals = vf.grab_jsl(lines, jsls, 1) for k in xrange(len(vals)): vals[k] = str( mops.round_uniform(float(vals[k]) * vf.vmhc, pyver='2.6'))
filetable = iop.flat_file_intable(filename) oneszero = filetable[1] p1s0.append(str(mops.round_uniform(float(oneszero[0]), pyver='2.6'))) # 0.1 p1s0.append(str(mops.round_uniform(float(oneszero[4]), pyver='2.6'))) # 0.5 p1s0.append(str(mops.round_uniform(float(oneszero[9]), pyver='2.6'))) # 1.0 p1s0.append(str(mops.round_uniform(float(oneszero[12]), pyver='2.6'))) # 1.3 p1s0.append(str(mops.round_uniform(float(oneszero[14]), pyver='2.6'))) # 1.5 p1s0.append(str(mops.round_uniform(float(oneszero[19]), pyver='2.6'))) # 2.0 p1s0.append('v' + str(numgroup[i])) t1s0.append(strl.array_to_str(p1s0, spc=' ')) p1s0 = [] output_list = strl.format_fancy(t1s0, list_return=True) iop.flat_file_write('all_3p0.txt', output_list) tend = time.time() print('') spc = ' ' print("Finished! No Errors reported, see below for run details:\n") print(spc + "The script took approx. " + str(round(tend - tstart, 1)) + " secs to run") print(spc + "The script found " + str(len(numgroup)) + " groupings") if (exist): print(spc +
def tabulate_pot_data(self, pot_data, equiv_momenta=True, header_line=False, errorCheck=None, **kwargs): kwargs = self.__update_funcNameHeader__("tabulate_pot_data", **kwargs) def get_new_file_name(file_name): if (not isinstance(file_name, str)): return False new_file_list = file_name.split('.') if (len(new_file_list) != 2): return False new_file_list[0] = new_file_list[0] + "_pwaves" new_file_line = new_file_list[0] + '.' + new_file_list[1] return new_file_line if (errorCheck == None): errorCheck = self.errorCheck if (errorCheck): if (self.__not_arr_print__(pot_data, **kwargs)): return False header_list = [] file_list = [] for file_data in pot_data: momenta = [] file_name, data_dict = file_data file_list.append(file_name) new_file_name = get_new_file_name(file_name) if (new_file_name == False): self.__err_print__( "could not generate a new file name for '" + str(file_name) + "'", **kwargs) continue data_list = [] for wave in sorted(list(data_dict)): wave_data = data_dict[wave] if (header_line): header_list.append(file_name + "_" + str(wave)) if (equiv_momenta): if (len(momenta) == 0): momenta = map(lambda lam: lam[0], wave_data) data_list.append(momenta) data_column = map(lambda lam: lam[1], wave_data) data_list.append(data_column) else: data_list.append(map(lambda lam: lam[0], wave_data)) data_list.append(map(lambda lam: lam[1], wave_data)) data_list_trans = px.table_trans(data_list, **kwargs) data_lines = px.matrix_to_str_array(data_list_trans, endline=True, **kwargs) if (self.__not_strarr_print__(data_lines, varID='data_lines', **kwargs)): continue if (header_line): header_line_str = strl.array_to_str(header_list, **kwargs) data_lines = [header_line_str] + data_lines iop.flat_file_write(new_file_name, data_lines, **kwargs) return True