diff --git a/Tests/Functional/PyCore/legacy/customformfactor.py b/Tests/Functional/PyCore/legacy/customformfactor.py deleted file mode 100644 index f2978465b44993ef6b45f73aa03e5e1f239f27ad..0000000000000000000000000000000000000000 --- a/Tests/Functional/PyCore/legacy/customformfactor.py +++ /dev/null @@ -1,111 +0,0 @@ -# Functional test: Custom formfactor example -from __future__ import print_function -import sys -import os -import numpy -import math -from utils import get_reference_data - -from libBornAgainCore import * -from libBornAgainFit import * # TODO remove this once ICloneable is back in Core/ - -phi_min, phi_max = -1.0, 1.0 -alpha_min, alpha_max = 0.0, 2.0 - - -class CustomFormFactor(IFormFactorBorn): - """ - A custom defined form factor - The form factor is V sech(q L) with - V volume of particle - L length scale which defines mean radius - """ - def __init__(self, V, L): - IFormFactorBorn.__init__(self) - # parameters describing the form factor - self.V = V - self.L = L - - def clone(self): - """ - IMPORTANT NOTE: - The clone method needs to call transferToCPP() on the cloned object - to transfer the ownership of the clone to the cpp code - """ - cloned_ff = CustomFormFactor(self.V, self.L) - cloned_ff.transferToCPP() - return cloned_ff - - def evaluate_for_q(self, q): - return self.V*1.0/math.cosh(q.mag()*self.L) - - -def get_sample(): - """ - Build and return the sample to calculate custom form factor in Distorted Wave Born Approximation. - """ - # defining materials - m_ambience = HomogeneousMaterial("Air", 0.0, 0.0) - m_substrate = HomogeneousMaterial("Substrate", 6e-6, 2e-8) - m_particle = HomogeneousMaterial("Particle", 6e-4, 2e-8) - - # collection of particles - ff = CustomFormFactor(343.0*nanometer, 7.0*nanometer) - particle = Particle(m_particle, ff) - particle_layout = ParticleLayout() - particle_layout.addParticle(particle, 1.0) - air_layer = Layer(m_ambience) - air_layer.addLayout(particle_layout) - substrate_layer = Layer(m_substrate) - - # assemble multilayer - multi_layer = MultiLayer() - multi_layer.addLayer(air_layer) - multi_layer.addLayer(substrate_layer) - return multi_layer - - -def get_simulation(): - """ - Create and return GISAXS simulation with beam and detector defined - IMPORTANT NOTE: - Multithreading should be deactivated by putting ThreadInfo.n_threads to -1 - """ - simulation = GISASSimulation() - simulation.getOptions().setNumberOfThreads(-1) - simulation.setDetectorParameters(100, phi_min*degree, phi_max*degree, 100, alpha_min*degree, alpha_max*degree) - simulation.setBeamParameters(1.0*angstrom, 0.2*degree, 0.0*degree) - return simulation - - -def run_simulation(): - """ - Run simulation and plot results - """ - sample = get_sample() - simulation = get_simulation() - simulation.setSample(sample) - simulation.runSimulation() - result = simulation.getIntensityData() - return result - - -def run_test(): - """ - run test and analyse test results - """ - result = run_simulation() - reference = get_reference_data('customformfactor_reference.int.gz') - diff = IntensityDataFunctions.getRelativeDifference(result, reference) - status = "OK" - if diff > 2e-3 or numpy.isnan(diff): - print( "difference: %g" % diff ) - status = "FAILED" - return "CustomFormFactor", "Test of custom formfactor", diff, status - - -if __name__ == '__main__': - name, description, diff, status = run_test() - print(name, description, diff, status) - if "FAILED" in status: - exit(1) diff --git a/Tests/Functional/PyCore/legacy/cylinders_ba_dwba_size.py b/Tests/Functional/PyCore/legacy/cylinders_ba_dwba_size.py deleted file mode 100644 index 50b05dfecd771515de152331a8271499d7bb05a4..0000000000000000000000000000000000000000 --- a/Tests/Functional/PyCore/legacy/cylinders_ba_dwba_size.py +++ /dev/null @@ -1,147 +0,0 @@ -# Functional test: IsGISAXS03 example: Cylinder formfactor in BA and DWBA -from __future__ import print_function -import sys -import os -import numpy -from utils import get_reference_data - -from libBornAgainCore import * - -# ---------------------------------- -# describe sample and run simulation -# ---------------------------------- -def RunSimulationDWBA(): - - # defining materials - mAmbience = HomogeneousMaterial("Air", 0.0, 0.0 ) - mSubstrate = HomogeneousMaterial("Substrate", 6e-6, 2e-8 ) - mParticle = HomogeneousMaterial("Particle", 6e-4, 2e-8 ) - # collection of particles - cylinder_ff = FormFactorCylinder(5*nanometer, 5*nanometer) - cylinder = Particle(mParticle, cylinder_ff) - particle_layout = ParticleLayout() - particle_layout.addParticle(cylinder, 1.0) - interference = InterferenceFunctionNone() - particle_layout.addInterferenceFunction(interference) - # air layer with particles and substrate form multi layer - air_layer = Layer(mAmbience) - air_layer.addLayout(particle_layout) - substrate_layer = Layer(mSubstrate, 0) - - multi_layer = MultiLayer() - multi_layer.addLayer(air_layer) - multi_layer.addLayer(substrate_layer) - - # build and run experiment - simulation = GISASSimulation() - detector = IsGISAXSDetector(100, 0.0*degree, 2.0*degree, 100, 0.0*degree, 2.0*degree) - simulation.setDetector(detector) - simulation.setBeamParameters(1.0*angstrom, 0.2*degree, 0.0*degree) - simulation.setSample(multi_layer) - simulation.runSimulation() - # intensity data - return simulation.getIntensityData() - - -# ---------------------------------- -# describe sample and run simulation - IsGISAXS3 functional test: cylinder in the air -# ---------------------------------- -def RunSimulationBA(): - # defining materials - mAmbience = HomogeneousMaterial("Air", 0.0, 0.0 ) - mSubstrate = HomogeneousMaterial("Substrate", 6e-6, 2e-8 ) - mParticle = HomogeneousMaterial("Particle", 6e-4, 2e-8 ) - - # collection of particles - cylinder_ff = FormFactorCylinder(5*nanometer, 5*nanometer) - cylinder = Particle(mParticle, cylinder_ff) - particle_layout = ParticleLayout() - particle_layout.addParticle(cylinder, 1.0) - interference = InterferenceFunctionNone() - particle_layout.addInterferenceFunction(interference) - - air_layer = Layer(mAmbience) - air_layer.addLayout(particle_layout) - - substrate_layer = Layer(mSubstrate, 0) - multi_layer = MultiLayer() - multi_layer.addLayer(air_layer) - - # build and run experiment - simulation = GISASSimulation() - detector = IsGISAXSDetector(100, 0.0*degree, 2.0*degree, 100, 0.0*degree, 2.0*degree) - simulation.setDetector(detector) - simulation.setBeamParameters(1.0*angstrom, 0.2*degree, 0.0*degree) - simulation.setSample(multi_layer) - simulation.runSimulation() - return simulation.getIntensityData() - - -# ---------------------------------- -# describe sample and run simulation - IsGISAXS3 functional test: cylinder in the air with size distribution -# ---------------------------------- -def RunSimulationBA_Size(): - # defining materials - mAmbience = HomogeneousMaterial("Air", 0.0, 0.0 ) - mSubstrate = HomogeneousMaterial("Substrate", 6e-6, 2e-8 ) - mParticle = HomogeneousMaterial("Particle", 6e-4, 2e-8 ) - - multi_layer = MultiLayer() - - cylinder_ff = FormFactorCylinder(5*nanometer, 5*nanometer) - particle_layout = ParticleLayout() - # preparing prototype of nano particle - radius = 5*nanometer - sigma = 0.2*radius - nano_particle = Particle(mParticle, cylinder_ff) - # radius of nanoparticles will be sampled with gaussian probability - nbins = 100 - n_sigma = 4.0*numpy.sqrt(2.0*numpy.log(2.0)) - gauss = DistributionGaussian(radius, sigma) - - par_distr = ParameterDistribution("*/Radius", gauss, nbins, n_sigma) - part_coll = ParticleDistribution(nano_particle, par_distr) - particle_layout.addParticle(part_coll) - - interference = InterferenceFunctionNone() - particle_layout.addInterferenceFunction(interference) - - air_layer = Layer(mAmbience) - air_layer.addLayout(particle_layout) - - multi_layer.addLayer(air_layer) - - # build and run experiment - simulation = GISASSimulation() - detector = IsGISAXSDetector(100, 0.0*degree, 2.0*degree, 100, 0.0*degree, 2.0*degree) - simulation.setDetector(detector) - simulation.setBeamParameters(1.0*angstrom, 0.2*degree, 0.0*degree) - simulation.setSample(multi_layer) - simulation.runSimulation() - return simulation.getIntensityData() - - -# -------------------------------------------------------------- -# run test and analyse test results -# -------------------------------------------------------------- -def runTest(): - resultBA = RunSimulationBA() - resultDWBA = RunSimulationDWBA() - resultBA_Size = RunSimulationBA_Size() - - diff = IntensityDataFunctions.getRelativeDifference(resultBA, get_reference_data("isgisaxs03_reference_BA.int.gz")) - diff += IntensityDataFunctions.getRelativeDifference(resultBA_Size, get_reference_data("isgisaxs03_reference_BA_size.int.gz")) - diff += IntensityDataFunctions.getRelativeDifference(resultDWBA, get_reference_data("isgisaxs03_reference_DWBA.int.gz")) - diff /= 3 - - status = "OK" - if(diff > 2e-10 or numpy.isnan(diff)): - status = "FAILED" - return "Cylinders_BA_DWBA_SIZE", "Cylinder formfactor in BA and DWBA", diff, status - - -if __name__ == '__main__': - name, description, diff, status = runTest() - print(name, description, diff, status) - if("FAILED" in status): - exit(1) diff --git a/Tests/Functional/PyCore/legacy/detector_resolution.py b/Tests/Functional/PyCore/legacy/detector_resolution.py deleted file mode 100644 index 7cf7f392908c7ed980f15e7d939f673a34a75a01..0000000000000000000000000000000000000000 --- a/Tests/Functional/PyCore/legacy/detector_resolution.py +++ /dev/null @@ -1,67 +0,0 @@ -# Functional test: detector resolution function -from __future__ import print_function -import sys -import os -import numpy -from utils import get_reference_data - -from libBornAgainCore import * - -phi_min, phi_max = -0.2, 1.8 -alpha_min, alpha_max = 0.0, 2.2 - -def RunSimulation(): - """ - describe sample and run simulation - """ - # defining materials - m_ambience = HomogeneousMaterial("Air", 0.0, 0.0) - m_substrate = HomogeneousMaterial("Substrate", 6e-6, 2e-8) - m_particle = HomogeneousMaterial("Particle", 6e-4, 2e-8) - - # collection of particles - cylinder_ff = FormFactorCylinder(5*nanometer, 5*nanometer) - cylinder = Particle(m_particle, cylinder_ff) - particle_layout = ParticleLayout() - particle_layout.addParticle(cylinder, 1.0) - - # assembling the sample - air_layer = Layer(m_ambience) - air_layer.addLayout(particle_layout) - substrate_layer = Layer(m_substrate) - - multi_layer = MultiLayer() - multi_layer.addLayer(air_layer) - multi_layer.addLayer(substrate_layer) - - # build simulation - simulation = GISASSimulation() - simulation.setDetectorParameters(40, phi_min*degree, phi_max*degree, 60, alpha_min*degree, alpha_max*degree) - simulation.setBeamParameters(1.0*angstrom, 0.2*degree, 0.0*degree) - simulation.setDetectorResolutionFunction(ResolutionFunction2DGaussian(0.0025, 0.0025)) - simulation.setSample(multi_layer) - - # run simulation and retrieve results - simulation.runSimulation() - return simulation.getIntensityData() - - -def runTest(): - """ - run test and analyse test results - """ - result = RunSimulation() - - diff = IntensityDataFunctions.getRelativeDifference(result, get_reference_data("resolutionfunction_reference.int.gz")) - - status = "OK" - if(diff > 2e-10 or numpy.isnan(diff)): - status = "FAILED" - return "beam_divergence", "Cylinder in DWBA with beam divergence", diff, status - - -if __name__ == '__main__': - name, description, diff, status = runTest() - print(name, description, diff, status) - if("FAILED" in status): - exit(1) diff --git a/Tests/Functional/PyCore/legacy/layerwithroughness.py b/Tests/Functional/PyCore/legacy/layerwithroughness.py deleted file mode 100644 index 6acf3c0591cf7a266e9c5b595762b6601c12fffd..0000000000000000000000000000000000000000 --- a/Tests/Functional/PyCore/legacy/layerwithroughness.py +++ /dev/null @@ -1,78 +0,0 @@ -# Functional test: Functional test for layer with correlated roughness -from __future__ import print_function -import sys -import os -import numpy -from utils import get_reference_data - -from libBornAgainCore import * - - -# ---------------------------------- -# describe sample and run simulation -# ---------------------------------- -def RunSimulation(): - # defining materials - m_ambience = HomogeneousMaterial("ambience", 0.0, 0.0) - m_part_a = HomogeneousMaterial("PartA", 5e-6, 0.0) - m_part_b = HomogeneousMaterial("PartB", 10e-6, 0.0) - m_substrate = HomogeneousMaterial("substrate", 15e-6, 0.0) - - l_ambience = Layer(m_ambience, 0) - l_part_a = Layer(m_part_a, 2.5*nanometer) - l_part_b = Layer(m_part_b, 5.0*nanometer) - l_substrate = Layer(m_substrate, 0) - - roughness = LayerRoughness() - roughness.setSigma(1.0*nanometer) - roughness.setHurstParameter(0.3) - roughness.setLatteralCorrLength(5*nanometer) - - my_sample = MultiLayer() - - # adding layers - my_sample.addLayer(l_ambience) - - n_repetitions = 5 - for i in range(n_repetitions): - my_sample.addLayerWithTopRoughness(l_part_a, roughness) - my_sample.addLayerWithTopRoughness(l_part_b, roughness) - - my_sample.addLayerWithTopRoughness(l_substrate, roughness) - my_sample.setCrossCorrLength(1e-4) - - # build and run experiment - simulation = GISASSimulation() - simulation.setDetectorParameters(100, -0.5*degree, 0.5*degree, 100, 0.0*degree, 1.0*degree) - simulation.setBeamParameters(1.0*angstrom, 0.2*degree, 0.0*degree) - simulation.setSample(my_sample) - simulation.runSimulation() - - # intensity data - return simulation.getIntensityData() - - -# -------------------------------------------------------------- -# run test and analyse test results -# -------------------------------------------------------------- -def runTest(): - result = RunSimulation() - reference = get_reference_data("roughness01_reference.int.gz") - - # IntensityDataIOFactory.writeIntensityData(result, "roughness01_reference.int.gz") - - diff = IntensityDataFunctions.getRelativeDifference(result, reference) - - status = "OK" - if diff > 2e-10 or numpy.isnan(diff): status = "FAILED" - return "LayerWithRoughness", "Layers with correlated roughness", diff, status - - -# ------------------------------------------------------------- -# main() -# ------------------------------------------------------------- -if __name__ == '__main__': - name, description, diff, status = runTest() - print(name, description, diff, status) - if "FAILED" in status: - exit(1) diff --git a/Tests/Functional/PyCore/legacy/montecarlo_integration.py b/Tests/Functional/PyCore/legacy/montecarlo_integration.py deleted file mode 100644 index 10cb9ae31ce1d1006c93185d3dee4476cd0f416a..0000000000000000000000000000000000000000 --- a/Tests/Functional/PyCore/legacy/montecarlo_integration.py +++ /dev/null @@ -1,87 +0,0 @@ -# Functional test: Monte-Carlo integration functional test -# The reference file should be generated without integration -from __future__ import print_function -import sys -import os -import numpy -from utils import get_reference_data - -from libBornAgainCore import * - -phi_min, phi_max = -0.5, 0.5 -alpha_min, alpha_max = 0.0, 0.5 -default_cylinder_radius = 5*nanometer -default_cylinder_height = 5*nanometer -scale = 1 - - -def get_sample(cylinder_radius, cylinder_height): - """ - Build and return the sample to calculate cylinder formfactor in Distorted Wave Born Approximation - for given cylinder_radius and cylinder_height - """ - # defining materials - m_ambience = HomogeneousMaterial("Air", 0.0, 0.0) - m_substrate = HomogeneousMaterial("Substrate", 6e-6, 2e-8) - m_particle = HomogeneousMaterial("Particle", 6e-4, 2e-8) - - # collection of particles - cylinder_ff = FormFactorCylinder(cylinder_radius, cylinder_height) - cylinder = Particle(m_particle, cylinder_ff) - particle_layout = ParticleLayout() - particle_layout.addParticle(cylinder, 1.0) - - air_layer = Layer(m_ambience) - air_layer.addLayout(particle_layout) - substrate_layer = Layer(m_substrate) - - multi_layer = MultiLayer() - multi_layer.addLayer(air_layer) - multi_layer.addLayer(substrate_layer) - return multi_layer - - -def get_simulation(): - """ - Create and return GISAXS simulation with beam and detector defined. - """ - simulation = GISASSimulation() - simulation.setDetectorParameters(50, phi_min*degree, phi_max*degree, 50, alpha_min*degree, alpha_max*degree) - simulation.setBeamParameters(1.0*angstrom, 0.2*degree, 0.0*degree) - simulation.getOptions().setMonteCarloIntegration(True, 50) - return simulation - - - -def run_simulation(): - """ - Run simulation and plot results - """ - sample = get_sample(default_cylinder_radius*scale, default_cylinder_height*scale) - simulation = get_simulation() - simulation.setSample(sample) - simulation.runSimulation() - result = simulation.getIntensityData() - # plot_intensity_data(simulation.getDetectorIntensity()) - return result - - -def run_test(): - """ - run test and analyse test results - """ - result = run_simulation() - # IntensityDataIOFactory.writeIntensityData(result, 'montecarlo_integration.int') - reference = get_reference_data('montecarlo_integration.int.gz') - diff = IntensityDataFunctions.getRelativeDifference(result, reference) - status = "OK" - if diff > 2e-2 or numpy.isnan(diff): - status = "FAILED" - return "MonteCarloIntegration", "Test of Monte-Carlo integration", diff, status - - -if __name__ == '__main__': - name, description, diff, status = run_test() - print(name, description, diff, status) - if "FAILED" in status: - exit(1)