C2110 UNIX and programming 9. lekce Petr Kulhánek, Jakub Štěpán kulhanek@chemi.muni.cz National Centre for Biomolecular Research, Faculty of Science Masaryk University, Kotlářská 2, CZ-61137 Brno I f°C'a MINISTERSTVO ŠKOLSTVÍ. op Vzdělávání '^^mJ^S7 ■ TOndVCR EVROPSKÁ UNIE MLÁDEŽE A TĚLOVÝCHOVY pro konkurenceschopnost MAíA^ INVESTICE DO ROZVOJE VZDĚLÁVÁNÍ CZ.1.07/2.2.00/15.0233 JIXand programming 9th lesson Contents >Bash * Cycle using while > Gnuplot * Language overview, command plot, terminals, command splot JlXand programming 9th lesson Bash > Cycle using while sllX and programming 9th lesson Cycle using while Cycle (loop) is control structure, that repeatedly processes set of commands. Repeats are done until condition is fulfilled. Cycle repeats until commandl return value is 0. IX and programming 9th lesson Cycle using for vs. while cycle 1=1 $1 <= 10 I++ etho $1 * Done before script start (count initialisation) If conditions is fulfilled, then commands in block do/done are processed test $1 echo $1 I=%expr $1 + 1* Count update after processing commands IIX and programming 9th lesson Redirection and pipes read A roura redirection 1=1 I <= 10 I++ Output of all commands is redirected to sllX and programming 9th lesson Home work I Explain different behavior of folloving scripts file.txt obsahuje pet radku. Print number 0 Print number 5 X and programming 9th lesson Home work II File rst.out (wolf.ncbr.muni.cz:/home/kulhanek/Data/rst.out) contains results of molecular dynamics simulation. Task is to extract dependence of temperature on simulation time from file. Time NSTEP = Etot BOND 1-4 NB EELEC EAMBER 500 942.6248 51.3204 17.7099 ■494 .7423 TIME(PS) = EKtot ANGLE 1-4 EEL EGB 0.500 TEMP(K) 151.0990 292.3619 981. 4071 -164.7991 [ non-restraint) 791.3436 Temperature 288.02 EPtot DIHED VDWAALS RESTRAINT PRESS 0.0 791.5258 176.5980 -68.3301 0 .1822 WARNING: Script nust not contain commands grep, awk and their variants. Use command read and while. sllX and programming 9th lesson Gnuplot > (Non)lnteractive run > Command plot > Terminals > Showcases http://www.gnuplot.info/ (documentation, tutorials, source codes) pm3 DMP + H2C free enemy [kcal/mol] 3.5 - 3 ID in 2.5 1.5 -2-1012 DD 14-16/16-7 [A] 100 A 80 60 40 20 IIX and programming 9th lesson Showcase minimum QM / ABF / Rewald = 8 A -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 DD (A) JlXand programming 9th lesson Showcase JlXand programming 9th lesson Interactive run Gnuplot is dedicated to draw 2D and 3D graphs, through interactive and scripting mode well. GNUPLOT Version 4.4 patchlevel 3 last modified March 2011 System: Linux 3.2.0-31-generic Copyright (C) 1986-1993, 1998, 2004, 2007-2010 Thomas Williams, Colin Kelley and many others gnuplot home: http://www.gnuplot.info faq, bugs, etc: type "help seeking-assistance" immediate help: type "help" plot window: hit 'h' Shell BASH command line Interactive mode [kulhanek@wolf ~]$ gnuplot Terminal type set to 1wxt gnuplot> _ gnuplot command line JlXand programming 9th lesson Noninteractive run We run interpreter and as its argument we put script name. $ gnuplot my_gnuplot_script Scripts does not need permission x (executable). We run directly script (shell automatically start interpreter). $ chmod my_gnuplot_script $./my_gnuplot_skript Scripts needs permission (executable) and interpreter [part of script). IIX and programming Command - plot > plot function/file [plot_setup] [, fee/file ...] Shows XY graph of function or data from file. Examples: lines, points, linespoints, dots Line color > plot sin(x) > plot cos(5.7*x+3.4) with points linecolor rgb "red" \ linewidth 2 title "cos" Data file name Line thickness legend > plot "input.txt" using 1:2 with lines Second column are y-axis values. First column are x-axis values. > plot sin(x), cos(x) Plots functions sin and cos to one graph. IIX and programming 9th lesson Exercise 1. Plot function graph of y=x2 2. Plot function from task 1 again, but with blue line. 3. Plot graph of temperature dependency on time from data file /home/kulhanek/Data/temp.txt Time is in first column, temperature is in second column. 4. Plot graph of function sin(x) using red line and function cos(x) using orange line with points. Do all tasks in interactive mode. JlXand programming 9th lesson Other commands > set title "title" > set xrange[min_value:max_value] > set xlabel "title" > set yrange[min_value:max_value] > set ylabel "title" > set nokey > pause -1 # Graph header # sets range of x axis # sets title of x axis # sets range of y axis # sets title of y axis # disables key for data in plot # wait for key press JlXand programming 9th lesson Exercise 1. Write script, that plots function y=x2 in range 0-10 for x axis. Run script un-directly using gnuplot interpreter. 2. Write script, that plots dependence of temperature on time from data in file /home/kulhanek/Data/temp.txt. Add axis labels including units. Time is in picoseconds, temperature in kelvin. JlXand programming 9th lesson Terminals Terminal determines output form. > set term xll # output is shown in window > set term wxt # output is shown in advanced window > set term png size 800,600 # output is plot as a picture in png format > set output "output, png" # output will be saved to file output.png > test # prints page with terminal features, terminals does have different abilities IX and programming 9th lesson Sample terminal outputs wxt 'gj Gnuplot (window id : 0) 3a 3 if splot functionkce/file [plot setup] [, fee/file ...] Shows XYZ graph of function or data from file. View point is set by command set view a,b, where a and b are view angles. View from top is set by set view map Sampling of density for x and y axis is set by command set isosamples a,b, where a and b gives number of samples in given direction. To highlight surface by its function value pm3d command may be used, for example: > splot x*x+y*y with pm3d JIX and programming 9th lesson Exercise 1. Plot function x2+y2 2. Set top view (set view) 3. Unset current view (unset view) 4. Raise density of points for function plot (set isosamples). Use values 10,20; 20,10 and 20,20 5. Use view pm3d 6. Set top view (set view) Do all tasks in interactive mode. JlXand programming 9th lesson