X0h on the Web! GID_sl on the Web! TER_sl on the Web! TRDS_sl on the Web! MAG_sl on the Web!

ATTENTION: if you downloaded any automation scripts before May-2025, please re-download them because of some changes at the Server.
X-Server is now behind Cloudflare and the scripts are updated to handle the Cloudflare protection. The old scripts may not work. The OASYS XRayServer plugin by Luca Rebuffi has also been updated.

Download Python & Perl scripts Links to 3rd-party scripts & OASYS

Automated access and remote fitting

This page is meant for those who are willing to make a step beyond regular web browser access to X-ray Server. It demonstrates how using very limited amount of scripting one can automate the server access, implement remote fitting or embed server programs into his/her own software.

As an example, a diffraction program written by a user could remotely access X-ray structure amplitudes provided by X0h. This would make user's code much more lightweight and the effort much smaller since sorting out the business of calculating structure factors could be left out. Another example could be the need to calculate a series of structure factors or diffraction or reflectivity curves as a function of a parameter. It would be much easier to script such operation than run a session in a browser several hundred or so times.

A separate issue is fitting. There have been many requests from users to provide remote fitting of experimental data at X-ray server. The main problem here is the number of parameters: for example, the Bragg curves calculated with GID_sl can be specified with hundreds or even thousands of parameters describing the surface layer. The input form presented below corresponds to a typical material science application. It describes the surface layer consisting of 72 layers and containing more than 200 parameters like thickness, strain and structure factor.

GID_form example

So, the question is, how to choose a subset of fittable parameters without loss of general applicability because making everything fittable would obviously make the programs and the interface unpractically heavy.

The second issue is that when it comes to fitting, often the simulated curves need to be convoluted with the geometry of experiment; for example, with the incident beam spread after the monochromator or slits, and etc. Given the diversity of geometries at synchrotrons and lab sources, incorpoation of generic account for experimental resolution function and geometrical corrections does not seem to be feasible.

Therefore, the server suggests to move the choice of the range of fitted parameters as well as the account for experimental corrections to the client side. In other, words, the server can solve the physical problem of X-ray interaction with model media, and the specifics of experiment are left to client-side software. This can be presented on the following scheme:

Remote access fitting

A fitting routine written by a user runs in a loop on his client computer. It fits experimental data by requesting data from the server via a wrapper script at each step of the fitting loop. Examples of wrapper scripts are provided below at this page. If necessary, the simulated curves returned by the wrapper are convoluted with experiment in user's software. Also, it is user's software that determines the set of fitting parameters and their range.

DOWNLOAD TEMPLATES

TASK WWW FORM PERL Examples PYTHON Examples
A script returning the X0h database lists or dumps under various conditions (only crystals, only cubic crystals, only atomic materials, and etc.). This script can be used by other scripts to supply them with available materials and thus provide full-cycle automated remote access. x0h_list form getX0hDB.pl getX0hDB.py
Example scripts returning original X0h structure records for a given material and all materials respectively. You can use output to verify coordinates of atoms in the unit cells of all materials contained in the X0h DB. x0h_dump form getX0hCoords.pl
 
getX0hCoordsAll.pl
getX0hCoords.py
 
getX0hCoordsAll.py
Example scripts returning original X0h atom records for a given element. You can use output to verify scattering factors, absorption, dispersion corrections and Deby-Waller parameters of atoms contained in the X0h DB. x0h_atom_dump form getX0hAtoms.pl getX0hAtoms.py
Example scripts interfacing X0h. See explanations inside the scripts. X0h_form getX0h.pl
 
calcAttenuation.pl
getX0h.py
 
calcAttenuation.py
Example script interfacing GID_sl. This script starts a calculation, then polls the server until it finishes, and downloads the results. It uses the CGI POST method which does not impose restrictions on the length of buffer describing surface profile -- see details here. GID_sl form getGID_query_post.pl getGID_query_post.py
Example script interfacing TER_sl. This script starts a calculation, then polls the server until it finishes, and downloads the results. It uses the CGI POST method which does not impose restrictions on the length of buffer describing surface profile -- see details here. TER_sl form getTER_query_post.pl getTER_query_post.py
Example script requesting X-ray standing waves from TER_sl. This script starts a calculation, then polls the server until it finishes, and downloads the results. It uses the CGI POST method which does not impose restrictions on the length of buffer describing surface profile -- see details here. TER_sl_sw form getTER_sw_query_post.pl getTER_sw_query_post.py
Example script interfacing TRDS_sl. This script starts a calculation, then polls the server until it finishes, and downloads the results. It uses the CGI POST method which does not impose restrictions on the length of buffer describing surface profile -- see details here. TRDS_sl form getTRDS_query_post.pl getTRDS_query_post.py
Example script interfacing MAG_sl. This script starts a calculation, then polls the server until it finishes, and downloads the results. It uses the CGI POST method which does not impose restrictions on the length of buffer describing surface profile -- see details here. MAG_sl form getMAG_query_post.pl getMAG_query_post.py

The above example scripts are written in Perl using Perl LWP module (WWW library for Perl). The latter is usually a part of standard Perl distribution. The Perl interpreter itself is default on UNIX and MAC OS. Freeware Perl distibution for Windows can be installed either as a part of Cygwin, or as a standalone package available from ActiveState or Strawberry. See also download information on the Perl website.

The scripts can be called from user's software written in any language using the system function. If a parameter needs to be varied, it can be passed to the script as a command line argument.

Third-party software for automated access

1. OASYS XRayServer plugin by Luca Rebuffi (Python)

In the course of years many colleagues wrote their own software for automating access to X-ray Server and some of them posted it on WWW. First and foremost I should mention the XRayServer plugin to OASYS (OrAnge SYnchrotron Suite) by Dr. Luca Rebuffi (formelly @ ELETTRA and now @ APS). The plugin embeds the X-ray Server access into Oasys and users do not need to do any programming for interacting with the Server; just graphically add and configure the X-Server widgets, as shown on the two screenshots below (cortesy Dr. Rebuffi). One can also arrange loop calls of the X-ray Server programs and add to the loops some logical analysis widgets, which in principle opens a path to remote fitting.

Oasys screenshot-1
Oasys screenshot-1

The plugin is implemented in Python and the source code is available at Github, which may be useful for studying and improving for advanced users. For those who are interested in a fastest and simplest route, I recommend installing and starting OASYS and then adding the plugin with a single click of a button.

2. Python_X-Ray_Server by Daniel Pelliccia

Another Python implementation of automated access to X-ray Server is a Github-hosted project Python_X-Ray_Server authored by Dr. Daniel Pelliccia (Instruments & Data Tools Pty Ltd, Australia). The advantage if this ditribution is that the scripts are stanalone and compact, similar to the Perl scripts available at this page, which is very good for a quick start. At the time of this writing the project only hosts a script for interacting with GID_sl, but there are plans to extend it to the rest of the X-ray Server programs.



X
Site navigation: