FOX/ObjCryst++  2022
ObjCryst/IO.cpp
1 /* ObjCryst++ Object-Oriented Crystallographic Library
2  (c) 2000-2006 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; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
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 /*
20 * source file for XMLInput/XMLOutput in ObjCryst++
21 *
22 */
23 
24 #include <stdio.h>//for sprintf
25 
26 #include "ObjCryst/ObjCryst/General.h"
27 #include "ObjCryst/ObjCryst/IO.h"
28 #include "ObjCryst/RefinableObj/IO.h"
29 #include "ObjCryst/RefinableObj/GlobalOptimObj.h"
30 //#include "ObjCryst/ObjCryst/SpaceGroup.h"
31 #include "ObjCryst/ObjCryst/Scatterer.h"
32 #include "ObjCryst/ObjCryst/Crystal.h"
33 #include "ObjCryst/ObjCryst/ZScatterer.h"
34 //#include "ObjCryst/ObjCryst/ScatteringData.h"
35 #include "ObjCryst/ObjCryst/ScatteringPower.h"
36 #include "ObjCryst/ObjCryst/ScatteringPowerSphere.h"
37 #include "ObjCryst/ObjCryst/Atom.h"
38 #include "ObjCryst/ObjCryst/DiffractionDataSingleCrystal.h"
39 #include "ObjCryst/ObjCryst/PowderPattern.h"
40 #include "ObjCryst/Quirks/VFNStreamFormat.h"
41 #include "ObjCryst/ObjCryst/Molecule.h"
42 
43 #include <iostream>
44 #include <fstream>
45 #include <sstream>
46 #include <cstdlib>
47 #include <boost/format.hpp>
48 
49 //#define USE_BACKGROUND_MAXLIKE_ERROR
50 
51 namespace ObjCryst
52 {
54 //
55 // Global functions
56 //
58 
59 float string2floatC(const string &s)
60 {
61  float v=0;
62  stringstream ss(s);
63  ss.imbue(std::locale::classic());
64  ss>>v;
65  return v;
66 }
67 
68 float InputFloat(istream &is, const char endchar)
69 {
70  float f;
71  // Get rid of spaces, returns etc...
72  while(0==isgraph(is.peek())) is.get();
73  stringstream tmp;
74  char c;
75  while((endchar!=is.peek())&&(' '!=is.peek()))
76  {
77  is.get(c) ;
78  // Explicit typecasting to char otherwise it is understood as an integer number from type charT...
79  tmp<<(char)(tolower(c)) ;
80  }
81  if(tmp.str().find("nan")!=string::npos)
82  {
83  VFN_DEBUG_MESSAGE("InputFloat(..):"<<tmp.str()<<" -> NAN ! -> 1",9);
84  return 1;
85  }
86  if(tmp.str().find("inf")!=string::npos)
87  {
88  VFN_DEBUG_MESSAGE("InputFloat(..):"<<tmp.str()<<" -> INF ! -> 1",9);
89  return 1;
90  }
91  tmp.imbue(std::locale::classic());
92  tmp>>f;
93  VFN_DEBUG_MESSAGE("InputFloat(..):"<<f<<","<<is.good(),3);
94  return f;
95 }
96 
97 bool ISNAN_OR_INF(REAL r)
98 {
99  #if defined(_MSC_VER) || defined(__BORLANDC__)
100  return _isnan(r) || (!_finite(r));
101  #else
102  return (isnan(r)!=0) || (isinf(r)!=0);
103  #endif
104 }
105 
106 void XMLCrystFileSaveGlobal(const string & filename)
107 {
108  VFN_DEBUG_ENTRY("XMLCrystFileSaveGlobal(filename)",5)
109 
110  ofstream out(filename.c_str());
111  if(!out){};//:TODO:
113  out.close();
114  VFN_DEBUG_EXIT("XMLCrystFileSaveGlobal(filename):End",5)
115 }
116 
117 void XMLCrystFileSaveGlobal(ostream &out)
118 {
119  VFN_DEBUG_ENTRY("XMLCrystFileSaveGlobal(ostream)",5)
120  out.imbue(std::locale::classic());
121  XMLCrystTag tag("ObjCryst");
122  time_t date=time(0);
123  char strDate[40];
124  strftime(strDate,sizeof(strDate),"%Y-%m-%dT%H:%M:%S%Z",gmtime(&date));//%Y-%m-%dT%H:%M:%S%Z
125  tag.AddAttribute("Date",strDate);
126  tag.AddAttribute("Revision","2024001"); // Update this version number if the format changes
127  out<<tag<<endl;
128 
129  for(int i=0;i<gCrystalRegistry.GetNb();i++)
130  gCrystalRegistry.GetObj(i).XMLOutput(out,1);
131 
132  for(int i=0;i<gDiffractionDataSingleCrystalRegistry.GetNb();i++)
133  gDiffractionDataSingleCrystalRegistry.GetObj(i).XMLOutput(out,1);
134 
135  for(int i=0;i<gPowderPatternRegistry.GetNb();i++)
136  gPowderPatternRegistry.GetObj(i).XMLOutput(out,1);
137 
138  for(int i=0;i<gOptimizationObjRegistry.GetNb();i++)
139  gOptimizationObjRegistry.GetObj(i).XMLOutput(out,1);
140 
141  tag.SetIsEndTag(true);
142  out<<tag;
143  VFN_DEBUG_EXIT("XMLCrystFileSaveGlobal(ostream)",5)
144 }
145 
147 {
148  VFN_DEBUG_ENTRY("XMLCrystFileLoadObjectList(filename)",5)
149 
150  ifstream is(filename.c_str());
151  if(!is){};//:TODO:
152  is.imbue(std::locale::classic());
154  for(;;)
155  {
156  XMLCrystTag *pTag =new XMLCrystTag (is);
157  if(true==is.eof())
158  {
159  VFN_DEBUG_EXIT("XMLCrystFileLoadObjectList(filename):End",5)
160  for(int i=0;i<reg.GetNb();i++) reg.GetObj(i).Print();
161  is.close();
162  return reg;
163  }
164  //pTag->Print();
165  if(("Crystal"==pTag->GetName()||
166  "DiffractionDataSingleCrystal"==pTag->GetName()||
167  "PowderPattern"==pTag->GetName()||
168  "GlobalOptimObj"==pTag->GetName())
169  && !(pTag->IsEndTag())) reg.Register(*pTag);
170  else delete pTag;
171  }
172  return reg;
173 }
174 
175 template<class T> void XMLCrystFileLoadObject(const string & filename,
176  const string &tagName,
177  const string &name, T*obj)
178 {
179  VFN_DEBUG_ENTRY("XMLCrystFileLoadObject(filename,IOCrystTag,T&)",5)
180 
181  ifstream is(filename.c_str());
182  if(!is){};//:TODO:
183  is.imbue(std::locale::classic());
184  XMLCrystTag tag;
185  while(true)
186  {
187  is>>tag;
188  if(true==is.eof())
189  {
190  cout<<"XMLCrystFileLoadObject(filename,IOCrystTag,T&):Not Found !"<<endl;
191  is.close();
192  obj=0;
193  VFN_DEBUG_EXIT("XMLCrystFileLoadObject(filename,IOCrystTag,T&)",5)
194  return;
195  }
196  if(tagName!=tag.GetName())continue;
197  for(unsigned int i=0;i<tag.GetNbAttribute();i++)
198  if("Name"==tag.GetAttributeName(i))
199  if(name==tag.GetAttributeValue(i)) break;
200  }
201  VFN_DEBUG_MESSAGE("XMLCrystFileLoadObject(filename,IOCrystTag,T&):Found"<<tag,5)
202  obj = new T;
203  obj->XMLInput(is,tag);
204  is.close();
205  VFN_DEBUG_EXIT("XMLCrystFileLoadObject(filename,IOCrystTag,T&)",5)
206 }
207 
208 template void XMLCrystFileLoadObject(const string & ,const string &,const string &,
209  Crystal*);
210 template void XMLCrystFileLoadObject(const string & ,const string &,const string &,
211  PowderPattern*);
212 template void XMLCrystFileLoadObject(const string & ,const string &,const string &,
213  DiffractionDataSingleCrystal*);
214 //template void IOCrystFileLoadObject(const string &,const IOCrystTag &,
215 // ZScatterer*);
216 template void XMLCrystFileLoadObject(const string & ,const string &,const string &,
217  PowderPatternBackground*);
218 template void XMLCrystFileLoadObject(const string & ,const string &,const string &,
219  PowderPatternDiffraction*);
220 template void XMLCrystFileLoadObject(const string & ,const string &,const string &,
221  MonteCarloObj*);
222 
223 void XMLCrystFileLoadAllObject(const string & filename)
224 {
225  VFN_DEBUG_ENTRY("XMLCrystFileLoadAllObject(filename,)",5)
226  ifstream is(filename.c_str());
227  if(is.fail()) throw ObjCrystException("XMLCrystFileLoadAllObject() failed input");
229  (*fpObjCrystInformUser)("Finished loading XML file:"+filename);
230  VFN_DEBUG_EXIT("XMLCrystFileLoadAllObject(filename,)",5)
231 }
232 void XMLCrystFileLoadAllObject(istream &is)
233 {
234  VFN_DEBUG_ENTRY("XMLCrystFileLoadAllObject(istream)",5)
235  is.imbue(std::locale::classic());
236  XMLCrystTag tag;
237  do {is>>tag;} while(("ObjCryst"!=tag.GetName()) && (false==is.eof()));
238 
239  while(true)
240  {
241  XMLCrystTag tag(is);
242  if(true==is.eof()) break;
243  if(tag.GetName()=="Crystal")
244  {
245  Crystal* obj = new Crystal;
246  obj->XMLInput(is,tag);
247  (*fpObjCrystInformUser)("XML: finished reading Crystal object:"+obj->GetName());
248  }
249  if(tag.GetName()=="PowderPattern")
250  {
251  PowderPattern* obj = new PowderPattern;
252  obj->XMLInput(is,tag);
253  (*fpObjCrystInformUser)("XML: finished reading Powder Pattern object:"+obj->GetName());
254  }
255  if(tag.GetName()=="DiffractionDataSingleCrystal")
256  {
257  DiffractionDataSingleCrystal* obj = new DiffractionDataSingleCrystal;
258  obj->XMLInput(is,tag);
259  (*fpObjCrystInformUser)("XML: finished reading Single Crystal Diffraction object:"+obj->GetName());
260  }
261  if(tag.GetName()=="GlobalOptimObj")
262  {
263  MonteCarloObj* obj = new MonteCarloObj;
264  obj->XMLInput(is,tag);
265  (*fpObjCrystInformUser)("XML: finished reading Global Optimization object:"+obj->GetName());
266  }
267  }
268  (*fpObjCrystInformUser)("Finished loading XML");
269  VFN_DEBUG_EXIT("XMLCrystFileLoadAllObject(istream)",5)
270 }
272 //
273 // I/O ScatteringPowerAtom
274 //
276 void ScatteringPowerAtom::XMLOutput(ostream &os,int indent)const
277 {
278  VFN_DEBUG_ENTRY("ScatteringPowerAtom::XMLOutput():"<<this->GetName(),5)
279  for(int i=0;i<indent;i++) os << " " ;
280  XMLCrystTag tag("ScatteringPowerAtom");
281  tag.AddAttribute("Name",mName);
282  tag.AddAttribute("Symbol",mSymbol);
283  os <<tag<<endl;
284 
285  this->GetPar(&mBiso).XMLOutput(os,"Biso",indent+1);
286  os<<endl;
287  if(false==this->mIsIsotropic)
288  {
289  REAL* bdata = (REAL*) mB.data();
290  this->GetPar(&bdata[0]).XMLOutput(os,"B11",indent+1);
291  os<<endl;
292  this->GetPar(&bdata[1]).XMLOutput(os,"B22",indent+1);
293  os<<endl;
294  this->GetPar(&bdata[2]).XMLOutput(os,"B33",indent+1);
295  os<<endl;
296  this->GetPar(&bdata[3]).XMLOutput(os,"B12",indent+1);
297  os<<endl;
298  this->GetPar(&bdata[4]).XMLOutput(os,"B13",indent+1);
299  os<<endl;
300  this->GetPar(&bdata[5]).XMLOutput(os,"B23",indent+1);
301  os<<endl;
302  }
303 
304  this->GetPar("ML Error").XMLOutput(os,"ML Error",indent+1);
305  os <<endl;
306 
307  this->GetPar("ML-Nb Ghost Atoms").XMLOutput(os,"ML-NbGhost",indent+1);
308  os <<endl;
309 
310  this->GetPar("Formal Charge").XMLOutput(os,"Formal Charge",indent+1);
311  os <<endl;
312 
313  for(int i=0;i<=indent;i++) os << " " ;
314  XMLCrystTag tag2("RGBColour");
315  os << tag2
316  << mColourRGB[0]<<" "
317  << mColourRGB[1]<<" "
318  << mColourRGB[2];
319  tag2.SetIsEndTag(true);
320  os << tag2<<endl;
321 
322  tag.SetIsEndTag(true);
323  for(int i=0;i<indent;i++) os << " " ;
324  os <<tag<<endl;
325  VFN_DEBUG_EXIT("ScatteringPowerAtom::XMLOutput():"<<this->GetName(),5)
326 }
327 
328 void ScatteringPowerAtom::XMLInput(istream &is,const XMLCrystTag &tagg)
329 {
330  VFN_DEBUG_ENTRY("ScatteringPowerAtom::XMLInput():"<<this->GetName(),5)
331  for(unsigned int i=0;i<tagg.GetNbAttribute();i++)
332  {
333  if("Name"==tagg.GetAttributeName(i)) this->SetName(tagg.GetAttributeValue(i));
334  if("Symbol"==tagg.GetAttributeName(i)) mSymbol=tagg.GetAttributeValue(i);
335  }
336  (*fpObjCrystInformUser)("Input ScatteringPowerAtom:"+mName+"("+mSymbol+")");
337  this->Init(mName,mSymbol,mBiso);
338  while(true)
339  {
340  XMLCrystTag tag(is);
341  if(("ScatteringPowerAtom"==tag.GetName())&&tag.IsEndTag())
342  {
343  VFN_DEBUG_EXIT("ScatteringPowerAtom::Exit():"<<this->GetName(),5)
344  return;
345  }
346  if("RGBColour"==tag.GetName())
347  {
348  float r,g,b;
349  is>>r>>g>>b;
350  this->SetColour(r,g,b);
351  XMLCrystTag junk(is);
352  }
353  if("Par"==tag.GetName())
354  {
355  for(unsigned int i=0;i<tag.GetNbAttribute();i++)
356  {
357  if("Name"==tag.GetAttributeName(i))
358  {
359  if("Biso"==tag.GetAttributeValue(i))
360  {
361  this->GetPar(&mBiso).XMLInput(is,tag);
362  this->mIsIsotropic = true;
363  break;
364  }
365  if("B11"==tag.GetAttributeValue(i))
366  {
367  this->GetPar(&mB.data()[0]).XMLInput(is,tag);
368  this->mIsIsotropic = false;
369  break;
370  }
371  if("B22"==tag.GetAttributeValue(i))
372  {
373  this->GetPar(&mB.data()[1]).XMLInput(is,tag);
374  this->mIsIsotropic = false;
375  break;
376  }
377  if("B33"==tag.GetAttributeValue(i))
378  {
379  this->GetPar(&mB.data()[2]).XMLInput(is,tag);
380  this->mIsIsotropic = false;
381  break;
382  }
383  if("B12"==tag.GetAttributeValue(i))
384  {
385  this->GetPar(&mB.data()[3]).XMLInput(is,tag);
386  this->mIsIsotropic = false;
387  break;
388  }
389  if("B13"==tag.GetAttributeValue(i))
390  {
391  this->GetPar(&mB.data()[4]).XMLInput(is,tag);
392  this->mIsIsotropic = false;
393  break;
394  }
395  if("B23"==tag.GetAttributeValue(i))
396  {
397  this->GetPar(&mB.data()[5]).XMLInput(is,tag);
398  this->mIsIsotropic = false;
399  break;
400  }
401  if("ML Error"==tag.GetAttributeValue(i))
402  {
403  this->GetPar("ML Error").XMLInput(is,tag);
404  break;
405  }
406  if("ML-NbGhost"==tag.GetAttributeValue(i))
407  {
408  this->GetPar("ML-Nb Ghost Atoms").XMLInput(is,tag);
409  break;
410  }
411  if("Formal Charge"==tag.GetAttributeValue(i))
412  {
413  this->GetPar("Formal Charge").XMLInput(is,tag);
414  break;
415  }
416  }
417  }
418  continue;
419  }
420  }
421 }
423 //
424 // I/O Atom
425 //
427 void Atom::XMLOutput(ostream &os,int indent)const
428 {
429  VFN_DEBUG_ENTRY("Atom::XMLOutput():"<<this->GetName(),5)
430  for(int i=0;i<indent;i++) os << " " ;
431  XMLCrystTag tag("Atom");
432  tag.AddAttribute("Name",mName);
433  tag.AddAttribute("ScattPow",mpScattPowAtom->GetName());
434  os <<tag;
435  os <<endl;
436  indent++;
437 
438  this->GetPar(mXYZ.data()+0).XMLOutput(os,"x",indent);
439  os <<endl;
440 
441  this->GetPar(mXYZ.data()+1).XMLOutput(os,"y",indent);
442  os <<endl;
443 
444  this->GetPar(mXYZ.data()+2).XMLOutput(os,"z",indent);
445  os <<endl;
446 
447  this->GetPar(&mOccupancy).XMLOutput(os,"Occup",indent);
448  os <<endl;
449 
450  tag.SetIsEndTag(true);
451  indent--;
452  for(int i=0;i<indent;i++) os << " " ;
453  os <<tag<<endl;
454 
455  VFN_DEBUG_EXIT("Atom::XMLOutput():"<<this->GetName(),5)
456 }
457 
458 void Atom::XMLInput(istream &is,const XMLCrystTag &tagg)
459 {
460  VFN_DEBUG_ENTRY("Atom::XMLInput():"<<this->GetName(),5)
461  string scattPowName;
462  for(unsigned int i=0;i<tagg.GetNbAttribute();i++)
463  {
464  if("Name"==tagg.GetAttributeName(i)) this->SetName(tagg.GetAttributeValue(i));
465  if("ScattPow"==tagg.GetAttributeName(i)) scattPowName=tagg.GetAttributeValue(i);
466  }
467  (*fpObjCrystInformUser)("XML: Loading Atom:"+this->GetName());
468  const ScatteringPower* scattPow=
469  &(this->GetCrystal().GetScatteringPowerRegistry().GetObj(scattPowName));
470  VFN_DEBUG_MESSAGE("Found Scattering Power:"<< scattPowName<<" at "<<scattPow,4);
471  this->Init(0,0,0,mName,scattPow,1);
472  while(true)
473  {
474  XMLCrystTag tag(is);
475  if(("Atom"==tag.GetName())&&tag.IsEndTag())
476  {
477  VFN_DEBUG_EXIT("Atom::Exit():"<<this->GetName(),5)
478  return;
479  }
480  if("Par"==tag.GetName())
481  {
482  for(unsigned int i=0;i<tag.GetNbAttribute();i++)
483  {
484  if("Name"==tag.GetAttributeName(i))
485  {
486  if("x"==tag.GetAttributeValue(i))
487  {
488  this->GetPar(mXYZ.data()+0).XMLInput(is,tag);
489  break;
490  }
491  if("y"==tag.GetAttributeValue(i))
492  {
493  this->GetPar(mXYZ.data()+1).XMLInput(is,tag);
494  break;
495  }
496  if("z"==tag.GetAttributeValue(i))
497  {
498  this->GetPar(mXYZ.data()+2).XMLInput(is,tag);
499  break;
500  }
501  if("Occup"==tag.GetAttributeValue(i))
502  {
503  this->GetPar(&mOccupancy).XMLInput(is,tag);
504  break;
505  }
506  }
507  }
508  continue;
509  }
510  }
511 }
513 //
514 // I/O ZAtom
515 //
517 void ZAtom::XMLOutput(ostream &os,int indent)const
518 {
519  VFN_DEBUG_ENTRY("ZAtom::XMLOutput():"<<this->GetName(),5)
520  for(int i=0;i<indent;i++) os << " " ;
521  XMLCrystTag tag("ZAtom");
522  tag.AddAttribute("Name",mName);
523  if(0!=this->GetScatteringPower())//else it is a dummy atom
524  tag.AddAttribute("ScattPow",this->GetScatteringPower()->GetName());
525 
526  tag.AddAttribute("BondAtom",this->GetZScatterer()
527  .GetZAtomRegistry()
528  .GetObj(this->GetZBondAtom())
529  .GetName());
530  tag.AddAttribute("AngleAtom",this->GetZScatterer()
531  .GetZAtomRegistry()
532  .GetObj(this->GetZAngleAtom())
533  .GetName());
534  tag.AddAttribute("DihedAtom",this->GetZScatterer()
535  .GetZAtomRegistry()
536  .GetObj(this->GetZDihedralAngleAtom())
537  .GetName());
538  os <<tag<<endl;
539  indent++;
540 
541 
542  this->GetZScatterer().GetPar(&mBondLength).XMLOutput(os,"BondLength",indent);
543  os <<endl;
544 
545  this->GetZScatterer().GetPar(&mAngle).XMLOutput(os,"Angle",indent);
546  os <<endl;
547 
548  this->GetZScatterer().GetPar(&mDihed).XMLOutput(os,"DihedAng",indent);
549  os <<endl;
550 
551  this->GetZScatterer().GetPar(&mOccupancy).XMLOutput(os,"Occup",indent);
552  os <<endl;
553 
554  indent--;
555  tag.SetIsEndTag(true);
556  for(int i=0;i<indent;i++) os << " " ;
557  os <<tag<<endl;
558  VFN_DEBUG_EXIT("ZAtom::XMLOutput():"<<this->GetName(),5)
559 }
560 
561 void ZAtom::XMLInput(istream &is,const XMLCrystTag &tagg)
562 {
563  VFN_DEBUG_ENTRY("ZAtom::XMLInput():"<<this->GetName(),5)
564  for(unsigned int i=0;i<tagg.GetNbAttribute();i++)
565  {
566  if("Name"==tagg.GetAttributeName(i))
567  {
568  this->SetName(tagg.GetAttributeValue(i));
569  continue;
570  }
571  if("ScattPow"==tagg.GetAttributeName(i))
572  {
573  const ScatteringPower* scattPow=&(this->GetZScatterer()
574  .GetCrystal()
576  .GetObj(tagg.GetAttributeValue(i)));
577  this->SetScatteringPower(scattPow);
578  continue;
579  }
580  if("BondAtom"==tagg.GetAttributeName(i))
581  {
582  mAtomBond=this->GetZScatterer().GetZAtomRegistry().Find(tagg.GetAttributeValue(i));
583  continue;
584  }
585  if("AngleAtom"==tagg.GetAttributeName(i))
586  {
587  mAtomAngle=this->GetZScatterer().GetZAtomRegistry().Find(tagg.GetAttributeValue(i));
588  continue;
589  }
590  if("DihedAtom"==tagg.GetAttributeName(i))
591  {
592  mAtomDihed=this->GetZScatterer().GetZAtomRegistry().Find(tagg.GetAttributeValue(i));
593  continue;
594  }
595  }
596  while(true)
597  {
598  XMLCrystTag tag(is);
599  if(("ZAtom"==tag.GetName())&&tag.IsEndTag())
600  {
601  VFN_DEBUG_EXIT("ZAtom::Exit():"<<this->GetName(),5)
602  return;
603  }
604  if("Par"==tag.GetName())
605  {
606  for(unsigned int i=0;i<tag.GetNbAttribute();i++)
607  {
608  if("Name"==tag.GetAttributeName(i))
609  {
610  if("BondLength"==tag.GetAttributeValue(i))
611  {
612  this->GetZScatterer().GetPar(&mBondLength).XMLInput(is,tag);
613  break;
614  }
615  if("Angle"==tag.GetAttributeValue(i))
616  {
617  this->GetZScatterer().GetPar(&mAngle).XMLInput(is,tag);
618  break;
619  }
620  if("DihedAng"==tag.GetAttributeValue(i))
621  {
622  this->GetZScatterer().GetPar(&mDihed).XMLInput(is,tag);
623  break;
624  }
625  if("Occup"==tag.GetAttributeValue(i))
626  {
627  this->GetZScatterer().GetPar(&mOccupancy).XMLInput(is,tag);
628  break;
629  }
630  }
631  }
632  continue;
633  }
634  }
635 }
636 
638 //
639 // I/O ZScatterer
640 //
642 void ZScatterer::XMLOutput(ostream &os,int indent)const
643 {
644  VFN_DEBUG_ENTRY("ZScatterer::XMLOutput():"<<this->GetName(),5)
645  for(int i=0;i<indent;i++) os << " " ;
646  XMLCrystTag tag("ZScatterer");
647  tag.AddAttribute("Name",mName);
648  os <<tag<<endl;
649  indent++;
650 
651  this->GetPar(mXYZ.data()+0).XMLOutput(os,"x",indent);
652  os <<endl;
653 
654  this->GetPar(mXYZ.data()+1).XMLOutput(os,"y",indent);
655  os <<endl;
656 
657  this->GetPar(mXYZ.data()+2).XMLOutput(os,"z",indent);
658  os <<endl;
659 
660  this->GetPar(&mOccupancy).XMLOutput(os,"Occup",indent);
661  os <<endl;
662 
663  this->GetPar(&mPhi).XMLOutput(os,"Phi",indent);
664  os <<endl;
665 
666  this->GetPar(&mChi).XMLOutput(os,"Chi",indent);
667  os <<endl;
668 
669  this->GetPar(&mPsi).XMLOutput(os,"Psi",indent);
670  os <<endl;
671 
672  for(int i=0;i<mZAtomRegistry.GetNb();i++) mZAtomRegistry.GetObj(i).XMLOutput(os,indent);
673 
674  if(mZAtomRegistry.GetNb()>0)
675  {
676  for(int i=0;i<=indent;i++) os << " " ;
677  XMLCrystTag tag2("PivotAtom",false,true);
678  tag2.AddAttribute("Name",this->GetZAtomRegistry().GetObj(mCenterAtomIndex).GetName());
679  os <<tag2<<endl;
680  }
681 
682  indent--;
683  tag.SetIsEndTag(true);
684  for(int i=0;i<indent;i++) os << " " ;
685  os <<tag<<endl;
686  VFN_DEBUG_EXIT("ZScatterer::XMLOutput():"<<this->GetName(),5)
687 }
688 
689 void ZScatterer::XMLInput(istream &is,const XMLCrystTag &tagg)
690 {
691  VFN_DEBUG_ENTRY("ZScatterer::XMLInput():"<<this->GetName(),5)
692  for(unsigned int i=0;i<tagg.GetNbAttribute();i++)
693  {
694  if("Name"==tagg.GetAttributeName(i)) this->SetName(tagg.GetAttributeValue(i));
695  }
696  (*fpObjCrystInformUser)("XML: Loading ZScatterer:"+this->GetName());
697  while(true)
698  {
699  XMLCrystTag tag(is);
700  if(("ZScatterer"==tag.GetName())&&tag.IsEndTag())
701  {
702  VFN_DEBUG_EXIT("ZScatterer::Exit():"<<this->GetName(),5)
703  return;
704  }
705  if("Par"==tag.GetName())
706  {
707  for(unsigned int i=0;i<tag.GetNbAttribute();i++)
708  {
709  if("Name"==tag.GetAttributeName(i))
710  {
711  if("x"==tag.GetAttributeValue(i))
712  {
713  this->GetPar(mXYZ.data()+0).XMLInput(is,tag);
714  break;
715  }
716  if("y"==tag.GetAttributeValue(i))
717  {
718  this->GetPar(mXYZ.data()+1).XMLInput(is,tag);
719  break;
720  }
721  if("z"==tag.GetAttributeValue(i))
722  {
723  this->GetPar(mXYZ.data()+2).XMLInput(is,tag);
724  break;
725  }
726  if("Occup"==tag.GetAttributeValue(i))
727  {
728  this->GetPar(&mOccupancy).XMLInput(is,tag);
729  break;
730  }
731  if("Phi"==tag.GetAttributeValue(i))
732  {
733  this->GetPar(&mPhi).XMLInput(is,tag);
734  break;
735  }
736  if("Chi"==tag.GetAttributeValue(i))
737  {
738  this->GetPar(&mChi).XMLInput(is,tag);
739  break;
740  }
741  if("Psi"==tag.GetAttributeValue(i))
742  {
743  this->GetPar(&mPsi).XMLInput(is,tag);
744  break;
745  }
746  }
747  }
748  continue;
749  }
750  if("ZAtom"==tag.GetName())
751  {
752  //we must take care of possible dummy atoms
753  const ScatteringPower* scattPow=0;
754  for(unsigned int i=0;i<tag.GetNbAttribute();i++)
755  if("ScattPow"==tag.GetAttributeName(i))
756  scattPow=&(this->GetCrystal().GetScatteringPowerRegistry()
757  .GetObj(tag.GetAttributeValue(i)));
758  const long nb=mZAtomRegistry.GetNb();
759  this->AddAtom("",scattPow,0,0,0,0,0,1);
760  mZAtomRegistry.GetObj(nb).XMLInput(is,tag);
761  // Update the name of refinable parameters
762  {
763  char buf [20];
764  sprintf(buf,"%d-%d",(int)nb,(int)(mZAtomRegistry.GetObj(nb).GetZBondAtom()));
765  this->GetPar(&(mZAtomRegistry.GetObj(nb).mBondLength))
766  .SetName("Length"+(string)buf);
767 
768  sprintf(buf,"%d-%d-%d",(int)nb,(int)(mZAtomRegistry.GetObj(nb).GetZBondAtom()),
769  (int)(mZAtomRegistry.GetObj(nb).GetZAngleAtom()));
770  this->GetPar(&(mZAtomRegistry.GetObj(nb).mAngle))
771  .SetName("Angle"+(string)buf);
772 
773  sprintf(buf,"%d-%d-%d-%d",(int)nb,(int)(mZAtomRegistry.GetObj(nb).GetZBondAtom()),
774  (int)(mZAtomRegistry.GetObj(nb).GetZAngleAtom()),
775  (int)(mZAtomRegistry.GetObj(nb).GetZDihedralAngleAtom()));
776  this->GetPar(&(mZAtomRegistry.GetObj(nb).mDihed))
777  .SetName("Dihed"+(string)buf);
778  }
779  }
780  if("PivotAtom"==tag.GetName())
781  {
782  for(unsigned int i=0;i<tag.GetNbAttribute();i++)
783  if("Name"==tag.GetAttributeName(i))
784  {
785  mCenterAtomIndex=this->GetZAtomRegistry().Find(tag.GetAttributeValue(i));
786  }
787  }
788  }
789 }
791 //
792 // I/O Crystal
793 //
795 void Crystal::XMLOutput(ostream &os,int indent)const
796 {
797  VFN_DEBUG_ENTRY("Crystal::XMLOutput():"<<this->GetName(),5)
798 
799  for(int i=0;i<indent;i++) os << " " ;
800  XMLCrystTag tag("Crystal");
801  tag.AddAttribute("Name",mName);
802  tag.AddAttribute("SpaceGroup",this->GetSpaceGroup().GetName());
803  os <<tag<<endl;
804  indent++;
805 
806  // :TODO:
807  this->GetPar("a").XMLOutput(os,"a",indent);
808  os <<endl;
809 
810  this->GetPar("b").XMLOutput(os,"b",indent);
811  os <<endl;
812 
813  this->GetPar("c").XMLOutput(os,"c",indent);
814  os <<endl;
815 
816  this->GetPar("alpha").XMLOutput(os,"alpha",indent);
817  os <<endl;
818 
819  this->GetPar("beta").XMLOutput(os,"beta",indent);
820  os <<endl;
821 
822  this->GetPar("gamma").XMLOutput(os,"gamma",indent);
823  os <<endl;
824 
825  for(unsigned int i=0;i<this->GetNbOption();i++)
826  {
827  this->GetOption(i).XMLOutput(os,indent);
828  os <<endl<<endl;
829  }
830 
831  for(int i=0;i<mScatteringPowerRegistry.GetNb();i++)
832  mScatteringPowerRegistry.GetObj(i).XMLOutput(os,indent);
833  os <<endl;
834  for(int i=0;i<mScattererRegistry.GetNb();i++)
835  mScattererRegistry.GetObj(i).XMLOutput(os,indent);
836  os <<endl;
837 
838  if(mvBumpMergePar.size()>0)
839  {
840  VBumpMergePar::const_iterator pos;
841  for(pos=mvBumpMergePar.begin();pos!=mvBumpMergePar.end();pos++)
842  {
843  for(int k=0;k<=indent;k++) os << " " ;
844  XMLCrystTag tagBump("AntiBumpDistance");
845  tagBump.AddAttribute("ScattPow1",pos->first.first->GetName());
846  tagBump.AddAttribute("ScattPow2",pos->first.second->GetName());
847  {
848  stringstream ss;
849  ss << pos->second.mCanOverlap;
850  tagBump.AddAttribute("AllowMerge",ss.str());
851  }
852  os<<tagBump;
853  tagBump.SetIsEndTag(true);
854  os<<sqrt(pos->second.mDist2)<<tagBump<<endl;
855  }
856  for(int k=0;k<=indent;k++) os << " " ;
857  XMLCrystTag tag2("AntiBumpScale");
858  os << tag2<< mBumpMergeScale;
859  tag2.SetIsEndTag(true);
860  os << tag2<<endl;
861  }
862  if(mvBondValenceRo.size()>0)
863  {
864  map<pair<const ScatteringPower*,const ScatteringPower*>, REAL>::const_iterator pos;
865  for(pos=mvBondValenceRo.begin();pos!=mvBondValenceRo.end();pos++)
866  {
867  for(int k=0;k<=indent;k++) os << " " ;
868  XMLCrystTag tagBVRo("BondValenceRo");
869  tagBVRo.AddAttribute("ScattPow1",pos->first.first->GetName());
870  tagBVRo.AddAttribute("ScattPow2",pos->first.second->GetName());
871  os<<tagBVRo;
872  tagBVRo.SetIsEndTag(true);
873  os<<pos->second<<tagBVRo<<endl;
874  }
875  for(int k=0;k<=indent;k++) os << " " ;
876  XMLCrystTag tag2("BondValenceCostScale");
877  os << tag2<< mBondValenceCostScale;
878  tag2.SetIsEndTag(true);
879  os << tag2<<endl;
880  }
881  if(mInterMolDistList.size()>0) {
882  for(int i=0;i<mInterMolDistList.size();i++) {
883  for(int k=0;k<=indent;k++) os << " " ;
884  XMLCrystTag tagIMD("InterMolecularDistRestr", false, true);
885 
886  string tmpAt1 = mInterMolDistList[i].get_list_At1();
887  tagIMD.AddAttribute("At1",tmpAt1);
888 
889  string tmpAt2 = mInterMolDistList[i].get_list_At2();
890  /*
891  for(int j=0;j<mInterMolDistList[i].mAt2.size();j++) {
892  tmpAt2 +=mInterMolDistList[i].mAt2[j];
893  if(j<(mInterMolDistList[i].mAt2.size()-1)) {
894  tmpAt2 += " ";
895  }
896  }
897  */
898  tagIMD.AddAttribute("At2",tmpAt2);
899  tagIMD.AddAttribute("Dist",std::to_string(sqrt(mInterMolDistList[i].mDist2)));
900  tagIMD.AddAttribute("Delta",std::to_string(mInterMolDistList[i].mDelta));
901  tagIMD.AddAttribute("Sigma",std::to_string(mInterMolDistList[i].mSig));
902  os<<tagIMD;
903  os<<endl;
904  }
905  for(int k=0;k<=indent;k++) os << " " ;
906  XMLCrystTag tag2("InterMolDistScale");
907  os << tag2<< mInterMolDistCostScale;
908  tag2.SetIsEndTag(true);
909  os << tag2<<endl;
910 
911  for(int k=0;k<=indent;k++) os << " " ;
912  XMLCrystTag tag3("mCostCalcMethod");
913  os << tag3<< mCostCalcMethod;
914  tag3.SetIsEndTag(true);
915  os << tag3<<endl;
916 
917  for(int k=0;k<=indent;k++) os << " " ;
918  XMLCrystTag tag4("mDistMaxMultiplier");
919  os << tag4<< mDistMaxMultiplier;
920  tag4.SetIsEndTag(true);
921  os << tag4<<endl;
922  }
923  indent--;
924  tag.SetIsEndTag(true);
925  for(int i=0;i<indent;i++) os << " " ;
926  os <<tag<<endl;
927  VFN_DEBUG_EXIT("Crystal::XMLOutput():"<<this->GetName(),5)
928 }
929 
930 void Crystal::XMLInput(istream &is,const XMLCrystTag &tagg)
931 {
932  VFN_DEBUG_ENTRY("Crystal::XMLInput():"<<this->GetName(),5)
933  (*fpObjCrystInformUser)("XML: Loading Crystal:");
934  //Remove Scatterers and Scattering Powers
935  for(long i=0;i<mScatteringPowerRegistry.GetNb();i++)
936  {
937  this->RemoveSubRefObj(mScatteringPowerRegistry.GetObj(i));
938  mScatteringPowerRegistry.GetObj(i).DeRegisterClient(*this);
939  }
940 
941  std::list<ScatteringPowerAtom*> vold_scattpow;
942  if(mDeleteSubObjInDestructor)
943  {
944  mScatteringPowerRegistry.DeleteAll();
945  }
946  else
947  {
948  // Keep track of the old atomic scattering powers to see if they can be re-used
949  for(std::vector<ScatteringPower*>::const_iterator pos=mScatteringPowerRegistry.begin() ;
950  pos!=mScatteringPowerRegistry.end(); ++pos)
951  {
952  if((*pos)->GetClassName().compare("ScatteringPowerAtom")!=0) continue;
953  vold_scattpow.push_back(dynamic_cast<ScatteringPowerAtom*>(*pos));
954  }
955  mScatteringPowerRegistry.DeRegisterAll();
956  }
957 
958  for(long i=0;i<mScattererRegistry.GetNb();i++)
959  {
960  this->RemoveSubRefObj(mScattererRegistry.GetObj(i));
961  mScattererRegistry.GetObj(i).DeRegisterClient(*this);
962  }
963  if(mDeleteSubObjInDestructor)
964  {
965  mScattererRegistry.DeleteAll();
966  }
967  else
968  {
969  mScattererRegistry.DeRegisterAll();
970  }
971 
972  for(unsigned int i=0;i<tagg.GetNbAttribute();i++)
973  {
974  if("Name"==tagg.GetAttributeName(i)) this->SetName(tagg.GetAttributeValue(i));
975  if("SpaceGroup"==tagg.GetAttributeName(i))
976  this->Init(1,2,3,M_PI/2,M_PI/2,M_PI/2,tagg.GetAttributeValue(i),this->GetName());
977  }
978  (*fpObjCrystInformUser)("XML: Loading Crystal:"+this->GetName()+"(spg:"+this->GetSpaceGroup().GetName()+")");
979  while(true)
980  {
981  XMLCrystTag tag(is);
982  if(("Crystal"==tag.GetName())&&tag.IsEndTag())
983  {
984  this->UpdateDisplay();
985  VFN_DEBUG_EXIT("Crystal::Exit():"<<this->GetName(),5)
986  return;
987  }
988  if("Par"==tag.GetName())
989  {
990  for(unsigned int i=0;i<tag.GetNbAttribute();i++)
991  {
992  if("Name"==tag.GetAttributeName(i))
993  {
994  this->GetPar(tag.GetAttributeValue(i)).XMLInput(is,tag);
995  }
996  }
997  continue;
998  }
999  if("Option"==tag.GetName())
1000  {
1001  for(unsigned int i=0;i<tag.GetNbAttribute();i++)
1002  if("Name"==tag.GetAttributeName(i))
1003  mOptionRegistry.GetObj(tag.GetAttributeValue(i)).XMLInput(is,tag);
1004  this->InitRefParList();// Fix the "used" tag of refinable par after options
1005  continue;
1006  }
1007  if("AntiBumpDistance"==tag.GetName())
1008  {
1009  float dist;
1010  bool useMerge=false;
1011  bool allowMerge;
1012  string scattPow1;
1013  string scattPow2;
1014  for(unsigned int i=0;i<tag.GetNbAttribute();i++)
1015  {
1016  if("AllowMerge"==tag.GetAttributeName(i))
1017  {
1018  stringstream ss(tag.GetAttributeValue(i));
1019  ss >>allowMerge;
1020  useMerge=true;
1021  continue;
1022  }
1023  if("ScattPow1"==tag.GetAttributeName(i)) scattPow1=tag.GetAttributeValue(i);
1024  if("ScattPow2"==tag.GetAttributeName(i)) scattPow2=tag.GetAttributeValue(i);
1025  }
1026  is>>dist;
1027  XMLCrystTag junk(is);//end tag
1028  if(useMerge)
1029  this->SetBumpMergeDistance(mScatteringPowerRegistry.GetObj(scattPow1),
1030  mScatteringPowerRegistry.GetObj(scattPow2),
1031  dist,allowMerge);
1032  else this->SetBumpMergeDistance(mScatteringPowerRegistry.GetObj(scattPow1),
1033  mScatteringPowerRegistry.GetObj(scattPow2),
1034  dist);
1035  continue;
1036  }
1037  if("BondValenceRo"==tag.GetName())
1038  {
1039  float ro;
1040  string scattPow1;
1041  string scattPow2;
1042  for(unsigned int i=0;i<tag.GetNbAttribute();i++)
1043  {
1044  if("ScattPow1"==tag.GetAttributeName(i)) scattPow1=tag.GetAttributeValue(i);
1045  if("ScattPow2"==tag.GetAttributeName(i)) scattPow2=tag.GetAttributeValue(i);
1046  }
1047  is>>ro;
1048  XMLCrystTag junk(is);//end tag
1049  this->AddBondValenceRo(mScatteringPowerRegistry.GetObj(scattPow1),
1050  mScatteringPowerRegistry.GetObj(scattPow2),ro);
1051  continue;
1052  }
1053  if("AntiBumpScale"==tag.GetName())
1054  {
1055  is>>mBumpMergeScale;
1056  XMLCrystTag junk(is);
1057  }
1058  if("BondValenceCostScale"==tag.GetName())
1059  {
1060  is>>mBondValenceCostScale;
1061  XMLCrystTag junk(is);
1062  }
1063  if("InterMolecularDistRestr"==tag.GetName())
1064  {
1065  vector<string> At1;
1066  vector<string> At2;
1067  string Dist;
1068  string Sigma;
1069  string Delta;
1070 
1071  bool er=false;
1072  for(unsigned int i=0;i<tag.GetNbAttribute();i++)
1073  {
1074  if("At1"==tag.GetAttributeName(i)) {
1075  string tmpAt1=tag.GetAttributeValue(i);
1076  if(tmpAt1.length()==0) {
1077  er = true;
1078  break;
1079  }
1080  stringstream ss(tmpAt1);
1081  string word;
1082  while (ss >> word) {
1083  At1.push_back(word);
1084  }
1085  if(At1.size()==0) {
1086  er = true;
1087  break;
1088  }
1089  }
1090  if("At2"==tag.GetAttributeName(i)) {
1091  string tmpAt2=tag.GetAttributeValue(i);
1092  if(tmpAt2.length()==0) {
1093  er = true;
1094  break;
1095  }
1096  stringstream ss(tmpAt2);
1097  string word;
1098  while (ss >> word) {
1099  At2.push_back(word);
1100  }
1101  if(At2.size()==0) {
1102  er = true;
1103  break;
1104  }
1105  }
1106  if("Dist"==tag.GetAttributeName(i)) {
1107  Dist=tag.GetAttributeValue(i);
1108  if(Dist.length()==0) {
1109  er = true;
1110  break;
1111  }
1112  }
1113  if("Sigma"==tag.GetAttributeName(i)) {
1114  Sigma=tag.GetAttributeValue(i);
1115  if(Sigma.length()==0) {
1116  er = true;
1117  break;
1118  }
1119  }
1120  if("Delta"==tag.GetAttributeName(i)) {
1121  Delta=tag.GetAttributeValue(i);
1122  if(Delta.length()==0) {
1123  er = true;
1124  break;
1125  }
1126  }
1127  }
1128  if(!er) {
1129  this->SetNewInterMolDist(At1, At2, stof(Dist), stof(Sigma), stof(Delta));
1130  }
1131  continue;
1132  }
1133  if("InterMolDistScale"==tag.GetName())
1134  {
1135  is>>mInterMolDistCostScale;
1136  XMLCrystTag junk(is);
1137  }
1138  if("mCostCalcMethod"==tag.GetName())
1139  {
1140  is>>mCostCalcMethod;
1141  XMLCrystTag junk(is);
1142  }
1143  if("mDistMaxMultiplier"==tag.GetName())
1144  {
1145  is>>mDistMaxMultiplier;
1146  XMLCrystTag junk(is);
1147  }
1148  if("Atom"==tag.GetName())
1149  {
1150  VFN_DEBUG_ENTRY("Crystal::XMLInput():reading an Atom",5)
1151  Atom *at=new Atom;
1152  at->SetCrystal(*this);
1153  at->XMLInput(is,tag);
1154  this->AddScatterer(at);
1155  VFN_DEBUG_EXIT("Crystal::XMLInput():reading an Atom",5)
1156  continue;
1157  }
1158  if("ScatteringPowerAtom"==tag.GetName())
1159  {
1160  VFN_DEBUG_ENTRY("Crystal::XMLInput():reading a ScatteringPowerAtom",5)
1161  VFN_DEBUG_MESSAGE("Crystal::XMLInput():reading a ScatteringPowerAtom",5)
1163  sc->XMLInput(is,tag);
1164  if(!mDeleteSubObjInDestructor)
1165  {
1166  // Can we re-use a previous scattering power since we did not delete them ?
1167  for(std::list<ScatteringPowerAtom*>::iterator pos= vold_scattpow.begin();
1168  pos!=vold_scattpow.end();++pos)
1169  {
1170  if((*pos)->GetSymbol() != sc->GetSymbol()) continue;
1171  if((*pos)->GetName() != sc->GetName()) continue;
1172  if((*pos)->GetFormalCharge() != sc->GetFormalCharge()) continue;
1173  if((*pos)->GetMaximumLikelihoodNbGhostAtom() != sc->GetMaximumLikelihoodNbGhostAtom()) continue;
1174  if((*pos)->GetMaximumLikelihoodPositionError() != sc->GetMaximumLikelihoodPositionError()) continue;
1175  if((*pos)->IsIsotropic() != sc->IsIsotropic()) continue;
1176  if(fabs((*pos)->GetBiso() - sc->GetBiso()) > 1e-4f) continue;
1177  if(!(*pos)->IsIsotropic())
1178  {
1179  if(fabs((*pos)->GetBij(0) - sc->GetBij(0)) > 1e-4f) continue;
1180  if(fabs((*pos)->GetBij(1) - sc->GetBij(1)) > 1e-4f) continue;
1181  if(fabs((*pos)->GetBij(2) - sc->GetBij(2)) > 1e-4f) continue;
1182  if(fabs((*pos)->GetBij(3) - sc->GetBij(3)) > 1e-4f) continue;
1183  if(fabs((*pos)->GetBij(4) - sc->GetBij(4)) > 1e-4f) continue;
1184  if(fabs((*pos)->GetBij(5) - sc->GetBij(5)) > 1e-4f) continue;
1185  }
1186  VFN_DEBUG_MESSAGE("Crystal::XMLInput(): reusing scattering power: "<<sc->GetName(),5);
1187  delete sc;
1188  sc = *pos;
1189  }
1190  }
1191  this->AddScatteringPower(sc);
1192  VFN_DEBUG_EXIT("Crystal::XMLInput():reading a ScatteringPowerAtom",5)
1193  continue;
1194  }
1195  if("ScatteringPowerSphere"==tag.GetName())
1196  {
1197  VFN_DEBUG_ENTRY("Crystal::XMLInput():reading a ScatteringPowerSphere",5)
1198  VFN_DEBUG_MESSAGE("Crystal::XMLInput():reading a ScatteringPowerSphere",5)
1200  sc->XMLInput(is,tag);
1201  this->AddScatteringPower(sc);
1202  VFN_DEBUG_EXIT("Crystal::XMLInput():reading a ScatteringPowerSphere",5)
1203  continue;
1204  }
1205  if("ZScatterer"==tag.GetName())
1206  {
1207  VFN_DEBUG_ENTRY("Crystal::XMLInput():reading a ZScatterer",5)
1208  VFN_DEBUG_MESSAGE("Crystal::XMLInput():reading a ZScatterer",5)
1209  ZScatterer *z=new ZScatterer("",*this);
1210  z->XMLInput(is,tag);
1211  this->AddScatterer(z);
1212  VFN_DEBUG_EXIT("Crystal::XMLInput():reading a ZScatterer",5)
1213  continue;
1214  }
1215  if("Molecule"==tag.GetName())
1216  {
1217  VFN_DEBUG_ENTRY("Crystal::XMLInput():reading a Molecule",5)
1218  VFN_DEBUG_MESSAGE("Crystal::XMLInput():reading a Molecule",5)
1219  Molecule *z=new Molecule(*this,"");
1220  z->XMLInput(is,tag);
1221  this->AddScatterer(z);
1222  VFN_DEBUG_EXIT("Crystal::XMLInput():reading a Molecule",5)
1223  continue;
1224  }
1225  }
1226  (*fpObjCrystInformUser)("XML: Finished loading Crystal:"+this->GetName());
1227 }
1229 //
1230 // I/O Radiation
1231 //
1233 void Radiation::XMLOutput(ostream &os,int indent)const
1234 {
1235  VFN_DEBUG_ENTRY("Radiation::XMLOutput():"<<this->GetName(),5)
1236  XMLCrystTag tag("Radiation");
1237  if(WAVELENGTH_ALPHA12==this->GetWavelengthType())
1238  tag.AddAttribute("XRayTube",mXRayTubeName);
1239  for(int i=0;i<indent;i++) os << " " ;
1240  os <<tag<<endl;
1241  indent++;
1242 
1243  mRadiationType.XMLOutput(os,indent);
1244  os<<endl;
1245 
1246  mWavelengthType.XMLOutput(os,indent);
1247  os<<endl;
1248 
1249  for(int i=0;i<indent;i++) os << " " ;
1250  {
1251  XMLCrystTag tag2("LinearPolarRate");
1252  os << tag2<< mLinearPolarRate;
1253  tag2.SetIsEndTag(true);
1254  os << tag2<<endl;
1255  }
1256 
1257  switch(this->GetWavelengthType())
1258  {
1259  case WAVELENGTH_MONOCHROMATIC: this->GetPar(mWavelength.data()).XMLOutput(os,indent);break;
1260  case WAVELENGTH_ALPHA12:
1261  {
1262  this->GetPar(mWavelength.data()).XMLOutput(os,indent);
1263  os <<endl;
1264  this->GetPar("XRayTubeDeltaLambda").XMLOutput(os,indent);
1265  os <<endl;
1266  this->GetPar("XRayTubeAlpha2Alpha1Ratio").XMLOutput(os,indent);
1267  break;
1268  }
1269  case WAVELENGTH_TOF:break;
1270  default: throw ObjCrystException("This radiation is not implemented !!");
1271  }
1272  os<<endl;
1273 
1274  indent--;
1275  tag.SetIsEndTag(true);
1276  for(int i=0;i<indent;i++) os << " " ;
1277  os <<tag;
1278 
1279  VFN_DEBUG_EXIT("Radiation::XMLOutput():"<<this->GetName(),5)
1280 }
1281 
1282 void Radiation::XMLInput(istream &is,const XMLCrystTag &tagg)
1283 {
1284  VFN_DEBUG_ENTRY("Radiation::XMLInput():"<<this->GetName(),5)
1285  string scattPowName;
1286  for(unsigned int i=0;i<tagg.GetNbAttribute();i++)
1287  {
1288  if("XRayTube"==tagg.GetAttributeName(i))
1289  if(tagg.GetAttributeValue(i)!="") // Something went wrong !
1290  this->SetWavelength(tagg.GetAttributeValue(i));
1291  }
1292 
1293  while(true)
1294  {
1295  XMLCrystTag tag(is);
1296  if(("Radiation"==tag.GetName())&&tag.IsEndTag())
1297  {
1298  // This will force the update of the 'used' status of the alpha1/alpha2 and delta lambda parameters
1299  this->SetWavelengthType((WavelengthType) mWavelengthType.GetChoice());
1300  VFN_DEBUG_EXIT("Radiation::Exit():"<<this->GetName(),5)
1301  return;
1302  }
1303  if("Option"==tag.GetName())
1304  {
1305  for(unsigned int i=0;i<tag.GetNbAttribute();i++)
1306  if("Name"==tag.GetAttributeName(i))
1307  {
1308  if("Radiation"==tag.GetAttributeValue(i)) mRadiationType.XMLInput(is,tag);
1309  if("Spectrum"==tag.GetAttributeValue(i)) mWavelengthType.XMLInput(is,tag);
1310  }
1311  }
1312  if("LinearPolarRate"==tag.GetName())
1313  {
1314  is>>mLinearPolarRate;
1315  XMLCrystTag junk(is);
1316  }
1317  if("XRayTubeDeltaLambda"==tag.GetName())
1318  {
1319  is>>mXRayTubeDeltaLambda;
1320  XMLCrystTag junk(is);
1321  }
1322  if("XRayTubeAlpha2Alpha1Ratio"==tag.GetName())
1323  {
1324  is>>mXRayTubeAlpha2Alpha1Ratio;
1325  XMLCrystTag junk(is);
1326  }
1327  if("Par"==tag.GetName())
1328  {
1329  for(unsigned int i=0;i<tag.GetNbAttribute();i++)
1330  {
1331  if("Name"==tag.GetAttributeName(i))
1332  {
1333  if("Wavelength"==tag.GetAttributeValue(i))
1334  {
1335  this->GetPar(mWavelength.data()).XMLInput(is,tag);
1336  break;
1337  }
1338  if("XRayTubeDeltaLambda"==tag.GetAttributeValue(i))
1339  {
1340  this->GetPar("XRayTubeDeltaLambda").XMLInput(is,tag);
1341  break;
1342  }
1343  if("XRayTubeAlpha2Alpha1Ratio"==tag.GetAttributeValue(i))
1344  {
1345  this->GetPar("XRayTubeAlpha2Alpha1Ratio").XMLInput(is,tag);
1346  break;
1347  }
1348  }
1349  }
1350  continue;
1351  }
1352  }
1353 }
1355 //
1356 // I/O DiffractionDataSingleCrystal
1357 //
1359 void DiffractionDataSingleCrystal::XMLOutput(ostream &os,int indent)const
1360 {
1361  VFN_DEBUG_ENTRY("DiffractionDataSingleCrystal::XMLOutput():"<<this->GetName(),5)
1362  for(int i=0;i<indent;i++) os << " " ;
1363  XMLCrystTag tag("DiffractionDataSingleCrystal");
1364  tag.AddAttribute("Name",mName);
1365  tag.AddAttribute("Crystal",this->GetCrystal().GetName());
1366  os <<tag<<endl;
1367  indent++;
1368 
1369  this->GetPar("Scale factor").XMLOutput(os,"Scale factor",indent);
1370  os <<endl;
1371 
1372  mRadiation.XMLOutput(os,indent);
1373  os <<endl;
1374 
1375  this->GetPar(&mGlobalBiso).XMLOutput(os,"globalBiso",indent);
1376  os <<endl;
1377 
1378  mGroupOption.XMLOutput(os,indent);
1379  os <<endl;
1380 
1381  for(int i=0;i<indent;i++) os << " " ;
1382  XMLCrystTag tag2("MaxSinThetaOvLambda");
1383  os << tag2<< mMaxSinThetaOvLambda;
1384  tag2.SetIsEndTag(true);
1385  os << tag2<<endl<<endl;
1386 
1387  if(mGroupOption.GetChoice()!=2)
1388  {
1389  XMLCrystTag tag3("HKLIobsSigmaWeightList");
1390  for(int i=0;i<indent;i++) os << " " ;
1391  os <<tag3<<endl;
1392 
1393  for(long j=0;j<this->GetNbRefl();j++)
1394  {
1395  for(int i=0;i<=indent;i++) os << " " ;
1396  os << mIntH(j) <<" "
1397  << mIntK(j) <<" "
1398  << mIntL(j) <<" "
1399  << mObsIntensity(j) <<" "
1400  << mObsSigma(j) <<" "
1401  << mWeight(j) <<" "
1402  <<endl;
1403  }
1404 
1405  tag3.SetIsEndTag(true);
1406  for(int i=0;i<indent;i++) os << " " ;
1407  os <<tag3<<endl;
1408  }
1409  else
1410  {
1411  XMLCrystTag tag3("HKLIobsSigmaWeightGROUPList");
1412  for(int i=0;i<indent;i++) os << " " ;
1413  os <<tag3<<endl;
1414 
1415  long first=0;
1416  for(long j=0;j<mNbGroup;j++)
1417  {
1418  XMLCrystTag tag4("HKLGroup");
1419  {
1420  stringstream s;
1421  s<<mGroupIobs(j);
1422  tag4.AddAttribute("Iobs",s.str());
1423  }
1424  {
1425  stringstream s;
1426  s<<mGroupSigma(j);
1427  tag4.AddAttribute("IobsSigma",s.str());
1428  }
1429  {
1430  stringstream s;
1431  s<<mGroupWeight(j);
1432  tag4.AddAttribute("Weight",s.str());
1433  }
1434  for(int i=0;i<=indent;i++) os << " " ;
1435  os<<tag4<<endl;
1436  for(long k=first;k<mGroupIndex(j);k++)
1437  {
1438  for(int i=0;i<=indent;i++) os << " " ;
1439  os << mIntH(k) <<" "<< mIntK(k) <<" "<< mIntL(k) <<" "<<endl;
1440  }
1441  for(int i=0;i<=indent;i++) os << " " ;
1442  tag4.SetIsEndTag(true);
1443  os<<tag4<<endl;
1444  first=mGroupIndex(j);
1445  }
1446 
1447  tag3.SetIsEndTag(true);
1448  for(int i=0;i<indent;i++) os << " " ;
1449  os <<tag3<<endl;
1450  }
1451 
1452  indent--;
1453  tag.SetIsEndTag(true);
1454  for(int i=0;i<indent;i++) os << " " ;
1455  os <<tag<<endl;
1456  VFN_DEBUG_EXIT("DiffractionDataSingleCrystal::XMLOutput():"<<this->GetName(),5)
1457 }
1458 
1460 {
1461  VFN_DEBUG_ENTRY("DiffractionDataSingleCrystal::XMLInput():"<<this->GetName(),5)
1462  for(unsigned int i=0;i<tagg.GetNbAttribute();i++)
1463  {
1464  if("Name"==tagg.GetAttributeName(i)) this->SetName(tagg.GetAttributeValue(i));
1465  if("Crystal"==tagg.GetAttributeName(i))
1466  this->SetCrystal(gCrystalRegistry.GetObj(tagg.GetAttributeValue(i)));
1467  }
1468  while(true)
1469  {
1470  XMLCrystTag tag(is);
1471  if(("DiffractionDataSingleCrystal"==tag.GetName())&&tag.IsEndTag())
1472  {
1473  this->UpdateDisplay();
1474  VFN_DEBUG_EXIT("DiffractionDataSingleCrystal::XMLInput():"<<this->GetName(),5)
1475  return;
1476  }
1477  if("Option"==tag.GetName())
1478  {
1479  for(unsigned int i=0;i<tag.GetNbAttribute();i++)
1480  if("Name"==tag.GetAttributeName(i))
1481  {
1482  string name=tag.GetAttributeValue(i);
1483  if(name=="Twinning correction") name="Group Reflections";
1484  mOptionRegistry.GetObj(name).XMLInput(is,tag);
1485  }
1486  continue;
1487  }
1488  if("Par"==tag.GetName())
1489  {
1490  for(unsigned int i=0;i<tag.GetNbAttribute();i++)
1491  {
1492  if("Name"==tag.GetAttributeName(i))
1493  {
1494  if("Scale factor"==tag.GetAttributeValue(i))
1495  {
1496  this->GetPar(&mScaleFactor).XMLInput(is,tag);
1497  break;
1498  }
1499  }
1500  }
1501  }
1502  if("Radiation"==tag.GetName()) mRadiation.XMLInput(is,tag);
1503  if("MaxSinThetaOvLambda"==tag.GetName())
1504  {
1505  is>>mMaxSinThetaOvLambda;
1506  XMLCrystTag junk(is);
1507  }
1508  if("Par"==tag.GetName())
1509  {
1510  for(unsigned int i=0;i<tag.GetNbAttribute();i++)
1511  {
1512  if("Name"==tag.GetAttributeName(i))
1513  {
1514  if("globalBiso"==tag.GetAttributeValue(i))
1515  {
1516  this->GetPar(&mGlobalBiso).XMLInput(is,tag);
1517  break;
1518  }
1519  }
1520  }
1521  }
1522  if("HKLIobsSigmaWeightList"==tag.GetName())
1523  {
1524  long nbrefl=0;
1525  CrystVector_long h(100),k(100),l(100);
1526  CrystVector_REAL iobs(100),sigma(100),weight(100);
1527  do
1528  {
1529  is >>h(nbrefl)>>k(nbrefl)>>l(nbrefl);
1530  iobs (nbrefl)=InputFloat(is); if(ISNAN_OR_INF(iobs (nbrefl))||(iobs (nbrefl)<0)) iobs (nbrefl)=1e-8;
1531  sigma (nbrefl)=InputFloat(is); if(ISNAN_OR_INF(sigma (nbrefl))||(sigma (nbrefl)<0)) sigma (nbrefl)=1e-8;
1532  weight(nbrefl)=InputFloat(is); if(ISNAN_OR_INF(weight(nbrefl))||(weight(nbrefl)<0)) weight(nbrefl)=1e-8;
1533 
1534  nbrefl++;
1535  if(nbrefl==iobs.numElements())
1536  {
1537  h.resizeAndPreserve(nbrefl+100);
1538  k.resizeAndPreserve(nbrefl+100);
1539  l.resizeAndPreserve(nbrefl+100);
1540  iobs.resizeAndPreserve(nbrefl+100);
1541  sigma.resizeAndPreserve(nbrefl+100);
1542  weight.resizeAndPreserve(nbrefl+100);
1543  }
1544  while(0==isgraph(is.peek())) is.get();
1545  //cout << is.peek()<<" "<<nbrefl<<endl;
1546  }
1547  while(is.peek()!='<');//until next tag
1548  XMLCrystTag junkEndTag(is);
1549 
1550  h.resizeAndPreserve(nbrefl);
1551  k.resizeAndPreserve(nbrefl);
1552  l.resizeAndPreserve(nbrefl);
1553  iobs.resizeAndPreserve(nbrefl);
1554  sigma.resizeAndPreserve(nbrefl);
1555  weight.resizeAndPreserve(nbrefl);
1556  this->SetHklIobs(h,k,l,iobs,sigma);
1557  this->SetWeight(weight);
1558  this->SortReflectionBySinThetaOverLambda();
1559  this->CalcIcalc();
1560  this->FitScaleFactorForRw();
1561  }
1562  if("HKLIobsSigmaWeightGROUPList"==tag.GetName())
1563  {
1564  mNbRefl=0;
1565  mNbGroup=0;
1566  // This must NOT be changed with this kind of data.
1567  mGroupOption.SetChoice(2);
1568  // So de-register the option so that it is hidden from the user's view
1569  mOptionRegistry.DeRegister(mGroupOption);
1570  mClockMaster.RemoveChild(mGroupOption.GetClock());
1571  mH.resize(500);
1572  mK.resize(500);
1573  mL.resize(500);
1574  mObsIntensity.resize(500);
1575  mObsSigma.resize(500);
1576  mGroupIndex.resize(500);
1577  mGroupIobs.resize(500);
1578  mGroupSigma.resize(500);
1579  mGroupWeight.resize(500);
1580  while(true)
1581  {
1582  XMLCrystTag grouptag(is);
1583  if(grouptag.GetName()=="HKLIobsSigmaWeightGROUPList") break;
1584  if(grouptag.GetName()=="HKLGroup")
1585  {
1586  for(unsigned int i=0;i<grouptag.GetNbAttribute();++i)
1587  {
1588  if(grouptag.GetAttributeName(i)=="Iobs")
1589  {
1590  stringstream sst;
1591  sst<<grouptag.GetAttributeValue(i);
1592  sst>>mGroupIobs(mNbGroup);
1593  continue;
1594  }
1595  if(grouptag.GetAttributeName(i)=="IobsSigma")
1596  {
1597  stringstream sst;
1598  sst<<grouptag.GetAttributeValue(i);
1599  sst>>mGroupSigma(mNbGroup);
1600  continue;
1601  }
1602  if(grouptag.GetAttributeName(i)=="Weight")
1603  {
1604  stringstream sst;
1605  sst<<grouptag.GetAttributeValue(i);
1606  sst>>mGroupWeight(mNbGroup);
1607  continue;
1608  }
1609  }
1610  VFN_DEBUG_MESSAGE("Group #"<<mNbGroup<<" ,Iobs="<<mGroupIobs(mNbGroup)<<" ,Sigma="<<mGroupSigma(mNbGroup)<<" ,Weight="<<mGroupWeight(mNbGroup),2)
1611  do
1612  {
1613  is >>mH(mNbRefl)>>mK(mNbRefl)>>mL(mNbRefl);
1614  VFN_DEBUG_MESSAGE(" "<<mH(mNbRefl)<<" "<<mK(mNbRefl)<<" "<<mL(mNbRefl),2)
1615  mGroupIndex(mNbRefl)=mNbGroup;
1616  mNbRefl++;
1617  if(mNbRefl==mH.numElements())
1618  {
1619  mH.resizeAndPreserve(mNbRefl+500);
1620  mK.resizeAndPreserve(mNbRefl+500);
1621  mL.resizeAndPreserve(mNbRefl+500);
1622  mObsIntensity.resizeAndPreserve(mNbRefl+500);
1623  mObsSigma.resizeAndPreserve(mNbRefl+500);
1624  mGroupIndex.resizeAndPreserve(mNbRefl+500);
1625  }
1626  while(0==isgraph(is.peek())) is.get();
1627  }
1628  while(is.peek()!='<');//until end tag
1629  XMLCrystTag junkEndTag(is);
1630  if(++mNbGroup==mGroupIobs.numElements())
1631  {
1632  mGroupIobs.resizeAndPreserve(mNbGroup+500);
1633  mGroupSigma.resizeAndPreserve(mNbGroup+500);
1634  mGroupWeight.resizeAndPreserve(mNbGroup+500);
1635  }
1636  }
1637  }
1638  mH.resizeAndPreserve(mNbRefl);
1639  mK.resizeAndPreserve(mNbRefl);
1640  mL.resizeAndPreserve(mNbRefl);
1641  mObsIntensity.resizeAndPreserve(mNbRefl);
1642  mObsSigma.resizeAndPreserve(mNbRefl);
1643  mWeight.resizeAndPreserve(mNbRefl);
1644  mGroupIndex.resizeAndPreserve(mNbRefl);
1645 
1646  mGroupIobs.resizeAndPreserve(mNbGroup);
1647  mGroupWeight.resizeAndPreserve(mNbGroup);
1648  mGroupSigma.resizeAndPreserve(mNbGroup);
1649 
1650  mHasObservedData=true;
1651 
1652  mMultiplicity.resize(mNbRefl);
1653  mMultiplicity=1;
1654 
1655  this->PrepareHKLarrays();
1656  this->SortReflectionBySinThetaOverLambda();
1657  }
1658  }
1659 }
1661 //
1662 // I/O PowderPatternBackground
1663 //
1665 void PowderPatternBackground::XMLOutput(ostream &os,int indent)const
1666 {
1667  VFN_DEBUG_ENTRY("PowderPatternBackground::XMLOutput():"<<this->GetName(),5)
1668  for(int i=0;i<indent;i++) os << " " ;
1669  XMLCrystTag tag("PowderPatternBackground");
1670  tag.AddAttribute("Name",this->GetName());
1671  os <<tag<<endl;
1672  indent++;
1673 
1674  mInterpolationModel.XMLOutput(os,indent);
1675  os<<endl;
1676 
1677  XMLCrystTag tag2("XIntensityList");
1678  for(int i=0;i<indent;i++) os << " " ;
1679  os <<tag2<<endl;
1680 
1681  REAL scale=1.0;
1682  if(this->GetParentPowderPattern().GetRadiation().GetWavelengthType()!=WAVELENGTH_TOF)
1683  scale=RAD2DEG;
1684 
1685  for(long j=0;j<mBackgroundNbPoint;j++)
1686  {
1687 
1688  for(int i=0;i<=indent;i++) os << " " ;
1689  os << mBackgroundInterpPointX(j)*scale <<" "
1690  << mBackgroundInterpPointIntensity(j) <<" "
1691  << !this->GetPar(mBackgroundInterpPointIntensity.data()+j).IsFixed()<<" "
1692  <<endl;
1693  }
1694 
1695  tag2.SetIsEndTag(true);
1696  for(int i=0;i<indent;i++) os << " " ;
1697  os <<tag2<<endl;
1698 
1699  #ifdef USE_BACKGROUND_MAXLIKE_ERROR
1700  this->GetPar("ML Model Error").XMLOutput(os,"ML Model Error",indent);
1701  os <<endl;
1702  #endif
1703 
1704  indent--;
1705  tag.SetIsEndTag(true);
1706  for(int i=0;i<indent;i++) os << " " ;
1707  os <<tag<<endl;
1708  VFN_DEBUG_EXIT("PowderPatternBackground::XMLOutput():"<<this->GetName(),5)
1709 }
1710 
1711 void PowderPatternBackground::XMLInput(istream &is,const XMLCrystTag &tagg)
1712 {
1713  VFN_DEBUG_ENTRY("PowderPatternBackground::XMLInput():"<<this->GetName(),5)
1714  for(unsigned int i=0;i<tagg.GetNbAttribute();i++)
1715  {
1716  if("Name"==tagg.GetAttributeName(i)) this->SetName(tagg.GetAttributeValue(i));
1717  if("Interpolation"==tagg.GetAttributeName(i))
1718  {// Obsolete, but we must still read this
1719  if("Linear"==tagg.GetAttributeValue(i)) mInterpolationModel.SetChoice(0);
1720  if("Spline"==tagg.GetAttributeValue(i)) mInterpolationModel.SetChoice(1);
1721  }
1722  }
1723  while(true)
1724  {
1725  XMLCrystTag tag(is);
1726  if(("PowderPatternBackground"==tag.GetName())&&tag.IsEndTag())
1727  {
1728  this->UpdateDisplay();
1729  VFN_DEBUG_EXIT("PowderPatternBackground::Exit():"<<this->GetName(),5)
1730  return;
1731  }
1732  if(("TThetaIntensityList"==tag.GetName())||("XIntensityList"==tag.GetName()))
1733  {
1734  long nbPoint=0;
1735  CrystVector_REAL bckgd2Theta(100);
1736  CrystVector_REAL bckgd(100);
1737  CrystVector_bool fix(100);
1738  do
1739  {
1740  VFN_DEBUG_MESSAGE("PowderPatternBackground::XMLInput():"<<mBackgroundNbPoint,1)
1741  is >>bckgd2Theta(nbPoint)
1742  >>bckgd(nbPoint)
1743  >>fix(nbPoint);
1744  nbPoint++;
1745  if(nbPoint==bckgd2Theta.numElements())
1746  {
1747  bckgd2Theta.resizeAndPreserve(nbPoint+100);
1748  bckgd.resizeAndPreserve(nbPoint+100);
1749  fix.resizeAndPreserve(nbPoint+100);
1750  }
1751  while(0==isgraph(is.peek())) is.get();//Why do I need that ?
1752  //cout << is.peek()<<" "<<nbrefl<<endl;
1753  }
1754  while(is.peek()!='<');//until next tag
1755  bckgd2Theta.resizeAndPreserve(nbPoint);
1756  bckgd.resizeAndPreserve(nbPoint);
1757  if(this->GetParentPowderPattern().GetRadiation().GetWavelengthType()!=WAVELENGTH_TOF)
1758  bckgd2Theta*= DEG2RAD;
1759  this->SetInterpPoints(bckgd2Theta,bckgd);
1760  this->InitRefParList();
1761  //read closing tag
1762  XMLCrystTag junkEndTag(is);
1763  }
1764  if("Par"==tag.GetName())
1765  {
1766  for(unsigned int i=0;i<tag.GetNbAttribute();i++)
1767  {
1768  if("Name"==tag.GetAttributeName(i))
1769  {
1770  if("ML Model Error"==tag.GetAttributeValue(i))
1771  {
1772  #ifdef USE_BACKGROUND_MAXLIKE_ERROR
1773  this->GetPar("ML Model Error").XMLInput(is,tag);
1774  break;
1775  #endif
1776  }
1777  }
1778  }
1779  }
1780  if("Option"==tag.GetName())
1781  {
1782  for(unsigned int i=0;i<tag.GetNbAttribute();i++)
1783  if("Name"==tag.GetAttributeName(i))
1784  mOptionRegistry.GetObj(tag.GetAttributeValue(i)).XMLInput(is,tag);
1785  continue;
1786  }
1787  }
1788 }
1790 //
1791 // I/O PowderPatternDiffraction
1792 //
1794 void PowderPatternDiffraction::XMLOutput(ostream &os,int indent)const
1795 {
1796  VFN_DEBUG_ENTRY("PowderPatternDiffraction::XMLOutput():"<<this->GetName(),5)
1797  for(int i=0;i<indent;i++) os << " " ;
1798  XMLCrystTag tag("PowderPatternCrystal");
1799  tag.AddAttribute("Name",this->GetName());
1800  tag.AddAttribute("Crystal",this->GetCrystal().GetName());
1801  {
1802  stringstream ss;
1803  ss<<this->IsIgnoringImagScattFact();
1804  tag.AddAttribute("IgnoreImagScattFact",ss.str());
1805  }
1806  os <<tag<<endl;
1807  indent++;
1808 
1809  if(mFreezeLatticePar)
1810  {
1811  XMLCrystTag t("FrozenLatticePar");
1812  t.AddAttribute("a", (boost::format("%f")%mFrozenLatticePar(0)).str() );
1813  t.AddAttribute("b", (boost::format("%f")%mFrozenLatticePar(1)).str() );
1814  t.AddAttribute("c", (boost::format("%f")%mFrozenLatticePar(2)).str() );
1815  t.AddAttribute("alpha", (boost::format("%f")%(mFrozenLatticePar(3)*180/M_PI)).str() );
1816  t.AddAttribute("beta" , (boost::format("%f")%(mFrozenLatticePar(4)*180/M_PI)).str() );
1817  t.AddAttribute("gamma", (boost::format("%f")%(mFrozenLatticePar(5)*180/M_PI)).str() );
1818  t.SetIsEmptyTag(true);
1819  for(int i=0;i<indent;i++) os << " " ;
1820  os<<t<<endl;
1821  }
1822 
1823  if(mpReflectionProfile!=0) mpReflectionProfile->XMLOutput(os,indent);
1824 
1825  this->GetPar(&mGlobalBiso).XMLOutput(os,"globalBiso",indent);
1826  os <<endl;
1827 
1828  if(mCorrTextureMarchDollase.GetNbPhase()>0)
1829  {
1830  mCorrTextureMarchDollase.XMLOutput(os,indent);
1831  }
1832 
1833  mCorrTextureEllipsoid.XMLOutput(os,indent);
1834 
1835  #if 0
1836  if(mFhklObsSq.numElements()>0)
1837  {
1838  XMLCrystTag tag2("FhklObsSq");
1839  for(int i=0;i<indent;i++) os << " " ;
1840  os <<tag2<<endl;
1841 
1842  for(long j=0;j<this->GetNbRefl();j++)
1843  {
1844  for(int i=0;i<=indent;i++) os << " " ;
1845  os << mIntH(j) <<" "
1846  << mIntK(j) <<" "
1847  << mIntL(j) <<" "
1848  << mFhklObsSq(j) <<endl;
1849  }
1850 
1851  tag2.SetIsEndTag(true);
1852  for(int i=0;i<indent;i++) os << " " ;
1853  os <<tag2<<endl;
1854  }
1855  #else
1856  if(mpLeBailData!=0) mpLeBailData->XMLOutput(os,indent);
1857  #endif
1858 
1859  indent--;
1860  tag.SetIsEndTag(true);
1861  for(int i=0;i<indent;i++) os << " " ;
1862  os <<tag<<endl;
1863  VFN_DEBUG_EXIT("PowderPatternDiffraction::XMLOutput():"<<this->GetName(),5)
1864 }
1865 
1867 {
1868  VFN_DEBUG_ENTRY("PowderPatternDiffraction::XMLInput():"<<this->GetName(),5)
1869  for(unsigned int i=0;i<tagg.GetNbAttribute();i++)
1870  {
1871  if("Name"==tagg.GetAttributeName(i)) this->SetName(tagg.GetAttributeValue(i));
1872  if("Crystal"==tagg.GetAttributeName(i))
1873  this->SetCrystal(gCrystalRegistry.GetObj(tagg.GetAttributeValue(i)));
1874  if("NeedLorentzCorr"==tagg.GetAttributeName(i))
1875  {
1876  stringstream ss(tagg.GetAttributeValue(i));
1877  bool b;
1878  ss>>b;
1879  //mNeedLorentzCorr=b;
1880  //mClockLorentzPolarSlitCorrPar.Reset();
1881  }
1882  if("NeedPolarCorr"==tagg.GetAttributeName(i))
1883  {
1884  stringstream ss(tagg.GetAttributeValue(i));
1885  bool b;
1886  ss>>b;
1887  //mNeedPolarCorr=b;
1888  //mClockLorentzPolarSlitCorrPar.Reset();
1889  }
1890  if("Polar_AFactor"==tagg.GetAttributeName(i))
1891  {
1892  stringstream ss(tagg.GetAttributeValue(i));
1893  float b;
1894  ss>>b;
1895  //mPolarAfactor=b;
1896  //mClockLorentzPolarSlitCorrPar.Reset();
1897  }
1898  if("NeedSlitApertureCorr"==tagg.GetAttributeName(i))
1899  {
1900  stringstream ss(tagg.GetAttributeValue(i));
1901  bool b;
1902  ss>>b;
1903  //mNeedSlitApertureCorr=b;
1904  //mClockLorentzPolarSlitCorrPar.Reset();
1905  }
1906  if("IgnoreImagScattFact"==tagg.GetAttributeName(i))
1907  {
1908  stringstream ss(tagg.GetAttributeValue(i));
1909  bool b;
1910  ss>>b;
1911  this->SetIsIgnoringImagScattFact(b);
1912  mClockLorentzPolarSlitCorrPar.Reset();
1913  }
1914  }
1915  while(true)
1916  {
1917  XMLCrystTag tag(is);
1918  if(("PowderPatternCrystal"==tag.GetName())&&tag.IsEndTag())
1919  {
1920  this->UpdateDisplay();
1921  VFN_DEBUG_EXIT("PowderPatternDiffraction::Exit():"<<this->GetName(),5)
1922  return;
1923  }
1924  if("Par"==tag.GetName())
1925  {
1926  for(unsigned int i=0;i<tag.GetNbAttribute();i++)
1927  {
1928  if("Name"==tag.GetAttributeName(i))
1929  {
1930  if("globalBiso"==tag.GetAttributeValue(i))
1931  {
1932  this->GetPar(&mGlobalBiso).XMLInput(is,tag);
1933  break;
1934  }
1935  if("U"==tag.GetAttributeValue(i))
1936  {
1937  mpReflectionProfile->GetPar("U").XMLInput(is,tag);
1938  break;
1939  }
1940  if("V"==tag.GetAttributeValue(i))
1941  {
1942  mpReflectionProfile->GetPar("V").XMLInput(is,tag);
1943  break;
1944  }
1945  if("W"==tag.GetAttributeValue(i))
1946  {
1947  mpReflectionProfile->GetPar("W").XMLInput(is,tag);
1948  break;
1949  }
1950  if("Eta0"==tag.GetAttributeValue(i))
1951  {
1952  mpReflectionProfile->GetPar("Eta0").XMLInput(is,tag);
1953  break;
1954  }
1955  if("Eta1"==tag.GetAttributeValue(i))
1956  {
1957  mpReflectionProfile->GetPar("Eta1").XMLInput(is,tag);
1958  break;
1959  }
1960  if("W0"==tag.GetAttributeValue(i))
1961  {
1962  //:TODO: mpReflectionProfile->GetPar("Eta0").XMLInput(is,tag);
1963  break;
1964  }
1965  if("W1"==tag.GetAttributeValue(i))
1966  {
1967  //:TODO: mpReflectionProfile->GetPar("Eta1").XMLInput(is,tag);
1968  break;
1969  }
1970  if("W2"==tag.GetAttributeValue(i))
1971  {
1972  //:TODO: mpReflectionProfile->GetPar("Eta2").XMLInput(is,tag);
1973  break;
1974  }
1975  }
1976  }
1977  continue;
1978  }
1979  if("Option"==tag.GetName())
1980  {
1981  for(unsigned int i=0;i<tag.GetNbAttribute();i++)
1982  {
1983  if("Name"==tag.GetAttributeName(i))
1984  {
1985  if("Profile Type"!=tag.GetAttributeValue(i))
1986  mOptionRegistry.GetObj(tag.GetAttributeValue(i)).XMLInput(is,tag);
1987  }
1988  }
1989  continue;
1990  }
1991  if("TextureMarchDollase"==tag.GetName())
1992  {
1993  mCorrTextureMarchDollase.XMLInput(is,tag);
1994  continue;
1995  }
1996  if("TextureEllipsoid"==tag.GetName())
1997  {
1998  mCorrTextureEllipsoid.XMLInput(is,tag);
1999  continue;
2000  }
2001  if("ReflectionProfilePseudoVoigt"==tag.GetName())
2002  {
2003  if(mpReflectionProfile==0)
2004  {
2005  mpReflectionProfile=new ReflectionProfilePseudoVoigt;
2006  }
2007  else
2008  if(mpReflectionProfile->GetClassName()!="ReflectionProfilePseudoVoigt")
2009  {
2010  this->SetProfile(new ReflectionProfilePseudoVoigt);
2011  }
2012  mpReflectionProfile->XMLInput(is,tag);
2013  continue;
2014  }
2015  if("ReflectionProfilePseudoVoigtAnisotropic"==tag.GetName())
2016  {
2017  if(mpReflectionProfile==0)
2018  {
2019  mpReflectionProfile=new ReflectionProfilePseudoVoigtAnisotropic;
2020  }
2021  else
2022  if(mpReflectionProfile->GetClassName()!="ReflectionProfilePseudoVoigtAnisotropic")
2023  {
2024  this->SetProfile(new ReflectionProfilePseudoVoigtAnisotropic);
2025  }
2026  mpReflectionProfile->XMLInput(is,tag);
2027  continue;
2028  }
2029  if("ReflectionProfileDoubleExponentialPseudoVoigt"==tag.GetName())
2030  {
2031  if(mpReflectionProfile==0)
2032  {
2033  mpReflectionProfile
2034  =new ReflectionProfileDoubleExponentialPseudoVoigt(this->GetCrystal());
2035  }
2036  else
2037  if(mpReflectionProfile->GetClassName()!="ReflectionProfileDoubleExponentialPseudoVoigt")
2038  {
2039  this->SetProfile(new ReflectionProfileDoubleExponentialPseudoVoigt(this->GetCrystal()));
2040  }
2041  mpReflectionProfile->XMLInput(is,tag);
2042  continue;
2043  }
2044  if("FhklObsSq"==tag.GetName())
2045  {// old-style extracted data
2046  long nbrefl=0;
2047  CrystVector_REAL iobs(100),sigma;
2048  CrystVector_long h(100),k(100),l(100);
2049  mFhklObsSq.resize(100);
2050  do
2051  {
2052  is >>h(nbrefl)>>k(nbrefl)>>l(nbrefl)>>iobs(nbrefl);
2053  nbrefl++;
2054  if(nbrefl==h.numElements())
2055  {
2056  h.resizeAndPreserve(nbrefl+100);
2057  k.resizeAndPreserve(nbrefl+100);
2058  l.resizeAndPreserve(nbrefl+100);
2059  iobs.resizeAndPreserve(nbrefl+100);
2060  }
2061  while(0==isgraph(is.peek())) is.get();
2062  }
2063  while(is.peek()!='<');//until next tag
2064  XMLCrystTag junkEndTag(is);
2065  h.resizeAndPreserve(nbrefl);
2066  k.resizeAndPreserve(nbrefl);
2067  l.resizeAndPreserve(nbrefl);
2068  iobs.resizeAndPreserve(nbrefl);
2069  sigma.resizeAndPreserve(nbrefl);
2070  sigma=1;
2071 
2072  if(mpLeBailData==0) mpLeBailData=new DiffractionDataSingleCrystal(this->GetCrystal(),false);
2073 
2074  mpLeBailData->SetHklIobs(h,k,l,iobs,sigma);
2075  mpLeBailData->SetWavelength(this->GetRadiation().GetWavelength()(0));
2076  mpLeBailData->SetRadiationType(this->GetRadiation().GetRadiationType());
2077 
2078  // Estimate resolution
2079  const REAL min=iobs.max()*1e-6;
2080  unsigned long iresol=0;
2081  for(long i=0;i<nbrefl;++i) if(iobs(i)>min) iresol=i;
2082  char buf[200];
2083  sprintf(buf,"LeBail (d=%4.2fA?):",1/(2*abs(mpLeBailData->GetSinThetaOverLambda()(iresol))+1e-6));
2084  mpLeBailData->SetName(string(buf)+this->GetCrystal().GetName());
2085  //mpLeBailData->SetName(string("LeBail (resol=?):")+this->GetCrystal().GetName());
2086  }
2087  if("DiffractionDataSingleCrystal"==tag.GetName())
2088  {// Le Bail data
2089  if(mpLeBailData==0) mpLeBailData=new DiffractionDataSingleCrystal(this->GetCrystal(),false);
2090  mpLeBailData->XMLInput(is,tag);
2091  }
2092  if("FrozenLatticePar"==tag.GetName())
2093  {
2094  this->FreezeLatticePar(true);
2095  for(unsigned int i=0;i<tag.GetNbAttribute();i++)
2096  {
2097  if("a"==tag.GetAttributeName(i))
2098  {
2099  stringstream ss(tag.GetAttributeValue(i));
2100  //ss.imbue(std::locale::classic());
2101  float v;
2102  ss>>v;
2103  this->SetFrozenLatticePar(0,v);
2104  }
2105  if("b"==tag.GetAttributeName(i))
2106  {
2107  stringstream ss(tag.GetAttributeValue(i));
2108  //ss.imbue(std::locale::classic());
2109  float v;
2110  ss>>v;
2111  this->SetFrozenLatticePar(1,v);
2112  }
2113  if("c"==tag.GetAttributeName(i))
2114  {
2115  stringstream ss(tag.GetAttributeValue(i));
2116  //ss.imbue(std::locale::classic());
2117  float v;
2118  ss>>v;
2119  this->SetFrozenLatticePar(2,v);
2120  }
2121  if("alpha"==tag.GetAttributeName(i))
2122  {
2123  stringstream ss(tag.GetAttributeValue(i));
2124  //ss.imbue(std::locale::classic());
2125  float v;
2126  ss>>v;
2127  this->SetFrozenLatticePar(3,v*M_PI/180);
2128  }
2129  if("beta"==tag.GetAttributeName(i))
2130  {
2131  stringstream ss(tag.GetAttributeValue(i));
2132  //ss.imbue(std::locale::classic());
2133  float v;
2134  ss>>v;
2135  this->SetFrozenLatticePar(4,v*M_PI/180);
2136  }
2137  if("gamma"==tag.GetAttributeName(i))
2138  {
2139  stringstream ss(tag.GetAttributeValue(i));
2140  //ss.imbue(std::locale::classic());
2141  float v;
2142  ss>>v;
2143  this->SetFrozenLatticePar(5,v*M_PI/180);
2144  }
2145  }
2146  }
2147  }
2148 }
2150 //
2151 // I/O PowderPattern
2152 //
2154 void PowderPattern::XMLOutput(ostream &os,int indent)const
2155 {
2156  VFN_DEBUG_ENTRY("PowderPattern::XMLOutput():"<<this->GetName(),5)
2157  for(int i=0;i<indent;i++) os << " " ;
2158  XMLCrystTag tag("PowderPattern");
2159  tag.AddAttribute("Name",mName);
2160  os <<tag<<endl;
2161  indent++;
2162 
2163  this->GetPar(&mXZero).XMLOutput(os,"Zero",indent);
2164  os <<endl;
2165  if(this->GetRadiation().GetWavelengthType()==WAVELENGTH_TOF)
2166  {
2167  this->GetPar(&mDIFC).XMLOutput(os,"TOF-DIFC",indent);
2168  os <<endl;
2169 
2170  this->GetPar(&mDIFA).XMLOutput(os,"TOF-DIFA",indent);
2171  os <<endl;
2172  }
2173  else
2174  {
2175  this->GetPar(&m2ThetaDisplacement).XMLOutput(os,"2ThetaDisplacement",indent);
2176  os <<endl;
2177 
2178  this->GetPar(&m2ThetaTransparency).XMLOutput(os,"2ThetaTransparency",indent);
2179  os <<endl;
2180  }
2181  if(mMuR>0)
2182  {
2183  this->GetPar(&mMuR).XMLOutput(os,"MuR",indent);
2184  os <<endl;
2185  }
2186 
2187  for(unsigned int i=0;i<this->GetNbOption();i++)
2188  {
2189  this->GetOption(i).XMLOutput(os,indent);
2190  os <<endl<<endl;
2191  }
2192 
2193  mRadiation.XMLOutput(os,indent);
2194  os <<endl;
2195  {
2196  for(int i=0;i<indent;i++) os << " " ;
2197  XMLCrystTag tag2("MaxSinThetaOvLambda");
2198  os << tag2<< mMaxSinThetaOvLambda;
2199  tag2.SetIsEndTag(true);
2200  os << tag2<<endl<<endl;
2201  }
2202 
2203  for(int j=0;j<mPowderPatternComponentRegistry.GetNb();j++)
2204  {
2205  mPowderPatternComponentRegistry.GetObj(j).XMLOutput(os,indent);
2206  XMLCrystTag tagg("PowderPatternComponent",false,true);
2207  {
2208  stringstream ss;
2209  ss<<mScaleFactor(j);
2210  tagg.AddAttribute("Scale",ss.str());
2211  }
2212  tagg.AddAttribute("Name",mPowderPatternComponentRegistry.GetObj(j).GetName());
2213  os<<endl;
2214  for(int i=0;i<indent;i++) os << " " ;
2215  os<<tagg<<endl<<endl;
2216  }
2217  XMLCrystTag tag2("XIobsSigmaWeightList");
2218  for(int i=0;i<indent;i++) os << " " ;
2219  os<<tag2<<endl;
2220 
2221  REAL scale=1.0;
2222  if(this->GetRadiation().GetWavelengthType()!=WAVELENGTH_TOF)
2223  scale=RAD2DEG;
2224 
2225  for(unsigned long j=0;j<this->GetNbPoint();j++)
2226  {
2227  for(int i=0;i<=indent;i++) os << " " ;
2228  os << scale*mX(j) <<" "
2229  << mPowderPatternObs(j) <<" "
2230  << mPowderPatternObsSigma(j) <<" "
2231  << mPowderPatternWeight(j) <<" "
2232  <<endl;
2233  }
2234  tag2.SetIsEndTag(true);
2235  for(int i=0;i<indent;i++) os << " " ;
2236  os<<tag2<<endl;
2237 
2238  for(int j=0;j<mExcludedRegionMinX.numElements();j++)
2239  {
2240  XMLCrystTag tag3("ExcludeX");
2241  for(int i=0;i<indent;i++) os << " " ;
2242  if(this->GetRadiation().GetWavelengthType()==WAVELENGTH_TOF)
2243  {
2244  os << tag3
2245  << mExcludedRegionMinX(j) <<" "
2246  << mExcludedRegionMaxX(j) ;
2247  }
2248  else
2249  {
2250  os << tag3
2251  << mExcludedRegionMinX(j)*RAD2DEG <<" "
2252  << mExcludedRegionMaxX(j)*RAD2DEG ;
2253  }
2254  tag3.SetIsEndTag(true);
2255  os<<tag3<<endl;
2256  }
2257 
2258 
2259  indent--;
2260  tag.SetIsEndTag(true);
2261  for(int i=0;i<indent;i++) os << " " ;
2262  os <<tag<<endl;
2263  VFN_DEBUG_EXIT("PowderPattern::XMLOutput():"<<this->GetName(),5)
2264 }
2265 
2266 void PowderPattern::XMLInput(istream &is,const XMLCrystTag &tagg)
2267 {
2268  VFN_DEBUG_ENTRY("PowderPattern::XMLInput():"<<this->GetName(),5)
2269  for(unsigned int i=0;i<tagg.GetNbAttribute();i++)
2270  {
2271  if("Name"==tagg.GetAttributeName(i)) this->SetName(tagg.GetAttributeValue(i));
2272  }
2273  while(true)
2274  {
2275  XMLCrystTag tag(is);
2276  if(("PowderPattern"==tag.GetName())&&tag.IsEndTag())
2277  {
2278  this->UpdateDisplay();
2279  VFN_DEBUG_EXIT("PowderPattern::Exit():"<<this->GetName(),5)
2280  return;
2281  }
2282  if("Radiation"==tag.GetName()) mRadiation.XMLInput(is,tag);
2283  if("MaxSinThetaOvLambda"==tag.GetName())
2284  {
2285  is>>mMaxSinThetaOvLambda;
2286  XMLCrystTag junk(is);
2287  }
2288  if("Par"==tag.GetName())
2289  {
2290  for(unsigned int i=0;i<tag.GetNbAttribute();i++)
2291  {
2292  if("Name"==tag.GetAttributeName(i))
2293  {
2294  if(("2ThetaZero"==tag.GetAttributeValue(i)) ||("Zero"==tag.GetAttributeValue(i)))
2295  {
2296  this->GetPar(&mXZero).XMLInput(is,tag);
2297  break;
2298  }
2299  if("2ThetaDisplacement"==tag.GetAttributeValue(i))
2300  {
2301  this->GetPar(&m2ThetaDisplacement).XMLInput(is,tag);
2302  break;
2303  }
2304  if("2ThetaTransparency"==tag.GetAttributeValue(i))
2305  {
2306  this->GetPar(&m2ThetaTransparency).XMLInput(is,tag);
2307  break;
2308  }
2309  if("TOF-DIFC"==tag.GetAttributeValue(i))
2310  {
2311  this->GetPar(&mDIFC).XMLInput(is,tag);
2312  break;
2313  }
2314  if("TOF-DIFA"==tag.GetAttributeValue(i))
2315  {
2316  this->GetPar(&mDIFA).XMLInput(is,tag);
2317  break;
2318  }
2319  if("MuR"==tag.GetAttributeValue(i))
2320  {
2321  this->GetPar(&mMuR).XMLInput(is,tag);
2322  break;
2323  }
2324  }
2325  }
2326  continue;
2327  }
2328  if("Option"==tag.GetName())
2329  {
2330  for(unsigned int i=0;i<tag.GetNbAttribute();i++)
2331  if("Name"==tag.GetAttributeName(i))
2332  mOptionRegistry.GetObj(tag.GetAttributeValue(i)).XMLInput(is,tag);
2333  continue;
2334  }
2335  if("PowderPatternBackground"==tag.GetName())
2336  {
2338  comp->SetParentPowderPattern(*this);
2339  comp->XMLInput(is,tag);
2340  continue;
2341  }
2342  if("PowderPatternCrystal"==tag.GetName())
2343  {
2345  comp->SetParentPowderPattern(*this);
2346  comp->XMLInput(is,tag);
2347  continue;
2348  }
2349  if("PowderPatternComponent"==tag.GetName())
2350  {
2351  REAL scale=1.0;
2352  string name;
2353  for(unsigned int i=0;i<tag.GetNbAttribute();i++)
2354  {
2355  if("Scale"==tag.GetAttributeName(i))
2356  {
2357  stringstream ss(tag.GetAttributeValue(i));
2358  ss>>scale;
2359  continue;
2360  }
2361  if("Name"==tag.GetAttributeName(i)) name=tag.GetAttributeValue(i);
2362  }
2363  this->AddPowderPatternComponent(gPowderPatternComponentRegistry.GetObj(name));
2364  mScaleFactor(mPowderPatternComponentRegistry.GetNb()-1)=scale;
2365  VFN_DEBUG_MESSAGE("->Adding Component :"<<name<<"with scale="<<scale,8);
2366  continue;
2367  }
2368  if("ExcludeX"==tag.GetName())
2369  {
2370  float min,max;
2371  is>>min>>max;
2372  if(this->GetRadiation().GetWavelengthType()==WAVELENGTH_TOF)
2373  this->AddExcludedRegion(min,max);
2374  else this->AddExcludedRegion(min*DEG2RAD,max*DEG2RAD);
2375  XMLCrystTag end(is);
2376  continue;
2377  }
2378  if("IobsSigmaWeightList"==tag.GetName())
2379  {
2380  // Old version, just for 2theta-intensity pattern (no TOF)
2381  VFN_DEBUG_ENTRY("Loading Iobs-Sigma-Weight List...",8);
2382  REAL min,step;
2383  for(unsigned int i=0;i<tag.GetNbAttribute();i++)
2384  {
2385  if("TThetaMin"==tag.GetAttributeName(i))
2386  {
2387  stringstream ss(tag.GetAttributeValue(i));
2388  ss>>min;
2389  VFN_DEBUG_MESSAGE("2Theta min="<<min,8);
2390  min*=DEG2RAD;
2391  }
2392  if("TThetaStep"==tag.GetAttributeName(i))
2393  {
2394  stringstream ss(tag.GetAttributeValue(i));
2395  ss>>step;
2396  VFN_DEBUG_MESSAGE("2Theta step="<<step<<tag.GetAttributeValue(i),8);
2397  step*=DEG2RAD;
2398  }
2399  }
2400  while(0==isgraph(is.peek())) is.get();
2401  if(is.peek()=='<')
2402  {
2403  cout <<"PowderPattern::XMLInput(): no data point in the powder pattern !"<<endl;
2404  XMLCrystTag junk(is);
2405  VFN_DEBUG_EXIT("Loading Iobs-Sigma-Weight List...",8);
2406  continue;
2407  }
2408  mNbPoint=0;
2409  mPowderPatternObs.resize(500);
2410  mPowderPatternObsSigma.resize(500);
2411  mPowderPatternWeight.resize(500);
2412  do
2413  {
2414  is >>mPowderPatternObs(mNbPoint)
2415  >>mPowderPatternObsSigma(mNbPoint)
2416  >>mPowderPatternWeight(mNbPoint);
2417  mNbPoint++;
2418  VFN_DEBUG_MESSAGE("Point #"<<mNbPoint,5);
2419  if(mNbPoint==(unsigned long)mPowderPatternObs.numElements())
2420  {
2421  mPowderPatternObs.resizeAndPreserve(mNbPoint+500);
2422  mPowderPatternObsSigma.resizeAndPreserve(mNbPoint+500);
2423  mPowderPatternWeight.resizeAndPreserve(mNbPoint+500);
2424  }
2425  while(0==isgraph(is.peek())) is.get();
2426  }
2427  while(is.peek()!='<');//until next tag
2428  this->SetPowderPatternPar(min,step,mNbPoint);
2429  mClockPowderPatternPar.Click();
2430 
2431  XMLCrystTag junk(is);
2432  VFN_DEBUG_EXIT("Loading Iobs-Sigma-Weight List...",8);
2433  continue;
2434  }
2435  if("XIobsSigmaWeightList"==tag.GetName())
2436  {
2437  VFN_DEBUG_ENTRY("Loading X-Iobs-Sigma-Weight List...",8);
2438  while(0==isgraph(is.peek())) is.get();
2439  if(is.peek()=='<')
2440  {
2441  cout <<"PowderPattern::XMLInput(): no data point in the powder pattern !"<<endl;
2442  XMLCrystTag junk(is);
2443  VFN_DEBUG_EXIT("Loading Iobs-Sigma-Weight List...",8);
2444  continue;
2445  }
2446  mNbPoint=0;
2447  mX.resize(500);
2448  mPowderPatternObs.resize(500);
2449  mPowderPatternObsSigma.resize(500);
2450  mPowderPatternWeight.resize(500);
2451  do
2452  {
2453  is >>mX(mNbPoint)
2454  >>mPowderPatternObs(mNbPoint)
2455  >>mPowderPatternObsSigma(mNbPoint)
2456  >>mPowderPatternWeight(mNbPoint);
2457  mNbPoint++;
2458  VFN_DEBUG_MESSAGE("Point #"<<mNbPoint,5);
2459  if(mNbPoint==(unsigned long)mPowderPatternObs.numElements())
2460  {
2461  mX.resizeAndPreserve(mNbPoint+500);
2462  mPowderPatternObs.resizeAndPreserve(mNbPoint+500);
2463  mPowderPatternObsSigma.resizeAndPreserve(mNbPoint+500);
2464  mPowderPatternWeight.resizeAndPreserve(mNbPoint+500);
2465  }
2466  while(0==isgraph(is.peek())) is.get();
2467  }
2468  while(is.peek()!='<');//until next tag
2469  mX.resizeAndPreserve(mNbPoint);
2470  if(this->GetRadiation().GetWavelengthType()!=WAVELENGTH_TOF)
2471  mX*=DEG2RAD;
2472  this->SetPowderPatternX(mX);
2473 
2474  XMLCrystTag junk(is);
2475  VFN_DEBUG_EXIT("Loading X-Iobs-Sigma-Weight List...",8);
2476  continue;
2477  }
2478  }
2479 }
2480 } //namespace
The namespace which includes all objects (crystallographic and algorithmic) in ObjCryst++.
Definition: doc-main.h:25
void XMLCrystFileLoadObject(const string &filename, const string &tagName, const string &name, T *obj)
Load an object from a file, identifying it from its tag.
ObjRegistry< OptimizationObj > gOptimizationObjRegistry("List of all Optimization objects")
Global Registry for all OptimizationObj.
ObjRegistry< PowderPatternComponent > gPowderPatternComponentRegistry("List of all PowderPattern Components")
Global registry for all PowderPatternComponent objects.
WavelengthType
Incident beam characteristics : monochromatic, X-Ray tube with Alpha1 and alpha2, MAD (a few waveleng...
Definition: General.h:102
float string2floatC(const string &s)
Function to convert a substring to a floating point value, imposing a C locale (using '.
Definition: ObjCryst/IO.cpp:59
bool ISNAN_OR_INF(REAL r)
Test if the value is a NaN.
Definition: ObjCryst/IO.cpp:97
void XMLCrystFileLoadAllObject(const string &filename)
Load all 'top' objects from a file (Crystal, PowderPattern, DiffDataSingleCrystal and GlobalOptimObj ...
float InputFloat(istream &is, const char endchar)
Safely read a floating-point value from a stream.
Definition: ObjCryst/IO.cpp:68
ObjRegistry< Crystal > gCrystalRegistry("List of all Crystals")
Global registry for all Crystal objects.
Definition: Crystal.h:669
ObjRegistry< DiffractionDataSingleCrystal > gDiffractionDataSingleCrystalRegistry("Global DiffractionDataSingleCrystal Registry")
Global registry for all PowderPattern objects.
void XMLCrystFileSaveGlobal(const string &filename)
Save all Objcryst++ objects.
ObjRegistry< XMLCrystTag > XMLCrystFileLoadObjectList(const string &filename)
Get the list (tags) of ObjCryst objects in a file.
The basic atom scatterer, in a crystal.
Definition: Atom.h:58
const ScatteringPower * mpScattPowAtom
The ScatteringPowerAtom associated to that atom.
Definition: Atom.h:164
void Init(const REAL x, const REAL y, const REAL z, const string &name, const ScatteringPower *pow, const REAL popu=1)
initialize the atom (used for arrays of atoms).
Definition: Atom.cpp:130
virtual void XMLInput(istream &is, const XMLCrystTag &tag)
Input From stream.
virtual void XMLOutput(ostream &os, int indent=0) const
Output to stream in well-formed XML.
virtual void XMLOutput(ostream &os, int indent=0) const
Output to stream in well-formed XML.
ObjRegistry< ScatteringPower > & GetScatteringPowerRegistry()
Get the registry of ScatteringPower included in this Crystal.
Definition: Crystal.cpp:236
virtual void XMLInput(istream &is, const XMLCrystTag &tag)
Input the crystal structure from a stream.
DiffractionData object for Single Crystal analysis.
virtual void XMLOutput(ostream &os, int indent=0) const
Output to stream in well-formed XML.
virtual void XMLInput(istream &is, const XMLCrystTag &tag)
Input From stream.
Exception class for ObjCryst++ library.
Definition: General.h:122
Molecule : class for complex scatterer descriptions using cartesian coordinates with bond length/angl...
Definition: Molecule.h:760
virtual void XMLInput(istream &is, const XMLCrystTag &tag)
Input From stream.
Definition: Molecule.cpp:2331
Phase to compute a background contribution to a powder pattern using an interpolation.
virtual void XMLOutput(ostream &os, int indent=0) const
Output to stream in well-formed XML.
virtual void SetParentPowderPattern(PowderPattern &)
Set the PowderPattern object which uses this component.
virtual void XMLInput(istream &is, const XMLCrystTag &tag)
Input From stream.
Class to compute the contribution to a powder pattern from a crystalline phase.
virtual void XMLInput(istream &is, const XMLCrystTag &tag)
Input From stream.
virtual void SetParentPowderPattern(PowderPattern &)
Set the PowderPattern object which uses this component.
virtual void XMLOutput(ostream &os, int indent=0) const
Output to stream in well-formed XML.
virtual void XMLOutput(ostream &os, int indent=0) const
Output to stream in well-formed XML.
virtual void XMLInput(istream &is, const XMLCrystTag &tag)
Input From stream.
Pseudo-Voigt reflection profile.
Pseudo-Voigt reflection profile, with 6-parameters anisotropic Lorentzian broadening and Toraya asymm...
Double-Exponential Pseudo-Voigt profile for TOF.
const Crystal & GetCrystal() const
In which crystal is this Scatterer included ?
Definition: Scatterer.cpp:137
CrystVector_REAL mXYZ
coordinates of the scatterer (or of its center..)
Definition: Scatterer.h:283
void SetCrystal(Crystal &)
Set the crystal in which is included this Scatterer.
Definition: Scatterer.cpp:136
REAL mOccupancy
Occupancy : 0 <= occ <= 1 For a multi-atom scatterer (polyhedron,..), this is the overall occupancy o...
Definition: Scatterer.h:289
virtual void XMLOutput(ostream &os, int indent=0) const
Output to stream in well-formed XML.
virtual void XMLInput(istream &is, const XMLCrystTag &tag)
Input From stream.
Abstract Base Class to describe the scattering power of any Scatterer component in a crystal.
float mColourRGB[3]
Colour for this ScatteringPower using RGB.
bool mIsIsotropic
Is the scattering isotropic ?
bool IsIsotropic() const
Returns true if the scattering power is isotropic, else false.
REAL GetBiso() const
Returns the isotropic temperature B factor.
REAL GetBij(const size_t &i, const size_t &j) const
Returns the anisotropic temperature B factor for (i, j) pair.
CrystVector_REAL mB
Anisotropic B(ij)
REAL GetMaximumLikelihoodNbGhostAtom() const
Maximum Likelihood: get the number of ghost elements per asymmetric unit.
REAL mBiso
Temperature isotropic B factor.
void SetColour(const string &colorName)
Set the colour from the associated POV-Ray name.
REAL GetMaximumLikelihoodPositionError() const
Maximum Likelihood: get the estimated error (sigma) on the positions for this kind of element.
The Scattering Power for an Atom.
virtual const string & GetSymbol() const
Returns the symbol ('Ta', 'O2-',...) of the atom.
virtual void XMLInput(istream &is, const XMLCrystTag &tag)
Input From stream.
string mSymbol
Symbol of this atom.
void Init()
Initialization of the object, used by all constructors, and operator=.
virtual void XMLOutput(ostream &os, int indent=0) const
Output to stream in well-formed XML.
\ brief ScatteringPower for a spherical particule
virtual void XMLInput(istream &is, const XMLCrystTag &tag)
Input From stream.
Class for individual atoms in a ZScatterer Object.
Definition: ZScatterer.h:87
long GetZAngleAtom() const
Index of the 2nd atom used to define the atom in the Z-Matrix (the one from which the angle is calcul...
Definition: ZScatterer.cpp:96
long GetZDihedralAngleAtom() const
Index of the 3rd atom used to define the atom in the Z-Matrix (the one from which the dihedral angle ...
Definition: ZScatterer.cpp:97
const ZScatterer & GetZScatterer() const
Get the ZScatterer associated to this ZAtom.
Definition: ZScatterer.cpp:92
void SetScatteringPower(const ScatteringPower *)
Set the ScatteringPower.
Definition: ZScatterer.cpp:108
long mAtomBond
The index (in the ZScatterer) of the atoms which are used to define the position of this atom.
Definition: ZScatterer.h:141
string mName
Name for this atom.
Definition: ZScatterer.h:145
REAL mBondLength
Bond length, angle and dihedral angle.
Definition: ZScatterer.h:143
long GetZBondAtom() const
Index of the 1st atom used to define the atom in the Z-Matrix (the one from which the bondlength is c...
Definition: ZScatterer.cpp:95
const ScatteringPower * GetScatteringPower() const
ScatteringPower for this atom.
Definition: ZScatterer.cpp:102
ZScatterer: the basic type of complex scatterers, where atom positions are defined using a standard "...
Definition: ZScatterer.h:191
const ObjRegistry< ZAtom > & GetZAtomRegistry() const
Access to the registry of ZAtoms.
Definition: ZScatterer.cpp:466
virtual void XMLInput(istream &is, const XMLCrystTag &tag)
Input From stream.
virtual void XMLOutput(ostream &os, int indent=0) const
Output to stream in well-formed XML.
class to input or output a well-formatted xml beginning or ending tag.
void XMLOutput(ostream &os, const string &name, int indent=0) const
XMLOutput to stream in well-formed XML.
void XMLInput(istream &is, const XMLCrystTag &tag)
XMLInput From stream.
Object Registry.
Definition: RefinableObj.h:645
T & GetObj(const unsigned int i)
Get object #i in the registry.
long GetNb() const
Get the index of an object in the registry, from its name Warning: it can change if an object is remo...
void Register(T &obj)
Register a new object. Already registered objects are skipped.
virtual void SetName(const string &name)
Name of the object.
RefinablePar & GetPar(const long i)
Access all parameters in the order they were inputted.
virtual const string & GetName() const
Name of the object.
string mName
Name for this RefinableObject. Should be unique, at least in the same scope.+.