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,
"P1",
"");
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)
146 cellDim(3) = M_PI/2.;
147 cellDim(4) = M_PI/2.;
148 cellDim(5) = M_PI*2./3.;
163 VFN_DEBUG_MESSAGE(
"UnitCell::LatticePar(i)",0)
164 if( (whichPar<0) || (whichPar>5))
165 throw ObjCrystException(
"UnitCell::LatticePar(int) :trying to access parameter>5!");
172 static CrystVector_REAL cellDim;
175 return cellDim(whichPar);
180 return cellDim(whichPar);
186 return cellDim(whichPar);
192 return cellDim(whichPar);
200 return cellDim(whichPar);
208 return cellDim(whichPar);
216 return cellDim(whichPar);
220 cellDim(3) = M_PI/2.;
221 cellDim(4) = M_PI/2.;
222 cellDim(5) = M_PI*2./3.;
224 return cellDim(whichPar);
231 return cellDim(whichPar);
237 VFN_DEBUG_MESSAGE(
"UnitCell::GetBMatrix()",0)
244 VFN_DEBUG_MESSAGE(
"UnitCell::GetOrthMatrix()",0)
254 CrystVector_REAL coords(3);
304 void UnitCell::Print(ostream &os)
const
306 VFN_DEBUG_MESSAGE(
"UnitCell::Print()",5)
311 os <<
" Cell dimensions : "
335 return a*b*c*sqrt(1-cos(alpha)*cos(alpha)-cos(beta)*cos(beta)-cos(gamma)*cos(gamma)
336 +2*cos(alpha)*cos(beta)*cos(gamma));
340 const REAL beta,
const REAL gamma,
const string &SpaceGroupId,
343 VFN_DEBUG_ENTRY(
"UnitCell::Init(a,b,c,alpha,beta,gamma,Sg,name)",10)
362 VFN_DEBUG_EXIT(
"UnitCell::Init(a,b,c,alpha,beta,gamma,Sg,name):End",10)
367 VFN_DEBUG_ENTRY(
"UnitCell::InitOptions",10)
368 static string ConstrainLatticeToSpaceGroupName;
369 static string ConstrainLatticeToSpaceGroupChoices[2];
371 static bool needInitNames=
true;
372 if(
true==needInitNames)
374 ConstrainLatticeToSpaceGroupName=
"Constrain Lattice to SpaceGroup Symmetry";
375 ConstrainLatticeToSpaceGroupChoices[0]=
"Yes (Default)";
376 ConstrainLatticeToSpaceGroupChoices[1]=
"No (Allow Crystallographic Pseudo-Symmetry)";
380 VFN_DEBUG_MESSAGE(
"UnitCell::Init(a,b,c,alpha,beta,gamma,Sg,name):Init options",5)
382 ConstrainLatticeToSpaceGroupChoices);
385 VFN_DEBUG_EXIT(
"UnitCell::InitOptions",10)
395 VFN_DEBUG_MESSAGE(
"UnitCell::InitMatrices() for crystal : "+this->
GetName(),5)
399 REAL a,b,c,alpha,beta,gamma;
400 REAL aa,bb,cc,alphaa,betaa,gammaa;
411 v=sqrt(1-cos(alpha)*cos(alpha)-cos(beta)*cos(beta)-cos(gamma)*cos(gamma)
412 +2*cos(alpha)*cos(beta)*cos(gamma));
418 alphaa=acos( (cos(beta )*cos(gamma)-cos(alpha))/sin(beta )/sin(gamma) );
419 betaa =acos( (cos(alpha)*cos(gamma)-cos(beta ))/sin(alpha)/sin(gamma) );
420 gammaa=acos( (cos(alpha)*cos(beta )-cos(gamma))/sin(alpha)/sin(beta ) );
424 mBMatrix = aa , bb*cos(gammaa) , cc*cos(betaa) ,
425 0 , bb*sin(gammaa) ,-cc*sin(betaa)*cos(alpha),
430 0 , b*sin(gamma) ,-c*sin(beta)*cos(alphaa),
440 VFN_DEBUG_MESSAGE(
"UnitCell::InitMatrices():End.",5)
447 VFN_DEBUG_ENTRY(
"UnitCell::UpdateLatticePar().",3)
517 VFN_DEBUG_EXIT(
"UnitCell::UpdateLatticePar().",3)
523 VFN_DEBUG_ENTRY(
"UnitCell::InitRefParList()",5)
594 gpRefParTypeUnitCellLength,REFPAR_DERIV_STEP_ABSOLUTE,
595 true,
true,a,
false,1.0);
602 gpRefParTypeUnitCellLength,REFPAR_DERIV_STEP_ABSOLUTE,
603 true,
true,b,
false,1.0);
610 gpRefParTypeUnitCellLength,REFPAR_DERIV_STEP_ABSOLUTE,
611 true,
true,c,
false,1.0);
618 gpRefParTypeUnitCellAngle,REFPAR_DERIV_STEP_ABSOLUTE,
619 true,
true,alpha,
false,RAD2DEG);
626 gpRefParTypeUnitCellAngle,REFPAR_DERIV_STEP_ABSOLUTE,
627 true,
true,beta,
false,RAD2DEG);
634 gpRefParTypeUnitCellAngle,REFPAR_DERIV_STEP_ABSOLUTE,
635 true,
true,gamma,
false,RAD2DEG);
651 VFN_DEBUG_EXIT(
"UnitCell::InitRefParList():Finished",5)
CrystVector_REAL GetLatticePar() const
Lattice parameters (a,b,c,alpha,beta,gamma) as a 6-element vector in Angstroems and radians...
void SetDerivStep(const REAL)
Fixed step to use to compute numerical derivative.
void AddPar(const RefinablePar &newRefPar)
Add a refinable parameter.
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.
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
const RefinableObjClock & GetClockSpaceGroup() const
Get the SpaceGroup Clock (corresponding to the time of the initialization of the SpaceGroup) ...
void OrthonormalToFractionalCoords(REAL &x, REAL &y, REAL &z) const
Get fractional cartesian coordinates for a set of (x,y,z) orthonormal coordinates.
UnitCell()
Default Constructor.
We need to record exactly when refinable objects have been modified for the last time (to avoid re-co...
void FractionalToOrthonormalCoords(REAL &x, REAL &y, REAL &z) const
Get orthonormal cartesian coordinates for a set of (x,y,z) fractional coordinates.
RefinableObjClock mClockLatticePar
Last time lattice parameters were changed.
RefObjOpt mConstrainLatticeToSpaceGroup
Option to override lattice parameters constraints from spacegroup choice.
void MillerToOrthonormalCoords(REAL &x, REAL &y, REAL &z) const
Get Miller H,K, L indices from orthonormal coordinates in reciprocal space.
void Click()
Record an event for this clock (generally, the 'time' an object has been modified, or some computation has been made)
long GetNbPar() const
Total number of refinable parameter in the object.
void AddChild(const RefinableObjClock &)
Add a 'child' clock.
unsigned int GetUniqueAxis() const
Which is the unique axis (for monoclinic space groups )
RefinablePar & GetPar(const long i)
Access all parameters in the order they were inputted.
virtual const string & GetClassName() const
Name for this class ("RefinableObj", "Crystal",...).
const string & GetName() const
Get the name of this spacegroup (its name, as supplied initially by the calling program or user) ...
void SetIsUsed(const bool)
Is the parameter used (if not, it is simply irrelevant in the model) ?
RefinableObjClock mClockMaster
Master clock, which is changed whenever the object has been altered.
SpaceGroup mSpaceGroup
The space group of the UnitCell.
const SpaceGroup & GetSpaceGroup() const
Access to the SpaceGroup object.
const RefinableObjClock & GetClockMetricMatrix() const
last time the metric matrices were changed
void OrthonormalToMillerCoords(REAL &x, REAL &y, REAL &z) const
Get orthonormal coordinates given a set of H,K, L indices in reciprocal space.
string mName
Name for this RefinableObject. Should be unique, at least in the same scope.+.
void InitMatrices() const
The crystallographic space group, and the cell choice.
void AssignClock(RefinableObjClock &clock)
RefinableObjClock mClockMetricMatrix
REAL GetVolume() const
Volume of Unit Cell (in Angstroems)
CrystVector_REAL mCellDim
a,b and c in Angstroems, angles (stored) in radians For cubic, rhomboedric UnitCells, only the 'a' parameter is relevant.
output a number as a formatted float:
RefinableObjClock mClockLatticeParUpdate
void Reset()
Reset a Clock to 0, to force an update.
Exception class for ObjCryst++ library.
CrystMatrix_REAL mOrthMatrixInvert
inverse of Eucl Matrix (i.e. inverse of de-orthogonalization matrix for direct space) ...
The namespace which includes all objects (crystallographic and algorithmic) in ObjCryst++.
Unit Cell class: Unit cell with spacegroup information.
Generic class for parameters of refinable objects.
const CrystMatrix_REAL & GetOrthMatrix() const
Get the orthogonalization matrix (UnitCell::mOrthMatrix)for the UnitCell in real space.
void ChangeSpaceGroup(const string &spgId)
Change the Spacegroup.
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.
virtual const string & GetName() const
Name of the object.
int GetSpaceGroupNumber() const
Id number of the spacegroup.
CrystMatrix_REAL mOrthMatrix
Eucl Matrix (Orthogonalization matrix for direct space) .
CrystMatrix_REAL mBMatrix
B Matrix (Orthogonalization matrix for reciprocal space) .
char GetExtension() const
Extension to space group symbol ('1','2':origin choice ; 'R','H'=rhomboedral/hexagonal) ...
virtual void InitOptions()
Init options.
void AddOption(RefObjOpt *opt)
virtual void SetName(const string &name)
Name of the object.
void InitRefParList()
Prepare the refinable parameters list.