-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathenergy.c
2629 lines (2263 loc) · 88.5 KB
/
energy.c
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
/*
** This is an implementation of model interactions between two amino acids
** as well within a single amino acid. This is a rather simple force-field.
**
** Copyright (c) 2004 - 2010 Alexei Podtelezhnikov
** Copyright (c) 2007 - 2013 Nikolas Burkoff, Csilla Varnai and David Wild
*/
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<float.h>
#include<math.h>
#include"canonicalAA.h"
#include"error.h"
#include"params.h"
#include"vector.h"
#include"rotation.h"
#include"aadict.h"
#include"peptide.h"
#include"vdw.h"
#include"energy.h"
#ifndef max
#define max(a,b) (((a) > (b)) ? (a) : (b))
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif
//#define NaN 0.0 / 0.0
#define Erg(I,J) erg[(I) * chain->NAA + (J)]
#define Ergt(I,J) ergt[(I - start) * chain->NAA + (J)]
/* contact map and associated stream */
#define Distb(I,J) biasmap->distb[(I) * biasmap->NAA + (J)]
/***********************************************************/
/**** CONSTANTS ****/
/***********************************************************/
/* CA-CA distance cutoff for Hbond interactions */
const double hbond_cutoff = 49.;
extern struct _ILE ILE;
extern struct _LEU LEU;
extern struct _PRO PRO;
extern struct _VAL VAL;
extern struct _PHE PHE;
extern struct _TRP TRP;
extern struct _TYR TYR;
extern struct _ASP ASP;
extern struct _GLU GLU;
extern struct _ARG ARG;
extern struct _HIS HIS;
extern struct _LYS LYS;
extern struct _SER SER;
extern struct _THR THR;
extern struct _CYS CYS;
extern struct _MET MET;
extern struct _ASN ASN;
extern struct _GLN GLN;
/***********************************************************/
/**** ENERGY MATRIX AND BIASMAP OPERATIONS ****/
/***********************************************************/
/* Initialize the energy matrix of a chain, that is,
fill the already allocated matrix with the amino acid
interaction energies. In the diagonal the intraresidual
energies go, and into (0,0), the global energy */
void energy_matrix_calculate(Chain *chain, Biasmap *biasmap, model_params *mod_params) {
int i, j;
/* (0,0) */
chain->Erg(0, 0) = global_energy(0,0,chain, NULL,biasmap, mod_params);
//fprintf(stderr,"first row %g %g", chain->Erg(0, 0), chain->Erg(1, 0));
/* (0,*) and (*,0) */
for (i = 1; i < chain->NAA; i++){
chain->Erg(0, i) = chain->Erg(i, 0) = 0.;
// fprintf(stderr,"%g ",chain->Erg(0,i));
}
//fprintf(stderr,"\n");
chain->Erg(1, 0) = cyclic_energy((chain->aa) + 1, (chain->aa) + chain->NAA - 1, 0);
/* diagonal */
//fprintf(stderr,"diag ");
//fprintf(stderr,"ENERGY1 START\n");
for (i = 1; i < chain->NAA; i++){
chain->Erg(i, i) = energy1((chain->aa) + i, mod_params);
// fprintf(stderr,"%g ",chain->Erg(i,i));
}
//fprintf(stderr,"\n");
//fprintf(stderr,"ENERGY1 END\n");
/* offdiagonal */
//fprintf(stderr,"offdiag ");
for (i = 1; i < chain->NAA; i++){
for (j = 1; j < i; j++){
chain->Erg(i, j) = chain->Erg(j, i) = energy2(biasmap,(chain->aa) + i, (chain->aa) + j, mod_params);
// fprintf(stderr,"%g ",chain->Erg(i,j));
}
//fprintf(stderr,"\n");
}
}
/* Calculate the total energy by adding up the energy matrix. */
double totenergy(Chain *chain)
{
int i, j;
double toten = chain->Erg(0, 0)+ chain->Erg(1, 0);
//fprintf(stderr, "tote... %g\n", chain->Erg(0,0));
for (i = 1; i < chain->NAA; i++)
for (j = 1; j <= i; j++) {
toten += chain->Erg(i, j);
// fprintf(stderr, "%g ", chain->Erg(i,j));
}
// fprintf(stderr,"\n");
return toten;
}
/* Calculate the local energy by adding up the diagonal of the energy matrix. */
double locenergy(Chain *chain)
{
int i;
double toten = 0.;
for (i = 1; i < chain->NAA; i++)
toten += chain->Erg(i, i);
return toten;
}
int bestRot(Chain *chain)
{
int i;
int Rotts=0;
int digits = 1;
//sprintf(Rots, "%i", (((chain->aa) + 1)->SCRot));
for (i = 1; i < chain->NAA; i++) {
if ((((chain->aa) + i)->SCRot) > 9 || (((chain->aa) + i)->SCRot) < 0) {
(((chain->aa) + i)->SCRot) = 0;
}
Rotts += (((chain->aa) + i)->SCRot) * digits;
digits = digits * 10;
}
return Rotts;
}
double extenergy(Chain *chain)
{
return chain->Erg(0, 0) + chain->Erg(1, 0);
}
double targetenergy(Chain *chain)
{
int i, j;
//double sqrtNAA = sqrt(chain->NAA);
//double sqrtNAA = chain->NAA;
double sqrtNAA = 4.;
double toten = sqrtNAA * chain->Erg(0, 0);
//fprintf(stderr, "tote... %g\n", chain->Erg(0,0));
for (i = 1; i < chain->NAA; i++)
for (j = 1; j <= i; j++) {
toten += chain->Erg(i, j);
// fprintf(stderr, "%g ", chain->Erg(i,j));
}
// fprintf(stderr,"\n");
return toten / sqrtNAA;
//return chain->Erg(0, 0);
}
double firstlastenergy(Chain *chain)
{
return chain->Erg(1, chain->NAA - 1);
//return chain->Erg(0, 0);
}
/* Print the energy matrix of a chain */
void energy_matrix_print(Chain *chain, Biasmap *biasmap, model_params *mod_params) {
int i, j;
for (i = 0; i < chain->NAA; i++){
for (j = 0; j <= i; j++){
fprintf(stderr,"%g ",chain->Erg(i, j));
}
fprintf(stderr,"\n");
}
}
/* Initialize matrix of Go-type contacts from a contact map file, unless
NULL is given as the contact map filename (return a zero contact map).
CAUTION! The diagonal contains the secondary structure information
of the amino acids. If the amino acid one letter codes are in the
diagonal, the contact map is meaningless. */
void biasmap_initialise(Chain *chain, Biasmap *biasmap, model_params *mod_params)
{
int i, j, k;
double val;
FILE *fin = NULL;
//fprintf(stderr,"Opening contact map file %s\n",mod_params->contact_map_file);
fin = fopen(mod_params->contact_map_file,"r");
int abort = 0;
if (fin == NULL) { // no file opened beforehand
if (mod_params->contact_map_file==NULL) {
fprintf(stderr, "ERROR: Invalid Go-type bias: %s.", mod_params->contact_map_file);
fprintf(stderr, " No contact map file specified.\n");
abort=1;
} else if ((fin = fopen(mod_params->contact_map_file, "r")) == NULL && strcmp(mod_params->contact_map_file,"NULL")!=0) { // nonexisting file and not NULL given
fprintf(stderr, "ERROR: Invalid Go-type bias: %s.", mod_params->contact_map_file);
fprintf(stderr, " Could not open file (missing?).\n");
abort = 1;
}
}
if (abort) {
stop("Contact map file has to be either an existing file or 'NULL' for no bias (see -p _B=... option).");
}
//if the biasmap has been already initialised (e.g. nested sampling), do not reread it
if((biasmap)->distb != NULL) {
if (fin) {
fclose(fin);
//fprintf(stderr,"Closing contact map file %s\n",mod_params->contact_map_file);
}
return; //when nested sampling - this is only to be done once
}
// allocate memory
(biasmap)->distb = (double *) realloc((biasmap)->distb, chain->NAA * chain->NAA * sizeof(double));
(biasmap)->NAA = chain->NAA;
if ((biasmap)->distb == NULL) {
stop("biasmap_initialise: Insufficient memory");
}
// if no biasmap, zero it
if (strcmp(mod_params->contact_map_file,"NULL")==0) {
fprintf(stderr,"WARNING! Contact map file 'NULL' given, so no bias interactions will be calculated.\n");
for (i = 1; i < chain->NAA; i++) {
for (j = 1; j < chain->NAA; j++) {
(biasmap)->distb[i * (biasmap)->NAA + j] = 0.0;
}
}
if (fin) {
fclose(fin);
//fprintf(stderr,"Closing contact map file %s\n",mod_params->contact_map_file);
}
return;
}
// otherwise read in contact map
for (i = 1; i < chain->NAA; i++)
for (j = 1; j < chain->NAA; j++) {
/* the fscanf consumes whitespaces, numbers,
decimal points, signs, but not most letters
so XOUZ is a good alphabet for symbolic maps */
k = fscanf(fin, "%lf", &val); /* read in actual number 0, 1 or -1 */
if (k == 0) { /* symbols used, not numbers */
switch (fgetc(fin) & 0x3) { /* character code % 4 */
case 0: /* X */
val = 1.0;
break;
case 1: /* U */
val = 1.0;
break;
case 2: /* Z */
val = -1.0;
break;
case 3: /* O */
val = 0.0;
break;
}
} else if (k == EOF)
goto out;
/* use 0s in the diagonal, if in the diagonal of the contact map the amino acid letters are printed,
otherwise they take a value according to the 1 letter code of the amino acid */
//if (i==j) val=0.0;
(biasmap)->distb[i * (biasmap)->NAA + j] = val;
}
out:
if (fin) {
fclose(fin);
//fprintf(stderr,"Closing contact map file %s\n",mod_params->contact_map_file);
}
fprintf(stderr, "Go-type bias: %dx%d\n", i - 1, chain->NAA - 1);
/* use 0s in the diagonal, if in the diagonal of the contact map the amino acid letters are printed,
otherwise they take a value according to the 1 letter code of the amino acid */
//fprintf(stderr,"WARNING: If the one-letter amino acid codes are in the diagonal, the bias potential's energy contribution will be meaningless! Check your contact map.\n");
/* special treatment for glycine */
if (mod_params->prt != 0.0)
for (i = 1; i < chain->NAA; i++)
if (chain->aa[i].id == 'G') {
//fprintf(stderr,"Gly %d (%d)",i,biasmap->NAA);
for (j = 1; j < chain->NAA; j++)
if (abs(i - j) > 1) {
//fprintf(stderr," %d",j);
(biasmap)->distb[i * (biasmap)->NAA + j] = (biasmap)->distb[j * (biasmap)->NAA + i] = 0.0;
}
//fprintf(stderr,"\n");
}
/* check if the biasing matrix is symmetric */
/* possible reasons for this are:
the contact map is lopsided
the contact contains spaces, which are skipped by fscanf
the one-letter amino acid codes are used in the diagonal, and there was a problem parsing N or I (on francesca) */
int lopsided = 0;
for (i = 1; i < chain->NAA; i++) {
for (j = 1; j < i; j++) {
if ((biasmap)->distb[i * (biasmap)->NAA + j] != (biasmap)->distb[j * (biasmap)->NAA + i]) {
fprintf(stderr, "Lopsided bias: %d %d valued %g %g\n", i, j, (biasmap)->distb[i * (biasmap)->NAA + j], (biasmap)->distb[j * (biasmap)->NAA + i]);
lopsided = 1;
}
}
}
if (lopsided) stop("Lopsided bias map!");
}
/* finalize matrix of Go-type contacts from contact map file
close input file */
void biasmap_finalise(Biasmap *biasmap){
if(biasmap){
if (biasmap->distb) free(biasmap->distb);
free(biasmap);
}
}
double lowerGridEnergy(double E) {
//return E;
//if (E > 2.71828) {
// //return log10f(E) + 9;
// return log(E) + 1.71828;
//}
if (E > 5) {
//return log10f(E) + 9;
return log(E) + 5;
}
return E;
}
void Cgridmap_initialise() {
FILE *gridmap = NULL;
gridmap = fopen("rigidReceptor.C.map", "r");
char line[256];
int i = 0, j = 0, k = 0;
//float spacing;
//int NX, NY, NZ;
//double spacing, centerX, centerY, centerZ;
//double mapvalues[];
targetBest = 999999.0;
while (fgets(line, sizeof(line), gridmap)) {
if (i < 3) {
//printf("%s", line);
i++;
continue;
}
char * pch;
pch = strtok(line, " ");
j = 0;
while (pch != NULL)
{
if (i == 3 && j == 1) {
spacing = atof(pch);
}
else if (i == 4 && j == 1) {
NX = atoi(pch) + 1;
}
else if (i == 4 && j == 2) {
NY = atoi(pch) + 1;
}
else if (i == 4 && j == 3) {
NZ = atoi(pch) + 1;
}
else if (i == 5 && j == 1) {
centerX = atof(pch);
}
else if (i == 5 && j == 2) {
centerY = atof(pch);
}
else if (i == 5 && j == 3) {
centerZ = atof(pch);
}
pch = strtok(NULL, " ");
j++;
}
i++;
if (i > 5) break;
}
printf("grid initialise succuss %i %i %i \n", NX, NY, NZ);
//double mapvalues[NX*NY*NZ];
double *mapvalues = malloc(NX*NY*NZ * sizeof(double));
//printf("succCACAussss %i %i %i \n", NX, NY, NZ);
i = 0;
while (fgets(line, sizeof(line), gridmap)) {
//mapvalues[i] = atof(line);
mapvalues[i] = lowerGridEnergy(atof(line));
i++;
}
fclose(gridmap);
//printf("succuss %s \n", mapvalues[0]);
//printf("succuss %i \n", sizeof(mapvalues));
Cmapvalue = mapvalues;
//free(mapvalues);
}
void Hgridmap_initialise() {
FILE *gridmap = NULL;
gridmap = fopen("rigidReceptor.HD.map", "r");
char line[256];
int i = 0;
double *Hmapvalues = malloc(NX*NY*NZ * sizeof(double));
while (fgets(line, sizeof(line), gridmap)) {
if (i < 6) {
i++;
continue;
}
Hmapvalues[i - 6] = lowerGridEnergy(atof(line));
i++;
}
fclose(gridmap);
Hmapvalue = Hmapvalues;
//free(Hmapvalues);
}
void Ngridmap_initialise() {
FILE *gridmap = NULL;
gridmap = fopen("rigidReceptor.N.map", "r");
char line[256];
int i = 0;
double *Nmapvalues = malloc(NX*NY*NZ * sizeof(double));
while (fgets(line, sizeof(line), gridmap)) {
if (i < 6) {
i++;
continue;
}
Nmapvalues[i - 6] = lowerGridEnergy(atof(line));
i++;
}
fclose(gridmap);
Nmapvalue = Nmapvalues;
//free(Nmapvalues);
}
void CAgridmap_initialise() {
FILE *gridmap = NULL;
gridmap = fopen("rigidReceptor.A.map", "r");
char line[256];
int i = 0;
double *CAmapvalues = malloc(NX*NY*NZ * sizeof(double));
while (fgets(line, sizeof(line), gridmap)) {
if (i < 6) {
i++;
continue;
}
CAmapvalues[i - 6] = atof(line);
i++;
}
fclose(gridmap);
CAmapvalue = CAmapvalues;
//free(CAmapvalues);
}
void NAgridmap_initialise() {
FILE *gridmap = NULL;
gridmap = fopen("rigidReceptor.NA.map", "r");
char line[256];
int i = 0;
double *NAmapvalues = malloc(NX*NY*NZ * sizeof(double));
while (fgets(line, sizeof(line), gridmap)) {
if (i < 6) {
i++;
continue;
}
NAmapvalues[i - 6] = lowerGridEnergy(atof(line));
i++;
}
fclose(gridmap);
NAmapvalue = NAmapvalues;
//free(NAmapvalues);
}
void Sgridmap_initialise() {
FILE *gridmap = NULL;
gridmap = fopen("rigidReceptor.S.map", "r");
char line[256];
int i = 0;
double *Smapvalues = malloc(NX*NY*NZ * sizeof(double));
while (fgets(line, sizeof(line), gridmap)) {
if (i < 6) {
i++;
continue;
}
Smapvalues[i - 6] = lowerGridEnergy(atof(line));
i++;
}
fclose(gridmap);
Smapvalue = Smapvalues;
//free(Smapvalues);
}
void Ogridmap_initialise() {
FILE *gridmap = NULL;
gridmap = fopen("rigidReceptor.OA.map", "r");
char line[256];
int i = 0;
double *Omapvalues = malloc(NX*NY*NZ * sizeof(double));
while (fgets(line, sizeof(line), gridmap)) {
if (i < 6) {
i++;
continue;
}
Omapvalues[i - 6] = lowerGridEnergy(atof(line));
i++;
}
fclose(gridmap);
Omapvalue = Omapvalues;
//free(Omapvalues);
}
void egridmap_initialise() {
FILE *gridmap = NULL;
gridmap = fopen("rigidReceptor.e.map", "r");
char line[256];
int i = 0;
double *emapvalues = malloc(NX*NY*NZ * sizeof(double));
while (fgets(line, sizeof(line), gridmap)) {
if (i < 6) {
i++;
continue;
}
emapvalues[i - 6] = lowerGridEnergy(atof(line));
i++;
}
fclose(gridmap);
emapvalue = emapvalues;
//free(emapvalues);
}
void dgridmap_initialise() {
FILE *gridmap = NULL;
gridmap = fopen("rigidReceptor.d.map", "r");
char line[256];
int i = 0;
double *dmapvalues = malloc(NX*NY*NZ * sizeof(double));
while (fgets(line, sizeof(line), gridmap)) {
if (i < 6) {
i++;
continue;
}
dmapvalues[i - 6] = lowerGridEnergy(atof(line));
i++;
}
fclose(gridmap);
dmapvalue = dmapvalues;
//free(dmapvalues);
}
/***********************************************************/
/**** ENERGY CONTRIBUTIONS ****/
/***********************************************************/
/* Low level routine to calculate the intensity of a linearly decaying function
from a maximum value to zero beyond a cutoff function:
strength_____.
.\
. \
0 . . . . . . .\._________
|<->|-decay width
|
|-cutoff
*/
inline double linear_decay(double distance, /* distance of the 2 atoms */
double contact_cutoff, /* upto which sum of their contact radii */
//double strength, /* the maximum value taken below the cutoff */
double decay_width /* the width of the linear decay */ ) {
if (distance > contact_cutoff + decay_width) return 0.0;
if (distance < contact_cutoff) return 1.0;
return (distance - contact_cutoff) / decay_width;
}
/* Energy contribution of proline phi dihedral angles
E = 30.0 (RT) * (phi - phi_0)^2
phi_0: equilibrium value, -PI/3 */
/* proline B restraints its phi angle with preceding A */
double proline(AA *a, AA *b)
{
double phi;
if (b->id != 'P')
return 0.0;
phi = dihedral_4(a->c, b->n, b->ca, b->c) + M_PI_3;
return 30. * phi * phi; /* RMSD by Ho et al. (2004) */
}
/* Bending energy contribution (internal stress)
E = 150 (RT) * ( angle(n,ca,c) - arccos(-1/3) )^2 */
double stress(AA *a, model_params *mod_params)
{
vector nca, cac; /* N-Ca and Ca-C bonds */
double beta, erg = 0.0;
subtract(nca, a->ca, a->n);
subtract(cac, a->c, a->ca);
/* ground-state angle is 180 - 111 = 69 (EH2001) */
beta = angle(nca, cac) - mod_params->stress_angle; //1.20427718387608740808;
erg += mod_params->stress_k * beta * beta; /* softer than Engh and Huber (2001) */
return erg;
}
/* Csilla: energy contribution of Go-type potential
E = kappa * C_ij * r_ij^2 for |i-j|>1
E = eta * cos(gamma_ij) for i-j=1
kappa: force constant (different for alpha-helix and beta-sheet)
C_ij:
r_ij: C_beta distances
eta: force constant (different for alpha-helix(positive) and beta-sheet(negative))
gamma_ij: C_beta,i-C_alpha,i-C_alpha,j-C_beta,j dihedral angle
a, b: i-th and j-th amino acids
*/
/* Go-type biasing potentials that stabilize alpha-helices and beta-sheets */
double bias(Biasmap *biasmap, AA *a, AA *b, model_params *mod_params)
{
int i = a->num, j = b->num;
double bb, dst2;
double r = 0;
double rs = 2.15; /* rs */
double bs = -0.25; /*kappa s */
if (biasmap->distb == NULL) {
stop("Contact matrix is not initialised. Perhaps missing contact map?");
}
/* works for multi-chain proteins */
switch ( max(abs(i - j), 1000 * abs(a->chainid - b->chainid)) ) {
case 0:
return 0.0;
case 1:
if (Distb(i, j) < 0.) {
bb = mod_params->bias_eta_beta; /* beta-strand twist */ /* eta_beta */
} else {
bb = mod_params->bias_eta_alpha; /* alpha-helix twist */ /* eta_alpha */
}
break;
case 3:
if(Distb(i, j) < 0){
/*Cys bond */
bb = bs;
r = rs;
}
else if (Distb(i, i) > 0. && Distb(j, j) > 0.){
bb = mod_params->bias_kappa_alpha_3; /* alpha-helix elasticity */ /* kappa_alpha */
r = mod_params->bias_r_alpha;
}
else{
if (rand() < Distb(i, j)*RAND_MAX) {
bb = mod_params->bias_kappa_beta; /* kappa_beta */
} else {
bb = 0;
}
r = mod_params->bias_r_beta;
}
break;
case 4:
if(Distb(i, j) < 0){
/*Cys bond */
bb = bs;
r = rs;
}
else if (Distb(i, i) > 0. && Distb(j, j) > 0.){
bb = mod_params->bias_kappa_alpha_4; /* alpha-helix elasticity */ /* kappa_alpha */
r = mod_params->bias_r_alpha;
}
else{
if (rand() < Distb(i, j)*RAND_MAX) {
bb = mod_params->bias_kappa_beta; /* kappa_beta */
} else {
bb = 0;
}
r = mod_params->bias_r_beta;
}
break;
default:
if(Distb(i, j) < 0){
/*Cys bond */
bb = bs;
r = rs;
}
else{
bb = mod_params->bias_kappa_beta; /* beta-sheet elasticity */ /* kappa_beta */
r = mod_params->bias_r_beta;
}
}
/* works for multi-chain proteins */
if ( max(abs(i - j), 1000 * abs(a->chainid - b->chainid)) > 1 ) {
vector x, y;
lincomb(x, 1. - mod_params->prt, a->ca, mod_params->prt, a->cb);
lincomb(y, 1. - mod_params->prt, b->ca, mod_params->prt, b->cb);
dst2 = distance(x, y);
dst2 = dst2 - 2*sqrt(dst2)*r + r*r;
} else { /* neighbouring amino acids */
vector x, y, z;
if (i > j) { /* reorder */
AA *temp;
temp = a;
a = b;
b = temp;
}
/* either baab or naac pseudo-dihedral is suitable */
subtract(x, a->ca, a->n);
subtract(y, b->ca, a->ca);
subtract(z, b->c, b->ca);
//set helix eta alpha phase shift
if (Distb(i, j) > 0.) dst2 = -phasindihedral(x,y,z, 0.13917, 0.99);
else dst2 = -cosdihedral(x, y, z);
//dst2 = -phasindihedral(x,y,z, 0.985,0.174); //strand
}
return Distb(i, j) * bb * dst2;
}
/* Energy contribution of hydrogen bonds
E = num_hb * hbs
num_hb: number of H-bonds between the two amino acids
hbs: H-bond strength (default: 2.2 (RT))
*/
double hbond(Biasmap *biasmap, AA *a, AA *b, model_params *mod_params)
{
//return -hbs * (hdonor(a, b) + hdonor(b, a));
double fact = 1.0;
// int i = a->num; int j = b->num;
// if( Distb( i, i ) * Distb( j, j ) == 0) fact /= 3.0;
//fprintf(stderr,"hbond %d %c",a->num,a->id);
//fprintf(stderr," N: %g",a->n[0]);
//fprintf(stderr," %g",a->n[1]);
//fprintf(stderr," %g",a->n[2]);
//fprintf(stderr," H: %g",a->h[0]);
//fprintf(stderr," %g",a->h[1]);
//fprintf(stderr," %g",a->h[2]);
//fprintf(stderr," , %d %c",b->num,b->id);
//fprintf(stderr," O: %g",b->o[0]);
//fprintf(stderr," %g",b->o[1]);
//fprintf(stderr," %g",b->o[2]);
//fprintf(stderr," C: %g",b->c[0]);
//fprintf(stderr," %g",b->c[1]);
//fprintf(stderr," %g\n",b->c[2]);
if (a->id == 'P') {
if (b->id == 'P') // no a->H, no b->H
return 0.0;
else // no a->H
return fact*-mod_params->hbs * hstrength(b->n,b->h,a->o,a->c, mod_params);
} else {
if (b->id == 'P') // no b->H
return fact*-mod_params->hbs * hstrength(a->n,a->h,b->o,b->c, mod_params);
else
return fact*-mod_params->hbs * (hstrength(a->n,a->h,b->o,b->c, mod_params) + hstrength(b->n,b->h,a->o,a->c, mod_params));
}
}
/* The scaling factor of hydrophobic interaction between a and b
R. Srinivasan, ProtSFG 22, 81--99 (1995)
R. Srinivasan et al., PNAS 96(25), 14258--14263 (1999)
2 if both amino acids are hydrophobic,
1 if one amino acid is hydrophobic, and the other one is amphipathic,
0 otherwise */
inline int hydrophobic_interaction_intensity(AA *a, AA *b, model_params *mod_params) {
/* works for multi-chain proteins */
if ( ( abs(a->num - b->num) < mod_params->hydrophobic_min_separation ) && ( a->chainid == b->chainid ) ) return 0;
/* hydrophobic -- hydrophobic */
if ( (a->etc & HYDROPHOBIC) && (b->etc & HYDROPHOBIC) ) return 2;
if ( (a->etc & HYDROPHOBIC) && (b->etc & AMPHIPATHIC) ) return 1;
if ( (a->etc & AMPHIPATHIC) && (b->etc & HYDROPHOBIC) ) return 1;
/* hydrophobic -- polar */
/* this accounts for the fewer polar -- polar interactions */
if (a->etc & HYDROPHOBIC) return -2;
if (b->etc & HYDROPHOBIC) return -2;
return 0;
}
/* Low level routine to calculate 2 atoms hydrophobic energy contribution
E = -k_h * f(d(a,b)) * intensity, if a and b are in contact
k_h is the hydrophobicity parameter (in RT)
d(a,b) is the distance between the respective atoms of a and b
f(d(a,b)) = d(a,b)^-1 */
/* inline double hydrophobic_low_recip(double distance,
double contact_cutoff,
model_params *mod_params) {
if (distance > mod_params->hydrophobic_max_cutoff) return 0.0;
if (distance < mod_params->hydrophobic_min_cutoff) distance = mod_params->hydrophobic_min_cutoff;
//fprintf(stderr," calc %g\n",(1.0/distance) - mod_params->hydrophobic_max_Eshift);
return (1.0/distance) - mod_params->hydrophobic_max_Eshift;
} */
/* Low level routine to calculate 2 atoms hydrophobic energy contribution using a spline potential
E = -k_h * f(d(a,b)) * intensity, if a and b are in contact
k_h is the hydrophobicity parameter (in RT)
d(a,b) is the distance between the respective atoms of a and b
f(d(a,b)) is a beta spline going from 1 to 0 between min_cutoff and max_cutoff */
/* inline double hydrophobic_low_spline(double distance,
double contact_cutoff,
model_params *mod_params) {
if (distance > mod_params->hydrophobic_r + mod_params->hydrophobic_half_delta) return 0.0;
if (distance < mod_params->hydrophobic_r - mod_params->hydrophobic_half_delta) distance = mod_params->hydrophobic_r - mod_params->hydrophobic_half_delta;
return (distance - mod_params->hydrophobic_r - mod_params->hydrophobic_half_delta)
* (distance - mod_params->hydrophobic_r - mod_params->hydrophobic_half_delta)
* (mod_params->hydrophobic_r - 2.0 * mod_params->hydrophobic_half_delta - distance)
/ (4.0 * mod_params->hydrophobic_half_delta * mod_params->hydrophobic_half_delta * mod_params->hydrophobic_half_delta) ;
} */
/* Low level routine to calculate 2 atoms hydrophobic energy contribution */
/* R. Srinivasan et al., PNAS 96(25), 14258--14263 (1999) */
inline double hydrophobic_low(double distance /* distance of the 2 atoms */,
double contact_cutoff /* sum of their contact radii */,
model_params *mod_params) {
if (distance > contact_cutoff + mod_params->hydrophobic_cutoff_range) return 0.0;
if (distance < contact_cutoff) return 1.0;
return (distance - contact_cutoff) / mod_params->hydrophobic_cutoff_range;
}
/* Energy contribution of hydrophobic interaction between a and b
E = -k_h * f(d(a,b)) * intensity, if a and b are in contact
k_h is the hydrophobicity parameter (in RT)
d(a,b) is the distance between the respective atoms of a and b
intensity depends on the hydrophobicity of the amino acids (see hydrophobic_intensity) */
/* Default: f(d(a,b)) = 1 */
double hydrophobic(Biasmap *biasmap, AA *a, AA *b, model_params *mod_params) {
/* return 0 if 0 */
if (mod_params->kauzmann_param == 0.0) return 0.0;
int intensity;
if ((intensity = hydrophobic_interaction_intensity(a,b,mod_params)) == 0) return 0.0;
/* calc hydrophobic contact radii */
double r_cb_a=0, r_g_a=0, r_g2_a=0;
double r_cb_b=0, r_g_b=0, r_g2_b=0;
if (a->etc & CB_) r_cb_a = hydrophobic_contact_radius(a->id, CB_, mod_params->sidechain_properties);
if (a->etc & G__) r_g_a = hydrophobic_contact_radius(a->id, G__, mod_params->sidechain_properties);
if (a->etc & G2_) r_g2_a = hydrophobic_contact_radius(a->id, G2_, mod_params->sidechain_properties);
if (b->etc & CB_) r_cb_b = hydrophobic_contact_radius(b->id, CB_, mod_params->sidechain_properties);
if (b->etc & G__) r_g_b = hydrophobic_contact_radius(b->id, G__, mod_params->sidechain_properties);
if (b->etc & G2_) r_g2_b = hydrophobic_contact_radius(b->id, G2_, mod_params->sidechain_properties);
double energy = 0;
if (mod_params->use_gamma_atoms != NO_GAMMA) {
/* all side chain contributions */
/* peptide should have been fixed by now, so no missing coordinates */
if ( (a->etc & CB_) && (b->etc & CB_) && r_cb_a > 0. && r_cb_b > 0. ) { /* CB -- CB */
energy += hydrophobic_low(sqrt(distance(a->cb, b->cb)), r_cb_a + r_cb_b, mod_params);
}
if ( (a->etc & CB_) && (b->etc & G__) && r_cb_a > 0. && r_g_b > 0. ) { /* CB -- G1 */
energy += hydrophobic_low(sqrt(distance(a->cb, b->g )), r_cb_a + r_g_b , mod_params);
}
if ( (a->etc & CB_) && (b->etc & G2_) && r_cb_a > 0. && r_g2_b > 0. ) { /* CB -- G2 */
energy += hydrophobic_low(sqrt(distance(a->cb, b->g2)), r_cb_a + r_g2_b, mod_params);
}
if ( (a->etc & G__) && (b->etc & CB_) && r_g_a > 0. && r_cb_b > 0. ) { /* G1 -- CB */
energy += hydrophobic_low(sqrt(distance(a->g , b->cb)), r_g_a + r_cb_b, mod_params);
}
if ( (a->etc & G__) && (b->etc & G__) && r_g_a > 0. && r_g_b > 0. ) { /* G1 -- G1 */
energy += hydrophobic_low(sqrt(distance(a->g , b->g )), r_g_a + r_g_b , mod_params);
}
if ( (a->etc & G__) && (b->etc & G2_) && r_g_a > 0. && r_g2_b > 0. ) { /* G1 -- G2 */
energy += hydrophobic_low(sqrt(distance(a->g , b->g2)), r_g_a + r_g2_b, mod_params);
}
if ( (a->etc & G2_) && (b->etc & CB_) && r_g2_a > 0. && r_cb_b > 0. ) { /* G2 -- CB */
energy += hydrophobic_low(sqrt(distance(a->g2, b->cb)), r_g2_a + r_cb_b, mod_params);
}
if ( (a->etc & G2_) && (b->etc & G__) && r_g2_a > 0. && r_g_b > 0. ) { /* G2 -- G1 */
energy += hydrophobic_low(sqrt(distance(a->g2, b->g )), r_g2_a + r_g_b , mod_params);
}
if ( (a->etc & G2_) && (b->etc & G2_) && r_g2_a > 0. && r_g2_b > 0. ) { /* G2 -- G2 */
energy += hydrophobic_low(sqrt(distance(a->g2, b->g2)), r_g2_a + r_g2_b, mod_params);
}
//fprintf(stderr,"%d %d %f ",a->num,b->num, energy);
return -mod_params->kauzmann_param * energy * (double) intensity;
} else {
/* OLD VERSION */
if (contact(a,b, mod_params)) {
return (-mod_params->kauzmann_param * ((double) intensity));
} else {
return 0.0;
}
}
}
double sidechain_hbond(Biasmap *biasmap, AA *a, AA *b, model_params *mod_params)
{
double intensity;
double erg = 0.0;
double hbond_distance;
double cos_goc_angle;
/* only from i, i+X */
/* works for multi-chain proteins */
if ( ( abs(a->num - b->num) < mod_params->sidechain_hbond_min_separation ) && ( a->chainid == b->chainid ) ) return 0.0;
/* side chain donor - backbone acceptor */
if (a->etc &G__ && b->etc &C__ && hbond_donor(a->id,G__, mod_params->sidechain_properties)) {
// check G--C distance
hbond_distance = sqrt(distance(a->g,b->c));
if (hbond_distance < sidechain_hbond_donor_radius(a->id,mod_params->sidechain_properties) + BACKBONE_ACCEPTOR_RADIUS + mod_params->sidechain_hbond_decay_width) {
//fprintf(stderr,"%c%d %c%d G-C distance %g ,",a->id,a->num,b->id,b->num,hbond_distance);
// check C--O--G angle
cos_goc_angle = cosangle(a->g,b->o,b->c);
//fprintf(stderr,"cos_goc_angle %g\n",cos_goc_angle);
if (cos_goc_angle < mod_params->sidechain_hbond_angle_cutoff) {
if ( (intensity = linear_decay(hbond_distance, sidechain_hbond_donor_radius(a->id,mod_params->sidechain_properties) + BACKBONE_ACCEPTOR_RADIUS, mod_params->sidechain_hbond_decay_width )) > 0.0 ) {
// fprintf(stderr,"found hbond %c %d G__ >> %c %d C__ %g\n",a->id,a->num,b->id,b->num,distance(a->g,b->c));
erg += -mod_params->sidechain_hbond_strength_s2b * intensity;
}
}
}
}
if (b->etc &G__ && a->etc &C__ && hbond_donor(b->id,G__, mod_params->sidechain_properties)) {
// check G--C distance
hbond_distance = sqrt(distance(b->g,a->c));
if (hbond_distance < sidechain_hbond_donor_radius(b->id,mod_params->sidechain_properties) + BACKBONE_ACCEPTOR_RADIUS + mod_params->sidechain_hbond_decay_width) {
//fprintf(stderr,"%c%d %c%d G-C distance %g ,",a->id,a->num,b->id,b->num,hbond_distance);
// check C--O--G angle
cos_goc_angle = cosangle(b->g,a->o,a->c);
//fprintf(stderr,"cos_goc_angle %g\n",cos_goc_angle);
if (cos_goc_angle < mod_params->sidechain_hbond_angle_cutoff) {
if ( (intensity = linear_decay(hbond_distance, sidechain_hbond_donor_radius(b->id,mod_params->sidechain_properties) + BACKBONE_ACCEPTOR_RADIUS, mod_params->sidechain_hbond_decay_width )) > 0.0 ) {
// fprintf(stderr,"found hbond %c %d G__ >> %c %d C__ %g\n",a->id,a->num,b->id,b->num,distance(a->g,b->c));
erg += -mod_params->sidechain_hbond_strength_s2b * intensity;
}
}
}
}
/* side chain acceptor - backbone donor */
if (a->etc &G__ && b->etc &N__ && b->etc &H__ && hbond_acceptor(a->id,G__, mod_params->sidechain_properties)) {
// check G--N distance
hbond_distance = sqrt(distance(a->g,b->n));
//fprintf(stderr,"check %c %d %c %d G-N distance %g (%g) %g \n",a->id,a->num,b->id,b->num,hbond_distance,sidechain_hbond_acceptor_radius(a->id,mod_params->sidechain_properties) + BACKBONE_DONOR_RADIUS + sidechain_hbond_decay_width,sqrt(distance(a->g,b->h)));
if (hbond_distance < sidechain_hbond_acceptor_radius(a->id,mod_params->sidechain_properties) + BACKBONE_DONOR_RADIUS + mod_params->sidechain_hbond_decay_width) {
//fprintf(stderr,"found %c %d %c %d G-N distance %g (%g) %g \n",a->id,a->num,b->id,b->num,hbond_distance,sidechain_hbond_acceptor_radius(a->id,mod_params->sidechain_properties) + BACKBONE_DONOR_RADIUS + sidechain_hbond_decay_width,sqrt(distance(a->g,b->h)));