-
Notifications
You must be signed in to change notification settings - Fork 3
/
param.cpp
1645 lines (1503 loc) · 49.5 KB
/
param.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
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
< BioEM software for Bayesian inference of Electron Microscopy images>
Copyright (C) 2017 Pilar Cossio, David Rohr, Fabio Baruffa, Markus Rampp,
Luka Stanisic, Volker Lindenstruth and Gerhard Hummer.
Max Planck Institute of Biophysics, Frankfurt, Germany.
Frankfurt Institute for Advanced Studies, Goethe University Frankfurt,
Germany.
Max Planck Computing and Data Facility, Garching, Germany.
Released under the GNU Public License, v3.
See license statement for terms of distribution.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#include <cstring>
#include <fftw3.h>
#include <fstream>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef WITH_OPENMP
#include <omp.h>
#endif
#include "map.h"
#include "param.h"
using namespace std;
bioem_param::bioem_param()
{
//**************** Initializing Variables and defaults ****************
// Number of Pixels
param_device.NumberPixels = 0;
param_device.NumberFFTPixels1D = 0;
// Euler angle grid spacing
angleGridPointsAlpha = 0;
angleGridPointsBeta = 0;
// Envelop function paramters
numberGridPointsEnvelop = 0;
// Contrast transfer function paramters
numberGridPointsCTF_amp = 0;
numberGridPointsCTF_phase = 0;
// ****center displacement paramters Equal in both directions***
param_device.maxDisplaceCenter = 0;
numberGridPointsDisplaceCenter = 0;
fft_plans_created = 0;
refCTF = NULL;
CtfParam = NULL;
angles = NULL;
angprior = NULL;
printModel = false;
BestmapCalcCC = false;
}
int bioem_param::readParameters(const char *fileinput)
{ // **************************************************************************************
// ***************************** Reading Input Parameters
// ******************************
// **************************************************************************************
// Control for Parameters
bool yesPixSi = false;
bool yesNumPix = false;
bool yesGPal = false;
bool yesGPbe = false;
bool yesMDC = false;
bool yesBFact = false;
bool yesDefocus = false;
bool yesAMP = false;
bool yesPSFenv = false;
bool yesPSFpha = false;
bool yesquatgrid = false;
//***************** Default VALUES
param_device.tousepsf = false;
writeCTF = false;
elecwavel = 0.019866;
doquater = false;
nocentermass = false;
printrotmod = false;
readquatlist = false;
doaaradius = true;
notnormmap = false;
usepsf = false;
yespriorAngles = false;
printrotmod = false;
ignorePDB = false;
NotUn_angles = 0;
priorMod = 1; // Default
shiftX = 0;
shiftY = 0;
param_device.sigmaPriorbctf = 100.;
param_device.sigmaPriordefo = 2.0;
param_device.Priordefcent = 3.0;
param_device.sigmaPrioramp = 0.5;
param_device.Priorampcent = 0.;
ifstream input(fileinput);
if (!input.good())
{
myError("Opening file: %s", fileinput);
}
char line[512] = {0};
char saveline[512];
cout << "\n +++++++++++++++++++++++++++++++++++++++++ \n";
cout << "\n READING BioEM PARAMETERS \n\n";
cout << " +++++++++++++++++++++++++++++++++++++++++ \n";
while (input.getline(line, 512))
{
strcpy(saveline, line);
char *token = strtok(line, " ");
if (token == NULL || line[0] == '#' || strlen(token) == 0)
{
// comment or blank line
}
else if (strcmp(token, "PIXEL_SIZE") == 0)
{
token = strtok(NULL, " ");
pixelSize = atof(token);
if (pixelSize < 0)
{
myError("Negative pixel size");
}
cout << "Pixel Size " << pixelSize << "\n";
yesPixSi = true;
}
else if (strcmp(token, "NUMBER_PIXELS") == 0)
{
token = strtok(NULL, " ");
param_device.NumberPixels = int(atoi(token));
if (param_device.NumberPixels < 0)
{
myError("Negative Number of Pixels");
}
cout << "Number of Pixels " << param_device.NumberPixels << "\n";
yesNumPix = true;
}
else if (strcmp(token, "GRIDPOINTS_ALPHA") == 0)
{
token = strtok(NULL, " ");
angleGridPointsAlpha = int(atoi(token));
if (angleGridPointsAlpha < 0)
{
myError("Negative GRIDPOINTS_ALPHA");
}
cout << "Grid points alpha " << angleGridPointsAlpha << "\n";
yesGPal = true;
}
else if (strcmp(token, "GRIDPOINTS_BETA") == 0)
{
token = strtok(NULL, " ");
angleGridPointsBeta = int(atoi(token));
if (angleGridPointsBeta < 0)
{
myError("Negative GRIDPOINTS_BETA");
}
cout << "Grid points in Cosine ( beta ) " << angleGridPointsBeta << "\n";
yesGPbe = true;
}
else if (strcmp(token, "USE_QUATERNIONS") == 0)
// else if (token=="USE_QUATERNIONS")
{
cout << "Orientations with Quaternions. \n";
doquater = true;
}
else if (strcmp(token, "GRIDPOINTS_QUATERNION") == 0)
{
if (!notuniformangles)
{
token = strtok(NULL, " ");
GridPointsQuatern = int(atoi(token));
cout << "Gridpoints Quaternions " << GridPointsQuatern << "\n";
}
else
{
myError("Inconsistent input: grid or list with quaternions?");
}
yesquatgrid = true;
doquater = true;
}
// CTF PARAMETERS
else if (strcmp(token, "CTF_B_ENV") == 0)
{
token = strtok(NULL, " ");
startBfactor = atof(token);
if (startBfactor < 0)
{
myError("Negative start B Env.");
}
token = strtok(NULL, " ");
endBfactor = atof(token);
if (endBfactor < 0)
{
myError("Negative end B Env.");
}
token = strtok(NULL, " ");
numberGridPointsEnvelop = int(atoi(token));
if (numberGridPointsEnvelop < 0)
{
myError("Negative number of grid points B Env.");
}
cout << "Grid CTF B-ENV: " << startBfactor << " " << endBfactor << " "
<< numberGridPointsEnvelop << "\n";
if (startBfactor > endBfactor)
{
myError("Grid ill defined end > start");
}
yesBFact = true;
}
else if (strcmp(token, "CTF_DEFOCUS") == 0)
{
token = strtok(NULL, " ");
startDefocus = atof(token);
if (startDefocus < 0)
{
myError("Negative start defocus");
}
token = strtok(NULL, " ");
endDefocus = atof(token);
if (endDefocus < 0)
{
myError("Negative end defocus");
}
token = strtok(NULL, " ");
numberGridPointsCTF_phase = int(atoi(token));
if (numberGridPointsCTF_phase < 0)
{
myError("Negative number of grid points defocus");
}
cout << "Grid CTF Defocus: " << startDefocus << " " << endDefocus << " "
<< numberGridPointsCTF_phase << "\n";
if (startDefocus > endDefocus)
{
myError("Grid ill defined end > start");
};
if (endDefocus > 8.)
{
myError("Defocus beyond 8micro-m range is not allowed");
}
yesDefocus = true;
}
else if (strcmp(token, "CTF_AMPLITUDE") == 0)
{
token = strtok(NULL, " ");
startGridCTF_amp = atof(token);
if (startGridCTF_amp < 0)
{
myError("Negative start amplitude");
}
token = strtok(NULL, " ");
endGridCTF_amp = atof(token);
if (endGridCTF_amp < 0)
{
myError("Negative end amplitude");
}
token = strtok(NULL, " ");
numberGridPointsCTF_amp = int(atoi(token));
if (numberGridPointsCTF_amp < 0)
{
myError("Negative number of grid points amplitude");
}
cout << "Grid Amplitude: " << startGridCTF_amp << " " << endGridCTF_amp
<< " " << numberGridPointsCTF_amp << "\n";
if (startGridCTF_amp > endGridCTF_amp)
{
myError("Grid ill defined end > start");
};
yesAMP = true;
}
else if (strcmp(token, "ELECTRON_WAVELENGTH") == 0)
{
token = strtok(NULL, " ");
elecwavel = atof(token);
if (elecwavel < 0.0150)
{
myError("Wrong electron wave length %lf. "
"Has to be in Angstrom (A)",
elecwavel);
}
cout << "Electron wave length in (A) is: " << elecwavel << "\n";
}
// PSF PARAMETERS
else if (strcmp(token, "USE_PSF") == 0)
{
usepsf = true;
param_device.tousepsf = true;
cout << "Important: Using Point Spread Function. Thus, all parameters "
"are in Real Space. \n";
}
else if (strcmp(token, "PSF_AMPLITUDE") == 0)
{
token = strtok(NULL, " ");
startGridCTF_amp = atof(token);
if (startGridCTF_amp < 0)
{
myError("Negative start amplitude");
}
token = strtok(NULL, " ");
endGridCTF_amp = atof(token);
if (endGridCTF_amp < 0)
{
myError("Negative end amplitude");
}
token = strtok(NULL, " ");
numberGridPointsCTF_amp = int(atoi(token));
if (numberGridPointsCTF_amp < 0)
{
myError("Negative number of grid points amplitude");
}
cout << "Grid Amplitude: " << startGridCTF_amp << " " << endGridCTF_amp
<< " " << numberGridPointsCTF_amp << "\n";
if (startGridCTF_amp > endGridCTF_amp)
{
myError("Grid ill defined end > start");
};
yesAMP = true;
}
else if (strcmp(token, "PSF_ENVELOPE") == 0)
{
token = strtok(NULL, " ");
startGridEnvelop = atof(token);
if (startGridEnvelop < 0)
{
myError("Negative start PSF Env.");
}
token = strtok(NULL, " ");
endGridEnvelop = atof(token);
if (endGridEnvelop < 0)
{
myError("Negative end PSF Env.");
}
token = strtok(NULL, " ");
numberGridPointsEnvelop = int(atoi(token));
if (numberGridPointsEnvelop < 0)
{
myError("Negative number of grid points PSF Env.");
}
cout << "Grid PSF Envelope: " << startGridEnvelop << " " << endGridEnvelop
<< " " << numberGridPointsEnvelop << "\n";
if (startGridEnvelop > endGridEnvelop)
{
myError("Grid ill defined end > start");
}
yesPSFenv = true;
}
else if (strcmp(token, "PSF_PHASE") == 0)
{
token = strtok(NULL, " ");
startGridCTF_phase = atof(token);
if (startGridCTF_phase < 0)
{
myError("Negative start amplitude");
}
token = strtok(NULL, " ");
endGridCTF_phase = atof(token);
if (endGridCTF_phase < 0)
{
myError("Negative end amplitude");
}
token = strtok(NULL, " ");
numberGridPointsCTF_phase = int(atoi(token));
if (numberGridPointsCTF_phase < 0)
{
myError("Negative number of grid points amplitude");
}
cout << "Grid PSF phase: " << startGridCTF_phase << " "
<< endGridCTF_phase << " " << numberGridPointsCTF_phase << "\n";
if (startGridCTF_phase > endGridCTF_phase)
{
myError("Grid ill defined end > start");
}
yesPSFpha = true;
}
else if (strcmp(token, "DISPLACE_CENTER") == 0)
{
token = strtok(NULL, " ");
param_device.maxDisplaceCenter = int(atoi(token));
if (param_device.maxDisplaceCenter < 0)
{
myError("Negative MAX_D_CENTER");
}
cout << "Maximum displacement Center " << param_device.maxDisplaceCenter
<< "\n";
token = strtok(NULL, " ");
param_device.GridSpaceCenter = int(atoi(token));
if (param_device.GridSpaceCenter < 0)
{
myError("Negative PIXEL_GRID_CENTER");
}
cout << "Grid space displacement center " << param_device.GridSpaceCenter
<< "\n";
yesMDC = true;
}
else if (strcmp(token, "WRITE_PROB_ANGLES") ==
0) // Key word if writing down each angle probabilities
{
token = strtok(NULL, " ");
param_device.writeAngles = int(atoi(token));
if (param_device.writeAngles < 0)
{
myError("Negative WRITE_PROB_ANGLES");
}
cout << "Writing " << param_device.writeAngles
<< " Probabilies of each angle \n";
}
else if (strcmp(token, "IGNORE_PDB") == 0) // Ignore PDB extension
{
ignorePDB = true;
cout << "Ignoring PDB extension in model file \n";
}
else if (strcmp(token, "NO_PROJECT_RADIUS") ==
0) // If projecting CA with amino-acid radius
{
doaaradius = false;
cout << "Not Projecting corresponding radius \n";
}
else if (strcmp(token, "WRITE_CTF_PARAM") == 0) // Number of Euler angle
// tripplets in non uniform
// Euler angle sampling
{
writeCTF = true;
token = strtok(NULL, " ");
cout << "Writing CTF parameters from PSF parameters that maximize the "
"posterior. \n";
}
else if (strcmp(token, "NO_CENTEROFMASS") == 0) // Number of Euler angle
// tripplets in non uniform
// Euler angle sampling
{
nocentermass = true;
cout << "BE CAREFUL CENTER OF MASS IS NOT REMOVED \n Calculated images "
"might be out of range \n";
}
else if (strcmp(token, "PRINT_ROTATED_MODELS") == 0) // Number of Euler
// angle tripplets in
// non uniform Euler
// angle sampling
{
printrotmod = true;
cout << "PRINTING out rotatted models (best for debugging)\n";
}
else if (strcmp(token, "NO_MAP_NORM") == 0)
{
notnormmap = true;
cout << "NOT NORMALIZING MAP\n";
}
else if (strcmp(token, "PRIOR_MODEL") == 0)
{
token = strtok(NULL, " ");
priorMod = atof(token);
cout << "MODEL PRIOR Probability " << priorMod << "\n";
}
else if (strcmp(token, "PRIOR_ANGLES") == 0)
{
yespriorAngles = true;
cout << "READING Priors for Orientations in additonal orientation file\n";
}
else if (strcmp(token, "SHIFT_X") == 0)
{
token = strtok(NULL, " ");
shiftX = atoi(token);
cout << "Shifting initial model X by " << shiftX << "\n";
}
else if (strcmp(token, "SHIFT_Y") == 0)
{
token = strtok(NULL, " ");
shiftY = atoi(token);
cout << "Shifting initial model Y by " << shiftY << "\n";
}
else if (strcmp(token, "SIGMA_PRIOR_B_CTF") == 0)
{
token = strtok(NULL, " ");
param_device.sigmaPriorbctf = atof(token);
cout << "Chainging Gaussian width in Prior of Envelope b parameter: "
<< param_device.sigmaPriorbctf << "\n";
}
else if (strcmp(token, "SIGMA_PRIOR_DEFOCUS") == 0)
{
token = strtok(NULL, " ");
param_device.sigmaPriordefo = atof(token);
cout << "Gaussian Width in Prior of defocus parameter: "
<< param_device.sigmaPriordefo << "\n";
}
else if (strcmp(token, "PRIOR_DEFOCUS_CENTER") == 0)
{
token = strtok(NULL, " ");
param_device.Priordefcent = atof(token);
cout << "Gaussian Center in Prior of defocus parameter: "
<< param_device.Priordefcent << "\n";
}
else if (strcmp(token, "SIGMA_PRIOR_AMP_CTF") == 0)
{
token = strtok(NULL, " ");
param_device.sigmaPrioramp = atof(token);
cout << "Gaussian Width in Prior of defocus parameter: "
<< param_device.sigmaPriordefo << "\n";
}
else if (strcmp(token, "PRIOR_AMP_CTF_CENTER") == 0)
{
token = strtok(NULL, " ");
param_device.Priorampcent = atof(token);
cout << "Gaussian Center in Prior of defocus parameter: "
<< param_device.Priordefcent << "\n";
}
else if (strcmp(token, "PRINT_ROTATED_MODELS") == 0) // Number of Euler
// angle tripplets in
// non uniform Euler
// angle sampling
{
printrotmod = true;
cout << "Printing out rotated models (best for debugging)\n";
}
}
input.close();
//************** Checks/Controlls for INPUT
if (not(yesPixSi))
{
myError("Input missing: please provide PIXEL_SIZE");
}
if (not(yesNumPix))
{
myError("Input missing: please provide NUMBER_PIXELS");
}
if (!notuniformangles)
{
if (!doquater)
{
if (not(yesGPal))
{
myError("Input missing: please provide GRIDPOINTS_ALPHA");
}
if (not(yesGPbe))
{
myError("Input missing: please provide GRIDPOINTS_BETA");
}
}
else if (!yesquatgrid)
{
myError("Input missing: please provide GRIDPOINTS_QUATERNION");
}
}
if (not(yesMDC))
{
myError("Input missing: please provide grid displacement CENTER");
}
cout << "To verify input of Priors:\n";
cout << "Sigma Prior B-Env: " << param_device.sigmaPriorbctf << "\n";
cout << "Sigma Prior Defocus: " << param_device.sigmaPriordefo << "\n";
cout << "Center Prior Defocus: " << param_device.Priordefcent << "\n";
// PSF or CTF Checks and asigments
if (usepsf)
{
if (not(yesPSFpha))
{
myError("Input missing: please provide grid PSF PHASE");
}
if (not(yesPSFenv))
{
myError("Input missing: please provide grid PSF ENVELOPE");
}
if (not(yesAMP))
{
myError("Input missing: please provide grid PSF AMPLITUD");
}
}
else
{
// cout << "Note - Calculation using CTF values (not PSF). If this is not
// correct then key word: USE_PSF missing in inputfile**\n";
if (not(yesBFact))
{
myError("Input missing: please provide grid CTF B Env.");
}
if (not(yesDefocus))
{
myError("Input missing: please provide grid CTF defocus");
}
if (not(yesAMP))
{
myError("Input missing: please provide grid CTF amplitude");
}
// Asigning values of phase according to defocus
startGridCTF_phase = startDefocus * M_PI * 2.f * 10000 * elecwavel;
endGridCTF_phase = endDefocus * M_PI * 2.f * 10000 * elecwavel;
// Asigning values of envelope according to b-envelope (not b-factor)
startGridEnvelop = startBfactor; // 2.f;
endGridEnvelop = endBfactor; // / 2.f;
param_device.Priordefcent *= M_PI * 2.f * 10000 * elecwavel;
param_device.sigmaPriordefo *= M_PI * 2.f * 10000 * elecwavel;
}
if (elecwavel == 0.019688)
cout << "Using default electron wave length: 0.019688 (A) of 300kV "
"microscope\n";
param_device.NumberFFTPixels1D = param_device.NumberPixels / 2 + 1;
FFTMapSize = param_device.NumberPixels * param_device.NumberFFTPixels1D;
nTotParallelMaps = CUDA_FFTS_AT_ONCE;
if (writeCTF && !usepsf)
{
myError("Writing CTF is only valid when integrating over the PSF");
}
cout << " +++++++++++++++++++++++++++++++++++++++++ \n";
return (0);
}
int bioem_param::forprintBest(const char *fileinput)
{
// **************************************************************************************
// **********Alternative parameter routine for only printing out a map
// ******************
ifstream input(fileinput);
withnoise = false;
showrotatemod = false;
writeCTF = false;
elecwavel = 0.019866;
doquater = false;
nocentermass = false;
printrotmod = false;
readquatlist = false;
doaaradius = true;
shiftX = 0;
shiftY = 0;
stnoise = 1;
//**** Different keywords! For printing MAP ************
if (!input.good())
{
myError("Opening best parameter file: %s", fileinput);
}
delete[] angles;
angles = new myfloat3_t[1]; // Only best orientation
char line[512] = {0};
char saveline[512];
bool ctfparam = false;
usepsf = false;
cout << "\n +++++++++++++++++++++++++++++++++++++++++ \n";
cout << "\n ONLY READING BEST PARAMETERS \n";
cout << "\n FOR PRINTING MAXIMIZED MAP \n";
cout << " +++++++++++++++++++++++++++++++++++++++++ \n";
while (input.getline(line, 512))
{
strcpy(saveline, line);
char *token = strtok(line, " ");
if (token == NULL || line[0] == '#' || strlen(token) == 0)
{
// comment or blank line
}
else if (strcmp(token, "PIXEL_SIZE") == 0)
{
token = strtok(NULL, " ");
pixelSize = atof(token);
if (pixelSize < 0)
{
myError("Negative pixel size");
}
cout << "Pixel Size " << pixelSize << "\n";
}
else if (strcmp(token, "NUMBER_PIXELS") == 0)
{
token = strtok(NULL, " ");
param_device.NumberPixels = int(atoi(token));
if (param_device.NumberPixels < 0)
{
myError("Negative number of pixels");
}
cout << "Number of Pixels " << param_device.NumberPixels << "\n";
}
else if (strcmp(token, "BEST_ALPHA") == 0)
{
token = strtok(NULL, " ");
angles[0].pos[0] = atof(token);
cout << "Best Alpha " << angles[0].pos[0] << "\n";
}
else if (strcmp(token, "BEST_BETA") == 0)
{
token = strtok(NULL, " ");
angles[0].pos[1] = atof(token);
cout << "Best beta " << angles[0].pos[1] << "\n";
}
else if (strcmp(token, "BEST_GAMMA") == 0)
{
token = strtok(NULL, " ");
angles[0].pos[2] = atof(token);
cout << "Best Gamma " << angles[0].pos[2] << "\n";
}
else if (strcmp(token, "USE_QUATERNIONS") == 0)
{
cout << "Orientations with Quaternions. \n";
doquater = true;
}
else if (strcmp(token, "BEST_Q1") == 0)
{
token = strtok(NULL, " ");
angles[0].pos[0] = atof(token);
cout << "Best q1 " << angles[0].pos[0] << "\n";
}
else if (strcmp(token, "BEST_Q2") == 0)
{
token = strtok(NULL, " ");
angles[0].pos[1] = atof(token);
cout << "Best q2 " << angles[0].pos[1] << "\n";
}
else if (strcmp(token, "BEST_Q3") == 0)
{
token = strtok(NULL, " ");
angles[0].pos[2] = atof(token);
cout << "Best Q3 " << angles[0].pos[2] << "\n";
}
else if (strcmp(token, "BEST_Q4") == 0)
{
token = strtok(NULL, " ");
angles[0].quat4 = atof(token);
cout << "Best Q3 " << angles[0].quat4 << "\n";
}
else if (strcmp(token, "USE_PSF") == 0)
{
usepsf = true;
cout << "Important: Using Point Spread Function. Thus, all parameters "
"are in Real Space. \n";
}
else if (strcmp(token, "BEST_PSF_ENVELOPE") == 0)
{
token = strtok(NULL, " ");
startGridEnvelop = atof(token);
if (startGridEnvelop < 0)
{
myError("Negative START_ENVELOPE");
}
cout << "Best Envelope PSF " << startGridEnvelop << "\n";
}
else if (strcmp(token, "BEST_PSF_PHASE") == 0)
{
token = strtok(NULL, " ");
startGridCTF_phase = atof(token);
cout << "Best Phase PSF " << startGridCTF_phase << "\n";
}
else if (strcmp(token, "BEST_PSF_AMP") == 0)
{
token = strtok(NULL, " ");
startGridCTF_amp = atof(token);
if (startGridCTF_amp < 0)
{
myError("Negative amplitude");
}
cout << "Best Amplitude PSF " << startGridCTF_amp << "\n";
}
else if (strcmp(token, "BEST_CTF_B_ENV") == 0)
{
token = strtok(NULL, " ");
startGridEnvelop = atof(token); // / 2.f;
if (startGridEnvelop < 0)
{
myError("Negative start B Env.");
}
cout << "Best B- Env " << startGridEnvelop << "\n";
ctfparam = true;
}
else if (strcmp(token, "BEST_CTF_DEFOCUS") == 0)
{
token = strtok(NULL, " ");
startGridCTF_phase = atof(token) * M_PI * 2.f * 10000 * elecwavel;
cout << "Best Defocus " << startGridCTF_phase << "\n";
ctfparam = true;
}
else if (strcmp(token, "BEST_CTF_AMP") == 0)
{
token = strtok(NULL, " ");
startGridCTF_amp = atof(token);
if (startGridCTF_amp < 0)
{
myError("Negative amplitude");
}
cout << "Best Amplitude " << startGridCTF_amp << "\n";
ctfparam = true;
}
else if (strcmp(token, "BEST_DX") == 0)
{
token = strtok(NULL, " ");
ddx = atoi(token);
cout << "Best dx " << ddx << "\n";
}
else if (strcmp(token, "BEST_DY") == 0)
{
token = strtok(NULL, " ");
ddy = atoi(token);
cout << "Best dy " << ddy << "\n";
}
else if (strcmp(token, "BEST_NORM") == 0)
{
token = strtok(NULL, " ");
bestnorm = atof(token);
cout << "Best norm " << bestnorm << "\n";
}
else if (strcmp(token, "BEST_OFFSET") == 0)
{
token = strtok(NULL, " ");
bestoff = atof(token);
cout << "Best offset " << bestoff << "\n";
}
else if (strcmp(token, "WITHNOISE") == 0)
{
token = strtok(NULL, " ");
stnoise = atof(token);
withnoise = true;
cout << "Including noise with standard deviation " << stnoise << "\n";
}
else if (strcmp(token, "NO_PROJECT_RADIUS") ==
0) // If projecting CA with amino-acid radius
{
doaaradius = false;
cout << "Not projecting corresponding radius \n";
}
else if (strcmp(token, "PRINT_ROTATED_MODELS") == 0) // Number of Euler
// angle tripplets in
// non uniform Euler
// angle sampling
{
printrotmod = true;
cout << "Printing out rotated models (best for debugging)\n";
}
else if (strcmp(token, "SHIFT_X") == 0)
{
token = strtok(NULL, " ");
shiftX = atoi(token);
cout << "Shifting initial model X by " << shiftX << "\n";
}
else if (strcmp(token, "SHIFT_Y") == 0)
{
token = strtok(NULL, " ");
shiftY = atoi(token);
cout << "Shifting initial model Y by " << shiftY << "\n";
}
}
if (doquater)
{
if (angles[0].quat4 * angles[0].quat4 > 1)
{
myError("Quaternion %lf", angles[0].quat4);
}
if (angles[0].pos[0] * angles[0].pos[0] > 1)
{
myError("Quaternion %lf", angles[0].pos[0]);
}
if (angles[0].pos[1] * angles[0].pos[1] > 1)
{
myError("Quaternion %lf", angles[0].pos[1]);
}
if (angles[0].pos[2] * angles[0].pos[2] > 1)
{
myError("Quaternion %lf", angles[0].pos[2]);
}
}
input.close();
if (usepsf && ctfparam)
{
myError("Inconsitent input: using both PSF and CTF?");
}
// Automatic definitions
numberGridPointsCTF_amp = 1;
gridCTF_amp = startGridCTF_amp;
numberGridPointsCTF_phase = 1;
gridCTF_phase = startGridCTF_phase;
numberGridPointsEnvelop = 1;
gridEnvelop = startGridEnvelop;
// doquater = false;
param_device.NumberFFTPixels1D = param_device.NumberPixels / 2 + 1;
FFTMapSize = param_device.NumberPixels * param_device.NumberFFTPixels1D;
nTotParallelMaps = CUDA_FFTS_AT_ONCE;
return 0;
}
void bioem_param::PrepareFFTs()
{
//********** PREPARING THE PLANS FOR THE FFTS ******************
if (mpi_rank == 0)
cout << "Preparing FFTs\n";
releaseFFTPlans();
mycomplex_t *tmp_map, *tmp_map2;
tmp_map = (mycomplex_t *) myfftw_malloc(sizeof(mycomplex_t) *
param_device.NumberPixels *
param_device.NumberPixels);
tmp_map2 = (mycomplex_t *) myfftw_malloc(sizeof(mycomplex_t) *
param_device.NumberPixels *
param_device.NumberPixels);
Alignment = 64;
fft_plan_c2c_forward = myfftw_plan_dft_2d(
param_device.NumberPixels, param_device.NumberPixels, tmp_map, tmp_map2,
FFTW_FORWARD, FFTW_MEASURE | FFTW_DESTROY_INPUT);
fft_plan_c2c_backward = myfftw_plan_dft_2d(
param_device.NumberPixels, param_device.NumberPixels, tmp_map, tmp_map2,
FFTW_BACKWARD, FFTW_MEASURE | FFTW_DESTROY_INPUT);
fft_plan_r2c_forward = myfftw_plan_dft_r2c_2d(
param_device.NumberPixels, param_device.NumberPixels,
(myfloat_t *) tmp_map, tmp_map2, FFTW_MEASURE | FFTW_DESTROY_INPUT);
fft_plan_c2r_backward = myfftw_plan_dft_c2r_2d(
param_device.NumberPixels, param_device.NumberPixels, tmp_map,
(myfloat_t *) tmp_map2, FFTW_MEASURE | FFTW_DESTROY_INPUT);
if (fft_plan_c2c_forward == 0 || fft_plan_c2c_backward == 0 ||
fft_plan_r2c_forward == 0 || fft_plan_c2r_backward == 0)
{
myError("Planning FFTs");
}
myfftw_free(tmp_map);
myfftw_free(tmp_map2);
const int count = omp_get_max_threads();
fft_scratch_complex = new mycomplex_t *[count];
fft_scratch_real = new myfloat_t *[count];
#pragma omp parallel
{
#pragma omp critical
{
const int i = omp_get_thread_num();
fft_scratch_complex[i] = (mycomplex_t *) myfftw_malloc(
sizeof(mycomplex_t) * param_device.NumberPixels *
param_device.NumberFFTPixels1D);
fft_scratch_real[i] = (myfloat_t *) myfftw_malloc(
sizeof(myfloat_t) * param_device.NumberPixels *
param_device.NumberPixels);
}
}
fft_plans_created = 1;
}
void bioem_param::releaseFFTPlans()
{
if (fft_plans_created)
{
const int count = omp_get_max_threads();
for (int i = 0; i < count; i++)
{
myfftw_free(fft_scratch_complex[i]);
myfftw_free(fft_scratch_real[i]);
}
delete[] fft_scratch_complex;
delete[] fft_scratch_real;
myfftw_destroy_plan(fft_plan_c2c_forward);
myfftw_destroy_plan(fft_plan_c2c_backward);
myfftw_destroy_plan(fft_plan_r2c_forward);
myfftw_destroy_plan(fft_plan_c2r_backward);
myfftw_cleanup();
}
fft_plans_created = 0;
}
int bioem_param::CalculateGridsParam(
const char *fileangles) // TO DO FOR QUATERNIONS
{
// **************************************************************************************
// **************** Routine that pre-calculates Orientation
// Grids**********************
// ************************************************************************************
if (!doquater)
{
//*********** With Euler angles *******************
cout << "Analysis Using Default Euler Angles\n";
if (!notuniformangles)