Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am trying to write a program using the Mathematica function IsotopeData, but am finding the code troublesome. Due to my (relative) familiarity with Python, I am puzzled as to how Mathematica works, as they are very different. $\require{mhchem}$

What I am trying to do, is to find the elements in a decay chain which end with either $\ce{^{191}_{77}Ir}$ or $\ce{^{193}_{77}Ir}$.

In Python syntax, what I'm trying to do would look a bit like this:

#A would be the Atomic Mass and Z the Atomic Number
#DaughterNuclide(Z,A) would return the Daughter Nuclides of the isotope

def IsoCheck(z,a):
    try:
        x = DaughterNuclide(z,a)
        if x in Isotopes:
             return [z,a]
        else:
             return [0,0]
    except:
        return [0,0]

L=[]
Isotopes = [[76,191],[78,191]]
for a in xrange(1,295):
    for z in xrange(1,119):
        if IsoCheck(z,a) != [0,0]:
            L.append(IsoCheck(z,a))

repeat = 1
#Then, repeat until all chains are over
while repeat == 1:
     repeat = 0
     for x in L:
         if IsoCheck(x) != [0,0] #Lets just pretend it isn't a list
             L.append(x)
             repeat = 1

Now, my question is this: what would the equivalent code to perform this task in Mathematica look like?

share|improve this question
    
I suggest you show some of your attempt in Mathematica (especially how you call the IsotopeData function), as of right now it's not clear what you're working with in Mathematica –  David Robinson Aug 22 '12 at 20:21
    
The DaughterNuclide parameter of the IsotopeData function is called by the equivalent IsotopeData[{z,a},"DaughterNuclide"] where DaughterNuclide(z,a) is called in the python script above. –  Acebulf Aug 22 '12 at 20:25
add comment

migrated from stackoverflow.com Aug 23 '12 at 13:02

This question came from our site for professional and enthusiast programmers.

1 Answer

up vote 16 down vote accepted

It is a nice application for the Graph[] features in Mma.
We can calculate quickly all possible decays for all known isotopes, and then let VertexComponent[] look for the chains ending in {"Iridium191", "Iridium193"}.

g = Graph@Union@Flatten[Thread[DirectedEdge @@ ##] & /@ 
      Select[{#, IsotopeData[#, "DaughterNuclides"]} & /@ IsotopeData[], #[[2]] != {} &]];

Union@Flatten[VertexComponent[g, #] & /@ {"Iridium191", "Iridium193"}]

$\begin{array}{l} Actinium207&Actinium209&Astatine195\\ Astatine197&Astatine199&Astatine201 \\ Bismuth191&Bismuth193&Bismuth195 \\ Bismuth197&Francium199&Francium201 \\ Francium203&Francium205&Gold191 \\ Gold193&Iridium191&Iridium193 \\ Lead191&Lead193&Mercury191 \\ Mercury193&Osmium191&Osmium193 \\ Platinum191&Platinum193&Polonium191 \\ Polonium193&Polonium195&Polonium197 \\ Protactinium213&Radium203&Radium205 \\ Radon195&Radon197&Radon199 \\ Radon201&Rhenium191&Rhenium193 \\ Thallium191&Thallium193&Thorium209 \\ \end{array}$

Edit

The possible decay chains are:

g1 = Union[Flatten[VertexComponent[g, #] & /@ #], #] &@{"Iridium191", "Iridium193"}
g2 = Subgraph[g, g1, VertexShapeFunction -> "Name",  GraphLayout -> "LayeredDrawing"]

Mathematica graphics

Edit 2

Another application.

(*All possible decays of all Isotopes *)
decays = Select[{#, IsotopeData[#, "DaughterNuclides"]} & /@ IsotopeData[], #[[2]] != {} &];
(*Identify the Isotope with more ways to decay *)
mostModes = SortBy[decays, -Length@#[[2]] &][[1, 1]];
(*Get its decay characteristics*)
mMdecays = IsotopeData[mostModes, #] & /@ {"DaughterNuclides", "DecayModeSymbols", "BranchingRatios"};
(*Aux Function*)
pos[mostModes] = Above; Table[pos[i] = Below, {i, mMdecays[[1]]}];
(*Draw a scheme of its decays modes and percentages*)
g = Framed@Graph[Labeled[#, Placed[{Text@Style[#, 14, FontFamily -> "Helvetica"]}, 
                                   {pos[#]}]] & /@ Join[{mostModes}, mMdecays[[1]]], 
   Labeled[DirectedEdge[mostModes, #[[1]]], Placed[{ToString@StandardForm@#[[2]] <> "\n" <> 
         ToString[100 #[[3]]] <> "%"}, {"Middle"}]] & /@ (Transpose@ mMdecays),
   ImagePadding -> 30]

Mathematica graphics

share|improve this answer
    
@R.M I think because you are not getting the whole decay chain. See update –  belisarius Aug 23 '12 at 13:20
1  
+1 Very elegant! –  Ajasja Aug 23 '12 at 13:54
    
Oh, the code and the images don't quite match up. I get this this under win 7 mma 8.0.1 –  Ajasja Aug 23 '12 at 13:56
1  
@Ajasja g1 = Union[Flatten[VertexComponent[g, #] & /@ #], #] &@{"Iridium191", "Iridium193"}; g2 = HighlightGraph[ Subgraph[g, g1, GraphLayout -> "LayeredDrawing", VertexLabels -> "Name", ImagePadding -> 20], {"Iridium193", "Iridium191"}] –  belisarius Aug 23 '12 at 13:58
1  
@Verde Naah, no need to apologize... lol. When did Argentinians become Canadians? :P I was just pointing out something that might not have occurred to most people – that mathjax might slow down the page loading on mobile devices :) –  rm -rf Aug 26 '12 at 4:36
show 7 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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