def tst_crystal(self): from dxtbx.serialize.crystal import to_dict, from_dict from dxtbx.model.crystal import crystal_model from scitbx import matrix real_space_a = matrix.col((35.2402102454, -7.60002142787, 22.080026774)) real_space_b = matrix.col((22.659572494, 1.47163505925, -35.6586361881)) real_space_c = matrix.col((5.29417246554, 38.9981792999, 4.97368666613)) c1 = crystal_model( real_space_a=real_space_a, real_space_b=real_space_b, real_space_c=real_space_c, space_group_symbol="P 1 2/m 1", mosaicity=0.1) d = to_dict(c1) c2 = from_dict(d) eps = 1e-7 assert(abs(matrix.col(d['real_space_a']) - real_space_a) <= eps) assert(abs(matrix.col(d['real_space_b']) - real_space_b) <= eps) assert(abs(matrix.col(d['real_space_c']) - real_space_c) <= eps) assert(d['space_group_hall_symbol'] == "-P 2y") assert(d['mosaicity'] == 0.1) assert(c1 == c2) print 'OK'
def tst_crystal_with_scan_points(self): from dxtbx.serialize.crystal import to_dict, from_dict from dxtbx.model.crystal import crystal_model from scitbx import matrix real_space_a = matrix.col((35.2402102454, -7.60002142787, 22.080026774)) real_space_b = matrix.col((22.659572494, 1.47163505925, -35.6586361881)) real_space_c = matrix.col((5.29417246554, 38.9981792999, 4.97368666613)) c1 = crystal_model( real_space_a=real_space_a, real_space_b=real_space_b, real_space_c=real_space_c, space_group_symbol="P 1 2/m 1", mosaicity=0.1) A = c1.get_A() c1.set_A_at_scan_points([A for i in range(5)]) d = to_dict(c1) c2 = from_dict(d) eps = 1e-9 for Acomp in (d['A_at_scan_points']): for e1, e2 in zip(A, Acomp): assert(abs(e1 - e2) <= eps) assert(c1 == c2) print 'OK'
def work(filename, cl=None): if cl is None: cl = [] import libtbx.phil phil_scope = libtbx.phil.parse('''\ index = False .type = bool integrate = False .type = bool indexing_min_spots = 10 .type = int(value_min=1) ''') if not os.access(filename, os.R_OK): raise RuntimeError("Server does not have read access to file %s" %filename) interp = phil_scope.command_line_argument_interpreter() params, unhandled = interp.process_and_fetch( cl, custom_processor='collect_remaining') index = params.extract().index integrate = params.extract().integrate indexing_min_spots = params.extract().indexing_min_spots from dials.command_line.find_spots import phil_scope as find_spots_phil_scope from dxtbx.datablock import DataBlockFactory from dials.array_family import flex interp = find_spots_phil_scope.command_line_argument_interpreter() phil_scope, unhandled = interp.process_and_fetch( unhandled, custom_processor='collect_remaining') logger.info('The following spotfinding parameters have been modified:') logger.info(find_spots_phil_scope.fetch_diff(source=phil_scope).as_str()) params = phil_scope.extract() # no need to write the hot mask in the server/client params.spotfinder.write_hot_mask = False datablock = DataBlockFactory.from_filenames([filename])[0] t0 = time.time() reflections = flex.reflection_table.from_observations(datablock, params) t1 = time.time() logger.info('Spotfinding took %.2f seconds' %(t1-t0)) from dials.algorithms.spot_finding import per_image_analysis imageset = datablock.extract_imagesets()[0] scan = imageset.get_scan() if scan is not None: i = scan.get_array_range()[0] else: i = 0 stats = per_image_analysis.stats_single_image( imageset, reflections, i=i, plot=False) stats = stats.__dict__ t2 = time.time() logger.info('Resolution analysis took %.2f seconds' %(t2-t1)) if index and stats['n_spots_no_ice'] > indexing_min_spots: import logging logging.basicConfig(stream=sys.stdout, level=logging.INFO) from dials.algorithms.indexing import indexer from dxtbx.serialize.crystal import to_dict interp = indexer.master_phil_scope.command_line_argument_interpreter() phil_scope, unhandled = interp.process_and_fetch( unhandled, custom_processor='collect_remaining') imagesets = [imageset] logger.info('The following indexing parameters have been modified:') indexer.master_phil_scope.fetch_diff(source=phil_scope).show() params = phil_scope.extract() params.indexing.scan_range=[] if (imageset.get_goniometer() is not None and imageset.get_scan() is not None and imageset.get_scan().get_oscillation()[1] == 0): imageset.set_goniometer(None) imageset.set_scan(None) try: idxr = indexer.indexer_base.from_parameters( reflections, imagesets, params=params) indexing_results = [] indexed_sel = idxr.refined_reflections.get_flags( idxr.refined_reflections.flags.indexed) indexed_sel &= ~(idxr.refined_reflections.get_flags( idxr.refined_reflections.flags.centroid_outlier)) for i_expt, expt in enumerate(idxr.refined_experiments): sel = idxr.refined_reflections['id'] == i_expt sel &= indexed_sel indexing_results.append({ 'crystal': to_dict(expt.crystal), 'n_indexed': sel.count(True), 'fraction_indexed': sel.count(True)/sel.size()}) stats['lattices'] = indexing_results stats['n_indexed'] = indexed_sel.count(True) stats['fraction_indexed'] = indexed_sel.count(True)/len(reflections) except Exception, e: logger.error(e) stats['error'] = str(e) #stats.crystal = None #stats.n_indexed = None #stats.fraction_indexed = None finally: