void DiffractionDataSingleCrystal::CalcIcalc() const { TAU_PROFILE("DiffractionData::CalcIcalc()","void ()",TAU_DEFAULT); VFN_DEBUG_MESSAGE("DiffractionData::CalcIcalc():"<<this->GetName(),3) this->GetFhklCalcSq(); if( (mClockStructFactorSq<mClockIcalc) && (mClockScaleFactor<mClockIcalc) && ((0==mGroupOption.GetChoice()) || (mClockPrepareTwinningCorr<mClockIcalc)) ) return; mCalcIntensity=mFhklCalcSq; mCalcIntensity*=mScaleFactor; if(0!=mGroupOption.GetChoice()) { if(1==mGroupOption.GetChoice()) this->PrepareTwinningCalc(); mGroupIcalc.resize(mNbGroup); mGroupIcalc=0; long first=0; for(long i=0;i<mNbGroup;i++) { //cout<<"Group #"<<i<<":"<<first<<"->"<<mGroupIndex(i)<<endl; for(long j=first;j<mGroupIndex(i);j++) { //cout <<" " << mIntH(j)<<" "<< mIntK(j)<<" "<< mIntL(j)<<" " << mCalcIntensity(j)<<endl; mGroupIcalc(i)+=mCalcIntensity(j); } first=mGroupIndex(i); //cout << " => Icalc="<< mGroupIcalc(i) <<" , Iobs="<< mGroupIobs(i)<<endl<<endl; } } mClockIcalc.Click(); }
//////////////////////////////////////////////////////////////////////// // // ATOM : the basic atom, within the crystal // //includes thermic factor (betas) and x,y,z,population // //////////////////////////////////////////////////////////////////////// Atom::Atom() :mScattCompList(1),mpScattPowAtom(0) { VFN_DEBUG_MESSAGE("Atom::Atom()",5) this->InitRefParList(); mScattCompList(0).mpScattPow=mpScattPowAtom; }
void DiffractionDataSingleCrystal::SaveHKLIobsIcalc(const string &filename) { VFN_DEBUG_MESSAGE("DiffractionDataSingleCrystal::SaveHKLIobsIcalc",5) this->GetIcalc(); ofstream out(filename.c_str()); CrystVector_REAL theta; theta=mTheta; theta *= RAD2DEG; if(false == mHasObservedData) { out << "# H K L Icalc theta sin(theta)/lambda" <<" Re(F) Im(F)" << endl; out << FormatVertVectorHKLFloats<REAL>(mH,mK,mL,mCalcIntensity, theta,mSinThetaLambda,mFhklCalcReal,mFhklCalcImag,12,4); } else { out << "# H K L Iobs Icalc theta" <<" sin(theta)/lambda Re(F) Im(F)" << endl; out << FormatVertVectorHKLFloats<REAL>(mH,mK,mL,mObsIntensity,mCalcIntensity, theta,mSinThetaLambda,mFhklCalcReal,mFhklCalcImag,12,4); } out.close(); VFN_DEBUG_MESSAGE("DiffractionDataSingleCrystal::SaveHKLIobsIcalc:End",3) }
Atom::Atom( const REAL x, const REAL y, const REAL z, const string &name, const ScatteringPower *pow,const REAL popu) :mScattCompList(1),mpScattPowAtom(pow) { VFN_DEBUG_MESSAGE("Atom::Atom(x,y,z,P,B,name,ScatteringPower):"<<name,5) this->Init(x,y,z,name,mpScattPowAtom,popu); }
REAL DiffractionDataSingleCrystal::GetBestRFactor() const { TAU_PROFILE("DiffractionData::GetBestRFactor()","void ()",TAU_DEFAULT); VFN_DEBUG_MESSAGE("DiffractionData::GetBestRFactor()",3); this->FitScaleFactorForR(); return this->GetR(); }
void ScatteringPower::Init() { VFN_DEBUG_MESSAGE("ScatteringPower::Init():"<<mName,2) mColourName="White"; mMaximumLikelihoodPositionError=0; mMaximumLikelihoodNbGhost=0; VFN_DEBUG_MESSAGE("ScatteringPower::Init():End",2) }
//////////////////////////////////////////////////////////////////////// // // AsymmetricUnit // //////////////////////////////////////////////////////////////////////// AsymmetricUnit::AsymmetricUnit() { VFN_DEBUG_MESSAGE("AsymmetricUnit::AsymmetricUnit()",5) mXmin=0; mYmin=0; mZmin=0; mXmax=1; mYmax=1; mZmax=1; }
void DiffractionDataSingleCrystal::InitRefParList() { VFN_DEBUG_MESSAGE("DiffractionDataSingleCrystal::InitRefParList()",5) RefinablePar tmp("Scale factor",&mScaleFactor, 1e-10,1e10,gpRefParTypeScattDataScale,REFPAR_DERIV_STEP_RELATIVE, false,true,true,false,1.); tmp.SetGlobalOptimStep(0.); tmp.AssignClock(mClockScaleFactor); tmp.SetDerivStep(1e-4); this->AddPar(tmp); }
REAL DiffractionDataSingleCrystal::GetRw()const { TAU_PROFILE("DiffractionData::Rw()"," REAL()",TAU_DEFAULT); VFN_DEBUG_MESSAGE("DiffractionData::Rw()",3); if(mHasObservedData==false) { return 0; } REAL tmp1=0; REAL tmp2=0; const REAL *p1; const REAL *p2; const REAL *p3; long nb; if(mGroupOption.GetChoice()==0) { p1=mCalcIntensity.data(); p2=mObsIntensity.data(); p3=mWeight.data(); nb=mNbReflUsed; } else { p1=mGroupIcalc.data(); p2=mGroupIobs.data(); p3=mGroupWeight.data(); nb=mGroupIobs.numElements(); } for(long i=nb;i>0;i--) { tmp1 += *p3 * ( *p1 - *p2) * ( *p1 - *p2); tmp2 += *p3 * *p2 * *p2; p1++;p2++;p3++; } tmp1=sqrt(tmp1/tmp2); VFN_DEBUG_MESSAGE("DiffractionData::Rw()="<<tmp1,3); return tmp1 ;// /this->GetNbRefl(); }
Atom::Atom(const Atom &old) :Scatterer(old),mScattCompList(1),mpScattPowAtom(old.mpScattPowAtom) { VFN_DEBUG_MESSAGE("Atom::Atom(&old):/Name="<<old.mName,5) //:TODO: Check if this is enough (copy constructor for Scatterer ??) this->Init(old.mXYZ(0),old.mXYZ(1),old.mXYZ(2), old.mName,mpScattPowAtom, old.mOccupancy); this->GetPar(mXYZ.data()). CopyAttributes(old.GetPar(old.mXYZ.data())); this->GetPar(mXYZ.data()+1).CopyAttributes(old.GetPar(old.mXYZ.data()+1)); this->GetPar(mXYZ.data()+2).CopyAttributes(old.GetPar(old.mXYZ.data()+2)); this->GetPar(&mOccupancy). CopyAttributes(old.GetPar(&(old.mOccupancy))); }
void DiffractionDataSingleCrystal::SetIobsToIcalc() { VFN_DEBUG_MESSAGE("DiffractionDataSingleCrystal::SetIobsToIcalc()",5) mObsIntensity=this->GetIcalc(); mObsSigma.resize(mNbRefl); mWeight.resize(mNbRefl); mWeight=1; mObsSigma=0; mHasObservedData=true; // Keep a copy as squared F(hkl), to enable fourier maps // :TODO: stop using mObsIntensity and just keep mFhklObsSq ? mFhklObsSq=mObsIntensity; mClockFhklObsSq.Click(); mClockMaster.Click(); }
void DiffractionDataSingleCrystal::FitScaleFactorForRw() const { TAU_PROFILE("DiffractionData::FitScaleFactorForRw()","void ()",TAU_DEFAULT); VFN_DEBUG_MESSAGE("DiffractionData::FitScaleFactorForRw()",3); if(mHasObservedData==false) {//throw exception here ? return; //throw ObjCrystException("DiffractionData::FitScaleFactorForRw() Cannot compute Rw // or scale factor: there is no observed data !"); } REAL tmp1=0; REAL tmp2=0; const REAL *p1; const REAL *p2; const REAL *p3; long nb; if(mGroupOption.GetChoice()==0) { p1=mCalcIntensity.data(); p2=mObsIntensity.data(); p3=mWeight.data(); nb=mNbReflUsed; } else { p1=mGroupIcalc.data(); p2=mGroupIobs.data(); p3=mGroupWeight.data(); nb=mGroupIobs.numElements(); } for(long i=nb;i>0;i--) { tmp1 += *p3 * (*p1) * (*p2++); tmp2 += *p3++ * (*p1) * (*p1); p1++; } mScaleFactor *= tmp1/tmp2; mClockScaleFactor.Click(); mCalcIntensity *= tmp1/tmp2; if(0!=mGroupOption.GetChoice()) mGroupIcalc*= tmp1/tmp2; mClockIcalc.Click(); }
void AsymmetricUnit::SetSpaceGroup(const SpaceGroup &spg) { VFN_DEBUG_MESSAGE("AsymmetricUnit::SetSpaceGroup(SpGroup)",5) tmp_C_Numeric_locale tmploc; # if 0 TAU_PROFILE("(AsymmetricUnit::SetSpaceGroup)","void (SpaceGroup)",TAU_DEFAULT); mXmin=0.; mYmin=0.; mZmin=0.; mXmax=1.; mYmax=1.; mZmax=1.; if(1==spg.GetSpaceGroupNumber()) return;//no need to search an asymmetric unit // Test points=reular grid of points inside the unit cell // All points must be or have at least a symmetric in the asymmetric unit const long nbPoints=13; CrystMatrix_REAL testPoints(nbPoints*nbPoints*nbPoints,3); { long l=0; for(long i=0;i<nbPoints;i++) for(long j=0;j<nbPoints;j++) for(long k=0;k<nbPoints;k++) { testPoints(l ,0)=i/(REAL)nbPoints; testPoints(l ,1)=j/(REAL)nbPoints; testPoints(l++,2)=k/(REAL)nbPoints; } } testPoints += 0.01; CrystVector_REAL vert(8);//vertices limits vert(0)=1/8.; vert(1)=1/6.; vert(2)=1/4.; vert(3)=1/3.; vert(4)=1/2.; vert(5)=2/3.; vert(6)=3/4.; vert(7)=1.; const int NbStep=vert.numElements(); CrystMatrix_REAL coords; double junk; REAL minVolume=1.; bool allPtsInAsym,tmp; for(long nx=0;nx<NbStep;nx++) for(long ny=0;ny<NbStep;ny++) for(long nz=0;nz<NbStep;nz++) { if(minVolume<(vert(nx)*vert(ny)*vert(nz)-.0001)) break; allPtsInAsym=true; for(int i=0;i<testPoints.rows();i++) { coords=spg.GetAllSymmetrics(testPoints(i,0),testPoints(i,1),testPoints(i,2)); for(long j=0;j<coords.numElements();j++) coords(j)=modf(coords(j)+10.,&junk) ; tmp=false; for(long j=0;j<coords.rows();j++) {//Test if at least one of the symmetrics is in the parallelepiped if( (coords(j,0) < vert(nx)) &&(coords(j,1) < vert(ny)) &&(coords(j,2) < vert(nz))) { //cout << modf(coords(j,0)+10.,junk) << " " // << modf(coords(j,1)+10.,junk) << " " // << modf(coords(j,2)+10.,junk) << endl; tmp=true; break; } } if(false==tmp) { //cout << " Rejected:"<<vert(nx)<<" "<<vert(ny)<<" "<<vert(nz)<<" "<<i<<endl; //cout << coords <<endl; allPtsInAsym=false; break; } } if( (true==allPtsInAsym)) { mXmax=vert(nx); mYmax=vert(ny); mZmax=vert(nz); VFN_DEBUG_MESSAGE("->ACCEPTED:" << mXmax <<" "<< mYmax <<" "<< mZmax <<endl,2) //cout << "->ACCEPTED:" << mXmax <<" "<< mYmax <<" "<< mZmax <<endl; minVolume=vert(nx)*vert(ny)*vert(nz); break;//no need to grow any more along z } } cout<<"->Finished Generating (pseudo) Asymmetric Unit, with:"<<endl <<" 0 <= x <= "<< mXmax<<endl <<" 0 <= y <= "<< mYmax<<endl <<" 0 <= z <= "<< mZmax<<endl<<endl; #else const cctbx::sgtbx::brick b(spg.GetCCTbxSpg().type()); #ifdef __DEBUG__ cout<<"->>Parallelepipedic Asymmetric Unit, from cctbx::sgtbx::brick:"<<endl <<b.as_string()<<endl; #endif mXmin=boost::rational_cast<REAL,int>(b(0,0).value()); mYmin=boost::rational_cast<REAL,int>(b(1,0).value()); mZmin=boost::rational_cast<REAL,int>(b(2,0).value()); mXmax=boost::rational_cast<REAL,int>(b(0,1).value()); mYmax=boost::rational_cast<REAL,int>(b(1,1).value()); mZmax=boost::rational_cast<REAL,int>(b(2,1).value()); #endif }
AsymmetricUnit::AsymmetricUnit(const SpaceGroup &spg) { VFN_DEBUG_MESSAGE("AsymmetricUnit::AsymmetricUnit(SpGroup)",5) this->SetSpaceGroup(spg); }
void SpaceGroup::ChangeSpaceGroup(const string &spgId) { VFN_DEBUG_MESSAGE("SpaceGroup::ChangeSpaceGroup():"<<spgId,5) this->InitSpaceGroup(spgId); }
mYmin=0; mZmin=0; mXmax=1; mYmax=1; mZmax=1; } AsymmetricUnit::AsymmetricUnit(const SpaceGroup &spg) { VFN_DEBUG_MESSAGE("AsymmetricUnit::AsymmetricUnit(SpGroup)",5) this->SetSpaceGroup(spg); } AsymmetricUnit::~AsymmetricUnit() { VFN_DEBUG_MESSAGE("AsymmetricUnit::~AsymmetricUnit(SpGroup)",5) } void AsymmetricUnit::SetSpaceGroup(const SpaceGroup &spg) { VFN_DEBUG_MESSAGE("AsymmetricUnit::SetSpaceGroup(SpGroup)",5) tmp_C_Numeric_locale tmploc; # if 0 TAU_PROFILE("(AsymmetricUnit::SetSpaceGroup)","void (SpaceGroup)",TAU_DEFAULT); mXmin=0.; mYmin=0.; mZmin=0.; mXmax=1.; mYmax=1.; mZmax=1.; if(1==spg.GetSpaceGroupNumber()) return;//no need to search an asymmetric unit
void DiffractionDataSingleCrystal::SetWavelength(const REAL lambda) { VFN_DEBUG_MESSAGE("DiffractionDataSingleCrystal::SetWavelength() to "<<lambda,5) this->GetRadiation().SetWavelength(lambda); }
void DiffractionDataSingleCrystal::SetWavelength(const string &XRayTubeElementName, const REAL alpha2Alpha2ratio) { VFN_DEBUG_MESSAGE("DiffractionDataSingleCrystal::SetWavelength() to "<<XRayTubeElementName,5) this->GetRadiation().SetWavelength(XRayTubeElementName,alpha2Alpha2ratio); }
void DiffractionDataSingleCrystal::SetWeight(const CrystVector_REAL& weight) { VFN_DEBUG_MESSAGE("DiffractionDataSingleCrystal::SetWeight(w)",5) mWeight=weight; mClockMaster.Click(); }
void DiffractionDataSingleCrystal::SetRadiationType(const RadiationType radiation) { VFN_DEBUG_MESSAGE("DiffractionDataSingleCrystal::SetRadiationType():End",5) mRadiation.SetRadiationType(radiation); }
void DiffractionDataSingleCrystal::ImportShelxHKLF4(const string &fileName) { VFN_DEBUG_ENTRY("DiffractionDataSingleCrystal::ImportShelxHKLF4():"<<fileName,10); char buf[101]; //configure members mNbRefl=100; mH.resize(mNbRefl); mK.resize(mNbRefl); mL.resize(mNbRefl); mObsIntensity.resize(mNbRefl); mObsSigma.resize(mNbRefl); long h=1,k=1,l=1,i=0; float iobs,sigma; //Import data { VFN_DEBUG_MESSAGE("inputing reflections from file (HKLF4): "<<fileName,10); ifstream fin (fileName.c_str()); if(!fin) { throw ObjCrystException("DiffractionDataSingleCrystal::ImportShelxHKLF4() : Error opening file for input:"+fileName); } for(;;) { fin.getline(buf,100); h=(int) atoi(string(buf).substr(0,4).c_str()); k=(int) atoi(string(buf).substr(4,4).c_str()); l=(int) atoi(string(buf).substr(8,4).c_str()); iobs=(float) atof(string(buf).substr(12,8).c_str()); sigma=(float) atof(string(buf).substr(20,8).c_str()); if((abs(h)+abs(k)+abs(l))==0) break; if(i==mNbRefl) { mNbRefl+=100; mH.resizeAndPreserve(mNbRefl); mK.resizeAndPreserve(mNbRefl); mL.resizeAndPreserve(mNbRefl); mObsIntensity.resizeAndPreserve(mNbRefl); mObsSigma.resizeAndPreserve(mNbRefl); } mH(i)=REAL(h); mK(i)=REAL(k); mL(i)=REAL(l); mObsIntensity(i)=REAL(iobs); mObsSigma(i)=REAL(sigma); i++; } VFN_DEBUG_MESSAGE("Finished reading from file (HKLF4) ",10); fin.close(); } //Finish mNbRefl=i; mH.resizeAndPreserve(mNbRefl); mK.resizeAndPreserve(mNbRefl); mL.resizeAndPreserve(mNbRefl); mObsIntensity.resizeAndPreserve(mNbRefl); mObsSigma.resizeAndPreserve(mNbRefl); mWeight.resize(mNbRefl); this->SetWeightToInvSigma2(1e-4,0); mHasObservedData=true; mMultiplicity.resize(mNbRefl); mMultiplicity=1; // Keep a copy as squared F(hkl), to enable fourier maps // :TODO: stop using mObsIntensity and just keep mFhklObsSq ? mFhklObsSq=mObsIntensity; mClockFhklObsSq.Click(); this->PrepareHKLarrays(); this->SortReflectionBySinThetaOverLambda(); { char buf [200]; sprintf(buf,"Imported Shelx HKLF 4 file, with %d reflections",(int)mNbRefl); (*fpObjCrystInformUser)((string)buf); } VFN_DEBUG_EXIT("DiffractionDataSingleCrystal::ImportShelxHKLF4() read "<<mNbRefl<<" reflections",10); }