/** Execute the algorithm. */ void PoldiCreatePeaksFromCell::exec() { // Get all user input regarding the unit cell SpaceGroup_const_sptr spaceGroup = getSpaceGroup(getProperty("SpaceGroup")); PointGroup_sptr pointGroup = PointGroupFactory::Instance().createPointGroupFromSpaceGroup(spaceGroup); UnitCell unitCell = getConstrainedUnitCell(getUnitCellFromProperties(), pointGroup->crystalSystem(), pointGroup->getCoordinateSystem()); g_log.information() << "Constrained unit cell is: " << unitCellToStr(unitCell) << '\n'; CompositeBraggScatterer_sptr scatterers = CompositeBraggScatterer::create( IsotropicAtomBraggScattererParser(getProperty("Atoms"))()); // Create a CrystalStructure-object for use with PoldiPeakCollection CrystalStructure crystalStructure(unitCell, spaceGroup, scatterers); double dMin = getProperty("LatticeSpacingMin"); double dMax = getDMaxValue(unitCell); // Create PoldiPeakCollection using given parameters, set output workspace PoldiPeakCollection_sptr peaks = boost::make_shared<PoldiPeakCollection>(crystalStructure, dMin, dMax); setProperty("OutputWorkspace", peaks->asTableWorkspace()); }
/** * Tries to refine the initial cell using the supplied peaks * * This method tries to refine the initial unit cell using the indexed peaks * that are supplied in the PoldiPeakCollection. If there are unindexed peaks, * the cell will not be refined at all, instead the unmodified initial cell * is returned. * * @param initialCell :: String with the initial unit cell * @param crystalSystem :: Crystal system name * @param peakCollection :: Collection of bragg peaks, must be indexed * * @return String for refined unit cell */ std::string PoldiFitPeaks2D::getRefinedStartingCell( const std::string &initialCell, const std::string &latticeSystem, const PoldiPeakCollection_sptr &peakCollection) { Geometry::UnitCell cell = Geometry::strToUnitCell(initialCell); ILatticeFunction_sptr latticeFunction = boost::dynamic_pointer_cast<ILatticeFunction>( FunctionFactory::Instance().createFunction("LatticeFunction")); latticeFunction->setLatticeSystem(latticeSystem); latticeFunction->fix(latticeFunction->parameterIndex("ZeroShift")); latticeFunction->setUnitCell(cell); // Remove errors from d-values PoldiPeakCollection_sptr clone = peakCollection->clone(); for (size_t i = 0; i < clone->peakCount(); ++i) { PoldiPeak_sptr peak = clone->peak(i); // If there are unindexed peaks, don't refine, just return the initial cell if (peak->hkl() == MillerIndices()) { return initialCell; } peak->setD(UncertainValue(peak->d().value())); } TableWorkspace_sptr peakTable = clone->asTableWorkspace(); IAlgorithm_sptr fit = createChildAlgorithm("Fit"); fit->setProperty("Function", boost::static_pointer_cast<IFunction>(latticeFunction)); fit->setProperty("InputWorkspace", peakTable); fit->setProperty("CostFunction", "Unweighted least squares"); fit->execute(); Geometry::UnitCell refinedCell = latticeFunction->getUnitCell(); return Geometry::unitCellToStr(refinedCell); }
/** Execute the algorithm. */ void PoldiCreatePeaksFromCell::exec() { // Get all user input regarding the unit cell SpaceGroup_const_sptr spaceGroup = getSpaceGroup(getProperty("SpaceGroup")); PointGroup_sptr pointGroup = PointGroupFactory::Instance().createPointGroupFromSpaceGroupSymbol( spaceGroup->hmSymbol()); UnitCell unitCell = getConstrainedUnitCell(getUnitCellFromProperties(), pointGroup->crystalSystem()); CompositeBraggScatterer_sptr scatterers = getScatterers(getProperty("Atoms")); // Create a CrystalStructure-object for use with PoldiPeakCollection CrystalStructure_sptr crystalStructure = boost::make_shared<CrystalStructure>(unitCell, spaceGroup, scatterers); double dMin = getProperty("LatticeSpacingMin"); double dMax = getDMaxValue(unitCell); // Create PoldiPeakCollection using given parameters, set output workspace PoldiPeakCollection_sptr peaks = boost::make_shared<PoldiPeakCollection>(crystalStructure, dMin, dMax); setProperty("OutputWorkspace", peaks->asTableWorkspace()); }
void PoldiFitPeaks1D2::exec() { setPeakFunction(getProperty("PeakFunction")); // Number of points around the peak center to use for the fit m_fwhmMultiples = getProperty("FwhmMultiples"); m_maxRelativeFwhm = getProperty("MaximumRelativeFwhm"); // try to construct PoldiPeakCollection from provided TableWorkspace TableWorkspace_sptr poldiPeakTable = getProperty("PoldiPeakTable"); m_peaks = getInitializedPeakCollection(poldiPeakTable); PoldiPeakCollection_sptr fittedPeaksNew = fitPeaks(m_peaks); PoldiPeakCollection_sptr fittedPeaksOld = m_peaks; int i = 0; while (fittedPeaksNew->peakCount() < fittedPeaksOld->peakCount() || i < 1) { fittedPeaksOld = fittedPeaksNew; fittedPeaksNew = fitPeaks(fittedPeaksOld); ++i; } setProperty("OutputWorkspace", fittedPeaksNew->asTableWorkspace()); setProperty("FitPlotsWorkspace", m_fitplots); }
/** Execute the algorithm. */ void PoldiIndexKnownCompounds::exec() { g_log.information() << "Starting POLDI peak indexing." << std::endl; DataObjects::TableWorkspace_sptr peakTableWorkspace = getProperty("InputWorkspace"); PoldiPeakCollection_sptr unindexedPeaks = boost::make_shared<PoldiPeakCollection>(peakTableWorkspace); g_log.information() << " Number of peaks: " << unindexedPeaks->peakCount() << std::endl; std::vector<Workspace_sptr> workspaces = getWorkspaces(getProperty("CompoundWorkspaces")); std::vector<PoldiPeakCollection_sptr> peakCollections = getPeakCollections(workspaces); g_log.information() << " Number of phases: " << peakCollections.size() << std::endl; /* The procedure is much easier to formulate with some state stored in member * variables, * which are initialized either from user input or from some defaults. */ setMeasuredPeaks(unindexedPeaks); setExpectedPhases(peakCollections); setExpectedPhaseNames(getWorkspaceNames(workspaces)); initializeUnindexedPeaks(); initializeIndexedPeaks(m_expectedPhases); /* For calculating scores in the indexing procedure, scattering contributions * are used. * The structure factors are scaled accordingly. */ std::vector<double> contributions = getContributions(m_expectedPhases.size()); std::vector<double> normalizedContributions = getNormalizedContributions(contributions); scaleIntensityEstimates(peakCollections, normalizedContributions); scaleToExperimentalValues(peakCollections, unindexedPeaks); // Tolerances on the other hand are handled as "FWHM". std::vector<double> tolerances = getTolerances(m_expectedPhases.size()); assignFwhmEstimates(peakCollections, tolerances); // With all necessary state assigned, the indexing procedure can be executed indexPeaks(unindexedPeaks, peakCollections); g_log.information() << " Unindexed peaks: " << m_unindexedPeaks->peakCount() << std::endl; /* Finally, the peaks are put into separate workspaces, determined by * the phase they have been attributed to, plus unindexed peaks. */ std::string inputWorkspaceName = getPropertyValue("InputWorkspace"); WorkspaceGroup_sptr outputWorkspaces = boost::make_shared<WorkspaceGroup>(); for (size_t i = 0; i < m_indexedPeaks.size(); ++i) { PoldiPeakCollection_sptr intensitySorted = getIntensitySortedPeakCollection(m_indexedPeaks[i]); assignCrystalStructureParameters(intensitySorted, m_expectedPhases[i]); ITableWorkspace_sptr tableWs = intensitySorted->asTableWorkspace(); AnalysisDataService::Instance().addOrReplace( inputWorkspaceName + "_indexed_" + m_phaseNames[i], tableWs); outputWorkspaces->addWorkspace(tableWs); } ITableWorkspace_sptr unindexedTableWs = m_unindexedPeaks->asTableWorkspace(); AnalysisDataService::Instance().addOrReplace( inputWorkspaceName + "_unindexed", unindexedTableWs); outputWorkspaces->addWorkspace(unindexedTableWs); setProperty("OutputWorkspace", outputWorkspaces); }