WeBWorK Problems

Chemistry Problems - Ionic Equations

Chemistry Problems - Ionic Equations

by Eric Stroyan -
Number of replies: 7
I would like to write problems that require the student to take a reaction, write out the total ionic equation, and then write the net ionic equation. Students would be presented with a reaction
AgNO_{3}(aq) + NaCl(aq) --> AgCl(s) + NaNO_{3}(aq)
be expected to write the total ionic equation,
Ag^{+1}(aq) + NO_{3}^{-1}(aq) + Na^{+1}(aq) + Cl^{-1}(aq) --> AgCl(s) + Na^{+1}(aq) + NO_{3}^{-1}(aq)
Then give the net ionic equation
Ag^{+1}(aq) + Cl^{-1}(aq) --> AgCl(s)
I have discovered that contextReaction.pl does not like all the charges and state designators.
Has anyone modified contextReaction.pl to do something like this, or does anyone have similar problems currently working? any help would be appreciated.

I have also updated (fixed) many of my extant chemistry problems if anyone wants copies, I can share them, just let me know.

I am also interested in any routines to calculate formula mass from a formula. My current approach is not too efficient. I have a database of all the compounds with atomic number and total amounts of constituents that I search and calculate from that information. I have had some success with using regexes to extract information from a TeX formula, but have not gotten anything to work reliably (I've been using the CPAN modules for Chemistry::..., but have not gotten far enough.

Any help is appreciated.
In reply to Eric Stroyan

Re: Chemistry Problems - Ionic Equations

by Davide Cervone -
I've modified the Reaction context to handle ions and states, so it now parses all the expressions above (though it does not require the braces, but does allow them).
The modified context is attached. Let me know if there are issues with this, as I'm not a chemist and don't know all the details about what might be legal and what isn't.
Also, I don't know if I have all the state designators that you need. I added (aq), (s), (l), and (g).
See the comments at the top of the file for additional information.

To use the updated version, use the File Manager to place the contextReaction.pll file in your course's templates/macros directory.

If you can confirm that this update is appropriate for the Reaction context, I will make a pull request to update the official copy of contextReaction.pl to include these features. If you think these changes should be optional, that can be done.
In reply to Davide Cervone

Re: Chemistry Problems - Ionic Equations

by Eric Stroyan -
Davide,
Works nicely!
I have included a sample problem below.
The only things that would need to be watched for is how the charges are input in the ions. Chemists' notations can vary. Generally monovalent ions are just given the charge without a number, e.g. Cl^{-}, Na^{+}, instead of Cl^{-1}, Na^{+1}. There is also some variation as to the ordering of charge information...Pb^{+2} or Pb^{2+}, Cl^{1-}, etc.
As far as I'm concerned these are not major issues (or really an issue at all), but I generally place a warning in the problem to students and spend a bit of class time teaching the use of LaTeX to enter answers.
This is a HUGE help for writing chemistry problems. I have also set up problems that draw from a macro containing a number of sample reactions so the problems can give a variety of examples to students.
I'm going to spend a bit more time torturing this, but it seems to me to be worthy of inclusion in the standard contextReaction.
Thanks again, this is great!
#
DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"contextReaction.pl"
);
#
#
TEXT(&beginproblem);
#
$showPartialCorrectAnswers = 1;
Context("Reaction");
#
$named_reactants ="Silver nitrate + Sodium chloride";
$named_products = "Silver chloride + Sodium nitrate";
#
# ID react, prod for complete molecular, total ionic, and net ionic equations.
#
$COMPLETE_REACTION=Formula("AgNO_{3} (aq) + NaCl (aq) --> AgCl (s) + NaNO_{3} (aq)");
#
$TOTAL_IONIC = Formula("Ag^{+1}(aq) + NO_{3}^{-1}(aq) + Na^{+1}(aq) + Cl^{-1}(aq) --> AgCl(s)+Na^{+1}(aq) + NO_{3}^{-1}(aq)");
#
$NET_IONIC=Formula("Ag^{+1}(aq) + Cl^{-1}(aq) --> AgCl(s)");
#
COMMENT("Reaction arrow is --> NOTE: two dashes and >. Charges for ions should be entered +1, +2, -1, -2, etc. Note the order and the 1 for the + and - cases");
BEGIN_TEXT
$BBOLD Answers should be entered using guidlines discussed in lecture. $EBOLD $BR
Consider the reaction shown below.$BR
$named_reactants \(\longrightarrow\) $named_products $BR
Write the complete molecular reaction equation.$BR
\{ans_rule(60)\}$BR
Write the total ionic equation.$BR
\{ans_rule(60)\}$BR
Write the net ionic equation for the reaction.$BR
\{ans_rule(60)\}
END_TEXT
#
ANS($COMPLETE_REACTION->cmp);
ANS($TOTAL_IONIC->cmp);
ANS($NET_IONIC->cmp);
#
ENDDOCUMENT();
In reply to Eric Stroyan

Re: Chemistry Problems - Ionic Equations

by Davide Cervone -
Generally monovalent ions are just given the charge without a number, e.g. Cl^{-}, Na^{+}, instead of Cl^{-1}, Na^{+1}.

Yes, I wondered about that. Doing that may be difficult to accomplish, as the MathObjects parser expects an operator to have at least one operand (and plus and minus need to be operators in order to handle negative numbers and adding two compounds). It might be possible to subclass something to override that, but I haven't looked into that.

There is also some variation as to the ordering of charge information...Pb^{+2} or Pb^{2+}, Cl^{1-}

That might be able to be handled as well, but I will have to look into it further.
In reply to Davide Cervone

Re: Chemistry Problems - Ionic Equations

by Eric Stroyan -
I don't think changing things to handle the notational irritations is worth the bother. Being able to handle the ions and states is a huge help for anyone writing chemistry problem. I only mention these things so that anyone writing a problem is aware. What you have here is great. I say leave it as is. You have made one chemist happy, and likely a large number of students not so much!
In reply to Davide Cervone

Re: Chemistry Problems - Ionic Equations

by Eric Stroyan -
I have thought of something else. Sometimes students are asked to balance Oxidation-Reduction reactions by using the half-reactions, something like Fe^{+3} + e^{-1} --> Fe^{+3}, S^{-2} --> SO_{4}^{-2} + 8e^{-1}. Could the electron, e^{-1} or just e, be added as an element something like
Context()->variables->add(e => $context::Reaction::ELEMENT); ?
I have not tried that yet. I have also updated my contextReaction with (ppt) and replaced the elements "Uut","Uuq","Uup","Uuh","Uus","Uuo" with their new (as of summer 2016) symbols "Nh","Fl","Mc","Lv","Ts","Og" (Nihonium, Flerovium, Muscovium, Livermorium, Tennessine, and Organesson.)
E.T.A.
I just tried
Context()->variables->add('e' => $context::Reaction::ELEMENT);

Seems to work well. Good stuff.
In reply to Eric Stroyan

Re: Chemistry Problems - Ionic Equations - RedOx

by Eric Stroyan -
This works!
Given a word equation, show the half-reactions.

DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"contextReaction.pl"
);
#
#
TEXT(&beginproblem);
#
$showPartialCorrectAnswers = 1;
Context("Reaction");
Context()->variables->add('e' => $context::Reaction::ELEMENT);
#
$named_reactants ="Zinc + Copper(II) sulfate";
$named_products = "Zinc sulfate + Copper";
#
$COMPLETE_REACTION=Formula("Zn(s) + CuSO_{4}(aq) --> ZnSO_{4}(aq) + Cu(s)");
#
$OXIDATION = Formula("Zn(s) --> Zn^{+2} + 2e^{-1}");
#
$REDUCTION=Formula("Cu^{+2} + 2e^{-1} --> Cu(s)");
#
COMMENT("Reaction arrow is --> NOTE: two dashes and >. Charges for ions should be entered +1, +2, -1, -2, etc. Note the order and the 1 for the + and - cases. Electrons are added as e^{-1}");
BEGIN_TEXT
$BBOLD Answers should be entered using guidlines discussed in lecture. $EBOLD $BR
Consider the reaction shown below.$BR
$named_reactants \(\longrightarrow\) $named_products $BR
Write the complete molecular reaction equation.$BR
\{ans_rule(60)\}$BR
Write the oxidation half-reaction.$BR
\{ans_rule(60)\}$BR
Write the reduction half-reaction.$BR
\{ans_rule(60)\}
END_TEXT
#
ANS($COMPLETE_REACTION->cmp);
ANS($OXIDATION->cmp);
ANS($REDUCTION->cmp);
#
ENDDOCUMENT();