def exercise_expand(): sg = sgtbx.space_group("P 41 (1,-1,0)") h = flex.miller_index(((3,1,-2), (1,-2,0))) assert tuple(sg.is_centric(h)) == (0, 1) p1 = miller.expand_to_p1_iselection( space_group=sg, anomalous_flag=False, indices=h, build_iselection=False) p1_i0 = ((-3,-1,2), (-1, 3,2),(3,1,2),(1,-3,2),(1,-2, 0),(2,1,0)) assert tuple(p1.indices) == p1_i0 assert p1.iselection.size() == 0 p1 = miller.expand_to_p1_iselection( space_group=sg, anomalous_flag=True, indices=h, build_iselection=False) assert tuple(p1.indices) \ == ((3,1,-2), (1,-3,-2), (-3,-1,-2), (-1,3,-2), (1,-2,0), (-2,-1,0), (-1,2,0), (2,1,0)) p1 = miller.expand_to_p1_iselection( space_group=sg, anomalous_flag=False, indices=h, build_iselection=True) assert tuple(p1.indices) == p1_i0 assert tuple(p1.iselection) == (0,0,0,0,1,1) a = flex.double((1,2)) p = flex.double((10,90)) p1 = miller.expand_to_p1_phases( space_group=sg, anomalous_flag=False, indices=h, data=p, deg=True) assert approx_equal(tuple(p1.data), (-10,110,110,-10, 90,30)) p1 = miller.expand_to_p1_phases( space_group=sg, anomalous_flag=True, indices=h, data=p, deg=True) assert approx_equal(tuple(p1.data), (10,-110,-110,10, 90,-30,-90,30)) p = flex.double([x * math.pi/180 for x in p]) v = [x * math.pi/180 for x in p1.data] p1 = miller.expand_to_p1_phases( space_group=sg, anomalous_flag=True, indices=h, data=p, deg=False) assert approx_equal(tuple(p1.data), v) f = flex.polar(a, p) p1 = miller.expand_to_p1_complex( space_group=sg, anomalous_flag=True, indices=h, data=f) assert approx_equal(tuple(flex.abs(p1.data)), (1,1,1,1,2,2,2,2)) assert approx_equal(tuple(flex.arg(p1.data)), v) hl = flex.hendrickson_lattman([(1,2,3,4), (5,6,7,8)]) p1 = miller.expand_to_p1_hendrickson_lattman( space_group=sg, anomalous_flag=True, indices=h, data=hl) assert approx_equal(p1.data, [ [1,2,3,4], [1.232051,-1.866025,-4.964102,0.5980762], [1.232051,-1.866025,-4.964102,0.5980762], [1,2,3,4], [5,6,7,8], [2.696152,-7.330127,-10.4282,2.062178], [-5,-6,7,8], [7.696152,-1.330127,3.428203,-10.06218]]) b = flex.bool([True,False]) p1 = miller.expand_to_p1_iselection( space_group=sg, anomalous_flag=True, indices=h, build_iselection=True) assert b.select(p1.iselection).all_eq( flex.bool([True, True, True, True, False, False, False, False])) i = flex.int([13,17]) p1 = miller.expand_to_p1_iselection( space_group=sg, anomalous_flag=True, indices=h, build_iselection=True) assert i.select(p1.iselection).all_eq(flex.int([13,13,13,13,17,17,17,17])) # assert approx_equal(miller.statistical_mean(sg, False, h, a), 4/3.) assert approx_equal(miller.statistical_mean(sg, True, h, a), 3/2.)
def run(args): import libtbx.load_env usage = "%s experiments.json [options]" %libtbx.env.dispatcher_name parser = OptionParser( usage=usage, phil=phil_scope, read_experiments=True, check_format=False, epilog=help_message) params, options = parser.parse_args(show_diff_phil=True) experiments = flatten_experiments(params.input.experiments) if len(experiments) == 0: parser.print_help() return elif len(experiments) > 1: raise Sorry("More than one experiment present") assert len(params.miller_index), "Must specify at least one miller_index to predict." experiment = experiments[0] reflections = flex.reflection_table() miller_indices = flex.miller_index() entering_flags = flex.bool() for mi in params.miller_index: miller_indices.append(mi) miller_indices.append(mi) entering_flags.append(True) entering_flags.append(False) reflections['miller_index'] = miller_indices reflections['entering'] = entering_flags reflections['id'] = flex.size_t(len(reflections), 0) if params.expand_to_p1: from cctbx.miller import expand_to_p1_iselection proxy = expand_to_p1_iselection( experiment.crystal.get_space_group(), anomalous_flag=True, indices=miller_indices, build_iselection=True) reflections = reflections.select(proxy.iselection) reflections['miller_index'] = proxy.indices from dials.algorithms.refinement.prediction.managed_predictors import ExperimentsPredictor predictor = ExperimentsPredictor([experiment]) predicted = predictor.predict(reflections) zmin, zmax = experiment.scan.get_array_range() z = predicted['xyzcal.px'].parts()[2] predicted = predicted.select((z >= zmin) & (z <= zmax)) show_predictions(predicted)
def run(args): assert args in [[], ["python"], ["c++"]] # sgno_list_by_index_list_by_cs = {} from cctbx import sgtbx from cctbx import miller for symbols in sgtbx.space_group_symbol_iterator(): psgi = sgtbx.space_group_info(symbols.universal_hermann_mauguin()) \ .primitive_setting() p_indices = miller.index_generator(space_group_type=psgi.type(), anomalous_flag=False, max_index=[4] * 3).to_array() # 4 is the smallest value leading to correct results; any larger # value will work, too, but will make this procedure slower p1_indices = miller.expand_to_p1_iselection( space_group=psgi.group(), anomalous_flag=False, indices=p_indices, build_iselection=False).indices from cctbx.array_family import flex sort_perm = flex.sort_permutation( data=miller.index_span(p1_indices).pack(p1_indices)) p1_indices = p1_indices.select(sort_perm) index_list = tuple(p1_indices) sgno = psgi.type().number() sgno_list_by_index_list = sgno_list_by_index_list_by_cs \ .setdefault(symbols.crystal_system(), {}) sgno_list_by_index_list.setdefault(index_list, []).append(sgno) from scitbx.graph import tardy_tree cluster_manager = tardy_tree.cluster_manager(n_vertices=231) for cs, sgno_list_by_index_list in sgno_list_by_index_list_by_cs.items(): for sgno_list in sgno_list_by_index_list.values(): i = sgno_list[0] for j in sgno_list[1:]: cluster_manager.connect_vertices(i=i, j=j, optimize=True) cluster_manager.tidy() # # everything below is just to format the results # if (args == []): for cluster in cluster_manager.clusters: if (len(cluster) == 1): break print(cluster) else: note = ("""\ Output of: cctbx/examples/find_sys_abs_equiv_space_groups.py %s If you have to edit this table, please send email to: [email protected] """ % args[0]).splitlines() # if (args == ["python"]): print("space_group_numbers = [") for line in note: print(" #", line) ci = cluster_manager.cluster_indices cl = cluster_manager.clusters for sgno in range(231): cluster = list(cl[ci[sgno]]) cluster.remove(sgno) if (len(cluster) == 0): s = "None" else: s = str(tuple(cluster)) if (sgno == 230): comma = "" else: comma = "," print(" %s%s" % (s, comma)) print("]") else: print("""\ #ifndef CCTBX_SGTBX_SYS_ABS_EQUIV_H #define CCTBX_SGTBX_SYS_ABS_EQUIV_H namespace cctbx { namespace sgtbx { namespace sys_abs_equiv { """) data = [] ci = cluster_manager.cluster_indices cl = cluster_manager.clusters for line in note: print(" //", line) for sgno in range(231): cluster = list(cl[ci[sgno]]) cluster.remove(sgno) if (len(cluster) == 0): data.append("0") else: cid = "data_%03d" % sgno data.append(cid) print(" static const unsigned %s[] = {%d, %s};" % (cid, len(cluster), ", ".join( [str(i) for i in cluster]))) print("") print(" static const unsigned* space_group_numbers[] = {") print(" ", ",\n ".join(data)) print("""\ }; }}} #endif // GUARD""")
def run(args): assert args in [[], ["python"], ["c++"]] # sgno_list_by_index_list_by_cs = {} from cctbx import sgtbx from cctbx import miller for symbols in sgtbx.space_group_symbol_iterator(): psgi = sgtbx.space_group_info(symbols.universal_hermann_mauguin()) \ .primitive_setting() p_indices = miller.index_generator( space_group_type=psgi.type(), anomalous_flag=False, max_index=[4]*3).to_array() # 4 is the smallest value leading to correct results; any larger # value will work, too, but will make this procedure slower p1_indices = miller.expand_to_p1_iselection( space_group=psgi.group(), anomalous_flag=False, indices=p_indices, build_iselection=False).indices from cctbx.array_family import flex sort_perm = flex.sort_permutation( data=miller.index_span(p1_indices).pack(p1_indices)) p1_indices = p1_indices.select(sort_perm) index_list = tuple(p1_indices) sgno = psgi.type().number() sgno_list_by_index_list = sgno_list_by_index_list_by_cs \ .setdefault(symbols.crystal_system(), {}) sgno_list_by_index_list.setdefault(index_list, []).append(sgno) from scitbx.graph import tardy_tree cluster_manager = tardy_tree.cluster_manager(n_vertices=231) for cs,sgno_list_by_index_list in sgno_list_by_index_list_by_cs.items(): for sgno_list in sgno_list_by_index_list.values(): i = sgno_list[0] for j in sgno_list[1:]: cluster_manager.connect_vertices(i=i, j=j, optimize=True) cluster_manager.tidy() # # everything below is just to format the results # if (args == []): for cluster in cluster_manager.clusters: if (len(cluster) == 1): break print cluster else: note = ("""\ Output of: cctbx/examples/find_sys_abs_equiv_space_groups.py %s If you have to edit this table, please send email to: [email protected] """ % args[0]).splitlines() # if (args == ["python"]): print "space_group_numbers = [" for line in note: print " #", line ci = cluster_manager.cluster_indices cl = cluster_manager.clusters for sgno in xrange(231): cluster = list(cl[ci[sgno]]) cluster.remove(sgno) if (len(cluster) == 0): s = "None" else: s = str(tuple(cluster)) if (sgno == 230): comma = "" else: comma = "," print " %s%s" % (s, comma) print "]" else: print """\ #ifndef CCTBX_SGTBX_SYS_ABS_EQUIV_H #define CCTBX_SGTBX_SYS_ABS_EQUIV_H namespace cctbx { namespace sgtbx { namespace sys_abs_equiv { """ data = [] ci = cluster_manager.cluster_indices cl = cluster_manager.clusters for line in note: print " //", line for sgno in xrange(231): cluster = list(cl[ci[sgno]]) cluster.remove(sgno) if (len(cluster) == 0): data.append("0") else: cid = "data_%03d" % sgno data.append(cid) print " static const unsigned %s[] = {%d, %s};" % ( cid, len(cluster), ", ".join([str(i) for i in cluster])) print "" print " static const unsigned* space_group_numbers[] = {" print " ", ",\n ".join(data) print """\
def run(args): import libtbx.load_env usage = "%s experiments.json [options]" % libtbx.env.dispatcher_name parser = OptionParser( usage=usage, phil=phil_scope, read_experiments=True, check_format=False, epilog=help_message, ) params, options = parser.parse_args(show_diff_phil=True) experiments = flatten_experiments(params.input.experiments) if len(experiments) == 0: parser.print_help() return elif len(experiments) > 1: raise Sorry("More than one experiment present") assert len(params.miller_index ), "Must specify at least one miller_index to predict." experiment = experiments[0] reflections = flex.reflection_table() miller_indices = flex.miller_index() entering_flags = flex.bool() for mi in params.miller_index: miller_indices.append(mi) miller_indices.append(mi) entering_flags.append(True) entering_flags.append(False) reflections["miller_index"] = miller_indices reflections["entering"] = entering_flags reflections["id"] = flex.size_t(len(reflections), 0) if params.expand_to_p1: from cctbx.miller import expand_to_p1_iselection proxy = expand_to_p1_iselection( experiment.crystal.get_space_group(), anomalous_flag=True, indices=miller_indices, build_iselection=True, ) reflections = reflections.select(proxy.iselection) reflections["miller_index"] = proxy.indices from dials.algorithms.refinement.prediction.managed_predictors import ( ExperimentsPredictor, ) predictor = ExperimentsPredictor([experiment]) predicted = predictor.predict(reflections) zmin, zmax = experiment.scan.get_array_range() z = predicted["xyzcal.px"].parts()[2] predicted = predicted.select((z >= zmin) & (z <= zmax)) show_predictions(predicted)