From 9d76bfe844d397c5d8b1b864ff291c3f4d62036c Mon Sep 17 00:00:00 2001
From: Celine Durniak <c.durniak@fz-juelich.de>
Date: Thu, 22 Jan 2015 10:08:46 +0100
Subject: [PATCH] Python Examples - new customFF and minor modifications for
 labeling in plots and renaming files.

---
 ....py => Interference1DRadialParaCrystal.py} |  2 +-
 ...stal2D.py => Interference2DParaCrystal.py} |  2 +-
 .../ex04_ComplexShapes/CustomFormFactor.py    | 26 +++++++++++++------
 .../OffSpecularSimulation.py                  |  2 +-
 4 files changed, 21 insertions(+), 11 deletions(-)
 rename Examples/python/simulation/ex03_InterferenceFunctions/{InterferenceParaCrystal1D.py => Interference1DRadialParaCrystal.py} (98%)
 rename Examples/python/simulation/ex03_InterferenceFunctions/{InterferenceParaCrystal2D.py => Interference2DParaCrystal.py} (98%)

diff --git a/Examples/python/simulation/ex03_InterferenceFunctions/InterferenceParaCrystal1D.py b/Examples/python/simulation/ex03_InterferenceFunctions/Interference1DRadialParaCrystal.py
similarity index 98%
rename from Examples/python/simulation/ex03_InterferenceFunctions/InterferenceParaCrystal1D.py
rename to Examples/python/simulation/ex03_InterferenceFunctions/Interference1DRadialParaCrystal.py
index 20c3bf59026..db987771267 100644
--- a/Examples/python/simulation/ex03_InterferenceFunctions/InterferenceParaCrystal1D.py
+++ b/Examples/python/simulation/ex03_InterferenceFunctions/Interference1DRadialParaCrystal.py
@@ -1,5 +1,5 @@
 """
-radial paracrystal (IsGISAXS example ex-4)
+radial paracrystal
 """
 import numpy
 import matplotlib
diff --git a/Examples/python/simulation/ex03_InterferenceFunctions/InterferenceParaCrystal2D.py b/Examples/python/simulation/ex03_InterferenceFunctions/Interference2DParaCrystal.py
similarity index 98%
rename from Examples/python/simulation/ex03_InterferenceFunctions/InterferenceParaCrystal2D.py
rename to Examples/python/simulation/ex03_InterferenceFunctions/Interference2DParaCrystal.py
index 0f8dd59534b..5a60aa00ed0 100644
--- a/Examples/python/simulation/ex03_InterferenceFunctions/InterferenceParaCrystal2D.py
+++ b/Examples/python/simulation/ex03_InterferenceFunctions/Interference2DParaCrystal.py
@@ -1,5 +1,5 @@
 """
-2D paracrystal (IsGISAXS example ex-4)
+2D paracrystal
 """
 import numpy
 import matplotlib
diff --git a/Examples/python/simulation/ex04_ComplexShapes/CustomFormFactor.py b/Examples/python/simulation/ex04_ComplexShapes/CustomFormFactor.py
index 8e667baf39e..e2e76daeb4f 100644
--- a/Examples/python/simulation/ex04_ComplexShapes/CustomFormFactor.py
+++ b/Examples/python/simulation/ex04_ComplexShapes/CustomFormFactor.py
@@ -10,32 +10,42 @@ from bornagain import *
 phi_min, phi_max = -1.0, 1.0
 alpha_min, alpha_max = 0.0, 2.0
 
+def sinc(x):
+    if abs(x) == 0.:
+        return 1.
+    else:
+        return cmath.sin(x)/x
 
 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
+    The particle is a polyhedron, whose planar cross section is a "plus" shape
+    with a side length L.
+    H is the height of particle
     """
-    def __init__(self, V, L):
+    def __init__(self, L, H): 
         IFormFactorBorn.__init__(self)
         # parameters describing the form factor
-        self.V = V
         self.L = L
+        self.H = H
 
+  
     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 = CustomFormFactor(self.L, self.H) 
         cloned_ff.transferToCPP()
         return cloned_ff
 
     def evaluate_for_q(self, q):
-        return self.V*1.0/cmath.cosh(q.mag()*self.L)
+        qzhH = 0.5*q.z()*self.H
+        qxhL = 0.5*q.x()*self.L
+        qyhL = 0.5*q.y()*self.L
+        return 0.5*self.H*self.L**2*cmath.exp(complex(0.,1.)*qzhH)*sinc(qzhH)*(sinc(0.5*qyhL)*(sinc(qxhL) - 0.5*sinc(0.5*qxhL)) + sinc(0.5*qxhL)*sinc(qyhL))
+
 
 
 def get_sample():
@@ -48,7 +58,7 @@ def get_sample():
     m_particle = HomogeneousMaterial("Particle", 6e-4, 2e-8)
 
     # collection of particles
-    ff = CustomFormFactor(343.0*nanometer, 7.0*nanometer)
+    ff = CustomFormFactor(20.0*nanometer, 15.0*nanometer)
     particle = Particle(m_particle, ff)
     particle_layout = ParticleLayout()
     particle_layout.addParticle(particle, 0.0, 1.0)
diff --git a/Examples/python/simulation/ex05_BeamAndDetector/OffSpecularSimulation.py b/Examples/python/simulation/ex05_BeamAndDetector/OffSpecularSimulation.py
index c2c15acd5e2..e5a17834230 100644
--- a/Examples/python/simulation/ex05_BeamAndDetector/OffSpecularSimulation.py
+++ b/Examples/python/simulation/ex05_BeamAndDetector/OffSpecularSimulation.py
@@ -74,7 +74,7 @@ def run_simulation():
                       extent=[alpha_i_min, alpha_i_max, alpha_f_min, alpha_f_max], aspect='auto')
     cb = pylab.colorbar(im)
     cb.set_label(r'Intensity (arb. u.)', fontsize=16)
-    pylab.xlabel(r'$\phi_f (^{\circ})$', fontsize=16)
+    pylab.xlabel(r'$\alpha_i (^{\circ})$', fontsize=16)
     pylab.ylabel(r'$\alpha_f (^{\circ})$', fontsize=16)
     pylab.show()
 
-- 
GitLab