Rev 13418 | Rev 14376 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
13403 | bpr | 1 | #!/bin/sh |
2 | |||
3 | exec perl <<'EOF' |
||
4 | |||
5 | use strict "vars"; |
||
6 | use warnings; |
||
7 | |||
8 | push (@ARGV,split(' ', $ENV{'wims_exec_parm'})) if ($ENV{'wims_exec_parm'}); |
||
9 | my ($file)=shift @ARGV; |
||
10 | |||
11 | my @valence1=('Li','Na','K','F','Cl','Br','I','At'); |
||
12 | my @valence2=('Be','Mg','Ca','Sr','Ba','O','Se','Te','Mn','Hg','Zn','Cu','S'); |
||
13 | my @valence3=('B','Al','N','P','As','Fe'); |
||
14 | my @valence4=('C','Si','Ge','Sn','A','Q'); |
||
13418 | bpr | 15 | my @other=('H'); |
13403 | bpr | 16 | my ($nbatom, $nbbond); |
17 | my $cnt=1; my $nH=0; |
||
18 | my %hash = (); |
||
19 | my $hash = \%hash; |
||
20 | my %atom = (); |
||
21 | my $atom = \%atom; |
||
22 | my $cntmax=10000; |
||
23 | my @a=(); |
||
24 | open(IN, "$file"); |
||
25 | while(<IN>) { |
||
26 | @a=split(" ", $_); |
||
27 | if($cnt==4){ |
||
28 | $nbatom=$a[0]; $nbbond=$a[1];$cntmax=4+$nbatom; |
||
29 | }; |
||
30 | if($cnt>4 && $cnt <= $cntmax) { |
||
31 | $hash->{$cnt-4}{name}=$a[3]; |
||
32 | if(!$atom->{$a[3]}) { $atom->{$a[3]}=1} else { $atom->{$a[3]} ++} |
||
13418 | bpr | 33 | if ( grep { $_ eq $a[3] } @valence4 ){ $hash->{$cnt-4}{hydrogen}=4} |
34 | elsif ( grep { $_ eq $a[3] } @valence1 ){ $hash->{$cnt-4}{hydrogen}=1} |
||
35 | elsif ( grep { $_ eq $a[3] } @valence2 ){ $hash->{$cnt-4}{hydrogen}=2} |
||
36 | elsif ( grep { $_ eq $a[3] } @valence3 ){ $hash->{$cnt-4}{hydrogen}=3} |
||
37 | elsif ( grep { $_ eq $a[3] } @other) {} |
||
13403 | bpr | 38 | else { |
13418 | bpr | 39 | #die( "$a[3]") |
13403 | bpr | 40 | } |
41 | } |
||
42 | if ($cnt > $cntmax && $cnt <= $cntmax + $nbbond) { |
||
43 | if (!($hash->{$a[0]}{name} =~ /H\b/) && !($hash->{$a[1]}{name} =~ /H\b/)) { |
||
13418 | bpr | 44 | $hash->{$a[0]}{hydrogen}-= $a[2]; |
45 | $hash->{$a[1]}{hydrogen}-= $a[2] |
||
13403 | bpr | 46 | } |
47 | } |
||
48 | if ($_ =~s /M CHG//) { |
||
49 | @a=split(" ", $_); |
||
50 | my $cc=1; |
||
51 | for my $ion (@a) { |
||
52 | if ($cc%2==0) { |
||
13418 | bpr | 53 | $hash->{$ion}{hydrogen} += $a[$cc]; |
13403 | bpr | 54 | } |
55 | $cc++; |
||
56 | } |
||
57 | }; |
||
58 | $cnt ++; |
||
59 | } |
||
60 | close IN; |
||
14144 | bpr | 61 | my $nbhydrogen=''; |
62 | for my $at (sort {$a<=>$b} keys %hash){ |
||
63 | $hash{$at}{'hydrogen'}=0 if (!(defined $hash{$at}{'hydrogen'}) || $hash{$at}{'hydrogen'}<0); |
||
64 | $nH = $nH+ $hash{$at}{'hydrogen'}; |
||
65 | $nbhydrogen .= "$at,$hash->{$at}{name},$hash->{$at}{hydrogen}\n"; |
||
13403 | bpr | 66 | } |
67 | $atom{'H'}=$nH; |
||
68 | my $formula=$atom{'C'} > 0 ? 'C' : '' ; |
||
69 | $formula .= $atom{'C'} if $atom{'C'} > 1; |
||
70 | $formula .= 'H' if $atom{'H'} > 0; |
||
71 | $formula .= $atom{'H'} if $atom{'H'} > 1; |
||
72 | |||
73 | for my $at (sort keys %atom){ |
||
74 | next if (!(defined ($atom{$at})) || $atom{$at}==0 ); |
||
75 | next if ($at=~'C\b' || $at=~'H\b'); |
||
13418 | bpr | 76 | $formula .= $atom{$at}==1? $at : $at . $atom{$at}; |
13403 | bpr | 77 | } |
14144 | bpr | 78 | print "$formula,[$nbhydrogen]"; |
13403 | bpr | 79 | EOF |