def run(args): from dials.util.options import OptionParser from dials.util.options import flatten_datablocks from dials.util.options import flatten_experiments from dials.util.options import flatten_reflections parser = OptionParser( phil=master_phil, read_datablocks=True, read_experiments=True, read_reflections=True, check_format=False) params, options = parser.parse_args(show_diff_phil=True) datablocks = flatten_datablocks(params.input.datablock) experiments = flatten_experiments(params.input.experiments) reflections = flatten_reflections(params.input.reflections)[0] if len(params.input.reflections) == 2: reflections2 = flatten_reflections(params.input.reflections)[1] else: reflections2 = None # find the reflections in the second set that DO NOT match those in the # first set mask, _ = reflections2.match_with_reference(reflections) reflections2 = reflections2.select(~mask) print "{0} reflections from the second set do not match the first". \ format(len(reflections2)) #reflections2 = reflections2.select(reflections2["miller_index"] == (-7,2,-25)) if len(datablocks) == 0: if len(experiments) > 0: imagesets = experiments.imagesets() else: parser.print_help() return elif len(datablocks) > 1: raise Sorry("Only one DataBlock can be processed at a time") else: imagesets = datablocks[0].extract_imagesets() if len(imagesets) > 1: raise Sorry("Only one ImageSet can be processed at a time") imageset = imagesets[0] import wxtbx.app a = wxtbx.app.CCTBXApp(0) a.settings = params f = PredRelpViewer( None, -1, "Prediction reciprocal lattice viewer", size=(1024,768)) f.load_reflections2(reflections2) f.load_models(imageset, reflections) f.Show() a.SetTopWindow(f) #a.Bind(wx.EVT_WINDOW_DESTROY, lambda evt: tb_icon.Destroy(), f) a.MainLoop()
def run(args): import libtbx.load_env usage = "%s [options] experiment.json indexed.pickle" % libtbx.env.dispatcher_name parser = OptionParser( usage=usage, phil=phil_scope, read_reflections=True, read_experiments=True, check_format=False, epilog=help_message, ) params, options = parser.parse_args(show_diff_phil=True) reflections = flatten_reflections(params.input.reflections) experiments = flatten_experiments(params.input.experiments) if len(reflections) == 0 or len(experiments) == 0: parser.print_help() return assert len(reflections) == 1 assert len(experiments) == 1 experiment = experiments[0] reflections = reflections[0] test_P1_crystal_indexing(reflections, experiment, params) test_crystal_pointgroup_symmetry(reflections, experiment, params)
def run(args): from dials.util.options import OptionParser from dials.util.options import flatten_experiments from dials.util.options import flatten_reflections import libtbx.load_env usage = "%s [options] integrated.pickle experiments.json" % ( libtbx.env.dispatcher_name) parser = OptionParser( usage=usage, phil=phil_scope, read_experiments=True, read_reflections=True, check_format=False, epilog=help_message) params, options = parser.parse_args(show_diff_phil=False) experiments = flatten_experiments(params.input.experiments) reflections = flatten_reflections(params.input.reflections) if len(experiments) != 1 or len(reflections) != 1: parser.print_help() exit() if not 'shoebox' in reflections[0]: print 'Please add shoeboxes to reflection pickle' exit() results = main(reflections[0], experiments[0], params) if results: print 'mean result: %.3f' % (sum(results) / len(results))
def run(args): import libtbx.load_env from dials.util.options import OptionParser from dials.util.options import flatten_reflections from libtbx.utils import Sorry from libtbx.phil import parse phil_scope = parse( """ hklout = hklout.pickle .type = str .help = "The output pickle file" """ ) usage = "%s integrated.pickle [hklout=hklout.pickle]" % (libtbx.env.dispatcher_name) parser = OptionParser(usage=usage, read_reflections=True, check_format=False, phil=phil_scope) params, options = parser.parse_args(show_diff_phil=True) reflections = flatten_reflections(params.input.reflections) if len(reflections) != 1: raise Sorry("exactly 1 reflection table must be specified") integrated_data = reflections[0] filter_good_reflections(integrated_data).as_pickle(params.hklout)
def run(self): ''' Parse the options. ''' from dials.util.options import flatten_experiments, flatten_reflections # Parse the command line arguments params, options = self.parser.parse_args(show_diff_phil=True) self.params = params experiments = flatten_experiments(params.input.experiments) reflections = flatten_reflections(params.input.reflections) assert len(reflections) == len(experiments) == 1 reflections = reflections[0] exp = experiments[0] from dials.algorithms.indexing import index_reflections from dials.algorithms.indexing.indexer import indexer_base reflections['id'] = flex.int(len(reflections), -1) reflections['imageset_id'] = flex.int(len(reflections), 0) reflections = indexer_base.map_spots_pixel_to_mm_rad(reflections, exp.detector, exp.scan) indexer_base.map_centroids_to_reciprocal_space( reflections, exp.detector, exp.beam, exp.goniometer,) index_reflections(reflections, experiments, params.d_min, tolerance=0.3) indexed_reflections = reflections.select(reflections['miller_index'] != (0,0,0)) print "Indexed %d reflections out of %d"%(len(indexed_reflections), len(reflections)) easy_pickle.dump("indexedstrong.pickle", indexed_reflections)
def run(self): '''Execute the script.''' from dials.array_family import flex # import dependency from dials.util.options import flatten_reflections from libtbx.utils import Sorry # Parse the command line params, options = self.parser.parse_args(show_diff_phil=True) reflections = flatten_reflections(params.input.reflections) if len(reflections) == 0: self.parser.print_help() return if len(reflections) != 1: raise Sorry('exactly 1 reflection table must be specified') reflections = reflections[0] # Check the key is valid assert(params.key in reflections) # Sort the reflections print "Sorting by %s with reverse=%r" % (params.key, params.reverse) reflections.sort(params.key, params.reverse) if options.verbose > 0: print "Head of sorted list " + attr + ":" n = min(len(reflections), 10) for i in range(10): print (reflections[i][attr]) # Save sorted reflections to file if params.output: print "Saving reflections to {0}".format(params.output) reflections.as_pickle(params.output) return
def run(self): '''Execute the script.''' from dials.array_family import flex from dials.util.options import flatten_datablocks from dials.util.options import flatten_reflections from time import time from dials.util import log from logging import info, debug from libtbx.utils import Sorry start_time = time() # Parse the command line params, options = self.parser.parse_args(show_diff_phil=False) # Configure the logging log.config( params.verbosity, info=params.output.log, debug=params.output.debug_log) from dials.util.version import dials_version info(dials_version()) # Log the diff phil diff_phil = self.parser.diff_phil.as_str() if diff_phil is not '': info('The following parameters have been modified:\n') info(diff_phil) # Ensure we have a data block datablocks = flatten_datablocks(params.input.datablock) reflections = flatten_reflections(params.input.reflections) if len(datablocks) == 0 and len(reflections) == 0: self.parser.print_help() return elif len(datablocks) != len(reflections): raise Sorry("Must have same number of datablocks and reflection tables") # Combine the datablocks and reflections datablock, reflections = combine( datablocks, reflections, params) # Save the reflections to file info('\n' + '-' * 80) reflections.as_pickle(params.output.reflections) info('Saved {0} reflections to {1}'.format( len(reflections), params.output.reflections)) # Save the datablock from dxtbx.datablock import DataBlockDumper info('Saving datablocks to {0}'.format( params.output.datablock)) dump = DataBlockDumper(datablocks) dump.as_file(params.output.datablock) # Print the time info("Time Taken: %f" % (time() - start_time))
def run(self): from dials.util.options import flatten_reflections from dials.viewer.viewer_interface import extract_n_show in_case_there_is_given_more_than_one_table = ''' # Parse the command line params, options = self.parser.parse_args(show_diff_phil=True) reflections = flatten_reflections(params.input.reflections) if len(reflections) == 0: self.parser.print_help() return #opens and closes the viewer for each new reflection table for table in reflections: print "table =", table extract_n_show(table) #''' # Parse the command line params, options = self.parser.parse_args(show_diff_phil=True) table = flatten_reflections(params.input.reflections) print "params, options =", params, options if len(table) == 0: self.parser.print_help() return extract_n_show(table[0])
def run(self): '''Execute the script.''' from dials.util.options import flatten_reflections, flatten_experiments # Parse the command line params, options = self.parser.parse_args(show_diff_phil=False) reflections = flatten_reflections(params.input.reflections) experiments = flatten_experiments(params.input.experiments) # Try to load the models and data nexp = len(experiments) if nexp == 0: print "No Experiments found in the input" self.parser.print_help() return if len(reflections) == 0: print "No reflection data found in the input" self.parser.print_help() return if len(reflections) > 1: raise Sorry("Only one reflections list can be imported at present") reflections = reflections[0] # first reflection list reflections = reflections.select(reflections['id'] == 0) # first experiment if len(reflections) == 0: print "No reflection data for the first experiment found in the input" self.parser.print_help() return if len(experiments) > 1: raise Sorry("Only one experiment can be imported at present") experiment = experiments[0] om = ObservationManager(reflections, experiment) gp_idx = om.group_index
def run(args): from dials.util import log import libtbx.load_env usage = "%s experiments.json indexed.pickle [options]" %libtbx.env.dispatcher_name from dials.util.options import OptionParser from dials.util.options import flatten_reflections from dials.util.options import flatten_experiments from dials.array_family import flex parser = OptionParser( usage=usage, phil=phil_scope, read_experiments=True, read_reflections=True, check_format=False, epilog=help_message) params, options = parser.parse_args(show_diff_phil=False) # Configure the logging #log.config(info=params.output.log, debug=params.output.debug_log) from dials.util.version import dials_version logger.info(dials_version()) # Log the diff phil diff_phil = parser.diff_phil.as_str() if diff_phil is not '': logger.info('The following parameters have been modified:\n') logger.info(diff_phil) experiments = flatten_experiments(params.input.experiments) reflections = flatten_reflections(params.input.reflections) assert(len(reflections) == 1) reflections = reflections[0] if len(experiments) == 0: parser.print_help() return #from dials.command_line import refine #params = refine.phil_scope.extract() indexed_reflections = reflections.select(reflections['id'] > -1) from dials.algorithms.refinement import RefinerFactory refiner = RefinerFactory.from_parameters_data_experiments( params, indexed_reflections, experiments) #refiner.run() rmsds = refiner.rmsds() import math xy_rmsds = math.sqrt(rmsds[0]**2 + rmsds[1]**2) print rmsds return
def run(args): import libtbx.load_env from libtbx.utils import Sorry from dials.util import log usage = "%s [options] datablock.json strong.pickle" %libtbx.env.dispatcher_name parser = OptionParser( usage=usage, phil=phil_scope, read_datablocks=True, read_reflections=True, check_format=False, epilog=help_message) params, options = parser.parse_args(show_diff_phil=False) datablocks = flatten_datablocks(params.input.datablock) reflections = flatten_reflections(params.input.reflections) if len(datablocks) == 0 or len(reflections) == 0: parser.print_help() exit(0) # Configure the logging log.config( info=params.output.log, debug=params.output.debug_log) # Log the diff phil diff_phil = parser.diff_phil.as_str() if diff_phil is not '': info('The following parameters have been modified:\n') info(diff_phil) imagesets = [] for datablock in datablocks: imagesets.extend(datablock.extract_imagesets()) assert len(imagesets) > 0 assert len(reflections) == len(imagesets) if params.scan_range is not None and len(params.scan_range) > 0: reflections = [ filter_reflections_by_scan_range(refl, params.scan_range) for refl in reflections] dps_params = dps_phil_scope.extract() # for development, we want an exhaustive plot of beam probability map: dps_params.indexing.plot_search_scope = params.plot_search_scope dps_params.indexing.mm_search_scope = params.mm_search_scope new_detector, new_beam = discover_better_experimental_model( imagesets, reflections, params, dps_params, nproc=params.nproc, wide_search_binning=params.wide_search_binning) for imageset in imagesets: imageset.set_detector(new_detector) imageset.set_beam(new_beam) from dxtbx.serialize import dump dump.datablock(datablock, params.output.datablock)
def run(args): import libtbx.load_env from libtbx.utils import Sorry from dials.util import log from logging import info import cPickle as pickle usage = "%s [options] datablock.json strong.pickle" % \ libtbx.env.dispatcher_name # Create the option parser parser = OptionParser( usage=usage, phil=phil_scope, read_reflections=True, read_datablocks=True, check_format=False, epilog=help_message) # Get the parameters params, options = parser.parse_args(show_diff_phil=False) # Configure the log log.config( params.verbosity, info='dials.find_hot_pixels.log', debug='dials.find_hot_pixels.debug.log') # Log the diff phil diff_phil = parser.diff_phil.as_str() if diff_phil is not '': info('The following parameters have been modified:\n') info(diff_phil) datablocks = flatten_datablocks(params.input.datablock) reflections = flatten_reflections(params.input.reflections) if len(datablocks) == 0 and len(reflections) == 0: parser.print_help() exit(0) if len(datablocks) > 1: raise Sorry("Only one DataBlock can be processed at a time") else: imagesets = datablocks[0].extract_imagesets() if len(reflections) == 0: raise Sorry("No reflection lists found in input") if len(reflections) > 1: raise Sorry("Multiple reflections lists provided in input") assert(len(reflections) == 1) reflections = reflections[0] mask = hot_pixel_mask(imagesets[0], reflections) pickle.dump(mask, open(params.output.mask, 'w'), pickle.HIGHEST_PROTOCOL) print 'Wrote hot pixel mask to %s' % params.output.mask return
def run(args): from dials.util.options import OptionParser from dials.util.options import flatten_datablocks from dials.util.options import flatten_experiments from dials.util.options import flatten_reflections import libtbx.load_env usage = "%s [options] datablock.json reflections.pickle" %( libtbx.env.dispatcher_name) parser = OptionParser( usage=usage, phil=phil_scope, read_datablocks=True, read_experiments=True, read_reflections=True, check_format=False, epilog=help_message) params, options = parser.parse_args(show_diff_phil=True) datablocks = flatten_datablocks(params.input.datablock) experiments = flatten_experiments(params.input.experiments) reflections = flatten_reflections(params.input.reflections) if (len(datablocks) == 0 and len(experiments) == 0) or len(reflections) == 0: parser.print_help() exit(0) if len(datablocks) == 0 and len(experiments) > 0: imagesets = experiments.imagesets() else: imagesets = [] for datablock in datablocks: imagesets.extend(datablock.extract_imagesets()) if len(reflections) > 1: assert len(reflections) == len(imagesets) from scitbx.array_family import flex for i in range(len(reflections)): reflections[i]['imageset_id'] = flex.int(len(reflections[i]), i) if i > 0: reflections[0].extend(reflections[i]) reflections = reflections[0] import wxtbx.app a = wxtbx.app.CCTBXApp(0) a.settings = params f = ReciprocalLatticeViewer( None, -1, "Reflection data viewer", size=(1024,768)) f.load_models(imagesets, reflections) f.Show() a.SetTopWindow(f) #a.Bind(wx.EVT_WINDOW_DESTROY, lambda evt: tb_icon.Destroy(), f) a.MainLoop()
def __init__(self, pickle_name, json_name): # load the integration.pickle file (reflection table) into memory and # load the experiments.json file (json) into memory, piecewise. # check_format=False because we don't wont to load any imagesets in the # experiement list importer = Importer([pickle_name, json_name], read_experiments=True, read_reflections=True, check_format=False) if importer.unhandled: print "unable to process:", importer.unhandled ConstructFrame.__init__(self, flatten_reflections(importer.reflections)[0], flatten_experiments(importer.experiments)[0])
def run(args): from dials.util.options import OptionParser from dials.util.options import flatten_datablocks from dials.util.options import flatten_experiments from dials.util.options import flatten_reflections from dials.util import log usage = "%s [options] datablock.json reflections.pickle" %( libtbx.env.dispatcher_name) parser = OptionParser( usage=usage, phil=phil_scope, read_datablocks=True, read_experiments=True, read_reflections=True, check_format=False, epilog=help_message) params, options = parser.parse_args() datablocks = flatten_datablocks(params.input.datablock) experiments = flatten_experiments(params.input.experiments) reflections = flatten_reflections(params.input.reflections) if (len(datablocks) == 0 and len(experiments) == 0) or len(reflections) == 0: parser.print_help() exit(0) ## Configure the logging #log.config(info='dials.rl_png.log') # Log the diff phil diff_phil = parser.diff_phil.as_str() if diff_phil is not '': logger.info('The following parameters have been modified:\n') logger.info(diff_phil) reflections = reflections[0] if len(datablocks) == 0 and len(experiments) > 0: imagesets = experiments.imagesets() else: imagesets = [] for datablock in datablocks: imagesets.extend(datablock.extract_imagesets()) f = ReciprocalLatticeJson(settings=params) f.load_models(imagesets, reflections) f.as_json(filename=params.output.json, compact=params.output.compact) print
def __init__(self, refl_name, json_name, outname=None): # load the integration.pickle file (reflection table) into memory and # load the experiments.json file (json) into memory, piecewise. # check_format=False because we don't wont to load any imagesets in the # experiement list importer = Importer([refl_name, json_name], read_experiments=True, read_reflections=True, check_format=False) if importer.unhandled: print "unable to process:", importer.unhandled reflections_l = flatten_reflections(importer.reflections) experiments_l = flatten_experiments(importer.experiments) assert len(experiments_l) == 1, "cannot construct a single frame from multiple experiments" frame = ConstructFrame.__init__(self, reflections_l[0], experiments_l[0]) if frame is not None: self.frame.make_frame()
def run(args): import libtbx.load_env from dials.array_family import flex from dials.util import log from dials.util.version import dials_version usage = "%s [options] experiment.json indexed.pickle" % \ libtbx.env.dispatcher_name parser = OptionParser( usage=usage, phil=phil_scope, read_reflections=True, read_experiments=True, check_format=False, epilog=help_message) params, options = parser.parse_args(show_diff_phil=True) # Configure the logging log.config(info=params.output.log, debug=params.output.debug_log) logger.info(dials_version()) reflections = flatten_reflections(params.input.reflections) experiments = flatten_experiments(params.input.experiments) if len(reflections) == 0 or len(experiments) == 0: parser.print_help() return assert(len(reflections) == 1) assert(len(experiments) == 1) experiment = experiments[0] reflections = reflections[0] # remove reflections with 0, 0, 0 index zero = (reflections['miller_index'] == (0, 0, 0)) logger.info('Removing %d unindexed reflections' % zero.count(True)) reflections = reflections.select(~zero) h, k, l = reflections['miller_index'].as_vec3_double().parts() h = h.iround() k = k.iround() l = l.iround() logger.info('Range on h: %d to %d' % (flex.min(h), flex.max(h))) logger.info('Range on k: %d to %d' % (flex.min(k), flex.max(k))) logger.info('Range on l: %d to %d' % (flex.min(l), flex.max(l))) test_P1_crystal_indexing(reflections, experiment, params) test_crystal_pointgroup_symmetry(reflections, experiment, params)
def read_reflection_file(self, reflection_file): ### open DIALS pickle file phil_scope_str=''' reflections = 'example_refined.pickle' ''' phil_scope = parse(phil_scope_str, process_includes=True) parser = OptionParser( phil=phil_scope, check_format=False, read_reflections=True) params, options = parser.parse_args(args=[reflection_file], show_diff_phil=True) reflections = flatten_reflections(params.input.reflections) self.reflections = reflections
def run(args): from dials.util.options import OptionParser from dials.util.options import flatten_datablocks from dials.util.options import flatten_experiments from dials.util.options import flatten_reflections import libtbx.load_env usage = "%s [options] datablock.json reflections.pickle" % ( libtbx.env.dispatcher_name) parser = OptionParser(usage=usage, phil=phil_scope, read_datablocks=True, read_experiments=True, read_reflections=True, check_format=False, epilog=help_message) params, options = parser.parse_args(show_diff_phil=True) datablocks = flatten_datablocks(params.input.datablock) experiments = flatten_experiments(params.input.experiments) reflections = flatten_reflections(params.input.reflections) if (len(datablocks) == 0 and len(experiments) == 0) or len(reflections) == 0: parser.print_help() exit(0) reflections = reflections[0] if len(datablocks) == 0 and len(experiments) > 0: imagesets = experiments.imagesets() else: imagesets = [] for datablock in datablocks: imagesets.extend(datablock.extract_imagesets()) import wxtbx.app a = wxtbx.app.CCTBXApp(0) a.settings = params f = DiffractionGeometryViewer(None, -1, "Diffraction Geometry viewer", size=(1024, 768)) f.load_models(imagesets, reflections) f.Show() a.SetTopWindow(f) #a.Bind(wx.EVT_WINDOW_DESTROY, lambda evt: tb_icon.Destroy(), f) a.MainLoop()
def run(args): import dials.util.banner # noqa: F401 - Importing means that it prints from dials.util.options import OptionParser from dials.util.options import flatten_experiments from dials.util.options import flatten_reflections usage = "dials.show [options] models.expt | image_*.cbf" parser = OptionParser( usage=usage, phil=phil_scope, read_experiments=True, read_experiments_from_images=True, read_reflections=True, check_format=False, epilog=help_message, ) params, options = parser.parse_args(show_diff_phil=True) experiments = flatten_experiments(params.input.experiments) reflections = flatten_reflections(params.input.reflections) if len(experiments) == 0 and len(reflections) == 0: parser.print_help() exit() if len(experiments): if not all(e.detector for e in experiments): sys.exit("Error: experiment has no detector") if not all(e.beam for e in experiments): sys.exit("Error: experiment has no beam") print( show_experiments( experiments, show_scan_varying=params.show_scan_varying, show_image_statistics=params.show_image_statistics, )) if len(reflections): print( show_reflections( reflections, show_intensities=params.show_intensities, show_profile_fit=params.show_profile_fit, show_centroids=params.show_centroids, show_all_reflection_data=params.show_all_reflection_data, show_flags=params.show_flags, max_reflections=params.max_reflections, show_identifiers=params.show_identifiers, ))
def run(self): ''' Parse the options. ''' from dials.util.options import flatten_experiments, flatten_reflections # Parse the command line arguments params, options = self.parser.parse_args(show_diff_phil=True) experiments = flatten_experiments(params.input.experiments) reflections = flatten_reflections(params.input.reflections) assert len(reflections) == 1 reflections = reflections[0] nvparams = dsp_phil.extract() domain_size = flex.double() mosaic_angle = flex.double() filtered_reflections = flex.reflection_table() for i in range(len(experiments)): refls = reflections.select(reflections['id'] == i) tmp = refls['id'] refls['id'] = flex.int(len(refls), 0) try: nv = NaveParameters(params = nvparams, experiments=experiments[i:i+1], reflections=refls, refinery=None, graph_verbose=False) crystal_model_nv = nv()[0] except Exception as e: print("Error recomputing mosaicity for experiment %d: %s"%(i, str(e))) continue domain_size.append(experiments[i].crystal.get_domain_size_ang() - crystal_model_nv.get_domain_size_ang()) mosaic_angle.append(experiments[i].crystal.get_half_mosaicity_deg() - crystal_model_nv.get_half_mosaicity_deg()) experiments[i].crystal = crystal_model_nv refls['id'] = tmp refls = refls.select(nv.nv_acceptance_flags) filtered_reflections.extend(refls) print("Saving new experiments as %s"%params.output.experiments) experiments.as_file(params.output.experiments) print("Removed %d out of %d reflections as outliers"%(len(reflections) - len(filtered_reflections), len(reflections))) print("Saving filtered reflections as %s"%params.output.experiments) filtered_reflections.as_pickle(params.output.reflections) if params.plot_changes: from matplotlib import pyplot as plt domain_size = domain_size.select((domain_size >= -10) & (domain_size <= 10)) mosaic_angle = mosaic_angle.select((mosaic_angle >= -0.1) & (mosaic_angle <= 0.1)) for d in [domain_size, mosaic_angle]: f = plt.figure() plt.hist(d, bins=30) plt.show()
def run(self): from dials.util.options import flatten_reflections from dials.viewer.viewer_interface import extract_n_show # Parse the command line params, options = self.parser.parse_args(show_diff_phil=True) table = flatten_reflections(params.input.reflections) if len(table) == 0: self.parser.print_help() return extract_n_show(table[0])
def run(self): '''Execute the script.''' from dials.util.options import flatten_reflections, flatten_experiments from libtbx.utils import Sorry from dials.array_family import flex # Parse the command line params, options = self.parser.parse_args(show_diff_phil=True) # Try to load the models and data if not params.input.experiments: print "No Experiments found in the input" self.parser.print_help() return if params.input.reflections: if len(params.input.reflections) != len(params.input.experiments): raise Sorry("The number of input reflections files does not match the " "number of input experiments") experiments = flatten_experiments(params.input.experiments) if params.input.reflections: reflections = flatten_reflections(params.input.reflections)[0] else: reflections = None import math experiments_template = "%s_%%0%sd.json" %( params.output.experiments_prefix, int(math.floor(math.log10(len(experiments))) + 1)) reflections_template = "%s_%%0%sd.pickle" %( params.output.reflections_prefix, int(math.floor(math.log10(len(experiments))) + 1)) for i, experiment in enumerate(experiments): from dxtbx.model.experiment.experiment_list import ExperimentList from dxtbx.serialize import dump experiment_filename = experiments_template %i print 'Saving experiment %d to %s' %(i, experiment_filename) dump.experiment_list(ExperimentList([experiment]), experiment_filename) if reflections is not None: reflections_filename = reflections_template %i print 'Saving reflections for experiment %d to %s' %(i, reflections_filename) ref_sel = reflections.select(reflections['id'] == i) ref_sel['id'] = flex.int(len(ref_sel), 0) ref_sel.as_pickle(reflections_filename) return
def run(args=None): import wx # It is unclear why, but it is crucial that wx # is imported before the parser is run. # Otherwise viewer will crash when run with # .cbf image as parameter on linux with wxPython>=3 # The problem can be traced to # dxtbx/format/FormatCBFFull.py:49 # ''' from iotbx.detectors.cbf import CBFImage ''' # and the wx import must happen before that import. WX3 = wx.VERSION[0] == 3 if not WX3: # HACK: Monkeypatch this renamed function so we can trick wxtbx's IntCtrl # without having to alter the package wx.SystemSettings_GetColour = wx.SystemSettings.GetColour dials.util.log.print_banner() usage_message = "dials.image_viewer models.expt [observations.refl]" parser = OptionParser( usage=usage_message, phil=phil_scope, read_experiments=True, read_reflections=True, read_experiments_from_images=True, epilog=help_message, ) params, options = parser.parse_args(args, show_diff_phil=True) experiments = [x.data for x in params.input.experiments] reflections = flatten_reflections(params.input.reflections) if len(experiments) == 0: parser.print_help() exit(0) flat_expts = flatten_experiments(params.input.experiments) if params.load_models: if any(e.detector is None for e in flat_expts): sys.exit("Error: experiment has no detector") if any(e.beam is None for e in flat_expts): sys.exit("Error: experiment has no beam") # If given a mask, replace the path with the loaded data if params.mask is not None: with open(params.mask, "rb") as f: params.mask = pickle.load(f) show_image_viewer(params=params, reflections=reflections, experiments=experiments)
def run(self): '''Execute the script.''' from dials.array_family import flex from dials.util.options import flatten_reflections from libtbx.utils import Sorry # Parse the command line params, options = self.parser.parse_args(show_diff_phil=True) reflections = flatten_reflections(params.input.reflections) if len(reflections) == 0: self.parser.print_help() raise Sorry('No valid reflection file given') if len(reflections) != 1: self.parser.print_help() raise Sorry('Exactly 1 reflection file must be specified') reflections = reflections[0] print "{0} reflections loaded".format(len(reflections)) if len(params.inclusions.flag) == 0: self.parser.print_help() raise Sorry('No inclusion criteria given') # Build up the initial inclusion selection inc = flex.bool(len(reflections)) for flag in params.inclusions.flag: sel = reflections.get_flags(getattr(reflections.flags, flag)) inc = inc | sel reflections = reflections.select(inc) print "{0} reflections selected to form the working set".format(len(reflections)) # Make requested exclusions from the current selection exc = flex.bool(len(reflections)) for flag in params.exclusions.flag: print flag sel = reflections.get_flags(getattr(reflections.flags, flag)) exc = exc | sel reflections = reflections.select(~exc) print "{0} reflections excluded from the working set".format(exc.count(True)) # Save filtered reflections to file if params.output.reflections: print "Saving {0} reflections to {1}".format(len(reflections), params.output.reflections) reflections.as_pickle(params.output.reflections) return
def run(phil=working_phil, args=None): usage = "dials.index [options] models.expt strong.refl" parser = OptionParser( usage=usage, phil=phil, read_reflections=True, read_experiments=True, check_format=False, epilog=help_message, ) params, options = parser.parse_args(args=args, show_diff_phil=False) # Configure the logging log.config(verbosity=options.verbose, logfile=params.output.log) logger.info(dials_version()) # Log the diff phil diff_phil = parser.diff_phil.as_str() if diff_phil != "": logger.info("The following parameters have been modified:\n") logger.info(diff_phil) experiments = flatten_experiments(params.input.experiments) reflections = flatten_reflections(params.input.reflections) if len(experiments) == 0: parser.print_help() return try: indexed_experiments, indexed_reflections = index( experiments, reflections, params) except (DialsIndexError, ValueError) as e: sys.exit(str(e)) # Save experiments if params.output.split_experiments: logger.info("Splitting experiments before output") indexed_experiments = ExperimentList( [copy.deepcopy(re) for re in indexed_experiments]) logger.info("Saving refined experiments to %s" % params.output.experiments) assert indexed_experiments.is_consistent() indexed_experiments.as_file(params.output.experiments) # Save reflections logger.info("Saving refined reflections to %s" % params.output.reflections) indexed_reflections.as_msgpack_file(filename=params.output.reflections)
def __init__(self, pickle_name, json_name, scan_no): # load the integration.pickle file (reflection table) into memory and # load the experiments.json file (json) into memory, piecewise. # check_format=False because we don't wont to load any imagesets in the # experiement list importer = Importer([pickle_name, json_name], read_experiments=True, read_reflections=True, check_format=False) if importer.unhandled: print("unable to process:", importer.unhandled) ConstructFrame.__init__(self, flatten_reflections(importer.reflections)[0], flatten_experiments(importer.experiments)[0], scan_no)
def __init__(self): """Check script input""" import libtbx.load_env from dials.util.options import OptionParser # The script usage usage = ( "usage: {0} [options] [param.phil] indexed.expt " "strong.refl" ).format(libtbx.env.dispatcher_name) parser = OptionParser( usage=usage, phil=phil_scope, read_reflections=True, read_experiments=True, check_format=False, epilog=help_message, ) params, options = parser.parse_args(show_diff_phil=True) if len(params.input.experiments) != 1: raise Sorry("Please provide a single experiment list as input") self._current_exp_path = params.input.experiments[0].filename el = params.input.experiments[0].data scan = el.scans() if len(scan) != 1: raise Sorry("Currently only a single scan is supported") self._scan = scan[0] reflections = flatten_reflections(params.input.reflections) if len(reflections) > 1: raise Sorry("Please provide a single reflection table as input") self._strong_path = params.input.reflections[0].filename self._num_strong = len(params.input.reflections[0].data) print( "{0} strong spots read from {1}".format(self._num_strong, self._strong_path) ) self._images_per_block = params.images_per_block self._constrain_detector = params.fix_detector_distance self._all_indexed = None return
def data_from_pickle_and_json(): from dials.util.options import ( OptionParser, flatten_reflections, flatten_experiments, ) help_message = """ Generates a dials.array_family.flex.reflection_table and a dxtbx.model.experiment_list.ExperimentList from a observations.refl and a models.expt. Examples: dials.util.intensity_explorer indexed.refl indexed.expt dials.util.intensity_explorer integrated.refl integrated.expt """ # Create the parser usage = ( "usage: dials.util.intensity_explorer [options] " "observations.refl models.expt" ) parser = OptionParser( usage=usage, read_reflections=True, read_experiments=True, check_format=True, epilog=help_message, ) # Parse the command line arguments params, options = parser.parse_args(show_diff_phil=True) # Show the help if len(params.input.reflections) != 1 or len(params.input.experiments) != 1: parser.print_help() exit(0) rtable = flatten_reflections(params.input.reflections) elist = flatten_experiments(params.input.experiments) rtable.del_selected(rtable["intensity.sum.variance"] <= 0) return rtable, elist
def run(self): params, options = self.parser.parse_args(show_diff_phil=True) datablocks = flatten_datablocks(params.input.datablock) experiments = flatten_experiments(params.input.experiments) reflections = flatten_reflections(params.input.reflections) if len(reflections) > 0: reflections = reflections[0] else: reflections = None all_detectors = [] for db in datablocks: all_detectors.extend(db.unique_detectors()) all_detectors.extend(experiments.detectors()) display_detectors(all_detectors[: min(len(all_detectors), 10)], reflections=reflections)
def run(args): usage = "%s [options] models.expt observations.refl" % (libtbx.env.dispatcher_name) parser = OptionParser( usage=usage, phil=phil_scope, read_experiments=True, read_reflections=True, check_format=False, epilog=help_message, ) params, options = parser.parse_args(show_diff_phil=True) experiments = flatten_experiments(params.input.experiments) reflections = flatten_reflections(params.input.reflections) if len(experiments) == 0 or len(reflections) == 0: parser.print_help() exit(0) if len(reflections) > 1: assert len(reflections) == len(experiments) for i in range(len(reflections)): reflections[i]["imageset_id"] = flex.int(len(reflections[i]), i) if i > 0: reflections[0].extend(reflections[i]) elif "imageset_id" not in reflections[0]: reflections[0]["imageset_id"] = reflections[0]["id"] reflections[0]["id"] = flex.int(reflections[0].size(), -1) reflections = reflections[0] a = wxtbx.app.CCTBXApp(0) a.settings = params f = ReciprocalLatticeViewer( None, -1, "Reflection data viewer", size=(1024, 768), settings=copy.deepcopy(params), ) f.load_models(experiments, reflections) f.Show() a.SetTopWindow(f) # a.Bind(wx.EVT_WINDOW_DESTROY, lambda evt: tb_icon.Destroy(), f) a.MainLoop()
def run(self): params, options = self.parser.parse_args(show_diff_phil=True) datablocks = flatten_datablocks(params.input.datablock) experiments = flatten_experiments(params.input.experiments) reflections = flatten_reflections(params.input.reflections) if len(reflections) > 0: reflections = reflections[0] else: reflections = None all_detectors = [] for db in datablocks: all_detectors.extend(db.unique_detectors()) all_detectors.extend(experiments.detectors()) display_detectors(all_detectors[:min(len(all_detectors), 10)], reflections=reflections)
def run(args): usage = "%s [options] indexed.expt indexed.refl" % libtbx.env.dispatcher_name parser = OptionParser( usage=usage, phil=phil_scope, read_reflections=True, read_experiments=True, check_format=False, epilog=help_message, ) params, options = parser.parse_args(show_diff_phil=True) # Configure the logging log.config(logfile=params.output.log) logger.info(dials_version()) reflections = flatten_reflections(params.input.reflections) experiments = flatten_experiments(params.input.experiments) if len(reflections) == 0 or len(experiments) == 0: parser.print_help() return assert len(reflections) == 1 assert len(experiments) == 1 experiment = experiments[0] reflections = reflections[0] # remove reflections with 0, 0, 0 index zero = reflections["miller_index"] == (0, 0, 0) logger.info("Removing %d unindexed reflections" % zero.count(True)) reflections = reflections.select(~zero) h, k, l = reflections["miller_index"].as_vec3_double().parts() h = h.iround() k = k.iround() l = l.iround() logger.info("Range on h: %d to %d" % (flex.min(h), flex.max(h))) logger.info("Range on k: %d to %d" % (flex.min(k), flex.max(k))) logger.info("Range on l: %d to %d" % (flex.min(l), flex.max(l))) test_P1_crystal_indexing(reflections, experiment, params) test_crystal_pointgroup_symmetry(reflections, experiment, params)
def run(): """Run the command line filtering script.""" flags = list(flex.reflection_table.flags.names.items()) flags.sort(key=itemgetter(0)) phil_scope = parse(phil_str, process_includes=True) # The script usage usage = "usage: dials.filter_reflections [options] experiment.expt" # Create the parser parser = OptionParser( usage=usage, phil=phil_scope, epilog=help_message, read_reflections=True, read_experiments=True, check_format=False, ) params, options = parser.parse_args(show_diff_phil=True) reflections = flatten_reflections(params.input.reflections) experiments = flatten_experiments(params.input.experiments) log.config(verbosity=options.verbose) if not reflections: parser.print_help() raise Sorry("No valid reflection file given") if len(reflections) != 1: parser.print_help() raise Sorry("Exactly 1 reflection file must be specified") reflections = reflections[0] # Check if any filter has been set using diff_phil filter_def = [ o for o in parser.diff_phil.objects if o.name not in ["input", "output"] ] if not filter_def: print("No filter specified. Performing analysis instead.") run_analysis(flags, reflections) else: run_filtering(params, experiments, reflections)
def run(args): import libtbx.load_env usage = """\ %s datablock.json reflections.pickle [options]""" %libtbx.env.dispatcher_name from dials.util.options import OptionParser from dials.util.options import flatten_datablocks from dials.util.options import flatten_experiments from dials.util.options import flatten_reflections from scitbx.array_family import flex from scitbx import matrix from libtbx.phil import command_line from libtbx.utils import Sorry parser = OptionParser( usage=usage, phil=master_phil_scope, read_datablocks=True, read_experiments=True, read_reflections=True, check_format=False) params, options = parser.parse_args(show_diff_phil=True) datablocks = flatten_datablocks(params.input.datablock) reflections = flatten_reflections(params.input.reflections) experiments = flatten_experiments(params.input.experiments) if len(datablocks) == 1: imageset = datablocks[0].extract_imagesets()[0] elif len(datablocks) > 1: raise Sorry("Only one DataBlock can be processed at a time") elif len(experiments.imagesets()) > 0: imageset = experiments.imagesets()[0] imageset.set_detector(experiments[0].detector) imageset.set_beam(experiments[0].beam) imageset.set_goniometer(experiments[0].goniometer) else: parser.print_help() return detector = imageset.get_detector() scan = imageset.get_scan() panel_origin_shifts = {0: (0,0,0)} try: hierarchy = detector.hierarchy() except AttributeError, e: hierarchy = None
def run(args): import libtbx.load_env usage = """\ %s datablock.json reflections.pickle [options]""" %libtbx.env.dispatcher_name from dials.util.options import OptionParser from dials.util.options import flatten_datablocks from dials.util.options import flatten_experiments from dials.util.options import flatten_reflections from scitbx.array_family import flex from scitbx import matrix from libtbx.utils import Sorry parser = OptionParser( usage=usage, phil=master_phil_scope, read_datablocks=True, read_experiments=True, read_reflections=True, check_format=False) params, options = parser.parse_args(show_diff_phil=True) datablocks = flatten_datablocks(params.input.datablock) reflections = flatten_reflections(params.input.reflections) experiments = flatten_experiments(params.input.experiments) if len(datablocks) == 1: imageset = datablocks[0].extract_imagesets()[0] elif len(datablocks) > 1: raise Sorry("Only one DataBlock can be processed at a time") elif len(experiments.imagesets()) > 0: imageset = experiments.imagesets()[0] imageset.set_detector(experiments[0].detector) imageset.set_beam(experiments[0].beam) imageset.set_goniometer(experiments[0].goniometer) else: parser.print_help() return detector = imageset.get_detector() scan = imageset.get_scan() panel_origin_shifts = {0: (0,0,0)} try: hierarchy = detector.hierarchy() except AttributeError, e: hierarchy = None
def __init__(self, path, json=None, pickle_ext=None, json_ext=None): if json is None: json = find_json(path, pickle_ext, json_ext) if json is None: importer = Importer([path], read_experiments=False, read_reflections=True, check_format=False) print "unable to find experiment list" self.experiments = None else: importer = Importer([path, json], read_experiments=True, read_reflections=True, check_format=False) try: self.experiments = flatten_experiments(importer.experiments)[0] except IndexError: print "unable to read experiment list" self.experiments = None try: self.reflections = flatten_reflections(importer.reflections)[0] except IndexError: print "unable to read reflection table" self.reflections = None
def get_exp_refl(path, exp_file='imported.expt', refl_file='strong.refl'): '''Get experiments and reflections[0] form an .expt and .refl files Returns - experiments,reflections[0] ''' if not refl_file: refl_file = exp_file.replace('.expt', '.refl') phil_scope = phil.parse(""" """) parser = OptionParser(usage='', phil=None, read_experiments=True, read_reflections=True) args = [path + exp_file, path + refl_file] params, _ = parser.parse_args(args, show_diff_phil=True) reflections, experiments = reflections_and_experiments_from_files( params.input.reflections, params.input.experiments) reflections = flatten_reflections(params.input.reflections) exp = experiments[0] refl = reflections[0] return experiments, refl
def __init__(self): '''Initialise the script.''' from dials.util.options import OptionParser, Importer, flatten_experiments, flatten_reflections import libtbx.load_env # The script usage usage = "usage: %s experiments.json reflections.pickle" \ % libtbx.env.dispatcher_name # Initialise the base class self.parser = OptionParser(usage=usage, read_experiments=True, read_reflections=True) # Parse the command line params, options = self.parser.parse_args(show_diff_phil=False) self.experiments = flatten_experiments(params.input.experiments) self.reflections = flatten_reflections(params.input.reflections)
def run(self): self.params, options = self.parser.parse_args() if len(self.params.input.experiments) == 0: self.parser.print_help() raise Sorry("No experiments found in the input") if len(self.params.input.reflections) == 0: self.parser.print_help() raise Sorry("No reflection data found in the input") import random random.seed(self.params.random_seed) flex.set_random_seed(self.params.random_seed) from dials.util.options import flatten_reflections self.original_reflections = flatten_reflections( self.params.input.reflections)[0] print("Number of reflections loaded: {0}".format( len(self.original_reflections))) # make errors to add to observed centroids self.set_random_error() obs_sets = [] for wrapper in self.params.input.experiments: obs_sets.append( self.create_indexed(experiments=wrapper.data, filename=wrapper.filename)) # Keep only predictions that are possible for all experiments obs_sets = self.select_intersection(obs_sets) # Write out reflections import os for refs, wrapper in zip(obs_sets, self.params.input.experiments): outname = os.path.splitext(wrapper.filename)[0] + ".pickle" print("Saving reflections to {0}".format(outname)) refs.as_pickle(outname)
def run(args): usage = ( "dials.resolutionizer [options] scaled.expt scaled.refl | scaled_unmerged.mtz" ) parser = OptionParser( usage=usage, phil=phil_scope, read_reflections=True, read_experiments=True, check_format=False, epilog=help_message, ) params, options, unhandled = parser.parse_args(return_unhandled=True, show_diff_phil=True) reflections = flatten_reflections(params.input.reflections) experiments = flatten_experiments(params.input.experiments) if (not reflections or not experiments) and not unhandled: parser.print_help() return if reflections and experiments and unhandled: sys.exit( "Must provide either scaled unmerged mtz OR dials-format scaled reflections and experiments files" ) # Configure the logging log.config(logfile=params.output.log) logger.info(dials_version()) if len(unhandled) == 1: scaled_unmerged = unhandled[0] m = resolutionizer.Resolutionizer.from_unmerged_mtz( scaled_unmerged, params.resolutionizer) else: reflections = parse_multiple_datasets(reflections) m = resolutionizer.Resolutionizer.from_reflections_and_experiments( reflections, experiments, params.resolutionizer) m.resolution_auto()
def run(self): """ Perform the integration. """ from time import time # Check the number of arguments is correct start_time = time() # Parse the command line params, options = self.parser.parse_args(show_diff_phil=False) reflections = flatten_reflections(params.input.reflections) experiments = flatten_experiments(params.input.experiments) if len(reflections) == 0 or len(experiments) == 0: self.parser.print_help() return elif len(reflections) != 1: raise Sorry("more than 1 reflection file was given") elif len(experiments) == 0: raise Sorry("no experiment list was specified") reflections = reflections[0] # Configure logging log.config(info="dials.merge_stills.log", debug="dials.merge_stills.debug.log") # Log the diff phil diff_phil = self.parser.diff_phil.as_str() if diff_phil is not "": logger.info("The following parameters have been modified:\n") logger.info(diff_phil) # Read the reference if params.input.reference: reference = self._read_reference(params.input.reference) else: reference = None # Do the merging reflections = scale_and_merge(experiments, reflections, params, reference)
def construct_frames_from_files(refl_name, json_name, outname=None, outdir=None): importer = Importer([refl_name, json_name], read_experiments=True, read_reflections=True, check_format=False) if importer.unhandled: print "unable to process:", importer.unhandled reflections_l = flatten_reflections(importer.reflections)[0] experiments_l = flatten_experiments(importer.experiments) frames = [] if outdir is None: outdir = '.' if outname is None: outname = 'int-%d' + refl_name.split('.pickle')[0] + '_extracted.pickle' elif '%' not in outname: outname = outname.split(".pickle")[0] + ("_%d.pickle") for i in range(len(experiments_l)): refl = reflections_l.select(reflections_l['id'] == i) if len(refl) == 0: continue expt = experiments_l[i] frame = ConstructFrame(refl, expt).make_frame() name = outname % i easy_pickle.dump(os.path.join(outdir, name), frame)
def run(args): from dials.util.options import OptionParser from dials.util.options import flatten_experiments from dials.util.options import flatten_reflections import libtbx.load_env usage = "%s [options] models.expt observations.refl" % ( libtbx.env.dispatcher_name) parser = OptionParser( usage=usage, phil=phil_scope, read_experiments=True, read_reflections=True, check_format=False, epilog=help_message, ) params, options = parser.parse_args(show_diff_phil=True) experiments = flatten_experiments(params.input.experiments) reflections = flatten_reflections(params.input.reflections) assert len(experiments) == len(reflections) nn = len(experiments) # FIXME check that all the crystals are in the primitive setting... # now compute grid of reciprocal RMSD's result = {} for j, expt in enumerate(experiments): for k, refl in enumerate(reflections): result[j, k] = test_index(expt, refl) # print matrix of results print(" " + "".join(["%7d" % j for j in range(nn)])) for k in range(nn): record = "".join([" %6.3f" % result[j, k] for j in range(nn)]) print("%8d" % k + record)
def run(args=None): usage = "dials.python bijvoet_group [options] scaled.expt scaled.refl" parser = OptionParser( usage=usage, phil=phil_scope, read_reflections=True, read_experiments=True, check_format=False, epilog=__doc__, ) params, options = parser.parse_args(args=args, show_diff_phil=False) dials.util.log.config(verbosity=options.verbose, logfile=params.output.log) experiments = flatten_experiments(params.input.experiments) reflections = flatten_reflections(params.input.reflections) if len(reflections) != 1: sys.exit("Exactly one reflection file needed.") bijvoet_table(experiments, reflections[0], params)
def run(args): from dials.util.options import OptionParser from dials.util.options import flatten_datablocks from dials.util.options import flatten_experiments from dials.util.options import flatten_reflections import libtbx.load_env usage = "%s [options] datablock.json reflections.pickle" %( libtbx.env.dispatcher_name) parser = OptionParser( usage=usage, phil=phil_scope, read_datablocks=True, read_experiments=True, read_reflections=True, check_format=False, epilog=help_message) params, options = parser.parse_args(show_diff_phil=True) datablocks = flatten_datablocks(params.input.datablock) experiments = flatten_experiments(params.input.experiments) reflections = flatten_reflections(params.input.reflections) if (len(datablocks) == 0 and len(experiments) == 0) or len(reflections) == 0: parser.print_help() exit(0) reflections = reflections[0] if len(datablocks) == 0 and len(experiments) > 0: imagesets = experiments.imagesets() else: imagesets = [] for datablock in datablocks: imagesets.extend(datablock.extract_imagesets()) spot_resolution_shells(imagesets, reflections, params)
def run(self): '''Execute the script.''' # Parse the command line params, options = self.parser.parse_args(show_diff_phil=True) try: assert len(params.input.reflections) == len(params.input.datablock) except AssertionError: raise Sorry( "The number of input reflections files does not match the " "number of input datablocks") datablocks = flatten_datablocks(params.input.datablock) reflections = flatten_reflections(params.input.reflections) if len(reflections): r = self.combine_reflections(reflections) # print number of reflections per imageset from libtbx.table_utils import simple_table max_id = max(r['id']) header = ["Imageset", "Nref"] nrefs_per_imset = [(r['id'] == i).count(True) for i in range(max_id + 1)] rows = [(str(i), str(n)) for (i, n) in enumerate(nrefs_per_imset)] st = simple_table(rows, header) print(st.format()) rf = params.output.reflections_filename print('Saving combined reflections to {0}'.format(rf)) r.as_pickle(rf) if len(datablocks): db = self.combine_datablocks(datablocks) dbf = params.output.datablocks_filename print('Saving combined datablocks to {0}'.format(dbf)) dump = DataBlockDumper(db) dump.as_file(dbf, compact=params.output.compact) return
def __init__(self, files): from dials.util.options import Importer, flatten_reflections, flatten_experiments importer = Importer(files, read_experiments=True, read_reflections=True, check_format=False) if importer.unhandled: print "Unable to handle one or more files:", importer.unhandled return reflections = flatten_reflections(importer.reflections) assert len( reflections ) == 1, "Implemented only for one reflection table at a time presently" experiment = None if importer.experiments: experiments = flatten_experiments(importer.experiments) assert len( experiments ) == 1, "Implemented only for one experiment at a time presently" experiment = experiments[0] super(ReflectionsRadialLengthsFromFiles, self).__init__(reflections[0], experiment=experiment)
def run(args=None): """Run assign experiment identifiers from the command line.""" usage = ( """Usage: dials.assign_experiment_identifiers observations.refl models.expt""" ) parser = OptionParser( usage=usage, read_experiments=True, read_reflections=True, phil=phil_scope, check_format=False, epilog=help_message, ) params, _ = parser.parse_args(args=args, show_diff_phil=False) if not params.input.experiments or not params.input.reflections: parser.print_help() sys.exit() reflections = flatten_reflections(params.input.reflections) experiments = flatten_experiments(params.input.experiments) reflections = parse_multiple_datasets(reflections) if len(experiments) != len(reflections): raise Sorry( "Mismatched number of experiments and reflection tables found: %s & %s." % (len(experiments), len(reflections))) try: experiments, reflections = assign_unique_identifiers( experiments, reflections, params.identifiers) except ValueError as e: raise Sorry(e) print("assigned identifiers: %s" % list(experiments.identifiers())) save_experiments(experiments, params.output.experiments) joint_table = flex.reflection_table() for reflection_table in reflections: joint_table.extend(reflection_table) save_reflections(joint_table, params.output.reflections)
def run(phil=working_phil, args=None): usage = "dials.index [options] models.expt strong.refl" parser = OptionParser( usage=usage, phil=phil, read_reflections=True, read_experiments=True, check_format=False, epilog=help_message, ) params, options = parser.parse_args(args=args, show_diff_phil=False) from dials.util import log # Configure the logging log.config(verbosity=options.verbose, logfile=params.output.log) from dials.util.version import dials_version logger.info(dials_version()) # Log the diff phil diff_phil = parser.diff_phil.as_str() if diff_phil != "": logger.info("The following parameters have been modified:\n") logger.info(diff_phil) experiments = flatten_experiments(params.input.experiments) reflections = flatten_reflections(params.input.reflections) if len(experiments) == 0: parser.print_help() return indexed = Index(experiments, reflections, params) indexed.export_experiments(params.output.experiments) indexed.export_reflections(params.output.reflections)
def run(args): import libtbx.load_env usage = ("""\ %s observations.refl [options]""" % libtbx.env.dispatcher_name) from dials.util.options import OptionParser from dials.util.options import flatten_reflections from dials.util import Sorry parser = OptionParser(usage=usage, phil=phil_scope, read_reflections=True, epilog=help_message) params, options = parser.parse_args(show_diff_phil=True) reflections = flatten_reflections(params.input.reflections) if len(reflections) != 1: parser.print_help() raise Sorry("Please provide a single file of reflections") refs = reflections[0] # raw periodograms ca = CentroidAnalyser(refs) results_r = ca(spans=None) # smoothed periodograms ca = CentroidAnalyser(refs) results_s = ca() if len(results_r) == 1: save_plots(params, results_r[0], results_s[0]) else: for i, (r_r, r_s) in enumerate(zip(results_r, results_s)): suffix = "_exp_{0}".format(i) save_plots(params, r_r, r_s, suffix=suffix)
def run(self): '''Execute the script.''' from dials.util.options import flatten_reflections, flatten_experiments # Parse the command line params, options = self.parser.parse_args(show_diff_phil=False) reflections = flatten_reflections(params.input.reflections) experiments = flatten_experiments(params.input.experiments) # Try to load the models and data nexp = len(experiments) if nexp == 0: print "No Experiments found in the input" self.parser.print_help() return if len(reflections) == 0: print "No reflection data found in the input" self.parser.print_help() return if len(reflections) > 1: raise Sorry("Only one reflections list can be imported at present") reflections = reflections[0] # first reflection list reflections = reflections.select( reflections['id'] == 0) # first experiment if len(reflections) == 0: print "No reflection data for the first experiment found in the input" self.parser.print_help() return if len(experiments) > 1: raise Sorry("Only one experiment can be imported at present") experiment = experiments[0] om = ObservationManager(reflections, experiment) # This currently does not work :-( # TypeError: Please report this error to [email protected]: No to_python (by-value) converter found for C++ type: scitbx::af::const_ref<cctbx::miller::index<int>, scitbx::af::trivial_accessor> om.group_index
def run(args): from dials.util.options import OptionParser from dials.util.options import flatten_experiments from dials.util.options import flatten_reflections import libtbx.load_env from dials.util import best usage = "%s [options] experiments.json integrated.pickle" % ( libtbx.env.dispatcher_name) parser = OptionParser( usage=usage, phil=phil_scope, read_experiments=True, read_reflections=True, epilog=help_message) params, options = parser.parse_args(show_diff_phil=True) experiments = flatten_experiments(params.input.experiments) reflections = flatten_reflections(params.input.reflections) if len(experiments) == 0 or len(reflections) == 0: parser.print_help() exit() #assert(len(experiments) == 1) experiment = experiments[0] reflections = reflections[0] imageset = experiment.imageset best.write_background_file('bestfile.dat', imageset, n_bins=params.n_bins) best.write_integrated_hkl('bestfile', reflections) best.write_par_file('bestfile.par', experiment)
def run(args): import libtbx.load_env usage = "%s experiments.json indexed.pickle [options]" %libtbx.env.dispatcher_name parser = OptionParser( usage=usage, phil=phil_scope, read_experiments=True, read_reflections=True, check_format=False, epilog=help_message) params, options = parser.parse_args(show_diff_phil=True) experiments = flatten_experiments(params.input.experiments) reflections = flatten_reflections(params.input.reflections) if len(experiments) == 0: parser.print_help() return elif len(experiments) > 1: raise Sorry("More than one experiment present") experiment = experiments[0] assert(len(reflections) == 1) reflections = reflections[0] intensities = reflections['intensity.sum.value'] variances = reflections['intensity.sum.variance'] if 'intensity.prf.value' in reflections: intensities = reflections['intensity.prf.value'] variances = reflections['intensity.prf.variance'] sel = (variances > 0) intensities = intensities.select(sel) variances = variances.select(sel) sigmas = flex.sqrt(variances) indices = reflections['miller_index'].select(sel) from cctbx import crystal, miller crystal_symmetry = crystal.symmetry( space_group=experiment.crystal.get_space_group(), unit_cell=experiment.crystal.get_unit_cell()) miller_set = miller.set( crystal_symmetry=crystal_symmetry, anomalous_flag=True, indices=indices) miller_array = miller.array( miller_set=miller_set, data=intensities, sigmas=sigmas).set_observation_type_xray_intensity() #miller_array.setup_binner(n_bins=50, reflections_per_bin=100) miller_array.setup_binner(auto_binning=True, n_bins=20) result = miller_array.i_over_sig_i(use_binning=True) result.show() from cctbx import uctbx d_star_sq_centre = result.binner.bin_centers(2) i_over_sig_i = flex.double( [d if d is not None else 0 for d in result.data[1:-1]]) sel = (i_over_sig_i > 0) d_star_sq_centre = d_star_sq_centre.select(sel) i_over_sig_i = i_over_sig_i.select(sel) log_i_over_sig_i = flex.log(i_over_sig_i) weights = result.binner.counts()[1:-1].as_double().select(sel) fit = flex.linear_regression( d_star_sq_centre, log_i_over_sig_i, weights=weights) m = fit.slope() c = fit.y_intercept() import math y_cutoff = math.log(params.i_sigi_cutoff) x_cutoff = (y_cutoff - c)/m estimated_d_min = uctbx.d_star_sq_as_d(x_cutoff) print "estimated d_min: %.2f" %estimated_d_min if params.plot: from matplotlib import pyplot fig = pyplot.figure() ax = fig.add_subplot(1,1,1) ax.plot( list(d_star_sq_centre), list(log_i_over_sig_i), label=r"ln(I/sigI)") ax.plot(pyplot.xlim(), [(m * x + c) for x in pyplot.xlim()], color='red') ax.plot([x_cutoff, x_cutoff], pyplot.ylim(), color='grey', linestyle='dashed') ax.plot(pyplot.xlim(), [y_cutoff, y_cutoff], color='grey', linestyle='dashed') ax.set_xlabel("d_star_sq") ax.set_ylabel("ln(I/sigI)") ax_ = ax.twiny() # ax2 is responsible for "top" axis and "right" axis xticks = ax.get_xticks() xlim = ax.get_xlim() xticks_d = [ uctbx.d_star_sq_as_d(ds2) if ds2 > 0 else 0 for ds2 in xticks ] xticks_ = [ds2/(xlim[1]-xlim[0]) for ds2 in xticks] ax_.set_xticks(xticks) ax_.set_xlim(ax.get_xlim()) ax_.set_xlabel(r"Resolution ($\AA$)") ax_.set_xticklabels(["%.1f" %d for d in xticks_d]) pyplot.savefig("estimate_resolution_limit.png") pyplot.clf()
def run(args): import libtbx.load_env from libtbx.utils import Sorry usage = "%s [options] experiments.json indexed.pickle" % libtbx.env.dispatcher_name parser = OptionParser( usage=usage, phil=phil_scope, read_reflections=True, read_experiments=True, check_format=False, epilog=help_message, ) params, options = parser.parse_args(show_diff_phil=True) reflections = flatten_reflections(params.input.reflections) experiments = flatten_experiments(params.input.experiments) if len(experiments) == 0 and len(reflections) == 0: parser.print_help() return elif len(experiments.crystals()) > 1: raise Sorry("Only one crystal can be processed at a time") if params.change_of_basis_op is None: raise Sorry("Please provide a change_of_basis_op.") reference_crystal = None if params.reference is not None: from dxtbx.serialize import load reference_experiments = load.experiment_list(params.reference, check_format=False) assert len(reference_experiments.crystals()) == 1 reference_crystal = reference_experiments.crystals()[0] if len(experiments) and params.change_of_basis_op is libtbx.Auto: if reference_crystal is not None: from dials.algorithms.indexing.compare_orientation_matrices import ( difference_rotation_matrix_and_euler_angles, ) cryst = experiments.crystals()[0] R, euler_angles, change_of_basis_op = difference_rotation_matrix_and_euler_angles(cryst, reference_crystal) print "Change of basis op: %s" % change_of_basis_op print "Rotation matrix to transform input crystal to reference::" print R.mathematica_form(format="%.3f", one_row_per_line=True) print "Euler angles (xyz): %.2f, %.2f, %.2f" % euler_angles elif len(reflections): assert len(reflections) == 1 # always re-map reflections to reciprocal space from dials.algorithms.indexing import indexer refl_copy = flex.reflection_table() for i, imageset in enumerate(experiments.imagesets()): if "imageset_id" in reflections[0]: sel = reflections[0]["imageset_id"] == i else: sel = reflections[0]["id"] == i refl = indexer.indexer_base.map_spots_pixel_to_mm_rad( reflections[0].select(sel), imageset.get_detector(), imageset.get_scan() ) indexer.indexer_base.map_centroids_to_reciprocal_space( refl, imageset.get_detector(), imageset.get_beam(), imageset.get_goniometer() ) refl_copy.extend(refl) # index the reflection list using the input experiments list refl_copy["id"] = flex.int(len(refl_copy), -1) from dials.algorithms.indexing import index_reflections index_reflections(refl_copy, experiments, tolerance=0.2) hkl_expt = refl_copy["miller_index"] hkl_input = reflections[0]["miller_index"] change_of_basis_op = derive_change_of_basis_op(hkl_input, hkl_expt) # reset experiments list since we don't want to reindex this experiments = [] else: change_of_basis_op = sgtbx.change_of_basis_op(params.change_of_basis_op) if len(experiments): experiment = experiments[0] cryst_orig = copy.deepcopy(experiment.crystal) cryst_reindexed = cryst_orig.change_basis(change_of_basis_op) if params.space_group is not None: a, b, c = cryst_reindexed.get_real_space_vectors() cryst_reindexed = crystal_model(a, b, c, space_group=params.space_group.group()) experiment.crystal.update(cryst_reindexed) print "Old crystal:" print cryst_orig print print "New crystal:" print cryst_reindexed print print "Saving reindexed experimental models to %s" % params.output.experiments dump.experiment_list(experiments, params.output.experiments) if len(reflections): assert len(reflections) == 1 reflections = reflections[0] miller_indices = reflections["miller_index"] if params.hkl_offset is not None: h, k, l = miller_indices.as_vec3_double().parts() h += params.hkl_offset[0] k += params.hkl_offset[1] l += params.hkl_offset[2] miller_indices = flex.miller_index(h.iround(), k.iround(), l.iround()) non_integral_indices = change_of_basis_op.apply_results_in_non_integral_indices(miller_indices) if non_integral_indices.size() > 0: print "Removing %i/%i reflections (change of basis results in non-integral indices)" % ( non_integral_indices.size(), miller_indices.size(), ) sel = flex.bool(miller_indices.size(), True) sel.set_selected(non_integral_indices, False) miller_indices_reindexed = change_of_basis_op.apply(miller_indices.select(sel)) reflections["miller_index"].set_selected(sel, miller_indices_reindexed) reflections["miller_index"].set_selected(~sel, (0, 0, 0)) print "Saving reindexed reflections to %s" % params.output.reflections easy_pickle.dump(params.output.reflections, reflections)
def run(args): from dials.util.options import OptionParser from dials.util.options import flatten_experiments from dials.util.options import flatten_reflections import libtbx.load_env usage = "%s [options] datablock.json" %( libtbx.env.dispatcher_name) parser = OptionParser( usage=usage, phil=phil_scope, read_experiments=True, read_reflections=True, check_format=True, epilog=help_message) params, options = parser.parse_args(show_diff_phil=True) experiments = flatten_experiments(params.input.experiments) reflections = flatten_reflections(params.input.reflections) if (len(reflections) == 0 or len(experiments) == 0): parser.print_help() exit(0) reflections = reflections[0] assert len(experiments) == 1 experiment = experiments[0] from dials.command_line.check_strategy import filter_shadowed_reflections sel = filter_shadowed_reflections(experiments, reflections) print "%i/%i (%.2f%%) shadowed reflections" %( sel.count(True), sel.size(), 100*sel.count(True)/sel.size()) if params.negate: sel = ~sel shadowed = reflections.select(sel) shadowed.as_pickle(params.output.reflections) if params.output.filter_hkl is not None: from rstbx.cftbx.coordinate_frame_helpers import align_reference_frame from scitbx import matrix detector = experiment.detector if len(detector) > 1: fast = detector[0].get_parent_fast_axis() slow = detector[0].get_parent_slow_axis() Rd = align_reference_frame(fast, (1,0,0), slow, (0,1,0)) origin = Rd * matrix.col(detector[0].get_parent_origin()) else: fast = detector[0].get_fast_axis() slow = detector[0].get_slow_axis() Rd = align_reference_frame(fast, (1,0,0), slow, (0,1,0)) origin = Rd * matrix.col(detector[0].get_origin()) with open(params.output.filter_hkl, 'wb') as f: for ref in shadowed: p = detector[ref['panel']] ox, oy = p.get_raw_image_offset() h, k, l = ref['miller_index'] x, y, z = ref['xyzcal.px'] dx, dy, dz = (2, 2, 2) print >> f, "%i %i %i %.1f %.1f %.1f %.1f %.1f %.1f" %( h, k, l, x+ox, y+oy, z, dx, dy, dz)
# Create the option parser parser = OptionParser( phil=phil_scope, read_experiments=True, read_reflections=True) # Parse the arguments params, options = parser.parse_args(show_diff_phil=True) assert(params.model is not None) model_data, model_mask = pickle.load(open(params.model)) # Get the experiments and reflections experiments = flatten_experiments(params.input.experiments) reflections = flatten_reflections(params.input.reflections) # Get the imageset assert len(experiments) == 1 assert len(reflections) == 1 reflections = reflections[0] imageset = experiments[0].imageset print list(reflections.keys()) reflections.unset_flags(flex.size_t(range(len(reflections))), reflections.flags.integrated_sum) reflections.unset_flags(flex.size_t(range(len(reflections))), reflections.flags.integrated_prf) del reflections['intensity.sum.value'] del reflections['intensity.sum.variance'] del reflections['background.mean'] del reflections['intensity.prf.value'] del reflections['intensity.prf.variance']
def run(self): '''Execute the script.''' from dials.array_family import flex from dials.util.options import flatten_reflections from libtbx.utils import Sorry # Parse the command line params, options = self.parser.parse_args(show_diff_phil=True) reflections = flatten_reflections(params.input.reflections) if len(reflections) == 0: self.parser.print_help() raise Sorry('No valid reflection file given') if len(reflections) != 1: self.parser.print_help() raise Sorry('Exactly 1 reflection file must be specified') reflections = reflections[0] # Check params if params.d_min is not None and params.d_max is not None: if params.d_min > params.d_max: raise Sorry("d_min must be less than d_max") if params.d_min is not None or params.d_max is not None: if 'd' not in reflections: raise Sorry("Reflection table has no resolution information") print "{0} reflections loaded".format(len(reflections)) if (len(params.inclusions.flag) == 0 and len(params.exclusions.flag) == 0 and params.d_min is None and params.d_max is None): print "No filter specified. Performing analysis instead." return self.analysis(reflections) # Build up the initial inclusion selection inc = flex.bool(len(reflections), True) # 2016/07/06 GW logic here not right should be && for each flag not or? for flag in params.inclusions.flag: sel = reflections.get_flags(getattr(reflections.flags, flag)) inc = inc & sel reflections = reflections.select(inc) print "{0} reflections selected to form the working set".format(len(reflections)) # Make requested exclusions from the current selection exc = flex.bool(len(reflections)) for flag in params.exclusions.flag: print flag sel = reflections.get_flags(getattr(reflections.flags, flag)) exc = exc | sel reflections = reflections.select(~exc) print "{0} reflections excluded from the working set".format(exc.count(True)) # Filter based on resolution if params.d_min is not None: selection = reflections['d'] >= params.d_min reflections = reflections.select(selection) print "Selected %d reflections with d >= %f" % (len(reflections), params.d_min) # Filter based on resolution if params.d_max is not None: selection = reflections['d'] <= params.d_max reflections = reflections.select(selection) print "Selected %d reflections with d <= %f" % (len(reflections), params.d_max) # Save filtered reflections to file if params.output.reflections: print "Saving {0} reflections to {1}".format(len(reflections), params.output.reflections) reflections.as_pickle(params.output.reflections) return