Scripting Resources for DigitalMicrograph™

banner

Dave Mitchell's DigitalMicrograph™ Scripting Website

Home | Scripts | Examples | Functions | Recent Updates | Tutorials | Resources | Publications | Consulting | Projects | Contact & Bio |PyJEM| Search

 

Example: Periodic Table Dialog
Function
Shows how to use pulldown menus containg elemental data, buttons and fields to create a display of elemental atomic numbers and weights.
Version
version:20041208, v1.0
Author
D. R. G. Mitchell
Acknowledgements

Some sections of code for this script was based on Bernhard Schaffer's EELS-Edges-Chart script, who in turn obtained lists of elemental data from W Grogger. The listing of atomic weights is by D R. G. . Mitchell

Comments
-
System Requirements
Should be compatible with all recent versions of DigitalMicrograph.
Known Issues
-
Supported
Yes
Included Files
Main script file.
Source Code

// An example script showing the use of dialogues to use periodic table information.

// This is useful in a lot of microscopy calculations where chemical element information

// is used. In this case, an element from a list of the periodic table is selected and

// the atomic number and atomic weight are displayed. Pressing the

// 'calculate' button displays a dialog showing the current element and its atomic number and weight

// This script can be readily modified to calculate something useful on the basis of the selected element.

 

// D. R. G. Mitchell, adminnospam@dmscripting.com (remove the nospam to make this email address work)

// v1.0, December 2004

// version:20041208

 

// Acknowledgements: Some sections of code for this script were based on Bernhard Schaffer's

// EELS-Edges-Chart script, who in turn obtained lists of elemental data from W Grogger.

// The listing of atomic weights is by D. Mitchell

 

 

taggroup atnofield, atwtfield, ellist, chooseelement

number dummy, i

 

/*************************************************************************

function GetElementName (c) W.Grogger FELMI

*************************************************************************/

string GetElementName(number atNum, number &result){

result = 1

if(atNum==1) return "Hydrogen"

if(atNum==2) return "Helium"

if(atNum==3) return "Lithium"

if(atNum==4) return "Beryllium"

if(atNum==5) return "Boron"

if(atNum==6) return "Carbon"

if(atNum==7) return "Nitrogen"

if(atNum==8) return "Oxygen"

if(atNum==9) return "Fluorine"

if(atNum==10) return "Neon"

if(atNum==11) return "Sodium"

if(atNum==12) return "Magnesium"

if(atNum==13) return "Aluminum"

if(atNum==14) return "Silicon"

if(atNum==15) return "Phosphorus"

if(atNum==16) return "Sulfur"

if(atNum==17) return "Chlorine"

if(atNum==18) return "Argon"

if(atNum==19) return "Potassium"

if(atNum==20) return "Calcium"

if(atNum==21) return "Scandium"

if(atNum==22) return "Titanium"

if(atNum==23) return "Vanadium"

if(atNum==24) return "Chromium"

if(atNum==25) return "Manganese"

if(atNum==26) return "Iron"

if(atNum==27) return "Cobalt"

if(atNum==28) return "Nickel"

if(atNum==29) return "Copper"

if(atNum==30) return "Zinc"

if(atNum==31) return "Gallium"

if(atNum==32) return "Germanium"

if(atNum==33) return "Arsenic"

if(atNum==34) return "Selenium"

if(atNum==35) return "Bromine"

if(atNum==36) return "Krypton"

if(atNum==37) return "Rubidium"

if(atNum==38) return "Strontium"

if(atNum==39) return "Yttrium"

if(atNum==40) return "Zirconium"

if(atNum==41) return "Niobium"

if(atNum==42) return "Molybdenum"

if(atNum==43) return "Technetium"

if(atNum==44) return "Ruthenium"

if(atNum==45) return "Rhodium"

if(atNum==46) return "Palladium"

if(atNum==47) return "Silver"

if(atNum==48) return "Cadmium"

if(atNum==49) return "Indium"

if(atNum==50) return "Tin"

if(atNum==51) return "Antimony"

if(atNum==52) return "Tellurium"

if(atNum==53) return "Iodine"

if(atNum==54) return "Xenon"

if(atNum==55) return "Cesium"

if(atNum==56) return "Barium"

if(atNum==57) return "Lanthanum"

if(atNum==58) return "Cerium"

if(atNum==59) return "Praseodymium"

if(atNum==60) return "Neodymium"

if(atNum==61) return "Promethium"

if(atNum==62) return "Samarium"

if(atNum==63) return "Europium"

if(atNum==64) return "Gadolinium"

if(atNum==65) return "Terbium"

if(atNum==66) return "Dysprosium"

if(atNum==67) return "Holmium"

if(atNum==68) return "Erbium"

if(atNum==69) return "Thulium"

if(atNum==70) return "Ytterbium"

if(atNum==71) return "Lutetium"

if(atNum==72) return "Hafnium"

if(atNum==73) return "Tantalum"

if(atNum==74) return "Tungsten"

if(atNum==75) return "Rhenium"

if(atNum==76) return "Osmium"

if(atNum==77) return "Iridium"

if(atNum==78) return "Platinum"

if(atNum==79) return "Gold"

if(atNum==80) return "Mercury"

if(atNum==81) return "Thallium"

if(atNum==82) return "Lead"

if(atNum==83) return "Bismuth"

if(atNum==84) return "Polonium"

if(atNum==85) return "Astatine"

if(atNum==86) return "Radon"

if(atNum==87) return "Francium"

if(atNum==88) return "Radium"

if(atNum==89) return "Actinium"

if(atNum==90) return "Thorium"

if(atNum==91) return "Protactinium"

if(atNum==92) return "Uranium"

if(atNum==93) return "Neptunium"

if(atNum==94) return "Plutonium"

if(atNum==95) return "Americium"

if(atNum==96) return "Curium"

if(atNum==97) return "Berkelium"

if(atNum==98) return "Californium"

if(atNum==99) return "Einsteinium"

if(atNum==100) return "Fermium"

if(atNum==101) return "Mendelevium"

if(atNum==102) return "Nobelium"

if(atNum==103) return "Lawrencium"

result = 0

return ""

}

 

 

 

/*************************************************************************

function GetElementSymbol (c) W.Grogger FELMI

*************************************************************************/

string GetElementSymbol(number atNum, number &result){

result = 1

if(atNum==1) return "H"

if(atNum==2) return "He"

if(atNum==3) return "Li"

if(atNum==4) return "Be"

if(atNum==5) return "B"

if(atNum==6) return "C"

if(atNum==7) return "N"

if(atNum==8) return "O"

if(atNum==9) return "F"

if(atNum==10) return "Ne"

if(atNum==11) return "Na"

if(atNum==12) return "Mg"

if(atNum==13) return "Al"

if(atNum==14) return "Si"

if(atNum==15) return "P"

if(atNum==16) return "S"

if(atNum==17) return "Cl"

if(atNum==18) return "Ar"

if(atNum==19) return "K"

if(atNum==20) return "Ca"

if(atNum==21) return "Sc"

if(atNum==22) return "Ti"

if(atNum==23) return "V"

if(atNum==24) return "Cr"

if(atNum==25) return "Mn"

if(atNum==26) return "Fe"

if(atNum==27) return "Co"

if(atNum==28) return "Ni"

if(atNum==29) return "Cu"

if(atNum==30) return "Zn"

if(atNum==31) return "Ga"

if(atNum==32) return "Ge"

if(atNum==33) return "As"

if(atNum==34) return "Se"

if(atNum==35) return "Br"

if(atNum==36) return "Kr"

if(atNum==37) return "Rb"

if(atNum==38) return "Sr"

if(atNum==39) return "Y"

if(atNum==40) return "Zr"

if(atNum==41) return "Nb"

if(atNum==42) return "Mo"

if(atNum==43) return "Tc"

if(atNum==44) return "Ru"

if(atNum==45) return "Rh"

if(atNum==46) return "Pd"

if(atNum==47) return "Ag"

if(atNum==48) return "Cd"

if(atNum==49) return "In"

if(atNum==50) return "Sn"

if(atNum==51) return "Sb"

if(atNum==52) return "Te"

if(atNum==53) return "I"

if(atNum==54) return "Xe"

if(atNum==55) return "Cs"

if(atNum==56) return "Ba"

if(atNum==57) return "La"

if(atNum==58) return "Ce"

if(atNum==59) return "Pr"

if(atNum==60) return "Nd"

if(atNum==61) return "Pm"

if(atNum==62) return "Sm"

if(atNum==63) return "Eu"

if(atNum==64) return "Gd"

if(atNum==65) return "Tb"

if(atNum==66) return "Dy"

if(atNum==67) return "Ho"

if(atNum==68) return "Er"

if(atNum==69) return "Tm"

if(atNum==70) return "Yb"

if(atNum==71) return "Lu"

if(atNum==72) return "Hf"

if(atNum==73) return "Ta"

if(atNum==74) return "W"

if(atNum==75) return "Re"

if(atNum==76) return "Os"

if(atNum==77) return "Ir"

if(atNum==78) return "Pt"

if(atNum==79) return "Au"

if(atNum==80) return "Hg"

if(atNum==81) return "Tl"

if(atNum==82) return "Pb"

if(atNum==83) return "Bi"

if(atNum==84) return "Po"

if(atNum==85) return "At"

if(atNum==86) return "Rn"

if(atNum==87) return "Fr"

if(atNum==88) return "Ra"

if(atNum==89) return "Ac"

if(atNum==90) return "Th"

if(atNum==91) return "Pa"

if(atNum==92) return "U"

if(atNum==93) return "Np"

if(atNum==94) return "Pu"

if(atNum==95) return "Am"

if(atNum==96) return "Cm"

if(atNum==97) return "Bk"

if(atNum==98) return "Cf"

if(atNum==99) return "Es"

if(atNum==100) return "Fm"

if(atNum==101) return "Md"

if(atNum==102) return "No"

if(atNum==103) return "Lr"

 

 

result = 0

return ""

}

 

/*************************************************************************

function GetAtomicWt (c) D. Mitchell, www.dmscripting.com

*************************************************************************/

number GetAtomicWt(number atNum)

{

 

if(atNum==1) return 1.008

if(atNum==2) return 4.0026

if(atNum==3) return 6.941

if(atNum==4) return 9.01218

if(atNum==5) return 10.81

if(atNum==6) return 12.011

if(atNum==7) return 14.0067

if(atNum==8) return 15.9994

if(atNum==9) return 18.9984

if(atNum==10) return 20.179

if(atNum==11) return 22.9898

if(atNum==12) return 24.305

if(atNum==13) return 26.9815

if(atNum==14) return 28.086

if(atNum==15) return 30.9738

if(atNum==16) return 32.06

if(atNum==17) return 35.453

if(atNum==18) return 39.948

if(atNum==19) return 39.102

if(atNum==20) return 40.08

if(atNum==21) return 44.9559

if(atNum==22) return 47.9

if(atNum==23) return 50.9414

if(atNum==24) return 51.996

if(atNum==25) return 54.938

if(atNum==26) return 55.847

if(atNum==27) return 58.9332

if(atNum==28) return 58.71

if(atNum==29) return 63.546

if(atNum==30) return 65.37

if(atNum==31) return 69.72

if(atNum==32) return 72.59

if(atNum==33) return 74.9216

if(atNum==34) return 78.96

if(atNum==35) return 79.904

if(atNum==36) return 83.8

if(atNum==37) return 85.4678

if(atNum==38) return 87.62

if(atNum==39) return 88.9059

if(atNum==40) return 91.22

if(atNum==41) return 92.9064

if(atNum==42) return 95.94

if(atNum==43) return 99

if(atNum==44) return 101.07

if(atNum==45) return 102.9055

if(atNum==46) return 106.4

if(atNum==47) return 107.868

if(atNum==48) return 112.4

if(atNum==49) return 114.82

if(atNum==50) return 118.69

if(atNum==51) return 121.75

if(atNum==52) return 127.6

if(atNum==53) return 126.9045

if(atNum==54) return 131.3

if(atNum==55) return 132.905

if(atNum==56) return 137.34

if(atNum==57) return 138.905

if(atNum==58) return 140.12

if(atNum==59) return 140.9077

if(atNum==60) return 144.24

if(atNum==61) return 147

if(atNum==62) return 150.4

if(atNum==63) return 151.96

if(atNum==64) return 157.25

if(atNum==65) return 158.9254

if(atNum==66) return 162.5

if(atNum==67) return 164.9303

if(atNum==68) return 167.26

if(atNum==69) return 168.9342

if(atNum==70) return 173.04

if(atNum==71) return 174.97

if(atNum==72) return 178.49

if(atNum==73) return 180.9479

if(atNum==74) return 183.85

if(atNum==75) return 186.2

if(atNum==76) return 190.2

if(atNum==77) return 192.22

if(atNum==78) return 195.09

if(atNum==79) return 196.9665

if(atNum==80) return 200.59

if(atNum==81) return 204.37

if(atNum==82) return 207.2

if(atNum==83) return 208.9806

if(atNum==84) return 210

if(atNum==85) return 210

if(atNum==86) return 222

if(atNum==87) return 223

if(atNum==88) return 226

if(atNum==89) return 227

if(atNum==90) return 232.0381

if(atNum==91) return 231

if(atNum==92) return 238.029

if(atNum==93) return 237

if(atNum==94) return 242

if(atNum==95) return 243

if(atNum==96) return 247

if(atNum==97) return 247

if(atNum==98) return 251

if(atNum==99) return 254

if(atNum==100) return 253

if(atNum==101) return 256

if(atNum==102) return 254

if(atNum==103) return 257

 

}

 

 

// This section responds to changes made in the dialog box, such as pushing a button

class PTDialogExample : uiframe

{

void cancelpane( object self) // when the 'Cancel' button is pressed

{

documentwindow windoc=getdocumentwindow(0)

windowclose(windoc,0)

}

 

void Calculate(object self) // When the 'Calculate' button is pressed

{

number currentatno=dlggetvalue(atnofield)

number currentatwt=dlggetvalue(atwtfield)

string elementname=getelementname(currentatno,dummy)

okdialog(""+elementname+": Atomic Number = "+currentatno+" Atomic Weight = "+currentatwt)

}

 

void ChangeElement(object self, taggroup tg) // When the drop down listing of elements is changed

{

DLGValue(atnofield,""+Trunc(tg.DLGGetValue()+1))

dlgvalue(atwtfield,getatomicwt(tg.dlggetvalue()+1))

 

}

 

}

 

 

// This creates a boxed label at the top of the dialog box

TagGroup MakeLabels()

{

taggroup box1_items

taggroup box1=dlgcreatebox("", box1_items)

TagGroup label1 = DLGCreateLabel("\n Periodic Table Dialog Example \n");

box1.dlgexternalpadding(0,10)

box1_items.dlgaddelement(label1)

return box1

}

 

 

// This creates the calculate and cancel buttons in the dialog

TagGroup MakeButtons()

{

taggroup pushbuttons

TagGroup CalculateButton = DLGCreatePushButton("Calculate", "Calculate").DLGSide("Bottom");

calculatebutton.dlgexternalpadding(10,10)

TagGroup CancelButton = DLGCreatePushButton(" Cancel ", "cancelpane").DLGSide("Bottom");

cancelbutton.dlgexternalpadding(10,10)

pushbuttons=dlggroupitems(calculatebutton, cancelbutton)

pushbuttons.dlgtablelayout(2,1,0)

 

return pushbuttons

}

 

 

// This creates the dropdown menu of chemical elements in the dialog

Taggroup Makedropdown()

{

chooseElement = DLGCreateChoice(ElList,0,"ChangeElement")

 

number zz

// The listing (ellist) of atomic number symbol and element (eg (2) He - Helium) is synthesised in this loop

// calling the functions getelementsymbol() and getelementname(). This list is then added to the drop down menu

For (zz=1;zz<104;zz++)

{

string elementname=GetElementSymbol(zz,dummy)+" - "+GetElementName(zz,dummy)

elementname="("+zz+") "+elementname

Ellist.DLGAddChoiceItemEntry(elementname)

}

return chooseelement

}

 

// This makes the fields in the dialog (atomic number and atomic weight)

Taggroup makefields()

{

taggroup varlab1=dlgcreatelabel("Atomic No.").dlganchor("West")

atnofield=dlgcreateintegerfield(1,10).dlganchor("West") // 1 is the initial field value and 6 the field width

taggroup group1=dlggroupitems(varlab1, atnofield)

group1.dlgtablelayout(2,1,0) // this sets the table as 2 columns by 1 high

 

taggroup varlab2=dlgcreatelabel("Atomic Wt.").dlganchor("West")

atwtfield=dlgcreaterealfield(1.0080,10,8).dlganchor("West") // 1.0080 is the default value - At Wt of H, 8 is the field width, and 5 is the

number of digits displayed in the field

taggroup group2=dlggroupitems(varlab2, atwtfield)

group2.dlgtablelayout(2,1,0) // this sets the table as 2 columns by 1 high

 

taggroup group3=dlggroupitems(group1, group2)

group3.dlgtablelayout(1,2,0)

return group3

}

 

 

// This adds a label at the foot of the dialog

Taggroup addfooter()

{

 

TagGroup label2 = DLGCreateLabel(" D. R. G. Mitchell version 1.0, Dec 2004.");

label2.dlgexternalpadding(0,5)

return label2

}

 

// This function calls the various functions to create the dialog

void CreatePTExampleDialog()

{

TagGroup dialog_items;

TagGroup dialog = DLGCreateDialog("", dialog_items);

// Dialog size/position can be set with dlgposition() commands. In the


// absence of these, the dialog will shrink to fit the bounds of the content.


// to set the dialog size, remove the // from in front of the line below

//dialog.DLGPosition(100, 300, 100, 730);

dialog_items.DLGAddElement( MakeLabels() );

dialog_items.dlgaddelement(makedropdown());

dialog_items.dlgaddelement(makefields())

dialog_items.DLGAddElement( MakeButtons() );

dialog_items.dlgaddelement(addfooter());

 

object dialog_frame = alloc(PTDialogExample).init(dialog)

dialog_frame.display("Periodic Table Dialog Example");

 

}

 

 

// Main program

// This calls the function above, which creates the dialog

CreatePTExampleDialog()