User Tools

Site Tools


howto:cdft

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
howto:cdft [2018/11/01 08:57] – [CDFT in summary] nholmberhowto:cdft [2018/11/01 09:20] – [Defining CDFT SCF parameters] nholmber
Line 83: Line 83:
 Settings for the CDFT SCF loop are controlled by the input section [[inp>FORCE_EVAL/DFT/QS/CDFT]]. An example of a typical CDFT input is given below. These parameter selections should be suitable for most systems. Settings for the CDFT SCF loop are controlled by the input section [[inp>FORCE_EVAL/DFT/QS/CDFT]]. An example of a typical CDFT input is given below. These parameter selections should be suitable for most systems.
  
-<note important>The CDFT input structure was altered slightly in CP2K version 6.1. The changes are indicated below. Input files for subsequent example calculations are provided for both versions 5.1 and 6.1, though using the latest available version is always recommended. </note>+<note important> Please note that the CDFT input structure was significantly altered in CP2K version 7.0. As the main difference to older CP2K versions, the Becke constraint section has been merged into the CDFT section. The example calculations below include different input files for CP2K versions 5.16.1, and 7.0 (and later). The use of the latest available version is strongly recommended. </note>
  
 <code cp2k> <code cp2k>
 &QS &QS
   ...   ...
-  &BECKE_CONSTRAINT 
-    ... 
-  &END BECKE_CONSTRAINT 
   ! CDFT loop settings   ! CDFT loop settings
 +  ! Please note that prior to CP2K version 7.0,
 +  ! Becke constraints were separate from the CDFT section
   &CDFT   &CDFT
     TYPE_OF_CONSTRAINT BECKE     TYPE_OF_CONSTRAINT BECKE
 +    ! Compute CDFT charges?
 +    ATOMIC_CHARGES  TRUE
 +    ! Constraint strength and target values
 +    ! Give one value per constraint
 +    STRENGTH        ${BECKE_STR}
 +    TARGET          ${BECKE_TARGET}
 +    ! Constraint definitions, each repetition defines a new constraint
 +    &ATOM_GROUP
 +      ATOMS 1
 +      COEFF 1
 +      CONSTRAINT_TYPE CHARGE
 +    &END ATOM_GROUP
 +    ! No constraint applied but calculate charges
 +    &DUMMY_ATOMS
 +      ATOMS 2
 +    &END DUMMY_ATOMS
 +    ! CDFT convergence and optimizer settings
     &OUTER_SCF ON     &OUTER_SCF ON
-      TYPE BECKE_CONSTRAINT+      TYPE CDFT_CONSTRAINT
       EXTRAPOLATION_ORDER 2       EXTRAPOLATION_ORDER 2
       MAX_SCF 10       MAX_SCF 10
       ! Convergence threshold       ! Convergence threshold
       EPS_SCF 1.0E-3       EPS_SCF 1.0E-3
-      ! Optimizer selection: now Newton's method with backtracking line search+      ! Optimizer selection: 
 +      ! Now Newton's method with backtracking line search
       OPTIMIZER NEWTON_LS       OPTIMIZER NEWTON_LS
-      ! Optimizer step size+      ! Optimizer (initial) step size
       STEP_SIZE -1.0       STEP_SIZE -1.0
       ! Note that the section CDFT_OPT exists in CP2K version >= 6.1       ! Note that the section CDFT_OPT exists in CP2K version >= 6.1
Line 111: Line 128:
         CONTINUE_LS         CONTINUE_LS
         FACTOR_LS 0.5         FACTOR_LS 0.5
-        ! Finite difference settings for calculation of Jacobian matrix+        ! Finite difference settings for Jacobian matrix
         JACOBIAN_STEP 1.0E-2         JACOBIAN_STEP 1.0E-2
         JACOBIAN_FREQ 1 1         JACOBIAN_FREQ 1 1
Line 117: Line 134:
         JACOBIAN_RESTART FALSE         JACOBIAN_RESTART FALSE
       &END CDFT_OPT       &END CDFT_OPT
-    &END OUTER_SCF+    &END 
 +    ! Settigs specific to Becke constraints 
 +    &BECKE_CONSTRAINT 
 +      ... 
 +    &END BECKE_CONSTRAINT 
 +    ! Print information about CDFT calculation 
 +    &PROGRAM_RUN_INFO ON 
 +      &EACH 
 +        QS_SCF 1 
 +      &END EACH 
 +      COMMON_ITERATION_LEVELS 2 
 +      ADD_LAST NUMERIC 
 +      FILENAME ./${NAME} 
 +    &END PROGRAM_RUN_INFO
   &END CDFT   &END CDFT
 &END QS &END QS
 </code> </code>
  
-The structure of this input section is quite straightforward. The keyword [[inp>FORCE_EVAL/DFT/QS/CDFT/OUTER_SCF#EPS_SCF|EPS_SCF]] defines the CDFT constraint convergence threshold $\varepsilon$ and [[inp>FORCE_EVAL/DFT/QS/CDFT/OUTER_SCF#OPTIMIZER|OPTIMIZER]] selects the CDFT optimizer. Using Newton or quasi-Newton optimizers (Broyden methods) is recommended for most applications. These optimizers accept additional control settings that define how the Jacobian matrix is calculated (keywords JACOBIAN_*) and how to optimize the step size $\alpha$ (keywords *_LS). These keywords are available in the [[inp>FORCE_EVAL/DFT/QS/CDFT/OUTER_SCF/CDFT_OPT|CDFT_OPT]] section. MD simulations with a single constraint might benefit from using the bisect optimizer, which avoids building the Jacobian matrix, in case a considerable amount of the total time per MD step is spent in building the Jacobian. Notice, however, that the frequency of Jacobian rebuilds [[inp>FORCE_EVAL/DFT/QS/CDFT/OUTER_SCF/CDFT_OPT#JACOBIAN_FREQ|JACOBIAN_FREQ]] can be controlled on a per MD step and per CDFT SCF step basis. The Broyden optimizers require less frequent rebuilds of the Jacobian matrix because the matrix is [[https://en.wikipedia.org/wiki/Broyden%27s_method|rank-one updated]] every iteration, although the stability of the method with respect to the rebuild frequency needs to be carefully studied.+The structure of this input section is quite straightforward and consists of three parts: 
 +  - Constraint definitions (type, which atoms to include, constraint target, etc) 
 +  - CDFT SCF loop settings (solver, convergence criterion, etc) 
 +  - Constraint weight function specific settings (Becke/Hirshfeld subsections)  
 + 
 +In the above example, a Becke constraint is selected using the keyword [[inp>FORCE_EVAL/DFT/QS/CDFT#TYPE_OF_CONSTRAINT|TYPE_OF_CONSTRAINT]]. The actual constraints are defined using the section [[inp>FORCE_EVAL/DFT/QS/CDFT/ATOM_GROUP|ATOM_GROUP]]. Each repetition of this section defines a new constraint. The constraint atoms are selected with the keyword [[inp>FORCE_EVAL/DFT/QS/CDFT/ATOM_GROUP#ATOMS|ATOMS]] and the keyword [[inp>FORCE_EVAL/DFT/QS/CDFT/ATOM_GROUP#COEFF|COEFF]] determines how the atoms are summed up to form the constraint. Usually all coefficients are set to +1, but mixing +1 and -1 coefficients would define the constraint as the difference between two groups of atoms. The keywords [[inp>FORCE_EVAL/DFT/QS/CDFT#TARGET|TARGET]] and [[inp>FORCE_EVAL/DFT/QS/CDFT#STRENGTH|STRENGTH]] define the constraint target values and the initial constraint strengths $\vec\lambda$, respectively. The constraint target value should be the desired number of valence electrons on the constraint atoms, suitably multiplied by atomic coefficients in case a relative constraint between two atom groups has been used. The constaint type is selected with the keyword [[inp>FORCE_EVAL/DFT/QS/CDFT/ATOM_GROUP#CONSTRAINT_TYPE|CONSTRAINT_TYPE]]. It is also possible to use fragment based constraints [[inp>FORCE_EVAL/DFT/QS/CDFT/ATOM_GROUP#FRAGMENT_CONSTRAINT|FRAGMENT_CONSTRAINT]], in which case the constraint target value is calculated from the superposition of isolated fragment densities according to the scheme in Figure 3.  
 + 
 +{{ howto:cdft-fragment-constraint.png?350 }} 
 +**Figure 3.** Using a fragment based CDFT constraint. The system is first divided into two fragments with atomic positions fixed in the same configuration as in the full system. The electron and spin densities of the fragment systems are then saved to cube files and subsequently used as input files for the CDFT calculation, where the constraint target value is calculated from the superimposed fragment densities.  
 + 
 +The OUTER_SCF section within the CDFT section defines settings for the CDFT SCF loop. The keyword [[inp>FORCE_EVAL/DFT/QS/CDFT/OUTER_SCF#EPS_SCF|EPS_SCF]] defines the CDFT constraint convergence threshold $\varepsilon$ and [[inp>FORCE_EVAL/DFT/QS/CDFT/OUTER_SCF#OPTIMIZER|OPTIMIZER]] selects the CDFT optimizer. Using Newton or quasi-Newton optimizers (Broyden methods) is recommended for most applications. These optimizers accept additional control settings that define how the Jacobian matrix is calculated (keywords JACOBIAN_*) and how to optimize the step size $\alpha$ (keywords *_LS). These keywords are available in the [[inp>FORCE_EVAL/DFT/QS/CDFT/OUTER_SCF/CDFT_OPT|CDFT_OPT]] section. MD simulations with a single constraint might benefit from using the bisect optimizer, which avoids building the Jacobian matrix, in case a considerable amount of the total time per MD step is spent in building the Jacobian. Notice, however, that the frequency of Jacobian rebuilds [[inp>FORCE_EVAL/DFT/QS/CDFT/OUTER_SCF/CDFT_OPT#JACOBIAN_FREQ|JACOBIAN_FREQ]] can be controlled on a per MD step and per CDFT SCF step basis. The Broyden optimizers require less frequent rebuilds of the Jacobian matrix because the matrix is [[https://en.wikipedia.org/wiki/Broyden%27s_method|rank-one updated]] every iteration, although the stability of the method with respect to the rebuild frequency needs to be carefully studied.
  
 Above, for instance, the Jacobian is explicitly calculated every CDFT SCF iteration and MD step by perturbing each constraint Lagragian using a first order forward difference stencil with a step size of $10^{-2}$. The Newton step size is optimized with backtracking line search using the update formula $\alpha_n = 0.5*\alpha_{n-1}$ for a maximum of 5 steps as long as the CDFT constraint error decreases. Above, for instance, the Jacobian is explicitly calculated every CDFT SCF iteration and MD step by perturbing each constraint Lagragian using a first order forward difference stencil with a step size of $10^{-2}$. The Newton step size is optimized with backtracking line search using the update formula $\alpha_n = 0.5*\alpha_{n-1}$ for a maximum of 5 steps as long as the CDFT constraint error decreases.
howto/cdft.txt · Last modified: 2024/01/03 13:20 by oschuett