示例#1
0
	void initialise()
	{

		// Get the MDs for both untilted and tilted particles
		MDu.read(fn_unt);
		MDt.read(fn_til);
		if (MDu.numberOfObjects() != MDt.numberOfObjects())
			REPORT_ERROR("Tiltpair plot ERROR: untilted and tilted STAR files have unequal number of entries.");

		// Get the symmetry point group
		int pgGroup, pgOrder;
		SL.isSymmetryGroup(fn_sym, pgGroup, pgOrder);
		SL.read_sym_file(fn_sym);

		// Make postscript header
		fh_eps.open(fn_eps.c_str(), std::ios::out);
	    if (!fh_eps)
	    	REPORT_ERROR("Tiltpair plot ERROR: Cannot open " + fn_eps + " for output");

	    fh_eps << "%%!PS-Adobe-2.0\n";
	    fh_eps << "%% Creator: Tilt pair analysis \n";
	    fh_eps << "%% Pages: 1\n";
	    fh_eps << "0 setgray\n";
	    fh_eps << "0.1 setlinewidth\n";
	    // Draw circles on postscript: 250pixels=plot_max_tilt
	    fh_eps << "300 400 83 0 360 arc closepath stroke\n";
	    fh_eps << "300 400 167 0 360 arc closepath stroke\n";
	    fh_eps << "300 400 250 0 360 arc closepath stroke\n";
	    fh_eps << "300 150 newpath moveto 300 650 lineto stroke\n";
	    fh_eps << "50 400 newpath moveto 550 400 lineto stroke\n";
	}
示例#2
0
void Postprocessing::writeFscXml(MetaDataTable &MDfsc)
{

    FileName fn_fsc = fn_out + "_fsc.xml";
	std::ofstream  fh;
    fh.open((fn_fsc).c_str(), std::ios::out);
    if (!fh)
        REPORT_ERROR( (std::string)"MetaDataTable::write Cannot write to file: " + fn_fsc);

    fh << "<fsc title=\"RELION masked-corrected FSC\" xaxis=\"Resolution (A-1)\" yaxis=\"Correlation Coefficient\">"<<std::endl;

    FOR_ALL_OBJECTS_IN_METADATA_TABLE(MDfsc)
    {
    	DOUBLE xx, yy;
    	MDfsc.getValue(EMDL_RESOLUTION, xx);
    	MDfsc.getValue(EMDL_POSTPROCESS_FSC_TRUE, yy);
    	fh << "  <coordinate>" << std::endl;
    	fh << "    <x>" << xx << "</x>" << std::endl;
    	fh << "    <y>" << yy << "</y>" << std::endl;
    	fh << "  </coordinate>" << std::endl;
    }
    fh << "</fsc>" << std::endl;
    fh.close();

}
示例#3
0
void Preprocessing::initialise()
{

    if (fns_coords_in == "" && fn_star_in == "" && fn_operate_in == "" && !do_join_starfile)
        REPORT_ERROR("Provide either --extract, --join_starfile or --operate_on");

    // Set up which coordinate files to extract particles from (or to join STAR file for)
    do_join_starfile = false;
    if (fns_coords_in != "" || fn_star_in != "")
    {
        do_join_starfile = true;
        if (do_extract && verb > 0)
        {
            if (extract_size < 0)
                REPORT_ERROR("Preprocessing::initialise ERROR: please provide the size of the box to extract particle using --extract_size ");

            std::cout << " Extract particles based on the following coordinate files: " << std::endl;
        }
        else if (!do_extract && verb > 0)
        {
            std::cout << " Creating output STAR file for particles based on the following coordinate files: " << std::endl;
        }

        // Get the filenames of all micrographs to be processed by CTFFIND
        if (fns_coords_in != "")
        {
            fns_coords_in.globFiles(fn_coords);
        }
        else if (fn_star_in != "")
        {
            MetaDataTable MDmics;
            MDmics.read(fn_star_in);
            if (!MDmics.containsLabel(EMDL_MICROGRAPH_NAME))
                REPORT_ERROR("Preprocessing::initialise ERROR: Input micrograph STAR file has no rlnMicrographName column!");
            fn_coords.clear();
            FileName fn_mic;
            FOR_ALL_OBJECTS_IN_METADATA_TABLE(MDmics)
            {
                MDmics.getValue(EMDL_MICROGRAPH_NAME, fn_mic);
                fn_mic = fn_mic.withoutExtension() + fn_pick_suffix;
                if (exists(fn_mic))
                    fn_coords.push_back(fn_mic);
                else if (verb > 0)
                    std::cout << "Warning: coordinate file " << fn_mic << " does not exist..." << std::endl;
            }
        }
示例#4
0
MetaDataTable::MetaDataTable(const MetaDataTable &MD)
{
    clear();
    this->setComment(MD.getComment());
    this->setName(MD.getName());
    this->isList = MD.isList;
    this->activeLabels = MD.activeLabels;
    this->objects.clear();
    this->objects.resize(MD.objects.size());
    for (unsigned long int idx = 0; idx < MD.objects.size(); idx++)
    {
    	 //long int idx = this->addObject();
    	this->objects[idx] = new MetaDataContainer(*(MD.objects[idx]));
    }
	current_objectID = 0;

}
示例#5
0
void MetaDataTable::append(MetaDataTable &app)
{
	// Go to the end of the table
	current_objectID = objects.size();
	FOR_ALL_OBJECTS_IN_METADATA_TABLE(app)
	{
		addObject(app.getObject());
	}
	// Reset pointer to the beginning of the table
	current_objectID = 0;

}
示例#6
0
	void run()
	{

		int iline = 0;
		FOR_ALL_OBJECTS_IN_METADATA_TABLE(MDu)
		{


			// Read input data
	        DOUBLE rot1,  tilt1,  psi1;
	        DOUBLE rot2,  tilt2,  psi2;
	        DOUBLE rot2p, tilt2p, psi2p;
	        DOUBLE best_tilt, best_alpha, best_beta;
	        DOUBLE distp;

	        MDu.getValue(EMDL_ORIENT_ROT, rot1);
	        MDt.getValue(EMDL_ORIENT_ROT, rot2, iline);
	        MDu.getValue(EMDL_ORIENT_TILT, tilt1);
	        MDt.getValue(EMDL_ORIENT_TILT, tilt2, iline);
	        MDu.getValue(EMDL_ORIENT_PSI, psi1);
	        MDt.getValue(EMDL_ORIENT_PSI, psi2, iline);
	        iline++;

	        // Bring both angles to a normalized set
	        rot1 = realWRAP(rot1, -180, 180);
	        tilt1 = realWRAP(tilt1, -180, 180);
	        psi1 = realWRAP(psi1, -180, 180);
	        rot2 = realWRAP(rot2, -180, 180);
	        tilt2 = realWRAP(tilt2, -180, 180);
	        psi2 = realWRAP(psi2, -180, 180);

	        // Apply rotations to find the minimum distance angles
	        rot2p = rot2;
	        tilt2p = tilt2;
	        psi2p = psi2;
	        distp = check_symmetries(rot1, tilt1, psi1, rot2p, tilt2p, psi2p);

	        // Calculate distance to user-defined point
			DOUBLE xp, yp, x, y;
			Matrix1D<DOUBLE> aux2(4);
			xp = dist_from_tilt * COSD(dist_from_alpha);
			yp = dist_from_tilt * SIND(dist_from_alpha);
			x = tilt2p * COSD(rot2p);
			y = tilt2p * SIND(rot2p);
			aux2(3) = sqrt((xp-x)*(xp-x) + (yp-y)*(yp-y));
			aux2(0) = tilt2p;
			aux2(1) = rot2p;
			aux2(2) = psi2p;
			add_to_postscript(tilt2p, rot2p, psi2p);

	    }

		// Close the EPS file to write it to disk
    	fh_eps << "showpage\n";
        fh_eps.close();

	}
示例#7
0
	void run()
	{
		EMDLabel label1, label2, label3;
		MD1.read(fn1);
		MD2.read(fn2);

		label1 = EMDL::str2Label(fn_label1);
		label2 = (fn_label2 == "") ? EMDL_UNDEFINED : EMDL::str2Label(fn_label2);
		label3 = (fn_label3 == "") ? EMDL_UNDEFINED : EMDL::str2Label(fn_label3);


		compareMetaDataTable(MD1, MD2, MDboth, MDonly1, MDonly2, label1, eps, label2, label3);

		std::cout << MDboth.numberOfObjects()  << " entries occur in both input STAR files." << std::endl;
		std::cout << MDonly1.numberOfObjects() << " entries occur only in the 1st input STAR file." << std::endl;
		std::cout << MDonly2.numberOfObjects() << " entries occur only in the 2nd input STAR file." << std::endl;
		if (fn_both != "")
			MDboth.write(fn_both);
		if (fn_only1 != "")
			MDonly1.write(fn_only1);
		if (fn_only2 != "")
			MDonly2.write(fn_only2);

	}
示例#8
0
	void read(int argc, char **argv)
	{

		parser.setCommandLine(argc, argv);

		int general_section = parser.addSection("General Options");
		fn_unt = parser.getOption("--u", "STAR file with the untilted xy-coordinates");
		fn_til = parser.getOption("--t", "STAR file with the untilted xy-coordinates");
		size = textToInteger(parser.getOption("--size", "Largest dimension of the micrograph (in pixels), e.g. 4096"));
		dim = textToInteger(parser.getOption("--dim", "Dimension of boxed particles (for EMAN .box files in pixels)", "200"));
		acc = textToFloat(parser.getOption("--acc", "Allowed accuracy (in pixels), e.g. half the particle diameter"));
		tilt = textToFloat(parser.getOption("--tilt", "Fix tilt angle (in degrees)", "99999."));
		rot = textToFloat(parser.getOption("--rot", "Fix direction of the tilt axis (in degrees), 0 = along y, 90 = along x", "99999."));
		do_opt = !parser.checkOption("--dont_opt", "Skip optimization of the transformation matrix");
		mind2 = ROUND(acc * acc);

		int angle_section = parser.addSection("Specified tilt axis and translational search ranges");
		tilt0 = textToFloat(parser.getOption("--tilt0", "Minimum tilt angle (in degrees)","0."));
		tiltF = textToFloat(parser.getOption("--tiltF", "Maximum tilt angle (in degrees)","99999."));
		if (tiltF == 99999.) tiltF = tilt0;
		tiltStep = textToFloat(parser.getOption("--tiltStep", "Tilt angle step size (in degrees)","1."));

		rot0 = textToFloat(parser.getOption("--rot0", "Minimum rot angle (in degrees)","0."));
		rotF = textToFloat(parser.getOption("--rotF", "Maximum rot angle (in degrees)","99999."));
		if (rotF == 99999.) rotF = rot0;
		rotStep = textToFloat(parser.getOption("--rotStep", "Rot angle step size (in degrees)","1."));

		x0 = textToInteger(parser.getOption("--x0", "Minimum X offset (pixels)","-99999"));
		xF = textToInteger(parser.getOption("--xF", "Maximum X offset (pixels)","99999"));
		xStep = textToInteger(parser.getOption("--xStep", "X offset step size (pixels)","-1"));
		y0 = textToInteger(parser.getOption("--y0", "Minimum Y offset (pixels)","-99999"));
		yF = textToInteger(parser.getOption("--yF", "Maximum Y offset (pixels)","99999"));
		yStep = textToInteger(parser.getOption("--yStep", "Y offset step size (pixels)","-1"));

       	// Check for errors in the command-line option
    	if (parser.checkForErrors())
    		REPORT_ERROR("Errors encountered on the command line, exiting...");

		// If tilt and rot were given: do not search those
		if (tilt != 99999.)
		{
			tilt0 = tiltF = tilt;
			tiltStep = 1.;
		}
		if (rot != 99999.)
		{
			rot0 = rotF = rot;
			rotStep = 1.;
		}

		// By default search the entire micrograph
		x0 = XMIPP_MAX(x0, -size);
		xF = XMIPP_MIN(xF, size);
		// By default use a xStep of one third the accuracy
		if (xStep < 0)
			xStep = acc / 3;

		// By default treat y search in the same way as the x-search
		if (y0 == -99999)
			y0 = x0;
		if (yF == 99999)
			yF = xF;
		if (yStep < 0)
			yStep = xStep;

		// Done reading, now fill p_unt and p_til
		MDunt.read(fn_unt);
		MDtil.read(fn_til);

		// Check for the correct labels
		if (!MDunt.containsLabel(EMDL_IMAGE_COORD_X) || !MDunt.containsLabel(EMDL_IMAGE_COORD_Y))
			REPORT_ERROR("ERROR: Untilted STAR file does not contain the rlnCoordinateX or Y labels");
		if (!MDtil.containsLabel(EMDL_IMAGE_COORD_X) || !MDtil.containsLabel(EMDL_IMAGE_COORD_Y))
			REPORT_ERROR("ERROR: Tilted STAR file does not contain the rlnCoordinateX or Y labels");

		double x, y;

		p_unt.clear();
		FOR_ALL_OBJECTS_IN_METADATA_TABLE(MDunt)
		{
			MDunt.getValue(EMDL_IMAGE_COORD_X, x);
			MDunt.getValue(EMDL_IMAGE_COORD_Y, y);
			p_unt.push_back((int)x);
			p_unt.push_back((int)y);
		}
		p_til.clear();
		FOR_ALL_OBJECTS_IN_METADATA_TABLE(MDtil)
		{
			MDtil.getValue(EMDL_IMAGE_COORD_X, x);
			MDtil.getValue(EMDL_IMAGE_COORD_Y, y);
			p_til.push_back((int)x);
			p_til.push_back((int)y);
		}

		// Initialize best transformation params
		best_x = best_y = 9999;
		best_rot = best_tilt = 9999.;

	}
示例#9
0
void ParticlePolisherMpi::reconstructShinyParticlesAndFscWeight(int ipass)
{
	if (verb > 0)
		std::cout << "+ Reconstructing two halves of shiny particles ..." << std::endl;

	// Re-read the shiny particles' metadatatable (ignore original particle names here...)
	exp_model.read(fn_out + ".star", true);

	 // Do the reconstructions for both halves
	if (node->rank == 0)
		reconstructShinyParticlesOneHalf(1);
	else if (node->rank == 1)
		reconstructShinyParticlesOneHalf(2);

	// Wait until both reconstructions have been done
	MPI_Barrier(MPI_COMM_WORLD);

	// Only the master performs the FSC-weighting
	FileName fn_post = (ipass == 1) ? "_post" : "_post2";
	if (node->rank == 0)
	{

		if (!do_start_all_over && exists(fn_in.withoutExtension() + "_" + fn_out + fn_post + "_masked.mrc")
						       && exists(fn_in.withoutExtension() + "_" + fn_out + fn_post + ".star") )
		{
			if (verb > 0)
				std::cout << std::endl << " + " << fn_in.withoutExtension() << "_" << fn_out << fn_post << "_masked.mrc already exists: re-reading map into memory." << std::endl;

			if (verb > 0)
				std::cout << std::endl << " + " << fn_in.withoutExtension() << "_" << fn_out << fn_post << ".star already exists: re-reading resolution from it." << std::endl;

			MetaDataTable MD;
			MD.read(fn_in.withoutExtension() + "_" + fn_out + fn_post + ".star", "general");
			MD.getValue(EMDL_POSTPROCESS_FINAL_RESOLUTION, maxres_model);
		}
		else
		{
			// Re-read the two halves to calculate FSCs
			Postprocessing prm;

			prm.clear();
			prm.fn_in = fn_in.withoutExtension() + "_" + fn_out;
			prm.fn_out = prm.fn_in + fn_post;
			prm.angpix = angpix;
			prm.do_auto_mask = false;
			prm.fn_mask = fn_mask;
			prm.do_auto_bfac = false;
			prm.do_fsc_weighting = true;
			prm.run();

			maxres_model = prm.global_resol;
		}
	}

	// Wait until the FSC-weighting has been done
	MPI_Barrier(MPI_COMM_WORLD);

	MultidimArray<DOUBLE> dum;
	Image<DOUBLE> refvol;
	FileName fn_vol;
	fn_vol = fn_in.withoutExtension() + "_" + fn_out + "_half1_class001_unfil.mrc";
	refvol.read(fn_vol);
	PPrefvol_half1.ori_size = XSIZE(refvol());
	PPrefvol_half1.padding_factor = 2;
	PPrefvol_half1.interpolator = TRILINEAR;
	PPrefvol_half1.r_min_nn = 10;
	PPrefvol_half1.data_dim = 2;
	PPrefvol_half1.computeFourierTransformMap(refvol(), dum);
	fn_vol = fn_in.withoutExtension() + "_" + fn_out + "_half2_class001_unfil.mrc";
	refvol.read(fn_vol);
	PPrefvol_half2.ori_size = XSIZE(refvol());
	PPrefvol_half2.padding_factor = 2;
	PPrefvol_half2.interpolator = TRILINEAR;
	PPrefvol_half2.r_min_nn = 10;
	PPrefvol_half2.data_dim = 2;
	PPrefvol_half2.computeFourierTransformMap(refvol(), dum);

}
示例#10
0
文件: fftw.cpp 项目: shy3u/GeRelion
void correctMapForMTF(MultidimArray<Complex >& FT, int ori_size, FileName& fn_mtf)
{

	MetaDataTable MDmtf;

	if (!fn_mtf.isStarFile())
	{
		REPORT_ERROR("correctMapForMTF ERROR: input MTF file is not a STAR file.");
	}

	MDmtf.read(fn_mtf);
	MultidimArray<double> mtf_resol, mtf_value;
	mtf_resol.resize(MDmtf.numberOfObjects());
	mtf_value.resize(mtf_resol);

	int i = 0;
	FOR_ALL_OBJECTS_IN_METADATA_TABLE(MDmtf)
	{
		MDmtf.getValue(EMDL_RESOLUTION_INVPIXEL, DIRECT_A1D_ELEM(mtf_resol, i));  // resolution needs to be given in 1/pix
		MDmtf.getValue(EMDL_POSTPROCESS_MTF_VALUE, DIRECT_A1D_ELEM(mtf_value, i));
		if (DIRECT_A1D_ELEM(mtf_value, i) < 1e-10)
		{
			std::cerr << " i= " << i <<  " mtf_value[i]= " << DIRECT_A1D_ELEM(mtf_value, i) << std::endl;
			REPORT_ERROR("Postprocessing::sharpenMap ERROR: zero or negative values encountered in MTF curve!");
		}
		i++;
	}

	double xsize = (double)ori_size;
	FOR_ALL_ELEMENTS_IN_FFTW_TRANSFORM(FT)
	{
		int r2 = kp * kp + ip * ip + jp * jp;
		double res = sqrt((double)r2) / xsize; // get resolution in 1/pixel
		if (res < 0.5)
		{

			// Find the suitable MTF value
			int i_0 = 0;
			for (int ii = 0; ii < XSIZE(mtf_resol); ii++)
			{
				if (DIRECT_A1D_ELEM(mtf_resol, ii) > res)
				{
					break;
				}
				i_0 = ii;
			}
			// linear interpolation: y = y_0 + (y_1 - y_0)*(x-x_0)/(x1_x0)
			double mtf;
			double x_0 = DIRECT_A1D_ELEM(mtf_resol, i_0);
			if (i_0 == MULTIDIM_SIZE(mtf_resol) - 1 || i_0 == 0) // check boundaries of the array
			{
				mtf = DIRECT_A1D_ELEM(mtf_value, i_0);
			}
			else
			{
				double x_1 = DIRECT_A1D_ELEM(mtf_resol, i_0 + 1);
				double y_0 = DIRECT_A1D_ELEM(mtf_value, i_0);
				double y_1 = DIRECT_A1D_ELEM(mtf_value, i_0 + 1);
				mtf = y_0 + (y_1 - y_0) * (res - x_0) / (x_1 - x_0);
			}

			// Divide Fourier component by the MTF
			DIRECT_A3D_ELEM(FT, k, i, j) /= mtf;
		}
	}



}
示例#11
0
void compareMetaDataTable(MetaDataTable &MD1, MetaDataTable &MD2,
		MetaDataTable &MDboth, MetaDataTable &MDonly1, MetaDataTable &MDonly2,
		EMDLabel label1, DOUBLE eps, EMDLabel label2, EMDLabel label3)
{
	if (!MD1.containsLabel(label1))
		REPORT_ERROR("compareMetaDataTableEqualLabel::ERROR MD1 does not contain the specified label1.");
	if (!MD2.containsLabel(label1))
		REPORT_ERROR("compareMetaDataTableEqualLabel::ERROR MD2 does not contain the specified label1.");

	if (label2 != EMDL_UNDEFINED)
	{
		if (!EMDL::isDouble(label1) || !EMDL::isDouble(label2))
			REPORT_ERROR("compareMetaDataTableEqualLabel::ERROR 2D or 3D distances are only allowed for DOUBLEs.");
		if (!MD1.containsLabel(label2))
			REPORT_ERROR("compareMetaDataTableEqualLabel::ERROR MD1 does not contain the specified label2.");
		if (!MD2.containsLabel(label2))
			REPORT_ERROR("compareMetaDataTableEqualLabel::ERROR MD2 does not contain the specified label2.");
	}

	if (label3 != EMDL_UNDEFINED)
	{
		if (!EMDL::isDouble(label3))
			REPORT_ERROR("compareMetaDataTableEqualLabel::ERROR 3D distances are only allowed for DOUBLEs.");
		if (!MD1.containsLabel(label3))
			REPORT_ERROR("compareMetaDataTableEqualLabel::ERROR MD1 does not contain the specified label3.");
		if (!MD2.containsLabel(label3))
			REPORT_ERROR("compareMetaDataTableEqualLabel::ERROR MD2 does not contain the specified label3.");
	}

	MDboth.clear();
	MDonly1.clear();
	MDonly2.clear();

	std::string mystr1, mystr2;
	int myint1, myint2;
	DOUBLE myd1, myd2, mydy1 = 0., mydy2 = 0., mydz1 = 0., mydz2 = 0.;


	// loop over MD1
	std::vector<long int> to_remove_from_only2;
	for (long int current_object1 = MD1.firstObject();
	              current_object1 != MetaDataTable::NO_MORE_OBJECTS && current_object1 != MetaDataTable::NO_OBJECTS_STORED;
	              current_object1 = MD1.nextObject())
	{
		if (EMDL::isString(label1))
			MD1.getValue(label1, mystr1);
		else if (EMDL::isInt(label1))
			MD1.getValue(label1, myint1);
		else if (EMDL::isDouble(label1))
		{
			MD1.getValue(label1, myd1);
			if (label2 != EMDL_UNDEFINED)
				MD1.getValue(label2, mydy1);
			if (label3 != EMDL_UNDEFINED)
				MD1.getValue(label3, mydz1);
		}
		else
			REPORT_ERROR("compareMetaDataTableEqualLabel ERROR: only implemented for strings, integers or DOUBLEs");

		// loop over MD2
		bool have_in_2 = false;
		for (long int current_object2 = MD2.firstObject();
		              current_object2 != MetaDataTable::NO_MORE_OBJECTS && current_object2 != MetaDataTable::NO_OBJECTS_STORED;
		              current_object2 = MD2.nextObject())
		{

			if (EMDL::isString(label1))
			{
				MD2.getValue(label1, mystr2);
				if (strcmp(mystr1.c_str(), mystr2.c_str()) == 0)
				{
					have_in_2 = true;
					to_remove_from_only2.push_back(current_object2);
					MDboth.addObject(MD1.getObject());
					break;
				}
			}
			else if (EMDL::isInt(label1))
			{
				MD2.getValue(label1, myint2);
				if ( ABS(myint2 - myint1) <= ROUND(eps) )
				{
					have_in_2 = true;
					to_remove_from_only2.push_back(current_object2);
					MDboth.addObject(MD1.getObject());
					break;
				}
			}
			else if (EMDL::isDouble(label1))
			{
				MD2.getValue(label1, myd2);
				if (label2 != EMDL_UNDEFINED)
					MD2.getValue(label2, mydy2);
				if (label3 != EMDL_UNDEFINED)
					MD2.getValue(label3, mydz2);

				DOUBLE dist = sqrt( (myd1 - myd2) * (myd1 - myd2) +
						            (mydy1 - mydy2) * (mydy1 - mydy2) +
						            (mydz1 - mydz2) * (mydz1 - mydz2) );
				if ( ABS(dist) <= eps )
				{
					have_in_2 = true;
					to_remove_from_only2.push_back(current_object2);
					//std::cerr << " current_object1= " << current_object1 << std::endl;
					//std::cerr << " myd1= " << myd1 << " myd2= " << myd2 << " mydy1= " << mydy1 << " mydy2= " << mydy2 << " dist= "<<dist<<std::endl;
					//std::cerr << " to be removed current_object2= " << current_object2 << std::endl;
					MDboth.addObject(MD1.getObject());
					break;
				}
			}
		}

		if (!have_in_2)
		{
			MDonly1.addObject(MD1.getObject());
		}
	}



	for (long int current_object2 = MD2.firstObject();
				current_object2 != MetaDataTable::NO_MORE_OBJECTS && current_object2 != MetaDataTable::NO_OBJECTS_STORED;
				current_object2 = MD2.nextObject())
	{

		bool to_be_removed = false;
		for (long int i = 0; i < to_remove_from_only2.size(); i++)
		{
			if (to_remove_from_only2[i] == current_object2)
			{
				to_be_removed = true;
				break;
			}
		}
		if (!to_be_removed)
		{
			//std::cerr << " doNOT remove current_object2= " << current_object2 << std::endl;
			MDonly2.addObject(MD2.getObject(current_object2));
		}
	}


}
示例#12
0
void Postprocessing::divideByMtf(MultidimArray<Complex > &FT)
{

	if (fn_mtf != "")
	{
		if (verb > 0)
		{
			std::cout << "== Dividing map by the MTF of the detector ..." << std::endl;
			std::cout.width(35); std::cout << std::left <<"  + mtf STAR-file: "; std::cout << fn_mtf << std::endl;
		}

		MetaDataTable MDmtf;

		if (!fn_mtf.isStarFile())
			REPORT_ERROR("Postprocessing::divideByMtf ERROR: input MTF file is not a STAR file.");

		MDmtf.read(fn_mtf);
		MultidimArray<DOUBLE> mtf_resol, mtf_value;
		mtf_resol.resize(MDmtf.numberOfObjects());
		mtf_value.resize(mtf_resol);

		int i =0;
		FOR_ALL_OBJECTS_IN_METADATA_TABLE(MDmtf)
		{
			MDmtf.getValue(EMDL_RESOLUTION_INVPIXEL, DIRECT_A1D_ELEM(mtf_resol, i) ); // resolution needs to be given in 1/pix
			MDmtf.getValue(EMDL_POSTPROCESS_MTF_VALUE, DIRECT_A1D_ELEM(mtf_value, i) );
			if (DIRECT_A1D_ELEM(mtf_value, i) < 1e-10)
			{
				std::cerr << " i= " << i <<  " mtf_value[i]= " << DIRECT_A1D_ELEM(mtf_value, i) << std::endl;
				REPORT_ERROR("Postprocessing::sharpenMap ERROR: zero or negative values encountered in MTF curve!");
			}
			i++;
		}

	    DOUBLE xsize = (DOUBLE)XSIZE(I1());
	    FOR_ALL_ELEMENTS_IN_FFTW_TRANSFORM(FT)
	    {
	    	int r2 = kp * kp + ip * ip + jp * jp;
	    	DOUBLE res = sqrt((DOUBLE)r2)/xsize; // get resolution in 1/pixel
			if (res < 0.5 )
			{

				// Find the suitable MTF value
				int i_0 = 0;
				for (int ii = 0; ii < XSIZE(mtf_resol); ii++)
				{
					if (DIRECT_A1D_ELEM(mtf_resol, ii) > res)
						break;
					i_0 = ii;
				}
				// linear interpolation: y = y_0 + (y_1 - y_0)*(x-x_0)/(x1_x0)
				DOUBLE mtf;
				DOUBLE x_0 = DIRECT_A1D_ELEM(mtf_resol, i_0);
				if (i_0 == MULTIDIM_SIZE(mtf_resol) - 1 || i_0 == 0) // check boundaries of the array
					mtf = DIRECT_A1D_ELEM(mtf_value, i_0);
				else
				{
					DOUBLE x_1 = DIRECT_A1D_ELEM(mtf_resol, i_0 + 1);
					DOUBLE y_0 = DIRECT_A1D_ELEM(mtf_value, i_0);
					DOUBLE y_1 = DIRECT_A1D_ELEM(mtf_value, i_0 + 1);
					mtf = y_0 + (y_1 - y_0)*(res - x_0)/(x_1 - x_0);
				}

				// Divide Fourier component by the MTF
				DIRECT_A3D_ELEM(FT, k, i, j) /= mtf;
			}
	    }

	}


}
示例#13
0
	void run()
	{
		MD.read(fn_star);

		// Check for rlnImageName label
		if (!MD.containsLabel(EMDL_IMAGE_NAME))
			REPORT_ERROR("ERROR: Input STAR file does not contain the rlnImageName label");

		if (do_split_per_micrograph && !MD.containsLabel(EMDL_MICROGRAPH_NAME))
			REPORT_ERROR("ERROR: Input STAR file does not contain the rlnMicrographName label");

		Image<DOUBLE> in;
		FileName fn_img, fn_mic;
		std::vector<FileName> fn_mics;
		std::vector<int> mics_ndims;

		// First get number of images and their size
		int ndim=0;
		bool is_first=true;
		int xdim, ydim, zdim;
		FOR_ALL_OBJECTS_IN_METADATA_TABLE(MD)
		{
			if (is_first)
			{
				MD.getValue(EMDL_IMAGE_NAME, fn_img);
				in.read(fn_img);
				xdim=XSIZE(in());
				ydim=YSIZE(in());
				zdim=ZSIZE(in());
				is_first=false;
			}

			if (do_split_per_micrograph)
			{
				MD.getValue(EMDL_MICROGRAPH_NAME, fn_mic);
				bool have_found = false;
				for (int m = 0; m < fn_mics.size(); m++)
				{
					if (fn_mic == fn_mics[m])
					{
						have_found = true;
						mics_ndims[m]++;
						break;
					}
				}
				if (!have_found)
				{
					fn_mics.push_back(fn_mic);
					mics_ndims.push_back(1);
				}
			}
			ndim++;
		}


		// If not splitting, just fill fn_mics and mics_ndim with one entry (to re-use loop below)
		if (!do_split_per_micrograph)
		{
			fn_mics.push_back("");
			mics_ndims.push_back(ndim);
		}


		// Loop over all micrographs
		for (int m = 0; m < fn_mics.size(); m++)
		{
			ndim = mics_ndims[m];
			fn_mic = fn_mics[m];

			// Resize the output image
			std::cout << "Resizing the output stack to "<< ndim<<" images of size: "<<xdim<<"x"<<ydim<<"x"<<zdim << std::endl;
			DOUBLE Gb = ndim*zdim*ydim*xdim*8./1024./1024./1024.;
			std::cout << "This will require " << Gb << "Gb of memory...."<< std::endl;
			Image<DOUBLE> out(xdim, ydim, zdim, ndim);

			int n = 0;
			init_progress_bar(ndim);
			FOR_ALL_OBJECTS_IN_METADATA_TABLE(MD)
			{
				FileName fn_mymic;
				if (do_split_per_micrograph)
					MD.getValue(EMDL_MICROGRAPH_NAME, fn_mymic);
				else
					fn_mymic="";

				if (fn_mymic == fn_mic)
				{

					MD.getValue(EMDL_IMAGE_NAME, fn_img);
					in.read(fn_img);

					if (do_apply_trans)
					{
						DOUBLE xoff = 0.;
						DOUBLE yoff = 0.;
						DOUBLE psi = 0.;
						MD.getValue(EMDL_ORIENT_ORIGIN_X, xoff);
						MD.getValue(EMDL_ORIENT_ORIGIN_Y, yoff);
						MD.getValue(EMDL_ORIENT_PSI, psi);
						// Apply the actual transformation
						Matrix2D<DOUBLE> A;
						rotation2DMatrix(psi, A);
					    MAT_ELEM(A,0, 2) = xoff;
					    MAT_ELEM(A,1, 2) = yoff;
					    selfApplyGeometry(in(), A, IS_NOT_INV, DONT_WRAP);
					}

					out().setImage(n, in());
					n++;
					if (n%100==0) progress_bar(n);

				}
			}
			progress_bar(ndim);


			FileName fn_out;
			if (do_split_per_micrograph)
			{
				// Remove any extensions from micrograph names....
				fn_out = fn_root + "_" + fn_mic.withoutExtension() + fn_ext;
			}
			else
				fn_out = fn_root + fn_ext;
			out.write(fn_out);
			std::cout << "Written out: " << fn_out << std::endl;
		}
		std::cout << "Done!" <<std::endl;
	}
示例#14
0
文件: ctf.cpp 项目: dtegunov/vlion
/* Read -------------------------------------------------------------------- */
void CTF::read(MetaDataTable &MD1, MetaDataTable &MD2, long int objectID)
{

	if (!MD1.getValue(EMDL_CTF_VOLTAGE, kV, objectID))
		if (!MD2.getValue(EMDL_CTF_VOLTAGE, kV, objectID))
			kV=200;

	if (!MD1.getValue(EMDL_CTF_DEFOCUSU, DeltafU, objectID))
		if (!MD2.getValue(EMDL_CTF_DEFOCUSU, DeltafU, objectID))
			DeltafU=0;

	if (!MD1.getValue(EMDL_CTF_DEFOCUSV, DeltafV, objectID))
		if (!MD2.getValue(EMDL_CTF_DEFOCUSV, DeltafV, objectID))
			DeltafV=DeltafU;

	if (!MD1.getValue(EMDL_CTF_DEFOCUS_ANGLE, azimuthal_angle, objectID))
		if (!MD2.getValue(EMDL_CTF_DEFOCUS_ANGLE, azimuthal_angle, objectID))
			azimuthal_angle=0;

	if (!MD1.getValue(EMDL_CTF_CS, Cs, objectID))
		if (!MD2.getValue(EMDL_CTF_CS, Cs, objectID))
			Cs=0;

	if (!MD1.getValue(EMDL_CTF_BFACTOR, Bfac, objectID))
		if (!MD2.getValue(EMDL_CTF_BFACTOR, Bfac, objectID))
			Bfac=0;

	if (!MD1.getValue(EMDL_CTF_SCALEFACTOR, scale, objectID))
		if (!MD2.getValue(EMDL_CTF_SCALEFACTOR, scale, objectID))
			scale=1;

	if (!MD1.getValue(EMDL_CTF_Q0, Q0, objectID))
		if (!MD2.getValue(EMDL_CTF_Q0, Q0, objectID))
			Q0=0;

    if (!MD1.getValue(EMDL_CTF_PHASESHIFT, PhaseShift, objectID))
        if (!MD2.getValue(EMDL_CTF_PHASESHIFT, PhaseShift, objectID))
            PhaseShift = 0;

	initialise();
}
示例#15
0
文件: ctf.cpp 项目: dtegunov/vlion
/* Write ------------------------------------------------------------------- */
void CTF::write(std::ostream &out)
{
    MetaDataTable MD;
    MD.addObject();
    MD.setValue(EMDL_CTF_VOLTAGE, kV);
    MD.setValue(EMDL_CTF_DEFOCUSU, DeltafU);
    MD.setValue(EMDL_CTF_DEFOCUSV, DeltafV);
    MD.setValue(EMDL_CTF_DEFOCUS_ANGLE, azimuthal_angle);
    MD.setValue(EMDL_CTF_CS, Cs);
    MD.setValue(EMDL_CTF_BFACTOR, Bfac);
    MD.setValue(EMDL_CTF_SCALEFACTOR, scale);
    MD.setValue(EMDL_CTF_Q0, Q0);
    MD.setValue(EMDL_CTF_PHASESHIFT, PhaseShift);
    MD.write(out);
}
示例#16
0
文件: ctf.cpp 项目: dtegunov/vlion
/* Read from 1 MetaDataTable ----------------------------------------------- */
void CTF::read(MetaDataTable &MD)
{
	MetaDataTable MDempty;
	MDempty.addObject(); // add one empty object
	read(MD, MDempty);
}