Ejemplo n.º 1
0
def parse_surface_id(sid, cmdname):

  if sid[:1] == '#':
    sid = sid[1:]

  fields = sid.split('.')
  if len(fields) == 1:
    fields.append('0')

  try:
    id, subid = int(fields[0]), int(fields[1])
  except ValueError:
    from Midas.midas_text import error
    error('%s: Bad model specifier %s' % (cmdname, sid))
    return None

  from chimera import openModels
  from _surface import SurfaceModel
  mlist = openModels.list(id = id, subid = subid, modelTypes = [SurfaceModel])
  if len(mlist) == 0:
    from Midas.midas_text import error
    error('%s: No surface with id %d.%d' % (cmdname, id, subid))
    return None

  return mlist[0]
Ejemplo n.º 2
0
def mesh_to_molecule(cmdname, args):
    
  fields = args.split()

  if len(fields) != 2:
    from Midas.midas_text import error
    error('%s requires 2 argument: %s <surface-model-id> <stick-radius>' %
          (cmdname, cmdname))
    return

  sid, rad = fields

  s = parse_surface_id(sid, cmdname)
  if s == None:
    return
  
  # Parse stick radius
  try:
    radius = float(rad)
  except ValueError:
    from Midas.midas_text import error
    error('%s: Invalid radius value %s' % (cmdname, rad))
    return

  molecule_from_mesh(s, radius)
Ejemplo n.º 3
0
def multiscale_color(cmdname, args):

    fields = args.split()

    if len(fields) != 3:
        from Midas.midas_text import error
        error(
            '%s requires 3 arguments, got %d: %s <multiscale-surface-id> <atom-spec> <coloring-distance>'
            % (cmdname, len(fields), cmdname))
        return

    surf_spec, atom_spec, dist = fields

    ms_models = parse_multiscale_models(surf_spec, cmdname)
    if len(ms_models) == 0:
        return

    atoms = parse_atom_specifier(atom_spec, cmdname)
    if len(atoms) == 0:
        return

    # Parse coloring distance
    try:
        distance = float(dist)
    except ValueError:
        from Midas.midas_text import error
        error('%s: Invalid distance value %s' % (cmdname, dist))
        return

    multiscale_color_by_atoms(ms_models, atoms, distance)
def split_molecules(cmdname, args):

    fields = args.split()

    from chimera import openModels, Molecule
    if len(fields) >= 1:
        from chimera import specifier
        sel = specifier.evalSpec(fields[0])
        mlist = sel.molecules()
    else:
        mlist = openModels.list(modelTypes=[Molecule])

    if len(mlist) == 0:
        from Midas.midas_text import error
        error('%s: No molecules to split.' % cmdname)
        return

    slist = []
    for m in mlist:
        clist = split_molecule(m)
        if clist:
            openModels.add(clist, baseId=m.id, noprefs=True)
            for c in clist:
                c.openState.xform = m.openState.xform
            slist.append(m)
            from chimera import makeLongBondsDashed, makePseudoBondsToMetals
            makePseudoBondsToMetals(clist)
            makeLongBondsDashed(clist)

    openModels.close(slist)
Ejemplo n.º 5
0
def multiscale_color(cmdname, args):
    
  fields = args.split()

  if len(fields) != 3:
    from Midas.midas_text import error
    error('%s requires 3 arguments, got %d: %s <multiscale-surface-id> <atom-spec> <coloring-distance>' % (cmdname, len(fields), cmdname))
    return

  surf_spec, atom_spec, dist = fields

  ms_models = parse_multiscale_models(surf_spec, cmdname)
  if len(ms_models) == 0:
    return

  atoms = parse_atom_specifier(atom_spec, cmdname)
  if len(atoms) == 0:
    return

  # Parse coloring distance
  try:
    distance = float(dist)
  except ValueError:
    from Midas.midas_text import error
    error('%s: Invalid distance value %s' % (cmdname, dist))
    return

  multiscale_color_by_atoms(ms_models, atoms, distance)
Ejemplo n.º 6
0
def no_bondzone_command(cmdname, args):

    from Midas.midas_text import error
    fields = args.split()
    if len(fields) > 1:
        error('Syntax error: %s [relative_point_spacing]' % cmdname)
        return

    use_bond_zone(False)
Ejemplo n.º 7
0
def no_bondzone_command(cmdname, args):

    from Midas.midas_text import error
    fields = args.split()
    if len(fields) > 1:
        error('Syntax error: %s [relative_point_spacing]' % cmdname)
        return

    use_bond_zone(False)
Ejemplo n.º 8
0
def bondzone_command(cmdname, args):

    from Midas.midas_text import error
    fields = args.split()
    if len(fields) > 1:
        error('Syntax error: %s [relative_point_spacing]' % cmdname)
        return
    elif len(fields) == 1:
        try:
            spacing = float(fields[0])
        except ValueError:
            error('Error: %s illegal point spacing "%s"' % (cmdname, fields[0]))
            return
        use_bond_zone(True, spacing)
    else:
        use_bond_zone(True)
Ejemplo n.º 9
0
def multiscale_uncolor(cmdname, args):

    fields = args.split()

    if len(fields) != 1:
        from Midas.midas_text import error
        error('%s requires 1 argument, got %d: %s <multiscale-surface-id>' %
              (cmdname, len(fields), cmdname))
        return

    surf_spec = fields[0]

    ms_models = parse_multiscale_models(surf_spec, cmdname)
    if len(ms_models) == 0:
        return

    multiscale_uncolor_surfaces(ms_models)
Ejemplo n.º 10
0
def multiscale_uncolor(cmdname, args):
    
  fields = args.split()

  if len(fields) != 1:
    from Midas.midas_text import error
    error('%s requires 1 argument, got %d: %s <multiscale-surface-id>'
          % (cmdname, len(fields), cmdname))
    return

  surf_spec = fields[0]

  ms_models = parse_multiscale_models(surf_spec, cmdname)
  if len(ms_models) == 0:
    return

  multiscale_uncolor_surfaces(ms_models)
Ejemplo n.º 11
0
def bondzone_command(cmdname, args):

    from Midas.midas_text import error
    fields = args.split()
    if len(fields) > 1:
        error('Syntax error: %s [relative_point_spacing]' % cmdname)
        return
    elif len(fields) == 1:
        try:
            spacing = float(fields[0])
        except ValueError:
            error('Error: %s illegal point spacing "%s"' %
                  (cmdname, fields[0]))
            return
        use_bond_zone(True, spacing)
    else:
        use_bond_zone(True)
Ejemplo n.º 12
0
def parse_atom_specifier(atom_spec, cmdname):

    # Parse atoms
    from chimera import specifier
    try:
        asel = specifier.evalSpec(atom_spec)
    except:
        from Midas.midas_text import error
        error('%s: Bad atom specifier %s' % (cmdname, atom_spec))
        return []

    atoms = asel.atoms()
    if len(atoms) == 0:
        from Midas.midas_text import error
        error('%s: No atoms specified by specifier %s' % (cmdname, atom_spec))
        return []

    return atoms
Ejemplo n.º 13
0
def parse_atom_specifier(atom_spec, cmdname):

  # Parse atoms
  from chimera import specifier
  try:
    asel = specifier.evalSpec(atom_spec)
  except:
    from Midas.midas_text import error
    error('%s: Bad atom specifier %s' % (cmdname, atom_spec))
    return []

  atoms = asel.atoms()
  if len(atoms) == 0:
    from Midas.midas_text import error
    error('%s: No atoms specified by specifier %s' % (cmdname, atom_spec))
    return []

  return atoms
Ejemplo n.º 14
0
def parse_multiscale_models(surf_spec, cmdname):
  
  # Parse multiscale models
  from chimera import specifier
  try:
    ssel = specifier.evalSpec(surf_spec)
  except:
    from Midas.midas_text import error
    error('%s: Bad model specifier %s' % (cmdname, surf_spec))
    return []

  ms_models = multiscale_models(ssel.models())

  if len(ms_models) == 0:
    from Midas.midas_text import error
    error('%s: No multiscale models specified by %s' % (cmdname, surf_spec))
    return []

  return ms_models
Ejemplo n.º 15
0
def parse_multiscale_models(surf_spec, cmdname):

    # Parse multiscale models
    from chimera import specifier
    try:
        ssel = specifier.evalSpec(surf_spec)
    except:
        from Midas.midas_text import error
        error('%s: Bad model specifier %s' % (cmdname, surf_spec))
        return []

    ms_models = multiscale_models(ssel.models())

    if len(ms_models) == 0:
        from Midas.midas_text import error
        error('%s: No multiscale models specified by %s' %
              (cmdname, surf_spec))
        return []

    return ms_models
def hkcage(h,
           k,
           radius=100.0,
           orientation='222',
           color=(1, 1, 1, 1),
           linewidth=1.0,
           sphere=0.0,
           replace=True):

    from Midas.midas_text import error
    if not type(h) is int or not type(k) is int:
        error('h and k must be integers, got %s %s' % (repr(h), repr(k)))
        return

    if h < 0 or k < 0 or (h == 0 and k == 0):
        error('h and k must be non-negative and one > 0, got %d %d' % (h, k))
        return

    from chimera import MaterialColor
    if isinstance(color, MaterialColor):
        color = color.rgba()

    from Icosahedron import coordinate_system_names
    if not orientation in coordinate_system_names:
        error('Invalid orientation %s, must be one of: %s' %
              (orientation, ', '.join(coordinate_system_names)))
        return

    from cages import show_hk_lattice
    show_hk_lattice(h, k, radius, orientation, color, linewidth, sphere,
                    replace)
Ejemplo n.º 17
0
def hkcage(h, k, radius = 100.0, orientation = '222', color = (1,1,1,1),
           linewidth = 1.0, sphere = 0.0, replace = True):

    from Midas.midas_text import error
    if not type(h) is int or not type(k) is int:
        error('h and k must be integers, got %s %s' % (repr(h), repr(k)))
        return

    if h < 0 or k < 0 or (h == 0 and k == 0):
        error('h and k must be non-negative and one > 0, got %d %d' % (h,k))
        return

    from chimera import MaterialColor
    if isinstance(color, MaterialColor):
        color = color.rgba()

    from Icosahedron import coordinate_system_names
    if not orientation in coordinate_system_names:
        error('Invalid orientation %s, must be one of: %s' %
              (orientation, ', '.join(coordinate_system_names)))
        return

    from cages import show_hk_lattice
    show_hk_lattice(h, k, radius, orientation, color, linewidth, sphere,
                    replace)
Ejemplo n.º 18
0
def make_surface(volumes, height = None, interpolation = 'none',
                 meshType = 'isotropic', colorMap = 'rainbow',
                 smoothingFactor = 0.3, smoothingIterations = 0,
                 replace = True):

  from Midas.midas_text import error

  if not height is None and not isinstance(height, (float,int)):
    error('Invalid non-numeric height "%s"' % str(height))
    return
  
  if not interpolation in ('cubic', 'none'):
    error('Invalid interpolation "%s" (cubic, none)' % str(interpolation))
    return
  
  if not meshType in ('isotropic', 'slash', 'backslash'):
    error('Invalid meshType "%s" (isotropic, slash, backslash)'
          % str(meshType))
    return
  
  if not colorMap in ('rainbow', 'none'):
    error('Invalid colorMap "%s" (rainbow, none)' % str(colorMap))
    return

  if not isinstance(smoothingIterations, int):
    error('Smoothing iterations must be integer, got "%s"'
          % str(smoothingIterations))
    return
  if not isinstance(smoothingFactor, (float,int)):
    error('Smoothing factor must be number, got "%s"'
          % str(smoothingFactor))
    return

  volumes = replace_solid_models_by_volume(volumes)
  
  from VolumeViewer import Volume
  for v in volumes:
    if not isinstance(v, Volume):
      error('Model %s is not a volume' % v.name)
      return

  for v in volumes:
    
    if len([s for s in v.matrix_size() if s == 1]) != 1:
      error('Volume %s is not a plane, size (%d,%d,%d)' %
            ((v.name,) + tuple(v.matrix_size())))
      return
    
  from toposurf import create_volume_plane_surface
  for v in volumes:
    create_volume_plane_surface(v, height, interpolation, meshType, colorMap,
                                smoothingFactor, smoothingIterations,
                                replace = replace)
Ejemplo n.º 19
0
def make_surface(volumes,
                 height=None,
                 interpolation='none',
                 meshType='isotropic',
                 colorMap='rainbow',
                 smoothingFactor=0.3,
                 smoothingIterations=0,
                 replace=True):

    from Midas.midas_text import error

    if not height is None and not isinstance(height, (float, int)):
        error('Invalid non-numeric height "%s"' % str(height))
        return

    if not interpolation in ('cubic', 'none'):
        error('Invalid interpolation "%s" (cubic, none)' % str(interpolation))
        return

    if not meshType in ('isotropic', 'slash', 'backslash'):
        error('Invalid meshType "%s" (isotropic, slash, backslash)' %
              str(meshType))
        return

    if not colorMap in ('rainbow', 'none'):
        error('Invalid colorMap "%s" (rainbow, none)' % str(colorMap))
        return

    if not isinstance(smoothingIterations, int):
        error('Smoothing iterations must be integer, got "%s"' %
              str(smoothingIterations))
        return
    if not isinstance(smoothingFactor, (float, int)):
        error('Smoothing factor must be number, got "%s"' %
              str(smoothingFactor))
        return

    volumes = replace_solid_models_by_volume(volumes)

    from VolumeViewer import Volume
    for v in volumes:
        if not isinstance(v, Volume):
            error('Model %s is not a volume' % v.name)
            return

    for v in volumes:

        if len([s for s in v.matrix_size() if s == 1]) != 1:
            error('Volume %s is not a plane, size (%d,%d,%d)' %
                  ((v.name, ) + tuple(v.matrix_size())))
            return

    from toposurf import create_volume_plane_surface
    for v in volumes:
        create_volume_plane_surface(v,
                                    height,
                                    interpolation,
                                    meshType,
                                    colorMap,
                                    smoothingFactor,
                                    smoothingIterations,
                                    replace=replace)