This tutorial gives an overview on how to draw a set of particles whose parameters follow a desired distribution. To fix ideas, let’s build the argument around cylindrical particles; In this case, the parameters will be radius, $r$; and height, $h$; the same reasoning should apply to other kinds of particles whose parameters differ (e.g. an Icosahedron does not have a parameter “radius”).
In the case in which a particle distribution is not applied, all particles are identical; for cylindrical particles, this means having the same radius and the same height (the default value is $5 , \rm{nm}$ for both).
Let’s start with a concrete example. To create a Gaussian distribution for the radius of cylindrical particles with the following properties,
one can roughly use the following recipe:
|
|
One can choose among six different distributions in order to break the default regularity of the parameters of the particles. At the same time, each distribution offers several parameters to tweak:
BornAgain provides a function to print the list of available particle parameters and their corresponding values: :
>>print(my_particle.parametersToString())
'/Particle/Abundance':1
'/Particle/PositionX':0
'/Particle/PositionY':0
'/Particle/PositionZ':0
'/Particle/Cylinder/Radius':5
'/Particle/Cylinder/Height':5
A ParticleDistribution is a set of particles in which a given particle
paramenter can take numberOfSamples
different values.
These values are equally spaced between them and the relative number of
particles with a particular value is proportional to the height of the
chosen distribution.
In order to prevent the extraction of unphysical values, one needs to set limits. For instance, in order to avoid extracting negative values for the radius of a cylinder, one can easily set limits to pass to the ParameterDistribution (line 10 on the recipe snippet above):
limits = ba.RealLimits.limited(1.0, 9.0))
The easiest way of generating a particle distribution from scratch is from the GUI. After that, one can export the layout as a Python script and tweak it to get the desired outcome:
One must note, however, that some functionality is only present through the Python API,
for instance, linkParameter
is not accessible through the GUI:
# linkParameter allows the height of the cylinders
# to be scaled proportionally to their radii:
par_distr.linkParameter("/Particle/Cylinder/Height")
Further details and a complete working script are provided in the tutorial Cylinders with size distribution.