def test_fft(): gv = get_eu_gv() from ImageD11.fft_index_refac import grid from ImageD11.indexing import ubitocellpars, write_ubi_file,\ refine g = grid(np=128, mr=1.0, nsig=20) g.gv_to_grid_new(gv) g.fft() g.props() g.peaksearch(open("eu.patterson_pks", "w")) g.read_peaks("eu.patterson_pks") vecs = rc_array(g.UBIALL.T, direction='col') assert vecs.shape == (3, g.colfile.nrows) order = argsort(g.colfile.sum_intensity)[::-1] vecs = take(vecs, order, axis=1) min_pks = 300 ntry = 0 assert g.gv.shape[1] == 3 tv = rc_array(g.gv, direction='row') print "Finding lattice l1 from patterson" l1 = find_lattice(vecs, min_vec2=9, test_vecs=tv, n_try=20) print "r2c == ubi matrix" print l1.r2c print "scores", l1.score(tv) print "cell", ubitocellpars(l1.r2c) l1.r2c = refine(l1.r2c, g.gv, tol=0.1) l1.c2r = inv(l1.r2c) print "With refine", l1.score(tv) print "cell", ubitocellpars(l1.r2c) print "Finding lattice l2 with gvectors to test" l2 = find_lattice(vecs, min_vec2=9, n_try=20, test_vecs=tv) print "r2c == ubi matrix" print l2.r2c print "scores", l2.score(tv) print "cell", ubitocellpars(l2.r2c) l2.r2c = refine(l2.r2c, g.gv, tol=0.1) l2.c2r = inv(l2.r2c) print "With refine", l2.score(tv) print "cell", ubitocellpars(l2.r2c) return
def test_fft(): gv = get_eu_gv() from ImageD11.fft_index_refac import grid from ImageD11.indexing import ubitocellpars, write_ubi_file,\ refine g = grid( np = 128, mr = 1.0, nsig = 20, minlen = 3. ) g.gv_to_grid_new(gv) g.fft() g.props() g.peaksearch(open("eu.patterson_pks","w")) g.read_peaks("eu.patterson_pks") vecs = g.UBIALL order = argsort( g.colfile.sum_intensity )[::-1] min_pks = 300 try: for i in order: print vecs[i], g.colfile.sum_intensity[i] for j in order[i:]: for k in order[j:]: print i,j,k try: l = lattice( vecs[i], vecs[j], vecs[k], space='real') t = 0.1 ref = refine( l.vi, gv, t) l = lattice( ref[0], ref[1], ref[2], space='real') print "UBI:" print l.vi print ubitocellpars(l.vi) s = l.score_recip( gv , t ) print "Indexes",s ,"at tolerance",t except: import traceback print traceback.print_exc() raise Exception("error") if s > min_pks: write_ubi_file( "trial.ubi", [ l.vi ] ) raise Exception("Really bad control structure") except: import traceback print traceback.print_exc() print "Got something"
else: # Test vectors are the g-vectors # Sort by length before searching?? logging.info("Doing lattice search") l = lattice_reduction.find_lattice( cur_gvecs, min_vec2=options.min_vec2, n_try=options.n_try, test_vecs=all_gvecs, tol=options.tol, fraction_indexed=options.fraction_indexed, noisy=options.noisy, ) if l is None: break l.r2c = indexing.refine(l.r2c, all_gvecs, tol=options.tol) l.c2r = np.linalg.inv(l.r2c) #print "all_gv 3,4", all_gvecs[3:5] #print np.dot(l.r2c, all_gvecs[3:5].T) #print l.score(all_gvecs[3:5], tol = options.tol) #print l.remainders( all_gvecs[3:5]) all = len(all_gvecs) npks = l.score(all_gvecs, tol=options.tol) if (1.0 * npks / len(all_gvecs)) < options.fraction_indexed: break dr = indexing.calc_drlv2(l.r2c, all_gvecs) t2 = options.tol * options.tol # print "tol, dr",t2,dr.shape, [d for d in dr[:10]] # print it !!! n2 = np.sum(np.where(dr < t2, 1, 0))