-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patharea_and_volume.cc
2773 lines (2338 loc) · 120 KB
/
area_and_volume.cc
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
//#include "network.h"
//#include <voro++.hh>
#include <sstream>
#include "area_and_volume.h"
#include "networkinfo.h"
#include "channel.h"
#include "string_additions.h"
#include "networkaccessibility.h"
#include "general.h"
#include "material.h"
using namespace std;
using namespace voro;
/** Returns the density of the provided ATOM_NETWORK, assuming it represents a single
* unit cell, in g/cm^3. */
double calcDensity(ATOM_NETWORK *atmnet){
double volume = calcDeterminant(atmnet->ucVectors); // Units of A^3
vector<ATOM>::iterator iter = atmnet->atoms.begin();
double massSum = 0;
while(iter != atmnet->atoms.end()){
massSum += iter->mass;
iter++;
}
return massSum/(AVOGRADOS_NUMBER*volume)*1.0e24; // Units of g/cm^3
}
/* Print the coordinates collected in MC sampling to the provides string
* This is the new version of the function that writes the output in all
* fromats of interests */
void NEWreportPoints(ostream &output, ATOM_NETWORK *atmnet, vector<Point> *axsPoints, vector<int> *axsPChIDs,
vector<Point> *inaxsPoints, vector<int> *inaxsPPIDs,
string type)
{
if(type=="ZEOVIS")
{
output << "{color green}" << "\n";
for(unsigned int i = 0; i < axsPoints->size(); i++){
Point coords = atmnet->abc_to_xyz(axsPoints->at(i));
output << "{point { " << coords[0] << " " << coords[1] << " " << coords[2] << "}}" << "\n";
};
output << "{color red}" << "\n";
for(unsigned int i = 0; i < inaxsPoints->size(); i++){
Point coords = atmnet->abc_to_xyz(inaxsPoints->at(i));
output << "{point {" << coords[0] << " " << coords[1] << " " << coords[2] << "}}" << "\n";
};
}
else if(type=="VISIT")
{
for(unsigned int i = 0; i < axsPoints->size(); i++){
Point coords = atmnet->abc_to_xyz(axsPoints->at(i));
output << coords[0] << " " << coords[1] << " " << coords[2] << " 1 a " << axsPChIDs->at(i) << "\n";
}
for(unsigned int i = 0; i < inaxsPoints->size(); i++){
Point coords = atmnet->abc_to_xyz(inaxsPoints->at(i));
output << coords[0] << " " << coords[1] << " " << coords[2] << " 0 n " << inaxsPPIDs->at(i) << "\n";
}
}
else if(type=="LIVERPOOL")
{
for(unsigned int i = 0; i < axsPoints->size(); i++){
Point coords = axsPoints->at(i);
output << coords[0] << " " << coords[1] << " " << coords[2] << " 1 a " << axsPChIDs->at(i) << "\n";
}
for(unsigned int i = 0; i < inaxsPoints->size(); i++){
Point coords = inaxsPoints->at(i);
output << coords[0] << " " << coords[1] << " " << coords[2] << " 0 n " << inaxsPPIDs->at(i) << "\n";
}
}
else
{
cout << "Output format unknown. Points not saved\n";
};
} //
/* Print the coordinates collected in MC sampling with additional column (value vector) to the provides string
* This is the new version of the function that writes the output in all
* fromats of interests */
void NEWreportPointsValue(ostream &output, ATOM_NETWORK *atmnet, vector<Point> *axsPoints, vector<int> *axsPChIDs,
vector<double> *value, string type)
{
if(type=="ZEOVIS")
{
cout << "ZEOVIS not supported. Not saving anything.\n";
}
else if(type=="VISIT")
{
for(unsigned int i = 0; i < axsPoints->size(); i++){
Point coords = atmnet->abc_to_xyz(axsPoints->at(i));
output << coords[0] << " " << coords[1] << " " << coords[2] << " " << axsPChIDs->at(i) << " " << value->at(i) << "\n";
}
}
else if(type=="LIVERPOOL")
{
for(unsigned int i = 0; i < axsPoints->size(); i++){
Point coords = axsPoints->at(i);
output << coords[0] << " " << coords[1] << " " << coords[2] << " " << axsPChIDs->at(i) << " " << value->at(i) << "\n";
}
}
else
{
cout << "Output format unknown. Points not saved\n";
};
} //
/* Print the coordinates contained in the provided vectors in a manner that they can be
* displayed using ZeoVis and its VMD interface. Accessible points are colored green while
* inaccessible points are colored red.*/
void reportPoints(ostream &output, vector<Point> axsPoints, vector<Point> inaxsPoints){
output << "{color green}" << "\n";
for(unsigned int i = 0; i < axsPoints.size(); i++){
Point coords = axsPoints.at(i);
output << "{point { " << coords[0] << " " << coords[1] << " " << coords[2] << "}}" << "\n";
}
output << "{color red}" << "\n";
for(unsigned int i = 0; i < inaxsPoints.size(); i++){
Point coords = inaxsPoints.at(i);
output << "{point {" << coords[0] << " " << coords[1] << " " << coords[2] << "}}" << "\n";
}
}
void reportResampledPoints(ostream &output, vector< pair<int, Point> > resampledInfo){
output << "set num_resamples " << resampledInfo.size() << "\n";
for(unsigned int i = 0; i < resampledInfo.size(); i++){
Point coords = resampledInfo[i].second;
output << "set rpoints(" << i << ") {" << coords[0] << " " << coords[1] << " " << coords[2] << "} " << "\n";
output << "set rcenters(" << i << ") " << resampledInfo[i].first << "\n";
}
}
/* Print the coordinates contained in the provided vectors in a manner that they can be
* * displayed using VisIT or analyzed using external programs using similar formating
* */
void reportPointsVisIT(ostream &output, vector<Point> axsPoints, vector<Point> inaxsPoints){
for(unsigned int i = 0; i < axsPoints.size(); i++){
Point coords = axsPoints.at(i);
output << coords[0] << " " << coords[1] << " " << coords[2] << " 1 a" << "\n";
}
for(unsigned int i = 0; i < inaxsPoints.size(); i++){
Point coords = inaxsPoints.at(i);
output << coords[0] << " " << coords[1] << " " << coords[2] << " 0 n" << "\n";
}
}
void reportPointsVisIT(ostream &output, vector<Point> axsPoints, vector<int> axsPChIDs, vector<Point> inaxsPoints, vector<int> inaxsPPIDs){
for(unsigned int i = 0; i < axsPoints.size(); i++){
Point coords = axsPoints.at(i);
output << coords[0] << " " << coords[1] << " " << coords[2] << " 1 a " << axsPChIDs[i] << "\n";
}
for(unsigned int i = 0; i < inaxsPoints.size(); i++){
Point coords = inaxsPoints.at(i);
output << coords[0] << " " << coords[1] << " " << coords[2] << " 0 n " << inaxsPPIDs[i] << "\n";
}
}
/* To adjust the sampling point to minimize its distance with the central atom, shift the point by the reverse of the
atom shift vector.
*/
void adjustSamplingPoint(Point *samplingPointXYZ, Point newAtomCoordsXYZ, Point origAtomCoordsXYZ, ATOM_NETWORK *atmnet){
Point xyzShift = origAtomCoordsXYZ.subtract(newAtomCoordsXYZ);
Point abcShift = atmnet->xyz_to_abc(xyzShift);
atmnet->translatePoint(samplingPointXYZ, abcShift[0], abcShift[1], abcShift[2]);
}
// Function defined in network.cc
void* performVoronoiDecomp(bool, ATOM_NETWORK *, VORONOI_NETWORK *, vector<VOR_CELL> &, bool, vector<BASIC_VCELL> &);
/** Returns the volume accessible to a particle of the provided radius. Accessible volume is defined as any region of space
* in which the center of the particle of the provided radius can reach. Excludes inaccessible pockets if requested */
double calcAV(ATOM_NETWORK *atmnet, ATOM_NETWORK *orgatmnet, bool highAccuracy, double r_probe_chan, double r_probe, int numSamples, bool excludePockets, ostream &output, char *filename, bool visualize, bool VisITflag, bool LiverpoolFlag, bool blockingMode, double low_dist_cutoff, double high_dist_cutoff, bool ProbeOccupiableFlag){
//determine whether we are only sampling volume within a specific distance range of the surface
bool within_range = false;
if(!(low_dist_cutoff<0 || high_dist_cutoff<0)) {
if(high_dist_cutoff<low_dist_cutoff) { //swap them
double temp = low_dist_cutoff;
low_dist_cutoff = high_dist_cutoff;
high_dist_cutoff = temp;
}
within_range = true;
}
// Create an object that handles analysis of accessibility of sampled points
AccessibilityClass accessAnalysis;
if(highAccuracy) accessAnalysis.setupAndFindChannels(atmnet, orgatmnet, highAccuracy, r_probe_chan, r_probe);
else accessAnalysis.setupAndFindChannels(atmnet, atmnet, highAccuracy, r_probe_chan, r_probe);
// setting up MC sampling
srand(randSeed);
vector<Point> axsPoints = vector<Point> (); // stores accessible points
vector<int> axsPointsChannelIDs; // stores the corresponding channel IDs
vector<Point> inaxsPoints = vector<Point> (); // inaccessible points
vector<int> inaxsPointsPocketIDs; // stores the corresponding pocket IDs
vector<Point> insidePoints = vector<Point> (); //domod: points inside atoms
vector<Point> narrowPoints = vector<Point> (); //domod: points not inside atoms, nor accessible, nor inaccessible
int count = 0;
int count_inaxs = 0;
int count_inside = 0; //domod: added to count samplepoins inside atoms
int count_within_range = 0;
int count_outside_range = 0;
vector<double> mindist_axs; // domod:
vector<double> mindist_inaxs;
// MC statistics can be collected w.r.t to identified channels and inaccessible pockets
vector<int> count_inChannel(accessAnalysis.n_channels,0);
vector<int> count_inPocket(accessAnalysis.n_pockets,0);
for(int i = 0; i < numSamples; i++){
bool overlaps = false;
bool inside = false;
double mindist_domod;
// Randomly sample point across the unit cell
double aPoint = (rand()*1.0)/RAND_MAX;
double bPoint = (rand()*1.0)/RAND_MAX;
double cPoint = (rand()*1.0)/RAND_MAX;
// Convert coords relative to the unit cell vectors into (x,y,z) coords
Point samplingPoint = atmnet->abc_to_xyz(aPoint, bPoint, cPoint);
// Calling accessibility object to determine accessibility of the point (this replaced a big chunk of code by Thomas)
pair<bool,bool> answer = (accessAnalysis.isVPointInsideAtomAndNotAccessible(samplingPoint,mindist_domod));
inside = answer.first; overlaps = answer.second;
if(accessAnalysis.needToResample() == true) i--; // the sampled point could not be analyzed in isVPointInsideAtomAndNotAccessible() function, resampling needed
if(inside == false && excludePockets == false) overlaps = false; // if ignore inacceible pockets, treat the point as accessible (unless inside atom)
//domod start: store also inside points
if(inside){
count_inside++;
Point abcCoords = Point(aPoint, bPoint, cPoint);
Point coords = atmnet->abc_to_xyz(abcCoords);
insidePoints.push_back(coords);
};
//domod end
// Store sampled points that did not overlap with an atom but were inaccessible for later visualization
if(accessAnalysis.needToResample() == false && !inside && overlaps){
mindist_inaxs.push_back(mindist_domod); //domod: store the mindistance with an atom
count_inaxs++;
pair <int,int> CoP = accessAnalysis.lastChannelOrPocket();
if(CoP.first!=-1)
{
cout << "Error: CoP.first!=-1 in pocket, consult source code provider\n";
} else {
count_inPocket[CoP.second]++;
};
if(!within_range) {
Point abcCoords = Point(aPoint, bPoint, cPoint);
Point coords = atmnet->abc_to_xyz(abcCoords);
inaxsPoints.push_back(coords);
inaxsPointsPocketIDs.push_back(CoP.second);
};
};
// Store accessible points for later visualization
if(accessAnalysis.needToResample() == false && !overlaps) {
mindist_axs.push_back(mindist_domod);
count++;
pair <int,int> CoP = accessAnalysis.lastChannelOrPocket();
if(CoP.second!=-1)
{
cout << "Error: CoP.second!=-1 in channel, consult source code provider\n";
} else {
count_inChannel[CoP.first]++;
};
Point abcCoords = Point(aPoint, bPoint, cPoint);
Point coords = atmnet->abc_to_xyz(abcCoords);
if(within_range) {
if(accessAnalysis.lastMinDist() >= low_dist_cutoff && accessAnalysis.lastMinDist() <= high_dist_cutoff) { //NOTE: minDist is the distance between centroids, it is NOT the distance to the surface - here we are comparing this distance to the tolerance range
count_within_range++;
axsPoints.push_back(coords);
} else {
count_outside_range++;
inaxsPoints.push_back(coords);
}
} else
{
axsPoints.push_back(coords);
axsPointsChannelIDs.push_back(CoP.first);
};
}
}; // ends a for loop over all sampled points
// Write the necessary commands to the output stream
// necessary to visualize the sampling
if(visualize){
if(VisITflag == false)
{
reportPoints(output, axsPoints, inaxsPoints);
}
else{
if(LiverpoolFlag == false)
{
//report points in std. VisIt format
reportPointsVisIT(output, axsPoints, inaxsPoints);
}
else{
//report points in Liverpool format
vector<Point> LiverpoolAxsPoints = vector<Point> ();
vector<Point> LiverpoolInaxsPoints = vector<Point> ();
for(unsigned i = 0; i < axsPoints.size(); i++)
{
LiverpoolAxsPoints.push_back(atmnet->xyz_to_abc(axsPoints[i]));
};
for(unsigned j = 0; j < inaxsPoints.size(); j++)
{
LiverpoolInaxsPoints.push_back(atmnet->xyz_to_abc(inaxsPoints[j]));
};
if(within_range == true) reportPointsVisIT(output, LiverpoolAxsPoints, LiverpoolInaxsPoints);
else reportPointsVisIT(output, LiverpoolAxsPoints, axsPointsChannelIDs, LiverpoolInaxsPoints, inaxsPointsPocketIDs);
};
};
//reportResampledPoints(output, resampledInfo);
}
// Write blocknig spheres based on current sampling points if blocking routine
// has been requested
if(blockingMode)
{
//report points in fractonal coordinates (Liverpool format used in visualization)
vector<Point> LiverpoolAxsPoints = vector<Point> ();
vector<Point> LiverpoolInaxsPoints = vector<Point> ();
for(unsigned i = 0; i < axsPoints.size(); i++)
{
LiverpoolAxsPoints.push_back(atmnet->xyz_to_abc(axsPoints[i]));
};
for(unsigned j = 0; j < inaxsPoints.size(); j++)
{
LiverpoolInaxsPoints.push_back(atmnet->xyz_to_abc(inaxsPoints[j]));
};
// call this if arg are point in factional coordiantes
blockPockets(atmnet, output, LiverpoolAxsPoints, axsPointsChannelIDs, LiverpoolInaxsPoints, inaxsPointsPocketIDs, r_probe_chan);
//call this if Cartesian points are to be used
// blockPockets(atmnet, output, axsPoints, axsPointsChannelIDs, inaxsPoints, inaxsPointsPocketIDs, r_probe_chan);
};
// Warn user if points were resampled
int resampleCount = accessAnalysis.getResampleCount();
if(resampleCount != 0){
cerr << "\n" << "\n"
<< "Warning: Resampled " << resampleCount << " points out of " << numSamples
<< " when analyzing " << atmnet->name << "\n"
<< "\n" << "\n";
}
//domod start: Further calculation of probe occupiable volume
//
//
int count_domod, count_domod_inaxs, count_domod_inside, count_domod_narrow;
if(ProbeOccupiableFlag == true)
{
count_domod = count; //points in the big accessible volume = points in the small accessible volume
count_domod_inaxs = count_inaxs; //points in the big inaccessible volume = points in the small inaccessible volume
count_domod_inside = count_inside; //points inside atoms = points outside small volumes
count_domod_narrow = 0; //points in a narrow inaccessible volume
if (r_probe > 0.0)
{
bool alreadyfound = false;
printf("ProbeOccupiableLoopStart: atoms: %d count: %d count_inaxs: %d count_inside: %d count_narrow: %d\n",
orgatmnet->numAtoms, count_domod, count_domod_inaxs, count_domod_inside, count_domod_narrow); //domodebug
//printf("DOMODEBUG domod loop \n"); //domodebug
//printf("%f %f %f %f %f %f %f %f %f\n",orgatmnet->ucVectors[0][0],orgatmnet->ucVectors[0][1],orgatmnet->ucVectors[0][2],
// orgatmnet->ucVectors[1][0],orgatmnet->ucVectors[1][1],orgatmnet->ucVectors[1][2],
// orgatmnet->ucVectors[2][0],orgatmnet->ucVectors[2][1],orgatmnet->ucVectors[2][2]);
for (int i=0; i<count_inside; i++)
{
alreadyfound=false;
//first make a loop to check again easily if the sample point is close to an atom:
//it is faster because we have less atoms than sample points and we discard all the "really inside" points
//!!! The purpose of the first loop is only to speed up the calculation to avoid the loop with all the in/accessible points in the small volume
for (int j=0; j<(orgatmnet->numAtoms); j++) //LOOP1: check if it is close to an atom.
{
ATOM curAtom = orgatmnet->atoms[j];
double minDist = orgatmnet->calcDistanceXYZ(
insidePoints[i][0],
insidePoints[i][1],
insidePoints[i][2],
curAtom.x,
curAtom.y,
curAtom.z);
//printf("%d %d |samplepoint: %6.3f %6.3f %6.3f |atom: %6.3f %6.3f %6.3f |dist: %6.3f |rad: %6.3f\n", i,j,insidePoints[i][0],insidePoints[i][1],insidePoints[i][2],curAtom.x,curAtom.y,curAtom.z,minDist,curAtom.radius); //domodebug
if (minDist <= curAtom.radius)
{
//keep it in count_inside
alreadyfound=true;
//printf("DOMODEBUG inside |samplepoint: %6.3f %6.3f %6.3f\n",insidePoints[i][0],insidePoints[i][1],insidePoints[i][2]); //domodebug
break;
}
}
if (!alreadyfound)
{
for (int j=0; j<count; j++) //LOOP2: check if it is close to an accessible point
{
double minDist = orgatmnet->calcDistanceXYZ(
insidePoints[i][0],
insidePoints[i][1],
insidePoints[i][2],
axsPoints[j][0],
axsPoints[j][1],
axsPoints[j][2]);
//if (minDist <= rprobe) //domodold
if (minDist <= r_probe+mindist_axs[j]) //domod: test with r_probe+delta with delta=mindist-r_probe
{
axsPoints.push_back(insidePoints[i]); //domodcheck: I don't want to touch this: maybe it is used for other calculations!
count_domod_inside--;
count_domod++;
alreadyfound=true;
//printf("DOMODEBUG axs |samplepoint: %6.3f %6.3f %6.3f\n",insidePoints[i][0],insidePoints[i][1],insidePoints[i][2]); //domodebug
break;
}
}
}
if (!alreadyfound)
{
for (int j=0; j<count_inaxs; j++) //LOOP3: check if it is close to an inaccessible point (NB: accessible point have priority in case of they are both in an accessible and non accessible volume)
{
double minDist = orgatmnet->calcDistanceXYZ(
insidePoints[i][0],
insidePoints[i][1],
insidePoints[i][2],
inaxsPoints[j][0],
inaxsPoints[j][1],
inaxsPoints[j][2]);
//if (minDist <= rprobe) //domodold
if (minDist <= r_probe+mindist_inaxs[j]) //domod: test with r_probe+delta with delta=mindist-r_probe
{
inaxsPoints.push_back(insidePoints[i]);
count_domod_inside--;
count_domod_inaxs++;
alreadyfound=true;
//printf("DOMODEBUG inax \n"); //domodebug
break;
}
}
}
if (!alreadyfound)
{
narrowPoints.push_back(insidePoints[i]);
//narrowPoints[count_domod_narrow][1]=insidePoints[i][1];
//narrowPoints[count_domod_narrow][2]=insidePoints[i][2];
count_domod_inside--;
count_domod_narrow++;
//printf("DOMODEBUG narrow |samplepoint: %6.3f %6.3f %6.3f\n",insidePoints[i][0],insidePoints[i][1],insidePoints[i][2]); //domodebug
}
}
printf("ProbeOccupiableLoopEnd: atoms: %d count: %d count_inaxs: %d count_inside: %d count_narrow: %d\n",
orgatmnet->numAtoms, count_domod, count_domod_inaxs, count_domod_inside, count_domod_narrow); //domodebug
}
//domod end
/*domodprintxyz: print a .xyz with points-- */
/*
ofstream myfile;
myfile.open ("see_access.xyz");
myfile << count_domod+(orgatmnet->numAtoms) << "\n";
myfile << "CELL: " << orgatmnet->a << " " << orgatmnet->b << " " << orgatmnet->c << " " << orgatmnet->alpha << " " << orgatmnet->beta << " " << orgatmnet->gamma << " #accessible points\n";
for (int i=0; i<count_domod; i++) {
if (i<count)
myfile << "He " << axsPoints[i][0] << " " << axsPoints[i][1] << " " << axsPoints[i][2] << "\n"; //before
else
myfile << "Ne " << axsPoints[i][0] << " " << axsPoints[i][1] << " " << axsPoints[i][2] << "\n"; //after
}
for (int i=0; i<orgatmnet->numAtoms; i++) {
ATOM curAtom = orgatmnet->atoms[i];
myfile << curAtom.type << " " << curAtom.x << " " << curAtom.y << " " << curAtom.z << "\n";
}
myfile.close();
//-------------------------------------
myfile.open ("see_nonaccess.xyz");
myfile << count_domod_inaxs+(orgatmnet->numAtoms) << "\n";
myfile << "CELL: " << orgatmnet->a << " " << orgatmnet->b << " " << orgatmnet->c << " " << orgatmnet->alpha << " " << orgatmnet->beta << " " << orgatmnet->gamma << " #non accessible points\n";
for (int i=0; i<count_domod_inaxs; i++) {
if (i<count_inaxs)
myfile << "He " << inaxsPoints[i][0] << " " << inaxsPoints[i][1] << " " << inaxsPoints[i][2] << "\n"; //before
else
myfile << "Ne " << inaxsPoints[i][0] << " " << inaxsPoints[i][1] << " " << inaxsPoints[i][2] << "\n"; //after
}
for (int i=0; i<orgatmnet->numAtoms; i++) {
ATOM curAtom = orgatmnet->atoms[i];
myfile << curAtom.type << " " << curAtom.x << " " << curAtom.y << " " << curAtom.z << "\n";
}
myfile.close();
//--------------------------------------
myfile.open ("see_narrow.xyz");
myfile << count_domod_narrow+(orgatmnet->numAtoms) << "\n";
myfile << "CELL: " << orgatmnet->a << " " << orgatmnet->b << " " << orgatmnet->c << " " << orgatmnet->alpha << " " << orgatmnet->beta << " " << orgatmnet->gamma << " #narrow points\n";
for (int i=0; i<count_domod_narrow; i++) {
myfile << "He " << narrowPoints[i][0] << " " << narrowPoints[i][1] << " " << narrowPoints[i][2] << "\n";
}
for (int i=0; i<orgatmnet->numAtoms; i++) {
ATOM curAtom = orgatmnet->atoms[i];
myfile << curAtom.type << " " << curAtom.x << " " << curAtom.y << " " << curAtom.z << "\n";
}
myfile.close();
//--------------------------------------
myfile.open ("see_cluster.xyz");
myfile << atmnet->numAtoms << "\n";
myfile << "CELL: " << orgatmnet->a << " " << orgatmnet->b << " " << orgatmnet->c << " " << orgatmnet->alpha << " " << orgatmnet->beta << " " << orgatmnet->gamma << " #cluster atoms after moltiplication + radius\n";
for (int i=0; i<atmnet->numAtoms; i++) {
ATOM curAtom = atmnet->atoms[i];
myfile << curAtom.type << " " << curAtom.x << " " << curAtom.y << " " << curAtom.z << " " << curAtom.radius << "\n";
}
myfile.close();
//-------------------------------------
myfile.open ("see_all.xyz");
myfile << count_domod+count_domod_inaxs+count_domod_narrow+(orgatmnet->numAtoms) << "\n";
myfile << "CELL: " << orgatmnet->a << " " << orgatmnet->b << " " << orgatmnet->c << " " << orgatmnet->alpha << " " << orgatmnet->beta << " " << orgatmnet->gamma
<< " #He: AX_before, Ne: AX_after, Ar: NAX_before, Kr: NAX_after, Xe: narrow\n";
for (int i=0; i<count_domod; i++) {
if (i<count)
myfile << "He " << axsPoints[i][0] << " " << axsPoints[i][1] << " " << axsPoints[i][2] << "\n";
else
myfile << "Ne " << axsPoints[i][0] << " " << axsPoints[i][1] << " " << axsPoints[i][2] << "\n";
}
for (int i=0; i<count_domod_inaxs; i++) {
if (i<count_inaxs)
myfile << "Ar " << inaxsPoints[i][0] << " " << inaxsPoints[i][1] << " " << inaxsPoints[i][2] << "\n";
else
myfile << "Kr " << inaxsPoints[i][0] << " " << inaxsPoints[i][1] << " " << inaxsPoints[i][2] << "\n";
}
for (int i=0; i<count_domod_narrow; i++) {
myfile << "Xe " << narrowPoints[i][0] << " " << narrowPoints[i][1] << " " << narrowPoints[i][2] << "\n";
}
for (int i=0; i<orgatmnet->numAtoms; i++) {
ATOM curAtom = orgatmnet->atoms[i];
myfile << curAtom.type << " " << curAtom.x << " " << curAtom.y << " " << curAtom.z << "\n";
}
myfile.close();
*/
/* end domodprintxyz------------------*/
}; // Ends If(ProbeOccupiableflag = true)
// Final analysis
double volumeFraction, origVolume, av;
if(ProbeOccupiableFlag == false)
{
volumeFraction = count*1.0/numSamples;
origVolume = calcDeterminant(atmnet->ucVectors);
av = volumeFraction * origVolume;
// Write the results to the output stream
if(!visualize&&!blockingMode){
double volumeFraction_inaxs = count_inaxs*1.0/numSamples;
double rho_crystal = calcDensity(atmnet);
double avPerMass = volumeFraction/rho_crystal;
double av_inaxs = volumeFraction_inaxs * origVolume;
double avPerMass_inaxs = volumeFraction_inaxs/rho_crystal;
// output << newAtomNet.name << " ";
output << "@ " << filename << " ";
output << "Unitcell_volume: " << origVolume << " Density: " << rho_crystal << " ";
output << "AV_A^3: " << av << " "
<< "AV_Volume_fraction: " << volumeFraction << " "
<< "AV_cm^3/g: " << avPerMass << " "
<< "NAV_A^3: " << av_inaxs << " "
<< "NAV_Volume_fraction: " << volumeFraction_inaxs << " "
<< "NAV_cm^3/g: " << avPerMass_inaxs;
if(within_range) {
double volumeFraction_within_range = count_within_range*1.0/numSamples;
double av_within_range = volumeFraction_within_range * origVolume;
double avPerMass_within_range = volumeFraction_within_range/rho_crystal;
output << " range_A^3: " << av_within_range << " "
<< "range_Volume_fraction: " << volumeFraction_within_range << " "
<< "range_cm^3/g: " << avPerMass_within_range;
}
output << "\n";
output << "Number_of_channels: " << count_inChannel.size() << " Channel_volume_A^3: ";
for(unsigned int i = 0; i < count_inChannel.size(); i++)
{
// output << count_inChannel[i]*100.00/count << " ";
output << count_inChannel[i]*(1.0/numSamples) * origVolume << " ";
};
output << "\nNumber_of_pockets: " << count_inPocket.size() << " Pocket_volume_A^3: ";
for(unsigned int i = 0; i < count_inPocket.size(); i++)
{
// output << count_inPocket[i]*100.00/count_inaxs << " ";
output << count_inPocket[i]*(1.0/numSamples) * origVolume << " ";
};
output << "\n";
} // ends "if(!visualize){..." writing output
} else { // Different printout in case of probe occupiable calcluation
volumeFraction = count_domod*1.0/numSamples; //domodinfo: here is the value for accessible points
origVolume = calcDeterminant(atmnet->ucVectors);
av = volumeFraction * origVolume;
// Write the results to the output stream
if(!visualize&&!blockingMode){
double volumeFraction_inaxs = count_domod_inaxs*1.0/numSamples; //domodinfo: here is the value for non accessible points
double rho_crystal = calcDensity(atmnet);
double avPerMass = volumeFraction/rho_crystal;
double av_inaxs = volumeFraction_inaxs * origVolume;
double avPerMass_inaxs = volumeFraction_inaxs/rho_crystal;
// output << newAtomNet.name << " ";
output << "@ " << filename << " ";
output << "Unitcell_volume: " << origVolume << " Density: " << rho_crystal << " ";
output << "POAV_A^3: " << av << " "
<< "POAV_Volume_fraction: " << volumeFraction << " "
<< "POAV_cm^3/g: " << avPerMass << " "
<< "PONAV_A^3: " << av_inaxs << " "
<< "PONAV_Volume_fraction: " << volumeFraction_inaxs << " "
<< "PONAV_cm^3/g: " << avPerMass_inaxs;
output << "\n";
output << "PROBE_OCCUPIABLE_VOL_CALC: filename| density(g/cm3)| probe rad| N points| probe ctr A fract| probe ctr NA fract| A fract| NA fract| narrow fract |ovlp fract.\n";
output << "PROBE_OCCUPIABLE___RESULT: "
<< filename << "\t"
<< rho_crystal << "\t"
<< r_probe << "\t"
<< numSamples << "\t"
<< (double)count/(double)numSamples << "\t"
<< (double)count_inaxs/(double)numSamples << "\t"
<< (double)count_domod/(double)numSamples << "\t"
<< (double)count_domod_inaxs/(double)numSamples << "\t"
<< (double)count_domod_narrow/(double)numSamples << "\t"
<< (double)count_domod_inside/(double)numSamples << "\n";
} // ends "if(!visualize){..." writing output
}; // ends else () when ProbeOccupiableFlag == true
accessAnalysis.deconstruct();
return av;
}
/** NEWcalcAV is operating on Material class. It does not have any output savings routines */
double NEWcalcAV(MATERIAL *Mat, double r_probe, int numSamples){
return NEWcalcAV(Mat, r_probe, numSamples, -1, -1);
}
/** NEWcalcAV is operating on Material class. It does not have any output savings routines */
double NEWcalcAV(MATERIAL *Mat, double r_probe, int numSamples, double low_dist_cutoff, double high_dist_cutoff){
// Inital checks
if(!(Mat->accessAnalysis.alreadySegmentedFlag))
{
cerr << "Cannot run calcAV without prior accessibility analysis.\nExiting with return 0\n";
return 0;
}
// Setting parameters
Mat->AVprobeRadius = r_probe;
// Cleaning structures in case of previous runs
Mat->AVcount = 0;
Mat->AVcount_inaxs = 0;
Mat->AVcount_within_range = 0;
Mat->AVcount_outside_range = 0;
Mat->AVaxsPoints.clear();
Mat->AVaxsPointsChannelIDs.clear();
Mat->AVinaxsPoints.clear();
Mat->AVinaxsPointsPocketIDs.clear();
Mat->AVcount_inChannel.clear();
Mat->AVcount_inPocket.clear();
//determine whether we are only sampling volume within a specific distance range of the surface
bool within_range = false;
if(!(low_dist_cutoff<0 || high_dist_cutoff<0)) {
if(high_dist_cutoff<low_dist_cutoff) { //swap them
double temp = low_dist_cutoff;
low_dist_cutoff = high_dist_cutoff;
high_dist_cutoff = temp;
}
within_range = true;
}
Mat->AVwithin_rangeFlag = within_range;
// setting up MC sampling
srand(randSeed);
numSamples = int(numSamples * calcDeterminant(Mat->atmnet.ucVectors));
Mat->AVnumSamples = numSamples;
cout << "Number of samples in volume calc: " << numSamples << endl;
bool excludePockets = true; // this is default (in old version, without voro-stuff it was used)
int count = 0;
int count_inaxs = 0;
int count_within_range = 0;
int count_outside_range = 0;
// MC statistics can be collected w.r.t to identified channels and inaccessible pockets
Mat->AVcount_inChannel.resize(Mat->accessAnalysis.n_channels,0);
Mat->AVcount_inPocket.resize(Mat->accessAnalysis.n_pockets,0);
for(int i = 0; i < numSamples; i++){
bool overlaps = false;
bool inside = false;
// Randomly sample point across the unit cell
double aPoint = (rand()*1.0)/RAND_MAX;
double bPoint = (rand()*1.0)/RAND_MAX;
double cPoint = (rand()*1.0)/RAND_MAX;
// Convert coords relative to the unit cell vectors into (x,y,z) coords
Point samplingPoint = Mat->atmnet.abc_to_xyz(aPoint, bPoint, cPoint);
// Calling accessibility object to determine accessibility of the point (this replaced a big chunk of code by Thomas)
pair<bool,bool> answer = (Mat->accessAnalysis.isVPointInsideAtomAndNotAccessible(samplingPoint));
inside = answer.first; overlaps = answer.second;
if(Mat->accessAnalysis.needToResample() == true) i--; // the sampled point could not be analyzed in isVPointInsideAtomAndNotAccessible() function, resampling needed
if(inside == false && excludePockets == false) overlaps = false; // if ignore inacceible pockets, treat the point as accessible (unless inside atom)
// Store sampled points that did not overlap with an atom but were inaccessible for later visualization
if(Mat->accessAnalysis.needToResample() == false && !inside && overlaps){
count_inaxs++;
pair <int,int> CoP = Mat->accessAnalysis.lastChannelOrPocket();
if(CoP.first!=-1)
{
cout << "Error: CoP.first!=-1 in pocket, consult source code provider\n";
} else {
Mat->AVcount_inPocket[CoP.second]++;
};
if(!within_range) {
//Point abcCoords = Point(aPoint, bPoint, cPoint); // to be removed as now we store fractional coordinates
//Point coords = Mat->atmnet.abc_to_xyz(abcCoords);
Point coords = Point(aPoint, bPoint, cPoint);
Mat->AVinaxsPoints.push_back(coords);
Mat->AVinaxsPointsPocketIDs.push_back(CoP.second);
};
};
// Store accessible points for later visualization
if(Mat->accessAnalysis.needToResample() == false && !overlaps) {
count++;
pair <int,int> CoP = Mat->accessAnalysis.lastChannelOrPocket();
if(CoP.second!=-1)
{
cout << "Error: CoP.second!=-1 in channel, consult source code provider\n";
} else {
Mat->AVcount_inChannel[CoP.first]++;
};
//Point abcCoords = Point(aPoint, bPoint, cPoint); // to be removed as now we store fractional coordinates
//Point coords = Mat->atmnet.abc_to_xyz(abcCoords);
Point coords = Point(aPoint, bPoint, cPoint);
if(within_range) {
if(Mat->accessAnalysis.lastMinDist() >= low_dist_cutoff && Mat->accessAnalysis.lastMinDist() <= high_dist_cutoff) { //NOTE: minDist is the distance between centroids, it is NOT the distance to the surface - here we are comparing this distance to the tolerance range
// RECHECK IF STILL TRUE FOR NON INFLATED ATOMS
count_within_range++;
Mat->AVaxsPoints.push_back(coords);
} else {
count_outside_range++;
Mat->AVinaxsPoints.push_back(coords);
}
} else
{
Mat->AVaxsPoints.push_back(coords);
Mat->AVaxsPointsChannelIDs.push_back(CoP.first);
};
}
}; // ends a for loop over all sampled points
// Warn user if points were resampled
int resampleCount = Mat->accessAnalysis.getResampleCount();
if(resampleCount != 0){
cerr << "\n" << "\n"
<< "Warning: Resampled " << resampleCount << " points out of " << numSamples
<< " when analyzing " << Mat->atmnet.name << "\n"
<< "\n" << "\n";
};
Mat->AVcount = count;
Mat->AVcount_inaxs = count_inaxs;
Mat->AVcount_within_range = count_within_range;
Mat->AVcount_outside_range = count_outside_range;
return count/numSamples;
} // ends NEWcalcAV
/* framgents of calcAV for saving outputs
// Write the necessary commands to the output stream
// necessary to visualize the sampling
if(visualize){
if(VisITflag == false)
{
reportPoints(output, axsPoints, inaxsPoints);
}
else{
if(LiverpoolFlag == false)
{
//report points in std. VisIt format
reportPointsVisIT(output, axsPoints, inaxsPoints);
}
else{
//report points in Liverpool format
vector<Point> LiverpoolAxsPoints = vector<Point> ();
vector<Point> LiverpoolInaxsPoints = vector<Point> ();
for(unsigned i = 0; i < axsPoints.size(); i++)
{
LiverpoolAxsPoints.push_back(atmnet->xyz_to_abc(axsPoints[i]));
};
for(unsigned j = 0; j < inaxsPoints.size(); j++)
{
LiverpoolInaxsPoints.push_back(atmnet->xyz_to_abc(inaxsPoints[j]));
};
if(within_range == true) reportPointsVisIT(output, LiverpoolAxsPoints, LiverpoolInaxsPoints);
else reportPointsVisIT(output, LiverpoolAxsPoints, axsPointsChannelIDs, LiverpoolInaxsPoints, inaxsPointsPocketIDs);
};
};
//reportResampledPoints(output, resampledInfo);
}
// Write blocknig spheres based on current sampling points if blocking routine
// has been requested
if(blockingMode)
{
//report points in fractonal coordinates (Liverpool format used in visualization)
vector<Point> LiverpoolAxsPoints = vector<Point> ();
vector<Point> LiverpoolInaxsPoints = vector<Point> ();
for(unsigned i = 0; i < axsPoints.size(); i++)
{
LiverpoolAxsPoints.push_back(atmnet->xyz_to_abc(axsPoints[i]));
};
for(unsigned j = 0; j < inaxsPoints.size(); j++)
{
LiverpoolInaxsPoints.push_back(atmnet->xyz_to_abc(inaxsPoints[j]));
};
// call this if arg are point in factional coordiantes
blockPockets(atmnet, output, LiverpoolAxsPoints, axsPointsChannelIDs, LiverpoolInaxsPoints, inaxsPointsPocketIDs, r_probe_chan);
//call this if Cartesian points are to be used
// blockPockets(atmnet, output, axsPoints, axsPointsChannelIDs, inaxsPoints, inaxsPointsPocketIDs, r_probe_chan);
};
*/
/* Function that calculates and print summary of NEWcalcAV */
void NEWcalcAVprint(MATERIAL *Mat, ostream &output, char *filename) {
double volumeFraction = Mat->AVcount*1.0/Mat->AVnumSamples;
double origVolume = calcDeterminant(Mat->atmnet.ucVectors);
double av = volumeFraction * origVolume;
// Write the results to the output stream
double volumeFraction_inaxs = Mat->AVcount_inaxs*1.0/Mat->AVnumSamples;
double rho_crystal = calcDensity(&(Mat->atmnet));
double avPerMass = volumeFraction/rho_crystal;
double av_inaxs = volumeFraction_inaxs * origVolume;
double avPerMass_inaxs = volumeFraction_inaxs/rho_crystal;
// output << newAtomNet.name << " ";
output << "@ " << filename << " ";
output << "Unitcell_volume: " << origVolume << " Density: " << rho_crystal << " ";
output << "AV_A^3: " << av << " "
<< "AV_Volume_fraction: " << volumeFraction << " "
<< "AV_cm^3/g: " << avPerMass << " "
<< "NAV_A^3: " << av_inaxs << " "
<< "NAV_Volume_fraction: " << volumeFraction_inaxs << " "
<< "NAV_cm^3/g: " << avPerMass_inaxs;
if(Mat->AVwithin_rangeFlag) {
double volumeFraction_within_range = Mat->AVcount_within_range*1.0/Mat->AVnumSamples;
double av_within_range = volumeFraction_within_range * origVolume;
double avPerMass_within_range = volumeFraction_within_range/rho_crystal;
output << " range_A^3: " << av_within_range << " "
<< "range_Volume_fraction: " << volumeFraction_within_range << " "
<< "range_cm^3/g: " << avPerMass_within_range;
}
output << "\n";
output << "Number_of_channels: " << Mat->AVcount_inChannel.size() << " Channel_volume_A^3: ";
for(unsigned int i = 0; i < Mat->AVcount_inChannel.size(); i++)
{
output << Mat->AVcount_inChannel[i]*(1.0/Mat->AVnumSamples) * origVolume << " ";
};
output << "\nNumber_of_pockets: " << Mat->AVcount_inPocket.size() << " Pocket_volume_A^3: ";
for(unsigned int i = 0; i < Mat->AVcount_inPocket.size(); i++)
{
output << Mat->AVcount_inPocket[i]*(1.0/Mat->AVnumSamples) * origVolume << " ";
};
output << "\n";
}
/* backup of AV function
double calcAV(ATOM_NETWORK *atmnet, ATOM_NETWORK *orgatmnet, bool highAccuracy, double r_probe_chan, double r_probe, int numSamples, bool excludePockets, ostream &output, char *filename, bool visualize, bool VisITflag, bool LiverpoolFlag, double low_dist_cutoff, double high_dist_cutoff){
//determine whether we are only sampling volume within a specific distance range of the surface
bool within_range = false;
if(!(low_dist_cutoff<0 || high_dist_cutoff<0)) {
if(high_dist_cutoff<low_dist_cutoff) { //swap them
double temp = low_dist_cutoff;
low_dist_cutoff = high_dist_cutoff;
high_dist_cutoff = temp;
}
within_range = true;
}
// Create a temporary copy of the atomic network in which each atom's radius has been increased by the probe radius
ATOM_NETWORK newAtomNet;
atmnet->copy(&newAtomNet);
for(int i = 0; i < newAtomNet.numAtoms; i++){ newAtomNet.atoms[i].radius += r_probe; }
// Calculate and store the Voronoi network for this new atomic network
VORONOI_NETWORK vornet;
vector<BASIC_VCELL> vorcells;