'''DISTorX project v2.3Lech Stanislaw Kalinowski 2017'''from ipywidgets import Layout, FloatSlider, interactfrom IPython.display import displayimport numpy as npimport matplotlib.pyplot as pltimport timedef DistorX(aa, bb, cc): #print "\n >>DISTorX<< \n" try: FileName = 'ca2sn' #raw_input("Please enter the input File Name: ") XYZ = np.genfromtxt(FileName, dtype=("S10",'float16', 'float16', 'float16')) except IOError: print "\nFile with given name dosent exist." raise SystemExit('Please try again.') n = len(XYZ) #print "\n", n, ' atoms in readed file.' lamb = 1.54056 #input("\nPlease enter the X-Ray wavelenght (1.54056): ") #aa = input("Please enter lattice patameter, a: ") #bb = input("Please enter lattice patameter, b: ") #cc = input("Please enter lattice patameter, c: ") no_planes=0 alpha = 90 #input("Please enter Alpha angle: ") betha = 90 #input("Please enter Betha angle: ") gamma = 90 #input("Please enter Gamma angle: ") t = time.time() start_time = t if (aa==bb==cc and alpha == betha == gamma == 90): CrystSystem = "Cubic" elif (aa==bb!=cc and alpha == betha == gamma == 90): CrystSystem = "Tetragonal" elif (aa!=bb!=cc and alpha == betha == gamma == 90): CrystSystem = "Orthorombic" elif (aa!=bb!=cc!=aa and alpha == betha == 90 and betha != 90): CrystSystem = "Monoclinic" elif (aa!=bb!=cc!=aa and alpha != betha != gamma and alpha != betha != gamma != 90): CrystSystem = "Triclinic" elif (aa==bb!=cc and alpha == betha == 90 and gamma == 120): CrystSystem = "Hexagonal" else: CrystSystem = "Triclinic or Amorphous" L1=L2=L3=L4=L5=L6=L7=L8=L9=np.float16(0.0) a = np.array([aa,0.0,0.0],dtype='float32') b = np.array([0.0,bb,0.0],dtype='float32') c = np.array([0.0,0.0,cc],dtype='float32') if (CrystSystem == "Cubic" or CrystSystem == "Tetragonal" or CrystSystem == "Orthorombic"): hmax=np.int8(a[0]) kmax=np.int8(b[1]) lmax=np.int8(c[2]) hmin=0 kmin=0 lmin=0 else: hmax=np.int8(a[0]) kmax=np.int8(b[1]) lmax=np.int8(c[2]) hmin=-hmax kmin=-kmax lmin=-lmax #print "\nCrystalographic system is ", CrystSystem V = np.sum(a*np.cross(b,c)) k1 = 2*np.pi*(np.cross(b,c))/V k2 = 2*np.pi*(np.cross(c,a))/V k3 = 2*np.pi*(np.cross(a,b))/V h=np.int8(0) k=np.int8(0) l=np.int8(0)#print "\nCell parameters: a =", a[0]," b =", b[1], ' c =', c[2] SF = 0.0 + 1j*0.0 hkls = np.array([0,0,0,0.0,0.0],dtype='float16') XRD = [] F = Int = Lp = 0.0 m = 0 test = False #print "\nCalculations in progres..." for h in range(hmin, hmax): for k in range (kmin, kmax): for l in range (lmin, lmax): #Multiplicity Conditions if (k == 0 and l == 0): m = 6 elif (h == k and l == 0): m = 12 elif (h == k): m = 24 elif (h == k == l): m = 8 elif (h != k and l == 0): m = 24 elif (h != k != l): m = 48 else: m = 1 for i in range(n): p = h * k1 q = k * k2 r = l * k3 L = p + q + r G = np.sqrt(L[0]*L[0] + L[1]*L[1] + L[2]*L[2]) s = G/(4*np.pi) sin = lamb*s if (sin <= 1): if (XYZ[i][0] == 'H'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 0.489918, 20.6593, 0.262003, 7.74039, 0.196767, 49.5519, 0.049879, 2.20159, 0.001305 elif (XYZ[i][0] == 'He'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 0.8734, 9.1037, 0.6309, 3.3568, 0.3112, 22.9276, 0.178, 0.9821, 0.0064 elif (XYZ[i][0] == 'Li'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 1.1282, 3.9546, 0.7508, 1.0524, 0.6175, 85.3905, 0.4653, 168.261, 0.0377 elif (XYZ[i][0] == 'Be'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 1.5919, 43.6427, 1.1278, 1.8623, 0.5391, 103.483, 0.7029, 0.542, 0.0385 elif (XYZ[i][0] == 'Na'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 4.7626, 3.285, 3.1736, 8.8422, 1.2674, 0.3136, 1.1128, 129.424, 0.676 elif (XYZ[i][0] == 'Cl'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 11.4604, 0.0104, 7.1964, 1.1662, 6.2556, 18.5194, 1.6455, 47.7784, -9.5574 elif (XYZ[i][0] == 'B'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 2.0545,23.2185,1.3326,1.021,1.0979,60.3498,0.7068,0.1403,-0.1932 elif (XYZ[i][0] == 'C'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 2.31, 20.8439, 1.02, 10.2075, 1.5886, 0.5687, 0.865, 51.6512, 0.2156 elif (XYZ[i][0] == 'N'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 12.2126, 0.0057, 3.1322, 9.8933, 2.0125, 28.9975, 1.1663, 0.5826, -11.529, elif (XYZ[i][0] == 'O'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 3.0485,13.2771,2.2868,5.7011,1.5463,0.3239,0.867,32.9089,0.2508 elif (XYZ[i][0] == 'F'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 3.5392,10.2825,2.6412,4.2944,1.517,0.2615,1.0243,26.1476,0.2776 elif (XYZ[i][0] == 'Ne'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 3.9553,8.4042,3.1125,3.4262,1.4546,0.2306,1.1251,21.7184,0.3515 elif (XYZ[i][0] == 'Na'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 4.7626,3.285,3.1736,8.8422,1.2674,0.3136,1.1128,129.424,0.676 elif (XYZ[i][0] == 'Mg'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 5.4204,2.8275,2.1735,79.2611,1.2269,0.3808,2.3073,7.1937,0.8584 elif (XYZ[i][0] == 'Al'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 6.4202,3.0387,1.9002,0.7426,1.5936,31.5472,1.9646,85.0886,1.1151 elif (XYZ[i][0] == 'Si'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 6.2915,2.4386,3.0353,32.3337,1.9891,0.6785,1.541,81.6937,1.1407 elif (XYZ[i][0] == 'P'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 6.4345,1.9067,4.1791,27.157,1.78,0.526,1.4908,68.1645,1.1149 elif (XYZ[i][0] == 'S'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 6.9053,1.4679,5.2034,22.2151,1.4379,0.2536,1.5863,56.172,0.8669 elif (XYZ[i][0] == 'Cl'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 11.46040, 0.0104,7.1964,1.1662,6.2556,18.5194,1.6455,47.7784,-9.5574 elif (XYZ[i][0] == 'Ar'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 7.4845,0.9072,6.7723,14.8407,0.6539,43.8983,1.6442,33.3929,1.4445 elif (XYZ[i][0] == 'K'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 8.2186,12.7949,7.4398,0.7748,1.0519,213.187,0.8659,41.6841,1.4228 elif (XYZ[i][0] == 'Ca'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 8.6266,10.4421,7.3873,0.6599,1.5899,85.7484,1.0211,178.437,1.3751 elif (XYZ[i][0] == 'Sc'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 9.189,9.0213,7.3679,0.5729,1.6409,136.108,1.468,51.3531,1.3329 elif (XYZ[i][0] == 'Ti'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 9.7595,7.8508 ,7.3558,0.5,1.6991,35.6338,1.9021,116.105,1.2807 elif (XYZ[i][0] == 'V'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 10.2971,6.8657,7.3511,0.4385,2.0703,26.8938,2.0571,102.478,1.2199 elif (XYZ[i][0] == 'Cr'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 10.6406,6.1038,7.3537,0.392,3.324,20.2626,1.4922,98.7399,1.1832 elif (XYZ[i][0] == 'Mn'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 11.2819,5.3409,7.3573,0.3432,3.0193,17.8674,2.2441,83.7543,1.0896 elif (XYZ[i][0] == 'Fe'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 11.7695,4.7611,7.3573,0.3072,3.5222,15.3535,2.3045,76.8805,1.0369 elif (XYZ[i][0] == 'Co'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 12.2841,4.2791,7.3409,0.2784,4.0034,13.5359,2.3488,71.1692,1.0118 elif (XYZ[i][0] == 'Ni'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 12.8376,3.8785,7.292,0.2565,4.4438,12.1763,2.38,66.3421,1.0341 elif (XYZ[i][0] == 'Cu'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 13.338,3.5828 ,7.1676,0.247,5.6158,11.3966,1.6735,64.8126,1.191 elif (XYZ[i][0] == 'Zn'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 14.0743,3.2655,7.0318,0.2333,5.1652,10.3163,2.41,58.7097,1.3041 elif (XYZ[i][0] == 'Ga'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 15.2354,3.0669,6.7006,0.2412,4.3591,10.7805,2.9623,61.4135,1.7189 elif (XYZ[i][0] == 'Ge'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 16.0816,2.8509,6.3747,0.2516,3.7068,11.4468,3.683,54.7625,2.1313 elif (XYZ[i][0] == 'As'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 16.6723,2.6345,6.0701,0.2647,3.4313,12.9479,4.2779,47.7972,2.531 elif (XYZ[i][0] == 'Se'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 17.0006,2.4098,5.8196,0.2726,3.9731,15.2372,4.3543,43.8163,2.8409 elif (XYZ[i][0] == 'Br'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 17.1789,2.1723,5.2358,16.5796,5.6377,0.2609,3.9851,41.4328,2.9557 elif (XYZ[i][0] == 'Kr'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 17.3555,1.9384,6.7286,16.5623,5.5493,0.2261,3.5375,39.3972,2.825 elif (XYZ[i][0] == 'Rb'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 17.1784,1.7888,9.6435,17.3151,5.1399,0.2748,1.5292,164.934,3.4873 elif (XYZ[i][0] == 'Sr'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 17.5663,1.5564,9.8184,14.0988,5.422,0.1664,2.6694,132.376,2.5064 elif (XYZ[i][0] == 'Y'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 17.776,1.4029 ,10.2946,12.8006,5.72629,0.125599,3.26588,104.354,1.91213 elif (XYZ[i][0] == 'Zr'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 17.8765,1.27618,10.948,11.916,5.41732,0.117622,3.65721,87.6627,2.06929 elif (XYZ[i][0] == 'Nb'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 17.6142,1.18865,12.0144,11.766,4.04183,0.204785,3.53346,69.7957,3.75591 elif (XYZ[i][0] == 'Mo'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 3.7025,0.2772,17.2356,1.0958,12.8876,11.004,3.7429,61.6584,4.3875 elif (XYZ[i][0] == 'Tc'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 19.1301,0.864132,11.0948,8.14487,4.64901,21.5707,2.71263,86.8472,5.40428 elif (XYZ[i][0] == 'Ru'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 19.2674,0.80852,12.9182,8.43467,4.86337,24.7997,1.56756,94.2928,5.37874 elif (XYZ[i][0] == 'Rh'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 19.2957,0.751536,14.3501,8.21758,4.73425,25.8749,1.28918,98.6062,5.328 elif (XYZ[i][0] == 'Pd'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 19.3319,0.698655,15.5017,7.98929,5.29537,25.2052,0.605844,76.8986,5.26593 elif (XYZ[i][0] == 'Ag'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 19.2808,0.6446,16.6885,7.4726,4.8045,24.6605,1.0463,99.8156,5.179 elif (XYZ[i][0] == 'Cd'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 19.2214,0.5946,17.6444,6.9089,4.461,24.7008,1.6029,87.4825,5.0694 elif (XYZ[i][0] == 'In'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 19.1624,0.5476,18.5596,6.3776,4.2948,25.8499,2.0396,92.8029,4.9391 elif (XYZ[i][0] == 'Sn'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 19.1889,5.8303,19.1005,0.5031,4.4585,26.8909,2.4663,83.9571,4.7821 elif (XYZ[i][0] == 'Sb'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 19.6418,5.3034,19.0455,0.4607,5.0371,27.9074,2.6827,75.2825,4.5909 elif (XYZ[i][0] == 'Te'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 19.9644,4.81742,19.0138,0.420885,6.14487,28.5284,2.5239,70.8403,4.352 elif (XYZ[i][0] == 'I'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 20.1472,4.347,18.9949,0.3814,7.5138,27.766,2.2735,66.8776,4.0712 elif (XYZ[i][0] == 'Xe'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 20.2933,3.9282,19.0298,0.344,8.9767,26.4659,1.99,64.2658,3.7118 elif (XYZ[i][0] == 'Cs'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 20.3892,3.569,19.1062,0.3107,10.662,24.3879,1.4953,213.904,3.3352 elif (XYZ[i][0] == 'Ba'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 20.3361,3.216,19.297,0.2756,10.888,20.2073,2.6959,167.202,2.7731 elif (XYZ[i][0] == 'La'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 20.578,2.94817,19.599,0.244475,11.3727,18.7726,3.28719,133.124,2.14678 elif (XYZ[i][0] == 'Ce'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 21.1671,2.81219,19.7695,0.226836,11.8513,17.6083,3.33049,127.113,1.86264 elif (XYZ[i][0] == 'Pr'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 22.044,2.77393,19.6697,0.222087,12.3856,16.7669,2.82428,143.644,2.0583 elif (XYZ[i][0] == 'Nd'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 22.6845,2.66248,19.6847,0.210628,12.774,15.885,2.85137,137.903,1.98486 elif (XYZ[i][0] == 'Pm'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 23.3405,2.5627,19.6095,0.202088,13.1235,15.1009,2.87516,132.721,2.02876 elif (XYZ[i][0] == 'Sm'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 24.0042,2.47274,19.4258,0.196451,13.4396,14.3996,2.89604,128.007,2.20963 elif (XYZ[i][0] == 'Eu'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 24.6274,2.3879,19.0886,0.1942, 13.7603,13.7546,2.9227,123.174,2.5745 elif (XYZ[i][0] == 'Gd'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 25.0709,2.25341,19.0798,0.181951,13.8518,12.9331,3.54545,101.398,2.4196 elif (XYZ[i][0] == 'Tb'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 25.8976,2.24256,18.2185,0.196143,14.3167,12.6648,2.95354,115.362,3.58324 elif (XYZ[i][0] == 'Dy'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 26.507,2.1802,17.6383,0.202172,14.5596,12.1899,2.96577,111.874,4.29728 elif (XYZ[i][0] == 'Ho'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 26.9049,2.07051,17.294,0.19794,14.5583,11.4407,3.63837,92.6566,4.56796 elif (XYZ[i][0] == 'Er'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 27.6563,2.07356,16.4285,0.223545,14.9779,11.3604,2.98233,105.703,5.92046 elif (XYZ[i][0] == 'Tm'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 28.1819,2.02859,15.8851,0.238849,15.1542,10.9975,2.98706,102.961,6.75621 elif (XYZ[i][0] == 'Yb'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 28.6641,1.9889,15.4345,0.257119,15.3087,10.6647,2.98963,100.417,7.56672 elif (XYZ[i][0] == 'Lu'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 28.9476,1.90182,15.2208,9.98519,15.1,0.261033,3.71601,84.3298,7.97628 elif (XYZ[i][0] == 'Hf'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 29.144,1.83262,15.1726,9.5999,14.7586,0.275116,4.30013,72.029,8.58154 elif (XYZ[i][0] == 'Ta'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 29.2024,1.77333,15.2293,9.37046,14.5135,0.295977,4.76492,63.3644,9.24354 elif (XYZ[i][0] == 'W'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 29.0818,1.72029,15.43,9.2259,14.4327,0.321703,5.11982,57.056,9.8875 elif (XYZ[i][0] == 'Re'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 28.7621,1.67191,15.7189,9.09227,14.5564,0.3505,5.44174,52.0861,10.472 elif (XYZ[i][0] == 'Os'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 28.1894,1.62903,16.155,8.97948,14.9305,0.382661,5.67589,48.1647,11.0005 elif (XYZ[i][0] == 'Ir'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 27.3049,1.59279,16.7296,8.86553,15.6115,0.417916,5.83377,45.0011,11.4722 elif (XYZ[i][0] == 'Pt'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 27.0059,1.51293,17.7639,8.81174,15.7131,0.424593,5.7837,38.6103,11.6883 elif (XYZ[i][0] == 'Au'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 16.8819,0.4611,18.5913,8.6216,25.5582,1.4826,5.86,36.3956,12.0658 elif (XYZ[i][0] == 'Hg'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 20.6809,0.545,19.0417,8.4484,21.6575,1.5729,5.9676,38.3246,12.6089 elif (XYZ[i][0] == 'Tl'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 27.5446,0.65515,19.1584,8.70751,15.538,1.96347,5.52593,45.8149,13.1746, elif (XYZ[i][0] == 'Pb'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 31.0617,0.6902,13.0637,2.3576,18.442,8.618,5.9696,47.2579,13.4118 elif (XYZ[i][0] == 'Bi'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 33.3689,0.704,12.951,2.9238,16.5877,8.7937,6.4692,48.0093,13.5782 elif (XYZ[i][0] == 'Po'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 34.6726,0.700999,15.4733,3.55078,13.1138,9.55642,7.02588,47.0045,13.677 elif (XYZ[i][0] == 'At'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 35.3163,0.68587,19.0211,3.97458,9.49887,11.3824,7.42518,45.4715,13.7108 elif (XYZ[i][0] == 'Rn'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 35.5631,0.6631,21.2816,4.0691,8.0037,14.0422,7.4433,44.2473,13.6905 elif (XYZ[i][0] == 'Fr'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 35.9299,0.646453,23.0547,4.17619,12.1439,23.1052,2.11253,150.645,13.7247 elif (XYZ[i][0] == 'Ra'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 35.763,0.616341,22.9064,3.87135,12.4739,19.9887,3.21097,142.325,13.6211 elif (XYZ[i][0] == 'Ac'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 35.6597,0.589092,23.1032,3.65155,12.5977,18.599,4.08655,117.02,13.5266 elif (XYZ[i][0] == 'Th'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 35.5645,0.563359,23.4219,3.46204,12.7473,17.8309,4.80703,99.1722,13.4314 elif (XYZ[i][0] == 'Pa'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 35.8847,0.547751,23.2948,3.41519,14.1891,16.9235,4.17287,105.251,13.4287 elif (XYZ[i][0] == 'U'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 36.0228,0.5293,23.4128,3.3253,14.9491,16.0927,4.188,100.613,13.3966 elif (XYZ[i][0] == 'Np'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 36.1874,0.511929,23.5964,3.25396,15.6402,15.3622,4.1855,97.4908,13.3573 elif (XYZ[i][0] == 'Pu'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 36.5254,0.499384,23.8083,3.26371,16.7707,14.9455,3.47947,105.98,13.3812 elif (XYZ[i][0] == 'Am'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 36.6706,0.483629,24.0992,3.20647,17.3415,14.3136,3.49331,102.273,13.3592 elif (XYZ[i][0] == 'Cm'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 36.6488,0.465154,24.4096,3.08997,17.399,13.4346,4.21665,88.4834,13.2887 elif (XYZ[i][0] == 'Bk'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 36.7881,0.451018,24.7736,3.04619,17.8919,12.8946,4.23284,86.003,13.2754 elif (XYZ[i][0] == 'Cf'): L1, L2, L3, L4, L5, L6, L7, L8, L9 = 36.9185,0.437533,25.1995,3.00775,18.3317,12.4044,4.24391,83.7881,13.2674 AFF = L1 * np.exp(-L2 *s*s) + L3 * np.exp(-L4 *s*s) + L5 * np.exp(-L6 *s*s) + L7 * np.exp(-L8 *s*s) + L9 SF += AFF * np.exp(-2 * np.pi * 1j * (XYZ[i][1] * h + XYZ[i][2] * k + XYZ[i][3] * l)) Int = np.absolute(SF) ThetaRad0 = np.arcsin(sin) Theta = ThetaRad0 * 2*180/np.pi ThetaRad = Theta * (np.pi/180) if (Theta > 10 and Theta < 180): Lp = (1+(np.cos(ThetaRad)*np.cos(ThetaRad)))/((np.sin(ThetaRad/2)*np.sin(ThetaRad/2))*np.cos(ThetaRad/2)) else: Lp = 1 #print Theta, ThetaRad, Lp, i, n, Inten if (i == n-1 and Theta > 0): P = Int*Int*Lp*m hkls = [h, k, l, Theta, P, m, Lp] XRD.append(hkls) no_planes = len(XRD) SF, AFF, Theta, L1, L2, L3, L4, L5, L6, L7, L8, L9 = 0,0,0,0,0,0,0,0,0,0,0,0 #print "\n", no_planes, "no. of reflection planes." #print hmin, kmin, lmin np.savetxt('XRD_calc_prof' + 'FileName', XRD, fmt='%1.2f') #print '\n...........END.............' #print("\nXRD Pattern calculated in %s seconds." %(time.time() - start_time)) A = np.array(XRD) np.around(A,decimals=2) X = A[:,3] Y = A[:,4] minimum = Y[0] maximum = Y[0] new_max=1 new_min=0 Ynew=[] for i in Y: if i < minimum: minimum = i for i in Y: if i > maximum: maximum = i for i in Y: i = (i - minimum)/(maximum - minimum)*(new_max-new_min) + new_min Ynew.append(i)#print X,Y#plt.xlim(0, 90)#plt.bar(X, Ynew, color="black", width=0.1)#plt.show()#print("\n Plot with intensity bars is made after --- %s seconds ---" % (time.time() - start_time)) def PseudoVoigtFunction(WavNr, Pos, Amp, GammaL, FracL): SigmaG = GammaL / np.sqrt(2*np.log(2)) # Calculate the sigma parameter for the Gaussian distribution from GammaL (coupled in Pseudo-Voigt) LorentzPart = Amp * (GammaL**2 / ((WavNr - Pos)**2 + GammaL**2)) # Lorentzian distribution GaussPart = Amp * np.exp( -((WavNr - Pos)/SigmaG)**2) # Gaussian distribution Fit = FracL * LorentzPart + (1 - FracL) * GaussPart # Linear combination of the two parts (or distributions) return Fit N = 3500 #print("\nCalculating Pseudo-Voigt Profile and Ploting XRD pattern...") TH = [0 for i in range(N)] # N = size of list you want INT = [0 for i in range(N)] for i in range(N): TH[i] = i*0.05 for n in range(len(X)): for i in range(N): if abs(TH[i] - X[n])<5: INT[i] += PseudoVoigtFunction(TH[i], X[n], Ynew[n], 0.1, 0.1) minimum = INT[0] maximum = INT[0] new_max=1 new_min=0 INTnew=[] for i in INT: if i < minimum: minimum = i for i in INT: if i > maximum: maximum = i for i in INT: i = (i - minimum)/(maximum - minimum)*(new_max-new_min) + new_min INTnew.append(i) np.savetxt('XRD_Pattern_PV_' + str(FileName), np.c_[TH, INTnew]) EXP = np.genfromtxt('EXP_Ca2Sn', dtype = ('float16', 'float16')) TH_exp,INT_exp = [],[] for i in range(len(EXP)): TH_exp.append(EXP[i][0]) INT_exp.append(EXP[i][1]) plt.figure(figsize=(16,9)) plt.plot(TH,INTnew, c='b', label='Simulation') plt.plot(TH_exp,INT_exp, c='r', label='Experiment') plt.legend(loc='upper right'); plt.xlim(10, 70) plt.xlabel('2theta (deg)') plt.ylabel('Intensity (a. u.)') plt.show() print("\n Plot with PV calculation made after - %s seconds -." %(time.time() - start_time)) del(XYZ) return#a = FloatRangeSlider(layout=Layout(width='1000px'))a = interact(DistorX, aa = FloatSlider(min=4, max=10, step=0.01, layout=Layout(width='800px')),\ bb = FloatSlider(min=4, max=10, step=0.01, layout=Layout(width='800px')),\ cc = FloatSlider(min=4, max=10, step=0.01, layout=Layout(width='800px'))); Plot with PV calculation made after - 1.04956507683 seconds -.In [ ]:
In [ ]: