In the previous section, we introduced a constraint DFT method to control the spin direction. The constraint DFT method enables us to evaluate a magnetic anisotropy energy (MAE) for magnetic systems in a selfconsistet manner based on the total energy. However, the computation tends to become very costly, and the calculation tends to be trapped to a local minima due to the degree of freedom of the occupation to degenerate localized states such as orbitals. A way to bypass these problems is to use a second variational method that a oneshot diagonalization within the noncolliear DFT is performed with spinorbit coupling (SOI) and the charge density calculated by the collinear DFT as initial guess after getting the SCF charge density within the collinear DFT. Since the variational scheme is based on the Harris functional [14], the perturbation by the spin rotation and the SOI is taken into account only in the band energy. The double counting term does not depend on the spin rotation, while it looks changed in the output of OpenMX, since the energy terms are calculated by the output density rather than the input density (please don't be confused by the output). Using the second variational method, we first calculate a ferromagnetic state within the collinear DFT, resulting in the SCF charge density. Then, the oneshot diagonalization for the Hamiltonian including SOI is performed within the noncolliear DFT using the restart file storing the SCF charge density. The restart file can be read by the following keywords:
scf.restart.filename FePt scf.restart c2nUsing the keyword 'scf.restart.filename', the restart file to be read is specified. By 'c2n' for the keyword 'scf.restart' one can port a restart file generated by a collinear DFT calculation to a noncollinear DFT calculation. As an example, the restart file above is generated by an input file 'FePt.dat' available in the directory 'work'. In the second calculation, the spin direction can be specified by the following keywords:
scf.Restart.Spin.Angle.Theta 90.0 scf.Restart.Spin.Angle.Phi 0.0The spin direction at all the spatial points is aligned along the direction determined by the two keywords which specify Euler angles. Therefore, it should be noted that the evaluation of the MAE by the second variational method is valid only for ferromagnetic systems. Let us demonstrate how the second variational method works to evaluate the MAE. Figure 36 shows the MAE curves for the spin rotational angle in the L1 FePt bulk. The result of 'Full SCF' was obtained by the constraint DFT method as explained in the section 38. The input file 'FePtNCSCF.dat' is available in the directory 'work'. At each spin rotational angle, the fully selfconsistent calculation was performed including the SOI within the noncollinear DFT, where the electronic temperature is 300 K and the kgrid is . The MAE of 2.78 meV/f.u. was obtained by 'Full SCF'. Two computational results by the second variational method are also shown in the Fig. 36. Using the restart file generated by the collinear calculation with the input file 'FePt.dat' in the directory 'work', we diagonalized once using an input file 'FePtNC.dat' available in the directory 'work'.

The second variational scheme might be useful for not only the evaluation of MAE, but also calculations of band structure of largescale systems, which may hamper direct SCF calculations by the noncollinear DFT method, to investigate how the SOI modifies the band structure.