/*
 * 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 qsardes.util.UtilsCalc;
import org.openscience.cdk.interfaces.IAtomContainer;
import qsardes.descriptor.DescriptorTopologicalDistance;

/**
 * Topological distance matrix descriptor (QSAR-WB Descriptors).
 * <BR><BR>
 * Calculates topological distance matrix descriptors.
 * <BR><BR>
 * Returns
 * <BR><BR>
 * SpMax_D - Leading eigenvalue.
 * <BR>
 * SpDiam_D - Spectral diameter.
 * <BR>
 * SpAD_D - Spectral absolute deviation.
 * <BR>
 * SpMAD_D - Spectral mean absolute deviation.
 * <BR>
 * EE_D - Estrada-like index.
 * <BR>
 * VE1_D - Coefficient sum of the last eigenvector.
 * <BR>
 * VE2_D - Average coefficient sum of the last eigenvector.
 * <BR>
 * VE3_D - Logarithmic coefficient sum of the last eigenvector.
 * <BR>
 * VR1_D - Randic-like eigenvector-based index.
 * <BR>
 * VR2_D - Normalized Randic-like eigenvector-based index.
 * <BR>
 * VR3_D - Logarithmic Randic-like eigenvector-based index.
 *
 * @author Nicola Chirico
 */
public final class QsarWBTopologicalDistance
        extends DescriptorTopologicalDistance
{
    public QsarWBTopologicalDistance()
    {
    }

    @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;
        }
    }
}
