-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.cpp
1293 lines (1116 loc) · 33.9 KB
/
main.cpp
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
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Pharmit
Copyright (c) David Ryan Koes, University of Pittsburgh and contributors.
All rights reserved.
Pharmit is licensed under both the BSD 3-clause license and the GNU
Public License version 2. Any use of the code that retains its reliance
on the GPL-licensed OpenBabel library is subject to the terms of the GPL2.
Use of the Pharmit code independently of OpenBabel (or any other
GPL2 licensed software) may choose between the BSD or GPL licenses.
See the LICENSE file provided with the distribution for more information.
*/
/*
* main.cpp
*
* Created on: Sep 12, 2011
* Author: dkoes
The goal of this project is to efficiently store molecular shapes within
a GSS-tree index for fast (and exact) similarity searching
http://dx.doi.org/10.1145/304181.304219
At some point I intend to properly break this out into a library for generic
shape handling, but at the moment everything assumes we are performing
molecular shape matching.
*/
#include <iostream>
#include <string>
#include "GSSTypes.h"
#include "boost/array.hpp"
#include "CommandLine2/CommandLine.h"
#include "GSSTreeCreator.h"
#include "GSSTreeSearcher.h"
#include "molecules/Molecule.h"
#include "KSamplePartitioner.h"
#include "packers/Packers.h"
#include "Timer.h"
#include "MiraObject.h"
using namespace std;
using namespace boost;
typedef shared_ptr<Packer> PackerPtr;
enum CommandEnum
{
Create,
MiraSearch,
DCMiraSearch,
NNSearch,
DCSearch,
MolGrid,
MergeMira,
BatchSearch,
BatchMiraSearch,
BatchDB,
SearchAllPointCombos,
CreateTrees,
CreateFromTrees,
CreateFromMira
};
cl::opt<CommandEnum> Command(cl::desc("Operation to perform:"), cl::Required,
cl::values(clEnumVal(Create, "Create a molecule shape index."),
clEnumVal(CreateTrees,"Create only the shapes with no index."),
clEnumVal(CreateFromTrees,"Create an index from already created shapes."),
clEnumVal(CreateFromMira,"Create an index from already created shapes."),
clEnumVal(MiraSearch, "Nearest neighbor searching of mira objects"),
clEnumVal(DCMiraSearch, "Distance constraint searching of mira objects"),
clEnumVal(NNSearch, "Nearest neighbor search"),
clEnumVal(DCSearch, "Distance constraint search"),
clEnumVal(MolGrid, "Generate molecule grid and debug output"),
clEnumVal(MergeMira, "Merge mira files into MIV/MSV"),
clEnumVal(BatchSearch, "Read in a jobs file for batch processing"),
clEnumVal(BatchMiraSearch, "Read in a mira jobs file for batch processing"),
clEnumVal(BatchDB, "Read in a jobs file for batch processing of a list of directories"),
clEnumVal(SearchAllPointCombos, "Search using all possible subsets of interaction points"),
clEnumValEnd));
cl::opt<bool> NNSearchAll("nn-search-all",
cl::desc(
"Perform exhaustive interaction point search with NNSearch as well as DCSearch"),
cl::init(false));
enum PackerEnum
{
FullMerge, Spectral, GreedyMerge, MatchPack
};
cl::opt<PackerEnum> PackerChoice(cl::desc("Packing algorithm:"),
cl::values(clEnumValN(FullMerge,"full-merge", "Greedy full merge."),
clEnumValN(GreedyMerge,"greedy-merge", "Greedy iterative merge."),
clEnumValN(MatchPack,"match-merge", "Optimal matching merging."),
clEnumValN(Spectral, "spectral", "Spectral packing"),
clEnumValEnd), cl::init(MatchPack));
cl::opt<unsigned> K("k", cl::desc("k nearest neighbors to find for NNSearch"),
cl::init(1));
cl::opt<double> NNThreshold("nn-threshold",cl::desc("Similarity cutoff for NNSearch"), cl::init(HUGE_VAL));
cl::opt<unsigned> Knn("knn", cl::desc("K for knn graph creation"), cl::init(8));
cl::opt<unsigned> Sentinals("sentinals",
cl::desc("Number of sentinals for knn initialization (zero random)"),
cl::init(32));
cl::opt<SpectralPacker::SpectralAlgEnum> SpectralAlg(
cl::desc("Spectral packing sub-algorithm:"),
cl::values(
clEnumValN(SpectralPacker::SortDense, "sort-dense", "Simple sort followed by dense packing"),
clEnumValN(SpectralPacker::SortPartition, "sort-partition", "Simple sort followed by largest separator partition packing"),
clEnumValN(SpectralPacker::ClusterFullEigen, "cluster-eigen", "Cluster eigen values using greedy packer"),
clEnumValN(SpectralPacker::RelaxationPacking, "relax", "Cluster form relaxation values"),
clEnumValEnd), cl::init(SpectralPacker::SortDense));
cl::opt<bool> ScanCheck("scancheck",
cl::desc("Perform a full scan to check results"), cl::Hidden);
cl::opt<bool> ScanOnly("scanonly", cl::desc("Search using only a scan"),
cl::Hidden);
cl::opt<bool> SingleConformer("single-conformer",
cl::desc("Output the single best conformer"), cl::init(false));
cl::opt<string> Input("in", cl::desc("Input file"));
cl::opt<string> Output("out", cl::desc("Output file"));
cl::opt<string> Database("db", cl::desc("Database file"));
cl::list<string> Files("files",cl::desc("Files for MiraMerge"));
cl::opt<double> LessDist("less",
cl::desc(
"Distance to reduce query mol by for constraint search (default 1A)."),
cl::init(1.0));
cl::opt<double> MoreDist("more",
cl::desc(
"Distance to increase query mol by for constraint search (default 1A)."),
cl::init(1.0));
cl::opt<double> ProbeRadius("probe-radius",
cl::desc("Radius of water probe for exmol only"), cl::init(1.4));
cl::opt<double> MaxDimension("max-dim", cl::desc("Maximum dimension."),
cl::init(64));
cl::opt<double> Resolution("resolution",
cl::desc("Best resolution for shape database creation."), cl::init(.5));
cl::opt<string> IncludeMol("ligand",
cl::desc("Molecule to use for minimum included volume"));
cl::opt<string> ExcludeMol("receptor",
cl::desc("Molecule to use for excluded volume"));
cl::opt<string> MIVShape("mira-miv", cl::desc("Mira shape to use for minimum included volume"));
cl::opt<string> MSVShape("mira-msv", cl::desc("Mira shape to use for maximum surrounding volume"));
cl::opt<bool> useInteractionPoints("use-interaction-points",
cl::desc(
"Analyze the ligand-receptor complex and generate a minimum shape centered around different interaction points."),
cl::init(false));
cl::opt<double> interactionPointRadius("interaction-point-radius",
cl::desc("Amount to grow interaction points into ligand shape."),
cl::init(0));
cl::opt<double> interactionDistance("interaction-distance",
cl::desc(
"Distance between ligand/receptor atom centers that are considered interacting"),
cl::init(6));
cl::opt<double> interactionMinCluster("interaction-min-cluster",
cl::desc("Minimum size of interaction point cluster."), cl::init(3));
cl::opt<double> interactionMaxClusterDist("interaction-max-cluster-dist",
cl::desc("Maximum span of interaction point cluster."), cl::init(4));
cl::opt<unsigned> KCenters("kcenters",
cl::desc("number of centers for ksample-split"), cl::init(8));
cl::opt<unsigned> KSampleMult("ksamplex",
cl::desc("multiplictive factor for ksampling"), cl::init(5));
cl::opt<unsigned> SwitchToPack("switch-to-pack",
cl::desc("Cutoff to trigger packing in nodes and leaves"),
cl::init(32768));
cl::opt<unsigned> Pack("pack", cl::desc("Maximum quantities per a node"),
cl::init(16));
cl::opt<bool> Print("print",cl::desc("Print text summary of output"),cl::init(false));
cl::opt<bool> Verbose("v", cl::desc("Verbose output"));
cl::opt<bool> UseUnnorm("use-unnorm",
cl::desc("Use unnormalized laplacian in spectral packing"),
cl::init(false));
cl::opt<Packer::ClusterDistance> ClusterDist(
cl::desc("Metric for cluster packing distance:"),
cl::values(
clEnumValN(Packer::AverageLink, "ave-dist", "Use 'average' metric between MIV/MSV representations of clusters"),
clEnumValN(Packer::CompleteLink, "complete-dist", "Use complete linkage value between cluster members"),
clEnumValN(Packer::SingleLink, "single-dist", "Use single linkage value between cluster members"),
clEnumValN(Packer::TotalLink, "total-dist", "Use total (sum) linkage value between cluster members"),
clEnumValEnd), cl::init(Packer::AverageLink));
cl::opt<DistanceFunction> ShapeDist(
cl::desc("Metric for distance between shapes:"),
cl::values(
clEnumValN(RelativeVolume,"rel-volume","Relative volume difference"),
clEnumValN(AbsVolume,"abs-volume", "Absolute volume difference"),
clEnumValN(Hausdorff,"hausdorff", "Hausdorff distance"),
clEnumValN(RelativeTriple, "rel-triple", "Triple including selectivity"),
clEnumValN(AbsoluteTriple, "abs-triple", "Triple including selectivity (absolute)"),
clEnumValN(IncludeExclude, "include-exclude","For comparing with include/exclude constraints"),
clEnumValN(RelVolExclude, "relvol-exclude","Volume comparison of ligand, exclusion comparison of receptor"),
clEnumValEnd), cl::init(RelativeVolume));
cl::opt<unsigned> SuperNodeDepth("superdepth",
cl::desc("Depth to descend to create aggregrated super root"),
cl::init(0));
cl::opt<unsigned> TimeTrials("time-trials",
cl::desc("Number of runs to get average for benchmarking"),
cl::init(1));
cl::opt<bool> ClearCache("clear-cache",
cl::desc("Clear file cache between each benchmarking run"),
cl::init(false));
cl::opt<bool> ClearCacheFirst("clear-cache-first",
cl::desc("Clear file cache before each benchmarking run"),
cl::init(false));
cl::opt<string> SproxelColor("sproxel-color",
cl::desc("Sproxel voxel descriptor"), cl::init("#0000ffff"));
cl::opt<bool> KeepHydrogens("h",
cl::desc("Retain hydrogens in input molecules"), cl::init(false));
typedef GSSTreeSearcher::ObjectTree ObjectTree;
//create min and max trees from molecular data
//caller takes owner ship of tree memory
static void create_trees(GSSTreeSearcher& gss, const string& includeMol,
const string& excludeMol, double less, double more,
GSSTreeSearcher::ObjectTree& smallTree,
GSSTreeSearcher::ObjectTree& bigTree)
{
double dimension = gss.getDimension();
double resolution = gss.getResolution();
//read query molecule(s)
//use explicit volumes
Molecule::iterator imolitr(includeMol, dimension, resolution, KeepHydrogens,
ProbeRadius);
Molecule inMol = *imolitr;
Molecule exMol;
if(filesystem::path(excludeMol).extension() != ".mira")
{
Molecule::iterator exmolitr(excludeMol, dimension, resolution,
KeepHydrogens, ProbeRadius);
exMol = *exmolitr;
//create trees
//receptor constraint, shrink by more and invert
bigTree = gss.createTreeFromObject(exMol, more, excludeMol.size() > 0 ); //if exclude empty, make don't invert
}
else //is mira object, don't need to compute grid
{
MiraObject obj;
ifstream mirain(excludeMol.c_str());
obj.read(mirain);
bigTree = gss.createTreeFromObject(obj, more, true);
}
//use the full shape of the ligand
smallTree = gss.createTreeFromObject(inMol, less);
if (useInteractionPoints)
{
//change small tree to just be interaction points
MGrid igrid(dimension, resolution);
inMol.computeInteractionGridPoints(exMol.getMol(), igrid, interactionDistance,
interactionMaxClusterDist, interactionMinCluster,
interactionPointRadius);
MGrid lgrid;
smallTree->makeGrid(lgrid, resolution);
lgrid &= igrid;
smallTree = shared_ptr<const MappableOctTree>(
MappableOctTree::createFromGrid(lgrid), free);
}
}
//do search between include and exclude
static void do_dcsearch(GSSTreeSearcher& gss, ObjectTree smallTree,
ObjectTree bigTree, const string& output)
{
ResultMolecules res(SingleConformer);
bool getres = output.size() > 0 || Print;
//search
if (!ScanOnly)
gss.dc_search(smallTree, bigTree, ObjectTree(), getres, res);
if (ScanCheck || ScanOnly)
{
ResultMolecules res2(SingleConformer);
gss.dc_scan_search(smallTree, bigTree, ObjectTree(), getres, res2);
if (res2.size() != res.size())
{
cerr << "Scanning found different number: " << res2.size() << "\n";
}
}
res.writeOutput(output, Print);
}
void do_nnsearch(GSSTreeSearcher& gss, const string& input,
const string& output, unsigned k, double thresh)
{
//read query molecule(s)
ResultMolecules res(SingleConformer);
Molecule::iterator molitr(input, gss.getDimension(), gss.getResolution(),
KeepHydrogens, ProbeRadius);
bool getresults = output.size() > 0 || Print;
for (; molitr; ++molitr)
{
const Molecule& mol = *molitr;
ObjectTree objTree = gss.createTreeFromObject(mol);
if (k < 1 && !isfinite(thresh)) //scan
{
gss.nn_scan(objTree, getresults, res);
}
else
{
gss.nn_search(objTree, k, thresh, getresults, res);
}
}
res.writeOutput(output, Print);
}
struct QInfo
{
string str;
CommandEnum cmd;
Molecule in;
Molecule ex;
unsigned k;
double less;
double more;
QInfo() :
cmd(Create), k(1), less(0), more(0)
{
}
QInfo(const string& s, const Molecule& i, const Molecule& e, double l,
double m) :
str(s), cmd(DCSearch), in(i), ex(e), less(l), more(m)
{
}
QInfo(const string& s, const Molecule& i, unsigned _k) :
str(s), cmd(NNSearch), in(i), k(_k)
{
}
};
//attempt to clear the file system cache,
//this is just for benchmarking purposes and requires the existance of clearfilecache
//which is a setuid (gasp) program I wrote that does precisely that
static void clear_cache()
{
#pragma GCC diagnostic ignored "-Wunused-result"
std::system("clearfilecache");
}
static void dumpTree(MappableOctTree *tree, ostream& out)
{
cout << "Size of tree " << tree->bytes() << "\n";
cout << "Volume of tree " << tree->volume() << "\n";
cout << "Nodes of tree " << tree->nodes() << "\n";
vector<unsigned> cnts;
tree->countLeavesAtDepths(cnts);
for (unsigned i = 0, n = cnts.size(); i < n; i++)
{
cout << i << " : " << cnts[i] << "\n";
}
if (out)
{
if (filesystem::extension(Output.c_str()) == ".raw")
tree->dumpRawGrid(out, Resolution);
if (filesystem::extension(Output.c_str()) == ".map")
tree->dumpAD4Grid(out, Resolution);
else if (filesystem::extension(Output.c_str()) == ".mira")
tree->dumpMiraGrid(out, Resolution);
else if (filesystem::extension(Output.c_str()) == ".csv")
tree->dumpSproxelGrid(out, Resolution, SproxelColor);
else
tree->dumpGrid(out, Resolution);
}
}
int main(int argc, char *argv[])
{
cl::ParseCommandLineOptions(argc, argv);
bool getres = Output.size() > 0 || Print;
switch (Command)
{
case Create:
case CreateFromTrees:
case CreateFromMira:
{
//read in all the molecules and calculate the max bounding box
KSamplePartitioner topdown(KCenters, KSampleMult,
KSamplePartitioner::AveCenter, SwitchToPack);
PackerPtr packer;
switch (PackerChoice)
{
case FullMerge:
packer = PackerPtr(
new FullMergePacker(Pack, ClusterDist, Knn, Sentinals));
break;
case MatchPack:
packer = PackerPtr(
new MatcherPacker(Pack, Knn, Sentinals, ClusterDist));
break;
case GreedyMerge:
packer = PackerPtr(
new GreedyPacker(Pack, ClusterDist, Knn, Sentinals));
break;
case Spectral:
packer = PackerPtr(
new SpectralPacker(Pack, SpectralAlg, !UseUnnorm));
break;
}
setDistance(ShapeDist);
GSSLevelCreator leveler(&topdown, packer.get(), SwitchToPack,
SwitchToPack);
GSSTreeCreator creator(&leveler, SuperNodeDepth);
filesystem::path dbpath(Database.c_str());
if (Command == Create)
{
Molecule::iterator molitr(Input, MaxDimension, Resolution,
KeepHydrogens, ProbeRadius);
if (!creator.create<Molecule, Molecule::iterator>(dbpath, molitr,
MaxDimension, Resolution))
{
cerr << "Error creating database\n";
exit(1);
}
}
else if (Command == CreateFromMira)
{
MiraObject::iterator miraitr(Input);
if (!creator.create<MiraObject, MiraObject::iterator>(dbpath,
miraitr, MaxDimension, Resolution))
{
cerr << "Error creating database\n";
exit(1);
}
}
else if (Command == CreateFromTrees) //trees already created
{
filesystem::path treedir(Input.c_str());
if (!creator.create(dbpath, treedir, MaxDimension, Resolution))
{
cerr << "Error creating database\n";
exit(1);
}
}
if (Verbose)
creator.printStats(cout);
}
break;
case CreateTrees:
{
//read in all the molecules and calculate the max bounding box
KSamplePartitioner topdown(KCenters, KSampleMult,
KSamplePartitioner::AveCenter, SwitchToPack);
PackerPtr packer = PackerPtr(
new MatcherPacker(Pack, Knn, Sentinals, ClusterDist));
setDistance(ShapeDist);
GSSLevelCreator leveler(&topdown, packer.get(), SwitchToPack,
SwitchToPack);
GSSTreeCreator creator(&leveler, SuperNodeDepth);
filesystem::path dbpath(Database.c_str());
Molecule::iterator molitr(Input, MaxDimension, Resolution,
KeepHydrogens, ProbeRadius);
if (!creator.createTreesOnly<Molecule, Molecule::iterator>(dbpath,
molitr, MaxDimension, Resolution))
{
cerr << "Error creating database\n";
exit(1);
}
}
break;
case MiraSearch:
{
//read in database
filesystem::path dbfile(Database.c_str());
GSSTreeSearcher gss(Verbose);
if (!gss.load(dbfile))
{
cerr << "Could not read database " << Database << "\n";
exit(-1);
}
setDistance(ShapeDist);
ifstream mirain(Input.c_str());
MiraObject obj;
obj.read(mirain);
StringResults res;
ObjectTree objTree = gss.createTreeFromObject(obj);
if (K < 1) //scan
{
gss.nn_scan(objTree, true, res);
}
else
{
gss.nn_search(objTree, K, HUGE_VAL, true, res);
}
for (unsigned i = 0, n = res.size(); i < n; i++)
{
cout << i << "\t" << res.getString(i) << "\t" << res.getScore(i)
<< "\n";
}
}
break;
case DCMiraSearch:
{
//read in database
filesystem::path dbfile(Database.c_str());
GSSTreeSearcher gss(Verbose);
if (!gss.load(dbfile))
{
cerr << "Could not read database " << Database << "\n";
exit(-1);
}
setDistance(ShapeDist);
double resolution = gss.getResolution();
setDistance(ShapeDist);
StringResults res;
ObjectTree objTree;
ObjectTree smallTree, bigTree;
if(Input.size() > 0)
{
ifstream mirain(Input.c_str());
MiraObject obj;
obj.read(mirain);
objTree = gss.createTreeFromObject(obj);
}
//search with passed shapes, does not invert exclude
if (MSVShape.size() > 0 && MIVShape.size() > 0)
{
MiraObject miv, msv;
ifstream mivin(MIVShape.c_str());
ifstream msvin(MSVShape.c_str());
miv.read(mivin);
msv.read(msvin);
smallTree = gss.createTreeFromObject(miv);
bigTree = gss.createTreeFromObject(msv);
}
else if(MSVShape.size() > 0 || MIVShape.size() > 0)
{
cerr << "Error, need to specify both MIV and MSV\n";
exit(-1);
}
else //base off of query shape
{
MGrid smallgrid, biggrid;
objTree->makeGrid(smallgrid, resolution);
biggrid = smallgrid;
smallgrid.shrink(LessDist);
biggrid.grow(MoreDist);
smallTree = ObjectTree(
MappableOctTree::createFromGrid(smallgrid));
bigTree = ObjectTree(
MappableOctTree::createFromGrid(biggrid));
}
if (!ScanOnly)
gss.dc_search(smallTree, bigTree, objTree, Output.size() > 1, res);
if (ScanCheck || ScanOnly)
{
StringResults res2;
gss.dc_scan_search(smallTree, bigTree, objTree, Output.size() > 1,
res2);
if (res2.size() != res.size())
{
cerr << "Scanning found different number\n";
}
}
for (unsigned i = 0, n = res.size(); i < n; i++)
{
cout << i << "\t" << res.getString(i) << "\t" << res.getScore(i)
<< "\n";
}
}
break;
case BatchMiraSearch:
{
//read in database
filesystem::path dbfile(Database.c_str());
GSSTreeSearcher gss(Verbose);
if (!gss.load(dbfile))
{
cerr << "Could not read database " << Database << "\n";
exit(-1);
}
double resolution = gss.getResolution();
setDistance(ShapeDist);
//read in each line of the batch file which should be
//cmd in_ligand in_receptor(for DC Search)
ifstream batch(Input.c_str());
if (!batch)
{
cerr << "Could not read batch file " << Input << "\n";
exit(-1);
}
string line;
while (getline(batch, line))
{
stringstream toks(line);
string cmd, mira;
toks >> cmd;
if (!toks)
break;
double less = 0, more = 0;
unsigned k = 1;
string mivfile, msvfile;
if (cmd == "DCSearch")
{
toks >> mira;
toks >> less;
toks >> more;
}
else if (cmd == "NNSearch")
{
toks >> mira;
toks >> k;
}
else if(cmd == "DCSearch2")
{
toks >> mira;
toks >> mivfile;
toks >> msvfile;
}
vector<double> times;
if (ClearCacheFirst)
clear_cache();
ifstream mirain(mira.c_str());
MiraObject obj;
obj.read(mirain);
ObjectTree objTree = gss.createTreeFromObject(obj);
ObjectTree smallTree, bigTree;
if (cmd == "DCSearch")
{
MGrid smallgrid, biggrid;
objTree->makeGrid(smallgrid, resolution);
biggrid = smallgrid;
smallgrid.shrink(less);
biggrid.grow(more);
smallTree = ObjectTree(
MappableOctTree::createFromGrid(smallgrid));
bigTree = ObjectTree(MappableOctTree::createFromGrid(biggrid));
}
else if(cmd == "DCSearch2")
{
MiraObject miv, msv;
ifstream msvin(msvfile.c_str());
ifstream mivin(mivfile.c_str());
msv.read(msvin);
miv.read(mivin);
smallTree = gss.createTreeFromObject(miv);
bigTree = gss.createTreeFromObject(msv);
}
for (unsigned i = 0; i < TimeTrials; i++)
{
if (ClearCache)
{
clear_cache();
}
StringResults res;
Timer t;
if (cmd == "DCSearch" || cmd == "DCSearch2")
{
gss.dc_search(smallTree, bigTree, objTree, Verbose, res);
}
else if (cmd == "NNSearch")
{
if (k < 1) //scan
{
gss.nn_scan(objTree, Verbose, res);
}
else
{
gss.nn_search(objTree, k, HUGE_VAL, Verbose, res);
}
}
else
{
cerr << "Illegal command " << cmd << " in batch file.\n";
exit(-1);
}
//if verbose, have results
for (unsigned i = 0, n = res.size(); i < n; i++)
{
cout << "RES " << mira << "\t" << res.getString(i) << "\t" << res.getScore(i)
<< "\n";
}
times.push_back(t.elapsed());
}
cout << "Batch " << line;
for (unsigned i = 0, n = times.size(); i < n; i++)
{
cout << " " << times[i];
}
cout << "\n";
}
}
break;
case NNSearch:
{
//read in database
filesystem::path dbfile(Database.c_str());
GSSTreeSearcher gss(Verbose);
if (!gss.load(dbfile))
{
cerr << "Could not read database " << Database << "\n";
exit(-1);
}
setDistance(ShapeDist);
if (ExcludeMol.size() == 0)
{
//actually do a nearest neighbor search intelligently
//using cutoffs within the tree search - this requires
//a backed-in distance funciton (ignores shapedist)
do_nnsearch(gss, IncludeMol, Output, K, NNThreshold);
}
else
{
//use shapedistance if two shapes are provided
ResultMolecules res(SingleConformer);
ObjectTree smallTree, bigTree;
create_trees(gss, IncludeMol, ExcludeMol, LessDist, MoreDist,
smallTree, bigTree);
if (K < 1) //scan
{
gss.nn_scan(smallTree, bigTree, getres, res);
}
else //actually, also a scan
{
gss.nn_search(smallTree, bigTree, K, getres, res);
}
res.writeOutput(Output, Print);
}
}
break;
case DCSearch:
{
//read in database
filesystem::path dbfile(Database.c_str());
GSSTreeSearcher gss(Verbose);
if (!gss.load(dbfile))
{
cerr << "Could not read database " << Database << "\n";
exit(-1);
}
setDistance(ShapeDist);
double dimension = gss.getDimension();
double resolution = gss.getResolution();
//read query molecule(s)
if (IncludeMol.size() > 0 || ExcludeMol.size() > 0)
{
ObjectTree smallTree, bigTree;
create_trees(gss, IncludeMol, ExcludeMol, LessDist, MoreDist,
smallTree, bigTree);
do_dcsearch(gss, smallTree, bigTree, Output);
}
else // range from single molecules
{
for (Molecule::iterator inmols(Input, dimension, resolution,
KeepHydrogens, ProbeRadius); inmols; ++inmols)
{
ResultMolecules res(SingleConformer);
//search
//create bounding trees
ObjectTree smallTree = gss.createTreeFromObject(*inmols,
LessDist);
ObjectTree bigTree = gss.createTreeFromObject(*inmols,
-MoreDist);
if (!ScanOnly)
gss.dc_search(smallTree, bigTree, ObjectTree(), getres, res);
if (ScanCheck || ScanOnly)
{
ResultMolecules res2(SingleConformer);
gss.dc_scan_search(smallTree, bigTree, ObjectTree(), getres,
res2);
if (res2.size() != res.size())
{
cerr << "Scanning found different number\n";
}
}
res.writeOutput(Output, Print);
}
}
}
break;
case BatchSearch:
{
//read in database
filesystem::path dbfile(Database.c_str());
GSSTreeSearcher gss(Verbose);
if (!gss.load(dbfile))
{
cerr << "Could not read database " << Database << "\n";
exit(-1);
}
setDistance(ShapeDist);
//read in each line of the batch file which should be
//cmd in_ligand in_receptor(for DC Search)
ifstream batch(Input.c_str());
if (!batch)
{
cerr << "Could not read batch file " << Input << "\n";
exit(-1);
}
string line;
while (getline(batch, line))
{
stringstream toks(line);
string cmd, ligand, receptor, output; //output always empty for batch
toks >> cmd;
if (!toks)
break;
double less = 0, more = 0;
unsigned k = 1;
if (cmd == "DCSearch")
{
toks >> ligand;
toks >> receptor;
toks >> less;
toks >> more;
}
else if (cmd == "NNSearch")
{
toks >> ligand;
toks >> k;
}
vector<double> times;
ObjectTree smallTree, bigTree;
if (cmd == "DCSearch")
create_trees(gss, ligand, receptor, less, more, smallTree, bigTree);
if (ClearCacheFirst)
clear_cache();
for (unsigned i = 0; i < TimeTrials; i++)
{
if (ClearCache)
{
clear_cache();
}
Timer t;
if (cmd == "DCSearch")
{
do_dcsearch(gss, smallTree, bigTree, output);
}
else if (cmd == "NNSearch")
{
do_nnsearch(gss, ligand, output, k, HUGE_VAL);
}
else
{
cerr << "Illegal command " << cmd << " in batch file.\n";
exit(-1);
}
times.push_back(t.elapsed());
}
cout << "Batch " << line;
for (unsigned i = 0, n = times.size(); i < n; i++)
{
cout << " " << times[i];
}
cout << "\n";
}
}
break;
case BatchDB:
{
//setup where we run the same set of queries on a list of databases (provided in Database)
//preproccess the queries to load in receptor/ligand structures
//read in each line of the batch file which should be
//cmd in_ligand in_receptor(for DC Search)
ifstream batch(Input.c_str());
if (!batch)
{
cerr << "Could not read batch file " << Input << "\n";
exit(-1);
}
vector<QInfo> qinfos;
string line;
while (getline(batch, line))
{
stringstream toks(line);
string cmd, ligand, receptor, output; //output always empty for batch
toks >> cmd;
if (!toks)
break;
if (cmd == "DCSearch")
{
double less = 0, more = 0;
toks >> ligand;
toks >> receptor;
toks >> less;
toks >> more;
Molecule::iterator inmol(ligand, MaxDimension, Resolution,
KeepHydrogens, ProbeRadius);
Molecule inMol = *inmol;
Molecule::iterator exmol(receptor, MaxDimension, Resolution,
KeepHydrogens, ProbeRadius);
Molecule exMol = *exmol;
qinfos.push_back(QInfo(line, inMol, exMol, less, more));
}
else if (cmd == "NNSearch")
{
unsigned k = 1;
toks >> ligand;
toks >> k;