[LON-CAPA-cvs] cvs: loncom /homework convertjme.pl
albertel
lon-capa-cvs@mail.lon-capa.org
Tue, 25 Jan 2005 14:55:16 -0000
albertel Tue Jan 25 09:55:16 2005 EDT
Modified files:
/loncom/homework convertjme.pl
Log:
- bug#3856, Number of hydrogens attached to a positively charged carbon atom is wrong. (from Guy Ash. by way of Jim Maxka)
Index: loncom/homework/convertjme.pl
diff -u loncom/homework/convertjme.pl:1.9 loncom/homework/convertjme.pl:1.10
--- loncom/homework/convertjme.pl:1.9 Mon Dec 8 13:36:58 2003
+++ loncom/homework/convertjme.pl Tue Jan 25 09:55:15 2005
@@ -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.9 2003/12/08 18:36:58 albertel Exp $
+# $Id: convertjme.pl,v 1.10 2005/01/25 14:55:15 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -135,7 +135,7 @@
units => "cm");
}
-my %valence = ("C",4,"N",3,"P",3,"O",2,"S",2);
+my %electrons = ("C",4,"N",5,"P",5,"O",6,"S",6);
my %font_width = (" ",250,"+",564,"-",500,"0",500,"1",500,"2",500,"3",500,"4",500,"5",500,"6",500,"7",500,"8",500,"9",500,"A",722,"B",667,"C",667,"D",722,"E",611,"F",556,"G",722,"H",722,"I",333,"J",389,"K",722,"L",611,"M",889,"N",722,"O",722,"P",556,"Q",722,"R",667,"S",556,"T",611,"U",722,"V",722,"W",944,"X",722,"Y",722,"Z",611,"a",444,"b",500,"c",444,"d",500,"e",444,"f",333,"g",500,"h",500,"i",278,"j",278,"k",500,"l",278,"m",778,"n",500,"o",500,"p",500,"q",500,"r",333,"s",389,"t",278,"u",500,"v",500,"w",722,"x",500,"y",500,"z",444);
my $font = '/usr/share/fonts/default/Type1/n021003l.pfb';
my $pointsize = 20;
@@ -333,14 +333,16 @@
if ($formula ne "C" || $sign ne ""||
$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}) {
- $nH = $valence{$formula} - $bonds[$i];
- $nH += (($charge eq "")? 1 : $charge) if ($sign eq "+");
- $nH -= (($charge eq "")? 1 : $charge) if ($sign eq "-");
+ if (exists $electrons{$formula}) {
+ # add H atoms to satisfy minimum valence
+ my $e = $electrons{$formula};
+ $e -= (($charge eq "")? 1 : $charge) if ($sign eq "+");
+ $e += (($charge eq "")? 1 : $charge) if ($sign eq "-");
+ my $valence = 4 - abs($e-4);
+ my $nH = $valence - @bonds[$i];
+ $formula .= "H" if ($nH > 0);
+ $formula .= $nH if ($nH > 1);
}
- $formula .= "H" if ($nH > 0);
- $formula .= $nH if ($nH > 1);
my @formula = $formula=~ /[A-Z][a-z]?\d*/g;
my $PI = 3.1415;