FOX/ObjCryst++  1.10.X (development)
1 /* ObjCryst++ Object-Oriented Crystallographic Library
2  (c) 2000-2002 Vincent Favre-Nicolin
3  2000-2001 University of Geneva (Switzerland)
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  GNU General Public License for more details.
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 /* Crystal.h header file for the Crystal object
20 *
21 */
25 #include "ObjCryst/CrystVector/CrystVector.h"
27 #include "ObjCryst/ObjCryst/General.h"
28 #include "ObjCryst/RefinableObj/RefinableObj.h"
29 #include "ObjCryst/ObjCryst/UnitCell.h"
30 #include "ObjCryst/ObjCryst/ScatteringPower.h"
31 #include "ObjCryst/ObjCryst/Scatterer.h"
33 //#include <stdlib.h>
34 #include <string>
35 //#include <iomanip>
36 //#include <cmath>
37 //#include <typeinfo>
38 //#include <fstream>
39 //#include <ctime>
41 namespace ObjCryst
42 {
43 class Scatterer; //forward declaration of another header's class :KLUDGE:
44 extern const RefParType *gpRefParTypeCrystal;
46 {
47  public:
49  {
50  if (mCount++ == 0)
51  {
52  gpRefParTypeCrystal=new RefParType (gpRefParTypeUnitCell,"Crystal");
53  }
54  }
56  {
57  if (--mCount == 0)
58  {
59  delete gpRefParTypeCrystal;
60  gpRefParTypeCrystal=0;
61  }
62  }
63  private:
64  static long mCount;
65 };
66 static NiftyStaticGlobalObjectsInitializer_Crystal NiftyStaticGlobalObjectsInitializer_Crystal_counter;
68 //######################################################################
96 //######################################################################
97 class Crystal:public UnitCell
98 {
99  public:
101  Crystal();
106  Crystal(const REAL a, const REAL b, const REAL c,
107  const string &SpaceGroupId);
113  Crystal(const REAL a, const REAL b, const REAL c, const REAL alpha,
114  const REAL beta, const REAL gamma,const string &SpaceGroupId);
117  Crystal(const Crystal &oldCryst);
119  ~Crystal();
120  virtual const string& GetClassName() const;
133  void AddScatterer(Scatterer *scatt);
135  void RemoveScatterer(Scatterer *scatt, const bool del=true);
138  long GetNbScatterer()const;
143  Scatterer & GetScatt(const string &scattName);
148  const Scatterer & GetScatt(const string &scattName) const;
153  Scatterer & GetScatt(const long scattIndex);
158  const Scatterer & GetScatt(const long scattIndex) const;
171  void AddScatteringPower(ScatteringPower *scattPow);
174  void RemoveScatteringPower(ScatteringPower *scattPow, const bool del=true);
176  ScatteringPower& GetScatteringPower(const string &name);
178  const ScatteringPower& GetScatteringPower(const string &name)const;
191  void Print(ostream &os=cout) const;
208  CrystMatrix_REAL GetMinDistanceTable(const REAL minDistance=0.1) const;
213  void PrintMinDistanceTable(const REAL minDistance=0.1,ostream &os=cout) const;
225  ostream& POVRayDescription(ostream &os,const CrystalPOVRayOptions &options)const;
238  virtual void GLInitDisplayList(const bool onlyIndependentAtoms=false,
239  const REAL xMin=-.1,const REAL xMax=1.1,
240  const REAL yMin=-.1,const REAL yMax=1.1,
241  const REAL zMin=-.1,const REAL zMax=1.1,
242  const bool displayNames=false,
243  const bool hideHydrogens=false)const;
265  void CalcDynPopCorr(const REAL overlapDist=1., const REAL mergeDist=.0)const ;
267  void ResetDynPopCorr()const ;
271  REAL GetDynPopCorr(const Scatterer* pscatt, unsigned int component)const;
284  void SetUseDynPopCorr(const int use);
288  int GetUseDynPopCorr() const;
293  REAL GetBumpMergeCost() const;
297  void SetBumpMergeDistance(const ScatteringPower &scatt1,
298  const ScatteringPower &scatt2, const REAL dist=1.5);
300  void SetBumpMergeDistance(const ScatteringPower &scatt1,
301  const ScatteringPower &scatt2, const REAL dist,
302  const bool allowMerge);
305  void RemoveBumpMergeDistance(const ScatteringPower &scatt1,
306  const ScatteringPower &scatt2);
310  {
311  BumpMergePar();
316  BumpMergePar(const REAL dist, const bool canOverlap=false);
318  REAL mDist2;
321  };
325  typedef std::map<pair<const ScatteringPower*, const ScatteringPower*>,Crystal::BumpMergePar > VBumpMergePar;
326  const VBumpMergePar& GetBumpMergeParList()const;
327  VBumpMergePar& GetBumpMergeParList();
331  virtual void XMLOutput(ostream &os,int indent=0)const;
332  virtual void XMLInput(istream &is,const XMLCrystTag &tag);
333  //virtual void XMLInputOld(istream &is,const IOCrystTag &tag);
335  virtual void GlobalOptRandomMove(const REAL mutationAmplitude,
336  const RefParType *type=gpRefParTypeObjCryst);
337  virtual REAL GetLogLikelihood()const;
346  virtual void CIFOutput(ostream &os, double mindist = 0.5)const;
348  virtual void GetGeneGroup(const RefinableObj &obj,
349  CrystVector_uint & groupIndex,
350  unsigned int &firstGroup) const;
351  virtual void BeginOptimization(const bool allowApproximations=false,
352  const bool enableRestraints=false);
353  void AddBondValenceRo(const ScatteringPower&,const ScatteringPower&,const REAL ro);
354  void RemoveBondValenceRo(const ScatteringPower&,const ScatteringPower&);
358  REAL GetBondValenceCost() const;
359  std::map<pair<const ScatteringPower*,const ScatteringPower*>, REAL>& GetBondValenceRoList();
360  const std::map<pair<const ScatteringPower*,const ScatteringPower*>, REAL>& GetBondValenceRoList()const;
367  void Init(const REAL a, const REAL b, const REAL c, const REAL alpha,
368  const REAL beta, const REAL gamma,const string &SpaceGroupId,
369  const string& name);
374  void SetDeleteSubObjInDestructor(const bool b);
383  void ConnectAtoms(const REAL min_relat_dist=0.4, const REAL max_relat_dist=1.3, const bool warnuser_fail=false);
384  private:
389  void InitOptions();
393  int FindScatterer(const string &scattName)const;
410  void CalcDistTable(const bool fast)const;
415  void CalcBondValenceSum()const;
421  VBumpMergePar mvBumpMergePar;
427  mutable REAL mBumpMergeCost;
433  struct Neighbour
434  {
435  Neighbour(const unsigned long neighbourIndex,const int sym,
436  const REAL dist2);
439  unsigned long mNeighbourIndex;
444  REAL mDist2;
445  };
448  {
450  unsigned long mIndex;
455  std::vector<Crystal::Neighbour> mvNeighbour;
456  };
460  mutable std::vector<NeighbourHood> mvDistTableSq;
464  mutable REAL mDistTableMaxDistance;
478  //Clocks
498  map<pair<const ScatteringPower*,const ScatteringPower*>, REAL> mvBondValenceRo;
506  mutable REAL mBondValenceCost;
511  mutable std::map<long, REAL> mvBondValenceCalc;
512  // Flag indicating whether to delete Scatterers and ScatteringPowers in
513  // the destructor (default true). Modified by
514  // SetDeleteSubObjInDestructor.
515  bool mDeleteSubObjInDestructor;
517  #ifdef __WX__CRYST__
518  public:
519  virtual WXCrystObjBasic* WXCreate(wxWindow*);
520  friend class WXCrystal;
521  #endif
522 };
528 }// namespace
531 #endif //_OBJCRYST_CRYSTAL_H_
RefinableObjClock mBondValenceCalcClock
Last time Bond Valences were calculated.
Definition: Crystal.h:502
const RefinableObjClock & GetMasterClockScatteringPower() const
Get the clock which reports all changes in ScatteringPowers.
Definition: Crystal.cpp:280
void RemoveBumpMergeDistance(const ScatteringPower &scatt1, const ScatteringPower &scatt2)
Remove an Anti-bumping distance between two scattering types.
Definition: Crystal.cpp:879
void RemoveScatterer(Scatterer *scatt, const bool del=true)
Remove a Scatterer. This also deletes the scatterer unless del=false.
Definition: Crystal.cpp:185
RefinableObjClock mClockScattCompList
Definition: Crystal.h:482
void CalcBondValenceSum() const
Calculate all Bond Valences.
Definition: Crystal.cpp:1239
Default Constructor.
Definition: Crystal.cpp:56
void PrintMinDistanceTable(const REAL minDistance=0.1, ostream &os=cout) const
Print the minimum distance table between all scattering centers (atoms) in the crystal.
Definition: Crystal.cpp:428
virtual void GlobalOptRandomMove(const REAL mutationAmplitude, const RefParType *type=gpRefParTypeObjCryst)
Make a random move of the current configuration.
Definition: Crystal.cpp:894
Crystal destructor.
Definition: Crystal.cpp:131
virtual const ScatteringComponentList & GetScatteringComponentList() const
Get the list of all scattering components.
Definition: Crystal.cpp:283
REAL mBondValenceCostScale
Bond Valence cost scale factor.
Definition: Crystal.h:508
void Print(ostream &os=cout) const
Prints some info about the crystal.
Definition: Crystal.cpp:324
We need to record exactly when refinable objects have been modified for the last time (to avoid re-co...
Definition: RefinableObj.h:138
void SetUseDynPopCorr(const int use)
Set the use of dynamical population correction (Crystal::mUseDynPopCorr).
Definition: Crystal.cpp:791
RefinableObjClock mLatticeClock
Clock for lattice paramaters.
Definition: Crystal.h:470
int FindScatterer(const string &scattName) const
Find a scatterer (its index # in mpScatterrer[]) with a given name.
Definition: Crystal.cpp:803
Interatomic distance for a given neighbour.
Definition: Crystal.h:433
RefinableObjClock mBondValenceCostClock
Last time the Bond Valence cost was calculated.
Definition: Crystal.h:504
ObjRegistry< ScatteringPower > mScatteringPowerRegistry
The registry of ScatteringPower for this Crystal.
Definition: Crystal.h:476
ObjRegistry< Scatterer > mScattererRegistry
The registry of scatterers for this UnitCell.
Definition: Crystal.h:418
int GetUseDynPopCorr() const
Get dynamical population correction setting.
Definition: Crystal.cpp:798
REAL GetBumpMergeCost() const
Get the Anti-bumping/pro-Merging cost function.
Definition: Crystal.cpp:820
bool mCanOverlap
Can the two atoms completely overlap ?
Definition: Crystal.h:320
REAL mDist2
The squared antibump interatomic distance.
Definition: Crystal.h:318
virtual REAL GetLogLikelihood() const
Get -log(likelihood) of the current configuration for the object.
Definition: Crystal.cpp:925
void SetBumpMergeDistance(const ScatteringPower &scatt1, const ScatteringPower &scatt2, const REAL dist=1.5)
Set the Anti-bumping distance between two scattering types.
Definition: Crystal.cpp:860
RefinableObjClock mClockDynPopCorr
Definition: Crystal.h:486
const RefinableObjClock & GetClockScattererList() const
When was the list of scatterers last changed ?
Definition: Crystal.cpp:892
RefinableObjClock mClockScattererList
Last time the list of Scatterers was changed.
Definition: Crystal.h:480
void CalcDynPopCorr(const REAL overlapDist=1., const REAL mergeDist=.0) const
Compute the 'Dynamical population correction for all atoms. Atoms which are considered "equivalent" (...
Definition: Crystal.cpp:708
REAL mBumpMergeScale
Bump-merge scale factor.
Definition: Crystal.h:429
RefinableObjClock mMasterClockScatteringPower
master clock recording every change in Scattering Powers
Definition: Crystal.h:488
Generic Refinable Object.
Definition: RefinableObj.h:752
void AddScatterer(Scatterer *scatt)
Add a scatterer to the crystal.
Definition: Crystal.cpp:174
RefinableObjClock mBondValenceParClock
Last Time Bond Valence parameters were changed.
Definition: Crystal.h:500
ScatteringComponentList mScattCompList
The list of all scattering components in the crystal.
Definition: Crystal.h:467
void ResetDynPopCorr() const
Reset Dynamical Population Correction factors (ie set it to 1)
Definition: Crystal.cpp:765
RefinableObjClock mBumpMergeParClock
Last Time Anti-bump parameters were changed.
Definition: Crystal.h:423
ObjRegistry< Crystal > gCrystalRegistry("List of all Crystals")
Global registry for all Crystal objects.
Definition: Crystal.h:525
Abstract base class for all objects in wxCryst.
Definition: wxCryst.h:127
void SetDeleteSubObjInDestructor(const bool b)
Set whether to delete the Scatterers and ScatteringPowers in the destructor.
Definition: Crystal.cpp:1848
REAL mBondValenceCost
Current Bond Valence cost.
Definition: Crystal.h:506
REAL GetBondValenceCost() const
Get the Bond-Valence cost function, which compares the expected valence to the one computed from Bond...
Definition: Crystal.cpp:1205
void RemoveScatteringPower(ScatteringPower *scattPow, const bool del=true)
Remove a ScatteringPower for this Crystal.
Definition: Crystal.cpp:237
std::vector< NeighbourHood > mvDistTableSq
Interatomic distance table for all unique atoms.
Definition: Crystal.h:460
void ConnectAtoms(const REAL min_relat_dist=0.4, const REAL max_relat_dist=1.3, const bool warnuser_fail=false)
Convert as much as possible the crystal's atoms to molecule(s).
Definition: Crystal.cpp:1295
Base class for options.
Definition: RefinableObj.h:550
unsigned long mIndex
Index of the atom in the scattering component list.
Definition: Crystal.h:450
Class to store POV-Ray output options.
Definition: General.h:175
virtual const string & GetClassName() const
Name for this class ("RefinableObj", "Crystal",...).
Definition: Crystal.cpp:168
virtual void XMLInput(istream &is, const XMLCrystTag &tag)
Input From stream.
const RefinableObjClock & GetClockScattCompList() const
Get the list of all scattering components.
Definition: Crystal.cpp:319
REAL mBumpMergeCost
Current bump-merge cost.
Definition: Crystal.h:427
RefObjOpt mUseDynPopCorr
Use Dynamical population correction (ScatteringComponent::mDynPopCorr) during Structure factor calcul...
Definition: Crystal.h:473
wxCryst class for Crystals
Definition: wxCrystal.h:80
virtual void XMLOutput(ostream &os, int indent=0) const
Output to stream in well-formed XML.
ostream & POVRayDescription(ostream &os, const CrystalPOVRayOptions &options) const
XMLOutput POV-Ray Description for this Crystal.
Definition: Crystal.cpp:461
std::vector< Crystal::Neighbour > mvNeighbour
List of neighbours.
Definition: Crystal.h:455
Scatterer & GetScatt(const string &scattName)
Provides an access to the scatterers.
Definition: Crystal.cpp:198
virtual void GetGeneGroup(const RefinableObj &obj, CrystVector_uint &groupIndex, unsigned int &firstGroup) const
Get the gene group assigned to each parameter.
Definition: Crystal.cpp:1141
REAL GetDynPopCorr(const Scatterer *pscatt, unsigned int component) const
Access the Dynamical Occupancy Correction for a given component (atom) in a given Scatterer...
Definition: Crystal.cpp:773
ObjRegistry< Scatterer > & GetScattererRegistry()
Get the registry of scatterers.
Definition: Crystal.cpp:218
CrystMatrix_REAL GetMinDistanceTable(const REAL minDistance=0.1) const
Minimum interatomic distance between all scattering components (atoms) in the crystal.
Definition: Crystal.cpp:387
unsigned int mUniquePosSymmetryIndex
Index of the symmetry operation for the chosen unique position in the (pseudo) asymmetric unit...
Definition: Crystal.h:453
ObjRegistry< ScatteringPower > & GetScatteringPowerRegistry()
Get the registry of ScatteringPower included in this Crystal.
Definition: Crystal.cpp:222
VBumpMergePar mvBumpMergePar
Anti-bump parameters map.
Definition: Crystal.h:421
void CalcDistTable(const bool fast) const
Compute the distance Table (mDistTable) for all scattering components.
Definition: Crystal.cpp:1628
RefObjOpt mDisplayEnantiomer
Display the enantiomeric (mirror along x) structure in 3D? This can be helpful for non-centrosymmetri...
Definition: Crystal.h:493
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: Crystal.cpp:1160
virtual void CIFOutput(ostream &os, double mindist=0.5) const
output Crystal structure as a cif file (EXPERIMENTAL !)
Definition: Crystal.cpp:930
The namespace which includes all objects (crystallographic and algorithmic) in ObjCryst++.
Definition: Atom.cpp:47
virtual void GLInitDisplayList(const bool onlyIndependentAtoms=false, const REAL xMin=-.1, const REAL xMax=1.1, const REAL yMin=-.1, const REAL yMax=1.1, const REAL zMin=-.1, const REAL zMax=1.1, const bool displayNames=false, const bool hideHydrogens=false) const
Create an OpenGL DisplayList of the crystal.
Definition: Crystal.cpp:545
Unit Cell class: Unit cell with spacegroup information.
Definition: UnitCell.h:71
map< pair< const ScatteringPower *, const ScatteringPower * >, REAL > mvBondValenceRo
Map of Bond Valence "Ro" parameters for each couple of ScatteringPower.
Definition: Crystal.h:498
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 Crystal parameters.
Definition: Crystal.cpp:1277
RefinableObjClock mClockNeighborTable
Definition: Crystal.h:484
std::map< long, REAL > mvBondValenceCalc
List of calculated bond valences, as a map, the key being the index of the atom in Crystal::mScattCom...
Definition: Crystal.h:511
Table of neighbours for a given unique atom.
Definition: Crystal.h:447
Crystal class: Unit cell, spacegroup, scatterers.
Definition: Crystal.h:97
unsigned int mNeighbourSymmetryIndex
The symmetry position associated to the neighbour (its index in the Crystal's scattering component li...
Definition: Crystal.h:442
Storage for anti-bump/merge parameters.
Definition: Crystal.h:309
class to input or output a well-formatted xml beginning or ending tag.
RefinableObjClock mDistTableClock
The time when the distance table was last calculated.
Definition: Crystal.h:462
long GetNbScatterer() const
Number of scatterers in the crystal.
Definition: Crystal.cpp:196
unsigned long mNeighbourIndex
The number associated to the neighbour (its index in the Crystal's scattering component list) ...
Definition: Crystal.h:439
ScatteringPower & GetScatteringPower(const string &name)
Find a ScatteringPower from its name. Names must be unique in a given Crystal.
Definition: Crystal.cpp:270
class of refinable parameter types.
Definition: RefinableObj.h:78
list of scattering positions in a crystal, associated with the corresponding occupancy and a pointer ...
REAL mDist2
The squared distance, in square Angstroems.
Definition: Crystal.h:444
Generic type of scatterer: can be an atom, or a more complex assembly of atoms.
Definition: Scatterer.h:130
void AddScatteringPower(ScatteringPower *scattPow)
Add a ScatteringPower for this Crystal.
Definition: Crystal.cpp:227
RefinableObjClock mBumpMergeCostClock
Last Time Anti-bump parameters were changed.
Definition: Crystal.h:425
const RefParType * gpRefParTypeObjCryst
Top RefParType for the ObjCryst++ library.
Object Registry.
Definition: RefinableObj.h:643
REAL mDistTableMaxDistance
The distance up to which the distance table & neighbours needs to be calculated.
Definition: Crystal.h:464
void InitOptions()
Init options.
Definition: Crystal.cpp:1576
std::map< pair< const ScatteringPower *, const ScatteringPower * >, Crystal::BumpMergePar > VBumpMergePar
Anti-bump parameters.
Definition: Crystal.h:325
Abstract Base Class to describe the scattering power of any Scatterer component in a crystal...