################################################################################# # # # This is a super small script that simply spits out the DAVES positions needed # # to achieve a given energy based on alignment conditions. The alignment # # conditions are defined in an external file and thus hopefully safe from user # # errors. The necessary information is as follows: # # # # Crystal d spacing (from h, k, l and xtal material) # # The energy DAVES was aligned at # # The analyzer / detector arm angles at that alignment energy # # The scaling factor between analyzer / detector arm movements # # For moving things, also whether this is the up or downstream set # # # # With that in hand, actually computing where the arms and analyzer angles # # need to go is rather straightforward via 4 equations. The hard part will be # # turning this into something useful within spec... # # # # v 0.1 - 2024.02.16 # # - First stab at writing this. Largely repurposed code from existing # # scan creation scripts. # # # # CJP, CHESS # ################################################################################# import numpy as np def main(): #----------------------------------------------------------------------------------------------------------------------------# # # Beginning of the script where the code reads in pre-saved values from the _VALUES file # This gets all necessary information for computing the motor positions for any arbitrary energy # #----------------------------------------------------------------------------------------------------------------------------# print("\n\n\n\n#################################################################################\n") print("This is a script that will calculate the motor positions needed for a given energy \nusing the DAVES spectrometer at the ID2A beamline at CHESS.\n") print("The alignment data needed is loaded into the '_VALUES' file and so you simply need \nto enter the energy you desire to go to.\n") print("v 0.5, 2024.02.16") print("\n#################################################################################\n") valueDict = {} print("\nValues read from file:\n") with open("_VALUES.txt") as g: valueLines = g.readlines() for a in valueLines: vLine = a.split("=") valueDict[vLine[0]] = vLine[1].strip() xtal = valueDict['XTAL'] h = int(valueDict['H']) k = int(valueDict['K']) l = int(valueDict['L']) radius = int(valueDict['R']) centerE = float(valueDict['E_ALIGN']) centerAnaAngle = float(valueDict['ANA']) centerDetAngle = float(valueDict['DET']) updown = valueDict['UPDN'] scale = float(valueDict['SCALE']) print("Crystal analyzers = " + xtal + "(" + str(h) + str(k) + str(l) + ")") print("Crystal radius = " + str(radius)) print("\nSpectrometer aligned at " + str(centerE) + " eV with the " + updown + " analyzers at " + str(centerAnaAngle) + " and detector at " + str(centerDetAngle)) print("Theta / 2-theta scaling factor = " + str(scale) +"\n") if xtal == "Si": lat = 5.43102 elif xtal == "Ge": lat = 5.65782 # Print out 2d value d = lat / np.sqrt(h*h + k*k + l*l) x = np.round_(d, decimals=6) # Need to convert d to a decimal so it can be rounded to a reasonable number of sig figs print("2d = ",2*x," A") thetaBragg = np.degrees(np.arcsin((12398.4 / centerE) / (2*d))) print("The alignment energy corresponds to a Bragg angle of " + str(np.round_(thetaBragg,4)) + " degrees.\n") #----------------------------------------------------------------------------------------------------------------------------# # # The hard work is done, now soliciting an energy from the user can generate the necessary motor positions # #----------------------------------------------------------------------------------------------------------------------------# energy = float(input("What energy do you want motor values for? ")) ana = np.round((2 * (np.degrees(np.arcsin(12398.4 / (2 * d * energy))) - thetaBragg)),decimals=3) det = np.round((scale * ana),decimals=3) alpha1 = np.round((np.degrees(np.arcsin(250 / (radius * (12398.4 / (2*d*energy))**2)))),decimals=3) alpha2 = np.round((np.degrees(np.arcsin(126 / (radius * (12398.4 / (2*d*energy))**2)))),decimals=3) print("Analyzer = " + str(ana) + "; Detector = " + str(det) + "; Alpha 1 = " + str(alpha1) + "; Alpha 2 = " + str(alpha2) + "\n\n") if __name__ == "__main__": main()