-
Notifications
You must be signed in to change notification settings - Fork 0
/
rebuild.c
executable file
·2082 lines (1743 loc) · 64 KB
/
rebuild.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 file is part of the SCHNAarP software package for the analysis and
* rebuilding of double helical nucleic acid structures. Detailed description
* of the underlying algorithms can be found in the following three papers:
*
* (1) Xiang-Jun Lu, M. A. El Hassan and C. A. Hunter (1997), "Structure
* and Conformation of Helical Nucleic Acids: Analysis Program
* (SCHNAaP)", J. Mol. Biol. 273, 668--680.
*
* (2) Xiang-Jun Lu, M. A. El Hassan and C. A. Hunter (1997), "Structure
* and Conformation of Helical Nucleic Acids: Rebuilding Program
* (SCHNArP)", J. Mol. Biol. 273, 681--691.
*
* (3) M. A. El Hassan and C. R. Calladine (1995), "The Assessment of the
* Geometry of Dinucleotide Steps in Double-Helical DNA; a New Local
* Calculation Scheme", J. Mol. Biol. 251, 648--664.
*
* Copyright (C) 1996-2002 Xiang-Jun Lu. Permission to use, copy, and modify
* this software is hereby granted to all academic and not-for-profit
* institutions without fee, provided that the above papers (or part of) are
* properly cited in related publications. However, the right to use this
* software in conjunction with for profit activities, and the right to
* distribute the software or modified or extended versions thereof for profit
* are *NOT* granted except by prior arrangement and written consent of the
* copyright holders.
*
* The software is provided "AS-IS" and without warranty of any kind, express,
* implied or otherwise, including without limitation, any warranty of
* merchantability or fitness for a particular purpose.
*
* The software was written by Xiang-Jun Lu ([email protected]). It started
* off his PhD thesis work at Dr. Chris Hunter Laboratory at University of
* Sheffield, U.K. The source code should be valuable for understanding the
* elegant CEHS algorithm, and many other aspects of nucleic acid structures.
* For real world applications, however, you are strongly recommended to
* switch to 3DNA (http://3dna.rutgers.edu).
*
* Revision history -- please see file 'Change.log'
*
* $LastChangedDate: 2009-06-01 18:34:25 -0400 (Mon, 01 Jun 2009) $
* $LastChangedRevision: 1556 $
* $LastChangedBy: xiangjun $
* ------------------------------------------------------------------------
>>>*/
#include "schna_ar_p.h"
/* %%%%%%%%%%%%%%%%%%% Common functions BEGIN %%%%%%%%%%%%%%%%%%% */
/* ALIGN_HELIX align the helix using an axis defined by <org_xyz> */
void align_helix(double **oxyz, double **xyz, long natom, double **org_xyz, long nbp)
{
char str[BUF512];
long ich, i, j;
double *hel_axis, *ave_xyz, *pnts_dist, **diff_org_xyz, dvar;
double **rotmat, **rotmat_T, **tmpxyz;
/* ----- Commented to probe for efficiency ----------- */
ich = 1;
/*
printf("\n1. View perpendicular to the 1st base-pair\n");
printf("2. View parallel to the 1st base-pair\n");
printf("3. View perpendicular to the 'best-fit' line through mid-bps\n");
printf("4. View perpendicular to the 'best-fit' helical axis\n");
printf("Your choice (1-4, Dft 1): ");
read_stdin_str(str);
ich = atoi(str);
*/
if ((ich < 1) || (ich > 4))
ich = 1;
hel_axis = dvector(1, 3);
ave_xyz = dvector(1, 3);
pnts_dist = dvector(1, nbp);
diff_org_xyz = dmatrix(1, nbp - 1, 1, 3);
if (ich == 1) {
for (i = 1; i <= natom; i++)
for (j = 1; j <= 3; j++)
oxyz[i][j] = xyz[i][j];
free_dvector(hel_axis, 1, 3);
free_dvector(ave_xyz, 1, 3);
free_dvector(pnts_dist, 1, nbp);
free_dmatrix(diff_org_xyz, 1, nbp - 1, 1, 3);
return;
} else if (ich == 2) {
hel_axis[1] = 0.0;
hel_axis[2] = 0.0;
hel_axis[3] = 1.0;
} else if (ich == 3)
lsline(hel_axis, ave_xyz, pnts_dist, org_xyz, nbp);
else {
for (i = 1; i <= nbp - 1; i++)
for (j = 1; j <= 3; j++)
diff_org_xyz[i][j] = org_xyz[i + 1][j] - org_xyz[i][j];
lsplane(hel_axis, &dvar, pnts_dist, diff_org_xyz, nbp - 1);
}
rotmat = dmatrix(1, 3, 1, 3);
rotmat_T = dmatrix(1, 3, 1, 3);
tmpxyz = dmatrix(1, natom, 1, 3);
alignz(rotmat, hel_axis); /* rotation matrix */
tr_dmatrix(rotmat_T, rotmat, 3, 3); /* its transpose */
mul_dmatrix(oxyz, xyz, rotmat_T, natom, 3, 3, 3);
rotz(rotmat, -90.0);
mul_dmatrix(tmpxyz, oxyz, rotmat, natom, 3, 3, 3);
rotx(rotmat, 90.0);
mul_dmatrix(oxyz, tmpxyz, rotmat, natom, 3, 3, 3);
/* matlab code: xyz=xyz*alignz(hel_axis)'*rotz(90)'*rotx(-90)'; */
free_dvector(hel_axis, 1, 3);
free_dvector(ave_xyz, 1, 3);
free_dvector(pnts_dist, 1, nbp);
free_dmatrix(diff_org_xyz, 1, nbp - 1, 1, 3);
free_dmatrix(rotmat, 1, 3, 1, 3);
free_dmatrix(rotmat_T, 1, 3, 1, 3);
free_dmatrix(tmpxyz, 1, natom, 1, 3);
}
/* xdir--0 for minor-->major as in A/B/W; 1 otherwise as in Z-DNA */
long get_xdir(double twist)
{
char yn, str[BUF512];
long xdir;
/* ----- Commented to probe for efficiency ----------- */
xdir = 0;
/*
if (twist < 0.0) { // Left-handed DNA
printf("\nPositive x-axis from MAJOR-->minor groove (y/n, Dft: y): ");
read_stdin_str(str);
yn = toupper(str[0]);
if (yn != 'N')
xdir = 1;
else
xdir = 0;
} else { // Right-handed DNA
printf("\nPositive x-axis from minor-->MAJOR groove (y/n, Dft: y): ");
read_stdin_str(str);
yn = toupper(str[0]);
if (yn != 'N')
xdir = 0;
else
xdir = 1;
}
*/
return xdir;
}
/* STR_DISPLAY graphical display of the generated structure using RasMol
%
% Input: imdl--representation model, 1 for atomic, and 2 for schematic */
void str_display(long imdl, char *filnam)
{
char *str, *cmd_str, *env_add, yn;
str = cvector(1, BUF512);
cmd_str = cvector(1, BUF512);
printf("\nDisplay of the generated structure [Y(Dft--RasMol)/N]: \n");
read_stdin_str(str);
yn = toupper(str[0]);
if (yn == 'N') {
free_cvector(str, 1, BUF512);
free_cvector(cmd_str, 1, BUF512);
return;
}
if ((env_add = getenv("SCHNA_AR_P")) == NULL)
nrerror("Environment variable SCHNA_AR_P undefined!!!\n");
strcpy(str, env_add);
strcat(str, "/Utilities/");
if (imdl == 1) { /* Atomic model: PDB format */
strcpy(cmd_str, "rasmol ");
strcat(cmd_str, filnam);
strcat(cmd_str, " -script ");
strcat(cmd_str, str);
strcat(cmd_str, "ATMrasmol.scr");
system(cmd_str);
} else { /* Rectangular block model: ALCHEMY format */
strcpy(cmd_str, "rasmol -alchemy ");
strcat(cmd_str, filnam);
strcat(cmd_str, " -script ");
strcat(cmd_str, str);
strcat(cmd_str, "BLKrasmol.scr");
system(cmd_str);
}
free_cvector(str, 1, BUF512);
free_cvector(cmd_str, 1, BUF512);
}
void set_bppar(double **bppar, long nbp, char **bpseq)
/* Set proper base-pair parameters for A-T & G-C */
{
long i, j, ibp;
char *str, *env_add, bpfile[BUF512], bchar;
char A_T[4], G_C[4];
double *A_Tpar, *G_Cpar, *T_Apar, *C_Gpar;
FILE *fbp;
str = cvector(1, BUF512);
/* ----- Commented to probe for efficiency ----------- */
ibp = 1;
/*
printf("\nWhich base-pair geometry to use:\n");
printf("1. Flat base-pair\n");
printf("2. Non-flat base-pair (overall X-ray average)\n");
printf("3. X-ray average for A-T and G-C separately\n");
printf("4. User defined geometry\n");
printf("Your choice (1-4, Dft 1): ");
read_stdin_str(str);
ibp = atoi(str);
*/
if ((ibp < 1) || (ibp > 4))
ibp = 1;
if (ibp == 1)
strcpy(bpfile, "BPflat.dat");
else if (ibp == 2)
strcpy(bpfile, "BPnflat.dat");
else if (ibp == 3)
strcpy(bpfile, "BPxray.dat");
else {
printf("Name of the base-pair geometry file: ");
read_stdin_str(bpfile);
}
if ((env_add = getenv("SCHNA_AR_P")) == NULL)
nrerror("Environment variable SCHNA_AR_P undefined!!!\n");
strcpy(str, env_add);
strcat(str, "/BaseGeo/");
strcat(str, bpfile);
fbp = open_file(str, "r");
A_Tpar = dvector(1, 6);
G_Cpar = dvector(1, 6);
T_Apar = dvector(1, 6);
C_Gpar = dvector(1, 6);
fgets(str, BUF512 - 1, fbp); /* Skip the first title line */
/* For A-T & T-A base-pairs */
fscanf(fbp, "%s", A_T);
upper(A_T, strlen(A_T));
if (strcmp(A_T, "A-T"))
nrerror("The first bp should be A-T!");
for (i = 1; i <= 6; i++) {
fscanf(fbp, "%lf", &A_Tpar[i]);
if (i == 1 || i == 4)
T_Apar[i] = -A_Tpar[i];
else
T_Apar[i] = A_Tpar[i];
}
/* For G-C & C-G base-pairs */
fscanf(fbp, "%s", G_C);
upper(G_C, strlen(G_C));
if (strcmp(G_C, "G-C"))
nrerror("The second bp should be G-C!");
for (i = 1; i <= 6; i++) {
fscanf(fbp, "%lf", &G_Cpar[i]);
if (i == 1 || i == 4)
C_Gpar[i] = -G_Cpar[i];
else
C_Gpar[i] = G_Cpar[i];
}
fclose(fbp);
/* Set base-pair parameters for each pair in the sequence */
for (i = 1; i <= nbp; i++) {
bchar = bpseq[1][i - 1];
if (bchar == 'A')
for (j = 1; j <= 6; j++)
bppar[i][j] = A_Tpar[j];
else if (bchar == 'T')
for (j = 1; j <= 6; j++)
bppar[i][j] = T_Apar[j];
else if (bchar == 'G')
for (j = 1; j <= 6; j++)
bppar[i][j] = G_Cpar[j];
else
for (j = 1; j <= 6; j++)
bppar[i][j] = C_Gpar[j];
}
free_cvector(str, 1, BUF512);
free_dvector(A_Tpar, 1, 6);
free_dvector(G_Cpar, 1, 6);
free_dvector(T_Apar, 1, 6);
free_dvector(C_Gpar, 1, 6);
}
/* Connect successive blocks of ALCHEMY data file */
/* This is a function called directly by SCHNArP, but
there is also a stand alone command version */
void alc_connect(char *filinp, char *filout)
{
long i, num, nbond, **lkg;
char **asym;
double **xyz;
long n_O1, n_O2, n_N1, n_N2;
long *O1, *O2, *N1, *N2;
lkg = lmatrix(1, MAX_ATOM, 1, 2);
asym = cmatrix(1, MAX_ATOM, 1, 3); /* 2-characters long */
xyz = dmatrix(1, MAX_ATOM, 1, 3);
rdalc(&num, &nbond, asym, lkg, xyz, filinp);
O1 = lvector(1, num);
O2 = lvector(1, num);
N1 = lvector(1, num);
N2 = lvector(1, num);
/* Note: No "O1" atom type in ALCHEMY */
str_idx(&n_O1, O1, asym, "O3", num);
str_idx(&n_O2, O2, asym, "O2", num);
str_idx(&n_N1, N1, asym, "N1", num);
str_idx(&n_N2, N2, asym, "N2", num);
if (n_O1 == 0) { /* No C1' atoms, so connect successive N atoms */
/* Strand I */
for (i = 1; i <= (n_N1 - 1); i++) {
nbond++;
lkg[nbond][1] = N1[i];
lkg[nbond][2] = N1[i + 1];
}
/* Strand II */
for (i = 1; i <= (n_N2 - 1); i++) {
nbond++;
lkg[nbond][1] = N2[i];
lkg[nbond][2] = N2[i + 1];
}
} else { /* There are O atoms */
/* Strand I */
for (i = 1; i <= (n_O1 - 1); i++) {
nbond++;
lkg[nbond][1] = O1[i];
lkg[nbond][2] = O1[i + 1];
}
/* Strand II */
for (i = 1; i <= (n_O2 - 1); i++) {
nbond++;
lkg[nbond][1] = O2[i];
lkg[nbond][2] = O2[i + 1];
}
}
for (i = 1; i <= num; i++)
if (!strcmp(asym[i], "BR"))
strcpy(asym[i], "O2"); /* O3 will also do */
wrtalc(num, nbond, asym, lkg, xyz, filout);
free_lvector(O1, 1, num);
free_lvector(O2, 1, num);
free_lvector(N1, 1, num);
free_lvector(N2, 1, num);
free_lmatrix(lkg, 1, MAX_ATOM, 1, 2);
free_cmatrix(asym, 1, MAX_ATOM, 1, 3);
free_dmatrix(xyz, 1, MAX_ATOM, 1, 3);
}
/* %%%%%%%%%%%%%%%%%%% Common functions END %%%%%%%%%%%%%%%%%%% */
/* %%%%%%%%%%%%%%%%%%% CEHS Building functions BEGIN %%%%%%%%%%%%%%%%%%% */
/* WRT_SEQ_CEHS write the sequence and its associated CEHS step parameters
% This file can be used for error check or fined-turned to
% get the desired result.
%
% Input: nbp--number of base-pairs
% bpseq--[2 by nbp] base-pair sequence
% steppar--[nbp by 6] CEHS step parameters */
void wrt_seq_CEHS(long nbp, char **bpseq, double **steppar)
{
long i, j;
char fstep[BUF512];
FILE *fo;
printf("\nOutput sequence CEHS parameter data file name (Dft CEHS_seq.dat): ");
read_stdin_str(fstep);
if (strlen(fstep) == 0)
strcpy(fstep, "CEHS_seq.dat");
fo = open_file(fstep, "w");
fprintf(fo, "%5ld base-pairs\n", nbp);
fprintf(fo, " Shift Slide Rise Tilt Roll Twist\n");
for (i = 1; i <= nbp; i++) {
fprintf(fo, "%c-%c ", bpseq[1][i - 1], bpseq[2][i - 1]);
for (j = 1; j <= 6; j++)
fprintf(fo, "%8.2f", steppar[i][j]);
fprintf(fo, "\n");
}
fclose(fo);
}
/* STD_CEHS build A, B, C, Z and other regular double helical
structure using CEHS step parameters */
void std_CEHS(long *nbp, char **bpseq, double **steppar)
{
long i, j, ich;
char str[BUF512];
double *stepblk, *Z_Cg, *Z_Gc;
double d1, d2, d3, d4, d5, d6;
printf("1. Standard A-form DNA (Twist=32, Roll=12, Slide=-1.5A)\n");
printf("2. Standard B-form DNA (Twist=36, Roll= 0, Slide= 0A)\n");
printf("3. Standard C-form DNA (Twist=40, Roll=-6, Slide= 1A)\n");
printf("4. Standard Z-form DNA (Twist=-10, Slide=5A for CG step)\n");
printf(" Twist=-50, Slide=0A for GC step)\n");
printf("5. Other regular double helical structures\n");
printf("Input your choice (1-5, Dft 2): ");
read_stdin_str(str);
ich = atoi(str);
if ((ich < 1) || (ich > 5))
ich = 2;
stepblk = dvector(1, 6);
Z_Cg = dvector(1, 6);
Z_Gc = dvector(1, 6);
/* Get the step parameters for building blocks */
switch (ich) {
case 1: /* A-form: [0 -1.5 3.23 0 12 32] */
stepblk[1] = 0.0;
stepblk[2] = -1.5;
stepblk[3] = 3.23;
stepblk[4] = 0.0;
stepblk[5] = 12.0;
stepblk[6] = 32.0;
break;
case 2: /* B-form: [0 0 3.38 0 0 36] */
stepblk[1] = 0.0;
stepblk[2] = 0.0;
stepblk[3] = 3.38;
stepblk[4] = 0.0;
stepblk[5] = 0.0;
stepblk[6] = 36.0;
break;
case 3: /* C-form: [0 1 3.36 0 -6 40] */
stepblk[1] = 0.0;
stepblk[2] = 1.0;
stepblk[3] = 3.36;
stepblk[4] = 0.0;
stepblk[5] = -6.0;
stepblk[6] = 40.0;
break;
case 4: /* Z-form: Two kinds of steps */
/* CG/CG [0 5 3.19 0 0 -10] */
Z_Cg[1] = 0.0;
Z_Cg[2] = 5.0;
Z_Cg[3] = 3.19;
Z_Cg[4] = 0.0;
Z_Cg[5] = 0.0;
Z_Cg[6] = -10.0;
/* GC/GC [0 0 3.85 0 0 -50] */
Z_Gc[1] = 0.0;
Z_Gc[2] = 0.0;
Z_Gc[3] = 3.85;
Z_Gc[4] = 0.0;
Z_Gc[5] = 0.0;
Z_Gc[6] = -50.0;
break;
default: /* Other regular form */
printf("\nInput 6 step parameters in the order of: \n");
printf("Shift Slide Rise Tilt Roll Twist\n");
while (1) { /* Infinite loop */
read_stdin_str(str);
j = sscanf(str, "%lf%lf%lf%lf%lf%lf", &d1, &d2, &d3, &d4, &d5, &d6);
if (j == 6)
break;
printf("Six step-parameters needed. Try again!\n");
}
stepblk[1] = d1;
stepblk[2] = d2;
stepblk[3] = d3;
stepblk[4] = d4;
stepblk[5] = d5;
stepblk[6] = d6;
}
/* Read in base sequence */
get_sequence(bpseq, nbp);
for (i = 1; i <= 6; i++)
steppar[1][i] = 0.0;
/* Get the whole set of step parameters */
if (ich != 4) /* Not Z-DNA */
for (i = 2; i <= (*nbp); i++)
for (j = 1; j <= 6; j++)
steppar[i][j] = stepblk[j];
else {
for (i = 2; i <= (*nbp); i += 2) /* CG/CG steps */
for (j = 1; j <= 6; j++)
steppar[i][j] = Z_Cg[j];
for (i = 3; i <= (*nbp); i += 2) /* CG/CG steps */
for (j = 1; j <= 6; j++)
steppar[i][j] = Z_Gc[j];
}
/* Write out base-pair sequence & step parameters */
wrt_seq_CEHS(*nbp, bpseq, steppar);
free_dvector(stepblk, 1, 6);
free_dvector(Z_Cg, 1, 6);
free_dvector(Z_Gc, 1, 6);
}
/* % DIMER_CEHS build arbitrary sequence DNA structure using various
% dimer models
%
% Note: All existing models can ONLY handle bend/curvature as a function
% of "Twist, Roll and/or Tilt" of the ten dinucleotide steps.
%
% The program given here is universal in that it accepts all six
% step parameters as in the X-ray model */
void dimer_CEHS(long *nbp, char **bpseq, double **steppar)
{
long i, j, k, ich;
char *str, *env_add, mfilnam[BUF512];
double **dmstep, *tmppar;
FILE *fm;
char bpstep[3];
/* --------------------------------------------------------------------
This initialization methods works for ANSI-C. But for unknown
reasons, it does NOT work on HP computers ......
See also <cehs.c> & <analysis.c>
Order of the 16 dinucleotide steps
char *dncl[17] = {"XX", "AA", "GA", "AG", "GG", "AT", "AC", "GC", "TA",
"CA", "CG", "TT", "TC", "CT", "CC", "GT", "TG"};
-------------------------------------------------------------------- */
/* The following stupid method should always work */
char *dncl[17];
dncl[0] = "XX";
dncl[1] = "AA";
dncl[2] = "GA";
dncl[3] = "AG";
dncl[4] = "GG";
dncl[5] = "AT";
dncl[6] = "AC";
dncl[7] = "GC";
dncl[8] = "TA";
dncl[9] = "CA";
dncl[10] = "CG";
dncl[11] = "TT";
dncl[12] = "TC";
dncl[13] = "CT";
dncl[14] = "CC";
dncl[15] = "GT";
dncl[16] = "TG";
/* Stop here ====================================== */
str = cvector(1, BUF512);
printf("Choose from one of the following dimer models\n");
printf("1. Calladine\n");
printf("2. Bolshoy\n");
printf("3. De Santis\n");
printf("4. Average step parameters from X-ray structures\n");
printf("5. User defined model\n");
printf("Your choice (1-5, Dft 4): ");
read_stdin_str(str);
ich = atoi(str);
if ((ich < 1) || (ich > 5))
ich = 4;
if (ich == 1)
strcpy(mfilnam, "dimer_CDM");
else if (ich == 2)
strcpy(mfilnam, "dimer_BMHT");
else if (ich == 3)
strcpy(mfilnam, "dimer_SPSS");
else if (ich == 4)
strcpy(mfilnam, "xray_AB");
else { /* User defined model */
printf("Name of your model data file: ");
read_stdin_str(mfilnam);
}
if ((env_add = getenv("SCHNA_AR_P")) == NULL)
nrerror("Environment variable SCHNA_AR_P undefined!!!\n");
strcpy(str, env_add);
strcat(str, "/BendModel/");
strcat(str, mfilnam);
fm = open_file(str, "r");
/* Read in the model data file. The 10 steps must be in order! */
dmstep = dmatrix(1, 16, 1, 6);
tmppar = dvector(1, 6);
zero_dmatrix(dmstep, 16, 6);
/* Skip the first 3 title lines */
for (i = 1; i <= 3; i++)
fgets(str, BUF512 - 1, fm);
for (i = 1; i <= 10; i++) {
fscanf(fm, "%s", bpstep);
upper(bpstep, strlen(bpstep));
if (strcmp(bpstep, dncl[i]))
nrerror("Base step in wrong order!!!");
for (j = 1; j <= 6; j++)
fscanf(fm, "%lf", &dmstep[i][j]);
}
fclose(fm);
/* Get the step parameters for the complementary steps
Keep the sign of "Slide, Rise, Roll & Twist" unchanged
Reverse the sign of "Shift & Tilt" */
for (i = 11; i <= 16; i++) {
if (i <= 14)
j = i - 10;
else if (i == 15)
j = 6;
else
j = 9;
dmstep[i][2] = dmstep[j][2];
dmstep[i][3] = dmstep[j][3];
dmstep[i][5] = dmstep[j][5];
dmstep[i][6] = dmstep[j][6];
dmstep[i][1] = -dmstep[j][1];
dmstep[i][4] = -dmstep[j][4];
}
/* Read in the base sequence */
get_sequence(bpseq, nbp);
for (i = 1; i <= 6; i++)
steppar[1][i] = 0.0; /* Null operation */
for (i = 2; i <= (*nbp); i++) {
strncpy(bpstep, (bpseq[1] + (i - 2)), 2); /* Note bpseq start from 0 not 1 */
for (j = 1; j <= 16; j++)
if (!strcmp(dncl[j], bpstep))
break;
for (k = 1; k <= 6; k++)
steppar[i][k] = dmstep[j][k];
}
/* Write out base-sequence and step parameters */
wrt_seq_CEHS(*nbp, bpseq, steppar);
free_cvector(str, 1, BUF512);
free_dvector(tmppar, 1, 6);
free_dmatrix(dmstep, 1, 16, 1, 6);
}
/* TRIMER_CEHS build arbitrary sequence DNA structure using
% (a) Satchwell, Drew & Travers's trimer model
% (b) Brukner et al's trinucleotide model
%
% Note: The bending parameter correlates with "Roll" angle */
void trimer_CEHS(long *nbp, char **bpseq, double **steppar)
{
long i, j, ich;
char *str, *env_add, mfilnam[BUF512], **tbp;
char tbp1[4], tbp2[4], ctbp2[4], tmp_tbp[8];
FILE *fid;
double *troll, low_roll, up_roll, max_roll, min_roll;
double dval;
str = cvector(1, BUF512);
printf("Choose from one of the following trimer models\n");
printf("1. Satchwell et al's model\n");
printf("2. Brukner et al's model\n");
printf("3. User defined model\n");
printf("Your choice (1-3, Dft 1): ");
read_stdin_str(str);
ich = atoi(str);
if ((ich < 1) || (ich > 3))
ich = 1;
if (ich == 1)
strcpy(mfilnam, "trimer_SDT");
else if (ich == 2)
strcpy(mfilnam, "trimer_BSSP");
else { /* User defined model */
printf("Name of your model data file: ");
read_stdin_str(mfilnam);
}
if ((env_add = getenv("SCHNA_AR_P")) == NULL)
nrerror("Environment variable SCHNA_AR_P undefined!!!\n");
strcpy(str, env_add);
strcat(str, "/BendModel/");
strcat(str, mfilnam);
fid = open_file(str, "r");
/* Read in the model data file */
for (i = 1; i <= 3; i++)
fgets(str, BUF512 - 1, fid);
tbp = cmatrix(1, 32, 1, 8);
troll = dvector(1, 32);
for (i = 1; i <= 32; i++) {
fscanf(fid, "%s", tmp_tbp);
upper(tmp_tbp, strlen(tmp_tbp));
for (j = 0; j <= 2; j++) {
tbp1[j] = tmp_tbp[j];
tbp2[j] = tmp_tbp[6 - j];
}
comp_base(ctbp2, tbp2, 3);
if (strcmp(tbp1, ctbp2))
nrerror("There are mismatched bases!");
strcpy(tbp[i], tmp_tbp);
fscanf(fid, "%lf", &troll[i]);
}
fclose(fid);
/* Change bending parameters to roll angle */
printf("Minimum roll (Dft 0.0): ");
read_stdin_str(str);
if (strlen(str) == 0)
low_roll = 0.0;
else
sscanf(str, "%lf", &low_roll);
printf("Maximum roll (Dft: 10.0): ");
read_stdin_str(str);
if (strlen(str) == 0)
up_roll = 10.0;
else
sscanf(str, "%lf", &up_roll);
if (up_roll < low_roll)
nrerror("Error roll angle range!");
max_roll = max_dvector(troll, 32);
min_roll = min_dvector(troll, 32);
/* Scale the roll into [low_roll...up_roll] */
for (i = 1; i <= 32; i++) {
dval = (troll[i] - min_roll) / (max_roll - min_roll);
troll[i] = (up_roll - low_roll) * dval + low_roll;
}
/* Read in the base sequence */
get_sequence(bpseq, nbp);
/* % The way to get a trinucleotide unit: e.g.
% 1 2 3 4
% A-G-T-C-A-A
% (1): A-G-T; (2): G-T-C; (3): T-C-A; (4): C-A-A
% So there are nbp-2 trinucleotide units! */
/* Deduce the trinucleotide step parameters from base sequence */
(*nbp)--;
zero_dmatrix(steppar, *nbp, 6);
for (i = 2; i <= (*nbp); i++) {
steppar[i][3] = 3.34; /* Rise */
steppar[i][6] = 34.3; /* Twist */
}
for (i = 1; i <= (*nbp) - 1; i++) {
strncpy(tbp1, (bpseq[1] + (i - 1)), 3);
for (j = 1; j <= 32; j++)
if (strstr(tbp[j], tbp1) != NULL)
break;
steppar[i + 1][5] = troll[j];
}
/* Write out base-sequence and step parameters */
wrt_seq_CEHS(*nbp, bpseq, steppar);
free_cvector(str, 1, BUF512);
free_dvector(troll, 1, 32);
free_cmatrix(tbp, 1, 32, 1, 8);
}
/* STEP_CEHS build arbitrary sequence DNA structure using the
% CEHS step parameters supplied.
%
% The input file can be most easily generated by firstly
% running a proper dimer/trimer model, and then modifying
% the output parameter file as desired. */
void step_CEHS(long *nbp, char **bpseq, double **steppar, int itot, char **ist, double **xconf, int phi, char **output) //char **output put this in argument not to go over output file output_coordinates.dat
{
long i, j;
char str[BUF512], tmpstr[4];
char seq1;
// FILE *fp;
/* ----- Commented to probe for efficiency ----------- */
//sprintf(str, "output_dnaflex/output_coordinates_%.6d.dat", phi);
//strcpy(str, "output_coordinates.dat");
/*
// Read in the step parameters
printf("Sequence-CEHS step parameter file name (Dft output_coordinates.dat): ");
read_stdin_str(str);
if (strlen(str) == 0)
strcpy(str, "output_coordinates.dat");
*/
*nbp = (long)itot + 1;
for (i = 0; i < (*nbp); i++) {
sscanf(output[i+2], "%s", tmpstr);
bpseq[1][i] = toupper(tmpstr[0]);
bpseq[2][i] = toupper(tmpstr[2]);
for (j = 0; j < 6; j++){
steppar[i+1][j+1] = xconf[j][i-1]; // hier wird schon was reingeschrieben obwohl es noch nicht aufs array xconf zugreift
}
}
sscanf(output[*nbp+2], "%s", tmpstr);
bpseq[1][*nbp-1] = toupper(tmpstr[0]);
bpseq[2][*nbp-1] = toupper(tmpstr[2]);
/* This is the code if we want to read from the file
fp = open_file(str, "r");
fgets(str, BUF512 - 1, fp);
sscanf(str, "%ld", nbp);
fgets(str, BUF512 - 1, fp); // skip one line
for (i = 1; i <= (*nbp); i++) {
fscanf(fp, "%s", tmpstr);
bpseq[1][i - 1] = toupper(tmpstr[0]);
bpseq[2][i - 1] = toupper(tmpstr[2]);
for (j = 1; j <= 6; j++)
fscanf(fp, "%lf", &steppar[i][j]);
}
*/
/*
printf ("%ld \n", *nbp);
for (i = 0; i < (*nbp); i++) {
printf("%c \n", bpseq[2][i]);
}
printf("%lf \n", steppar[2][1]);
printf("%s \n", output[3]);
*/
// DO NOT DO THIS BECAUSE IT GIVES AN ERROR WHEN EXECUTING THE WHOLE MC STUFF 1000 TIMES
/* Base-pair consistency check! */
/*
comp_base(str, bpseq[1], *nbp);
if (strcmp(str, bpseq[2]))
nrerror("There are mismatched bases!");
*/
// fclose(fp);
}
void exact_CEHS(long *nbp, char **bpseq, double **bppar, double **steppar)
{
long i, j;
char str[BUF512], tmpstr[4];
FILE *fp;
printf("Name of the local CEHS parameter data file: ");
read_stdin_str(str);
fp = open_file(str, "r");
fgets(str, BUF512 - 1, fp);
sscanf(str, "%ld", nbp);
fgets(str, BUF512 - 1, fp); /* skip one line */
for (i = 1; i <= (*nbp); i++) {
fscanf(fp, "%s", tmpstr);
bpseq[1][i - 1] = toupper(tmpstr[0]);
bpseq[2][i - 1] = toupper(tmpstr[2]);
for (j = 1; j <= 6; j++)
fscanf(fp, "%lf", &bppar[i][j]);
for (j = 1; j <= 6; j++)
fscanf(fp, "%lf", &steppar[i][j]);
}
fclose(fp);
}
/* % ATOMIC_CEHS build DNA atomic structure using CEHS parameters
%
% Input: nbp--number of base-pairs
% bpseq--base-pair sequence
% bppar--[nbp by 6] CEHS base-pair parameters
% steppar--[nbp by 6] CEHS step parameters
% xdir--+x-axis direction */
void atomic_CEHS(long nbp, char **bpseq, double **bppar, double **steppar,
long xdir, char *filnam, double **xyz_float, char **pdb_data, char **pdb_tot, char **n7_data, int *tot_num_at)
{
long i, j, k, m, i2, num1, num2, tn1 = 0, tn2 = 0;
char base_set[BUF512], *dir_name, *env_add;
double **orien_next, **orien_next_T, *pos_next, **org_xyz;
char **asym1, **asym2, **t_asym1, **t_asym2;
double **xyz1, **xyz2, **t_xyz1, **t_xyz2, **xyztmp1, **xyztmp2;
char *t_btype1, *t_btype2;
long *t_bnum1, *t_bnum2, ATM_NUM = 100;
char bpname[3];
long **ts2; /* keep track of strand II base atoms */
double **orien, **mst, *pos, *tmp_vec;
long *base_num, tot_num;
char **tot_asym, *base_type, *strand;
double **tot_xyz, **tot_xyz2;
/* Read in atomic base geometry */
dir_name = cvector(1, BUF512);
/* ----- Commented to probe for efficiency ----------- */
strcpy(base_set, "NDB96");
/*
printf("\nBase geometry set to use (Dft NDB96): ");
read_stdin_str(base_set);
if (strlen(base_set) == 0)
strcpy(base_set, "NDB96");
*/
if ((env_add = getenv("SCHNA_AR_P")) == NULL)
nrerror("Environment variable SCHNA_AR_P undefined!!!\n");
strcpy(dir_name, env_add);
strcat(dir_name, "/BaseGeo/");
strcat(dir_name, base_set);
strcat(dir_name, "_");
/* Variable initializations */
orien_next = dmatrix(1, 3, 1, 3);
orien_next_T = dmatrix(1, 3, 1, 3);
pos_next = dvector(1, 3);
org_xyz = dmatrix(1, nbp, 1, 3);
identity_dmatrix(orien_next, 3); /* for setting the first bp */
zero_dvector(pos_next, 3);
/* For strand I */
t_asym1 = cmatrix(1, MAX_ATOM, 1, 4);
t_btype1 = cvector(1, MAX_ATOM);
t_bnum1 = lvector(1, MAX_ATOM);
t_xyz1 = dmatrix(1, MAX_ATOM, 1, 3);
/* For strand II */
t_asym2 = cmatrix(1, MAX_ATOM, 1, 4);
t_btype2 = cvector(1, MAX_ATOM);
t_bnum2 = lvector(1, MAX_ATOM);
t_xyz2 = dmatrix(1, MAX_ATOM, 1, 3);
orien = dmatrix(1, 3, 1, 3);
mst = dmatrix(1, 3, 1, 3);
pos = dvector(1, 3);
tmp_vec = dvector(1, 3);