пятница, 22 октября 2010 г.

WolframAlpha and why I love its widgets

I am trying out new Capabilities of the Wolfram Alpha engine. Well, it is not that complicated as Mathematica, but still very useful, especially the new Widgets feature.

Let's learn by example. I need to have some easily accessible tool to recalculate lattice parameters from hexagonal to rhombohedral setting. How do I do that?

Well, first of all, I go to developer.wolframalpha.com and register myself as a 'developer'. Next, I watch the tutorial demonstrating the process of creating widgets. Five minutes later I start to shape my own.
The principle is very simple. You create a formula, assign variables, shape your widget, make some style adjustments and .. it is ready!

If we take a closer look.. the formula behind the widget is simple. I take A and C lattice parameters for the hexagonal cell and recalculate them:

{ArcCos[(15*a^2-c^2)/(2*c^2+6*a^2)]/pi*180, Sqrt[(c^2+3*a^2)/9]} where a=[//number:${A}//], c=[//number:${C}//]

As a result I obtain two values: one of them is the rhombohedral angle (Degrees), the other is the rhombohedral lattice parameter. The only trick was to make WolframAlpha engine to reuse the variables c,a or to set the simultaneously. We set all of them by where a=[//number:${A}//], c=[//number:${C}//].
Is that simple? I believe it is!

Now, let us answer the question - why we need it. My reasons are simple. I need something online, so I do not have to crawl all over my folders trying to find the solution. It also saves me some amount of disk space and backup efforts, which are more annoying than lack of space.
WolframAlpha will never displace Mathematica, but this tool is indeed worth to use. The widget which performs a reverse transformation (rhombohedral to hexagonal) can be found here or below.
Good day to you!

четверг, 21 октября 2010 г.

simple fityk tricks

Finally, I got stuck with experimental data and have some free time.
Ok:) tips I would like to share.

Fityk is great because:
  • tool is free and works on different platforms (Windows, Mac OS?, Linux)
  • program allows use of user defined models
  • fitted models can be saved

Of course I miss features of:
  • saving color of lines, size of points for different functions used in the model
  • custom formating of the output (i errors)
  • using constrains
  • changing of visual baseline (in Fityk it is fixed to 0, all shapes are plotted relative to it) to some user defined constant value.
But I still like it. Comparing other free software (Gnuplot) to Fityk, I must say that these programs do different things and are in principle supplementary. Today's simple tricks:
  • estimating errors of the fitted model: s=max(y-F(x)). We set values for the standard deviation as a constant value for all points. This value is considered as maximum deviation of experimental points y[n] from the fitted model F(x).
  • setting manual constrains, like limiting parameter $param to positive values. For this we need to create another variable, for instance, $dummy and set: $dummy=~{10}; $param=sqrt($dummy^2). This way we define that Fityk may vary the $dummy variable, and $param variable depends linearly on it and is always positive. This trick is very useful if you need to avoid undesirable subtraction/addition of different Gaussian or Lorentz peaks (Spectroscopy, X-ray diffraction). Need to mention, that you have to control both widths/heights of the Lorentz/Gauss.
I strongly recommend to read the Fityk's Users Guide for some additional tricks like summing up the datasets, etc. The summation of datasets can be used as datasets subtraction, for instance, to remove calculated background from the X-ray dataset. Let us assume that @0 and @1 contain the observed spectrum and the calculated background. A simple line y=-y in @1; @2= sum_same_x @0+@1; delete @1; delete @0; will give us a spectrum without the background.

GSAS vs Fullprof - what I like, what do you like?

I am far from being professional with modern crystallography tools. However, here comes my impression of what I like in these two software packages (GSAS, Fullprof). I do not include comments on JANA2006, another marvelous piece of software. My comments are subjective and there are more comments than tips and tricks to it.

Fullprof. I know, the Fullprof .pcr files are difficult to handle, but I find them more and more attractive with highlighting (my previous post).

  • LeBail fitting is fast. First, you set DUM parameter to 1, Pcr=1, AUT=0 (skip auto assignment to the fitting variables), Number of refined parameters=0 (according to manual). Then, please set JBT=2 and IRF=0 for all phases under consideration. After that you run the .pcr file with the Fullprof, fit background (polynomial or by manual selection of the background points). Setting Pcr=1 is really crucial if you want to prevent messing up your fitting.
  • I really like combination of highlighting of .pcr file syntax with manual numerical assignment of codewords for different fitted parameters. I usually set AUT=0 in the beginning, then fit the background(assigning CODEWORDS 11-61), then I fit the lattice + zero shifts (some other CODEWORDS), then the peak shapes and etc. If now I assign the Number of fitted parameters only to 6, I will fit only the background. Then, I can slowly increase the Number of fitted parameters and fit the lattice and so on. Only if I am sure I will not mess up the fitting, I can set the AUT=1. I find this way of selecting the parameters to fit is faster, specially with LeBail fitting, than that checkbox style of GSAS.
  • Setting up the magnetic structure is way faster in Fullprof compared with the GSAS.
  • I like the way how simulations work in Fullprof. However, there is an important trick to it. It looks like Fullprof does not like really large numbers (version 2000/2006 in peak intensities/heights). If you have a really strange simulation diffraction pattern with peaks cut off to 0 intensity in the middle, pay attention to: scale of the phase, ATZ of the phase (take a look in .out file), occupation numbers. These are the pictures, first shows bad simulation, second - good.


  • RTFM:)
GSAS.
  • Yes, GSAS has a way much better tutorials. The combination of CMPR+EXPGUI is nicely explained in the same tutorials.
  • The simulation of the diffraction spectra (except the magnetic phase) works like a breeze in GSAS.
  • RTFM is really important.
  • The texture fitting of the GSAS is more sophisticated than in Fullprof. If I have strange textures in my material, I will prefer GSAS.
  • Background fitting in GSAS is outstanding, different models, fitting of the manually selected background points.

Of course, there are many things I do not like, but they are minor. Usually, I have many complains about the user interface. But this is not the complain I would express to the authors of these packages. The guys have done a brilliant job. Thank you guys!!!
However, I think, that investing whole lot of money and research to the creation of even better tools with the cooperation with the IT guys should be at the same priority as investing in the International Tables of Crystallography, International Crystallography Database and their support. I would like to have better tools.