def runAlign():
	# -----------------------------------------------------------------------------
	### set files
	#maindir = '/ami/data16/appion/09mar04b/models/emanmodel28'
	default_settings.set('limit_voxel_count', False)
	maindir = '/home/vossman/Documents/papers/initmodel/initmodels-figure'
	map1_path = os.path.join(maindir, 'reconemdb.mrc')

	map1 = open_volume_file(map1_path)[0]
	map1.set_parameters(surface_levels = [1.0])
	mrcfiles = glob.glob(os.path.join(maindir, '*.mrc'))
	aligndir = os.path.join(maindir, 'align/')
	if not os.path.isdir(aligndir):
		os.mkdir(aligndir)
	N = len(mrcfiles)
	random.shuffle(mrcfiles)
	for i,mrcfile in enumerate(mrcfiles):
		if os.path.basename(mrcfile)[:5] == "align":
			continue
		new_path = os.path.join(aligndir, 'align'+os.path.basename(mrcfile))
		if os.path.isfile(new_path):
			print "----------", os.path.basename(mrcfile)
			continue
		print ("\n==============================\n", 
			os.path.basename(mrcfile), 
			"\n==============================\n")
		map2 = open_volume_file(mrcfile)[0]
		map2.set_parameters(surface_levels = [1.0])
		new_path = os.path.join(aligndir, 'align'+os.path.basename(mrcfile))
		fit_map_in_map(map1, map2, map1_threshold=1.0)
		runCommand('vop #1 resample onGrid #0 modelId %d'%(i+N))
		runCommand('volume #%d save %s'%(i+N, new_path))
		map2.close()
		runCommand('close #1')
		runCommand('close #%d'%(i+N))
Example #2
0
def fit_map_in_map(map1_path, map2_path, xformName,
                   initial_map1_transform = None,
                   map1_threshold = None,
                   ijk_step_size_min = 0.01,    # Grid index units
                   ijk_step_size_max = 0.5,     # Grid index units
                   max_steps = 5000,
                   optimize_translation = True,
                   optimize_rotation = True):


  # Files have to have file suffix indicating volume format.
  from VolumeViewer import open_volume_file
  map1 = open_volume_file(map1_path)[0]  # Assume files contain just one array
  map2 = open_volume_file(map2_path)[0]

  if initial_map1_transform:
    from Matrix import chimera_xform
    xf = chimera_xform(initial_map1_transform)
    map1.surface_model().openState.globalXform(xf)
    
  use_threshold = (map1_threshold != None)
  
  from FitMap.fitmap import map_points_and_weights, motion_to_maximum
  points, point_weights = map_points_and_weights(map1, use_threshold)

  if len(points) == 0:
    if use_threshold:
      print 'No grid points above map threshold.'
    else:
      print 'Map has no non-zero values.'
    return

  move_tf, stats = motion_to_maximum(points, point_weights, map2, max_steps,
                                     ijk_step_size_min, ijk_step_size_max,
                                     optimize_translation, optimize_rotation)

  import Matrix
  if initial_map1_transform:
    move_tf = Matrix.multiply_matrices(move_tf, initial_map1_transform)

  header = ('\nFit map %s in map %s using %d points\n'
            % (map1.name, map2.name, stats['points']) +
            '  correlation = %.4g, overlap = %.4g\n'
            % (stats['correlation'], stats['overlap']) +
            '  steps = %d, shift = %.3g, angle = %.3g degrees\n'
            % (stats['steps'], stats['shift'], stats['angle']))
  print header
  f = open(xformName,'w')
  for i in range(4):  
    for j in range(3):
     # print move_tf[j][i]
      f.write('{:f}'.format(move_tf[j][i]))
      f.write("\n")

  f.close()
  print move_tf
  tfs = Matrix.transformation_description(move_tf)
  print tfs
Example #3
0
def fit_map_in_map(
    map1_path,
    map2_path,
    initial_map1_transform=None,
    map1_threshold=None,
    ijk_step_size_min=0.01,  # Grid index units
    ijk_step_size_max=0.5,  # Grid index units
    max_steps=2000,
    optimize_translation=True,
    optimize_rotation=True,
    metric='sum product'
):  # 'sum product' > overlap; other options are 'correlation' and 'correlation about mean'

    # Files have to have file suffix indicating volume format.
    map1 = open_volume_file(map1_path)[
        0]  # Assume files contain just one array
    map2 = open_volume_file(map2_path)[0]

    if initial_map1_transform:
        from Matrix import chimera_xform
        xf = chimera_xform(initial_map1_transform)
        map1.surface_model().openState.globalXform(xf)

    use_threshold = (map1_threshold != None)
    points, point_weights = map_points_and_weights(map1, use_threshold)

    if len(points) == 0:
        if use_threshold:
            print 'No grid points above map threshold.'
        else:
            print 'Map has no non-zero values.'
        return

    move_tf, stats = motion_to_maximum(points, point_weights, map2, max_steps,
                                       ijk_step_size_min, ijk_step_size_max,
                                       optimize_translation, optimize_rotation,
                                       metric)

    if initial_map1_transform:
        move_tf = Matrix.multiply_matrices(move_tf, initial_map1_transform)

    header = ('\nFit map %s in map %s using %d points\n' %
              (map1.name, map2.name, stats['points']) +
              '  correlation = %.4g, overlap = %.4g\n' %
              (stats['correlation'], stats['overlap']) +
              '  steps = %d, shift = %.3g, angle = %.3g degrees\n' %
              (stats['steps'], stats['shift'], stats['angle']))
    print header

    tfs = Matrix.transformation_description(move_tf)
    print tfs
def transform(model_path, fixed_model_path, ea = (0.0, 0.0, 0.0),
              t = (0.0, 0.0, 0.0), move_atoms=True):
    """Translates and/or rotates a model.

    Parameters
    ----------
    model_path : str
        The path to the file containing the model that will be moved.
    fixed_model_path : str
        The path to the file containing the model that will remain
        in place.
    ea : tuple
        3-tuple of Euler angles for rotating the model.
    t : tuple
        3-tuple of xyz displacements for translating the model.
    move_atoms : bool
        Determines whether the atoms or the coordinate system should
        be moved.

    """
    model = open_volume_file(model_path)[0]
    fixed_model = open_volume_file(fixed_model_path)[0]
    
    try:
      ea = map(float, ea)
      t = map(float, t)
    except ValueError:
      from chimera.replyobj import warning
      warning('Error parsing Euler angle or translation number')
      return

    if len(ea) != 3:
      from chimera.replyobj import warning
      warning('Requires 3 Euler angles.')
      return

    if len(t) != 3:
      from chimera.replyobj import warning
      warning('Requires 3 translation values.')
      return

    xf = mt.euler_xform(ea, t)
    if isinstance(model, Molecule) and move_atoms:
      mt.transform_atom_coordinates(m.atoms, xf)
    else:
      mt.transform_coordinate_axes(model, xf)

    print('Transformation matrix:')
    print(xf)
def fetch_eds_map(id, type = '2fofc', open_models = True):

  site = 'eds.bmc.uu.se'
  url_pattern = 'http://%s/eds/dfs/%s/%s/%s'

  # Fetch map.
  from chimera.replyobj import status
  status('Fetching %s from web site %s...\n' % (id,site), blankAfter = False)
  if type == 'fofc':
    map_name = id + '_diff.omap'
  elif type == '2fofc':
    map_name = id + '.omap'
  map_url = url_pattern % (site, id[1:3], id, map_name)
  name = 'map %s' % id
  minimum_map_size = 8192       # bytes
  from chimera import fetch
  map_path, headers = fetch.fetch_file(map_url, name, minimum_map_size,
                                       'EDS', map_name)
    
  # Display map.
  status('Opening map %s...\n' % map_name, blankAfter = False)
  from VolumeViewer import open_volume_file
  models = open_volume_file(map_path, 'dsn6', map_name, 'mesh',
                            open_models = open_models)
  status('\n')

  return models
Example #6
0
 def draw(self):
     """
     Research on Chimera's Volume extensions
     """
     try:
         grad_file, dens_file = self.data['grad_cube'], self.data['dens_cube']
     except KeyError:
         raise UserError('NCIPlot has not been run yet!')
     else:
         gradient = open_volume_file(grad_file, show_dialog=False,
                 model_id=(self._model_id[0], 1))[0]
         density = open_volume_file(dens_file, show_dialog=False,
                 model_id=(self._model_id[0], 2))[0]
         density.display = False
         self._model_id[0] += 1
     return gradient, density
    def open_cb(path, ftype=name):
      from VolumeViewer import open_volume_file
      vlist = open_volume_file(path, ftype, open_models = False,
			       show_data = False, show_dialog = False)
      import chimera
      if len(vlist) > 0 and not chimera.nogui:
        from SurfaceColor.gui import show_surface_color_dialog
	d = show_surface_color_dialog()
	d.use_electrostatics_colormap()
	# TODO: Should set volume menu entry, but volumes are not yet opened.
      return vlist
def fetch_emdb_map(id, open_fit_pdbs = False, open_models = True):

  site = 'ftp.ebi.ac.uk'
  url_pattern = 'ftp://%s/pub/databases/emdb/structures/EMD-%s/map/%s'
  xml_url_pattern = 'ftp://%s/pub/databases/emdb/structures/EMD-%s/header/%s'

  from chimera.replyobj import status, info
  status('Fetching %s from %s...\n' % (id,site), blankAfter = False)

  # Fetch map.
  map_name = 'emd_%s.map' % id
  map_gz_name = map_name + '.gz'
  map_url = url_pattern % (site, id, map_gz_name)
  name = 'EMDB %s' % id
  minimum_map_size = 8192       # bytes
  from chimera import fetch
  map_path, headers = fetch.fetch_file(map_url, name, minimum_map_size,
                                       'EMDB', map_name, uncompress = True)
    
  # Display map.
  status('Opening map %s...\n' % map_name, blankAfter = False)
  from VolumeViewer import open_volume_file
  models = open_volume_file(map_path, 'ccp4', map_name, 'surface',
                            open_models = open_models)

  if open_fit_pdbs:
    # Find fit pdb ids.
    status('EMDB %s: looking for fits PDBs\n' % id)
    pdb_ids = fit_pdb_ids_from_web_service(id)
    msg = ('EMDB %s has %d fit PDB models: %s\n'
           % (id, len(pdb_ids), ','.join(pdb_ids)))
    status(msg)
    info(msg)
    if pdb_ids:
      mlist = []
      from chimera import _openPDBIDModel, openModels
      for pdb_id in pdb_ids:
        status('Opening %s\n' % pdb_id)
        if open_models:
          m = openModels.open(pdb_id, 'PDBID')
        else:
          m = _openPDBIDModel(pdb_id)
        mlist.extend(m)
      models.extend(mlist)

  return models
Example #9
0
    def add_volumes(self, paths):
        if not paths:
            return
        if len(paths) != len(self.ensemble):
            raise ValueError('Provide exactly one volume per frame.')

        volumes = []
        for i, path in enumerate(paths):
            basename, ext = os.path.splitext(path)
            if ext in MULTIWFN_SUPPORTED_EXTENSIONS:
                show_message('Converting to cube...')
                path = _multiwfn_to_cube(path)
                show_message('Converting to cube... Done!', blankAfter=3)
            volume = open_volume_file(path,
                                      show_dialog=False,
                                      model_id=1000 + i)[0]
            volume.display = False
            volumes.append(volume)

        self.volumes = volumes
        self.isosurface()
        self.colorize_by_volume(alpha=0.6)
        self.update_volume()
        self.volume_ui = self.launch_orbitraj_dialog()
Example #10
0
 def open_cb(path, ftype=name):
   from VolumeViewer import open_volume_file
   drlist = open_volume_file(path, ftype, open_models = False)
   models = [dr.surface_model() for dr in drlist]
   drlist = None # Work around numpy bug #454
   return models