23 #include "ObjCryst/ObjCryst/UnitCell.h"
24 #include "ObjCryst/Quirks/VFNStreamFormat.h"
28 const RefParType *gpRefParTypeUnitCell=0;
29 const RefParType *gpRefParTypeUnitCellLength=0;
30 const RefParType *gpRefParTypeUnitCellAngle=0;
31 long NiftyStaticGlobalObjectsInitializer_UnitCell::mCount=0;
35 mBMatrix(3,3),mOrthMatrix(3,3),mOrthMatrixInvert(3,3)
37 VFN_DEBUG_MESSAGE(
"UnitCell::UnitCell()",10)
39 this->
Init(10,11,12,M_PI/2+.1,M_PI/2+.2,M_PI/2+.3,
"P 1",
"");
46 mBMatrix(3,3),mOrthMatrix(3,3),mOrthMatrixInvert(3,3)
48 VFN_DEBUG_MESSAGE(
"UnitCell::UnitCell(a,b,c,Sg)",10)
49 this->
Init(a,b,c,M_PI/2,M_PI/2,M_PI/2,SpaceGroupId,
"");
56 const REAL beta,
const REAL gamma,
const string &SpaceGroupId):
58 mBMatrix(3,3),mOrthMatrix(3,3),mOrthMatrixInvert(3,3)
60 VFN_DEBUG_MESSAGE(
"UnitCell::UnitCell(a,b,c,alpha,beta,gamma,Sg)",10)
61 this->
Init(a,b,c,alpha,beta,gamma,SpaceGroupId,
"");
68 mCellDim(old.mCellDim),mSpaceGroup(old.GetSpaceGroup()),
69 mBMatrix(3,3),mOrthMatrix(3,3),mOrthMatrixInvert(3,3)
71 VFN_DEBUG_MESSAGE(
"UnitCell::UnitCell(&oldUnitCell)",10)
72 this ->InitRefParList();
82 VFN_DEBUG_ENTRY(
"UnitCell::~UnitCell()",5)
83 VFN_DEBUG_EXIT(
"UnitCell::~UnitCell()",5)
88 const static string className=
"UnitCell";
94 VFN_DEBUG_MESSAGE(
"UnitCell::GetLatticePar()",0)
147 cellDim(3) = M_PI/2.;
148 cellDim(4) = M_PI/2.;
149 cellDim(5) = M_PI*2./3.;
164 VFN_DEBUG_MESSAGE(
"UnitCell::LatticePar(i)",0)
165 if( (whichPar<0) || (whichPar>5))
166 throw ObjCrystException(
"UnitCell::LatticePar(int) :trying to access parameter>5!");
174 static CrystVector_REAL cellDim;
177 return cellDim(whichPar);
182 return cellDim(whichPar);
188 return cellDim(whichPar);
194 return cellDim(whichPar);
202 return cellDim(whichPar);
210 return cellDim(whichPar);
218 return cellDim(whichPar);
222 cellDim(3) = M_PI/2.;
223 cellDim(4) = M_PI/2.;
224 cellDim(5) = M_PI*2./3.;
226 return cellDim(whichPar);
233 return cellDim(whichPar);
239 VFN_DEBUG_MESSAGE(
"UnitCell::GetBMatrix()",0)
246 VFN_DEBUG_MESSAGE(
"UnitCell::GetOrthMatrix()",0)
256 CrystVector_REAL coords(3);
306 void UnitCell::Print(ostream &os)
const
308 VFN_DEBUG_MESSAGE(
"UnitCell::Print()",5)
313 os <<
" Cell dimensions : "
345 return a*b*c*sqrt(1-cos(alpha)*cos(alpha)-cos(beta)*cos(beta)-cos(gamma)*cos(gamma)
346 +2*cos(alpha)*cos(beta)*cos(gamma));
350 const REAL beta,
const REAL gamma,
const string &SpaceGroupId,
353 VFN_DEBUG_ENTRY(
"UnitCell::Init(a,b,c,alpha,beta,gamma,Sg,name)",10)
376 VFN_DEBUG_EXIT(
"UnitCell::Init(a,b,c,alpha,beta,gamma,Sg,name):End",10)
381 VFN_DEBUG_ENTRY(
"UnitCell::InitOptions",10)
382 static string ConstrainLatticeToSpaceGroupName;
383 static string ConstrainLatticeToSpaceGroupChoices[2];
385 static bool needInitNames=
true;
386 if(
true==needInitNames)
388 ConstrainLatticeToSpaceGroupName=
"Constrain Lattice to SpaceGroup Symmetry";
389 ConstrainLatticeToSpaceGroupChoices[0]=
"Yes (Default)";
390 ConstrainLatticeToSpaceGroupChoices[1]=
"No (Allow Crystallographic Pseudo-Symmetry)";
394 VFN_DEBUG_MESSAGE(
"UnitCell::Init(a,b,c,alpha,beta,gamma,Sg,name):Init options",5)
396 ConstrainLatticeToSpaceGroupChoices);
399 VFN_DEBUG_EXIT(
"UnitCell::InitOptions",10)
410 VFN_DEBUG_MESSAGE(
"UnitCell::InitMatrices() for crystal : "+this->
GetName(),5)
414 REAL a,b,c,alpha,beta,gamma;
415 REAL aa,bb,cc,alphaa,betaa,gammaa;
426 v=sqrt(1-cos(alpha)*cos(alpha)-cos(beta)*cos(beta)-cos(gamma)*cos(gamma)
427 +2*cos(alpha)*cos(beta)*cos(gamma));
433 alphaa=acos( (cos(beta )*cos(gamma)-cos(alpha))/sin(beta )/sin(gamma) );
434 betaa =acos( (cos(alpha)*cos(gamma)-cos(beta ))/sin(alpha)/sin(gamma) );
435 gammaa=acos( (cos(alpha)*cos(beta )-cos(gamma))/sin(alpha)/sin(beta ) );
439 mBMatrix = aa , bb*cos(gammaa) , cc*cos(betaa) ,
440 0 , bb*sin(gammaa) ,-cc*sin(betaa)*cos(alpha),
445 0 , b*sin(gamma) ,-c*sin(beta)*cos(alphaa),
455 VFN_DEBUG_MESSAGE(
"UnitCell::InitMatrices():End.",5)
462 VFN_DEBUG_ENTRY(
"UnitCell::UpdateLatticePar().",3)
532 VFN_DEBUG_EXIT(
"UnitCell::UpdateLatticePar().",3)
538 VFN_DEBUG_ENTRY(
"UnitCell::InitRefParList()",5)
609 gpRefParTypeUnitCellLength,REFPAR_DERIV_STEP_ABSOLUTE,
610 true,
true,a,
false,1.0);
617 gpRefParTypeUnitCellLength,REFPAR_DERIV_STEP_ABSOLUTE,
618 true,
true,b,
false,1.0);
625 gpRefParTypeUnitCellLength,REFPAR_DERIV_STEP_ABSOLUTE,
626 true,
true,c,
false,1.0);
633 gpRefParTypeUnitCellAngle,REFPAR_DERIV_STEP_ABSOLUTE,
634 true,
true,alpha,
false,RAD2DEG);
641 gpRefParTypeUnitCellAngle,REFPAR_DERIV_STEP_ABSOLUTE,
642 true,
true,beta,
false,RAD2DEG);
649 gpRefParTypeUnitCellAngle,REFPAR_DERIV_STEP_ABSOLUTE,
650 true,
true,gamma,
false,RAD2DEG);
666 VFN_DEBUG_EXIT(
"UnitCell::InitRefParList():Finished",5)
The namespace which includes all objects (crystallographic and algorithmic) in ObjCryst++.
Exception class for ObjCryst++ library.
The crystallographic space group, and the cell choice.
char GetExtension() const
Extension to space group symbol ('1','2':origin choice ; 'R','H'=rhomboedral/hexagonal)
const string & GetName() const
Get the name of this spacegroup (its name, as supplied initially by the calling program or user)
unsigned int GetUniqueAxis() const
Which is the unique axis (for monoclinic space groups )
int GetSpaceGroupNumber() const
Id number of the spacegroup.
const RefinableObjClock & GetClockSpaceGroup() const
Get the SpaceGroup Clock (corresponding to the time of the initialization of the SpaceGroup)
void ChangeSpaceGroup(const string &spgId)
Change the Spacegroup.
Unit Cell class: Unit cell with spacegroup information.
CrystMatrix_REAL mBMatrix
B Matrix (Orthogonalization matrix for reciprocal space)
CrystVector_REAL mCellDim
a,b and c in Angstroems, angles (stored) in radians For cubic, rhomboedric UnitCells,...
CrystMatrix_REAL mOrthMatrixInvert
inverse of Eucl Matrix (i.e. inverse of de-orthogonalization matrix for direct space)
CrystVector_REAL GetOrthonormalCoords(const REAL x, const REAL y, const REAL z) const
Get orthonormal cartesian coordinates for a set of (x,y,z) fractional coordinates.
CrystVector_REAL GetLatticePar() const
Lattice parameters (a,b,c,alpha,beta,gamma) as a 6-element vector in Angstroems and radians.
void ChangeSpaceGroup(const string &spgId)
Change the spacegroup.
void MillerToOrthonormalCoords(REAL &x, REAL &y, REAL &z) const
Get Miller H,K, L indices from orthonormal coordinates in reciprocal space.
CrystMatrix_REAL mOrthMatrix
Eucl Matrix (Orthogonalization matrix for direct space)
const RefinableObjClock & GetClockMetricMatrix() const
last time the metric matrices were changed
REAL GetVolume() const
Volume of Unit Cell (in Angstroems)
void InitRefParList()
Prepare the refinable parameters list.
UnitCell()
Default Constructor.
RefinableObjClock mClockMetricMatrix
virtual void Init(const REAL a, const REAL b, const REAL c, const REAL alpha, const REAL beta, const REAL gamma, const string &SpaceGroupId, const string &name)
Init all UnitCell parameters.
void OrthonormalToFractionalCoords(REAL &x, REAL &y, REAL &z) const
Get fractional cartesian coordinates for a set of (x,y,z) orthonormal coordinates.
SpaceGroup mSpaceGroup
The space group of the UnitCell.
RefinableObjClock mClockLatticePar
Last time lattice parameters were changed.
virtual const string & GetClassName() const
Name for this class ("RefinableObj", "Crystal",...).
RefinableObjClock mClockLatticeParUpdate
void InitMatrices() const
const SpaceGroup & GetSpaceGroup() const
Access to the SpaceGroup object.
const CrystMatrix_REAL & GetOrthMatrix() const
Get the orthogonalization matrix (UnitCell::mOrthMatrix)for the UnitCell in real space.
void OrthonormalToMillerCoords(REAL &x, REAL &y, REAL &z) const
Get orthonormal coordinates given a set of H,K, L indices in reciprocal space.
RefObjOpt mConstrainLatticeToSpaceGroup
Option to override lattice parameters constraints from spacegroup choice.
CrystMatrix_REAL mBMatrixInvert
inverse of B Matrix (i.e. inverse of orthogonalization matrix for direct space)
const CrystMatrix_REAL & GetBMatrix() const
Get the 'B' matrix (UnitCell::mBMatrix)for the UnitCell (orthogonalization matrix for the given latti...
const RefinableObjClock & GetClockLatticePar() const
last time the Lattice parameters were changed
virtual void InitOptions()
Init options.
void FractionalToOrthonormalCoords(REAL &x, REAL &y, REAL &z) const
Get orthonormal cartesian coordinates for a set of (x,y,z) fractional coordinates.
We need to record exactly when refinable objects have been modified for the last time (to avoid re-co...
void Reset()
Reset a Clock to 0, to force an update.
void AddChild(const RefinableObjClock &)
Add a 'child' clock.
void Click()
Record an event for this clock (generally, the 'time' an object has been modified,...
Generic class for parameters of refinable objects.
void SetDerivStep(const REAL)
Fixed step to use to compute numerical derivative.
void AssignClock(RefinableObjClock &clock)
void SetIsUsed(const bool)
Is the parameter used (if not, it is simply irrelevant in the model) ?
void AddPar(const RefinablePar &newRefPar)
Add a refinable parameter.
virtual void SetName(const string &name)
Name of the object.
RefinablePar & GetPar(const long i)
Access all parameters in the order they were inputted.
virtual const string & GetName() const
Name of the object.
long GetNbPar() const
Total number of refinable parameter in the object.
void AddOption(RefObjOpt *opt)
RefinableObjClock mClockMaster
Master clock, which is changed whenever the object has been altered.
string mName
Name for this RefinableObject. Should be unique, at least in the same scope.+.
output a number as a formatted float: