def as_table(self, cluster_info): from libtbx.str_utils import wordwrap headers = [ "Cluster", "No. datasets", "Datasets", "Height", "Multiplicity", "Completeness", ] rows = [] for info in cluster_info: rows.append( [ "%i" % info.cluster_id, "%i" % len(info.labels), wordwrap(" ".join("%s" % l for l in info.labels)), "%.2g" % info.height, "%.1f" % info.multiplicity, "%.2f" % info.completeness, ] ) rows.insert(0, headers) return rows
def print_resids(resids): assert (len(resids) > 0) w = 0 line = " ".join([ resid.strip() for resid in resids ]) lines = str_utils.wordwrap(line, 60).split("\n") print(" residue IDs: %s" % lines[0], file=out) for line in lines[1:] : print(" %s" % line, file=out)
def print_resids (resids) : assert (len(resids) > 0) w = 0 line = " ".join([ resid.strip() for resid in resids ]) lines = str_utils.wordwrap(line, 60).split("\n") print >> out, " residue IDs: %s" % lines[0] for line in lines[1:] : print >> out, " %s" % line
def get_reflection_file_server(data_manager, params, datatype='x_ray'): ''' Convenience function for getting a reflection file server based on a selection of Miller arrays from the iotbx.data_manager.miller_array.miller_array_phil_str PHIL scope :params data_manager: DataManager with processed files :type data_manager: iotbx.data_manager.DataManager object :params params: PHIL extract with set parameters :type params: libtbx.phil.scope_extract object :params datatype: matches type property in miller_array_phil_str :type datatype: str :rtype: iotbx.reflection_file_utils.reflection_file_server object or None The function returns None if there are no files that match datatype. ''' filenames = list() labels = list() # find files if (hasattr(params, 'data')): try: for scope in params.data: if (scope.type == datatype): filenames.append(scope.file_name) labels.append(scope.labels) except (TypeError, AttributeError): raise Sorry( wordwrap( 'The "data" scope is not in the expected format. See iotbx.data_manager.miller_array.miller_array_phil_str for the expected format.' )) # get file server rfs = None if (len(filenames) > 0): rfs = data_manager.get_reflection_file_server(filenames=filenames, labels=labels) return rfs
def as_table(self, cluster_info): from libtbx.str_utils import wordwrap rows = [] headers = [ 'Cluster', 'Datasets', 'Height', 'Multiplicity', 'Completeness' ] for info in cluster_info: rows.append([ '%i' % info.cluster_id, wordwrap(' '.join('%s' % l for l in info.labels)), '%.2g' % info.height, '%.1f' % info.multiplicity, '%.2f' % info.completeness, ]) # sort table by completeness perm = flex.sort_permutation( flex.double(c.completeness for c in cluster_info)) rows = [rows[i] for i in perm] import tabulate return tabulate.tabulate(rows, headers, tablefmt='rst')
def process_phil(self, phil_list): '''' Process PHIL arguments Currently only handles command-line changes Will add inclusion of PHIL files from data_manager first, then command-line options ''' print('Processing PHIL parameters:', file=self.logger) print('-' * self.text_width, file=self.logger) print('', file=self.logger) printed_something = False data_sources = list() sources = list() unused_phil = list() # PHIL files are processed in order from command-line if (self.data_manager.has_phils()): phil_names = self.data_manager.get_phil_names() phil = list() print(' Adding PHIL files:', file=self.logger) print(' ------------------', file=self.logger) for name in phil_names: # remove DataManager scope since input files are already loaded phil_scope = self.data_manager.get_phil(name) for phil_object in phil_scope.objects: if (phil_object.name == 'data_manager'): phil_scope.objects.remove(phil_object) phil.append(phil_scope) print(' %s' % name, file=self.logger) data_sources.extend(phil) print('', file=self.logger) printed_something = True # command-line PHIL arguments override any previous settings and are # processed in given order def custom_processor(arg): unused_phil.append(arg) return True if (len(phil_list) > 0): interpreter = self.master_phil.command_line_argument_interpreter( home_scope='') print(' Adding command-line PHIL:', file=self.logger) print(' -------------------------', file=self.logger) for phil in phil_list: print(' %s' % phil, file=self.logger) print('', file=self.logger) printed_something = True working = interpreter.process_args( phil_list, custom_processor=custom_processor) if (len(working) > 0): sources.extend(working) if (self.namespace.overwrite): # override overwrite if True sources.append(iotbx.phil.parse('output.overwrite=True')) if ((len(data_sources) + len(sources)) > 0): self.working_phil, more_unused_phil = self.master_phil.fetch( sources=data_sources + sources, track_unused_definitions=True) unused_phil.extend(more_unused_phil) else: self.working_phil = self.master_phil # show unrecognized parameters and abort if (len(unused_phil) > 0): print(' Unrecognized PHIL parameters:', file=self.logger) print(' -----------------------------', file=self.logger) for phil in unused_phil: print(' %s' % phil, file=self.logger) print('', file=self.logger) error_message = 'Some PHIL parameters are not recognized by %s.\n' % \ self.prog error_message += wordwrap( 'Please run this program with the --show-defaults option to see what parameters are available.', max_chars=self.text_width) + '\n' error_message += wordwrap( 'PHIL parameters in files should be fully specified (e.g. "output.overwrite" instead of just "overwrite")', max_chars=self.text_width) + '\n' raise Sorry(error_message) if (not printed_something): print(' No PHIL parameters found', file=self.logger) print('', file=self.logger)
def process_phil(self, phil_list): '''' Process PHIL arguments Also checks PHIL arguments (command line and files) for parameters that specify files (.type = path) ''' print('Processing PHIL parameters:', file=self.logger) print('-' * self.text_width, file=self.logger) print('', file=self.logger) printed_something = False data_sources = list() sources = list() unused_phil = list() # PHIL files are processed in order from command-line if (self.data_manager.has_phils()): phil_names = self.data_manager.get_phil_names() phil = list() print(' Adding PHIL files:', file=self.logger) print(' ------------------', file=self.logger) for name in phil_names: # remove DataManager scope since input files are already loaded phil_scope = self.data_manager.get_phil(name) for phil_object in phil_scope.objects: if (phil_object.name == 'data_manager'): phil_scope.objects.remove(phil_object) phil.append(phil_scope) print(' %s' % name, file=self.logger) data_sources.extend(phil) print('', file=self.logger) printed_something = True # command-line PHIL arguments override any previous settings and are # processed in given order def custom_processor(arg): unused_phil.append(arg) return True if (len(phil_list) > 0): interpreter = self.master_phil.command_line_argument_interpreter( home_scope='') print(' Adding command-line PHIL:', file=self.logger) print(' -------------------------', file=self.logger) for phil in phil_list: print(' %s' % phil, file=self.logger) print('', file=self.logger) printed_something = True working = interpreter.process_args( phil_list, custom_processor=custom_processor) if (len(working) > 0): sources.extend(working) if (self.namespace.overwrite): # override overwrite if True sources.append(iotbx.phil.parse('output.overwrite=True')) if ((len(data_sources) + len(sources)) > 0): self.working_phil, more_unused_phil = self.master_phil.fetch( sources=data_sources + sources, track_unused_definitions=True) unused_phil.extend(more_unused_phil) else: self.working_phil = self.master_phil.fetch() # show unrecognized parameters and abort if (len(unused_phil) > 0): print(' Unrecognized PHIL parameters:', file=self.logger) print(' -----------------------------', file=self.logger) for phil in unused_phil: print(' %s' % phil, file=self.logger) print('', file=self.logger) error_message = 'Some PHIL parameters are not recognized by %s.\n' % \ self.prog error_message += wordwrap( 'Please run this program with the --show-defaults option to see what parameters are available.', max_chars=self.text_width) + '\n' error_message += wordwrap( 'PHIL parameters in files should be fully specified (e.g. "output.overwrite" instead of just "overwrite")', max_chars=self.text_width) + '\n' raise Sorry(error_message) # process input phil for file/directory defintions and add to DataManager # Note: if a PHIL file is input as a PHIL parameter, the contents of the # file will NOT be parsed and validated. The PHIL file should be provided # as a command-line argument. This is mostly for finding data files # defined by PHIL parameters that should be added to the DataManager diff_phil = self.master_phil.fetch_diff(self.working_phil) paths = self.check_phil_for_paths(diff_phil) if (len(paths) > 0): files = list() dirs = list() for path in paths: if (path is not None): if (os.path.isfile(path)): files.append(path) elif (os.path.isdir(path)): dirs.append(path) if (self.parse_files): self.process_files(files, message='Processing files from PHIL:') if (self.parse_dir): self.process_dir(dirs, message='Processing directories from PHIL:') if (not printed_something): print(' No PHIL parameters found', file=self.logger) print('', file=self.logger)