From 27c185bf4db09b9c0e7e5b692f89002cad3afd15 Mon Sep 17 00:00:00 2001 From: Walter Van Herck <w.van.herck@fz-juelich.de> Date: Tue, 17 Feb 2015 14:33:41 +0100 Subject: [PATCH] Added functional test for python script generation of LatticeBasis and readded old isgisaxs06b functional test --- Core/StandardSamples/IsGISAXS06Builder.cpp | 28 +-- Core/StandardSamples/SimulationRegistry.cpp | 4 + Core/StandardSamples/StandardSimulations.cpp | 19 +- Core/StandardSamples/StandardSimulations.h | 1 + Core/Tools/src/LabelSample.cpp | 12 +- Core/Tools/src/PyGenVisitor.cpp | 213 +++++++++--------- Tests/FunctionalTests/TestCore/CMakeLists.txt | 2 +- .../FunctionalTests/TestPyCore/CMakeLists.txt | 1 + .../PyScript_isgisaxs06b.cpp | 14 ++ .../FunctionalTests/TestPyCore/isgisaxs06.py | 2 +- 10 files changed, 170 insertions(+), 126 deletions(-) create mode 100644 Tests/FunctionalTests/TestPyCore/PyScript_isgisaxs06b/PyScript_isgisaxs06b.cpp diff --git a/Core/StandardSamples/IsGISAXS06Builder.cpp b/Core/StandardSamples/IsGISAXS06Builder.cpp index 235f3fa89f3..5191c5f481a 100644 --- a/Core/StandardSamples/IsGISAXS06Builder.cpp +++ b/Core/StandardSamples/IsGISAXS06Builder.cpp @@ -24,6 +24,8 @@ #include "IntensityDataIOFactory.h" #include "Utils.h" +#include <LatticeBasis.h> + // ----------------------------------------------------------------------------- // lattice #1: @@ -82,23 +84,21 @@ ISample *IsGISAXS06Lattice2Builder::buildSample() const 100.0*Units::nanometer/2.0/M_PI); interference_function.setProbabilityDistribution(pdf); - ParticleLayout particle_layout1; - // particle 1 FormFactorCylinder ff_cyl(5.0*Units::nanometer, 5.0*Units::nanometer); - kvector_t position(0.0, 0.0, 0.0); - Particle p(particle_material, ff_cyl); - ParticleInfo particle_info(p, position, 1.0); - particle_layout1.addParticleInfo(particle_info); - particle_layout1.addInterferenceFunction(interference_function); - ParticleLayout particle_layout2; - // particle 2 + Particle cylinder(particle_material, ff_cyl); + std::vector<kvector_t > positions; + kvector_t position_1(0.0, 0.0, 0.0); kvector_t position_2(5.0*Units::nanometer, 5.0*Units::nanometer, 0.0); - particle_info.setPosition(position_2); - particle_layout2.addParticleInfo(particle_info); - particle_layout2.addInterferenceFunction(interference_function); + positions.push_back(position_1); + positions.push_back(position_2); + LatticeBasis basis; + basis.addParticle(cylinder, positions); - air_layer.addLayout(particle_layout1); - air_layer.addLayout(particle_layout2); + ParticleLayout particle_layout; + particle_layout.addParticle(basis); + particle_layout.addInterferenceFunction(interference_function); + particle_layout.setTotalParticleSurfaceDensity(0.5); + air_layer.addLayout(particle_layout); multi_layer->addLayer(air_layer); multi_layer->addLayer(substrate_layer); diff --git a/Core/StandardSamples/SimulationRegistry.cpp b/Core/StandardSamples/SimulationRegistry.cpp index 4727226763f..34bbbb17068 100644 --- a/Core/StandardSamples/SimulationRegistry.cpp +++ b/Core/StandardSamples/SimulationRegistry.cpp @@ -131,6 +131,10 @@ SimulationRegistry::SimulationRegistry() "gui_isgisaxs06a", StandardSimulations::gui_IsGISAXS06L1, "GUI: 2D lattice with disorders"); + registerItem( + "gui_isgisaxs06b", StandardSimulations::gui_IsGISAXS06L2, + "GUI: 2D lattice centered"); + registerItem( "gui_isgisaxs07", StandardSimulations::gui_IsGISAXS07, "GUI: Mixture of fixed particles"); diff --git a/Core/StandardSamples/StandardSimulations.cpp b/Core/StandardSamples/StandardSimulations.cpp index aa248be833a..23bdb931801 100644 --- a/Core/StandardSamples/StandardSimulations.cpp +++ b/Core/StandardSamples/StandardSimulations.cpp @@ -383,7 +383,7 @@ Simulation *StandardSimulations::PolarizedDWBAMagCylinders1() Simulation *result = new Simulation(); - result->setDetectorParameters(100, 0.0*Units::degree, 2.0*Units::degree, + result->setDetectorParameters(100, 0.0*Units::degree, 2.0*Units::degree, 100, 0.0*Units::degree, 2.0*Units::degree); result->setBeamParameters(1.0*Units::angstrom, 0.2*Units::degree, 0.0*Units::degree); @@ -557,6 +557,23 @@ Simulation *StandardSimulations::gui_IsGISAXS06L1() return result; } +Simulation *StandardSimulations::gui_IsGISAXS06L2() +{ + SampleBuilderFactory factory; + SampleBuilder_t builder = factory.createBuilder("isgisaxs06b"); + + Simulation *result = new Simulation(); + + result->setDetectorParameters(100, 0.0*Units::degree, 2.0*Units::degree, + 100, 0.0*Units::degree, 2.0*Units::degree); + result->setBeamParameters(1.0*Units::angstrom, 0.2*Units::degree, + 0.0*Units::degree); + + result->setSampleBuilder( builder ); + + return result; +} + Simulation *StandardSimulations::gui_IsGISAXS07() { SampleBuilderFactory factory; diff --git a/Core/StandardSamples/StandardSimulations.h b/Core/StandardSamples/StandardSimulations.h index 9e6ad4b4b84..04eccd4a6c8 100644 --- a/Core/StandardSamples/StandardSimulations.h +++ b/Core/StandardSamples/StandardSimulations.h @@ -53,6 +53,7 @@ Simulation *gui_IsGISAXS041DDL(); Simulation *gui_IsGISAXS042DDL(); Simulation *gui_IsGISAXS11(); Simulation *gui_IsGISAXS06L1(); +Simulation *gui_IsGISAXS06L2(); Simulation *gui_IsGISAXS07(); Simulation *gui_MultipleLayouts(); } diff --git a/Core/Tools/src/LabelSample.cpp b/Core/Tools/src/LabelSample.cpp index 28b3d7b7e15..0ee39e1951b 100644 --- a/Core/Tools/src/LabelSample.cpp +++ b/Core/Tools/src/LabelSample.cpp @@ -13,6 +13,7 @@ // // ************************************************************************** // +#include <LatticeBasis.h> #include <iostream> #include "LabelSample.h" #include "ParticleCoreShell.h" @@ -53,10 +54,13 @@ std::string LabelSample::getLabel(const MultiLayer *sample) std::string LabelSample::getLabel(const IParticle *sample) { - if (const ParticleCoreShell *pcs = dynamic_cast<const ParticleCoreShell*>(sample)) - return m_ParticleCoreShellLabel[pcs]; - if (const Particle *p = dynamic_cast<const Particle*>(sample)) - return m_ParticleLabel[p]; + if (const ParticleCoreShell *core_shell_particle = + dynamic_cast<const ParticleCoreShell*>(sample)) + return m_ParticleCoreShellLabel[core_shell_particle]; + if (const Particle *particle = dynamic_cast<const Particle*>(sample)) + return m_ParticleLabel[particle]; + if (const LatticeBasis *lattice_basis = dynamic_cast<const LatticeBasis*>(sample)) + return m_LatticeBasisLabel[lattice_basis]; throw Exceptions::NotImplementedException("LabelSample::getLabel: called" " for unknown IParticle type"); } diff --git a/Core/Tools/src/PyGenVisitor.cpp b/Core/Tools/src/PyGenVisitor.cpp index 6cbbf879d8b..82880adc6d1 100644 --- a/Core/Tools/src/PyGenVisitor.cpp +++ b/Core/Tools/src/PyGenVisitor.cpp @@ -244,8 +244,9 @@ std::string PyGenVisitor::definePreamble() const std::ostringstream result; result << "import numpy\n"; result << "from libBornAgainCore import *\n"; - result << "#NOTE: Uncomment the next import statement for plotting\n"; - result << "#import pylab\n\n"; + result << "#NOTE: Uncomment the next import statements for plotting\n"; + result << "#import pylab\n"; + result << "#import matplotlib\n\n"; result << "#NOTE: All the ANGLES are displayed in RADIANS\n\n"; result << "#NOTE: Running this Script by default will write output data" << "to \"output.int\" file\n"; @@ -308,7 +309,7 @@ std::string PyGenVisitor::defineMaterials() const if (p_material->isScalarMaterial()) { result << "\t" << m_label->getLabel(p_material) << " = HomogeneousMaterial(\"" << p_material->getName(); - result << "\"," << PyGenTools::printDouble(delta) << "," + result << "\", " << PyGenTools::printDouble(delta) << ", " << PyGenTools::printDouble(beta) << ")\n"; } else { @@ -327,7 +328,7 @@ std::string PyGenVisitor::defineMaterials() const << ")\n"; result << "\t" << m_label->getLabel(p_material) << " = HomogeneousMagneticMaterial(\"" << p_material->getName(); - result << "\"," << PyGenTools::printDouble(delta) << ", " + result << "\", " << PyGenTools::printDouble(delta) << ", " << PyGenTools::printDouble(beta) << ", " << "magnetic_field)\n"; } @@ -352,7 +353,7 @@ std::string PyGenVisitor::defineLayers() const << m_label->getLabel(layer->getMaterial()); if (layer->getThickness() != 0) { - result << "," << layer->getThickness(); + result << ", " << layer->getThickness(); } result << ")\n"; it++; @@ -377,9 +378,9 @@ std::string PyGenVisitor::defineFormFactors() const dynamic_cast<const FormFactorAnisoPyramid *>(p_ff)) { result << " = FormFactorAnisoPyramid(" - << anisoPyramid->getLength()<< "*nanometer," - << anisoPyramid->getWidth() << "*nanometer," - << anisoPyramid->getHeight() << "*nanometer," + << anisoPyramid->getLength()<< "*nanometer, " + << anisoPyramid->getWidth() << "*nanometer, " + << anisoPyramid->getHeight() << "*nanometer, " << anisoPyramid->getAlpha() << ")\n"; } @@ -387,8 +388,8 @@ std::string PyGenVisitor::defineFormFactors() const dynamic_cast<const FormFactorBox *>(p_ff)) { result << " = FormFactorBox(" - << box->getLength() << "*nanometer," - << box->getWidth() << "*nanometer," + << box->getLength() << "*nanometer, " + << box->getWidth() << "*nanometer, " << box->getHeight() << "*nanometer)\n"; } @@ -396,8 +397,8 @@ std::string PyGenVisitor::defineFormFactors() const dynamic_cast<const FormFactorCone *>(p_ff)) { result << " = FormFactorCone(" - << cone->getRadius() << "*nanometer," - << cone->getHeight() << "*nanometer," + << cone->getRadius() << "*nanometer, " + << cone->getHeight() << "*nanometer, " << cone->getAlpha() << ")\n"; } @@ -405,8 +406,8 @@ std::string PyGenVisitor::defineFormFactors() const dynamic_cast<const FormFactorCone6 *>(p_ff)) { result << " = FormFactorCone6(" - << cone6->getRadius() << "*nanometer," - << cone6->getHeight() << "*nanometer," + << cone6->getRadius() << "*nanometer, " + << cone6->getHeight() << "*nanometer, " << cone6->getAlpha() << ")\n"; } @@ -414,9 +415,9 @@ std::string PyGenVisitor::defineFormFactors() const dynamic_cast<const FormFactorCuboctahedron *>(p_ff)) { result << " = FormFactorCuboctahedron(" - << cuboctahedron->getLength() << "*nanometer," - << cuboctahedron->getHeight() << "*nanometer," - << cuboctahedron->getHeightRatio() << "*nanometer" + << cuboctahedron->getLength() << "*nanometer, " + << cuboctahedron->getHeight() << "*nanometer, " + << cuboctahedron->getHeightRatio() << "*nanometer, " << cuboctahedron->getAlpha() << ")\n"; } @@ -424,7 +425,7 @@ std::string PyGenVisitor::defineFormFactors() const dynamic_cast<const FormFactorCylinder *>(p_ff)) { result << " = FormFactorCylinder(" - << cylinder->getHeight() << "*nanometer," + << cylinder->getHeight() << "*nanometer, " << cylinder->getRadius() << "*nanometer)\n"; } @@ -432,8 +433,8 @@ std::string PyGenVisitor::defineFormFactors() const dynamic_cast<const FormFactorEllipsoidalCylinder *>(p_ff)) { result << " = FormFactorEllipsoidalCylinder(" - << ellipsoidalCylinder->getRadiusA() << "*nanometer," - << ellipsoidalCylinder->getRadiusB() << "*nanometer," + << ellipsoidalCylinder->getRadiusA() << "*nanometer, " + << ellipsoidalCylinder->getRadiusB() << "*nanometer, " << ellipsoidalCylinder->getHeight() << "*nanometer)\n"; } @@ -448,7 +449,7 @@ std::string PyGenVisitor::defineFormFactors() const dynamic_cast<const FormFactorFullSpheroid *>(p_ff)) { result << " = FormFactorFullSpheroid(" - << fullSpheroid->getRadius() << "*nanometer," + << fullSpheroid->getRadius() << "*nanometer, " << fullSpheroid->getHeight() << "*nanometer)\n"; } @@ -463,7 +464,7 @@ std::string PyGenVisitor::defineFormFactors() const else { result << " = FormFactorGauss(" - << gauss->getRadius() << "*nanometer," + << gauss->getRadius() << "*nanometer, " << gauss->getHeight() << "*nanometer)\n"; } } @@ -472,8 +473,8 @@ std::string PyGenVisitor::defineFormFactors() const dynamic_cast<const FormFactorHemiEllipsoid *>(p_ff)) { result << " = FormFactorHemiEllipsoid(" - << hemiEllipsoid->getRadiusA() << "*nanometer," - << hemiEllipsoid->getRadiusB() << "*nanometer," + << hemiEllipsoid->getRadiusA() << "*nanometer, " + << hemiEllipsoid->getRadiusB() << "*nanometer, " << hemiEllipsoid->getHeight() << "*nanometer)\n"; } @@ -481,7 +482,7 @@ std::string PyGenVisitor::defineFormFactors() const dynamic_cast<const FormFactorInfLongBox *>(p_ff)) { result << " = FormFactorInfLongBox(" - << infLongBox->getWidth() << "*nanometer," + << infLongBox->getWidth() << "*nanometer, " << infLongBox->getHeight() << "*nanometer)\n"; } @@ -489,7 +490,7 @@ std::string PyGenVisitor::defineFormFactors() const dynamic_cast<const FormFactorInfLongRipple1 *>(p_ff)) { result << " = FormFactorInfLongRipple1(" - << infLongRipple1->getWidth() << "*nanometer," + << infLongRipple1->getWidth() << "*nanometer, " << infLongRipple1->getHeight() << "*nanometer)\n"; } @@ -497,8 +498,8 @@ std::string PyGenVisitor::defineFormFactors() const dynamic_cast<const FormFactorInfLongRipple2 *>(p_ff)) { result << " = FormFactorInfLongRipple2(" - << infLongRipple2->getWidth() << "*nanometer," - << infLongRipple1->getHeight() << "*nanometer," + << infLongRipple2->getWidth() << "*nanometer, " + << infLongRipple1->getHeight() << "*nanometer, " << infLongRipple2->getAsymetry() << "*nanometer)\n"; } @@ -513,7 +514,7 @@ std::string PyGenVisitor::defineFormFactors() const else { result << " = FormFactorLorentz(" - << lorentz->getRadius() << "*nanometer," + << lorentz->getRadius() << "*nanometer, " << lorentz->getHeight() << "*nanometer)\n"; } } @@ -522,7 +523,7 @@ std::string PyGenVisitor::defineFormFactors() const dynamic_cast<const FormFactorPrism3 *>(p_ff)) { result << " = FormFactorPrism3(" - << prism3->getLength() << "*nanometer," + << prism3->getLength() << "*nanometer, " << prism3->getHeight() << "*nanometer)\n"; } @@ -530,7 +531,7 @@ std::string PyGenVisitor::defineFormFactors() const dynamic_cast<const FormFactorPrism6 *>(p_ff)) { result << " = FormFactorPrism6(" - << prism6->getRadius() << "*nanometer," + << prism6->getRadius() << "*nanometer, " << prism6->getHeight() << "*nanometer)\n"; } @@ -538,8 +539,8 @@ std::string PyGenVisitor::defineFormFactors() const dynamic_cast<const FormFactorPyramid *>(p_ff)) { result << " = FormFactorPyramid(" - << pyramid->getLength() << "*nanometer," - << pyramid->getHeight() << "*nanometer," + << pyramid->getLength() << "*nanometer, " + << pyramid->getHeight() << "*nanometer, " << pyramid->getAlpha() << ")\n"; } @@ -547,8 +548,8 @@ std::string PyGenVisitor::defineFormFactors() const dynamic_cast<const FormFactorRipple1 *>(p_ff)) { result << " = FormFactorRipple1(" - << ripple1->getLength() << "*nanometer," - << ripple1->getWidth() << "*nanometer," + << ripple1->getLength() << "*nanometer, " + << ripple1->getWidth() << "*nanometer, " << ripple1->getHeight() << "*nanometer)\n"; } @@ -556,9 +557,9 @@ std::string PyGenVisitor::defineFormFactors() const dynamic_cast<const FormFactorRipple2 *>(p_ff)) { result << " = FormFactorRipple2(" - << ripple2->getLength() << "*nanometer," - << ripple2->getWidth() << "*nanometer," - << ripple2->getHeight() << "nanometer," + << ripple2->getLength() << "*nanometer, " + << ripple2->getWidth() << "*nanometer, " + << ripple2->getHeight() << "nanometer, " << ripple2->getAsymmetry() << "*nanometer)\n"; } @@ -566,8 +567,8 @@ std::string PyGenVisitor::defineFormFactors() const dynamic_cast<const FormFactorTetrahedron *>(p_ff)) { result << " = FormFactorTetrahedron(" - << tetrahedron->getLength() << "*nanometer," - << tetrahedron->getHeight() << "*nanometer," + << tetrahedron->getLength() << "*nanometer, " + << tetrahedron->getHeight() << "*nanometer, " << tetrahedron->getAlpha() << ")\n"; } @@ -575,7 +576,7 @@ std::string PyGenVisitor::defineFormFactors() const dynamic_cast<const FormFactorTruncatedSphere *>(p_ff)) { result << " = FormFactorTruncatedSphere(" - << truncatedSphere->getRadius() << "*nanometer," + << truncatedSphere->getRadius() << "*nanometer, " << truncatedSphere->getHeight() << "*nanometer)\n"; } @@ -583,8 +584,8 @@ std::string PyGenVisitor::defineFormFactors() const dynamic_cast<const FormFactorTruncatedSpheroid *>(p_ff)) { result << " = FormFactorTruncatedSpheroid(" - << truncatedSpheroid->getRadius() << "*nanometer," - << truncatedSpheroid->getHeight() << "*nanometer," + << truncatedSpheroid->getRadius() << "*nanometer, " + << truncatedSpheroid->getHeight() << "*nanometer, " << truncatedSpheroid->getHeightFlattening() << "*nanometer)\n"; } @@ -645,11 +646,11 @@ std::string PyGenVisitor::defineParticles() const } result << "\t" << it->second << " = Particle(" << m_label->getLabel(particle->getMaterial()) - << "," << m_label->getLabel(particle->getFormFactor()); + << ", " << m_label->getLabel(particle->getFormFactor()); if (particle->getTransform3D()) { - result << "," << it->second << "_rotation"; + result << ", " << it->second << "_rotation"; } result << ")\n"; @@ -672,12 +673,12 @@ std::string PyGenVisitor::defineCoreShellParticles() const kvector_t position = it->first->getRelativeCorePosition(); result << "\t" << it->second << "_relPosition = kvector_t(" - << position.x() << "*nanometer," - << position.y() << "*nanometer," + << position.x() << "*nanometer, " + << position.y() << "*nanometer, " << position.z() << "*nanometer)"; result << "\n\t" << it->second << " = ParticleCoreShell(" - << m_label->getLabel(it->first->getShellParticle()) << "," + << m_label->getLabel(it->first->getShellParticle()) << ", " << m_label->getLabel(it->first->getCoreParticle()) << ", " << it->second << "_relPosition)\n"; it++; @@ -700,16 +701,16 @@ std::string PyGenVisitor::defineLatticeBases() const for (size_t i=0; i<it->first->getNbrParticles(); ++i) { std::vector<kvector_t> position_vector = it->first->getParticlePositions(i); for (size_t j=0; j<position_vector.size(); ++j) { - result << "\tparticle_" << i - << "_position_" << j << " = kvector_t(" - << position_vector[j].x() << "*nanometer," - << position_vector[j].y() << "*nanometer," + result << "\tparticle_" << i+1 + << "_position_" << j+1 << " = kvector_t(" + << position_vector[j].x() << "*nanometer, " + << position_vector[j].y() << "*nanometer, " << position_vector[j].z() << "*nanometer)\n"; } result << "\t" << it->second << ".addParticle(" << m_label->getLabel(it->first->getParticle(i)) << ", ["; for (size_t j=0; j<position_vector.size(); ++j) { - result << "particle_" << i << "_position_" << j; + result << "particle_" << i+1 << "_position_" << j+1; if (j!=position_vector.size()-1) result << ", "; } result << "])\n"; @@ -771,7 +772,7 @@ std::string PyGenVisitor::defineInterferenceFunctions() const { result << "\t" << it->second << "_pdf = FTDistribution1DVoigt(" - << PyGenTools::printDouble(fTD1DVoigt->getOmega()) << "," + << PyGenTools::printDouble(fTD1DVoigt->getOmega()) << ", " << PyGenTools::printDouble(fTD1DVoigt->getEta()) << ")\n"; } @@ -842,7 +843,7 @@ std::string PyGenVisitor::defineInterferenceFunctions() const { result << "\t" << it->second << " = InterferenceFunctionRadialParaCrystal(" - << oneDParaCrystal->getPeakDistance() << "*nanometer," + << oneDParaCrystal->getPeakDistance() << "*nanometer, " << oneDParaCrystal->getDampingLength() << "*nanometer)\n"; if (oneDParaCrystal->getKappa() != 0.0) @@ -869,7 +870,7 @@ std::string PyGenVisitor::defineInterferenceFunctions() const { result << "\t" << it->second << "_pdf = FTDistribution1DVoigt(" - << PyGenTools::printDouble(fTD1DVoigt->getOmega()) << "," + << PyGenTools::printDouble(fTD1DVoigt->getOmega()) << ", " << PyGenTools::printDouble(fTD1DVoigt->getEta()) << ")\n"; } @@ -956,7 +957,7 @@ std::string PyGenVisitor::defineInterferenceFunctions() const result << "\t" << it->second << "_pdf = FTDistribution2DCauchy(" << PyGenTools::printDouble(fTD2DCauchy->getCoherenceLengthX()) - << "*nanometer," + << "*nanometer, " << PyGenTools::printDouble(fTD2DCauchy->getCoherenceLengthY()) << "*nanometer" << ")\n"; if (fTD2DCauchy->getGamma() != 0.0) @@ -973,7 +974,7 @@ std::string PyGenVisitor::defineInterferenceFunctions() const { result << "\t" << it->second << "_pdf = FTDistribution2DCone(" - << fTD2DCone->getCoherenceLengthX() << "*nanometer," + << fTD2DCone->getCoherenceLengthX() << "*nanometer, " << fTD2DCone->getCoherenceLengthY() << "*nanometer" << ")\n"; @@ -991,7 +992,7 @@ std::string PyGenVisitor::defineInterferenceFunctions() const { result << "\t" << it->second << "_pdf = FTDistribution2DGate(" - << fTD2DGate->getCoherenceLengthX() << "*nanometer," + << fTD2DGate->getCoherenceLengthX() << "*nanometer, " << fTD2DGate->getCoherenceLengthY() << "*nanometer" << ")\n"; @@ -1009,7 +1010,7 @@ std::string PyGenVisitor::defineInterferenceFunctions() const { result << "\t" << it->second << "_pdf = FTDistribution2DGauss(" - << fTD2DGauss->getCoherenceLengthX() << "*nanometer," + << fTD2DGauss->getCoherenceLengthX() << "*nanometer, " << fTD2DGauss->getCoherenceLengthY() << "*nanometer" << ")\n"; @@ -1027,8 +1028,8 @@ std::string PyGenVisitor::defineInterferenceFunctions() const { result << "\t" << it->second << "_pdf = FTDistribution2DVoigt(" - << fTD2DVoigt->getCoherenceLengthX() << "*nanometer," - << fTD2DVoigt->getCoherenceLengthY() << "*nanometer," + << fTD2DVoigt->getCoherenceLengthX() << "*nanometer, " + << fTD2DVoigt->getCoherenceLengthY() << "*nanometer, " << PyGenTools::printDouble(fTD2DVoigt->getEta()) << ")\n"; if (fTD2DVoigt->getGamma() != 0.0) @@ -1065,9 +1066,9 @@ std::string PyGenVisitor::defineInterferenceFunctions() const { result << "\t" << it->second << " = InterferenceFunction2DParaCrystal.createSquare(" - << twoDParaCrystal->getLatticeLengths()[0]<< "*nanometer," - << twoDParaCrystal->getDampingLength() << "*nanometer," - << domainSize[0] << "*nanometer," + << twoDParaCrystal->getLatticeLengths()[0]<< "*nanometer, " + << twoDParaCrystal->getDampingLength() << "*nanometer, " + << domainSize[0] << "*nanometer, " << domainSize[1] << "*nanometer)\n"; } @@ -1078,9 +1079,9 @@ std::string PyGenVisitor::defineInterferenceFunctions() const { result << "\t" << it->second << " = InterferenceFunction2DParaCrystal.createHexagonal(" - << twoDParaCrystal->getLatticeLengths()[0]<< "*nanometer," - << twoDParaCrystal->getDampingLength() << "*nanometer," - << domainSize[0] << "*nanometer," + << twoDParaCrystal->getLatticeLengths()[0]<< "*nanometer, " + << twoDParaCrystal->getDampingLength() << "*nanometer, " + << domainSize[0] << "*nanometer, " << domainSize[1] << "*nanometer)\n"; } @@ -1088,12 +1089,12 @@ std::string PyGenVisitor::defineInterferenceFunctions() const { result << "\t" << it->second << " = InterferenceFunction2DParaCrystal" - << twoDParaCrystal->getLatticeLengths()[0]<< "*nanometer," - << twoDParaCrystal->getLatticeLengths()[1] << "*nanometer," + << twoDParaCrystal->getLatticeLengths()[0]<< "*nanometer, " + << twoDParaCrystal->getLatticeLengths()[1] << "*nanometer, " << PyGenTools::printDouble( - twoDParaCrystal->getAlphaLattice()) << "," + twoDParaCrystal->getAlphaLattice()) << ", " << PyGenTools::printDouble( - twoDParaCrystal->getLatticeOrientation()) << "," + twoDParaCrystal->getLatticeOrientation()) << ", " << twoDParaCrystal->getDampingLength() << "*nanometer)\n"; @@ -1102,7 +1103,7 @@ std::string PyGenVisitor::defineInterferenceFunctions() const { result << "\t" << it->second << ".setDomainSizes(" - << domainSize[0] << "*nanometer," + << domainSize[0] << "*nanometer, " << domainSize[1] << "*nanometer)\n"; } @@ -1122,7 +1123,7 @@ std::string PyGenVisitor::defineInterferenceFunctions() const { result << "\t" << it->second << "_pdf_1 = FTDistribution2DCauchy(" - << fTD2DCauchy->getCoherenceLengthX() << "*nanometer," + << fTD2DCauchy->getCoherenceLengthX() << "*nanometer, " << fTD2DCauchy->getCoherenceLengthY() << "*nanometer)\n"; if (fTD2DCauchy->getGamma() != 0.0) @@ -1138,7 +1139,7 @@ std::string PyGenVisitor::defineInterferenceFunctions() const { result << "\t" << it->second << "_pdf_1 = FTDistribution2DCone(" - << fTD2DCone->getCoherenceLengthX() << "*nanometer," + << fTD2DCone->getCoherenceLengthX() << "*nanometer, " << fTD2DCone->getCoherenceLengthY() << "*nanometer)\n"; if (fTD2DCone->getGamma() != 0.0) @@ -1154,7 +1155,7 @@ std::string PyGenVisitor::defineInterferenceFunctions() const { result << "\t" << it->second << "_pdf_1 = FTDistribution2DGate(" - << fTD2DGate->getCoherenceLengthX() << "*nanometer," + << fTD2DGate->getCoherenceLengthX() << "*nanometer, " << fTD2DGate->getCoherenceLengthY() << "*nanometer)\n"; if (fTD2DGate->getGamma() != 0.0) @@ -1170,7 +1171,7 @@ std::string PyGenVisitor::defineInterferenceFunctions() const { result << "\t" << it->second << "_pdf_1 = FTDistribution2DGauss(" - << fTD2DGauss->getCoherenceLengthX() << "*nanometer," + << fTD2DGauss->getCoherenceLengthX() << "*nanometer, " << fTD2DGauss->getCoherenceLengthY() << "*nanometer)\n"; if (fTD2DGauss->getGamma() != 0.0) @@ -1186,8 +1187,8 @@ std::string PyGenVisitor::defineInterferenceFunctions() const { result << "\t" << it->second << "_pdf_1 = FTDistribution2DVoigt(" - << fTD2DVoigt->getCoherenceLengthX() << "*nanometer," - << fTD2DVoigt->getCoherenceLengthY() << "*nanometer," + << fTD2DVoigt->getCoherenceLengthX() << "*nanometer, " + << fTD2DVoigt->getCoherenceLengthY() << "*nanometer, " << PyGenTools::printDouble(fTD2DVoigt->getEta()) << ")\n"; if (fTD2DVoigt->getGamma() != 0.0) @@ -1214,7 +1215,7 @@ std::string PyGenVisitor::defineInterferenceFunctions() const { result << "\t" << it->second << "_pdf_2 = FTDistribution2DCauchy(" - << fTD2DCauchy->getCoherenceLengthX() << "*nanometer," + << fTD2DCauchy->getCoherenceLengthX() << "*nanometer, " << fTD2DCauchy->getCoherenceLengthY() << "*nanometer)\n"; if (fTD2DCauchy->getGamma() != 0.0) @@ -1230,7 +1231,7 @@ std::string PyGenVisitor::defineInterferenceFunctions() const { result << "\t" << it->second << "_pdf_2 = FTDistribution2DCone(" - << fTD2DCone->getCoherenceLengthX() << "*nanometer," + << fTD2DCone->getCoherenceLengthX() << "*nanometer, " << fTD2DCone->getCoherenceLengthY() << "*nanometer)\n"; if (fTD2DCone->getGamma() != 0.0) @@ -1246,7 +1247,7 @@ std::string PyGenVisitor::defineInterferenceFunctions() const { result << "\t" << it->second << "_pdf_2 = FTDistribution2DGate(" - << fTD2DGate->getCoherenceLengthX() << "*nanometer," + << fTD2DGate->getCoherenceLengthX() << "*nanometer, " << fTD2DGate->getCoherenceLengthY() << "*nanometer)\n"; if (fTD2DGate->getGamma() != 0.0) @@ -1262,7 +1263,7 @@ std::string PyGenVisitor::defineInterferenceFunctions() const { result << "\t" << it->second << "_pdf_2 = FTDistribution2DGauss(" - << fTD2DGauss->getCoherenceLengthX() << "*nanometer," + << fTD2DGauss->getCoherenceLengthX() << "*nanometer, " << fTD2DGauss->getCoherenceLengthY() << "*nanometer)\n"; if (fTD2DGauss->getGamma() != 0.0) @@ -1278,8 +1279,8 @@ std::string PyGenVisitor::defineInterferenceFunctions() const { result << "\t" << it->second << "_pdf_2 = FTDistribution2DVoigt(" - << fTD2DVoigt->getCoherenceLengthX() << "*nanometer," - << fTD2DVoigt->getCoherenceLengthY() << "*nanometer," + << fTD2DVoigt->getCoherenceLengthX() << "*nanometer, " + << fTD2DVoigt->getCoherenceLengthY() << "*nanometer, " << PyGenTools::printDouble(fTD2DVoigt->getEta()) << ")\n"; if (fTD2DVoigt->getGamma() != 0.0) @@ -1301,7 +1302,7 @@ std::string PyGenVisitor::defineInterferenceFunctions() const result << "\t" << it->second << ".setProbabilityDistributions(" - << it->second << "_pdf_2," << it->second << "_pdf_2)\n\n"; + << it->second << "_pdf_2, " << it->second << "_pdf_2)\n\n"; } else @@ -1347,9 +1348,9 @@ std::string PyGenVisitor::defineParticleLayouts() const << m_label->getLabel(particleInfo->getParticle()) << "_position = kvector_t(" << pos.x() - << "*nanometer," + << "*nanometer, " << pos.y() - << "*nanometer," + << "*nanometer, " << pos.z() << "*nanometer)\n"; @@ -1357,9 +1358,9 @@ std::string PyGenVisitor::defineParticleLayouts() const << m_label->getLabel(particleInfo->getParticle()) << "_positionInfo = ParticleInfo(" << m_label->getLabel(particleInfo->getParticle()) - << "," + << ", " << m_label->getLabel(particleInfo->getParticle()) - << "_position," + << "_position, " << PyGenTools::printDouble(particleInfo->getAbundance()) << ")\n"; @@ -1373,8 +1374,8 @@ std::string PyGenVisitor::defineParticleLayouts() const result << "\t" << it->second << ".addParticle(" << m_label->getLabel(particleInfo->getParticle()) - << "," - << PyGenTools::printDouble(particleInfo->getDepth()) << "," + << ", " + << PyGenTools::printDouble(particleInfo->getDepth()) << ", " << PyGenTools::printDouble(particleInfo->getAbundance()) <<")\n"; } particleIndex++; @@ -1403,7 +1404,9 @@ std::string PyGenVisitor::defineParticleLayouts() const result << "\t" << it->second << ".setApproximation(ILayout."; result << "ISGISAXSMOR)\n"; break; - } + } + result << "\t" << it->second << ".setTotalParticleSurfaceDensity(" + << it->first->getTotalParticleSurfaceDensity() << ")\n"; } it++; } @@ -1422,8 +1425,8 @@ std::string PyGenVisitor::defineRoughnesses() const { result << "\t" << it->second << " = LayerRoughness(" - << it->first->getSigma() << "*nanometer," - << it->first->getHurstParameter() << "," + << it->first->getSigma() << "*nanometer, " + << it->first->getHurstParameter() << ", " << it->first->getLatteralCorrLength() << "*nanometer)\n"; it++; } @@ -1490,7 +1493,7 @@ std::string PyGenVisitor::defineMultiLayers() const result << "\t" << it->second << ".addLayerWithTopRoughness(" << m_label->getLabel(it->first->getLayer(layerIndex)) - << "," + << ", " << m_label->getLabel(layerInterface->getRoughness()) << ")\n"; } @@ -1517,11 +1520,11 @@ std::string PyGenVisitor::defineDetector(const Simulation *simulation) const size_t index = 0; while (index < numberOfDetectorDimensions) { - if (index != 0) {result << ",";} + if (index != 0) {result << ", ";} result << simulation->getInstrument().getDetectorAxis(index).getSize() - << "," + << ", " << simulation->getInstrument().getDetectorAxis(index).getMin() - << "," + << ", " << simulation->getInstrument().getDetectorAxis(index).getMax(); index++; } @@ -1535,8 +1538,8 @@ std::string PyGenVisitor::defineBeam(const Simulation *simulation) const result << std::setprecision(12); result << "\t# Defining Beam Parameters\n"; result << "\tsimulation.setBeamParameters(" ; - result << simulation->getInstrument().getBeam().getWavelength() << "*nanometer," - << simulation->getInstrument().getBeam().getAlpha() << "," + result << simulation->getInstrument().getBeam().getWavelength() << "*nanometer, " + << simulation->getInstrument().getBeam().getAlpha() << ", " << simulation->getInstrument().getBeam().getPhi() << ")\n"; return result.str(); } @@ -1550,8 +1553,8 @@ std::string PyGenVisitor::definePlotting(const Simulation *simulation) const result << "#def plotSimulation(simulation):\n"; result << "#\tresult = simulation.getIntensityData().getArray()" << "+ 1 # +1 for log scale\n"; - result << "#\tim = pylab.imshow(numpy.rot90(result, 1)," - << "norm=pylab.colors.LogNorm(), extent=["; + result << "#\tim = pylab.imshow(numpy.rot90(result, 1), " + << "norm=matplotlib.colors.LogNorm(), extent=["; size_t index = 0; size_t numberOfDetectorDimensions = simulation->getInstrument().getDetectorDimension(); @@ -1559,10 +1562,10 @@ std::string PyGenVisitor::definePlotting(const Simulation *simulation) const { if (index != 0) { - result << ","; + result << ", "; } result << simulation->getInstrument().getDetectorAxis(index).getMin() - << "," + << ", " << simulation->getInstrument().getDetectorAxis(index).getMax(); index++; } diff --git a/Tests/FunctionalTests/TestCore/CMakeLists.txt b/Tests/FunctionalTests/TestCore/CMakeLists.txt index 6a7deb64c6d..11f74a6958e 100644 --- a/Tests/FunctionalTests/TestCore/CMakeLists.txt +++ b/Tests/FunctionalTests/TestCore/CMakeLists.txt @@ -13,7 +13,7 @@ set(list_of_tests "IsGISAXS041DDL" "IsGISAXS042DDL" "IsGISAXS06L1" -# "IsGISAXS06L2" + "IsGISAXS06L2" "IsGISAXS06L3" "IsGISAXS06L4" "IsGISAXS07" diff --git a/Tests/FunctionalTests/TestPyCore/CMakeLists.txt b/Tests/FunctionalTests/TestPyCore/CMakeLists.txt index 93818677813..41af8e39c69 100644 --- a/Tests/FunctionalTests/TestPyCore/CMakeLists.txt +++ b/Tests/FunctionalTests/TestPyCore/CMakeLists.txt @@ -35,6 +35,7 @@ set(list_of_cpp_python_tests "PyScript_isgisaxs04_1DDL" "PyScript_isgisaxs04_2DDL" "PyScript_isgisaxs06a" + "PyScript_isgisaxs06b" "PyScript_isgisaxs07" "PyScript_isgisaxs11" "PyScript_multiplelayoutbuilder" diff --git a/Tests/FunctionalTests/TestPyCore/PyScript_isgisaxs06b/PyScript_isgisaxs06b.cpp b/Tests/FunctionalTests/TestPyCore/PyScript_isgisaxs06b/PyScript_isgisaxs06b.cpp new file mode 100644 index 00000000000..c5ac5755ddd --- /dev/null +++ b/Tests/FunctionalTests/TestPyCore/PyScript_isgisaxs06b/PyScript_isgisaxs06b.cpp @@ -0,0 +1,14 @@ +#include "PyGenTools.h" +#include "SimulationRegistry.h" + +int main() +{ + SimulationRegistry simulationRegistry; + Simulation *simulation = + simulationRegistry.createSimulation("gui_isgisaxs06b"); + bool test = PyGenTools::testPyScript(simulation); + std::cout << "Python Script Generation Test for isgisaxs06b" + << "(2D lattice centered):" + << (test? "[OK]" : "[FAILED]") << std::endl; + return (test ? 0 : 1); +} diff --git a/Tests/FunctionalTests/TestPyCore/isgisaxs06.py b/Tests/FunctionalTests/TestPyCore/isgisaxs06.py index 5de5b25d055..6d4d32e28f3 100644 --- a/Tests/FunctionalTests/TestPyCore/isgisaxs06.py +++ b/Tests/FunctionalTests/TestPyCore/isgisaxs06.py @@ -62,7 +62,7 @@ def run_simulation_centered(): pdf = FTDistribution2DCauchy(300.0*nanometer/2.0/numpy.pi, 100.0*nanometer/2.0/numpy.pi) interference.setProbabilityDistribution(pdf) - # particle 1 + # two cylinders at fixed position of each other cylinder_ff = FormFactorCylinder(5*nanometer, 5*nanometer) cylinder = Particle(mParticle, cylinder_ff) position1 = kvector_t(0.0, 0.0, 0.0) -- GitLab