BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
MesoCrystalItem.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/Model/Sample/MesoCrystalItem.cpp
6 //! @brief Implements class MesoCrystalItem
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2021
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
24 #include "GUI/Util/Error.h"
25 #include "Sample/Particle/Crystal.h"
26 #include "Sample/Particle/IFormFactor.h"
27 #include "Sample/Particle/MesoCrystal.h"
28 #include "Sample/Particle/Particle.h"
29 #include "Sample/Particle/ParticleCoreShell.h"
30 #include "Sample/Scattering/Rotations.h"
31 
32 namespace {
33 
34 const QString abundance_tooltip = "Proportion of this type of mesocrystal normalized to the \n"
35  "total number of particles in the layout";
36 
37 const QString position_tooltip = "Relative position of the mesocrystal's reference point \n"
38  "in the coordinate system of the parent (nm)";
39 
40 } // namespace
41 
43  : ItemWithParticles(abundance_tooltip, position_tooltip)
44  , m_materials(materials)
45 {
46  m_vectorA.init("First lattice vector", "Coordinates of the first lattice vector",
47  Unit::nanometer, "vectorA");
48  m_vectorB.init("Second lattice vector", "Coordinates of the second lattice vector",
49  Unit::nanometer, "vectorB");
50  m_vectorC.init("Third lattice vector", "Coordinates of the third lattice vector",
51  Unit::nanometer, "vectorC");
52 
53  m_outerShape.init<FormFactorItemCatalog>("Outer Shape", "", "outerShape");
54  m_basisParticle.init<ItemWithParticlesCatalog>("Basis", "", "basis", materials);
55 }
56 
58 {
59  s.assertVersion(0);
62  Serialize::rwSelected<RotationItemCatalog>(s, m_rotation);
66  Serialize::rwSelected<FormFactorItemCatalog>(s, m_outerShape);
67  Serialize::rwSelected<ItemWithParticlesCatalog>(s, m_basisParticle, m_materials);
68 }
69 
70 std::unique_ptr<MesoCrystal> MesoCrystalItem::createMesoCrystal() const
71 {
72  const Lattice3D& lattice = getLattice();
73  if (!(lattice.unitCellVolume() > 0.0))
74  throw Error("MesoCrystalItem::createMesoCrystal(): "
75  "Lattice volume not strictly positive");
76  std::unique_ptr<IParticle> basis = getBasis();
77  if (!basis)
78  throw Error("MesoCrystalItem::createMesoCrystal(): "
79  "No basis particle defined");
80  Crystal crystal(*basis, lattice);
81 
82  std::unique_ptr<IFormFactor> ff = getOuterShape();
83  if (!ff)
84  throw Error("MesoCrystalItem::createMesoCrystal(): "
85  "No outer shape defined");
86 
87  auto result = std::make_unique<MesoCrystal>(crystal, *ff);
88  result->setParticlePosition(position());
89  if (auto r = createRotation(); r && !r->isIdentity())
90  result->setRotation(*r);
91 
92  return result;
93 }
94 
95 Lattice3D MesoCrystalItem::getLattice() const
96 {
97  return Lattice3D(m_vectorA, m_vectorB, m_vectorC);
98 }
99 
100 std::unique_ptr<IParticle> MesoCrystalItem::getBasis() const
101 {
102  if (auto* p = dynamic_cast<ParticleItem*>(m_basisParticle.get()))
103  return p->createParticle();
104 
105  if (auto* p = dynamic_cast<ParticleCoreShellItem*>(m_basisParticle.get()))
106  return p->createParticleCoreShell();
107 
108  if (auto* p = dynamic_cast<ParticleCompositionItem*>(m_basisParticle.get()))
109  return p->createParticleComposition();
110 
111  if (auto* p = dynamic_cast<MesoCrystalItem*>(m_basisParticle.get()))
112  return p->createMesoCrystal();
113 
114  return {};
115 }
116 
117 std::unique_ptr<IFormFactor> MesoCrystalItem::getOuterShape() const
118 {
119  return m_outerShape->createFormFactor();
120 }
121 
123 {
124  return m_outerShape;
125 }
126 
128 {
129  m_outerShape.set(p);
130 }
131 
133 {
134  return m_basisParticle.get();
135 }
136 
138 {
139  m_basisParticle.set(basis);
140 }
141 
143 {
144  m_vectorA.set(v);
145 }
146 
148 {
149  m_vectorB.set(v);
150 }
151 
153 {
154  m_vectorC.set(v);
155 }
156 
158 {
159  return m_vectorA;
160 }
161 
163 {
164  return m_vectorB;
165 }
166 
168 {
169  return m_vectorC;
170 }
171 
172 QVector<ItemWithParticles*> MesoCrystalItem::containedItemsWithParticles() const
173 {
174  QVector<ItemWithParticles*> result;
175  if (basisParticle())
177  return result;
178 }
Defines error class.
Defines class FormFactorItemCatalog.
Defines FormFactorItems classes.
Defines class ItemWithParticlesCatalog.
Defines class MesoCrystalItem.
Defines class ParticleCompositionItem.
Defines class ParticleCoreShellItem.
Defines class ParticleItem.
Defines class RotationItemCatalog.
Defines class Streamer.
@ nanometer
virtual std::unique_ptr< IFormFactor > createFormFactor() const =0
VectorProperty m_position
SelectionProperty< RotationItem * > m_rotation
std::unique_ptr< IRotation > createRotation() const
nullptr only if "no rotation". Can contain identity!
DoubleProperty m_abundance
virtual QVector< ItemWithParticles * > containedItemsWithParticles() const =0
Return full hierarchical contained items with particles.
void setRawDataVectorA(const R3 &vector_a)
void setOuterShape(FormFactorItem *p)
std::unique_ptr< IFormFactor > getOuterShape() const
void setRawDataVectorC(const R3 &vector_c)
VectorDescriptor vectorB() const
VectorDescriptor vectorC() const
void setRawDataVectorB(const R3 &vector_b)
void setBasis(ItemWithParticles *basis)
VectorProperty m_vectorB
const MaterialItems * m_materials
VectorProperty m_vectorC
std::unique_ptr< MesoCrystal > createMesoCrystal() const
SelectionProperty< FormFactorItem * > m_outerShape
std::unique_ptr< IParticle > getBasis() const
VectorDescriptor vectorA() const
SelectionDescriptor< FormFactorItem * > outerShape() const
VectorProperty m_vectorA
Lattice3D getLattice() const
MesoCrystalItem(const MaterialItems *materials)
void serialize(Streamer &s) override
SelectionProperty< ItemWithParticles * > m_basisParticle
ItemWithParticles * basisParticle() const
QVector< ItemWithParticles * > containedItemsWithParticles() const override
Return full hierarchical contained items with particles.
Describes a selection (various possibilities and the current one).
void set(T t, bool callInitializer=false)
Directly set the new item.
T get() const
Direct access to the stored pointer.
void init(const QString &label, const QString &tooltip, const QString &persistentTag, ArgsForCreation... argsForCreation)
Initialize by means of a catalog class and optional creation arguments.
Supports serialization to or deserialization from QXmlStream.
Definition: Streamer.h:36
void assertVersion(unsigned expectedVersion) const
As reader, throws DeserializationException unless the expected version is read. As writer,...
Definition: Streamer.cpp:26
Describes properties of a 3D vector, consisting of three double values.
void set(const R3 &d)
void init(const QString &label, const QString &tooltip, const variant< QString, Unit > &unit, const QString &persistentTag)
void rwProperty(Streamer &s, DoubleProperty &d)