1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556
|
/* massXpert - the true massist's program.
--------------------------------------
Copyright(C) 2006,2007 Filippo Rusconi
http://www.massxpert.org/massXpert
This file is part of the massXpert project.
The massxpert project is the successor to the "GNU polyxmass"
project that is an official GNU project package(see
www.gnu.org). The massXpert project is not endorsed by the GNU
project, although it is released ---in its entirety--- under the
GNU General Public License. A huge part of the code in massXpert
is actually a C++ rewrite of code in GNU polyxmass. As such
massXpert was started at the Centre National de la Recherche
Scientifique(FRANCE), that granted me the formal authorization to
publish it under this Free Software License.
This software is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License version 3, as published by the Free Software Foundation.
This software 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 software; if not, write to the
Free Software Foundation, Inc.,
51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/////////////////////// Local includes
#include "chemicalGroup.hpp"
namespace massXpert
{
ChemicalGroup::ChemicalGroup(QString name, float pka,
bool acidCharged, int polRule)
: m_name(name), m_pka(pka),
m_acidCharged(acidCharged), m_polRule(polRule)
{
Q_ASSERT(m_pka > 0 && m_pka < 14);
}
ChemicalGroup::ChemicalGroup(const ChemicalGroup &other)
: m_name(other.m_name), m_pka(other.m_pka),
m_acidCharged(other.m_acidCharged), m_polRule(other.m_polRule)
{
}
ChemicalGroup::~ChemicalGroup()
{
while(!m_ruleList.isEmpty())
delete m_ruleList.takeFirst();
}
void
ChemicalGroup::setName(QString name)
{
m_name = name;
}
QString
ChemicalGroup::name() const
{
return m_name;
}
void
ChemicalGroup::setPka(float pka)
{
Q_ASSERT(pka > 0 && pka < 14);
m_pka = pka;
}
float
ChemicalGroup::pka() const
{
return m_pka;
}
void
ChemicalGroup::setAcidCharged(bool acidCharged)
{
m_acidCharged = acidCharged;
}
bool
ChemicalGroup::isAcidCharged() const
{
return m_acidCharged;
}
void
ChemicalGroup::setPolRule(int polRule)
{
m_polRule = polRule;
}
int
ChemicalGroup::polRule() const
{
return m_polRule;
}
QList<ChemicalGroupRule *> &
ChemicalGroup::ruleList()
{
return m_ruleList;
}
ChemicalGroupRule *
ChemicalGroup::findRuleEntity(QString value, int *index) const
{
int ruleIndex = 0;
if (!index)
ruleIndex = 0;
else
{
if(*index < 0)
return 0;
else if (*index > m_ruleList.size())
return 0;
ruleIndex = *index;
}
if (value.isEmpty())
return 0;
for (int iter = ruleIndex; iter < m_ruleList.size(); ++iter)
{
ChemicalGroupRule *rule = m_ruleList.at(iter);
if(rule->entity() == value)
{
if (index)
*index = iter;
return rule;
}
}
return 0;
}
ChemicalGroupRule *
ChemicalGroup::findRuleName(QString value, int *index) const
{
int ruleIndex = 0;
if (!index)
ruleIndex = 0;
else
{
if(*index < 0)
return 0;
else if (*index > m_ruleList.size())
return 0;
ruleIndex = *index;
}
if (value.isEmpty())
return 0;
for (int iter = ruleIndex; iter < m_ruleList.size(); ++iter)
{
ChemicalGroupRule *rule = m_ruleList.at(iter);
if(rule->name() == value)
{
if (index)
*index = iter;
return rule;
}
}
return 0;
}
ChemicalGroupRule *
ChemicalGroup::findRule(QString entity, QString name, int *index) const
{
int ruleIndex = 0;
if (!index)
ruleIndex = 0;
else
{
if(*index < 0)
return 0;
else if (*index > m_ruleList.size())
return 0;
ruleIndex = *index;
}
if (entity.isEmpty() || name.isEmpty())
return 0;
for (int iter = ruleIndex; iter < m_ruleList.size(); ++iter)
{
ChemicalGroupRule *rule = m_ruleList.at(iter);
if(rule->entity() == entity && rule->name() == name)
{
if (index)
*index = iter;
return rule;
}
}
return 0;
}
bool
ChemicalGroup::renderXmlMnmElement(const QDomElement &element)
{
QDomElement child;
// In an acidobasic definition file, the following xml structure
// is encountered:
// <acidobasicdata>
// <monomers>
// <monomer>
// <code>A</code>
// <mnmchemgroup>
// <name>N-term NH2</name>
// <pka>9.6</pka>
// <acidcharged>TRUE</acidcharged>
// <polrule>left_trapped</polrule>
// <chemgrouprule>
// <entity>LE_PLM_MODIF</entity>
// <name>Acetylation</name>
// <outcome>LOST</outcome>
// </chemgrouprule>
// </mnmchemgroup>
// <mnmchemgroup>
// <name>C-term COOH</name>
// <pka>2.35</pka>
// <acidcharged>FALSE</acidcharged>
// <polrule>right_trapped</polrule>
// </mnmchemgroup>
// </monomer>
// The relevant DTD lines are:
// <!ELEMENT monomer(code,mnmchemgroup*)>
// <!ELEMENT mnmchemgroup(name,pka,acidcharged,polrule,chemgrouprule*)>
// And the element the parameter points to is:
// <chemgroup>
// Which means that element.tagName() == "chemgroup" and that we'll
// have to go one step down to the first child of the current node
// in order to get to the <name> element.
if (element.tagName() != "mnmchemgroup")
return false;
child = element.firstChildElement("name");
if (child.isNull())
return false;
m_name = child.text();
child = child.nextSiblingElement();
if (child.isNull() || child.tagName() != "pka")
return false;
bool ok = false;
m_pka = child.text().toFloat(&ok);
if (!m_pka && !ok)
return false;
if (m_pka <= 0 || m_pka >= 14)
return false;
child = child.nextSiblingElement();
if (child.isNull() || child.tagName() != "acidcharged")
return false;
if (child.text() != "FALSE" && child.text() != "TRUE")
return false;
m_acidCharged =(child.text() == "FALSE" ? false : true);
// And now the polrule element. There should be one, here, in fact,
// because we are dealing with a monomer, and not a modification.
child = child.nextSiblingElement();
if (child.isNull() || child.tagName() != "polrule")
return false;
if (child.text() == "never_trapped")
m_polRule = MXP_CHEMGROUP_NEVER_TRAPPED;
else if (child.text() == "left_trapped")
m_polRule = MXP_CHEMGROUP_LEFT_TRAPPED;
else if (child.text() == "right_trapped")
m_polRule = MXP_CHEMGROUP_RIGHT_TRAPPED;
else
return false;
// And finally the chemical group rules... There might be zero, one
// or more.
QDomElement childChemGroupRule = child.nextSiblingElement("chemgrouprule");
while(!childChemGroupRule.isNull())
{
ChemicalGroupRule *rule = new ChemicalGroupRule();
if(!rule->renderXmlElement(childChemGroupRule))
{
delete rule;
return false;
}
m_ruleList.append(rule);
childChemGroupRule = childChemGroupRule.nextSiblingElement();
}
return true;
}
bool
ChemicalGroup::renderXmlMdfElement(const QDomElement &element)
{
QDomElement child;
// In an acidobasic definition file, the following xml structure
// is encountered:
// <acidobasicdata>
// <modifs>
// <modif>
// <name>Phosphorylation</name>
// <mdfchemgroup>
// <name>none_set</name>
// <pka>12</pka>
// <acidcharged>FALSE</acidcharged>
// </mdfchemgroup>
// <mdfchemgroup>
// <name>none_set</name>
// <pka>7</pka>
// <acidcharged>FALSE</acidcharged>
// </mdfchemgroup>
// </modif>
// </modifs>
// The relevant DTD lines are:
// <!ELEMENT modif(name,mdfchemgroup*)>
// <!ELEMENT mdfchemgroup(name,pka,acidcharged)>
// And the element the parameter points to is:
// <chemgroup>
// Which means that element.tagName() == "chemgroup" and that we'll
// have to go one step down to the first child of the current node
// in order to get to the <name> element.
if (element.tagName() != "mdfchemgroup")
return false;
child = element.firstChildElement("name");
if (child.isNull())
return false;
m_name = child.text();
child = child.nextSiblingElement();
if (child.isNull() || child.tagName() != "pka")
return false;
bool ok = false;
m_pka = child.text().toFloat(&ok);
if (!m_pka && !ok)
return false;
if (m_pka <= 0 || m_pka >= 14)
return false;
child = child.nextSiblingElement();
if (child.isNull() || child.tagName() != "acidcharged")
return false;
if (child.text() != "FALSE" && child.text() != "TRUE")
return false;
m_acidCharged =(child.text() == "FALSE" ? false : true);
return true;
}
//////////////////////// ChemicalGroupProp ////////////////////////
ChemicalGroupProp::ChemicalGroupProp(const QString &name,
ChemicalGroup *data)
{
if (!name.isEmpty())
m_name = name;
else
m_name = QString();
mpa_data = static_cast<void *>(data);
}
ChemicalGroupProp::~ChemicalGroupProp()
{
deleteData();
}
//! Deletes the data in this double property.
/*! The data is destroyed as a double is destroyed.
*/
void
ChemicalGroupProp::deleteData()
{
if (mpa_data)
{
delete static_cast<ChemicalGroup *>(mpa_data);
mpa_data = 0;
}
}
void *
ChemicalGroupProp::clone() const
{
ChemicalGroupProp *prop = 0;
if (mpa_data)
prop = new ChemicalGroupProp(m_name,
static_cast<ChemicalGroup *>(mpa_data));
return static_cast<void *>(prop);
}
void
ChemicalGroupProp::cloneOut(void *other) const
{
Q_ASSERT(other);
ChemicalGroupProp *otherProp = static_cast<ChemicalGroupProp *>(other);
if (otherProp->mpa_data)
otherProp->deleteData();
otherProp->m_name = m_name;
ChemicalGroup *chemicalGroup = 0;
if (mpa_data)
{
chemicalGroup = static_cast<ChemicalGroup *>(mpa_data);
otherProp->mpa_data =
static_cast<void *>(new ChemicalGroup(*chemicalGroup));
}
else
otherProp->mpa_data = 0;
}
void
ChemicalGroupProp::cloneIn(const void *other)
{
Q_ASSERT(other);
const ChemicalGroupProp *otherProp =
static_cast<const ChemicalGroupProp *>(other);
if (mpa_data)
deleteData();
m_name = otherProp->m_name;
ChemicalGroup *chemicalGroup = 0;
if (otherProp->mpa_data)
{
chemicalGroup = static_cast<ChemicalGroup *>(otherProp->mpa_data);
mpa_data = static_cast<void *>(new ChemicalGroup(*chemicalGroup));
}
else
mpa_data = 0;
}
bool
ChemicalGroupProp::renderXmlElement(const QDomElement &element, int version)
{
if (element.isNull())
;
return false;
}
QString *
ChemicalGroupProp::formatXmlElement(int offset, const QString &indent)
{
offset = offset;
if (indent.isEmpty())
;
return 0;
}
} // namespace massXpert
|