Geometry optimization# 几何优化

Basic usage# 基本用法 #

Optimizing a geometry means finding the geometry that minimizes the total energy for a given method.
优化几何结构意味着找到在给定方法下使总能量最小的几何结构。

Now, suppose you want to calculate the optimized geometry of the amino acid alanine for a given method. The first step is to have some kind of guess geometry. You can use Avogadro to draw its structure and run the simple optimizer to get a reasonable atom arrangement:
现在,假设你想计算给定方法下氨基酸丙氨酸的优化几何结构。第一步是要有某种猜测的几何结构。你可以使用 Avogadro 来绘制其结构并运行简单的优化器以获得合理的原子排列:

../_images/alanine.png

Figure: Creation of the input structure in Avogadro.
图:在 Avogadro 中创建输入结构。
#

and with those coordinates, you can already set up your ORCA input!
有了这些坐标,您就可以设置您的 ORCA 输入了!

Note 注释

One can use Avogadro itself to make the input, save the molecule as a .xyz and read it (see Reading from external file, or add the coordinates directly to the Structure section of the input using the "xyz" flag.
可以使用 Avogadro 直接制作输入,将分子保存为.xyz 格式并读取它(参见从外部文件读取),或者直接将坐标添加到输入的 Structure 部分,使用"xyz"标志。

If you want to optimize the geometry, for instance using DFT, all you have to do is to choose a functional and a basis set and add OPT to the main input:
如果你想优化几何结构,例如使用 DFT,只需选择一个泛函和一个基组,并在主输入中添加 OPT:

!B3LYP D4 DEF2-SVP OPT
* xyz 0 1
N         -0.83911        0.76325       -0.31843
C          0.61442        0.72014       -0.25075
C          1.01669       -0.56167        0.49740
O          0.20095       -1.36984        0.93753
H         -1.37884        0.05803        0.17605
H          1.00414        0.66192       -1.27362
C          1.17285        1.95192        0.45211
H          0.87124        2.87150       -0.05988
H          0.81191        2.01288        1.48492
H          2.26726        1.92903        0.48485
H         -1.30551        1.57618       -0.71069
O          2.33980       -0.77979        0.66176
H          3.04559       -0.08055        0.28096
*

Important 重要

DFT and HF are known to perform poorly with intermolecular or weak interactions. In general it is advisable to use a dispersion correction like the charge-dependent D4 [Grimme2017] correction, these will correct both the energies and gradients and lead to much better results. For an example, see the dispersion corrections tutorial.
DFT 和 HF 在处理分子间或弱相互作用时表现不佳。通常建议使用诸如电荷依赖的 D4[Grimme2017]校正等色散校正方法,这些方法将同时修正能量和梯度,从而获得更好的结果。例如,请参阅色散校正教程。

If everything is right, you should first see on the output, after the main header:
如果一切正常,您首先应在输出中看到主标题之后的内容:

                       *****************************
                       * Geometry Optimization Run *
                       *****************************

Geometry optimization settings:
Update method            Update   .... BFGS
Choice of coordinates    CoordSys .... (2022) Redundant Internals
Initial Hessian          InHess   .... Almloef's Model
Max. no of cycles        MaxIter  .... 50  

Convergence Tolerances:  
Energy Change            TolE     ....  5.0000e-06 Eh  
Max. Gradient            TolMAXG  ....  3.0000e-04 Eh/bohr    
RMS Gradient             TolRMSG  ....  1.0000e-04 Eh/bohr
Max. Displacement        TolMAXD  ....  4.0000e-03 bohr
RMS Displacement         TolRMSD  ....  2.0000e-03 bohr
Strict Convergence                .... False
[...]

where some of the parameters for the optimization are written.
其中一些优化参数被写入。

Then the SCF runs, followed by the calculation of a gradient and information related the current step is given:
然后运行 SCF,接着计算梯度,并给出与当前步骤相关的信息:

                                .--------------------.
          ----------------------|Geometry convergence|-------------------------
          Item                value                   Tolerance       Converged
          ---------------------------------------------------------------------
          RMS gradient        0.0131221890            0.0001000000      NO
          MAX gradient        0.0693329334            0.0003000000      NO
          RMS step            0.0338354977            0.0020000000      NO
          MAX step            0.1850954319            0.0040000000      NO
          ........................................................
          Max(Bonds)      0.0979      Max(Angles)    4.24
          Max(Dihed)        2.52      Max(Improp)    0.00
          ---------------------------------------------------------------------

The optimization has not yet converged - more geometry cycles are needed

Since the guess geometry was far from good, none of the criteria for convergence are achieved on the first step. The geometry is then modified according to the default algorithm (a quasi-Newton method) and you can see the changes in geometry next:
由于初始几何构型远非理想,第一步中未达到任何收敛标准。随后根据默认算法(拟牛顿法)对几何构型进行修正,以下为几何变化情况:

    -----------------------------------------------------------------
                    Redundant Internal Coordinates


    -----------------------------------------------------------------
         Definition                    Initial Value    Approx d2E/dq
    -----------------------------------------------------------------
      1. B(C   1,N   0)                  1.4557         0.439528
      2. B(C   2,C   1)                  1.5377         0.363127
      3. B(O   3,C   2)                  1.2297         1.008194
      4. B(H   4,N   0)                  1.0164         0.422588
      5. B(H   4,O   3)                  2.2615         0.004360
[...]

and the process is repeated until the criteria are met:
该过程不断重复,直至满足标准:

                                .--------------------.
          ----------------------|Geometry convergence|-------------------------
          Item                value                   Tolerance       Converged
          ---------------------------------------------------------------------
          Energy change      -0.0000017024            0.0000050000      YES
          RMS gradient        0.0000385484            0.0001000000      YES
          MAX gradient        0.0001252435            0.0003000000      YES
          RMS step            0.0004721674            0.0020000000      YES
          MAX step            0.0017352647            0.0040000000      YES
          ........................................................
          Max(Bonds)      0.0009      Max(Angles)    0.03
          Max(Dihed)        0.08      Max(Improp)    0.00
          ---------------------------------------------------------------------

                    ***********************HURRAY********************
                    ***        THE OPTIMIZATION HAS CONVERGED     ***
                    *************************************************

Warning 警告

Always check for the HURRAY message for full convergence of your geometry optimization. If the geometry optimization is close to but not fully converged this message will be missing even though ORCA may state that the run was successful! If this is the case you should consider restarting the optimization to reach full convergence.
始终检查 HURRAY 消息以确认几何优化完全收敛。如果几何优化接近但未完全收敛,即使 ORCA 可能声明运行成功,此消息也会缺失!若出现此情况,应考虑重新启动优化以实现完全收敛。

Here you can see how the geometry changes during the optimization:
在这里,您可以看到几何形状在优化过程中的变化:

../_images/opt.gif

Figure: Optimization of alanine.
图:丙氨酸的优化。
#

Although the initial guess appeared to be good, as one can see, the B3LYP functional predicts the geometry somewhat different from the input given. The initial guess had the amine group in a more planar configuration that was fixed by the optimization, along with corrections in the bond lengths.
尽管初始猜测看似良好,但如所见,B3LYP 泛函预测的几何结构与给定的输入略有不同。初始猜测中氨基处于更平面的构型,这一问题在优化过程中得到了修正,同时修正了键长。

Important 重要

After a geometry optimization run, a file named basename.xyz is printed with the final geometry coordinates that can be later used in following calculations. The optimization trajectory is also stored in basename_trj.xyz.
几何优化运行后,会生成一个名为 basename.xyz 的文件,其中包含最终的几何坐标,这些坐标可用于后续计算。优化轨迹也存储在 basename_trj.xyz 中。

You can also see how the energy of the molecule goes down as the optimization progresses, leaning towards convergence:
你还可以看到,随着优化过程的推进,分子的能量逐渐降低,趋向收敛:

../_images/enconv.png

Figure: Energy convergence for the optimization of alanine.
图:丙氨酸优化中的能量收敛。
#

Is this a real minimum?#
这是一个真正的最小值吗?

How can one know if this is a real minimum? The norm of the gradient is also zero at saddle points, or maybe the gradient was low, but not sufficiently low.
如何判断这是一个真正的极小值?梯度的范数在鞍点处也为零,或者可能是梯度虽低,但并未足够低。

It is possible to check that by calculating the vibrational frequencies on the final geometry, adding a FREQ keyword on the main input:
可以通过计算最终几何结构上的振动频率来验证,在主输入中添加 FREQ 关键字:

!B3LYP D4 DEF2-SVP OPT FREQ
*XYZFILE 0 1 structure.xyz

Then, after computing the exact Hessian, the frequencies will be printed:
然后,在计算出精确的 Hessian 矩阵后,将打印出频率:

-----------------------
VIBRATIONAL FREQUENCIES
----------------------- 
      
Scaling factor for frequencies =  1.000000000  (already applied!)        
      
     0:       0.00 cm**-1
     1:       0.00 cm**-1
     2:       0.00 cm**-1
     3:       0.00 cm**-1
     4:       0.00 cm**-1
     5:       0.00 cm**-1
     6:      61.84 cm**-1
     7:     233.75 cm**-1
     8:     247.07 cm**-1
     9:     256.69 cm**-1
    10:     323.06 cm**-1
[...]

and you can see, all frequencies besides the first translations and rotations are positive, that means we do have a true minimum.
可以看到,除了第一次平移和旋转之外的所有频率均为正值,这意味着我们确实达到了一个真正的最小值。

Important 重要

All positive frequencies guarantee a local minimum, but not necessarily a global minimum! You can use GOAT to automatically search for the global minimum and the conformer ensemble.
所有正频率确保局部最小值,但未必是全局最小值!您可以使用 GOAT 来自动搜索全局最小值和构象集合。

Numerical gradients# 数值梯度

The quality of the final geometry depends on the quality of the method you choose. In case you want to optimize the geometry for a method to which there is currently no analytical gradient, you can ask for the numerical gradient using the NUMGRAD flag:
最终几何结构的质量取决于您所选择方法的质量。若您希望针对当前尚无解析梯度的方法优化几何结构,可以使用 NUMGRAD 标志请求数值梯度:

!DLPNO-CCSD(T) cc-pVTZ cc-pVTZ/C OPT NUMGRAD

Warning 警告

Take care when using numerical gradients, the calculation will take much longer if the system is large.
使用数值梯度时要小心,如果系统规模较大,计算时间会显著增加。

How to remove negative frequencies?#
如何去除负频率?

It is not uncommon that, after a geometry optimization run, you end up with one or more negative frequencies, notably if your system has weak intermolecular interactions. It might be that you are stuck on a saddle point or that the optimization criteria was just not good enough.
在几何优化运行后,得到一个或多个负频率的情况并不少见,特别是在系统存在弱分子间相互作用时尤为显著。这可能意味着你陷入了鞍点,或者优化标准不够严格。

If you have many small negative frequencies, you probably just need a tighter convergence:
如果你有许多小的负频率,可能只需更严格的收敛条件:

!TIGHTOPT

or, in drastic cases:
或者,在极端情况下:

!VERYTIGHTOPT

and it should do it.
而且它应该这样做。

If your system has one large negative frequency, it might be closer to a saddle point than a minimum. Then, the best solution would be to take your final structure and displace it in the direction of that mode. For more info check Removing negative frequencies.
如果你的系统存在一个较大的负频率,它可能更接近鞍点而非极小值。此时,最佳方案是将最终结构沿该模式方向进行位移。更多信息请参阅“消除负频率”。

Optimization of Hydrogen atoms#
氢原子优化

In some cases, it can be useful to only optimize the positions of the hydrogen atoms. To do so, we can add the optimizehydrogens true to the %geom block:
在某些情况下,仅优化氢原子的位置可能是有益的。为此,我们可以在 %geom 块中添加 optimizehydrogens true

!r2SCAN-3c OPT

%geom 
 optimizehydrogens true
end

*XYZFILE 0 1 structure.xyz