def step_v(n, mn, mx): step = () box = () for a, b in zip(mn, mx): box += tuple([b - a]) step += tuple([(b - a) / rint(n)]) v = rint(n * n * n) / (box[0] * box[1] * box[2]) return step, v
def step_v(n, mn, mx): step = () box = () for a,b in zip(mn,mx): box += tuple( [b-a] ) step += tuple( [(b-a)/rint(n)] ) v = rint( n*n*n ) / (box[0]*box[1]*box[2]) return step, v
def number_from_string(s): flds = s.split("/") if (len(flds) == 2): from boost.rational import int as rint return rint(int(flds[0]), int(flds[1])) return (eval(s) + 0) * 1
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 loop_grid(asu, n, mn, mx, asu2=None): assert (asu2 is None) or isinstance(asu, new_asu.direct_space_asu) first_is_new = False step, vv = step_v(n, mn, mx) grid = () for s in step: g = rint(1) / s g = g.numerator() // g.denominator() + 1 assert g > 0, "Step = " + str(step) grid += tuple([g]) mna = list(mn) mxa = list(mx) for i in xrange(3): mna[i] -= 5 * step[i] mna[i] *= grid[i] mna[i] = mna[i].numerator() // mna[i].denominator() - 1 mxa[i] += 5 * step[i] mxa[i] *= grid[i] mxa[i] = mxa[i].numerator() // mxa[i].denominator() + 1 print >>cout, "grid test step= ", step, " min= ", mna, " max= ", mxa, \ " grid=", grid if isinstance(asu, new_asu.direct_space_asu): import copy # TODO: implement # asu_opt = copy.copy(asu) # asu_opt.optimize_for_grid(grid) # assert asu_opt.is_optimized() and (not asu.is_optimized()) first_is_new = True # max_p = asu_opt.get_optimized_grid_limits() # print >>cout, "grid limits: ", max_p result = 0 i = mna[0] while i <= mxa[0]: ii = rint(i, grid[0]) j = mna[1] while j <= mxa[1]: jj = rint(j, grid[1]) k = mna[2] while k <= mxa[2]: kk = rint(k, grid[2]) b = asu.is_inside((ii, jj, kk)) # rational test if b: result += 1 if first_is_new: num = (i, j, k) den = grid where = asu.where_is(num, den) # integer test #TODO: implement? assert b == asu.is_inside(num,den) assert (b and (where == 1 or where == -1)) or ((not b) and where == 0) #TODO: implemnt where_opt = asu_opt.where_is( num ) # optimized test # assert where_opt == where #TODO: implement? assert b == asu_opt.is_inside(num) if asu2 is not None: assert b == asu2.is_inside((ii, jj, kk)) # rational test k += 1 j += 1 i += 1 shape = result / vv return (result, shape)
def number_from_string(s): flds = s.split("/") if (len(flds) == 2): from boost.rational import int as rint return rint(int(flds[0]), int(flds[1])) return (eval(s)+0)*1
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 loop_grid(asu, n, mn, mx, asu2=None): assert (asu2 is None) or isinstance(asu, new_asu.direct_space_asu) first_is_new = False step, vv = step_v(n, mn, mx) grid = () for s in step: g = rint(1) / s g = g.numerator()//g.denominator() + 1 assert g > 0, "Step = "+str(step) grid += tuple([g]) mna = list(mn) mxa = list(mx) for i in xrange(3): mna[i] -= 5*step[i] mna[i] *= grid[i] mna[i] = mna[i].numerator()//mna[i].denominator()-1 mxa[i] += 5*step[i] mxa[i] *= grid[i] mxa[i] = mxa[i].numerator()//mxa[i].denominator()+1 print >>cout, "grid test step= ", step, " min= ", mna, " max= ", mxa, \ " grid=", grid if isinstance(asu, new_asu.direct_space_asu): import copy # TODO: implement # asu_opt = copy.copy(asu) # asu_opt.optimize_for_grid(grid) # assert asu_opt.is_optimized() and (not asu.is_optimized()) first_is_new = True # max_p = asu_opt.get_optimized_grid_limits() # print >>cout, "grid limits: ", max_p result = 0 i = mna[0] while i <= mxa[0] : ii = rint(i,grid[0]) j = mna[1] while j <= mxa[1] : jj = rint(j,grid[1]) k = mna[2] while k <= mxa[2] : kk = rint(k,grid[2]) b = asu.is_inside((ii,jj,kk)) # rational test if b : result += 1 if first_is_new: num = (i, j, k) den = grid where = asu.where_is(num,den) # integer test #TODO: implement? assert b == asu.is_inside(num,den) assert ( b and (where==1 or where==-1)) or ( (not b) and where==0 ) #TODO: implemnt where_opt = asu_opt.where_is( num ) # optimized test # assert where_opt == where #TODO: implement? assert b == asu_opt.is_inside(num) if asu2 is not None : assert b == asu2.is_inside( (ii,jj,kk) ) # rational test k += 1 j += 1 i += 1 shape = result / vv return (result,shape)