diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f11e5b..e3fc7d0 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,8 @@ configure_file(cyl3000fvp5.pos ${CMAKE_CURRENT_BINARY_DIR}/cyl3000fvp5.pos @ONLY configure_file(cylslab3000.pos ${CMAKE_CURRENT_BINARY_DIR}/cylslab3000.pos @ONLY) configure_file(etaGold.txt ${CMAKE_CURRENT_BINARY_DIR}/etaGold.txt @ONLY) configure_file(etaSilver.txt ${CMAKE_CURRENT_BINARY_DIR}/etaSilver.txt @ONLY) +configure_file(etaSilverAnalytic.txt ${CMAKE_CURRENT_BINARY_DIR}/etaSilverAnalytic.txt @ONLY) +configure_file(etaSilverPalik.txt ${CMAKE_CURRENT_BINARY_DIR}/etaSilverPalik.txt @ONLY) configure_file(mstm_guiwindow.ui ${CMAKE_CURRENT_BINARY_DIR}/mstm_guiwindow.ui @ONLY) diff --git a/etaSilverAnalytic.txt b/etaSilverAnalytic.txt new file mode 100755 index 0000000..75e28cf --- /dev/null +++ b/etaSilverAnalytic.txt @@ -0,0 +1,91 @@ +lambda n k +0.0100000000000000 1.99874212285352 7.40160564289515e-07 +0.0200000000000000 1.99496373791465 5.93249304218415e-06 +0.0300000000000000 1.98865049436344 2.00856923709213e-05 +0.0400000000000000 1.97977816906083 4.78237796031694e-05 +0.0500000000000000 1.96831219444569 9.39496422498963e-05 +0.0600000000000000 1.95420696748117 0.000163516145663353 +0.0700000000000000 1.93740490652807 0.000261908274293207 +0.0800000000000000 1.91783520880517 0.000394940720131893 +0.0900000000000000 1.89541224242518 0.000568976766003941 +0.100000000000000 1.87003348167680 0.000791076435636021 +0.110000000000000 1.84157685895607 0.00106918505900473 +0.120000000000000 1.80989735642963 0.00141237821762450 +0.130000000000000 1.77482258702928 0.00183118647403141 +0.140000000000000 1.73614700450444 0.00233803504447199 +0.150000000000000 1.69362421378938 0.00294785264195312 +0.160000000000000 1.64695658740033 0.00367893559804121 +0.170000000000000 1.59578096190723 0.00455420855720960 +0.180000000000000 1.53964846170926 0.00560312245782817 +0.190000000000000 1.47799522295529 0.00686461815031610 +0.200000000000000 1.41009844732108 0.00839195805439517 +0.210000000000000 1.33500765672896 0.0102610243716721 +0.220000000000000 1.25143152158357 0.0125855176537332 +0.230000000000000 1.15753908229747 0.0155471652403854 +0.240000000000000 1.05057962634948 0.0194626090377881 +0.250000000000000 0.926065577974920 0.0249555548554986 +0.260000000000000 0.775684807682064 0.0335132110894466 +0.270000000000000 0.580193703304924 0.0501754876831495 +0.280000000000000 0.268709074846921 0.120825004070894 +0.290000000000000 0.0744887505624970 0.484239038793258 +0.300000000000000 0.0549251629349535 0.727009425670726 +0.310000000000000 0.0482298084669144 0.913498864267024 +0.320000000000000 0.0451717819368366 1.07278258652603 +0.330000000000000 0.0437226143632531 1.21549992488752 +0.340000000000000 0.0431530234438622 1.34689796418303 +0.350000000000000 0.0431304964260104 1.47000389708942 +0.360000000000000 0.0434799352355059 1.58674361280351 +0.370000000000000 0.0440996700890492 1.69842749464179 +0.380000000000000 0.0449263229086013 1.80599203432380 +0.390000000000000 0.0459181900705482 1.91013212769992 +0.400000000000000 0.0470466346082099 2.01137892751222 +0.410000000000000 0.0482913014138866 2.11014830644610 +0.420000000000000 0.0496373031388701 2.20677241771830 +0.430000000000000 0.0510734868153768 2.30152102443833 +0.440000000000000 0.0525913241260602 2.39461636853598 +0.450000000000000 0.0541841772767239 2.48624381273028 +0.460000000000000 0.0558467994703216 2.57655963175531 +0.470000000000000 0.0575749865868963 2.66569683000611 +0.480000000000000 0.0593653290240664 2.75376956130967 +0.490000000000000 0.0612150315026381 2.84087653848472 +0.500000000000000 0.0631217799867603 2.92710369970778 +0.510000000000000 0.0650836418940100 3.01252631934372 +0.520000000000000 0.0670989902343180 3.09721069752415 +0.530000000000000 0.0691664452177764 3.18121552613657 +0.540000000000000 0.0712848287962605 3.26459300330508 +0.550000000000000 0.0734531289050373 3.34738975027905 +0.560000000000000 0.0756704710652806 3.42964757155490 +0.570000000000000 0.0779360956333116 3.51140408949253 +0.580000000000000 0.0802493394251032 3.59269327761261 +0.590000000000000 0.0826096207624066 3.67354591146684 +0.600000000000000 0.0850164272178162 3.75398995196845 +0.610000000000000 0.0874693055058289 3.83405087301163 +0.620000000000000 0.0899678530930330 3.91375194285001 +0.630000000000000 0.0925117111951267 3.99311446687103 +0.640000000000000 0.0951005589000495 4.07215799796532 +0.650000000000000 0.0977341082111723 4.15090051955538 +0.660000000000000 0.100412099846559 4.22935860544490 +0.670000000000000 0.103134299662948 4.30754755992730 +0.680000000000000 0.105900495598587 4.38548154100979 +0.690000000000000 0.108710495049113 4.46317366913715 +0.700000000000000 0.111564122606523 4.54063612341488 +0.710000000000000 0.114461218103929 4.61788022701646 +0.720000000000000 0.117401634918919 4.69491652319959 +0.730000000000000 0.120385238496467 4.77175484314199 +0.740000000000000 0.123411905058980 4.84840436662883 +0.750000000000000 0.126481520476390 4.92487367647474 +0.760000000000000 0.129593979273616 5.00117080743895 +0.770000000000000 0.132749183756328 5.07730329028678 +0.780000000000000 0.135947043238885 5.15327819156209 +0.790000000000000 0.139187473360812 5.22910214956021 +0.800000000000000 0.142470395480209 5.30478140692704 +0.810000000000000 0.145795736134189 5.38032184025495 +0.820000000000000 0.149163426557888 5.45572898700022 +0.830000000000000 0.152573402254762 5.53100807000590 +0.840000000000000 0.156025602611934 5.60616401987992 +0.850000000000000 0.159519970555181 5.68120149544840 +0.860000000000000 0.163056452238887 5.75612490247800 +0.870000000000000 0.166634996766918 5.83093841083923 +0.880000000000000 0.170255555940882 5.90564597026278 +0.890000000000000 0.173918084032711 5.98025132482400 +0.900000000000000 0.177622537578868 6.05475802627589 diff --git a/etaSilverPalik.txt b/etaSilverPalik.txt new file mode 100755 index 0000000..2ffcab2 --- /dev/null +++ b/etaSilverPalik.txt @@ -0,0 +1,244 @@ +lambda n k +1.240E-4 0.9990 1.29E-6 +1.550E-4 1.000 2.92E-6 +2.066E-4 1.002 8.36E-6 +2.480E-4 1.001 1.52E-5 +2.755E-4 1.001 2.21E-5 +3.099E-4 1.003 3.57E-5 +3.444E-4 1.003 3.24E-5 +3.542E-4 1.003 1.72E-5 +4.133E-4 1.001 1.43E-5 +4.959E-4 1.001 2.40E-5 +6.199E-4 1.001 4.72E-5 +8.265E-4 0.999 1.21E-4 +12.40E-4 0.998 5.23E-4 +15.50E-4 0.997 1.08E-3 +16.75E-4 0.998 1.42E-3 +20.66E-4 0.997 2.69E-3 +24.80E-4 0.997 4.57E-3 +30.99E-4 0.998 8.82E-3 +33.51E-4 1.007 8.23E-3 +35.42E-4 1.001 1.68E-3 +41.33E-4 0.996 2.32E-3 +44.28E-4 0.994 2.70E-3 +47.68E-4 0.992 3.11E-3 +51.66E-4 0.989 3.50E-3 +56.35E-4 0.987 3.45E-3 +61.99E-4 0.982 3.77E-3 +68.88E-4 0.978 4.31E-3 +72.93E-4 0.973 4.42E-3 +77.49E-4 0.968 4.38E-3 +82.65E-4 0.963 4.07E-3 +88.56E-4 0.955 3.54E-3 +95.37E-4 0.943 3.66E-3 +103.3E-4 0.926 6.22E-3 +112.7E-4 0.902 1.72E-2 +118.1E-4 0.890 2.61E-2 +124.0E-4 0.876 3.82E-2 +130.5E-4 0.861 5.65E-2 +137.8E-4 0.849 8.24E-2 +145.9E-4 0.846 0.111 +155.0E-4 0.848 0.139 +158.9E-4 0.851 0.149 +163.1E-4 0.853 0.158 +167.5E-4 0.853 0.166 +172.2E-4 0.851 0.181 +177.1E-4 0.859 0.197 +182.3E-4 0.871 0.208 +187.8E-4 0.883 0.211 +193.7E-4 0.885 0.210 +200.0E-4 0.881 0.211 +206.6E-4 0.873 0.221 +213.8E-4 0.868 0.237 +221.4E-4 0.871 0.259 +229.6E-4 0.885 0.274 +233.9E-4 0.890 0.275 +238.4E-4 0.889 0.276 +243.1E-4 0.886 0.281 +248.0E-4 0.884 0.290 +253.0E-4 0.885 0.200 +258.3E-4 0.888 0.309 +263.8E-4 0.893 0.317 +269.5E-4 0.896 0.323 +281.8E-4 0.899 0.334 +295.2E-4 0.897 0.349 +309.9E-4 0.896 0.368 +317.9E-4 0.895 0.378 +326.3E-4 0.892 0.388 +335.1E-4 0.885 0.400 +344.4E-4 0.876 0.418 +354.2E-4 0.865 0.454 +364.6E-4 0.879 0.489 +375.7E-4 0.899 0.514 +387.4E-4 0.921 0.528 +399.9E-4 0.932 0.534 +413.2E-4 0.931 0.541 +427.5E-4 0.919 0.557 +435.0E-4 0.911 0.572 +442.8E-4 0.902 0.590 +450.8E-4 0.851 0.616 +459.2E-4 0.886 0.650 +459.2E-4 0.882 0.399 +467.9E-4 0.886 0.421 +476.9E-4 0.887 0.444 +486.2E-4 0.891 0.468 +506.1E-4 0.906 0.522 +527.6E-4 0.943 0.584 +539.1E-4 0.980 0.614 +551.0E-4 1.029 0.624 +563.6E-4 1.075 0.615 +576.7E-4 1.104 0.584 +590.4E-4 1.109 0.561 +604.8E-4 1.105 0.549 +619.9E-4 1.098 0.548 +652.6E-4 1.096 0.565 +688.8E-4 1.101 0.593 +729.3E-4 1.121 0.635 +774.9E-4 1.167 0.676 +799.9E-4 1.202 0.691 +826.6E-4 1.243 0.693 +855.1E-4 1.281 0.679 +885.6E-4 1.308 0.656 +918.4E-4 1.322 0.628 +953.7E-4 1.322 0.603 +991.9E-4 1.315 0.588 +0.1025 1.308 0.581 +0.1051 1.304 0.578 +0.1078 1.300 0.573 +0.1107 1.293 0.566 +0.1137 1.280 0.560 +0.1170 1.265 0.560 +0.1204 1.252 0.564 +0.1240 1.241 0.568 +0.1278 1.229 0.566 +0.1348 1.182 0.550 +0.1378 1.149 0.552 +0.1409 1.112 0.563 +0.1442 1.073 0.581 +0.1476 1.032 0.610 +0.1512 0.993 0.653 +0.1550 0.962 0.706 +0.1590 0.940 0.770 +0.1631 0.935 0.832 +0.1675 0.936 0.892 +0.1722 0.942 0.951 +0.1771 0.953 1.01 +0.1823 0.969 1.07 +0.1879 0.995 1.13 +0.1937 1.028 1.18 +0.1968 1.048 1.21 +0.2000 1.072 1.24 +0.2033 1.098 1.26 +0.2066 1.125 1.27 +0.2138 1.173 1.29 +0.2214 1.208 1.30 +0.2296 1.238 1.31 +0.2384 1.265 1.33 +0.2480 1.298 1.35 +0.2530 1.320 1.35 +0.2583 1.343 1.35 +0.2638 1.372 1.35 +0.2695 1.404 1.33 +0.2755 1.441 1.31 +0.2818 1.476 1.26 +0.2883 1.502 1.19 +0.2952 1.519 1.08 +0.2988 1.522 0.992 +0.3024 1.496 0.882 +0.3061 1.432 0.766 +0.3100 1.323 0.647 +0.3115 1.246 0.586 +0.3139 1.149 0.540 +0.3155 1.044 0.514 +0.3179 0.932 0.504 +0.3195 0.815 0.526 +0.3220 0.708 0.565 +0.3237 0.616 0.609 +0.3263 0.526 0.663 +0.3306 0.371 0.813 +0.3324 0.321 0.902 +0.3351 0.294 0.986 +0.3397 0.259 1.12 +0.3444 0.238 1.24 +0.3542 0.209 1.44 +0.3647 0.186 1.61 +0.3757 0.200 1.67 +0.3875 0.192 1.81 +0.4000 0.173 1.95 +0.4133 0.173 2.11 +0.4275 0.160 2.26 +0.4428 0.157 2.40 +0.4592 0.144 2.56 +0.4769 0.132 2.72 +0.4959 0.130 2.88 +0.5166 0.130 3.07 +0.5391 0.129 3.25 +0.5636 0.120 3.45 +0.5904 0.121 3.66 +0.6199 0.131 3.88 +0.6526 0.140 4.15 +0.6888 0.140 4.44 +0.7293 0.148 4.74 +0.7749 0.143 5.09 +0.8266 0.145 5.50 +0.8856 0.163 5.95 +0.9537 0.198 6.43 +1.033 0.226 6.99 +1.127 0.251 7.67 +1.240 0.329 8.49 +1.265 0.375 7.78 +1.291 0.383 7.92 +1.305 0.358 8.95 +1.319 0.392 8.06 +1.348 0.401 8.21 +1.378 0.411 8.37 +1.3780 0.396 9.48 +1.409 0.421 8.37 +1.442 0.431 8.70 +1.459 0.446 10.1 +1.476 0.442 8.88 +1.512 0.455 9.08 +1.550 0.469 9.32 +1.5500 0.514 10.8 +1.590 0.485 9.57 +1.631 0.501 9.84 +1.653 0.624 11.5 +1.675 0.519 10.1 +1.722 0.537 10.4 +1.771 0.557 10.7 +1.7710 0.844 12.2 +1.823 0.578 11.1 +1.879 0.600 11.4 +1.907 0.873 13.3 +1.937 0.624 11.8 +2.000 0.650 12.2 +2.066 0.668 12.6 +2.0660 1.064 14.4 +2.138 0.729 13.0 +2.214 0.774 13.5 +2.296 0.823 14.0 +2.384 0.878 14.5 +2.480 0.939 15.1 +2.583 1.007 15.7 +2.695 1.083 16.4 +2.818 1.168 17.1 +2.952 1.265 17.9 +3.100 1.387 18.8 +3.263 1.536 19.8 +3.444 1.710 20.9 +3.647 1.915 22.1 +3.875 2.160 23.5 +4.133 2.446 25.1 +4.428 2.786 26.9 +4.769 3.202 29.0 +5.166 3.732 31.3 +5.636 4.425 34.0 +6.199 5.355 37.0 +6.526 5.960 38.6 +6.888 6.670 40.4 +7.293 7.461 42.5 +7.749 8.376 44.8 +8.266 9.441 47.1 +8.856 10.69 49.4 +9.537 12.21 52.2 +9.919 13.11 53.7 diff --git a/mstm-gui.py b/mstm-gui.py index 97aa743..36a2a25 100755 --- a/mstm-gui.py +++ b/mstm-gui.py @@ -17,277 +17,314 @@ from matplotlib.patches import Patch from pylab import * class GuiWindow(QtGui.QMainWindow): - - params = ParameterClass('msinput.inp') - - def setParams(self): - #update the Gui based on values in the parameters structure - self.ui.spinStartLambda.setValue(self.params.minLambda) - self.ui.spinEndLambda.setValue(self.params.maxLambda) - self.ui.spinNearFieldLambda.setValue(self.params.snapshotLambda) - self.ui.spinNumSamples.setValue(self.params.nSamples) - self.ui.spinNumSpheres.setValue(int(self.params['number_spheres'])) - #near field stuff - self.ui.cmbPlaneSlice.setCurrentIndex(int(self.params['near_field_plane_coord']) - 1) - verts = self.params['near_field_plane_vertices'] - self.ui.spinNearFieldWidth.setValue(verts[2] - verts[0]) - self.ui.spinNearFieldHeight.setValue(verts[3] - verts[1]) - self.ui.spinNearFieldSteps.setValue(self.params.nSteps) - - fi = QtCore.QFileInfo(self.params.matFilename) - self.ui.txtMaterial.setText(fi.baseName()) - - #update global parameters for the dimer simulation - self.ui.spinSpacing.setValue(self.params.d) - self.ui.spinRadius.setValue(self.params.a) - - def getParams(self): - self.params.minLambda = self.ui.spinStartLambda.value() - self.params.maxLambda = self.ui.spinEndLambda.value() - self.params.snapshotLambda = self.ui.spinNearFieldLambda.value() - self.params.nSamples = self.ui.spinNumSamples.value() - self.params.nSpheres = self.ui.spinNumSpheres.value() - - #incident light properties - if self.ui.chkRandomOrientation.isChecked(): - self.params['fixed_or_random_orientation'] = 1 - else: - self.params['fixed_or_random_orientation'] = 0 - self.params['incident_azimuth_angle_deg'] = self.ui.spinAlpha.value() - self.params['incident_polar_angle_deg'] = self.ui.spinBeta.value() - self.params['polarization_angle_deg'] = self.ui.spinGamma.value() - - self.params.showOutput = self.ui.chkShowOutput.isChecked() - - self.params.inWater = self.ui.chkInWater.isChecked() - - - #near field - if self.ui.chkNearField.isChecked(): - self.params['calculate_near_field'] = 1 - else: - self.params['calculate_near_field'] = 0 - self.params['near_field_plane_coord'] = self.ui.cmbPlaneSlice.currentIndex() + 1 - width = (self.ui.spinNearFieldWidth.value()/2) - height = (self.ui.spinNearFieldHeight.value()/2) - self.params['near_field_plane_vertices'] = [-width, -height, width, height] - dx = self.ui.spinNearFieldWidth.value() / (self.ui.spinNearFieldSteps.value() - 1) - self.params['spacial_step_size'] = dx - - #global parameters for dimers - self.params.d = self.ui.spinSpacing.value() - self.params.a = self.ui.spinRadius.value() - - return self.params - - def simulate(self): - self.results = RunSimulation(True) - - #plot results of interest - wl = self.results['lambda'] - - if int(self.params['fixed_or_random_orientation']) == 0: - unpol = self.results['extinction_unpolarized'] - para = self.results['extinction_parallel'] - perp = self.results['extinction_perpendicular'] - plt.plot(wl, unpol, 'r-', label='unpolarized') - plt.plot(wl, para, 'g-', label='parallel') - plt.plot(wl, perp, 'b-', label='perpendicular') - else: - total = self.results['extinction_total'] - plt.plot(wl, total, 'r-', label='extinction') - - #plot the near field maximum values if available - - if self.params['calculate_near_field']: - maxima = self.results.maxNearField - print(len(wl)) - print(len(maxima)) - plt.plot(wl, maxima) - - - - plt.legend(loc = 'upper left') - plt.ylabel('Extinction') - plt.xlabel('Wavelength (um)') - plt.show() - - def func3(self, x,y): - return (1- x/2 + x**5 + y**3)*exp(-x**2-y**2) - - def snapshot(self): - - self.results = RunSimulation(False) - - if self.params['calculate_near_field']: - #verts = self.params['near_field_plane_vertices'] - #dx = (verts[2] - verts[0])/(self.params.nSteps) - #x = arange(verts[0], verts[2], dx) - #print(len(x)) - #y = arange(verts[1], verts[3], dx) - #X, Y = meshgrid(x, y) - E = array(self.results.gridNearField) - #pcolor(X, Y, E, cmap=cm.RdBu) - #colorbar() - #axis([verts[0], verts[2], verts[1], verts[3]]) - - pcolor(E, cmap=cm.RdBu) - colorbar() - - # make these smaller to increase the resolution - #dx, dy = 0.05, 0.05 - - #x = arange(-3.0, 3.0001, dx) - #y = arange(-3.0, 3.0001, dy) - #X,Y = meshgrid(x, y) - - #Z = self.func3(X, Y) - #pcolor(X, Y, Z, cmap=cm.RdBu, vmax=abs(Z).max(), vmin=-abs(Z).max()) - #colorbar() - #axis([-3,3,-3,3]) - - show() - - def saveresults(self): - fileName = QtGui.QFileDialog.getSaveFileName(w, 'Save Spectral Results', '', 'DAT data files (*.dat)') - if fileName: - self.results.saveFile(fileName) - - def loadmaterial(self): - fileName = QtGui.QFileDialog.getOpenFileName(w, 'Load Material Refractive Index', '', 'TXT data files (*.txt)') - if fileName: - self.params.matFilename = fileName - - fi = QtCore.QFileInfo(fileName) - self.ui.txtMaterial.setText(fi.baseName()) - - def spherenum(self, i): - self.ui.tblSpheres.setRowCount(i) - print(i) - - def __init__(self): - QtGui.QWidget.__init__(self) - - #dimer-specific settings - self.params['number_spheres'] = 2 - self.params['sphere_position_file'] = '' - - #load the UI window - self.ui = uic.loadUi('mstm_guiwindow.ui') - #update the displayed parameters - self.setParams() - #display the UI - self.ui.show() - - #controls - self.connect(self.ui.btnSimulate, QtCore.SIGNAL("clicked()"), self.simulate) - self.connect(self.ui.btnEvaluateNearField, QtCore.SIGNAL("clicked()"), self.snapshot) - self.connect(self.ui.mnuSaveResults, QtCore.SIGNAL("triggered()"), self.saveresults) - self.connect(self.ui.mnuLoadMaterial, QtCore.SIGNAL("triggered()"), self.loadmaterial) - self.connect(self.ui.spinNumSpheres, QtCore.SIGNAL("valueChanged(int)"), self.spherenum) + + params = ParameterClass('msinput.inp') + + def setParams(self): + #update the Gui based on values in the parameters structure + self.ui.spinStartLambda.setValue(self.params.minLambda) + self.ui.spinEndLambda.setValue(self.params.maxLambda) + self.ui.spinNearFieldLambda.setValue(self.params.snapshotLambda) + self.ui.spinNumSamples.setValue(self.params.nSamples) + self.ui.spinNumSpheres.setValue(int(self.params['number_spheres'])) + #near field stuff + self.ui.cmbPlaneSlice.setCurrentIndex(int(self.params['near_field_plane_coord']) - 1) + verts = self.params['near_field_plane_vertices'] + self.ui.spinNearFieldWidth.setValue(verts[2] - verts[0]) + self.ui.spinNearFieldHeight.setValue(verts[3] - verts[1]) + self.ui.spinNearFieldSteps.setValue(self.params.nSteps) + + fi = QtCore.QFileInfo(self.params.matFilename) + self.ui.txtMaterial.setText(fi.baseName()) + + #update global parameters for the dimer simulation + self.ui.spinSpacing.setValue(self.params.d) + self.ui.spinRadius.setValue(self.params.a) + + def getParams(self): + self.params.minLambda = self.ui.spinStartLambda.value() + self.params.maxLambda = self.ui.spinEndLambda.value() + self.params.snapshotLambda = self.ui.spinNearFieldLambda.value() + self.params.nSamples = self.ui.spinNumSamples.value() + self.params['number_spheres'] = self.ui.spinNumSpheres.value() + + #incident light properties + if self.ui.chkRandomOrientation.isChecked(): + self.params['fixed_or_random_orientation'] = 1 + else: + self.params['fixed_or_random_orientation'] = 0 + self.params['incident_azimuth_angle_deg'] = self.ui.spinAlpha.value() + self.params['incident_polar_angle_deg'] = self.ui.spinBeta.value() + self.params['polarization_angle_deg'] = self.ui.spinGamma.value() + + self.params.showOutput = self.ui.chkShowOutput.isChecked() + self.params.inWater = self.ui.chkInWater.isChecked() + + + #near field + if self.ui.chkNearField.isChecked(): + self.params['calculate_near_field'] = 1 + else: + self.params['calculate_near_field'] = 0 + self.params['near_field_plane_coord'] = self.ui.cmbPlaneSlice.currentIndex() + 1 + width = (self.ui.spinNearFieldWidth.value()/2) + height = (self.ui.spinNearFieldHeight.value()/2) + self.params['near_field_plane_vertices'] = [-width, -height, width, height] + dx = self.ui.spinNearFieldWidth.value() / (self.ui.spinNearFieldSteps.value() - 1) + self.params['spacial_step_size'] = dx + + #global parameters for dimers + self.params.d = self.ui.spinSpacing.value() + self.params.a = self.ui.spinRadius.value() + + #get the spheres from the table + nSpheres = self.ui.tblSpheres.rowCount() + print("Row count: " + str(nSpheres)) + print("Orientatino: " + str(self.params['fixed_or_random_orientation'])) + + self.params.sphereList = [] + for s in range(nSpheres): + a = float(self.ui.tblSpheres.item(s, 0).text()) + x = float(self.ui.tblSpheres.item(s, 1).text()) + y = float(self.ui.tblSpheres.item(s, 2).text()) + z = float(self.ui.tblSpheres.item(s, 3).text()) + self.params.addSphere(a, x, y, z) + + return self.params + + def simulate(self): + self.results = RunSimulation(True) + + #plot results of interest + wl = self.results['lambda'] + + if int(self.params['fixed_or_random_orientation']) == 0: + unpol = self.results['extinction_unpolarized'] + para = self.results['extinction_parallel'] + perp = self.results['extinction_perpendicular'] + plt.plot(wl, unpol, 'r-', label='unpolarized') + plt.plot(wl, para, 'g-', label='parallel') + plt.plot(wl, perp, 'b-', label='perpendicular') + else: + total = self.results['extinction_total'] + plt.plot(wl, total, 'r-', label='extinction') + + #plot the near field maximum values if available + + if self.params['calculate_near_field']: + maxima = self.results.maxNearField + print(len(wl)) + print(len(maxima)) + plt.plot(wl, maxima) + + + + plt.legend(loc = 'upper left') + plt.ylabel('Extinction') + plt.xlabel('Wavelength (um)') + plt.show() + + def func3(self, x,y): + return (1- x/2 + x**5 + y**3)*exp(-x**2-y**2) + + def snapshot(self): + + self.results = RunSimulation(False) + + if self.params['calculate_near_field']: + #verts = self.params['near_field_plane_vertices'] + #dx = (verts[2] - verts[0])/(self.params.nSteps) + #x = arange(verts[0], verts[2], dx) + #print(len(x)) + #y = arange(verts[1], verts[3], dx) + #X, Y = meshgrid(x, y) + E = array(self.results.gridNearField) + #pcolor(X, Y, E, cmap=cm.RdBu) + #colorbar() + #axis([verts[0], verts[2], verts[1], verts[3]]) + + pcolor(E, cmap=cm.RdBu) + colorbar() + print("Maximum enhancement: " + str(abs(E).max())) + + # make these smaller to increase the resolution + #dx, dy = 0.05, 0.05 + + #x = arange(-3.0, 3.0001, dx) + #y = arange(-3.0, 3.0001, dy) + #X,Y = meshgrid(x, y) + + #Z = self.func3(X, Y) + #pcolor(X, Y, Z, cmap=cm.RdBu, vmax=abs(Z).max(), vmin=-abs(Z).max()) + #colorbar() + #axis([-3,3,-3,3]) + + show() + + def saveresults(self): + fileName = QtGui.QFileDialog.getSaveFileName(w, 'Save Spectral Results', '', 'DAT data files (*.dat)') + if fileName: + self.results.saveFile(fileName) + + def loadmaterial(self): + fileName = QtGui.QFileDialog.getOpenFileName(w, 'Load Material Refractive Index', '', 'TXT data files (*.txt)') + if fileName: + self.params.matFilename = fileName + + fi = QtCore.QFileInfo(fileName) + self.ui.txtMaterial.setText(fi.baseName()) + + def spherenum(self, i): + self.ui.tblSpheres.setRowCount(i) + print(i) + + def updatedimers(self): + + d = self.ui.spinSpacing.value() + a = self.ui.spinRadius.value() + + self.ui.tblSpheres.setItem(0, 0, QtGui.QTableWidgetItem(str(a))) + self.ui.tblSpheres.setItem(0, 1, QtGui.QTableWidgetItem(str(-(d + 2*a)/2))) + self.ui.tblSpheres.setItem(0, 2, QtGui.QTableWidgetItem(str(0.0))) + self.ui.tblSpheres.setItem(0, 3, QtGui.QTableWidgetItem(str(0.0))) + + self.ui.tblSpheres.setItem(1, 0, QtGui.QTableWidgetItem(str(a))) + self.ui.tblSpheres.setItem(1, 1, QtGui.QTableWidgetItem(str((d + 2*a)/2))) + self.ui.tblSpheres.setItem(1, 2, QtGui.QTableWidgetItem(str(0.0))) + self.ui.tblSpheres.setItem(1, 3, QtGui.QTableWidgetItem(str(0.0))) + + + def __init__(self): + QtGui.QWidget.__init__(self) + + #dimer-specific settings + self.params['number_spheres'] = 2 + self.params['sphere_position_file'] = '' + + #load the UI window + self.ui = uic.loadUi('mstm_guiwindow.ui') + + + + #controls + self.connect(self.ui.btnSimulate, QtCore.SIGNAL("clicked()"), self.simulate) + self.connect(self.ui.btnEvaluateNearField, QtCore.SIGNAL("clicked()"), self.snapshot) + self.connect(self.ui.mnuSaveResults, QtCore.SIGNAL("triggered()"), self.saveresults) + self.connect(self.ui.mnuLoadMaterial, QtCore.SIGNAL("triggered()"), self.loadmaterial) + self.connect(self.ui.spinNumSpheres, QtCore.SIGNAL("valueChanged(int)"), self.spherenum) + self.connect(self.ui.spinRadius, QtCore.SIGNAL("valueChanged(double)"), self.updatedimers) + self.connect(self.ui.spinSpacing, QtCore.SIGNAL("valueChanged(double)"), self.updatedimers) + + #update the displayed parameters + self.setParams() + + #update the sphere table with the default dimer values + self.updatedimers() + + #display the UI + self.ui.show() class ProgressBar(QtGui.QWidget): - def __init__(self, parent=None, total=20): - super(ProgressBar, self).__init__(parent) - self.name_line = QtGui.QLineEdit() + def __init__(self, parent=None, total=20): + super(ProgressBar, self).__init__(parent) + self.name_line = QtGui.QLineEdit() - self.progressbar = QtGui.QProgressBar() - self.progressbar.setMinimum(1) - self.progressbar.setMaximum(total) + self.progressbar = QtGui.QProgressBar() + self.progressbar.setMinimum(1) + self.progressbar.setMaximum(total) - main_layout = QtGui.QGridLayout() - main_layout.addWidget(self.progressbar, 0, 0) + main_layout = QtGui.QGridLayout() + main_layout.addWidget(self.progressbar, 0, 0) - self.setLayout(main_layout) - self.setWindowTitle("Progress") + self.setLayout(main_layout) + self.setWindowTitle("Progress") - def update_progressbar(self, val): - self.progressbar.setValue(val) - + def update_progressbar(self, val): + self.progressbar.setValue(val) + def RunSimulation(spectralSim = True): - - #set the parameters based on the UI - parameters = w.getParams() - - - - #load the material - material = MaterialClass(parameters.matFilename) - - #add water if necessary - if parameters.inWater: - material.addSolution(1.33) - - #for a spectral simulation, set the range and number of samples - if spectralSim: - minLambda = parameters.minLambda - maxLambda = parameters.maxLambda - nSamples = parameters.nSamples - else: - minLambda = parameters.snapshotLambda - maxLambda = parameters.snapshotLambda - nSamples = 1 - - #store the simulation results - results = SimParserClass(parameters) - - #create a progress bar - pbar = ProgressBar(total=nSamples) - pbar.show() - - #for each wavelength in the material - for i in range(nSamples): - - if i == 0: - l = minLambda - else: - l = minLambda + i*(maxLambda - minLambda)/(nSamples - 1) - - - - #set the computed parameters - m = material[l] - n = m.n - parameters['real_ref_index_scale_factor'] = n.real - parameters['imag_ref_index_scale_factor'] = n.imag - parameters['length_scale_factor'] = (2.0 * 3.14159)/l - parameters['scattering_plane_angle_deg'] = gamma; - parameters['near_field_output_data'] = 0 - - a = parameters.a; - d = parameters.d; - parameters.clearSpheres() - parameters.addSphere(a, -(d + 2*a)/2, 0, 0) - parameters.addSphere(a, (d + 2*a)/2, 0, 0) - - #save the scripted input file - parameters.saveFile(l, 'scriptParams.inp') - - #run the binary - from subprocess import call - if parameters.showOutput: - call(["./ms-tmatrix", "scriptParams.inp"]) - else: - devnull = open('/dev/null', 'w') - call(["./ms-tmatrix", "scriptParams.inp"], stdout=devnull) - - #parse the simulation results - results.parseSimFile(l, 'test.dat') - - if parameters['calculate_near_field']: - results.parseNearField('nf-temp.dat') - - - #update the progress bar - pbar.update_progressbar(i+1) - - #return the results - return results; - - - + + #set the parameters based on the UI + parameters = w.getParams() + + + + #load the material + material = MaterialClass(parameters.matFilename) + + #add water if necessary + if parameters.inWater: + material.addSolution(1.33) + + #for a spectral simulation, set the range and number of samples + if spectralSim: + minLambda = parameters.minLambda + maxLambda = parameters.maxLambda + nSamples = parameters.nSamples + else: + minLambda = parameters.snapshotLambda + maxLambda = parameters.snapshotLambda + nSamples = 1 + + #store the simulation results + results = SimParserClass(parameters) + + #create a progress bar + pbar = ProgressBar(total=nSamples) + pbar.show() + + #for each wavelength in the material + for i in range(nSamples): + + if i == 0: + l = minLambda + else: + l = minLambda + i*(maxLambda - minLambda)/(nSamples - 1) + + #set the computed parameters + m = material[l] + n = m.n + parameters['real_ref_index_scale_factor'] = n.real + parameters['imag_ref_index_scale_factor'] = n.imag + parameters['length_scale_factor'] = (2.0 * 3.14159)/l + parameters['scattering_plane_angle_deg'] = gamma; + parameters['near_field_output_data'] = 0 + #parameters['number_spheres'] = 1 + + #a = parameters.a; + #d = parameters.d; + #parameters.clearSpheres() + #parameters.addSphere(a, -(d + 2*a)/2, 0, 0) + #parameters.addSphere(a, (d + 2*a)/2, 0, 0) + + #save the scripted input file + parameters.saveFile(l, 'scriptParams.inp') + + #run the binary + from subprocess import call + if parameters.showOutput: + call(["./ms-tmatrix", "scriptParams.inp"]) + else: + devnull = open('/dev/null', 'w') + call(["./ms-tmatrix", "scriptParams.inp"], stdout=devnull) + + #parse the simulation results + results.parseSimFile(l, 'test.dat') + + if parameters['calculate_near_field']: + results.parseNearField('nf-temp.dat') + + + #update the progress bar + pbar.update_progressbar(i+1) + + #return the results + return results; + + + diff --git a/mstm_guiwindow.ui b/mstm_guiwindow.ui index c132e51..aed2101 100755 --- a/mstm_guiwindow.ui +++ b/mstm_guiwindow.ui @@ -651,6 +651,12 @@ 22 + + 3 + + + 0.001000000000000 + @@ -679,7 +685,7 @@ - 89 + 80 30 @@ -691,7 +697,7 @@ - pX + x diff --git a/mstm_materials.py b/mstm_materials.py index 6b3e945..712e5fe 100755 --- a/mstm_materials.py +++ b/mstm_materials.py @@ -80,11 +80,11 @@ class MaterialClass: #open the real refractive index file irFID = open(fileName, 'r') #read the first line to get the units (wavelength (um) or wavenumber (cm^2)) - lightUnits = irFID.readline().split('\t', 1)[0] + lightUnits = irFID.readline().split()[0] #load the material for line in irFID: - l, n, k = map(float, line.split("\t")) + l, n, k = map(float, line.split()) #if units are in wavenumber, convert to wavelength if lightUnits == "nu": diff --git a/mstm_simparser.py b/mstm_simparser.py index a3656ee..9babb7d 100755 --- a/mstm_simparser.py +++ b/mstm_simparser.py @@ -82,7 +82,7 @@ class SimParserClass: self.gridNearField[y].append(values[2]) E = array(self.gridNearField) - self.maxNearField.append(pow(E.max(), 2)) + self.maxNearField.append(abs(E).max()) def saveFile(self, fileName): -- libgit2 0.21.4