def file_print(self): if len(self.outfile) == 0: print('Warning: no file is going to output') print(' : please try to change the input chargefile') exit() else: print('\nOne sample of generated GROMACS_top files is:\n') print(' [ atoms ]') for i in self.atomndx: print(self.outfile[0][i], end='') print('\nDo you want to continue? y/yes, else quit') print(' this will generate \'top\' files >', end=' ') get_input = input() if get_input.upper() != 'Y' and get_input.upper != 'YES': print('\nWarning: you have decided to quit ...') print(' : nothing is generated\n') exit() else: print('\nGreat! Going to generate files ...\n') topnamelist = [] for top in self.outfile: fname = file_gen_new(self.fname, fextend='top', foriginal=False) topnamelist.append(fname) with open(fname, mode='wt') as f: for line in top: f.write(line) fnamelist = self.fname + '_NameList' fnamelist = file_gen_new(fnamelist, fextend='txt', foriginal=False) with open(fnamelist, mode='wt') as f: f.write( '# This is a collection of all the generated GROMACS topfile names \n' ) f.write('# The topfile used is:\n') f.write('# {:s}\n'.format(self.toppath)) f.write('# The charge_file used is:\n') f.write('# {:s}\n\n'.format(self.file_line_chargepath)) if len(self.file_line_symmetry) != 0: f.write('# The symmetry_list used is:\n') f.write('# {:s}\n\n'.format(self.file_line_symmetry)) for i in topnamelist: f.write(i) f.write('\n')
def file_print(self): """write files""" bo = False if len(self.outfile) == 0: print('Warning: no file is going to output') print(' : please try to change the input chargefile') else: print('\nOne sample of generated GROMACS_top files is:\n') print(' [ atoms ]') for i in self.atomndx: print(self.outfile[0][i], end='') line = "This will generate 'top' files, " line += '({:} topfiles will be generated)\n'.format(self.gennm) line += 'Do you want to continue? y/yes, else quit' print(line, end=' ') get_input = input() if get_input.upper() != 'Y' and get_input.upper != 'YES': print('\nWarning: you have decided to quit ...') print(' : nothing is generated\n') else: print('\nGreat! Going to generate files ...\n') bo = True if bo: topnamelist = [] for top in self.outfile: fname = file_gen_new(self.fname, fextend='top', foriginal=False) topnamelist.append(fname) with open(fname, mode='wt') as f: for line in top: f.write(line) fnamelist = self.fname + '_NameList' fnamelist = file_gen_new(fnamelist, fextend='txt', foriginal=False) print('Note: please check file: < {:} >'.format(fnamelist)) with open(fnamelist, mode='wt') as f: f.write('# The collection of all GROMACS topfile names \n') f.write('# The topfile used is:\n') f.write('# {:s}\n'.format(self.toppath)) f.write('# The charge_file used is:\n') f.write('# {:s}\n\n'.format(self.file_line_chargepath)) f.write('# The symmetry_list used is:\n') f.write('# {:s}\n\n'.format(str(self.symmetry_list))) for i in topnamelist: f.write(i) f.write('\n')
def file_print(self): pf = file_gen_new('bash_GAML_AutoTraining', fextend='sh') with open(pf, mode='wt') as f: f.write('#!/bin/bash\n') f.write('# -*- coding: utf-8 -*-\n\n') for key in sorted(self.parameters): if 'RAW' in key: pass elif self.parameters[key] is None: f.write("{:}= \n".format(key)) else: if key == 'symmetry_list' or key == 'counter_list' or \ key == 'offset_list': f.write("{:}='{:}'\n".format( key, self.parameters[key + 'RAW'])) elif key == 'pn_limit' or key == 'gromacs_energy_kw' or \ key == 'literature_value': f.write("{:}='{:}'\n".format(key, self.parameters[key])) else: f.write('{:}={:}\n'.format(key, self.parameters[key])) f.write('\n\n\n') f.write(self._shfile) print('Note: the file < {:} > has been generated, '.format(pf)) print(' : which can be directly executed for auto-training')
def file_print(self): """writing to file""" print('One sample of generated Gaussian_com files is:\n') print(self.outfile[0], end='') print('Do you want to continue? y/yes, else quit') line = 'This will generate < {:} > files'.format(len(self.outfile)) print(line) tmp = input() if tmp.lower() != 'y' and tmp.lower != 'yes': print('Note: exiting...') return print('\nGreat! Going to generate files ...\n') fnamelist = [] for line in self.outfile: filename = file_gen_new(self.fname, fextend='com', foriginal=False) fnamelist.append(filename) new = filename[:filename.rfind('.')] line = '%chk={:}.chk\n'.format(new) + line with open(filename, 'wt') as f: f.write(line) pf = self.fname + '_namelist' pf = file_gen_new(pf, fextend='txt', foriginal=False) print('Note: please check file: < {:} >'.format(pf)) with open(pf, mode='wt') as f: f.write('# Collection of generated file names\n\n') f.write('# The topfile is:\n') f.write('# {:}\n\n'.format(self.toppath)) f.write('# The pdbfile is:\n') f.write('# {:}\n\n'.format(self.file_path)) f.write('# The select_range is < {:} > Angstrom\n'.format( self.select_range)) f.write('# Reference format: [residue-index, molecule-index]\n\n') for i, j in enumerate(fnamelist): line = '' for t in self.chooselist[i]: line += '[' + str(t[0] + 1) + ',' + str(t[1] + 1) + '] ' line = line.strip() f.write('{:<6d}: {:} \n'.format(i + 1, line))
def file_print(self): pfname = file_gen_new(self.fname, fextend='txt', foriginal=False) with open(pfname, mode='wt') as f: f.write('# Simulation process result\n\n') f.write('# The input file used is:\n') f.write('# {:}\n\n'.format(self.file)) f.write('# The charge file used is:\n') f.write('# {:}\n\n'.format(self.chargefile)) f.write('# Note the used MAE value is < {:} >\n\n'.format( self.MAE)) if self.bool_gas: f.write('# The total number of atoms are < {:} >\n'.format( self.atomnm)) f.write('# The temperature is < {:} K >\n'.format( self.temperature)) self.kwlist = [ 'HVAP' if i == 'Potential' else i for i in self.kwlist ] f.write('\n\n') cnt = 0 endlist = [] for pair in self.prochargefile: bool_end = False line = 'PAIR ' for ch in pair: line += '{:>7.4f} '.format(ch) err = self.errlist[cnt] if 'NaN' in err: line += 'MAE NaN' else: maerr = sum([abs(tmp) for tmp in err]) / len(err) if maerr <= self.MAE: bool_end = True line += 'MAE {:>6.4f}'.format(maerr) ndx = 0 for kw in self.kwlist: line += ' {:} '.format(kw) line += '{:>7.4f}'.format(err[ndx]) ndx += 1 f.write(line) f.write('\n') if bool_end: endlist.append(line.replace('PAIR', 'HEAD')) cnt += 1 if len(endlist) != 0: f.write('\n\n') f.write('# The training MAE requirement has been fulfilled\n') for t in endlist: f.write(t) f.write('\n')
def file_print(self): fname = file_gen_new(self.fname,fextend='txt',foriginal=True) print('Note: new file: < {:} >'.format(fname)) with open(fname,mode='wt') as f: f.write('# File charge ranges based on the input charge_file \n') f.write('# The charge file used is:\n') f.write('# {:s}\n'.format(self.charge_path)) f.write('# Line is corresponded to each atom \n\n') j = 1 for i in self.charge_range: f.write('ATOM {:>6d} {:>11.4f} {:>11.4f}\n'.format(j,i[0],i[1])) j += 1
def file_print(self): """the module used, file_gen_new""" fnamelist = [] for sys in self.outfile: filename = file_gen_new(pfname, fextend='com', foriginal=False) fnamelist.append(filename) with open(filename, mode='wt') as f: for res in sys: for line in res: f.write(line) f.write('\n') pfname = pfname + '_namelist' pfname = file_gen_new(pfname, fextend='txt', foriginal=False) with open(pfname, mode='wt') as f: f.write('# This file is a name_list of chosen_residue \n\n') f.write('# The topfile used is:\n') f.write('# {:s}\n\n'.format(self.toppath)) f.write('# The pdbfile used is:\n') f.write('# {:s}\n\n'.format(self.file_path)) f.write( '# The value corresponds to the input pdb file residue number \n' ) f.write('# The select_range used is < {:} > Angstrom\n'.format( self.select_range)) f.write('\n [namelist] \n\n') f.write('# nm res_1 res_2 ... filename\n\n') j = 1 count = 0 for i in fnamelist: f.write('{:>6d} {:s} {:>20s} \n'.format( j, resnmprint[count], i)) count += 1 j += 1
def file_print(self): self.figure_plot() pfname = file_gen_new(self.fname, fextend='txt', foriginal=False) with open(pfname, mode='wt') as f: f.write( '# This is the final calculation result, which is not normalized \n\n' ) f.write('# The corresponded parameters are: \n\n') f.write('# The input file used is: \n') f.write('# {:s} \n\n'.format(self.filepath)) f.write('# The error_tolerance is: < {} > \n'.format( self.error_tolerance)) f.write('# The percent_range is: < {} > \n'.format(self.percent)) f.write('# The stepsize is: < {} > \n'.format(self.stepsize)) f.write('# The plot pallette_number is: < {} > \n\n\n'.format( self.pallette_nm)) f.write( '# Note: each column is corresponded to its own data_range \n') f.write( '# and those data_ranges are the final optimal charge_range \n\n' ) f.write('# For each different atomtype, the charge_range is: \n') i = 0 for j in self.valuerangelist: f.write('# {}'.format(self.atomtype_list[i])) f.write(' {:>8.3f} {:>8.3f} \n'.format(j[0], j[1])) i += 1 f.write('\n\n') f.write( '# From the Feature Statistical Standard Error Selection,\n') f.write('# the most influenced atomtype sequence is: \n') f.write('# ') for i in self.ndxlist: f.write(' {} '.format(self.atomtype_list[i])) f.write('\n\n\n') f.write( '# In total, the selected_charge_pair_number is: < {} > \n'. format(self.select_pairnm)) f.write('# the dataset is:\n\n') for line in self.profile: f.write(line) f.write('\n')
def run(self): """get built-in script file""" details = { 'bash_analysesDES.sh': 'For DES result analyses', 'bash_DES.sh': 'For DES training', 'bash_GAML.sh': 'For conventional solvents training', 'bash_genTopfiles.sh': 'For GROMACS topology file generations', 'bash_rmfilesIndividual.sh': 'For folder cleanup', 'bash_visAdd.sh': 'For viscosity property training', 'bash_visAnalysisByFolder.sh': 'For viscosity property analyzing', 'GAML-BASH-Interface.sh': 'For command GAML_autotrain', 'py_bool_repeatsChk.py': 'For charge pair repeats check out', } if self.available: print('Available scripts:') for cnt, f in enumerate(self.files): if f in details: print(' {:2d} --> {:<30} {:}'.format( cnt + 1, f, details[f])) else: print(' {:2d} --> {:}'.format(cnt + 1, f)) print('\nWhich scripts do you want to get?') print('Please input its number. (Input q/quit to quit)') while True: tmp = input() if tmp.lower() in ['q', 'quit']: break try: self.n = int(float(tmp)) if self.n <= 0: self.n = None raise ValueError except ValueError: pass if isinstance(self.n, int) and self.n <= len(self.files): self.available = False break else: print('Wrong choose. (Input q/quit to quit)') if self.available: print('You decided to quit..') else: cwd = os.getcwd() fname = self.files[self.n - 1] fp = resource_filename(__name__, 'scripts/' + fname) if os.path.isfile(fp): fname = file_gen_new(fname) print('Note: script file: < {:} >'.format(fname)) shutil.copy(fp, cwd + '/' + fname)
def file_print(self): fname = file_gen_new(self.fname,fextend='txt',foriginal=True) charge_range = self.charge_range() with open(fname,mode='wt') as f: f.write('# This is the generated charge_range based on the input charge_file \n') f.write('# The charge file used is:\n') f.write('# {:s}\n'.format(self.charge_path)) f.write('# Each line\'s charge_range is corresponded to each atom \n\n') j = 1 for i in charge_range: f.write('ATOM {:>6d} {:>8.4f} {:>8.4f}\n'.format(j,i[0],i[1])) j += 1
def file_print(self): fname = file_gen_new(self.fname, fextend='txt') print('Note: new file < {:} >'.format(fname)) with open(fname, mode='wt') as f: f.write('# GAML charge scheme \n\n') if len(self.symmetry_list) != 0: f.write('# symmetry_list: < {:} >\n'.format( self.file_line_symmetry)) if len(self.offset_list) != 0: f.write('# offset_list: < {:} >\n'.format( self.file_line_offset)) if len(self.counter_list) != 0: f.write('# counter_list: < {:} >\n'.format( self.file_line_counter)) if len(self.pn_limit) != 0: tmp = [str(i[0] + 1) + i[1] for i in self.pn_limit] f.write('# pn_limit: < {:} >\n'.format(tmp)) f.write('# total_charge: < {:} >\n'.format(self.total_charge)) f.write('# bool_neutral: < {:} >\n'.format(self.bool_neutral)) f.write('# bool_nozero: < {:} >\n\n'.format(self.bool_nozero)) if self.charge_path is None: f.write('# charge_range file: < NotDefined >\n') else: f.write('# charge_range file: < {:} >\n'.format( self.charge_path)) f.write('# For each entry, the charge_range:\n') j = 1 for i in self.charge_list: f.write('#ATOM {:>4} {:>6} {:>6}\n'.format( j, i[0], i[1])) j += 1 f.write('\n\n# generated charge pairs: \n\n') for i in self.chargepair: f.write('PAIR ') for j in i: f.write('{:>7.3}'.format(j)) f.write('\n') f.write('\n\n')
def file_print(self): fname = file_gen_new(self.fname,fextend='txt') with open(fname,mode='wt') as f: f.write('# This is the randomly generated charge pairs based on charge_range_list \n\n') if self.symmetry_list is not None: f.write('# The symmetry_list used is:\n') f.write('# {:s}\n\n'.format(self.prolist.file_line_symmetry)) if len(self.prolist.file_line_offset) != 0: f.write('# The offset_list used is:\n') f.write('# {:s}\n\n'.format(self.prolist.file_line_offset)) if (self.counter_list is not None) and len(self.counter_list) != 0: f.write('# The counter_list used is:\n') f.write('# {:s}\n\n'.format(self.prolist.file_line_counter)) if len(self.pn_limit) != 0: f.write('# The pn_limit used is:\n') f.write('# {:s}\n\n'.format(self.file_line_pn_limit)) f.write('# The total_charge is: < {:} >\n\n'.format(self.total_charge)) f.write('# The bool_neutral is: < {:s} >\n\n'.format('ON' if self.bool_neutral else 'OFF')) f.write('# The bool_nozero is: < {:s} >\n\n'.format('ON' if self.bool_nozero else 'OFF')) if isinstance(self.charge_path,str): f.write('# The used charge_range file is:\n# {:s}\n\n'.format(self.charge_path)) f.write('# For each entry, the charge_range is:\n\n') j = 1 for i in self.charge_list: f.write('# ATOM {:>3} {:>8} {:>8}\n'.format(j,i[0],i[1])) j += 1 f.write('\n\n# The randomly generated charges are: \n\n') for i in self.chargepair: f.write('PAIR ') for j in i: f.write('{:>7.3}'.format(j)) f.write('\n') f.write('\n\n')
def figure_plot(self): cmap = plt.get_cmap(self.color_map) fig = plt.figure(facecolor='w', figsize=(10, 6)) ax = fig.add_subplot(111) ax.set_yticks(range(len(self.yticklist))) ax.set_yticklabels(self.yticklist) ax.get_xaxis().set_visible(False) ax.set_title('Error Tolerance: {}, Percent: {}'.format( self.error_tolerance, self.percent)) getcmap = ax.imshow(self.prolist, cmap=cmap, aspect='auto') cb = plt.colorbar(mappable=getcmap, shrink=1.0, pad=0.02) cb.set_ticks([]) pfname = file_gen_new(self.fname, fextend='png', foriginal=False) pfname = pfname[:pfname.rfind('.png')] plt.tight_layout() fig.savefig(pfname)
def file_print(self): """write to file""" self.figure_plot() pfname = file_gen_new(self.fname, fextend='txt', foriginal=False) print('Note: new file < {:} >'.format(pfname)) with open(pfname, mode='wt') as f: f.write('# Final calculation result (not normalized)\n\n') f.write('# input file: < {:} >\n'.format(self.filepath)) f.write('# error_tolerance: < {:} >\n'.format( self.error_tolerance)) f.write('# percent_range: < {:} >\n'.format(self.percent)) f.write('# stepsize: < {:} >\n'.format(self.stepsize)) f.write('# pallette_number: < {:} >\n\n\n'.format( self.pallette_nm)) f.write('# Column corresponds to its own data range (optimized)\n') f.write('# For each different atomtype, charge range is:\n') for i, j in enumerate(self.valuerangelist): f.write('# {:}'.format(self.atomtype_list[i])) f.write(' {:>8.3f} {:>8.3f}\n'.format(j[0], j[1])) f.write('\n\n') f.write('# Feature Statistical Standard Error Selection\n') f.write('# the most influenced atomtype sequence is:\n') f.write('#') for i in self.ndxlist: f.write(' {:} '.format(self.atomtype_list[i])) f.write('\n\n\n') f.write('# Number of selection is: < {:} >\n'.format(self.pnm)) f.write('# Dataset is:\n') for line in self.profile: f.write(line) f.write('\n')
def file_print(self): """overwrite parent method""" self.fname = file_gen_new(self.fname, fextend='txt', foriginal=False) print('Note: new file < {:} >'.format(self.fname)) with open(self.fname, mode='wt') as f: f.write('# Genetic Algorithm Machine Learning\n') f.write('# Total number of charge_pairs are: < {:} >\n\n'.format( self.gennm)) if len(self.symmetry_list) != 0: f.write('# symmetry_list: < {:} >\n'.format( self.file_line_symmetry)) if len(self.offset_list) != 0: f.write('# offset_list: < {:} >\n'.format( self.file_line_offset)) f.write('# offset_nm: < {:} >\n'.format(self.offset_nm)) if len(self.counter_list) != 0: f.write('# counter_list: < {:} >\n'.format( self.file_line_counter)) if len(self.pn_limit) != 0: tmp = [str(i[0] + 1) + i[1] for i in self.pn_limit] line = ','.join(tmp).strip(',') f.write('# pn_limit: < {:} >\n\n'.format(line)) f.write('# ratio: (ML:Average:Mutation) < {:} >\n'.format( self.ratio)) f.write('# using ratio: (ML:Average:Mutation) < {:} >\n'.format( self.ratio_new)) f.write('# threshold: < {:} >\n'.format(self.threshold)) f.write('# total_charge: < {:} >\n\n'.format(self.total_charge)) f.write('# bool_neutral: < {:} >\n'.format(self.bool_neutral)) f.write('# bool_nozero: < {:} >\n\n'.format(self.bool_nozero)) if self.file_path is not None: f.write('# file_path: < {:} >\n'.format(self.file_path)) if self.charge_path is not None: f.write('# charge_path: < {:} >\n\n'.format(self.charge_path)) nm_nor = len(self.chargepair_nor) if nm_nor > 0: f.write('# normal charge_range:\n') j = 1 for i in self.charge_list_nor: f.write('#ATOM {:>4} {:>7} {:>7}\n'.format( j, i[0], i[1])) j += 1 f.write('\n\n') print( 'Number of charge pairs generated by the normal charge range are: ', nm_nor) f.write( '# The charge_pair generated by normal charge_range: ({:})\n\n' .format(nm_nor)) for i in self.chargepair_nor: f.write('PAIR ') for j in i: f.write('{:>7}'.format(j)) f.write('\n') nm_new = len(self.chargepair_new) if nm_new > 0: f.write('\n\n# charge_extend_by: < {:} >\n'.format( self.charge_extend_by)) f.write( '# With the addition or subtraction, or keeping constant, in both low and high bound\n' ) f.write('# New charge_range:\n\n') j = 1 for i in self.charge_list_new: f.write('#ATOM {:>4} {:>7} {:>7}\n'.format( j, round(i[0], 3), round(i[1], 3))) j += 1 f.write('\n\n') print( 'Number of charge pairs generated by the new charge range are: ', nm_new) f.write( '# The charge_pair generated by modified charge_range: ({:})\n\n' .format(nm_new)) for i in self.chargepair_new: f.write('PAIR ') for j in i: f.write('{:>7}'.format(j)) f.write('\n') if self.file_path is not None: f.write('\n\n') nm_ml = len(self.chargepair_ml) if nm_ml > 0: print( 'Number of charge pairs generated by the Genetic Algorithm are: ', nm_ml) f.write( '# The charge_pair generated by Genetic Algorithm: ({:})\n\n' .format(nm_ml)) for i in self.chargepair_ml: f.write('PAIR ') for j in i: f.write('{:>7}'.format(j)) f.write('\n') nm_av = len(self.chargepair_av) if nm_av > 0: print('Number of charge_pairs generated by the Average are: ', nm_av) f.write( '\n\n# The charge_pair generated by Average: ({:})\n\n'. format(nm_av)) for i in self.chargepair_av: f.write('PAIR ') for j in i: f.write('{:>7}'.format(j)) f.write('\n')
def file_print(self): self.fname = file_gen_new(self.fname, fextend='txt', foriginal=False) print('The combined generated charge file name is:', end=' ') print(self.fname) with open(self.fname, mode='wt') as f: f.write( '# This is the genetic algorithm machine learning generated charge file\n' ) f.write( '# The total number of generated charge_pairs are: < {:} >\n\n' .format(self.gennm)) if len(self.symmetry_list) != 0: f.write('# The symmetry_list used is:\n') f.write('# {:}\n\n'.format(self.file_line_symmetry)) if len(self.file_line_offset) != 0: f.write('# The offset_list used is:\n') f.write('# {:}\n'.format(self.file_line_offset)) f.write('# The offset_nm used is: < {:} >\n\n'.format( self.offset_nm)) if len(self.reflist) != 0: f.write('# The counter_list used is:\n') f.write('# {:}\n\n'.format(self.file_line_counter)) if len(self.pn_limit) != 0: f.write('# The pn_limit used is:\n') f.write('# {:}\n\n'.format(self.file_line_limit)) if self.ratio is not None: f.write('# The ratio used is:\n') f.write('# {:}\n'.format(self.ratio)) f.write( '# For each entry, the threshold used is: < {:} >\n'.format( self.threshold)) f.write('# The bool_neutral is: < {:} >\n'.format( 'ON' if self.bool_neutral else 'OFF')) f.write('# The total_charge is: < {:} >\n\n'.format( self.total_charge)) if self.file_path is not None: f.write('# The file_path used is:\n') f.write('# {:}\n'.format(self.file_path)) if self.charge_path is not None: if isinstance(self.charge_path, str): f.write('# The charge_path used is:\n') f.write('# {:}\n\n'.format(self.charge_path)) f.write('# The normal charge_range used is:\n\n') j = 1 for i in self.charge_nor_list: f.write('# ATOM {:>4} {:>7} {:>7}\n'.format( j, i[0], i[1])) j += 1 f.write('\n\n') print( 'The number of charge_pairs generated by the normal charge range are: ', len(self.schemelist_nor)) f.write( '# The charge_pair generated by normal charge_range;\n\n') for i in self.schemelist_nor: f.write('PAIR ') for j in i: f.write('{:>7}'.format(j)) f.write('\n') f.write( '\n\n# The value of charge_extention is: < {:} >\n'.format( self.charge_extend_by)) f.write( '# With the addition or subtraction, or keeping constant, in both low and high bound\n' ) f.write('# The new charge_range used is:\n\n') j = 1 for i in self.charge_new_list: f.write('# ATOM {:>4} {:>7} {:>7}\n'.format( j, round(i[0], 3), round(i[1], 3))) j += 1 f.write('\n\n') print( 'The number of charge_pairs generated by the new charge range are: ', len(self.schemelist_new)) f.write( '# The charge_pair generated by modified charge_range;\n\n' ) for i in self.schemelist_new: f.write('PAIR ') for j in i: f.write('{:>7}'.format(j)) f.write('\n') if self.file_path is not None: f.write('\n\n') if len(self.galist_ml) != 0: print( 'The number of charge_pairs generated by the Genetic Algorithm are: ', len(self.galist_ml)) f.write( '# The charge_pair generated by Genetic Algorithm\n\n') for i in self.galist_ml: f.write('PAIR ') for j in i: f.write('{:>7}'.format(j)) f.write('\n') if len(self.galist_average) != 0: print( 'The number of charge_pairs generated by the Average are: ', len(self.galist_average)) f.write('\n\n# The charge_pair generated by Average\n\n') for i in self.galist_average: f.write('PAIR ') for j in i: f.write('{:>7}'.format(j)) f.write('\n')
def file_print(self): pfname = file_gen_new(self.fname, fextend='txt', foriginal=False) print('Note: new file < {:} >'.format(pfname)) with open(pfname, mode='wt') as f: f.write('# Simulation process result\n\n') f.write('# input file: < {:} >\n\n'.format(self.file)) f.write('# charge file: < {:} >\n\n'.format(self.chargefile)) f.write('# MAE: < {:} >\n'.format(self.MAE)) if self.bool_gas: f.write('# total number of atoms: < {:} >\n'.format( self.atomnm)) f.write('# temperature: < {:} K >\n'.format(self.temperature)) self.kwlist = [ 'HVAP' if i == 'potential' else i.capitalize() for i in self.kwlist ] f.write('\n') f.write('# corresponding Keywords and literature values are:\n') f.write('#Keywords: ') for kw in self.kwlist: f.write(' {:>8}'.format(kw)) f.write('\n#LiValues: ') for v in self.literature_value: f.write(' {:8}'.format(v)) f.write('\n\n\n') endlist = [] lenkw = len(self.kwlist) for cnt, pair in enumerate(self.prochargefile): bool_end = False line = 'PAIR ' for ch in pair: line += '{:>7.4f} '.format(ch) err = self.errlist[cnt] if 'NaN' in err: line += 'MAE NaN' else: maerr = sum([abs(tmp) for tmp in err]) / lenkw if maerr <= self.MAE: bool_end = True line += 'MAE {:>6.4f}'.format(maerr) for ndx, kw in enumerate(self.kwlist): line += ' {:} '.format(kw) if err[ndx] == 'NaN': line += ' NaN' else: line += '{:>7.4f}'.format(err[ndx]) f.write(line) f.write('\n') if bool_end: endlist.append(line.replace('PAIR', 'HEAD')) if len(endlist) != 0: f.write('\n\n') f.write('# The training MAE requirement is fulfilled\n') for t in endlist: f.write(t) f.write('\n')