Changeset 14e9eb3 in sasview for calculator
- Timestamp:
- May 28, 2010 1:24:47 PM (15 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 25a2ee3
- Parents:
- 2882fb5
- Location:
- calculator
- Files:
-
- 4 added
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
calculator/docs/sphinx/_build/html/_sources/api/index.txt
rbeb374a r14e9eb3 15 15 16 16 sld_calculator.rst 17 slit_length_calculator.rst -
calculator/docs/sphinx/_build/html/api/index.html
rbeb374a r14e9eb3 60 60 <tr class="field"><th class="field-name">Release:</th><td class="field-body">0.1</td> 61 61 </tr> 62 <tr class="field"><th class="field-name">Date:</th><td class="field-body">May 2 7, 2010</td>62 <tr class="field"><th class="field-name">Date:</th><td class="field-body">May 28, 2010</td> 63 63 </tr> 64 64 </tbody> … … 68 68 <li class="toctree-l1"><a class="reference internal" href="sld_calculator.html">Sld Calculator</a><ul> 69 69 <li class="toctree-l2"><a class="reference internal" href="sld_calculator.html#module-sans.calculator.sld_calculator"><tt class="docutils literal"><span class="pre">sans.calculator.sld_calculator</span></tt></a></li> 70 </ul> 71 </li> 72 <li class="toctree-l1"><a class="reference internal" href="slit_length_calculator.html">Slit Length Calculator</a><ul> 73 <li class="toctree-l2"><a class="reference internal" href="slit_length_calculator.html#module-sans.calculator.slit_length_calculator"><tt class="docutils literal"><span class="pre">sans.calculator.slit_length_calculator</span></tt></a></li> 70 74 </ul> 71 75 </li> -
calculator/docs/sphinx/_build/html/api/sld_calculator.html
rbeb374a r14e9eb3 25 25 <link rel="top" title="calculator v0.1.0 documentation" href="../index.html" /> 26 26 <link rel="up" title="Reference" href="index.html" /> 27 <link rel="next" title="Slit Length Calculator" href="slit_length_calculator.html" /> 27 28 <link rel="prev" title="Reference" href="index.html" /> 28 29 </head> … … 37 38 <a href="../py-modindex.html" title="Python Module Index" 38 39 >modules</a> |</li> 40 <li class="right" > 41 <a href="slit_length_calculator.html" title="Slit Length Calculator" 42 accesskey="N">next</a> |</li> 39 43 <li class="right" > 40 44 <a href="index.html" title="Reference" … … 54 58 <div class="section" id="module-sans.calculator.sld_calculator"> 55 59 <span id="sans-calculator-sld-calculator"></span><h2><a class="reference internal" href="#module-sans.calculator.sld_calculator"><tt class="xref py py-mod docutils literal"><span class="pre">sans.calculator.sld_calculator</span></tt></a><a class="headerlink" href="#module-sans.calculator.sld_calculator" title="Permalink to this headline">¶</a></h2> 56 <p>This module intends to compute the neutron scattering length density of molecule 57 @author: Gervaise B. Alina</p> 60 <p>This module intends to compute the neutron scattering length density 61 of a molecule.It uses methods of the periodictable package to provide 62 easy user interface for Sld calculator applications.</p> 58 63 <dl class="class"> 59 64 <dt id="sans.calculator.sld_calculator.SldCalculator"> 60 65 <em class="property">class </em><tt class="descclassname">sans.calculator.sld_calculator.</tt><tt class="descname">SldCalculator</tt><a class="headerlink" href="#sans.calculator.sld_calculator.SldCalculator" title="Permalink to this definition">¶</a></dt> 61 66 <dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">object</span></tt></p> 62 <p>compute neutron SLD and related parameters</p> 63 <dl class="method"> 64 <dt id="sans.calculator.sld_calculator.SldCalculator.calculate_coherence_im"> 65 <tt class="descname">calculate_coherence_im</tt><big>(</big><big>)</big><a class="headerlink" href="#sans.calculator.sld_calculator.SldCalculator.calculate_coherence_im" title="Permalink to this definition">¶</a></dt> 66 <dd>Compute imaginary part of the absorption</dd></dl> 67 67 <p>Given a molecule, a density and a wavelength, this class 68 determine scattering length density.</p> 69 <p>Example: To get the sld value and the length 1/e the following 70 methods need to be called in this later order:</p> 71 <div class="highlight-python"><pre>formula = "H2O" 72 density = 1.0 73 wavelength = 6.0 74 sld_calculator = SldCalculator() 75 sld_calculator.set_value(formula, density, wavelength) 76 sld_real, sld_im, _ = sld_calculator.calculate_neutron_sld() 77 result : sld = sld_real +i sld_im</pre> 78 </div> 79 <p>Note: <strong>set_value()</strong> and <strong>calculate_neutron_sld()</strong> methods must 80 be called in this order prior calling <strong>calculate_length()</strong> to get 81 the proper result.</p> 68 82 <dl class="method"> 69 83 <dt id="sans.calculator.sld_calculator.SldCalculator.calculate_length"> … … 75 89 <tt class="descname">calculate_neutron_sld</tt><big>(</big><big>)</big><a class="headerlink" href="#sans.calculator.sld_calculator.SldCalculator.calculate_neutron_sld" title="Permalink to this definition">¶</a></dt> 76 90 <dd>Compute the neutron SLD for a given molecule 77 @return absorp: absorption78 @return coh: coherence cross section91 @return sld_real : real part of the sld value 92 @return sld_im: imaginary part of the sld value 79 93 @return inc: incoherence cross section</dd></dl> 80 94 … … 87 101 <dl class="method"> 88 102 <dt id="sans.calculator.sld_calculator.SldCalculator.set_value"> 89 <tt class="descname">set_value</tt><big>(</big><em> user_formula</em>, <em>density</em>, <em>wavelength=6.0</em><big>)</big><a class="headerlink" href="#sans.calculator.sld_calculator.SldCalculator.set_value" title="Permalink to this definition">¶</a></dt>90 <dd>Store values of density and wavelength into the calculator91 and compute the volume</dd></dl>103 <tt class="descname">set_value</tt><big>(</big><em>formula</em>, <em>density</em>, <em>wavelength=6.0</em><big>)</big><a class="headerlink" href="#sans.calculator.sld_calculator.SldCalculator.set_value" title="Permalink to this definition">¶</a></dt> 104 <dd>Store values into the sld calculator and compute the corresponding 105 volume.</dd></dl> 92 106 93 107 </dd></dl> … … 113 127 <p class="topless"><a href="index.html" 114 128 title="previous chapter">Reference</a></p> 129 <h4>Next topic</h4> 130 <p class="topless"><a href="slit_length_calculator.html" 131 title="next chapter">Slit Length Calculator</a></p> 115 132 <h3>This Page</h3> 116 133 <ul class="this-page-menu"> … … 145 162 >modules</a> |</li> 146 163 <li class="right" > 164 <a href="slit_length_calculator.html" title="Slit Length Calculator" 165 >next</a> |</li> 166 <li class="right" > 147 167 <a href="index.html" title="Reference" 148 168 >previous</a> |</li> -
calculator/docs/sphinx/_build/html/genindex.html
rbeb374a r14e9eb3 48 48 49 49 <div class="genindex-jumpbox"> 50 <a href="#C"><strong>C</strong></a> | <a href="# S"><strong>S</strong></a>50 <a href="#C"><strong>C</strong></a> | <a href="#G"><strong>G</strong></a> | <a href="#S"><strong>S</strong></a> 51 51 </div> 52 52 <h2 id="C">C</h2> 53 53 <table width="100%" class="indextable genindextable"><tr> 54 54 <td width="33%" valign="top"><dl> 55 <dt><a href="api/sld_calculator.html#sans.calculator.sld_calculator.SldCalculator.calculate_coherence_im">calculate_coherence_im() (sans.calculator.sld_calculator.SldCalculator method)</a></dt>56 55 <dt><a href="api/sld_calculator.html#sans.calculator.sld_calculator.SldCalculator.calculate_length">calculate_length() (sans.calculator.sld_calculator.SldCalculator method)</a></dt> 56 <dt><a href="api/sld_calculator.html#sans.calculator.sld_calculator.SldCalculator.calculate_neutron_sld">calculate_neutron_sld() (sans.calculator.sld_calculator.SldCalculator method)</a></dt> 57 57 </dl></td> 58 58 <td width="33%" valign="top"><dl> 59 <dt><a href="api/sl d_calculator.html#sans.calculator.sld_calculator.SldCalculator.calculate_neutron_sld">calculate_neutron_sld() (sans.calculator.sld_calculator.SldCalculator method)</a></dt>59 <dt><a href="api/slit_length_calculator.html#sans.calculator.slit_length_calculator.SlitlengthCalculator.calculate_slit_length">calculate_slit_length() (sans.calculator.slit_length_calculator.SlitlengthCalculator method)</a></dt> 60 60 <dt><a href="api/sld_calculator.html#sans.calculator.sld_calculator.SldCalculator.calculate_xray_sld">calculate_xray_sld() (sans.calculator.sld_calculator.SldCalculator method)</a></dt> 61 </dl></td> 62 </tr></table> 63 64 <h2 id="G">G</h2> 65 <table width="100%" class="indextable genindextable"><tr> 66 <td width="33%" valign="top"><dl> 67 <dt><a href="api/slit_length_calculator.html#sans.calculator.slit_length_calculator.SlitlengthCalculator.get_slit_length_unit">get_slit_length_unit() (sans.calculator.slit_length_calculator.SlitlengthCalculator method)</a></dt> 61 68 </dl></td> 62 69 </tr></table> … … 66 73 <td width="33%" valign="top"><dl> 67 74 <dt><a href="api/sld_calculator.html#module-sans.calculator.sld_calculator">sans.calculator.sld_calculator (module)</a></dt> 68 <dt><a href="api/sld_calculator.html#sans.calculator.sld_calculator.SldCalculator.set_value">set_value() (sans.calculator.sld_calculator.SldCalculator method)</a></dt> 75 <dt><a href="api/slit_length_calculator.html#module-sans.calculator.slit_length_calculator">sans.calculator.slit_length_calculator (module)</a></dt> 76 <dt><a href="api/slit_length_calculator.html#sans.calculator.slit_length_calculator.SlitlengthCalculator.set_data">set_data() (sans.calculator.slit_length_calculator.SlitlengthCalculator method)</a></dt> 69 77 </dl></td> 70 78 <td width="33%" valign="top"><dl> 79 <dt><a href="api/sld_calculator.html#sans.calculator.sld_calculator.SldCalculator.set_value">set_value() (sans.calculator.sld_calculator.SldCalculator method)</a></dt> 71 80 <dt><a href="api/sld_calculator.html#sans.calculator.sld_calculator.SldCalculator">SldCalculator (class in sans.calculator.sld_calculator)</a></dt> 81 <dt><a href="api/slit_length_calculator.html#sans.calculator.slit_length_calculator.SlitlengthCalculator">SlitlengthCalculator (class in sans.calculator.slit_length_calculator)</a></dt> 72 82 </dl></td> 73 83 </tr></table> -
calculator/docs/sphinx/_build/html/index.html
rbeb374a r14e9eb3 67 67 <li class="toctree-l1"><a class="reference internal" href="api/index.html">Reference</a><ul> 68 68 <li class="toctree-l2"><a class="reference internal" href="api/sld_calculator.html">Sld Calculator</a></li> 69 <li class="toctree-l2"><a class="reference internal" href="api/slit_length_calculator.html">Slit Length Calculator</a></li> 69 70 </ul> 70 71 </li> -
calculator/docs/sphinx/_build/html/py-modindex.html
rbeb374a r14e9eb3 69 69 <a href="api/sld_calculator.html#module-sans.calculator.sld_calculator"><tt class="xref">sans.calculator.sld_calculator</tt></a></td><td> 70 70 <em></em></td></tr> 71 <tr class="cg-1"> 72 <td></td> 73 <td> 74 <a href="api/slit_length_calculator.html#module-sans.calculator.slit_length_calculator"><tt class="xref">sans.calculator.slit_length_calculator</tt></a></td><td> 75 <em></em></td></tr> 71 76 </table> 72 77 -
calculator/docs/sphinx/_build/html/searchindex.js
rbeb374a r14e9eb3 1 Search.setIndex({objects:{"sans.calculator.sld_calculator":{SldCalculator:[ 2,1,1]},"sans.calculator":{sld_calculator:[2,0,0]},"sans.calculator.sld_calculator.SldCalculator":{calculate_neutron_sld:[2,2,1],calculate_coherence_im:[2,2,1],calculate_xray_sld:[2,2,1],calculate_length:[2,2,1],set_value:[2,2,1]}},terms:{comput:[1,2],san:[0,2],sld_calcul:[0,2],thi:2,modul:[1,2],independ:1,calcul:[0,1,2],indic:1,correspond:2,each:1,packag:1,slit:[],exist:2,coher:2,tabl:1,sansview:1,follow:1,gervais:2,paramet:2,index:1,given:2,absorpt:2,sub:1,author:2,titl:[],section:2,releas:[0,1],cross:2,param:2,content:[],other:1,densiti:2,formula:2,page:1,document:[],intend:2,tool:1,neutron:2,refer:[0,1],calculate_xray_sld:2,applic:1,alina:2,relat:2,"return":2,string:2,get:2,wavelength:2,imaginari:2,object:2,molecul:2,sld:[0,1,2],calculate_length:2,volum:2,date:[0,1],atom:2,mai:[0,1],elementi:2,part:2,absorp:2,"class":2,valu:2,welcom:[],search:1,contain:1,calculate_coherence_im:2,current:1,sldcalcul:2,element:2,length:2,base:2,necessari:1,store:2,user_formula:2,calculate_neutron_sld:2,small:1,coh:2,incoher:2,inc:2,scatter:2,set_valu:2},objtypes:{"0":"py:module","1":"py:class","2":"py:method"},titles:["Reference","Calculator","Sld Calculator"],objnames:{"0":"Python module","1":"Python class","2":"Python method"},filenames:["api/index","index","api/sld_calculator"]})1 Search.setIndex({objects:{"sans.calculator.sld_calculator":{SldCalculator:[3,1,1]},"sans.calculator":{sld_calculator:[3,0,0],slit_length_calculator:[2,0,0]},"sans.calculator.slit_length_calculator.SlitlengthCalculator":{get_slit_length_unit:[2,2,1],calculate_slit_length:[2,2,1],set_data:[2,2,1]},"sans.calculator.sld_calculator.SldCalculator":{calculate_neutron_sld:[3,2,1],calculate_length:[3,2,1],calculate_xray_sld:[3,2,1],set_value:[3,2,1]},"sans.calculator.slit_length_calculator":{SlitlengthCalculator:[2,1,1]}},terms:{thi:[2,3],follow:[1,3],paramet:[],get_slit_length_unit:2,easi:3,param:[2,3],should:[],better:[],densiti:3,arrai:2,real:3,applic:[1,3],"return":[2,3],string:3,get:3,molecul:3,beam:2,calculate_sld_im:[],volum:3,method:3,necessari:1,user_formula:[],each:1,small:[1,2],page:1,set:2,sld_calcul:[0,3],sldcalcul:3,result:3,proper:3,wavelength:3,todo:[],index:1,absorpt:[],sub:1,"3rd":2,section:3,slit_length_calcul:[0,2],content:[],formula:3,imaginari:3,slitlengthcalcul:2,refer:[0,1],alina:[],sansview:1,contain:1,calculate_slit_length:2,calculate_length:3,set_data:2,releas:[0,1],valu:[2,3],search:1,current:1,prior:3,length:[0,1,2,3],base:[2,3],calculate_neutron_sld:3,coh:[],col:2,point:[],modul:[2,1,3],independ:1,"2nd":2,saxsess:2,"1st":2,unit:2,given:3,from:2,call:3,sld_real:3,interfac:3,store:3,quickli:2,tool:[1,2],factor:[],part:3,atom:3,set_valu:3,must:3,none:2,provid:3,calcul:[0,1,2,3],sld:[0,1,3],scatter:3,later:3,comput:[2,1,3],san:[0,2,3],indic:1,packag:[1,3],slit:[0,1,2],exist:3,coher:[],tabl:1,need:[2,3],gervais:[],inc:3,date:[0,1],welcom:[],calculate_xray_sld:3,titl:[],cross:3,note:3,other:1,futur:[],document:[],neutron:3,incoher:3,sld_im:3,relat:[],intend:3,allow:2,max:[],object:[2,3],periodict:3,user:[2,3],mai:[0,1],elementi:3,absorp:[],data:2,"class":[2,3],don:2,calculate_coherence_im:[],author:[],correspond:3,element:3,h2o:3,exampl:3,determin:[2,3],profil:2,order:3},objtypes:{"0":"py:module","1":"py:class","2":"py:method"},titles:["Reference","Calculator","Slit Length Calculator","Sld Calculator"],objnames:{"0":"Python module","1":"Python class","2":"Python method"},filenames:["api/index","index","api/slit_length_calculator","api/sld_calculator"]}) -
calculator/docs/sphinx/api/index.rst
rbeb374a r14e9eb3 15 15 16 16 sld_calculator.rst 17 slit_length_calculator.rst -
calculator/docs/sphinx/genmods.py
rbeb374a r14e9eb3 54 54 modules=[ 55 55 ('sld_calculator', 'Sld Calculator'), 56 ('slit_length_calculator', 'Slit Length Calculator'), 56 57 ] 57 58 package='sans.calculator' -
calculator/sld_calculator.py
rbeb374a r14e9eb3 1 1 """ 2 3 of a molecule.It uses methods of the periodictable package to provide4 2 This module intends to compute the neutron scattering length density 3 of a molecule.It uses methods of the periodictable package to provide 4 easy user interface for Sld calculator applications. 5 5 """ 6 6 … … 10 10 from periodictable.constants import avogadro_number 11 11 import periodictable.nsf 12 neutron_sld_from_atoms = periodictable.nsf.neutron_sld_from_atoms12 neutron_sld_from_atoms = periodictable.nsf.neutron_sld_from_atoms 13 13 14 14 class SldCalculator(object): … … 16 16 Given a molecule, a density and a wavelength, this class 17 17 determine scattering length density. 18 19 Example: To get the sld value and the length 1/e the following 20 methods need to be called in this later order:: 21 formula = "H2O" 22 density = 1.0 23 wavelength = 6.0 24 sld_calculator = SldCalculator() 25 sld_calculator.set_value(formula, density, wavelength) 26 sld_real, sld_im, _ = sld_calculator.calculate_neutron_sld() 27 result : sld = sld_real +i sld_im 28 29 Note: **set_value()** and **calculate_neutron_sld()** methods must 30 be called in this order prior calling **calculate_length()** to get 31 the proper result. 18 32 """ 19 33 def __init__(self): 34 #Private variable 35 self._volume = 0.0 36 #Inputs 20 37 self.wavelength = 6.0 38 self.sld_formula = None 39 self.density = None 40 #Outputs 41 self.sld_real = None 42 self.sld_im = None 21 43 self.coherence = 0.0 22 44 self.absorption = 0.0 23 45 self.incoherence = 0.0 24 self.sld_formula = None 25 self.volume = 0.0 26 self.density = None 27 self.length= 0.0 46 self.length = 0.0 28 47 29 def set_value(self, user_formula, density, wavelength=6.0):48 def set_value(self, formula, density, wavelength=6.0): 30 49 """ 31 50 Store values into the sld calculator and compute the corresponding … … 34 53 self.wavelength = wavelength 35 54 self.density = float(density) 36 self.sld_formula = formula(str( user_formula), density=self.density)55 self.sld_formula = formula(str(formula), density=self.density) 37 56 38 57 if self.density == 0: 39 58 raise ZeroDivisionError("integer division or modulo\ 40 59 by zero for density") 41 self. volume = (self.sld_formula.mass / self.density) / avogadro_number\60 self._volume = (self.sld_formula.mass / self.density) / avogadro_number\ 42 61 *1.0e24 43 62 … … 63 82 """ 64 83 Compute the neutron SLD for a given molecule 65 @return absorp: absorption66 return coh: coherence cross section84 @return sld_real : real part of the sld value 85 @return sld_im: imaginary part of the sld value 67 86 @return inc: incoherence cross section 68 87 """ … … 72 91 return 73 92 atom = self.sld_formula.atoms 74 coh, absorp, inc = neutron_sld_from_atoms(atom, self.density,93 sld_real, sld_im, inc = neutron_sld_from_atoms(atom, self.density, 75 94 self.wavelength) 76 #Don't know if value is return in cm or cm^(-1).assume return in cm77 # to match result of neutron inc of Alan calculator78 95 self.incoherence = inc 79 self.absorption = absorp 80 self.coherence = coh 81 return self.coherence, self.absorption, self.incoherence 82 96 self.sld_real = sld_real 97 self.sld_im = sld_im 98 return self.sld_real, self.sld_im, self.incoherence 83 99 84 100 def calculate_length(self): … … 87 103 """ 88 104 self.length = (self.coherence + self.absorption +\ 89 self.incoherence) / self. volume105 self.incoherence) / self._volume 90 106 return self.length 91 107 92 93 def calculate_coherence_im(self):94 """95 Compute imaginary part of the absorption96 """97 atom = self.sld_formula.atoms98 #im: imaginary part of neutron SLD99 im = 0100 for el, count in atom.iteritems():101 if el.neutron.b_c_i is not None:102 im += el.neutron.b_c_i * count103 104 if self.volume != 0:105 im = im/self.volume106 else:107 raise ZeroDivisionError("integer division or modulo\108 by zero for volume")109 return im -
calculator/slit_length_calculator.py
r0bf2c6f r14e9eb3 1 1 """ 2 This software was developed by the University of Tennessee as part of the 3 Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 4 project funded by the US National Science Foundation. 5 6 See the license text in license.txt 7 8 copyright 2008, 2009, University of Tennessee 2 This module is a small tool to allow user to quickly 3 determine the slit length value of data. 9 4 """ 10 5 from numpy import * … … 12 7 class SlitlengthCalculator(object): 13 8 """ 14 compute slit length from SAXSess beam profile (1st col. Q , 2nd col. I , and 3rd col. dI.: don't need the 3rd)15 @object: data where are data.y and data.x9 compute slit length from SAXSess beam profile (1st col. Q , 2nd col. I , 10 and 3rd col. dI.: don't need the 3rd) 16 11 """ 17 12 def __init__(self): … … 31 26 def set_data(self, x=None, y=None): 32 27 """ 33 34 @ Param x, y: x array and y array28 set data 29 :param x, y: x array and y array 35 30 """ 36 31 self.x = x 37 32 self.y = y 38 33 39 40 34 def calculate_slit_length(self): 41 35 """ 42 Calculate slit length using 10 max point 43 ToDo: Near future, it should be re-factored in better method. 36 Calculate slit length. 44 37 """ 45 38 # None data do nothing 46 39 if self.y == None or self.x == None: 47 40 return 48 49 41 # set local variable 50 42 y = self.y … … 96 88 # set slit_length 97 89 self.slit_length = slit_length 98 99 def get_slit_length(self):100 """101 Calculate and return the slit length102 """103 self.calculate_slit_length()104 90 return self.slit_length 105 91 106 92 def get_slit_length_unit(self): 107 93 """ 108 return the slit length unit94 return the slit length unit. 109 95 """ 110 96 return self.slit_length_unit
Note: See TracChangeset
for help on using the changeset viewer.