#!/usr/bin/perl # check the charges, and multiplicities in the # html vs. mol files # # read the current directory # open each file and extract formula, charge, and multiplicity #$file = "allyl-.mol" ; #$file = "CH3AsH2.mol" ; #$file = "BF3.mol" ; opendir(DIR,'.') || die "Can't open directory\n" ; local(@filenames) = readdir(DIR) ; closedir(DIR) ; for (@filenames) { next unless /mol$/ ; $file = $_ ; open(MOL,$file) || die "Can't open mol file $file" ; $nel = 0 ; $#elm = 0 ; $comment = scalar() ; $isis = scalar() ; $blank = scalar() ; $_ = scalar() ; ($atoms,$bonds,$stuff) = split ; $i = 0 ; while () { ($x,$y,$z,$el) = split ; $new = 1 ; for ($iel=0 ; $iel<$nel ; $iel++) { if ( $el eq $elm[$iel] ) { $ielm{$el}++ ; $new = 0 ; last } ; # end if $el eq } ; # end for $iel if ( $new ) { $elm[$nel] = $el ; $ielm{$el} = 1 ; $nel++ } $i++ ; last if $i == $atoms ; } # now charge and multiplicity from mole file $chargem = 0 ; $multm = 1 ; while () { if (/CHARGE/) { $chargem = ; chop($chargem) ;} if (/MULTIPLICITY/) { $multm = ; chop($multm) } } # end while charge and multiplicity # # # now get charge, multiplicity and header from html file $file =~ s/mol/html/ ; open(HTM,$file) || die "Can't open html file $file" ; $charge = 0 ; $multiplicity = 1 ; $chg = '' ; $mult = '' ; while () { last if /Tell/ ; if (/BODY/) { s/// ; s/

// ; s/<\/H2>// ; chop ; $head = $_ ; } if (/charge/) { s/The ion charge is // ; ($chg,$tail) = split(/\./) ; } $charge = $chg if $chg ; if (/multiplicity/) { s/The multiplicity is // ; ($mult,$tail) = split(/\./) if $charge == 0 ; ($stuff,$mult,$tail) = split(/\./) if $charge != 0 ; } } $multiplicity = $mult if $mult ; # only print out those that don't agree if ( ( $charge != $chargem ) || ( $multiplicity != $multm ) ) { print "$charge\t$multiplicity\t$chargem\t$multm\t$head\t$file\n" } }