FOX/ObjCryst++  1.10.X (development)
ScatteringPowerSphere.cpp
1 /* ObjCryst++ Object-Oriented Crystallographic Library
2  (c) 2000-2002 Vincent Favre-Nicolin vincefn@users.sourceforge.net
3  2000-2001 University of Geneva (Switzerland)
4 
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; version 2 of the License.
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 /* ScatteringPowerSphere.cpp
19 * source file for the spherical scattering power
20 *
21 */
22 
23 #include <cmath>
24 #include <cstdlib>
25 
26 #include "ObjCryst/ObjCryst/ScatteringPowerSphere.h"
27 #include "ObjCryst/Quirks/VFNStreamFormat.h"
28 
29 #ifdef __WX__CRYST__
30 #include "ObjCryst/wxCryst/wxScatteringPowerSphere.h"
31 #endif
32 
33 namespace ObjCryst
34 {
36 //
37 // ScatteringPowerSphere
38 //
40 
42 {
43  cout<<"Creating scattering power for fullerene"<<endl;
44  this->Init("C60",3.56,1.0);
45 }
46 
48  const REAL radius,
49  const REAL bIso)
50 {
51  this->Init(name,radius,bIso);
52 }
53 
55 {}
56 
57 ScatteringPowerSphere::~ScatteringPowerSphere()
58 {
59 }
60 
61 // Disable the base-class function.
63 {
64  // This should be never called.
65  abort();
66 }
67 
68 void ScatteringPowerSphere::Init(const string &name,
69  const REAL radius,
70  const REAL bIso)
71 {
72  this->SetName(name);
73  mRadius=radius;
74  mColourRGB[0]=0.2;
75  mColourRGB[1]=0.2;
76  mColourRGB[2]=0.2;
77  if(this->GetNbPar()==0) this->InitRefParList();
78 }
79 
81 {
82  const static string className="ScatteringPowerSphere";
83  return className;
84 }
85 
87  const int spgSymPosIndex) const
88 {
89 
90  CrystVector_REAL sf;
91  #if 0
92  // :TODO: Support anisotropic form factor. For the moment use only mAxisLengthX
93  REAL a,b,c;
94  CrystMatrix_REAL phiMatrix(3,3),chiMatrix(3,3),psiMatrix(3,3);
95  phiMatrix= cos(mPhi) , -sin(mPhi) , 0,
96  sin(mPhi) , cos(mPhi) , 0,
97  0 ,0 ,1;
98 
99  chiMatrix= cos(mChi) ,0 ,-sin(mChi),
100  0 ,1 ,0,
101  sin(mChi) ,0 ,cos(mChi);
102 
103  psiMatrix= 1 , 0 , 0,
104  0 ,cos(mPsi) ,-sin(mPsi),
105  0 ,sin(mPsi) ,cos(mPsi);
106 
107  CrystMatrix_REAL phiChiPsiMatrix=product(chiMatrix,product(phiMatrix,psiMatrix));
108 
109  a=phiChiPsiMatrix(0,0)*mAxisLengthX+phiChiPsiMatrix(0,1)*mAxisLengthY+phiChiPsiMatrix(0,2)*mAxisLengthZ;
110  b=phiChiPsiMatrix(1,0)*mAxisLengthX+phiChiPsiMatrix(1,1)*mAxisLengthY+phiChiPsiMatrix(1,2)*mAxisLengthZ;
111  c=phiChiPsiMatrix(2,0)*mAxisLengthX+phiChiPsiMatrix(2,1)*mAxisLengthY+phiChiPsiMatrix(2,2)*mAxisLengthZ;
112  const REAL *pX=data.GetReflX().data();
113  const REAL *pY=data.GetReflY().data();
114  const REAL *pZ=data.GetReflZ().data();
115  sf.resize(data.GetNbRefl());
116  REAL *pSF=sf.data();
117  for(long i=0;i<data.GetNbReflBelowMaxSinThetaOvLambda();i++)
118  *pSF++ = 2*M_PI * ( *pX++ * a + *pY++ * b + *pZ++ * c );
119  pSF=sf.data();
120  for(long i=0;i<data.GetNbReflBelowMaxSinThetaOvLambda();i++)
121  {
122  *pSF = sin(*pSF) / *pSF;
123  *pSF++;
124  }
125  #else
126  sf=data.GetSinThetaOverLambda();
127  sf *= 2*M_PI*mRadius;
128  REAL *pSF=sf.data();
129  for(long i=0;i<data.GetNbReflBelowMaxSinThetaOvLambda();i++)
130  {
131  *pSF = sin(*pSF) / *pSF;
132  pSF++;
133  }
134  #endif
135  return sf;
136 }
137 
139 {
140  return 1;
141 }
142 
144  const int spgSymPosIndex) const
145 {
146  VFN_DEBUG_MESSAGE("ScatteringPowerSphere::GetTemperatureFactor(&data):"<<mName,3)
147  CrystVector_REAL sf(data.GetNbRefl());
148  CrystVector_REAL stolsq(data.GetNbRefl());
149  const CrystVector_REAL stol=data.GetSinThetaOverLambda();
150  stolsq=stol;
151  stolsq*=stol;
152 
153  #ifdef __VFN_VECTOR_USE_BLITZ__
154  #define SF sf
155  #define STOLSQ stolsq
156  #else
157  #define SF (*ssf)
158  #define STOLSQ (*sstolsq)
159 
160  REAL *ssf=sf.data();
161  const REAL *sstolsq=stolsq.data();
162 
163  for(long ii=0;ii<sf.numElements();ii++)
164  {
165  #endif
166 
167  SF=exp(-mBiso*STOLSQ);
168 
169  #ifdef __VFN_VECTOR_USE_BLITZ__
170 
171  #else
172  ssf++;
173  sstolsq++;
174  }
175  #endif
176 
177  #undef SF
178  #undef STOLSQ
179  return sf;
180 }
181 
183  const int spgSymPosIndex) const
184 {
185  CrystMatrix_REAL fprime(1,1);//:TODO: more than one lambda
186  fprime=0;
187  return fprime;
188 }
189 
191  const int spgSymPosIndex) const
192 {
193  CrystMatrix_REAL fsecond(1,1);//:TODO: more than one lambda
194  fsecond=0;
195  return fsecond;
196 }
197 
199 
200 void ScatteringPowerSphere::Print()const
201 {
202 
203 }
204 
205 void ScatteringPowerSphere::XMLOutput(ostream &os,int indent)const
206 {
207  VFN_DEBUG_ENTRY("ScatteringPowerSphere::XMLOutput():"<<this->GetName(),5)
208  for(int i=0;i<indent;i++) os << " " ;
209  XMLCrystTag tag("ScatteringPowerSphere");
210  tag.AddAttribute("Name",mName);
211  os <<tag<<endl;
212 
213  for(int i=0;i<=indent;i++) os << " " ;
214  this->GetPar(&mRadius).XMLOutput(os,"Radius",0);
215  os<<endl;
216 
217  for(int i=0;i<=indent;i++) os << " " ;
218  this->GetPar(&mBiso).XMLOutput(os,"Biso",0);
219  os<<endl;
220 
221  for(int i=0;i<=indent;i++) os << " " ;
222  XMLCrystTag tag2("RGBColour");
223  os << tag2
224  << mColourRGB[0]<<" "
225  << mColourRGB[1]<<" "
226  << mColourRGB[2];
227  tag2.SetIsEndTag(true);
228  os << tag2<<endl;
229 
230  tag.SetIsEndTag(true);
231  for(int i=0;i<indent;i++) os << " " ;
232  os <<tag<<endl;
233  VFN_DEBUG_EXIT("ScatteringPowerSphere::XMLOutput():"<<this->GetName(),5)
234 }
235 
236 void ScatteringPowerSphere::XMLInput(istream &is,const XMLCrystTag &tagg)
237 {
238  VFN_DEBUG_ENTRY("ScatteringPowerSphere::XMLInput():"<<this->GetName(),5)
239  string symbol;
240  for(unsigned int i=0;i<tagg.GetNbAttribute();i++)
241  {
242  if("Name"==tagg.GetAttributeName(i)) this->SetName(tagg.GetAttributeValue(i));
243  if("Symbol"==tagg.GetAttributeName(i)) symbol=tagg.GetAttributeValue(i);
244  }
245  this->Init(mName,3.56,1.0);
246  while(true)
247  {
248  XMLCrystTag tag(is);
249  if(("ScatteringPowerSphere"==tag.GetName())&&tag.IsEndTag())
250  {
251  VFN_DEBUG_EXIT("ScatteringPowerSphere::Exit():"<<this->GetName(),5)
252  return;
253  }
254  if("RGBColour"==tag.GetName())
255  {
256  float r,g,b;
257  is>>r>>g>>b;
258  this->SetColour(r,g,b);
259  XMLCrystTag junk(is);
260  }
261  if("Par"==tag.GetName())
262  {
263  for(unsigned int i=0;i<tag.GetNbAttribute();i++)
264  {
265  if("Name"==tag.GetAttributeName(i))
266  { cout <<tag<<endl;
267  if("Radius"==tag.GetAttributeValue(i)) this->GetPar(&mRadius).XMLInput(is,tag);
268  if("Biso"==tag.GetAttributeValue(i)) this->GetPar(&mBiso).XMLInput(is,tag);
269  break;
270  }
271  }
272  continue;
273  }
274  }
275 }
276 void ScatteringPowerSphere::InitRefParList()
277 {
278  {
279  RefinablePar tmp("Radius",&mRadius,3.,5.,
280  gpRefParTypeScattPow,REFPAR_DERIV_STEP_RELATIVE,
281  true,true,true,false);
282  tmp.SetDerivStep(1e-3);
283  tmp.SetGlobalOptimStep(.1);
284  tmp.AssignClock(mClock);
285  this->AddPar(tmp);
286  }
287  {
288  RefinablePar tmp("Biso",&mBiso,0.1,5.,
289  gpRefParTypeScattPowTemperatureIso,REFPAR_DERIV_STEP_ABSOLUTE,
290  true,true,true,false);
291  tmp.SetDerivStep(1e-3);
292  tmp.SetGlobalOptimStep(.5);
293  tmp.AssignClock(mClock);
294  this->AddPar(tmp);
295  }
296 }
297 
298 #ifdef __WX__CRYST__
299 
300 WXCrystObjBasic* ScatteringPowerSphere::WXCreate(wxWindow* parent)
301 {
302  //:TODO: Check mpWXCrystObj==0
303  mpWXCrystObj=new WXScatteringPowerSphere(parent,this);
304  return mpWXCrystObj;
305 }
306 #endif
307 
308 
309 }//namespace
virtual void XMLOutput(ostream &os, int indent=0) const
Output to stream in well-formed XML.
virtual long GetNbReflBelowMaxSinThetaOvLambda() const
Recalc, and get the number of reflections which should be actually used, due to the maximuml sin(thet...
void AddPar(const RefinablePar &newRefPar)
Add a refinable parameter.
void SetColour(const string &colorName)
Set the colour from the associated POV-Ray name.
const CrystVector_REAL & GetSinThetaOverLambda() const
Return an array with for all reflections.
virtual const string & GetClassName() const
Name for this class ("RefinableObj", "Crystal",...).
virtual CrystVector_REAL GetTemperatureFactor(const ScatteringData &data, const int spgSymPosIndex=0) const
Get the temperature factor for all reflections of a given ScatteringData object.
long GetNbPar() const
Total number of refinable parameter in the object.
void XMLInput(istream &is, const XMLCrystTag &tag)
XMLInput From stream.
RefinablePar & GetPar(const long i)
Access all parameters in the order they were inputted.
virtual CrystMatrix_REAL GetResonantScattFactImag(const ScatteringData &data, const int spgSymPosIndex=0) const
Get the imaginary part of the resonant scattering factor.
Class to compute structure factors for a set of reflections and a Crystal.
ScatteringPowerSphere()
Default constructor.
virtual CrystVector_REAL GetScatteringFactor(const ScatteringData &data, const int spgSymPosIndex=0) const
Get the Scattering factor for all reflections of a given ScatteringData object.
const CrystVector_REAL & GetReflZ() const
Return the 1D array of orthonormal z coordinates for all reflections (recipr. space) ...
\ brief ScatteringPower for a spherical particule
string mName
Name for this RefinableObject. Should be unique, at least in the same scope.+.
REAL mBiso
Isotropic temperature B-factor.
const CrystVector_REAL & GetReflY() const
Return the 1D array of orthonormal y coordinates for all reflections (recipr. space) ...
const CrystVector_REAL & GetReflX() const
Return the 1D array of orthonormal x coordinates for all reflections (recipr. space) ...
REAL GetRadius() const
Return the physical radius of this type of scatterer (for 3D display purposes).
virtual CrystMatrix_REAL GetResonantScattFactReal(const ScatteringData &data, const int spgSymPosIndex=0) const
Get the real part of the resonant scattering factor.
float mColourRGB[3]
Colour for this ScatteringPower using RGB.
RefinableObjClock mClock
Clock.
void Init()
Initialization of the object, used by all constructors, and operator=.
virtual void XMLInput(istream &is, const XMLCrystTag &tag)
Input From stream.
virtual REAL GetForwardScatteringFactor(const RadiationType) const
Get the scattering factor at (0,0,0).
long GetNbRefl() const
Return the number of reflections in this experiment.
The namespace which includes all objects (crystallographic and algorithmic) in ObjCryst++.
Definition: Atom.cpp:47
Generic class for parameters of refinable objects.
Definition: RefinableObj.h:223
REAL mRadius
Radius of the sphere.
virtual const string & GetName() const
Name of the object.
RadiationType
Type of radiation used.
Definition: General.h:94
class to input or output a well-formatted xml beginning or ending tag.
virtual void SetName(const string &name)
Name of the object.
void XMLOutput(ostream &os, const string &name, int indent=0) const
XMLOutput to stream in well-formed XML.