Skip to content

Commit

Permalink
Refs #9200 option for permutations of conventional cells
Browse files Browse the repository at this point in the history
  • Loading branch information
VickieLynch committed Mar 24, 2014
1 parent cb381c3 commit 9216c8b
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 36 deletions.
7 changes: 6 additions & 1 deletion Code/Mantid/Framework/Crystal/src/SelectCellWithForm.cpp
Expand Up @@ -99,6 +99,9 @@ namespace Crystal

this->declareProperty(new PropertyWithValue<double>( "AverageError", 0.0,
Direction::Output), "The average HKL indexing error if apply==true.");

this->declareProperty( "AllowPermutations", false,
"Allow permutations of conventional cells" );
}

Kernel::Matrix<double> SelectCellWithForm::DetermineErrors( std::vector<double> &sigabc, const Kernel::Matrix<double> &UB,
Expand Down Expand Up @@ -173,6 +176,8 @@ namespace Crystal
OrientedLattice o_lattice = ws->mutableSample().getOrientedLattice();
Matrix<double> UB = o_lattice.getUB();

bool allowPermutations = this->getProperty("AllowPermutations");

if ( ! IndexingUtils::CheckUB( UB ) )
{
throw std::runtime_error(
Expand All @@ -183,7 +188,7 @@ namespace Crystal
bool apply = this->getProperty("Apply");
double tolerance = this->getProperty("Tolerance");

ConventionalCell info = ScalarUtils::GetCellForForm( UB, form_num );
ConventionalCell info = ScalarUtils::GetCellForForm( UB, form_num, allowPermutations );

DblMatrix newUB = info.GetNewUB();

Expand Down
6 changes: 5 additions & 1 deletion Code/Mantid/Framework/Crystal/src/ShowPossibleCells.cpp
Expand Up @@ -89,6 +89,9 @@ namespace Crystal
this->declareProperty(
new PropertyWithValue<int>( "NumberOfCells", 0,
Direction::Output), "Gets set with the number of possible cells.");

this->declareProperty( "AllowPermutations", false,
"Allow permutations of conventional cells" );
}

//--------------------------------------------------------------------------
Expand Down Expand Up @@ -116,8 +119,9 @@ namespace Crystal

double max_scalar_error = this->getProperty("MaxScalarError");
bool best_only = this->getProperty("BestOnly");
bool allowPermutations = this->getProperty("AllowPermutations");

std::vector<ConventionalCell> list = ScalarUtils::GetCells( UB, best_only );
std::vector<ConventionalCell> list = ScalarUtils::GetCells( UB, best_only, allowPermutations );

ScalarUtils::RemoveHighErrorForms( list, max_scalar_error );

Expand Down
Expand Up @@ -54,7 +54,7 @@ namespace Geometry
{
public:
/// Construct a ConventionalCell for the specified UB and form number
ConventionalCell( const Kernel::DblMatrix & UB, size_t form_num = 0 );
ConventionalCell( const Kernel::DblMatrix & UB, size_t form_num = 0, bool allowPermutations = false);

/// get the form number for this conventional cell
size_t GetFormNum() const;
Expand Down Expand Up @@ -86,7 +86,8 @@ namespace Geometry
private:
void init( const Kernel::DblMatrix & UB,
ReducedCell & form_0,
ReducedCell & form_i );
ReducedCell & form_i,
bool allowPermutations);
void SetSidesIncreasing( Kernel::DblMatrix & UB );
void StandardizeTetragonal( Kernel::DblMatrix & UB );
void StandardizeHexagonal( Kernel::DblMatrix & UB );
Expand Down
Expand Up @@ -57,28 +57,32 @@ class MANTID_GEOMETRY_DLL ScalarUtils
/// reflecting pairs of sides a, b, c.
static std::vector<ConventionalCell> GetCells(
const Kernel::DblMatrix & UB,
bool best_only );
bool best_only,
bool allowPermutations = false);

/// Get list of conventional cells for UB with specified type and centering,
/// using this UB, and three related "almost Niggli" cells obtained by
/// reflecting pairs of sides a, b, c.
static std::vector<ConventionalCell> GetCells(
const Kernel::DblMatrix & UB,
const std::string & cell_type,
const std::string & centering );
const std::string & centering,
bool allowPermutations = false);

/// Get list of conventional cells for UB with specified type and centering,
/// using ONLY this UB, not related reflected cells.
static std::vector<ConventionalCell> GetCellsUBOnly(
const Kernel::DblMatrix & UB,
const std::string & cell_type,
const std::string & centering );
const std::string & centering,
bool allowPermutations = false);

/// Get the best conventional cell for the form number, using the specified
/// UB, and three related "almost Niggli" cells obtained by reflecting
/// pairs of sides a, b, c.
static ConventionalCell GetCellForForm( const Kernel::DblMatrix & UB,
size_t form_num );
size_t form_num,
bool allowPermutations = false);
/// Remove cells from list that have scalar errors above the specified level
static void RemoveHighErrorForms( std::vector<ConventionalCell> & list,
double level );
Expand Down
30 changes: 19 additions & 11 deletions Code/Mantid/Framework/Geometry/src/Crystal/ConventionalCell.cpp
Expand Up @@ -27,7 +27,8 @@ namespace Geometry
* reduced form number.
*/
ConventionalCell::ConventionalCell( const Kernel::DblMatrix & UB,
size_t form_num )
size_t form_num,
bool allowPermutations)
{
form_number = form_num;
std::vector<double> lat_par;
Expand All @@ -39,7 +40,7 @@ namespace Geometry
ReducedCell form_i = ReducedCell( form_num,
lat_par[0], lat_par[1], lat_par[2],
lat_par[3], lat_par[4], lat_par[5] );
init( UB, form_0, form_i );
init( UB, form_0, form_i ,allowPermutations);
}


Expand Down Expand Up @@ -174,7 +175,8 @@ namespace Geometry
*/
void ConventionalCell::init( const Kernel::DblMatrix & UB,
ReducedCell & form_0,
ReducedCell & form_i )
ReducedCell & form_i,
bool allowPermutations)
{
scalars_error = form_0.WeightedDistance( form_i );
cell_type = form_i.GetCellType();
Expand All @@ -187,15 +189,21 @@ namespace Geometry
Kernel::DblMatrix UB_tran( hkl_tran );
UB_tran.Invert();
adjusted_UB = UB * UB_tran;

if ( cell_type == ReducedCell::TETRAGONAL() )
{
StandardizeTetragonal( adjusted_UB );
}
else if ( cell_type == ReducedCell::HEXAGONAL() ||
cell_type == ReducedCell::RHOMBOHEDRAL() )
if (allowPermutations)
{
StandardizeHexagonal( adjusted_UB );
if ( cell_type == ReducedCell::ORTHORHOMBIC() )
{
SetSidesIncreasing( adjusted_UB );
}
else if ( cell_type == ReducedCell::TETRAGONAL() )
{
StandardizeTetragonal( adjusted_UB );
}
else if ( cell_type == ReducedCell::HEXAGONAL() ||
cell_type == ReducedCell::RHOMBOHEDRAL() )
{
StandardizeHexagonal( adjusted_UB );
}
}
}

Expand Down
51 changes: 37 additions & 14 deletions Code/Mantid/Framework/Geometry/src/Crystal/ScalarUtils.cpp
Expand Up @@ -86,15 +86,16 @@ static const std::string BRAVAIS_CENTERING[15] =

std::vector<ConventionalCell> ScalarUtils::GetCells(
const DblMatrix & UB,
bool best_only )
bool best_only ,
bool allowPermutations)
{
std::vector<ConventionalCell> result;

size_t num_lattices = 15;
for ( size_t i = 0; i < num_lattices; i++ )
{
std::vector<ConventionalCell>
temp = GetCells( UB, BRAVAIS_TYPE[i], BRAVAIS_CENTERING[i] );
temp = GetCells( UB, BRAVAIS_TYPE[i], BRAVAIS_CENTERING[i], allowPermutations);
if ( best_only )
{
ConventionalCell info = GetCellBestError( temp, true );
Expand Down Expand Up @@ -136,18 +137,29 @@ std::vector<ConventionalCell> ScalarUtils::GetCells(
std::vector<ConventionalCell> ScalarUtils::GetCells(
const DblMatrix & UB,
const std::string & cell_type,
const std::string & centering )
const std::string & centering,
bool allowPermutations)
{
double angle_tolerance = 2.0;
double length_factor = 1.05;

std::vector<ConventionalCell> result;
// Get exact form requested and not permutations
std::vector<DblMatrix> UB_list;
UB_list.push_back(UB);

std::vector<DblMatrix> UB_list;
if (allowPermutations)
{
UB_list = GetRelatedUBs( UB, length_factor, angle_tolerance );
}
else
{
// Get exact form requested and not permutations
UB_list.push_back(UB);
}

for ( size_t k = 0; k < UB_list.size(); k++ )
{
std::vector<ConventionalCell>
temp = GetCellsUBOnly( UB_list[k], cell_type, centering );
temp = GetCellsUBOnly( UB_list[k], cell_type, centering, allowPermutations );

for ( size_t i = 0; i < temp.size(); i++ )
AddIfBest( result, temp[i] );
Expand Down Expand Up @@ -181,7 +193,8 @@ std::vector<ConventionalCell> ScalarUtils::GetCells(
std::vector<ConventionalCell> ScalarUtils::GetCellsUBOnly(
const DblMatrix & UB,
const std::string & cell_type,
const std::string & centering )
const std::string & centering ,
bool allowPermutations)
{
std::vector<ConventionalCell> result;

Expand Down Expand Up @@ -219,18 +232,28 @@ std::vector<ConventionalCell> ScalarUtils::GetCellsUBOnly(
* error of any related matrix.
*/
ConventionalCell ScalarUtils::GetCellForForm( const DblMatrix & UB,
size_t form_num )
size_t form_num ,
bool allowPermutations)
{
ConventionalCell info( UB );
double angle_tolerance = 2.0;
double length_factor = 1.05;
ReducedCell form_0;
ReducedCell form;

double min_error = 1e20; // errors are usually < 10, so this is big enough
// Get exact form requested and not permutations
std::vector<double> l_params;
std::vector<DblMatrix> UB_list;
UB_list.push_back(UB);

std::vector<double> l_params;
std::vector<DblMatrix> UB_list;
if (allowPermutations)
{
UB_list = GetRelatedUBs( UB, angle_tolerance, length_factor );
}
else
{
// Get exact form requested and not permutations
UB_list.push_back(UB);
}
for ( size_t i = 0; i < UB_list.size(); i++ )
{
IndexingUtils::GetLatticeParameters( UB_list[i], l_params );
Expand All @@ -244,7 +267,7 @@ ConventionalCell ScalarUtils::GetCellForForm( const DblMatrix & UB,
double error = form_0.WeightedDistance( form );
if ( error < min_error )
{
info = ConventionalCell( UB_list[i], form_num );
info = ConventionalCell( UB_list[i], form_num, allowPermutations );
min_error = error;
}
}
Expand Down
6 changes: 3 additions & 3 deletions Code/Mantid/Framework/Geometry/test/ConventionalCellTest.h
Expand Up @@ -130,9 +130,9 @@ class ConventionalCellTest : public CxxTest::TestSuite
void test_HexagonalCase()
{
Matrix<double> correctNewUB(3,3,false);
V3D row_0( -0.122709, 0.006640, -0.144541 );
V3D row_1( -0.161964,-0.003276, 0.115259 );
V3D row_2( 0.117973, 0.233336, 0.005870 );
V3D row_0( 0.122709, 0.006640, 0.144541 );
V3D row_1( 0.161964, -0.003276, -0.115259 );
V3D row_2( -0.117973, 0.233336, -0.005870 );
correctNewUB.setRow( 0, row_0 );
correctNewUB.setRow( 1, row_1 );
correctNewUB.setRow( 2, row_2 );
Expand Down

0 comments on commit 9216c8b

Please sign in to comment.