Changeset 077207b in sasview


Ignore:
Timestamp:
Jan 4, 2013 9:30:31 AM (11 years ago)
Author:
Jae Cho <jhjcho@…>
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:
d7b6913
Parents:
ab7e3a4
Message:

added pdb reader

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • calculatorview/src/sans/perspectives/calculator/gen_scatter_panel.py

    rdbc5dc9b r077207b  
    2020 
    2121from data_util.calcthread import CalcThread 
    22 #from sans.guiframe.local_perspectives.plotting.Plotter2D import ModelPanel2D \ 
    23 #                    as PlotPanel 
    24 #from danse.common.plottools.PlotPanel import PlotPanel 
    25 #from danse.common.plottools.SimplePlot import PlotFrame 
    2622from sans.guiframe.local_perspectives.plotting.SimplePlot import PlotFrame 
    27 #from danse.common.plottools.plottables import Graph 
    2823from sans.guiframe.dataFitting import Data2D 
    29 #from sans.guiframe.utils import PanelMenu 
    3024from sans.dataloader.data_info import Detector 
    3125from sans.dataloader.data_info import Source 
     
    3832from wx.lib.scrolledpanel import ScrolledPanel 
    3933from sans.perspectives.calculator.load_thread import GenReader 
    40 #import matplotlib.pyplot as plt 
    4134from danse.common.plottools.arrow3d import Arrow3D 
    42 #from danse.common.plottools.toolbar import NavigationToolBar 
     35 
    4336_BOX_WIDTH = 76 
    4437#Slit length panel size  
     
    5144    PANEL_HEIGHT = 370 
    5245    FONT_VARIANT = 1 
    53 _QMAX_DEFAULT = 0.1 
     46_QMAX_DEFAULT = 0.3 
    5447_NPTS_DEFAULT = 50  
    5548 
     
    434427        for type in omf_type: 
    435428            wildcard.append(type) 
    436         #for type in pdb_type: 
    437         #    wildcard.append(type) 
     429        for type in pdb_type: 
     430            wildcard.append(type) 
    438431        wildcard = '|'.join(wildcard) 
    439432        dlg = wx.FileDialog(self, "Choose a file", location, 
     
    474467            if self.reader is not None and self.reader.isrunning(): 
    475468                self.reader.stop() 
     469            self.browse_button.Enable(False) 
     470            self.browse_button.SetLabel("Loading...") 
    476471            if self.parent.parent is not None: 
    477472                wx.PostEvent(self.parent.parent,  
     
    482477                                    updatefn=self.load_update) 
    483478            self.reader.queue() 
    484             self.load_update() 
     479            #self.load_update() 
    485480        except: 
    486481            self.ext = None 
     
    496491        """ 
    497492        print update on the status bar 
    498         """ 
     493        """        
    499494        if self.parent.parent is None: 
    500495                return  
     
    511506        """ 
    512507        #compute the slit size 
     508        self.browse_button.Enable(True) 
     509        self.browse_button.SetLabel('Load') 
    513510        try: 
    514511            filename = data.filename 
     
    529526            self._set_sld_data_helper(True) 
    530527        except: 
    531             #raise 
    532528            if self.parent.parent is None: 
    533                 return  
     529                raise 
    534530            msg = "Loading Error: This file format is not supported " 
    535531            msg += "for GenSANS."  
     
    540536        if self.parent.parent is None: 
    541537            return  
     538         
    542539        msg = "Load Complete" 
    543540        wx.PostEvent(self.parent.parent, StatusEvent(status=msg, type='stop')) 
     
    619616        is_zero = sld_tot == 0.0   
    620617        if is_zero.any(): 
    621             ax.plot(pos_x[is_zero], pos_y[is_zero], pos_z[is_zero], marker,  
     618            ax.plot(pos_x[is_zero], pos_z[is_zero], pos_y[is_zero], marker,  
    622619                        c="y", alpha=0.5, markeredgecolor='y',  
    623620                        markersize=m_size)  
     
    629626            sld_mz = sld_mz[is_nonzero] 
    630627 
    631         ax.plot(pos_x, pos_y,  
    632                 pos_z, marker, c="k",  
     628        ax.plot(pos_x, pos_z, pos_y,  
     629                marker, c="k",  
    633630                alpha=0.5, markeredgecolor="k", markersize=m_size)  
    634631         
     
    671668                                                      color_z)) 
    672669                         
    673                         arrows = Arrow3D(panel, x_arrow, y_arrow,  
    674                                                   z_arrow, colors,  
     670                        arrows = Arrow3D(panel, x_arrow, z_arrow, y_arrow,  
     671                                                  colors,  
    675672                                                  mutation_scale=10, lw=1,  
    676673                                                  arrowstyle="->", alpha = 0.5) 
     
    692689        panel.subplot.figure.subplots_adjust(left=0.05, right=0.95,  
    693690                                             bottom=0.05, top=0.96) 
     691        # Use y, z axes (in mpl 3d) as z, y axes  
     692        # that consistent with SANS coords. 
    694693        ax.set_xlabel('x ($\A%s$)'% output.pos_unit) 
    695         ax.set_ylabel('y ($\A%s$)'% output.pos_unit) 
    696         ax.set_zlabel('z ($\A%s$)'% output.pos_unit) 
     694        ax.set_ylabel('z ($\A%s$)'% output.pos_unit) 
     695        ax.set_zlabel('y ($\A%s$)'% output.pos_unit) 
    697696        num_graph = str(self.graph_num) 
    698697        frame.SetTitle('Graph %s: %s'% (num_graph, graph_title))         
     
    11371136         
    11381137        self.npixels_sizer = wx.BoxSizer(wx.HORIZONTAL) 
    1139         self.box_sld = wx.StaticBox(self, -1, str("Mean SLD")) 
     1138        self.box_sld = wx.StaticBox(self, -1,  
     1139                                    str("Scattering Length (Density)")) 
    11401140        self.box_node = wx.StaticBox(self, -1, str("Nodes")) 
    11411141        self.boxsizer_sld = wx.StaticBoxSizer(self.box_sld, wx.VERTICAL) 
     
    13601360    def set_sld_ctr(self, sld_data): 
    13611361        """ 
     1362        Set sld textctrls 
    13621363        """ 
    13631364        if sld_data == None: 
     
    13751376                    max_val = numpy.max(sld_list[key]) 
    13761377                    mean_val = numpy.mean(sld_list[key]) 
    1377                     enable = (min_val == max_val) 
     1378                    enable = (min_val == max_val) and \ 
     1379                             sld_data.pix_type == 'pixel' 
    13781380                    ctr_list[1].SetValue(format_number(mean_val, True)) 
    13791381                    ctr_list[1].Enable(enable) 
  • calculatorview/src/sans/perspectives/calculator/media/gen_sans_help.html

    r318b5bbb r077207b  
    112112</p> 
    113113<br> 
    114 *Note: The values of 'Up_frac_i' and 'Up_frac_f' must be in the range between 0 and 1. 
     114*Note I: The values of 'Up_frac_i' and 'Up_frac_f' must be in the range between 0 and 1. 
     115For example, both values are 0.5 for unpolarized neutrons. 
     116<br> 
     117*Note II: The unit of intensity calculated from .sld, .omf, or .txt files is 1/cm, otherwise 
     118it is &#197;<sup>2</sup>. (In the first equation above, the V is set to 1.) 
     119<br> 
     120*Note III: This computation is totally based on the pixel (or atomic) data fixed 
     121in the xyz coordinates. Thus no angular orientational averaging is considered. 
     122<br> 
     123*Note IV: For the neutron scattering length density, only the its real component is taken account. 
    115124</body> 
  • sanscalculator/src/sans/calculator/sans_gen.py

    rab7e3a4 r077207b  
    44from sans.models.BaseComponent import BaseComponent 
    55import sans.models.sans_extension.sld2i as mod 
     6from periodictable import formula 
    67import numpy 
    78import os 
     
    5455        self.params['scale']       = 1.0 
    5556        self.params['background']  = 0.0 
    56         self.params['Up_frac_i']     = 1.0 
    57         self.params['Up_frac_f']    = 1.0 
     57        self.params['Up_frac_i']     = 0.5 
     58        self.params['Up_frac_f']    = 0.5 
    5859        self.params['Up_theta']  = 0.0 
    5960        self.description='GenSAS' 
     
    440441    ## List of allowed extensions 
    441442    ext = ['.pdb', '.PDB'] 
    442  
     443     
    443444    def read(self, path): 
    444445        """ 
     
    458459        sld_my = numpy.zeros(0) 
    459460        sld_mz = numpy.zeros(0) 
    460         pix_symbol = numpy.zeros(0)#numpy.array([]) 
     461        pix_symbol = numpy.zeros(0) 
    461462        try: 
    462463            input_f = open(path, 'rb') 
    463464            buff = input_f.read() 
    464             #buff.replace(' ', '') 
    465465            lines = buff.split('\n') 
    466466            input_f.close() 
    467467            for line in lines: 
    468468                try: 
    469                     toks = line.split() 
     469                    #toks = line.split() 
    470470                    # check if line starts with "ATOM" 
    471                     if toks[0].count('ATM') > 0 or toks[0] == 'ATOM': 
     471                    if line[0:6].strip().count('ATM') > 0 or \ 
     472                                line[0:6].strip() == 'ATOM': 
    472473                        # define fields of interest 
    473                         atom_id = toks[1] 
    474                         atom_name = toks[2] 
    475                         if line[12] == '' or len(atom_name) == 4: 
    476                             atom_name = atom_name[0].upper()  
    477                         else: 
    478                             atom_name = atom_name[0].upper() + \ 
    479                                         atom_name[1].lower() 
     474                        atom_id = line[6:11].strip() 
     475                        atom_name = line[12:16].strip() 
    480476                        try: 
    481                             float(toks[3]) 
    482                             ind = 3 
     477                            float(line[12]) 
     478                            atom_name = atom_name[1].upper() 
    483479                        except: 
    484                             ind = 4 
    485                         res_name = toks[ind] 
    486                         #chain_name = toks[3].strip() 
    487                         #residue_id = toks[4].strip() 
    488                         try: 
    489                             float(toks[4]) 
    490                         except: 
    491                             ind += 1 
    492                         ind += 1 
    493                         _pos_x = float(toks[ind]) 
    494                         ind += 1 
    495                         _pos_y = float(toks[ind]) 
    496                         ind += 1 
    497                         _pos_z = float(toks[ind]) 
     480                            if len(atom_name) == 4: 
     481                                atom_name = atom_name[0].upper() 
     482                            elif line[12] != ' ':  
     483                                atom_name = atom_name[0].upper() + \ 
     484                                        atom_name[1].lower()  
     485                            else: 
     486                                atom_name = atom_name[0].upper() 
     487                        #res_name = line[17:20].strip() 
     488                        #chain_name = line[21:22].strip() 
     489                        _pos_x = float(line[30:38].strip()) 
     490                        _pos_y = float(line[38:46].strip()) 
     491                        _pos_z = float(line[46:54].strip()) 
     492                         
    498493                        pos_x = numpy.append(pos_x, _pos_x) 
    499494                        pos_y = numpy.append(pos_y, _pos_y) 
    500495                        pos_z = numpy.append(pos_z, _pos_z) 
    501                         sld_n = numpy.append(sld_n, 7e-06) 
     496                        try: 
     497                            #from periodictable import nsf 
     498                            #val = nsf.neutron_sld(atom_name) 
     499                            val = formula(atom_name).atoms.keys()[0].neutron.b_c 
     500                            # sld in Ang unit (from fm) 
     501                            val = float(val) 
     502                            val *= 1.0e-5 
     503                            sld_n = numpy.append(sld_n, val) 
     504                        except: 
     505                            print "Error: set the sld of %s to zero"% atom_name 
     506                            sld_n = numpy.append(sld_n,  0.0)                      
    502507                        sld_mx = numpy.append(sld_mx, 0) 
    503508                        sld_my = numpy.append(sld_my, 0) 
     
    883888            self.ynodes = None 
    884889            self.znodes = None 
    885          
     890       
    886891    def set_stepsize(self): 
    887892        """ 
Note: See TracChangeset for help on using the changeset viewer.