-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalyzers.cpp
More file actions
457 lines (425 loc) · 17.5 KB
/
analyzers.cpp
File metadata and controls
457 lines (425 loc) · 17.5 KB
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
#include <iostream>
#include <fstream>
#include <random>
#include <algorithm>
#include <math.h>
#include <ctime>
#include <string>
#include <vector>
#include "omp.h"
#include <mpi.h>
#include <iomanip>
#include <chrono>
#include "membrane_mc.hpp"
#include "analyzers.hpp"
#include "utilities.hpp"
#include "saruprng.hpp"
using namespace std;
Analyzers::Analyzers() {
// Constructor
// Should need to do nothing here
}
Analyzers::Analyzers(int bins, int storage_time, int storage_umb_time, MembraneMC& sys) : bins(bins), storage_time(storage_time), storage_umb_time(storage_umb_time) {
// Adjust size of storage variables
int storage = sys.cycles_prod/storage_time;
energy_storage.resize(storage,0.0);
area_storage.resize(storage,0.0);
area_proj_storage.resize(storage,0.0);
mass_storage.resize(storage,0.0);
// Adjust rho variables
vector<double> list(bins,0.0);
rho.resize(6,list);
bin_size = sys.lengths[0]/bins;
// Adjust output_path
output_path = sys.output_path;
}
Analyzers::~Analyzers() {
// Destructor
// Should need to do nothing here
}
void Analyzers::EnergyAnalyzer() {
// Evaluate average
double energy_ave = 0.0;
for(int i=0; i<storage_counts; i++) {
energy_ave += energy_storage[i];
}
energy_ave = energy_ave/storage_counts;
// Evaluate standard deviation using Bessel's correction
double energy_std = 0.0;
for(int i=0; i<storage_counts; i++) {
energy_std += pow(energy_ave-energy_storage[i],2);
}
energy_std = sqrt(energy_std/(storage_counts-1));
ofstream myfile;
myfile.open(output_path+"/energy.txt", std::ios_base::app);
myfile << "Energy from simulation run" << endl;
myfile << "Average " << std::scientific << energy_ave << " Standard deviation " << std::scientific << energy_std << endl;
myfile.close();
myfile.open(output_path+"/energy_storage.txt", std::ios_base::app);
myfile << "Energy from run" << endl;
myfile.precision(8);
for(int i=0; i<storage_counts; i+=10) {
myfile << std::scientific << energy_storage[i] << endl;
}
myfile.close();
}
void Analyzers::AreaAnalyzer() {
// Evaluate average
double area_ave = 0.0;
for(int i=0; i<storage_counts; i++) {
area_ave += area_storage[i];
}
area_ave = area_ave/storage_counts;
// Evaluate standard deviation using Bessel's correction
double area_std = 0.0;
for(int i=0; i<storage_counts; i++) {
area_std += pow(area_ave-area_storage[i],2);
}
area_std = sqrt(area_std/(storage_counts-1));
ofstream myfile;
myfile.open(output_path+"/area.txt", std::ios_base::app);
myfile.precision(17);
myfile << "Area from simulation run" << endl;
myfile << "Average " << std::scientific << area_ave << " Standard deviation " << std::scientific << area_std << endl;
myfile.close();
myfile.open(output_path+"/area_storage.txt", std::ios_base::app);
myfile.precision(8);
myfile << "Area from run" << endl;
for(int i=0; i<storage_counts; i+=10) {
myfile << std::scientific << area_storage[i] << endl;
}
myfile.close();
}
void Analyzers::AreaProjAnalyzer() {
// Evaluate average
double area_ave = 0.0;
for(int i=0; i<storage_counts; i++) {
area_ave += area_proj_storage[i];
}
area_ave = area_ave/storage_counts;
area_proj_average = area_ave;
// Evaluate standard deviation using Bessel's correction
double area_std = 0.0;
for(int i=0; i<storage_counts; i++) {
area_std += pow(area_ave-area_proj_storage[i],2);
}
area_std = sqrt(area_std/(storage_counts-1));
ofstream myfile;
myfile.open(output_path+"/area_proj.txt", std::ios_base::app);
myfile.precision(17);
myfile << "Area from simulation run" << endl;
myfile << "Average " << std::scientific << area_ave << " Standard deviation " << std::scientific << area_std << endl;
myfile.close();
myfile.open(output_path+"/area_proj_storage.txt", std::ios_base::app);
myfile.precision(8);
myfile << "Area from run" << endl;
for(int i=0; i<storage_counts; i+=10) {
myfile << std::scientific << area_proj_storage[i] << endl;
}
myfile.close();
}
void Analyzers::MassAnalyzer() {
// Evaluate average
double mass_ave = 0.0;
for(int i=0; i<storage_counts; i++) {
mass_ave += mass_storage[i];
}
mass_ave = mass_ave/storage_counts;
// Evaluate standard deviation using Bessel's correction
double mass_std = 0.0;
for(int i=0; i<storage_counts; i++) {
mass_std += pow(mass_ave-mass_storage[i],2);
}
mass_std = sqrt(mass_std/(storage_counts-1));
ofstream myfile;
myfile.open(output_path+"/mass.txt", std::ios_base::app);
myfile.precision(17);
myfile << "Mass from simulation run" << endl;
myfile << "Average " << std::scientific << mass_ave << " Standard deviation " << std::scientific << mass_std << endl;
myfile.close();
myfile.open(output_path+"/mass_storage.txt", std::ios_base::app);
myfile.precision(8);
myfile << "Mass from run" << endl;
for(int i=0; i<storage_counts; i+=10) {
myfile << std::scientific << mass_storage[i] << endl;
}
myfile.close();
}
void Analyzers::UmbOutput(double& phi, double& phi_bending, double& phi_phi, vector<double>& lengths, double& area_total, ofstream& myfile) {
// Output current umbrella variables
// Evaluate average of energy to scale results
// Commands to speed things up
// turns off synchronization of C++ streams
ios_base::sync_with_stdio(false);
// Turns off flushing of out before in
cin.tie(NULL);
myfile << std::scientific << " " << std::scientific << phi << " " << std::scientific << phi_bending << " " << std::scientific << phi_phi << " " << std::scientific << lengths[0]*lengths[1] << " " << std::scientific << area_total << "\n";
}
void Analyzers::ClusterAnalysis(MembraneMC& sys) {
// Do cluster analysis on current lattice configuration
// Will find all clusters that have proteins/species associated with protein
// Iterate over all the proteins as a start, find clusters from there
// Note that clusters with just species associated with protein are not counted
//
// Initialize cluster list
cluster cluster_cur;
cluster_cur.vertex_status.resize(sys.vertices, -1);
cluster_cur.cluster_list.clear();
// Begin iteration
vector<int> list;
for(int i=0; i<sys.vertices; i++) {
if(sys.protein_node[i] == 0) {
if(cluster_cur.vertex_status[i] == -1) {
cluster_cur.cluster_list.push_back(list);
ClusterDFS(sys, i, cluster_cur.cluster_list.size()-1, cluster_cur);
}
}
}
// Output current cluster statistics
// Commands to speed things up
// turns off synchronization of C++ streams
ios_base::sync_with_stdio(false);
// Turns off flushing of out before in
cin.tie(NULL);
ofstream myfile;
myfile.open(output_path+"/cluster.txt", std::ios_base::app);
myfile << "# " << sys.count_step << endl;
for(int i=0; i<cluster_cur.cluster_list.size(); i++) {
int protein_in_cluster = 0;
for(int j=0; j<cluster_cur.cluster_list[i].size(); j++) {
if(sys.ising_array[cluster_cur.cluster_list[i][j]] == 2) {
protein_in_cluster++;
}
}
myfile << cluster_cur.cluster_list[i].size() << " " << protein_in_cluster << "\n";
}
//Do analysis to append to counting vectors
int number_clusters_ = cluster_cur.cluster_list.size();
double mean_cluster_number_ = 0;
double mean_cluster_weight_ = 0;
double mean_cluster_number_protein_ = 0;
double mean_cluster_weight_protein_ = 0;
for(int i=0; i<cluster_cur.cluster_list.size(); i++) {
int cluster_size_ = cluster_cur.cluster_list[i].size();
int cluster_size_protein_ = 0;
for(int j=0; j<cluster_cur.cluster_list[i].size(); j++) {
if(sys.ising_array[cluster_cur.cluster_list[i][j]] == 2) {
cluster_size_protein_++;
}
}
mean_cluster_number_ += cluster_size_;
mean_cluster_number_protein_ += cluster_size_protein_;
mean_cluster_weight_ += cluster_size_*cluster_size_;
mean_cluster_weight_protein_ += cluster_size_protein_*cluster_size_protein_;
}
mean_cluster_weight_ /= mean_cluster_number_;
mean_cluster_weight_protein_ /= mean_cluster_number_protein_;
mean_cluster_number_ /= number_clusters_;
mean_cluster_number_protein_ /= number_clusters_;
//Push back to storage
number_clusters.push_back(number_clusters_);
mean_cluster_number.push_back(mean_cluster_number_);
mean_cluster_weight.push_back(mean_cluster_weight_);
mean_cluster_number_protein.push_back(mean_cluster_number_protein_);
mean_cluster_weight_protein.push_back(mean_cluster_weight_protein_);
}
void Analyzers::ClusterDFS(MembraneMC& sys, int vertex_ind, int cluster_ind, cluster& cluster_cur) {
// do recursive depth-first search
cluster_cur.vertex_status[vertex_ind] = 0;
cluster_cur.cluster_list[cluster_ind].push_back(vertex_ind);
for(int i=0; i<sys.point_neighbor_list[vertex_ind].size(); i++) {
int neighbor = sys.point_neighbor_list[vertex_ind][i];
if(cluster_cur.vertex_status[neighbor] == -1) {
if(sys.ising_array[neighbor] != 0) {
ClusterDFS(sys, neighbor, cluster_ind, cluster_cur);
}
}
}
}
void Analyzers::ClusterPostAnalysis() {
//Do analysis on the cluster vectors
// Evaluate averages
double mean_cluster_number_ave = 0.0;
double mean_cluster_weight_ave = 0.0;
double mean_cluster_number_protein_ave = 0.0;
double mean_cluster_weight_protein_ave = 0.0;
double number_clusters_ave = 0.0;
int storage_counts = mean_cluster_number.size();
for(int i=0; i<storage_counts; i++) {
mean_cluster_number_ave += mean_cluster_number[i];
mean_cluster_weight_ave += mean_cluster_weight[i];
mean_cluster_number_protein_ave += mean_cluster_number_protein[i];
mean_cluster_weight_protein_ave += mean_cluster_weight_protein[i];
number_clusters_ave += number_clusters[i];
}
mean_cluster_number_ave = mean_cluster_number_ave/storage_counts;
mean_cluster_weight_ave = mean_cluster_weight_ave/storage_counts;
mean_cluster_number_protein_ave = mean_cluster_number_protein_ave/storage_counts;
mean_cluster_weight_protein_ave = mean_cluster_weight_protein_ave/storage_counts;
number_clusters_ave = number_clusters_ave/storage_counts;
// Evaluate standard deviation using Bessel's correction
double mean_cluster_number_std = 0.0;
double mean_cluster_weight_std = 0.0;
double mean_cluster_number_protein_std = 0.0;
double mean_cluster_weight_protein_std = 0.0;
double number_clusters_std = 0.0;
for(int i=0; i<storage_counts; i++) {
mean_cluster_number_std += pow(mean_cluster_number_ave-mean_cluster_number[i],2);
mean_cluster_weight_std += pow(mean_cluster_weight_ave-mean_cluster_weight[i],2);
mean_cluster_number_protein_std += pow(mean_cluster_number_protein_ave-mean_cluster_number_protein[i],2);
mean_cluster_weight_protein_std += pow(mean_cluster_weight_protein_ave-mean_cluster_weight_protein[i],2);
number_clusters_std += pow(number_clusters_ave-number_clusters[i],2);
}
mean_cluster_number_std = sqrt(mean_cluster_number_std/(storage_counts-1));
mean_cluster_weight_std = sqrt(mean_cluster_weight_std/(storage_counts-1));
mean_cluster_number_protein_std = sqrt(mean_cluster_number_protein_std/(storage_counts-1));
mean_cluster_weight_protein_std = sqrt(mean_cluster_weight_protein_std/(storage_counts-1));
number_clusters_std = sqrt(number_clusters_std/(storage_counts-1));
ofstream myfile;
myfile.precision(10);
myfile.open(output_path+"/cluster_analysis.txt", std::ios_base::app);
myfile << "# Cluster analysis from simulation run" << endl;
myfile << "MCN " << std::scientific << mean_cluster_number_ave << " " << std::scientific << mean_cluster_number_std << endl;
myfile << "MCW " << std::scientific << mean_cluster_weight_ave << " " << std::scientific << mean_cluster_weight_std << endl;
myfile << "MCPN " << std::scientific << mean_cluster_number_protein_ave << " " << std::scientific << mean_cluster_number_protein_std << endl;
myfile << "MCPW " << std::scientific << mean_cluster_weight_protein_ave << " " << std::scientific << mean_cluster_weight_protein_std << endl;
myfile << "NC " << std::scientific << number_clusters_ave << " " << std::scientific << number_clusters_std << endl;
myfile.close();
myfile.open(output_path+"/cluster_analysis_storage.txt", std::ios_base::app);
myfile << "# Cluster analysis from run" << endl;
for(int i=0; i<storage_counts; i+=10) {
myfile << std::scientific << mean_cluster_number[i] << " " << std::scientific << mean_cluster_weight[i] << " " << std::scientific << mean_cluster_number_protein[i] << " " << std::scientific << mean_cluster_weight_protein[i] << " " << number_clusters[i] << endl;
}
myfile.close();
}
void Analyzers::RDFRoutine(MembraneMC& sys, int ind, int spec_0, int spec_1, int spec_2, int spec_3) {
// routine to sample rho
Utilities util;
#pragma omp parallel for schedule(dynamic,32)
for(int i=0; i<sys.vertices; i++) {
if((sys.ising_array[i] == spec_0) || (sys.ising_array[i] == spec_1)) {
for(int j=0; j<sys.vertices; j++) {
if(i != j) {
if((sys.ising_array[j] == spec_2) || (sys.ising_array[j] == spec_3)) {
double distance = util.LengthLink(sys,i,j);
int bin_loc = int(distance/bin_size);
if((distance<sys.lengths[0]*0.5) && (bin_loc < bins)) {
#pragma omp atomic
rho[ind][bin_loc] += 1;
}
}
}
}
}
}
}
void Analyzers::RhoSample(MembraneMC& sys) {
// Sample radial distribution function
// Will be measuring a bunch of these...
int pairs[6][4];
// 2-2
pairs[0][0] = 2;
pairs[0][1] = 2;
pairs[0][2] = 2;
pairs[0][3] = 2;
// 2-1
pairs[1][0] = 2;
pairs[1][1] = 2;
pairs[1][2] = 1;
pairs[1][3] = 1;
// 2-0
pairs[2][0] = 2;
pairs[2][1] = 2;
pairs[2][2] = 0;
pairs[2][3] = 0;
// 1-1
pairs[3][0] = 1;
pairs[3][1] = 1;
pairs[3][2] = 1;
pairs[3][3] = 1;
// 1-0
pairs[4][0] = 1;
pairs[4][1] = 1;
pairs[4][2] = 0;
pairs[4][3] = 0;
// 0-0
pairs[5][0] = 0;
pairs[5][1] = 0;
pairs[5][2] = 0;
pairs[5][3] = 0;
for(int i=0; i<6; i++) {
RDFRoutine(sys, i, pairs[i][0], pairs[i][1], pairs[i][2], pairs[i][3]);
}
rdf_sample++;
mass_sample[0] += sys.vertices-sys.num_proteins-sys.mass;
mass_sample[1] += sys.mass;
mass_sample[2] += sys.num_proteins;
}
void Analyzers::RhoAnalyzer(MembraneMC& sys) {
// Analyze the mean density with respect to the protein center
mass_sample[0] /= rdf_sample;
mass_sample[1] /= rdf_sample;
mass_sample[2] /= rdf_sample;
double area_change = 0;
double nIdeal = 0;
// Evaluate average projected area
double area_ave = 0.0;
for(int i=0; i<storage_counts; i++) {
area_ave += area_proj_storage[i];
}
area_ave = area_ave/storage_counts;
area_proj_average = area_ave;
double rho_ideal[6];
rho_ideal[0] = mass_sample[2]/(area_proj_average);
rho_ideal[1] = mass_sample[2]/(area_proj_average);
rho_ideal[2] = mass_sample[2]/(area_proj_average);
rho_ideal[3] = mass_sample[1]/(area_proj_average);
rho_ideal[4] = mass_sample[1]/(area_proj_average);
rho_ideal[5] = mass_sample[0]/(area_proj_average);
double num_count[6];
num_count[0] = mass_sample[2];
num_count[1] = mass_sample[1];
num_count[2] = mass_sample[0];
num_count[3] = mass_sample[1];
num_count[4] = mass_sample[0];
num_count[5] = mass_sample[0];
for(int k=0; k<6; k++) {
#pragma omp parallel for
for(int i=0; i<bins; i++) {
area_change = (pow(i+1,2)-pow(i,2))*pow(bin_size,2);
nIdeal = M_PI*area_change*rho_ideal[k];
rho[k][i] = rho[k][i]/(nIdeal*num_count[k]*rdf_sample);
}
}
// Output to file
for(int k=0; k<6; k++) {
ofstream myfile;
myfile.precision(10);
myfile.open(output_path+"/rho_protein_"+to_string(k)+".txt", std::ios_base::app);
myfile << "area_proj_average " << area_proj_average << endl;
myfile << "Length_x*Length_y " << sys.lengths[0]*sys.lengths[1] << endl;
myfile << "Bin size " << bin_size << endl;
for(int i=0; i<bins; i++) {
myfile << bin_size*(i+0.5) << " " << std::scientific << rho[k][i] << endl;
}
myfile.close();
}
// Output masses for post-processing
ofstream myfile;
myfile.precision(10);
myfile.open(output_path+"/rho_protein_mass.txt", std::ios_base::app);
myfile << std::scientific << mass_sample[0] << " " << std::scientific << mass_sample[1] << " " << std::scientific << mass_sample[2] << endl;
}
void Analyzers::OutputAnalyzers(MembraneMC& sys) {
// Output analyzers
sys.t1 = chrono::steady_clock::now();
EnergyAnalyzer();
AreaAnalyzer();
AreaProjAnalyzer();
MassAnalyzer();
ClusterPostAnalysis();
RhoAnalyzer(sys);
sys.t2 = chrono::steady_clock::now();
chrono::duration<double> time_span_anal = sys.t2-sys.t1;
sys.time_storage_other[5] += time_span_anal.count();
}