// @String(label = "Mode:", choices={"Calculate", "Overlay", "Overlay & Crop"}, style="radioButtonHorizontal", description="Choose how far you want the program to go.") mode /* * This script provides an instantaneous conversion from reciprocal space to real * space for selected area diffraction (SAD) pattern measurements. * * It assumes that your diffraction pattern was collected using Gatan's * Digital Micrograph software, and that your image is properly calibrated in * reciprocal space, i.e. scale bar units display as 1/nm in DM. * * It also assumes that you have used imageJ's circle tool to measure the spot/ring * patterns concentric to the (000) direct beam. From the area measurement, the radius * (G) is found. From G = 1/d in reciprocal space, the d-spacing is calculated for * each measurement made. * * Written by: Mak Koten, Ph.D. (2018) * Version 2.2 */ // Make sure the right measurements are set (for next time plugin is run). setMeasurements(); // Read the area from the results window into an area array. area=getArray("Area"); // Calculate G and d from Area measurements. G=calcG(area); d=calcD(area); e=dError(d); // Print the values of d as a list in a text window. [[Un-comment next line to enable]]. //printToText("d-Spacing List","d (A)", d); // Update the results table. updateResults(); if (mode == "Calculate") { exit; } // Duplicate the image. run("Select None"); run("Duplicate...", " "); diffPattern = getImageID(); // Loop through the Results table and draw labels on the rings you want to ID. selectWindow("Results"); X = getArray("X"); Y = getArray("Y"); R = getArray(" G (1/nm)"); // Draw the ring number on the duplicate image. if (mode == "Overlay" || mode == "Overlay & Crop") { selectImage(diffPattern); drawLabels(X, Y, R); } // Crop and zoom the diffraction pattern to the area measured. if (mode == "Overlay & Crop") { x1=X[0]; y1=Y[0]; z=0; // z is a dummy variable that I don't need. //L1=2.1*R[R.length-1]; Array.getStatistics(R, min, max, mean, stdDev); L1=2.2*max; toUnscaled(x1, y1); toUnscaled(L1, z); // toUnscaled needs two variables.. hence z. x1=floor(x1); y1=floor(y1); L1=floor(L1); if (L1>getHeight()) { L1=getHeight(); } cropDPcenter(x1, y1, L1); } // Show d-spacing on image in upper right hand corner. writeDvalues(R); /* ************************* * * * * FUNCTIONS * * * * ************************* */ // This ensures that Area and centroid will be measured the next time, if they weren't already... function setMeasurements() { run("Set Measurements...", "area centroid redirect=None decimal=3"); } // This will return an array created from a column in the Results window. function getArray(resultsHeader) { array = newArray(); for (i=0; i", xPos, yPos+1.10*textHeight, "black"); } } // Crop the image to a square that zooms in on the area measured. function cropDPcenter(centerX, centerY, sideLength) { makeRectangle(centerX-0.5*sideLength, centerY-0.5*sideLength, sideLength, sideLength); run("Crop"); } // Write the d-spacing values to the upper right corner of the image. function writeDvalues(array) { setColor("black"); setJustification("left"); fontSize=floor(getHeight/40); setFont("Monospaced", fontSize); textWidth=getStringWidth(" "); gap = floor(getWidth/20); for (i = 0; i < array.length; i++) { y=gap+i*1.3*fontSize; ring=i+1; dValue1=10/array[i]; dValue2=toString(dValue1, 3); if (i>=9) { drawString(" "+ring+":"+dValue2+" A ", getWidth-textWidth-0.5*gap, y, "white"); } else { drawString(" "+ring+": "+dValue2+" A ", getWidth-textWidth-0.5*gap, y, "white"); } } } // Sometimes useful for troubleshooting. function list(name, a) { print(name); Array.print(a); }