# The LearningOnline Network with CAPA
# chemical equation style response
#
# $Id: chemresponse.pm,v 1.56 2005/05/26 21:26:25 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
#
package Apache::chemresponse;
use strict;
use Apache::lonxml;
use Apache::lonnet;
use Apache::lonlocal;
BEGIN {
&Apache::lonxml::register('Apache::chemresponse',('organicresponse','organicstructure','reactionresponse','chem'));
}
sub chem_standard_order {
my ($reaction) = @_;
my ($re,$pr) = split(/->|<=>/,$reaction);
my @reactants = split(/\s\+/,$re);
my @products = split(/\s\+/,$pr);
foreach my $substance (@reactants,@products) {
$substance =~ s/(\^\d*)\s+/$1_/g; # protect superscript space
$substance =~ s/\s*//g; # strip whitespace
$substance =~ s/_/ /g; # restore superscript space
}
@reactants = sort @reactants;
@products = sort @products;
my $standard = '';
foreach my $substance (@reactants) {
$standard .= $substance;
$standard .= ' + ';
}
$standard =~ s/ \+ $//; # get rid of trailing plus sign
$standard .= ' -> ';
foreach my $substance (@products) {
$standard .= $substance;
$standard .= ' + ';
}
$standard =~ s/ \+ $//; # get rid of trailing plus sign
return $standard;
}
sub separate_jme_window {
my ($smile_input,$jme_input,$molecule,$options,$shown_text)=@_;
my $smilesection;
if (defined($smile_input)) {
$smilesection=<'; }
my $body=<
Molecule Editor
JME Editor courtesy of Peter Ertl, Novartis