# PPM

## Pythonic Programming for Multilayers

Alessandro MIRONE

ESRF

## Download and installation

This ftp link points to a download zone where you can find the binary packages you need and instruction to install easily PPM

## Description of the packages

Once you have installed the packages, following the instruction found in the download zone, you can use the scalar and the magnetic version

of the PPM packages by running

/scisoft/ESRF_sw/linux_i386/PACKAGES/PPM/WRAPPERS/ppm

and

/scisoft/ESRF_sw/linux_i386/PACKAGES/PPM/WRAPPERS/ppmtens

respectively.

PPM is written in C for the low level, numerically time consuming, part, and in Python for the high level part.

It is possible to use PPM as a Library, describing syntactically your model with a set of high level python instruction, and this

methodology allows the most advanced use of PPM.

However the most common use of PPM is through the graphical interface.

This manual explains the utilisation of such a graphical interface for the newbyes.

The graphical interface used for PPM is a really original one. I have create such an interface to manipulate

graphically the Classes and Methods provided by the PPM library.

More in general, my original graphical interface ( that I called pyguibeans ), allows to manipulate graphically the functionalities of a

generic Python library, once a short description of classes and methods is provided to the interface in a suited format.

Of course I have already done the work for you, of exporting PPM library to pyguibeans, and the result is summarized by this screenshot .

## Presentation of the interface

Click on this link todownload a very simple example. Open the examples ex1.bean with the Load Bean option of the File menu, using the scalar version ppm.

What you see now on the interface panel is:

- On the first row from top :

1. The classes and methods list. You can drag and drop items from this list over the second (middle) row to create new lines of code. Drag is done with middle button.

2. The parameters input window. When you clik in the middle row, on a code-line, the settable parameters can be configured in this window

3. The list of defined variables. Dont confuse a variable defined in a line of code such like a in a=O(x,t,z) and the Variable class define in the following section. This panel shows all the variables defined by you. Click on one of them to see what happens in the second row.

4. The parameter Help. When, in the parameters input window, you click on the input form of a given parameter, help should appear here concerning such parameter.

5. The class and methods Help. When, in the classes and methods list, you click on an item, help should appear here concerning such item.

- On the second row, each item correspond to a line of code. Click on one to change its parameters. You can also move it by dragging. To delete a selected line type <ESC>

- The third row shows the code associated with the actual selection of second row.

## The use of Variables

You describe your model creating objects and assembling them together. Objects are created giving them different kinds of parameters like filenames, float numbers or even previously defined objects . Float number parameters may be things like thicknesses, densities, energies and so on.

When you pass a float parameter to an object, you have the possibility, and a very useful one indeed, to give, instead of a float, an object of the class Variable.

Objects of such a class have a current value, a minimum and a maximum. They can enter in the definition of a model and can be given to the optimizing routines to be optimised

Following this link you can download a very simple example involving variables. Open the examples ex1.bean using the Load Bean option of the File menu, using the scalar version ppm.

The first line defines a Variable object. It is associate with the name a. ( Now go to the variables list panel , third window in first row, select the variable a, press <Enter>, and see what happens, you might need to tear to the left the columns of the panel to see the value of the variable that is shown on the right )

The second line is a dependent variable. See how it is defined. Read the help of its Class and that for its parameters. Go to the variable list panel, select the associated variable, press <Enter> and see what happens.

The remaining lines show how to create correlated variables like the partial densities of two different elements in a given compound. When you vary the compound density, the partial densities vary dependently, according to stechiometry.

## Simulating Multilayers

This is after all a manual on a multilayer program, and you are eager to see a simulated scan. So let's pass to a concrete example without to much feedling about Classes, objects and other things.

I have prepared for you this beautiful example, ex2.bean that you can load using the Load Bean option of the File menu, using the scalar version ppm.

In the middle row, you can see, from top to bottom, the items composing the model :

- Two items, one to create the f1f2 table, and the other for the f0 table.

t0=Dabax_f0_Table("f0_WaasKirf.dat",)

t12=Dabax_f1f2_Table("f1f2_Henke.dat",)

What is shown here are just the corresponding lines of code. However you dont have to deal with such lines. You can play with the interface, in particular you can get help clicking on the parameter entry forms. These lines are just an handy way to show you what is happening without producing screenshots. The same applies to the rest of this manual.

Dabax tables are in /scisoft/ESRF_sw/os_arch/PACKAGES/PPM/DATA.

Os_arch depends on what system you are working on( if you have the chance to get the suited distribution of PPM for you system)

- An item to create an optical material from the tables, it will compose a layer of the bilayer, another item for the other layer and another for the substrate

fo_ind=IndexFromTable(t0,t12,"Fe",4.0,"O",2.0,)

alo_ind=IndexFromTable(t0,t12,"Al",2.0,"O",3.0,)

subst_ind=IndexFromTable(t0,t12,"Al",2.0,"O",3.0,)

As you see, the element names begin in upper-case. That depends on the naming scheme used in DATA directory ( Manolo's dabax files ) and you can check there in case of doubts.

- The three layers composing the stack

feo_layer=PPM_SimpleLayer(thickness=10.0,roughness=5.0,material=fo_ind,)

alo_layer=PPM_SimpleLayer(thickness=10.0,roughness=6.0,material=alo_ind,)

subst_layer=PPM_SimpleLayer(thickness=0.0,roughness=6.0,material=alo_ind,)

- the bilayer, the repeated bilayer, and the whole stack that is the sum of the substrate plus the repeated bilayer.

bilayer=SumThings(alo_layer,feo_layer,)

NXbilayers=MultiplyAThing(10,bilayer,)

stack=SumThings(subst_layer,NXbilayers,)

- The scan to perform. This scan is created by the function ScanReader. This function can define experimental scans. If you dont have experimental data you cans also synthetize scan. In this example we synthetise the scan.

scan0=ScanReader(wavelenghts_col=15.0,angles_col=[10.0,40,0.01 ],angle_factor=math.pi/180,)

scan1=ScanReader(wavelenghts_col=20.0,angles_col=[10.0,40,0.01 ],angle_factor=math.pi/180,)

A scan is alway a sequance of points, each one having a wavelenght, an angle (theta), a data,a statistical weight. These can be read from a file, weights are optional, but you can also synthetise scans as shown above. Data values dont matter in this case.

More scans can be specified like in this example.

- The fit object. Fit objects provide comparisons between a model ( our stack ) and a set of experimental scans. When you click on the Just View button all the lines are executed, thus creating all specified objects, then the error function of the fit object is called, the calculated and experimental scan datas are retrieved from inside the fit object and finally displaied on graph widgets. If several comparison-type objects (fits) are present, the last one found in the lines of code will be used.

In the next section we'll optimise fits. By now click the Just View button, see what happens, play with graph widgets using right mouse button to get a pop-up menu , and save the data to files. We'll use such files as experimental data to be fitted in the nex section.