FOX/ObjCryst++  1.10.X (development)
DiffractionDataSingleCrystal.h
1 /*
2 * ObjCryst++ : a Crystallographic computing library in C++
3 * http://objcryst.sourceforge.net
4 * http://www.ccp14.ac.uk/ccp/web-mirrors/objcryst/
5 *
6 * (c) 2000-2001 Vincent FAVRE-NICOLIN vincefn@users.sourceforge.net
7 *
8 */
9 /* DiffractionDataSingleCrystal.h header file for single-crystal
10 * diffraction objects.
11 *
12 */
13 #ifndef _OBJCRYST_DIFFDATA_SINGLECRYSTAL_H_
14 #define _OBJCRYST_DIFFDATA_SINGLECRYSTAL_H_
15 
16 #include "ObjCryst/CrystVector/CrystVector.h"
17 
18 #include "ObjCryst/ObjCryst/General.h"
19 
20 #include "ObjCryst/ObjCryst/ScatteringPower.h"
21 #include "ObjCryst/ObjCryst/Crystal.h"
22 #include "ObjCryst/ObjCryst/ScatteringData.h"
23 //#include "ObjCryst/ObjCryst/SpaceGroup.h"
24 //#include "ObjCryst/ObjCryst/Scatterer.h"
25 
26 //#include <stdlib.h>
27 #include <string>
28 //#include <iomanip>
29 //#include <cmath>
30 //#include <typeinfo>
31 //#include <fstream>
32 //#include <ctime>
33 
34 namespace ObjCryst
35 {
36 //######################################################################
37 // DiffractionDataSingleCrystal
48 //######################################################################
49 
51 {
52  public:
61  DiffractionDataSingleCrystal(const bool regist=true);
68  DiffractionDataSingleCrystal(Crystal &cryst,const bool regist=true);
73  virtual const string& GetClassName() const;
74 
81  const CrystVector_REAL& GetIcalc() const;
83  std::map<RefinablePar*, CrystVector_REAL> & GetIcalc_FullDeriv(std::set<RefinablePar *> &vPar);
84 
86  const CrystVector_REAL& GetIobs() const;
88  void SetIobs(const CrystVector_REAL&);
89 
91  const CrystVector_REAL& GetSigma() const;
93  void SetSigma(const CrystVector_REAL&);
94 
96  void SetIobsToIcalc();
97 
99  const CrystVector_REAL& GetWeight() const;
101  void SetWeight(const CrystVector_REAL&);
102 
111  void SetHklIobs(const CrystVector_long &h,
112  const CrystVector_long &k,
113  const CrystVector_long &l,
114  const CrystVector_REAL &iObs,
115  const CrystVector_REAL &sigma);
116 
125  void ImportHklIobs(const string &fileName,const long nbRefl,const int skipLines=0);
134  void ImportHklIobsSigma(const string &fileName,const long nbRefl,const int skipLines=0);
142  void ImportShelxHKLF4(const string &fileName);
148  void ImportCIF(const string &fileName);
154  void ImportHklIobsSigmaJanaM91(const string &fileName);
170  void ImportHklIobsGroup(const string &fileName,const unsigned int skipLines=0);
171 
177  virtual REAL GetRw()const;
183  virtual REAL GetR()const;
184 
190  // \return \f$ \chi^2 = \sum_i \left( \frac{ y_i^{obs}-y_i^{calc}}{\sigma_i} \right)^2
191  virtual REAL GetChi2()const;
192 
193  /* \brief Return Goodness of Fit
194  *
195  * \return \f$ GoF = \frac{\sum_i w_i\left( y_i^{obs}-y_i^{calc} \right)^2}
196  * {N_{obs}-N_{indep.par}} \f$
197  virtual REAL GoF()const;
198  */
199 
204  virtual void FitScaleFactorForRw() const;
209  virtual void FitScaleFactorForR() const;
212  virtual REAL GetBestRFactor() const;
213 
217  virtual void SetSigmaToSqrtIobs();
226  virtual void SetWeightToInvSigma2(const REAL minRelatSigma=1e-4, const REAL minIobsSigmaRatio=0);
227 
229  REAL GetScaleFactor()const;
230  // Set the Scale factor (applied to Icalc to match Iobs)
231  //void SetScaleFactor(const REAL);
232 
236  virtual void PrintObsData()const;
241  virtual void PrintObsCalcData()const;
242 
243  virtual void SetUseOnlyLowAngleData(const bool useOnlyLowAngle,const REAL angle=0.);
244 
247  void SaveHKLIobsIcalc(const string &filename="hklIobsIcalc.out");
248  virtual void GlobalOptRandomMove(const REAL mutationAmplitude,
249  const RefParType *type=gpRefParTypeObjCryst);
250  virtual REAL GetLogLikelihood()const;
251  //LSQ functions
252  virtual unsigned int GetNbLSQFunction()const;
253  virtual const CrystVector_REAL& GetLSQCalc(const unsigned int) const;
254  virtual const CrystVector_REAL& GetLSQObs(const unsigned int) const;
255  virtual const CrystVector_REAL& GetLSQWeight(const unsigned int) const;
256  virtual std::map<RefinablePar*, CrystVector_REAL> & GetLSQ_FullDeriv(const unsigned int,std::set<RefinablePar *> &vPar);
257  virtual void XMLOutput(ostream &os,int indent=0)const;
258  virtual void XMLInput(istream &is,const XMLCrystTag &tag);
259  //virtual void XMLInputOld(istream &is,const IOCrystTag &tag);
260  virtual const Radiation& GetRadiation()const;
263  virtual void SetRadiationType(const RadiationType radiation);
265  void SetWavelength(const REAL );
284  void SetWavelength(const string &XRayTubeElementName,const REAL alpha2Alpha2ratio=0.5);
286  void SetEnergy(const REAL );
287 
288  protected:
289  private:
290  virtual void InitRefParList();
292  void CalcIcalc() const;
293  void CalcIcalc_FullDeriv(std::set<RefinablePar *> &vPar);
294  virtual CrystVector_long SortReflectionBySinThetaOverLambda(const REAL maxTheta=-1.);
296  void InitOptions();
299  void PrepareTwinningCalc() const;
302 
308  CrystVector_REAL mObsIntensity ;
310  CrystVector_REAL mObsSigma ;
312  CrystVector_REAL mWeight ;
314  mutable CrystVector_REAL mCalcIntensity ;
316  mutable std::map<RefinablePar*, CrystVector_REAL> mCalcIntensity_FullDeriv;
319  mutable REAL mScaleFactor;
321  mutable REAL mChi2;
322  //Clocks
329  // Grouped reflections
334  mutable CrystVector_REAL mGroupIobs;
336  mutable CrystVector_REAL mGroupSigma;
338  mutable CrystVector_REAL mGroupIcalc;
339  mutable std::map<RefinablePar*, CrystVector_REAL> mGroupIcalc_FullDeriv;
342  mutable CrystVector_REAL mGroupWeight;
356  mutable CrystVector_long mGroupIndex;
358  mutable long mNbGroup;
360  mutable long mNbGroupUsed;
363 
364  // The Radiation for this object
365  Radiation mRadiation;
366  #ifdef __WX__CRYST__
367  public:
368  virtual WXCrystObjBasic* WXCreate(wxWindow*);
369  friend class WXDiffractionSingleCrystal;//to access the Radiation object
370 
371  #endif
372 };
375 
376 } //namespace ObjCryst
377 
378 #endif //_OBJCRYST_DIFFDATA_SINGLECRYSTAL_H_
virtual const string & GetClassName() const
Name for this class ("RefinableObj", "Crystal",...).
virtual REAL GetLogLikelihood() const
Get -log(likelihood) of the current configuration for the object.
const CrystVector_REAL & GetIcalc() const
returns the calculated diffracted intensity.
void ImportHklIobsSigmaJanaM91(const string &fileName)
Import h,k,l,I,Sigma from a Jana98 '*.m91' file.
const CrystVector_REAL & GetIobs() const
Return the array of observed intensities for all peaks.
RefObjOpt mGroupOption
Option for the type of grouping (0:no, 1:by theta values (twinning), 2:user-supplied groups) ...
const CrystVector_REAL & GetWeight() const
Return the weights (for each reflection) used for computing Rw.
We need to record exactly when refinable objects have been modified for the last time (to avoid re-co...
Definition: RefinableObj.h:138
virtual void PrintObsData() const
Print H, K, L Iobs sigma for all reflections.
REAL GetScaleFactor() const
Scale factor (applied to Icalc to match Iobs)
virtual const Radiation & GetRadiation() const
Get the radiation object for this data.
virtual void XMLInput(istream &is, const XMLCrystTag &tag)
Input From stream.
virtual void SetSigmaToSqrtIobs()
Set sigma for all observed intensities to sqrt(obs)
virtual void FitScaleFactorForRw() const
Compute the best scale factor minimising Rw.
void ImportHklIobs(const string &fileName, const long nbRefl, const int skipLines=0)
Import h,k,l,I from a file.
void SetIobs(const CrystVector_REAL &)
Return the array of observed intensities for all peaks.
virtual CrystVector_long SortReflectionBySinThetaOverLambda(const REAL maxTheta=-1.)
void SetWeight(const CrystVector_REAL &)
Change the weights (for each reflection) used for computing Rw.
CrystVector_REAL mGroupIcalc
The calculated intensities summed on all reflections that are grouped.
RefinableObjClock mClockScaleFactor
Last modification of the scale factor.
CrystVector_long mGroupIndex
The index of reflections which need to be summed.
virtual const CrystVector_REAL & GetLSQObs(const unsigned int) const
Get the observed values for the LSQ function.
virtual const CrystVector_REAL & GetLSQCalc(const unsigned int) const
Get the current calculated value for the LSQ function.
virtual unsigned int GetNbLSQFunction() const
Number of LSQ functions.
Class to compute structure factors for a set of reflections and a Crystal.
Abstract base class for all objects in wxCryst.
Definition: wxCryst.h:127
CrystVector_REAL mObsSigma
Sigma for observed intensities (either individual reflections or spectrum)
ObjRegistry< DiffractionDataSingleCrystal > gDiffractionDataSingleCrystalRegistry("Global DiffractionDataSingleCrystal Registry")
Global registry for all PowderPattern objects.
virtual void GlobalOptRandomMove(const REAL mutationAmplitude, const RefParType *type=gpRefParTypeObjCryst)
Make a random move of the current configuration.
CrystVector_REAL mGroupWeight
The weight on each reflection sum in case of grouped reflections.
Base class for options.
Definition: RefinableObj.h:550
virtual void SetRadiationType(const RadiationType radiation)
Set : neutron or x-ray experiment ? Wavelength ?
virtual const CrystVector_REAL & GetLSQWeight(const unsigned int) const
Get the weight values for the LSQ function.
DiffractionData object for Single Crystal analysis.
DiffractionDataSingleCrystal(const bool regist=true)
Default constructor.
CrystVector_REAL mCalcIntensity
Calculated intensities.
void SetHklIobs(const CrystVector_long &h, const CrystVector_long &k, const CrystVector_long &l, const CrystVector_REAL &iObs, const CrystVector_REAL &sigma)
input H,K,L, Iobs and Sigma
virtual void FitScaleFactorForR() const
Compute the best scale factor minimising R.
void SaveHKLIobsIcalc(const string &filename="hklIobsIcalc.out")
Save H,K,L Iobs Icalc to a file, text format, 3 columns theta Iobs Icalc.
void SetEnergy(const REAL)
Set the (monochromatic) energy of the beam.
virtual std::map< RefinablePar *, CrystVector_REAL > & GetLSQ_FullDeriv(const unsigned int, std::set< RefinablePar * > &vPar)
Get the first derivative for the LSQ function for each parameter supplied in a list.
void PrepareTwinningCalc() const
Determine the index of reflections to be summed because of twinning (GroupOption==1) The reflections ...
CrystVector_REAL mGroupIobs
The observed intensities summed on all reflections that are (or could be) overlapped dur to a twinnin...
WX Class for DiffractionDataSingleCrystal objects.
void ImportShelxHKLF4(const string &fileName)
Import h,k,l,I,Sigma from a file using shelx HKLF 4 format.
CrystVector_REAL mGroupSigma
The uncertainty on observed grouped intensities.
const CrystVector_REAL & GetSigma() const
Return the array of sigmas for observed intensities, for all peaks.
void ImportHklIobsGroup(const string &fileName, const unsigned int skipLines=0)
Import h,k,l and grouped intensities from a file.
virtual REAL GetR() const
Return the Crystal R-factor (unweighted)
virtual void SetWeightToInvSigma2(const REAL minRelatSigma=1e-4, const REAL minIobsSigmaRatio=0)
Set the weight for all observed intensities to 1/sigma^2.
virtual REAL GetBestRFactor() const
Compute the best scale factor to minimize R, apply this scale factor and return the R value obtained...
RefinableObjClock mClockIcalc
Last time Icalc was computed.
The namespace which includes all objects (crystallographic and algorithmic) in ObjCryst++.
Definition: Atom.cpp:47
CrystVector_REAL mObsIntensity
Observed intensity (after ABS and LP corrections)
RefinableObjClock mClockChi2
Clock the last time Chi^2 was computed.
void SetSigma(const CrystVector_REAL &)
Return the array of sigmas for observed intensities, for all peaks.
RadiationType
Type of radiation used.
Definition: General.h:94
void ImportHklIobsSigma(const string &fileName, const long nbRefl, const int skipLines=0)
Import h,k,l,I,Sigma from a file.
void SetIobsToIcalc()
Set Iobs to current values of Icalc. Mostly used for tests.
CrystVector_REAL mWeight
weight for computing R-Factor, for each observed value.
Crystal class: Unit cell, spacegroup, scatterers.
Definition: Crystal.h:97
void InitOptions()
Init options (currently only twinning).
RefinableObjClock mClockPrepareTwinningCorr
Clock for twinning, when the preparation of twinning correction was last made.
virtual REAL GetRw() const
Return the Crystal R-factor (weighted)
class to input or output a well-formatted xml beginning or ending tag.
virtual void XMLOutput(ostream &os, int indent=0) const
Output to stream in well-formed XML.
class of refinable parameter types.
Definition: RefinableObj.h:78
bool mHasObservedData
Are there observed intensities ?
Class to define the radiation (type, monochromaticity, wavelength(s)) of an experiment.
virtual DiffractionDataSingleCrystal * CreateCopy() const
So-called virtual copy constructor.
const RefParType * gpRefParTypeObjCryst
Top RefParType for the ObjCryst++ library.
Object Registry.
Definition: RefinableObj.h:643
virtual void PrintObsCalcData() const
Print H, K, L Iobs sigma Icalc for all reflections Iobs and sigma (if given) are scaled to Icalc (if ...
std::map< RefinablePar *, CrystVector_REAL > & GetIcalc_FullDeriv(std::set< RefinablePar * > &vPar)
virtual REAL GetChi2() const
Return conventionnal Chi^2.
long mNbGroupUsed
Number of groups below max[sin(theta)/lambda].
void ImportCIF(const string &fileName)
Import diffraction data from a CIF file.
void SetWavelength(const REAL)
Set the (monochromatic) wavelength of the beam.