Logo Search packages:      
Sourcecode: kalzium version File versions  Download package

kalziumgradienttype.cpp

/***************************************************************************
 *   Copyright (C) 2005, 2006      by Pino Toscano, toscano.pino@tiscali.it      *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program 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 General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
 ***************************************************************************/

#include "kalziumgradienttype.h"

#include "element.h"
#include "prefs.h"
#include "kalziumdataobject.h"
#include <kunitconversion/converter.h>

#include <QVariant>

#include <klocale.h>
#include <kdebug.h>

#include <math.h>

KalziumGradientTypeFactory::KalziumGradientTypeFactory()
{
    m_gradients << KalziumSOMGradientType::instance();
    m_gradients << KalziumCovalentRadiusGradientType::instance();
    m_gradients << KalziumVanDerWaalsRadiusGradientType::instance();
    m_gradients << KalziumMassGradientType::instance();
    m_gradients << KalziumBoilingPointGradientType::instance();
    m_gradients << KalziumMeltingPointGradientType::instance();
    m_gradients << KalziumElectronegativityGradientType::instance();
    m_gradients << KalziumElectronaffinityGradientType::instance();
    m_gradients << KalziumDiscoverydateGradientType::instance();
    m_gradients << KalziumIonizationGradientType::instance();
}

00048 KalziumGradientTypeFactory* KalziumGradientTypeFactory::instance()
{
    static KalziumGradientTypeFactory kttf;
    return &kttf;
}

00054 KalziumGradientType* KalziumGradientTypeFactory::build( int id ) const
{
    if ( ( id < 0 ) || ( id >= m_gradients.count() ) )
        return 0;

    return m_gradients.at( id );
}

00062 KalziumGradientType* KalziumGradientTypeFactory::build( const QByteArray& id ) const
{
    for ( int i = 0; i < m_gradients.count(); i++ )
    {
        if ( m_gradients.at( i )->name() == id )
            return m_gradients.at( i );
    }

    return 0;
}

00073 QStringList KalziumGradientTypeFactory::gradients() const
{
    QStringList l;
    for ( int i = 0; i < m_gradients.count(); i++ )
    {
        l << m_gradients.at( i )->description();
    }
    return l;
}


KalziumGradientType::KalziumGradientType()
{
}

KalziumGradientType::~KalziumGradientType()
{
}

00092 KalziumGradientType* KalziumGradientType::instance()
{
    return 0;
}

00097 double KalziumGradientType::elementCoeff( int el ) const
{
    double val = value( el );
    if ( val == -1 ) return val;

    if ( logarithmicGradient() ) {
        double minVal = minValue();
        double maxVal = maxValue();

        // Fixing negativ values for log calculation (no negativ values alowed -> NaN)
        if ( minVal < 0 ) {
            minVal = abs(minVal) + 1; // make shure it's bigger than 0
            maxVal += minVal;
            val += minVal;
            minVal = 0.01;
        };

        double result = ( log(val) - log(minVal) ) / ( log(maxVal) - log(minVal));

        // now we perform a "gamma-correction" on the result. Indeed, logarithmic gradients
        // often have the problem that all high values have roughly the same color. Note that
        // as firstColor() is not necessarily black and secondColor() is not necessarily white,
        // this is not exactly a "gamma-correction" in the usual sense.
        const double gamma = 1.4;
        result = exp(gamma * log(result));
        return result;
    } else {
        return ( val - minValue() ) / ( maxValue() - minValue() );
    }
}

00128 QColor KalziumGradientType::firstColor() const
{
    return Prefs::minColor();
}

00133 QColor KalziumGradientType::secondColor() const
{
    return Prefs::maxColor();
}

00138 QColor KalziumGradientType::notAvailableColor() const
{
    return Qt::lightGray;
}

00143 QColor KalziumGradientType::calculateColor( const double coeff ) const
{
    if ( ( coeff < 0.0 ) || ( coeff > 1.0 ) ) return notAvailableColor();

    QColor color2 = secondColor();
    QColor color1 = firstColor();

    int red = static_cast<int>( (color2.red() - color1.red()) * coeff + color1.red() );
    int green = static_cast<int>( (color2.green() - color1.green()) * coeff + color1.green() );
    int blue = static_cast<int>( (color2.blue() - color1.blue()) * coeff + color1.blue() );

    return QColor( red, green, blue );
}

00157 KalziumCovalentRadiusGradientType* KalziumCovalentRadiusGradientType::instance()
{
    static KalziumCovalentRadiusGradientType kcrgt;
    return &kcrgt;
}

KalziumCovalentRadiusGradientType::KalziumCovalentRadiusGradientType()
        : KalziumGradientType()
{
}

00168 QByteArray KalziumCovalentRadiusGradientType::name() const
{
    return "CovalentRadius";
}

00173 QString KalziumCovalentRadiusGradientType::description() const
{
    return i18n( "Covalent Radius" );
}

00178 double KalziumCovalentRadiusGradientType::value( int el ) const
{
    QVariant v = KalziumDataObject::instance()->element( el )
                 ->dataAsVariant( ChemicalDataObject::radiusCovalent, Prefs::lengthUnit() );
    if ( v.type() != QVariant::Double ) return -1;
    return v.toDouble();
}

00186 QString KalziumCovalentRadiusGradientType::unit() const
{
    return KalziumDataObject::instance()->unitAsString( Prefs::lengthUnit() );
}

00191 int KalziumCovalentRadiusGradientType::decimals() const
{
    return 2;
}

00196 double KalziumCovalentRadiusGradientType::minValue() const
{
    KUnitConversion::Value minValue( 0.32, KUnitConversion::Angstrom );
    return minValue.convertTo( Prefs::lengthUnit() ).number();
}

00202 double KalziumCovalentRadiusGradientType::maxValue() const
{
    KUnitConversion::Value minValue( 2.25, KUnitConversion::Angstrom );
    return minValue.convertTo( Prefs::lengthUnit() ).number();
}

00208 bool KalziumCovalentRadiusGradientType::logarithmicGradient() const
{
    return Prefs::logarithmicCovalentRadiusGradient();
}


00214 KalziumVanDerWaalsRadiusGradientType* KalziumVanDerWaalsRadiusGradientType::instance()
{
    static KalziumVanDerWaalsRadiusGradientType kvdwrgt;
    return &kvdwrgt;
}

KalziumVanDerWaalsRadiusGradientType::KalziumVanDerWaalsRadiusGradientType()
        : KalziumGradientType()
{
}

00225 QByteArray KalziumVanDerWaalsRadiusGradientType::name() const
{
    return "KalziumVanDerWaalsRadiusGradientType";
}

00230 QString KalziumVanDerWaalsRadiusGradientType::description() const
{
    return i18n( "van Der Waals" );
}

00235 double KalziumVanDerWaalsRadiusGradientType::value( int el ) const
{
    QVariant v = KalziumDataObject::instance()->element( el )
                 ->dataAsVariant( ChemicalDataObject::radiusVDW, Prefs::lengthUnit() );
    if ( v.type() != QVariant::Double ) return -1;
    return v.toDouble();
}

00243 QString KalziumVanDerWaalsRadiusGradientType::unit() const
{
    return KalziumDataObject::instance()->unitAsString( Prefs::lengthUnit() );
}

00248 int KalziumVanDerWaalsRadiusGradientType::decimals() const
{
    return 1;
}


00254 double KalziumVanDerWaalsRadiusGradientType::minValue() const
{
    KUnitConversion::Value minValue( 1.2, KUnitConversion::Angstrom );
    return minValue.convertTo( Prefs::lengthUnit() ).number();
}

00260 double KalziumVanDerWaalsRadiusGradientType::maxValue() const
{
    KUnitConversion::Value minValue( 3.0, KUnitConversion::Angstrom );
    return minValue.convertTo( Prefs::lengthUnit() ).number();
}

00266 bool KalziumVanDerWaalsRadiusGradientType::logarithmicGradient() const
{
    return Prefs::logarithmicVanDerWaalsRadiusGradient();
}


00272 KalziumMassGradientType* KalziumMassGradientType::instance()
{
    static KalziumMassGradientType kargt;
    return &kargt;
}

KalziumMassGradientType::KalziumMassGradientType()
        : KalziumGradientType()
{
}

00283 QByteArray KalziumMassGradientType::name() const
{
    return "AtomicMass";
}

00288 QString KalziumMassGradientType::description() const
{
    return i18n( "Atomic Mass" );
}

00293 double KalziumMassGradientType::value( int el ) const
{
    QVariant v = KalziumDataObject::instance()->element( el )->dataAsVariant( ChemicalDataObject::mass );
    if ( v.type() != QVariant::Double ) return -1;
    return v.toDouble();
}

00300 QString KalziumMassGradientType::unit() const
{
    return i18n("u");
}

00305 int KalziumMassGradientType::decimals() const
{
    return 5;
}

00310 double KalziumMassGradientType::minValue() const
{
    return 1.00794;
}

00315 double KalziumMassGradientType::maxValue() const
{
    return 294.0;
}

00320 bool KalziumMassGradientType::logarithmicGradient() const
{
    return Prefs::logarithmicMassGradient();
}

00325 KalziumBoilingPointGradientType* KalziumBoilingPointGradientType::instance()
{
    static KalziumBoilingPointGradientType kbpgt;
    return &kbpgt;
}

KalziumBoilingPointGradientType::KalziumBoilingPointGradientType()
        : KalziumGradientType()
{
}

00336 QByteArray KalziumBoilingPointGradientType::name() const
{
    return "BoilingPoint";
}

00341 QString KalziumBoilingPointGradientType::description() const
{
    return i18n( "Boiling Point" );
}

00346 double KalziumBoilingPointGradientType::value( int el ) const
{
    QVariant v = KalziumDataObject::instance()->element( el )->dataAsVariant( ChemicalDataObject::boilingpoint, Prefs::temperatureUnit() );
    if ( v.type() != QVariant::Double ) return -1;
    return v.toDouble();
}

00353 QString KalziumBoilingPointGradientType::unit() const
{
    return KalziumDataObject::instance()->unitAsString( Prefs::temperatureUnit() );
}

00358 int KalziumBoilingPointGradientType::decimals() const
{
    return 3;
}

00363 double KalziumBoilingPointGradientType::minValue() const
{
    KUnitConversion::Value minValue( 4.216, KUnitConversion::Kelvin );
    return minValue.convertTo( Prefs::temperatureUnit() ).number();
}

00369 double KalziumBoilingPointGradientType::maxValue() const
{
    KUnitConversion::Value minValue( 5870.0, KUnitConversion::Kelvin );
    return minValue.convertTo( Prefs::temperatureUnit() ).number();
}

00375 bool KalziumBoilingPointGradientType::logarithmicGradient() const
{
    return Prefs::logarithmicBoilingPointGradient();
}


00381 KalziumMeltingPointGradientType* KalziumMeltingPointGradientType::instance()
{
    static KalziumMeltingPointGradientType kmpgt;
    return &kmpgt;
}

KalziumMeltingPointGradientType::KalziumMeltingPointGradientType()
        : KalziumGradientType()
{
}

00392 QByteArray KalziumMeltingPointGradientType::name() const
{
    return "MeltingPoint";
}

00397 QString KalziumMeltingPointGradientType::description() const
{
    return i18n( "Melting Point" );
}

00402 double KalziumMeltingPointGradientType::value( int el ) const
{
    QVariant v = KalziumDataObject::instance()->element( el )->dataAsVariant( ChemicalDataObject::meltingpoint, Prefs::temperatureUnit() );
    if ( v.type() != QVariant::Double ) return -1;
    return v.toDouble();
}

00409 QString KalziumMeltingPointGradientType::unit() const
{
    return KalziumDataObject::instance()->unitAsString( Prefs::temperatureUnit() );
}

00414 int KalziumMeltingPointGradientType::decimals() const
{
    return 2;
}

00419 double KalziumMeltingPointGradientType::minValue() const
{
    KUnitConversion::Value minValue( 0.94, KUnitConversion::Kelvin );
    return minValue.convertTo( Prefs::temperatureUnit() ).number();
}

00425 double KalziumMeltingPointGradientType::maxValue() const
{
    KUnitConversion::Value minValue( 3825.0, KUnitConversion::Kelvin );
    return minValue.convertTo( Prefs::temperatureUnit() ).number();
}

00431 bool KalziumMeltingPointGradientType::logarithmicGradient() const
{
    return Prefs::logarithmicMeltingPointGradient();
}

00436 KalziumSOMGradientType* KalziumSOMGradientType::instance()
{
    static KalziumSOMGradientType kargt;
    return &kargt;
}

KalziumSOMGradientType::KalziumSOMGradientType()
        : KalziumGradientType()
{
}

00447 QByteArray KalziumSOMGradientType::name() const
{
    return "SOM";
}

00452 QString KalziumSOMGradientType::description() const
{
    return i18n( "State of matter" );
}

00457 double KalziumSOMGradientType::value( int el ) const
{
    Q_UNUSED(el);
    return -1000;
}

00463 QString KalziumSOMGradientType::unit() const
{
    return KalziumDataObject::instance()->unitAsString( Prefs::temperatureUnit() );;
}

00468 int KalziumSOMGradientType::decimals() const
{
    return 2;
}

00473 double KalziumSOMGradientType::minValue() const
{
    KUnitConversion::Value minValue( 0.94, KUnitConversion::Kelvin );
    return minValue.convertTo( Prefs::temperatureUnit() ).number();
}

00479 double KalziumSOMGradientType::maxValue() const
{
    KUnitConversion::Value minValue( 5870.0, KUnitConversion::Kelvin );
    return minValue.convertTo( Prefs::temperatureUnit() ).number();
}

00485 bool KalziumSOMGradientType::logarithmicGradient() const
{
    return true;
//     return Prefs::logarithmicSOMGradient();
}


00492 KalziumElectronegativityGradientType* KalziumElectronegativityGradientType::instance()
{
    static KalziumElectronegativityGradientType kegt;
    return &kegt;
}

KalziumElectronegativityGradientType::KalziumElectronegativityGradientType()
        : KalziumGradientType()
{
}

00503 QByteArray KalziumElectronegativityGradientType::name() const
{
    return "Electronegativity";
}

00508 QString KalziumElectronegativityGradientType::description() const
{
    return i18n( "Electronegativity (Pauling)" );
}

00513 double KalziumElectronegativityGradientType::value( int el ) const
{
    QVariant v = KalziumDataObject::instance()->element( el )->dataAsVariant( ChemicalDataObject::electronegativityPauling );
    if ( v.type() != QVariant::Double ) return -1;
    return v.toDouble();
}

00520 QString KalziumElectronegativityGradientType::unit() const
{
    return QString();
}

00525 int KalziumElectronaffinityGradientType::decimals() const
{
    return 2;
}

00530 double KalziumElectronegativityGradientType::minValue() const
{
    return 0.7;
}

00535 double KalziumElectronegativityGradientType::maxValue() const
{
    return 3.98;
}

00540 bool KalziumElectronegativityGradientType::logarithmicGradient() const
{
    return Prefs::logarithmicElectronegativityGradient();
}

///DISCOVERYDATE///

00547 KalziumDiscoverydateGradientType* KalziumDiscoverydateGradientType::instance()
{
    static KalziumDiscoverydateGradientType kegt;
    return &kegt;
}

KalziumDiscoverydateGradientType::KalziumDiscoverydateGradientType()
        : KalziumGradientType()
{
}

00558 QByteArray KalziumDiscoverydateGradientType::name() const
{
    return "Discoverydate";
}

00563 QString KalziumDiscoverydateGradientType::description() const
{
    return i18n( "Discovery date" );
}

00568 double KalziumDiscoverydateGradientType::value( int el ) const
{
    QVariant v = KalziumDataObject::instance()->element( el )->dataAsVariant( ChemicalDataObject::date );
    if ( v.value<int>() == 0 ) return -1;
    return v.toDouble();
}

00575 QString KalziumDiscoverydateGradientType::unit() const
{
    return QString();
}

00580 int KalziumDiscoverydateGradientType::decimals() const
{
    return 0;
}


00586 double KalziumDiscoverydateGradientType::minValue() const
{
    return 1669.0;
}

00591 double KalziumDiscoverydateGradientType::maxValue() const
{
    return QDate::currentDate().year();
}

00596 bool KalziumDiscoverydateGradientType::logarithmicGradient() const
{
    return Prefs::logarithmicDiscoverydateGradient();
}


///ELECTRONAFFINITY///

00604 KalziumElectronaffinityGradientType* KalziumElectronaffinityGradientType::instance()
{
    static KalziumElectronaffinityGradientType kegt;
    return &kegt;
}

KalziumElectronaffinityGradientType::KalziumElectronaffinityGradientType()
        : KalziumGradientType()
{
}

00615 QByteArray KalziumElectronaffinityGradientType::name() const
{
    return "Electronaffinity";
}

00620 QString KalziumElectronaffinityGradientType::description() const
{
    return i18n( "Electronaffinity" );
}

00625 double KalziumElectronaffinityGradientType::value( int el ) const
{
    QVariant v = KalziumDataObject::instance()->element( el )->dataAsVariant( ChemicalDataObject::electronAffinity, Prefs::energiesUnit() );
    return v.toDouble();
}

00631 QString KalziumElectronaffinityGradientType::unit() const
{
    return KalziumDataObject::instance()->unitAsString( Prefs::energiesUnit() );
}

00636 int KalziumElectronegativityGradientType::decimals() const
{
    return 2;
}

00641 double KalziumElectronaffinityGradientType::minValue() const
{
    KUnitConversion::Value minValue( -0.07, KUnitConversion::Electronvolt );
    return minValue.convertTo( Prefs::energiesUnit() ).number();
}

00647 double KalziumElectronaffinityGradientType::maxValue() const
{
    KUnitConversion::Value minValue( 3.7, KUnitConversion::Electronvolt );
    return minValue.convertTo( Prefs::energiesUnit() ).number();
}

00653 bool KalziumElectronaffinityGradientType::logarithmicGradient() const
{
    return Prefs::logarithmicElectronaffinityGradient();
}

///FIRST IONIZATINO///

00660 KalziumIonizationGradientType* KalziumIonizationGradientType::instance()
{
    static KalziumIonizationGradientType kegt;
    return &kegt;
}

KalziumIonizationGradientType::KalziumIonizationGradientType()
        : KalziumGradientType()
{
}

00671 QByteArray KalziumIonizationGradientType::name() const
{
    return "Ionization";
}

00676 QString KalziumIonizationGradientType::description() const
{
    return i18n( "First Ionization" );
}

00681 double KalziumIonizationGradientType::value( int el ) const
{
    QVariant v = KalziumDataObject::instance()->element( el )->dataAsVariant( ChemicalDataObject::ionization, Prefs::energiesUnit() );
    return v.toDouble();
}

00687 QString KalziumIonizationGradientType::unit() const
{
    return KalziumDataObject::instance()->unitAsString( Prefs::energiesUnit() );
}

00692 int KalziumIonizationGradientType::decimals() const
{
    return 2;
}

00697 double KalziumIonizationGradientType::minValue() const
{
    KUnitConversion::Value minValue( 3.89, KUnitConversion::Electronvolt );
    return minValue.convertTo( Prefs::energiesUnit() ).number();
}

00703 double KalziumIonizationGradientType::maxValue() const
{
    KUnitConversion::Value minValue( 25.0, KUnitConversion::Electronvolt );
    return minValue.convertTo( Prefs::energiesUnit() ).number();
}

00709 bool KalziumIonizationGradientType::logarithmicGradient() const
{
    return Prefs::logarithmicIonizationGradient();
}

Generated by  Doxygen 1.6.0   Back to index