From bf000e1694664245fa28af45f486ec87aa46e387 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Sun, 15 Nov 2020 22:31:49 +0100 Subject: [PATCH] Prepare for exporting Lattice2D to Python --- Core/Export/SampleLabelHandler.cpp | 21 +++++++++++++++----- Core/Export/SampleLabelHandler.h | 16 ++++++++++----- Core/Export/SampleToPython.cpp | 31 +++++++++++++++++++++++++----- Core/Export/SampleToPython.h | 3 ++- auto/Wrap/doxygenCore.i | 15 ++++++++++++--- 5 files changed, 67 insertions(+), 19 deletions(-) diff --git a/Core/Export/SampleLabelHandler.cpp b/Core/Export/SampleLabelHandler.cpp index 529291f3aab..f4c79391091 100644 --- a/Core/Export/SampleLabelHandler.cpp +++ b/Core/Export/SampleLabelHandler.cpp @@ -53,9 +53,14 @@ std::string SampleLabelHandler::labelMaterial(const Material* mat) return m_MaterialLabel[mat]; } -std::string SampleLabelHandler::labelLattice(const Lattice3D* lat) +std::string SampleLabelHandler::labelLattice2D(const Lattice2D* lat) { - return m_LatticeLabel[lat]; + return m_Lattice2DLabel[lat]; +} + +std::string SampleLabelHandler::labelLattice3D(const Lattice3D* lat) +{ + return m_Lattice3DLabel[lat]; } std::string SampleLabelHandler::labelMultiLayer(const MultiLayer* ml) @@ -136,10 +141,16 @@ void SampleLabelHandler::insertMaterial(const Material* mat) m_MaterialLabel.insert(mat, label); } -void SampleLabelHandler::insertLattice(const Lattice3D* sample) +void SampleLabelHandler::insertLattice2D(const Lattice2D* sample) +{ + std::string label = "lattice2D_" + std::to_string(m_Lattice2DLabel.size() + 1); + m_Lattice2DLabel.insert(sample, label); +} + +void SampleLabelHandler::insertLattice3D(const Lattice3D* sample) { - std::string label = "lattice_" + std::to_string(m_LatticeLabel.size() + 1); - m_LatticeLabel.insert(sample, label); + std::string label = "lattice3D_" + std::to_string(m_Lattice3DLabel.size() + 1); + m_Lattice3DLabel.insert(sample, label); } void SampleLabelHandler::insertMesoCrystal(const MesoCrystal* sample) diff --git a/Core/Export/SampleLabelHandler.h b/Core/Export/SampleLabelHandler.h index 09712d421fa..108708f7585 100644 --- a/Core/Export/SampleLabelHandler.h +++ b/Core/Export/SampleLabelHandler.h @@ -25,6 +25,7 @@ class IInterferenceFunction; class ParticleLayout; class Material; class IRotation; +class Lattice2D; class Lattice3D; class Layer; class LayerRoughness; @@ -51,7 +52,8 @@ public: typedef LabelMap<const Layer*> layers_t; typedef LabelMap<const ParticleLayout*> layouts_t; typedef LabelMap<const Material*> materials_t; - typedef LabelMap<const Lattice3D*> lattices_t; + typedef LabelMap<const Lattice2D*> lattices2D_t; + typedef LabelMap<const Lattice3D*> lattices3D_t; typedef LabelMap<const MesoCrystal*> mesocrystals_t; typedef LabelMap<const MultiLayer*> multilayers_t; typedef LabelMap<const ParticleComposition*> particlecompositions_t; @@ -68,7 +70,8 @@ public: layers_t* layerMap() { return &m_LayerLabel; } layouts_t* particleLayoutMap() { return &m_ParticleLayoutLabel; } materials_t* materialMap() { return &m_MaterialLabel; } - lattices_t* latticeMap() { return &m_LatticeLabel; } + lattices2D_t* lattice2DMap() { return &m_Lattice2DLabel; } + lattices3D_t* lattice3DMap() { return &m_Lattice3DLabel; } mesocrystals_t* mesocrystalMap() { return &m_MesoCrystalLabel; } multilayers_t* multiLayerMap() { return &m_MultiLayerLabel; } particlecompositions_t* particleCompositionMap() { return &m_ParticleCompositionLabel; } @@ -84,7 +87,8 @@ public: std::string labelLayer(const Layer* sample); std::string labelLayout(const ParticleLayout* sample); std::string labelMaterial(const Material* sample); - std::string labelLattice(const Lattice3D* sample); + std::string labelLattice2D(const Lattice2D* sample); + std::string labelLattice3D(const Lattice3D* sample); std::string labelMultiLayer(const MultiLayer* sample); std::string labelParticle(const IAbstractParticle* sample); std::string labelRotation(const IRotation* sample); @@ -96,7 +100,8 @@ public: void insertLayer(const Layer* sample); void insertLayout(const ParticleLayout* sample); void insertMaterial(const Material* sample); - void insertLattice(const Lattice3D* sample); + void insertLattice2D(const Lattice2D* sample); + void insertLattice3D(const Lattice3D* sample); void insertMesoCrystal(const MesoCrystal* sample); void insertMultiLayer(const MultiLayer* sample); void insertParticleComposition(const ParticleComposition* sample); @@ -113,7 +118,8 @@ private: layers_t m_LayerLabel; layouts_t m_ParticleLayoutLabel; materials_t m_MaterialLabel; - lattices_t m_LatticeLabel; + lattices2D_t m_Lattice2DLabel; + lattices3D_t m_Lattice3DLabel; mesocrystals_t m_MesoCrystalLabel; multilayers_t m_MultiLayerLabel; particlecompositions_t m_ParticleCompositionLabel; diff --git a/Core/Export/SampleToPython.cpp b/Core/Export/SampleToPython.cpp index 12e167f9752..e1c65530c0a 100644 --- a/Core/Export/SampleToPython.cpp +++ b/Core/Export/SampleToPython.cpp @@ -67,7 +67,7 @@ void SampleToPython::initLabels(const MultiLayer& multilayer) for (auto x : INodeUtils::AllDescendantsOfType<ParticleDistribution>(multilayer)) m_label->insertParticleDistribution(x); for (auto x : INodeUtils::AllDescendantsOfType<Lattice3D>(multilayer)) - m_label->insertLattice(x); + m_label->insertLattice3D(x); for (auto x : INodeUtils::AllDescendantsOfType<Crystal>(multilayer)) m_label->insertCrystal(x); for (auto x : INodeUtils::AllDescendantsOfType<MesoCrystal>(multilayer)) @@ -84,7 +84,8 @@ std::string SampleToPython::defineGetSample() const { return "def " + pyfmt::getSampleFunctionName() + "():\n" + defineMaterials() + defineLayers() + defineFormFactors() + defineParticles() + defineCoreShellParticles() - + defineParticleCompositions() + defineLattices() + defineCrystals() + + defineParticleCompositions() + defineLattices2D() + defineLattices3D() + + defineCrystals() + defineMesoCrystals() + defineParticleDistributions() + defineInterferenceFunctions() + defineParticleLayouts() + defineRoughnesses() + addLayoutsToLayers() + defineMultiLayers() + "\n\n"; @@ -285,9 +286,29 @@ std::string SampleToPython::defineParticleCompositions() const return result.str(); } -std::string SampleToPython::defineLattices() const +std::string SampleToPython::defineLattices2D() const { - const auto themap = m_label->latticeMap(); + const auto themap = m_label->lattice2DMap(); + if (themap->empty()) + return ""; + std::ostringstream result; + result << std::setprecision(12); + result << "\n" << indent() << "# Defining 2D lattices\n"; + for (auto it = themap->begin(); it != themap->end(); ++it) { + const Lattice2D* p_lattice = it->first; + std::string lattice_name = it->second; + result << indent() << lattice_name << " = ba.BasicLattice(\n"; + result << indent() << indent() + << pyfmt::printNm(p_lattice->length1()) << ", " + << pyfmt::printNm(p_lattice->length2()) << ", " + << pyfmt::printNm(p_lattice->latticeAngle()) << "),\n"; + } + return result.str(); +} + +std::string SampleToPython::defineLattices3D() const +{ + const auto themap = m_label->lattice3DMap(); if (themap->empty()) return ""; std::ostringstream result; @@ -327,7 +348,7 @@ std::string SampleToPython::defineCrystals() const continue; result << indent() << crystal_name << " = ba.Crystal("; result << m_label->labelParticle(p_basis) << ", "; - result << m_label->labelLattice(p_lattice) << ")\n"; + result << m_label->labelLattice3D(p_lattice) << ")\n"; } return result.str(); } diff --git a/Core/Export/SampleToPython.h b/Core/Export/SampleToPython.h index 4f9caa5b3b3..f60aaeaa742 100644 --- a/Core/Export/SampleToPython.h +++ b/Core/Export/SampleToPython.h @@ -43,7 +43,8 @@ private: std::string defineCoreShellParticles() const; std::string defineParticleDistributions() const; std::string defineParticleCompositions() const; - std::string defineLattices() const; + std::string defineLattices2D() const; + std::string defineLattices3D() const; std::string defineCrystals() const; std::string defineMesoCrystals() const; std::string defineInterferenceFunctions() const; diff --git a/auto/Wrap/doxygenCore.i b/auto/Wrap/doxygenCore.i index 91b79dad64e..9da439c9a8f 100644 --- a/auto/Wrap/doxygenCore.i +++ b/auto/Wrap/doxygenCore.i @@ -1955,7 +1955,10 @@ C++ includes: SampleLabelHandler.h %feature("docstring") SampleLabelHandler::materialMap "materials_t* SampleLabelHandler::materialMap() "; -%feature("docstring") SampleLabelHandler::latticeMap "lattices_t* SampleLabelHandler::latticeMap() +%feature("docstring") SampleLabelHandler::lattice2DMap "lattices2D_t* SampleLabelHandler::lattice2DMap() +"; + +%feature("docstring") SampleLabelHandler::lattice3DMap "lattices3D_t* SampleLabelHandler::lattice3DMap() "; %feature("docstring") SampleLabelHandler::mesocrystalMap "mesocrystals_t* SampleLabelHandler::mesocrystalMap() @@ -2000,7 +2003,10 @@ C++ includes: SampleLabelHandler.h %feature("docstring") SampleLabelHandler::labelMaterial "std::string SampleLabelHandler::labelMaterial(const Material *sample) "; -%feature("docstring") SampleLabelHandler::labelLattice "std::string SampleLabelHandler::labelLattice(const Lattice3D *sample) +%feature("docstring") SampleLabelHandler::labelLattice2D "std::string SampleLabelHandler::labelLattice2D(const Lattice2D *sample) +"; + +%feature("docstring") SampleLabelHandler::labelLattice3D "std::string SampleLabelHandler::labelLattice3D(const Lattice3D *sample) "; %feature("docstring") SampleLabelHandler::labelMultiLayer "std::string SampleLabelHandler::labelMultiLayer(const MultiLayer *sample) @@ -2033,7 +2039,10 @@ C++ includes: SampleLabelHandler.h %feature("docstring") SampleLabelHandler::insertMaterial "void SampleLabelHandler::insertMaterial(const Material *sample) "; -%feature("docstring") SampleLabelHandler::insertLattice "void SampleLabelHandler::insertLattice(const Lattice3D *sample) +%feature("docstring") SampleLabelHandler::insertLattice2D "void SampleLabelHandler::insertLattice2D(const Lattice2D *sample) +"; + +%feature("docstring") SampleLabelHandler::insertLattice3D "void SampleLabelHandler::insertLattice3D(const Lattice3D *sample) "; %feature("docstring") SampleLabelHandler::insertMesoCrystal "void SampleLabelHandler::insertMesoCrystal(const MesoCrystal *sample) -- GitLab