User Tools

Site Tools


exercises:2016_uzh_cmest:first_simulation_run

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
exercises:2016_uzh_cmest:first_simulation_run [2016/09/28 13:26] tmuellerexercises:2016_uzh_cmest:first_simulation_run [2020/08/21 10:15] (current) – external edit 127.0.0.1
Line 253: Line 253:
 ====== Tips & Tricks ====== ====== Tips & Tricks ======
  
 +===== Parsing the output =====
 +
 +Many times you will have to get some value out of a simulation output, in this case, the energy.
 +This can achieved in a number of ways:
 +
 +  * Using the ''grep'' command:<code>
 +$ grep "Total FORCE_EVAL" energy.out
 +</code>which gives you:<code>
 + ENERGY| Total FORCE_EVAL ( FIST ) energy (a.u.):             -0.000250281091139
 +</code>
 +  * Using the ''awk'' tool:<code>
 +$ awk '/Total FORCE_EVAL/ { print $9; }' energy.out
 +</code>which returns:<code>
 +-0.000250281091139
 +</code>''awk'' reads a given file line-by-line and splits a line into multiple fields (using whitespace as delimiter). The command above tells ''awk'' to look for the string ''Total FORCE_EVAL'' in a line and if found, print field number 9 of it, effectively returning the energy.
 +
 +===== Generating input files =====
 +
 +Many times you will have to run the same simulation with different parameters (here the distance).
 +
 +A simple way to generate the different input files is using shell scripting in combination with ''sed'' (the stream editor):
 +
 +<code>
 +for d in $(seq 2 0.1 4); do
 +  sed -e "s|4 0 0|${d} 0 0|" energy.inp > energy_${d}A.inp
 +  cp2k.sopt -i energy_${d}A.inp -o energy_${d}A.out
 +  awk '/Total FORCE_EVAL/ { print $9; }' energy_${d}A.out
 +done
 +</code>
 +
 +  * The command ''seq 2 0.1 4'' generates the numbers ''2.0'', ''2.1'', ''2.2'', ... , ''4.0'' (try it out!)
 +  * With ''for d in $(seq 2 0.1 4); do'' we use the shell to run all commands which follow once for every number (stored in ''$d'')
 +  * ''sed -e "s|4 0 0|$d 0 0|" energy.inp'' looks for ''4 0 0'' in the file ''energy.inp'' (the original file from above) and replaces ''4 0 0'' by ''$d 0 0'' (that is: ''2.0'', ''2.1'', ''2.2'', ...)
 +  * ... and using ''> energy_${d}A.out'' we redirect the output of the ''sed'' command to new files ''energy_2.0A.out'', ''energy_2.1A.out'', etc.
 +  * Then we run ''cp2k.sopt'' as shown before on those new input files and write the output to new output files as well
 +  * Using ''awk'' we extract the energy from the output file
exercises/2016_uzh_cmest/first_simulation_run.1475069184.txt.gz · Last modified: 2020/08/21 10:15 (external edit)