-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathx_helix.c
3045 lines (2404 loc) · 99.5 KB
/
x_helix.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 version determines helix packing between all helices in a protein */
// dmf 6.27.17
// ISSUE: 'axial' contact distances vulnerable to averaging over curved helices -
// there may be work-arounds (e.g. introduce kinks in the .dssp file), or
// there may be tests that could be added.
// ISSUES: hardwired location of ancillary files [need to work out a usage protocol]
// ISSUES: contact.txt list doesn't indicate which to which in the list. how to clarify?
// they are pairs, but tries to create unique residues list for the count.
//
// dmf 6.29.17
// FUTURE: would be easy to just to a brute-force screen of the distance
// between the 'local' axes in order to find the pairs that are closest together.
// once that point is found (which should generally agree with the more idealized
// algorithm), create a short, localized axis (say over 2-turns of helix, or
// whatever would be a typical packing area, so 11 residues or so (center +/- 5 residues)
// and get the idealized crossing angles over that interface. SHOULD BE DONE. this would
// actually give a more realistic picture of both packing distance and packing angle.
//
// SEE website for original code: http://fbs3pcu113.leeds.ac.uk/HelixPackingPair/source.html
//
// creates the following files:
// ** helix_packing_pair.txt - simplest list of packing pairs
// ** helices.txt - lists helix numbers, packing angle and distance of contact pairs
// ** contact.txt - lists residues of helix pairs involved in contacts
// axis.txt - seems to be coordinates of local segment axes for each helix
// geom.txt - helix-fitting measures
// helix_shape.txt - lists shape of helices
//
// dmf 6.27.17
// Fixes:
// 1) change #define DLINLEN to 160 (was 150)
// Addresses: Problem arising from DSSP webserver line length issue, but OK now
// 2) change variable output_filename[20] to output_helices[24], or output_axis[24], or
// output_contact[24], output_geom[24] (in various functions), and substitute in code throughout;
// also, output_file1[25] to output_packing[28]; also output_file2[20] to output_shape[24]
// 3) change usage of obpdbfile, so that it allows 1xyz.pdb as a default alternate to pdb1xyz.ent
// 4) added global flag new_open to control contact file opens (was flagged on helix # -> bug if
// helix '0' reappeared in processing list)
// dmf 6.28.17
// 5) added output to axis.py with axial points and contact points for display in PyMol. see comments.
// Addresses: Create a graphical translation of the tabular data by using axis.txt data
// to do PyMol workaround like this:
// pseudoatom pt1, pos=[x1, y1, z1]
// pseudoatom pt2, pos=[x2, y2, z2]
// distance /pt1, /pt2
// set dash_gap, 0
// see: https://sourceforge.net/p/pymol/mailman/message/25795427/
// dmf 6.29.17
// 6) changed the 'long helix' handling limit from 30 to 34
// 7) added segment_segment_closest_points3d() to get contact points within the helix segments;
// added code to skew.h to do this; rearranged some code. see comments.
// Addresses: Original close contact code determines helix distance based on infinite extension
// of the helix axial lines. THIS IS REQUIRED FOR THE SIMPLE HELIX ANGLE
// CALCULATION. But this also leads to nonsensical 'contact points' and
// likely is the source of the helix distances being too small. some helix distances
// are maybe too small (6.7A, for example). Gly/Gly packing gives ~6.4A axial distance
// (ballpark). 'close' packing may also be arising due to use of average helix axis
// over the whole (possibly curved) helix.
// dmf 7.12.17
// 8) recalculate helix_pair.distance so that the helix_packing_pair.txt output is consistent
// with the numbers output to axis.py
// dmf 7.25.17
// 9) begin working on adding a Identifier to the output file names.
// 1st - restructure main() code in anticipation of filename modification by pdb id
// 2nd - there are seven (7) output files to handle:
// helix_shape.txt - output_shape; open in main() only
// helix_packing_pair.txt - output_packing; open in main() only
// helices.txt - output_helices; open in main() only
// axis.py - pymol_axis; open in main() and get_bending_angle()
// axis.txt - output_axis; open in get_local_axis(), get_bending_angle() and two_helix_contact_vectors()
// contact.txt - output_contact; open in atom_distance() only
// geom.txt - output_geom; open in fit() only
// 3rd - added function to generate filenames with pdb_id appended - all good.
// Addresses: output files are not named per the files being processed (e.g.
// should have "1ffh_output.txt" or whatever, not just "output.txt")
//
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#include "skew.h"
// dmf 6.27.17
// #define DEBUG
// dmf 6.27.17 increased DLINLEN from 150
#define DLINLEN 160
#define MAXHELICES 1000 /* max helices in protein - set between 500-1000 */
#define MAXRESIDUES 200 /* maximum residues in a helix - set between 100-200 */
#define LINLEN 128
#define CLINLEN 450
#define MAXHELIXATOMS (MAXRESIDUES*10)
#define SQR(X) ((X)*(X))
#define TOLERANCE 0.6 /* to be used in packing threshold calculation */
#define TOLERANCE2 (106.0/100.0) /* to be used in determining atom-atom bonds */
#define MIN_CONTACT_RESIDUES 3 /* minimum contacting residues per helix that constitute packing */
#define OBPDBDIR "/usr3/database/pdbobso/"
/* Global Variables */
// dmf 6.27.17
int new_open = 1;
// dmf 7.29.17
char output_helices[30];
char output_packing[30];
char output_shape[30];
char output_axis[30];
char output_geom[30];
char output_contact[30];
char pymol_axis[30];
/* For a helix containing 100 residues: there are 97 local axes, 98 local origins, 32 bending angles */
struct HELIX
{
int helix_no;
char pdb[5];
char chain;
char residues[MAXRESIDUES+1];
float residue_numbers[MAXRESIDUES];
float ca_coord[MAXRESIDUES][3];
double unit_local_axis[MAXRESIDUES-3][3];
double origin[MAXRESIDUES-2][3];
double bending_angle[MAXRESIDUES/3];
double max_bending_angle;
int residues_total;
int atoms_total;
char geometry; /* S for short, U for unknown, K for kinked, C for curved, L for linear */
};
struct ATOM
{
int atom_number;
char atom_name[5];
char residue_name[4];
char chain;
float residue_number;
float atom_coord[3];
int hdonor; /* 1 for hbond donor or 0 if not */
int charge; /* 0 for neutral, 1 for positive, 2 for negative */
};
struct DISTANCE
{
float distance;
char atom_name1[5];
char atom_name2[5];
float residue_number1;
float residue_number2;
int helix_number1;
int helix_number2;
};
struct HELIXPAIR
{
int helix_one;
int helix_two;
int neighbours; /* 0 for unrelated helices, 1 for neighbours */
int packed; /* 0 for unpacked, 1 for packed helices */
int h1_residues; /* number of residues of helix 1 involved in contact */
int h2_residues; /* number of residues of helix 2 involved in contact */
int h1_start; /* first residue of helix one in contact area, zero means first residue in helix (and not first in protein sequence) */
int h2_start; /* first residue of helix two in contact area, zero means first residue in helix */
int h1_end; /* last residue of helix one contact area */
int h2_end; /* last residue of helix two contact area */
int vdw; /* number of interhelical vdw contacts */
int hbond; /* number of interhelical hbond contacts */
int electrostatic; /* number of interhelical electrostatic interactions */
int covalent; /* number of interhelical covalent bonds */
double angle1; /* the interhelical dihedral angle using all helical axis vectors */
double angle2; /* the interhelical dihedral angle using only the axis vectors in the contact area */
double distance; /* length of line of closest approach between the 2 helix axes using first method */
};
/* Prototypes */
struct HELIX* read_helices(FILE *fpi_dssp, int *helices_total, char *pdb_id);
struct ATOM** read_atom(FILE *fpi_pdb, struct HELIX*, int *helices_total, int *helices_atom_total);
void get_atom_info(struct ATOM**, struct HELIX*, int *helices_total);
void get_ca_coords(struct HELIX*, struct ATOM**, int *helices_total);
void get_local_axis(int helix_number, struct HELIX*);
void get_bending_angle(int helix_number, struct HELIX*);
void fit(int helix_number, struct HELIX*);
double** matinv3(double **h);
double** matinv2(double **p);
void destroy_matrix3(double **s);
void destroy_matrix2(double **q);
struct HELIXPAIR** neighbours(int *helices_total);
struct DISTANCE** residue_distance(int helix1, int helix2, struct HELIX*, struct HELIXPAIR**);
struct DISTANCE** atom_distance(int helix1, int helix2, struct HELIX*, struct ATOM**, struct HELIXPAIR**);
void destroy_residue_residue(struct DISTANCE**, struct HELIX*, int helix_number);
void destroy_atom_atom(struct DISTANCE**, struct HELIX*, int helix_number);
void two_helix_all_vectors(int helix_A, int helix_B, struct HELIX*, struct HELIXPAIR**);
void two_helix_contact_vectors(int helix_A, int helix_B, struct HELIX*, struct HELIXPAIR**);
void destroy_helix_atom(struct ATOM**, int *helices_total);
void destroy_helix_pair(struct HELIXPAIR**, int *helices_total);
// dmf 7.29.17
void create_filenames(char *pdb_id);
/* --------------------------------Entry Point---------------------------- */
int main(void)
{
/* Variables */
FILE *fpi_dssp;
FILE *fpi_pdb;
FILE *fpi_cath;
FILE *fpo_helices;
FILE *fpo_packing;
FILE *fpo_shape;
struct HELIX *helix;
struct ATOM **helix_atom;
struct DISTANCE **residue_residue;
struct HELIXPAIR **helix_pair;
struct DISTANCE **atom_atom;
int g,h,i,j;
int helices_total;
int helices_atom_total;
char pdb_id[5];
char temp_pdb[5]="";
char dsspfile[50];
char PDBDIR[39];
char DSSPDIR[41];
char pdbfile[50];
char obpdbfile[40];
char cathfile[50]="";
char line[CLINLEN];
// dmf 6.30.17
FILE *fpo_pyaxis;
#ifdef DEBUG
printf("\n\tHello world!\n\tDebugging mode active\n\n");
#endif
printf("\nInput filename read by taking first four characters of each line.\n");
printf("Four characters: <pdb code>\n\n");
printf("Please enter PDB directory (or leave blank for current directory): ");
fgets (PDBDIR,39,stdin);
if(PDBDIR[strlen(PDBDIR)-1]=='\n') PDBDIR[strlen(PDBDIR)-1]='\0';
if(strlen(PDBDIR) && PDBDIR[strlen(PDBDIR)-1]!='/') strcat(PDBDIR,"/");
printf("Please enter DSSP directory (or leave blank for current directory): ");
fgets (DSSPDIR,41,stdin);
if(DSSPDIR[strlen(DSSPDIR)-1]=='\n') DSSPDIR[strlen(DSSPDIR)-1]='\0';
if(strlen(DSSPDIR) && DSSPDIR[strlen(DSSPDIR)-1]!='/') strcat(DSSPDIR,"/");
printf("Please enter the input filename (eg cath.txt, Hreps.v2.4, Nreps.v2.4): ");
// scanf ("%s",cathfile);
// dmf
sprintf(cathfile,"test.txt");
// while(getchar() != 10); /* Clear the input stream */
printf("\n");
if((fpi_cath=fopen(cathfile,"r"))==NULL)
{
printf("Error opening %s\n",cathfile);
exit(1);
}
// ***** cath.txt read loop *****
// the following reads in each line from the cathfile input list and processes it
while(!feof(fpi_cath))
{
fgets(line, CLINLEN, fpi_cath);
if(line[0]=='\n' || line[0]==' ') continue;
if(line[strlen(line)-1]=='\n') line[strlen(line)-1]='\0';
// dmf 7.25.17 want to grab the 'line' to a filename specifier to be
// added to each of the output filenames.
// dmf 7.25.17 this grabs the line from the input list
strncpy(pdb_id,line,4);
// dmf 7.25.17 this truncates the line to 4 characters + \0
pdb_id[4]='\0';
// dmf 7.25.17 this compares the new name to the current name. Note how it works:
// The strcmp() and strncmp() functions return an integer greater than,
// equal to, or less than 0, according as the string s1 is greater than,
// equal to, or less than the string s2.
if(strcmp(temp_pdb,pdb_id))
{
strcpy(temp_pdb,pdb_id);
strcpy(dsspfile,DSSPDIR);
strcat(dsspfile,pdb_id);
strcat(dsspfile,".dssp");
strcpy(pdbfile,PDBDIR);
strcat(pdbfile,"pdb");
strcat(pdbfile,pdb_id);
strcat(pdbfile,".ent");
// dmf 6.28.17 change to allow 1xyz.pdb as a default alternate to pdb1xyz.ent
strcpy(obpdbfile,PDBDIR);
strcat(obpdbfile,pdb_id);
strcat(obpdbfile,".pdb");
printf("\nAnalysis of %s in progress\n",pdb_id);
printf("Input Files: %s, %s\n\n",dsspfile,pdbfile);
// dmf 7.29.17 create the output filenames
create_filenames(pdb_id);
// ** moved from above **
// dmf 7.25.17 - want to modify output_packing to include identifying string.
// therefore, this statement needs to be moved to after file input, below.
if((fpo_packing=fopen(output_packing, "w"))==NULL)
{
printf("\n\n** Error writing to file '%s'!",output_packing);
exit(1);
}
fprintf(fpo_packing,"Protein\tHelix1\tHelix2\tCont 1\tCont 2\tGlobal Angle\tLocal Angle\tDistance\tCovalnt\tElectro\tH-Bond\tVDW\n");
// dmf 7.25.17 - want to modify output_shape to include identifying string.
// therefore, this statement needs to be moved to after file input, below.
if((fpo_shape=fopen(output_shape, "w"))==NULL)
{
printf("\n\n** Error writing to file '%s'!",output_shape);
exit(1);
}
fprintf(fpo_shape,"Protein\tChain\tHelix\tLength\tGeom\tMax Bending Angle\n");
// ** end of moved from above **
// dmf 7.25.17 - want to modify output_helices to include identifying string.
if((fpo_helices=fopen(output_helices, "w"))==NULL)
{
printf("\n\n** Error writing to file '%s'!",output_helices);
exit(1);
}
if((fpi_dssp=fopen(dsspfile,"r"))==NULL)
{
printf("\n\nError opening %s\n",dsspfile);
exit(1);
}
helix=read_helices(fpi_dssp, &helices_total, pdb_id);
fclose(fpi_dssp);
if((fpi_pdb=fopen(pdbfile,"r"))==NULL)
{
if((fpi_pdb=fopen(obpdbfile,"r"))==NULL)
{
printf("\n\nError opening %s\n",pdbfile);
printf("Error opening %s\n",obpdbfile);
exit(1);
}
}
helix_atom=read_atom(fpi_pdb, helix, &helices_total, &helices_atom_total);
fclose(fpi_pdb);
get_atom_info(helix_atom, helix, &helices_total);
get_ca_coords(helix, helix_atom, &helices_total);
for(i=0;i<helices_total;i++)
{
get_local_axis(i, helix);
get_bending_angle(i, helix);
fit(i, helix);
}
for(i=0;i<helices_total;i++)
{
fprintf(fpo_helices,"protein: %s, chain: %c, helix: %d, start residue: %.2f, last residue: %.2f\n",helix[i].pdb,helix[i].chain,helix[i].helix_no,helix[i].residue_numbers[0],helix[i].residue_numbers[helix[i].residues_total-1]);
fprintf(fpo_helices,"number of residues: %d, sequence: %s\n",helix[i].residues_total,helix[i].residues);
fprintf(fpo_helices,"maximum bending angle: %f degrees, overall geometry: %c\n\n",helix[i].max_bending_angle,helix[i].geometry);
}
fprintf(fpo_helices,"Total Number of Helices = %d\n\n",helices_total);
helix_pair=neighbours(&helices_total);
fprintf(fpo_helices,"Neighbouring Helices\n\n");
for(j=0;j<helices_total;j++)
{
printf(".");
fflush(stdout);
for(i=0;i<=j;i++)
{
residue_residue=residue_distance(i, j, helix, helix_pair);
destroy_residue_residue(residue_residue, helix, i);
if(helix_pair[i][j].neighbours==1)
{
atom_atom=atom_distance(i, j, helix, helix_atom, helix_pair);
fprintf(fpo_helices,"helix %d & ",helix_pair[i][j].helix_one);
fprintf(fpo_helices,"helix %d ",helix_pair[i][j].helix_two);
fprintf(fpo_helices,"neighbours: %d ",helix_pair[i][j].neighbours);
fprintf(fpo_helices,"packed: %d ",helix_pair[i][j].packed);
fprintf(fpo_helices,"helix %d contact residues: %d ",helix_pair[i][j].helix_one,helix_pair[i][j].h1_residues);
fprintf(fpo_helices,"helix %d contact residues: %d ",helix_pair[i][j].helix_two,helix_pair[i][j].h2_residues);
fprintf(fpo_helices,"helix %d first contact residue: %d ",helix_pair[i][j].helix_one,helix_pair[i][j].h1_start);
fprintf(fpo_helices,"last contact residue: %d ",helix_pair[i][j].h1_end);
fprintf(fpo_helices,"helix %d first contact residue: %d ",helix_pair[i][j].helix_two,helix_pair[i][j].h2_start);
fprintf(fpo_helices,"last contact residue: %d ",helix_pair[i][j].h2_end);
fprintf(fpo_helices,"covalents: %d ",helix_pair[i][j].covalent);
fprintf(fpo_helices,"electrostatics: %d ",helix_pair[i][j].electrostatic);
fprintf(fpo_helices,"hbonds: %d ",helix_pair[i][j].hbond);
fprintf(fpo_helices,"vdws: %d\n",helix_pair[i][j].vdw);
destroy_atom_atom(atom_atom, helix, i);
}
}
}
fprintf(fpo_helices,"\nPacked Helices: Angles & Distance of Closest Approach\n\n");
for(j=0;j<helices_total;j++)
{
for(i=0;i<=j;i++)
{
if((helix_pair[i][j].packed==1) && (helix[i].residues_total>=4) && (helix[j].residues_total>=4))
{
two_helix_all_vectors(i, j, helix, helix_pair);
two_helix_contact_vectors(i, j, helix, helix_pair);
fprintf(fpo_helices,"Helix %d & Helix %d\n",i,j);
fprintf(fpo_helices,"Global Angle (from all vectors): %f degrees\nLocal Angle (from contact vectors): %f degrees\nInteraxial Distance: %f Angstroms\n\n",helix_pair[i][j].angle1,helix_pair[i][j].angle2,helix_pair[i][j].distance);
}
}
}
fprintf(fpo_helices,"\nAtomic List\n\n");
for(i=0;i<helices_total;i++)
{
for(j=0;j<helix[i].atoms_total;j++)
{
fprintf(fpo_helices,"atom: %d,%s hbond donor: %d charge: %d residue: %s residue number: %.2f chain: %c\n",helix_atom[i][j].atom_number,helix_atom[i][j].atom_name,helix_atom[i][j].hdonor,helix_atom[i][j].charge,helix_atom[i][j].residue_name,helix_atom[i][j].residue_number,helix_atom[i][j].chain);
}
fprintf(fpo_helices,"\n");
}
fprintf(fpo_helices,"total number of helical atoms = %d\n\n",helices_atom_total);
fclose(fpo_helices);
for(j=0;j<helices_total;j++)
{
for(i=0;i<=j;i++)
{
if((helix_pair[i][j].packed==1) && (helix[i].residues_total>=4) && (helix[j].residues_total>=4))
{
// output to "output_packing", file is already open with header text
fprintf(fpo_packing,"%s\t%d\t%d\t%d\t%d\t",helix[i].pdb,helix[i].helix_no,helix[j].helix_no,helix_pair[i][j].h1_residues,helix_pair[i][j].h2_residues);
fprintf(fpo_packing,"%f\t%f\t%f\t",helix_pair[i][j].angle1,helix_pair[i][j].angle2,helix_pair[i][j].distance);
fprintf(fpo_packing,"%d\t%d\t%d\t%d\n",helix_pair[i][j].covalent,helix_pair[i][j].electrostatic,helix_pair[i][j].hbond,helix_pair[i][j].vdw);
}
}
}
fclose(fpo_packing);
for(i=0;i<helices_total;i++)
{
// output to "output_shape", file is already open with header text
fprintf(fpo_shape,"%s\t%c\t%d\t%d\t",helix[i].pdb,helix[i].chain,helix[i].helix_no,helix[i].residues_total);
fprintf(fpo_shape,"%c\t%f\n",helix[i].geometry,helix[i].max_bending_angle);
}
fclose(fpo_shape);
printf(" Done\n");
free(helix);
destroy_helix_atom(helix_atom, &helices_total);
destroy_helix_pair(helix_pair, &helices_total);
// add tail information to axis.py
// dmf 7.25.17 - want to modify pymol_axis to include identifying string
// dmf 7.27.17 note that this file is opened and appended to in several different
// functions, so this "a+" is required here.
if((fpo_pyaxis=fopen(pymol_axis, "a+"))==NULL)
{
printf("\n\n** Error appending to file '%s'!",pymol_axis);
exit(1);
}
fprintf(fpo_pyaxis,"set dash_gap, 0, cont*\n");
fprintf(fpo_pyaxis,"set dash_radius, 0.40\n");
fprintf(fpo_pyaxis,"set dash_round_ends, 0\n");
fprintf(fpo_pyaxis,"set dash_color, 0xffcc00, dist*\n");
fprintf(fpo_pyaxis,"hide labels, dist*\n");
fclose(fpo_pyaxis);
}
}
// end of cathfile input read and process loop
// ***** end of cath.txt read loop *****
fclose(fpi_cath);
return 0;
}
// end of main();
/* ------------------------------------------------------------------------- */
/* Function to read DSSP file, get residues in helices, and initialise helix array */
struct HELIX* read_helices(FILE *fpi_dssp, int *helices_total, char *pdb_id)
{
/* Variables */
char line[DLINLEN];
struct HELIX *helix;
char res[7];
char res_sub_type;
float res_number;
float res_sub_number;
int g,h,i=0,j,k=0;
char previous_structure='Z';
char current_structure='X';
helix=(struct HELIX *) calloc(MAXHELICES,sizeof(struct HELIX));
/* fill the array of the structure HELIX with junk for debugging */
for (g=0; g<MAXHELICES; g++)
{
helix[g].residues_total=-1;
helix[g].helix_no=-1;
helix[g].atoms_total=-1;
helix[g].max_bending_angle=0;
helix[g].chain='Z';
helix[g].geometry='S';
for (h=0; h<MAXRESIDUES; h++)
{
helix[g].residues[h]='Z';
helix[g].residue_numbers[h]=-1;
helix[g].ca_coord[h][0]=-9999;
helix[g].ca_coord[h][1]=-9999;
helix[g].ca_coord[h][2]=-9999;
}
helix[g].residues[h+1]='\0';
for (h=0; h<MAXRESIDUES-3; h++)
{
helix[g].unit_local_axis[h][0]=-1;
helix[g].unit_local_axis[h][1]=-1;
helix[g].unit_local_axis[h][2]=-1;
}
for (h=0; h<MAXRESIDUES-2; h++)
{
helix[g].origin[h][0]=-1;
helix[g].origin[h][1]=-1;
helix[g].origin[h][2]=-1;
}
for (h=0; h<MAXRESIDUES/3; h++)
{
helix[g].bending_angle[h]=-1;
}
}
/* start getting the dssp file line by line, and get to important bit */
do
{
fgets(line, DLINLEN, fpi_dssp);
}
while(!feof(fpi_dssp) && line[2]!='#');
/* i is number of helices */
/* k is number of residues in each helix */
while(!feof(fpi_dssp))
{
fgets(line, DLINLEN, fpi_dssp);
if(line[strlen(line)-1]=='\n') line[strlen(line)-1]='\0';
if(line[13]!='!')
{
if(line[11]==' ') line[11]='0';
for(j=0; j<6; j++) res[j]=line[j+5];
res[6]='\0';
/* get residue number, e.g. residue 10 becomes 10.00 */
res_number=atof(res);
res_sub_type=' ';
res_sub_number=0.0;
/* get residue sub-label if it exists */
if(line[10]!=' ' && line[10]!='0' && line[10]!='1' && line[10]!='2' && line[10]!='3' && line[10]!='4' && line[10]!='5' && line[10]!='6' && line[10]!='7' && line[10]!='8' && line[10]!='9')
{
res_sub_type=line[10];
res_sub_number=res_sub_type-64;
res_sub_number=res_sub_number/100;
}
/* this has converted residue 1A into 1.01, residue 2B into 2.02 etc. */
res_number+=res_sub_number;
current_structure=line[16]; /* update current secondary structure type */
if(current_structure=='I' || current_structure=='G' || current_structure=='H') /* if secondary structure of this line is a helix... */
{
strcpy(helix[i].pdb,pdb_id);
helix[i].chain=line[11];
helix[i].residue_numbers[k]=res_number;
helix[i].residues[k]=line[13];
helix[i].residues[k+1]='\0';
/* and increment k (the helix residue number) for the next residue of existing helix */
k++;
if(k==MAXRESIDUES)
{
printf("\n\nMaximum helix residue number has been reached for helix %d\n",i);
exit(1);
}
}
/* if secondary structure of this line is not a helix and the structure from */
/* the previous line was... then assume end of helix and reset k (helix residue number) */
/* and increment i (the helix number) in preparation for start of next helix. */
else if((current_structure!='I' || current_structure!='G' || current_structure!='H') && (previous_structure=='I' || previous_structure=='G' || previous_structure=='H'))
{
helix[i].residues_total=k;
helix[i].helix_no=i;
k=0;
i++;
if(i==MAXHELICES)
{
printf("\n\nMaximum number of helices allowed has been reached\n");
exit(1);
}
}
previous_structure=current_structure;
}
else if((line[13]=='!') && (previous_structure=='I' || previous_structure=='G' || previous_structure=='H'))
{
previous_structure='Z';
current_structure='X';
helix[i].residues_total=k;
helix[i].helix_no=i;
k=0;
i++;
if(i==MAXHELICES)
{
printf("\n\nMaximum number of helices allowed has been reached\n");
exit(1);
}
}
}
*helices_total=i;
return helix;
}
/* ------------------------------------------------------------------------- */
/* Function to read PDB file and get atom details if they are in the DSSP defined helices */
struct ATOM** read_atom(FILE *fpi_pdb, struct HELIX *helix, int *helices_total, int *helices_atom_total)
{
/* Variables */
struct ATOM **helix_atom;
char line[LINLEN];
// char coord[9];
// dmf 6.27.17
char coord[10];
char resseq[6];
char resname[4];
char chain;
char res_sub_type;
float res_sub_number;
float current_residue_number=-1.5;
float last_residue_in_helix=-1.5;
char number[6];
int g,h,i=0,j=0,k,l,m=0,n=0;
/* Allocate the memory for the 2d array dynamically
*
* -- max atoms per helix (1000-2000)-->
* |
* number of helices
* \/
*/
helix_atom = (struct ATOM **) calloc(*helices_total,sizeof(struct ATOM*));
for(k=0; k<*helices_total; k++)
{
helix_atom[k] = (struct ATOM *) calloc(MAXHELIXATOMS,sizeof(struct ATOM));
}
/* fill all atom and residue numbers in entire 2-D array with junk */
for(g=0; g<*helices_total; g++)
{
for(h=0; h<MAXHELIXATOMS; h++)
{
helix_atom[g][h].atom_number=-1;
helix_atom[g][h].residue_number=-1;
helix_atom[g][h].chain='Z';
helix_atom[g][h].atom_coord[0]=-9999;
helix_atom[g][h].atom_coord[1]=-9999;
helix_atom[g][h].atom_coord[2]=-9999;
helix_atom[g][h].hdonor=0;
helix_atom[g][h].charge=0;
}
}
/* Read input file until all helices are completed */
while(!feof(fpi_pdb) && strncmp(line,"END",3))
{
fgets(line, LINLEN, fpi_pdb);
if(line[strlen(line)-1]=='\n') line[strlen(line)-1]='\0';
/* If record name is ATOM or HETATM and the atom name is not H ... */
if((line[13]!='H') && (!strncmp(line,"ATOM ",6) || !strncmp(line,"HETATM",6)))
{
if(line[21]==' ') line[21]='0';
chain=line[21];
for(k=0;k<3;k++) resname[k]=line[k+17];
resname[3]='\0';
/* if the chain is right and the residue is not a water molecule */
if((chain==helix[i].chain) && (strcmp(resname,"HOH")))
{
/* current residue number from PDB atom list */
/* e.g. residue 1 becomes 1.00 */
for(k=0;k<5;k++) resseq[k]=line[k+22];
resseq[5]='\0';
current_residue_number=atof(resseq);
res_sub_type=' ';
res_sub_number=0.0;
/* get residue sub-label if it exists */
if(line[26]!=' ' && line[26]!='0' && line[26]!='1' && line[26]!='2' && line[26]!='3' && line[26]!='4' && line[26]!='5' && line[26]!='6' && line[26]!='7' && line[26]!='8' && line[26]!='9')
{
res_sub_type=line[26];
res_sub_number=res_sub_type-64;
res_sub_number=res_sub_number/100;
}
/* this has converted residue 1A into 1.01, residue 1Z into 1.26 etc. */
current_residue_number+=res_sub_number;
/* For within a helix, where j (helix residue number) must be incremented before assignments to atom variables are made */
if((current_residue_number==helix[i].residue_numbers[j+1]) && (last_residue_in_helix==helix[i].residue_numbers[j]))
{
j++;
}
/* For start or within helix, where PDB residue number equals helix residue number */
if(current_residue_number==helix[i].residue_numbers[j])
{
/* atom_number */
for(k=0;k<5;k++) number[k]=line[k+6];
number[5]='\0';
helix_atom[i][m].atom_number=atoi(number);
/* atom name */
for(k=0;k<4;k++) helix_atom[i][m].atom_name[k]=line[k+12];
helix_atom[i][m].atom_name[4]='\0';
/* residue name */
strcpy(helix_atom[i][m].residue_name,resname);
/* chain */
helix_atom[i][m].chain=chain;
/* residue number */
helix_atom[i][m].residue_number=current_residue_number;
/* co-ordinates */
k=30;
for(g=0;g<3;g++)
{
for(h=0;h<9;h++) coord[h]=line[h+k];
coord[9]='\0';
helix_atom[i][m].atom_coord[g]=atof(coord);
k=k+8;
}
last_residue_in_helix=current_residue_number; /* update last residue number in helix */
m++; /* m represents total atoms in a helix */
n++; /* n represents total atoms in all helices */
}
/* for a search for the start of another helix */
if((current_residue_number!=helix[i].residue_numbers[j]) && (last_residue_in_helix==helix[i].residue_numbers[j]))
{
j++;
}
/* when a helix is at an end */
if(j==helix[i].residues_total)
{
helix[i].atoms_total=m;
i++;
j=0;
m=0;
}
/* when all helices are completed */
if(i==*helices_total)
{
break;
}
}
}
}
*helices_atom_total=n;
return helix_atom;
}
/* ------------------------------------------------------------------------- */
/* Function to update ATOM structures in the helix_atom 2-D array with hydrogen bond donor and electrostatic info */
void get_atom_info(struct ATOM **helix_atom, struct HELIX *helix, int *helices_total)
{
/* Variables */
int i,j,k,l;
FILE *fp; // dmf 7.27.17 - leave as fp
char line[LINLEN];
char residue[4];
char atom[5];
char hbond[2];
char electro[2];
int hbond_donor;
int electrostatic;
if((fp=fopen("translation.txt","r")) == NULL)
{
printf("\n\nError opening translation.txt\n");
exit(1);
}
while(!feof(fp))
{
fgets(line,LINLEN,fp);
if(line[strlen(line)-1]=='\n') line[strlen(line)-1]='\0';
for(k=0;k<3;k++) residue[k]=line[k];
residue[3]='\0';
for(l=0;l<4;l++) atom[l]=line[4+l];
atom[4]='\0';
hbond[0]=line[9];
hbond[1]='\0';
hbond_donor=atoi(hbond);
electro[0]=line[11];
electro[1]='\0';
electrostatic=atoi(electro);
for(i=0;i<*helices_total;i++)
{
for(j=0;j<helix[i].atoms_total;j++)
{
if((!strcmp(residue,helix_atom[i][j].residue_name)) && (!strcmp(atom,helix_atom[i][j].atom_name)))
{
helix_atom[i][j].hdonor=hbond_donor;
helix_atom[i][j].charge=electrostatic;
}
}
}
}
// printf("\n\nresidue %s, atom %s, hbond %d, charge %d\n",residue,atom,hbond_donor,electrostatic);
fclose(fp);
}
/* ------------------------------------------------------------------------- */
/* Little function to get CA co-ordinates from one structure to another */
void get_ca_coords(struct HELIX *helix, struct ATOM **helix_atom, int *helices_total)
{
/* Variables */
int i,j,k;
float current_residue;
float previous_residue;
for (i=0;i<*helices_total;i++)
{
k=0; /* set back to zero for new helix */
previous_residue=-1.5; /* reset for new helix */
for(j=0;j<helix[i].atoms_total;j++)
{
current_residue=helix_atom[i][j].residue_number;
if((!strcmp(helix_atom[i][j].atom_name," CA ")) && (current_residue!=previous_residue))
{
helix[i].ca_coord[k][0]=helix_atom[i][j].atom_coord[0];
helix[i].ca_coord[k][1]=helix_atom[i][j].atom_coord[1];
helix[i].ca_coord[k][2]=helix_atom[i][j].atom_coord[2];
k++; /* k is number of CA atoms */
previous_residue=current_residue;
}
if(k==helix[i].residues_total+1)
{
printf("\n\n*** Maximum number of helix CA co-ordinates transferred ***\n");
exit(1);
}
}
}
}
/* ------------------------------------------------------------------------- */
/* Function to get the unit local axes (upto 97 in a 100 residue helix) of a single helix */