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 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771
|
// $Id: testDepictor.cpp 1988 2012-03-06 04:36:59Z glandrum $
//
// Copyright (C) 2004-2010 Greg Landrum and Rational Discovery LLC
//
// @@ All Rights Reserved @@
// This file is part of the RDKit.
// The contents are covered by the terms of the BSD license
// which is included in the file license.txt, found at the root
// of the RDKit source tree.
//
#include <RDGeneral/Invariant.h>
#include <RDGeneral/RDLog.h>
#include <GraphMol/RDKitBase.h>
#include <string>
#include <iostream>
#include <GraphMol/FileParsers/MolWriters.h>
#include <GraphMol/FileParsers/FileParsers.h>
#include <GraphMol/FileParsers/MolSupplier.h>
#include <RDGeneral/FileParseException.h>
#include "RDDepictor.h"
#include "DepictUtils.h"
#include <GraphMol/SmilesParse/SmilesParse.h>
#include <GraphMol/Conformer.h>
#include <Geometry/point.h>
#include <Geometry/Transform3D.h>
#include <RDGeneral/utils.h>
#include <stdlib.h>
#include <boost/tokenizer.hpp>
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
using namespace RDKit;
void test1() {
//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C3)CCCC2C1C3CCC2 \
C12=CC=C3C(C4=C(C=CC=C5)C5=C3)C1C(C=C4)=CC=C2 \
C12CCCC3(CCCCC3)C1CCCC2 \
C1CCCC2(CC2)C1 C12C3C4C1C5C2C3C45 \
C2(C=C(C=C5)NC5=C4)=CC(C=C2)=CC1=CC=C(C=C3C=CC4=N3)N1";
*/
std::string rdbase = getenv("RDBASE");
std::string ofile = rdbase + "/Code/GraphMol/Depictor/test_data/test1.out.sdf";
SDWriter writer(ofile);
boost::char_separator<char> spaceSep(" ");
tokenizer tokens(smiString,spaceSep);
for(tokenizer::iterator token=tokens.begin();
token!=tokens.end();
++token){
std::string smi=*token;
RWMol *m = SmilesToMol(smi, 0, 1);
TEST_ASSERT(m)
RDDepict::compute2DCoords(*m);
writer.write(*m);
delete m;
}
}
void testCollisions() {
std::string smiString = "CN([CH](Cc3ccc(OS(c2cccc1c2ccnc1)(=O)=O)cc3)C(=O)N5CCN(c4ccccc4)CC5)S(c7cccc6c7ccnc6)(=O)=O \
CC(C)C12CCC(C)(CC1)CC2 \
CC(C)C1CCC2(CC)CCCC1CCC2 \
CC(OC1C(CCCC3)C3C(CCCC2)C2C1OC(C)=O)=O \
OC(=O)C1=C(C=CC=C1)C2=C3C=CC(=O)C(=C3OC4=C2C=CC(=C4Br)O)Br \
CC(CC(=O)OCC(F)(F)C(F)(F)C(F)(F)C(F)F)CC(=O)OCC(F)(F)C(F)(F)C(F)(F)C(F)F \
CC(C)(C)O[Si](OCC(F)(F)C(F)(F)C(F)(F)C(F)(F)C(F)(F)C(F)F)(OCC(F)(F)C(F)(F)C(F)(F)C(F)(F)C(F)(F)C(F)F)OC(C)(C)C \
CN2C3CC(OC(=O)C(CO)c1ccccc1)CC2CC3";
std::string rdbase = getenv("RDBASE");
std::string ofile = rdbase + "/Code/GraphMol/Depictor/test_data/collisions.out.sdf";
SDWriter writer(ofile);
boost::char_separator<char> spaceSep(" ");
tokenizer tokens(smiString,spaceSep);
for(tokenizer::iterator token=tokens.begin();
token!=tokens.end();
++token){
std::string smi=*token;
RWMol *m = SmilesToMol(smi, 0, 1);
TEST_ASSERT(m);
unsigned int confId = RDDepict::compute2DCoords(*m);
// check that there are no collisions in the molecules
const Conformer &conf = m->getConformer(confId);
int natms = m->getNumAtoms();
for (int i = 0; i < natms; i++) {
RDGeom::Point3D loci = conf.getAtomPos(i);
for (int j = i+1; j < natms; j++) {
RDGeom::Point3D locj = conf.getAtomPos(j);
locj -= loci;
CHECK_INVARIANT(locj.length() > 0.35, "");
}
}
writer.write(*m);
delete m;
}
}
void testAddHs() {
// test for issue 193
std::string smi = "F[C@H](Cl)Br";
RWMol *m = SmilesToMol(smi, 0, 1);
ROMol *m2 = MolOps::addHs(*m);
RDDepict::compute2DCoords(*m2);
delete m;
delete m2;
}
void testIssue198() {
std::string smi = "Cl.C[N+](C)(C)CCO";
RWMol *m = SmilesToMol(smi, 0, 1);
unsigned int confId = RDDepict::compute2DCoords(*m);
RDKit::ROMol::AtomIterator ai;
const Conformer &conf = m->getConformer(confId);
for (ai = m->beginAtoms(); ai != m->endAtoms(); ai++) {
RDGeom::Point3D loc = conf.getAtomPos((*ai)->getIdx());
CHECK_INVARIANT(loc.x < 100.0, "");
CHECK_INVARIANT(loc.y < 100.0, "");
CHECK_INVARIANT(loc.z < 100.0, "");
}
delete m;
}
void test2() {
std::string rdbase = getenv("RDBASE");
std::string smifile = rdbase + "/Code/GraphMol/Depictor/test_data/first_200.tpsa.csv";
SmilesMolSupplier smiSup(smifile, ",", 0, -1);
std::string ofile = rdbase + "/Code/GraphMol/Depictor/test_data/first_200.out.sdf";
SDWriter writer(ofile);
ROMol *mol;
while (1) {
try {
mol = smiSup.next();
std::string mname;
//wmol = static_cast<RWMol *>(mol);
RDDepict::compute2DCoords(*mol);
writer.write(*mol);
} catch (FileParseException &) {
break;
}
}
}
void test3() {
std::string rdbase = getenv("RDBASE");
std::string smifile = rdbase + "/Code/GraphMol/Depictor/test_data/cis_trans_cases.csv";
SmilesMolSupplier smiSup(smifile, ",", 0, 1);
std::string ofile = rdbase + "/Code/GraphMol/Depictor/test_data/cis_trans_cpp.out.sdf";
SDWriter writer(ofile);
ROMol *mol;
while (1) {
try {
mol = smiSup.next();
std::string mname;
//wmol = static_cast<RWMol *>(mol);
RDDepict::compute2DCoords(*mol);
writer.write(*mol);
} catch (FileParseException &) {
break;
}
}
}
void _compareCoords(const ROMol *mol1, unsigned int cid1,
const ROMol *mol2, unsigned int cid2,
double tol = 0.01) {
unsigned int nat = mol1->getNumAtoms();
CHECK_INVARIANT(nat == mol2->getNumAtoms(), "");
const RDKit::Conformer &conf1 = mol1->getConformer(cid1);
const RDKit::Conformer &conf2 = mol1->getConformer(cid2);
for (unsigned int i = 0; i < nat; i++) {
RDGeom::Point3D pt1 = conf1.getAtomPos(i);
RDGeom::Point3D pt2 = conf2.getAtomPos(i);
pt2 -= pt1;
CHECK_INVARIANT(fabs(pt2.x) < tol, "");
CHECK_INVARIANT(fabs(pt2.y) < tol, "");
//if ((fabs(pt2.x) >= tol) || (fabs(pt2.y) >= tol) ) {
// BOOST_LOG(rdInfoLog)<< pt1 << " " << pt2 << "\n";
//}
}
}
void test4() {
// test prespecified coordinates for various smiles
RDGeom::INT_POINT2D_MAP crdMap;
crdMap[0] = RDGeom::Point2D(3.52, 1.30); crdMap[1] = RDGeom::Point2D(2.77, 0.0);
crdMap[2] = RDGeom::Point2D(1.27, 0.0); crdMap[3] = RDGeom::Point2D(0.39, 1.21);
crdMap[4] = RDGeom::Point2D(-1.03, 0.75); crdMap[5] = RDGeom::Point2D(-1.03, -0.75);
crdMap[6] = RDGeom::Point2D(0.39, -1.21);
// self check
std::string smi = "Cl\\C=C1/SCCC1";
RWMol *m1 = SmilesToMol(smi, 0, 1);
unsigned int cid1 = RDDepict::compute2DCoords(*m1, &crdMap, false);
RWMol *mref = SmilesToMol(smi, 0, 1);
unsigned int cid2 = RDDepict::compute2DCoords(*mref);
MolToMolFile(*mref, "junk.mol");
//_compareCoords(m1, mref);
delete m1;
// now lets remove some of the coordinates
crdMap.erase(crdMap.find(3));
crdMap.erase(crdMap.find(4));
m1 = SmilesToMol(smi, 0, 1);
cid1 = RDDepict::compute2DCoords(*m1, &crdMap, false);
//MolToMolFile(m1, "junk.mol");
//_compareCoords(m1, mref);
delete m1;
//little bit more complicated
smi = "Cl\\C=C1/SCCC1(CC1CC1)";
m1 = SmilesToMol(smi, 0, 1);
cid1 = RDDepict::compute2DCoords(*m1, &crdMap, false);
//MolToMolFile(m1, "junk1.mol");
delete mref;
mref = SmilesToMol(smi, 0, 1);
RDDepict::compute2DCoords(*mref, 0, false);
_compareCoords(m1, cid1, mref, cid2);
delete m1;
// little more complicate we will specify coordinates from half of both the rings
crdMap[7] = RDGeom::Point2D(0.85, -2.64);
crdMap[8] = RDGeom::Point2D(-0.15, -3.75);
crdMap[9] = RDGeom::Point2D(-0.46, -5.22);
m1 = SmilesToMol(smi, 0, 1);
cid1 = RDDepict::compute2DCoords(*m1, &crdMap, false);
//MolToMolFile(m1, "junk1.mol");
//MolToMolFile(mref, "junk2.mol");
_compareCoords(m1, cid1, mref, cid2);
delete m1;
// one final test for a case we know is a pain
smi = "C1CCCC2(Cl)(CCCCCC12)";
crdMap.clear();
crdMap[0]=RDGeom::Point2D(-0.83,-3.12); crdMap[1]=RDGeom::Point2D(0.19,-4.22);
crdMap[2]=RDGeom::Point2D(1.66,-3.88); crdMap[3]=RDGeom::Point2D(2.10, -2.45);
crdMap[4]=RDGeom::Point2D(1.08,-1.35); crdMap[5]=RDGeom::Point2D(2.56, -1.12);
crdMap[6]=RDGeom::Point2D(1.73,0.00); crdMap[7]=RDGeom::Point2D(1.08, 1.35);
crdMap[8]=RDGeom::Point2D(-0.38,1.69); crdMap[9]=RDGeom::Point2D(-1.56, 0.75);
crdMap[10]=RDGeom::Point2D(-1.56,-0.75); crdMap[11]=RDGeom::Point2D(-0.38, -1.69);
delete mref;
mref = SmilesToMol(smi, 0, 1);
cid2 = RDDepict::compute2DCoords(*mref, 0, false);
crdMap.erase(crdMap.find(5));
//MolToMolFile(mref, "junk1.mol");
m1 = SmilesToMol(smi, 0, 1);
cid1 = RDDepict::compute2DCoords(*m1, &crdMap, false);
_compareCoords(m1, cid1, mref, cid2);
delete m1;
delete mref;
}
void tempTest() {
int i;
RDGeom::Point3D pt1, pt2, pt3;
double cosT, sinT;
RDGeom::Transform3D trans;
RDGeom::Point3D rotnAxis;
double dt;
for (i = 0; i < 100; i++) {
pt1.x = (double)(rand()%1000);
pt1.y = (double)(rand()%1000);
pt1.z = (double)(rand()%1000);
pt1.normalize();
pt2.x = (double)(rand()%1000);
pt2.y = (double)(rand()%1000);
pt2.z = (double)(rand()%1000);
pt2.normalize();
cosT = -pt1.dotProduct(pt2);
sinT = sqrt(1.0-cosT*cosT);
rotnAxis = pt1.crossProduct(pt2);
rotnAxis.normalize();
trans.setToIdentity();
trans.SetRotation(cosT,sinT, rotnAxis);
pt3 = pt2;
trans.TransformPoint(pt3);
dt = pt1.dotProduct(pt3);
if (fabs(dt + 1.0) > 1.0e-3) {
BOOST_LOG(rdInfoLog)<< i << " (" << pt1 << ") (" << pt2 << ") ("
<< pt3 << ") (" << rotnAxis << ") " << dt << "\n";
}
}
}
void testIssue248() {
std::string smiString = "OCC(=O)C1(O)[CH](O)C[CH]2[CH]3CCC4=CC(=O)C=CC4(C)C3(F)[CH](O)CC21C \
CC(C)[CH](OC(C)=O)c1nc2ccccc2c(=O)n1[CH]1CC2(OC1=O)c1c(cccc1)N1C(=O)C(C)(C)N(O)[CH]12 \
CC(CC(=O)OCC(F)(F)C(F)(F)C(F)(F)C(F)F)CC(=O)OCC(F)(F)C(F)(F)C(F)(F)C(F)F \
CC(O[CH]1C(=O)C2(C)[CH](O)C[CH]3OCC3(OC(C)=O)[CH]2[CH](OC(=O)c2ccccc2)C2(O)C[CH](OC([CH](O)[CH](NC(=O)c3ccccc3)c3ccccc3)=O)C(C)=C1C2(C)C)=O \
COc1c2O[CH]3[CH](O)C=C[CH]4C33CCN(C)[CH]4Cc(c32)cc1 \
CN1CCC23[CH]4Oc5c(O)ccc(c25)C[CH]1[CH]3C=C[CH]4O \
CN1C2CCC1C[CH](OC(=O)C(CO)c1ccccc1)C2 \
COC([CH]1C2CCC(C[CH]1OC(c1ccccc1)=O)N2C)=O \
OCC(=O)C1(O)[CH](O)C[CH]2[CH]3CCC4=CC(=O)C=CC4(C)C3(F)[CH](O)CC21C";
//COC12C3Oc4c(O)ccc5c4C33CCN(CC4CC4)[CH](C5)C3(C[CH]1C(O)(C)C(C)(C)C)CC2";
boost::char_separator<char> spaceSep(" ");
tokenizer tokens(smiString,spaceSep);
for(tokenizer::iterator token=tokens.begin();
token!=tokens.end();
++token){
std::string smi=*token;
RWMol *m = SmilesToMol(smi, 0, 1);
unsigned int confId = RDDepict::compute2DCoords(*m);
// check that there are no collisions in the molecules
int natms = m->getNumAtoms();
int i, j;
for (i = 0; i < natms; i++) {
const Conformer &conf = m->getConformer(confId);
RDGeom::Point3D loci = conf.getAtomPos(i);
for (j = i+1; j < natms; j++) {
RDGeom::Point3D locj = conf.getAtomPos(j);
locj -= loci;
if(locj.length()<=0.30){
std::cout << "mismatch: " << i << " " << j << " " << locj.length() << std::endl;
std::cout << "\t" << smi << std::endl;
std::cout << MolToMolBlock(*m,true,confId)<<std::endl;
}
CHECK_INVARIANT(locj.length() > 0.30, "");
}
}
delete m;
}
}
void testQueries() {
std::string smaString = "C[C,N] c1cc[c,n]cc1C";
boost::char_separator<char> spaceSep(" ");
tokenizer tokens(smaString,spaceSep);
for(tokenizer::iterator token=tokens.begin();
token!=tokens.end();
++token){
std::string sma=*token;
RWMol *m = SmartsToMol(sma);
unsigned int confId = RDDepict::compute2DCoords(*m);
// check that there are no collisions in the molecules
int natms = m->getNumAtoms();
int i, j;
for (i = 0; i < natms; i++) {
const Conformer &conf = m->getConformer(confId);
RDGeom::Point3D loci = conf.getAtomPos(i);
for (j = i+1; j < natms; j++) {
RDGeom::Point3D locj = conf.getAtomPos(j);
locj -= loci;
if(locj.length()<=0.30){
std::cout << "mismatch: " << i << " " << j << " " << locj.length() << std::endl;
std::cout << "\t" << sma << std::endl;
std::cout << MolToMolBlock(*m,true,confId)<<std::endl;
}
CHECK_INVARIANT(locj.length() > 0.30, "");
}
}
delete m;
}
}
void testRemoveHsCrash() {
std::string rdbase = getenv("RDBASE");
std::string molfile = rdbase + "/Code/GraphMol/Depictor/test_data/hs_crash.mol";
RWMol *m=MolFileToMol(molfile,true,false);
TEST_ASSERT(m);
ROMol *newM=MolOps::removeHs(*static_cast<ROMol *>(m));
delete m;
unsigned int confId = RDDepict::compute2DCoords(*newM);
TEST_ASSERT(confId>=0);
delete newM;
}
void testIssue2091304() {
// the problem here was a crash, so just finishing is success.
RDGeom::INT_POINT2D_MAP crdMap;
crdMap[0] = RDGeom::Point2D(0., 1.50);
std::string smi = "COC";
RWMol *m1 = SmilesToMol(smi);
RDDepict::compute2DCoords(*m1, &crdMap, false);
delete m1;
}
void testIssue2303566() {
RDGeom::INT_POINT2D_MAP crdMap;
crdMap[0]=RDGeom::Point2D(0.0781827, -0.112109);
crdMap[1]=RDGeom::Point2D(1.13205, -0.415657);
crdMap[2]=RDGeom::Point2D(0.676323, -1.51974);
crdMap[3]=RDGeom::Point2D(0.735363, -2.62024);
crdMap[4]=RDGeom::Point2D(0.974216, -1.5726);
crdMap[5]=RDGeom::Point2D(1.02041, -1.56945);
std::string mb = "\n\
RDKit 2D\n\
\n\
6 7 0 0 0 0 0 0 0 0999 V2000\n\
0.0782 -0.1121 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n\
1.1321 -0.4157 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n\
0.6763 -1.5197 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n\
0.7354 -2.6202 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n\
1.0098 -1.5757 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0\n\
1.0218 -1.5749 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n\
1 2 1 0\n\
1 3 1 0\n\
3 2 1 0\n\
3 4 1 0\n\
5 6 2 0\n\
2 4 1 0\n\
1 4 1 0\n\
M END\n";
RWMol *m1 = MolBlockToMol(mb);
// in the original bug, this led to a crash, so just having it complete
// means the test passed.
unsigned int cid1 = RDDepict::compute2DCoords(*m1, &crdMap, false);
TEST_ASSERT(cid1>=0);
delete m1;
}
void testIssue2821647() {
{
std::string smi = "CCCCC";
RWMol *m1 = SmilesToMol(smi);
unsigned int cid1 = RDDepict::compute2DCoords(*m1,0,true);
double xx=0,yy=0;
for (unsigned int i = 0; i < m1->getNumAtoms(); i++) {
const Conformer &conf = m1->getConformer(cid1);
RDGeom::Point3D loci = conf.getAtomPos(i);
xx+=loci.x*loci.x;
yy+=loci.y*loci.y;
}
TEST_ASSERT(xx>yy);
delete m1;
}
{
std::string smi = "c1ccccc1CCCCCC1CC1";
RWMol *m1 = SmilesToMol(smi);
unsigned int cid1 = RDDepict::compute2DCoords(*m1,0,true);
double xx=0,yy=0;
for (unsigned int i = 0; i < m1->getNumAtoms(); i++) {
const Conformer &conf = m1->getConformer(cid1);
RDGeom::Point3D loci = conf.getAtomPos(i);
xx+=loci.x*loci.x;
yy+=loci.y*loci.y;
}
TEST_ASSERT(xx>yy);
delete m1;
}
{
std::string smi = "c1ccc2c(c1)oc1c3ccccc3oc21";
RWMol *m1 = SmilesToMol(smi);
unsigned int cid1 = RDDepict::compute2DCoords(*m1,0,true);
double xx=0,yy=0;
for (unsigned int i = 0; i < m1->getNumAtoms(); i++) {
const Conformer &conf = m1->getConformer(cid1);
RDGeom::Point3D loci = conf.getAtomPos(i);
xx+=loci.x*loci.x;
yy+=loci.y*loci.y;
}
TEST_ASSERT(xx>yy);
delete m1;
}
{
std::string smi = "[H]n1c2ccccc2c2n([H])c3ccccc3c12";
RWMol *m1 = SmilesToMol(smi);
unsigned int cid1 = RDDepict::compute2DCoords(*m1,0,true);
double xx=0,yy=0;
for (unsigned int i = 0; i < m1->getNumAtoms(); i++) {
const Conformer &conf = m1->getConformer(cid1);
RDGeom::Point3D loci = conf.getAtomPos(i);
xx+=loci.x*loci.x;
yy+=loci.y*loci.y;
}
TEST_ASSERT(xx>yy);
delete m1;
}
}
void testIssue2948402() {
{
std::string smi = "C1C2CC3=CC=CC(C2)CC(O3)C1";
RWMol *m1 = SmilesToMol(smi);
unsigned int cid1 = RDDepict::compute2DCoords(*m1,0,true);
TEST_ASSERT(cid1>=0);
delete m1;
}
}
void testIssue2995724() {
{
// the original problem from Thomas Heller:
std::string smi = "OC(=O)[C@@H]1CCCN1";
RWMol *m1 = SmilesToMol(smi);
unsigned int cid1 = RDDepict::compute2DCoords(*m1,0,true);
const Conformer &conf = m1->getConformer(cid1);
for (unsigned int i = 0; i < m1->getNumAtoms(); i++) {
RDGeom::Point3D loci = conf.getAtomPos(i);
// we're testing for NaNs here:
TEST_ASSERT(loci.x>-5.0);
TEST_ASSERT(loci.x<5.0);
TEST_ASSERT(loci.y>-5.0);
TEST_ASSERT(loci.y<5.0);
}
delete m1;
}
{
// additional test cases from Kirk DeLisle:
std::string smis[]={"CCC(N1CCN(CC1)C(CC)O)O.Cl[Pt](Cl)(Cl)(Cl)(Cl)Cl",
"CN(C)S(=O)(=O)N1CCN(CC1)S(=O)(=O)N(C)C",
"Cc1ccc(cc1C)Nc2nc(nc(n2)N)CN3CCN(CC3)C",
"CC1(OC(=C(C(=O)O1)C2=NCCC2)O)C"};
for(unsigned int j=0;j<4;j++){
RWMol *m1 = SmilesToMol(smis[j]);
unsigned int cid1 = RDDepict::compute2DCoords(*m1,0,true);
const Conformer &conf = m1->getConformer(cid1);
for (unsigned int i = 0; i < m1->getNumAtoms(); i++) {
RDGeom::Point3D loci = conf.getAtomPos(i);
TEST_ASSERT(loci.x>-7.0);
TEST_ASSERT(loci.x<7.0);
TEST_ASSERT(loci.y>-6.0);
TEST_ASSERT(loci.y<6.0);
}
delete m1;
}
}
}
void testBondLengthChange() {
{
std::string smi = "CC";
RWMol *m1 = SmilesToMol(smi);
unsigned int cid1 = RDDepict::compute2DCoords(*m1,0,true);
const Conformer &conf = m1->getConformer(cid1);
TEST_ASSERT(feq(conf.getAtomPos(0).x,-0.75));
TEST_ASSERT(feq(conf.getAtomPos(1).x,0.75));
delete m1;
}
{
std::string smi = "CC";
RWMol *m1 = SmilesToMol(smi);
RDDepict::BOND_LEN=1.0;
unsigned int cid1 = RDDepict::compute2DCoords(*m1,0,true);
const Conformer &conf = m1->getConformer(cid1);
TEST_ASSERT(feq(conf.getAtomPos(0).x,-0.5));
TEST_ASSERT(feq(conf.getAtomPos(1).x,0.5));
delete m1;
}
}
void testIssue3122141() {
{
std::string smi = "ClC1=C(Cl)C2(Cl)C3C(Cl)C=CC3C1(Cl)C2(Cl)Cl";
RWMol *m1 = SmilesToMol(smi);
RDGeom::INT_POINT2D_MAP crdMap;
crdMap[1]=RDGeom::Point2D(1.0,2.0);
unsigned int cid1 = RDDepict::compute2DCoords(*m1, &crdMap, false);
TEST_ASSERT(cid1>=0);
delete m1;
}
}
void testIssue3135833() {
{
std::string smi = "N#CC(/C=[N+](/c1cccnc1)c1c2cc(C(=O)c3ncsc3-c3cccnc3)ccc2ccc1)=C(/[NH3+])[S-]";
RWMol *m1 = SmilesToMol(smi);
TEST_ASSERT(m1);
RDGeom::INT_POINT2D_MAP crdMap;
crdMap[32]=RDGeom::Point2D(-2.8518,1.0270);
crdMap[33]=RDGeom::Point2D(-2.7999,-0.4721);
crdMap[4]=RDGeom::Point2D(-1.4239,-2.6758);
crdMap[11]=RDGeom::Point2D(-1.4757,-1.1767);
crdMap[12]=RDGeom::Point2D(-0.2034,-0.3823);
crdMap[13]=RDGeom::Point2D(1.1208,-1.0869);
crdMap[14]=RDGeom::Point2D(2.3931,-0.2924);
crdMap[15]=RDGeom::Point2D(3.7173,-0.9971);
crdMap[28]=RDGeom::Point2D(2.3412,1.2067);
crdMap[29]=RDGeom::Point2D(1.0170,1.9113);
crdMap[30]=RDGeom::Point2D(-0.2553,1.1168);
crdMap[31]=RDGeom::Point2D(-1.5795,1.8215);
unsigned int cid1 = RDDepict::compute2DCoords(*m1, &crdMap, false);
TEST_ASSERT(cid1>=0);
delete m1;
}
}
void testIssue3487469() {
{
std::string smi = "C*C";
RWMol *m1 = SmilesToMol(smi);
TEST_ASSERT(m1);
TEST_ASSERT(m1->getAtomWithIdx(1)->getHybridization()==Atom::UNSPECIFIED);
unsigned int cid1 = RDDepict::compute2DCoords(*m1,0,true);
const Conformer &conf = m1->getConformer(cid1);
RDGeom::Point3D p0 = conf.getAtomPos(0);
RDGeom::Point3D p1 = conf.getAtomPos(1);
RDGeom::Point3D p2 = conf.getAtomPos(2);
RDGeom::Point3D v1=p0-p1,v2=p2-p1;
v1.normalize();
v2.normalize();
TEST_ASSERT(feq(v1.dotProduct(v2),-0.5,.01))
delete m1;
}
}
int main() {
RDLog::InitLogs();
#if 1
BOOST_LOG(rdInfoLog)<< "***********************************************************\n";
BOOST_LOG(rdInfoLog)<< " test1 \n";
test1();
BOOST_LOG(rdInfoLog)<< "***********************************************************\n\n";
BOOST_LOG(rdInfoLog)<< "***********************************************************\n";
BOOST_LOG(rdInfoLog)<< " testCollisions \n";
testCollisions();
BOOST_LOG(rdInfoLog)<< "***********************************************************\n\n";
BOOST_LOG(rdInfoLog)<< "***********************************************************\n";
BOOST_LOG(rdInfoLog)<< " testAddHs \n";
testAddHs();
BOOST_LOG(rdInfoLog)<< "***********************************************************\n\n";
BOOST_LOG(rdInfoLog)<< "***********************************************************\n";
BOOST_LOG(rdInfoLog)<< " test198 \n";
testIssue198();
BOOST_LOG(rdInfoLog)<< "***********************************************************\n\n";
BOOST_LOG(rdInfoLog)<< "***********************************************************\n";
BOOST_LOG(rdInfoLog)<< " test2 \n";
test2();
BOOST_LOG(rdInfoLog)<< "***********************************************************\n";
BOOST_LOG(rdInfoLog)<< "***********************************************************\n";
BOOST_LOG(rdInfoLog)<< " test3 \n";
test3();
BOOST_LOG(rdInfoLog)<< "***********************************************************\n";
BOOST_LOG(rdInfoLog)<< "***********************************************************\n";
BOOST_LOG(rdInfoLog)<< " test4 \n";
test4();
BOOST_LOG(rdInfoLog)<< "***********************************************************\n";
BOOST_LOG(rdInfoLog)<< "***********************************************************\n";
BOOST_LOG(rdInfoLog)<< " tempTest \n";
tempTest();
BOOST_LOG(rdInfoLog)<< "***********************************************************\n";
BOOST_LOG(rdInfoLog)<< "***********************************************************\n";
BOOST_LOG(rdInfoLog)<< " Issue248 \n";
testIssue248();
BOOST_LOG(rdInfoLog)<< "***********************************************************\n";
BOOST_LOG(rdInfoLog)<< "***********************************************************\n";
BOOST_LOG(rdInfoLog)<< " Test Queries \n";
testQueries();
BOOST_LOG(rdInfoLog)<< "***********************************************************\n";
BOOST_LOG(rdInfoLog)<< "***********************************************************\n";
BOOST_LOG(rdInfoLog)<< " Test crashes associated with RemoveHs \n";
testRemoveHsCrash();
BOOST_LOG(rdInfoLog)<< "***********************************************************\n";
BOOST_LOG(rdInfoLog)<< "***********************************************************\n";
BOOST_LOG(rdInfoLog)<< " Test Issue 2091304\n";
testIssue2091304();
BOOST_LOG(rdInfoLog)<< "***********************************************************\n";
BOOST_LOG(rdInfoLog)<< "***********************************************************\n";
BOOST_LOG(rdInfoLog)<< " Test Issue 2303566\n";
testIssue2303566();
BOOST_LOG(rdInfoLog)<< "***********************************************************\n";
BOOST_LOG(rdInfoLog)<< "***********************************************************\n";
BOOST_LOG(rdInfoLog)<< " Test Issue 2821647\n";
testIssue2821647();
BOOST_LOG(rdInfoLog)<< "***********************************************************\n";
BOOST_LOG(rdInfoLog)<< "***********************************************************\n";
BOOST_LOG(rdInfoLog)<< " Test Issue 2948402\n";
testIssue2948402();
BOOST_LOG(rdInfoLog)<< "***********************************************************\n";
BOOST_LOG(rdInfoLog)<< "***********************************************************\n";
BOOST_LOG(rdInfoLog)<< " Test Issue 2995724\n";
testIssue2995724();
BOOST_LOG(rdInfoLog)<< "***********************************************************\n";
BOOST_LOG(rdInfoLog)<< "***********************************************************\n";
BOOST_LOG(rdInfoLog)<< " Testing a change of the depictor bond length\n";
testBondLengthChange();
BOOST_LOG(rdInfoLog)<< "***********************************************************\n";
BOOST_LOG(rdInfoLog)<< "***********************************************************\n";
BOOST_LOG(rdInfoLog)<< " Test Issue 3122141\n";
testIssue3122141();
BOOST_LOG(rdInfoLog)<< "***********************************************************\n";
#endif
BOOST_LOG(rdInfoLog)<< "***********************************************************\n";
BOOST_LOG(rdInfoLog)<< " Test Issue 3135833\n";
testIssue3135833();
BOOST_LOG(rdInfoLog)<< "***********************************************************\n";
BOOST_LOG(rdInfoLog)<< "***********************************************************\n";
BOOST_LOG(rdInfoLog)<< " Test Issue 3487469\n";
testIssue3487469();
BOOST_LOG(rdInfoLog)<< "***********************************************************\n";
return(0);
}
|