-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPKINANGL.c
1550 lines (1436 loc) · 60.4 KB
/
PKINANGL.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
#include "PKIN.h"
/*3456789_123456789_123456789_123456789_123456789_123456789_123456789_12345678*/
/****idealizedCalphaAngles()**************************************************/
void idealizedCalphaAngles(char targetresidue[4],float* dist,float* angleCAB,float* dihedralNCAB, float* angleNAB, float* dihedralCNAB, float* angleideal)
{
if( targetresidue[0] == 'a'
&& targetresidue[1] == 'l'
&& targetresidue[2] == 'a')
{
*dist = (float)1.536;
*angleCAB = (float)110.1;
*dihedralNCAB = (float)122.9;
*angleNAB = (float)110.6;
*dihedralCNAB = (float)-122.6;
*angleideal = (float)111.2;
}
else if( targetresidue[0] == 'p'
&& targetresidue[1] == 'r'
&& targetresidue[2] == 'o')
{
*dist = (float)1.530;
*angleCAB = (float)112.2;
*dihedralNCAB = (float)115.1;
*angleNAB = (float)103.0;
*dihedralCNAB = (float)-120.7;
*angleideal = (float)111.8; /*pro and gly different*/
}
else if( ( targetresidue[0] == 'v'
&& targetresidue[1] == 'a'
&& targetresidue[2] == 'l')
||( targetresidue[0] == 't'
&& targetresidue[1] == 'h'
&& targetresidue[2] == 'r')
||( targetresidue[0] == 'i'
&& targetresidue[1] == 'l'
&& targetresidue[2] == 'e') )
{/*branched beta*/
*dist = (float)1.540;
*angleCAB = (float)109.1;
*dihedralNCAB = (float)123.4;
*angleNAB = (float)111.5;
*dihedralCNAB = (float)-122.0;
*angleideal = (float)111.2;
}
else if( targetresidue[0] == 'g'
&& targetresidue[1] == 'l'
&& targetresidue[2] == 'y')
{
*dist = (float)1.10; /*CB == HA1*/
*angleCAB = (float)109.3;
*dihedralNCAB = (float)121.6;
*angleNAB = (float)109.3;
*dihedralCNAB = (float)-121.6;
*angleideal = (float)112.5; /*gly and pro different*/
}
else
{/*all other aa*/
*dist = (float)1.530;
*angleCAB = (float)110.1;
*dihedralNCAB = (float)122.8;
*angleNAB = (float)110.5;
*dihedralCNAB = (float)-122.6;
*angleideal = (float)111.2;
}
}
/*___idealizedCalphaAngles()_________________________________________________*/
/****constructbeta()**********************************************************/
int constructbeta(float betaideal[3],char targetresidue[4]
,float altalpha[3], float altnite[3], char* altchoice)
{
/*compute an idealized Cbeta position from an average of construction*/
/*of Cbeta from both directions*/
int i=0, j=0, k=0, n=0, ireturn=0;
float dist=0,angleCAB=0,angleNAB=0,dihedralNCAB=0,dihedralCNAB=0;
float betaxyz[3],betaNCAB[3],betaCNAB[3],betadist=0;
/*Let 1st 1,2,3,4 array indecies correspond to N,CA,C,CB atoms*/
/*Let 1,2,3,... indecies correspond to primary,secondary,tertiary conf*/
#define MAXA 8
int L[5][MAXA] ={{0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}};
float X[5][MAXA] ={{0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}};
float Y[5][MAXA] ={{0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}};
float Z[5][MAXA] ={{0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}};
float O[5][MAXA] ={{0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}};
char calt[5][MAXA] ={{' ',' ',' ',' ',' ',' ',' ',' '}
, {' ',' ',' ',' ',' ',' ',' ',' '}, {' ',' ',' ',' ',' ',' ',' ',' '}
, {' ',' ',' ',' ',' ',' ',' ',' '}, {' ',' ',' ',' ',' ',' ',' ',' '}};
char charac[MAXA] ={' ',' ',' ',' ',' ',' ',' ',' '};
/*charac: last read alt char of nth alt conf atoms, should all be the same*/
char ouralt[MAXA] ={' ',' ',' ',' ',' ',' ',' ',' '};
/*ouralt: our renaming as a,b,c,d,e,... in our best guess at order*/
char ournam[MAXA] ={' ','a','b','c','d','e','f','g'};/*starting at index==1*/
int nam=0; /*running index of existing alts*/
int nw=4; /*accum max index of wierd alt conf designator*/
int m=0; /*running index for wierd alt conf*/
int nconf=0; /*counter for number of conformers*/
#define N 1
#define C 2
#define A 3
#define B 4 /*which makes Cbeta as the last (dominant) choice when enumerating*/
float fcxyz[4][3] ={{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}};
int jcbeta=1; /*so atom info defaults to first atom of res if gly*/
int Lglycine=0;
char colr[16],cntl[5];
float dev=0,raddev=0;
double anx=0,any=0,anz=0,acx=0,acy=0,acz=0;
double ctx=0,cty=0,ctz=0,ccx=0,ccy=0,ccz=0,ncx=0,ncy=0,ncz=0,vx=0,vy=0,vz=0;
double anmag=0,acmag=0,cosangle=0,disttau=0,tauoffset=0;
float angle=0,angleideal=(float)109.6, angletaudev=0, dihedralNABB=0;
int ipad=0,resnum=0;
char pdbstr[16],resstr[8],substr[8],resins;
#ifdef LABELSPSEUDOTAU
float raddel=0,del=0;
#endif
char ptm=' ', altchar=' ', nowaltchar=' ';
if(*altchoice!='a'&&*altchoice!='b'&&*altchoice!='c'&&*altchoice!='1'&&*altchoice!='2')
{/*filter for those alt conf characters this routine can handle*/
*altchoice = ' '; /*safety: default to primary conf*/
}
Lglycine = 1; /*presume special case*/
/*Allow for up to 3 alternate conformations of sidechain*/
/*where mainchain may or may not have alt. conf.*/
for(j=1; j<=maxatm; j++)
{/*j: find CB & the three mc atoms of orig residue to base CB calc*/
/*scheme is NOT logically complete, but maybe practically complete*/
/*idea is to rank alternate conformers as primary,secondary,tertiary*/
/*expectation is alt indicators in order as ' ','b','c' or 'a','b','c' */
/*allowance for ' ','a','b' as well as some simple out of order cases*/
/* 3 alt conf are recognized, hopefully confusions ignored gracefully*/
if ( (atom[j][1]=='n') && (atom[j][2]==' ') ) {/*N*/ n = N;}
else if( (atom[j][1]=='c') && (atom[j][2]=='a') ) {/*Calpha*/ n = A;}
else if( (atom[j][1]=='c') && (atom[j][2]==' ') ) {/*Carbonyl*/ n = C;}
else if( (atom[j][1]=='c') && (atom[j][2]=='b')
&& ((atom[j][3]==' ') || (atom[j][3]=='1')) ) /*use 1 of AIB*/
{/*Cbeta*/
n = B;
Lglycine = 0; /*some sort of Cbeta is specified*/
nconf++; /*counter for number of conformers*/
}
else {/*ignore*/ n = 0;}
if(n>0)
{/*atom is grist for Cbeta mill*/
if(atom[j][4]==' ') /*alt char in 5th place (index==4) of name*/
{/*alt==' '*/
/*putatively a primary conformation*/
if(L[n][1]==0)
{/*first occurance of putative primary conformer*/
charac[1] = atom[j][4];
calt[n][1]=atom[j][4]; L[n][1]=j;
X[n][1]=x[j]; Y[n][1]=y[j]; Z[n][1]=z[j]; O[n][1]=o[j];
}
else if(calt[n][1]=='a'||calt[n][1]=='1') /*earlier a alt*/
{/*recategorize primary vs secondary conformer, blank then a*/
/*possibly scheme uses ' ', 'a' for primary, secondary confs*/
if(L[n][2]==0)
{/*not previously encountered a secondary conf, so...*/
k=L[n][1];
charac[2] = charac[1];
calt[n][2]=calt[n][1]; L[n][2]=k; /*reassign as secondary*/
X[n][2]=x[k]; Y[n][2]=y[k]; Z[n][2]=z[k]; O[n][2]=o[k];
charac[1] = atom[j][4];
calt[n][1]=atom[j][4]; L[n][1]=j; /*assign as primary*/
X[n][1]=x[j]; Y[n][1]=y[j]; Z[n][1]=z[j]; O[n][1]=o[j];
}
else if(L[n][3]==0)
{/*not previously encountered a tertiary conf, so...*/
k=L[n][2];
charac[3] = charac[2];
calt[n][3]=calt[n][2]; L[n][3]=k; /*reassign as tertiary*/
X[n][3]=x[k]; Y[n][3]=y[k]; Z[n][3]=z[k]; O[n][3]=o[k];
k=L[n][1];
charac[2] = charac[1];
calt[n][2]=calt[n][1]; L[n][2]=k; /*reassign as secondary*/
X[n][2]=x[k]; Y[n][2]=y[k]; Z[n][2]=z[k]; O[n][2]=o[k];
charac[1] = atom[j][4];
calt[n][1]=atom[j][4]; L[n][1]=j; /*assign as primary*/
X[n][1]=x[j]; Y[n][1]=y[j]; Z[n][1]=z[j]; O[n][1]=o[j];
}
/*anything more confusing is ignored*/
}
else if(calt[n][1]==' ')
{/*second occurance of ' ' treated as secondary conf*/
if(L[n][2]==0)
{/*not previously encountered a secondary conf, so...*/
charac[2] = atom[j][4];
calt[n][2]=atom[j][4]; L[n][2]=j;
X[n][2]=x[j]; Y[n][2]=y[j]; Z[n][2]=z[j]; O[n][2]=o[j];
}
}
/*anything more confusing is ignored*/
}/*alt==' '*/
else if( (atom[j][4]=='a')||(atom[j][4]=='1') )
{/*alt=='a'||'1'*/
/*putatively a primary conformation*/
if(L[n][1]==0)
{/*first occurance of putative primary conformer*/
charac[1] = atom[j][4];
calt[n][1]=atom[j][4]; L[n][1]=j;
X[n][1]=x[j]; Y[n][1]=y[j]; Z[n][1]=z[j]; O[n][1]=o[j];
}
else if(calt[n][1]==' ') /*can't handle mixed a,b with 1,2*/
{/*possibly scheme uses ' ', 'a' for primary, secondary confs*/
if(L[n][2]==0)
{/*not previously encountered a secondary conf, so...*/
charac[2] = atom[j][4];
calt[n][2]=atom[j][4]; L[n][2]=j;
X[n][2]=x[j]; Y[n][2]=y[j]; Z[n][2]=z[j]; O[n][2]=o[j];
}
}
/*anything more confusing is ignored*/
}/*alt=='a'||'1'*/
else if( (atom[j][4]=='b')||(atom[j][4]=='2') )
{/*alt=='b'||'2'*/
/*putatively a secondary conformation, can go as 2nd or 3rd*/
/*but some pathologies have first alt==b, which we rename as a*/
if(L[n][1]==0)
{/*first occurance of any conformer*/
charac[1] = atom[j][4];
calt[n][1]=atom[j][4]; L[n][1]=j;
X[n][1]=x[j]; Y[n][1]=y[j]; Z[n][1]=z[j]; O[n][1]=o[j];
}
else if(L[n][2]==0)
{/*first occurance of putative secondary conformer, normal case*/
charac[2] = atom[j][4];
calt[n][2]=atom[j][4]; L[n][2]=j;
X[n][2]=x[j]; Y[n][2]=y[j]; Z[n][2]=z[j]; O[n][2]=o[j];
}
else if(calt[n][2]=='a'||calt[n][2]=='1') /*presume a,b OR 1,2*/
{/*recategorize secondary vs tertiary conformer here*/
/*possibly scheme uses ' ', 'a', 'b' for prime, sec., tert. confs*/
if(L[n][3]==0)
{/*not previously encountered a tertiary conf, so...*/
charac[3] = atom[j][4];
calt[n][3]=atom[j][4]; L[n][3]=j;
X[n][3]=x[j]; Y[n][3]=y[j]; Z[n][3]=z[j]; O[n][3]=o[j];
}
}
/*anything more confusing is ignored*/
}/*alt=='b'||'2'*/
else if( (atom[j][4]=='c')||(atom[j][4]=='3') )
{/*alt=='c'||'3'*/
/*putatively a tertiary conformation*/
/*but some pathologies do not adhere to a,b,c*/
if(L[n][1]==0)
{/*first occurance of any conformer*/
charac[1] = atom[j][4];
calt[n][1]=atom[j][4]; L[n][1]=j;
X[n][1]=x[j]; Y[n][1]=y[j]; Z[n][1]=z[j]; O[n][1]=o[j];
}
else if(L[n][2]==0)
{/*first occurance of putative secondary conformer, normal case*/
charac[2] = atom[j][4];
calt[n][2]=atom[j][4]; L[n][2]=j;
X[n][2]=x[j]; Y[n][2]=y[j]; Z[n][2]=z[j]; O[n][2]=o[j];
}
else if(L[n][3]==0)
{/*first occurance of putative tertiary conformer, usual case*/
charac[3] = atom[j][4];
calt[n][3]=atom[j][4]; L[n][3]=j;
X[n][3]=x[j]; Y[n][3]=y[j]; Z[n][3]=z[j]; O[n][3]=o[j];
}
else if(L[n][nw]==0) /*nw initialized as 4, next index past 3 a,b,c */
{/*first occurance of this designated putative conformer*/
charac[nw] = atom[j][4];
calt[n][nw]=atom[j][4]; L[n][nw]=j;
X[n][nw]=x[j]; Y[n][nw]=y[j]; Z[n][nw]=z[j]; O[n][nw]=o[j];
}
/*this works if c is the 4th alt, otherwise may mess up */
/*anything more confusing is ignored*/
}/*alt=='c'||'3'*/
else /*atom[j][4] not blank nor a,b,c,1,2,3 but some other character*/
{/*alt==wierd*/
/*putatively a wierdly designated alternate conformation*/
if(L[n][nw]==0) /*nw initialized as 4, next index past 3 a,b,c */
{/*first occurance of this designated putative conformer*/
charac[nw] = atom[j][4];
calt[n][nw]=atom[j][4]; L[n][nw]=j;
X[n][nw]=x[j]; Y[n][nw]=y[j]; Z[n][nw]=z[j]; O[n][nw]=o[j];
}
else /*see if atom[j][4] matches previous atom's alt char*/
{
for(m=4; m<=nw; m++)
{
if(atom[j][4]==charac[m])
{
break; /*carrying m on to next section of code*/
}
}
if(m>nw)
{/*new wierd alt char*/
if(nw < MAXA-1)
{
nw++;
m=nw;
charac[m] = atom[j][4];
}
}
if(m<MAXA)
{/*there is room to load this conformation*/
/*presume new type with same alt char*/
/*overwrite any previous atom of this type and alt char*/
calt[n][m]=atom[j][4]; L[n][m]=j;
X[n][m]=x[j]; Y[n][m]=y[j]; Z[n][m]=z[j]; O[n][m]=o[j];
}
}
/*anything more confusing is ignored*/
}/*alt==wierd*/
}/*atom is grist for Cbeta mill*/
}/*j: find CB & the three mc atoms of orig residue to base CB calc*/
if(L[N][1] != 0 && L[A][1] != 0 && L[C][1] != 0)
{/*got N,CA,C: compute idealized Cbeta position*/
/*make sure that all sidechain confs have mainchain atoms*/
if(L[N][1] != 0)
{
for(m=2; m<=nw; m++)
{
if(L[N][m]==0) { X[N][m]=X[N][1]; Y[N][m]=Y[N][1]; Z[N][m]=Z[N][1]; }
}
}
if(L[A][1] != 0)
{
for(m=2; m<=nw; m++)
{
if(L[A][m]==0) { X[A][m]=X[A][1]; Y[A][m]=Y[A][1]; Z[A][m]=Z[A][1]; }
}
}
if(L[C][1] != 0)
{
for(m=2; m<=nw; m++)
{
if(L[C][m]==0) { X[C][m]=X[C][1]; Y[C][m]=Y[C][1]; Z[C][m]=Z[C][1]; }
}
}
if(L[B][1] != 0)
{
for(m=2; m<=nw; m++)
{
if(L[B][m]==0) { X[B][m]=X[B][1]; Y[B][m]=Y[B][1]; Z[B][m]=Z[B][1]; }
}
}
/*
Idealizing the Cb:
Ala, from C: 1.536 Å, 110.1, 122.9 (i.e., N,C,Ca,Cb)
Ala, from N: 1.536 Å, 110.6, -122.6 (i.e., C,N,Ca,Cb)
Pro, from C: 1.530 Å, 112.2, 115.1
Pro, from N: 1.530 Å, 103.0, -120.7
Val, from C: 1.540 Å, 109.1, 123.4 (Thr, Ile)
Val, from N: 1.540 Å, 111.5, -122.0
Leu, from C: 1.530 Å, 110.1, 122.8 (Met, Phe, Ser)
Leu, from N: 1.530 Å, 110.5, -122.6
*/
/*only matters what residue it is to be mutated to*/
/*i.e. always newresidue */
idealizedCalphaAngles(targetresidue,&dist,&angleCAB,&dihedralNCAB,&angleNAB,&dihedralCNAB,&angleideal);
if(Lcbetadev)
{
nam = 1; /*first indexed alt*/
for(i=1; i<MAXA; i++) /*050404*/
{/*sanity check and renaming of alts for our cbdevdump output*/
if(L[B][i]!=0)
{/*an ith alt of cbeta exists*/
ouralt[i] = ournam[nam];
nam++;
}
}
}
/*for(i=1; i<=3; i++)*/
for(i=1; i<MAXA; i++) /*050404*/
{/*check for primary,secondary,tertiary, ..., alt conformers*/
/*alternate ideal conformers only meaningful if mainchain has alternate conf*/
/*so check that at least one of mc has this alt*/
/*EXCEPT: for cbetadev calc deviation even if no alt mainchain atoms 031124*/
/*if((Lcbetadev && L[B][i]!=0) || (L[N][i]!=0 || L[A][i]!=0 || L[C][i]!=0 ) )*/
if( (Lcbetadev && L[B][i]!=0) /*and there is an alt CB to compare to*/
|| (!Lcbetadev && L[N][i]!=0) /*at least one mc atom has an alt conf*/
|| (!Lcbetadev && L[A][i]!=0)
|| (!Lcbetadev && L[C][i]!=0) )
{/*construct Cbeta conformer*/
fcxyz[0][0] = X[N][i];
fcxyz[0][1] = Y[N][i];
fcxyz[0][2] = Z[N][i];
fcxyz[1][0] = X[C][i];
fcxyz[1][1] = Y[C][i];
fcxyz[1][2] = Z[C][i];
fcxyz[2][0] = X[A][i];
fcxyz[2][1] = Y[A][i];
fcxyz[2][2] = Z[A][i];
constructfourth(fcxyz,dist,angleCAB,dihedralNCAB);
betaNCAB[0] = fcxyz[3][0];
betaNCAB[1] = fcxyz[3][1];
betaNCAB[2] = fcxyz[3][2];
fcxyz[0][0] = X[C][i];
fcxyz[0][1] = Y[C][i];
fcxyz[0][2] = Z[C][i];
fcxyz[1][0] = X[N][i];
fcxyz[1][1] = Y[N][i];
fcxyz[1][2] = Z[N][i];
fcxyz[2][0] = X[A][i];
fcxyz[2][1] = Y[A][i];
fcxyz[2][2] = Z[A][i];
constructfourth(fcxyz,dist,angleNAB,dihedralCNAB);
betaCNAB[0] = fcxyz[3][0];
betaCNAB[1] = fcxyz[3][1];
betaCNAB[2] = fcxyz[3][2];
betaxyz[0] = (betaNCAB[0]+betaCNAB[0])/2;
betaxyz[1] = (betaNCAB[1]+betaCNAB[1])/2;
betaxyz[2] = (betaNCAB[2]+betaCNAB[2])/2;
betadist=distan(X[A][i],Y[A][i],Z[A][i],betaxyz[0],betaxyz[1],betaxyz[2]);
if(betadist != dist)
{/*recompute distance of averaged beta position*/
fcxyz[3][0] = betaxyz[0] - X[A][i];
fcxyz[3][1] = betaxyz[1] - Y[A][i];
fcxyz[3][2] = betaxyz[2] - Z[A][i];
betaxyz[0] = X[A][i] + fcxyz[3][0]*dist/betadist;
betaxyz[1] = Y[A][i] + fcxyz[3][1]*dist/betadist;
betaxyz[2] = Z[A][i] + fcxyz[3][2]*dist/betadist;
}
/*for mutation, match altconf character with primary,secondary,tertiary */
nowaltchar = ' '; /*default for primary conformer*/
for(n=N; n<=B; n++)
{/*vote on what is the alt conf character for this enumerated conformer*/
if(calt[n][i]!=' ') {nowaltchar = calt[n][i];}
/*so a blank will not override an earlier different character*/
/*beta, if present, dominant over others*/
}
if( (i==1 && *altchoice==' ')||(nowaltchar == *altchoice) )
{/*nth alt conformer used for idealized mutation*/
*altchoice = nowaltchar;
betaideal[0] = betaxyz[0];
betaideal[1] = betaxyz[1];
betaideal[2] = betaxyz[2];
altalpha[0] = X[A][i]; /*supposedly the appropriate Calpha for this conf*/
altalpha[1] = Y[A][i];
altalpha[2] = Z[A][i];
altnite[0] = X[N][i]; /*supposedly the appropriate Nitrogen for this conf*/
altnite[1] = Y[N][i];
altnite[2] = Z[N][i];
}
ireturn = 1;
if(Lcbetadev > 0 && !Lglycine)
{/*output of deviation of C-beta from ideal*/
#ifdef LABELSPSEUDOTAU
/*compute spread from the N and C directions*/
/*a measure of non-ideal tau*/
del = distan( betaNCAB[0],betaNCAB[1],betaNCAB[2]
,betaCNAB[0],betaCNAB[1],betaCNAB[2]);
if(del > .004) {raddel = del/2;}
else {raddel = (float)0.002;}/*minimal: 0 gets default radius*/
#endif /*LABELSPSEUDOTAU*/
/*compute the deviation from ideal beta position*/
if(Lglycine)
{/*artifact: don't output CB on gly, kept in for bookkeeping*/
raddev = (float)0.002;/*minimal: 0 gets default radius*/
dev = 0;
/*ptm = 't'; 041031 no cbetadev pointmasters*/
}
else
{
dev =
distan( X[B][i],Y[B][i],Z[B][i],betaxyz[0],betaxyz[1],betaxyz[2]);
if(dev > .002) {raddev = dev;}
else {raddev = (float)0.002;}/*minimal: 0 gets default radius*/
/*041031 no cbetadev pointmasters*/
/*if (dev < .05) {ptm = 't'; }*/ /*changed from a 030605*/
/*else if(dev < .1) {ptm = 'u'; }*/ /*cbetadev*/
/*else if(dev < .2) {ptm = 'v'; }*/
/*else if(dev < .3) {ptm = 'w'; }*/
/*else if(dev < .4) {ptm = 'x'; }*/
/*else if(dev < .5) {ptm = 'y'; }*/
/*else {ptm = 'z'; }*/
}
/*dihedral N---CA---CBideal---CBactual 011105 */
dihedralNABB = (float)dihedral4pt(
(double)X[N][i],(double)Y[N][i],(double)Z[N][i]
,(double)X[A][i],(double)Y[A][i],(double)Z[A][i]
,(double)betaxyz[0],(double)betaxyz[1],(double)betaxyz[2]
,(double)X[B][i],(double)Y[B][i],(double)Z[B][i] );
if(!Lcbdevdump && dev >= .25) /*041031 only bad cbetadev, no ptmasters*/
{/*NOT a cbeta deviation dump, write scratch for kinemage*/
Listcbdev=TRUE;
cbdevoutl=1;
{
if(i==1)
{
sprintf(cntl,"cbda"); /*Cbeta deviation BALLS, a conformation */
typenow=typecbda;
sprintf(colr,"gold");
jcbeta = L[B][i];
}
else if(i==2)
{
sprintf(cntl,"cbdb"); /*Cbeta deviation BALLS, b conformation */
typenow=typecbdb;
sprintf(colr,"pink");
}
else /*if(i==3) but 040504 any beyond 3 get lumped into c*/
{
sprintf(cntl,"cbdc"); /*Cbeta deviation BALLS, c conformation */
typenow=typecbdc;
sprintf(colr,"red");
}
/*041031 no cbetadev pointmasters*/
/*sprintf(temps,"%s{ cb %s %s %d%s %.3f %.2f}"*/
/* " '%c' r=%.3f %s %.3f, %.3f, %.3f"EOLO*/
/* ,cntl,res[jcbeta],sub[jcbeta],num[jcbeta],rins[jcbeta]*/
/* ,dev,dihedralNABB*/
/* ,ptm,raddev,colr,betaxyz[0],betaxyz[1],betaxyz[2]);*/
sprintf(temps,"%s{ cb %s %s%4d%s %.3f %.2f}"
" r=%.3f %s %.3f, %.3f, %.3f"EOLO
,cntl,res[jcbeta],sub[jcbeta],num[jcbeta],rins[jcbeta]
,dev,dihedralNABB
,raddev,colr,betaxyz[0],betaxyz[1],betaxyz[2]);
++countxyz;++pointcnt[typenow];countpoints(cntl,0);
putonetextblockline(&mainscratch,temps);
}
#ifdef LABELSPSEUDOTAU
sprintf(cntl,"cbdm"); /*Cbeta construction mismatch BALLS */
typenow=typecbdm;
sprintf(colr,"sky");
sprintf(temps,"%s{ cb %s %s%4d%s %.3f} r=%.3f %s %.3f, %.3f, %.3f"EOLO
,cntl,res[jcbeta],sub[jcbeta],num[jcbeta],rins[jcbeta]
,del,raddel,colr,betaxyz[0],betaxyz[1],betaxyz[2]);
++countxyz;++pointcnt[typenow];countpoints(cntl,0);
putonetextblockline(&mainscratch,temps);
sprintf(cntl,"cbdv"); /*Cbeta construction mismatch VECTORS */
typenow=typecbdv;
sprintf(colr,"hotpink");
sprintf(temps,"%s{ cb %s %s%4d%s %.3f}P %s %.3f, %.3f, %.3f"
"{ cb %s %s%4d%s %.3f}L %s %.3f, %.3f, %.3f"EOLO
,cntl,res[jcbeta],sub[jcbeta],num[jcbeta],rins[jcbeta]
,del,colr,betaNCAB[0],betaNCAB[1],betaNCAB[2]
,res[jcbeta],sub[jcbeta],num[jcbeta],rins[jcbeta]
,del,colr,betaCNAB[0],betaCNAB[1],betaCNAB[2]);
++countxyz;++pointcnt[typenow];countpoints(cntl,0);
++countxyz;++pointcnt[typenow];countpoints(cntl,0);
putonetextblockline(&mainscratch,temps);
sprintf(cntl,"cbdl"); /*Cbeta deviation LABELS */
typenow=typecbdl;
sprintf(colr,"gold");
sprintf(temps,"%s{ cb %s %s%4d%s %.3f %.3f} %s"
"< %.3f, %.3f, %.3f; %.3f, %.3f, %.3f >"
" %.3f, %.3f, %.3f"EOLO
,cntl,res[jcbeta],sub[jcbeta],num[jcbeta],rins[jcbeta]
,dev,del,colr
,betaNCAB[0],betaNCAB[1],betaNCAB[2]
,betaCNAB[0],betaCNAB[1],betaCNAB[2]
,betaxyz[0],betaxyz[1],betaxyz[2]);
++countxyz;++pointcnt[typenow];countpoints(cntl,0);
putonetextblockline(&mainscratch,temps);
#endif /*LABELSPSEUDOTAU*/
if (i==1) sprintf(cntl,"cbde"); /*Calpha Cbeta VECTORS */
else if(i==2) sprintf(cntl,"cbdf"); /*Calpha Cbeta VECTORS */
/*else if(i==3) sprintf(cntl,"cbdg");*/ /*040504 3+ as c */
else sprintf(cntl,"cbdg"); /*Calpha Cbeta VECTORS */
typenow=typecbde;
sprintf(colr,"peach");
/*NB: white space between z {...} : {...}P x,y,z {...}L */
sprintf(temps,"%s{ ca %s %s%4d%s}P %s %.3f, %.3f, %.3f"
" { cb %s %s%4d%s}L %s %.3f, %.3f, %.3f"EOLO
,cntl,res[jcbeta],sub[jcbeta],num[jcbeta],rins[jcbeta]
,colr,X[A][i],Y[A][i],Z[A][i]
,res[jcbeta],sub[jcbeta],num[jcbeta],rins[jcbeta]
,colr,betaxyz[0],betaxyz[1],betaxyz[2]);
++countxyz;++pointcnt[typenow];countpoints(cntl,0);
++countxyz;++pointcnt[typenow];countpoints(cntl,0);
putonetextblockline(&mainscratch,temps);
}/*NOT a dump, write scratch for kinemage*/
else if(Lcbdevdumpmax) /*040318*/
{/*just accummulate the maximum value of cbeta deviation */
if(dev > cbetadevmax) {cbetadevmax = dev;}
}
else if(Lcbdevdump) /*must check after Lcbdevdumpmax*/
{/*write scratch for colon delineated dump of deviation*/
Ldump = 1; /*dump equivalent of kinemage List...*/
/*This dump never goes through Listext... but other dumps use the*/
/*regular machinery in PKINCSBS to calc output info*/
/*also inhibit tau deviation claculation and output*/
Ltaudev = 0;
sprintf(cntl,"dump"); /*colon-delineated-list dump*/
ipad = 0;
for(j=0;j<7;j++)
{/*taking just the first 7 char of the stripped input file name*/
pdbstr[j] = PDBfileStr[j];
if(pdbstr[j] == '\0') {ipad = 1;}
if(ipad) {pdbstr[j] = ' ';}
}
pdbstr[7] = '\0';
ipad = 0;
for(j=0;j<3;j++)
{
resstr[j] = res[jcbeta][j];
if(resstr[j] == '\0') {ipad = 1;}
if(ipad) {resstr[j] = ' ';}
}
resstr[3] = '\0';
/* chain ID string */
/*substr[0] = sub[jcbeta][0];
substr[1] = sub[jcbeta][1];
substr[2] = '\0';*/
substr[0] = sub[jcbeta][0];
substr[1] = sub[jcbeta][1];
substr[2] = sub[jcbeta][2];
substr[3] = sub[jcbeta][3];
substr[4] = sub[jcbeta][4];
/*substr[1] = '\0'; go to 2char, 080325*/
resnum = num[jcbeta];
resins = (char)rins[jcbeta][0]; /*rins is a C string*/
/*if (i==1 && L[B][2]==0 && L[B][3]==0 ) {altchar=' ';}*/ /*one conf*/
if(nconf <=1) {altchar=' ';} /*one conf*/
/*else if(i==1) altchar='a';*/ /*at least another alt conf*/
/*else if(i==2) altchar='b';*/ /*Standard ' ' or a,b,c designation*/
/*else if(i==3) altchar='c';*/
else {altchar = ouralt[i];} /*at least another alt conf*/
/*040504 MAXA==8 so 7 alts, original put on end of line*/
/*note: charac[i] is actual alt char from pdb file, now put on end*/
/*cntl stripped in output, insertion code on end of residue number*/
sprintf(temps,"%s%s :%c:%s:%s:%4d%c:%7.3f:%7.2f:%7.2f:%c:"EOLO
,cntl,PDBfileStr,altchar,resstr,substr,resnum,resins,dev,dihedralNABB,O[B][i],charac[i]);
/*,cntl,pdbstr,altchar,resstr,substr,resnum,resins,dev,dihedralNABB,O[B][i]);*/
putonetextblockline(&mainscratch,temps);
}/*write scratch for colon delineated dump of deviation*/
}/*output of deviation of C-beta from ideal*/
if(Ltaudev)
{/*tau angle deviation*/
Listtaudev = 1;
anx = (double)X[N][i] - (double)X[A][i]; /*vector CA-->N*/
any = (double)Y[N][i] - (double)Y[A][i];
anz = (double)Z[N][i] - (double)Z[A][i];
acx = (double)X[C][i] - (double)X[A][i]; /*vector CA-->C*/
acy = (double)Y[C][i] - (double)Y[A][i];
acz = (double)Z[C][i] - (double)Z[A][i];
/*normalize vectors*/
anmag = sqrt( anx*anx + any*any + anz*anz );
anx = anx/anmag;
any = any/anmag;
anz = anz/anmag;
acmag = sqrt( acx*acx + acy*acy + acz*acz );
acx = acx/acmag;
acy = acy/acmag;
acz = acz/acmag;
/*get angle from normalized vectors*/
cosangle = dotproduct(anx,any,anz,acx,acy,acz);
angle = (float)(acos(cosangle)*360/(2*3.14159));
/*an--> ac--> both outof Calpha, __/ */
/*dotproduct is projection of one onto the other so */
/*cosangle translates directly to tau angle*/
angletaudev = angle - angleideal;
if(angletaudev >= 0)
{
sprintf(colr,"sky");
}
else
{
sprintf(colr,"pink");
}
sprintf(cntl,"tau ");
typenow=typetau;
/* ctxyz: . N */
/*ctr tau position: C__/ */
ctx = (X[A][i] +anx +X[A][i] +acx)/2;
cty = (Y[A][i] +any +Y[A][i] +acy)/2;
ctz = (Z[A][i] +anz +Z[A][i] +acz)/2;
/*Calpha---ctr tau position*/
disttau = sqrt((X[A][i]-ctx)*(X[A][i]-ctx)+(Y[A][i]-cty)*(Y[A][i]-cty)+(Z[A][i]-ctz)*(Z[A][i]-ctz));
/*calculate offset based on tau angle deviation*/
/*Linear*/
if(angletaudev > 0) {angle = angletaudev/2;}
else if(angletaudev < 0) {angle = -angletaudev/2;}
else {angle = 0;}
tauoffset = disttau*tan(angle*2*3.14159/360);
/*vector from tau ctr position to unit vector point along CA---N */
vx = X[A][i]+anx - ctx;
vy = Y[A][i]+any - cty;
vz = Z[A][i]+anz - ctz;
/*magnitude (distance) from tau ctr point to that unit vector*/
disttau = sqrt(vx*vx + vy*vy + vz*vz);
/*components of the offset point, are vx/dist, vy/dist, vz/dist*/
/*offset point toward N: */
ncx = ctx + tauoffset*vx/disttau;
ncy = cty + tauoffset*vy/disttau;
ncz = ctz + tauoffset*vz/disttau;
/*offset point toward C: */
ccx = ctx - tauoffset*vx/disttau;
ccy = cty - tauoffset*vy/disttau;
ccz = ctz - tauoffset*vz/disttau;
if(tauoffset < .002)
{tauoffset = (float)0.002;}/*minimal: 0 gets default radius*/
sprintf(cntl,"taub");
typenow=typetaub;
sprintf(temps
,"%s{ tau %s %s%4d%s %.3f}P B r=%.4f %s %.3f, %.3f, %.3f"EOLO
,cntl,res[jcbeta],sub[jcbeta],num[jcbeta],rins[jcbeta]
,angletaudev,tauoffset,colr
,ctx,cty,ctz); /*ctr tau position*/
++countxyz;++pointcnt[typenow];countpoints(cntl,0);
putonetextblockline(&mainscratch,temps);
sprintf(cntl,"tauv"); /*NB pointID has no atom name field*/
sprintf(temps
,"%s{%s %s%4d%s:i}P U %.3f, %.3f, %.3f L U %s %.3f, %.3f, %.3f "
"P U %.3f, %.3f, %.3f L U %s %.3f, %.3f, %.3f\n"
,cntl,res[jcbeta],sub[jcbeta],num[jcbeta],rins[jcbeta]
,X[A][i],Y[A][i],Z[A][i],colr,ccx,ccy,ccz,X[A][i],Y[A][i],Z[A][i],colr,ncx,ncy,ncz);
putonetextblockline(&mainscratch,temps);
/*Square*/
angle = (angletaudev*angletaudev)/2;
tauoffset = disttau*tan(angle*2*3.14159/360);
/*vector from tau ctr position to unit vector point along CA---N */
vx = X[A][i]+anx - ctx;
vy = Y[A][i]+any - cty;
vz = Z[A][i]+anz - ctz;
/*magnitude (distance) from tau ctr point to that unit vector*/
disttau = sqrt(vx*vx + vy*vy + vz*vz);
/*components of the offset point, are vx/dist, vy/dist, vz/dist*/
/*offset point toward N: */
ncx = ctx + tauoffset*vx/disttau;
ncy = cty + tauoffset*vy/disttau;
ncz = ctz + tauoffset*vz/disttau;
/*offset point toward C: */
ccx = ctx - tauoffset*vx/disttau;
ccy = cty - tauoffset*vy/disttau;
ccz = ctz - tauoffset*vz/disttau;
if(tauoffset < .002)
{tauoffset = (float)0.002;}/*minimal: 0 gets default radius*/
sprintf(cntl,"taus"); /*NB pointID has no atom name field*/
typenow=typetaus;
sprintf(temps
,"%s{ tau %s %s%4d%s %.3f}P B r=%.4f %s %.3f, %.3f, %.3f"EOLO
,cntl,res[jcbeta],sub[jcbeta],num[jcbeta],rins[jcbeta]
,angletaudev,tauoffset,colr
,ctx,cty,ctz); /*ctr tau position*/
++countxyz;++pointcnt[typenow];countpoints(cntl,0);
putonetextblockline(&mainscratch,temps);
sprintf(cntl,"tauw");
sprintf(temps /*NB pointID has no atom name field*/
,"%s{%s %s%4d%s:i}P U %.3f, %.3f, %.3f L U %s %.3f, %.3f, %.3f "
"P U %.3f, %.3f, %.3f L U %s %.3f, %.3f, %.3f\n"
,cntl,res[jcbeta],sub[jcbeta],num[jcbeta],rins[jcbeta]
,X[A][i],Y[A][i],Z[A][i],colr,ccx,ccy,ccz,X[A][i],Y[A][i],Z[A][i],colr,ncx,ncy,ncz);
putonetextblockline(&mainscratch,temps);
}/*tau angle deviation*/
}/*construct Cbeta conformer*/
}/*check for a,b,c conformers*/
}/*got N,CA,C: compute idealized Cbeta position*/
else
{
ireturn = 0;
}
return(ireturn);
}
/*___constructbeta()_________________________________________________________*/
/****constructgamma()*********************************************************/
int constructgamma(float gammaxyz[3],char oldresidue,char newresidue)
{/*shift gamma atom of ref structure into ideal geometrical position */
/*so putting ideal sidechain into position will not distort geometry*/
int Lnn = 0, ireturn=0, j=0, Ldihedral=0;
float distance=0,angle=0,dihedral=0;
double cosangle=0;
float bmag=0;
float ax=0,ay=0,az=0,bx=0,by=0,bz=0;
float fcxyz[4][3] ={{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}};
/*distance and angle identically match ideal aa of library array*/
/*dihdral is fudged from real gamma atom position, if there is one*/
/*get vectors from ideal sidechain*/ /*do piecemeal for easier proofing*/
/*CA->CB->CG: b,a */ /* IDEAL: Y[x,y,z][ca,cb,cg] i.e. the mutant*/
fcxyz[1][0] = (float)Y[1][1]; /*second atom of 4: CA ideal*/
fcxyz[1][1] = (float)Y[2][1];
fcxyz[1][2] = (float)Y[3][1];
fcxyz[2][0] = (float)Y[1][2]; /*third atom of 4: CB ideal*/
fcxyz[2][1] = (float)Y[2][2];
fcxyz[2][2] = (float)Y[3][2];
fcxyz[3][0] = (float)Y[1][3]; /*fourth atom of 4: CG ideal*/
fcxyz[3][1] = (float)Y[2][3]; /*of course, gamma atom might be C, O, S*/
fcxyz[3][2] = (float)Y[3][3];
ax = (fcxyz[3][0]-fcxyz[2][0]); /*ultimate vector CB-->CG*/
ay = (fcxyz[3][1]-fcxyz[2][1]);
az = (fcxyz[3][2]-fcxyz[2][2]);
bx = (fcxyz[1][0]-fcxyz[2][0]); /*penultimate vector CB-->CA*/
by = (fcxyz[1][1]-fcxyz[2][1]);
bz = (fcxyz[1][2]-fcxyz[2][2]);
/*get ideal distance from ideal sidechain*/
distance = (float)sqrt( ax*ax + ay*ay + az*az );
ax = ax/distance;
ay = ay/distance;
az = az/distance;
bmag = (float)sqrt( bx*bx + by*by + bz*bz );
bx = bx/bmag;
by = by/bmag;
bz = bz/bmag;
/*get ideal angle from the ideal sidechain normalized vectors*/
cosangle = dotproduct(ax,ay,az,bx,by,bz);
angle = (float)(acos(cosangle)*360/(2*3.14159));
/*
sprintf(alertstr,CRLF"constr CG with dist: %.3f, ang: %.3f, from cosangle: %.3f"CRLF
,distance,angle,cosangle);
pkintextinsert(alertstr);
adjusttext(1);
*/
{/*look for the actual mainchain N for dihedral definition*/
for(j=1; j<=maxatm; j++)
{/*find the mainchain N*/
if( (atom[j][1]=='n')
&& (atom[j][2]==' '))
{
Lnn = 1;
fcxyz[0][0] = x[j]; /*first atom of 4, real mainchain N*/
fcxyz[0][1] = y[j];
fcxyz[0][2] = z[j];
break;
}
}/*find the mainchain N*/
if(Lnn)
{/*found old real mainchain N from which to calculate a dihedral*/
/*get practical dihedral using new beta but old gamma atom position*/
/* e.g. --one presumes that the gamma atom was in electron density-- */
fcxyz[1][0] = (float)X[1][1]; /*second atom of 4: CA real*/
fcxyz[1][1] = (float)X[2][1];
fcxyz[1][2] = (float)X[3][1];
fcxyz[2][0] = (float)X[1][2]; /*third atom of 4: CB calculated */
fcxyz[2][1] = (float)X[2][2]; /*already inserted into X array*/
fcxyz[2][2] = (float)X[3][2];
if( newresidue=='A'
||oldresidue=='A'
||oldresidue=='G'
||(oldresidue=='P' && newresidue!='P') )
{/*staggered h's for new Ala*/
/*force trans for longer residue on old Gly,Ala or Pro*/
dihedral = 180;
Ldihedral = 1;
}
else
{/*use dihedral based on old structure*/
fcxyz[3][0] = (float)X[1][3]; /*fourth atom of 4: CG real original*/
fcxyz[3][1] = (float)X[2][3]; /*of course, gamma atom might be C, O, S*/
fcxyz[3][2] = (float)X[3][3];
dihedral = (float)dihedral4pt(
(double)fcxyz[0][0],(double)fcxyz[0][1],(double)fcxyz[0][2]
,(double)fcxyz[1][0],(double)fcxyz[1][1],(double)fcxyz[1][2]
,(double)fcxyz[2][0],(double)fcxyz[2][1],(double)fcxyz[2][2]
,(double)fcxyz[3][0],(double)fcxyz[3][1],(double)fcxyz[3][2] );
Ldihedral = 1;
}/*use dihedral based on old structure*/
}/*found old real mainchain N from which to calculate a dihedral*/
}/*look for the actual mainchain N for dihedral definition*/
/*
sprintf(alertstr,CRLF"constr CG with dist: %.3f, ang: %.3f, dih: %.3f"CRLF
,distance,angle,dihedral);
pkintextinsert(alertstr);
adjusttext(1);
*/
if(Ldihedral)
{/*use 3 atoms + distance,angle,diheral to compute 4th atom position*/
constructfourth(fcxyz,distance,angle,dihedral);
/*uses 1st,2nd,3rd atoms [0,1,2], etc. rtns: 4th atom in index[3]*/
gammaxyz[0] = fcxyz[3][0];
gammaxyz[1] = fcxyz[3][1];
gammaxyz[2] = fcxyz[3][2];
ireturn = 1;
}/*use 3 atoms + distance,angle,diheral to compute 4th atom position*/
return(ireturn);
}/*shift gamma atom of ref structure*/
/*___constructgamma()________________________________________________________*/
/****constructfourth()********************************************************/
void constructfourth(float fcxyz[4][3],float dist,float angle,float dihedral)
{/*construct at distance,angle,dihedral*/
double ax=0,ay=0,az=0,bx=0,by=0,bz=0,cx=0,cy=0,cz=0,dx=0,dy=0,dz=0,cmag=0;
float angledhdrl=0;
/*calculate the new line from points 1,2,3, */
/* dist 3-4, angle 2-3-4, dihedral 1-2-3-4 */
/* cross: (2->3)X(2->1) ==> (2->5), aXb ==> c at dihedral 90*/
ax = fcxyz[2][0] - fcxyz[1][0];
ay = fcxyz[2][1] - fcxyz[1][1];
az = fcxyz[2][2] - fcxyz[1][2];
bx = fcxyz[0][0] - fcxyz[1][0];
by = fcxyz[0][1] - fcxyz[1][1];
bz = fcxyz[0][2] - fcxyz[1][2];
/* c = a x b */
docrossproduct(ax,ay,az,bx,by,bz,&cx,&cy,&cz);/*return vector is c*/ /*.*/
/*
printf("cross product:"
CRLF"%f = %f x %f - %f x %f"
CRLF"%f = %f x %f - %f x %f"
CRLF"%f = %f x %f - %f x %f"
,cx,ay,bz,az,by
,cy,az,bx,ax,bz
,cz,ax,by,ay,bx );
*/
/*normalization factor*/
cmag = sqrt( (cx)*(cx) + (cy)*(cy) + (cz)*(cz) ); /*c*/
/*get components of c normalized to correct distance*/
if(cmag > 0.000001)
{
cx = cx*dist/cmag;
cy = cy*dist/cmag;
cz = cz*dist/cmag;
}
/*place point along c at correct distance from 3rd point,*/
/* c is a xproduct, an so it is at a dihedral of 90 to a,b plane*/
cx = cx + fcxyz[2][0];
cy = cy + fcxyz[2][1];
cz = cz + fcxyz[2][2];
/*save x,y,z of point on c which is at the correct distance from 3rd point*/
dx = cx;
dy = cy;
dz = cz;
/*rotate d(xyz) around 2->3 for correct dihedral*/
angledhdrl = dihedral - 90; /*since is perpendicular to a,b plane*/
/*actual dihedral defined from a,b plane*/
ax = fcxyz[1][0];
ay = fcxyz[1][1];
az = fcxyz[1][2];
bx = fcxyz[2][0];
by = fcxyz[2][1];
bz = fcxyz[2][2];
doaxisrot(&dx,&dy,&dz,(float)angledhdrl, ax, ay, az, bx, by, bz);
/*now d(xyz) is at the correct dihedral*/
/*Adjust d(xyz) so it is at the correct angle to 2->3 */
/*rotate pt 4 around perpendicular to vectors 2->3 and 3->4 */
/* cross: (3->4)X(3->2) ==> (3->6), aXb ==> c at 90 to plane*/
ax = dx - fcxyz[2][0];
ay = dy - fcxyz[2][1];
az = dz - fcxyz[2][2];
bx = fcxyz[1][0] - fcxyz[2][0];
by = fcxyz[1][1] - fcxyz[2][1];
bz = fcxyz[1][2] - fcxyz[2][2];
/* c = a x b */
docrossproduct(ax,ay,az,bx,by,bz,&cx,&cy,&cz);/*return vector is c*/ /*.*/
/*normalization factor*/
cmag = sqrt( (cx)*(cx) + (cy)*(cy) + (cz)*(cz) ); /*c*/
if(cmag > 0.000001)
{
cx = cx/cmag;
cy = cy/cmag;
cz = cz/cmag;
}
/*rotate around 3->perpendicular for correct angle*/
angledhdrl = 90 - angle;
/*actual angle defined in plane from 0*/
/*but 4th point was placed at 90 to 3->2 vector*/
ax = fcxyz[2][0]; /*define a as the 3rd point*/
ay = fcxyz[2][1];
az = fcxyz[2][2];
cx = cx + fcxyz[2][0]; /*move rotation vector to 3rd point*/
cy = cy + fcxyz[2][1];
cz = cz + fcxyz[2][2];
bx = cx; /*define b as point on rotation vector*/
by = cy;