Newer
Older
"""
Custom form factor in DWBA.
"""

Wuttke, Joachim
committed
import bornagain as ba
Celine Durniak
committed
def sinc(x):

Wuttke, Joachim
committed
if abs(x) == 0:
Celine Durniak
committed
return 1.

Wuttke, Joachim
committed
"""

Wuttke, Joachim
committed
A custom defined form factor.
The particle is a prism of height H,
with a base in form of a Greek cross ("plus" sign) with side length L.
"""
def __init__(self, L, H):
# parameters describing the form factor
self.L = L
Celine Durniak
committed
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.L, self.H)
cloned_ff.transferToCPP()
return cloned_ff
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))
Celine Durniak
committed
def exec_spanZ(self, rotation):
def get_sample():
"""
Returns a sample with particles, having a custom form factor, on a substrate.
"""
# defining materials
m_vacuum = ba.RefractiveMaterial("Vacuum", 0, 0)
m_substrate = ba.RefractiveMaterial("Substrate", 6e-6, 2e-8)
m_particle = ba.RefractiveMaterial("Particle", 6e-4, 2e-8)
# collection of particles

Wuttke, Joachim
committed
particle = ba.Particle(m_particle, ff)
particle_layout = ba.ParticleLayout()
particle_layout.addParticle(particle)
vacuum_layer = ba.Layer(m_vacuum)
vacuum_layer.addLayout(particle_layout)

Wuttke, Joachim
committed
substrate_layer = ba.Layer(m_substrate)
# assemble sample
sample = ba.MultiLayer()
sample.addLayer(vacuum_layer)
sample.addLayer(substrate_layer)
return sample
beam = ba.Beam(1, 1*angstrom, ba.Direction(0.2*deg, 0))
det = ba.SphericalDetector(n, -1*deg, 1*deg, n, 0, 2*deg)
simulation = ba.ScatteringSimulation(beam, sample, det)
simulation.options().setNumberOfThreads(
1) # deactivate multithreading (why?)
return simulation
if __name__ == '__main__':
simulation = get_simulation(sample)
result = simulation.simulate()
bp.plot_simulation_result(result)