def _set_optimizer_type(self, new_optimizer_type: type): """ changes the current type of Optimizer and creates and applies a Optimizer of that type. @Warnings Should only be called via set_action_type which handles type checking. Parameters ---------- new_optimizer_type : t.Type[Filter] type of the new Filter Returns ------- NoReturn """ if new_optimizer_type == None: self.current_optimizer_type = None self.my_optimizer = None return if not new_optimizer_type in self.available_optimizer_types + [None]: raise TypeError(str(new_optimizer_type) + ' is not an available type of Optimizer') self.my_optimizer = new_optimizer_type(self.selected_atoms) # SWITCHTABLE FOR input function input_functions = u.do_nothing() if isinstance(self.my_optimizer, Optimizer.GreedyGraphOptimizer): input_function = qt_dialogs.create_multi_dialog( title='Parameters for GreedyGraphOptimizer', \ inputs=['number of restraints', 'maximal distance of restraints', 'tree-algorithm', 'optimize molecules pairs by'], \ options={'tree-algorithm': ['minmax', 'cog', 'prim', "biased_avg"], 'optimize molecules pairs by': ['None', 'convex_hull', 'pca_2d']}, \ default={'number of restraints': '4', 'maximal distance of restraints': '1.0', 'algorithm': 'minmax', 'optimize molecules pairs by': 'convex_hull'}) elif isinstance(self.my_optimizer, Optimizer.BruteForceRingOptimzer): input_function = qt_dialogs.create_multi_dialog( title='Parameters for BruteForceOptimizer', \ inputs=['number of restraints', 'maximal distance of restraints', 'algorithm', 'optimize molecules pairs by'], \ options={'algorithm': ['convex_hull', 'pca'], 'optimize molecules pairs by': ['None', 'convex_hull', 'pca_2d']}, \ default={'number of restraints': '4', 'maximal distance of restraints': '1.2', 'algorithm': 'pca', 'optimize molecules pairs by': 'pca_2d'}) elif isinstance(self.my_optimizer, Optimizer.MetaMoleculeRingOptimizer): input_function = qt_dialogs.create_multi_dialog( title='Parameters for BestMoleculeRingOptimizer', \ inputs=['number of restraints', 'maximal distance of restraints', 'algorithm', 'optimize molecules pairs by'], \ options={'algorithm': ['convex_hull', 'pca'], 'optimize molecules pairs by': ['convex_hull', 'pca_2d']}, \ default={'number of restraints': '4', 'maximal distance of restraints': '1.2', 'algorithm': 'pca', 'optimize molecules pairs by': 'pca_2d'}) if try_to_get_args(self.my_optimizer, input_function): time_start = time.time() try: self.selected_restraints = self.my_optimizer.make_restraints() time_stop = time.time() print('Optimized in ' + '{:0.1f}'.format(time_stop - time_start) + ' s', mv=3) except u.NoOptimalSolutionException as ex: print('Failed to find a optimal solution under the given conditions:', ex, mv=4) else: self.my_optimizer = None self.current_optimizer_type = None
def _set_optimizer_type(self, new_optimizer_type: type): ''' _set_optimizer_type changes the current type of Optimizer and creates and applies a Optimizer of that type. :warning: Should only be called via set_action_type which handles type checking. :param new_optimizer_type: type of the new Filter :type new_optimizer_type: t.Type[Filter] :return: None :rtype: None ''' if new_optimizer_type == None: self.current_optimizer_type = None self.my_optimizer = None return if not new_optimizer_type in self.available_optimizer_types + [None]: raise TypeError(str(new_optimizer_type) + ' is not an available type of Optimizer') self.my_optimizer = new_optimizer_type(self.selected_atoms) # TODO: See TODO in u.creat_multi_dialog # SWITCHTABLE FOR input function input_functions = u.do_nothing() # TODO: More elegant than these hardcoded input functions: Give each Optimizer etc. an attribute specifzing which args it needs, which we can than pass to create_multi_dialog # TODO: Generate new field in pyqt win to select if you want a chain, ring, or all to all connection if isinstance(self.my_optimizer, Optimizer.TreeHeuristicOptimizer): input_function = u.create_multi_dialog(title='Parameters for TreeHeuristicOptimizer', \ inputs=['number of restraints', 'maximal distance of restraints', 'tree-algorithm', 'optimize molecules pairs by'], \ options={'tree-algorithm': ['shortest', 'cog', 'prim', "biased_avg"], 'optimize molecules pairs by': ['None', 'convex_hull', 'pca_2d']}, \ default={'number of restraints': '4', 'maximal distance of restraints': '1.2', 'algorithm': 'shortest', 'optimize molecules pairs by': 'pca_2d'}) elif isinstance(self.my_optimizer, Optimizer.BruteForceRingOptimzer): input_function = u.create_multi_dialog(title='Parameters for BruteForceOptimizer', \ inputs=['number of restraints', 'maximal distance of restraints', 'algorithm', 'optimize molecules pairs by'], \ options={'algorithm': ['convex_hull', 'pca'], 'optimize molecules pairs by': ['None', 'convex_hull', 'pca_2d']}, \ default={'number of restraints': '4', 'maximal distance of restraints': '1.2', 'algorithm': 'pca', 'optimize molecules pairs by': 'pca_2d'}) elif isinstance(self.my_optimizer, Optimizer.MetaMoleculeRingOptimizer): input_function = u.create_multi_dialog(title='Parameters for BestMoleculeRingOptimizer', \ inputs=['number of restraints', 'maximal distance of restraints', 'algorithm', 'optimize molecules pairs by'], \ options={'algorithm': ['convex_hull', 'pca'], 'optimize molecules pairs by': ['convex_hull', 'pca_2d']}, \ default={'number of restraints': '4', 'maximal distance of restraints': '1.2', 'algorithm': 'pca', 'optimize molecules pairs by': 'pca_2d'}) if try_to_get_args(self.my_optimizer, input_function): time_start = time.time() try: self.selected_restraints = self.my_optimizer.make_restraints() time_stop = time.time() print('Optimized in ' + '{:0.1f}'.format(time_stop - time_start) + ' s', mv=3) except u.NoOptimalSolutionException as ex: print('Failed to find a optimal solution under the given conditions:', ex, mv=4) else: self.my_optimizer = None self.current_optimizer_type = None