EntDetect 1.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. EntDetect/Jwalk/GridTools.py +567 -0
  2. EntDetect/Jwalk/PDBTools.py +532 -0
  3. EntDetect/Jwalk/SASDTools.py +543 -0
  4. EntDetect/Jwalk/SurfaceTools.py +150 -0
  5. EntDetect/Jwalk/__init__.py +19 -0
  6. EntDetect/Jwalk/naccess.config.txt +255 -0
  7. EntDetect/__init__.py +10 -0
  8. EntDetect/_logging.py +71 -0
  9. EntDetect/change_resolution.py +2361 -0
  10. EntDetect/clustering.py +2626 -0
  11. EntDetect/compare_sim2exp.py +1927 -0
  12. EntDetect/entanglement_features.py +478 -0
  13. EntDetect/gaussian_entanglement.py +2067 -0
  14. EntDetect/order_params.py +1048 -0
  15. EntDetect/resources/__init__.py +11 -0
  16. EntDetect/resources/__pycache__/__init__.cpython-311.pyc +0 -0
  17. EntDetect/resources/calc_K.pl +712 -0
  18. EntDetect/resources/calc_Q.pl +962 -0
  19. EntDetect/resources/pulchra +0 -0
  20. EntDetect/resources/shared_files/__init__.py +2 -0
  21. EntDetect/resources/shared_files/bt_contact_potential.dat +22 -0
  22. EntDetect/resources/shared_files/karanicolas_dihe_parm.dat +1600 -0
  23. EntDetect/resources/shared_files/kgs_contact_potential.dat +22 -0
  24. EntDetect/resources/shared_files/mj_contact_potential.dat +22 -0
  25. EntDetect/resources/stride +0 -0
  26. EntDetect/statistics.py +1344 -0
  27. EntDetect/utilities.py +201 -0
  28. entdetect-1.2.0.dist-info/METADATA +26 -0
  29. entdetect-1.2.0.dist-info/RECORD +45 -0
  30. entdetect-1.2.0.dist-info/WHEEL +5 -0
  31. entdetect-1.2.0.dist-info/entry_points.txt +11 -0
  32. entdetect-1.2.0.dist-info/licenses/LICENSE +674 -0
  33. entdetect-1.2.0.dist-info/top_level.txt +2 -0
  34. scripts/__init__.py +5 -0
  35. scripts/convert_cor_psf_to_pdb.py +103 -0
  36. scripts/run_Foldingpathway.py +162 -0
  37. scripts/run_MSM.py +152 -0
  38. scripts/run_OP_on_simulation_traj.py +194 -0
  39. scripts/run_change_resolution.py +63 -0
  40. scripts/run_compare_sim2exp.py +215 -0
  41. scripts/run_montecarlo.py +158 -0
  42. scripts/run_nativeNCLE.py +179 -0
  43. scripts/run_nonnative_entanglement_clustering.py +110 -0
  44. scripts/run_population_modeling.py +117 -0
  45. scripts/run_workflow4_nativeNCLE_batch.py +412 -0
@@ -0,0 +1,962 @@
1
+ #!/usr/bin/perl
2
+
3
+ use Getopt::Long;
4
+ use Data::Dumper;
5
+
6
+ my ($help, $input_cor, $sec_def, $dom_def, $traj, $start, $end, $if_meaningful, $mask, $output_dir, $restart);
7
+ GetOptions(
8
+ 'help|h!' => \$help,
9
+ 'input|i=s' => \$input_cor,
10
+ 'secs|s=s' => \$sec_def,
11
+ 'domain|d=s' => \$dom_def,
12
+ 'traj|t=s' => \$traj,
13
+ 'begin|b=s' => \$start,
14
+ 'end|e=s' => \$end,
15
+ 'meaningful|m=s' => \$if_meaningful,
16
+ 'mask|k=s' => \$mask,
17
+ 'outdir|o=s' => \$output_dir,
18
+ 'restart|r=s' => \$restart,
19
+ );
20
+
21
+ my $usage = "
22
+ Usage: perl calc_native_contact_fraction.pl
23
+ --input | -i <INPUT.COR> for identify native contacts
24
+ --domain | -d <DOMAIN.DAT> for domain defination
25
+ [--secs | -s] <SECONDARY STRUCTURE> for secondary
26
+ structure defination. If no file specified,
27
+ it will calculate all native contacts regardless
28
+ of the secondary structure.
29
+ --traj | -t <TRAJ.DCD> for simulation trajectory
30
+ [--begin | -b] <START STEP> to split trajectory.
31
+ Default is 1
32
+ [--end | -e] <END STEP> to split trajectory.
33
+ Default is the end frame.
34
+ [--meaningful | -m] <1 or 0> 1 to only calculate contacts
35
+ in the interface has native contacts;
36
+ 0 to calculate all possible interfaces.
37
+ The interface has no native contacts will
38
+ always has Q = 1.
39
+ Default is 0.
40
+ [--mask | -k] <MASK> for a subset of residues to calculate their
41
+ native contacts with all other residues.
42
+ Default is 'all'.
43
+ Example MASK:
44
+ '1-45' for selection from resid 1 to 45;
45
+ '1,3,5-9' for selection of resid 1, 3
46
+ and from 5 to 9.
47
+ [--outdir | -o] <DIRECTORY> for the outputs. Default is the directory
48
+ of your trajectories
49
+ [--restart | -r] <0 or 1> 0: Do not restart calculation; 1: Restart
50
+ calculation. Default is 0.
51
+ [--help | -h]\n
52
+ Example for DOMAIN.DAT:
53
+ 1:96 302:350 a #Domain 1 is from resid 1 to 96 and 302 to 350, and in
54
+ #alpha-helix class
55
+ 97:155 b #Domain 2 is from resid 97 to 155 and in beta-sheet class
56
+ 156:301 c #Domain 3 is from resid 156 to 301 and in alpha-beta class\n\n";
57
+
58
+ if($help)
59
+ {
60
+ die($usage);
61
+ }
62
+ elsif(!(defined($input_cor) && defined($dom_def) && defined($traj)))
63
+ {
64
+ die($usage);
65
+ }
66
+
67
+ if(!defined($sec_def))
68
+ {
69
+ $sec_def = "";
70
+ }
71
+ if(!defined($start))
72
+ {
73
+ $start = 1;
74
+ }
75
+ if(!defined($end))
76
+ {
77
+ $end = 9999999999999999999;
78
+ }
79
+ if(!defined($if_meaningful))
80
+ {
81
+ $if_meaningful = 0;
82
+ }
83
+ if(!defined($mask))
84
+ {
85
+ $mask = "all";
86
+ }
87
+
88
+ my @str = ();
89
+ if($traj =~ /\.cor$/)
90
+ {
91
+ @str = split(/\.cor/, $traj);
92
+ }
93
+ else
94
+ {
95
+ @str = split(/\.dcd/, $traj);
96
+ }
97
+ @str = split(/\//, $str[0]);
98
+ my $name = $str[$#str];
99
+ my $dir = join("/", @str[0...$#str-1]);
100
+ if(@str eq 1)
101
+ {
102
+ $dir = './';
103
+ }
104
+
105
+ if(!defined($output_dir))
106
+ {
107
+ $output_dir = $dir;
108
+ }
109
+
110
+ if(!defined($restart))
111
+ {
112
+ $restart = 0;
113
+ }
114
+ elsif($restart != 0)
115
+ {
116
+ $restart = 1;
117
+ }
118
+
119
+ my $cutoff = 8;
120
+
121
+ my @domain = parse_domain($dom_def);
122
+ my @sel_idx = parse_mask($mask);
123
+ if($sel_idx[0] eq "all")
124
+ {
125
+ print "-> Select all residues\n";
126
+ }
127
+ else
128
+ {
129
+ print "-> Select ".@sel_idx." residues\n";
130
+ }
131
+
132
+ my @native_cor = parse_cor($input_cor);
133
+ my $native_natom = @native_cor;
134
+
135
+ my @results = calc_contact_dist_map(\@native_cor, $cutoff);
136
+ my @native_contact_map = @{$results[0]};
137
+ my @native_distance_map = @{$results[1]};
138
+
139
+ my @sec_struc = parse_secondary_structure($sec_def);
140
+
141
+ my @native_contact_number = calc_contact_number(\@native_contact_map, \@domain, \@sec_struc, \@sel_idx);
142
+ my @meaningful_domain_idx = ();
143
+ print "-> native contacts found in $input_cor:\n";
144
+ for(my $i = 1; $i <= @domain; $i++)
145
+ {
146
+ my $dom = $domain[$i-1];
147
+ if($native_contact_number[$i-1] ne 0)
148
+ {
149
+ push@meaningful_domain_idx, $i;
150
+ }
151
+
152
+ if($dom->{"class"} eq "i")
153
+ {
154
+ print " Interface ".$dom->{"range"}->[0]."|".$dom->{"range"}->[1].": ".$native_contact_number[$i-1]."\n";
155
+ }
156
+ else
157
+ {
158
+ print " Domain ".$i.": ".$native_contact_number[$i-1]."\n";
159
+ }
160
+ }
161
+
162
+ if(!$if_meaningful)
163
+ {
164
+ @meaningful_domain_idx = (1..@domain);
165
+ }
166
+
167
+ if($traj =~ /\.cor$/)
168
+ {
169
+ open(DAT, ">${output_dir}/Q_${name}.dat")||die("Error: cannot create ${output_dir}/Q_${name}.dat\n\n");
170
+ foreach my $i (@meaningful_domain_idx)
171
+ {
172
+ my $dom = $domain[$i-1];
173
+ if($dom->{"class"} eq "i")
174
+ {
175
+ printf DAT ("%10s ", $dom->{"range"}->[0]."|".$dom->{"range"}->[1]);
176
+ }
177
+ else
178
+ {
179
+ printf DAT ("%10s ", "D_$i");
180
+ }
181
+ }
182
+ printf DAT ("%10s\n", "total");
183
+ my @traj_cor = parse_cor($traj);
184
+ my $natom = @traj_cor;
185
+ if($natom ne $native_natom)
186
+ {
187
+ print("Warning: atom numbers mismatch in $input_cor ($native_natom) and $traj ($natom)\n")
188
+ }
189
+ my @traj_contact_number = calc_traj_contact_number(\@traj_cor, \@domain, \@sec_struc, \@native_contact_map, \@native_distance_map, \@sel_idx);
190
+ my $tot_tcn = 0;
191
+ my $tot_ncn = 0;
192
+ foreach my $j (@meaningful_domain_idx)
193
+ {
194
+ my $fraction = 1;
195
+ if($native_contact_number[$j-1] != 0)
196
+ {
197
+ $fraction = $traj_contact_number[$j-1] / $native_contact_number[$j-1];
198
+ }
199
+ else
200
+ {
201
+ $fraction = -1;
202
+ }
203
+ $fraction = sprintf("%.4f", $fraction);
204
+ printf DAT ("%10s ", $fraction);
205
+ $tot_tcn += $traj_contact_number[$j-1];
206
+ $tot_ncn += $native_contact_number[$j-1];
207
+ }
208
+ my $fraction = 1;
209
+ if($tot_ncn != 0)
210
+ {
211
+ $fraction = $tot_tcn / $tot_ncn;
212
+ }
213
+ else
214
+ {
215
+ $fraction = -1;
216
+ }
217
+ $fraction = sprintf("%.4f", $fraction);
218
+ printf DAT ("%10s\n", $fraction);
219
+ exit;
220
+ }
221
+
222
+ open(my $dcdfile, "<$traj") || die("Error: Cannot find $traj\n\n");
223
+ binmode($dcdfile);
224
+ my ($natom, $tstep, $nframe, $first, $delta, $crystal, $fixed) = read_DCD_head($dcdfile);
225
+
226
+ if($natom ne $native_natom)
227
+ {
228
+ print("Warning: atom numbers mismatch in $input_cor ($native_natom) and $traj ($natom)\n")
229
+ }
230
+
231
+ if($restart && -s "${output_dir}/Q_${name}.dat")
232
+ {
233
+ open(DAT, "<${output_dir}/Q_${name}.dat")||die("Error: cannot find ${output_dir}/Q_${name}.dat\n\n");
234
+ open(DAT_COPY, ">${output_dir}/Q_${name}_copy.dat")||die("Error: cannot create ${output_dir}/Q_${name}_copy.dat\n\n");
235
+
236
+ foreach my $i (@meaningful_domain_idx)
237
+ {
238
+ my $dom = $domain[$i-1];
239
+ if($dom->{"class"} eq "i")
240
+ {
241
+ printf DAT_COPY ("%10s ", $dom->{"range"}->[0]."|".$dom->{"range"}->[1]);
242
+ }
243
+ else
244
+ {
245
+ printf DAT_COPY ("%10s ", "D_$i");
246
+ }
247
+ }
248
+ printf DAT_COPY ("%10s\n", "total");
249
+
250
+ my $num_lines = 0;
251
+ while(my $line = <DAT>)
252
+ {
253
+ if($line =~ /^\s*\-?[0-9].+\n$/)
254
+ {
255
+ $num_lines++;
256
+ print DAT_COPY "$line";
257
+ }
258
+ }
259
+ close(DAT);
260
+ close(DATA_COPY);
261
+ `rm -f ${output_dir}/Q_${name}.dat`;
262
+ `mv ${output_dir}/Q_${name}_copy.dat ${output_dir}/Q_${name}.dat`;
263
+
264
+ $start += $num_lines;
265
+ open(DAT, ">>${output_dir}/Q_${name}.dat")||die("Error: cannot find ${output_dir}/Q_${name}.dat\n\n");
266
+ }
267
+ else
268
+ {
269
+ open(DAT, ">${output_dir}/Q_${name}.dat")||die("Error: cannot create ${output_dir}/Q_${name}.dat\n\n");
270
+ foreach my $i (@meaningful_domain_idx)
271
+ {
272
+ my $dom = $domain[$i-1];
273
+ if($dom->{"class"} eq "i")
274
+ {
275
+ printf DAT ("%10s ", $dom->{"range"}->[0]."|".$dom->{"range"}->[1]);
276
+ }
277
+ else
278
+ {
279
+ printf DAT ("%10s ", "D_$i");
280
+ }
281
+ }
282
+ printf DAT ("%10s\n", "total");
283
+ }
284
+
285
+ my $deltat = $delta * $tstep;
286
+ my $firstframe = $first / $delta;
287
+ for(my $i = 1; $i <= $nframe; $i++)
288
+ {
289
+ my @traj_cor = read_DCD_frame($dcdfile, $crystal);
290
+ if($i >= $start && $i <= $end)
291
+ {
292
+ my @traj_contact_number = calc_traj_contact_number(\@traj_cor, \@domain, \@sec_struc, \@native_contact_map, \@native_distance_map, \@sel_idx);
293
+ my $tot_tcn = 0;
294
+ my $tot_ncn = 0;
295
+ foreach my $j (@meaningful_domain_idx)
296
+ {
297
+ my $fraction = 1;
298
+ if($native_contact_number[$j-1] != 0)
299
+ {
300
+ $fraction = $traj_contact_number[$j-1] / $native_contact_number[$j-1];
301
+ }
302
+ else
303
+ {
304
+ $fraction = -1;
305
+ }
306
+ $fraction = sprintf("%.4f", $fraction);
307
+ printf DAT ("%10s ", $fraction);
308
+ $tot_tcn += $traj_contact_number[$j-1];
309
+ $tot_ncn += $native_contact_number[$j-1];
310
+ }
311
+ my $fraction = 1;
312
+ if($tot_ncn != 0)
313
+ {
314
+ $fraction = $tot_tcn / $tot_ncn;
315
+ }
316
+ else
317
+ {
318
+ $fraction = -1;
319
+ }
320
+ $fraction = sprintf("%.4f", $fraction);
321
+ printf DAT ("%10s\n", $fraction);
322
+ }
323
+ }
324
+ close(DAT);
325
+
326
+ ######################################################
327
+ sub parse_domain
328
+ {
329
+ my $dom_def = $_[0];
330
+
331
+ my @domain = ();
332
+
333
+ my %class = ("a" => "Alpha-helix",
334
+ "b" => "Beta-sheet",
335
+ "c" => "Alpha-Beta");
336
+
337
+ print "-> Domain defination:\n";
338
+
339
+ open(DAT, "<$dom_def") || die("Error: Cannot find $dom_def\n\n");
340
+ my $n = 1;
341
+ my $start_min = 10000;
342
+ while(my $line = <DAT>)
343
+ {
344
+ chomp($line);
345
+ $line =~ s/^\s+|\s+$//g;
346
+ if($line !~ /^#/ && $line ne '')
347
+ {
348
+ my @str = split(/\s*#/, $line);
349
+ my @data = split(/\s+/, $str[0]);
350
+ my @res_range = @data[0..$#data-1];
351
+ my $sec_class = $data[$#data];
352
+ print " Domain $n: ";
353
+ if($sec_class ne "a" && $sec_class ne "b" && $sec_class ne "c")
354
+ {
355
+ die("Error: Forget to specify class as a, b or c?\n\n");
356
+ }
357
+ my %dom = ("range" => [],
358
+ "class" => $sec_class);
359
+ foreach my $d (@res_range)
360
+ {
361
+ my @data = split(/\s*:\s*/, $d);
362
+ my $start = $data[0];
363
+ my $end = $data[1];
364
+ print "$start ~ $end; ";
365
+ if($start < $start_min)
366
+ {
367
+ $start_min = $start;
368
+ }
369
+ push@{$dom{"range"}}, [$start, $end];
370
+ }
371
+ print "Class: ".$class{$sec_class}."\n";
372
+ push@domain, \%dom;
373
+ $n++;
374
+ }
375
+ }
376
+ close(DAT);
377
+
378
+ my $offset = $start_min - 1;
379
+ foreach my $d (@domain)
380
+ {
381
+ foreach my $r (@{$d->{"range"}})
382
+ {
383
+ $r->[0] -= $offset;
384
+ $r->[1] -= $offset;
385
+ }
386
+ }
387
+
388
+ for(my $i = 1; $i < $n-1; $i++)
389
+ {
390
+ for(my $j = $i+1; $j < $n; $j++)
391
+ {
392
+ my %hash = ("range" => [$i, $j],
393
+ "class" => "i",);
394
+ push@domain, \%hash;
395
+ }
396
+ }
397
+ return @domain;
398
+ }
399
+
400
+ ######################################################
401
+ sub parse_mask
402
+ {
403
+ my $mask = $_[0];
404
+ my @sel_idx = ();
405
+ $mask =~ s/^\s+|\s+$//g;
406
+ if($mask eq "all")
407
+ {
408
+ @sel_idx = ("all");
409
+ }
410
+ else
411
+ {
412
+ my @str = split(/,\s*/, $mask);
413
+ foreach my $s (@str)
414
+ {
415
+ if($s =~ /\-/)
416
+ {
417
+ my @str_1 = split(/\s*\-\s*/, $s);
418
+ for(my $i = $str_1[0]; $i <= $str_1[1]; $i++)
419
+ {
420
+ push@sel_idx, $i;
421
+ }
422
+ }
423
+ else
424
+ {
425
+ push@sel_idx, $s;
426
+ }
427
+ }
428
+ }
429
+ return @sel_idx;
430
+ }
431
+
432
+ ######################################################
433
+ sub parse_cor
434
+ {
435
+ my $cor = $_[0];
436
+
437
+ my @native_cor = ();
438
+ my $num_atom = 0;
439
+ my $if_ext = 0;
440
+ open(COR, "<$cor") || die("Error: cannot find $cor\n\n");
441
+ while(my $line = <COR>)
442
+ {
443
+ chomp($line);
444
+ if($line !~ /^\*/)
445
+ {
446
+ if($line =~ /^\s*[0-9]+$/)
447
+ {
448
+ $line =~ s/^\s+|\s+$//g;
449
+ $num_atom = $line;
450
+ }
451
+ elsif($line =~ /^\s*[0-9]+\s+EXT$/)
452
+ {
453
+ $line =~ s/^\s+|\s+$//g;
454
+ $if_ext = 1;
455
+ my @str = split(/\s+/, $line);
456
+ $num_atom = $str[0];
457
+ }
458
+ else
459
+ {
460
+ my ($x, $y, $z) = (0, 0, 0);
461
+ if($if_ext eq 0)
462
+ {
463
+ ($x, $y, $z) = unpack("x5 x5 x6 x1 x3 a10 a10 a10 x20", $line);
464
+ }
465
+ else
466
+ {
467
+ ($x, $y, $z) = unpack("x10 x10 x10 x10 a20 a20 a20 x10 x10 x20", $line);
468
+ }
469
+ $x =~ s/^\s+|\s+$//g;
470
+ $y =~ s/^\s+|\s+$//g;
471
+ $z =~ s/^\s+|\s+$//g;
472
+ push@native_cor, [$x, $y, $z];
473
+ }
474
+ }
475
+ }
476
+ close(COR);
477
+
478
+ return @native_cor;
479
+ }
480
+
481
+ ######################################################
482
+ sub parse_secondary_structure
483
+ {
484
+ my $sec_def = $_[0];
485
+ my @sec_struc = ();
486
+ print "-> Secondary structure defination:\n";
487
+ print " ";
488
+ if($sec_def eq "")
489
+ {
490
+ print "None\n";
491
+ return ([1, 99999999999999]);
492
+ }
493
+ open(DAT, "<$sec_def") || die("Error: cannot find $sec_def\n\n");
494
+ while(my $line = <DAT>)
495
+ {
496
+ chomp($line);
497
+ my @str = split(/\s+/, $line);
498
+ push@sec_struc, [$str[1], $str[2]];
499
+ print $str[1]." ~ ".$str[2]."; ";
500
+ }
501
+ close(DAT);
502
+ print "\n";
503
+ return @sec_struc;
504
+ }
505
+
506
+ #########################################################
507
+ sub calc_contact_dist_map
508
+ {
509
+ my @coor = @{$_[0]};
510
+ my $cutoff = $_[1];
511
+
512
+ my @c_map = ();
513
+ my @d_map = ();
514
+ for(my $i = 0; $i < @coor; $i++)
515
+ {
516
+ $c_map[$i] = [];
517
+ $d_map[$i] = [];
518
+ }
519
+
520
+ for(my $i = 0; $i < @coor-4; $i++)
521
+ {
522
+ for(my $j = $i + 4; $j < @coor; $j++)
523
+ {
524
+ my $distance = ($coor[$i]->[0] - $coor[$j]->[0]) ** 2 + ($coor[$i]->[1] - $coor[$j]->[1]) ** 2 + ($coor[$i]->[2] - $coor[$j]->[2]) ** 2;
525
+ $distance = $distance ** 0.5;
526
+
527
+ if($distance <= $cutoff)
528
+ {
529
+ $c_map[$i]->[$j] = 1;
530
+ $c_map[$j]->[$i] = 1;
531
+ $d_map[$i]->[$j] = $distance;
532
+ $d_map[$j]->[$i] = $distance;
533
+ }
534
+ else
535
+ {
536
+ $c_map[$i]->[$j] = 0;
537
+ $c_map[$j]->[$i] = 0;
538
+ $d_map[$i]->[$j] = 0;
539
+ $d_map[$j]->[$i] = 0;
540
+ }
541
+ }
542
+ }
543
+
544
+ my @results = (\@c_map, \@d_map);
545
+ return @results;
546
+ }
547
+
548
+ #########################################################
549
+ sub calc_contact_number
550
+ {
551
+ my @map = @{$_[0]};
552
+ my @domain = @{$_[1]};
553
+ my @sec_struc = @{$_[2]};
554
+ my @sel_idx = @{$_[3]};
555
+
556
+ my @result = ();
557
+ foreach my $dom (@domain)
558
+ {
559
+ my $contact_num = 0;
560
+ my @range = @{$dom->{"range"}};
561
+ if($dom->{"class"} eq "i")
562
+ {
563
+ my @range_1 = @{$domain[$range[0]-1]->{"range"}};
564
+ my @range_2 = @{$domain[$range[1]-1]->{"range"}};
565
+ foreach my $rd_1 (@range_1)
566
+ {
567
+ for(my $i = $rd_1->[0]; $i <= $rd_1->[1]; $i++)
568
+ {
569
+ my $tag_i = 0;
570
+ foreach my $rs (@sec_struc)
571
+ {
572
+ if($i >= $rs->[0] && $i <= $rs->[1])
573
+ {
574
+ $tag_i = 1;
575
+ last;
576
+ }
577
+ }
578
+
579
+ if($tag_i eq 0)
580
+ {
581
+ next;
582
+ }
583
+
584
+ foreach my $rd_2 (@range_2)
585
+ {
586
+ for(my $j = $rd_2->[0]; $j <= $rd_2->[1]; $j++)
587
+ {
588
+ my $tag_j = 0;
589
+ foreach my $rs (@sec_struc)
590
+ {
591
+ if($j >= $rs->[0] && $j <= $rs->[1])
592
+ {
593
+ $tag_j = 1;
594
+ last;
595
+ }
596
+ }
597
+
598
+ if($tag_j eq 0)
599
+ {
600
+ next;
601
+ }
602
+
603
+ if($map[$i-1]->[$j-1] == 1)
604
+ {
605
+ if($sel_idx[0] eq "all")
606
+ {
607
+ $contact_num++;
608
+ }
609
+ elsif(($i ~~ @sel_idx) || ($j ~~ @sel_idx))
610
+ {
611
+ $contact_num++;
612
+ }
613
+ }
614
+ }
615
+ }
616
+ }
617
+ }
618
+ }
619
+ else
620
+ {
621
+ foreach my $rd (@range)
622
+ {
623
+ for(my $i = $rd->[0]; $i <= $rd->[1]-1; $i++)
624
+ {
625
+ my $tag_i = 0;
626
+ foreach my $rs (@sec_struc)
627
+ {
628
+ if($i >= $rs->[0] && $i <= $rs->[1])
629
+ {
630
+ $tag_i = 1;
631
+ last;
632
+ }
633
+ }
634
+
635
+ if($tag_i eq 0)
636
+ {
637
+ next;
638
+ }
639
+
640
+ for(my $j = $i+1; $j <= $rd->[1]; $j++)
641
+ {
642
+ my $tag_j = 0;
643
+ foreach my $rs (@sec_struc)
644
+ {
645
+ if($j >= $rs->[0] && $j <= $rs->[1])
646
+ {
647
+ $tag_j = 1;
648
+ last;
649
+ }
650
+ }
651
+
652
+ if($tag_j eq 0)
653
+ {
654
+ next;
655
+ }
656
+
657
+ if($map[$i-1]->[$j-1] == 1)
658
+ {
659
+ if($sel_idx[0] eq "all")
660
+ {
661
+ $contact_num++;
662
+ }
663
+ elsif(($i ~~ @sel_idx) || ($j ~~ @sel_idx))
664
+ {
665
+ $contact_num++;
666
+ }
667
+ }
668
+ }
669
+ }
670
+ }
671
+ }
672
+ push@result, $contact_num;
673
+ }
674
+ return @result;
675
+ }
676
+
677
+ #########################################################
678
+ sub calc_traj_contact_number
679
+ {
680
+ my @coor = @{$_[0]};
681
+ my @domain = @{$_[1]};
682
+ my @sec_struc = @{$_[2]};
683
+ my @c_map = @{$_[3]};
684
+ my @d_map = @{$_[4]};
685
+ my @sel_idx = @{$_[5]};
686
+ my $sdist = 1.2;
687
+
688
+ my @result = ();
689
+ foreach my $dom (@domain)
690
+ {
691
+ my $contact_num = 0;
692
+ my @range = @{$dom->{"range"}};
693
+ if($dom->{"class"} eq "i")
694
+ {
695
+ my @range_1 = @{$domain[$range[0]-1]->{"range"}};
696
+ my @range_2 = @{$domain[$range[1]-1]->{"range"}};
697
+ foreach my $rd_1 (@range_1)
698
+ {
699
+ for(my $i = $rd_1->[0]; $i <= $rd_1->[1]; $i++)
700
+ {
701
+ my $tag_i = 0;
702
+ foreach my $rs (@sec_struc)
703
+ {
704
+ if($i >= $rs->[0] && $i <= $rs->[1])
705
+ {
706
+ $tag_i = 1;
707
+ last;
708
+ }
709
+ }
710
+
711
+ if($tag_i eq 0)
712
+ {
713
+ next;
714
+ }
715
+
716
+ foreach my $rd_2 (@range_2)
717
+ {
718
+ for(my $j = $rd_2->[0]; $j <= $rd_2->[1]; $j++)
719
+ {
720
+ my $tag_j = 0;
721
+ foreach my $rs (@sec_struc)
722
+ {
723
+ if($j >= $rs->[0] && $j <= $rs->[1])
724
+ {
725
+ $tag_j = 1;
726
+ last;
727
+ }
728
+ }
729
+
730
+ if($tag_j eq 0)
731
+ {
732
+ next;
733
+ }
734
+
735
+ if($c_map[$i-1]->[$j-1] == 1)
736
+ {
737
+ my $distance = 0;
738
+ if($coor[$i-1] ne "" && $coor[$j-1] ne "")
739
+ {
740
+ $distance = ($coor[$i-1]->[0] - $coor[$j-1]->[0]) ** 2 + ($coor[$i-1]->[1] - $coor[$j-1]->[1]) ** 2 + ($coor[$i-1]->[2] - $coor[$j-1]->[2]) ** 2;
741
+ $distance = $distance ** 0.5;
742
+ }
743
+ if($distance <= $sdist * $d_map[$i-1]->[$j-1] && $distance > 0)
744
+ {
745
+ if($sel_idx[0] eq "all")
746
+ {
747
+ $contact_num++;
748
+ }
749
+ elsif(($i ~~ @sel_idx) || ($j ~~ @sel_idx))
750
+ {
751
+ $contact_num++;
752
+ }
753
+ }
754
+ }
755
+ }
756
+ }
757
+ }
758
+ }
759
+ }
760
+ else
761
+ {
762
+ foreach my $rd (@range)
763
+ {
764
+ for(my $i = $rd->[0]; $i <= $rd->[1]-1; $i++)
765
+ {
766
+ my $tag_i = 0;
767
+ foreach my $rs (@sec_struc)
768
+ {
769
+ if($i >= $rs->[0] && $i <= $rs->[1])
770
+ {
771
+ $tag_i = 1;
772
+ last;
773
+ }
774
+ }
775
+
776
+ if($tag_i eq 0)
777
+ {
778
+ next;
779
+ }
780
+
781
+ for(my $j = $i+1; $j <= $rd->[1]; $j++)
782
+ {
783
+ my $tag_j = 0;
784
+ foreach my $rs (@sec_struc)
785
+ {
786
+ if($j >= $rs->[0] && $j <= $rs->[1])
787
+ {
788
+ $tag_j = 1;
789
+ last;
790
+ }
791
+ }
792
+
793
+ if($tag_j eq 0)
794
+ {
795
+ next;
796
+ }
797
+
798
+ if($c_map[$i-1]->[$j-1] == 1)
799
+ {
800
+ my $distance = 0;
801
+ if($coor[$i-1] ne "" && $coor[$j-1] ne "")
802
+ {
803
+ $distance = ($coor[$i-1]->[0] - $coor[$j-1]->[0]) ** 2 + ($coor[$i-1]->[1] - $coor[$j-1]->[1]) ** 2 + ($coor[$i-1]->[2] - $coor[$j-1]->[2]) ** 2;
804
+ $distance = $distance ** 0.5;
805
+ }
806
+ if($distance <= $sdist * $d_map[$i-1]->[$j-1] && $distance > 0)
807
+ {
808
+ if($sel_idx[0] eq "all")
809
+ {
810
+ $contact_num++;
811
+ }
812
+ elsif(($i ~~ @sel_idx) || ($j ~~ @sel_idx))
813
+ {
814
+ $contact_num++;
815
+ }
816
+ }
817
+ }
818
+ }
819
+ }
820
+ }
821
+ }
822
+ push@result, $contact_num;
823
+ }
824
+ return @result;
825
+ }
826
+
827
+ #########################################################
828
+ sub readFortran
829
+ {
830
+ my $handle=shift;
831
+
832
+ my $dat;
833
+ my $tdat;
834
+
835
+ read($handle,$tdat,4) || die "cannot read data";
836
+ my $len=unpack("L",$tdat);
837
+ read($handle,$dat,$len) || die "cannot read data";
838
+ read($handle,$tdat,4) || die "cannot read data";
839
+
840
+ # printf STDERR "Fread %d bytes\n",$len;
841
+
842
+ return ($dat,$len);
843
+ }
844
+
845
+ ################################################################
846
+ sub read_DCD
847
+ {
848
+ my $traj = $_[0];
849
+ my $boxsize = $_[1];
850
+ my $from = 1;
851
+ my $to = 999999999999999;
852
+ my $step = 1;
853
+
854
+ open(my $dcdfile, "<$traj") || die("Error: Cannot find $traj\n\n");
855
+ binmode($dcdfile);
856
+ my $buffer;
857
+ my $len;
858
+ ($buffer,$len)=readFortran($dcdfile);
859
+ my ($tag,@icontrol)=unpack("A4L*",$buffer);
860
+
861
+ ($buffer,$len)=readFortran($dcdfile);
862
+ ($buffer,$len)=readFortran($dcdfile);
863
+ my $natom=unpack("L",$buffer);
864
+
865
+ my $tstep=unpack("f",pack("L",$icontrol[9]))*4.88882129E-02;
866
+ my $nfiles=$icontrol[0];
867
+ my $first=$icontrol[1];
868
+ my $delta=$icontrol[2];
869
+ my $deltat=$icontrol[2]*$tstep;
870
+ my $crystal=$icontrol[10];
871
+ my $fixed=$icontrol[8];
872
+
873
+ my $firstframe=$first/$delta;
874
+
875
+ my ($xbuf,$ybuf,$zbuf);
876
+
877
+ my $itot = 0;
878
+ for (my $i=1; $itot<=$to && $i<=$nfiles; $i++)
879
+ {
880
+ $itot++;
881
+ if ($crystal)
882
+ {
883
+ my ($tbuf,$tlen)=readFortran($dcdfile);
884
+ if ($boxsize)
885
+ {
886
+ my @cdat=unpack("d*",$tbuf);
887
+ printf "%f %f %f\n",$cdat[0],$cdat[2],$cdat[5];
888
+ }
889
+ }
890
+
891
+ ($xbuf,$len)=readFortran($dcdfile); # printf STDERR "%d ",$len;
892
+ ($ybuf,$len)=readFortran($dcdfile); # printf STDERR "%d ",$len;
893
+ ($zbuf,$len)=readFortran($dcdfile); # printf STDERR "%d \n",$len;
894
+
895
+ if ($itot>=$from && $itot<=$to && ($itot%$step)==0 && !$boxsize)
896
+ {
897
+ my @xcoor=unpack("f*",$xbuf);
898
+ my @ycoor=unpack("f*",$ybuf);
899
+ my @zcoor=unpack("f*",$zbuf);
900
+ for(my $j = 0; $j < @xcoor; $j++)
901
+ {
902
+ print "$xcoor[$j] $ycoor[$j] $zcoor[$j]\n";
903
+ }
904
+ print "\n";
905
+ }
906
+ }
907
+ close($dcdfile);
908
+ }
909
+
910
+ ################################################################
911
+ sub read_DCD_head
912
+ {
913
+ my $dcdfile = $_[0];
914
+ my $buffer;
915
+ my $len;
916
+ ($buffer,$len)=readFortran($dcdfile);
917
+ my ($tag,@icontrol)=unpack("A4L*",$buffer);
918
+
919
+ ($buffer,$len)=readFortran($dcdfile);
920
+ ($buffer,$len)=readFortran($dcdfile);
921
+ my $natom=unpack("L",$buffer);
922
+
923
+ my $tstep=unpack("f",pack("L",$icontrol[9]))*4.88882129E-02;
924
+ my $nframe=$icontrol[0];
925
+ my $first=$icontrol[1];
926
+ my $delta=$icontrol[2];
927
+ my $crystal=$icontrol[10];
928
+ my $fixed=$icontrol[8];
929
+
930
+ my @results = ($natom, $tstep, $nframe, $first, $delta, $crystal, $fixed);
931
+ return @results;
932
+ }
933
+
934
+ ################################################################
935
+ sub read_DCD_frame
936
+ {
937
+ my $dcdfile = $_[0];
938
+ my $crystal = $_[1];
939
+
940
+ my @coor = ();
941
+
942
+ my ($xbuf,$ybuf,$zbuf);
943
+
944
+ if ($crystal)
945
+ {
946
+ my ($tbuf,$tlen)=readFortran($dcdfile);
947
+ }
948
+
949
+ ($xbuf,$len)=readFortran($dcdfile);
950
+ ($ybuf,$len)=readFortran($dcdfile);
951
+ ($zbuf,$len)=readFortran($dcdfile);
952
+
953
+ my @xcoor=unpack("f*",$xbuf);
954
+ my @ycoor=unpack("f*",$ybuf);
955
+ my @zcoor=unpack("f*",$zbuf);
956
+ for(my $j = 0; $j < @xcoor; $j++)
957
+ {
958
+ push@coor, [$xcoor[$j], $ycoor[$j], $zcoor[$j]];
959
+ }
960
+
961
+ return @coor;
962
+ }