/*
 * Copyright (c) 2026 University of Insubria <https://www.uninsubria.it>
 *
 * This library 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 2.1 of the License, or (at
 * your option) any later version. All we ask is that proper credit is given
 * for our work, which includes - but is not limited to - adding the above
 * copyright notice to the beginning of your source code files, and to any
 * copyright notice that you may distribute with programs based on this work.
 *
 * This library 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 this program; if not, write to the Free Software Foundation, Inc.
 * <https://fsf.org/>
 */

package qsardes.descriptor.qsarwb;

import java.util.Arrays;
import qsardes.util.UtilsCalc;
import java.util.List;
import org.openscience.cdk.interfaces.IAtomContainer;
import qsardes.descriptor.DescriptorBaryszMatrix;

/**
 * Barysz matrix descriptors (QSAR-WB Descriptors).
 * <BR><BR>
 * Calculates Barysz matrix descriptors.
 * <BR><BR>
 * Returns
 * <BR><BR>
 * SpAbs_Dz# - Graph energy.
 * <BR>
 * SpMax_Dz# - Leading eigenvalue.
 * <BR>
 * SpDiam_Dz# - Spectral diameter.
 * <BR>
 * SpAD_Dz# - Spectral absolute deviation.
 * <BR>
 * SpMAD_Dz# - Spectral mean absolute deviation.
 * <BR>
 * EE_Dz# - Estrada-like index.
 * <BR>
 * SM1_Dz# - Order 1 spectral moment.
 * <BR>
 * VE1_Dz# - Coefficient sum of the last eigenvector.
 * <BR>
 * VE2_Dz# - Average coefficient sum of the last eigenvector.
 * <BR>
 * VE3_Dz# - Logarithmic coefficient sum of the last eigenvector.
 * <BR>
 * VR1_Dz# - Randic-like eigenvector-based index.
 * <BR>
 * VR2_Dz# - Normalized Randic-like eigenvector-based index.
 * <BR>
 * VR3_Dz# - Logarithmic Randic-like eigenvector-based index.
 * <BR><BR>
 * # is the weight defined as Z = atomic number, m = atomic mass,
 * v = van der Waals atomic volume, e = Sanderson atomic electronegativity,
 * p = atomic polarizability, i = atomic first ionization potential,
 * s = atomic instrinsic state (hydrogens included),
 * pe = Pauling electronegativity, are = Allred-Rocow electronegativity.
 *
 * @author Nicola Chirico
 */
public final class QsarWBBaryszMatrix extends DescriptorBaryszMatrix
{
    public QsarWBBaryszMatrix()
    {
    }

    @Override
    protected List<String> get_weights_list()
    {
        return Arrays.asList("DzZ", "Dzm", "Dzv", "Dze", "Dzp", "Dzi",
                "Dzs", "Dzpe", "Dzare");
    }

    @Override
    protected double calculate_sp_ve1_sum(UtilsCalc utils_calc,
            double[][] eig_vec_array)
    {
        return utils_calc.calc_col_abs_sum(eig_vec_array,
                eig_vec_array[0].length - 1);
    }

    @Override
    protected double calculate_sp_vr1_sum(IAtomContainer iac,
            UtilsCalc utils_calc, double[][] eig_vec_array)
    {
    	return utils_calc.calc_vr1_sum(iac, eig_vec_array,
    	        eig_vec_array[0].length - 1);
    }

    @Override
    protected double get_sp_ve1_sum(double sp_ve1_sum)
    {
        return sp_ve1_sum;
    }

    @Override
    protected double get_ve3(double sp_ve1_sum, int atom_count)
    {
        try {
            return StrictMath.log(((double) atom_count / 10.0) * sp_ve1_sum);
        } catch (Exception ex) {
            return Double.NaN;
        }
    }

    @Override
    protected double get_vr3(double vr1_sum, int atom_count)
    {
        try {
            return StrictMath.log(((double) atom_count / 10.0) * vr1_sum);
        } catch (Exception ex) {
            return Double.NaN;
        }
    }
}
