| <large>libXpertMassCore and libXpertMassGui Developer Documentation</large>

- libXpertMassCore
- CrossLinker

# MsXpS::libXpertMassCore::CrossLinker Class

class MsXpS::libXpertMassCore::CrossLinker

The CrossLinker class provides abstractions to define the chemical basis of a cross-linking reaction. More...

Header: | `#include <MsXpS/libXpertMassCore/CrossLinker.hpp>`

- List of all members, including inherited members
- CrossLinker is part of Aqueous chemical reactions.

## Public Functions

| CrossLinker(MsXpS::libXpertMassCore::PolChemDefCstSPtr pol_chem_def_csp)
| CrossLinker(MsXpS::libXpertMassCore::PolChemDefCstSPtr pol_chem_def_csp, const QDomElement &element, int version = 1)
| CrossLinker(MsXpS::libXpertMassCore::PolChemDefCstSPtr pol_chem_def_csp = nullptr, const QString &name = QString(), const QString &formula = QString(), double mono = 0.0, double avg = 0.0)
| CrossLinker(const MsXpS::libXpertMassCore::CrossLinker &other)
virtual | ~CrossLinker()
const MsXpS::libXpertMassCore::CrossLinker & | accountMasses(double &mono, double &avg, int times = 1) const
const MsXpS::libXpertMassCore::CrossLinker & | accountMasses(double *mono_p = nullptr, double *avg_p = nullptr, int times = 1) const
bool | appendModif(MsXpS::libXpertMassCore::ModifCstSPtr modif_csp)
bool | calculateMasses(const MsXpS::libXpertMassCore::IsotopicDataCstSPtr &isotopic_data_csp)
bool | calculateMasses(const MsXpS::libXpertMassCore::IsotopicDataCstSPtr &isotopic_data_csp, double &mono, double &avg) const
QString | formatXmlClkElement(int offset, const QString &indent = Utils::xmlIndentationToken) const
const MsXpS::libXpertMassCore::CrossLinkerCstSPtr | getFromPolChemDefByName() const
double | getMass(MsXpS::libXpertMassCore::Enums::MassType mass_type) const
MsXpS::libXpertMassCore::ModifCstSPtr | getModifAt(std::size_t index) const
const std::vector<MsXpS::libXpertMassCore::ModifCstSPtr> & | getModifsCstRef() const
std::vector<MsXpS::libXpertMassCore::ModifCstSPtr> & | getModifsRef()
QString | getName() const
const MsXpS::libXpertMassCore::PolChemDefCstSPtr & | getPolChemDefCstSPtr() const
bool | hasModif(const QString &modif_name)
bool | initialize(const QDomElement &element, int version = 1)
bool | insertModifAt(MsXpS::libXpertMassCore::ModifCstSPtr modif_csp, std::size_t index)
MsXpS::libXpertMassCore::Enums::PolChemDefEntityStatus | isKnownByNameInPolChemDef() const
bool | isValid() const
int | modifIndex(const QString &modif_name)
bool | removeModifAt(std::size_t index)
bool | renderXmlClkElement(const QDomElement &element, int version)
void | setFormula(const QString &formula_string)
void | setName(const QString &name)
void | setPolChemDefCstSPtr(MsXpS::libXpertMassCore::PolChemDefCstSPtr pol_chem_def_csp)
QString | toString() const
bool | validate(MsXpS::libXpertMassCore::ErrorList *error_list_p) const
bool | operator!=(const MsXpS::libXpertMassCore::CrossLinker &other) const
MsXpS::libXpertMassCore::CrossLinker & | operator=(const MsXpS::libXpertMassCore::CrossLinker &other)
bool | operator==(const MsXpS::libXpertMassCore::CrossLinker &other) const

## Protected Variables

double | m_avg
QString | m_formula
bool | m_isValid
std::vector<MsXpS::libXpertMassCore::ModifCstSPtr> | m_modifs
double | m_mono
QString | m_name
MsXpS::libXpertMassCore::PolChemDefCstSPtr | mcsp_polChemDef

## Detailed Description

The notion of a cross-linker is that it is the description of the chemical reaction that is carried out by Monomers in a Polymer or in an Oligomer sequence to form a CrossLink.

There are two different kinds of chemical entities potentially involved in the description of a CrossLinker:

Modif instances that are applied to Monomer instances. the formula that completes the chemical reactions described by the Modif instances.

## Member Function Documentation

### CrossLinker::CrossLinker(MsXpS::libXpertMassCore::PolChemDefCstSPtr pol_chem_def_csp)

Constructs a CrossLinker instance with the pol_chem_def_csp PolChemDef.

### CrossLinker::CrossLinker(MsXpS::libXpertMassCore::PolChemDefCstSPtr pol_chem_def_csp, const QDomElement &element, int version = 1)

Constructs a CrossLinker instance starting from an XML <clk> element and a pol_chem_def_csp PolChemDef. The version indicates what version of the XML element is to be used.

This is the current format:

    <clk>
      <name>CFP-chromophore</name>
      <formula></formula>
      <modifname>Chromo-O</modifname>
      <modifname>Chromo-H3</modifname>
      <modifname>Chromo-H</modifname>
    </clk>

The rendering of the Modif instances requires that the PolChemDef be available. If this is not the case, the rendering of the CrossLinker is stopped at the first <modifname> element and false is returned.

See also renderXmlClkElement().

### CrossLinker::CrossLinker(MsXpS::libXpertMassCore::PolChemDefCstSPtr pol_chem_def_csp = nullptr, const QString &name = QString(), const QString &formula = QString(), double mono = 0.0, double avg = 0.0)

Constructs a CrossLinker instance.

- pol_chem_def_csp: the polymer chemistry definition (PolChemDef).
- name: the name of this CrossLinker.
- formula: the Formula that potentially complements the description of the reaction that is the basis of this CrossLinker (used to initialize the Formula base class).

### CrossLinker::CrossLinker(const MsXpS::libXpertMassCore::CrossLinker &other)

Constructs a CrossLinker instance as a copy of other.

### `[virtual noexcept]` CrossLinker::~CrossLinker()

Destructs this CrossLinker instance

### const MsXpS::libXpertMassCore::CrossLinker &CrossLinker::accountMasses(double &mono, double &avg, int times = 1) const

Increases mono and avg by the corresponding member masses first compounded by times.

Returns this CrossLinker.

### const MsXpS::libXpertMassCore::CrossLinker &CrossLinker::accountMasses(double *mono_p = nullptr, double *avg_p = nullptr, int times = 1) const

Increases mono_p and avg_p by the corresponding member masses first compounded by times.

Returns this CrossLinker.

### bool CrossLinker::appendModif(MsXpS::libXpertMassCore::ModifCstSPtr modif_csp)

Adds modif_csp to this CrossLinker instance.

Returns true.

### bool CrossLinker::calculateMasses(const MsXpS::libXpertMassCore::IsotopicDataCstSPtr &isotopic_data_csp)

Returns true if the mass calculations for this CrossLinker instance are performed without error, false otherwise.

The calculation involved accounting masses for the Modifs (if any) and for the Formula (if non-empty). The member masses (m_mono and m_avg) are updated.

The reference data for the computations are accessed at isotopic_data_csp.

### bool CrossLinker::calculateMasses(const MsXpS::libXpertMassCore::IsotopicDataCstSPtr &isotopic_data_csp, double &mono, double &avg) const

Returns true if the mass calculations for this CrossLinker instance are performed without error, false otherwise.

The calculation involved accounting masses for the Modifs (if any) and for the Formula (if non-empty). The masses calculated are set to mono and avg.

The calculations are performed using reference data in isotopic_data_csp.

### QString CrossLinker::formatXmlClkElement(int offset, const QString &indent = Utils::xmlIndentationToken) const

Formats this CrossLinker instance in a heap-allocated string to be used as an XML element in the polymer chemistry definition.

The formatting of the XML element takes into account offset and indent by prepending the string with offset * indent character substring.

indent defaults to two spaces.

Returns a dynamically allocated string that needs to be freed after use.

### const MsXpS::libXpertMassCore::CrossLinkerCstSPtr CrossLinker::getFromPolChemDefByName() const

Returns the CrossLinker instance from the polymer chemistry definition registered in this instance.

The key to search the CrossLinker is this instance's member name.

If there is no PolChemDef available, nullptr is returned.

If no CrossLinker instance is found by this instance's name, nullptr is returned.

### double CrossLinker::getMass(MsXpS::libXpertMassCore::Enums::MassType mass_type) const

Returns the mass of the type defined by mass_type.

### MsXpS::libXpertMassCore::ModifCstSPtr CrossLinker::getModifAt(std::size_t index) const

Returns the Modif instance at index.

index cannot be out-of-bounds.

### const std::vector<MsXpS::libXpertMassCore::ModifCstSPtr> &CrossLinker::getModifsCstRef() const

Returns a constant reference to the container of Modif instances.

### std::vector<MsXpS::libXpertMassCore::ModifCstSPtr> &CrossLinker::getModifsRef()

Returns a reference to the container of Modif instances.

### QString CrossLinker::getName() const

Returns the name.

### const MsXpS::libXpertMassCore::PolChemDefCstSPtr &CrossLinker::getPolChemDefCstSPtr() const

Returns the PolChemDef.

### bool CrossLinker::hasModif(const QString &modif_name)

Returns an iterator to the found Modif instance by modif_name in the container.

### bool CrossLinker::initialize(const QDomElement &element, int version = 1)

Initializes this CrossLinker instance using element, according to version.

Returns true if the rendering of element was successful, false otherwise.

See also renderXmlClkElement().

### bool CrossLinker::insertModifAt(MsXpS::libXpertMassCore::ModifCstSPtr modif_csp, std::size_t index)

Sets the Modif at index index to modif_csp.

index cannot be out-of-bounds (fatal error).

Returns true.

### MsXpS::libXpertMassCore::Enums::PolChemDefEntityStatus CrossLinker::isKnownByNameInPolChemDef() const

Returns the status of this CrossLinker instance the polymer chemistry definition registered in this instance.

The key to search the CrossLinker is this instance's member name.

If there is no PolChemDef available, Enums::PolChemDefEntityStatus::POL_CHEM_DEF_NOT_AVAILABLE is returned.

If no CrossLinker instance is found by this instance's name, Enums::PolChemDefEntityStatus::ENTITY_NOT_KNOWN is returned, otherwise Enums::PolChemDefEntityStatus::ENTITY_KNOWN is returned.

### bool CrossLinker::isValid() const

Returns the validity status of this CrossLinker.

### int CrossLinker::modifIndex(const QString &modif_name)

Returns the index of the found Modif instance by modif_name in the container, -1 otherwise.

### bool CrossLinker::removeModifAt(std::size_t index)

Removes the Modif instance at index.

index cannot be out-of-bounds.

Returns true.

### bool CrossLinker::renderXmlClkElement(const QDomElement &element, int version)

Returns true if parsing of XML element, using a versioned function was successful, false otherwise.

The data in element are set to this CrossLinker instance if they validated successfully, thus essentially initializing this CrossLinker instance.

The format of the element is:

    <clk>
      <name>CFP-chromophore</name>
      <formula></formula>
      <modifname>Chromo-O</modifname>
      <modifname>Chromo-H3</modifname>
      <modifname>Chromo-H</modifname>
    </clk>

### void CrossLinker::setFormula(const QString &formula_string)

Sets the formula to formula_string.

### void CrossLinker::setName(const QString &name)

Sets the name of the CrossLinker.

### void CrossLinker::setPolChemDefCstSPtr(MsXpS::libXpertMassCore::PolChemDefCstSPtr pol_chem_def_csp)

Sets the PolChemDef to pol_chem_def_csp.

### QString CrossLinker::toString() const

Returns a string representing this CrossLinker instance.

### bool CrossLinker::validate(MsXpS::libXpertMassCore::ErrorList *error_list_p) const

Returns true if this CrossLinker instance validates successfully, false otherwise.

The validation involves the following:

- The member polymer chemistry definition must exist.
- The name cannot be empty.
- The formula (if not empty) must validate successfully against the member polymer chemistry definition.
- The list of Modif instances must contain either no or more than two Modif instances. In the latter case, the Modif instances must be found in the member polymer chemistry definition and must validate successfully.

When an error occurs, the message is stored in error_list_p.

### bool CrossLinker::operator!=(const MsXpS::libXpertMassCore::CrossLinker &other) const

Returns true if this CrossLinker and other are different.

Returns the negated result of operator==().

### MsXpS::libXpertMassCore::CrossLinker &CrossLinker::operator=(const MsXpS::libXpertMassCore::CrossLinker &other)

Assigns other to this CrossLinker instance.

Returns a reference to this CrossLinker instance.

### bool CrossLinker::operator==(const MsXpS::libXpertMassCore::CrossLinker &other) const

Returns true if this CrossLinker and other are identical.

## Member Variable Documentation

### double CrossLinker::m_avg

This variable holds the average mass of the CrossLinker.

### QString CrossLinker::m_formula

This variable holds the formula that must be applied when the cross-link occurs.

Note: This formula can be empty because the CrossLinker can be fully described, from a chemical standpoint, by listing Modif instances in the member m_modifs container of Modif instances.

### bool CrossLinker::m_isValid

Tells if the CrossLinker is valid.

### std::vector<MsXpS::libXpertMassCore::ModifCstSPtr> CrossLinker::m_modifs

This variable holds the container of Modif instances that describe the reaction (or the reactions) involved in the formation of a CrossLink between Monomers of a Polymer (or of an Oligomer) sequence.

### double CrossLinker::m_mono

This variable holds the monoisotopic mass of the CrossLinker.

### QString CrossLinker::m_name

This variable holds the name of the CrossLinker, "DisulphideBond", for example.

### MsXpS::libXpertMassCore::PolChemDefCstSPtr CrossLinker::mcsp_polChemDef

This variable holds the reference polymer chemistry definition.