-
Notifications
You must be signed in to change notification settings - Fork 3
/
chromosome3D.pl
2557 lines (2501 loc) · 130 KB
/
chromosome3D.pl
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
#!/usr/bin/perl -w
# version 1.2, Badri Adhikari, 2/18/2016
use strict;
use warnings;
use Carp;
use Cwd 'abs_path';
use File::Basename;
use Getopt::Long;
use Scalar::Util qw(looks_like_number);
# Location of CNSsuite
my $cns_suite = "/home/bap54/chr3D_projects/project01/programs/cns_solve_1.3";
my $cns_executable = "$cns_suite/intel-x86_64bit-linux/bin/cns_solve";
my $dg_sa_log = "/dev/null"; # replace with dgsa.log if space is NOT a concern
# Chromosome Model building parameters
my $KSCALING = 11;
my $ALPHA = 0.5;
my $SEPARATION = 5;
my $MODELCOUNT = 20;
# User inputs
my $help;
my $dir_out;
my $file_if;
GetOptions(
"h" => \$help,
"o=s" => \$dir_out,
"k=i" => \$KSCALING,
"a=s" => \$ALPHA,
"m=i" => \$MODELCOUNT,
"i=s" => \$file_if)
or confess "ERROR! Error in command line arguments!";
print_usage() if defined $help;
print_usage("Input IF matrix not found!") if not defined $file_if;
print_usage("Output directory not defined!") if not defined $dir_out;
print_usage("Input IF file $file_if does not exist!") if not -f $file_if;
$KSCALING = 11 if not defined $KSCALING;
$ALPHA = 0.5 if not defined $ALPHA;
$MODELCOUNT = 20 if not defined $MODELCOUNT;
mkdir $dir_out or confess "ERROR! Could not create output directory $dir_out!" if not -d $dir_out;
print_usage("Output directory $dir_out does not exist!") if not -d $dir_out;
print "Start Time : ".(localtime)." [$0]\n";
print "Input : $file_if\n";
print "Output Dir : $dir_out\n";
print "Scaling(K) : $KSCALING\n";
print "Alpha : $ALPHA\n";
print "Effective Conversion Equation is : D = $KSCALING/[(IF^$ALPHA)*(avg of IF^$ALPHA)]\n";
my $ID = basename($file_if, ".txt");
system_cmd("rm -f $dir_out/*");
system_cmd("cp $file_if $dir_out/") if not -f $ID;
chdir $dir_out or confess $!;
$file_if = $ID.".txt";
$dir_out = ".";
my $L = calc_len_IF($file_if);
print "L : $L\n";
# CNS Suite parameters
my $min_sep = $SEPARATION;
my $con_wt = 10;
my $model_count = $MODELCOUNT;
my $rep2 = 0.85;
my $atomselect = 2;
my $rep1 = 1.0;
my $mini = 15000;
my $model_info_log = "model_info.log";
my $mode = "trial";
my $DISTRELAX = 0.5;
# http://proteopedia.org/wiki/index.php/Standard_Residues and http://prody.csb.pitt.edu/manual/reference/atomic/flags.html
our %AA3TO1 = qw(ALA A ASN N CYS C GLN Q HIS H LEU L MET M PRO P THR T TYR Y ARG R ASP D GLU E GLY G ILE I LYS K PHE F SER S TRP W VAL V);
our %AA1TO3 = reverse %AA3TO1;
# Verify CNS Suite installation
confess "ERROR! Cannot find CNS suite folder at $cns_suite! Check CNS installation!" if not -d $cns_suite;
confess "ERROR! cns_solve_env.sh not found inside $cns_suite/! Check CNS installation!" if not -f "$cns_suite/cns_solve_env.sh";
confess "ERROR! CNS executable $cns_executable not found! Check CNS installation!" if not -f $cns_executable;
confess "ERROR! protein.param not found inside $cns_suite/libraries/toppar/! Check CNS installation!" if not -f "$cns_suite/libraries/toppar/protein.param";
# Generate restraints from IF matrix
IF2dist_new("$ID.txt", "$ID.dist", $KSCALING);
dist2rr("$ID.dist", "$ID.rr");
carr2tbl("$ID.rr", "contact.tbl");
print "Restraints : ".count_lines("contact.tbl")." lines in tbl file\n";
# Make Fasta file for CNS Suite input
my $REFSEQUENCE = "RSEDWQCPRTPYAASRDFDVKYVVPSFSAGGLVQAMVTYEGDRNESAVFVAIRNRLHVLGPDLKSVQSLATGPAGDPGCQTCAACGPGPHGPPGDTDTKVLVLDPALPALVSCGSSLQGRCFLHDLEPQGTAVHLAAPACLFSAHHNRPDDCPDCVASPLGTRVTVVEQGQASYFYVASSLDAAVAGSFSPRSVSIRRLKADASGFAPGFVALSVLPKHLVSYSIEYVHSFHTGAFVYFLTVQPASVTDDPSALHTRLARLSATEPELGDYRELVLDCRFAPKLVPRGSPEGGQPYPVLQVAHSAPVGAQLATELSIAEGQEVLFGVFVTGKDGGPGVGPNSVVCAFPIDLLDTLIDEGVERCCESPVHPGLRRGLDFFQSPSFCPNPPGLEALSPNTSCRHFPLLVSSSFSRVDLFNGLLGPVQVTALYVTRLDNVTVAHMGTMDGRILQVELVRSLNYLLYVSNFSLGDSGQPVQRDVSRLGDHLLFASGDQVFQVPIQGPGCRHFLTCGRCLRAWHFMGCGWCGNMCGQQKECPGSWQQDHCPPKLTEFHPHSGPLRGSTRLTLCGSNFYLHPSGLVPEGTHQVTVGQSPCRPLPKDSSKLRPVPRKDFVEEFECELEPLGTQAVGPTNVSLTVTNMPPGKHFRVDGTSVLRGFSFMETG";
my $sequence = substr $REFSEQUENCE, 0, $L;
my $file_seq = "$ID.fasta";
system_cmd("rm -f $file_seq");
print2file($file_seq, ">$ID");
print2file($file_seq, "$sequence");
print "\n";
print "(A) Build extended mtf and pdb..\n";
build_extended();
print "(B) Build models using CNS dgsa..\n";
build_models();
print "(C) Assess models..\n";
assess_dgsa();
print "\nFinished [$0]: ".(localtime)."\n";
sub IF2dist_new{
my $matrix = shift;
my $file_dist = shift;
my $a = shift;
system_cmd("rm -f $file_dist");
my %input = ();
open MATRIX, $matrix or confess $!;
my $i = 0;
while(<MATRIX>){
chomp $_;
$_ =~ s/^\s+//;
confess "??" if length($_) < 3;
my @R = split /\s+/, $_;
for(my $j = 0; $j <= $#R; $j++){
confess "ERROR! dist not defined!" if not defined $R[$j];
$input{$i+1}{$j+1} = $R[$j];
}
$i++;
}
close MATRIX;
my %output = ();
my $mean_sqrt = 0;
for(my $i = 1; $i <= $L; $i++){
for(my $j = 1; $j <= $L; $j++){
$output{$i}{$j} = $input{$i}{$j} ** $ALPHA;
$mean_sqrt += $output{$i}{$j};
}
}
# divide by mean
$mean_sqrt = $mean_sqrt/($L * $L);
for(my $i = 1; $i <= $L; $i++){
for(my $j = 1; $j <= $L; $j++){
$output{$i}{$j} = $output{$i}{$j}/$mean_sqrt;
}
}
# perform conversion
for(my $i = 1; $i <= $L; $i++){
for(my $j = 1; $j <= $L; $j++){
if ($output{$i}{$j} == 0){
$output{$i}{$j} = -1;
next;
}
$output{$i}{$j} = $a / $output{$i}{$j};
}
}
# write output
for(my $i = 1; $i <= $L; $i++){
for(my $j = 1; $j <= $L; $j++){
print2line($file_dist, sprintf "%.1f ", $output{$i}{$j});
}
print2file($file_dist, "");
}
}
sub calc_len_IF{
my $matrix = shift;
my $length;
open MATRIX, $matrix or confess $!;
while(<MATRIX>){
chomp $_;
$_ =~ s/^\s+//;
die "??" if length($_) < 2;
my @R = split /\s+/, $_;
$length = $#R + 1;
last;
}
close MATRIX;
confess ":(" if not defined $length;
return $length;
}
sub dist2rr{
my $matrix = shift;
my $rr = shift;
my $SEP = shift;
confess "NEED matrix and rr" if not ($matrix && $rr);
my %distances = ();
open MATRIX, $matrix or confess $!;
my $i = 0;
while(<MATRIX>){
chomp $_;
$_ =~ s/^\s+//;
die "??" if length($_) < 2;
my @R = split /\s+/, $_;
for(my $j = $i+1; $j <= $#R; $j++){
next if abs($j - $i) < $min_sep;
next if $R[$j] <= 0;
$distances{($i+1)." ".($j+1)} = $R[$j];
}
$i++;
}
close MATRIX;
system_cmd("rm -f $rr");
foreach (sort keys %distances){
print2file($rr, (sprintf "$_ %.2f %.2f 1.0", $distances{$_}, $distances{$_}));
}
}
sub add_connect_rows{
my $in_pdb = shift;
my $L = length(seq_chain($in_pdb));
for(my $i = 1; $i < $L; $i++){
print2file($in_pdb, sprintf "CONECT%5s%5s", $i, $i+1);
}
print2file($in_pdb, "END");
}
sub seq_chain{
my $chain = shift;
confess "ERROR! file $chain does not exist!" if not -f $chain;
my $seq = "";
open CHAIN, $chain or confess $!;
while(<CHAIN>){
next if $_ !~ m/^ATOM/;
next unless (parse_pdb_row($_,"aname") eq "CA");
confess "ERROR!: ".parse_pdb_row($_,"rname")." residue not defined! \nFile: $chain! \nLine : $_" if (not defined $AA3TO1{parse_pdb_row($_,"rname")});
my $res = $AA3TO1{parse_pdb_row($_,"rname")};
$seq .= $res;
}
close CHAIN;
confess "$chain has less than 1 residue!" if (length($seq) < 1);
return $seq;
}
sub build_extended{
confess "ERROR! expected fasta file not found in the extended directory!" if not -f $file_seq;
write_cns_seq($file_seq, "input.seq");
write_cns_generate_seq_file();
write_cns_generate_extended_file();
open JOB, ">job.sh" or confess "ERROR! Could not open job.sh $!";
print JOB "#!/bin/bash \n";
print JOB "# CNS-CONFIGURATION \n";
print JOB "source $cns_suite/cns_solve_env.sh \n";
print JOB "export KMP_AFFINITY=none \n";
print JOB "$cns_executable < gseq.inp > gseq.log \n";
print JOB "$cns_executable < extn.inp > extn.log \n";
close JOB;
system_cmd("chmod +x job.sh");
system_cmd("./job.sh", "job.log");
confess "FAILED! extended.mtf not found!" if not -f "extended.pdb";
system_cmd("rm -f gseq.log");
system_cmd("rm -f extn.log");
}
sub build_models{
# prepare CNS task files
system_cmd("rm -f iam.*");
write_cns_dgsa_file();
open JOB, ">job.sh" or confess "ERROR! Could not open job.sh $!";
print JOB "#!/bin/bash \n";
print JOB "echo \"starting cns..\" \n";
print JOB "touch iam.running \n";
print JOB "# CNS-CONFIGURATION \n";
print JOB "source $cns_suite/cns_solve_env.sh \n";
print JOB "export KMP_AFFINITY=none \n";
print JOB "$cns_suite/intel-x86_64bit-linux/bin/cns_solve < dgsa.inp > $dg_sa_log \n";
print JOB "if [ -f \"${ID}_${model_count}.pdb\" ]; then \n";
print JOB " rm iam.running \n";
print JOB " echo \"trial structures written.\" \n";
print JOB " rm *embed* \n";
print JOB " exit \n";
print JOB "fi \n";
print JOB "if [ -f \"${ID}a_${model_count}.pdb\" ]; then \n";
print JOB " rm iam.running \n";
print JOB " echo \"accepted structures written.\" \n";
print JOB " rm *embed* \n";
print JOB " exit \n";
print JOB "fi \n";
if ($dg_sa_log ne "/dev/null"){
print JOB "tail -n 30 $dg_sa_log \n";
}
print JOB "echo \"ERROR! Final structures not found!\" \n";
print JOB "echo \"CNS FAILED!\" \n";
print JOB "mv iam.running iam.failed \n";
close JOB;
print "Starting job [$dir_out/job.sh > job.log]\n";
system_cmd("chmod +x job.sh");
system_cmd("./job.sh > job.log");
confess "ERROR! Something went wrong while running CNS! Check job.log and dgsa.log!" if -f "iam.failed";
}
sub system_cmd{
my $command = shift;
my $log = shift;
confess "EXECUTE [$command]?\n" if (length($command) < 5 and $command =~ m/^rm/);
if(defined $log){
system("$command &> $log");
}
else{
system($command);
}
if($? != 0){
my $exit_code = $? >> 8;
confess "ERROR!! Could not execute [$command]! \nError message: [$!]";
}
}
sub count_lines{
my $file = shift;
my $lines = 0;
return 0 if not -f $file;
open FILE, $file or confess "ERROR! Could not open $file! $!";
while (<FILE>){
chomp $_;
$_ =~ tr/\r//d; # chomp does not remove \r
next if not defined $_;
next if length($_) < 1;
$lines ++;
}
close FILE;
return $lines;
}
sub print2file{
my $file = shift;
my $message = shift;
my $newline = shift;
$newline = "\n" if not defined $newline;
if (-f $file){
open FILE, ">>$file" or confess $!;
print FILE $message.$newline;
close FILE;
}
else{
open FILE, ">$file" or confess $!;
print FILE $message.$newline;
close FILE;
}
}
sub carr2tbl{
my $file_rr = shift;
my $file_tbl = shift;
confess ":(" if not -f $file_rr;
open RR, $file_rr or confess $!;
while(<RR>){
next unless ($_ =~ /[0-9]/);
$_ =~ s/^\s+//;
next unless ($_ =~ /^[0-9]/);
my @C = split(/\s+/, $_);
confess "ERROR! Expecting a pair in row [".$_."]!\n" if (not defined $C[0] || not defined $C[1]);
confess "ERROR! Confidence column not defined in row [".$_."] in file $file_rr!\n" if not defined $C[4];
my $distance = sprintf("%.2f", ($C[3]+$C[2])/2);
my $negdev = sprintf("%.2f", ($C[3]-$C[2])/2);
my $posdev = $negdev;
if ($C[2] eq "0"){
$distance = sprintf("%.2f", 3.6);
$negdev = sprintf("%.2f", 0.1);
$posdev = sprintf("%.2f", ($C[3] - 3.6));
}
print2file($file_tbl, (sprintf "assign45 (resid %3d and name %2s) (resid %3d and name %2s) %.2f %.2f %.2f", $C[0], "ca", $C[1], "ca", $distance, $negdev, $posdev));
}
}
sub print2line{
my $file = shift;
my $message = shift;
if (-f $file){
open FILE, ">>$file" or confess $!;
print FILE $message;
close FILE;
}
else{
open FILE, ">$file" or confess $!;
print FILE $message;
close FILE;
}
}
sub tbl2rows_hash{
my $file_tbl = shift;
confess "ERROR! tbl file $file_tbl does not exist!" if not -f $file_tbl;
my %noe = ();
open NOETBL, $file_tbl or confess $!;
while (<NOETBL>){
$_ =~ s/^\s+//;
next if $_ !~ m/^assign/;
$_ =~ s/^\s+//;
$_ =~ s/\(/ /g;
$_ =~ s/\)/ /g;
$noe{$_} = 1;
}
close NOETBL;
confess "$file_tbl seems empty!" if not %noe;
return %noe;
}
sub coverage_tbl{
my $file_fasta = shift;
my $file_tbl = shift;
my $flag_dihe = shift;
confess "ERROR! fasta file $file_fasta does not exist!" if not -f $file_fasta;
confess "ERROR! tbl file $file_tbl does not exist!" if not -f $file_tbl;
$flag_dihe = 0 if not defined $flag_dihe;
my $seq = seq_fasta($file_fasta);
my $L = length $seq;
my $cov = $seq;
$cov =~ s/[A-Z]/-/g;
my %noe = tbl2rows_hash($file_tbl);
foreach (keys %noe){
#assign (resid 123 and name CA) (resid 58 and name CA) 3.60 0.10 3.40
my @C = split /\s+/, $_;
my $r1 = $C[2]; my $r2 = $C[7];
# the case when "ca or cb" restraints are provided
#assign ((resid 123 and name ca) or (resid 123 and name cb)) ((resid 58 and name ca) or (resid 58 and name cb)) 3.60 0.10 3.40
$r2 = $C[13] if $C[6] eq "or";
$r2 = $C[17] if $flag_dihe;
my $c1 = substr $cov, ($r1 - 1), 1;
my $c2 = substr $cov, ($r2 - 1), 1;
if ($c1 eq "-" ){
$c1 = 1;
}
elsif ($c1 eq "*" ){
$c1 = "*";
}
else{
$c1++;
$c1 = "*" if ($c1 > 9);
}
if ($c2 eq "-" ){
$c2 = 1;
}
elsif ($c2 eq "*" ){
$c2 = "*";
}
else{
$c2++;
$c2 = "*" if ($c2 > 9);
}
substr $cov, ($r1 - 1), 1, $c1;
substr $cov, ($r2 - 1), 1, $c2;
}
my $cov2 = $cov;
$cov2 =~ s/-//g;
return sprintf "$cov [%12s : %3s restraints touching %s residues]", basename($file_tbl), (scalar keys %noe), length($cov2);
}
sub count_satisfied_tbl_rows{
my $file_pdb = shift;
my $file_tbl = shift;
my $type = shift;
confess "ERROR! file pdb $file_pdb does not exist!" if not -f $file_pdb;
confess "ERROR! file tbl $file_tbl does not exist!" if not -f $file_tbl;
confess "ERROR! Invalid type!" if not ($type eq "noe" or $type eq "dihedral");
my $count = 0;
my $total = 0;
my %log_rows = ();
my %tbl_hash = ssnoe_tbl_min_pdb_dist($file_tbl, $file_pdb);
foreach (sort keys %tbl_hash){
my $viol_flag = 1;
my $distance = $tbl_hash{$_}{"distance"};
my @D = split /\s+/, $distance;
my $pdb_distance = $tbl_hash{$_}{"pdb_distance"};
my $deviation = $pdb_distance - ( $D[0] + $D[2] );
if ($pdb_distance < ( $D[0] + $D[2] + $DISTRELAX) ){
$count ++;
$viol_flag = 0;
$deviation = 0.0;
}
if ($pdb_distance < ( $D[0] - $D[1] - $DISTRELAX) ){
$count--;
$viol_flag = 1;
$deviation = -($D[0] - $D[1] - $pdb_distance);
}
$log_rows{(sprintf "%3s\t%.2f\t%.2f # $_", $viol_flag, $deviation, $pdb_distance)} = $viol_flag;
$total++;
}
my $file_viol = "".basename($file_tbl,".tbl")."_violation.txt";
print2file($file_viol, "#NOE violation check; $file_pdb against $file_tbl");
print2file($file_viol, "#violation-flag, deviation, actual-measurement, Input-NOE-restraint");
foreach (sort {$log_rows{$b} <=> $log_rows{$a}} keys %log_rows){
print2file($file_viol, $_);
}
return $count."/".$total;
}
sub ssnoe_tbl_min_pdb_dist{
my $file_tbl = shift;
my $file_pdb = shift;
confess ":(" if not -f $file_tbl;
confess ":(" if not -f $file_pdb;
my %noe_hash = ();
open NOETBL, $file_tbl or confess $!;
while (<NOETBL>){
chomp $_;
$_ =~ s/^\s+//;
$_ =~ s/\)/ /g;
$_ =~ s/\(/ /g;
confess "$_" if $_ !~ m/^assign/;
my @C = split /\s+/, $_;
if ($C[6] eq "or" and $C[17] eq "or"){
$noe_hash{$_}{"left"} = $C[2]." ".$C[5]." ".$C[8]." ".$C[11];
$noe_hash{$_}{"right"} = $C[13]." ".$C[16]." ".$C[19]." ".$C[22];
$noe_hash{$_}{"distance"} = $C[23]." ".$C[24]." ".$C[25];
}
elsif ($C[6] eq "or" and $C[17] ne "or"){
$noe_hash{$_}{"left"} = $C[2]." ".$C[5]." ".$C[8]." ".$C[11];
$noe_hash{$_}{"right"} = $C[13]." ".$C[16];
$noe_hash{$_}{"distance"} = $C[17]." ".$C[18]." ".$C[19];
}
elsif ($C[6] ne "or" and $C[11] eq "or"){
$noe_hash{$_}{"left"} = $C[2]." ".$C[5];
$noe_hash{$_}{"right"} = $C[7]." ".$C[10]." ".$C[13]." ".$C[16];
$noe_hash{$_}{"distance"} = $C[17]." ".$C[18]." ".$C[19];
}
else{
$noe_hash{$_}{"left"} = $C[2]." ".$C[5];
$noe_hash{$_}{"right"} = $C[7]." ".$C[10];
$noe_hash{$_}{"distance"} = $C[11]." ".$C[12]." ".$C[13];
}
}
close NOETBL;
confess "$file_tbl seems empty!" if not %noe_hash;
my %xyzPDB = xyz_pdb($file_pdb, "all");
foreach (sort keys %noe_hash){
my $left = $noe_hash{$_}{"left"};
my $right = $noe_hash{$_}{"right"};
my $distance = $noe_hash{$_}{"distance"};
my @L = split /\s+/, $left;
my @R = split /\s+/, $right;
my @D = split /\s+/, $distance;
my %left_list = ();
my %right_list = ();
for(my $i = 0; $i <= $#L; $i = $i+2){
$left_list{$L[$i]." ".$L[$i+1]} = 1;
}
for(my $i = 0; $i <= $#R; $i = $i+2){
$right_list{$R[$i]." ".$R[$i+1]} = 1;
}
my $distance_pdb = 1000.0;
foreach my $le (keys %left_list){
foreach my $ri (keys %right_list){
my @L = split /\s+/, $le;
my @R = split /\s+/, $ri;
confess "$file_pdb does not have ".$L[0]." ".uc($L[1])."\n" if not defined $xyzPDB{$L[0]." ".uc($L[1])};
confess "$file_pdb does not have ".$R[0]." ".uc($R[1])."\n" if not defined $xyzPDB{$R[0]." ".uc($R[1])};
my $d = calc_dist($xyzPDB{$L[0]." ".uc($L[1])}, $xyzPDB{$R[0]." ".uc($R[1])});
$distance_pdb = $d if $d < $distance_pdb;
}
}
$noe_hash{$_}{"pdb_distance"} = $distance_pdb;
}
return %noe_hash;
}
sub noe_tbl_violation_coverage{
my $file_pdb = shift;
my $file_tbl = shift;
confess "ERROR! file pdb $file_pdb does not exist!" if not -f $file_pdb;
confess "ERROR! file tbl $file_tbl does not exist!" if not -f $file_tbl;
my $cov = seq_chain($file_pdb);
$cov =~ s/[A-Z]/-/g;
my %tbl_hash = ssnoe_tbl_min_pdb_dist($file_tbl, $file_pdb);
my %xyz = xyz_pdb($file_pdb, "all");
foreach (sort keys %tbl_hash){
my $left = $tbl_hash{$_}{"left"};
my $right = $tbl_hash{$_}{"right"};
my $distance = $tbl_hash{$_}{"distance"};
my @L = split /\s+/, $left;
my @R = split /\s+/, $right;
my @D = split /\s+/, $distance;
my $pdb_distance = $tbl_hash{$_}{"pdb_distance"};
substr $cov, $L[0] - 1, 1, "x" if $pdb_distance > $D[0] + $D[2] + 0.2;
substr $cov, $R[0] - 1, 1, "x" if $pdb_distance > $D[0] + $D[2] + 0.2;
substr $cov, $L[0] - 1, 1, "x" if $pdb_distance < $D[0] - $D[1] - 0.2;
substr $cov, $R[0] - 1, 1, "x" if $pdb_distance < $D[0] - $D[1] - 0.2;
}
return $cov;
}
sub sum_noe_dev{
my $file_pdb = shift;
my $file_tbl = shift;
confess "ERROR! file pdb $file_pdb does not exist!" if not -f $file_pdb;
confess "ERROR! file tbl $file_tbl does not exist!" if not -f $file_tbl;
my $sum_dev = 0.0;
my %tbl_hash = ssnoe_tbl_min_pdb_dist($file_tbl, $file_pdb);
foreach (sort keys %tbl_hash){
my $viol_flag = 1;
my @D = split /\s+/, $tbl_hash{$_}{"distance"};
my $pdb_distance = $tbl_hash{$_}{"pdb_distance"};
if ($pdb_distance > ( $D[0] + $D[2] + 0.2) ){
$sum_dev += $pdb_distance - ( $D[0] + $D[2] );
}
if ($pdb_distance < ( $D[0] - $D[1] - 0.2) ){
$sum_dev += ( $D[0] - $D[1] ) - $pdb_distance;
}
}
return sprintf "%.2f", $sum_dev;
}
sub get_cns_energy{
my $cns_pdb = shift;
my $energy_term = shift; # "overall", "vdw", "bon", "noe"
confess "ERROR! file $cns_pdb does not exist!" if not -f $cns_pdb;
confess "ERROR! energy term must be overall vdw bon or noe" if not ($energy_term eq "overall" or $energy_term eq "bon" or $energy_term eq "vdw" or $energy_term eq "noe");
my $value = "X";
open CHAIN, $cns_pdb or confess $!;
while(<CHAIN>){
chomp $_;
next if $_ !~ m/^REMARK\ $energy_term/;
$_ =~ s/\s+//g;
my @C = split /=/, $_;
$value = $C[1];
}
close CHAIN;
return int($value);
}
sub load_pdb{
my $dir_chains = shift;
confess ":( directory $dir_chains does not exist!" if not -d $dir_chains;
my @pdb_list = <$dir_chains/*.pdb>;
if(not (@pdb_list)){
@pdb_list = <$dir_chains/*.ent>;
}
confess "ERROR! Directory $dir_chains has no pdb files!\n" unless(@pdb_list);
return @pdb_list;
}
sub pdb2rnum_rname{
my $chain = shift;
confess "ERROR! file $chain does not exist!" if not -f $chain;
my %rnum_rname = ();
open CHAIN, $chain or confess $!;
while(<CHAIN>){
next if $_ !~ m/^ATOM/;
$rnum_rname{parse_pdb_row($_,"rnum")} = parse_pdb_row($_,"rname");
}
close CHAIN;
confess ":(" if not scalar keys %rnum_rname;
return %rnum_rname;
}
sub xyz_pdb{
my $chain = shift;
my $atom_selection = shift; # ca or cb or all
$atom_selection = uc($atom_selection);
confess "ERROR! file $chain does not exist!" if not -f $chain;
confess "ERROR! Selection must be ca or cb or all" if not ($atom_selection eq "CA" or $atom_selection eq "ALL" or $atom_selection eq "CB");
my %xyz_pdb = ();
open CHAIN, $chain or confess $!;
while(<CHAIN>){
next if $_ !~ m/^ATOM/;
$xyz_pdb{"".parse_pdb_row($_,"rnum")." ".parse_pdb_row($_,"aname")} = "".parse_pdb_row($_,"x")." ".parse_pdb_row($_,"y")." ".parse_pdb_row($_,"z");
}
close CHAIN;
confess "ERROR!: xyz_pdb is empty\n" if (not scalar keys %xyz_pdb);
return %xyz_pdb if $atom_selection eq "ALL";
my %rnum_rname = pdb2rnum_rname($chain);
my %selected_xyz = ();
foreach (sort keys %xyz_pdb){
my @C = split /\s+/, $_;
my $this_atom = $atom_selection;
$this_atom = "CA" if ($atom_selection eq "CB" and $rnum_rname{$C[0]} eq "GLY");
next if $C[1] ne $this_atom;
$selected_xyz{$C[0]} = $xyz_pdb{$_};
}
confess ":(" if not scalar keys %selected_xyz;
return %selected_xyz;
}
sub parse_pdb_row{
my $row = shift;
my $param = shift;
my $result;
$result = substr($row,6,5) if ($param eq "anum");
$result = substr($row,12,4) if ($param eq "aname");
$result = substr($row,16,1) if ($param eq "altloc");
$result = substr($row,17,3) if ($param eq "rname");
$result = substr($row,22,5) if ($param eq "rnum");
$result = substr($row,26,1) if ($param eq "insertion");
$result = substr($row,21,1) if ($param eq "chain");
$result = substr($row,30,8) if ($param eq "x");
$result = substr($row,38,8) if ($param eq "y");
$result = substr($row,46,8) if ($param eq "z");
confess "Invalid row[$row] or parameter[$param]" if (not defined $result);
$result =~ s/\s+//g;
return $result;
}
sub clash_count{
my $file_pdb = shift;
my $threshold = shift;
confess "ERROR! pdb file $file_pdb not defined!" if not -f $file_pdb;
confess "ERROR! threshold not defined!" if not defined $threshold;
my $count = 0;
my %ca_xyz = xyz_pdb($file_pdb, "ca");
foreach my $r1 (sort keys %ca_xyz){
my @R1 = split /\s+/, $ca_xyz{$r1};
my $x1 = $R1[0]; my $y1 = $R1[1]; my $z1 = $R1[2];
foreach my $r2 (sort keys %ca_xyz){
next if $r1 >= $r2;
my @R2 = split /\s+/, $ca_xyz{$r2};
my $x2 = $R2[0]; my $y2 = $R2[1]; my $z2 = $R2[2];
my $d = sqrt(($x1-$x2)**2+($y1-$y2)**2+($z1-$z2)**2);
if ($d <= $threshold){
$count++;
}
}
}
return $count;
}
sub calc_dist{
my $x1y1z1 = shift;
my $x2y2z2 = shift;
confess "ERROR! x1y1z1 not defined!" if !$x1y1z1;
confess "ERROR! x2y2z2 not defined!" if !$x2y2z2;
my @row1 = split(/\s+/, $x1y1z1);
my $x1 = $row1[0]; my $y1 = $row1[1]; my $z1 = $row1[2];
confess "ERROR! One of the xyz in $x1y1z1 is not a number!" if (not looks_like_number($x1) or not looks_like_number($y1) or not looks_like_number($z1));
my @row2 = split(/\s+/, $x2y2z2);
my $x2 = $row2[0]; my $y2 = $row2[1]; my $z2 = $row2[2];
confess "ERROR! One of the xyz in $x2y2z2 is not a number!" if (not looks_like_number($x2) or not looks_like_number($y2) or not looks_like_number($z2));
my $d = sprintf "%.3f", sqrt(($x1-$x2)**2+($y1-$y2)**2+($z1-$z2)**2);
return $d;
}
sub seq_fasta{
my $file_fasta = shift;
confess "ERROR! Fasta file $file_fasta does not exist!" if not -f $file_fasta;
my $seq = "";
open FASTA, $file_fasta or confess $!;
while (<FASTA>){
next if (substr($_,0,1) eq ">");
chomp $_;
$_ =~ tr/\r//d; # chomp does not remove \r
$seq .= $_;
}
close FASTA;
return $seq;
}
sub write_cns_seq{
my $file_fasta = shift;
my $file_cns_seq = shift;
confess "ERROR! Fasta file $file_fasta does not exist!" if not -f $file_fasta;
confess "ERROR! Output not defined!" if not defined $file_cns_seq;
my @seq = split //, seq_fasta($file_fasta);
my $three_letter_seq;
foreach (@seq) {
$three_letter_seq .= $AA1TO3{$_}." ";
}
system_cmd("rm -f $file_cns_seq");
while($three_letter_seq){
if(length ($three_letter_seq) <= 64 ){
print2file($file_cns_seq, $three_letter_seq);
$three_letter_seq = ();
}
else{
print2file($file_cns_seq, substr($three_letter_seq, 0, 64));
$three_letter_seq = substr($three_letter_seq, 64);
}
}
}
sub assess_dgsa{
my @seq_files = <./*.fasta>;
confess ":( fasta not found!" if not defined $file_seq;
my $ID = basename($file_seq, ".fasta");
my @pdbList = load_pdb($dir_out);
# also verify if CNS actually accepted all the distance restraints provided
my $search_string = "N1";
if(not -f $dg_sa_log){
# PROBABLY THE SERVER DOES NOT HAVE SPACE!
system_cmd("touch dgsa.log.noverification");
}
else{
my $result = `grep NOEPRI $dg_sa_log | grep $search_string | head -n 1`;
my @C = split /\s+/, $result;
my $count = $C[($#C)-1];
if ($count != count_lines("contact.tbl")){
system_cmd("touch assess.failed");
confess ":( CNS did not accept all restraints of contact.tlb! Something wrong somewhere! Only $count accepted";
}
}
# remove "trial" structure of corresponding "accepted" structure because they are same
for(my $i = 0; $i <= 1000; $i++){
next if not -f "${ID}a_$i.pdb";
print "\ndeleting ${ID}_$i.pdb because ${ID}a_$i.pdb exists!";
system_cmd("rm ./${ID}_$i.pdb");
}
my %energyNoe = ();
foreach my $pdb (@pdbList) {
next if $pdb =~ m/sub_embed/;
next if $pdb =~ m/extended/;
$energyNoe{$pdb} = get_cns_energy($pdb, "noe");
}
my $bestPdb = (sort {$energyNoe{$a} <=> $energyNoe{$b}} keys %energyNoe)[0];
print "\n";
print "NOE_SATISFIED(±${DISTRELAX}A) SUM_OF_DEVIATIONS>= 0.2 PDB\n";
foreach my $pdb (sort {$energyNoe{$b} <=> $energyNoe{$a}} keys %energyNoe){
my ($n1, $s1);
$n1 = count_satisfied_tbl_rows($pdb, "contact.tbl", "noe");
$s1 = sum_noe_dev($pdb, "contact.tbl");
printf "%-9s %-9s %-25s\n", $n1, $s1, basename($pdb, ".pdb");
}
print "\n";
print "removing non-CA ATOM rows and backing up REMARK rows..\n";
foreach my $pdb (sort {$energyNoe{$b} <=> $energyNoe{$a}} keys %energyNoe){
system_cmd("rm -f ca_filtered.pdb");
filter_nonCA($pdb, "ca_filtered.pdb", $model_info_log);
reindex_chain("ca_filtered.pdb", 1, $pdb); # to reorder the atom numbers as well
system_cmd("rm -f ca_filtered.pdb");
system_cmd("sed -i \"s/END//g\" $pdb");
add_connect_rows($pdb);
}
print "\n";
my $i = 1;
foreach( sort {$energyNoe{$a} <=> $energyNoe{$b}} keys %energyNoe){
print "model$i.pdb <= $_\n";
system_cmd("mv $_ ${ID}_model$i.pdb");
$i++;
last if $i > 5;
}
}
sub reindex_chain{
my $file_pdb = shift;
my $index = shift;
my $out_pdb = shift;
confess "ERROR! file $file_pdb does not exist!" if not -f $file_pdb;
confess "ERROR! index $index is invalied!" if not defined $index;
my $res_counter = $index - 1;
my $atom_counter = 0;
my $prev_res_num = "XX";
open OUTPDB, ">$out_pdb" or confess $!;
open PDBFILE, $file_pdb or confess $!;
foreach (<PDBFILE>) {
last if $_ =~ /^TER/;
last if $_ =~ /^ENDMDL/;
next if $_ !~ m/^ATOM/;
next if not ((parse_pdb_row($_,"altloc") eq "") or (parse_pdb_row($_,"altloc") eq "A"));
next if not defined $AA3TO1{parse_pdb_row($_,"rname")};
my $this_rnum = parse_pdb_row($_,"rnum");
if ($prev_res_num ne $this_rnum) {
$prev_res_num = $this_rnum;
$res_counter++;
}
$atom_counter++;
my $rnum_string = sprintf("%4s", $res_counter);
my $anum_string = sprintf("%5s", $atom_counter);
my $row = substr($_,0,6).$anum_string.substr($_,11,5)." ".substr($_,17,3)." "." ".$rnum_string." ".substr($_,27);
print OUTPDB $row;
}
close PDBFILE;
print OUTPDB "END\n";
close OUTPDB;
}
sub filter_nonCA{
my $in_pdb = shift;
my $out_pdb = shift;
my $log_file = shift;
confess "ERROR! file does not exist!" if not -f $in_pdb;
print2line($log_file, $in_pdb);
open FILEPDB, $in_pdb or confess "ERROR! Could not open $in_pdb! $!";
while (<FILEPDB>){
my $r = $_;
print2line($log_file, $r) if ($r =~ /^REMARK/);
next if $r !~ /^ATOM/;
next if ($r =~ /^ATOM/ && $r !~ /CA/);
print2line($out_pdb, $r);
}
close FILEPDB;
print2line($log_file, "");
}
sub write_cns_dgsa_file{
print2file("dgsa.inp", "{+ file: dgsa.inp +}");
print2file("dgsa.inp", "{+ directory: nmr_calc +}");
print2file("dgsa.inp", "{+ description: distance geometry, full or substructure, with ");
print2file("dgsa.inp", " simulated annealing regularization starting from ");
print2file("dgsa.inp", " extended strand or pre-folded structures. +}");
print2file("dgsa.inp", "{+ authors: Gregory Warren, Michael Nilges, John Kuszewski, ");
print2file("dgsa.inp", " Marius Clore and Axel Brunger +}");
print2file("dgsa.inp", "{+ copyright: Yale University +}");
print2file("dgsa.inp", "{+ reference: Clore GM, Gronenborn AM, Tjandra N, Direct structure refinement ");
print2file("dgsa.inp", " against residual dipolar couplings in the presence of rhombicity");
print2file("dgsa.inp", " of unknown magnitude., J. Magn. Reson., 131, In press, (1998) +}");
print2file("dgsa.inp", "{+ reference: Clore GM, Gronenborn AM, Bax A, A robust method for determining ");
print2file("dgsa.inp", " the magnitude of the fully asymmetric alignment tensor of");
print2file("dgsa.inp", " oriented macromolecules in the absence of structural");
print2file("dgsa.inp", " information., J. Magn. Reson., In press (1998) +}");
print2file("dgsa.inp", "{+ reference: Garrett DS, Kuszewski J, Hancock TJ, Lodi PJ, Vuister GW,");
print2file("dgsa.inp", " Gronenborn AM, Clore GM, The impact of direct refinement against ");
print2file("dgsa.inp", " three-bond HN-C alpha H coupling constants on protein structure");
print2file("dgsa.inp", " determination by NMR., J. Magn. Reson. Ser. B, 104(1), ");
print2file("dgsa.inp", " 99-103, (1994) May +}");
print2file("dgsa.inp", "{+ reference: Kuszewski J, Nilges M, Brunger AT, Sampling and efficiency ");
print2file("dgsa.inp", " of metric matrix distance geometry: A novel partial metrization ");
print2file("dgsa.inp", " algorithm. J. Biomol. NMR 2, 33-56, (1992). +} ");
print2file("dgsa.inp", "{+ reference: Kuszewski J, Qin J, Gronenborn AM, Clore GM, The impact of direct");
print2file("dgsa.inp", " refinement against 13C alpha and 13C beta chemical shifts on ");
print2file("dgsa.inp", " protein structure determination by NMR., J. Magn. Reson. Ser. B,");
print2file("dgsa.inp", " 106(1), 92-6, (1995) Jan +}");
print2file("dgsa.inp", "{+ reference: Kuszewski J, Gronenborn AM, Clore GM, The impact of direct");
print2file("dgsa.inp", " refinement against proton chemical shifts on protein structure ");
print2file("dgsa.inp", " determination by NMR., J. Magn. Reson. Ser. B, 107(3), 293-7, ");
print2file("dgsa.inp", " (1995) Jun +}");
print2file("dgsa.inp", "{+ reference: Kuszewski J, Gronenborn AM, Clore GM, A potential involving ");
print2file("dgsa.inp", " multiple proton chemical-shift restraints for ");
print2file("dgsa.inp", " nonstereospecifically assigned methyl and methylene protons.");
print2file("dgsa.inp", " J. Magn. Reson. Ser. B, 112(1), 79-81, (1996) Jul. +}");
print2file("dgsa.inp", "{+ reference: Nilges M, Clore GM, Gronenborn AM, Determination of ");
print2file("dgsa.inp", " three-dimensional structures of proteins from interproton ");
print2file("dgsa.inp", " distance data by hybrid distance geometry-dynamical simulated ");
print2file("dgsa.inp", " annealing calculations. FEBS Lett. 229, 317-324 (1988). +}");
print2file("dgsa.inp", "{+ reference: Nilges M, Clore GM, Gronenborn AM, Determination of ");
print2file("dgsa.inp", " three-dimensional structures of proteins from interproton ");
print2file("dgsa.inp", " distance data by dynamical simulated annealing from a random ");
print2file("dgsa.inp", " array of atoms. FEBS LEtt. 239, 129-136 (1988). +}");
print2file("dgsa.inp", "{+ reference: Nilges M, Kuszewski J, Brunger AT, In: Computational Aspects ");
print2file("dgsa.inp", " of the Study of Biological Macromolecules by NMR. ");
print2file("dgsa.inp", " (J.C. Hoch, ed.), New York: Plenum Press, (1991). +}");
print2file("dgsa.inp", "{+ reference: Tjandra N, Garrett DS, Gronenborn AM, Bax A, Clore GM, Defining");
print2file("dgsa.inp", " long range order in NMR structure determination from the ");
print2file("dgsa.inp", " dependence of heteronuclear relaxation times on rotational ");
print2file("dgsa.inp", " diffusion anisotropy. Nature Struct. Biol., 4(6), 443-9,");
print2file("dgsa.inp", " (1997) June +}");
print2file("dgsa.inp", "{+ reference: Tjandra N, Omichinski JG, Gronenborn AM, Clore GM, Bax A, Use of");
print2file("dgsa.inp", " dipolar 1H-15N and 1H-13C couplings in the structure");
print2file("dgsa.inp", " determination of magnetically oriented macromolecules in");
print2file("dgsa.inp", " solution. Nature Struct. Biol., 4(9), 732-8, (1997) Sept +} ");
print2file("dgsa.inp", " ");
print2file("dgsa.inp", "{- Guidelines for using this file:");
print2file("dgsa.inp", " - all strings must be quoted by double-quotes");
print2file("dgsa.inp", " - logical variables (true/false) are not quoted");
print2file("dgsa.inp", " - do not remove any evaluate statements from the file -}");
print2file("dgsa.inp", "{- begin block parameter definition -} define(");
print2file("dgsa.inp", "{======================= molecular structure =========================}");
print2file("dgsa.inp", "{* parameter file(s) *}");
# CNS_TOPPAR:protein-allhdg5-4.param
print2file("dgsa.inp", "{===>} par.1=\"CNS_TOPPAR:protein.param\";");
print2file("dgsa.inp", "{===>} par.2=\"\";");
print2file("dgsa.inp", "{===>} par.3=\"\";");
print2file("dgsa.inp", "{===>} par.4=\"\";");
print2file("dgsa.inp", "{===>} par.5=\"\";");
print2file("dgsa.inp", "{* structure file(s) *}");
print2file("dgsa.inp", "{===>} struct.1=\"extended.mtf\";");
print2file("dgsa.inp", "{===>} struct.2=\"\";");
print2file("dgsa.inp", "{===>} struct.3=\"\";");
print2file("dgsa.inp", "{===>} struct.4=\"\";");
print2file("dgsa.inp", "{===>} struct.5=\"\";");
print2file("dgsa.inp", "{* input coordinate file(s) *}");
print2file("dgsa.inp", "{===>} pdb.in.file.1=\"extended.pdb\";");
print2file("dgsa.inp", "{===>} pdb.in.file.2=\"\";");
print2file("dgsa.inp", "{===>} pdb.in.file.3=\"\";");
print2file("dgsa.inp", "{========================== atom selection ===========================}");
print2file("dgsa.inp", "{* input \"backbone\" selection criteria for average structure generation *}");
print2file("dgsa.inp", "{* for protein (name n or name ca or name c)");
print2file("dgsa.inp", " for nucleic acid (name O5' or name C5' or name C4' or name C3' ");
print2file("dgsa.inp", " or name O3' or name P) *}");
print2file("dgsa.inp", "{===>} pdb.atom.select=(name n or name ca or name c);");
print2file("dgsa.inp", "{======================= refinement parameters ========================}");
print2file("dgsa.inp", "{* distance geometry *}");
print2file("dgsa.inp", "{+ choice: true false +}");
print2file("dgsa.inp", "{===>} flg.dg.flag=true;");
print2file("dgsa.inp", "{* distance geometry/simualted annealing regularization (DGSA) *}");
print2file("dgsa.inp", "{+ choice: true false +}");
print2file("dgsa.inp", "{===>} flg.dgsa.flag=true;");
print2file("dgsa.inp", "{* if only regularizing coordinate files (no DG) then ");
print2file("dgsa.inp", " enter the number of coordinate files to be regularized (DGSA) *}");
print2file("dgsa.inp", "{===>} pdb.dg.count=$model_count;");
print2file("dgsa.inp", "{* seed for random number generator *}");
print2file("dgsa.inp", "{* change to get different initial velocities *}");
print2file("dgsa.inp", "{===>} md.seed=82364;");
print2file("dgsa.inp", "{* select whether the number of structures will be either trial or ");
print2file("dgsa.inp", " accepted structures and whether to print only the trial, accepted, ");
print2file("dgsa.inp", " both sets of structures. The printing format is as follows:");
print2file("dgsa.inp", " trial = pdb.out.name + _#.pdb , accepted = pdb.out.name + a_#.pdb *} ");
print2file("dgsa.inp", "{* are the number of structures to be trials or accepted? *}");
print2file("dgsa.inp", "{+ choice: \"trial\" \"accept\" +}");
print2file("dgsa.inp", "{===>} flg.trial.struc=\"$mode\";");
print2file("dgsa.inp", "{* number of trial or accepted structures *}");
print2file("dgsa.inp", "{===>} pdb.end.count=$model_count;");
print2file("dgsa.inp", "{* print accepted structures *}");
print2file("dgsa.inp", "{+ choice: true false +}");
print2file("dgsa.inp", "{===>} flg.print.accept=true;");
print2file("dgsa.inp", "{* print trial structures *}");
print2file("dgsa.inp", "{+ choice: true false +}");
print2file("dgsa.inp", "{===>} flg.print.trial=true;");
print2file("dgsa.inp", "{* calculate an average structure for either the trial or ");
print2file("dgsa.inp", " accepted structure. If calculate accepted average is false then ");
print2file("dgsa.inp", " an average for the trial structures will be calculated. *}");
print2file("dgsa.inp", "{* calculate an average structure? *}");
print2file("dgsa.inp", "{+ choice: true false +}");