Subversion Repositories wimsdev

Rev

Rev 14144 | 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 {
14376 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
    }
14376 bpr 47
    if (!($hash->{$a[0]}{name} =~ /H\b/) && ($hash->{$a[1]}{name} =~ /H\b/)) {
48
      $hash->{$a[0]}{hydrogenfichier}++;
49
    }
50
    if (!($hash->{$a[1]}{name} =~ /H\b/) && ($hash->{$a[0]}{name} =~ /H\b/)) {
51
      $hash->{$a[1]}{hydrogenfichier}++;
52
    }
13403 bpr 53
  }
54
  if ($_ =~s /M  CHG//) {
55
    @a=split(" ", $_);
56
    my $cc=1;
57
    for my $ion (@a) {
58
      if ($cc%2==0) {
13418 bpr 59
        $hash->{$ion}{hydrogen} += $a[$cc];
13403 bpr 60
      }
61
      $cc++;
62
    }
63
  };
64
  $cnt ++;
65
}
66
close IN;
14144 bpr 67
my $nbhydrogen='';
68
for my $at (sort {$a<=>$b} keys %hash){
69
  $hash{$at}{'hydrogen'}=0 if (!(defined $hash{$at}{'hydrogen'}) || $hash{$at}{'hydrogen'}<0);
70
  $nH = $nH+ $hash{$at}{'hydrogen'};
71
  $nbhydrogen .= "$at,$hash->{$at}{name},$hash->{$at}{hydrogen}\n";
13403 bpr 72
}
14376 bpr 73
my $nbhydrogenfichier='';
74
for my $at (sort {$a<=>$b} keys %hash){
75
  if(!($hash->{$at}{name} =~ /H\b/)){
76
    $hash{$at}{'hydrogenfichier'}=0 if (!(defined $hash{$at}{'hydrogenfichier'})
77
      || $hash{$at}{'hydrogenfichier'}<0);
78
    $nbhydrogenfichier .= "$at,$hash->{$at}{name},$hash->{$at}{hydrogenfichier}\n";
79
  }
80
}
81
 
13403 bpr 82
$atom{'H'}=$nH;
83
my $formula=$atom{'C'} > 0 ? 'C' : '' ;
84
$formula .= $atom{'C'} if $atom{'C'} > 1;
85
$formula .= 'H' if $atom{'H'} > 0;
86
$formula .= $atom{'H'} if $atom{'H'} > 1;
87
 
88
for my $at (sort keys %atom){
89
  next if (!(defined ($atom{$at})) || $atom{$at}==0 );
90
  next if ($at=~'C\b' || $at=~'H\b');
13418 bpr 91
  $formula .= $atom{$at}==1? $at : $at . $atom{$at};
13403 bpr 92
}
14376 bpr 93
print "$formula,[$nbhydrogen],[$nbhydrogenfichier]";
13403 bpr 94
EOF