def find_distances(unit_cell, space_group, sites_frac, distance_cutoff): space_group_type = space_group.type() # reference_asu, metric_free_asu, and asu are Python objects reference_asu = cctbx.sgtbx.direct_space_asu.reference_table.get_asu(space_group_type.number()) metric_free_asu = reference_asu.change_basis( space_group_type.cb_op().inverse() # change_of_basis_op_to_reference_setting ) asu = cctbx.crystal.direct_space_asu.direct_space_asu(asu=metric_free_asu, unit_cell=unit_cell) proto_asu = proto.direct_space_asu(space_group_type) # C++ type # todo in C++: convert proto_asu cuts to as_float_cut_plane() # all objects below are wrapped C++ objects float_asu = cctbx.crystal.direct_space_asu_float_asu( unit_cell=unit_cell, cuts=[cut.as_float_cut_plane() for cut in metric_free_asu.cuts], is_inside_epsilon=1.0e-6 ) asu_mappings = cctbx.crystal.direct_space_asu_asu_mappings( space_group=space_group, asu=float_asu, buffer_thickness=distance_cutoff ) asu_mappings.process_sites_frac(original_sites=sites_frac, min_distance_sym_equiv=0.5) pair_asu_table = cctbx.crystal.pair_asu_table(asu_mappings=asu_mappings) pair_asu_table.add_all_pairs(distance_cutoff=distance_cutoff) pair_sym_table = pair_asu_table.extract_pair_sym_table() for i, pair_sym_dict in enumerate(pair_sym_table): print "i:", i for j, sym_ops in pair_sym_dict.items(): print " j:", j for sym_op in sym_ops: frac_i = sites_frac[i] frac_j = sites_frac[j] frac_ji = sym_op * frac_j print " %-20s %8.3f" % (str(sym_op), unit_cell.distance(frac_i, frac_ji))
def find_distances(unit_cell, space_group, sites_frac, distance_cutoff): space_group_type = space_group.type() # reference_asu, metric_free_asu, and asu are Python objects reference_asu = cctbx.sgtbx.direct_space_asu.reference_table.get_asu( space_group_type.number()) metric_free_asu = reference_asu.change_basis( space_group_type.cb_op() # change_of_basis_op_to_reference_setting .inverse()) asu = cctbx.crystal.direct_space_asu.direct_space_asu(asu=metric_free_asu, unit_cell=unit_cell) proto_asu = proto.direct_space_asu(space_group_type) # C++ type # todo in C++: convert proto_asu cuts to as_float_cut_plane() # all objects below are wrapped C++ objects float_asu = cctbx.crystal.direct_space_asu_float_asu( unit_cell=unit_cell, cuts=[cut.as_float_cut_plane() for cut in metric_free_asu.cuts], is_inside_epsilon=1.e-6) asu_mappings = cctbx.crystal.direct_space_asu_asu_mappings( space_group=space_group, asu=float_asu, buffer_thickness=distance_cutoff) asu_mappings.process_sites_frac(original_sites=sites_frac, min_distance_sym_equiv=0.5) pair_asu_table = cctbx.crystal.pair_asu_table(asu_mappings=asu_mappings) pair_asu_table.add_all_pairs(distance_cutoff=distance_cutoff) pair_sym_table = pair_asu_table.extract_pair_sym_table() for i, pair_sym_dict in enumerate(pair_sym_table): print("i:", i) for j, sym_ops in pair_sym_dict.items(): print(" j:", j) for sym_op in sym_ops: frac_i = sites_frac[i] frac_j = sites_frac[j] frac_ji = sym_op * frac_j print(" %-20s %8.3f" % (str(sym_op), unit_cell.distance(frac_i, frac_ji)))
def compare(spgr, n=NSteps, verbose=False): if verbose: print cout.getvalue() cout.truncate(0) grp = space_group_info(spgr) print >> cout, "Comparing asus for group: ", spgr, " n-steps= ", n asuo = grp.direct_space_asu() print >> cout, "=== Original python asu ===" asuo.show_comprehensive_summary(cout) print >> cout, ":: raw facets" as_raw_asu(asuo, cout) mxo = tuple(asuo.box_max()) mno = tuple(asuo.box_min()) print >> cout, "box min= ", mno, " max= ", mxo ### NEW C++ ASU asun = new_asu.direct_space_asu(grp.type()) print >> cout, "=== New C++ asu ===" asun.show_comprehensive_summary(cout) mnn = asun.box_min() mxn = asun.box_max() print >> cout, "box min= ", mnn, " max= ", mxn assert mnn == mno assert mxn == mxo old_vertices = asuo.shape_vertices() new_vertices = asun.shape_vertices() # C++ sorted list assert len(old_vertices) == len(new_vertices) # TODO: the following seems to use the same ordering operation # as mine in C++ old_vertices = sorted(old_vertices) for a, b in zip(old_vertices, new_vertices): print >> cout, a, " == ", b assert a == b, str(a) + " != " + str(b) ins, v = loop_grid(asun, n, mnn, mxn, asuo) print >>cout, "N inside = ", ins, " volume = ", v, \ " expected volume = ", rint(1,grp.group().order_z()) ### SHAPE ONLY asun.shape_only() asuo = asuo.shape_only() mxo2 = tuple(asuo.box_max()) mno2 = tuple(asuo.box_min()) mnn2 = asun.box_min() mxn2 = asun.box_max() assert mxo2 == mxo assert mno2 == mno assert mxn2 == mxn assert mnn2 == mnn loop_grid(asun, n, mnn, mxn, asuo) unit_cell = grp.any_compatible_unit_cell(volume=5000.0) fasun = asun.as_float_asu(unit_cell, 1.0E-6) fasuo = cctbx.crystal.direct_space_asu_float_asu( unit_cell=unit_cell, cuts=[cut.as_float_cut_plane() for cut in asuo.cuts], is_inside_epsilon=1.e-6) # python sucks big: still (in 2.5) there is no float.epsilon/max/tiny/etc assert approx_equal(fasun.is_inside_epsilon(), fasuo.is_inside_epsilon(), 1.0E-100) assert len(fasun.cuts()) == len(fasuo.cuts()), \ "%d != %d"%(len(fasuo.cuts()),len(fasun.cuts())) assert ((len(fasun.cuts()) < 200) & (len(fasun.cuts()) > 3)), \ len(fasun.cuts()) if verbose: print cout.getvalue() cout.truncate(0)
def compare(spgr, n=NSteps, verbose=False): if verbose: print cout.getvalue() cout.truncate(0) grp = space_group_info(spgr) print >>cout, "Comparing asus for group: ", spgr, " n-steps= ", n asuo = grp.direct_space_asu() print >>cout, "=== Original python asu ===" asuo.show_comprehensive_summary(cout) print >>cout, ":: raw facets" as_raw_asu(asuo, cout) mxo = tuple( asuo.box_max() ) mno = tuple( asuo.box_min() ) print >>cout, "box min= ", mno, " max= ", mxo ### NEW C++ ASU asun = new_asu.direct_space_asu(grp.type()) print >>cout, "=== New C++ asu ===" asun.show_comprehensive_summary(cout) mnn = asun.box_min() mxn = asun.box_max() print >>cout, "box min= ", mnn, " max= ", mxn assert mnn == mno assert mxn == mxo old_vertices = asuo.shape_vertices() new_vertices = asun.shape_vertices() # C++ sorted list assert len(old_vertices) == len(new_vertices) # TODO: the following seems to use the same ordering operation # as mine in C++ old_vertices = sorted(old_vertices) for a,b in zip(old_vertices,new_vertices): print >>cout, a, " == ", b assert a == b, str(a)+" != "+str(b) ins,v = loop_grid(asun, n, mnn, mxn, asuo) print >>cout, "N inside = ", ins, " volume = ", v, \ " expected volume = ", rint(1,grp.group().order_z()) ### SHAPE ONLY asun.shape_only() asuo = asuo.shape_only() mxo2 = tuple( asuo.box_max() ) mno2 = tuple( asuo.box_min() ) mnn2 = asun.box_min() mxn2 = asun.box_max() assert mxo2 == mxo assert mno2 == mno assert mxn2 == mxn assert mnn2 == mnn loop_grid(asun, n, mnn, mxn, asuo) unit_cell = grp.any_compatible_unit_cell(volume=5000.0) fasun = asun.as_float_asu( unit_cell, 1.0E-6); fasuo = cctbx.crystal.direct_space_asu_float_asu( unit_cell=unit_cell, cuts=[cut.as_float_cut_plane() for cut in asuo.cuts], is_inside_epsilon=1.e-6) # python sucks big: still (in 2.5) there is no float.epsilon/max/tiny/etc assert approx_equal(fasun.is_inside_epsilon(), fasuo.is_inside_epsilon(), 1.0E-100) assert len(fasun.cuts()) == len(fasuo.cuts()), \ "%d != %d"%(len(fasuo.cuts()),len(fasun.cuts())) assert ((len(fasun.cuts()) < 200) & (len(fasun.cuts()) > 3)), \ len(fasun.cuts()) if verbose: print cout.getvalue() cout.truncate(0)