コード例 #1
0
ファイル: Matrix.cpp プロジェクト: radixvinni/aal
 //(c) Chernysheva, TEST(Matrix, ToStringNotNullBits)
 //------->>>>>>>>>-----------------
 //перевод матрицы в строку,
 //возвращает строку c номерами строк и столбцов с ненулевыми значениям
 //в формате {строка, столбец}
 string Matrix::ToStringNotNullBits()
 {
   string res = "";
   switch (CodeWord)
   {
     case ON_LINE:
       for (int i = 0; i < RowCount; i++)
       {
         for (int j = 0; j < ColCount; j++)
         {
           bool val = this->getBit(i, j);
           if (val)
             res += "{" + i_to_str(i) + "," + i_to_str(j) + "}";
         }
       }
       break;
     case ON_COLUMN:
       Matrix buf(*this);
       buf.conversionMatrix();
       for (int i = 0; i < buf.getRowCount(); i++)
       {
         for (int j = 0; j < buf.getColCount(); j++)
         {
           bool val = buf.getBit(i, j);
           if (val)
             res += "{" + i_to_str(i) + "," + i_to_str(j) + "}";
         }
       }
       break;
   }
   return res;
 }
コード例 #2
0
void Deconvoluter::process()
{
    std::string file = FileParser::getKey("TWINNED_MTZ", std::string(""));
    wangEnvName = FileParser::getKey("WANG_ENVELOPE_OUTPUT", std::string("wang.env"));
    molUnitName = FileParser::getKey("MOL_UNIT_ENVELOPE_OUTPUT", std::string("mol_unit.env"));
    tempFftMapName = FileParser::getKey("TEMP_FFT_MAP", std::string("temp_fft.map"));
    tempAveMapName = FileParser::getKey("TEMP_AVERAGE_MAP", std::string("temp_ave.map"));
    tempMtzName = FileParser::getKey("TEMP_AVERAGE_MTZ", std::string("temp_ave.mtz"));
    tempSortedMtzName = FileParser::getKey("TEMP_AVERAGE_SORTED_MTZ", std::string("temp_sorted_ave.mtz"));
    cadMtzName = FileParser::getKey("TEMP_CAD_MTZ", std::string("temp_cad.mtz"));
    fsmeltMtzName = FileParser::getKey("TEMP_FSMELT_MTZ", std::string("temp_fsmelt.mtz"));
    std::string fObsLab = FileParser::getKey("LABIN_AMPLITUDES", std::string("F"));
    std::string fCalcLab = FileParser::getKey("LABOUT_CALC_AMPLITUDES", std::string("FC"));
    std::string ncsDefs = FileParser::getKey("NCS_DEFINITIONS_FILE", std::string(""));

    std::vector<double> ccAll, ccSinglets, rAll, rSinglets;

    if (ncsDefs.length() == 0)
    {
        std::cout << "Warning! NCS definitions file missing. Please specify file in GAP format using keyword NCS_DEFINITIONS_FILE" << std::endl;
        exit(1);
    }

    int bins = 20;
    int maxCycles = FileParser::getKey("MAXIMUM_CYCLES", 10);

    if (file == "")
    {
        std::cout << "Twinned MTZ has not been provided, please provide file path under keyword TWINNED_MTZ" << std::endl;
        exit(1);
    }

    // loading original, twinned MTZ into memory.
    originalMtz = MtzPtr(new MtzManager(file));
    originalMtz->loadReflections(false);
    MtzManager::setReference(&*originalMtz);
    spaceGroup = FileParser::getKey("SPACE_GROUP", originalMtz->getLowGroup()->spg_num);



    std::cout << "Loaded original MTZ file " << file << std::endl;
    bool skipFirst = FileParser::getKey("SKIP_FIRST_CYCLE", false);

    int beginning = FileParser::getKey("RESUME_FROM_CYCLE", 0);
    if (beginning > 0) skipFirst = true;

    for (int i = beginning; i < maxCycles; i++)
    {
        if (i > beginning || (i == beginning && !skipFirst))
        {
            fastFourierTransform(file, tempFftMapName, (i > 0));
            gapEnvelope(tempFftMapName);
            gapAverage(tempFftMapName, wangEnvName, molUnitName);
            map_to_sf(tempAveMapName, tempMtzName);
            sort_mtz(tempMtzName, tempSortedMtzName);
            cad(tempSortedMtzName, cadMtzName);
            fsmelt(file, cadMtzName, fsmeltMtzName);
        }

        MtzPtr nextMtz = MtzPtr(new MtzManager(fsmeltMtzName));
        nextMtz->loadReflections(true); // fc in "intensity" and f in "fc"...

        nextMtz->applyScaleFactorsForBins(bins);

        nextMtz->individualDetwinningScales((i == maxCycles - 1));
        nextMtz->copyOtherAmplitudesFromReference();
        file = "detwinned_cycle_" + i_to_str(i) + ".mtz";
        nextMtz->writeToFile(file);

        std::cout << "******************************" << std::endl;
        std::cout << "**    CORRELATION (ALL)     **" << std::endl;
        std::cout << "******************************" << std::endl;
        std::cout << std::endl << "Correlation between all scaled data and original twinned data" << std::endl;
        std::cout << std::endl << std::setw(15) << "Low res " << std::setw(15) << "High res " << std::setw(15) << "Correl" << std::setw(15) << "Num refl" << std::endl;

        ccAll.push_back(nextMtz->correlationWithManager(&*originalMtz, false, false, 0, 0, bins, NULL, false));

        std::cout << "*******************************" << std::endl;
        std::cout << "**  CORRELATION (SINGLETS)   **" << std::endl;
        std::cout << "*******************************" << std::endl;
        std::cout << std::endl << "Correlation between singlet scaled data and original twinned data" << std::endl;
        std::cout << std::endl << std::setw(15) << "Low res " << std::setw(15) << "High res " << std::setw(15) << "Correl" << std::setw(15) << "Num refl" << std::endl;

        ccSinglets.push_back(nextMtz->correlationWithManager(&*originalMtz, false, false, 0, 0, bins, NULL, true));

        std::cout << "******************************" << std::endl;
        std::cout << "**      R FACTOR (ALL)      **" << std::endl;
        std::cout << "******************************" << std::endl;
        std::cout << std::endl << "R factor between all scaled data and original twinned data" << std::endl;
        std::cout << std::endl << std::setw(15) << "Low res " << std::setw(15) << "High res " << std::setw(15) << "Correl" << std::setw(15) << "Num refl" << std::endl;

        rAll.push_back(nextMtz->rSplitWithManager(&*originalMtz, false, false, 0, 0, bins, NULL, false));

        std::cout << "*******************************" << std::endl;
        std::cout << "**   R FACTOR (SINGLETS)     **" << std::endl;
        std::cout << "*******************************" << std::endl;
        std::cout << std::endl << "R factor between singlet scaled data and original twinned data" << std::endl;
        std::cout << std::endl << std::setw(15) << "Low res " << std::setw(15) << "High res " << std::setw(15) << "Correl" << std::setw(15) << "Num refl" << std::endl;

        rSinglets.push_back(nextMtz->rSplitWithManager(&*originalMtz, false, false, 0, 0, bins, NULL, true));
    }

    std::cout << "*******************************" << std::endl;
    std::cout << "**   END OF DECONVOLUTION    **" << std::endl;
    std::cout << "*******************************" << std::endl;
    std::cout << std::endl << "Summary of deconvolution:" << std::endl << std::endl;
    std::cout << "Cycle\tCCall\tCCsinglets\tRall\tRsinglets" << std::endl;

    for (int i = 0; i < ccAll.size(); i++)
    {
        std::cout << i << "\t" << ccAll[i] << "\t" << ccSinglets[i] << "\t" << rAll[i] << "\t" << rSinglets[i] << std::endl;
    }
}
コード例 #3
0
ファイル: GraphDrawer.cpp プロジェクト: cppxfel/cppxfel
void GraphDrawer::partialityPlot(std::string filename, GraphMap properties, double maxRes)
{
    double correl = mtz->correlation();
    mtz->setActiveAmbiguity(1);
    double invCorrel = mtz->correlation();
    
    std::cout << "Ambiguity 0: " << correl << ", ambiguity 1: " << invCorrel << std::endl;
    
    if (correl > invCorrel)
        mtz->setActiveAmbiguity(0);
    
    double gradient = mtz->gradientAgainstManager(MtzManager::getReferenceManager());
    mtz->applyScaleFactor(gradient);
    
    properties["title"] = "Partiality plot " + mtz->getFilename();
	properties["xTitle"] = "Wavelength (Å)";
	properties["yTitle"] = "Fraction of merged data set (%)";
	properties["plotType"] = "fill";

	vector<double> resolutions;
	StatisticsManager::generateResolutionBins(0, maxRes, 4, &resolutions);

	vector<std::string> files;

	vector<Partial> partials;
	StatisticsManager::twoImagePartialityStatsWritten(&partials,
			&MtzManager::getReferenceManager(), &mtz);

	std::cout << "Total number of reflections in MTZ: " << partials.size() << std::endl;

	double maxPercentage = 1000;
	std::sort(partials.begin(), partials.end(), sortByPercentage);

	maxPercentage = partials[partials.size() - 10].percentage;

    if (maxPercentage < 500 || !std::isfinite(maxPercentage))
		maxPercentage = 500;

	maxPercentage = 500;

	std::sort(partials.begin(), partials.end(), sortByWavelength);

	double minX = partials[50].wavelength;
	double maxX = partials[partials.size() - 50].wavelength;
    double middle = partials[partials.size() / 2].wavelength;

    double wantedWidth = 0.08;
    
  //  std::cout << "minX: " << minX << ", maxX: " << maxX << ", middle: " << middle << std::endl;
    
	if (maxX - minX > wantedWidth)
	{
        maxX = middle + wantedWidth / 2;
		minX = middle - wantedWidth / 2;
	}

	int resCount = (int)resolutions.size();

	properties["xMin"] = minX;
	properties["xMax"] = maxX;
	properties["yMin2"] = 0;
	properties["yMax2"] = 5.0;
	properties["yMax"] = maxPercentage;

	vector<double> xs, xs2, xs3, xs4, ys, ys2, ys3, ys4, scatterX, scatterY;

    std::cout << std::setw(12) << "Low res" << std::setw(12) << "High res" << std::setw(12) << "Num refl." << std::endl;
    
    
	for (int shell = 0; shell < resCount - 1; shell++)
	{
		xs.clear();
		ys.clear();
        xs2.clear();
		ys2.clear();
        xs3.clear();
        ys3.clear();

		double lowRes = 1 / resolutions[shell];
		double highRes = 1 / resolutions[shell + 1];

        std::ofstream partLog;
        partLog.open("partiality_" + i_to_str(shell) + ".csv");
        partLog << "h,k,l,wavelength,partiality,percentage,intensity,resolution" << std::endl;
        
        int count = 0;
        
		for (int i = 0; i < partials.size(); i++)
		{
			if (partials[i].resolution > lowRes
					&& partials[i].resolution < highRes)
			{
                if (partials[i].wavelength != partials[i].wavelength
                    || partials[i].percentage != partials[i].percentage
                    || partials[i].partiality != partials[i].partiality)
                    continue;
                
                if (partials[i].percentage > maxPercentage)
                    continue;

                double h = partials[i].miller->getH();
                double k = partials[i].miller->getK();
                double l = partials[i].miller->getL();
                double wavelength = partials[i].wavelength;
                double partiality = partials[i].partiality;
                double percentage = partials[i].percentage;
                double intensity = partials[i].miller->getRawestIntensity();
                double resolution = partials[i].resolution;

                partLog << h << "," << k << "," << l << "," << wavelength << "," << partiality << "," <<
                percentage << "," << intensity << "," << resolution << std::endl;
                count++;
            }
		}
        
        partLog.close();

		std::cout << std::setw(12) << 1 / lowRes << std::setw(12) <<  1 / highRes << std::setw(12) << count
				<< std::endl;
	}
/*
	int milliseconds = 1200 / resCount;

	std::string animate = "convert -delay " + i_to_str(milliseconds) + " -loop 0 ";
	std::string rmv = "rm ";

	for (int i = 0; i < resCount - 1; i++)
	{
		animate += files[i] + " ";
		rmv += files[i] + " ";
	}

	rmv += "\n";

	std::string fullName = generateFilename(filename, "gif");

	animate += fullName;
	animate += "\n";
//	std::cout << animate << std::endl;

	std::string all = animate + rmv;

	system(all.c_str());

	std::cout << "N: plot " << fullName << std::endl;

	properties["title"] = "Partiality scatter";
	properties["xTitle"] = "Predicted partiality";
	properties["yTitle"] = "Fraction of merged data set (%)";
	properties["plotType"] = "point";

	properties["xMin"] = 0;
	properties["xMax"] = 1.2;
	properties["yMin"] = 0;
    properties["yMax"] = maxPercentage;
*/
//	plot(filename + "_scatter", properties, scatterX, scatterY);
}