Skip to content

Commit

Permalink
Added uncertainties in lattice parameters. refs #6837
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiSavici committed Apr 12, 2013
1 parent 340daea commit d0ea5b4
Show file tree
Hide file tree
Showing 4 changed files with 220 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,21 @@ namespace Geometry
void setalpha(double _alpha,const int angleunit=angDegrees);
void setbeta(double _beta,const int angleunit=angDegrees);
void setgamma(double _gamma,const int angleunit=angDegrees);

// Set errors
void setError(double _aerr, double _berr, double _cerr, double _alphaerr, double _betaerr, double _gammaerr,const int angleunit=angDegrees);
void setErrora(double _aerr);
void setErrorb(double _berr);
void setErrorc(double _cerr);
void setErroralpha(double _alphaerr,const int angleunit=angDegrees);
void setErrorbeta(double _betaerr,const int angleunit=angDegrees);
void setErrorgamma(double _gammaerr,const int angleunit=angDegrees);
// Get errors in latice parameters
double errora() const;
double errorb() const;
double errorc() const;
double erroralpha(const int angleunit=angDegrees) const;
double errorbeta(const int angleunit=angDegrees) const;
double errorgamma(const int angleunit=angDegrees) const;
// Access private variables
const Kernel::DblMatrix& getG() const;
const Kernel::DblMatrix& getGstar() const;
Expand All @@ -124,6 +138,8 @@ namespace Geometry
std::vector <double> da;
/// Reciprocal lattice parameters (in \f$ \mbox{ \AA }^{-1} \f$ and radians)
std::vector <double> ra;
/// Error in lattice parameters (in \f$ \mbox{ \AA } \f$ and radians)
std::vector <double> errorda;
/** Metric tensor
\f[ \left( \begin{array}{ccc}
aa & ab\cos(\gamma) & ac\cos(\beta) \\
Expand Down
167 changes: 159 additions & 8 deletions Code/Mantid/Framework/Geometry/src/Crystal/UnitCell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,38 @@ namespace Geometry

/** Default constructor.
\f$ a = b = c = 1 \mbox{\AA, } \alpha = \beta = \gamma = 90^\circ \f$ */
UnitCell::UnitCell(): da(6), ra(6), G(3,3), Gstar(3,3), B(3,3)
UnitCell::UnitCell(): da(6), ra(6), errorda(6), G(3,3), Gstar(3,3), B(3,3)
{
da[0]=da[1]=da[2]=1.;
da[3]=da[4]=da[5]=deg2rad*90.0;
errorda[0]=errorda[1]=errorda[2]=errorda[3]=errorda[4]=errorda[5]=0.0;
recalculate();
}

/** Copy constructor
@param other :: The UnitCell from which to copy lattice parameters
*/
UnitCell::UnitCell(const UnitCell& other):da(other.da),ra(other.ra),G(other.G),Gstar(other.Gstar),B(other.B),Binv(other.Binv)
UnitCell::UnitCell(const UnitCell& other):da(other.da),ra(other.ra),errorda(other.errorda),G(other.G),Gstar(other.Gstar),B(other.B),Binv(other.Binv)
{
}

/** Constructor
@param _a, _b, _c :: lattice parameters \f$ a, b, c \f$ \n
with \f$\alpha = \beta = \gamma = 90^\circ \f$*/
UnitCell::UnitCell(double _a, double _b, double _c): da(6), ra(6), G(3,3), Gstar(3,3), B(3,3)
UnitCell::UnitCell(double _a, double _b, double _c): da(6), ra(6), errorda(6), G(3,3), Gstar(3,3), B(3,3)
{
da[0]=_a;da[1]=_b;da[2]=_c;
// Angles are 90 degrees in radians ->Pi/2
da[3]=da[4]=da[5]=0.5*M_PI;
errorda[0]=errorda[1]=errorda[2]=errorda[3]=errorda[4]=errorda[5]=0.0;
recalculate();
}

/** Constructor
@param _a, _b, _c, _alpha, _beta, _gamma :: lattice parameters\n
@param angleunit :: units for angle, of type #AngleUnits. Default is degrees.
*/
UnitCell::UnitCell(double _a, double _b, double _c, double _alpha, double _beta, double _gamma,const int angleunit): da(6), ra(6), G(3,3), Gstar(3,3), B(3,3)
UnitCell::UnitCell(double _a, double _b, double _c, double _alpha, double _beta, double _gamma,const int angleunit): da(6), ra(6), errorda(6), G(3,3), Gstar(3,3), B(3,3)
{
da[0]=_a;da[1]=_b;da[2]=_c;
// Angle transformed in radians
Expand All @@ -58,7 +60,8 @@ namespace Geometry
da[4]=_beta;
da[5]=_gamma;
}
recalculate();
errorda[0]=errorda[1]=errorda[2]=errorda[3]=errorda[4]=errorda[5]=0.0;
recalculate();
}

/// Destructor
Expand Down Expand Up @@ -267,6 +270,81 @@ namespace Geometry
return ra[5]*rad2deg;
}



/** Get lattice parameter error
@return errora :: errorlattice parameter \f$ a \f$ (in \f$ \mbox{\AA} \f$ )
*/
double UnitCell::errora() const
{
return errorda[0];
}

/** Get lattice parameter error
@return errorb :: errorlattice parameter \f$ b \f$ (in \f$ \mbox{\AA} \f$ )
*/
double UnitCell::errorb() const
{
return errorda[1];
}

/** Get lattice parameter error
@return errorc :: errorlattice parameter \f$ c \f$ (in \f$ \mbox{\AA} \f$ )
*/
double UnitCell::errorc() const
{
return errorda[2];
}


/** Get lattice parameter error
@param angleunit :: units for angle, of type #AngleUnits . Default is degrees.
@return erroralpha :: errorlattice parameter \f$ alpha \f$ (in degrees or radians )
*/
double UnitCell::erroralpha(const int angleunit) const
{
if (angleunit==angDegrees)
{
return errorda[3]*rad2deg;
}
else
{
return errorda[3];
}
}

/** Get lattice parameter error
@param angleunit :: units for angle, of type #AngleUnits . Default is degrees.
@return erroralpha :: errorlattice parameter \f$ beta \f$ (in degrees or radians )
*/
double UnitCell::errorbeta(const int angleunit) const
{
if (angleunit==angDegrees)
{
return errorda[4]*rad2deg;
}
else
{
return errorda[4];
}
}

/** Get lattice parameter error
@param angleunit :: units for angle, of type #AngleUnits . Default is degrees.
@return erroralpha :: errorlattice parameter \f$ gamma \f$ (in degrees or radians )
*/
double UnitCell::errorgamma(const int angleunit) const
{
if (angleunit==angDegrees)
{
return errorda[5]*rad2deg;
}
else
{
return errorda[5];
}
}

/** Set lattice parameters
@param _a, _b, _c, _alpha, _beta, _gamma :: lattice parameters\n
@param angleunit :: units for angle, of type #AngleUnits . Default is degrees.
Expand All @@ -289,13 +367,42 @@ namespace Geometry
recalculate();
}

/** Set lattice parameter errors
@param _aerr, _berr, _cerr, _alphaerr, _betaerr, _gammaerr :: lattice parameter errors\n
@param angleunit :: units for angle, of type #AngleUnits . Default is degrees.
*/

void UnitCell::setError(double _aerr, double _berr, double _cerr, double _alphaerr, double _betaerr, double _gammaerr,const int angleunit)
{
errorda[0]=_aerr; errorda[1]=_berr; errorda[2]=_cerr;
if (angleunit==angDegrees)
{
errorda[3]=deg2rad*_alphaerr;
errorda[4]=deg2rad*_betaerr;
errorda[5]=deg2rad*_gammaerr;
}
else
{
errorda[3]=_alphaerr;
errorda[4]=_betaerr;
errorda[5]=_gammaerr;
}
}


/** Set lattice parameter
@param _a :: lattice parameter \f$ a \f$ (in \f$ \mbox{\AA} \f$ )*/
void UnitCell::seta(double _a)
{
da[0]=_a;
recalculate();
}
/** Set lattice parameter error
@param _aerr :: lattice parameter \f$ a \f$ error (in \f$ \mbox{\AA} \f$ )*/
void UnitCell::setErrora(double _aerr)
{
errorda[0]=_aerr;
}

/** Set lattice parameter
@param _b :: lattice parameter \f$ b \f$ (in \f$ \mbox{\AA} \f$ )*/
Expand All @@ -304,15 +411,25 @@ namespace Geometry
da[1]=_b;
recalculate();
}

/** Set lattice parameter error
@param _aerr :: lattice parameter \f$ b \f$ error (in \f$ \mbox{\AA} \f$ )*/
void UnitCell::setErrorb(double _berr)
{
errorda[1]=_berr;
}
/** Set lattice parameter
@param _c :: lattice parameter \f$ c \f$ (in \f$ \mbox{\AA} \f$ )*/
void UnitCell::setc(double _c)
{
da[2]=_c;
recalculate();
}

/** Set lattice parameter error
@param _aerr :: lattice parameter \f$ c \f$ error (in \f$ \mbox{\AA} \f$ )*/
void UnitCell::setErrorc(double _cerr)
{
errorda[2]=_cerr;
}
/** Set lattice parameter
@param _alpha :: lattice parameter \f$ \alpha \f$
@param angleunit :: units for angle, of type #AngleUnits. Default is degrees.
Expand All @@ -325,7 +442,17 @@ namespace Geometry
da[3]=_alpha;
recalculate();
}

/** Set lattice parameter error
@param _alphaerr :: lattice parameter \f$ \alpha \f$ error
@param angleunit :: units for angle, of type #AngleUnits. Default is degrees.
*/
void UnitCell::setErroralpha(double _alphaerr,const int angleunit)
{
if (angleunit==angDegrees)
errorda[3]=deg2rad*_alphaerr;
else
errorda[3]=_alphaerr;
}
/** Set lattice parameter
@param _beta :: lattice parameter \f$ \beta \f$
@param angleunit :: units for angle, of type #AngleUnits. Default is degrees.
Expand All @@ -339,6 +466,18 @@ namespace Geometry
recalculate();
}

/** Set lattice parameter error
@param _betaerr :: lattice parameter \f$ \beta \f$ error
@param angleunit :: units for angle, of type #AngleUnits. Default is degrees.
*/
void UnitCell::setErrorbeta(double _betaerr,const int angleunit)
{
if (angleunit==angDegrees)
errorda[4]=deg2rad*_betaerr;
else
errorda[4]=_betaerr;
}

/** Set lattice parameter
@param _gamma :: lattice parameter \f$ \gamma \f$
@param angleunit :: units for angle, of type #AngleUnits. Default is degrees.
Expand All @@ -352,6 +491,18 @@ namespace Geometry
recalculate();
}

/** Set lattice parameter error
@param _gammaerr :: lattice parameter \f$ \gamma \f$ error
@param angleunit :: units for angle, of type #AngleUnits. Default is degrees.
*/
void UnitCell::setErrorgamma(double _gammaerr,const int angleunit)
{
if (angleunit==angDegrees)
errorda[5]=deg2rad*_gammaerr;
else
errorda[5]=_gammaerr;
}

/// Return d-spacing (\f$ \mbox{ \AA } \f$) for a given h,k,l coordinate
double UnitCell::d(double h, double k, double l) const
{
Expand Down
30 changes: 30 additions & 0 deletions Code/Mantid/Framework/Geometry/test/UnitCellTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,36 @@ class UnitCellTest : public CxxTest::TestSuite
TS_ASSERT_DELTA(u2.a(),3,1e-10);
}

void test_Uncertainties()
{
UnitCell u(2,3,4,85.,95.,100);
TS_ASSERT_DELTA(u.errora(),0,1e-10);
TS_ASSERT_DELTA(u.errorb(),0,1e-10);
TS_ASSERT_DELTA(u.errorc(),0,1e-10);
TS_ASSERT_DELTA(u.erroralpha(),0,1e-10);
TS_ASSERT_DELTA(u.errorbeta(),0,1e-10);
TS_ASSERT_DELTA(u.errorgamma(),0,1e-10);
u.setError(0.1,0.2,0.3,5,6,7);
TS_ASSERT_DELTA(u.errora(),0.1,1e-10);
TS_ASSERT_DELTA(u.errorb(),0.2,1e-10);
TS_ASSERT_DELTA(u.errorc(),0.3,1e-10);
TS_ASSERT_DELTA(u.erroralpha(),5,1e-10);
TS_ASSERT_DELTA(u.errorbeta(),6,1e-10);
TS_ASSERT_DELTA(u.errorgamma(),7,1e-10);
u.setErrora(0.01);
u.setErrorb(0.02);
u.setErrorc(0.03);
u.setErroralpha(0.11);
u.setErrorbeta(0.12);
u.setErrorgamma(0.15,angRadians);
TS_ASSERT_DELTA(u.errora(),0.01,1e-10);
TS_ASSERT_DELTA(u.errorb(),0.02,1e-10);
TS_ASSERT_DELTA(u.errorc(),0.03,1e-10);
TS_ASSERT_DELTA(u.erroralpha(),0.11,1e-10);
TS_ASSERT_DELTA(u.errorbeta(),0.12,1e-10);
TS_ASSERT_DELTA(u.errorgamma(angRadians),0.15,1e-10);
}

void checkCell(UnitCell & u)
{
TS_ASSERT_DELTA(u.a(),2.5,1e-10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,13 @@ void export_UnitCell()
.def( "cstar", (double ( UnitCell::* )() const) &UnitCell::cstar )
.def( "d", (double ( UnitCell::* )( double,double,double ) const) &UnitCell::d, (arg("h"), arg("k"), arg("l") ))
.def( "d", (double ( UnitCell::* )(const V3D &) const) &UnitCell::d, (arg("hkl")))
.def( "dstar", (double ( UnitCell::* )( double,double,double ) const) &UnitCell::dstar , (arg("h"), arg("k"), arg("l") ))
.def( "dstar", (double ( UnitCell::* )( double,double,double ) const) &UnitCell::dstar , (arg("h"), arg("k"), arg("l") ))
.def( "errora", (double ( UnitCell::* )() const) &UnitCell::errora)
.def( "errorb", (double ( UnitCell::* )() const) &UnitCell::errorb)
.def( "errorc", (double ( UnitCell::* )() const) &UnitCell::errorc)
.def( "erroralpha", (double ( UnitCell::* )( int const ) const) &UnitCell::erroralpha , (arg("Unit")=(int)(angDegrees)))
.def( "errorbeta", (double ( UnitCell::* )( int const ) const) &UnitCell::errorbeta , (arg("Unit")=(int)(angDegrees)))
.def( "errorgamma", (double ( UnitCell::* )( int const ) const) &UnitCell::errorgamma , (arg("Unit")=(int)(angDegrees)))
.def( "gamma", (double ( UnitCell::* )() const) &UnitCell::gamma )
.def( "gammastar", (double ( UnitCell::* )() const) &UnitCell::gammastar )
.def( "recAngle", (double ( UnitCell::* )( double,double,double,double,double,double,int const ) const)&UnitCell::recAngle, ( arg("h1"), arg("k1"), arg("l1"), arg("h2"), arg("k2"), arg("l2"), arg("Unit")=(int)(angDegrees) ))
Expand All @@ -78,6 +84,13 @@ void export_UnitCell()
.def( "setbeta", (void ( UnitCell::* )( double,int const ) )( &UnitCell::setbeta ), ( arg("_beta"), arg("Unit")=(int)(angDegrees) ) )
.def( "setc", (void ( UnitCell::* )( double ) )( &UnitCell::setc ), ( arg("_c") ) )
.def( "setgamma", (void ( UnitCell::* )( double,int const ) )( &UnitCell::setgamma ), ( arg("_gamma"), arg("Unit")=(int)(angDegrees) ) )
.def( "setError", (void ( UnitCell::* )( double,double,double,double,double,double,int const)) &UnitCell::setError, ( arg("_aerr"), arg("_berr"), arg("_cerr"), arg("_alphaerr"), arg("_betaerr"), arg("_gammaerr"), arg("Unit")=(int)(angDegrees)))
.def( "setErrora", (void ( UnitCell::* )( double ) )( &UnitCell::setErrora ), ( arg("_aerr") ) )
.def( "setErroralpha", (void ( UnitCell::* )( double,int const ) )( &UnitCell::setErroralpha ), ( arg("_alphaerr"), arg("Unit")=(int)(angDegrees) ) )
.def( "setErrorb", (void ( UnitCell::* )( double ) )( &UnitCell::setErrorb ), ( arg("_berr") ) )
.def( "setErrorbeta", (void ( UnitCell::* )( double,int const ) )( &UnitCell::setErrorbeta ), ( arg("_betaerr"), arg("Unit")=(int)(angDegrees) ) )
.def( "setErrorc", (void ( UnitCell::* )( double ) )( &UnitCell::setErrorc ), ( arg("_cerr") ) )
.def( "setErrorgamma", (void ( UnitCell::* )( double,int const ) )( &UnitCell::setErrorgamma ), ( arg("_gammaerr"), arg("Unit")=(int)(angDegrees) ) )
.def( "volume", (double ( UnitCell::* )() const) &UnitCell::volume)
.def( "getG", &UnitCell::getG, return_readonly_numpy())
.def( "getGstar", &UnitCell::getGstar, return_readonly_numpy())
Expand Down

0 comments on commit d0ea5b4

Please sign in to comment.