6
$\begingroup$

The command

ColorData["Atoms", "Panel"]

indicates RGBColors of atoms by clicking a panel.

As I don't want to reinvent the wheel, I asked myself:

How do I transform ColorData["Atoms", "Panel"] into a click panel for chemical elements, which could be used as an argument for other functions like ElementData[] or IsotopeData[]?

$\endgroup$
  • 1
    $\begingroup$ What is the question? If this is not a question but instead intended to be instructional for others please edit the post to make it a question (it can be very simple) then post the majority of this as a self-answer. Thanks. $\endgroup$ – Mr.Wizard Jul 19 '14 at 7:23
  • 2
    $\begingroup$ @ Mr.Wizeard: Thx, I followed your suggestions, and brought it in Q&A form. $\endgroup$ – hieron Jul 24 '14 at 5:33
  • $\begingroup$ You will notice that you already have a combined four votes. :-) $\endgroup$ – Mr.Wizard Jul 24 '14 at 6:19
11
$\begingroup$

simple version

With a single codeline, ColorData["Atoms", "Panel"], can be transformed in a click panel for ElementData[].

{ColorData["Atoms", "Panel"] // 
  ReplaceAll[#, RuleDelayed[ "MouseClicked", $_] :> 
   (RuleDelayed["MouseClicked", 
      atomClicked = Part[RuleDelayed["MouseClicked", $], 
       2, 2, 2, 1, 1, 1]])] &, 
 Dynamic[atomClicked, Initialization :> (atomClicked = "H")]
}

simple click panel for periodic table

changing size or removing panel

Now it would be nice to change the panel size.This could be done simply by using

... // Magnify[#, 2] &

but maybe not the best solution.Therefore I added another function, which replaces ImageSize in Graphics.

(*version2 >>> shows how to remove the panel and how to change image size*)
Clear@"`*"
atomClicked = "H";(*init>>>important*)
imageSize[size_] := 
 ReplaceAll[#, 
   Graphics[x_, {y__}] :> Graphics[x, {ImageSize -> size, y}]] &;
atomClickedFunction = 
  ReplaceAll[#, 
    RuleDelayed[
      "MouseClicked", $_] :> (RuleDelayed["MouseClicked", 
       atomClicked = 
        Part[RuleDelayed["MouseClicked", $], 2, 2, 2, 1, 1, 1]])] &;
{ColorData["Atoms", "Panel"] // atomClickedFunction // imageSize@600 //
      First (*removes Panel*), atomClicked, 
    ElementData[atomClicked, "AlternateStandardNames" (* >>>
     Latin names,
     only for Latin abbreviations available in ElementData[]*)], 
    ElementData[atomClicked, "AtomicNumber"], 
    ElementData[atomClicked, "StandardName"], 
    ElementData[atomClicked, "DiscoveryYear"], 
    ElementData[atomClicked, "DiscoveryCountries"]} // Column // 
  Framed // Dynamic

a clickPanel for ElementData[ ] now

Transformed in a clickPanel for ElementData[ ] now.

Implementing the code in form of a Module[] with optionPatterns and more ... could be the next step ...

Just an idea ...

$\endgroup$
9
$\begingroup$

I recently needed to do something like this. Here's a simplified version of what I came up with:

DynamicModule[{elem = "Hydrogen"}, 
              Panel[Row[{(ColorData["Atoms", "Panel"] /. 
              HoldPattern["MouseClicked" :> rhs_] :> ("MouseClicked" :> (elem = 
              CanonicalName[ElementData[Cases[Unevaluated[rhs], _Rule, ∞][[1, 1]]]]))) /. 
              g_Graphics :> Append[g, ImageSize -> Large] /.
              Panel[stuff_, __] :> stuff, Spacer[20], 
              Dynamic[Grid[Transpose[{Style[#, Bold] & /@
                           {"name:", "symbol:", "atomic number:", "atomic weight:",
                            "phase:", "electron configuration:"}, 
                           Table[ElementData[elem, prop],
                                 {prop, {"Name", "Symbol", "AtomicNumber", "AtomicWeight",
                                         "Phase", "ElectronConfigurationString"}}] /.
                           {e_EntityClass :> ToLowerCase[CanonicalName[e]], 
                            m_Missing :> ToLowerCase[First[m]], 
                            q_Quantity :> QuantityMagnitude[q]}}], Alignment -> Left], 
                      TrackedSymbols :> {elem}]}]]]

interactive periodic table

$\endgroup$
  • 1
    $\begingroup$ Very nice! The answer reminds me of the chemical knowledge I learned in high school seven years ago. Especially, the priority of 3d>4s that about electron configuration. $\endgroup$ – xyz May 23 '16 at 3:38
  • 2
    $\begingroup$ @J.M. beautiful, useful and instructive (Mma wise). :) $\endgroup$ – ubpdqn May 24 '16 at 7:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.