Skip to content

Commit e326dcb

Browse files
committed
Merge branch 'upstream-objcryst'
* upstream-objcryst: Avoid access to mpScattPow for dummy atom Add STL-type methods (begin, end, size) for ObjRegistry and Molecule objects Minor changes to be in sync with https://github.com/diffpy/libobjcryst Add access to Options in OptimizationObj, by number or name. Also provide access by name in RefinableObj MonteCarloObj: add public access to AutoLSQ option Radiation: fix automatic setting of options and used parameters
2 parents c6658f3 + 19a7a1d commit e326dcb

10 files changed

Lines changed: 220 additions & 12 deletions

File tree

src/ObjCryst/ObjCryst/Atom.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,23 @@ string Atom::GetComponentName(const int i) const{ return this->GetName();}
169169
void Atom::Print() const
170170
{
171171
VFN_DEBUG_MESSAGE("Atom::Print()",1)
172-
cout << "Atom ("
173-
<< FormatString(mpScattPowAtom->GetSymbol(),4) << ") :"
174-
<< FormatString(this->GetName(),16) << " at : "
175-
<< FormatFloat(this->GetX())
176-
<< FormatFloat(this->GetY())
177-
<< FormatFloat(this->GetZ());
178-
if(this->IsDummy()) cout << " DUMMY! ";
172+
if(this->IsDummy())
173+
{
174+
cout << "Atom (DUMMY) :"
175+
<< FormatString(this->GetName(),16) << " at : "
176+
<< FormatFloat(this->GetX())
177+
<< FormatFloat(this->GetY())
178+
<< FormatFloat(this->GetZ());
179+
}
179180
else
180181
{
181-
cout << ", Biso="
182+
cout << "Atom ("
183+
<< FormatString(mpScattPowAtom->GetSymbol(),4) << ") :"
184+
<< FormatString(this->GetName(),16) << " at : "
185+
<< FormatFloat(this->GetX())
186+
<< FormatFloat(this->GetY())
187+
<< FormatFloat(this->GetZ())
188+
<< ", Biso="
182189
<< FormatFloat(mpScattPowAtom->GetBiso())
183190
<< ", Popu=" << FormatFloat(this->GetOccupancy());
184191
}
@@ -303,6 +310,7 @@ void Atom::GLInitDisplayList(const bool onlyIndependentAtoms,
303310
const bool fullMoleculeInLimits)const
304311
{
305312
VFN_DEBUG_MESSAGE("Atom::GLInitDisplayList():"<<this->GetName(),5)
313+
if(this->IsDummy()) return ;
306314
REAL en=1;
307315
if(displayEnantiomer==true) en=-1;
308316

@@ -323,7 +331,6 @@ void Atom::GLInitDisplayList(const bool onlyIndependentAtoms,
323331
const REAL bb=this->GetCrystal().GetLatticePar(1);
324332
const REAL cc=this->GetCrystal().GetLatticePar(2);
325333

326-
if(this->IsDummy()) return ;
327334
if(hideHydrogens && (mpScattPowAtom->GetForwardScatteringFactor(RAD_XRAY)<1.5)) return;
328335
GLUquadricObj* pQuadric = gluNewQuadric();
329336
if(true==onlyIndependentAtoms)

src/ObjCryst/ObjCryst/Molecule.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,9 @@ void MolBondAngle::SetAtom3(MolAtom& at){mvpAtom[2]=&at;}
937937
//MolAtom& MolBondAngle::GetAtom1(){return *(mvpAtom[0]);}
938938
//MolAtom& MolBondAngle::GetAtom2(){return *(mvpAtom[1]);}
939939
//MolAtom& MolBondAngle::GetAtom3(){return *(mvpAtom[2]);}
940+
std::size_t MolBondAngle::size() const {return mvpAtom.size();}
941+
vector<MolAtom*>::const_iterator MolBondAngle::begin() const {return mvpAtom.begin();}
942+
vector<MolAtom*>::const_iterator MolBondAngle::end() const {return mvpAtom.end();}
940943
#ifdef __WX__CRYST__
941944
WXCrystObjBasic* MolBondAngle::WXCreate(wxWindow* parent)
942945
{
@@ -1294,6 +1297,9 @@ MolAtom& MolDihedralAngle::GetAtom1(){return *(mvpAtom[0]);}
12941297
MolAtom& MolDihedralAngle::GetAtom2(){return *(mvpAtom[1]);}
12951298
MolAtom& MolDihedralAngle::GetAtom3(){return *(mvpAtom[2]);}
12961299
MolAtom& MolDihedralAngle::GetAtom4(){return *(mvpAtom[3]);}
1300+
std::size_t MolDihedralAngle::size() const {return mvpAtom.size();}
1301+
vector<MolAtom*>::const_iterator MolDihedralAngle::begin() const {return mvpAtom.begin();}
1302+
vector<MolAtom*>::const_iterator MolDihedralAngle::end() const {return mvpAtom.end();}
12971303
#ifdef __WX__CRYST__
12981304
WXCrystObjBasic* MolDihedralAngle::WXCreate(wxWindow* parent)
12991305
{

src/ObjCryst/ObjCryst/Molecule.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ class MolBond:public Restraint
229229
void SetBondOrder(const REAL length);
230230
bool IsFreeTorsion()const;
231231
void SetFreeTorsion(const bool isInRing);
232+
232233
private:
233234
pair<MolAtom*,MolAtom*> mAtomPair;
234235
REAL mLength0,mDelta,mSigma;
@@ -316,6 +317,9 @@ class MolBondAngle:public Restraint
316317
MolAtom& GetAtom3();
317318
bool IsFlexible()const;
318319
void SetFlexible(const bool isInRing);
320+
std::size_t size() const;
321+
vector<MolAtom*>::const_iterator begin() const;
322+
vector<MolAtom*>::const_iterator end() const;
319323
private:
320324
/// The vector of the 3 atoms involved in the bond angle.
321325
vector<MolAtom*> mvpAtom;
@@ -408,6 +412,9 @@ class MolDihedralAngle:public Restraint
408412
MolAtom& GetAtom2();
409413
MolAtom& GetAtom3();
410414
MolAtom& GetAtom4();
415+
std::size_t size() const;
416+
vector<MolAtom*>::const_iterator begin() const;
417+
vector<MolAtom*>::const_iterator end() const;
411418
private:
412419
/// The vector of the 4 atoms involved in the bond angle.
413420
vector<MolAtom*> mvpAtom;

src/ObjCryst/ObjCryst/ScatteringData.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,23 @@ void Radiation::SetRadiationType(const RadiationType rad)
220220
{
221221
mRadiationType.SetChoice(rad);
222222
if(rad == RAD_NEUTRON) mLinearPolarRate=0;
223-
if(rad == RAD_ELECTRON) mLinearPolarRate=0;
224-
if(rad != RAD_XRAY) this->SetWavelengthType(WAVELENGTH_MONOCHROMATIC);
223+
if(rad == RAD_ELECTRON)
224+
{
225+
mLinearPolarRate=0;
226+
this->SetWavelengthType(WAVELENGTH_MONOCHROMATIC);
227+
}
225228
else this->UpdateDisplay();
226229
}
227230

228231
void Radiation::SetWavelengthType(const WavelengthType &type)
229232
{
230233
mWavelengthType.SetChoice((unsigned long) type);
231-
if(type==WAVELENGTH_TOF) this->SetRadiationType(RAD_NEUTRON);
234+
if(type==WAVELENGTH_TOF)
235+
{
236+
this->SetRadiationType(RAD_NEUTRON);
237+
this->GetPar("XRayTubeDeltaLambda").SetIsUsed(false);
238+
this->GetPar("XRayTubeAlpha2Alpha1Ratio").SetIsUsed(false);
239+
}
232240
if(type==WAVELENGTH_ALPHA12)
233241
{
234242
this->SetRadiationType(RAD_XRAY);

src/ObjCryst/ObjCryst/ZScatterer.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,6 +1530,21 @@ void ZScatterer::ExportFenskeHallZMatrix(ostream &os)
15301530
void ZScatterer::SetCenterAtomIndex(const unsigned int ix){mCenterAtomIndex=ix;}
15311531
unsigned int ZScatterer::GetCenterAtomIndex()const{return mCenterAtomIndex;}
15321532

1533+
std::size_t ZScatterer::size() const
1534+
{
1535+
return mZAtomRegistry.size();
1536+
}
1537+
1538+
vector<ZAtom*>::const_iterator ZScatterer::begin() const
1539+
{
1540+
return mZAtomRegistry.begin();
1541+
}
1542+
1543+
vector<ZAtom*>::const_iterator ZScatterer::end() const
1544+
{
1545+
return mZAtomRegistry.end();
1546+
}
1547+
15331548
void ZScatterer::GlobalOptRandomMove(const REAL mutationAmplitude,
15341549
const RefParType *type)
15351550
{

src/ObjCryst/ObjCryst/ZScatterer.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,19 @@ class ZScatterer: public Scatterer
350350
void SetCenterAtomIndex(const unsigned int);
351351
/// Get the index of the central atom (around which the rotation is made)
352352
unsigned int GetCenterAtomIndex()const;
353+
/** STL access to registry of Zatom size
354+
*/
355+
std::size_t size() const;
356+
/** low-level access to the underlying vector of ZAtom begin().
357+
* Const access as we do not want the number and order of objects to change,
358+
* but the objects themselves can be modified.
359+
*/
360+
vector<ZAtom*>::const_iterator begin() const;
361+
/** low-level access to the underlying vector of ZAtom end().
362+
* Const access as we do not want the number and order of objects to change,
363+
* but the objects themselves can be modified.
364+
*/
365+
vector<ZAtom*>::const_iterator end() const;
353366
protected:
354367
/** Update the atom coordinates (in real units, in Angstroems).
355368
*

src/ObjCryst/RefinableObj/GlobalOptimObj.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,59 @@ long& OptimizationObj::NbTrialPerRun() {return mNbTrialPerRun;}
299299

300300
const long& OptimizationObj::NbTrialPerRun() const {return mNbTrialPerRun;}
301301

302+
unsigned int OptimizationObj::GetNbOption()const
303+
{
304+
return mOptionRegistry.GetNb();
305+
}
306+
307+
ObjRegistry<RefObjOpt>& OptimizationObj::GetOptionList()
308+
{
309+
return mOptionRegistry;
310+
}
311+
312+
RefObjOpt& OptimizationObj::GetOption(const unsigned int i)
313+
{
314+
VFN_DEBUG_MESSAGE("RefinableObj::GetOption()"<<i,3)
315+
//:TODO: Check
316+
return mOptionRegistry.GetObj(i);
317+
}
318+
319+
RefObjOpt& OptimizationObj::GetOption(const string & name)
320+
{
321+
VFN_DEBUG_MESSAGE("OptimizationObj::GetOption()"<<name,3)
322+
const long i=mOptionRegistry.Find(name);
323+
if(i<0)
324+
{
325+
this->Print();
326+
throw ObjCrystException("OptimizationObj::GetOption(): cannot find option: "+name+" in object:"+this->GetName());
327+
}
328+
return mOptionRegistry.GetObj(i);
329+
}
330+
331+
const RefObjOpt& OptimizationObj::GetOption(const unsigned int i)const
332+
{
333+
VFN_DEBUG_MESSAGE("RefinableObj::GetOption()"<<i,3)
334+
//:TODO: Check
335+
return mOptionRegistry.GetObj(i);
336+
}
337+
338+
const RefObjOpt& OptimizationObj::GetOption(const string & name)const
339+
{
340+
VFN_DEBUG_MESSAGE("OptimizationObj::GetOption()"<<name,3)
341+
const long i=mOptionRegistry.Find(name);
342+
if(i<0)
343+
{
344+
this->Print();
345+
throw ObjCrystException("OptimizationObj::GetOption(): cannot find option: "+name+" in object:"+this->GetName());
346+
}
347+
return mOptionRegistry.GetObj(i);
348+
}
349+
350+
const ObjRegistry<RefinableObj>& OptimizationObj::GetRefinedObjList() const
351+
{
352+
return mRefinedObjList;
353+
}
354+
302355
void OptimizationObj::PrepareRefParList()
303356
{
304357
VFN_DEBUG_ENTRY("OptimizationObj::PrepareRefParList()",6)
@@ -375,6 +428,7 @@ void OptimizationObj::InitOptions()
375428
needInitNames=false;//Only once for the class
376429
}
377430
mXMLAutoSave.Init(6,&xmlAutoSaveName,xmlAutoSaveChoices);
431+
this->AddOption(&mXMLAutoSave);
378432
VFN_DEBUG_MESSAGE("OptimizationObj::InitOptions():End",5)
379433
}
380434

@@ -404,6 +458,13 @@ void OptimizationObj::BuildRecursiveRefObjList()
404458
}
405459
}
406460

461+
void OptimizationObj::AddOption(RefObjOpt *opt)
462+
{
463+
VFN_DEBUG_ENTRY("OptimizationObj::AddOption()",5)
464+
mOptionRegistry.Register(*opt);
465+
VFN_DEBUG_EXIT("OptimizationObj::AddOption()",5)
466+
}
467+
407468
//#################################################################################
408469
//
409470
// MonteCarloObj
@@ -2087,6 +2148,11 @@ void MonteCarloObj::InitOptions()
20872148
mAnnealingScheduleMutation.Init(6,&AnnealingScheduleMutationName,AnnealingScheduleChoices);
20882149
mSaveTrackedData.Init(2,&saveTrackedDataName,saveTrackedDataChoices);
20892150
mAutoLSQ.Init(3,&runAutoLSQName,runAutoLSQChoices);
2151+
this->AddOption(&mGlobalOptimType);
2152+
this->AddOption(&mAnnealingScheduleTemp);
2153+
this->AddOption(&mAnnealingScheduleMutation);
2154+
this->AddOption(&mSaveTrackedData);
2155+
this->AddOption(&mAutoLSQ);
20902156
VFN_DEBUG_MESSAGE("MonteCarloObj::InitOptions():End",5)
20912157
}
20922158

src/ObjCryst/RefinableObj/GlobalOptimObj.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,21 @@ class OptimizationObj
222222
virtual long& NbTrialPerRun();
223223
/// Number of trial per run
224224
virtual const long& NbTrialPerRun() const;
225+
//Options
226+
/// Access to the options registry
227+
ObjRegistry<RefObjOpt>& GetOptionList();
228+
/// Number of Options for this object
229+
unsigned int GetNbOption()const;
230+
/// Access to the options
231+
RefObjOpt& GetOption(const unsigned int i);
232+
/// Access to the options by name
233+
RefObjOpt& GetOption(const string & name);
234+
/// const access to the options
235+
const RefObjOpt& GetOption(const unsigned int i)const;
236+
/// const access to the options by name
237+
const RefObjOpt& GetOption(const string & name)const;
238+
/// Access the list of refined object
239+
const ObjRegistry<RefinableObj>& GetRefinedObjList() const;
225240
protected:
226241
/// \internal Prepare mRefParList for the refinement
227242
void PrepareRefParList();
@@ -235,6 +250,8 @@ class OptimizationObj
235250
/// object has been added or modified. If no object has been
236251
/// added and no sub-object has been added/removed, then nothing is done.
237252
void BuildRecursiveRefObjList();
253+
/// \internal Add an option for this parameter
254+
void AddOption(RefObjOpt *opt);
238255
/// The refinable par list used during refinement. Only a condensed version
239256
/// of all objects. This is useful to keep an history of modifications, and to
240257
/// restore previous values.
@@ -308,6 +325,10 @@ class OptimizationObj
308325
/// MainTracker object to track the evolution of cost functions, likelihood,
309326
/// and individual parameters.
310327
MainTracker mMainTracker;
328+
/// List of options for this object. Note that these are just references,
329+
/// to options allocated by the object, to have a simple global access to
330+
/// all options
331+
ObjRegistry<RefObjOpt> mOptionRegistry;
311332
private:
312333
#ifdef __WX__CRYST__
313334
public:

src/ObjCryst/RefinableObj/RefinableObj.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,11 +983,13 @@ template<class T> void ObjRegistry<T>::DeleteAll()
983983

984984
template<class T> T& ObjRegistry<T>::GetObj(const unsigned int i)
985985
{
986+
if(i>=this->GetNb()) throw ObjCrystException("ObjRegistry<T>::GetObj(i): i >= nb!");
986987
return *(mvpRegistry[i]);
987988
}
988989

989990
template<class T> const T& ObjRegistry<T>::GetObj(const unsigned int i) const
990991
{
992+
if(i>=this->GetNb()) throw ObjCrystException("ObjRegistry<T>::GetObj(i): i >= nb!");
991993
return *(mvpRegistry[i]);
992994
}
993995

@@ -1116,6 +1118,21 @@ template<class T> void ObjRegistry<T>::UpdateUI()
11161118
#endif
11171119
}
11181120

1121+
template<class T> std::size_t ObjRegistry<T>::size() const
1122+
{
1123+
return (std::size_t) mvpRegistry.size();
1124+
}
1125+
1126+
template<class T> typename vector<T*>::const_iterator ObjRegistry<T>::begin() const
1127+
{
1128+
return mvpRegistry.begin();
1129+
}
1130+
1131+
template<class T> typename vector<T*>::const_iterator ObjRegistry<T>::end() const
1132+
{
1133+
return mvpRegistry.end();
1134+
}
1135+
11191136
#ifdef __WX__CRYST__
11201137
template<class T> WXRegistry<T>* ObjRegistry<T>::WXCreate(wxWindow *parent)
11211138
{
@@ -1846,6 +1863,11 @@ void RefinableObj::ResetParList()
18461863
VFN_DEBUG_MESSAGE("RefinableObj::ResetParList():End.",3)
18471864
}
18481865

1866+
ObjRegistry<RefObjOpt>& RefinableObj::GetOptionList()
1867+
{
1868+
return mOptionRegistry;
1869+
}
1870+
18491871
unsigned int RefinableObj::GetNbOption()const
18501872
{
18511873
return mOptionRegistry.GetNb();
@@ -1858,12 +1880,36 @@ RefObjOpt& RefinableObj::GetOption(const unsigned int i)
18581880
return mOptionRegistry.GetObj(i);
18591881
}
18601882

1883+
RefObjOpt& RefinableObj::GetOption(const string & name)
1884+
{
1885+
VFN_DEBUG_MESSAGE("RefinableObj::GetOption()"<<name,3)
1886+
const long i=mOptionRegistry.Find(name);
1887+
if(i<0)
1888+
{
1889+
this->Print();
1890+
throw ObjCrystException("RefinableObj::GetOption(): cannot find option: "+name+" in object:"+this->GetName());
1891+
}
1892+
return mOptionRegistry.GetObj(i);
1893+
}
1894+
18611895
const RefObjOpt& RefinableObj::GetOption(const unsigned int i)const
18621896
{
18631897
//:TODO: Check
18641898
return mOptionRegistry.GetObj(i);
18651899
}
18661900

1901+
const RefObjOpt& RefinableObj::GetOption(const string & name)const
1902+
{
1903+
VFN_DEBUG_MESSAGE("RefinableObj::GetOption()"<<name,3)
1904+
const long i=mOptionRegistry.Find(name);
1905+
if(i<0)
1906+
{
1907+
this->Print();
1908+
throw ObjCrystException("RefinableObj::GetOption(): cannot find option: "+name+" in object:"+this->GetName());
1909+
}
1910+
return mOptionRegistry.GetObj(i);
1911+
}
1912+
18671913
void RefinableObj::GetGeneGroup(const RefinableObj &obj,
18681914
CrystVector_uint & groupIndex,
18691915
unsigned int &first) const

0 commit comments

Comments
 (0)