// This file is part of GQCG-GQCP.
//
// Copyright (C) 2017-2020  the GQCG developers
//
// GQCG-GQCP is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GQCG-GQCP is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with GQCG-GQCP.  If not, see <http://www.gnu.org/licenses/>.

#include "QCModel/HF/StabilityMatrices/GHFStabilityMatrices.hpp"
#include "Utilities/complex.hpp"
#include "gqcpy/include/interfaces.hpp"

#include <pybind11/eigen.h>
#include <pybind11/pybind11.h>


namespace gqcpy {


// Provide some shortcuts for frequent namespaces.
namespace py = pybind11;
using namespace GQCP;


/**
 *  Add Python bindings for some APIs related to `GHF Stability matrices`.
 *
 *  @tparam Class               The type of the Pybind11 `class_` (generated by the compiler).
 *
 *  @param py_class             The Pybind11 `class_` that should obtain APIs related to `GHFStabilityMatrices`.
 */
template <typename Class>
void bindQCModelGHFStabilityInterface(Class& py_class) {

    // The C++ type corresponding to the Python class.
    using Type = typename Class::type;
    using Scalar = typename Type::Scalar;

    py_class
        .def(
            "subMatrixA",
            &Type::subMatrixA,
            "Return the stability submatrix A.")

        .def(
            "subMatrixB",
            &Type::subMatrixB,
            "Return the stability submatrix B.")

        .def(
            "instabilityRotationMatrix",
            [](const Type& stability_matrices, const size_t occupied_orbitals, const size_t virtual_orbitals, const double& scaling_factor) {
                return stability_matrices.instabilityRotationMatrix(occupied_orbitals, virtual_orbitals, scaling_factor);
            },
            py::arg("N_occupied"),
            py::arg("N_virtual"),
            py::arg("scaling_factor") = 1.0,
            "Return the transformation corresponding to the lowest-lying eigenvector of the internal instability Hessian.");
}


void bindGHFStabilityMatrices(py::module& module) {

    // Define Python classes related to `real GHFStabilityMatrices` and expose their interfaces.
    py::class_<GHFStabilityMatrices<double>> py_GHFStabilityMatrices_d {module, "GHFStabilityMatrices_d", "The real generalized Hartree-Fock stability matrices."};

    // Expose the `HartreeFockRealStability` interface.
    bindQCModelHartreeFockRealStabilityInterface(py_GHFStabilityMatrices_d);

    // Expose the `GHFStability` interface.
    bindQCModelGHFStabilityInterface(py_GHFStabilityMatrices_d);

    // Define Python classes related to `complex GHFStabilityMatrices` and expose their interfaces.
    py::class_<GHFStabilityMatrices<complex>> py_GHFStabilityMatrices_cd {module, "GHFStabilityMatrices_cd", "The complex generalized Hartree-Fock stability matrices."};

    // Expose the `HartreeFockComplexStability` interface.
    bindQCModelHartreeFockComplexStabilityInterface(py_GHFStabilityMatrices_cd);

    // Expose the `GHFStability` interface.
    bindQCModelGHFStabilityInterface(py_GHFStabilityMatrices_cd);
}


}  // namespace gqcpy
