FOX/ObjCryst++  2022
Indexing.h
1 /* ObjCryst++ Object-Oriented Crystallographic Library
2  (c) 2006- Vincent Favre-Nicolin vincefn@users.sourceforge.net
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 /*
19 * source file for Indexing classes & functions
20 *
21 */
22 #ifndef _OBJCRYST_INDEXING_H_
23 #define _OBJCRYST_INDEXING_H_
24 
25 #include <math.h>
26 #include <fstream>
27 #include <iostream>
28 #include <vector>
29 #include <list>
30 #include <time.h>
31 #include "ObjCryst/RefinableObj/RefinableObj.h"
32 #include "ObjCryst/RefinableObj/LSQNumObj.h"
33 #include "ObjCryst/ObjCryst/PowderPattern.h"
34 namespace ObjCryst
35 {
40 { TRICLINIC, MONOCLINIC, ORTHORHOMBIC, HEXAGONAL, RHOMBOEDRAL, TETRAGONAL, CUBIC,
41 ORTHOROMBIC=ORTHORHOMBIC // Fix historical typo for backwards compatibility
42 };
43 
44 enum CrystalCentering
45 { LATTICE_P,LATTICE_I,LATTICE_A,LATTICE_B,LATTICE_C,LATTICE_F};
46 
54 float EstimateCellVolume(const float dmin, const float dmax, const float nbrefl,
55  const CrystalSystem system,const CrystalCentering centering,const float kappa=1);
56 
62 {
63  public:
64  RecUnitCell(const float zero=0,const float par0=0,const float par1=0,const float par2=0,
65  const float par3=0,const float par4=0,const float par5=0,CrystalSystem lattice=CUBIC,
66  const CrystalCentering cent=LATTICE_P, const unsigned int nbspurious=0);
67  RecUnitCell(const RecUnitCell &old);
68  void operator=(const RecUnitCell &rhs);
69  // access to ith parameter
70  //float operator[](const unsigned int i);
75  float hkl2d(const float h,const float k,const float l,REAL *derivpar=NULL,const unsigned int derivhkl=0) const;
81  void hkl2d_delta(const float h,const float k,const float l,const RecUnitCell &delta, float & dmin, float &dmax) const;
88  std::vector<float> DirectUnitCell(const bool equiv=false)const;
107  REAL par[7];
108  CrystalSystem mlattice;
109  CrystalCentering mCentering;
111  unsigned int mNbSpurious;
112 };
113 
118 class PeakList
119 {
120  public:
121  PeakList();
122  PeakList(const PeakList &old);
123  void operator=(const PeakList &rhs);
124  ~PeakList();
125  void ImportDhklDSigmaIntensity(std::istream &is,float defaultsigma=.001);
126  void ImportDhklIntensity(std::istream &is);
127  void ImportDhkl(std::istream &is);
128  void Import2ThetaIntensity(std::istream &is, const float wavelength=1.5418);
146  float Simulate(float zero, float a, float b, float c,
147  float alpha, float beta, float gamma,
148  bool deg, unsigned int nb=20, unsigned int nbspurious=0,
149  float sigma=0, float percentMissing=0, const bool verbose=false,
150  const bool merge=false);
151  void ExportDhklDSigmaIntensity(std::ostream &out)const;
154  void AddPeak(const float d, const float iobs=1.0,const float dobssigma=0.0,const float iobssigma=0.0,
155  const int h=0,const int k=0, const int l=0,const float d2calc=0);
156  void RemovePeak(unsigned int i);
157  void Print(std::ostream &os) const;
159  struct hkl0
160  {
161  hkl0(const int h=0,const int k=0, const int l=0);
163  int h,k,l;
164  };
168  struct hkl
169  {
170  hkl(const float dobs=1.0,const float iobs=0.0,const float dobssigma=0.0,const float iobssigma=0.0,
171  const int h=0,const int k=0, const int l=0,const float d2calc=0);
173  float dobs;
175  float dobssigma;
177  float d2obs;
179  float d2obsmin;
181  float d2obsmax;
183  float iobs;
185  float iobssigma;
187  mutable int h,k,l;
189  mutable std::list<hkl0> vDicVolHKL;
191  mutable bool isIndexed;
193  mutable bool isSpurious;
195  mutable unsigned long stats;
197  mutable float d2calc;
199  mutable float d2diff;
200  };
202  vector<hkl> & GetPeakList();
204  const vector<hkl> & GetPeakList()const ;
208  mutable vector<hkl>mvHKL;
211  mutable list<hkl> mvPredictedHKL;
212 };
213 
215 float Score(const PeakList &dhkl, const RecUnitCell &ruc, const unsigned int nbSpurious=0,
216  const bool verbose=false,const bool storehkl=false,
217  const bool storePredictedHKL=false);
218 
223 {
224  public:
225  CellExplorer(const PeakList &dhkl, const CrystalSystem lattice, const unsigned int nbSpurious);
226  void Evolution(unsigned int ng,const bool randomize=true,const float f=0.7,const float cr=0.5,unsigned int np=100);
227  void SetLengthMinMax(const float min,const float max);
228  void SetAngleMinMax(const float min,const float max);
229  void SetVolumeMinMax(const float min,const float max);
230  void SetNbSpurious(const unsigned int nb);
232  void SetD2Error(const float err);
233  void SetMinMaxZeroShift(const float min,const float max);
234  void SetCrystalSystem(const CrystalSystem system);
235  void SetCrystalCentering(const CrystalCentering cent);
236  virtual const string& GetClassName() const;
237  virtual const string& GetName() const;
238  virtual void Print() const;
239  virtual unsigned int GetNbLSQFunction() const;
240  virtual const CrystVector_REAL& GetLSQCalc(const unsigned int) const;
241  virtual const CrystVector_REAL & GetLSQObs(const unsigned int) const;
242  virtual const CrystVector_REAL & GetLSQWeight(const unsigned int) const;
243  virtual const CrystVector_REAL & GetLSQDeriv(const unsigned int, RefinablePar &);
244  virtual void BeginOptimization(const bool allowApproximations=false, const bool enableRestraints=false);
245  void LSQRefine(int nbCycle=1, bool useLevenbergMarquardt=true, const bool silent=false);
251  void DicVol(const float minScore=10,const unsigned int minDepth=3,const float stopOnScore=50.0,const unsigned int stopOnDepth=6);
257  void ReduceSolutions(const bool updateReportThreshold=false);
258  float GetBestScore()const;
259  const std::list<std::pair<RecUnitCell,float> >& GetSolutions()const;
260  std::list<std::pair<RecUnitCell,float> >& GetSolutions();
261  private:
262  unsigned int RDicVol(RecUnitCell uc0, RecUnitCell uc1, unsigned int depth,unsigned long &nbCalc,const float minV,const float maxV,vector<unsigned int> vdepth=vector<unsigned int>());
263  void Init();
265  std::list<std::pair<RecUnitCell,float> > mvSolution;
266  unsigned int mnpar;
267  const PeakList *mpPeakList;
268  float mLengthMin,mLengthMax;
269  float mAngleMin,mAngleMax;
270  float mVolumeMin,mVolumeMax;
271  float mZeroShiftMin,mZeroShiftMax;
273  float mMin[7];
276  float mAmp[7];
280  CrystalCentering mCentering;
281  unsigned int mNbSpurious;
282  float mD2Error;
283  LSQNumObj mLSQObj;
284  mutable CrystVector_REAL mObs;
285  mutable CrystVector_REAL mCalc;
286  mutable CrystVector_REAL mWeight;
287  mutable CrystVector_REAL mDeriv;
291  float mBestScore;
293  std::vector<unsigned int> mvNbSolutionDepth;
294  float mMinScoreReport;
295  unsigned int mMaxDicVolDepth,mDicVolDepthReport;
298  mutable float mCosAngMax;
300  unsigned int mNbLSQExcept;
301 };
302 
303 
304 }//namespace
305 #endif
The namespace which includes all objects (crystallographic and algorithmic) in ObjCryst++.
Definition: doc-main.h:25
float EstimateCellVolume(const float dmin, const float dmax, const float nbrefl, const CrystalSystem system, const CrystalCentering centering, const float kappa)
Estimate volume from number of peaks at a given dmin See J.
Definition: Indexing.cpp:46
float Score(const PeakList &dhkl, const RecUnitCell &rpar, const unsigned int nbSpurious, const bool verbose, const bool storehkl, const bool storePredictedHKL)
Compute score for a candidate RecUnitCell and a PeakList.
Definition: Indexing.cpp:948
CrystalSystem
Different lattice types.
Definition: Indexing.h:40
Lightweight class describing the reciprocal unit cell, for the fast computation of d*_hkl^2.
Definition: Indexing.h:62
void hkl2d_delta(const float h, const float k, const float l, const RecUnitCell &delta, float &dmin, float &dmax) const
Compute d*^2 for one hkl reflection: this functions computes a d*^2 range (min,max) for a given range...
Definition: Indexing.cpp:456
unsigned int mNbSpurious
The number of spurious lines used to match this RecUnitCell.
Definition: Indexing.h:111
REAL par[7]
The 6 parameters defining 1/d_hkl^2 = d*_hkl^2, for different crystal classes, from: d*_hkl^2 = zero ...
Definition: Indexing.h:107
float hkl2d(const float h, const float k, const float l, REAL *derivpar=NULL, const unsigned int derivhkl=0) const
Compute d*^2 for hkl reflection if deriv != -1, compute derivate versus the corresponding parameter.
Definition: Indexing.cpp:108
RecUnitCell(const float zero=0, const float par0=0, const float par1=0, const float par2=0, const float par3=0, const float par4=0, const float par5=0, CrystalSystem lattice=CUBIC, const CrystalCentering cent=LATTICE_P, const unsigned int nbspurious=0)
light-weight class storing the reciprocal space unitcell
Definition: Indexing.cpp:81
std::vector< float > DirectUnitCell(const bool equiv=false) const
Compute real space unit cell from reciprocal one.
Definition: Indexing.cpp:564
Class to store positions of observed reflections.
Definition: Indexing.h:119
float Simulate(float zero, float a, float b, float c, float alpha, float beta, float gamma, bool deg, unsigned int nb=20, unsigned int nbspurious=0, float sigma=0, float percentMissing=0, const bool verbose=false, const bool merge=false)
Generate a list of simulated peak positions, from given lattice parameters.
Definition: Indexing.cpp:807
vector< hkl > & GetPeakList()
Get peak list.
Definition: Indexing.cpp:942
list< hkl > mvPredictedHKL
Full list of calculated HKL positions for a given solution, up to a given resolution After finding a ...
Definition: Indexing.h:211
vector< hkl > mvHKL
Predict peak positions Best h,k,l for each observed peak (for least-squares refinement) This is store...
Definition: Indexing.h:208
void AddPeak(const float d, const float iobs=1.0, const float dobssigma=0.0, const float iobssigma=0.0, const int h=0, const int k=0, const int l=0, const float d2calc=0)
Add one peak.
Definition: Indexing.cpp:898
One set of Miller indices, a possible indexation for a reflection.
Definition: Indexing.h:160
int h
Miller indices.
Definition: Indexing.h:163
One observed diffraction line, to be indexed.
Definition: Indexing.h:169
float d2calc
Calculated position, 1/d^2.
Definition: Indexing.h:197
bool isSpurious
Is this an impurity line ?
Definition: Indexing.h:193
unsigned long stats
Indexing statistics.
Definition: Indexing.h:195
float d2obsmax
Min value for observed peak position 1/(d-disgma/2)^2.
Definition: Indexing.h:181
float dobs
Observed peak position 1/d.
Definition: Indexing.h:173
float d2diff
1/d^2 difference, obs-calc
Definition: Indexing.h:199
float d2obsmin
Min value for observed peak position 1/(d+disgma/2)^2.
Definition: Indexing.h:179
float iobs
Observed peak intensity.
Definition: Indexing.h:183
float dobssigma
Error on peak position.
Definition: Indexing.h:175
std::list< hkl0 > vDicVolHKL
Possible Miller indices, stored during a dichotomy search.
Definition: Indexing.h:189
int h
Miller indices, after line is indexed.
Definition: Indexing.h:187
bool isIndexed
Is this line indexed ?
Definition: Indexing.h:191
float d2obs
Observed peak position 1/d^2.
Definition: Indexing.h:177
float iobssigma
Error on observed peak intensity.
Definition: Indexing.h:185
Algorithm class to find the correct indexing from observed peak positions.
Definition: Indexing.h:223
unsigned int mNbLSQExcept
Number of exceptions caught during LSQ, in a given search - above 20 LSQ is disabled.
Definition: Indexing.h:300
CrystalCentering mCentering
Centering type.
Definition: Indexing.h:280
virtual const CrystVector_REAL & GetLSQObs(const unsigned int) const
Get the observed values for the LSQ function.
Definition: Indexing.cpp:1453
virtual void BeginOptimization(const bool allowApproximations=false, const bool enableRestraints=false)
This should be called by any optimization class at the begining of an optimization.
Definition: Indexing.cpp:1494
float mBestScore
Current best score.
Definition: Indexing.h:291
float mCosAngMax
Stored value of cos(max ang) for tricilinic search - we do not want to recompute the cos at every dic...
Definition: Indexing.h:298
CrystalSystem mlattice
Lattice type for which we search.
Definition: Indexing.h:278
virtual const string & GetClassName() const
Name for this class ("RefinableObj", "Crystal",...).
Definition: Indexing.cpp:1423
virtual const string & GetName() const
Name of the object.
Definition: Indexing.cpp:1428
void SetD2Error(const float err)
Allowed error on 1/d (squared!), used for dicvol.
Definition: Indexing.cpp:1421
virtual const CrystVector_REAL & GetLSQCalc(const unsigned int) const
Get the current calculated value for the LSQ function.
Definition: Indexing.cpp:1440
virtual unsigned int GetNbLSQFunction() const
Number of LSQ functions.
Definition: Indexing.cpp:1437
virtual const CrystVector_REAL & GetLSQWeight(const unsigned int) const
Get the weight values for the LSQ function.
Definition: Indexing.cpp:1458
std::list< std::pair< RecUnitCell, float > > mvSolution
Max number of obs reflections to use.
Definition: Indexing.h:265
float mMin[7]
Min values for all parameters (7=unit cell +zero)
Definition: Indexing.h:273
std::vector< unsigned int > mvNbSolutionDepth
Number of solutions found during dicvol search, at each depth.
Definition: Indexing.h:293
RecUnitCell mRecUnitCell
Reciprocal unit cell used for least squares refinement.
Definition: Indexing.h:289
float mAmp[7]
Max amplitude (max=min+amplitude) for all parameters All parameters are treated as periodic for DE (?...
Definition: Indexing.h:276
void DicVol(const float minScore=10, const unsigned int minDepth=3, const float stopOnScore=50.0, const unsigned int stopOnDepth=6)
Run DicVOl algorithm, store only solutions with score >minScore or depth>=minDepth,...
Definition: Indexing.cpp:2140
void ReduceSolutions(const bool updateReportThreshold=false)
Sort all solutions by score, remove duplicates.
Definition: Indexing.cpp:2643
virtual const CrystVector_REAL & GetLSQDeriv(const unsigned int, RefinablePar &)
Get the first derivative values for the LSQ function, for a given parameter.
Definition: Indexing.cpp:1464
(Quick & dirty) Least-Squares Refinement Object with Numerical derivatives
Definition: LSQNumObj.h:39
Generic class for parameters of refinable objects.
Definition: RefinableObj.h:225
Generic Refinable Object.
Definition: RefinableObj.h:784