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,11 @@
1
+ """Bundled resource files shipped with EntDetect.
2
+
3
+ This package exists so :mod:`importlib.resources` can locate bundled helper
4
+ executables/scripts (e.g., ``calc_Q.pl``, ``calc_K.pl``, ``stride``, ``pulchra``)
5
+ and supporting data files.
6
+ """
7
+ """Packaged resource files for EntDetect.
8
+
9
+ This subpackage exists so `importlib.resources` can locate bundled helper
10
+ executables/scripts (e.g., `calc_Q.pl`, `stride`, `pulchra`) and data files.
11
+ """
@@ -0,0 +1,712 @@
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, $output_dir);
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
+ 'outdir|o=s' => \$output_dir,
16
+ );
17
+
18
+ my $usage = "
19
+ Usage: perl calc_chirality_number.pl
20
+ --input | -i <INPUT.COR> for identify native contacts
21
+ --domain | -d <DOMAIN.DAT> for domain defination
22
+ [--secs | -s] <SECONDARY STRUCTURE> for secondary
23
+ structure defination. If no file specified,
24
+ it will calculate all residues regardless
25
+ of the secondary structure.
26
+ --traj | -t <TRAJ.DCD> for simulation trajectory
27
+ [--begin | -b] <START STEP> to split trajectory.
28
+ Default is 1
29
+ [--end | -e] <END STEP> to split trajectory.
30
+ Default is the end frame.
31
+ [--outdir | -o] <DIRECTORY> for the outputs. Default is the directory
32
+ of your trajectories
33
+ [--help | -h]\n
34
+ Example for DOMAIN.DAT:
35
+ 1:96 302:350 a #Domain 1 is from resid 1 to 96 and 302 to 350, and in
36
+ #alpha-helix class
37
+ 97:155 b #Domain 2 is from resid 97 to 155 and in beta-sheet class
38
+ 156:301 c #Domain 3 is from resid 156 to 301 and in alpha-beta class\n\n";
39
+
40
+ if($help)
41
+ {
42
+ die($usage);
43
+ }
44
+ elsif(!(defined($input_cor) && defined($dom_def) && defined($traj)))
45
+ {
46
+ die($usage);
47
+ }
48
+
49
+ if(!defined($sec_def))
50
+ {
51
+ $sec_def = "";
52
+ }
53
+ if(!defined($start))
54
+ {
55
+ $start = 1;
56
+ }
57
+ if(!defined($end))
58
+ {
59
+ $end = 9999999999999999999;
60
+ }
61
+
62
+ my @str = ();
63
+ if($traj =~ /\.cor$/)
64
+ {
65
+ @str = split(/\.cor/, $traj);
66
+ }
67
+ else
68
+ {
69
+ @str = split(/\.dcd/, $traj);
70
+ }
71
+ @str = split(/\//, $str[0]);
72
+ my $name = $str[$#str];
73
+ my $dir = join("/", @str[0...$#str-1]);
74
+ if(@str eq 1)
75
+ {
76
+ $dir = './';
77
+ }
78
+
79
+ if(!defined($output_dir))
80
+ {
81
+ $output_dir = $dir;
82
+ }
83
+
84
+ my $cutoff = 0;
85
+
86
+ my @domain = parse_domain($dom_def);
87
+
88
+ my @native_cor = parse_cor($input_cor);
89
+ my $native_natom = @native_cor;
90
+
91
+ my @sec_struc = parse_secondary_structure($sec_def);
92
+
93
+ my @native_c_list = calc_traj_c_list(\@native_cor, \@domain, \@sec_struc);
94
+ #print "@{$native_c_list[$#native_c_list]} \n";
95
+
96
+ if($traj =~ /\.cor$/)
97
+ {
98
+ open(DAT, ">${output_dir}/K_${name}.dat")||die("Error: cannot create ${output_dir}/K_${name}.dat\n\n");
99
+ for(my $i = 1; $i <= @domain; $i++)
100
+ {
101
+ my $dom = $domain[$i-1];
102
+ if($dom->{"class"} eq "i")
103
+ {
104
+ printf DAT ("%10s ", $dom->{"range"}->[0]."|".$dom->{"range"}->[1]);
105
+ }
106
+ else
107
+ {
108
+ printf DAT ("%10s ", "D_$i");
109
+ }
110
+ }
111
+ printf DAT ("%10s\n", "total");
112
+ my @traj_cor = parse_cor($traj);
113
+ my $natom = @traj_cor;
114
+ if($natom ne $native_natom)
115
+ {
116
+ print("Warning: atom numbers mismatch in $input_cor ($native_natom) and $traj ($natom)\n")
117
+ }
118
+ my @traj_c_list = calc_traj_c_list(\@traj_cor, \@domain, \@sec_struc);
119
+
120
+ for(my $i = 0; $i < @traj_c_list; $i++)
121
+ {
122
+ my $K = calc_K($native_c_list[$i], $traj_c_list[$i], $cutoff);
123
+ my $fraction = sprintf("%.4f", $K);
124
+ printf DAT ("%10s ", $fraction);
125
+ }
126
+ printf DAT ("\n");
127
+ exit;
128
+ }
129
+
130
+ open(my $dcdfile, "<$traj") || die("Error: Cannot find $traj\n\n");
131
+ binmode($dcdfile);
132
+ my ($natom, $tstep, $nframe, $first, $delta, $crystal, $fixed) = read_DCD_head($dcdfile);
133
+
134
+ if($natom ne $native_natom)
135
+ {
136
+ print("Warning: atom numbers mismatch in $input_cor ($native_natom) and $traj ($natom)\n")
137
+ }
138
+
139
+ open(DAT, ">${output_dir}/K_${name}.dat")||die("Error: cannot create ${output_dir}/K_${name}.dat\n\n");
140
+ for(my $i = 1; $i <= @domain; $i++)
141
+ {
142
+ my $dom = $domain[$i-1];
143
+ if($dom->{"class"} eq "i")
144
+ {
145
+ printf DAT ("%10s ", $dom->{"range"}->[0]."|".$dom->{"range"}->[1]);
146
+ }
147
+ else
148
+ {
149
+ printf DAT ("%10s ", "D_$i");
150
+ }
151
+ }
152
+ printf DAT ("%10s\n", "total");
153
+
154
+ my $deltat = $delta * $tstep;
155
+ my $firstframe = $first / $delta;
156
+ for(my $i_frame = 1; $i_frame <= $nframe; $i_frame++)
157
+ {
158
+ my @traj_cor = read_DCD_frame($dcdfile, $crystal);
159
+ if($i_frame >= $start && $i_frame <= $end)
160
+ {
161
+ my @traj_c_list = calc_traj_c_list(\@traj_cor, \@domain, \@sec_struc);
162
+ #print "@{$traj_c_list[$#traj_c_list]} \n";
163
+
164
+ for(my $i = 0; $i < @traj_c_list; $i++)
165
+ {
166
+ my $K = calc_K($native_c_list[$i], $traj_c_list[$i], $cutoff);
167
+ my $fraction = sprintf("%.4f", $K);
168
+ printf DAT ("%10s ", $fraction);
169
+ }
170
+ printf DAT ("\n");
171
+ }
172
+ }
173
+ close(DAT);
174
+
175
+ ######################################################
176
+ sub parse_domain
177
+ {
178
+ my $dom_def = $_[0];
179
+
180
+ my @domain = ();
181
+
182
+ my %class = ("a" => "Alpha-helix",
183
+ "b" => "Beta-sheet",
184
+ "c" => "Alpha-Beta");
185
+
186
+ print "-> Domain defination:\n";
187
+
188
+ open(DAT, "<$dom_def") || die("Error: Cannot find $dom_def\n\n");
189
+ my $n = 1;
190
+ my $start_min = 10000;
191
+ while(my $line = <DAT>)
192
+ {
193
+ chomp($line);
194
+ $line =~ s/^\s+|\s+$//g;
195
+ if($line !~ /^#/)
196
+ {
197
+ my @str = split(/\s*#/, $line);
198
+ my @data = split(/\s+/, $str[0]);
199
+ my @res_range = @data[0..$#data-1];
200
+ my $sec_class = $data[$#data];
201
+ print " Domain $n: ";
202
+ if($sec_class ne "a" && $sec_class ne "b" && $sec_class ne "c")
203
+ {
204
+ die("Error: Forget to specify class as a, b or c?\n\n");
205
+ }
206
+ my %dom = ("range" => [],
207
+ "class" => $sec_class);
208
+ foreach my $d (@res_range)
209
+ {
210
+ my @data = split(/\s*:\s*/, $d);
211
+ my $start = $data[0];
212
+ my $end = $data[1];
213
+ print "$start ~ $end; ";
214
+ if($start < $start_min)
215
+ {
216
+ $start_min = $start;
217
+ }
218
+ push@{$dom{"range"}}, [$start, $end];
219
+ }
220
+ print "Class: ".$class{$sec_class}."\n";
221
+ push@domain, \%dom;
222
+ $n++;
223
+ }
224
+ }
225
+ close(DAT);
226
+
227
+ my $offset = $start_min - 1;
228
+ foreach my $d (@domain)
229
+ {
230
+ foreach my $r (@{$d->{"range"}})
231
+ {
232
+ $r->[0] -= $offset;
233
+ $r->[1] -= $offset;
234
+ }
235
+ }
236
+
237
+ for(my $i = 1; $i < $n-1; $i++)
238
+ {
239
+ for(my $j = $i+1; $j < $n; $j++)
240
+ {
241
+ my %hash = ("range" => [$i, $j],
242
+ "class" => "i",);
243
+ push@domain, \%hash;
244
+ }
245
+ }
246
+ return @domain;
247
+ }
248
+
249
+ ######################################################
250
+ sub parse_mask
251
+ {
252
+ my $mask = $_[0];
253
+ my @sel_idx = ();
254
+ $mask =~ s/^\s+|\s+$//g;
255
+ if($mask eq "all")
256
+ {
257
+ @sel_idx = ("all");
258
+ }
259
+ else
260
+ {
261
+ my @str = split(/,\s*/, $mask);
262
+ foreach my $s (@str)
263
+ {
264
+ if($s =~ /\-/)
265
+ {
266
+ my @str_1 = split(/\s*\-\s*/, $s);
267
+ for(my $i = $str_1[0]; $i <= $str_1[1]; $i++)
268
+ {
269
+ push@sel_idx, $i;
270
+ }
271
+ }
272
+ else
273
+ {
274
+ push@sel_idx, $s;
275
+ }
276
+ }
277
+ }
278
+ return @sel_idx;
279
+ }
280
+
281
+ ######################################################
282
+ sub parse_cor
283
+ {
284
+ my $cor = $_[0];
285
+
286
+ my @native_cor = ();
287
+ my $num_atom = 0;
288
+ my $if_ext = 0;
289
+ open(COR, "<$cor") || die("Error: cannot find $cor\n\n");
290
+ while(my $line = <COR>)
291
+ {
292
+ chomp($line);
293
+ if($line !~ /^\*/)
294
+ {
295
+ if($line =~ /^\s*[0-9]+$/)
296
+ {
297
+ $line =~ s/^\s+|\s+$//g;
298
+ $num_atom = $line;
299
+ }
300
+ elsif($line =~ /^\s*[0-9]+\s+EXT$/)
301
+ {
302
+ $line =~ s/^\s+|\s+$//g;
303
+ $if_ext = 1;
304
+ my @str = split(/\s+/, $line);
305
+ $num_atom = $str[0];
306
+ }
307
+ else
308
+ {
309
+ my ($x, $y, $z) = (0, 0, 0);
310
+ if($if_ext eq 0)
311
+ {
312
+ ($x, $y, $z) = unpack("x5 x5 x6 x1 x3 a10 a10 a10 x20", $line);
313
+ }
314
+ else
315
+ {
316
+ ($x, $y, $z) = unpack("x10 x10 x10 x10 a20 a20 a20 x10 x10 x20", $line);
317
+ }
318
+ $x =~ s/^\s+|\s+$//g;
319
+ $y =~ s/^\s+|\s+$//g;
320
+ $z =~ s/^\s+|\s+$//g;
321
+ push@native_cor, [$x, $y, $z];
322
+ }
323
+ }
324
+ }
325
+ close(COR);
326
+
327
+ return @native_cor;
328
+ }
329
+
330
+ ######################################################
331
+ sub parse_secondary_structure
332
+ {
333
+ my $sec_def = $_[0];
334
+ my @sec_struc = ();
335
+ print "-> Secondary structure defination:\n";
336
+ print " ";
337
+ if($sec_def eq "")
338
+ {
339
+ print "None\n";
340
+ return ([1, 99999999999999]);
341
+ }
342
+ open(DAT, "<$sec_def") || die("Error: cannot find $sec_def\n\n");
343
+ while(my $line = <DAT>)
344
+ {
345
+ chomp($line);
346
+ my @str = split(/\s+/, $line);
347
+ push@sec_struc, [$str[1], $str[2]];
348
+ print $str[1]." ~ ".$str[2]."; ";
349
+ }
350
+ close(DAT);
351
+ print "\n";
352
+ return @sec_struc;
353
+ }
354
+
355
+ #########################################################
356
+ sub V_dot
357
+ {
358
+ my @V1 = @{$_[0]};
359
+ my @V2 = @{$_[1]};
360
+
361
+ my $result = 0;
362
+ for(my $i = 0; $i < @V1; $i++)
363
+ {
364
+ $result += $V1[$i] * $V2[$i];
365
+ }
366
+
367
+ return $result;
368
+ }
369
+
370
+ #########################################################
371
+ sub V_cross
372
+ {
373
+ my @V1 = @{$_[0]};
374
+ my @V2 = @{$_[1]};
375
+
376
+ my @result = ();
377
+ $result[0] = $V1[1]*$V2[2]-$V1[2]*$V2[1];
378
+ $result[1] = $V1[2]*$V2[0]-$V1[0]*$V2[2];
379
+ $result[2] = $V1[0]*$V2[1]-$V1[1]*$V2[0];
380
+
381
+ return @result;
382
+ }
383
+
384
+ #########################################################
385
+ sub V_norm
386
+ {
387
+ my @V1 = @{$_[0]};
388
+
389
+ my $result = sqrt(V_dot(\@V1, \@V1));
390
+
391
+ return $result;
392
+ }
393
+
394
+ #########################################################
395
+ sub V_add
396
+ {
397
+ my @V1 = @{$_[0]};
398
+ my @V2 = @{$_[1]};
399
+
400
+ my @result = ();
401
+ for(my $i = 0; $i < @V1; $i++)
402
+ {
403
+ $result[$i] = $V1[$i] + $V2[$i];
404
+ }
405
+
406
+ return @result;
407
+ }
408
+
409
+ #########################################################
410
+ sub V_minus
411
+ {
412
+ my @V1 = @{$_[0]};
413
+ my @V2 = @{$_[1]};
414
+
415
+ my @result = ();
416
+ for(my $i = 0; $i < @V1; $i++)
417
+ {
418
+ $result[$i] = $V1[$i] - $V2[$i];
419
+ }
420
+
421
+ return @result;
422
+ }
423
+
424
+ #########################################################
425
+ sub calc_c_list
426
+ {
427
+ my @coor = @{$_[0]};
428
+ my @sel = @{$_[1]};
429
+
430
+ my @c_list = ();
431
+
432
+ for(my $i = 0; $i < @sel-3; $i++)
433
+ {
434
+ my @v1 = V_minus($coor[$sel[$i+1]], $coor[$sel[$i]]);
435
+ my @v2 = V_minus($coor[$sel[$i+2]], $coor[$sel[$i+1]]);
436
+ my @v3 = V_minus($coor[$sel[$i+3]], $coor[$sel[$i+2]]);
437
+ my @a = V_cross(\@v1, \@v2);
438
+ my $c = V_dot(\@a, \@v3);
439
+ my $cn = V_norm(\@v1) * V_norm(\@v2) * V_norm(\@v3);
440
+ if($cn == 0)
441
+ {
442
+ $c = 'nan';
443
+ }
444
+ else
445
+ {
446
+ # $c = $c / (V_norm(\@v1) * V_norm(\@v2) * V_norm(\@v3));
447
+ $c = $c / $cn;
448
+ }
449
+ push@c_list, $c;
450
+ }
451
+
452
+ return @c_list;
453
+ }
454
+
455
+ #########################################################
456
+ sub calc_traj_c_list
457
+ {
458
+ my @coor = @{$_[0]};
459
+ my @domain = @{$_[1]};
460
+ my @sec_struc = @{$_[2]};
461
+
462
+ my @result = ();
463
+ foreach my $dom (@domain)
464
+ {
465
+ my @range = @{$dom->{"range"}};
466
+ if($dom->{"class"} eq "i")
467
+ {
468
+ my @range_1 = @{$domain[$range[0]-1]->{"range"}};
469
+ my @range_2 = @{$domain[$range[1]-1]->{"range"}};
470
+ @range = (@range_1, @range_2);
471
+ }
472
+
473
+ my @sel = ();
474
+ foreach my $rd (@range)
475
+ {
476
+ for(my $i = $rd->[0]; $i <= $rd->[1]; $i++)
477
+ {
478
+ my $tag_i = 0;
479
+ foreach my $rs (@sec_struc)
480
+ {
481
+ #if($i >= $rs->[0] && $i <= $rs->[1])
482
+ if($i == $rs->[0] || $i == $rs->[1])
483
+ {
484
+ $tag_i = 1;
485
+ last;
486
+ }
487
+ }
488
+
489
+ if($tag_i eq 1)
490
+ {
491
+ push@sel, $i-1;
492
+ }
493
+ }
494
+ }
495
+ my @c_list = calc_c_list(\@coor, \@sel);
496
+ push@result, \@c_list;
497
+ }
498
+ my @sel = ();
499
+ for(my $i = 1; $i <= $sec_struc[$#sec_struc]->[1]; $i++)
500
+ {
501
+ my $tag_i = 0;
502
+ foreach my $rs (@sec_struc)
503
+ {
504
+ #if($i >= $rs->[0] && $i <= $rs->[1])
505
+ if($i == $rs->[0] || $i == $rs->[1])
506
+ {
507
+ $tag_i = 1;
508
+ last;
509
+ }
510
+ }
511
+
512
+ if($tag_i eq 1)
513
+ {
514
+ push@sel, $i-1;
515
+ }
516
+ }
517
+ my @c_list = calc_c_list(\@coor, \@sel);
518
+ push@result, \@c_list;
519
+ return @result;
520
+ }
521
+
522
+ #########################################################
523
+ sub calc_K
524
+ {
525
+ my @native_c_list = @{$_[0]};
526
+ my @traj_c_list = @{$_[1]};
527
+ my $cutoff = $_[2];
528
+
529
+ my $K = 0;
530
+ my $not_nan = 0;
531
+ for(my $i = 0; $i < @native_c_list; $i++)
532
+ {
533
+ if($traj_c_list[$i] ne 'nan' && $traj_c_list[$i]*$native_c_list[$i] >= 0)
534
+ {
535
+ $K += 1;
536
+ }
537
+ if($native_c_list[$i] ne 'nan')
538
+ {
539
+ $not_nan += 1;
540
+ }
541
+ }
542
+ if($not_nan == 0)
543
+ {
544
+ $K = -1;
545
+ }
546
+ else
547
+ {
548
+ $K /= $not_nan;
549
+ }
550
+ return $K;
551
+ }
552
+
553
+ #########################################################
554
+ sub calc_K_2
555
+ {
556
+ my @native_c_list = @{$_[0]};
557
+ my @traj_c_list = @{$_[1]};
558
+ my $cutoff = $_[2];
559
+
560
+ my $K_0 = 0;
561
+ my $K_1 = 0;
562
+ for(my $i = 0; $i < @native_c_list; $i++)
563
+ {
564
+ $K_0 += $native_c_list[$i];
565
+ $K_1 += $traj_c_list[$i];
566
+ }
567
+ if($K_0 * $K_1 < 0)
568
+ {
569
+ return 1;
570
+ }
571
+ else
572
+ {
573
+ return 0;
574
+ }
575
+ }
576
+
577
+ #########################################################
578
+ sub readFortran
579
+ {
580
+ my $handle=shift;
581
+
582
+ my $dat;
583
+ my $tdat;
584
+
585
+ read($handle,$tdat,4) || die "cannot read data";
586
+ my $len=unpack("L",$tdat);
587
+ read($handle,$dat,$len) || die "cannot read data";
588
+ read($handle,$tdat,4) || die "cannot read data";
589
+
590
+ # printf STDERR "Fread %d bytes\n",$len;
591
+
592
+ return ($dat,$len);
593
+ }
594
+
595
+ ################################################################
596
+ sub read_DCD
597
+ {
598
+ my $traj = $_[0];
599
+ my $boxsize = $_[1];
600
+ my $from = 1;
601
+ my $to = 999999999999999;
602
+ my $step = 1;
603
+
604
+ open(my $dcdfile, "<$traj") || die("Error: Cannot find $traj\n\n");
605
+ binmode($dcdfile);
606
+ my $buffer;
607
+ my $len;
608
+ ($buffer,$len)=readFortran($dcdfile);
609
+ my ($tag,@icontrol)=unpack("A4L*",$buffer);
610
+
611
+ ($buffer,$len)=readFortran($dcdfile);
612
+ ($buffer,$len)=readFortran($dcdfile);
613
+ my $natom=unpack("L",$buffer);
614
+
615
+ my $tstep=unpack("f",pack("L",$icontrol[9]))*4.88882129E-02;
616
+ my $nfiles=$icontrol[0];
617
+ my $first=$icontrol[1];
618
+ my $delta=$icontrol[2];
619
+ my $deltat=$icontrol[2]*$tstep;
620
+ my $crystal=$icontrol[10];
621
+ my $fixed=$icontrol[8];
622
+
623
+ my $firstframe=$first/$delta;
624
+
625
+ my ($xbuf,$ybuf,$zbuf);
626
+
627
+ my $itot = 0;
628
+ for (my $i=1; $itot<=$to && $i<=$nfiles; $i++)
629
+ {
630
+ $itot++;
631
+ if ($crystal)
632
+ {
633
+ my ($tbuf,$tlen)=readFortran($dcdfile);
634
+ if ($boxsize)
635
+ {
636
+ my @cdat=unpack("d*",$tbuf);
637
+ printf "%f %f %f\n",$cdat[0],$cdat[2],$cdat[5];
638
+ }
639
+ }
640
+
641
+ ($xbuf,$len)=readFortran($dcdfile); # printf STDERR "%d ",$len;
642
+ ($ybuf,$len)=readFortran($dcdfile); # printf STDERR "%d ",$len;
643
+ ($zbuf,$len)=readFortran($dcdfile); # printf STDERR "%d \n",$len;
644
+
645
+ if ($itot>=$from && $itot<=$to && ($itot%$step)==0 && !$boxsize)
646
+ {
647
+ my @xcoor=unpack("f*",$xbuf);
648
+ my @ycoor=unpack("f*",$ybuf);
649
+ my @zcoor=unpack("f*",$zbuf);
650
+ for(my $j = 0; $j < @xcoor; $j++)
651
+ {
652
+ print "$xcoor[$j] $ycoor[$j] $zcoor[$j]\n";
653
+ }
654
+ print "\n";
655
+ }
656
+ }
657
+ close($dcdfile);
658
+ }
659
+
660
+ ################################################################
661
+ sub read_DCD_head
662
+ {
663
+ my $dcdfile = $_[0];
664
+ my $buffer;
665
+ my $len;
666
+ ($buffer,$len)=readFortran($dcdfile);
667
+ my ($tag,@icontrol)=unpack("A4L*",$buffer);
668
+
669
+ ($buffer,$len)=readFortran($dcdfile);
670
+ ($buffer,$len)=readFortran($dcdfile);
671
+ my $natom=unpack("L",$buffer);
672
+
673
+ my $tstep=unpack("f",pack("L",$icontrol[9]))*4.88882129E-02;
674
+ my $nframe=$icontrol[0];
675
+ my $first=$icontrol[1];
676
+ my $delta=$icontrol[2];
677
+ my $crystal=$icontrol[10];
678
+ my $fixed=$icontrol[8];
679
+
680
+ my @results = ($natom, $tstep, $nframe, $first, $delta, $crystal, $fixed);
681
+ return @results;
682
+ }
683
+
684
+ ################################################################
685
+ sub read_DCD_frame
686
+ {
687
+ my $dcdfile = $_[0];
688
+ my $crystal = $_[1];
689
+
690
+ my @coor = ();
691
+
692
+ my ($xbuf,$ybuf,$zbuf);
693
+
694
+ if ($crystal)
695
+ {
696
+ my ($tbuf,$tlen)=readFortran($dcdfile);
697
+ }
698
+
699
+ ($xbuf,$len)=readFortran($dcdfile);
700
+ ($ybuf,$len)=readFortran($dcdfile);
701
+ ($zbuf,$len)=readFortran($dcdfile);
702
+
703
+ my @xcoor=unpack("f*",$xbuf);
704
+ my @ycoor=unpack("f*",$ybuf);
705
+ my @zcoor=unpack("f*",$zbuf);
706
+ for(my $j = 0; $j < @xcoor; $j++)
707
+ {
708
+ push@coor, [$xcoor[$j], $ycoor[$j], $zcoor[$j]];
709
+ }
710
+
711
+ return @coor;
712
+ }