--- loncom/homework/convertjme.pl 2003/10/20 16:25:33 1.8 +++ loncom/homework/convertjme.pl 2003/12/08 18:36:58 1.9 @@ -2,7 +2,7 @@ # The LearningOnline Network with CAPA # Dynamically converts JME strings into either a png or ps file. # -# $Id: convertjme.pl,v 1.8 2003/10/20 16:25:33 albertel Exp $ +# $Id: convertjme.pl,v 1.9 2003/12/08 18:36:58 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -72,7 +72,7 @@ if ($loncapa) { $ps = $ENV{'cgi.'.$id.'.PS'}; @JMEstring=&unescape($ENV{'cgi.'.$id.'.JME'}); } else { - my @JMEstring = @ARGV; + @JMEstring = @ARGV; $width = shift @JMEstring; $png = 1; $ps = 1; @@ -86,7 +86,6 @@ my @modulator_structs=split(/\|/,$modula my @product_structs=split(/\|/,$products); - my @all_structs=(@reactant_structs,@modulator_structs,@product_structs); #get size of image and initialize image and globals @@ -200,6 +199,7 @@ foreach my $struct (@all_structs) { my @adjacent = map {0} 0..$natoms-1; my @bondsx = map {0} 0..$natoms-1; my @bondsy = map {0} 0..$natoms-1; + my @aldehyde = map {0} 0..$natoms-1; for (my $i = 0; $i < $nbonds; $i++) { $bonds[$atomA[$i]] += ($bondType[$i]>0) ? $bondType[$i] : 1; $bonds[$atomB[$i]] += ($bondType[$i]>0) ? $bondType[$i] : 1; @@ -211,8 +211,15 @@ foreach my $struct (@all_structs) { $bondsy[$atomA[$i]] += $y[$atomB[$i]] - $y[$atomA[$i]]; $bondsx[$atomB[$i]] += $x[$atomA[$i]] - $x[$atomB[$i]]; $bondsy[$atomB[$i]] += $y[$atomA[$i]] - $y[$atomB[$i]]; + + if ( @bondType[$i] == 2) { + @aldehyde[@atomA[$i]] ++ if (@name[@atomB[$i]] eq "O"); + @aldehyde[@atomB[$i]] ++ if (@name[@atomA[$i]] eq "O"); + } + } + # Draw bonds for (my $i = 0; $i < $nbonds; $i++) { my $xa = $x[$atomA[$i]]; @@ -268,7 +275,8 @@ foreach my $struct (@all_structs) { } elsif ($bondType[$i] == 2 && (($adjacent[$atomA[$i]] == 1 && $adjacent[$atomB[$i]] > 2)|| - ($adjacent[$atomB[$i]] == 1 && $adjacent[$atomA[$i]] > 2))) { + ($adjacent[$atomB[$i]] == 1 && $adjacent[$atomA[$i]] > 2)|| + @name[@atomA[$i]] eq "O" || @name[@atomB[$i]] eq "O")) { # centered bond my $xperp = $doubleWidth*$sina; my $yperp = $doubleWidth*$cosa; @@ -322,11 +330,8 @@ foreach my $struct (@all_structs) { for (my $i = 0; $i < $natoms; $i++) { my ($formula,$sign,$charge) = ($name[$i] =~ /(\w+)([\+|\-])?(\d)?/); - if ($png) { - $sign = "–" if ($sign eq "-"); # replace by n-dash - } if ($formula ne "C" || $sign ne ""|| - $adjacent[$i] < 2 || ($adjacent[$i] == 2 && $bonds[$i] == 4)) { + $adjacent[$i] < 2 || ($adjacent[$i] == 2 && $bonds[$i] == 4) || (@aldehyde[$i] == 1 && @bonds[$i] == 3)) { # don't show C, unless charged, terminal, or linear my $nH = 0; if (exists $valence{$formula}) { @@ -545,6 +550,7 @@ sub printCharge_png { my ($sign,$charge,$x,$y) = @_; my $yy = 662; + $sign = "–" if ($sign eq "-"); # replace by n-dash $charge = "" if ($charge == 1); $charge .= $sign;