-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmolgroups.cc
executable file
·6538 lines (5321 loc) · 208 KB
/
molgroups.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
/*
* molgroups.cc
* Gauss
*
* Created by Frank Heinrich on 27/10/08.
* updated July-2013
* Copyright 2008 __MyCompanyName__. All rights reserved.
*
*/
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "math.h"
#include "molgroups.h"
//------------------------------------------------------------------------------------------------------
//Parent Object Implementation
nSLDObj::nSLDObj()
{
bWrapping=true;
bConvolution=false;
bProtonExchange=false;
dSigmaConvolution=1;
iNumberOfConvPoints=7;
absorb=0;
};
nSLDObj::~nSLDObj(){};
double nSLDObj::fnGetAbsorb(double z){return absorb;};
// returns a n-point gaussian interpolation of the area within 4 sigma
// all area calculatioins are routed through this function, whether they use convolution or not
// convolution works only for objects with fixed nSLD. Broadening an nSLD profile is not as direct as
// broadening a nSL profile. For reason, however, objects report a nSLD(z) and not a nSL(z)
// if it becomes necessary to broaden profiles with variable nSLD, structural changes to the code
// have to be implemented.
double nSLDObj::fnGetConvolutedArea(double dz)
{
int i;
double dgauss, dnormsum, dsum, dd;
if (bConvolution==true) {
dnormsum=0; dsum=0;
for (i=0; i<iNumberOfConvPoints; i++) {
dd=8/(double)iNumberOfConvPoints*(double)i-4;
dgauss=exp((-0.5)*dd*dd); //(sigma_convolution)^2/(sigma_convolution)^2 cancels
dnormsum+=dgauss;
dsum+=fnGetArea(dz+dd*dSigmaConvolution)*dgauss;
}
if (dnormsum!=0) {
return dsum/dnormsum;
}
else return 0;
}
else {
return fnGetArea(dz);
}
}
void nSLDObj::fnSetConvolution(double _sigma_convolution, int _iNumberOfConvPoints)
{
bConvolution=true;
dSigmaConvolution=_sigma_convolution;
iNumberOfConvPoints=_iNumberOfConvPoints;
}
void nSLDObj::fnWriteData2File(FILE *fp, const char *cName, int dimension, double stepsize)
{
double dLowerLimit, dUpperLimit, d, dmirror, dAreaInc, dnSLDInc;
int i;
fprintf(fp, "z%s a%s nsl%s \n",cName, cName, cName);
dLowerLimit=fnGetLowerLimit();
dUpperLimit=fnGetUpperLimit();
d=floor(dLowerLimit/stepsize+0.5)*stepsize;
for (i=0; i<dimension; i++)
{
d=double(i)*stepsize;
dmirror=d-float(2*i)*stepsize;
if ((bWrapping==true) && (dmirror>=dLowerLimit))
{
dAreaInc=fnGetConvolutedArea(d)+fnGetConvolutedArea(dmirror);
dnSLDInc=(fnGetnSLD(d)*fnGetConvolutedArea(d)+fnGetnSLD(dmirror)*fnGetConvolutedArea(dmirror))/(fnGetConvolutedArea(d)+fnGetConvolutedArea(dmirror));
//printf("Bin %i Area %f nSLD %e nSL %e \n", i, dAreaInc, fnGetnSLD(d), fnGetnSLD(d)*dAreaInc*stepsize);
}
else
{
dAreaInc=fnGetConvolutedArea(d);
dnSLDInc=fnGetnSLD(d);
//printf("Bin %i z %g Area %f nSLD %e nSL %e \n", i, d, dAreaInc, fnGetnSLD(d), fnGetnSLD(d)*dAreaInc*stepsize);
}
fprintf(fp, "%lf %lf %e \n", d, dAreaInc, dnSLDInc*dAreaInc*stepsize);
};
fprintf(fp, "\n");
}
//does a Catmull-Rom Interpolation on an equal distance grid
// 0<t<=1 is the relative position on the interval between p0 and p1
// p-1 and p2 are needed for derivative calculation
double nSLDObj::CatmullInterpolate(double t, double pm1, double p0, double p1, double p2){
double m0, m1, t_2, t_3, h00, h10, h01, h11;
m0=(p1-pm1)/2;
m1=(p2-p0) /2;
t_2=t*t;
t_3=t_2*t;
h00= 2*t_3-3*t_2+1;
h10= t_3-2*t_2+t;
h01=(-2)*t_3+3*t_2;
h11= t_3-t_2;
return h00*p0+h10*m0+h01*p1+h11*m1;
};
double nSLDObj::fnTriCubicCatmullInterpolate(double p[4][4][4],double t[3]){
double dFirstStage[4][4];
double dSecondStage[4];
int i,j;
for (i=0; i<4; i++){
for (j=0; j<4; j++){
dFirstStage[i][j]=CatmullInterpolate(t[0],p[0][i][j],p[1][i][j],p[2][i][j],p[3][i][j]);
}
}
for (i=0; i<4; i++){
dSecondStage[i]=CatmullInterpolate(t[1],dFirstStage[0][i],dFirstStage[1][i],dFirstStage[2][i],dFirstStage[3][i]);
}
return CatmullInterpolate(t[2],dSecondStage[0],dSecondStage[1],dSecondStage[2],dSecondStage[3]);
};
//Philosophy for this first method: You simply add more and more volume and nSLD to the
//volume and nSLD array. After all objects have filled up those arrays the maximal area is
//determined which is the area per molecule and unfilled volume is filled with bulk solvent.
//Hopefully the fit algorithm finds a physically meaningful solution. There has to be a global
//hydration paramter for the bilayer.
//Returns maximum area
double nSLDObj::fnWriteProfile(double aArea[], double anSL[], int dimension, double stepsize, double dMaxArea)
{
double dLowerLimit, dUpperLimit, d, dAreaInc, dprefactor;
int i;
dLowerLimit=fnGetLowerLimit();
dUpperLimit=fnGetUpperLimit();
if (dUpperLimit==0)
{
dUpperLimit=double(dimension)*stepsize;
}
d=floor(dLowerLimit/stepsize+0.5)*stepsize;
while (d<=dUpperLimit)
{
i=int(d/stepsize);
dprefactor=1;
if ((i<0) && (bWrapping==true)) {i=-1*i;};
if ((i==0) && (bWrapping==true)) {dprefactor=2;} //avoid too low filling when mirroring
if ((i>=0) && (i<dimension))
{
dAreaInc=fnGetConvolutedArea(d);
aArea[i]=aArea[i]+dAreaInc*dprefactor;
if (aArea[i]>dMaxArea) {dMaxArea=aArea[i];};
anSL[i]=anSL[i]+fnGetnSLD(d)*dAreaInc*stepsize*dprefactor;
//printf("Bin %i AreaInc %g total %g MaxArea %g nSL %f total %f \n", i, dAreaInc, aArea[i], dMaxArea, fnGetnSLD(d)*dAreaInc*stepsize, anSL[i]);
}
d=d+stepsize;
};
return dMaxArea;
};
double nSLDObj::fnWriteProfile(double aArea[], double anSL[], double aAbsorb[], int dimension, double stepsize, double dMaxArea)
{
double dLowerLimit, dUpperLimit, d, dAreaInc, dprefactor;
int i;
dLowerLimit=fnGetLowerLimit();
dUpperLimit=fnGetUpperLimit();
if (dUpperLimit==0)
{
dUpperLimit=double(dimension)*stepsize;
}
d=floor(dLowerLimit/stepsize+0.5)*stepsize;
while (d<=dUpperLimit)
{
i=int(d/stepsize);
dprefactor=1;
//printf("Here we are %i, dimension %i \n", i, dimension);
if ((i<0) && (bWrapping==true)) {i=-1*i;};
if ((i==0) && (bWrapping==true)) {dprefactor=2;} //avoid too low filling when mirroring
if ((i>=0) && (i<dimension))
{
//printf("Bin %i Areainc %f area now %f nSLD %g Absorbinc %g Absorb now %g nSLinc %g nSL now %g \n", i, dAreaInc, aArea[i], fnGetnSLD(d), aAbsorb[i], fnGetAbsorb(d)*dAreaInc*stepsize, fnGetnSLD(d)*dAreaInc*stepsize, anSL[i]);
dAreaInc=fnGetConvolutedArea(d);
aArea[i]=aArea[i]+dAreaInc*dprefactor;
if (aArea[i]>dMaxArea) {dMaxArea=aArea[i];};
anSL[i]=anSL[i]+fnGetnSLD(d)*dAreaInc*stepsize*dprefactor;
aAbsorb[i]=aAbsorb[i]+fnGetAbsorb(d)*dAreaInc*stepsize*dprefactor;
//printf("Bin %i Area %f total %f nSL %f total %f \n", i, dAreaInc, aArea[i], fnGetnSLD(d)*dAreaInc*stepsize, anSL[i]);
}
d=d+stepsize;
};
return dMaxArea;
};
void nSLDObj::fnOverlayProfile(double aArea[], double anSL[], int dimension, double stepsize, double dMaxArea)
{
double dLowerLimit, dUpperLimit, d, dAreaInc, dprefactor, temparea;
int i;
dLowerLimit=fnGetLowerLimit();
dUpperLimit=fnGetUpperLimit();
if (dUpperLimit==0)
{
dUpperLimit=double(dimension)*stepsize;
}
d=floor(dLowerLimit/stepsize+0.5)*stepsize;
while (d<=dUpperLimit)
{
i=int(d/stepsize);
dprefactor=1;
if ((i<0) && (bWrapping==true)) {i=-1*i;};
if ((i==0) && (bWrapping==true)) {dprefactor=2;} //avoid too low filling when mirroring
if ((i>=0) && (i<dimension))
{
dAreaInc=fnGetConvolutedArea(d);
temparea=dAreaInc*dprefactor+aArea[i];
if (temparea<=dMaxArea) {
aArea[i]=aArea[i]+dAreaInc*dprefactor;
anSL[i]=anSL[i]+fnGetnSLD(d)*dAreaInc*stepsize*dprefactor;
}
else {
if ((temparea-dMaxArea)<=aArea[i]) //overfill is not larger than existing area
{
anSL[i]=anSL[i]*(1-((temparea-dMaxArea)/aArea[i])); //eliminate the overfilled portion using original content
anSL[i]=anSL[i]+fnGetnSLD(d)*dAreaInc*stepsize*dprefactor;
aArea[i]=dMaxArea;
//printf("Replace: Bin %i temparea %g Areainc %g area now %g dMaxArea %g nSLD %g nSLinc %g nSL now %g \n", i, temparea, dAreaInc, aArea[i], dMaxArea, fnGetnSLD(d), fnGetnSLD(d)*dAreaInc*stepsize, anSL[i]);
}
else //overfill is larger!!, this is non-physical
{
anSL[i]=fnGetnSLD(d)*dMaxArea*stepsize;
aArea[i]=dMaxArea;
};
}
}
d=d+stepsize;
}
};
void nSLDObj::fnOverlayProfile(double aArea[], double anSL[], double aAbsorb[], int dimension, double stepsize, double dMaxArea)
{
double dLowerLimit, dUpperLimit, d, dAreaInc, dprefactor, temparea;
int i;
dLowerLimit=fnGetLowerLimit();
dUpperLimit=fnGetUpperLimit();
if (dUpperLimit==0)
{
dUpperLimit=double(dimension)*stepsize;
}
d=floor(dLowerLimit/stepsize+0.5)*stepsize;
while (d<=dUpperLimit)
{
i=int(d/stepsize);
dprefactor=1;
//printf("Here we are %i, dimension %i, maxarea %f \n", i, dimension, dMaxArea);
if ((i<0) && (bWrapping==true)) {i=-1*i;};
if ((i==0) && (bWrapping==true)) {dprefactor=2;} //avoid too low filling when mirroring
if ((i>=0) && (i<dimension))
{
dAreaInc=fnGetConvolutedArea(d);
temparea=dAreaInc*dprefactor+aArea[i];
if (temparea>dMaxArea) {
//printf("Bin %i Areainc %f area now %f nSLD %g Absorbinc %g Absorb now %g nSLinc %g nSL now %g \n", i, dAreaInc, aArea[i], fnGetnSLD(d), aAbsorb[i], fnGetAbsorb(d)*dAreaInc*stepsize, fnGetnSLD(d)*dAreaInc*stepsize, anSL[i]);
anSL[i]=anSL[i]*(1-((temparea-dMaxArea)/aArea[i])); //eliminate the overfilled portion using original content
anSL[i]=anSL[i]+fnGetnSLD(d)*dAreaInc*stepsize*dprefactor;
aAbsorb[i]=aAbsorb[i]*(1-((temparea-dMaxArea)/aArea[i])); //eliminate the overfilled portion using original content
aAbsorb[i]=aAbsorb[i]+fnGetAbsorb(d)*dAreaInc*stepsize*dprefactor;
aArea[i]=dMaxArea;
}
else {
//printf("Bin %i Areainc %f area now %f nSLD %g Absorbinc %g Absorb now %g nSLinc %g nSL now %g \n", i, dAreaInc, aArea[i], fnGetnSLD(d), aAbsorb[i], fnGetAbsorb(d)*dAreaInc*stepsize, fnGetnSLD(d)*dAreaInc*stepsize, anSL[i]);
aArea[i]=aArea[i]+dAreaInc*dprefactor;
anSL[i]=anSL[i]+fnGetnSLD(d)*dAreaInc*stepsize*dprefactor;
aAbsorb[i]=aAbsorb[i]+fnGetAbsorb(d)*dAreaInc*stepsize*dprefactor;
}
}
d=d+stepsize;
};
};
//------------------------------------------------------------------------------------------------------
//Function Object Implementation
//------------------------------------------------------------------------------------------------------
BoxErr::BoxErr(double dz, double dsigma, double dlength, double dvolume, double dnSL, double dnumberfraction=1)
{
z=dz; sigma=dsigma; l=dlength, vol=dvolume, nSL=dnSL, nf=dnumberfraction;
};
BoxErr::~BoxErr(){};
//Gaussian function definition, integral is volume, return value is area at position z
double BoxErr::fnGetArea(double dz) {
return (vol/l)*0.5*(erf((dz-z+0.5*l)/sqrt(2)/sigma)-erf((dz-z-0.5*l)/sqrt(2)/sigma))*nf;
};
//constant nSLD
double BoxErr::fnGetnSLD(double dz) {return nSL/vol;};
//Gaussians are cut off below and above 3 sigma
double BoxErr::fnGetLowerLimit() {return z-0.5*l-3*sigma;};
double BoxErr::fnGetUpperLimit() {return z+0.5*l+3*sigma;};
void BoxErr::fnWritePar2File(FILE *fp, const char *cName, int dimension, double stepsize)
{
fprintf(fp, "BoxErr %s z %lf sigma %lf l %lf vol %lf nSL %e nf %lf \n",cName, z, sigma, l, vol, nSL, nf);
nSLDObj::fnWriteData2File(fp, cName, dimension, stepsize);
}
//------------------------------------------------------------------------------------------------------
Box2Err::Box2Err(double dz, double dsigma1, double dsigma2, double dlength, double dvolume, double dnSL, double dnumberfraction=1)
{
z=dz; sigma1=dsigma1; sigma2=dsigma2; l=dlength, vol=dvolume, nSL=dnSL, nf=dnumberfraction;
nsldbulk_store=0;
};
Box2Err::~Box2Err(){};
//Gaussian function definition, integral is volume, return value is area at position z
double Box2Err::fnGetArea(double dz) {
if ((l!=0) && (sigma1!=0) && (sigma2!=0)) {
return (vol/l)*0.5*(erf((dz-z+0.5*l)/sqrt(2)/sigma1)-erf((dz-z-0.5*l)/sqrt(2)/sigma2))*nf;
}
else {
return 0;
}
};
double Box2Err::fnGetnSL(double bulknsld) {
if (bProtonExchange) {
if (vol!=0) {
return ((bulknsld+0.56e-6)*nSL2+(6.36e-6-bulknsld)*nSL)/(6.36e-6+0.56e-6);
}
else {
return 0;
}
}
else {
return nSL;
}
};
//constant nSLD
double Box2Err::fnGetnSLD(double dz) {
if (vol!=0) {
if (bProtonExchange) {
return ((nsldbulk_store+0.56e-6)*nSL2+(6.36e-6-nsldbulk_store)*nSL)/(6.36e-6+0.56e-6)/vol;
}
else {
return nSL/vol;
}
}
else {
return 0;
}
}
double Box2Err::fnGetnSLD(double dz, double bulknsld) {
if (bProtonExchange) {
if (vol!=0) {
nsldbulk_store=bulknsld; //store bulk solvent for later plotting purposes
return ((bulknsld+0.56e-6)*nSL2+(6.36e-6-bulknsld)*nSL)/(6.36e-6+0.56e-6)/vol;
}
else {
return 0;
}
}
else {
return fnGetnSLD(dz);
}
};
//Gaussians are cut off below and above 3 sigma
double Box2Err::fnGetLowerLimit() {return z-0.5*l-3*sigma1;};
double Box2Err::fnGetUpperLimit() {return z+0.5*l+3*sigma2;};
void Box2Err::fnSetnSL(double _nSL, double _nSL2)
{
nSL=_nSL;
nSL2=_nSL2;
bProtonExchange=true;
}
void Box2Err::fnSetSigma(double sigma)
{
sigma1=sigma;
sigma2=sigma;
}
void Box2Err::fnSetSigma(double dsigma1, double dsigma2)
{
sigma1=dsigma1;
sigma2=dsigma2;
}
void Box2Err::fnSetZ(double dz)
{
z=dz;
};
void Box2Err::fnWritePar2File(FILE *fp, const char *cName, int dimension, double stepsize)
{
fprintf(fp, "Box2Err %s z %lf sigma1 %lf sigma2 %lf l %lf vol %lf nSL %lf nSL2 %e nf %lf \n",cName, z, sigma1, sigma2, l, vol, nSL, nSL2, nf);
nSLDObj::fnWriteData2File(fp, cName, dimension, stepsize);
}
//------------------------------------------------------------------------------------------------------
Gaussian::Gaussian(double dz, double dsigma, double dvolume, double dnSL, double dnumberfraction=1)
{
z=dz; sigma=dsigma; vol=dvolume, nSL=dnSL, nf=dnumberfraction;
};
Gaussian::~Gaussian(){};
//Gaussian function definition, integral is volume, return value is area at position z
double Gaussian::fnGetArea(double dz) {return (vol/sqrt(2*3.141592654)/sigma)*exp(-0.5*(z-dz)*(z-dz)/sigma/sigma)*nf;};
//constant nSLD
double Gaussian::fnGetnSLD(double dz) {return nSL/vol;};
//Gaussians are cut off below and above 3 sigma
double Gaussian::fnGetLowerLimit() {return z-3*sigma;};
double Gaussian::fnGetUpperLimit() {return z+3*sigma;};
void Gaussian::fnWritePar2File(FILE *fp, const char *cName, int dimension, double stepsize)
{
fprintf(fp, "Gaussian %s z %lf sigma %lf vol %lf nSL %e nf %lf \n",cName, z, sigma, vol, nSL, nf);
nSLDObj::fnWriteData2File(fp, cName, dimension, stepsize);
}
//------------------------------------------------------------------------------------------------------
Parabolic::Parabolic(double dC, double dH, double dn, double dnSLD, double dnumberfraction=1)
{
C=dC; H=dH, n=dn, nSLD=dnSLD, nf=dnumberfraction;
bWrapping=false;
};
Parabolic::~Parabolic(){};
//Gaussian function definition, integral is volume, return value is area at position z
double Parabolic::fnGetArea(double dz) {
if (dz<H) {return C*(1-pow(dz/H,n))*nf;}
else {return 0;}
};
//constant nSLD
double Parabolic::fnGetnSLD(double dz) {return nSLD;};
//Gaussians are cut off below and above 3 sigma
double Parabolic::fnGetLowerLimit() {return 0;};
double Parabolic::fnGetUpperLimit() {return 0;};
void Parabolic::fnWritePar2File(FILE *fp, const char *cName, int dimension, double stepsize)
{
fprintf(fp, "Parabolic %s C %lf H %lf n %lf nSLD %e nf %lf \n",cName, C, H, n, nSLD, nf);
nSLDObj::fnWriteData2File(fp, cName, dimension, stepsize);
}
//------------------------------------------------------------------------------------------------------
StretchGaussian::StretchGaussian(double dz, double dsigma, double dlength, double dvolume, double dnSL, double dnumberfraction=1)
{
z=dz; sigma=dsigma; l=dlength, vol=dvolume, nSL=dnSL, nf=dnumberfraction;
};
StretchGaussian::~StretchGaussian(){};
//Gaussian function definition, integral is volume, return value is area at position z
double StretchGaussian::fnGetArea(double dz) {
double returnvalue;
double temp, dvgauss;
temp=sqrt(2*3.141592654)*sigma;
dvgauss=vol/(1+l/temp);
if (dz<(z-0.5*l))
{
returnvalue=dvgauss/temp*exp(-0.5*(z-dz-0.5*l)*(z-dz-0.5*l)/sigma*sigma)*nf;
}
else if ((dz>=(z-0.5*l)) && (dz<=(z+0.5*l)))
{
returnvalue=dvgauss/temp*nf;
}
else
{
returnvalue=dvgauss/temp*exp(-0.5*(dz-z-0.5*l)*(dz-z-0.5*l)/sigma*sigma)*nf;
}
return returnvalue;
};
//constant nSLD
double StretchGaussian::fnGetnSLD(double dz) {return nSL/vol;};
//Gaussians are cut off below and above 3 sigma
double StretchGaussian::fnGetLowerLimit() {return z-0.5*l-3*sigma;};
double StretchGaussian::fnGetUpperLimit() {return z+0.5*l+3*sigma;};
void StretchGaussian::fnWritePar2File(FILE *fp, const char *cName, int dimension, double stepsize)
{
fprintf(fp, "Gaussian %s z %lf sigma %lf l %lf vol %lf nSL %e nf %lf \n",cName, z, sigma, l, vol, nSL, nf);
nSLDObj::fnWriteData2File(fp, cName, dimension, stepsize);
}
//------------------------------------------------------------------------------------------------------
// Combined Object Implementation
//------------------------------------------------------------------------------------------------------
PC::PC()
{
cg = new Box2Err(0,0,0,0,0,0,1);
phosphate = new Box2Err(0,0,0,0,0,0,1);
choline = new Box2Err(0,0,0,0,0,0,1);
cg->l=4.21; phosphate->l=3.86; choline->l=6.34; //from fit to Feller data
cg->sigma1=2.53; cg->sigma2=2.29;
phosphate->sigma1=2.29; phosphate->sigma2=2.02;
choline->sigma1=2.02; choline->sigma2=2.26;
//from fit to Feller data
l=9.575; //group cg phosphate choline
//z 15.00 18.44 19.30
//l 4.21 3.86 6.34
cg->vol=147; phosphate->vol=54; choline->vol=120; //nominal values
cg->nSL=3.7755e-4; phosphate->nSL=2.8350e-4; choline->nSL=-6.0930e-5;
cg->nf=1; phosphate->nf=1; choline->nf=1;
vol=cg->vol+phosphate->vol+choline->vol;
nSL=cg->nSL+phosphate->nSL+choline->nSL;
fnAdjustParameters();
};
PC::~PC(){
delete cg;
delete phosphate;
delete choline;
};
void PC::fnAdjustParameters(){
cg->z=z-0.5*l+0.5*cg->l; phosphate->z=z-0.5*l+cg->l+0.5*phosphate->l;
choline->z=z+0.5*l-0.5*choline->l;
};
//Return value is area at position z
double PC::fnGetArea(double dz) {
return (cg->fnGetArea(dz)+phosphate->fnGetArea(dz)+choline->fnGetArea(dz))*nf;
};
double PC::fnGetTotalnSL(){
return cg->nSL+phosphate->nSL+choline->nSL;
};
//get nSLD from molecular subgroups
double PC::fnGetnSLD(double dz) {
double cgarea, pharea, charea, sum;
cgarea=cg->fnGetArea(dz);
pharea=phosphate->fnGetArea(dz);
charea=choline->fnGetArea(dz);
sum=cgarea+pharea+charea;
if (sum==0) {return 0;}
else {
return (cg->fnGetnSLD(dz)*cgarea+
phosphate->fnGetnSLD(dz)*pharea+
choline->fnGetnSLD(dz)*charea)/sum;
}
};
//Use limits of molecular subgroups
double PC::fnGetLowerLimit() {return cg->fnGetLowerLimit();};
double PC::fnGetUpperLimit() {return choline->fnGetUpperLimit();};
void PC::fnSetSigma(double sigma)
{
cg->sigma1=sigma;
cg->sigma2=sigma;
phosphate->sigma1=sigma;
phosphate->sigma2=sigma;
choline->sigma1=sigma;
choline->sigma2=sigma;
};
void PC::fnSetZ(double dz){
z=dz;
fnAdjustParameters();
};
void PC::fnWritePar2File(FILE *fp, const char *cName, int dimension, double stepsize)
{
//char *str = new char[80];
fprintf(fp, "PC %s z %lf l %lf vol %lf nf %lf \n",cName, z, l,cg->vol+phosphate->vol+choline->vol, nf);
nSLDObj::fnWriteData2File(fp, cName, dimension, stepsize);
//cg->fnWritePar2File(fp, "cg", dimension, stepsize);
//phosphate->fnWritePar2File(fp, "phosphate", dimension, stepsize);
//choline->fnWritePar2File(fp, "choline", dimension, stepsize);
//delete []str;
}
//------------------------------------------------------------------------------------------------------
PCm::PCm()
{
cg->sigma2=2.53; cg->sigma1=2.29; //from fit to Feller data
phosphate->sigma2=2.29; phosphate->sigma1=2.02;
choline->sigma2=2.02; choline->sigma1=2.26;
fnAdjustParameters();
};
PCm::~PCm() {};
void PCm::fnAdjustParameters(){
cg->z=z+0.5*l-0.5*cg->l; phosphate->z=z+0.5*l-cg->l-0.5*phosphate->l;
choline->z=z-0.5*l+0.5*choline->l;
};
//Use limits of molecular subgroups
double PCm::fnGetLowerLimit() {return cg->fnGetLowerLimit();};
double PCm::fnGetUpperLimit() {return choline->fnGetUpperLimit();};
void PCm::fnWritePar2File(FILE *fp, const char *cName, int dimension, double stepsize)
{
//char *str = new char[80];
fprintf(fp, "PCm %s z %lf l %lf vol %lf nf %lf \n",cName, z, l,cg->vol+phosphate->vol+choline->vol, nf);
nSLDObj::fnWriteData2File(fp, cName, dimension, stepsize);
//cg->fnWritePar2File(fp, "cg_m", dimension, stepsize);
//phosphate->fnWritePar2File(fp, "phosphate_m", dimension, stepsize);
//choline->fnWritePar2File(fp, "choline_m", dimension, stepsize);
//delete []str;
}
//---------------------------------------------------------------------------------------------------------------
PS::PS()
{
cg = new Box2Err(0,0,0,0,0,0,1);
phosphate = new Box2Err(0,0,0,0,0,0,1);
serine = new Box2Err(0,0,0,0,0,0,1);
cg->l=3.6; phosphate->l=2.0; serine->l=3.0; //from fit to Feller data
cg->sigma1=2.53; cg->sigma2=2.29;
phosphate->sigma1=2.29; phosphate->sigma2=2.02;
serine->sigma1=2.02; serine->sigma2=2.26;
//from fit to Feller data
l=8.6; //group cg phosphate choline
//z 15.00 18.44 19.30
//l 4.21 3.86 6.34
cg->vol=147; phosphate->vol=54; serine->vol=80; //nominal values
cg->nSL=3.7755e-4; phosphate->nSL=2.8350e-4; serine->nSL=1.8408E-04;
cg->nf=1; phosphate->nf=1; serine->nf=1;
fnAdjustParameters();
};
PS::~PS(){
delete cg;
delete phosphate;
delete serine;
};
void PS::fnAdjustParameters(){
cg->z=z-0.5*l+0.5*cg->l; phosphate->z=z-0.5*l+cg->l+0.5*phosphate->l;
serine->z=z+0.5*l-0.5*serine->l;
};
//Return value is area at position z
double PS::fnGetArea(double dz) {
return (cg->fnGetArea(dz)+phosphate->fnGetArea(dz)+serine->fnGetArea(dz))*nf;
};
//get nSLD from molecular subgroups
double PS::fnGetnSLD(double dz) {
double cgarea, pharea, searea, sum;
cgarea=cg->fnGetArea(dz);
pharea=phosphate->fnGetArea(dz);
searea=serine->fnGetArea(dz);
sum=cgarea+pharea+searea;
if (sum==0) {return 0;}
else {
return (cg->fnGetnSLD(dz)*cgarea+
phosphate->fnGetnSLD(dz)*pharea+
serine->fnGetnSLD(dz)*searea)/sum;
}
};
//Use limits of molecular subgroups
double PS::fnGetLowerLimit() {return cg->fnGetLowerLimit();};
double PS::fnGetUpperLimit() {return serine->fnGetUpperLimit();};
void PS::fnSetSigma(double sigma)
{
cg->sigma1=sigma;
cg->sigma2=sigma;
phosphate->sigma1=sigma;
phosphate->sigma2=sigma;
serine->sigma1=sigma;
serine->sigma2=sigma;
};
void PS::fnSetZ(double dz){
z=dz;
fnAdjustParameters();
};
void PS::fnSetnSL(double nSL_cg, double nSL_phosphate, double nSL_serine){
//printf("nSL cg %e nSL phosphate %e nSL serine %e \n", nSL_cg, nSL_phosphate, nSL_serine);
cg->nSL=nSL_cg;
phosphate->nSL=nSL_phosphate;
serine->nSL=nSL_serine;
}
void PS::fnWritePar2File(FILE *fp, const char *cName, int dimension, double stepsize)
{
//char *str = new char[80];
//fprintf(fp, "PC %s z %lf l %lf nf %lf \n",cName, z, l, nf);
//nSLDObj::fnWriteData2File(fp, cName, dimension, stepsize);
cg->fnWritePar2File(fp, "cg", dimension, stepsize);
phosphate->fnWritePar2File(fp, "phosphate", dimension, stepsize);
serine->fnWritePar2File(fp, "serine", dimension, stepsize);
//delete []str;
}
//-----------------------------------------------------------------------------------------------------------
//Amino Acids
//-----------------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------------
//general implementation
//-----------------------------------------------------------------------------------------------------------
//ExchangeRatio is not yet fully implemented
AminoAcid::AminoAcid()
{
ExchangeRatio=0;
Deuterated=0;
}
double AminoAcid::fnGetnSLD(double z)
{
double temp;
if (Deuterated==1) {temp=1;}
else {temp=0.;}
//correct for deuterated residues
return (nSL-temp*float(nH)*(-3.741e-5)+temp*float(nH)*(6.674e-5))/vol;
}
//-----------------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------------
//Specific implementations
//-----------------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------------
AA_Lys::AA_Lys()
{
nSL=1.5660e-4;
vol=171.3;
nH=13;
nExch=4;
}
AA_Arg::AA_Arg()
{
nSL=3.4260e-4;
vol=202.1;
nH=13;
nExch=6;
}
AA_His::AA_His()
{
nSL=4.7406e-4;
vol=167.3;
nH=7;
nExch=3;
}
AA_Asn::AA_Asn()
{
nSL=3.4356e-4;
vol=135.2;
nH=6;
nExch=3;
}
AA_Asp::AA_Asp()
{
nSL=3.8343e-4;
vol=124.5;
nH=4;
nExch=1;
}
AA_Cys::AA_Cys()
{
nSL=1.9191e-4;
vol=105.6;
nH=5;
nExch=1;
}
AA_Thr::AA_Thr()
{
nSL=2.1315e-4;
vol=122.1;
nH=7;
nExch=2;
}
AA_Ser::AA_Ser()
{
nSL=2.2149e-4;
vol=99.1;
nH=5;
nExch=2;
}
AA_Gln::AA_Gln()
{
nSL=3.3522e-4;
vol=161.1;
nH=8;
nExch=3;
}
AA_Glu::AA_Glu()
{
nSL=3.7509e-4;
vol=155.1;
nH=6;
nExch=1;
}
AA_Pro::AA_Pro()
{
nSL=2.2158e-4;
vol=129.3;
nH=7;
nExch=0;
}
AA_Gly::AA_Gly()
{
nSL=1.7178e-4;
vol=66.4;
nH=3;
nExch=1;
}
AA_Ala::AA_Ala()
{
nSL=1.6344e-4;
vol=91.5;
nH=5;
nExch=1;
}
AA_Val::AA_Val()
{
nSL=1.4676e-4;
vol=141.7;
nH=9;
nExch=1;
}
AA_Ile::AA_Ile()
{
nSL=1.3842e-4;
vol=168.8;
nH=11;
nExch=1;
}
AA_Leu::AA_Leu()
{
nSL=1.3842e-4;
vol=167.9;
nH=11;
nExch=1;
}
AA_Met::AA_Met()
{
nSL=1.7523e-4;
vol=170.8;
nH=9;
nExch=1;
}
AA_Tyr::AA_Tyr()
{
nSL=4.7073e-4;
vol=203.6;
nH=9;
nExch=2;
}
AA_Phe::AA_Phe()
{
nSL=4.1268e-4;
vol=203.4;
nH=9;
nExch=1;
}
AA_Trp::AA_Trp()
{
nSL=6.0123e-4;
vol=237.6;
nH=10;
nExch=2;
}
//----------------------------------------------------------------------------------------------------------------
// floating lipid bilayer
//----------------------------------------------------------------------------------------------------------------
BLM_quaternary::BLM_quaternary(){
headgroup1 = new PCm(); //mirrored PC head group
lipid1 = new Box2Err();
methyl1 = new Box2Err();
methyl2 = new Box2Err();
lipid2 = new Box2Err();
headgroup2 = new PC(); //PC head group
headgroup1_2= new Box2Err(); //second headgroups
headgroup2_2 = new Box2Err();
headgroup1_3 = new Box2Err();
headgroup2_3 = new Box2Err();
defect_hydrocarbon = new Box2Err();
defect_headgroup = new Box2Err();
volacyllipid=925;
nslacyllipid=-2.67e-4;
volmethyllipid=98.8;
nslmethyllipid=-9.15e-5;
hc_substitution_1=0;
hc_substitution_2=0;
headgroup1_2->vol=330; //was 330
headgroup2_2->vol=330; //was 330
headgroup1_3->vol=330; //was 330
headgroup2_3->vol=330; //was 330
headgroup1_2->nSL=6.0012e-4; // was 6.0122e-4
headgroup2_2->nSL=6.0012e-4; // was 6.0122e-4
headgroup1_3->nSL=6.0012e-4; // was 6.0122e-4
headgroup2_3->nSL=6.0012e-4; // was 6.0122e-4
headgroup1_2->l=9.5;
headgroup2_2->l=9.5;
headgroup1_3->l=9.5;
headgroup2_3->l=9.5;
volacyllipid_2=925;
nslacyllipid_2=-2.67e-4;
volmethyllipid_2=98.8;
nslmethyllipid_2=-9.15e-5;