def linear_save(volumes, dir_name, frames, niter, reg, rate, subregion='all', step = 1, model_id = None) : v1 = volumes[0] v2 = volumes[1] m1 = v1.matrix(step = step, subregion = subregion) m2 = v2.matrix(step = step, subregion = subregion) from .utils import convolutional_barycenter, convolutional_barycenter_cpu, convolutional_barycenter_gpu import mrcfile import progressbar rate_function = RateMap[rate.lower()] all_weights = rate_function(frames) all_weights = [(round(i,6),round(1-i,6)) for i in all_weights] for i,weights in enumerate(all_weights): if i%5 == 0 : print('(%i of %i)'%(i,frames)) padding = len(str(frames))+1 str_i = str(i) padded_i = str_i.zfill(padding) result_file = dir_name + '/' + padded_i + 'linear_%s_%s_weights%s.mrc'%(v1.name,v2.name, str(weights)) import time t0 = time.time() m = weights[0]*m1+weights[1]*m2 print(time.time()-t0) from chimerax.map.data import ArrayGridData from chimerax.map.data.mrc import save m_grid = ArrayGridData(m) save(m_grid, result_file)
def ot_save(volumes, dir_name, frames, niter, reg, rate, subregion='all', step=1, model_id=None, name1=None, name2=None): v1 = volumes[0] v2 = volumes[1] m1 = v1.matrix(step=step, subregion=subregion) m2 = v2.matrix(step=step, subregion=subregion) from .utils import convolutional_barycenter, convolutional_barycenter_cpu, convolutional_barycenter_gpu import mrcfile import progressbar rate_function = RateMap[rate.lower()] all_weights = rate_function(frames) all_weights = [(round(i, 6), round(1 - i, 6)) for i in all_weights] for i, weights in enumerate(all_weights): if i % 5 == 0: print('(%i of %i)' % (i, frames)) padding = len(str(frames)) + 1 str_i = str(i) padded_i = str_i.zfill(padding) if name1 == None: name1 = v1.name if name2 == None: name2 = v2.name #result_file = dir_name + '/' +padded_i +'ot_%s_%s_weights%s.mrc'%(v1.name,v2.name, str(weights)) result_file = dir_name + '/' + padded_i + 'ot_%s_%s_weights%s.mrc' % ( name1, name2, str(weights)) #result_file = dir_name + '/ot_%s_%s_weights%s.mrc'%(v1.name,v2.name, str(weights)) m = convolutional_barycenter([m1, m2], reg, weights, niter=niter, verbose=False, cupy_var=cupy_var, filter_func=filter_func) from chimerax.map.data import ArrayGridData from chimerax.map.data.mrc import save m_grid = ArrayGridData(m) save(m_grid, result_file)