/*! @file

@brief Non-linear core corrections

@details

@section NLCC_INTRO About Nonlinear Core Corrections

This version of pseudo can fit pseudopotentials for DFT calculations with a nonlinear core correction.
For this purpose, a simple analytic approximation of the core charge density will be described by
few parameters that may be included as additional free parameters for the fitting procedure. The model
core charge density will be taken into account only for the exchange correlation terms. 

For the sake of simplicity and stable fits with little degrees of freedom, this version of pseudo
only supports the trivial case of one single Gaussian with a spherical contraction.


An experimental feature of BigDFT is to perform calculations with nonlinear core corrections in
case some optional input files are present. Thes files nlcc.Xy contain the coefficients for a
Gaussian representation of the valence and total charge distributions per atom, where Xy is the
label of the chemical element. The first line gives the number of Gaussians for the valence, where
the input value N refers to N(N+1)/2 Gaussians.
Then follows one line per Gaussian with five numeric values
                                                                    sigma_k c0_k c2_k c4_k c6_k
The radial density is the sum over the Gaussians 
                                                                 rho(r) = 4pi* sum( g_k(r) p_k(r) )
where each Gausian 
                                                                 g_k(r)= exp( -0.5(r/sigma_k)**2 )
is contracted with a polynomial
                                                                      p_k(r) = sum( r**j cj_k)

After the coefficients of the valence charge, the total charge is given in the very same format,
with a leading line that again gives the number of Gaussians. Only the difference of the two charge
distributions is relevant for the calculation, i.e. the core charge distribution. If the number of
Gaussians is zero for the valence, the following charge distribution thus equals the core charge.

This is the case for the simple nlcc files to be read, fitted and generated by pseudo. These are
restricted to the special case of one single Gaussian with up to four polynomial coefficients.
For better convergence during the fit, the polynomial term is scaled by the width of the Gaussian
rcore = sigma_1, which gives another convention for the coefficients
                                                                      gcore_k = c1_k*rcore**k .

These coefficients gcore are written to the resulting psppar file. The corresponding section on
line 5 of psppar is optional and serves for proofreading. The first field of this line is mandatory
and gives the number of seperable terms in HGH-K format.


The recommended strategy when doing a fit with NLCC is to first model the core charge density as
returned by the all electron program in the file ae.core.dens.plt, which also contains the valence
charge. When pseudo is invoked in presence of a file "nlcc", it will generate a simple gnuplot
script that should help to plot and fit the core charge. A simplest input guess in the file "nlcc"
could be

          0 no valence
          1 one Gaussian
          0.5 0.1 0.0 0.0 0.0 0.0
          One Gaussian of small amplitude and width 0.5

The resulting file "nlcc.gnplt" can then be used for fitting to 'ae.core.dens.plt'. One should
try to capture the core charge accurately where there is some overlap with the (pseudo-) valence.
To do so, one may pick an interesting region in the plot and enter

                                           fit rho(x)*x**2 'ae.core.dens.plt' via rcore,c0,c2
or take a wider range and use

                      fit rho(x)*x**4 'ae.core.dens.plt' u 1:($1**2*$2) via rcore,c0,c2,c4,c6

Of course, gnuplot is just an example for software that could be used for this task.
Once a reasonable representation of the core charge is found, the next step is to fit a new
pseudopotential in presence of a constant NLCC resulting from that charge. It is important to
note that the function in above gnuplot script uses gcore_k, not c1_k. Therefore, the resulting
parameters rcore and gcore must be plugged into the file "psppar" on line 5. The file "nlcc",
which uses BigDFT's convention c1_k, should be (re)moved, since both files will be read by pseudo.
Invoking pseudo with the new "psppar" results in output of a file "nlcc" with consistent data. 

When some decent accuracy has been achieved by fitting the pseudopotential, one can try to further
improve the result by enabling additional free fitting parameters, that correspond to the
coefficients of the core charge for the NLCC. These parameters are optional inputs on line 4 of 
"FITPAR". Notice the first value on this line always specifies the number of separable terms, which
is mandatory, just like on line 5 of "psppar".

*/
