def run_loop_input(self, lines, score=None): lines_iterator = iter(lines) while True: try: line = next(lines_iterator) except StopIteration: return self.ff cols = line.split() if cols[0] == 'DIR': self.direc = cols[1] if cols[0] == 'FFLD': # Import FF data. if cols[1] == 'read': if cols[2] == 'mm3.fld': self.ff = datatypes.MM3( os.path.join(self.direc, cols[2])) if 'prm' in line: self.ff = datatypes.TinkerFF( os.path.join(self.direc, cols[2])) if 'frcmod' in line: self.ff = datatypes.AmberFF( os.path.join(self.direc, cols[2])) self.ff.import_ff() self.ff.method = 'READ' with open(os.path.join(self.direc, cols[2]), 'r') as f: self.ff.lines = f.readlines() # Export FF data. if cols[1] == 'write': self.ff.export_ff(os.path.join(self.direc, cols[2])) # Trim parameters. if cols[0] == 'PARM': logger.log(20, '~~ SELECTING PARAMETERS ~~'.rjust(79, '~')) self.ff.params = parameters.trim_params_by_file( self.ff.params, os.path.join(self.direc, cols[1])) if cols[0] == 'LOOP': # Read lines that will be looped over. inner_loop_lines = [] line = next(lines_iterator) while line.split()[0] != 'END': inner_loop_lines.append(line) line = next(lines_iterator) # Make loop object and populate attributes. loop = Loop() loop.convergence = float(cols[1]) loop.direc = self.direc loop.ff = self.ff loop.args_ff = self.args_ff loop.args_ref = self.args_ref loop.ref_data = self.ref_data loop.loop_lines = inner_loop_lines # Log commands. pretty_loop_input(inner_loop_lines, name='OPTIMIZATION LOOP', score=self.ff.score) # Run inner loop. self.ff = loop.opt_loop() # Note: Probably want to update this to append the directory given # by the new DIR command. if cols[0] == 'RDAT': logger.log(20, '~~ CALCULATING REFERENCE DATA ~~'.rjust(79, '~')) if len(cols) > 1: self.args_ref = ' '.join(cols[1:]).split() self.ref_data = opt.return_ref_data(self.args_ref) if cols[0] == 'CDAT': logger.log(20, '~~ CALCULATING FF DATA ~~'.rjust(79, '~')) if len(cols) > 1: self.args_ff = ' '.join(cols[1:]).split() self.ff.data = calculate.main(self.args_ff) if cols[0] == 'COMP': # Deprecated # self.ff.score = compare.compare_data( # self.ref_data, self.ff.data) # if '-o' in cols: # compare.pretty_data_comp( # self.ref_data, # self.ff.data, # os.path.join(self.direc, cols[cols.index('-o') + 1])) # if '-p' in cols: # compare.pretty_data_comp( # self.ref_data, # self.ff.data, # doprint=True) output = False doprint = False r_dict = compare.data_by_type(self.ref_data) c_dict = compare.data_by_type(self.ff.data) r_dict, c_dict = compare.trim_data(r_dict, c_dict) if '-o' in cols: output = os.path.join(self.direc, cols[cols.index('-o') + 1]) if '-p' in cols: doprint = True self.ff.score = compare.compare_data(r_dict, c_dict, output=output, doprint=doprint) if cols[0] == 'GRAD': grad = gradient.Gradient(direc=self.direc, ff=self.ff, ff_lines=self.ff.lines, args_ff=self.args_ff) #### Should probably just write a function instead of looping #### this for every gradient method. This includes everything #### between the two lines of #. TR 20180112 ############################################################## for col in cols[1:]: if "lstsq" in col: g_args = col.split('=')[1].split(',') for arg in g_args: if arg == "True": grad.do_lstsq = True elif arg == False: grad.do_lstsq = False if 'radii' in arg: grad.lstsq_radii = [] radii_vals = re.search(r"\[(.+)\]", arg).group(1).split('/') if radii_vals == "None": grad.lstsq_radii = None else: for val in radii_vals: grad.lstsq_radii.append(float(val)) if 'cutoff' in arg: grad.lstsq_cutoff = [] cutoff_vals = re.search( r"\[(.+)\]", arg).group(1).split('/') if cutoff_vals == "None": grad.lstsq_cutoff = None else: if len(cutoff_vals) > 2 or \ len(cutoff_vals) < 2: raise Exception("Cutoff values must " \ "be between two numbers.") for val in cutoff_vals: grad.lstsq_cutoff.append(float(val)) elif "newton" in col: g_args = col.split('=')[1].split(',') for arg in g_args: if arg == "True": grad.do_newton = True elif arg == False: grad.do_newton = False if 'radii' in arg: grad.newton_radii = [] radii_vals = re.search(r"\[(.+)\]", arg).group(1).split('/') if radii_vals == 'None': grad.newton_radii = None else: for val in radii_vals: grad.newton_radii.append(float(val)) if 'cutoff' in arg: grad.newton_cutoff = [] cutoff_vals = re.search( r"\[(.+)\]", arg).group(1).split('/') if cutoff_vals == 'None': grad.newton_cutoff = None else: if len(cutoff_vals) > 2 or \ len(cutoff_vals) < 2: raise Exception("Cutoff values must " \ "be between two numbers.") for val in cutoff_vals: grad.newton_cutoff.append(float(val)) elif "levenberg" in col: g_args = col.split('=')[1].split(',') for arg in g_args: if arg == "True": grad.do_levenberg = True elif arg == False: grad.do_levenberg = False if 'radii' in arg: grad.levenberg_radii = [] radii_vals = re.search(r"\[(.+)\]", arg).group(1).split('/') if radii_vals == 'None': grad.levenberg_radii = None else: for val in radii_vals: grad.levenberg_radii.append(float(val)) if 'cutoff' in arg: grad.levenberg_cutoff = [] cutoff_vals = re.search( r"\[(.+)\]", arg).group(1).split('/') if cutoff_vals == 'None': grad.levenberg_cutoff = None else: if len(cutoff_vals) > 2 or \ len(cutoff_vals) < 2: raise Exception("Cutoff values must " \ "be between two numbers.") for val in cutoff_vals: grad.levenberg_cutoff.append( float(val)) if 'factor' in arg: grad.levenberg_cutoff = [] factor_vals = re.search( r"\[(.+)\]", arg).group(1).split('/') if factor_vals == 'None': grad.levenberg_factor = None else: for val in factor_vals: grad.levenberg_factor.append( float(val)) elif "lagrange" in col: g_args = col.split('=')[1].split(',') for arg in g_args: if arg == "True": grad.do_lagrange = True elif arg == False: grad.do_lagrange = False if 'radii' in arg: grad.lagrange_radii = [] radii_vals = re.search(r"\[(.+)\]", arg).group(1).split('/') if radii_vals == 'None': grad.lagrange_radii = None else: for val in radii_vals: grad.lagrange_radii.append(float(val)) if 'cutoff' in arg: grad.lagrange_cutoff = [] cutoff_vals = re.search( r"\[(.+)\]", arg).group(1).split('/') if cutoff_vals == 'None': grad.lagrange_cutoff = None else: if len(cutoff_vals) > 2 or \ len(cutoff_vals) < 2: raise Exception("Cutoff values must " \ "be between two numbers.") for val in cutoff_vals: grad.lagrange_cutoff.append(float(val)) if 'factor' in arg: grad.lagrange_factors = [] factor_vals = re.search( r"\[(.+)\]", arg).group(1).split('/') if factor_vals == 'None': grad.lagrange_factors = None else: for val in factor_vals: grad.lagrange_factors.append( float(val)) elif "svd" in col: g_args = col.split('=')[1].split(',') for arg in g_args: if arg == "True": grad.do_svd = True elif arg == False: grad.do_svd = False if 'radii' in arg: grad.svd_radii = [] radii_vals = re.search(r"\[(.+)\]", arg).group(1).split('/') if radii_vals == 'None': grad.svd_radii = None else: for val in radii_vals: grad.svd_radii.append(float(val)) if 'cutoff' in arg: grad.svd_cutoff = [] cutoff_vals = re.search( r"\[(.+)\]", arg).group(1).split('/') if cutoff_vals == 'None': grad.svd_cutoff = None else: if len(cutoff_vals) > 2 or \ len(cutoff_vals) < 2: raise Exception("Cutoff values must " \ "be between two numbers.") for val in cutoff_vals: grad.svd_cutoff.append(float(val)) if 'factor' in arg: grad.svd_cutoff = [] factor_vals = re.search( r"\[(.+)\]", arg).group(1).split('/') if factor_vals == 'None': grad.svd_factor = None else: for val in factor_vals: grad.svd_factor.append(float(val)) else: raise Exception("'{}' : Not Recognized".format(col)) ############################################################## self.ff = grad.run(ref_data=self.ref_data) if cols[0] == 'SIMP': simp = simplex.Simplex(direc=self.direc, ff=self.ff, ff_lines=self.ff.lines, args_ff=self.args_ff) for col in cols[1:]: if "max_params" in col: simp.max_params = col.split('=')[1] else: raise Exception("'{}' : Not Recognized".format(col)) self.ff = simp.run(r_data=self.ref_data) if cols[0] == 'WGHT': data_type = cols[1] co.WEIGHTS[data_type] = float(cols[2]) if cols[0] == 'STEP': param_type = cols[1] co.STEPS[param_type] = float(cols[2])
FF. """ old_ff.copy_attributes(new_ff) if len(old_ff.params) > len(new_ff.params): logger.log(15, ' -- Restoring {} parameters to new FF.'.format( len(old_ff.params) - len(new_ff.params))) # Backup new parameters. new_params = copy.deepcopy(new_ff.params) # Copy over all old parameters. new_ff.params = copy.deepcopy(old_ff.params) # Replace the old with the new. for i, param_o in enumerate(old_ff.params): for param_n in new_params: # Should replace this with a general index scheme. if param_o.mm3_row == param_n.mm3_row and \ param_o.mm3_col == param_n.mm3_col: new_ff.params[i] = copy.deepcopy(param_n) return new_ff if __name__ == '__main__': logging.config.dictConfig(co.LOG_SETTINGS) # Just for testing. ff = datatypes.MM3('b071/mm3.fld') ff.import_ff() ff.params = parameters.trim_params_by_file(ff.params, 'b071/params.txt') a = Simplex( direc='b071', ff=ff, args_ff=' -d b071 -me X002a.mae X002b.mae -mb X002a.mae', args_ref=' -d b071 -je X002a.mae X002b.mae -jb X002a.mae') a.run()
def run_loop_input(self, lines, score=None): lines_iterator = iter(lines) while True: try: line = lines_iterator.next() except StopIteration: return self.ff cols = line.split() if cols[0] == 'DIR': self.direc = cols[1] if cols[0] == 'FFLD': # Import FF data. if cols[1] == 'read': self.ff = datatypes.MM3(os.path.join(self.direc, cols[2])) self.ff.import_ff() self.ff.method = 'READ' with open(os.path.join(self.direc, cols[2]), 'r') as f: self.ff.lines = f.readlines() # Export FF data. if cols[1] == 'write': self.ff.export_ff(os.path.join(self.direc, cols[2])) # Trim parameters. if cols[0] == 'PARM': logger.log(20, '~~ SELECTING PARAMETERS ~~'.rjust(79, '~')) self.ff.params = parameters.trim_params_by_file( self.ff.params, os.path.join(self.direc, cols[1])) if cols[0] == 'LOOP': # Read lines that will be looped over. inner_loop_lines = [] line = lines_iterator.next() while line.split()[0] != 'END': inner_loop_lines.append(line) line = lines_iterator.next() # Make loop object and populate attributes. loop = Loop() loop.convergence = float(cols[1]) loop.direc = self.direc loop.ff = self.ff loop.args_ff = self.args_ff loop.args_ref = self.args_ref loop.ref_data = self.ref_data loop.loop_lines = inner_loop_lines # Log commands. pretty_loop_input(inner_loop_lines, name='OPTIMIZATION LOOP', score=self.ff.score) # Run inner loop. self.ff = loop.opt_loop() # Note: Probably want to update this to append the directory given # by the new DIR command. if cols[0] == 'RDAT': logger.log(20, '~~ CALCULATING REFERENCE DATA ~~'.rjust(79, '~')) if len(cols) > 1: self.args_ref = ' '.join(cols[1:]).split() self.ref_data = opt.return_ref_data(self.args_ref) if cols[0] == 'CDAT': logger.log(20, '~~ CALCULATING FF DATA ~~'.rjust(79, '~')) if len(cols) > 1: self.args_ff = ' '.join(cols[1:]).split() self.ff.data = calculate.main(self.args_ff) if cols[0] == 'COMP': self.ff.score = compare.compare_data(self.ref_data, self.ff.data) if '-o' in cols: compare.pretty_data_comp( self.ref_data, self.ff.data, os.path.join(self.direc, cols[cols.index('-o') + 1])) if '-p' in cols: compare.pretty_data_comp(self.ref_data, self.ff.data) if cols[0] == 'GRAD': grad = gradient.Gradient(direc=self.direc, ff=self.ff, ff_lines=self.ff.lines, args_ff=self.args_ff) self.ff = grad.run(ref_data=self.ref_data) if cols[0] == 'SIMP': simp = simplex.Simplex(direc=self.direc, ff=self.ff, ff_lines=self.ff.lines, args_ff=self.args_ff) self.ff = simp.run(r_data=self.ref_data) if cols[0] == 'WGHT': data_type = cols[1] co.WEIGHTS[data_type] = float(cols[2])
def run_loop_input(self, lines, score=None): lines_iterator = iter(lines) while True: try: line = next(lines_iterator) except StopIteration: return self.ff cols = line.split() if cols[0] == 'DIR': self.direc = cols[1] if cols[0] == 'FFLD': # Import FF data. if cols[1] == 'read': if cols[2] == 'mm3.fld': self.ff = datatypes.MM3(os.path.join(self.direc, cols[2])) if '.prm' in cols[2]: self.ff = datatypes.TinkerFF(os.path.join(self.direc, cols[2])) self.ff.import_ff() self.ff.method = 'READ' with open(os.path.join(self.direc, cols[2]), 'r') as f: self.ff.lines = f.readlines() # Export FF data. if cols[1] == 'write': self.ff.export_ff(os.path.join(self.direc, cols[2])) # Trim parameters. if cols[0] == 'PARM': logger.log(20, '~~ SELECTING PARAMETERS ~~'.rjust(79, '~')) self.ff.params = parameters.trim_params_by_file( self.ff.params, os.path.join(self.direc, cols[1])) if cols[0] == 'LOOP': # Read lines that will be looped over. inner_loop_lines = [] line = next(lines_iterator) while line.split()[0] != 'END': inner_loop_lines.append(line) line = next(lines_iterator) # Make loop object and populate attributes. loop = Loop() loop.convergence = float(cols[1]) loop.direc = self.direc loop.ff = self.ff loop.args_ff = self.args_ff loop.args_ref = self.args_ref loop.ref_data = self.ref_data loop.loop_lines = inner_loop_lines # Log commands. pretty_loop_input( inner_loop_lines, name='OPTIMIZATION LOOP', score=self.ff.score) # Run inner loop. self.ff = loop.opt_loop() # Note: Probably want to update this to append the directory given # by the new DIR command. if cols[0] == 'RDAT': logger.log( 20, '~~ CALCULATING REFERENCE DATA ~~'.rjust(79, '~')) if len(cols) > 1: self.args_ref = ' '.join(cols[1:]).split() self.ref_data = opt.return_ref_data(self.args_ref) if cols[0] == 'CDAT': logger.log( 20, '~~ CALCULATING FF DATA ~~'.rjust(79, '~')) if len(cols) > 1: self.args_ff = ' '.join(cols[1:]).split() self.ff.data = calculate.main(self.args_ff) if cols[0] == 'COMP': # Deprecated # self.ff.score = compare.compare_data( # self.ref_data, self.ff.data) # if '-o' in cols: # compare.pretty_data_comp( # self.ref_data, # self.ff.data, # os.path.join(self.direc, cols[cols.index('-o') + 1])) # if '-p' in cols: # compare.pretty_data_comp( # self.ref_data, # self.ff.data, # doprint=True) output = False doprint = False r_dict = compare.data_by_type(self.ref_data) c_dict = compare.data_by_type(self.ff.data) r_dict, c_dict = compare.trim_data(r_dict,c_dict) if '-o' in cols: output = os.path.join(self.direc, cols[cols.index('-o') +1]) if '-p' in cols: doprint = True self.ff.score = compare.compare_data( r_dict, c_dict, output=output, doprint=doprint) if cols[0] == 'GRAD': grad = gradient.Gradient( direc=self.direc, ff=self.ff, ff_lines=self.ff.lines, args_ff=self.args_ff) #### Should probably just write a function instead of looping #### this for every gradient method. This includes everything #### between the two lines of #. TR 20180112 ############################################################## for col in cols[1:]: if "lstsq" in col: g_args = col.split('=')[1].split(',') for arg in g_args: if arg == "True": grad.do_lstsq=True elif arg == False: grad.do_lstsq=False if 'radii' in arg: grad.lstsq_radii = [] radii_vals = re.search( r"\[(.+)\]",arg).group(1).split('/') if radii_vals == "None": grad.lstsq_radii = None else: for val in radii_vals: grad.lstsq_radii.append(float(val)) if 'cutoff' in arg: grad.lstsq_cutoff = [] cutoff_vals = re.search( r"\[(.+)\]",arg).group(1).split('/') if cutoff_vals == "None": grad.lstsq_cutoff = None else: if len(cutoff_vals) > 2 or \ len(cutoff_vals) < 2: raise Exception("Cutoff values must " \ "be between two numbers.") for val in cutoff_vals: grad.lstsq_cutoff.append(float(val)) elif "newton" in col: g_args = col.split('=')[1].split(',') for arg in g_args: if arg == "True": grad.do_newton=True elif arg == False: grad.do_newton=False if 'radii' in arg: grad.newton_radii = [] radii_vals = re.search( r"\[(.+)\]",arg).group(1).split('/') if radii_vals=='None': grad.newton_radii = None else: for val in radii_vals: grad.newton_radii.append(float(val)) if 'cutoff' in arg: grad.newton_cutoff = [] cutoff_vals = re.search( r"\[(.+)\]",arg).group(1).split('/') if cutoff_vals=='None': grad.newton_cutoff = None else: if len(cutoff_vals) > 2 or \ len(cutoff_vals) < 2: raise Exception("Cutoff values must " \ "be between two numbers.") for val in cutoff_vals: grad.newton_cutoff.append(float(val)) elif "levenberg" in col: g_args = col.split('=')[1].split(',') for arg in g_args: if arg == "True": grad.do_levenberg=True elif arg == False: grad.do_levenberg=False if 'radii' in arg: grad.levenberg_radii = [] radii_vals = re.search( r"\[(.+)\]",arg).group(1).split('/') if radii_vals=='None': grad.levenberg_radii = None else: for val in radii_vals: grad.levenberg_radii.append(float(val)) if 'cutoff' in arg: grad.levenberg_cutoff = [] cutoff_vals = re.search( r"\[(.+)\]",arg).group(1).split('/') if cutoff_vals=='None': grad.levenberg_cutoff = None else: if len(cutoff_vals) > 2 or \ len(cutoff_vals) < 2: raise Exception("Cutoff values must " \ "be between two numbers.") for val in cutoff_vals: grad.levenberg_cutoff.append(float(val)) if 'factor' in arg: grad.levenberg_cutoff = [] factor_vals = re.search( r"\[(.+)\]",arg).group(1).split('/') if factor_vals=='None': grad.levenberg_factor = None else: for val in factor_vals: grad.levenberg_factor.append(float(val)) elif "lagrange" in col: g_args = col.split('=')[1].split(',') for arg in g_args: if arg == "True": grad.do_lagrange=True elif arg == False: grad.do_lagrange=False if 'radii' in arg: grad.lagrange_radii = [] radii_vals = re.search( r"\[(.+)\]",arg).group(1).split('/') if radii_vals=='None': grad.lagrange_radii = None else: for val in radii_vals: grad.lagrange_radii.append(float(val)) if 'cutoff' in arg: grad.lagrange_cutoff = [] cutoff_vals = re.search( r"\[(.+)\]",arg).group(1).split('/') if cutoff_vals=='None': grad.lagrange_cutoff = None else: if len(cutoff_vals) > 2 or \ len(cutoff_vals) < 2: raise Exception("Cutoff values must " \ "be between two numbers.") for val in cutoff_vals: grad.lagrange_cutoff.append(float(val)) if 'factor' in arg: grad.lagrange_factors = [] factor_vals = re.search( r"\[(.+)\]",arg).group(1).split('/') if factor_vals=='None': grad.lagrange_factors = None else: for val in factor_vals: grad.lagrange_factors.append(float(val)) elif "svd" in col: g_args = col.split('=')[1].split(',') for arg in g_args: if arg == "True": grad.do_svd=True elif arg == False: grad.do_svd=False if 'radii' in arg: grad.svd_radii = [] radii_vals = re.search( r"\[(.+)\]",arg).group(1).split('/') if radii_vals=='None': grad.svd_radii = None else: for val in radii_vals: grad.svd_radii.append(float(val)) if 'cutoff' in arg: grad.svd_cutoff = [] cutoff_vals = re.search( r"\[(.+)\]",arg).group(1).split('/') if cutoff_vals=='None': grad.svd_cutoff = None else: if len(cutoff_vals) > 2 or \ len(cutoff_vals) < 2: raise Exception("Cutoff values must " \ "be between two numbers.") for val in cutoff_vals: grad.svd_cutoff.append(float(val)) if 'factor' in arg: grad.svd_cutoff = [] factor_vals = re.search( r"\[(.+)\]",arg).group(1).split('/') if factor_vals=='None': grad.svd_factor = None else: for val in factor_vals: grad.svd_factor.append(float(val)) else: raise Exception("'{}' : Not Recognized".format(col)) ############################################################## self.ff = grad.run(ref_data=self.ref_data) if cols[0] == 'SIMP': simp = simplex.Simplex( direc=self.direc, ff=self.ff, ff_lines=self.ff.lines, args_ff=self.args_ff) for col in cols[1:]: if "max_params" in col: simp.max_params = col.split('=')[1] else: raise Exception("'{}' : Not Recognized".format(col)) self.ff = simp.run(r_data=self.ref_data) if cols[0] == 'WGHT': data_type = cols[1] co.WEIGHTS[data_type] = float(cols[2]) if cols[0] == 'STEP': param_type = cols[1] co.STEPS[param_type] = float(cols[2])
def run_loop_input(self, lines, score=None): lines_iterator = iter(lines) while True: try: line = lines_iterator.next() except StopIteration: return self.ff cols = line.split() if cols[0] == 'DIR': self.direc = cols[1] if cols[0] == 'FFLD': # Import FF data. if cols[1] == 'read': self.ff = datatypes.MM3(os.path.join(self.direc, cols[2])) self.ff.import_ff() self.ff.method = 'READ' with open(os.path.join(self.direc, cols[2]), 'r') as f: self.ff.lines = f.readlines() # Export FF data. if cols[1] == 'write': self.ff.export_ff(os.path.join(self.direc, cols[2])) # Trim parameters. if cols[0] == 'PARM': logger.log(20, '~~ SELECTING PARAMETERS ~~'.rjust(79, '~')) self.ff.params = parameters.trim_params_by_file( self.ff.params, os.path.join(self.direc, cols[1])) if cols[0] == 'LOOP': # Read lines that will be looped over. inner_loop_lines = [] line = lines_iterator.next() while line.split()[0] != 'END': inner_loop_lines.append(line) line = lines_iterator.next() # Make loop object and populate attributes. loop = Loop() loop.convergence = float(cols[1]) loop.direc = self.direc loop.ff = self.ff loop.args_ff = self.args_ff loop.args_ref = self.args_ref loop.ref_data = self.ref_data loop.loop_lines = inner_loop_lines # Log commands. pretty_loop_input( inner_loop_lines, name='OPTIMIZATION LOOP', score=self.ff.score) # Run inner loop. self.ff = loop.opt_loop() # Note: Probably want to update this to append the directory given # by the new DIR command. if cols[0] == 'RDAT': logger.log( 20, '~~ CALCULATING REFERENCE DATA ~~'.rjust(79, '~')) if len(cols) > 1: self.args_ref = ' '.join(cols[1:]).split() self.ref_data = opt.return_ref_data(self.args_ref) if cols[0] == 'CDAT': logger.log( 20, '~~ CALCULATING FF DATA ~~'.rjust(79, '~')) if len(cols) > 1: self.args_ff = ' '.join(cols[1:]).split() self.ff.data = calculate.main(self.args_ff) if cols[0] == 'COMP': self.ff.score = compare.compare_data( self.ref_data, self.ff.data) if '-o' in cols: compare.pretty_data_comp( self.ref_data, self.ff.data, os.path.join(self.direc, cols[cols.index('-o') + 1])) if '-p' in cols: compare.pretty_data_comp( self.ref_data, self.ff.data) if cols[0] == 'GRAD': grad = gradient.Gradient( direc=self.direc, ff=self.ff, ff_lines=self.ff.lines, args_ff=self.args_ff) self.ff = grad.run(ref_data=self.ref_data) if cols[0] == 'SIMP': simp = simplex.Simplex( direc=self.direc, ff=self.ff, ff_lines=self.ff.lines, args_ff=self.args_ff) self.ff = simp.run(r_data=self.ref_data) if cols[0] == 'WGHT': data_type = cols[1] co.WEIGHTS[data_type] = float(cols[2])
old_ff.copy_attributes(new_ff) if len(old_ff.params) > len(new_ff.params): logger.log( 15, ' -- Restoring {} parameters to new FF.'.format( len(old_ff.params) - len(new_ff.params))) # Backup new parameters. new_params = copy.deepcopy(new_ff.params) # Copy over all old parameters. new_ff.params = copy.deepcopy(old_ff.params) # Replace the old with the new. for i, param_o in enumerate(old_ff.params): for param_n in new_params: # Should replace this with a general index scheme. if param_o.mm3_row == param_n.mm3_row and \ param_o.mm3_col == param_n.mm3_col: new_ff.params[i] = copy.deepcopy(param_n) return new_ff if __name__ == '__main__': logging.config.dictConfig(co.LOG_SETTINGS) # Just for testing. ff = datatypes.MM3('b071/mm3.fld') ff.import_ff() ff.params = parameters.trim_params_by_file(ff.params, 'b071/params.txt') a = Simplex(direc='b071', ff=ff, args_ff=' -d b071 -me X002a.mae X002b.mae -mb X002a.mae', args_ref=' -d b071 -je X002a.mae X002b.mae -jb X002a.mae') a.run()