forked from LaradjiSoftMatter/SoftMold
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataExtraction.h
1693 lines (1488 loc) · 48.6 KB
/
dataExtraction.h
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
/**
* \brief Data extraction while the program runs.
* This is the data extraction header. It is currently used for molecular dynamics
* (see MD.cpp), but it is probably general enough for other usage, like DPD. This
* is a user modifiable header that can extract quantities like kinetic or potential
* energy, center of mass, tension, etc... Some objects are defined twice, once here
* and once in MD.cpp; that shouldn't be a problem unless you run out of memory. The
* basic usage of this is as follows:
* 1. Build your system and this object.
* 2. Initialize some values.
* 3. Run MD until measure interval is complete.
* 4. Execute the compute member function of this object.
* 5. repeat step 2 unless system is done.
* 6. Destroy objects and exit.
*
* What you are modifying here is three parts:
* 1. The constructor member is run during build phase (step 1 above).
* 2. The initialize member is run during initialization (step 2 above).
* 2. The compute member is executed every measure interval (step 4 above).\n
* 3. The destructor member is run prior to exiting (step 6 above).
*
* Also, note that you are passing the blob object into the object's constructor; so
* at an interval, you should have all the information about the system.
*
* This is also a template. T is the numeric type (float, double, int, etc...) and
* U is the system blob type (see systemMD.h and systemDPD.h for an example of the blob).
*
* If you plan on modifying the object, then you should probably put quickly computed
* variables in the compute member, and persistent variables, which require information
* from the previous steps, as private members of this object.
*/
template <typename T, typename U>
class dataExtraction {
public:
/**
* The constructor, where blob is a pointer (don't forget the reference operator (&)!)
* and name is a pointer to a '\0' terminated char string. Execute this after you build
* the system (after reading in an mpd file, for example).
*/
dataExtraction(U *blob, char *name);
/**
* Alternative constructor, where blob is a pointer (don't forget the reference operator (&)!)
* and name is a pointer to a '\0' terminated char string. Execute this after you build
* the system (after reading in an mpd file, for example). Also accepts the absolute position
* of a particle list, so that you can track diffusion.
*/
dataExtraction(U *blob, char *name, position<T> *absolutePosition);
/**
* The destructor, where old memory goes to die. This should be executed after it falls
* out of scope, like when a function (e.g. main()) exits.
*/
~dataExtraction();
/**
* An initialize member. Call this after you build it. It automatically calls compute too.
* Mainly, it just does some extra setup prior to your molecular dynamics loop.
*/
void initialize();
/**
* This does some computations faster. Data extraction is still put off until compute is called.
*/
void computeFast();
/**
* A compute member. Call this every measure interval to update the data extraction. When
* you modify it, don't forget to close files when you are done using them. Typical extraction
* is as follows:
* 1. Set values you want.
* 2. Compute against data in the system blob.
* 3. Open a file.
* 4. Write computed data to the file.
* 5. Close the file.
*
* Although, you could swap steps 2 and 3.
*/
void compute();
/**
* Starts calculation of diffusion.
*/
void startDiffusion();
#ifdef ANCHOR_DATA
/**
* An extra member to view the current state of a parameter. I use this to cut the simulation
* short if there are too many anchors broken. I recommend adding whatever you want.
* Not active unless ANCHOR type is defined!
*/
int readNAnchors()
{
return nAnchor;
};
/**
* An extra member to view the current state of a parameter. I use this to cut the simulation
* short if there are too many anchors broken. I recommend adding whatever you want.
* Not active unless ANCHOR type is defined!
*/
int readNBrokenAnchors()
{
return nBroken;
};
#endif
private:
//These variables are typically set during construction:
//The system blob.
U *System;
//The name of the system.
char *name;
//Non-bonded pair interactions. Persistant object, but you have to execute
//the build member prior to use.
//See 'include/algorithms/cellOpt.h'.
CellOpt<T, Potential<T>, Force <T> > pairInteractions;
//An object that computes kinetic energy. Doesn't really need to be persistent.
//See 'include/algorithms/dataCollection.h'.
Kinetic<T> kinetic;
//Tracks the kinetic energy density distribution as a histagram
std::vector<int> kEnergyDensity;
T kEnergyDensityPartition;//actual length of energy ranges
//An object that computes inner volumes. This one is quite complex.
//See 'include/algorithms/volume.h'.
//VolumeExtraction<T> volumize;
//An object for locating neighbors with cell lists. (Standard neighbor list for system)
//See 'include/algorithms/cell.h'.
Cell<T> neighbors;
//An object for getting nearby bleb particles. (Different indices)
//See 'include/algorithms/cell.h'.
Cell<T> blebNeighbors;
//A stack for recursion.
int *stack;
//Flags for our stack.
int *flag;
//Bleb particle indices.
int *blebParticles;
//Flip flop object? (nComponents, inner ratio, outer ratio, ...)
//Useful references for past (persistent) data
//#ifdef SOLVENT
//Number of particles exchanged between inside and outside.
//Need to know what it was before to compare.
int nExchanged;
//#endif
//For flip flop rate calculations?
//bool *flipFlop;
#ifdef ANCHOR_DATA
//A list of anchor indices. Not necessarily persistent, just difficult to compute
//in large systems.
int *anchorIndex;
//Tracks broken anchors.
bool *brokenAnchor;
//Total number of anchors.
int nAnchor;
//Total number of broken anchors
int nBroken;
//Indices of clusters.
int *clusterIndices;
//Initial anchor distance.
T initialAnchorDistance;
//Average anchor distance.
T anchorDistance;
//A vector containing all anchor connections, shares indices with anchorIndex above.
std::vector< std::vector <int> > anchorConnections;
//A vector containing all anchor and cytoskeleton particles, We are using this in
// place of a neighbor list under the assumption that there are far fewer cytoskeleton
// particles than there are neighbors when we search for exclusions.
std::vector<int> cytoAnchorList;
//Track mean squared displacement of cytoskeleton anchor, for execluded volume.
std::vector< std::vector<T> > msCytoAnchor;
//Track number of mean square displacement datapoints.
int nMSCytoAnchorSteps;
//Old anchor positions
std::vector< position<T> > oldAnchorPositions;
//list of cytoskeleton molecules
std::vector<int> cytoList;
#endif
#ifdef FLAT_MEMBRANE
//Height map for flat membrane fluctuations.
T *heightMap;
//Height map number of elements per cell.
T *heightMapElements;
//Number of heightMap cells projected onto the Z plane.
twoVector<int> heightMapCells;
//Size of each heightMap Cell.
twoVector<T> heightMapCellSize;
#endif
#ifdef NANOPARTICLE
int nanoParticleOffset;
int nNanoParticleElements;
#endif
//For diffusion, it is the absolute position of a particle (no pbc)
position<T> *aP;
//For diffusion, stores the start positions and signifies the start of diffusion calculations
position<T> *aPStart;
};
template <typename T, typename U>
dataExtraction<T,U>::dataExtraction(U *blob, char *name, position<T> *absolutePosition)
{
System=blob;
this->name=name;
//initialize data structures here, some of these are created twice per execution (once in main, once here)
kinetic.initialize((*System).getVelocities(), (*System).readNParticles());
//potential info
pairInteractions.initialize((*System).getPositions(), (*System).getAccelerations(),
(*System).getTwoBodyFconst(), (*System).getTwoBodyUconst(), (*System).readNParticles(),
(*System).readNTypes(), (*System).readSize(), (*System).readPeriodic(), (*System).readCutoff());
//For volume
//int *excludeType=new int[(*System).readNTypes()];
//for(int i=1;i<(*System).readNTypes();i++)
// excludeType[i-1]=i;
//volumize.initialize((*System).getPositions(), (*System).readNParticles(), (*System).readSize(),
// (*System).readCutoff(), excludeType, (*System).readNTypes()-1, (*System).readSeed());
//delete excludeType;
//neighbor list
neighbors.initialize((*System).getPositions(), (*System).readNParticles(), (*System).readCutoff(), (*System).readSize());
#ifdef ANCHOR_DATA
nAnchor=0;
//count number of anchors
for(int i=0;i<(*System).readNParticles();i++)
{
if((*System).getPositions()[i].type==ANCHOR)
nAnchor++;
if((*System).getPositions()[i].type==ANCHOR || (*System).getPositions()[i].type==CYTO)
cytoAnchorList.push_back(i);
}
if(nAnchor!=0)
{
anchorIndex=new int[nAnchor];
brokenAnchor=new bool[nAnchor];
}
else
{
brokenAnchor=NULL;
anchorIndex=NULL;
}
nAnchor=0;
//Fill anchor indices
for(int i=0;i<(*System).readNParticles();i++)
if((*System).getPositions()[i].type==ANCHOR)
anchorIndex[nAnchor++]=i;
//For cluster finding during blebbing
stack=new int[(*System).readNParticles()];
flag=new int[(*System).readNParticles()];
blebParticles=new int[(*System).readNParticles()];
blebNeighbors.initialize((*System).getPositions(), (*System).readNParticles(), (*System).readCutoff(), \
(*System).readSize(), blebParticles, (*System).readNParticles());
for(int i=0;i<(*System).readNMolecules();i++)
{
bool containsCyto=false;
//pick a structure by type
switch((*System).getMolecule()[i].readType())
{
case BOND:
{
for(int l=0;l<(*System).getMolecule()[i].readNBond();l++)
{
//These are the first and second particles of the bond
int firstParticle=(*System).getMolecule()[i].getBonds()[l].s[0];
int secondParticle=(*System).getMolecule()[i].getBonds()[l].s[1];
if((*System).getPositions()[firstParticle].type==CYTO ||
(*System).getPositions()[firstParticle].type==ANCHOR ||
(*System).getPositions()[firstParticle].type==MONOMER)
containsCyto=true;
if((*System).getPositions()[secondParticle].type==CYTO ||
(*System).getPositions()[secondParticle].type==ANCHOR ||
(*System).getPositions()[secondParticle].type==MONOMER)
containsCyto=true;
}
break;
}
case BEND:
{
for(int l=0;l<(*System).getMolecule()[i].readNBond();l++)
{
//These are the first and second particles of the bond
int firstParticle=(*System).getMolecule()[i].getBonds()[l].s[0];
int secondParticle=(*System).getMolecule()[i].getBonds()[l].s[1];
int thirdParticle=(*System).getMolecule()[i].getBonds()[l].s[2];
if((*System).getPositions()[firstParticle].type==CYTO ||
(*System).getPositions()[firstParticle].type==ANCHOR ||
(*System).getPositions()[firstParticle].type==MONOMER)
containsCyto=true;
if((*System).getPositions()[secondParticle].type==CYTO ||
(*System).getPositions()[secondParticle].type==ANCHOR ||
(*System).getPositions()[secondParticle].type==MONOMER)
containsCyto=true;
if((*System).getPositions()[thirdParticle].type==CYTO ||
(*System).getPositions()[thirdParticle].type==ANCHOR ||
(*System).getPositions()[thirdParticle].type==MONOMER)
containsCyto=true;
}
break;
}
case CHAIN:
{
//Go through all bond descriptions
for(int l=0;l<(*System).getMolecule()[i].readNBond();l++)
{
fourVector<int> *bond=(*System).getMolecule()[i].getBonds();
//bond info
int start=bond[l].s[START];
int nChains=bond[l].s[NCHAINS];
int length=bond[l].s[CHAINLENGTH];
//go through all chain lengths
for(int k=start; k<start+length*nChains; k++)
{
if((*System).getPositions()[k].type==CYTO ||
(*System).getPositions()[k].type==ANCHOR ||
(*System).getPositions()[k].type==MONOMER)
containsCyto=true;
}
}
break;
}
default:
{
//does nothing
break;
}
}
if(containsCyto)
cytoList.push_back(i);
}
#endif
#ifdef FLAT_MEMBRANE
heightMapCells.x=256;
heightMapCells.y=256;
heightMapCellSize.x=(*System).readSize().x/T(heightMapCells.x);
heightMapCellSize.y=(*System).readSize().y/T(heightMapCells.y);
heightMap=new T[heightMapCells.x*heightMapCells.y];
heightMapElements=new T[heightMapCells.x*heightMapCells.y];
#endif
aP=absolutePosition;
aPStart=NULL;
kEnergyDensityPartition=0.0001;
}
template <typename T, typename U>
dataExtraction<T,U>::dataExtraction(U *blob, char *name)
{
System=blob;
this->name=name;
//initialize data structures here, some of these are created twice per execution (once in main, once here)
kinetic.initialize((*System).getVelocities(), (*System).readNParticles());
//potential info
pairInteractions.initialize((*System).getPositions(), (*System).getAccelerations(),
(*System).getTwoBodyFconst(), (*System).getTwoBodyUconst(), (*System).readNParticles(),
(*System).readNTypes(), (*System).readSize(), (*System).readPeriodic(), (*System).readCutoff());
//For volume
//int *excludeType=new int[(*System).readNTypes()];
//for(int i=1;i<(*System).readNTypes();i++)
// excludeType[i-1]=i;
//volumize.initialize((*System).getPositions(), (*System).readNParticles(), (*System).readSize(),
// (*System).readCutoff(), excludeType, (*System).readNTypes()-1, (*System).readSeed());
//delete excludeType;
//neighbor list
neighbors.initialize((*System).getPositions(), (*System).readNParticles(), (*System).readCutoff(), (*System).readSize());
#ifdef ANCHOR_DATA
nAnchor=0;
//count number of anchors
for(int i=0;i<(*System).readNParticles();i++)
{
if((*System).getPositions()[i].type==ANCHOR)
nAnchor++;
if((*System).getPositions()[i].type==ANCHOR || (*System).getPositions()[i].type==CYTO)
cytoAnchorList.push_back(i);
}
if(nAnchor!=0)
{
anchorIndex=new int[nAnchor];
brokenAnchor=new bool[nAnchor];
}
else
{
brokenAnchor=NULL;
anchorIndex=NULL;
}
nAnchor=0;
//Fill anchor indices
for(int i=0;i<(*System).readNParticles();i++)
if((*System).getPositions()[i].type==ANCHOR)
anchorIndex[nAnchor++]=i;
//For cluster finding during blebbing
stack=new int[(*System).readNParticles()];
flag=new int[(*System).readNParticles()];
blebParticles=new int[(*System).readNParticles()];
blebNeighbors.initialize((*System).getPositions(), (*System).readNParticles(), (*System).readCutoff(), \
(*System).readSize(), blebParticles, (*System).readNParticles());
for(int i=0;i<(*System).readNMolecules();i++)
{
bool containsCyto=false;
//pick a structure by type
switch((*System).getMolecule()[i].readType())
{
case BOND:
{
for(int l=0;l<(*System).getMolecule()[i].readNBond();l++)
{
//These are the first and second particles of the bond
int firstParticle=(*System).getMolecule()[i].getBonds()[l].s[0];
int secondParticle=(*System).getMolecule()[i].getBonds()[l].s[1];
if((*System).getPositions()[firstParticle].type==CYTO ||
(*System).getPositions()[firstParticle].type==ANCHOR ||
(*System).getPositions()[firstParticle].type==MONOMER)
containsCyto=true;
if((*System).getPositions()[secondParticle].type==CYTO ||
(*System).getPositions()[secondParticle].type==ANCHOR ||
(*System).getPositions()[secondParticle].type==MONOMER)
containsCyto=true;
}
break;
}
case BEND:
{
for(int l=0;l<(*System).getMolecule()[i].readNBond();l++)
{
//These are the first and second particles of the bond
int firstParticle=(*System).getMolecule()[i].getBonds()[l].s[0];
int secondParticle=(*System).getMolecule()[i].getBonds()[l].s[1];
int thirdParticle=(*System).getMolecule()[i].getBonds()[l].s[2];
if((*System).getPositions()[firstParticle].type==CYTO ||
(*System).getPositions()[firstParticle].type==ANCHOR ||
(*System).getPositions()[firstParticle].type==MONOMER)
containsCyto=true;
if((*System).getPositions()[secondParticle].type==CYTO ||
(*System).getPositions()[secondParticle].type==ANCHOR ||
(*System).getPositions()[secondParticle].type==MONOMER)
containsCyto=true;
if((*System).getPositions()[thirdParticle].type==CYTO ||
(*System).getPositions()[thirdParticle].type==ANCHOR ||
(*System).getPositions()[thirdParticle].type==MONOMER)
containsCyto=true;
}
break;
}
case CHAIN:
{
//Go through all bond descriptions
for(int l=0;l<(*System).getMolecule()[i].readNBond();l++)
{
fourVector<int> *bond=(*System).getMolecule()[i].getBonds();
//bond info
int start=bond[l].s[START];
int nChains=bond[l].s[NCHAINS];
int length=bond[l].s[CHAINLENGTH];
//go through all chain lengths
for(int k=start; k<start+length*nChains; k++)
{
if((*System).getPositions()[k].type==CYTO ||
(*System).getPositions()[k].type==ANCHOR ||
(*System).getPositions()[k].type==MONOMER)
containsCyto=true;
}
}
break;
}
default:
{
//does nothing
break;
}
}
if(containsCyto)
cytoList.push_back(i);
}
#endif
#ifdef FLAT_MEMBRANE
heightMapCells.x=256;
heightMapCells.y=256;
heightMapCellSize.x=(*System).readSize().x/float(heightMapCells.x);
heightMapCellSize.y=(*System).readSize().y/float(heightMapCells.y);
heightMap=new T[heightMapCells.x*heightMapCells.y];
heightMapElements=new T[heightMapCells.x*heightMapCells.y];
#endif
aP=NULL;
aPStart=NULL;
kEnergyDensityPartition=0.0001;
}
template <typename T, typename U>
dataExtraction<T,U>::~dataExtraction()
{
std::fstream dataFile;
std::string buf("kEnergyDensity_");
buf+=name;
buf+=".dat";
dataFile.open(buf.c_str(), std::ios::out);
long int partitionSum=0;
for(int i=0;i<kEnergyDensity.size();i++)
partitionSum+=kEnergyDensity[i];
for(int i=0;i<kEnergyDensity.size();i++)
{
dataFile << static_cast<float>(i)*kEnergyDensityPartition << '\t';
dataFile << static_cast<float>(kEnergyDensity[i])/static_cast<float>(partitionSum) << std::endl;
}
dataFile.close();
#ifdef ANCHOR_DATA
if(anchorIndex!=NULL)
delete anchorIndex;
if(brokenAnchor!=NULL)
delete brokenAnchor;
if(stack!=NULL)
delete stack;
if(flag!=NULL)
delete flag;
if(blebParticles!=NULL)
delete blebParticles;
#endif
#ifdef FLAT_MEMBRANE
if(heightMap!=NULL)
delete heightMap;
if(heightMapElements!=NULL)
delete heightMapElements;
#endif
if(aPStart!=NULL)
delete aPStart;
}
template <typename T, typename U>
void dataExtraction<T,U>::initialize()
{
//do initial data collection here (usually before system is run)
nExchanged=0;
//useful references
position<T> *p=(*System).getPositions();
threeVector<T> *v=(*System).getVelocities();
threeVector<T> *a=(*System).getAccelerations();
threeVector<T> s=(*System).readSize();
T cutoffSqr=(*System).readCutoff();
cutoffSqr*=cutoffSqr;
#ifdef ANCHOR_DATA
if(nAnchor>0)
{
int nConnections=0;
//let's just assume no anchors are broken when it starts
for(int i=0;i<nAnchor;i++)
brokenAnchor[i]=false;
//quick molecule access
molecule<T, fourVector<int> > *m=(*System).getMolecule();
initialAnchorDistance=0;
//Quick overview of what will be done:
// 1. Find a list of BOND types that contains the anchor.
// 2. Find a all CHAINs that contain the anchor's bonded particle (likely a cytoskeleton chain).
// 3. Find a BOND type that contains the CHAIN type's other end.
// 4. Check if it is bonded to another anchor.
// 5. Determine the distance between that anchor and the current anchor.
//Note: this assumes each chain that connects anchors is unique!
//check initial distance between anchors.
//This is deeply nested, but should be fairly quick because there are far fewer anchors and
// chains than particles in the system.
for(int anchor=0;anchor<nAnchor;anchor++)
{
std::vector<int> connected;
//1. Find a BOND type that contains the anchor.
for(int mol=0;mol<(*System).readNMolecules();mol++)
{
if(m[mol].readType()==BOND)
{
//reset every time we start a new search
m[mol].resetFind();
for(twoVector<int> buf=m[mol].findBond(anchorIndex[anchor]);buf.x!=-1;buf=m[mol].findBond(anchorIndex[anchor]))
{
//We found a bond
if(buf.x!=-1)
{
//we will push back the current cytoskeleton chain start particle
if(buf.y==0)
connected.push_back(m[mol].getBonds()[buf.x].s[1]);
else
connected.push_back(m[mol].getBonds()[buf.x].s[0]);
}
}
}
}
//2. Find a CHAIN type that contains the anchor's bonded particle
for(int mol=0;mol<(*System).readNMolecules();mol++)
{
if(m[mol].readType()==CHAIN)
{
//do it for each connected chain particle
for(int i=0;i<connected.size();i++)
{
//reset every time we start a new search
m[mol].resetFind();
twoVector<int> buf=m[mol].findBond(connected[i]);
//We found a chain
if(buf.x!=-1)
{
int start=m[mol].getBonds()[buf.x].s[START];
int length=m[mol].getBonds()[buf.x].s[CHAINLENGTH];
//we will adjust this to the the other end of the chain.
if((connected[i]-start)%length==0)
connected[i]+=(length);//connected[i] is at the beginning, grab the one at the end.
else
connected[i]-=(length);//connected[i] is at the end, grab the one at the beginning.
}
else
{
#ifdef WARNINGS_ENABLED
//std::cout << "Warning (dataExtraction): Can't locate chain!\n";
#endif
}
}
}
}
//3. Find a BOND type that contains the CHAIN type's other end.
for(int mol=0;mol<(*System).readNMolecules();mol++)
{
if(m[mol].readType()==BOND)
{
//do it for each connected chain particle
for(int i=0;i<connected.size();i++)
{
//reset every time we start a new search
m[mol].resetFind();
twoVector<int> buf=m[mol].findBond(connected[i]);
//We found a bond
if(buf.x!=-1)
{
//we will push back the current cytoskeleton chain start particle
if(buf.y==0)
connected[i]=m[mol].getBonds()[buf.x].s[1];
else
connected[i]=m[mol].getBonds()[buf.x].s[0];
}
else
{
#ifdef WARNINGS_ENABLED
//std::cout << "Warning (dataExtraction): Can't locate other anchor!\n";
#endif
}
}
}
}
//4. Check if it is bonded to another anchor.
for(int i=0;i<connected.size();i++)
if(p[connected[i]].type!=ANCHOR)//is it an anchor?
connected.erase(connected.begin()+i);//it isn't an anchor, remove it
//We don't have to repeat the above for every compute() call, only the 5th step is repeated in compute().
anchorConnections.push_back(connected);
//5. Determine the distance between that anchor and the current anchor.
for(int i=0;i<anchorConnections[anchor].size();i++)
{
threeVector<T> d;
//calculate bond length using minimum image
d.x=p[anchorIndex[anchor]].x-p[anchorConnections[anchor][i]].x;
d.y=p[anchorIndex[anchor]].y-p[anchorConnections[anchor][i]].y;
d.z=p[anchorIndex[anchor]].z-p[anchorConnections[anchor][i]].z;
if(d.x>=s.x/2.0) d.x-=s.x;
if(d.x<=-s.x/2.0) d.x+=s.x;
if(d.y>=s.y/2.0) d.y-=s.y;
if(d.y<=-s.y/2.0) d.y+=s.y;
if(d.z>=s.z/2.0) d.z-=s.z;
if(d.z<=-s.z/2.0) d.z+=s.z;
anchorDistance+=sqrt(d.x*d.x+d.y*d.y+d.z*d.z);
nConnections++;
}
}
if(nConnections>0)
anchorDistance/=float(nConnections);
else
anchorDistance=1.0;
initialAnchorDistance=anchorDistance;
if(initialAnchorDistance<10.0)//There is a thickness associated with the bilayer, this 2x that thickness
initialAnchorDistance=10.0;
std::cout << "Using anchor to anchor distance for bleb search cutoff: " << initialAnchorDistance << '\n';
std::cout << "There are " << nAnchor << " anchors.\n";
//Initialize mean square displacement
if(aP!=NULL)
{
for(int i=0;i<nAnchor;i++)
msCytoAnchor.push_back(std::vector<T>());
for(int i=0;i<nAnchor;i++)
oldAnchorPositions.push_back(aP[cytoAnchorList[i]]);
nMSCytoAnchorSteps=0;
}
}
#endif
#ifdef NANOPARTICLE
nanoParticleOffset=-1;
nNanoParticleElements=0;
for(int i=0;i<(*System).readNParticles();i++)
{
if(p[i].type==NANOPARTICLE && nanoParticleOffset==-1)
{
nanoParticleOffset=i;
}
if(p[i].type!=NANOPARTICLE && nanoParticleOffset>=0)
{
nNanoParticleElements=i-nanoParticleOffset;
break;
}
}
if(nNanoParticleElements==0)
nNanoParticleElements=(*System).readNParticles()-nanoParticleOffset;
#endif
}
template <typename T, typename U>
void dataExtraction<T,U>::startDiffusion()
{
if(aP!=NULL && aPStart==NULL)
{
aPStart=new position<T>[(*System).readNParticles()];
for(int i=0;i<(*System).readNParticles();i++)
{
aPStart[i]=aP[i];
//Alternative version (Doesn't work the same way!):
//aPStart[i]=(*System).getPositions()[i];
}
}
}
template <typename T, typename U>
void dataExtraction<T,U>::computeFast()
{
#ifdef ANCHOR_DATA
/*
//track anchor deviation
if(aP!=NULL)
{
for(int i=0;i<nAnchor;i++)
{
//Compute the MSD from their start
threeVector<T> d;
d.x=aP[cytoAnchorList[i]].x-oldAnchorPositions[i].x;
d.y=aP[cytoAnchorList[i]].y-oldAnchorPositions[i].y;
d.z=aP[cytoAnchorList[i]].z-oldAnchorPositions[i].z;
msCytoAnchor[i].push_back(sqrt(d.x*d.x+d.y*d.y+d.z*d.z));
}
}
*/
#endif
}
template <typename T, typename U>
void dataExtraction<T,U>::compute()
{
//useful references
position<T> *p=(*System).getPositions();
threeVector<T> *v=(*System).getVelocities();
threeVector<T> *a=(*System).getAccelerations();
threeVector<T> s=(*System).readSize();
T cutoffSqr=(*System).readCutoff();
cutoffSqr*=cutoffSqr;
//Cuda works for this
pairInteractions.resize((*System).readSize());//Can't forget this!
pairInteractions.build();
T potential=pairInteractions.computePotential();
//Cuda does not work on this loop yet
//Better version of molecule interactions
T lBond=0;
int nBond=0;
T costhetaBend=0;
int nBend=0;
twoVector<T> lBend;
lBend.x=0;
lBend.y=0;
T beadPotential=0;
int nBeads=0;
//Go through all molecule structures
for(int k=0;k<(*System).readNMolecules();k++)
{
//pick a structure by type
switch((*System).getMolecule()[k].readType())
{
case BOND:
{
potential+=(*System).doBondPotential(k);
//Go through all in bond list
T lBondPrivate=0;
//#pragma omp parallel for reduction(+:lBondPrivate)
for(int l=0;l<(*System).getMolecule()[k].readNBond();l++)
{
//These are the first and second particles of the bond
int firstParticle=(*System).getMolecule()[k].getBonds()[l].s[0];
int secondParticle=(*System).getMolecule()[k].getBonds()[l].s[1];
//calculate bond length using minimum image
T dx=p[firstParticle].x-p[secondParticle].x;
T dy=p[firstParticle].y-p[secondParticle].y;
T dz=p[firstParticle].z-p[secondParticle].z;
if(dx>=s.x/2.0) dx-=s.x;
if(dx<=-s.x/2.0) dx+=s.x;
if(dy>=s.y/2.0) dy-=s.y;
if(dy<=-s.y/2.0) dy+=s.y;
if(dz>=s.z/2.0) dz-=s.z;
if(dz<=-s.z/2.0) dz+=s.z;
lBondPrivate+=sqrt(dx*dx+dy*dy+dz*dz);
}
lBond+=lBondPrivate;
nBond+=(*System).getMolecule()[k].readNBond();
break;
}
case BEND:
{
for(int l=0;l<(*System).getMolecule()[k].readNBond();l++)
{
//These are the first and second particles of the bond
int firstParticle=(*System).getMolecule()[k].getBonds()[l].s[0];
int secondParticle=(*System).getMolecule()[k].getBonds()[l].s[1];
int thirdParticle=(*System).getMolecule()[k].getBonds()[l].s[2];
twoVector<T> dr;
threeVector<T> da, db;
//calculate bond length using minimum image
da.x=p[firstParticle].x-p[secondParticle].x;
da.y=p[firstParticle].y-p[secondParticle].y;
da.z=p[firstParticle].z-p[secondParticle].z;
db.x=p[secondParticle].x-p[thirdParticle].x;
db.y=p[secondParticle].y-p[thirdParticle].y;
db.z=p[secondParticle].z-p[thirdParticle].z;
if(da.x>=s.x/2.0) da.x-=s.x;
if(da.x<=-s.x/2.0) da.x+=s.x;
if(da.y>=s.y/2.0) da.y-=s.y;
if(da.y<=-s.y/2.0) da.y+=s.y;
if(da.z>=s.z/2.0) da.z-=s.z;
if(da.z<=-s.z/2.0) da.z+=s.z;
if(db.x>=s.x/2.0) db.x-=s.x;
if(db.x<=-s.x/2.0) db.x+=s.x;
if(db.y>=s.y/2.0) db.y-=s.y;
if(db.y<=-s.y/2.0) db.y+=s.y;
if(db.z>=s.z/2.0) db.z-=s.z;
if(db.z<=-s.z/2.0) db.z+=s.z;
dr.s[0]=sqrt(da.x*da.x+da.y*da.y+da.z*da.z);
dr.s[1]=sqrt(db.x*db.x+db.y*db.y+db.z*db.z);
lBend.s[0]+=dr.s[0];
lBend.s[1]+=dr.s[1];
costhetaBend+=(da.x*db.x+da.y*db.y+da.z*db.z)/(dr.s[0]*dr.s[1]);
}
nBend+=(*System).getMolecule()[k].readNBond();
potential+=(*System).doBendPotential(k);
break;
}
case CHAIN:
{
potential+=(*System).doChainPotential(k);
break;
}
case BEAD:
{
T tempBeadPotential=(*System).doBeadPotential(k);
beadPotential+=tempBeadPotential;
potential+=tempBeadPotential;
nBeads++;
break;
}
case BOUNDARY:
{
potential+=(*System).doBoundaryPotential(k);
break;
}
case FLOATING_BASE:
{
potential+=(*System).doFloatingBasePotential(k);
break;
}
case ZTORQUE:
{
potential+=(*System).doZTorquePotential(k);
break;
}
case ZPOWERPOTENTIAL:
{
potential+=(*System).doZPowerPotential(k);
break;
}
case NANOCORE:
{
T tempBeadPotential=(*System).doNanoCorePotential(k);
beadPotential+=tempBeadPotential;
potential+=tempBeadPotential;
nBeads++;
break;
}
case BALL:
{
potential+=(*System).doBallPotential(k);
break;
}
default:
{
//does nothing
break;
}
}
}
std::fstream dataFile;
std::string buf("potential_");
buf+=name;
buf+=".dat";
dataFile.open(buf.c_str(), std::ios::app | std::ios::out);
dataFile << (*System).readInitialTime() << '\t' << potential << std::endl;
dataFile.close();
//Just copy this one and use it as a template