howto:converging_cutoff
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
converging_cutoff [2014/01/25 08:00] – fix exponent notation vondele | howto:converging_cutoff [2020/08/21 10:15] – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== |
- | '' | + | ===== Introduction ===== |
+ | '' | ||
simulation packages, requires the use of a real-space (RS) | simulation packages, requires the use of a real-space (RS) | ||
integration grid to represent certain functions, such as the | integration grid to represent certain functions, such as the | ||
- | electron density and the product Gaussian functions. '' | + | electron density and the product Gaussian functions. '' |
uses a multi-grid system for mapping the product Gaussians onto the | uses a multi-grid system for mapping the product Gaussians onto the | ||
RS grid(s), so that wide and smooth Gaussian functions are mapped | RS grid(s), so that wide and smooth Gaussian functions are mapped | ||
Line 17: | Line 18: | ||
This tutorial assumes the reader already has some knowledge of how | This tutorial assumes the reader already has some knowledge of how | ||
- | to perform a simple energy calculation using '' | + | to perform a simple energy calculation using '' |
- | be found in tutorial: | + | be found in tutorial: |
- | '' | + | |
A completed example from an earlier calculation can be obtained from | A completed example from an earlier calculation can be obtained from | ||
- | the file '' | + | the file {{:converging_grid.tgz|converging_grid.tgz}} |
- | calculations were carried out using CP2K SVN trunk revision 13180. | + | calculations were carried out using CP2K version 2.4. |
- | ===== '' | ||
- | Before we go through the input file, it is worth while to explain | + | ==== '' |
- | how the multi-grid is constructed in '' | + | Before we go through the input file, it is worthwhile |
+ | how the multi-grid is constructed in '' | ||
Gaussians are mapped onto the different grid levels. Hopefully this | Gaussians are mapped onto the different grid levels. Hopefully this | ||
- | will offer the reader | + | will offer the reader a clear picture of how the key control |
parameters affect the grids, and thus the overall accuracy of a | parameters affect the grids, and thus the overall accuracy of a | ||
calculation. | calculation. | ||
All multi-grid related settings for a calculation is controlled via | All multi-grid related settings for a calculation is controlled via | ||
- | keywords in [[http:// | + | keywords in [[inp>FORCE_EVAL/ |
- | [[http:// | + | [[inp>FORCE_EVAL|FORCE_EVAL]]. The number of levels for the multi-grid is defined by |
- | [[http:// | + | [[inp>FORCE_EVAL/ |
defines the planewave cutoff (default unit is in Ry) for the | defines the planewave cutoff (default unit is in Ry) for the | ||
//finest// level of the multi-grid. | //finest// level of the multi-grid. | ||
Line 47: | Line 47: | ||
{\alpha^{(i-1)}} | {\alpha^{(i-1)}} | ||
\end{equation*} | \end{equation*} | ||
- | where \(\alpha\) has a default value of 3.0, and since '' | + | where \(\alpha\) has a default value of 3.0, and since '' |
- | versions | + | versions |
- | [[http:// | + | [[inp>FORCE_EVAL/ |
the finer grid for all multi-grid levels. | the finer grid for all multi-grid levels. | ||
- | Having constructed the multi-grid, '' | + | Having constructed the multi-grid, '' |
- | the Gaussians onto the grids. The keyword [[http:// | + | the Gaussians onto the grids. The keyword [[inp>FORCE_EVAL/ |
which product Gaussians are mapped onto which level of the | which product Gaussians are mapped onto which level of the | ||
- | multi-grid. | + | multi-grid. |
that the number of grid points covered by the Gaussian---no matter | that the number of grid points covered by the Gaussian---no matter | ||
- | how wide or narrow---are roughly the same. [[http:// | + | how wide or narrow---are roughly the same. [[inp>FORCE_EVAL/ |
planewave cutoff of a reference grid covered by a Gaussian with | planewave cutoff of a reference grid covered by a Gaussian with | ||
unit standard deviation (\(e^{\vert\vec{r}\vert^2}\)). A Gaussian | unit standard deviation (\(e^{\vert\vec{r}\vert^2}\)). A Gaussian | ||
Line 63: | Line 63: | ||
function will cover number of grid points greater than or equal to | function will cover number of grid points greater than or equal to | ||
the number of grid points \(e^{\lvert\vec{r}\rvert^2}\) will cover on | the number of grid points \(e^{\lvert\vec{r}\rvert^2}\) will cover on | ||
- | a reference grid defined by [[http:// | + | a reference grid defined by [[inp>FORCE_EVAL/ |
Therefore, the two most important keywords effecting the | Therefore, the two most important keywords effecting the | ||
- | integration grid and the accuracy of a calculation are [[http:// | + | integration grid and the accuracy of a calculation are [[inp>FORCE_EVAL/ |
- | [[http:// | + | [[inp>FORCE_EVAL/ |
- | and the calculation may become inaccurate; and if '' | + | and the calculation may become inaccurate; and if '' |
- | too low, then even if you have a high [[http:// | + | too low, then even if you have a high [[inp>FORCE_EVAL/ |
be mapped onto the coarsest level of the multi-grid, and thus the | be mapped onto the coarsest level of the multi-grid, and thus the | ||
effective integration grid for the calculation may still be too | effective integration grid for the calculation may still be too | ||
coarse. | coarse. | ||
- | ====== Example: Bulk Si with 8 atoms in a cubic cell ====== | ||
+ | |||
+ | ===== Example: Bulk Si with 8 atoms in a cubic cell ===== | ||
We demonstrate the process using an example based on Bulk Si with 8 | We demonstrate the process using an example based on Bulk Si with 8 | ||
atoms in a face centred cubic unit cell. | atoms in a face centred cubic unit cell. | ||
- | ===== Template Input File ===== | ||
- | To systematically find the best [[http:// | + | ==== Template Input File ==== |
- | which are sufficient for a given accuracy (say, \(10^-6\) Ry in total | + | To systematically find the best [[inp>FORCE_EVAL/ |
+ | which are sufficient for a given accuracy (say, \(10^{-6}\) Ry in total | ||
energy), we need to perform a series of single point energy | energy), we need to perform a series of single point energy | ||
calculations. It is much easier to use a set of scripts that can | calculations. It is much easier to use a set of scripts that can | ||
automate this process. | automate this process. | ||
- | To do this, we first write a template input file: '' | + | To do this, we first write a template input file: '' |
as shown below: | as shown below: | ||
Line 101: | Line 102: | ||
POTENTIAL_FILE_NAME | POTENTIAL_FILE_NAME | ||
&MGRID | &MGRID | ||
+ | NGRIDS 4 | ||
CUTOFF LT_cutoff | CUTOFF LT_cutoff | ||
REL_CUTOFF LT_rel_cutoff | REL_CUTOFF LT_rel_cutoff | ||
Line 160: | Line 162: | ||
&END PRINT | &END PRINT | ||
&END FORCE_EVAL | &END FORCE_EVAL | ||
- | </ | + | </ |
We go through this input file quickly. Readers who have gone | We go through this input file quickly. Readers who have gone | ||
- | through the tutorial on how to perform a simple static energy and | + | through the [[static_calculation|tutorial on how to perform a simple static energy and |
- | force calculation using '' | + | force calculation]] using '' |
understanding most parts the above input. | understanding most parts the above input. | ||
Line 174: | Line 176: | ||
PRINT_LEVEL MEDIUM | PRINT_LEVEL MEDIUM | ||
&END GLOBAL | &END GLOBAL | ||
- | </ | + | </ |
- | The keyword [[http:// | + | The keyword [[inp>GLOBAL#RUN_TYPE|RUN_TYPE]] is set to '' |
calculate the energies of the system, forces will not be | calculate the energies of the system, forces will not be | ||
calculated. Since we are only interested in the convergence of the | calculated. Since we are only interested in the convergence of the | ||
integration grid, just looking at the total energy usually suffices; | integration grid, just looking at the total energy usually suffices; | ||
and since we will be performing a series of computations, | and since we will be performing a series of computations, | ||
- | cheaper each run is the better. We set [[http:// | + | cheaper each run is the better. We set [[inp>GLOBAL#PRINT_LEVEL|PRINT_LEVEL]] to '' |
that the information about how many Gaussian functions are mapped | that the information about how many Gaussian functions are mapped | ||
onto which grid are printed. We need this information to analyse the | onto which grid are printed. We need this information to analyse the | ||
- | suitability of the chosen [[http:// | + | suitability of the chosen [[inp>FORCE_EVAL/ |
The most important part in the template input is: | The most important part in the template input is: | ||
<code cp2k> | <code cp2k> | ||
&MGRID | &MGRID | ||
+ | NGRIDS 4 | ||
CUTOFF LT_cutoff | CUTOFF LT_cutoff | ||
REL_CUTOFF LT_rel_cutoff | REL_CUTOFF LT_rel_cutoff | ||
&END MGRID | &END MGRID | ||
- | </ | + | </ |
- | The symbols '' | + | The symbols '' |
the automated scripts will search for and replace with the relevant | the automated scripts will search for and replace with the relevant | ||
- | values. The default units for both [[http:// | + | values. The default units for both [[inp>FORCE_EVAL/ |
Ry. | Ry. | ||
- | In '' | + | In '' |
<code cp2k> | <code cp2k> | ||
MAX_SCF 1 | MAX_SCF 1 | ||
- | </ | + | </ |
So that no self-consistent loops will be performed. This is okay for | So that no self-consistent loops will be performed. This is okay for | ||
checking the integration grid, because irrespective of | checking the integration grid, because irrespective of | ||
self-consistency, | self-consistency, | ||
consistent energies. | consistent energies. | ||
- | ===== Converging '' | ||
- | We start by setting [[http:// | + | |
- | systematically vary [[http:// | + | ==== Converging '' |
+ | We start by setting [[inp>FORCE_EVAL/ | ||
+ | systematically vary [[inp>FORCE_EVAL/ | ||
usually sufficient for most calculations, | usually sufficient for most calculations, | ||
- | be checked later when we vary [[http:// | + | be checked later when we vary [[inp>FORCE_EVAL/ |
- | ==== Generating Inputs ==== | ||
- | We want to perform a series of calculations, | + | === Generating Inputs === |
+ | We want to perform a series of calculations, | ||
from 50 Ry to 500 Ry in steps of 50 Ry. From experience, the | from 50 Ry to 500 Ry in steps of 50 Ry. From experience, the | ||
- | desired [[http:// | + | desired [[inp>FORCE_EVAL/ |
energy should be well within this range. To do this, we first need | energy should be well within this range. To do this, we first need | ||
to make sure the basis and pseudopotential parameter files | to make sure the basis and pseudopotential parameter files | ||
- | '' | + | '' |
- | together with '' | + | together with '' |
- | such as the file '' | + | such as the file '' |
- | < | + | < |
#!/bin/bash | #!/bin/bash | ||
Line 247: | Line 251: | ||
cp $potential_file $work_dir | cp $potential_file $work_dir | ||
done | done | ||
- | </ | + | </ |
The user should remember to set the permission of the new script | The user should remember to set the permission of the new script | ||
Line 253: | Line 257: | ||
< | < | ||
chmod u+x ./ | chmod u+x ./ | ||
- | </ | + | </ |
Entering the command line | Entering the command line | ||
< | < | ||
./ | ./ | ||
- | </ | + | </ |
- | generates directories '' | + | generates directories '' |
- | each containing '' | + | each containing '' |
- | '' | + | '' |
- | that [[http:// | + | that [[inp>FORCE_EVAL/ |
values in the range between 50 Ry and 500 Ry. | values in the range between 50 Ry and 500 Ry. | ||
- | ==== Running Calculations ==== | ||
+ | |||
+ | === Running Calculations === | ||
With the input files generated and checked, the next step is to | With the input files generated and checked, the next step is to | ||
- | run them. A bash script such as '' | + | run them. A bash script such as '' |
the job: | the job: | ||
- | < | + | < |
#!/bin/bash | #!/bin/bash | ||
Line 298: | Line 303: | ||
done | done | ||
wait | wait | ||
- | </ | + | </ |
The above script is slightly complex, because it allows several | The above script is slightly complex, because it allows several | ||
- | jobs to run in parallel. Setting the variable '' | + | jobs to run in parallel. Setting the variable '' |
- | the path to the '' | + | the path to the '' |
- | '' | + | '' |
the number of MPI processes to be used in parallel for each | the number of MPI processes to be used in parallel for each | ||
- | job. '' | + | job. '' |
used for running all of the jobs. In the above example, the jobs | used for running all of the jobs. In the above example, the jobs | ||
are run on a 24 core local workstation, | are run on a 24 core local workstation, | ||
- | used for performing the [[http:// | + | used for performing the [[inp>FORCE_EVAL/ |
and 2 cores are used for each calculation. This means up to 8 jobs | and 2 cores are used for each calculation. This means up to 8 jobs | ||
will run in parallel, until the jobs are exhausted from the list | will run in parallel, until the jobs are exhausted from the list | ||
- | given in '' | + | given in '' |
The reader can write their own script where they see fit, and if | The reader can write their own script where they see fit, and if | ||
Line 320: | Line 325: | ||
< | < | ||
chmod u+x ./ | chmod u+x ./ | ||
- | </ | + | </ |
followed by | followed by | ||
< | < | ||
./ | ./ | ||
- | </ | + | </ |
runs the calculations in the background. This calculation only | runs the calculations in the background. This calculation only | ||
took a couple of minutes to complete on our local workstation. | took a couple of minutes to complete on our local workstation. | ||
- | ==== Analysing Results ==== | ||
+ | |||
+ | === Analysing Results === | ||
After all of the calculations have finished, all the information | After all of the calculations have finished, all the information | ||
about total energies and distribution of Gaussians on the | about total energies and distribution of Gaussians on the | ||
- | multi-grid are written in the '' | + | multi-grid are written in the '' |
directories. | directories. | ||
The total energy can be found in the section of the output shown | The total energy can be found in the section of the output shown | ||
- | below (in this example from '' | + | below (in this example from '' |
< | < | ||
Line 369: | Line 375: | ||
Total energy: | Total energy: | ||
- | </ | + | </ |
Regexp search | Regexp search | ||
< | < | ||
"^[ \t]*Total energy:" | "^[ \t]*Total energy:" | ||
- | </ | + | </ |
will find the relevant line. | will find the relevant line. | ||
Line 388: | Line 394: | ||
count for grid 4: | count for grid 4: | ||
total gridlevel count : 10496 | total gridlevel count : 10496 | ||
- | </ | + | </ |
- | which tells us that for [[http:// | + | which tells us that for [[inp>FORCE_EVAL/ |
Ry, 2720 product Gaussians has been distributed to grid level 1, | Ry, 2720 product Gaussians has been distributed to grid level 1, | ||
the finest level, 5000 for level 2, 2760 for level 3 and 16 for | the finest level, 5000 for level 2, 2760 for level 3 and 16 for | ||
level 4, the coarsest. The planewave cutoff for each multi-grid | level 4, the coarsest. The planewave cutoff for each multi-grid | ||
- | level can be read from the right-hand-side columns. Here '' | + | level can be read from the right-hand-side columns. Here '' |
means the Hartree energy unit, 1 Ha = 2 Ry. | means the Hartree energy unit, 1 Ha = 2 Ry. | ||
It is much easier if we can gather all the information together | It is much easier if we can gather all the information together | ||
into one file, which allows us to plot the results. | into one file, which allows us to plot the results. | ||
- | done, again, by using a simple script. '' | + | done, again, by using a simple script. '' |
below is such an example: | below is such an example: | ||
- | < | + | < |
#!/bin/bash | #!/bin/bash | ||
Line 424: | Line 430: | ||
awk ' | awk ' | ||
if $grid_header ; then | if $grid_header ; then | ||
- | for ((igrid=1; igrid <= $ngrids; igrid++)) ; do | + | for ((igrid=1; igrid <= ngrids; igrid++)) ; do |
printf " | NG on grid %d" $igrid >> $plot_file | printf " | NG on grid %d" $igrid >> $plot_file | ||
done | done | ||
Line 431: | Line 437: | ||
fi | fi | ||
printf " | printf " | ||
- | for ((igrid=1; igrid <= $ngrids; igrid++)) ; do | + | for ((igrid=1; igrid <= ngrids; igrid++)) ; do |
grid=$(grep -e '^[ \t]*count for grid' $work_dir/ | grid=$(grep -e '^[ \t]*count for grid' $work_dir/ | ||
awk -v igrid=$igrid '(NR == igrid){print $5}') | awk -v igrid=$igrid '(NR == igrid){print $5}') | ||
Line 438: | Line 444: | ||
printf " | printf " | ||
done | done | ||
- | </ | + | </ |
Type | Type | ||
< | < | ||
chmod u+x ./ | chmod u+x ./ | ||
- | </ | + | </ |
and then run it using | and then run it using | ||
< | < | ||
./ | ./ | ||
- | </ | + | </ |
- | will produce a file named '' | + | will produce a file named '' |
< | < | ||
# Grid cutoff vs total energy | # Grid cutoff vs total energy | ||
Line 465: | Line 471: | ||
450.00 | 450.00 | ||
500.00 | 500.00 | ||
- | </ | + | </ |
- | The data shows that given the [[http:// | + | The data shows that given the [[inp>FORCE_EVAL/ |
- | [[http:// | + | [[inp>FORCE_EVAL/ |
- | less than \(10^{-8}\) Ha. The reader may also notice that as [[http:// | + | less than \(10^{-8}\) Ha. The reader may also notice that as [[inp>FORCE_EVAL/ |
increases, the number of Gaussians being assigned to the finest | increases, the number of Gaussians being assigned to the finest | ||
- | grids decreases. Therefore, simply increasing [[http:// | + | grids decreases. Therefore, simply increasing [[inp>FORCE_EVAL/ |
- | increasing [[http:// | + | increasing [[inp>FORCE_EVAL/ |
in energy, as more and more Gaussians get pushed to coarser grid | in energy, as more and more Gaussians get pushed to coarser grid | ||
- | levels, negating the increase in [[http:// | + | levels, negating the increase in [[inp>FORCE_EVAL/ |
In this example, the test results point to 250 Ry as a good choice | In this example, the test results point to 250 Ry as a good choice | ||
- | for [[http:// | + | for [[inp>FORCE_EVAL/ |
distribution of Gaussian functions on the grids are reasonable: it | distribution of Gaussian functions on the grids are reasonable: it | ||
is the lowest cutoff energy where the finest grid level is used, | is the lowest cutoff energy where the finest grid level is used, | ||
- | but at the same time with the majority of the Gaussians on the | + | but at the same time with the majority of the Gaussians on the coarser grids. |
- | coarser grids. | + | |
- | ===== Converging '' | + | |
- | In the next step, we vary the value of [[http:// | ||
- | [[http:// | ||
- | ==== Generating Inputs | + | ==== Converging '' |
+ | In the next step, we vary the value of [[inp> | ||
+ | [[inp> | ||
- | For the energy convergence test with varying [[http:// | ||
- | follow a similar procedure as that for [[http:// | ||
- | template input file '' | ||
- | '' | ||
- | < | + | === Generating Inputs === |
+ | For the energy convergence test with varying [[inp> | ||
+ | follow a similar procedure as that for [[inp> | ||
+ | template input file '' | ||
+ | '' | ||
+ | |||
+ | < | ||
#!/bin/bash | #!/bin/bash | ||
Line 519: | Line 525: | ||
cp $potential_file $work_dir | cp $potential_file $work_dir | ||
done | done | ||
- | </ | + | </ |
Setting the permission for the script to " | Setting the permission for the script to " | ||
- | it produces directories '' | + | it produces directories '' |
- | each containing files '' | + | each containing files '' |
- | '' | + | '' |
- | [[http:// | + | [[inp>FORCE_EVAL/ |
100 respectively. | 100 respectively. | ||
- | ==== Running Calculations ==== | ||
+ | |||
+ | === Running Calculations === | ||
Again to run the calculations, | Again to run the calculations, | ||
- | '' | + | '' |
- | < | + | < |
#!/bin/bash | #!/bin/bash | ||
Line 560: | Line 567: | ||
done | done | ||
wait | wait | ||
- | </ | + | </ |
In the above example, again, we have used 16 cores in total, and | In the above example, again, we have used 16 cores in total, and | ||
Line 566: | Line 573: | ||
< | < | ||
./ | ./ | ||
- | </ | + | </ |
- | ==== Analysing Results ==== | + | |
+ | === Analysing Results === | ||
Total energies and distribution of Gaussian functions on the | Total energies and distribution of Gaussian functions on the | ||
multi-grid are obtained the same way from the results as that for | multi-grid are obtained the same way from the results as that for | ||
- | the [[http:// | + | the [[inp>FORCE_EVAL/ |
- | To put all of the results from the [[http:// | + | To put all of the results from the [[inp>FORCE_EVAL/ |
one place, we can make some minor modifications to | one place, we can make some minor modifications to | ||
- | '' | + | '' |
- | < | + | < |
# | # | ||
Line 600: | Line 608: | ||
awk ' | awk ' | ||
if $grid_header ; then | if $grid_header ; then | ||
- | for ((igrid=1; igrid <= $ngrids; igrid++)) ; do | + | for ((igrid=1; igrid <= ngrids; igrid++)) ; do |
printf " | NG on grid %d" $igrid >> $plot_file | printf " | NG on grid %d" $igrid >> $plot_file | ||
done | done | ||
Line 607: | Line 615: | ||
fi | fi | ||
printf " | printf " | ||
- | for ((igrid=1; igrid <= $ngrids; igrid++)) ; do | + | for ((igrid=1; igrid <= ngrids; igrid++)) ; do |
grid=$(grep -e '^[ \t]*count for grid' $work_dir/ | grid=$(grep -e '^[ \t]*count for grid' $work_dir/ | ||
awk -v igrid=$igrid '(NR == igrid){print $5}') | awk -v igrid=$igrid '(NR == igrid){print $5}') | ||
Line 614: | Line 622: | ||
printf " | printf " | ||
done | done | ||
- | </ | + | </ |
Making the script executable, and running the script using | Making the script executable, and running the script using | ||
< | < | ||
./ | ./ | ||
- | </ | + | </ |
produces the following results written in file | produces the following results written in file | ||
- | '' | + | '' |
< | < | ||
Line 639: | Line 647: | ||
| | ||
100.00 | 100.00 | ||
- | </ | + | </ |
- | The results show that as one increases the value of [[http:// | + | The results show that as one increases the value of [[inp>FORCE_EVAL/ |
more Gaussians get mapped onto the finer grids. The error in total | more Gaussians get mapped onto the finer grids. The error in total | ||
- | energy reduces to less than \(10^{-8}\) Ha when [[http:// | + | energy reduces to less than \(10^{-8}\) Ha when [[inp>FORCE_EVAL/ |
greater or equal to 60 Ry. The results thus indicate that 60 Ry is | greater or equal to 60 Ry. The results thus indicate that 60 Ry is | ||
- | indeed a suitable choice for the value of [[http:// | + | indeed a suitable choice for the value of [[inp>FORCE_EVAL/ |
So finally we conclude that the setting | So finally we conclude that the setting | ||
Line 653: | Line 661: | ||
REL_CUTOFF 60 | REL_CUTOFF 60 | ||
&END MGRID | &END MGRID | ||
- | </ | + | </ |
is sufficient for a calculation with the required accuracy. | is sufficient for a calculation with the required accuracy. | ||
howto/converging_cutoff.txt · Last modified: 2024/05/29 15:46 by oschuett