[LON-CAPA-cvs] cvs: loncom /homework convertjme.pl

albertel lon-capa-cvs@mail.lon-capa.org
Mon, 08 Dec 2003 18:36:58 -0000


albertel		Mon Dec  8 13:36:58 2003 EDT

  Modified files:              
    /loncom/homework	convertjme.pl 
  Log:
  - new version for Guy Ashkenazi
  
  
Index: loncom/homework/convertjme.pl
diff -u loncom/homework/convertjme.pl:1.8 loncom/homework/convertjme.pl:1.9
--- loncom/homework/convertjme.pl:1.8	Mon Oct 20 12:25:33 2003
+++ loncom/homework/convertjme.pl	Mon Dec  8 13:36:58 2003
@@ -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 @@
     $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 @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 @@
     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 @@
 	$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 @@
 	}
 	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 @@
     for (my $i = 0; $i < $natoms; $i++) {
 	my ($formula,$sign,$charge) =
 	    ($name[$i] =~ /(\w+)([\+|\-])?(\d)?/);
-	if ($png) {
-	    $sign = "&#8211;" 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 @@
     my ($sign,$charge,$x,$y) = @_;
     my $yy = 662;
 
+    $sign = "&#8211;" if ($sign eq "-");  # replace by n-dash
     $charge = "" if ($charge == 1);
     $charge .= $sign;