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 557 558 559 560 561 562 563 564 565 566 567
|
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
#include <BALL/DOCKING/COMMON/result.h>
namespace BALL
{
Result::Method Result::getMethod(int i)
{
switch(i)
{
case 0:
return Result::RECEPTORIMPORT;
case 1:
return Result::LIGANDIMPORT;
case 2:
return Result::DOCKING;
case 3:
return Result::RESCORING;
case 4:
return Result::MDRESCORING;
case 5:
return Result::CONSENSUSRESCORING;
case 6:
return Result::MOLECULE_CHECK;
}
return Result::UNKNOWN;
}
Result* Result::makeLigandImportResult()
{
Result* res = new Result();
res->setMethod(LIGANDIMPORT);
return res;
}
Result* Result::makeReceptorImportResult()
{
Result* res = new Result();
res->setMethod(RECEPTORIMPORT);
return res;
}
Result* Result::makeDockingResult()
{
Result* res = new Result();
res->setMethod(DOCKING);
return res;
}
Result* Result::makeRescoringResult()
{
Result* res = new Result();
res->setMethod(RESCORING);
return res;
}
Result::Result()
{
description_ = "";
timestamp_ = "";
toolinfo_ = "";
}
Result::Result(const Result::Method& _method)
{
method = _method;
description_ = "";
timestamp_ = "";
toolinfo_ = "";
}
Result::Result(const Result& res)
{
operator = (res);
}
Result::Result(const Result& res, const HashSet<String>& IDs)
{
method = res.method;
result_data_ = res.result_data_;
description_ = res.description_;
for (HashMap < String, vector < ResultData > > ::const_iterator it = res.result_data_.begin(); it != res.result_data_.end(); it++)
{
if (IDs.has(it->first)) result_data_.insert(*it);
}
for (HashMap < String, ResultData > ::const_iterator it = res.result_output_data_.begin(); it != res.result_output_data_.end(); it++)
{
if (IDs.has(it->first)) result_output_data_.insert(*it);
}
for (vector < String > ::const_iterator it = res.input_conformations_.begin(); it != res.input_conformations_.end(); it++)
{
if (IDs.has(*it)) input_conformations_.push_back(*it);
}
for (HashSet < String > ::const_iterator it = res.input_conformations_map_.begin(); it != res.input_conformations_map_.end(); it++)
{
if (IDs.has(*it)) input_conformations_map_.insert(*it);
}
}
void Result::clear()
{
result_data_.clear();
result_output_data_.clear();
input_conformations_.clear();
input_conformations_map_.clear();
}
void Result::operator = (const Result& res)
{
method = res.method;
description_ = res.description_;
result_data_ = res.result_data_;
result_output_data_ = res.result_output_data_;
input_conformations_ = res.input_conformations_;
input_conformations_map_ = res.input_conformations_map_;
}
void Result::operator += (const Result& res)
{
if (method != res.method)
{
throw BALL::Exception::GeneralException(__FILE__, __LINE__, "Result::operator += ", "Results can only be added to another Result of the same type!");
}
for (HashMap < String, vector < ResultData > > ::const_iterator it = res.result_data_.begin(); it != res.result_data_.end(); it++)
{
result_data_.insert(*it);
}
for (HashMap < String, ResultData > ::const_iterator it = res.result_output_data_.begin(); it != res.result_output_data_.end(); it++)
{
result_output_data_.insert(*it);
}
for (vector < String > ::const_iterator it = res.input_conformations_.begin(); it != res.input_conformations_.end(); it++)
{
input_conformations_.push_back(*it);
}
for (HashSet < String > ::const_iterator it = res.input_conformations_map_.begin(); it != res.input_conformations_map_.end(); it++)
{
input_conformations_map_.insert(*it);
}
}
Result::~Result()
{
}
Result::Method Result::getMethod()
{
return method;
}
String Result::getMethodString()
{
switch(method)
{
case 0:
return "RECEPTORIMPORT";
case 1:
return "LIGANDIMPORT";
case 2:
return "DOCKING";
case 3:
return "RESCORING";
case 4:
return "MDRESCORING";
case 5:
return "CONSENSUSCORING";
case 6:
return "MOLECULE_CHECK";
default:
return "N/A";
}
}
void Result::setMethod(Result::Method _method)
{
method = _method;
}
void Result::setTimestamp(const String& timestamp)
{
timestamp_ = timestamp;
}
const String& Result::getTimestamp()
{
return timestamp_;
}
void Result::setToolInfo(const String& toolinfo)
{
toolinfo_ = toolinfo;
}
const String& Result::getToolInfo()
{
return toolinfo_;
}
void Result::setDescription(const String& text)
{
description_ = text;
}
const String& Result::getDescription()
{
return description_;
}
const vector < String > * Result::getInputConformations()
{
return &input_conformations_;
}
Conformation* Result::getInputConformer(Ligand* lig)
{
for (Position i = 0; i < lig->getNumberOfConformations(); i++)
{
Conformation* conf = lig->getConformation(i);
String confid = conf->getId();
if (input_conformations_map_.has(confid))
{
return conf;
}
}
throw(Exception::GeneralException(__FILE__, __LINE__, "Result", "no input conformation found for ligand"));
}
Conformation* Result::getFirstOutputConformation(Ligand* lig)
{
for (Position i = 0; i < lig->getNumberOfConformations(); i++)
{
Conformation* conf = lig->getConformation(i);
String confid = conf->getId();
if (hasOutputData(confid))
{
return conf;
}
}
throw(Exception::GeneralException(__FILE__, __LINE__, "Result", "no first output conformation found for ligand"));
}
vector < Result::ResultData > Result::getOutputConformations(Ligand* lig)
{
vector<ResultData> ret;
for (Position i = 0; i < lig->getNumberOfConformations(); i++)
{
Conformation* conf = lig->getConformation(i);
String confid = conf->getId();
if (hasOutputData(confid))
{
Result::ResultData rd = getOutputData(confid);
rd.setConformation(conf);
ret.push_back(rd);
}
}
return ret;
}
const HashSet<String>* Result::getInputIds()
{
return &input_conformations_map_;
}
HashSet<String> Result::getOutputIds()
{
HashSet<String> ret;
HashMap<String, vector<ResultData> >::Iterator iter = result_data_.begin();
for (; iter != result_data_.end(); iter++)
{
vector<ResultData>::iterator iter2 = (iter->second).begin();
for (; iter2 != (iter->second).end(); iter2++)
{
ResultData rd = *iter2;
ret.insert(rd.getLigandConformationId());
}
}
return ret;
}
void Result::add(Conformation* lig_conf_in, Conformation* lig_conf_out, int scoringmethod, double energy, Conformation* rec_conf)
{
ResultData rd;
rd.setEnergy(energy);
rd.setScoringMethod(scoringmethod);
rd.setLigandConformation(lig_conf_out);
rd.setReceptorConformation(rec_conf);
add(lig_conf_in, rd);
}
void Result::add(Conformation* lig_conf_in, ResultData &rd)
{
add(lig_conf_in->getId(), rd);
}
void Result::add(const String& lig_conf_id_in, const String& lig_conf_id_out, int scoringmethod, double energy, const String& rec_conf_id)
{
ResultData rd;
rd.setEnergy(energy);
rd.setScoringMethod(scoringmethod);
rd.setLigandConformationId(lig_conf_id_out);
rd.setReceptorConformationId(rec_conf_id);
add(lig_conf_id_in, rd);
}
void Result::add(String lig_conf_id_in, ResultData &rd)
{
if ( input_conformations_map_.has(lig_conf_id_in)
&& result_output_data_.has(rd.getLigandConformationId()) )
{
//cout<<"[Warning:] Result object already has data for given pair of input- and output-conformation! Thus, no new data is added!"<<endl;
return;
}
if (!result_data_.has(lig_conf_id_in))
{
input_conformations_.push_back(lig_conf_id_in);
input_conformations_map_.insert(lig_conf_id_in);
result_data_[lig_conf_id_in] = vector<ResultData>();
}
result_data_[lig_conf_id_in].push_back(rd);
result_output_data_[rd.getLigandConformationId()] = rd;
}
void Result::erase(const FlexibleMolecule* flexmol)
{
const vector < Conformation* > & confs = flexmol->getConformations();
HashSet<String> conf_set;
for (Size i = 0; i < confs.size(); i++)
{
String ID = confs[i]->getId();
conf_set.insert(ID);
result_data_.erase(ID);
result_output_data_.erase(ID);
input_conformations_map_.erase(ID);
}
for (vector < String > ::iterator it = input_conformations_.begin(); it != input_conformations_.end(); )
{
if (conf_set.has(*it))
{
it = input_conformations_.erase(it);
}
else it++;
}
}
void Result::erase(const String& ID)
{
result_data_.erase(ID);
result_output_data_.erase(ID);
input_conformations_map_.erase(ID);
for (vector < String > ::iterator it = input_conformations_.begin(); it != input_conformations_.end(); )
{
if (*it == ID)
{
it = input_conformations_.erase(it);
break;
}
else it++;
}
}
void Result::sort(const list<String>& input_order, list<String>& output_order)
{
input_conformations_.clear();
output_order.clear();
for (list < String > ::const_iterator it = input_order.begin(); it != input_order.end(); it++)
{
HashMap<String, vector<ResultData> >::iterator it2 = result_data_.find(*it);
if (it2 != result_data_.end())
{
input_conformations_.push_back(*it);
for (Size i = 0; i < it2->second.size(); i++)
{
output_order.push_back(it2->second[i].getLigandConformationId());
}
}
}
}
bool Result::hasOutputData(String id)
{
return (result_output_data_.has(id));
}
Result::ResultData Result::getOutputData(String id)
{
if (result_output_data_.has(id))
{
return result_output_data_[id];
}
else
{
throw(Exception::InvalidArgument(__FILE__, __LINE__, "supplied id not found"));
}
}
const vector<Result::ResultData>* Result::get(String inpose_id)
{
return &result_data_[inpose_id];
}
String Result::toString(const ResultData &rd)
{
String ret="";
ret += " method: "+ String(rd.getScoringMethod());
ret += " energy: "+ String(rd.getEnergy());
ret += " lig_id: "+ rd.getLigandConformationId();
ret += " rec_id: "+ rd.getReceptorConformationId();
ret += " ";
return ret;
}
Result::ResultData::ResultData()
: scoringmethod(UNKNOWN)
{
has_lig_id = false;
has_rec_id = false;
has_energy = false;
has_method = false;
resulttype = -1;
}
Result::ResultData::ResultData(int result_type)
: scoringmethod(UNKNOWN)
{
has_lig_id = false;
has_rec_id = false;
has_energy = false;
has_method = false;
resulttype = result_type;
}
void Result::ResultData::setReceptorConformationId(String id)
{
rec_conf_id = id;
has_rec_id = true;
}
void Result::ResultData::setReceptorConformation(Conformation* conf)
{
rec_conf_id = conf->getId();
has_rec_id = true;
}
String Result::ResultData::getReceptorConformationId() const
{
return rec_conf_id;
}
void Result::ResultData::setLigandConformationId(String id)
{
has_lig_id = true;
lig_conf_id = id;
}
void Result::ResultData::setLigandConformation(Conformation* conf)
{
has_lig_id = true;
lig_conf_id = conf->getId();
}
String Result::ResultData::getLigandConformationId() const
{
return lig_conf_id;
}
void Result::ResultData::setScoringMethod(int _method)
{
scoringmethod = _method;
has_method = true;
}
int Result::ResultData::getScoringMethod() const
{
return scoringmethod;
}
void Result::ResultData::setEnergy(double e)
{
energy = e;
has_energy = true;
}
double Result::ResultData::getEnergy() const
{
return energy;
}
bool Result::ResultData::hasReceptorConformationId() const
{
if (scoringmethod == LIGANDIMPORT || scoringmethod == RECEPTORIMPORT)
{
return false;
}
return has_rec_id;
}
bool Result::ResultData::hasLigandConformationId() const
{
return has_lig_id;
}
bool Result::ResultData::hasEnergy() const
{
if (scoringmethod == LIGANDIMPORT || scoringmethod == RECEPTORIMPORT)
{
return false;
}
return has_energy;
}
bool Result::ResultData::hasScoringMethod() const
{
if (scoringmethod == LIGANDIMPORT || scoringmethod == RECEPTORIMPORT)
{
return false;
}
return has_method;
}
bool Result::ResultData::check() const
{
switch(resulttype)
{
case Result::DOCKING:
if (has_energy && has_lig_id && has_rec_id && has_method)
{
return true;
}
return false;
break;
case Result::LIGANDIMPORT:
if (has_lig_id)
return true;
return false;
break;
default:
return true;
}
}
void Result::ResultData::setConformation(Conformation* conf)
{
conformation = conf;
}
Conformation* Result::ResultData::getConformation()
{
return conformation;
}
const HashMap<String, vector<Result::ResultData> >* Result::getData()
{
return &result_data_;
}
}
|