BornAgain  1.19.0
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/coregui/Models/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 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
31 
32 namespace {
33 const QString abundance_tooltip = "Proportion of this type of mesocrystal normalized to the \n"
34  "total number of particles in the layout";
35 
36 const QString lattice_vector1_tooltip = "Coordinates of the first lattice vector";
37 
38 const QString lattice_vector2_tooltip = "Coordinates of the second lattice vector";
39 
40 const QString lattice_vector3_tooltip = "Coordinates of the third lattice vector";
41 
42 const QString position_tooltip = "Relative position of the mesocrystal's reference point \n"
43  "in the coordinate system of the parent (nm)";
44 
45 const QString density_tooltip =
46  "Number of mesocrystals per square nanometer (particle surface density).\n "
47  "Should be defined for disordered and 1d-ordered particle collections.";
48 
49 bool IsIParticleName(QString name)
50 {
51  return (name.startsWith("Particle") || name.startsWith("ParticleComposition")
52  || name.startsWith("ParticleCoreShell") || name.startsWith("MesoCrystal"));
53 }
54 
55 } // namespace
56 
57 const QString MesoCrystalItem::P_OUTER_SHAPE = "Outer Shape";
58 const QString MesoCrystalItem::T_BASIS_PARTICLE = "Basis Particle";
59 const QString MesoCrystalItem::P_VECTOR_A = "First lattice vector";
60 const QString MesoCrystalItem::P_VECTOR_B = "Second lattice vector";
61 const QString MesoCrystalItem::P_VECTOR_C = "Third lattice vector";
62 
63 // TODO make derived from ParticleItem
64 
66 {
67  setToolTip("A 3D crystal structure of nanoparticles");
68 
69  addGroupProperty(P_OUTER_SHAPE, "Form Factor");
70 
72  ->setLimits(RealLimits::limited(0.0, 1.0))
73  .setDecimals(3)
74  .setToolTip(abundance_tooltip);
75 
76  addProperty<VectorItem>(P_VECTOR_A)->setToolTip(lattice_vector1_tooltip);
77  addProperty<VectorItem>(P_VECTOR_B)->setToolTip(lattice_vector2_tooltip);
78  addProperty<VectorItem>(P_VECTOR_C)->setToolTip(lattice_vector3_tooltip);
79  addProperty<VectorItem>(ParticleItem::P_POSITION)->setToolTip(position_tooltip);
80 
82  QStringList() << "Particle"
83  << "ParticleCoreShell"
84  << "ParticleComposition"
85  << "MesoCrystal");
87 
88  registerTag(ParticleItem::T_TRANSFORMATION, 0, 1, QStringList() << "Rotation");
89 
92  QStringList additional_names{QString::fromStdString("Lattice"),
93  QString::fromStdString("Crystal")};
94  addTranslator(VectorParameterTranslator(P_VECTOR_A, "BasisA", additional_names));
95  addTranslator(VectorParameterTranslator(P_VECTOR_B, "BasisB", additional_names));
96  addTranslator(VectorParameterTranslator(P_VECTOR_C, "BasisC", additional_names));
97 
102  } else {
104  }
105  });
106 }
107 
109 {
110  return item<VectorItem>(ParticleItem::P_POSITION);
111 }
112 
113 std::unique_ptr<MesoCrystal> MesoCrystalItem::createMesoCrystal() const
114 {
115  const Lattice3D& lattice = getLattice();
116  if (!(lattice.unitCellVolume() > 0.0))
117  throw GUIHelpers::Error("MesoCrystalItem::createMesoCrystal(): "
118  "Lattice volume not strictly positive");
119  std::unique_ptr<IParticle> basis = getBasis();
120  if (!basis)
121  throw GUIHelpers::Error("MesoCrystalItem::createMesoCrystal(): "
122  "No basis particle defined");
123  Crystal crystal(*basis, lattice);
124 
125  std::unique_ptr<IFormFactor> ff = getOuterShape();
126  if (!ff)
127  throw GUIHelpers::Error("MesoCrystalItem::createMesoCrystal(): "
128  "No outer shape defined");
129 
130  auto result = std::make_unique<MesoCrystal>(crystal, *ff);
131  TransformToDomain::setTransformationInfo(result.get(), *this);
132 
133  return result;
134 }
135 
136 QStringList MesoCrystalItem::translateList(const QStringList& list) const
137 {
138  QStringList result = list;
139  // Add CrystalType to path name of basis particle
140  if (IsIParticleName(list.back()))
141  result << QString::fromStdString("Crystal");
142  result = SessionItem::translateList(result);
143  return result;
144 }
145 
147 {
148  const kvector_t a1 = item<VectorItem>(P_VECTOR_A)->getVector();
149  const kvector_t a2 = item<VectorItem>(P_VECTOR_B)->getVector();
150  const kvector_t a3 = item<VectorItem>(P_VECTOR_C)->getVector();
151  return Lattice3D(a1, a2, a3);
152 }
153 
154 std::unique_ptr<IParticle> MesoCrystalItem::getBasis() const
155 {
156  QVector<SessionItem*> childlist = children();
157  for (int i = 0; i < childlist.size(); ++i) {
158  if (childlist[i]->modelType() == "Particle") {
159  auto* particle_item = static_cast<ParticleItem*>(childlist[i]);
160  return particle_item->createParticle();
161  } else if (childlist[i]->modelType() == "ParticleCoreShell") {
162  auto* particle_coreshell_item = static_cast<ParticleCoreShellItem*>(childlist[i]);
163  return particle_coreshell_item->createParticleCoreShell();
164  } else if (childlist[i]->modelType() == "ParticleComposition") {
165  auto* particlecomposition_item = static_cast<ParticleCompositionItem*>(childlist[i]);
166  return particlecomposition_item->createParticleComposition();
167  } else if (childlist[i]->modelType() == "MesoCrystal") {
168  auto* mesocrystal_item = static_cast<MesoCrystalItem*>(childlist[i]);
169  return mesocrystal_item->createMesoCrystal();
170  }
171  }
172  return {};
173 }
174 
175 std::unique_ptr<IFormFactor> MesoCrystalItem::getOuterShape() const
176 {
177  auto& ff_item = groupItem<FormFactorItem>(MesoCrystalItem::P_OUTER_SHAPE);
178  return ff_item.createFormFactor();
179 }
Defines class ComboProperty.
Defines class Crystal.
Defines FormFactorItems classes.
Defines class GUIHelpers functions.
Defines and implements interface IFormFactor.
Defines class MesoCrystalItem.
Defines class MesoCrystal.
Defines ModelPath namespace.
Defines class ParticleCompositionItem.
Defines class ParticleCoreShellItem.
Defines ParticleCoreShell.
Defines class ParticleItem.
Defines class Particle.
Defines namespace SessionItemUtils.
Defines class TransformToDomain.
Defines class VectorItem.
A crystal structure, defined by a Bravais lattice, a basis, and a position variance.
Definition: Crystal.h:35
A Bravais lattice, characterized by three basis vectors, and optionally an ISelectionRule.
Definition: Lattice3D.h:29
double unitCellVolume() const
Returns the volume of the unit cell.
Definition: Lattice3D.cpp:73
std::unique_ptr< IFormFactor > getOuterShape() const
static const QString P_VECTOR_C
QStringList translateList(const QStringList &list) const override
std::unique_ptr< MesoCrystal > createMesoCrystal() const
std::unique_ptr< IParticle > getBasis() const
static const QString T_BASIS_PARTICLE
Lattice3D getLattice() const
static const QString P_VECTOR_B
VectorItem * positionItem() const
static const QString P_VECTOR_A
static const QString P_OUTER_SHAPE
void setOnParentChange(std::function< void(SessionItem *)> f, const void *caller=0)
Calls back when parent has changed, reports newParent.
Definition: ModelMapper.cpp:60
std::unique_ptr< ParticleComposition > createParticleComposition() const
std::unique_ptr< ParticleCoreShell > createParticleCoreShell() const
std::unique_ptr< Particle > createParticle() const
static const QString P_ABUNDANCE
Definition: ParticleItem.h:26
static const QString T_TRANSFORMATION
Definition: ParticleItem.h:29
static const QString P_POSITION
Definition: ParticleItem.h:28
static RealLimits limited(double left_bound_value, double right_bound_value)
Creates an object bounded from the left and right.
Definition: RealLimits.cpp:125
SessionItem * addProperty(const QString &name, const QVariant &variant)
Add new property item and register new tag.
SessionItem & setDecimals(int n)
bool registerTag(const QString &name, int min=0, int max=-1, QStringList modelTypes={})
Add new tag to this item with given name, min, max and types.
virtual QStringList translateList(const QStringList &list) const
SessionItem * addGroupProperty(const QString &groupTag, const QString &groupType)
Creates new group item and register new tag, returns GroupItem.
ModelMapper * mapper()
Returns the current model mapper of this item. Creates new one if necessary.
SessionItem * parent() const
Returns parent of this item.
Definition: SessionItem.cpp:73
void setDefaultTag(const QString &tag)
Set default tag.
void addTranslator(const IPathTranslator &translator)
void setItemValue(const QString &tag, const QVariant &variant)
Directly set value of item under given tag.
QVector< SessionItem * > children() const
Returns vector of all children.
SessionItem & setToolTip(const QString &tooltip)
QString modelType() const
Get model type.
void setEnabled(bool enabled)
SessionItem * getItem(const QString &tag="", int row=0) const
Returns item in given row of given tag.
SessionItem & setLimits(const RealLimits &value)
QString const & name(EShape k)
Definition: particles.cpp:21
bool HasOwnAbundance(const SessionItem *item)
void setTransformationInfo(IParticle *result, const SessionItem &item)