def load_reflections_file(self,
                           file_name,
                           set_array=True,
                           data_only=False):
     file_name = to_str(file_name)
     if (file_name != ""):
         from iotbx.reflection_file_reader import any_reflection_file
         self.viewer.isnewfile = True
         #self.params.NGL_HKLviewer.mergedata = None
         self.viewer.iarray = -1
         self.viewer.colour_scene_id = -1
         self.viewer.radii_scene_id = -1
         self.viewer.match_valarrays = []
         self.viewer.proc_arrays = []
         self.spacegroup_choices = []
         display.reset_settings()
         self.settings = display.settings()
         self.viewer.settings = self.params.NGL_HKLviewer.viewer
         self.viewer.mapcoef_fom_dict = {}
         try:
             hkl_file = any_reflection_file(file_name)
             arrays = hkl_file.as_miller_arrays(
                 merge_equivalents=False,
             )  #observation_type_callback=misc_dialogs.get_shelx_file_data_type)
             #arrays = f.file_server.miller_arrays
         except Exception as e:
             self.NewFileLoaded = False
             self.mprint(to_str(e))
             arrays = []
         valid_arrays = []
         self.array_infostrs = []
         self.array_infotpls = []
         for array in arrays:
             #if array.is_hendrickson_lattman_array() :
             #  continue
             #elif (data_only) :
             if (not array.is_real_array()) and (not array.is_complex_array()) \
              and (not array.is_integer_array()) and (not array.is_bool_array()) :
                 self.mprint('Ignoring miller array \"%s\" of %s' \
                   %(array.info().label_string(), type(array.data()[0]) ) )
                 continue
             self.array_infostrs.append(
                 ArrayInfo(array, self.mprint).infostr)
             self.array_infotpls.append(
                 ArrayInfo(array, self.mprint).infotpl)
             valid_arrays.append(array)
         self.valid_arrays = valid_arrays
         self.mprint("Miller arrays in this file:")
         for e in self.array_infostrs:
             self.mprint("%s" % e)
         self.NewFileLoaded = True
         if (len(valid_arrays) == 0):
             msg = "No arrays of the supported types in this file."
             self.mprint(msg)
             self.NewFileLoaded = False
             return False
         elif (len(valid_arrays) >= 1):
             if (set_array):
                 self.set_miller_array()
             return True
Example #2
0
  def make_new_miller_array(self):
    miller_array_operations_lst = eval(self.params.NGL_HKLviewer.miller_array_operations)
    unique_miller_array_operations_lst = []
    for (operation, label, arrid1, arrid2) in miller_array_operations_lst:
      isunique = True
      for arr in self.procarrays:
        if label in arr.info().label_string():
          self.mprint(label + " is already labelling one of the original miller arrays")
          isunique = False
          break
      if isunique:
        unique_miller_array_operations_lst.append( (operation, label, arrid1, arrid2) )

    self.params.NGL_HKLviewer.miller_array_operations = str(unique_miller_array_operations_lst)
    from copy import deepcopy
    millarr1 = deepcopy(self.procarrays[arrid1])
    newarray = None
    if arrid2:
      millarr2 = deepcopy(self.procarrays[arrid2])
      newarray = self.viewer.OperateOn2MillerArrays(millarr1, millarr2, operation)
    else:
      newarray = self.viewer.OperateOn1MillerArray(millarr1, operation)
    if newarray:
      newarray.set_info(millarr1._info )
      newarray._info.labels = [ label ]
      procarray, procarray_info = self.process_miller_array(newarray)
      self.procarrays.append(procarray)
      self.viewer.proc_arrays = self.procarrays
      self.viewer.has_new_miller_array = True
      self.viewer.array_infostrs.append( ArrayInfo(procarray, self.mprint).infostr )
      self.viewer.array_infotpls.append( ArrayInfo(procarray, self.mprint).infotpl )
      mydict = { "array_infotpls": self.viewer.array_infotpls, "NewHKLscenes" : True, "NewMillerArray" : True}
      self.SendInfoToGUI(mydict)
  def make_new_miller_array(self):
    miller_array_operations_lst = eval(self.params.miller_array_operations)
    unique_miller_array_operations_lst = []
    for (operation, label, arrid1, arrid2) in miller_array_operations_lst:
      for arr in self.procarrays:
        if label in arr.info().label_string() or label in [ "", None]:
          raise Sorry("Provide an unambiguous label for your new miller array!")
      unique_miller_array_operations_lst.append( (operation, label, arrid1, arrid2) )
    self.params.miller_array_operations = str(unique_miller_array_operations_lst)
    from copy import deepcopy
    millarr1 = deepcopy(self.procarrays[arrid1])
    newarray = None
    if arrid2 != -1:
      millarr2 = deepcopy(self.procarrays[arrid2])
      newarray = self.viewer.OperateOn2MillerArrays(millarr1, millarr2, operation)
    else:
      newarray = self.viewer.OperateOn1MillerArray(millarr1, operation)
    if newarray is not None:
      newarray.set_info(millarr1._info )
      newarray._info.labels = [ label ]
      procarray, procarray_info = self.process_miller_array(newarray)
      self.procarrays.append(procarray)
      self.viewer.proc_arrays = self.procarrays
      self.viewer.has_new_miller_array = True
      self.viewer.array_infostrs.append( ArrayInfo(procarray, self.mprint).infostr )
      self.viewer.array_infotpls.append( ArrayInfo(procarray, self.mprint).infotpl )
      #self.viewer.SupersetMillerArrays()

      hkls = self.origarrays["HKLs"]
      nanarr = flex.double(len(hkls), float("nan"))
      m = miller.match_indices(hkls, procarray.indices() )
      indices_of_matched_hkls = m.pairs().column(0)
      for i,e in enumerate(indices_of_matched_hkls):
        nanarr[e] = procarray.data()[i]
      self.origarrays[label] = list(nanarr)
      mydict = { "array_infotpls": self.viewer.array_infotpls, "NewHKLscenes" : True, "NewMillerArray" : True}
      self.SendInfoToGUI(mydict)
Example #4
0
 def LoadReflectionsFile(self, file_name, set_array=True, data_only=False):
     file_name = to_str(file_name)
     if (file_name != ""):
         from iotbx.reflection_file_reader import any_reflection_file
         self.viewer.isnewfile = True
         self.viewer.iarray = 0
         self.viewer.icolourcol = 0
         self.viewer.iradiicol = 0
         display.reset_settings()
         self.settings = display.settings()
         self.viewer.settings = self.settings
         self.viewer.mapcoef_fom_dict = {}
         try:
             hkl_file = any_reflection_file(file_name)
         except Exception, e:
             raise Sorry(to_str(e))
         arrays = hkl_file.as_miller_arrays(
             merge_equivalents=False,
         )  #observation_type_callback=misc_dialogs.get_shelx_file_data_type)
         #arrays = f.file_server.miller_arrays
         valid_arrays = []
         self.array_info = []
         for array in arrays:
             #if array.is_hendrickson_lattman_array() :
             #  continue
             #elif (data_only) :
             if (data_only):
                 if (not array.is_real_array()) and (
                         not array.is_complex_array()):
                     continue
             self.array_info.append(ArrayInfo(array).infostr)
             valid_arrays.append(array)
         self.valid_arrays = valid_arrays
         for i, e in enumerate(self.array_info):
             self.mprint("%d, %s" % (i, e))
         if (len(valid_arrays) == 0):
             msg = "No arrays of the supported types in this file."
             raise Sorry(msg)
         elif (len(valid_arrays) == 1):
             if (set_array):
                 self.set_miller_array(valid_arrays[0])
             return valid_arrays[0]
 def finish_dataloading(self, arrays):
   valid_arrays = []
   self.viewer.array_infostrs = []
   self.viewer.array_infotpls = []
   for i,array in enumerate(arrays) :
     arrayinfo = ArrayInfo(array, self.mprint)
     self.viewer.array_infostrs.append( arrayinfo.infostr )
     self.viewer.array_infotpls.append( arrayinfo.infotpl )
     if i==0:
       mydict = { "spacegroup_info": arrayinfo.spginf, "unitcell_info": arrayinfo.ucellinf }
       self.SendInfoToGUI(mydict)
     valid_arrays.append(array)
   self.valid_arrays = valid_arrays
   self.mprint("%d Miller arrays in this data set:" %len(arrays))
   for e in self.viewer.array_infostrs:
     self.mprint("%s" %e)
   self.mprint("\n")
   self.NewFileLoaded = True
   if (len(valid_arrays) == 0):
     msg = "No arrays of the supported types present."
     self.mprint(msg)
     self.NewFileLoaded=False
   elif (len(valid_arrays) >= 1):
     self.set_miller_array()
     self.update_space_group_choices(0) # get the default spacegroup choice
     mydict = { "info": self.infostr,
                 "array_infotpls": self.viewer.array_infotpls,
                 "bin_infotpls": self.viewer.bin_infotpls,
                 "html_url": self.viewer.url,
                 "tncsvec": self.tncsvec,
                 "merge_data": self.params.merge_data,
                 "spacegroups": [e.symbol_and_number() for e in self.spacegroup_choices],
                 "NewFileLoaded": self.NewFileLoaded,
                 "file_name": self.params.openfilename
               }
     self.SendInfoToGUI(mydict)
   self.params.openfilename = None
  def load_reflections_file(self, file_name, set_array=True, data_only=False):
    file_name = to_str(file_name)
    if (file_name != ""):
      self.mprint("Reading file...")
      from iotbx.reflection_file_reader import any_reflection_file
      self.viewer.isnewfile = True
      #self.params.NGL_HKLviewer.mergedata = None
      self.params.NGL_HKLviewer.viewer.scene_id = None
      self.viewer.colour_scene_id = None
      self.viewer.radii_scene_id = None
      self.viewer.match_valarrays = []
      self.viewer.proc_arrays = []
      self.spacegroup_choices = []
      display.reset_settings()
      self.settings = display.settings()
      self.viewer.settings = self.params.NGL_HKLviewer.viewer
      self.viewer.mapcoef_fom_dict = {}
      self.hklfile_history = []
      self.tncsvec = None
      try :
        hkl_file = any_reflection_file(file_name)
        arrays = hkl_file.as_miller_arrays(merge_equivalents=False,
          )#observation_type_callback=misc_dialogs.get_shelx_file_data_type)
        #arrays = f.file_server.miller_arrays
        if hkl_file._file_type == 'ccp4_mtz':
          self.hklfile_history = list(hkl_file._file_content.history())
          for e in self.hklfile_history:
            if "TNCS NMOL" in e and "VECTOR" in e:
              svec = e.split()[-3:]
              t1 = float(svec[0])
              t2 = float(svec[1])
              t3 = float(svec[2])
              if (t1*t1 + t2*t2 + t3*t3) > 0.0:
                self.tncsvec = [ t1, t2, t3 ]
                self.mprint("tNCS vector found in header of mtz file: %s" %str(svec) )
      except Exception as e :
        self.NewFileLoaded=False
        self.mprint(to_str(e))
        arrays = []

      valid_arrays = []
      self.viewer.array_infostrs = []
      self.viewer.array_infotpls = []
      for array in arrays :
        #if array.is_hendrickson_lattman_array() :
        #  continue
        #elif (data_only) :
        if (not array.is_real_array()) and (not array.is_complex_array()) \
         and (not array.is_integer_array()) and (not array.is_bool_array()) :
          self.mprint('Ignoring miller array \"%s\" of %s' \
            %(array.info().label_string(), type(array.data()[0]) ) )
          continue
        self.viewer.array_infostrs.append( ArrayInfo(array, self.mprint).infostr )
        self.viewer.array_infotpls.append( ArrayInfo(array, self.mprint).infotpl )
        valid_arrays.append(array)
      self.valid_arrays = valid_arrays
      self.mprint("Miller arrays in this file:")
      for e in self.viewer.array_infostrs:
        self.mprint("%s" %e)
      self.mprint("\n")
      self.NewFileLoaded = True
      if (len(valid_arrays) == 0):
        msg = "No arrays of the supported types in this file."
        self.mprint(msg)
        self.NewFileLoaded=False
        return False
      elif (len(valid_arrays) >= 1):
        if (set_array):
          self.set_miller_array()
          self.viewer.superset_all_miller_arrays()
        mydict = { "info": self.infostr,
                   "array_infotpls": self.viewer.array_infotpls,
                   "bin_infotpls": self.viewer.bin_infotpls,
                   "html_url": self.viewer.url,
                   "tncsvec": self.tncsvec,
                   "merge_data": self.params.NGL_HKLviewer.merge_data,
                   "spacegroups": [e.symbol_and_number() for e in self.spacegroup_choices],
                   "NewFileLoaded": self.NewFileLoaded
                  }
        self.SendInfoToGUI(mydict)
        return True