GCC Code Coverage Report


./
File: src/XpertMass/Isotope.cpp
Date: 2024-08-24 11:26:06
Lines:
174/232
75.0%
Functions:
29/30
96.7%
Branches:
103/268
38.4%

Line Branch Exec Source
1 /* BEGIN software license
2 *
3 * MsXpertSuite - mass spectrometry software suite
4 * -----------------------------------------------
5 * Copyright (C) 2009--2024 Filippo Rusconi
6 *
7 * http://www.msxpertsuite.org
8 *
9 * This file is part of the MsXpertSuite project.
10 *
11 * The MsXpertSuite project is the successor of the massXpert project. This
12 * project now includes various independent modules:
13 *
14 * - massXpert, model polymer chemistries and simulate mass spectrometric data;
15 * - mineXpert, a powerful TIC chromatogram/mass spectrum viewer/miner;
16 *
17 * This program is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation, either version 3 of the License, or
20 * (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 *
30 * END software license
31 */
32
33
34 /////////////////////// Qt includes
35 #include <QString>
36 #include <QDebug>
37
38 /////////////////////// Local includes
39 #include "Isotope.hpp"
40
41 namespace MsXpS
42 {
43
44 namespace libXpertMass
45 {
46
47
48 // #include <libisospec++/isoSpec++.h>
49 //
50 // extern const int elem_table_ID[ISOSPEC_NUMBER_OF_ISOTOPIC_ENTRIES];
51 // extern const int elem_table_atomicNo[ISOSPEC_NUMBER_OF_ISOTOPIC_ENTRIES];
52 // extern const double
53 // elem_table_probability[ISOSPEC_NUMBER_OF_ISOTOPIC_ENTRIES];
54 // extern const double elem_table_mass[ISOSPEC_NUMBER_OF_ISOTOPIC_ENTRIES];
55 // extern const int elem_table_massNo[ISOSPEC_NUMBER_OF_ISOTOPIC_ENTRIES];
56 // extern const int
57 // elem_table_extraNeutrons[ISOSPEC_NUMBER_OF_ISOTOPIC_ENTRIES];
58 // extern const char* elem_table_element[ISOSPEC_NUMBER_OF_ISOTOPIC_ENTRIES];
59 // extern const char* elem_table_symbol[ISOSPEC_NUMBER_OF_ISOTOPIC_ENTRIES];
60 // extern const bool elem_table_Radioactive[ISOSPEC_NUMBER_OF_ISOTOPIC_ENTRIES];
61 // extern const double
62 // elem_table_log_probability[ISOSPEC_NUMBER_OF_ISOTOPIC_ENTRIES];
63
64 // This is the order of the columns in the gui TableView
65 // ID
66 // ELEMENT,
67 // SYMBOL,
68 // ATOMIC_NO,
69 // MASS,
70 // MASS_NO,
71 // EXTRA_NEUTRONS,
72 // PROBABILITY,
73 // LN_PROBABILITY,
74 // RADIOACTIVE,
75
76 /*!
77 \enum MsXpS::libXpertMass::IsotopeFields
78
79 \brief This enum type documents the various member data in \l{Isotope}.
80
81 The values assigned to the various enum members are used to specify the
82 columsn in the GUI table view. They are also used to access substrings in
83 the proper order in the \l{Isotope::initialize()}.
84
85 \value ID Indicates Isotope::m_id.
86 \value ELEMENT Indicates Isotope::m_element.
87 \value SYMBOL Indicates the Isotope::m_symbol.
88 \value ATOMIC_NUMBER Indicates the Isotope::m_atomicNo.
89 \value MASS Indicates the Isotope::m_mass.
90 \value MASS_NUMBER Indicates the Isotope::m_massNo.
91 \value EXTRA_NEUTRONS Indicates the Isotope::m_extraNeutrons.
92 \value PROBABILITY Indicates the Isotope::m_probability.
93 \value LN_PROBABILITY Indicates the Isotope::m_lnProbability.
94 \value RADIOACTIVE Indicates the Isotope::m_radioactive.
95 \omitvalue LAST
96 */
97
98 /*!
99 \class MsXpS::libXpertMass::Isotope
100 \inmodule libXpertMass
101 \ingroup PolChemDefBuildingdBlocks
102 \inheaderfile Isotope.hpp
103
104 \brief The Isotope class models an isotope.
105
106 The Isotope class models an Isotope by featuring all the methods and
107 member data required to fully characterize an isotope. The member data in this
108 class have been inspired by the element tables from the IsoSpec library.
109 Please, see \l{https://github.com/MatteoLacki/IsoSpec/}.
110 */
111
112 /*!
113 \variable int MsXpS::libXpertMass::Isotope::m_id
114
115 \brief The unambiguous id for the chemical element (Hydrogen: 1, Helium, 2,
116 Carbon 6, for example). The \a id is repeated for each isotope of each chemical
117 element.
118 */
119
120 /*!
121 \variable int MsXpS::libXpertMass::Isotope::m_element
122
123 \brief The element, like "carbon" or "nitrogen" (lowercase).
124 */
125
126 /*!
127 \variable int MsXpS::libXpertMass::Isotope::m_symbol
128 \brief The symbol, like "C" or "N".
129 */
130
131 /*!
132 \variable int MsXpS::libXpertMass::Isotope::m_atomicNo
133 \brief The atomic number (Z), like 6 for "C", number of protons.
134 */
135
136 /*!
137 \variable int MsXpS::libXpertMass::Isotope::m_mass
138 \brief The mass.
139 */
140
141 /*!
142 \variable int MsXpS::libXpertMass::Isotope::m_massNo
143 \brief The mass number, (A) like 12 for "C", number of (protons + neutrons).
144 */
145
146 /*!
147 \variable int MsXpS::libXpertMass::Isotope::m_extraNeutrons
148 \brief The extra neutrons in the isotope's nucleus.
149 */
150
151 /*!
152 \variable int MsXpS::libXpertMass::Isotope::m_probability
153 \brief The probability of this isotope, that is, its abundance.
154 */
155
156 /*!
157 \variable int MsXpS::libXpertMass::Isotope::m_lnProbability
158 \brief The ln (natural logarithm) of the probability
159 \c p (e\sup{ln(p)}=p).
160 */
161
162 /*!
163 \variable int MsXpS::libXpertMass::Isotope::m_radioactive
164 \brief The true if the isotope is unstable (disintegrates), false
165 otherwise.
166 */
167
168 /*!
169 \typedef IsotopeSPtr
170 \relates Isotope
171
172 Synonym for std::shared_ptr<Isotope>.
173 */
174
175 /*!
176 \typedef IsotopeCstSPtr
177 \relates Isotope
178
179 Synonym for std::shared_ptr<const Isotope>.
180 */
181
182 /*!
183 \brief Constructs the \l{Isotope} with all the required arguments.
184
185 The isotope is created as a fully documented instance if all the following
186 parameters a correctly set:
187
188 \a id \l{MsXpS::libXpertMass::Isotope::m_id}
189
190 \a element \l{MsXpS::libXpertMass::Isotope::m_element}
191
192 \a symbol \l{MsXpS::libXpertMass::Isotope::m_symbol}
193
194 \a atomicNo \l{MsXpS::libXpertMass::Isotope::m_atomicNo}
195
196 \a mass \l{MsXpS::libXpertMass::Isotope::m_mass}
197
198 \a massNo \l{MsXpS::libXpertMass::Isotope::m_massNo}
199
200 \a extraNeutrons \l{MsXpS::libXpertMass::Isotope::m_extraNeutrons}
201
202 \a probability \l{MsXpS::libXpertMass::Isotope::m_probability}
203
204 \a lnProbability \l{MsXpS::libXpertMass::Isotope::m_lnProbability}
205
206 \a radioactive \l{MsXpS::libXpertMass::Isotope::m_radioactive}
207 */
208 14016 Isotope::Isotope(int id,
209 QString element,
210 QString symbol,
211 int atomicNo,
212 double mass,
213 int massNo,
214 int extraNeutrons,
215 double probability,
216 double lnProbability,
217 14016 bool radioactive)
218 14016 : m_id(id),
219 14016 m_element(element),
220 14016 m_symbol(symbol),
221 14016 m_atomicNo(atomicNo),
222 14016 m_mass(mass),
223 14016 m_massNo(massNo),
224 14016 m_extraNeutrons(extraNeutrons),
225 14016 m_probability(probability),
226 14016 m_lnProbability(lnProbability),
227 14016 m_radioactive(radioactive)
228 {
229 14016 }
230
231
232 /*!
233 \brief Constructs the \l{Isotope} as a copy of \a other.
234 */
235 28 Isotope::Isotope(const Isotope &other)
236 {
237 28 m_id = other.m_id;
238 28 m_element = other.m_element;
239 28 m_symbol = other.m_symbol;
240 28 m_atomicNo = other.m_atomicNo;
241 28 m_mass = other.m_mass;
242 28 m_massNo = other.m_massNo;
243 28 m_extraNeutrons = other.m_extraNeutrons;
244 28 m_probability = other.m_probability;
245 28 m_lnProbability = other.m_lnProbability;
246 28 m_radioactive = other.m_radioactive;
247 28 }
248
249 /*!
250 \brief Constructs the \l{Isotope} using all the data in the \a text string.
251
252 The strings contains all the Isotope data, separated by a comma ',' exactly
253 with the same format as that implemented by Isotope::toString().
254
255 \sa Isotope::initialize(), Isotope::toString()
256 */
257 118664 Isotope::Isotope(const QString &text)
258 {
259 // This is somehow the reverse of toString().
260
261
2/4
✓ Branch 1 taken 118664 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 118664 times.
118664 if(!initialize(text))
262 qFatal("Failed to initialize an isotope with text.");
263 118664 }
264
265 /*!
266 \brief Destructs the \l{Isotope}.
267 */
268 39624 Isotope::~Isotope()
269 {
270 39624 }
271
272 /*!
273 Initializes the \l{Isotope} using all the data in the \a text string.
274
275 The string passed as argument is QString::simplified() and
276 QString::split() with ',' as the delimiter.
277
278 The obtained strings are converted to the corresponding numerical or textual
279 values to initalize all the member data. The code is similar to:
280
281 \code
282 m_radioactive =
283 string_list[static_cast<int>(IsotopeFields::RADIOACTIVE)].toInt(&ok);
284
285 if(!ok)
286 {
287 qDebug() << "Failed to extract the isotope radioactive.";
288 return false;
289 }
290 \endcode
291
292 Returns true if the string contained valid substrings that successfully
293 initialized the \l{Isotope}, false otherwise.
294
295 \sa Isotope::Isotope(const QString &text)
296 */
297 bool
298 118664 Isotope::initialize(const QString &text)
299 {
300
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 118664 times.
118664 if(text.isEmpty())
301 return false;
302
303 // At this point deconstruct the line. Make sure we remove all spaces from
304 // beginning and end.
305
306
1/2
✓ Branch 1 taken 118664 times.
✗ Branch 2 not taken.
118664 QString local_text = text.simplified();
307
308 // At this point, use a regular expression to match the text.
309
310
1/2
✓ Branch 2 taken 118664 times.
✗ Branch 3 not taken.
118664 QStringList string_list = local_text.split(',');
311
312 // qDebug() << "Expecting " << static_cast<int>(IsotopeFields::LAST)
313 //<< "comma-separated fields for isotope-describing text line."
314 //<< "QStringList is:" << string_list;
315
316
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 118664 times.
118664 if(string_list.size() != static_cast<int>(IsotopeFields::LAST))
317 {
318 qDebug() << "The text does not match an Isotope definition.";
319 return false;
320 }
321
322 118664 bool ok = false;
323
324 118664 m_id =
325
3/6
✓ Branch 1 taken 118664 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 118664 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 118664 times.
✗ Branch 8 not taken.
118664 string_list[static_cast<int>(IsotopeFields::ID)].simplified().toInt(&ok);
326
327
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 118664 times.
118664 if(!ok)
328 {
329 qDebug() << "Failed to extract the isotope ID.";
330 return false;
331 }
332
333 m_element =
334
2/4
✓ Branch 1 taken 118664 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 118664 times.
✗ Branch 5 not taken.
118664 string_list[static_cast<int>(IsotopeFields::ELEMENT)].simplified();
335
336
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 118664 times.
118664 if(m_element.isEmpty())
337 {
338 qDebug() << "Failed to extract the element name.";
339 return false;
340 }
341
342
2/4
✓ Branch 1 taken 118664 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 118664 times.
✗ Branch 5 not taken.
118664 m_symbol = string_list[static_cast<int>(IsotopeFields::SYMBOL)].simplified();
343
344
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 118664 times.
118664 if(m_symbol.isEmpty())
345 {
346 qDebug() << "Failed to extract the element symbol.";
347 return false;
348 }
349
350
1/2
✓ Branch 1 taken 118664 times.
✗ Branch 2 not taken.
118664 m_atomicNo = string_list[static_cast<int>(IsotopeFields::ATOMIC_NUMBER)]
351
1/2
✓ Branch 1 taken 118664 times.
✗ Branch 2 not taken.
118664 .simplified()
352
1/2
✓ Branch 1 taken 118664 times.
✗ Branch 2 not taken.
118664 .toInt(&ok);
353
354
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 118664 times.
118664 if(!ok)
355 {
356 qDebug() << "Failed to extract the isotope atomic number.";
357 return false;
358 }
359
360 118664 m_mass =
361
3/6
✓ Branch 1 taken 118664 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 118664 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 118664 times.
✗ Branch 8 not taken.
118664 string_list[static_cast<int>(IsotopeFields::MASS)].simplified().toDouble(
362 &ok);
363
364
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 118664 times.
118664 if(!ok)
365 {
366 qDebug() << "Failed to extract the isotope mass.";
367 return false;
368 }
369
370
1/2
✓ Branch 1 taken 118664 times.
✗ Branch 2 not taken.
118664 m_massNo = string_list[static_cast<int>(IsotopeFields::MASS_NUMBER)]
371
1/2
✓ Branch 1 taken 118664 times.
✗ Branch 2 not taken.
118664 .simplified()
372
1/2
✓ Branch 1 taken 118664 times.
✗ Branch 2 not taken.
118664 .toDouble(&ok);
373
374
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 118664 times.
118664 if(!ok)
375 {
376 qDebug() << "Failed to extract the isotope mass number.";
377 return false;
378 }
379
380
1/2
✓ Branch 1 taken 118664 times.
✗ Branch 2 not taken.
118664 m_extraNeutrons = string_list[static_cast<int>(IsotopeFields::EXTRA_NEUTRONS)]
381
1/2
✓ Branch 1 taken 118664 times.
✗ Branch 2 not taken.
118664 .simplified()
382
1/2
✓ Branch 1 taken 118664 times.
✗ Branch 2 not taken.
118664 .toInt(&ok);
383
384
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 118664 times.
118664 if(!ok)
385 {
386 qDebug() << "Failed to extract the isotope extra neutrons.";
387 return false;
388 }
389
390
1/2
✓ Branch 1 taken 118664 times.
✗ Branch 2 not taken.
118664 m_probability = string_list[static_cast<int>(IsotopeFields::PROBABILITY)]
391
1/2
✓ Branch 1 taken 118664 times.
✗ Branch 2 not taken.
118664 .simplified()
392
1/2
✓ Branch 1 taken 118664 times.
✗ Branch 2 not taken.
118664 .toDouble(&ok);
393
394
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 118664 times.
118664 if(!ok)
395 {
396 qDebug() << "Failed to extract the isotope probability.";
397 return false;
398 }
399
400
1/2
✓ Branch 1 taken 118664 times.
✗ Branch 2 not taken.
118664 m_lnProbability = string_list[static_cast<int>(IsotopeFields::LN_PROBABILITY)]
401
1/2
✓ Branch 1 taken 118664 times.
✗ Branch 2 not taken.
118664 .simplified()
402
1/2
✓ Branch 1 taken 118664 times.
✗ Branch 2 not taken.
118664 .toDouble(&ok);
403
404
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 118664 times.
118664 if(!ok)
405 {
406 qDebug() << "Failed to extract the isotope log probability.";
407 return false;
408 }
409
410
2/6
✓ Branch 1 taken 118664 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 118664 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
237328 if(string_list[static_cast<int>(IsotopeFields::RADIOACTIVE)].simplified() ==
411
4/6
✓ Branch 1 taken 118664 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 14832 times.
✓ Branch 5 taken 103832 times.
✓ Branch 6 taken 14832 times.
✗ Branch 7 not taken.
252160 "0" ||
412
5/10
✓ Branch 1 taken 14832 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 14832 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 14832 times.
✓ Branch 8 taken 103832 times.
✓ Branch 10 taken 118664 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
133496 string_list[static_cast<int>(IsotopeFields::RADIOACTIVE)].simplified() ==
413 "1")
414 {
415
1/2
✓ Branch 1 taken 118664 times.
✗ Branch 2 not taken.
118664 m_radioactive = string_list[static_cast<int>(IsotopeFields::RADIOACTIVE)]
416
1/2
✓ Branch 1 taken 118664 times.
✗ Branch 2 not taken.
118664 .simplified()
417
1/2
✓ Branch 1 taken 118664 times.
✗ Branch 2 not taken.
118664 .toInt(&ok);
418
419
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 118664 times.
118664 if(!ok)
420 {
421 qDebug() << "Failed to extract the isotope radioactive.";
422 return false;
423 }
424 }
425 else if(string_list[static_cast<int>(IsotopeFields::RADIOACTIVE)]
426 .simplified() == "false" ||
427 string_list[static_cast<int>(IsotopeFields::RADIOACTIVE)]
428 .simplified() == "false")
429 {
430 m_radioactive = false;
431 }
432 else if(string_list[static_cast<int>(IsotopeFields::RADIOACTIVE)]
433 .simplified() == "true")
434 {
435 m_radioactive = true;
436 }
437 else
438 {
439 qDebug() << "Failed to extract the isotope radioactive.";
440 return false;
441 }
442
443 // qDebug() << toString();
444
445 118664 return true;
446 118664 }
447
448 /*!
449 \brief Sets the id of the isotope to \a id.
450
451 \sa getId()
452 */
453 void
454 4 Isotope::setId(int id)
455 {
456 4 m_id = id;
457 4 }
458
459
460 /*!
461 \brief Returns the id of the isotope.
462
463 \sa setId()
464 */
465 int
466 12 Isotope::getId() const
467 {
468 12 return m_id;
469 }
470
471 /*!
472 \brief Sets the element of the isotope to \a element.
473
474 \sa getElement()
475 */
476 void
477 4 Isotope::setElement(const QString &element)
478 {
479 4 m_element = element;
480 4 }
481
482
483 /*!
484 \brief Returns the element of the isotope.
485
486 \sa setElement()
487 */
488 QString
489 60 Isotope::getElement() const
490 {
491 60 return m_element;
492 }
493
494
495 /*!
496 \brief Sets the symbol of the isotope to \a symbol.
497
498 \sa getSymbol()
499 */
500 void
501 12 Isotope::setSymbol(const QString &symbol)
502 {
503 12 m_symbol = symbol;
504 12 }
505
506
507 /*!
508 \brief Returns the symbol of the isotope.
509
510 \sa setSymbol()
511 */
512 QString
513 12369204 Isotope::getSymbol() const
514 {
515 12369204 return m_symbol;
516 }
517
518
519 /*!
520 \brief Sets the the atomic number of the isotope to \a atomic_number.
521
522 \sa getAtomicNo()
523 */
524 void
525 4 Isotope::setAtomicNo(int atomic_number)
526 {
527 4 m_atomicNo = atomic_number;
528 4 }
529
530
531 /*!
532 \brief Returns the atomic number of the isotope.
533
534 \sa setAtomicNo()
535 */
536 int
537 12 Isotope::getAtomicNo() const
538 {
539 12 return m_atomicNo;
540 }
541
542
543 /*!
544 \brief Sets the the mass of the isotope to \a mass.
545
546 \sa getMass()
547 */
548 void
549 8 Isotope::setMass(double mass)
550 {
551 8 m_mass = mass;
552 8 }
553
554 /*!
555 \brief Returns the mass of the isotope.
556
557 \sa setMass()
558 */
559 double
560 216628 Isotope::getMass() const
561 {
562 216628 return m_mass;
563 }
564
565
566 /*!
567 \brief Sets the the mass number of the isotope to \a mass_number.
568
569 \sa getMassNo()
570 */
571 void
572 4 Isotope::setMassNo(int mass_number)
573 {
574 4 m_massNo = mass_number;
575 4 }
576
577 /*!
578 \brief Returns the mass number of the isotope.
579
580 \sa setMassNo()
581 */
582 int
583 12 Isotope::getMassNo() const
584 {
585 12 return m_massNo;
586 }
587
588
589 /*!
590 \brief Sets the extra neutrons of the isotope to \a extra_neutrons.
591
592 \sa getExtraNeutrons()
593 */
594 void
595 4 Isotope::setExtraNeutrons(int extra_neutrons)
596 {
597 4 m_extraNeutrons = extra_neutrons;
598 4 }
599
600 /*!
601 \brief Returns the extra neutrons of the isotope.
602
603 \sa setExtraNeutrons()
604 */
605 int
606 12 Isotope::getExtraNeutrons() const
607 {
608 12 return m_extraNeutrons;
609 }
610
611 /*!
612 \brief Sets the probability (the abundance) of the isotope to \a probability.
613
614 \sa getProbability()
615 */
616 void
617 8 Isotope::setProbability(double probability)
618 {
619 8 m_probability = probability;
620 8 }
621
622 /*!
623 \brief Returns the probability (the abundance) of the isotope.
624
625 \sa setProbability()
626 */
627 double
628 482676 Isotope::getProbability() const
629 {
630 482676 return m_probability;
631 }
632
633 /*!
634 \brief Sets the ln(probability) of the isotope to \a ln_probability.
635
636 \sa getLnProbability()
637 */
638 void
639 4 Isotope::setLnProbability(double ln_probability)
640 {
641 4 m_lnProbability = ln_probability;
642 4 }
643
644 /*!
645 \brief Returns the ln(probability) of the isotope.
646
647 \sa setLnProbability()
648 */
649 double
650 12 Isotope::getLnProbability() const
651 {
652 12 return m_lnProbability;
653 }
654
655 /*!
656 \brief Sets if the isotope is radioactive to \a is_radioactive.
657
658 \sa getRadioactive()
659 */
660 void
661 4 Isotope::setRadioactive(bool is_radioactive)
662 {
663 4 m_radioactive = is_radioactive;
664 4 }
665
666 /*!
667 \brief Returns true if the isotope is radioactive, false otherwise.
668
669 \sa setRadioactive()
670 */
671 bool
672 12 Isotope::getRadioactive() const
673 {
674 12 return m_radioactive;
675 }
676
677 /*!
678 \brief Validates the isotope.
679
680 The symbol, mass and probability member data are scrutinized and
681 if errors are detected an error counter is incremented.
682
683 \a errors_p Pointer to a string where the detected errors (if any) are stored
684 as meaningful strings. If \a errors_p is nullptr, the errors are not stored.
685
686 \code
687
688 if(m_symbol.isEmpty())
689 {
690 ++error_count;
691 errors += "The symbol is not set.";
692 }
693 \endcode
694
695 Returns the error count. If no error occurred, the returned value is 0.
696 */
697 int
698 56 Isotope::validate(QString *errors_p) const
699 {
700 56 int error_count = 0;
701 56 QString errors;
702
703 // The minimal set of data that an isotope needs to have is the symbol, the
704 // mass and the probability.
705
706
2/2
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 44 times.
56 if(m_symbol.isEmpty())
707 {
708 12 ++error_count;
709
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 errors += "The symbol is not set. ";
710 }
711
712
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 44 times.
56 if(m_mass <= 0)
713 {
714 12 ++error_count;
715
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 errors += "The mass is not set. ";
716 }
717
718
3/4
✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 48 times.
56 if(m_probability > 1 || m_probability <= 0)
719 {
720 8 ++error_count;
721
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 errors += "The probability is not set. ";
722 }
723
724 // Now, if there were errors, we would like to document them with the symbol
725 // name if it was set.
726
727
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 40 times.
56 if(error_count)
728 {
729
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(errors_p)
730 {
731
2/2
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 4 times.
16 if(m_symbol.isEmpty())
732
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 *errors_p = errors + "\n";
733 else
734 // Document the name of the symbol to make the errors more
735 // meaningful.
736
5/10
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 4 times.
✗ Branch 14 not taken.
4 *errors_p += "For symbol " + m_symbol + ": " + errors + "\n";
737 }
738 }
739
740 56 return error_count;
741 56 }
742
743 /*!
744 \brief Assigns to this isotope the \a other isotope's member data.
745
746 Each member datum in \a other is copied to this isotope.
747
748 Returns a reference to this isotope.
749 */
750 Isotope &
751 Isotope::operator=(const Isotope &other)
752 {
753 if(&other == this)
754 return *this;
755
756 m_id = other.m_id;
757 m_element = other.m_element;
758 m_symbol = other.m_symbol;
759 m_atomicNo = other.m_atomicNo;
760 m_mass = other.m_mass;
761 m_massNo = other.m_massNo;
762 m_extraNeutrons = other.m_extraNeutrons;
763 m_probability = other.m_probability;
764 m_lnProbability = other.m_lnProbability;
765 m_radioactive = other.m_radioactive;
766
767 return *this;
768 }
769
770 /*!
771 \brief Tests the equality between this isotope and \a other.
772
773 Each member datum in \a other is compared to this isotope's member datum. If a
774 difference is detected, a counter is incremented.
775
776 Returns true if no difference has been encountered (the counter is 0) and
777 false otherwise.
778
779 \sa operator!=()
780 */
781 bool
782 16 Isotope::operator==(const Isotope &other) const
783 {
784
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if(&other == this)
785 return true;
786
787
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 12 times.
16 if(m_id != other.m_id)
788 4 return false;
789
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
12 if(m_element != other.m_element)
790 return false;
791
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
12 if(m_symbol != other.m_symbol)
792 return false;
793
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(m_atomicNo != other.m_atomicNo)
794 return false;
795
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(m_mass != other.m_mass)
796 return false;
797
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(m_massNo != other.m_massNo)
798 return false;
799
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(m_extraNeutrons != other.m_extraNeutrons)
800 return false;
801
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(m_probability != other.m_probability)
802 return false;
803
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(m_lnProbability != other.m_lnProbability)
804 return false;
805
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(m_radioactive != other.m_radioactive)
806 return false;
807
808 12 return true;
809 }
810
811
812 /*!
813 \brief Tests the inequality between this isotope and \a other.
814
815 Returns the negated result of operator==().
816
817 \sa operator==()
818 */
819 bool
820 20 Isotope::operator!=(const Isotope &other) const
821 {
822
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 4 times.
20 if(&other == this)
823 16 return false;
824
825 4 return !operator==(other);
826 }
827
828 /*!
829 \brief Returns a string containing a comma-separated textual representation
830 of all the member data values.
831
832 All the member data values are separated using commas ','. Only the values
833 are stored in the string, without naming the variables:
834
835 \code
836 return QString("%1,%2,%3,%4,%5,%6,%7,%8,%9,%10")
837 .arg(m_id)
838 .arg(m_element)
839 .arg(m_symbol)
840 .arg(m_atomicNo)
841 .arg(m_mass, 0, 'f', 60)
842 .arg(m_massNo)
843 .arg(m_extraNeutrons)
844 .arg(m_probability, 0, 'f', 60)
845 .arg(m_lnProbability, 0, 'f', 60)
846 .arg(m_radioactive ? 1 : 0);
847 \endcode
848
849 Returns a string.
850 */
851 QString
852 2308 Isotope::toString() const
853 {
854 // We need to use CSV because there might be spaces in the
855 // text in the IsoSpec tables.
856
1/2
✓ Branch 1 taken 2308 times.
✗ Branch 2 not taken.
2308 return QString("%1,%2,%3,%4,%5,%6,%7,%8,%9,%10")
857
1/2
✓ Branch 1 taken 2308 times.
✗ Branch 2 not taken.
4616 .arg(m_id)
858
1/2
✓ Branch 1 taken 2308 times.
✗ Branch 2 not taken.
4616 .arg(m_element)
859
1/2
✓ Branch 1 taken 2308 times.
✗ Branch 2 not taken.
4616 .arg(m_symbol)
860
1/2
✓ Branch 1 taken 2308 times.
✗ Branch 2 not taken.
4616 .arg(m_atomicNo)
861
1/2
✓ Branch 1 taken 2308 times.
✗ Branch 2 not taken.
4616 .arg(m_mass, 0, 'f', 60)
862
1/2
✓ Branch 1 taken 2308 times.
✗ Branch 2 not taken.
4616 .arg(m_massNo)
863
1/2
✓ Branch 1 taken 2308 times.
✗ Branch 2 not taken.
4616 .arg(m_extraNeutrons)
864
1/2
✓ Branch 1 taken 2308 times.
✗ Branch 2 not taken.
4616 .arg(m_probability, 0, 'f', 60)
865
1/2
✓ Branch 1 taken 2308 times.
✗ Branch 2 not taken.
6924 .arg(m_lnProbability, 0, 'f', 60)
866
3/4
✓ Branch 0 taken 288 times.
✓ Branch 1 taken 2020 times.
✓ Branch 3 taken 2308 times.
✗ Branch 4 not taken.
4616 .arg(m_radioactive ? 1 : 0);
867 }
868
869 } // namespace libXpertMass
870
871 } // namespace MsXpS
872