libXpertMass Developer Documentation
  • libXpertMass
  • Ionizable
  • Ionizable Class

    class MsXpS::libXpertMass::Ionizable

    The Ionizable class provides abstractions to work with entities that have masses (base class Ponderable) and that can be ionized. More...

    Header: #include <Ionizable.hpp>
    Inherits: MsXpS::libXpertMass::PolChemDefEntity and MsXpS::libXpertMass::Ponderable
    Inherited By:

    MsXpS::libXpertMass::Oligomer and MsXpS::libXpertMass::Polymer

    Public Functions

    Ionizable(PolChemDefCstSPtr pol_chem_def_csp, const QString &name = QString("NOT_SET"), const Ponderable &ponderable = Ponderable(), const IonizeRule &ionize_rule = IonizeRule(), bool is_ionized = false)
    Ionizable(const Ionizable &other)
    virtual ~Ionizable()
    virtual int charge() const
    virtual int deionize()
    virtual int ionize()
    virtual int ionize(const IonizeRule &ionize_rule)
    const IonizeRule &ionizeRule() const
    IonizeRule *ionizeRule()
    bool isIonized() const
    virtual double molecularMass(MassType mass_type)
    int setCharge(int charge)
    QString toString()
    virtual bool validate()
    virtual bool operator!=(const Ionizable &other) const
    virtual Ionizable &operator=(const Ionizable &other)
    virtual bool operator==(const Ionizable &other) const

    Reimplemented Public Functions

    virtual bool calculateMasses() override

    Static Public Members

    int ionize(Ionizable *ionizable, const IonizeRule &ionize_rule)

    Protected Variables

    IonizeRule m_ionizeRule
    bool m_isIonized

    Detailed Description

    An Ionizable is a Ponderable that might undergo ionization, using either its own member IonizeRule or an IonizeRule passed as argument to one of its functions. An Ionizable is also a PolChemDefEntity, as it has to know at each instant what polymer chemistry definition it is based upon. The ionization status of the Ionizable can be checked at each moment and a call to an ionizing function will first trigger deionization if the Ionizable is already ionized. The main members of the Ionizable class are the following:

    Upon creation of an Ionizable (without use of the copy constructor), all the data required for the full qualification of the new instance should be passed to the constructor. Default parameters ensure that the Ionizable is set to a consistent status (that is its IonizeRule member is invalid and that its m_isIonized flag is false).

    The caller is responsible for seeding correct and consistent values into the constructor for proper operation of the class instances.

    For the ionization to be actually performed, and the masses to be effectively updated to account for that ionization, the Ionizable instance must be ionize()d.

    It is possible to deionize() an Ionizable instance as it is possible to reionize the instance with another IonizeRule, which will replace the member IonizeRule if the reionization succeeds. The deionize() call effects the state of the Ionizable instance only if the m_isIonized boolean is true.

    Member Function Documentation

    Ionizable::Ionizable(PolChemDefCstSPtr pol_chem_def_csp, const QString &name = QString("NOT_SET"), const Ponderable &ponderable = Ponderable(), const IonizeRule &ionize_rule = IonizeRule(), bool is_ionized = false)

    Constructs an Ionizable.

    The Ionizable instance will be an ionized entity if is_ionized is true. The ponderable's mono and avg masses must thus be masses which take (is_ionized is true) or do not take (is_ionized is false) into account the data located in ionize_rule. If is_ionized is true, the ionize_rule is validated and the level of the ionization must not be 0. If one of these two tests fails, this is an error and the program aborts.

    pol_chem_def_csp Polymer chemistry definition (cannot be nullptr);

    name Name of this Ionizable (defaults to "NOT_SET");

    ponderable Ponderable (mono and avg masses);

    ionize_rule IonizeRule (defaults to IonizeRule(), that is, an invalid IonizeRule).

    is_ionized Tells if the Ionizable to be constructed should be considered as an ionized chemical entity.

    Ionizable::Ionizable(const Ionizable &other)

    Constructs an Ionizable as a copy of other.

    No assumption should be made as to the status of the created Ionizable. The caller should characterize the ionization status of the Ionizable with isIonized().

    [virtual noexcept] Ionizable::~Ionizable()

    Destructs this Ionizable.

    [override virtual] bool Ionizable::calculateMasses()

    Calculates the masses of this Ionizable.

    If this Ionizable is ionized, the masses of the Ponderable base class are let unchanged. If this Ionizable is not ionized and the IonizeRule is valid, perform the ionization, which calculates the masses.

    This function returns false if the member IonizeRule is not valid or if the ionization failed, true otherwise.

    See also ionize().

    [virtual] int Ionizable::charge() const

    Returns the ionization charge of this Ionizable.

    The charge is returned as a positive number (0 allowed) or as -1 if the IonizeRule is not valid or if m_isIonized is false.

    Note: The charge is returned as the compound product of the IonizeRule's m_charge and m_level members.

    See also setCharge().

    [virtual] int Ionizable::deionize()

    Deionizes this Ionizable.

    This Ionizable is deionized using its member m_ionizeRule. The following logic is applied:

    1. If this Ionizable is not ionized, this function returns 0.
    2. If the member ionizeRule is not valid, this function returns -1 because it does not make sense to try to change the ionization of an Ionizable if its member IonizeRule is not valid.
    3. The deionization process is carried out. If the process is successful, 1 is returned, otherwise -1 is returned.

    [virtual] int Ionizable::ionize()

    Ionizes this Ionizable.

    Ionization is performed on this Ionizable using the member IonizeRule.

    The following logic is applied:

    1. If the member ionizeRule is not valid, this function returns -1 because it does not make sense to try to change the charge of an Ionizable if its member IonizeRule is not valid.
    2. If this Ionizable is ionized, return 0 (already ionized, then nothing to do).
    3. The mass status of this Ionizable (Ponderable base class) is stored for later comparison.
    4. The ionization process is carried out and the new mass status is compared to the older one. If the new status differs from the previous one, than 1 is returned, otherwise -1 is returned.

    [virtual] int Ionizable::ionize(const IonizeRule &ionize_rule)

    Ionizes this Ionizable using ionize_rule.

    The following logic is applied:

    1. If ionize_rule is not valid, this function returns -1 because it does not make sense to try to change the charge of an Ionizable if that ionization rule is not valid.
    2. If this Ionizable is ionized, first deionize() it. If this step fails, returns -1.
    3. The ionization process is carried out. If the process is successful, 1 is returned, otherwise -1 is returned.

    See also ionize().

    [static] int Ionizable::ionize(Ionizable *ionizable, const IonizeRule &ionize_rule)

    Ionizes the ionizable using ionize_rule.

    The following logic is applied:

    1. If ionize_rule is not valid, this function returns -1 because it does not make sense to try to change the charge of an Ionizable if that ionization rule is not valid.
    2. If ionizable is ionized, first deionize() it. If this step fails, returns -1.
    3. The ionization process is carried out. If the process is successful, 1 is returned, otherwise -1 is returned.

    See also ionize().

    const IonizeRule &Ionizable::ionizeRule() const

    Returns a constant reference to this IonizeRule.

    IonizeRule *Ionizable::ionizeRule()

    Returns a pointer to this IonizeRule.

    bool Ionizable::isIonized() const

    Returns true if this Ionizable is ionized, false otherwise.

    The ionization status is returned on the basis of the m_isIonized member boolean value.

    [virtual] double Ionizable::molecularMass(MassType mass_type)

    Returns the molecular mass (either monoisotopic or average, depending on mass_type)

    A copy of this Ionizable is first made, then it is deionized and its mass is returned.

    int Ionizable::setCharge(int charge)

    Sets the charge of this Ionizable to charge.

    The charge of an ionizable is the compound product of m_charge and m_level in its IonizeRule member. The value passed as charge is that compound product. Thus, the member IonizeRule is updated to reflect the new charge using the following code:

    int level = charge / m_ionizeRule.charge();
    m_ionizeRule.setLevel(level);

    Only the level value of IonizeRule is changed to reflect the change of the charge because the chemistry of the ionization rule itself must not be changed.

    The following logic is applied:

    1. If the member ionizeRule is not valid, this function returns -1 because it does not make sense to try to change the charge of an Ionizable if its member IonizeRule is not valid.
    2. This Ionizable is first deionized if it is ionized. If the deionization fails -1 is returned.
    3. This Ionizable is ionized with the level value in its member IonizeRule. If that ionization fails, -1 is returned.

    At this point all the process went fine and 1 is returned.

    See also charge().

    QString Ionizable::toString()

    Returns a string describing this Ionizable.

    [virtual] bool Ionizable::validate()

    Validates this Ionizable.

    The member IonizeRule needs to validate successfully.

    Returns true if the validation is successfull, false otherwise.

    [virtual] bool Ionizable::operator!=(const Ionizable &other) const

    Returns true if this Ionizable is different than other, false otherwise.

    [virtual] Ionizable &Ionizable::operator=(const Ionizable &other)

    Assigns other to this Ionizable.

    Return A reference to this Ionizable instance.

    [virtual] bool Ionizable::operator==(const Ionizable &other) const

    Returns true if this Ionizable is identical to other, false otherwise.

    Member Variable Documentation

    IonizeRule Ionizable::m_ionizeRule

    This variable holds the ionization rule that defines the way to ionize this Ionizable.

    See also IonizeRule.

    bool Ionizable::m_isIonized

    Tells if this Ionizable has undergone an ionization.