Skip to content

Commit cc3b828

Browse files
committed
When adding a Scatterer (Atom, Molecule, Polyhedron) to a Crystal, throw an exception if the corresponding ScatteringPower have not already been added to the Crystal.
1 parent d3e402b commit cc3b828

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/extensions/crystal_ext.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838

3939
#undef B0
4040
#include <ObjCryst/ObjCryst/Crystal.h>
41+
#include <ObjCryst/ObjCryst/Atom.h>
42+
#include <ObjCryst/ObjCryst/Molecule.h>
4143
#include <ObjCryst/ObjCryst/CIF.h>
4244
#include <ObjCryst/ObjCryst/UnitCell.h>
4345

@@ -59,6 +61,30 @@ void _AddScatterer(Crystal& crystal, Scatterer* scatt)
5961
"Cannot add nonexistant Scatterer");
6062
throw_error_already_set();
6163
}
64+
// Make sure the associated ScatteringPower exists in the Crystal
65+
if(scatt->GetClassName()=="Atom")
66+
{
67+
Atom *pat=dynamic_cast<Atom*>(scatt);
68+
if(!(pat->IsDummy()))
69+
{
70+
const ScatteringPower *psp = &pat->GetScatteringPower();
71+
if(crystal.GetScatteringPowerRegistry().Find(psp)<0)
72+
throw ObjCryst::ObjCrystException("The Atom's scattering power must be added to the Crystal first.");
73+
}
74+
}
75+
else if(scatt->GetClassName()=="Molecule")
76+
{
77+
Molecule *pm=dynamic_cast<Molecule*>(scatt);
78+
for(int i=0; i<pm->GetNbComponent(); i++)
79+
{
80+
if(!(pm->GetAtom(i).IsDummy()))
81+
{
82+
if(crystal.GetScatteringPowerRegistry().Find(&(pm->GetAtom(i).GetScatteringPower()))<0)
83+
throw ObjCryst::ObjCrystException("The Molecule or Polyhedra scattering powers must be added to the Crystal first.");
84+
}
85+
}
86+
}
87+
6288
crystal.AddScatterer(scatt);
6389
}
6490

@@ -71,6 +97,7 @@ void _RemoveScatterer(Crystal& crystal, Scatterer* scatt)
7197
"Cannot remove nonexistant Scatterer");
7298
throw_error_already_set();
7399
}
100+
74101
crystal.RemoveScatterer(scatt, false);
75102
}
76103

0 commit comments

Comments
 (0)