Exemplo n.º 1
0
def main():
    progname = optparse.os.path.basename(sys.argv[0])
    usage = progname + " stack_in  stack_out"
    parser = optparse.OptionParser(usage, version=sp_global_def.SPARXVERSION)
    (options, args) = parser.parse_args()

    if sp_global_def.CACHE_DISABLE:
        sp_utilities.disable_bdb_cache()

    # check length of arguments list. less than 2 is illegal
    if len(args) < 2:
        sp_global_def.sxprint("usage: " + usage)
        sp_global_def.sxprint("Please run '" + progname +
                              " -h' for detailed options")
    # 2 is file to file copying
    elif 2 == len(args):
        # print "file to file"
        sp_applications.cpy(args[0], args[1])
    # more than 2, this means a wildcard is transformed to a list of filenams
    else:
        # print "list to file"
        #
        # XXX: note that wildcards only work for filenames! wildcards in files
        #    are processed by the shell and read in as a space-delimited list
        #    of filenames. however, this does NOT work for bdb:image1 type names,
        #    since these will not be found and processed by the shell, not being
        #    normal files. globbing of db objects will have to be done here!
        #
        # make sure we only pass the last entry of args as output file name,
        #    since [-1:] pass a list containing only the last entry....
        #
        # application.cpy
        sp_applications.cpy(args[:-1], args[-1:][0])
Exemplo n.º 2
0
def main():
	progname = os.path.basename(sys.argv[0])
	usage = progname + " stack outdir <maskfile> --ou=outer_radius --br=brackets --center=center_type --eps=epsilon --maxit=max_iter --CTF --snr=SNR --function=user_function_name"
	parser = OptionParser(usage,version=SPARXVERSION)
	parser.add_option("--ou", type="float", default=-1, help="  outer radius for a 2-D mask within which the alignment is performed")
	parser.add_option("--br", type="float", default=1.75, help="  brackets for the search of orientation parameters (each parameter will be checked +/- bracket (set to 1.75)")
	parser.add_option("--center", type="float", default=1, help="  0 - if you do not want the average to be centered, 1 - center the average (default=1)")
	parser.add_option("--eps", type="float", default=0.001, help="  stopping criterion, program will terminate when the relative increase of the criterion is less than epsilon  ")
	parser.add_option("--maxit", type="float", default=10, help="  maximum number of iterations (set to 10) ")
	parser.add_option("--CTF", action="store_true", default=False, help="  Consider CTF correction during the alignment ")
	parser.add_option("--snr", type="float", default=1.0, help="  Signal-to-Noise Ratio of the data")	
	parser.add_option("--function", type="string", default="ref_ali2d", help="  name of the reference preparation function")
	(options, args) = parser.parse_args()
	if len(args) < 2 or len(args) >3:
		sxprint( "Usage: " + usage )
		sxprint( "Please run '" + progname + " -h' for detailed options" )
		ERROR( "Invalid number of parameters used. Please see usage information above." )
		return
		
	else:
		if len(args) == 2:
			mask = None
		else:
			mask = args[2]
		
		from sp_applications import local_ali2d

		if sp_global_def.CACHE_DISABLE:
			from sp_utilities import disable_bdb_cache
			disable_bdb_cache()
		
		sp_global_def.BATCH = True	
		local_ali2d(args[0], args[1], mask, options.ou, options.br, options.center, options.eps, options.maxit, options.CTF, options.snr, options.function)
		sp_global_def.BATCH = False	
Exemplo n.º 3
0
def main():

    progname = os.path.basename(sys.argv[0])
    usage = progname + "2Dprojections plot_output Read projection angles from 2Dprojections file or from a text file and write a 2D image file containing their distribution on a hemisphere."
    parser = OptionParser(usage, version=SPARXVERSION)
    parser.add_option("--wnx",
                      type="int",
                      default=256,
                      help="plot image size (default = 256)")

    (options, args) = parser.parse_args()

    if len(args) != 2:
        sxprint("Usage: " + usage)
        sxprint("Please run \'" + progname + " -h\' for detailed options")
        ERROR(
            "Invalid number of parameters used. Please see usage information above."
        )
        return

    else:
        if sp_global_def.CACHE_DISABLE:
            from sp_utilities import disable_bdb_cache
            disable_bdb_cache()
        from sp_applications import plot_projs_distrib
        sp_global_def.BATCH = True
        plot_projs_distrib(args[0], args[1], options.wnx)
        sp_global_def.BATCH = False
Exemplo n.º 4
0
def main():
    progname = os.path.basename(sys.argv[0])
    usage = progname + " input_stack output_stack average --avg --CTF"
    parser = OptionParser(usage, version=SPARXVERSION)
    parser.add_option(
        "--avg",
        action="store_true",
        default=True,
        help=
        "  Subtract averages computed within corners of individual images, default False"
    )
    parser.add_option(
        "--CTF",
        action="store_true",
        default=False,
        help="  Consider CTF correction during the alignment, dafault False")

    (options, args) = parser.parse_args()

    if len(args) != 3:
        sxprint("Usage: " + usage)
        sxprint("Please run \'" + progname + " -h\' for detailed options")
        ERROR(
            "Invalid number of parameters used. Please see usage information above."
        )
        return

    else:
        if sp_global_def.CACHE_DISABLE:
            from sp_utilities import disable_bdb_cache
            disable_bdb_cache()
        from sp_applications import prepare_2d_forPCA
        sp_global_def.BATCH = True
        prepare_2d_forPCA(args[0], args[1], args[2], options.avg, options.CTF)
        sp_global_def.BATCH = False
Exemplo n.º 5
0
def main():

	arglist = []
	for arg in sys.argv:
		arglist.append( arg )

	progname = os.path.basename( arglist[0] )
	usage = progname + "  stack1 <stack2> <mask> --ccc --fsc file --inf --rad=r"
	parser = OptionParser(usage, version=SPARXVERSION)

	parser.add_option( "--ccc", action="store_true", default=False, help="print cross corelation coefficient" )
	parser.add_option( "--fsc", type="string",       default="",    help="calculate resolution curve" )
	parser.add_option( "--inf", action="store_true", default=False, help="print basic infomation of the img" )
	parser.add_option( "--rad", type="int",          default=-1,    help="radius of operation" )

	(options,args) = parser.parse_args( arglist[1:] )
     
	if len(args)<1 or len(args)>3:
		sxprint("usage: " + usage)
		sxprint("Please run '" + progname + " -h' for detailed options")
		ERROR( "Invalid number of parameters. Please see usage information above" )
		return

	if sp_global_def.CACHE_DISABLE:
		from sp_utilities import disable_bdb_cache
		disable_bdb_cache()

	from sp_applications import imgstat

	sp_global_def.BATCH = True
	imgstat( args, options.ccc, options.fsc, options.inf, options.rad )
Exemplo n.º 6
0
def main():
    progname = os.path.basename(sys.argv[0])
    usage = progname + "  input_stack output_stack --subavg=average_image --rad=mask_radius --nvec=number_of_eigenvectors --incore --mask=maskfile --shuffle --usebuf --MPI"
    parser = OptionParser(usage, version=SPARXVERSION)
    parser.add_option("--subavg",
                      type="string",
                      default="",
                      help="subtract average")
    parser.add_option("--rad", type="int", default=-1, help="radius of mask")
    parser.add_option("--nvec",
                      type="int",
                      default=1,
                      help="number of eigenvectors")
    parser.add_option("--mask", type="string", default="", help="mask file")
    parser.add_option("--genbuf",
                      action="store_true",
                      default=False,
                      help="use existing buffer")
    parser.add_option("--shuffle",
                      action="store_true",
                      default=False,
                      help="use shuffle")
    parser.add_option("--incore",
                      action="store_true",
                      default=False,
                      help="no buffer on a disk")
    parser.add_option("--MPI",
                      action="store_true",
                      default=False,
                      help="run mpi version")

    (options, args) = parser.parse_args()

    input_stacks = args[0:-1]
    output_stack = args[-1]

    if options.nvec is None:
        ERROR("Error: number of components is not given")
        return

    isRoot = True
    if options.MPI:
        isRoot = (mpi.mpi_comm_rank(mpi.MPI_COMM_WORLD) == 0)

    if sp_global_def.CACHE_DISABLE:
        from sp_utilities import disable_bdb_cache
        disable_bdb_cache()

    from sp_applications import pca
    sp_global_def.BATCH = True
    vecs = []
    vecs = pca(input_stacks, options.subavg, options.rad, options.nvec,
               options.incore, options.shuffle, not (options.genbuf),
               options.mask, options.MPI)

    if isRoot:
        for i in range(len(vecs)):
            vecs[i].write_image(output_stack, i)

    sp_global_def.BATCH = False
Exemplo n.º 7
0
def main():

    progname = os.path.basename(sys.argv[0])
    usage = progname + " stack dendoname averages_name --K=number_of_groups"
    parser = OptionParser(usage, version=SPARXVERSION)
    parser.add_option("--K",
                      type="int",
                      default=2,
                      help="Number of classes (default 2)")

    (options, args) = parser.parse_args()
    if len(args) != 3:
        sxprint("Usage: " + usage)
        sxprint("Please run \'" + progname + " -h\' for detailed options")
        ERROR(
            "Invalid number of parameters used. Please see usage information above."
        )
        return

    else:
        if sp_global_def.CACHE_DISABLE:
            from sp_utilities import disable_bdb_cache
            disable_bdb_cache()
        from sp_applications import HAC_averages
        sp_global_def.BATCH = True
        HAC_averages(args[0], args[1], args[2], options.K)
        sp_global_def.BATCH = False
Exemplo n.º 8
0
def main():
    progname = os.path.basename(sys.argv[0])
    usage = progname + " input_stack start end output_stack  <mask> --rad=mask_radius"
    parser = OptionParser(usage, version=SPARXVERSION)
    parser.add_option("--rad",     type="int", default=-1, help="radius of mask")
    parser.add_option("--verbose", type="int", default=0,  help="verbose level (0|1)")

    (options, args) = parser.parse_args()

    if len(args) < 4:
        sxprint("Usage: " + usage)
        sxprint("Please run \'" + progname + " -h\' for details")
        ERROR( "Invalid number of parameters used. Please see usage information above." )
        return
    else:
        from string import atoi
        input_stack  = args[0]
        imgstart     = atoi( args[1] )
        imgend       = atoi( args[2] ) +1
        output_stack = args[3]
        if(len(args) == 5): 
            mask = args[4]
        else:
            mask = None

    if sp_global_def.CACHE_DISABLE:
        from sp_utilities import disable_bdb_cache
        disable_bdb_cache()
    from sp_applications import varimax
    sp_global_def.BATCH = True
    varimax(input_stack, list(range(imgstart, imgend)), output_stack, mask, options.rad, options.verbose)
    sp_global_def.BATCH = False
Exemplo n.º 9
0
def main():
	progname = os.path.basename(sys.argv[0])
	usage = progname + " input_filename output_filename --sym=Symmetry group --phi --theta --psi=The 3 Eulerian angles in degrees --r=Radius of mask --phirange --thetarange --psirange=A search scale for each angle --ftol --xtol = convergence criterion the function and angles values"
	parser = OptionParser(usage,version=SPARXVERSION)
	parser.add_option("--sym",        type="string", default="c1", help="  String that specifies the point group symmetry. default = 'c1'")
	parser.add_option("--phi",        type='float',default=0.0, help="  phi angle, default = 0")
	parser.add_option("--theta",      type='float',default=0.0, help=" theta angle, default=0")
	parser.add_option("--psi",        type='float',default=0.0, help=" phi angle, default=0")
	parser.add_option("--r",          type='float',default=None,help=" Input the radius of the mask. default=None")
	parser.add_option("--phirange",   type='float',default=20.0,help=" The search scale for phi angle...default=20")
	parser.add_option("--thetarange", type='float',default=20.0,help=" The search scale for theta angle...default=20")
	parser.add_option("--psirange",   type='float',default=20.0,help=" The search scale for psi angle...default=20")
	parser.add_option("--ftol",       type='float',default=1.e-4,help=" convergence criterion on the function values...default = 1.e-4")
	parser.add_option("--xtol",       type='float',default=1.e-4,help=" convergence criterion on the variable values...default = 1.e-4")
	
	(options, args) = parser.parse_args()
	
	if len(args) != 2:
		sxprint("Usage: " + usage)
		sxprint("Please run \'" + progname + " -h\' for detailed options")
		ERROR( "Invalid number of parameters used. Please see usage information above." )
		return
	
	else:
		if sp_global_def.CACHE_DISABLE:
			from sp_utilities import disable_bdb_cache
			disable_bdb_cache()
		from sp_applications  import  rot_sym
		sp_global_def.BATCH = True
		rot_sym(args[0],args[1],options.sym,options.r,options.phi,options.theta,options.psi,options.phirange,options.thetarange,options.psirange,options.ftol,options.xtol)
		sp_global_def.write_command('.')
		sp_global_def.BATCH = False
Exemplo n.º 10
0
def main():
    progname = os.path.basename(sys.argv[0])
    usage = progname + " stack montagefile --N=image_per_row --gx=gap_on_x_axis --gy=gap_on_y_axis --bg=background_option --scale --number --begin_zero"
    parser = OptionParser(usage, version=SPARXVERSION)
    parser.add_option("--N",
                      type="int",
                      default=10,
                      help="number of images per row (default = 10)")
    parser.add_option(
        "--gx",
        type="int",
        default=0,
        help="number of pixels of the gap on x-axis (default = 0)")
    parser.add_option(
        "--gy",
        type="int",
        default=-1,
        help="number of pixels of the gap on y-axis (default = gx)")
    parser.add_option(
        "--bg",
        type="int",
        default=0,
        help=
        "background option: 0. use minimum as background; 1. use maximum as background; 2. use 0 as background; 3. use average as background (default = 0)"
    )
    parser.add_option("--scale",
                      action="store_true",
                      default=False,
                      help="whether to scale all particles to (0, 1) ")
    parser.add_option("--number",
                      action="store_true",
                      default=False,
                      help="whether to show particle number on the particle")
    parser.add_option("--begin_zero",
                      action="store_true",
                      default=False,
                      help="whether to use zero as the starting point")

    (options, args) = parser.parse_args()

    if len(args) != 2:
        sxprint("Usage: " + usage)
        sxprint("Please run '" + progname + " -h' for detailed options")
        RROR(
            "Invalid number of parameters used. Please see usage information above."
        )
        return

    else:
        if sp_global_def.CACHE_DISABLE:
            from sp_utilities import disable_bdb_cache
            disable_bdb_cache()

        sp_global_def.BATCH = True
        write_montage_file(args[0], args[1], options.N, options.gx, options.gy,
                           options.bg, options.scale, options.number,
                           options.begin_zero)
        sp_global_def.BATCH = False
Exemplo n.º 11
0
def main():

    progname = os.path.basename(sys.argv[0])
    usage = progname + " stack dendoname <maskfile> --link=kind_of_link --dist=kind_of_dist --dissimilar"
    parser = OptionParser(usage, version=SPARXVERSION)
    parser.add_option(
        "--link",
        type='string',
        default="single",
        help="Kind of linkage: single, complete, average (default single)")
    parser.add_option("--dist",
                      type='string',
                      default="sim_SqEuc",
                      help="Kind of distance: SqEuc, CCC (default SqEuc)")
    parser.add_option(
        "--dissimilar",
        action='store_true',
        default=False,
        help="Change the distance to the negative value (default False)")

    chk_link = ['single', 'complete', 'average']
    chk_dist = ['SqEuc', 'CCC']

    (options, args) = parser.parse_args()
    if len(args) < 2 or len(args) > 3:
        sxprint("Usage: " + usage)
        sxprint("Please run '" + progname + " -h' for detailed options")
        ERROR(
            "Invalid number of parameters. Please see usage information above."
        )
        return

    elif options.link not in chk_link:
        ERROR("Kind of linkage unknown")
        return

    elif options.dist not in chk_dist:
        ERROR("Kind of distance unknown")
        return

    else:
        if len(args) == 2: maskname = None
        else: maskname = args[2]

        if sp_global_def.CACHE_DISABLE:
            from sp_utilities import disable_bdb_cache
            disable_bdb_cache()
        from sp_applications import HAC_clustering
        sp_global_def.BATCH = True
        HAC_clustering(args[0], args[1], maskname, options.link, options.dist,
                       options.dissimilar)
        sp_global_def.BATCH = False
Exemplo n.º 12
0
def main():
	
	progname = os.path.basename(sys.argv[0])
	# # horatio active_refactoring Jy51i1EwmLD4tWZ9_00003_1
	# usage = progname + " stack <name_output> --ali --active --set_size=param_name_with_size --set_members=param_name_with_id"
	# # horatio active_refactoring Jy51i1EwmLD4tWZ9_00003_2	
	usage = progname + " stack <name_output> --ali --set_size=param_name_with_size --set_members=param_name_with_id"
	parser = OptionParser(usage,version=SPARXVERSION)
	parser.add_option("--ali"        , action = "store_true", default=False, help="Perform average using alignment parameters")

	# # horatio active_refactoring Jy51i1EwmLD4tWZ9_00004_1	
	# parser.add_option("--active"     , action = "store_true", default=False, help="Perform average only for active images")
	
	parser.add_option("--set_size"   , type   = "string"    , default=None , help="Save number of input images to parameter with given name")
	parser.add_option("--set_members", type   = "string"    , default=None , help="Save list of id of input images to parameter named \"members\", id of input images are taken from parameter with given name")
	parser.add_option("--filament"        , action = "store_true", default=False, help="Calculate stack of averages according to filament membership")
	(options, args) = parser.parse_args()
	if len(args) < 1 or len(args) > 2:
		sxprint( "Usage: " + usage )
		sxprint( "Please run \'" + progname + " -h\' for detailed options" )
		sp_global_def.ERROR( "Invalid number of parameters used. Please see usage information above." )
		return
		
	else: 
		if len(args) == 1: 
			name_output = None
		else:
			name_output = args[1]
		
		if options.filament:
			from sp_development import ave_ali_filament
	
			if sp_global_def.CACHE_DISABLE:
				from sp_utilities import disable_bdb_cache
				disable_bdb_cache()
	
			sp_global_def.BATCH = True
			ave_ali_filament(args[0], name_output, options.ali)
			sp_global_def.BATCH = False
		
		else:
			from sp_applications import ave_ali
	
			if sp_global_def.CACHE_DISABLE:
				from sp_utilities import disable_bdb_cache
				disable_bdb_cache()
	
			sp_global_def.BATCH = True
			ave_ali(args[0], name_output, options.ali, options.set_size, options.set_members)
			sp_global_def.BATCH = False
Exemplo n.º 13
0
def main():
	arglist = []
	for arg in sys.argv:
		arglist.append( arg )

	progname = os.path.basename( arglist[0] )
	usage = progname + " stack --params='parm1 parm2 parm3 ...' --zero --one --set=number --randomize --rand_alpha --import=file --export=file --print --backup --suffix --restore --delete"
	parser = OptionParser(usage, version=SPARXVERSION)

	parser.add_option("--params",	   type="string",       default=None,    help="parameter list")
	parser.add_option("--zero",	       action="store_true", default=False,   help="set parameter to zero")
	parser.add_option("--one",	       action="store_true", default=False,   help="set parameter to one")
	parser.add_option("--set",	       type="float",        default=0.0,     help="set parameter to a value (different from 0.0)")
	parser.add_option("--randomize",   action="store_true", default=False,   help="set parameter to randomized value")
	parser.add_option("--rand_alpha",  action="store_true", default=False,   help="set all angles to randomized value")
	parser.add_option("--import",	   type="string",       dest="fimport",  default=None, help="import parameters from file")
	parser.add_option("--export",	   type="string",       dest="fexport",  default=None, help="export parameters to file")
	parser.add_option("--print",	   action="store_true", dest="fprint",   default=False, help="print parameters")
	parser.add_option("--backup",	   action="store_true", default=False,   help="backup parameters")
	parser.add_option("--suffix",	   type="string",       default="_backup",    help="suffix for xform name in backup")
	parser.add_option("--restore",     action="store_true", default=False,   help="restore parameters")
	parser.add_option("--delete",      action="store_true", default=False,   help="delete parameters")
	parser.add_option("--consecutive", action="store_true", default=False,   help="set selected parameter to consecutive integers starting from 0")
	parser.add_option("--list", type="string", default=None,   help="Indices list containing the same amount of rows as the import file")

	(options,args) = parser.parse_args( arglist[1:] )

	if not options.fprint:
		sp_global_def.print_timestamp( "Start" )
		sp_global_def.write_command()

	if len(args) != 1 :
		sxprint( "Usage: " + usage )
		ERROR( "Invalid number of parameters provided. Please see usage information above." )
		return

	if options.params == None:
		sxprint( "Usage: " + usage )
		ERROR( "No parameters provided. Please see usage information above." )
		return

	if sp_global_def.CACHE_DISABLE:
		from sp_utilities import disable_bdb_cache
		disable_bdb_cache()
	from sp_applications import header
	header(args[0], options.params, options.zero, options.one, options.set, options.randomize, options.rand_alpha, options.fimport, options.fexport, \
		options.fprint, options.backup, options.suffix, options.restore, options.delete, options.consecutive, options.list)
	if not options.fprint:
		sp_global_def.print_timestamp( "Finish" )
Exemplo n.º 14
0
def main():

	import sys

	arglist = []
	for arg in sys.argv:
		arglist.append( arg )

	progname = os.path.basename(arglist[0])
	usage = progname + " prjstack outdir bufprefix --delta --d --nvol --nbufvol --seedbase --snr --npad --CTF --MPI --verbose"
	parser = OptionParser(usage,version=SPARXVERSION)
	parser.add_option("--nvol",     type="int",                         help="number of resample volumes to be generated")
	parser.add_option("--nbufvol",  type="int",          default=1,     help="number of fftvols in the memory")
	parser.add_option("--delta",    type="float",        default=10.0,  help="angular step for cones")
	parser.add_option("--d",        type="float",        default=0.1,   help="fraction of projections to leave out")
	parser.add_option("--CTF",      action="store_true", default=False, help="use CTF")
	parser.add_option("--snr",      type="float",        default=1.0,   help="Signal-to-Noise Ratio")
	parser.add_option("--npad",     type="int",          default=2,     help="times of padding")
	parser.add_option("--seedbase", type="int",          default=-1,    help="random seed base")
	parser.add_option("--MPI",      action="store_true", default=False, help="use MPI")
	parser.add_option("--verbose",  type="int",          default=0,     help="verbose level: 0 no, 1 yes")

	(options, args) = parser.parse_args( arglist[1:] )

	if( len(args) !=1 and len(args) != 3):
		sxprint("Usage: " + usage)
		ERROR( "Invalid number of parameters used. Please see usage information above." )
		return

	prjfile = args[0]

	if options.MPI:
		myid = mpi.mpi_comm_rank( mpi.MPI_COMM_WORLD )
		ncpu = mpi.mpi_comm_size( mpi.MPI_COMM_WORLD )
	else:
		myid = 0
		ncpu = 1

	if sp_global_def.CACHE_DISABLE:
		from sp_utilities import disable_bdb_cache
		disable_bdb_cache()

	outdir = args[1]
	bufprefix = args[2]
	resample( prjfile, outdir, bufprefix, options.nbufvol, options.nvol, options.seedbase,\
	           options.delta, options.d, options.snr, options.CTF, options.npad,\
		   options.MPI, myid, ncpu, options.verbose )
Exemplo n.º 15
0
def main():
    progname = os.path.basename(sys.argv[0])
    usage = progname + " stack "
    parser = OptionParser(usage, version=sp_global_def.SPARXVERSION)
    (options, args) = parser.parse_args(sys.argv[1:])
    if len(args) != 1:
        sxprint("Usage: " + usage)
        sxprint("Please run \'" + progname + " -h\' for detailed options")
        ERROR(
            "Invalid number of parameters used. Please see usage information above."
        )
        return

    else:
        if sp_global_def.CACHE_DISABLE:
            from sp_utilities import disable_bdb_cache
            disable_bdb_cache()
        from sp_applications import wrapper_params_3D_to_2D
        sp_global_def.BATCH = True
        wrapper_params_3D_to_2D(args[0])
        sp_global_def.BATCH = False
Exemplo n.º 16
0
def main():
    arglist = []
    for arg in sys.argv:
        arglist.append(arg)

    progname = os.path.basename(arglist[0])
    usage = progname + " prjstack bufprefix --npad --CTF --verbose"
    parser = OptionParser(usage, version=SPARXVERSION)
    parser.add_option("--CTF",
                      action="store_true",
                      default=False,
                      help="use CTF")
    parser.add_option("--npad", type="int", default=2, help="times of padding")
    parser.add_option("--verbose",
                      type="int",
                      default=0,
                      help="verbose level: 0 no, 1 yes")

    (options, args) = parser.parse_args(arglist[1:])

    if (len(args) != 2):
        sxprint("Usage: " + usage)
        sxprint("Please run \'" + progname + " -h\' for detailed options")
        ERROR(
            "Invalid number of parameters used. Please see usage information above."
        )
        return

    prjfile = args[0]

    if sp_global_def.CACHE_DISABLE:
        from sp_utilities import disable_bdb_cache
        disable_bdb_cache()

    bufprefix = args[1]
    nprj = EMUtil.get_image_count(prjfile)
    genbuf(prjfile, bufprefix, 0, nprj, options.CTF, options.npad,
           options.verbose)
Exemplo n.º 17
0
def main():
    progname = os.path.basename(sys.argv[0])
    usage = progname + " stack_in  stack_out"
    parser = OptionParser(usage, version=SPARXVERSION)
    parser.add_option(
        "--shift",
        action="store_true",
        default=False,
        help=
        "Apply only translation, disregard rotation, useful for centering of data (default False)"
    )
    parser.add_option(
        "--ignore_mirror",
        action="store_true",
        default=False,
        help=
        "If centering data with CTF and astigmatism, use option ignore mirror (default False)"
    )
    parser.add_option("--method",
                      type="string",
                      default="quadratic",
                      help="Interpolation method (default quadratic)")
    (options, args) = parser.parse_args()
    if len(args) != 2:
        sxprint("Usage: " + usage)
        sxprint("Please run \'" + progname + " -h\' for detailed options")
        ERROR(
            "Invalid number of parameters used. Please see usage information above."
        )
        return
    else:
        if sp_global_def.CACHE_DISABLE:
            from sp_utilities import disable_bdb_cache
            disable_bdb_cache()
        sp_global_def.BATCH = True
        transform2d(args[0], args[1], options.shift, options.ignore_mirror,
                    options.method)
        sp_global_def.BATCH = False
Exemplo n.º 18
0
def main():
    progname = os.path.basename(sys.argv[0])
    usage = progname + " configure_file.cfg"

    parser = OptionParser(usage, version=SPARXVERSION)
    (options, args) = parser.parse_args()

    if len(args) != 1:
        sxprint("Usage: " + usage)
        sxprint("Please run \'" + progname + " -h\' for detailed options")
        sp_global_def.ERROR(
            "Invalid number of parameters used. Please see usage information above."
        )
        return

    if sp_global_def.CACHE_DISABLE:
        from sp_utilities import disable_bdb_cache
        disable_bdb_cache()

    from sp_development import ali2d_mref
    sp_global_def.BATCH = True
    ali2d_mref(args[0])
    sp_global_def.BATCH = False
Exemplo n.º 19
0
def main():
	progname = os.path.basename(sys.argv[0])
	usage = progname + " out_averages outdir --ou=outer_radius --xr=x_range --ts=translation_step --maxit=max_iteration --CTF --snr=SNR --function=user_function_name --Fourvar --th_err=threshold_cutoff --ali=kind_of_alignment --center=center_type"
	parser = OptionParser(usage,version=SPARXVERSION)
	parser.add_option("--ou",       type="int",        default=-1,             help="outer radius for rotational correlation < nx/2-1 (set to the radius of the particle)")
	parser.add_option("--xr",       type="string",       default="4 2",      help="range for translation search in x direction, search is +/xr ")
	parser.add_option("--ts",       type="string",       default="2 1", help="step of translation search in both directions")
	parser.add_option("--maxit",    type="float",        default=0,              help="maximum number of iterations (0 means the maximum iterations is 10, but it will automatically stop should the criterion falls")
	parser.add_option("--CTF",      action="store_true", default=False,          help="Consider CTF correction during the alignment ")
	parser.add_option("--snr",      type="float",        default=1.0,            help="signal-to-noise ratio of the data (set to 1.0)")
	parser.add_option("--Fourvar",  action="store_true", default=False,          help="compute Fourier variance")
	parser.add_option("--function", type="string",       default="ref_ali2d",    help="name of the reference preparation function")
	parser.add_option('--Ng',	type='int',		default=-1,		help='Ng')
	parser.add_option('--K',	type='int',		default=-1,		help='K')
	parser.add_option("--dst",	type="float", 		default=0.0,		help="")
	parser.add_option("--center",   type="float",  default=-1,            help="-1.average center method; 0.not centered; 1.phase approximation; 2.cc with Gaussian function; 3.cc with donut-shaped image 4.cc with user-defined reference 5.cc with self-rotated average")
	parser.add_option("--CUDA",     action="store_true", default=False,          help=" whether to use CUDA ")
	parser.add_option("--GPUID",      type="string",          default="",            help=" ID of GPUs to use")
	parser.add_option('--MPI',      action='store_true',   default=False,          help='MPI')

	(options, args) = parser.parse_args()
	if len(args) != 3:
		sxprint( "Usage: " + usage )
		sxprint( "Please run '" + progname + " -h' for detailed options" )
		ERROR( "Invalid number of parameters used. Please see usage information above." )
		return
		
	else:
		if sp_global_def.CACHE_DISABLE:
			from sp_utilities import disable_bdb_cache
			disable_bdb_cache()

		sp_global_def.BATCH = True
		from sp_development import mref_alignment
		mref_alignment(args[0], args[1], args[2], options.ou, options.xr, options.ts, options.maxit, options.function, options.snr, options.CTF, 
				options.Fourvar, options.Ng, options.K, options.dst, options.center, options.CUDA, options.GPUID, options.MPI)
		sp_global_def.BATCH = False
Exemplo n.º 20
0
def main():
    arglist = []
    for arg in sys.argv:
        arglist.append(arg)
    progname = optparse.os.path.basename(arglist[0])
    usage = progname + """ inputvolume  locresvolume maskfile outputfile   --radius --falloff  --MPI

	    Locally filer a volume based on local resolution volume (sxlocres.py) within area outlined by the maskfile
	"""
    parser = optparse.OptionParser(usage, version=sp_global_def.SPARXVERSION)

    parser.add_option(
        "--radius",
        type="int",
        default=-1,
        help=
        "if there is no maskfile, sphere with r=radius will be used, by default the radius is nx/2-1"
    )
    parser.add_option("--falloff",
                      type="float",
                      default=0.1,
                      help="falloff of tanl filter (default 0.1)")
    parser.add_option("--MPI",
                      action="store_true",
                      default=False,
                      help="use MPI version")

    (options, args) = parser.parse_args(arglist[1:])

    if len(args) < 3 or len(args) > 4:
        sp_global_def.sxprint("See usage " + usage)
        sp_global_def.ERROR(
            "Wrong number of parameters. Please see usage information above.")
        return

    if sp_global_def.CACHE_DISABLE:
        pass  #IMPORTIMPORTIMPORT from sp_utilities import disable_bdb_cache
        sp_utilities.disable_bdb_cache()

    if options.MPI:
        number_of_proc = mpi.mpi_comm_size(mpi.MPI_COMM_WORLD)
        myid = mpi.mpi_comm_rank(mpi.MPI_COMM_WORLD)
        main_node = 0

        if (myid == main_node):
            #print sys.argv
            vi = sp_utilities.get_im(sys.argv[1])
            ui = sp_utilities.get_im(sys.argv[2])
            #print   Util.infomask(ui, None, True)
            radius = options.radius
            nx = vi.get_xsize()
            ny = vi.get_ysize()
            nz = vi.get_zsize()
            dis = [nx, ny, nz]
        else:
            falloff = 0.0
            radius = 0
            dis = [0, 0, 0]
            vi = None
            ui = None
        dis = sp_utilities.bcast_list_to_all(dis, myid, source_node=main_node)

        if (myid != main_node):
            nx = int(dis[0])
            ny = int(dis[1])
            nz = int(dis[2])
        radius = sp_utilities.bcast_number_to_all(radius, main_node)
        if len(args) == 3:
            if (radius == -1):
                radius = min(nx, ny, nz) // 2 - 1
            m = sp_utilities.model_circle(radius, nx, ny, nz)
            outvol = args[2]

        elif len(args) == 4:
            if (myid == main_node):
                m = sp_morphology.binarize(sp_utilities.get_im(args[2]), 0.5)
            else:
                m = sp_utilities.model_blank(nx, ny, nz)
            outvol = args[3]
            sp_utilities.bcast_EMData_to_all(m, myid, main_node)

        pass  #IMPORTIMPORTIMPORT from sp_filter import filterlocal
        filteredvol = sp_filter.filterlocal(ui, vi, m, options.falloff, myid,
                                            main_node, number_of_proc)

        if (myid == 0):
            filteredvol.write_image(outvol)

    else:
        vi = sp_utilities.get_im(args[0])
        ui = sp_utilities.get_im(
            args[1]
        )  # resolution volume, values are assumed to be from 0 to 0.5

        nn = vi.get_xsize()

        falloff = options.falloff

        if len(args) == 3:
            radius = options.radius
            if (radius == -1):
                radius = nn // 2 - 1
            m = sp_utilities.model_circle(radius, nn, nn, nn)
            outvol = args[2]

        elif len(args) == 4:
            m = sp_morphology.binarize(sp_utilities.get_im(args[2]), 0.5)
            outvol = args[3]

        sp_fundamentals.fftip(vi)  # this is the volume to be filtered

        #  Round all resolution numbers to two digits
        for x in range(nn):
            for y in range(nn):
                for z in range(nn):
                    ui.set_value_at_fast(x, y, z,
                                         round(ui.get_value_at(x, y, z), 2))
        st = EMAN2_cppwrap.Util.infomask(ui, m, True)

        filteredvol = sp_utilities.model_blank(nn, nn, nn)
        cutoff = max(st[2] - 0.01, 0.0)
        while (cutoff < st[3]):
            cutoff = round(cutoff + 0.01, 2)
            pt = EMAN2_cppwrap.Util.infomask(
                sp_morphology.threshold_outside(ui, cutoff - 0.00501,
                                                cutoff + 0.005), m, True)
            if (pt[0] != 0.0):
                vovo = sp_fundamentals.fft(
                    sp_filter.filt_tanl(vi, cutoff, falloff))
                for x in range(nn):
                    for y in range(nn):
                        for z in range(nn):
                            if (m.get_value_at(x, y, z) > 0.5):
                                if (round(ui.get_value_at(x, y, z),
                                          2) == cutoff):
                                    filteredvol.set_value_at_fast(
                                        x, y, z, vovo.get_value_at(x, y, z))

        sp_global_def.write_command(optparse.os.path.dirname(outvol))
        filteredvol.write_image(outvol)
Exemplo n.º 21
0
def main():
    progname = os.path.basename(sys.argv[0])
    usage = progname + " stack <maskfile> --search_rng=10 --maxit=max_iteration --CTF --snr=SNR --Fourvar=Fourier_variance --oneDx --MPI"
    parser = OptionParser(usage, version=SPARXVERSION)
    parser.add_option("--search_rng",
                      type="int",
                      default=-1,
                      help="Search range for x-shift")
    parser.add_option("--search_ang",
                      type="int",
                      default=-1,
                      help="Search range for inplane rotation angle")
    parser.add_option(
        "--search_rng_y",
        type="int",
        default=-1,
        help=
        "Search range for x-shift. Not used for 1D search (oneDx flag set).")
    parser.add_option("--maxit",
                      type="int",
                      default=100,
                      help="Maximum number of iterations program will perform")
    parser.add_option("--CTF",
                      action="store_true",
                      default=False,
                      help="Use CTF correction")
    parser.add_option(
        "--snr",
        type="float",
        default=1.0,
        help="signal-to-noise ratio of the data (default is 1.0)")
    parser.add_option("--Fourvar",
                      action="store_true",
                      default=False,
                      help="compute Fourier variance")
    parser.add_option("--oneDx",
                      action="store_true",
                      default=False,
                      help="1D search along x-axis")
    parser.add_option("--MPI",
                      action="store_true",
                      default=False,
                      help="use MPI")
    parser.add_option("--curvature",
                      action="store_true",
                      default=False,
                      help="for curved filament alignment")
    (options, args) = parser.parse_args()

    if not (options.MPI):
        sxprint("Only MPI version is currently implemented.")
        sxprint("Please run '" + progname + " -h' for detailed options")
        return

    if len(args) < 1 or len(args) > 2:
        sxprint("usage: " + usage)
        sxprint("Please run '" + progname + " -h' for detailed options")
    else:

        if len(args) == 1: mask = None
        else: mask = args[1]

        if sp_global_def.CACHE_DISABLE:
            from sp_utilities import disable_bdb_cache
            disable_bdb_cache()

        sp_global_def.BATCH = True
        if options.oneDx:
            helicalshiftali_MPI(args[0], mask, options.maxit, options.CTF,
                                options.snr, options.Fourvar,
                                options.search_rng)
        else:
            shiftali_MPI(args[0], mask, options.maxit, options.CTF,
                         options.snr, options.Fourvar, options.search_rng,
                         options.oneDx, options.search_rng_y)
        sp_global_def.BATCH = False

        return
Exemplo n.º 22
0
def main():
    progname = os.path.basename(sys.argv[0])
    usage = progname + " averages1 averages2 --th_grp"
    parser = OptionParser(usage, version=SPARXVERSION)
    parser.add_option("--T",
                      type="int",
                      default=0,
                      help=" Threshold for matching")
    parser.add_option("--J", type="int", default=50, help=" J")
    parser.add_option("--max_branching",
                      type="int",
                      default=40,
                      help=" maximum branching")
    parser.add_option("--verbose",
                      action="store_true",
                      default=False,
                      help=" Threshold for matching")
    parser.add_option("--timing",
                      action="store_true",
                      default=False,
                      help=" Get the timing")

    (options, args) = parser.parse_args()

    if sp_global_def.CACHE_DISABLE:
        from sp_utilities import disable_bdb_cache
        disable_bdb_cache()

    sp_global_def.BATCH = True

    from numpy import array
    from sp_statistics import k_means_stab_bbenum

    R = len(args)
    Parts = []
    mem = [0] * R
    avg = [0] * R
    for r in range(R):
        data = EMData.read_images(args[r])
        avg[r] = len(data)

        part = []
        for k in range(len(data)):
            lid = data[k].get_attr('members')
            mem[r] += len(lid)
            lid = array(lid, 'int32')
            lid.sort()
            part.append(lid.copy())
        Parts.append(part)

    if options.timing:
        from time import time
        time1 = time()

    MATCH, STB_PART, CT_s, CT_t, ST, st = k_means_stab_bbenum(
        Parts,
        T=options.T,
        J=options.J,
        max_branching=options.max_branching,
        stmult=0.1,
        branchfunc=2)

    if options.verbose:
        sxprint(MATCH)
        sxprint(STB_PART)
        sxprint(CT_s)
        sxprint(CT_t)
        sxprint(ST)
        sxprint(st)
        sxprint(" ")

    for i in range(len(MATCH)):
        u = MATCH[i][0]  # u is the group in question in partition 1
        assert len(STB_PART[u]) == CT_s[u]
        sxprint("Group ", end=' ')
        for r in range(R):
            sxprint("%3d " % (MATCH[i][r]), end=' ')
        sxprint(" matches:   group size = ", end=' ')
        for r in range(R):
            sxprint(" %3d" % len(Parts[r][MATCH[i][r]]), end=' ')
        sxprint("     matched size = %3d" % (CT_s[u]), end=' ')
        if options.verbose:
            sxprint("   matched group = %s" % (STB_PART[u]))
        else:
            sxprint("")

    sxprint("\nNumber of averages = ", end=' ')
    for r in range(R):
        sxprint("%3d" % (avg[r]), end=' ')
    sxprint("\nTotal number of particles = ", end=' ')
    for r in range(R):
        sxprint("%3d" % (mem[r]), end=' ')
    sxprint("     number of matched particles = %5d" % (sum(CT_s)))

    if options.timing:
        sxprint("Elapsed time = ", time() - time1)

    sp_global_def.BATCH = False
Exemplo n.º 23
0
def main():
    arglist = []
    for arg in sys.argv:
        arglist.append(arg)
    progname = os.path.basename(arglist[0])
    usage = progname + " stack ref_vol outdir --dp=rise --dphi=rotation --apix=pixel_size --phistep=phi_step --zstep=z_step --fract=helicising_fraction --rmax=maximum_radius --rmin=min_radius --CTF --sym=c1 --function=user_function --maxit=max_iter --MPI"
    parser = OptionParser(usage, version=SPARXVERSION)
    parser.add_option("--dp",
                      type="float",
                      default=1.0,
                      help="delta z - translation in Angstroms")
    parser.add_option("--dphi",
                      type="float",
                      default=1.0,
                      help="delta phi - rotation in degrees")
    parser.add_option("--apix",
                      type="float",
                      default=1.84,
                      help="pixel size in Angstroms")
    parser.add_option("--rmin",
                      type="int",
                      default=0,
                      help="minimal radial extent of structure")
    parser.add_option("--rmax",
                      type="int",
                      default=70,
                      help="maximal radial extent of structure")
    parser.add_option("--fract",
                      type="float",
                      default=0.66,
                      help="fraction of the volume used for helical search")
    parser.add_option("--sym",
                      type="string",
                      default="c1",
                      help="symmetry of the structure")
    parser.add_option("--function",
                      type="string",
                      default="helical",
                      help="name of the reference preparation function")
    parser.add_option("--zstep",
                      type="int",
                      default=1,
                      help="Step size for translational search along z")
    parser.add_option("--CTF",
                      action="store_true",
                      default=False,
                      help="CTF correction")
    parser.add_option("--maxit",
                      type="int",
                      default=5,
                      help="maximum number of iterations performed")
    parser.add_option("--MPI",
                      action="store_true",
                      default=False,
                      help="use MPI version")

    (options, args) = parser.parse_args(arglist[1:])

    if len(args) != 3:
        sxprint("Usage: " + usage)
        sxprint("Please run \'" + progname + " -h\' for detailed options")
        ERROR(
            "Invalid number of parameters used. Please see usage information above."
        )
        return

    else:
        if not options.MPI:
            ERROR(
                "There is only MPI version of sxfilrecons3d.py. See SPARX wiki page for downloading MyMPI details."
            )
            return

        if sp_global_def.CACHE_DISABLE:
            from sp_utilities import disable_bdb_cache
            disable_bdb_cache()

        from sp_development import filrecons3D_MPI
        sp_global_def.BATCH = True
        filrecons3D_MPI(args[0], args[1], args[2], options.dp, options.dphi,
                        options.apix, options.function, options.zstep,
                        options.fract, options.rmax, options.rmin, options.CTF,
                        options.maxit, options.sym)

        sp_global_def.BATCH = False
Exemplo n.º 24
0
def main():

    progname = os.path.basename(sys.argv[0])
    usage = progname + " proj_stack output_averages --MPI"
    parser = OptionParser(usage, version=SPARXVERSION)

    parser.add_option("--img_per_group",
                      type="int",
                      default=100,
                      help="number of images per group")
    parser.add_option("--radius",
                      type="int",
                      default=-1,
                      help="radius for alignment")
    parser.add_option(
        "--xr",
        type="string",
        default="2 1",
        help="range for translation search in x direction, search is +/xr")
    parser.add_option(
        "--yr",
        type="string",
        default="-1",
        help=
        "range for translation search in y direction, search is +/yr (default = same as xr)"
    )
    parser.add_option(
        "--ts",
        type="string",
        default="1 0.5",
        help=
        "step size of the translation search in both directions, search is -xr, -xr+ts, 0, xr-ts, xr, can be fractional"
    )
    parser.add_option(
        "--iter",
        type="int",
        default=30,
        help="number of iterations within alignment (default = 30)")
    parser.add_option(
        "--num_ali",
        type="int",
        default=5,
        help="number of alignments performed for stability (default = 5)")
    parser.add_option("--thld_err",
                      type="float",
                      default=1.0,
                      help="threshold of pixel error (default = 1.732)")
    parser.add_option(
        "--grouping",
        type="string",
        default="GRP",
        help=
        "do grouping of projections: PPR - per projection, GRP - different size groups, exclusive (default), GEV - grouping equal size"
    )
    parser.add_option(
        "--delta",
        type="float",
        default=-1.0,
        help="angular step for reference projections (required for GEV method)"
    )
    parser.add_option(
        "--fl",
        type="float",
        default=0.3,
        help="cut-off frequency of hyperbolic tangent low-pass Fourier filter")
    parser.add_option(
        "--aa",
        type="float",
        default=0.2,
        help="fall-off of hyperbolic tangent low-pass Fourier filter")
    parser.add_option("--CTF",
                      action="store_true",
                      default=False,
                      help="Consider CTF correction during the alignment ")
    parser.add_option("--MPI",
                      action="store_true",
                      default=False,
                      help="use MPI version")

    (options, args) = parser.parse_args()

    myid = mpi.mpi_comm_rank(MPI_COMM_WORLD)
    number_of_proc = mpi.mpi_comm_size(MPI_COMM_WORLD)
    main_node = 0

    if len(args) == 2:
        stack = args[0]
        outdir = args[1]
    else:
        sp_global_def.ERROR("Incomplete list of arguments",
                            "sxproj_stability.main",
                            1,
                            myid=myid)
        return
    if not options.MPI:
        sp_global_def.ERROR("Non-MPI not supported!",
                            "sxproj_stability.main",
                            1,
                            myid=myid)
        return

    if sp_global_def.CACHE_DISABLE:
        from sp_utilities import disable_bdb_cache
        disable_bdb_cache()
    sp_global_def.BATCH = True

    img_per_grp = options.img_per_group
    radius = options.radius
    ite = options.iter
    num_ali = options.num_ali
    thld_err = options.thld_err

    xrng = get_input_from_string(options.xr)
    if options.yr == "-1":
        yrng = xrng
    else:
        yrng = get_input_from_string(options.yr)

    step = get_input_from_string(options.ts)

    if myid == main_node:
        nima = EMUtil.get_image_count(stack)
        img = get_image(stack)
        nx = img.get_xsize()
        ny = img.get_ysize()
    else:
        nima = 0
        nx = 0
        ny = 0
    nima = bcast_number_to_all(nima)
    nx = bcast_number_to_all(nx)
    ny = bcast_number_to_all(ny)
    if radius == -1: radius = nx / 2 - 2
    mask = model_circle(radius, nx, nx)

    st = time()
    if options.grouping == "GRP":
        if myid == main_node:
            sxprint("  A  ", myid, "  ", time() - st)
            proj_attr = EMUtil.get_all_attributes(stack, "xform.projection")
            proj_params = []
            for i in range(nima):
                dp = proj_attr[i].get_params("spider")
                phi, theta, psi, s2x, s2y = dp["phi"], dp["theta"], dp[
                    "psi"], -dp["tx"], -dp["ty"]
                proj_params.append([phi, theta, psi, s2x, s2y])

            # Here is where the grouping is done, I didn't put enough annotation in the group_proj_by_phitheta,
            # So I will briefly explain it here
            # proj_list  : Returns a list of list of particle numbers, each list contains img_per_grp particle numbers
            #              except for the last one. Depending on the number of particles left, they will either form a
            #              group or append themselves to the last group
            # angle_list : Also returns a list of list, each list contains three numbers (phi, theta, delta), (phi,
            #              theta) is the projection angle of the center of the group, delta is the range of this group
            # mirror_list: Also returns a list of list, each list contains img_per_grp True or False, which indicates
            #              whether it should take mirror position.
            # In this program angle_list and mirror list are not of interest.

            proj_list_all, angle_list, mirror_list = group_proj_by_phitheta(
                proj_params, img_per_grp=img_per_grp)
            del proj_params
            sxprint("  B  number of groups  ", myid, "  ", len(proj_list_all),
                    time() - st)
        mpi_barrier(MPI_COMM_WORLD)

        # Number of groups, actually there could be one or two more groups, since the size of the remaining group varies
        # we will simply assign them to main node.
        n_grp = nima / img_per_grp - 1

        # Divide proj_list_all equally to all nodes, and becomes proj_list
        proj_list = []
        for i in range(n_grp):
            proc_to_stay = i % number_of_proc
            if proc_to_stay == main_node:
                if myid == main_node: proj_list.append(proj_list_all[i])
            elif myid == main_node:
                mpi_send(len(proj_list_all[i]), 1, MPI_INT, proc_to_stay,
                         SPARX_MPI_TAG_UNIVERSAL, MPI_COMM_WORLD)
                mpi_send(proj_list_all[i], len(proj_list_all[i]), MPI_INT,
                         proc_to_stay, SPARX_MPI_TAG_UNIVERSAL, MPI_COMM_WORLD)
            elif myid == proc_to_stay:
                img_per_grp = mpi_recv(1, MPI_INT, main_node,
                                       SPARX_MPI_TAG_UNIVERSAL, MPI_COMM_WORLD)
                img_per_grp = int(img_per_grp[0])
                temp = mpi_recv(img_per_grp, MPI_INT, main_node,
                                SPARX_MPI_TAG_UNIVERSAL, MPI_COMM_WORLD)
                proj_list.append(list(map(int, temp)))
                del temp
            mpi_barrier(MPI_COMM_WORLD)
        sxprint("  C  ", myid, "  ", time() - st)
        if myid == main_node:
            # Assign the remaining groups to main_node
            for i in range(n_grp, len(proj_list_all)):
                proj_list.append(proj_list_all[i])
            del proj_list_all, angle_list, mirror_list

    #   Compute stability per projection projection direction, equal number assigned, thus overlaps
    elif options.grouping == "GEV":

        if options.delta == -1.0:
            ERROR(
                "Angular step for reference projections is required for GEV method"
            )
            return

        from sp_utilities import even_angles, nearestk_to_refdir, getvec
        refproj = even_angles(options.delta)
        img_begin, img_end = MPI_start_end(len(refproj), number_of_proc, myid)
        # Now each processor keeps its own share of reference projections
        refprojdir = refproj[img_begin:img_end]
        del refproj

        ref_ang = [0.0] * (len(refprojdir) * 2)
        for i in range(len(refprojdir)):
            ref_ang[i * 2] = refprojdir[0][0]
            ref_ang[i * 2 + 1] = refprojdir[0][1] + i * 0.1

        sxprint("  A  ", myid, "  ", time() - st)
        proj_attr = EMUtil.get_all_attributes(stack, "xform.projection")
        #  the solution below is very slow, do not use it unless there is a problem with the i/O
        """
		for i in xrange(number_of_proc):
			if myid == i:
				proj_attr = EMUtil.get_all_attributes(stack, "xform.projection")
			mpi_barrier(MPI_COMM_WORLD)
		"""
        sxprint("  B  ", myid, "  ", time() - st)

        proj_ang = [0.0] * (nima * 2)
        for i in range(nima):
            dp = proj_attr[i].get_params("spider")
            proj_ang[i * 2] = dp["phi"]
            proj_ang[i * 2 + 1] = dp["theta"]
        sxprint("  C  ", myid, "  ", time() - st)
        asi = Util.nearestk_to_refdir(proj_ang, ref_ang, img_per_grp)
        del proj_ang, ref_ang
        proj_list = []
        for i in range(len(refprojdir)):
            proj_list.append(asi[i * img_per_grp:(i + 1) * img_per_grp])
        del asi
        sxprint("  D  ", myid, "  ", time() - st)
        #from sys import exit
        #exit()

    #   Compute stability per projection
    elif options.grouping == "PPR":
        sxprint("  A  ", myid, "  ", time() - st)
        proj_attr = EMUtil.get_all_attributes(stack, "xform.projection")
        sxprint("  B  ", myid, "  ", time() - st)
        proj_params = []
        for i in range(nima):
            dp = proj_attr[i].get_params("spider")
            phi, theta, psi, s2x, s2y = dp["phi"], dp["theta"], dp[
                "psi"], -dp["tx"], -dp["ty"]
            proj_params.append([phi, theta, psi, s2x, s2y])
        img_begin, img_end = MPI_start_end(nima, number_of_proc, myid)
        sxprint("  C  ", myid, "  ", time() - st)
        from sp_utilities import nearest_proj
        proj_list, mirror_list = nearest_proj(
            proj_params, img_per_grp,
            list(range(img_begin, img_begin + 1)))  #range(img_begin, img_end))
        refprojdir = proj_params[img_begin:img_end]
        del proj_params, mirror_list
        sxprint("  D  ", myid, "  ", time() - st)

    else:
        ERROR("Incorrect projection grouping option")
        return

    ###########################################################################################################
    # Begin stability test
    from sp_utilities import get_params_proj, read_text_file
    #if myid == 0:
    #	from utilities import read_text_file
    #	proj_list[0] = map(int, read_text_file("lggrpp0.txt"))

    from sp_utilities import model_blank
    aveList = [model_blank(nx, ny)] * len(proj_list)
    if options.grouping == "GRP":
        refprojdir = [[0.0, 0.0, -1.0]] * len(proj_list)
    for i in range(len(proj_list)):
        sxprint("  E  ", myid, "  ", time() - st)
        class_data = EMData.read_images(stack, proj_list[i])
        #print "  R  ",myid,"  ",time()-st
        if options.CTF:
            from sp_filter import filt_ctf
            for im in range(len(class_data)):  #  MEM LEAK!!
                atemp = class_data[im].copy()
                btemp = filt_ctf(atemp, atemp.get_attr("ctf"), binary=1)
                class_data[im] = btemp
                #class_data[im] = filt_ctf(class_data[im], class_data[im].get_attr("ctf"), binary=1)
        for im in class_data:
            try:
                t = im.get_attr(
                    "xform.align2d")  # if they are there, no need to set them!
            except:
                try:
                    t = im.get_attr("xform.projection")
                    d = t.get_params("spider")
                    set_params2D(im, [0.0, -d["tx"], -d["ty"], 0, 1.0])
                except:
                    set_params2D(im, [0.0, 0.0, 0.0, 0, 1.0])
        #print "  F  ",myid,"  ",time()-st
        # Here, we perform realignment num_ali times
        all_ali_params = []
        for j in range(num_ali):
            if (xrng[0] == 0.0 and yrng[0] == 0.0):
                avet = ali2d_ras(class_data,
                                 randomize=True,
                                 ir=1,
                                 ou=radius,
                                 rs=1,
                                 step=1.0,
                                 dst=90.0,
                                 maxit=ite,
                                 check_mirror=True,
                                 FH=options.fl,
                                 FF=options.aa)
            else:
                avet = within_group_refinement(class_data, mask, True, 1,
                                               radius, 1, xrng, yrng, step,
                                               90.0, ite, options.fl,
                                               options.aa)
            ali_params = []
            for im in range(len(class_data)):
                alpha, sx, sy, mirror, scale = get_params2D(class_data[im])
                ali_params.extend([alpha, sx, sy, mirror])
            all_ali_params.append(ali_params)
        #aveList[i] = avet
        #print "  G  ",myid,"  ",time()-st
        del ali_params
        # We determine the stability of this group here.
        # stable_set contains all particles deemed stable, it is a list of list
        # each list has two elements, the first is the pixel error, the second is the image number
        # stable_set is sorted based on pixel error
        #from utilities import write_text_file
        #write_text_file(all_ali_params, "all_ali_params%03d.txt"%myid)
        stable_set, mir_stab_rate, average_pix_err = multi_align_stability(
            all_ali_params, 0.0, 10000.0, thld_err, False, 2 * radius + 1)
        #print "  H  ",myid,"  ",time()-st
        if (len(stable_set) > 5):
            stable_set_id = []
            members = []
            pix_err = []
            # First put the stable members into attr 'members' and 'pix_err'
            for s in stable_set:
                # s[1] - number in this subset
                stable_set_id.append(s[1])
                # the original image number
                members.append(proj_list[i][s[1]])
                pix_err.append(s[0])
            # Then put the unstable members into attr 'members' and 'pix_err'
            from sp_fundamentals import rot_shift2D
            avet.to_zero()
            if options.grouping == "GRP":
                aphi = 0.0
                atht = 0.0
                vphi = 0.0
                vtht = 0.0
            l = -1
            for j in range(len(proj_list[i])):
                #  Here it will only work if stable_set_id is sorted in the increasing number, see how l progresses
                if j in stable_set_id:
                    l += 1
                    avet += rot_shift2D(class_data[j], stable_set[l][2][0],
                                        stable_set[l][2][1],
                                        stable_set[l][2][2],
                                        stable_set[l][2][3])
                    if options.grouping == "GRP":
                        phi, theta, psi, sxs, sy_s = get_params_proj(
                            class_data[j])
                        if (theta > 90.0):
                            phi = (phi + 540.0) % 360.0
                            theta = 180.0 - theta
                        aphi += phi
                        atht += theta
                        vphi += phi * phi
                        vtht += theta * theta
                else:
                    members.append(proj_list[i][j])
                    pix_err.append(99999.99)
            aveList[i] = avet.copy()
            if l > 1:
                l += 1
                aveList[i] /= l
                if options.grouping == "GRP":
                    aphi /= l
                    atht /= l
                    vphi = (vphi - l * aphi * aphi) / l
                    vtht = (vtht - l * atht * atht) / l
                    from math import sqrt
                    refprojdir[i] = [
                        aphi, atht,
                        (sqrt(max(vphi, 0.0)) + sqrt(max(vtht, 0.0))) / 2.0
                    ]

            # Here more information has to be stored, PARTICULARLY WHAT IS THE REFERENCE DIRECTION
            aveList[i].set_attr('members', members)
            aveList[i].set_attr('refprojdir', refprojdir[i])
            aveList[i].set_attr('pixerr', pix_err)
        else:
            sxprint(" empty group ", i, refprojdir[i])
            aveList[i].set_attr('members', [-1])
            aveList[i].set_attr('refprojdir', refprojdir[i])
            aveList[i].set_attr('pixerr', [99999.])

    del class_data

    if myid == main_node:
        km = 0
        for i in range(number_of_proc):
            if i == main_node:
                for im in range(len(aveList)):
                    aveList[im].write_image(args[1], km)
                    km += 1
            else:
                nl = mpi_recv(1, MPI_INT, i, SPARX_MPI_TAG_UNIVERSAL,
                              MPI_COMM_WORLD)
                nl = int(nl[0])
                for im in range(nl):
                    ave = recv_EMData(i, im + i + 70000)
                    nm = mpi_recv(1, MPI_INT, i, SPARX_MPI_TAG_UNIVERSAL,
                                  MPI_COMM_WORLD)
                    nm = int(nm[0])
                    members = mpi_recv(nm, MPI_INT, i, SPARX_MPI_TAG_UNIVERSAL,
                                       MPI_COMM_WORLD)
                    ave.set_attr('members', list(map(int, members)))
                    members = mpi_recv(nm, MPI_FLOAT, i,
                                       SPARX_MPI_TAG_UNIVERSAL, MPI_COMM_WORLD)
                    ave.set_attr('pixerr', list(map(float, members)))
                    members = mpi_recv(3, MPI_FLOAT, i,
                                       SPARX_MPI_TAG_UNIVERSAL, MPI_COMM_WORLD)
                    ave.set_attr('refprojdir', list(map(float, members)))
                    ave.write_image(args[1], km)
                    km += 1
    else:
        mpi_send(len(aveList), 1, MPI_INT, main_node, SPARX_MPI_TAG_UNIVERSAL,
                 MPI_COMM_WORLD)
        for im in range(len(aveList)):
            send_EMData(aveList[im], main_node, im + myid + 70000)
            members = aveList[im].get_attr('members')
            mpi_send(len(members), 1, MPI_INT, main_node,
                     SPARX_MPI_TAG_UNIVERSAL, MPI_COMM_WORLD)
            mpi_send(members, len(members), MPI_INT, main_node,
                     SPARX_MPI_TAG_UNIVERSAL, MPI_COMM_WORLD)
            members = aveList[im].get_attr('pixerr')
            mpi_send(members, len(members), MPI_FLOAT, main_node,
                     SPARX_MPI_TAG_UNIVERSAL, MPI_COMM_WORLD)
            try:
                members = aveList[im].get_attr('refprojdir')
                mpi_send(members, 3, MPI_FLOAT, main_node,
                         SPARX_MPI_TAG_UNIVERSAL, MPI_COMM_WORLD)
            except:
                mpi_send([-999.0, -999.0, -999.0], 3, MPI_FLOAT, main_node,
                         SPARX_MPI_TAG_UNIVERSAL, MPI_COMM_WORLD)

    sp_global_def.BATCH = False
    mpi_barrier(MPI_COMM_WORLD)
Exemplo n.º 25
0
def main():
    progname = os.path.basename(sys.argv[0])
    usage = """%prog [options] input.pdb output.hdf
	
Converts a pdb file into an electron density map. 0,0,0 in PDB space will 
map to the center of the volume."""

    parser = OptionParser(usage=usage, version=EMANVERSION)

    parser.add_option("--apix",
                      "-A",
                      type="float",
                      help="Angstrom/voxel",
                      default=1.0)
    parser.add_option("--box",
                      "-B",
                      type="string",
                      help="Box size in pixels, <xyz> or <x,y,z>")
    parser.add_option("--het",
                      action="store_true",
                      help="Include HET atoms in the map",
                      default=False)
    parser.add_option(
        "--chains",
        type="string",
        help=
        "String list of chain identifiers to include, e.g. 'ABEFG'; default: include all chains",
        default='')
    parser.add_option(
        "--center",
        type="string",
        default="a",
        help=
        "center: c - coordinates; a (default) - center of gravity; <x,y,z> - vector (in Angstrom) to subtract from all coordinates; n - none"
    )
    parser.add_option("--O",
                      action="store_true",
                      default=False,
                      help="use O system of coordinates")
    parser.add_option("--quiet",
                      action="store_true",
                      default=False,
                      help="Verbose is the default")
    parser.add_option("--tr0",
                      type="string",
                      default="none",
                      help="Filename of initial 3x4 transformation matrix")
    parser.add_option("--set_apix_value",
                      action="store_true",
                      help="Set apix value in header of the ouput map",
                      default=False)

    (options, args) = parser.parse_args()  #

    if len(args) < 2:
        ERROR("Input and output files required")
        return

    if sp_global_def.CACHE_DISABLE:
        from sp_utilities import disable_bdb_cache
        disable_bdb_cache()

    chains = options.chains
    if chains == '':
        chains = None

    try:
        infile = open(args[0], "r")
    except:
        ERROR("Cannot open input file")
        return

    aavg = [0, 0, 0]  # calculate atomic center
    asig = [0, 0, 0]  # to compute radius of gyration
    natm = 0
    atoms = []  # we store a list of atoms to process to avoid multiple passes
    nelec = 0
    mass = 0

    # read in initial-transformation file:
    if (options.tr0 != "none"):
        cols = read_text_file(options.tr0, -1)
        txlist = []
        for i in range(3):
            txlist.append(cols[0][i])
            txlist.append(cols[1][i])
            txlist.append(cols[2][i])
            txlist.append(cols[3][i])
        tr0 = Transform(txlist)

    # parse the pdb file and pull out relevant atoms
    for line in infile:
        if (line[:4] == 'ATOM' or (line[:6] == 'HETATM' and options.het)):
            if chains and (line[21] not in chains): continue
            try:
                a = line[12:14].strip()
                aseq = int(line[6:11].strip())
                res = int(line[22:26].strip())
                if (options.O):
                    x = float(line[38:46])
                    y = float(line[30:38])
                    z = -float(line[46:54])
                else:
                    x = float(line[30:38])
                    y = float(line[38:46])
                    z = float(line[46:54])
            except:
                sxprint(
                    "PDB Parse error:\n%s\n'%s','%s','%s'  '%s','%s','%s'\n" %
                    (line, line[12:14], line[6:11], line[22:26], line[30:38],
                     line[38:46], line[46:54]))
                sxprint(a, aseq, res, x, y, z)

            try:
                nelec += atomdefs[a.upper()][0]
                mass += atomdefs[a.upper()][1]
            except:
                sxprint(("Unknown atom %s ignored at %d" % (a, aseq)))

            atoms.append([a, x, y, z])
            natm += 1

            if (options.center == "a"):
                aavg[0] += x * atomdefs[a.upper()][1]
                aavg[1] += y * atomdefs[a.upper()][1]
                aavg[2] += z * atomdefs[a.upper()][1]
                asig[0] += x**2 * atomdefs[a.upper()][1]
                asig[1] += y**2 * atomdefs[a.upper()][1]
                asig[2] += z**2 * atomdefs[a.upper()][1]
            else:
                aavg[0] += x
                aavg[1] += y
                aavg[2] += z
                asig[0] += x**2
                asig[1] += y**2
                asig[2] += z**2
    infile.close()

    if (options.center == "a"):
        rad_gyr = sqrt((asig[0] + asig[1] + asig[2]) / mass -
                       (aavg[0] / mass)**2 - (aavg[1] / mass)**2 -
                       (aavg[2] / mass)**2)
    else:
        rad_gyr = sqrt((asig[0] + asig[1] + asig[2]) / natm -
                       (aavg[0] / natm)**2 - (aavg[1] / natm)**2 -
                       (aavg[2] / natm)**2)

    if not options.quiet:
        sxprint(
            "%d atoms; total charge = %d e-; mol mass = %.2f kDa; radius of gyration = %.2f A"
            % (natm, nelec, mass / 1000.0, rad_gyr))

    # center PDB according to option:
    if (options.center == "a"):
        if not options.quiet:
            sxprint(
                "center of gravity at %1.1f,%1.1f,%1.1f (center of volume at 0,0,0)"
                % (aavg[0] / mass, aavg[1] / mass, aavg[2] / mass))
        for i in range(len(atoms)):
            atoms[i][1] -= aavg[0] / mass
            atoms[i][2] -= aavg[1] / mass
            atoms[i][3] -= aavg[2] / mass
    if (options.center == "c"):
        if not options.quiet:
            sxprint(
                "atomic center at %1.1f,%1.1f,%1.1f (center of volume at 0,0,0)"
                % (aavg[0] / natm, aavg[1] / natm, aavg[2] / natm))
        for i in range(len(atoms)):
            atoms[i][1] -= aavg[0] / natm
            atoms[i][2] -= aavg[1] / natm
            atoms[i][3] -= aavg[2] / natm
    spl = options.center.split(',')
    if len(spl) == 3:  # substract the given vector from all coordinates
        if not options.quiet:
            sxprint(
                "vector to substract: %1.1f,%1.1f,%1.1f (center of volume at 0,0,0)"
                % (float(spl[0]), float(spl[1]), float(spl[2])))
        for i in range(len(atoms)):
            atoms[i][1] -= float(spl[0])
            atoms[i][2] -= float(spl[1])
            atoms[i][3] -= float(spl[2])

    # apply given initial transformation (this used to be done before centering,
    # thereby loosing the translation. This is the right place to apply tr0):
    if (options.tr0 != "none"):
        if not options.quiet:
            sxprint("Applying initial transformation to PDB coordinates... ")
        for i in range(len(atoms)):
            atom_coords = Vec3f(atoms[i][1], atoms[i][2], atoms[i][3])
            new_atom_coords = tr0 * atom_coords
            atoms[i][1] = new_atom_coords[0]
            atoms[i][2] = new_atom_coords[1]
            atoms[i][3] = new_atom_coords[2]
        if not options.quiet:
            sxprint("done.\n")

    # bounding box:
    amin = [atoms[0][1], atoms[0][2], atoms[0][3]]
    amax = [atoms[0][1], atoms[0][2], atoms[0][3]]
    for i in range(1, len(atoms)):
        for k in range(3):
            amin[k] = min(atoms[i][k + 1], amin[k])
            amax[k] = max(atoms[i][k + 1], amax[k])

    if not options.quiet:
        sxprint("Range of coordinates [A]: x: %7.2f - %7.2f" %
                (amin[0], amax[0]))
        sxprint("                          y: %7.2f - %7.2f" %
                (amin[1], amax[1]))
        sxprint("                          z: %7.2f - %7.2f" %
                (amin[2], amax[2]))

    # find the output box size, either user specified or from bounding box
    box = [0, 0, 0]
    try:
        spl = options.box.split(',')
        if len(spl) == 1: box[0] = box[1] = box[2] = int(spl[0])
        else:
            box[0] = int(spl[0])
            box[1] = int(spl[1])
            box[2] = int(spl[2])
    except:
        for i in range(3):
            box[i] = int(2 * max(fabs(amax[i]), fabs(amin[i])) / options.apix)
            #  Increase the box size by 1/4.
            box[i] += box[i] // 4

    if not options.quiet:
        sxprint("Bounding box [pixels]: x: %5d " % box[0])
        sxprint("                       y: %5d " % box[1])
        sxprint("                       z: %5d " % box[2])

    # figure oversampled box size
    #bigb = max(box[0],box[1],box[2])
    fcbig = 1
    """Multiline Comment0"""
    #MULTILINEMULTILINEMULTILINE 0
    #MULTILINEMULTILINEMULTILINE 0
    #MULTILINEMULTILINEMULTILINE 0
    #MULTILINEMULTILINEMULTILINE 0
    #MULTILINEMULTILINEMULTILINE 0
    #MULTILINEMULTILINEMULTILINE 0
    #MULTILINEMULTILINEMULTILINE 0
    if not options.quiet:
        sxprint("Box size: %d x %d x %d" % (box[0], box[1], box[2]),
                ",  oversampling ", fcbig)

    # Calculate working dimensions
    pixelbig = options.apix / fcbig
    bigbox = []
    for i in range(3):
        bigbox.append(box[i] * fcbig)

    # initialize the final output volume
    outmap = EMData(bigbox[0], bigbox[1], bigbox[2], True)
    nc = []
    for i in range(3):
        nc.append(bigbox[i] // 2)
    # fill in the atoms
    for i in range(len(atoms)):
        #print "Adding %d '%s'"%(i,atoms[i][0])
        if not options.quiet and i % 1000 == 0:
            sxprint('\r   %d' % i, end=' ')
            sys.stdout.flush()
        try:
            elec = atomdefs[atoms[i][0].upper()][0]
            #outmap[int(atoms[i][1]/pixelbig+bigbox[0]//2),int(atoms[i][2]/pixelbig+bigbox[1]//2),int(atoms[i][3]/pixelbig+bigbox[2]//2)] += elec
            for k in range(2):
                pz = atoms[i][3] / pixelbig + nc[2]
                dz = pz - int(pz)
                uz = ((1 - k) + (2 * k - 1) * dz) * elec
                for l in range(2):
                    py = atoms[i][2] / pixelbig + nc[1]
                    dy = py - int(py)
                    uy = ((1 - l) + (2 * l - 1) * dy) * uz
                    for m in range(2):
                        px = atoms[i][1] / pixelbig + nc[0]
                        dx = px - int(px)
                        outmap[int(px) + m,
                               int(py) + l,
                               int(pz) + k] += ((1 - m) +
                                                (2 * m - 1) * dx) * uy
        except:
            sxprint("Skipping %d '%s'" % (i, atoms[i][0]))

    if not options.quiet:
        sxprint('\r   %d\nConversion complete.' %
                len(atoms))  #,"    Now shape atoms."
    """Multiline Comment1"""
    #MULTILINEMULTILINEMULTILINE 1
    #MULTILINEMULTILINEMULTILINE 1
    #MULTILINEMULTILINEMULTILINE 1
    #MULTILINEMULTILINEMULTILINE 1
    #MULTILINEMULTILINEMULTILINE 1
    #MULTILINEMULTILINEMULTILINE 1
    #MULTILINEMULTILINEMULTILINE 1
    #MULTILINEMULTILINEMULTILINE 1
    #MULTILINEMULTILINEMULTILINE 1
    (filename_path, filextension) = os.path.splitext(args[1])
    if filextension == ".hdf":
        if options.set_apix_value:
            outmap.set_attr("apix_x", options.apix)
            outmap.set_attr("apix_y", options.apix)
            outmap.set_attr("apix_z", options.apix)
            outmap.set_attr("pixel_size", options.apix)
        else:
            sxprint("Pixel_size is not set in the header!")

        outmap.write_image(args[1], 0, EMUtil.ImageType.IMAGE_HDF)

    elif filextension == ".spi":
        outmap.write_image(args[1], 0, EMUtil.ImageType.IMAGE_SINGLE_SPIDER)

    else:
        ERROR("Unknown image type")
        return
Exemplo n.º 26
0
def main():

    progname = os.path.basename(sys.argv[0])
    usage = progname + " stack outdir <maskfile> --K=10 --trials=2 --debug --maxit=100 --rand_seed=10 --crit='all' --F=0.9 --T0=2.0 --init_method='rnd' --normalize --CTF --MPI --CUDA"
    parser = OptionParser(usage, version=SPARXVERSION)
    parser.add_option("--K",
                      type="int",
                      default=2,
                      help="Number of classes (default 2)")
    parser.add_option("--trials",
                      type="int",
                      default=1,
                      help="Number of trials of K-means (default 1)")
    parser.add_option("--maxit",
                      type="int",
                      default=100,
                      help="Maximum number of iterations within K-means")
    parser.add_option("--CTF",
                      action="store_true",
                      default=False,
                      help="Perform classification using CTF information")
    parser.add_option("--rand_seed",
                      type="int",
                      default=-1,
                      help="Random seed of initial (default random)")
    parser.add_option(
        "--crit",
        type="string",
        default="D",
        help=
        "Criterions: Coleman [C], Harabasz[H], Davies-Bouldin[D], All [all]")
    #parser.add_option("--F",          type="float",        default=0.0,       help="Cooling in simulated annealing, ex.: 0.9")
    #parser.add_option("--T0",         type="float",        default=0.0,       help="Initial temperature in simulated annealing, ex: 100")
    parser.add_option("--MPI",
                      action="store_true",
                      default=False,
                      help="Use MPI version")
    parser.add_option("--debug", action="store_true", default=False, help="")
    parser.add_option("--normalize",
                      action="store_true",
                      default=False,
                      help="Normalize images under the mask")
    parser.add_option(
        '--init_method',
        type='string',
        default='rnd',
        help=
        'Method used to initialize partition: "rnd" randomize or "d2w" for d2 weighting initialization (default is rnd)'
    )

    (options, args) = parser.parse_args()
    if len(args) < 2 or len(args) > 3:
        sxprint("usage: " + usage)
        sxprint("Please run '" + progname + " -h' for detailed options")
        ERROR(
            "Invalid number of parameters used. Please see usage information above."
        )
        return

    elif options.trials < 1:
        ERROR("Number of trials should be at least 1")
        return

    else:
        if len(args) == 2: mask = None
        else: mask = args[2]

        if options.K < 2:
            ERROR("K must be > 1 group")
            return

        if options.CTF:
            ERROR("CTF option not implemented")
            return

        if sp_global_def.CACHE_DISABLE:
            from sp_utilities import disable_bdb_cache
            disable_bdb_cache()
        from sp_applications import k_means_main
        sp_global_def.BATCH = True
        k_means_main(args[0], args[1], mask, "SSE", options.K,
                     options.rand_seed, options.maxit, options.trials,
                     options.crit, options.CTF, 0.0, 0.0, options.MPI, False,
                     options.debug, options.normalize, options.init_method)
        sp_global_def.BATCH = False
Exemplo n.º 27
0
def main():
    progname = os.path.basename(sys.argv[0])
    usage = progname + " stack outdir <maskfile> --ir=inner_radius --ou=outer_radius --rs=ring_step --xr=x_range --yr=y_range --ts=translation_step --dst=delta --center=center --maxit=max_iteration --CTF --snr=SNR --Fourvar=Fourier_variance --Ng=group_number --Function=user_function_name --CUDA --GPUID --MPI"
    parser = OptionParser(usage, version=SPARXVERSION)
    parser.add_option(
        "--ir",
        type="float",
        default=1,
        help="inner radius for rotational correlation > 0 (set to 1)")
    parser.add_option(
        "--ou",
        type="float",
        default=-1,
        help=
        "outer radius for rotational correlation < nx/2-1 (set to the radius of the particle)"
    )
    parser.add_option(
        "--rs",
        type="float",
        default=1,
        help="step between rings in rotational correlation > 0 (set to 1)")
    parser.add_option(
        "--xr",
        type="string",
        default="4 2 1 1",
        help="range for translation search in x direction, search is +/xr ")
    parser.add_option(
        "--yr",
        type="string",
        default="-1",
        help="range for translation search in y direction, search is +/yr ")
    parser.add_option("--ts",
                      type="string",
                      default="2 1 0.5 0.25",
                      help="step of translation search in both directions")
    parser.add_option("--dst", type="float", default=0.0, help="delta")
    parser.add_option(
        "--center",
        type="float",
        default=-1,
        help=
        "-1.average center method; 0.not centered; 1.phase approximation; 2.cc with Gaussian function; 3.cc with donut-shaped image 4.cc with user-defined reference 5.cc with self-rotated average"
    )
    parser.add_option(
        "--maxit",
        type="float",
        default=0,
        help=
        "maximum number of iterations (0 means the maximum iterations is 10, but it will automatically stop should the criterion falls"
    )
    parser.add_option("--CTF",
                      action="store_true",
                      default=False,
                      help="use CTF correction during alignment ")
    parser.add_option("--snr",
                      type="float",
                      default=1.0,
                      help="signal-to-noise ratio of the data (set to 1.0)")
    parser.add_option("--Fourvar",
                      action="store_true",
                      default=False,
                      help="compute Fourier variance")
    parser.add_option("--Ng",
                      type="int",
                      default=-1,
                      help="number of groups in the new CTF filtration")
    parser.add_option("--num_ali",
                      type="int",
                      default=3,
                      help="number of independent alignments to do")
    parser.add_option(
        "--function",
        type="string",
        default="ref_ali2d",
        help="name of the reference preparation function (default ref_ali2d)")
    parser.add_option("--CUDA",
                      action="store_true",
                      default=False,
                      help="use CUDA program")
    parser.add_option("--GPUID",
                      type="string",
                      default="",
                      help="ID of GPUs available")
    parser.add_option("--MPI",
                      action="store_true",
                      default=False,
                      help="use MPI version ")

    (options, args) = parser.parse_args()

    if len(args) < 2 or len(args) > 3:
        sxprint("Usage: " + usage)
        sxprint("Please run '" + progname + " -h' for detailed options")
        ERROR(
            "Invalid number of parameters used. Please see usage information above."
        )
        return

    else:
        if args[1] == 'None':
            outdir = None
        else:
            outdir = args[1]

        if len(args) == 2:
            mask = None
        else:
            mask = args[2]

        from sp_development import multi_ali2d

        if sp_global_def.CACHE_DISABLE:
            from sp_utilities import disable_bdb_cache
            disable_bdb_cache()

        sp_global_def.BATCH = True
        multi_ali2d(args[0], outdir, mask, options.ir, options.ou, options.rs, options.xr, options.yr, options.ts, options.dst, options.center, \
         options.maxit, options.CTF, options.snr, options.Fourvar, options.Ng, options.num_ali, options.function, options.CUDA, options.GPUID, options.MPI)
        sp_global_def.BATCH = False
Exemplo n.º 28
0
def main():
    arglist = []
    for arg in sys.argv:
        arglist.append(arg)

    progname = optparse.os.path.basename(arglist[0])
    usage = (
        progname
        + " prj_stack volume [begin end step] --CTF --npad=ntimes_padding --list=file --group=ID --snr=SNR --sym=symmetry --verbose=(0|1) --xysize --MPI"
    )
    parser = optparse.OptionParser(usage, version=sp_global_def.SPARXVERSION)

    parser.add_option(
        "--CTF", action="store_true", default=False, help="apply CTF correction"
    )
    parser.add_option("--snr", type="float", default=1.0, help="Signal-to-Noise Ratio")
    parser.add_option("--sym", type="string", default="c1", help="symmetry")
    parser.add_option(
        "--list",
        type="string",
        help="file with list of images to be used in the first column",
    )
    parser.add_option(
        "--group",
        type="int",
        default=-1,
        help="perform reconstruction using images for a given group number (group is attribute in the header)",
    )
    parser.add_option(
        "--MPI", action="store_true", default=False, help="use MPI version "
    )
    parser.add_option(
        "--npad", type="int", default=2, help="number of times padding (default 2)"
    )
    parser.add_option(
        "--verbose",
        type="int",
        default=0,
        help="verbose level: 0 no verbose, 1 verbose",
    )
    parser.add_option(
        "--xysize", type="int", default=-1, help="user expected size at xy direction"
    )
    parser.add_option(
        "--zsize", type="int", default=-1, help="user expected size at z direction"
    )
    parser.add_option(
        "--smearstep",
        type="float",
        default=0.0,
        help="Rotational smear step (default 0.0, no smear)",
    )
    parser.add_option(
        "--interpolation_method",
        type="string",
        default="4nn",
        help="4nn, or tril: nearest neighbor, or trilinear interpolation",
    )
    parser.add_option(
        "--niter",
        type="int",
        default=10,
        help="number of iterations for iterative reconstruction",
    )
    parser.add_option(
        "--upweighted",
        action="store_true",
        default=False,
        help="apply background noise",
    )
    parser.add_option(
        "--compensate",
        action="store_true",
        default=False,
        help="compensate in reconstruction",
    )
    parser.add_option(
        "--chunk_id",
        type="int",
        default=-1,
        help="reconstruct both odd and even groups of particles",
    )
    parser.add_option(
        "--target_window_size",
        type="int",
        default=-1,
        help=" size of the targeted reconstruction ",
    )

    (options, args) = parser.parse_args(arglist[1:])

    if sp_global_def.CACHE_DISABLE:
        sp_utilities.disable_bdb_cache()

    if len(args) == 2:
        prj_stack = args[0]
        vol_stack = args[1]
        nimage = EMAN2_cppwrap.EMUtil.get_image_count(prj_stack)
        pid_list = list(range(0, nimage))
    elif len(args) == 5:
        prj_stack = args[0]
        vol_stack = args[1]
        begin = string.atoi(args[2])
        end = string.atoi(args[3])
        step = string.atoi(args[4])
        pid_list = list(range(begin, end, step))
    else:
        sp_global_def.ERROR("Incomplete list of arguments")
        return

    if options.list and options.group > -1:
        sp_global_def.ERROR("options group and list cannot be used together")
        return

    sp_global_def.BATCH = True
    if options.interpolation_method == "4nn":
        sp_applications.recons3d_n(
            prj_stack,
            pid_list,
            vol_stack,
            options.CTF,
            options.snr,
            1,
            options.npad,
            options.sym,
            options.list,
            options.group,
            options.verbose,
            options.MPI,
            options.xysize,
            options.zsize,
            options.smearstep,
            options.upweighted,
            options.compensate,
            options.chunk_id,
        )
    elif options.interpolation_method == "tril":
        if options.MPI is False:
            sp_global_def.ERROR(
                "Trilinear interpolation reconstruction has MPI version only!"
            )
            return
        sp_applications.recons3d_trl_MPI(
            prj_stack,
            pid_list,
            vol_stack,
            options.CTF,
            options.snr,
            1,
            options.npad,
            options.sym,
            options.verbose,
            options.niter,
            options.compensate,
            options.target_window_size,
        )

    else:
        sp_global_def.ERROR(
            "Wrong interpolation method. The current options are 4nn, and tril. 4nn is the default one."
        )
        return

    sp_global_def.write_command(optparse.os.path.dirname(vol_stack))
    sp_global_def.BATCH = False
Exemplo n.º 29
0
def main():
    arglist = []
    for arg in sys.argv:
        arglist.append(arg)
    progname = os.path.basename(arglist[0])
    usage = progname + " stack ref_vol outdir  <maskfile> --ir=inner_radius --ou=outer_radius --rs=ring_step --xr=x_range --ynumber=y_numbers  --txs=translational_search_stepx  --delta=angular_step --an=angular_neighborhood --center=1 --maxit=max_iter --CTF --snr=1.0  --ref_a=S --sym=c1 --datasym=symdoc --new"

    parser = OptionParser(usage, version=SPARXVERSION)
    #parser.add_option("--ir",                 type="float", 	     default= -1,                 help="inner radius for rotational correlation > 0 (set to 1) (Angstroms)")
    parser.add_option(
        "--ou",
        type="float",
        default=-1,
        help=
        "outer radius for rotational 2D correlation < int(nx/2)-1 (set to the radius of the particle) (Angstroms)"
    )
    parser.add_option(
        "--rs",
        type="int",
        default=1,
        help="step between rings in rotational correlation >0  (set to 1)")
    parser.add_option(
        "--xr",
        type="string",
        default=" 4  2 1  1   1",
        help=
        "range for translation search in x direction, search is +/-xr (Angstroms) "
    )
    parser.add_option(
        "--txs",
        type="string",
        default="1 1 1 0.5 0.25",
        help=
        "step size of the translation search in x directions, search is -xr, -xr+ts, 0, xr-ts, xr (Angstroms)"
    )
    parser.add_option(
        "--y_restrict",
        type="string",
        default="-1 -1 -1 -1 -1",
        help=
        "range for translational search in y-direction, search is +/-y_restrict in Angstroms. This only applies to local search, i.e., when an is not -1. If y_restrict < 0, then for ihrsrlocalcons (option --localcons local search with consistency), the y search range is set such that it is the same ratio to dp as angular search range is to dphi. For regular ihrsr, y search range is the full range when y_restrict< 0. Default is -1."
    )
    parser.add_option(
        "--ynumber",
        type="string",
        default="4 8 16 32 32",
        help=
        "even number of the translation search in y direction, search is (-dpp/2,-dpp/2+dpp/ny,,..,0,..,dpp/2-dpp/ny dpp/2]"
    )
    parser.add_option("--delta",
                      type="string",
                      default=" 10 6 4  3   2",
                      help="angular step of reference projections")
    parser.add_option(
        "--an",
        type="string",
        default="-1",
        help=
        "angular neighborhood for local searches (default -1, meaning do exhaustive search)"
    )
    parser.add_option(
        "--maxit",
        type="int",
        default=30,
        help=
        "maximum number of iterations performed for each angular step (default 30) "
    )
    parser.add_option("--CTF",
                      action="store_true",
                      default=False,
                      help="CTF correction")
    parser.add_option("--snr",
                      type="float",
                      default=1.0,
                      help="Signal-to-Noise Ratio of the data (default 1)")
    parser.add_option("--MPI",
                      action="store_true",
                      default=True,
                      help="use MPI version")
    #parser.add_option("--fourvar",           action="store_true",   default=False,               help="compute Fourier variance")
    parser.add_option("--apix",
                      type="float",
                      default=-1.0,
                      help="pixel size in Angstroms")
    parser.add_option("--dp",
                      type="float",
                      default=-1.0,
                      help="delta z - translation in Angstroms")
    parser.add_option("--dphi",
                      type="float",
                      default=-1.0,
                      help="delta phi - rotation in degrees")

    parser.add_option(
        "--ndp",
        type="int",
        default=12,
        help=
        "In symmetrization search, number of delta z steps equals to 2*ndp+1")
    parser.add_option(
        "--ndphi",
        type="int",
        default=12,
        help="In symmetrization search,number of dphi steps equas to 2*ndphi+1"
    )
    parser.add_option("--dp_step",
                      type="float",
                      default=0.1,
                      help="delta z (Angstroms) step  for symmetrization")
    parser.add_option("--dphi_step",
                      type="float",
                      default=0.1,
                      help="dphi step for symmetrization")

    parser.add_option(
        "--psi_max",
        type="float",
        default=10.0,
        help=
        "maximum psi - how far rotation in plane can can deviate from 90 or 270 degrees (default 10)"
    )
    parser.add_option("--rmin",
                      type="float",
                      default=0.0,
                      help="minimal radius for hsearch (Angstroms)")
    parser.add_option("--rmax",
                      type="float",
                      default=80.0,
                      help="maximal radius for hsearch (Angstroms)")
    parser.add_option("--fract",
                      type="float",
                      default=0.7,
                      help="fraction of the volume used for helical search")
    parser.add_option("--sym",
                      type="string",
                      default="c1",
                      help="symmetry of the structure")
    parser.add_option("--function",
                      type="string",
                      default="helical",
                      help="name of the reference preparation function")
    parser.add_option("--datasym",
                      type="string",
                      default="datasym.txt",
                      help="symdoc")
    parser.add_option(
        "--nise",
        type="int",
        default=200,
        help="start symmetrization after nise steps (default 200)")
    parser.add_option("--npad",
                      type="int",
                      default=2,
                      help="padding size for 3D reconstruction, (default 2)")
    parser.add_option("--debug",
                      action="store_true",
                      default=False,
                      help="debug")
    parser.add_option("--new",
                      action="store_true",
                      default=False,
                      help="use rectangular recon and projection version")
    parser.add_option(
        "--initial_theta",
        type="float",
        default=90.0,
        help="intial theta for reference projection (default 90)")
    parser.add_option(
        "--delta_theta",
        type="float",
        default=1.0,
        help="delta theta for reference projection (default 1.0)")
    parser.add_option("--WRAP",
                      type="int",
                      default=1,
                      help="do helical wrapping (default 1, meaning yes)")

    (options, args) = parser.parse_args(arglist[1:])
    if len(args) < 1 or len(args) > 5:
        sxprint("usage: " + usage + "\n")
        sxprint("Please run '" + progname + " -h' for detailed options")
        ERROR(
            "Invalid number of parameters used. please see usage information above."
        )
        return
    else:
        # Convert input arguments in the units/format as expected by ihrsr_MPI in applications.
        if options.apix < 0:
            ERROR("Please enter pixel size")
            return

        rminp = int((float(options.rmin) / options.apix) + 0.5)
        rmaxp = int((float(options.rmax) / options.apix) + 0.5)

        from sp_utilities import get_input_from_string, get_im

        xr = get_input_from_string(options.xr)
        txs = get_input_from_string(options.txs)
        y_restrict = get_input_from_string(options.y_restrict)

        irp = 1
        if options.ou < 0: oup = -1
        else: oup = int((options.ou / options.apix) + 0.5)
        xrp = ''
        txsp = ''
        y_restrict2 = ''

        for i in range(len(xr)):
            xrp += " " + str(float(xr[i]) / options.apix)
        for i in range(len(txs)):
            txsp += " " + str(float(txs[i]) / options.apix)
        # now y_restrict has the same format as x search range .... has to change ihrsr accordingly
        for i in range(len(y_restrict)):
            y_restrict2 += " " + str(float(y_restrict[i]) / options.apix)

        if sp_global_def.CACHE_DISABLE:
            from sp_utilities import disable_bdb_cache
            disable_bdb_cache()

        from sp_applications import ihrsr
        sp_global_def.BATCH = True
        if len(args) < 4: mask = None
        else: mask = args[3]
        ihrsr(args[0], args[1], args[2], mask, irp, oup, options.rs, xrp,
              options.ynumber, txsp, options.delta, options.initial_theta,
              options.delta_theta, options.an, options.maxit, options.CTF,
              options.snr, options.dp, options.ndp, options.dp_step,
              options.dphi, options.ndphi, options.dphi_step, options.psi_max,
              rminp, rmaxp, options.fract, options.nise, options.npad,
              options.sym, options.function, options.datasym, options.apix,
              options.debug, options.MPI, options.WRAP, y_restrict2)
        sp_global_def.BATCH = False
Exemplo n.º 30
0
def main():
    global debug, logid
    progname = os.path.basename(sys.argv[0])
    usage = """%prog [options] <input stack/image> ...
	
Various CTF-related operations on images, including automatic fitting. Note that automatic fitting is limited to 5 microns
underfocus at most. Input particles should be unmasked and unfiltered. A minimum of ~20% padding around the
particles is required for background extraction, even if this brings the edge of another particle into the box in some cases.
Particles should be reasonably well centered. Can also optionally phase flip and Wiener filter particles. Wiener filtration comes
after phase-flipping, so if phase flipping is performed Wiener filtered particles will also be phase-flipped. Note that both
operations are performed on oversampled images if specified (though final real-space images are clipped back to their original
size. Increasing padding during the particle picking process will improve the accuracy of phase-flipping, particularly for
images far from focus."""

    parser = OptionParser(usage=usage, version=EMANVERSION)

    parser.add_option("--gui",
                      action="store_true",
                      help="Start the GUI for interactive fitting",
                      default=False)
    parser.add_option("--auto_fit",
                      action="store_true",
                      help="Runs automated CTF fitting on the input images",
                      default=False)
    parser.add_option(
        "--bgmask",
        type="int",
        help=
        "Compute the background power spectrum from the edge of the image, specify a mask radius in pixels which would largely mask out the particles. Default is boxsize/2.",
        default=0)
    parser.add_option("--apix",
                      type="float",
                      help="Angstroms per pixel for all images",
                      default=0)
    parser.add_option("--voltage",
                      type="float",
                      help="Microscope voltage in KV",
                      default=0)
    parser.add_option("--cs",
                      type="float",
                      help="Microscope Cs (spherical aberation)",
                      default=0)
    parser.add_option("--ac",
                      type="float",
                      help="Amplitude contrast (percentage, default=10)",
                      default=10)
    parser.add_option(
        "--autohp",
        action="store_true",
        help=
        "Automatic high pass filter of the SNR only to remove initial sharp peak, phase-flipped data is not directly affected (default false)",
        default=False)
    #parser.add_option("--invert",action="store_true",help="Invert the contrast of the particles in output files (default false)",default=False)
    parser.add_option("--nonorm",
                      action="store_true",
                      help="Suppress per image real-space normalization",
                      default=False)
    parser.add_option(
        "--nosmooth",
        action="store_true",
        help=
        "Disable smoothing of the background (running-average of the log with adjustment at the zeroes of the CTF)",
        default=False)
    #parser.add_option("--phaseflip",action="store_true",help="Perform phase flipping after CTF determination and writes to specified file.",default=False)
    #parser.add_option("--wiener",action="store_true",help="Wiener filter (optionally phaseflipped) particles.",default=False)
    parser.add_option("--oversamp",
                      type="int",
                      help="Oversampling factor",
                      default=1)
    parser.add_option(
        "--sf",
        type="string",
        help=
        "The name of a file containing a structure factor curve. Can improve B-factor determination.",
        default=None)
    parser.add_option("--debug", action="store_true", default=False)

    (options, args) = parser.parse_args()

    if len(args) < 1: parser.error("Input image required")

    if sp_global_def.CACHE_DISABLE:
        from sp_utilities import disable_bdb_cache
        disable_bdb_cache()

    if options.auto_fit:
        if options.voltage == 0: parser.error("Please specify voltage")
        if options.cs == 0: parser.error("Please specify Cs")
    if options.apix == 0: sxprint("Using A/pix from header")

    debug = options.debug

    global sfcurve
    if options.sf:
        sfcurve = XYData()
        sfcurve.read_file(options.sf)

    logid = E2init(sys.argv)

    #	if options.oversamp>1 : options.apix/=float(options.oversamp)

    db_project = db_open_dict("bdb:project")
    db_parms = db_open_dict("bdb:e2ctf.parms")
    db_misc = db_open_dict("bdb:e2ctf.misc")

    options.filenames = args
    ### Power spectrum and CTF fitting
    if options.auto_fit:
        img_sets = pspec_and_ctf_fit(
            options,
            debug)  # converted to a function so to work with the workflow

        ### This computes the intensity of the background subtracted power spectrum at each CTF maximum for all sets
        global envelopes  # needs to be a global for the Simplex minimizer
        # envelopes is essentially a cache of information that could be useful at later stages of refinement
        # as according to Steven Ludtke
        for i in img_sets:
            envelopes.append(ctf_env_points(i[2], i[3], i[1]))

        # we use a simplex minimizer to try to rescale the individual sets to match as best they can
        scales = [1.0] * len(img_sets)
        if (len(img_sets) > 3):
            incr = [0.2] * len(img_sets)
            simp = Simplex(env_cmp, scales, incr)
            scales = simp.minimize(maxiters=1000)[0]
            #		sxprint scales
            sxprint(" ")

        # apply the final rescaling
        envelope = []
        for i in range(len(scales)):
            cur = envelopes[i]
            for j in range(len(cur)):
                envelope.append((cur[j][0], cur[j][1] * scales[i]))

        envelope.sort()
        envelope = [i for i in envelope
                    if i[1] > 0]  # filter out all negative peak values

        db_misc = db_open_dict("bdb:e2ctf.misc")
        db_misc["envelope"] = envelope
        #db_close_dict("bdb:e2ctf.misc")

        #out=file("envelope.txt","w")
        #for i in envelope: out.write("%f\t%f\n"%(i[0],i[1]))
        #out.close()

    ### GUI - user can update CTF parameters interactively
    if options.gui:
        img_sets = get_gui_arg_img_sets(options.filenames)
        if len(img_sets) == 0:
            E2end(logid)
            ERROR("img_sets == 0")
            return

        app = EMApp()
        gui = GUIctf(app, img_sets)
        gui.show_guis()
        app.exec_()

        sxprint("done execution")

    ### Process input files
    #if debug : print "Phase flipping / Wiener filtration"
    # write wiener filtered and/or phase flipped particle data to the local database
    #if options.phaseflip or options.wiener: # only put this if statement here to make the program flow obvious
    #	write_e2ctf_output(options) # converted to a function so to work with the workflow

    E2end(logid)