Пример #1
0
def surfinglines():
    cmd.hide('everything')
    glb.update()
    cmd.map_new('map', "gaussian", "0.75", 'all')
    glb.procolor(None,show_all='lines')
    cmd.isosurface('map1', 'map', '1')
    cmd.color('orange', "map1")
    cmd.set('transparency', '0.4')
    cmd.set('ambient', '0.45')
Пример #2
0
Файл: nci.py Проект: rmera/ncipy
def nci( arg1 ):
	densf=arg1+"-dens"
	gradf=arg1+"-grad"
#	gdens=open(densf+".cube","r")
#	grad=open(gradf+".cube","r")
	cmd.isosurface("grad",gradf, 0.5)
	cmd.ramp_new("ramp", densf, [-5,5], "rainbow")
	cmd.set("surface_color", "ramp", "grad")
	cmd.set('two_sided_lighting',value=1)
Пример #3
0
 def testSurfaceAction(self):
     sele = 'surf1'
     mapname = 'map1'
     self._make_map(mapname)
     cmd.isosurface(sele, mapname)
     m = menu.surface_action(cmd, sele)
     self._eval_first(m)
     m = menu.surface_hide(cmd, sele)
     self._eval_first(m)
     m = menu.surface_show(cmd, sele)
     self._eval_first(m)
Пример #4
0
def rpcLoadSurface(fileName, objName, format='', surfaceLevel=1.0):
  """ loads surface data from a file and adds an isosurface
 
    Arguments:
      fileName: the file to load
      objName: (OPTIONAL) name of the object to create
      format: (OPTIONAL) the format of the input file
      surfaceLevel: (OPTIONAL) the isosurface level
 
   """
  if not objName:
    objName = fileName.split('.')[0]
  gridName = 'grid-%s' % objName
  res = cmd.load(fileName, gridName, format='')
  cmd.isosurface(objName, gridName, level=surfaceLevel)
  if res is not None:
    return res
  else:
    return ''
Пример #5
0
 def esurf(event):
     delcrea()
     try:
         if len(nameit.get()) < 1:
             
             
             showinfo("Error", 'Enter a name for the object')
             interior.mainloop()
         elif len(pdbname.get()) < 1:
             
             
             showinfo('Error', "Enter the Map Filename")
             interior.mainloop()
         else:
             cmd.isosurface(nameit.get(), pdbname.get(), contour1.get())
     except:
         
         
         showinfo("Error", 'No map is present')
         interior.mainloop()
Пример #6
0
 def esurf1(event):
     delcrea()
     try:
         if len(nameit.get()) < 1:
             
             
             showinfo("Error", 'Enter a name for the object')
             interior.mainloop()
         elif len(pdbname.get()) < 1:
             
             
             showinfo('Error', "Enter the Map Filename")
             interior.mainloop()
         
         else:
             cmd.isosurface(nameit.get(), pdbname.get(), contour1.get(), ('sele'))
     except:
         cmd.orient('all')
         
         
         showinfo("Error", 'No map is present\n Or there is no selection ("sele")')
         interior.mainloop()
Пример #7
0
def esurf(*args):
    delcrea()
    try:
        cmd.isosurface('map1','map', contour1.get())
    except:
        try:
            cmd.set("suspend_updates",1,quiet=1)
            cmd.remove("hydro")
            cmd.enable('all')
            cmd.map_new('map',"gaussian","0.75", 'all')
            cmd.isosurface("map1", "map", 9999.0, 'all')
            cmd.set("suspend_updates",0,quiet=1)
            cmd.refresh()
            cmd.isosurface('map1','map', contour1.get())
        except:
            showinfo("Error", 'No PDB is present')
            interior.mainloop()
Пример #8
0
def esurf1(event):
    delcrea()
    try:
        cmd.isosurface('map1','map', contour1.get(), 'sele')
    except:
        try:
            cmd.set("suspend_updates",1,quiet=1)
            cmd.remove("hydro")
            cmd.enable('all')
            cmd.map_new('map',"gaussian","0.75", 'all')
            cmd.isosurface("map1", "map", 9999.0, 'all')
            cmd.set("suspend_updates",0,quiet=1)
            cmd.refresh()
            cmd.isosurface('map1','map', contour1.get(), 'sele')
        except:
            cmd.orient('all')
            showinfo("Error", 'No PDB is present\nOr there is no selection ('"sele"')')
            interior.mainloop()
Пример #9
0
from os.path import join
import tempfile
import zipfile
import math
from pymol import cmd, finish_launching
from pymol.cgo import *

finish_launching()

cmd.set_color("pomegranate",
              (0.9411764705882353, 0.20392156862745098, 0.20392156862745098))
cmd.load("test_grid.grd", "mygrid", state=1)
cmd.isosurface(name="mysurface", map="mygrid", level="4")

cmd.color("pomegranate", "mysurface")
Пример #10
0
def genAV(obstacles,
          attachment,
          linker_length=20.0,
          linker_diameter=2.0,
          dye_radius=3.5,
          disc_step=0.9,
          name=None,
          state=1,
          stripsc=True,
          allowed_sphere_radius=0.0,
          smoothSurf=True):

    source = np.array(cmd.get_model(attachment, state).get_coord_list())
    if (source.shape[0] != 1):
        print(
            'attachment selection must contain exactly one atom, selected: {}'.
            format(source.shape[0]))
        return
    source = source.reshape(3)

    srcAt = cmd.get_model(attachment, state).atom[0]
    srcModelName = cmd.get_names('objects', 0, attachment)[0]

    obstacles = '(' + obstacles + ') and not (' + attachment + ')'
    if stripsc and isAA(srcAt.resn):
        obstacles += ' and not (' + srcModelName
        if len(srcAt.chain) > 0:
            obstacles += ' and chain ' + srcAt.chain
        obstacles += ' and resi ' + srcAt.resi + ' and sidechain' + ')'
    if allowed_sphere_radius > 0.0:
        obstacles += ' and not (({}) around {})'.format(
            attachment, allowed_sphere_radius)

    xyzRT = np.zeros((1, 4))
    nAtoms = cmd.count_atoms(obstacles)
    if nAtoms > 0:
        atoms = cmd.get_model(obstacles, state).atom
        nAtoms = len(atoms)
        xyzRT = np.zeros((nAtoms, 4))
        for i, at in enumerate(atoms):
            xyzRT[i] = [at.coord[0], at.coord[1], at.coord[2], at.vdw]

    av1 = ll.dyeDensityAV1(xyzRT.T, source, linker_length, linker_diameter,
                           dye_radius, disc_step)
    m = avToModel(av1)
    if len(m.atom) == 0:
        print('Failed: Empty AV. Is attachment position buried?')
        return
    if name is None:
        name = srcModelName + '_'
        if len(srcAt.chain) > 0:
            name += srcAt.chain + '-'
        name += srcAt.resi + '-' + srcAt.name
    cmd.load_model(m, name)

    if smoothSurf:
        surfName = name + '_surf'
        mapName = name + '_map'
        gRes = cmd.get('gaussian_resolution')
        cmd.set('gaussian_resolution', 3.0)
        cmd.map_new(mapName, 'gaussian', 1.0, name, 6)
        cmd.isosurface(surfName, mapName, 0.9)
        cmd.set('gaussian_resolution', gRes)
        cmd.disable(name)
Пример #11
0
colour_dict = {'acceptor':'red', 'donor':'blue', 'apolar':'yellow', 'negative':'purple', 'positive':'cyan'}

threshold_list = [10, 14, 17]
gfiles = ['donor.grd', 'apolar.grd', 'acceptor.grd']
grids = ['donor', 'apolar', 'acceptor']
num = 0
surf_transparency = 0.2

if dirpath:
    gfiles = [join(dirpath, g) for g in gfiles]

for t in threshold_list:
    for i in range(len(grids)):
        try:
            cmd.load(r'%s'%(gfiles[i]), '%s_%s'%(grids[i], str(num)))
            cmd.isosurface('surface_%s_%s_%s'%(grids[i], t, num), '%s_%s'%(grids[i], num), t)
            cmd.set('transparency', surf_transparency, 'surface_%s_%s_%s'%(grids[i], t, num))
            cmd.color(colour_dict['%s'%(grids[i])], 'surface_%s_%s_%s'%(grids[i], t, num))
            cmd.group('threshold_%s'%(t), members = 'surface_%s_%s_%s'%(grids[i],t, num))
            cmd.group('threshold_%s' % (t), members='label_threshold_%s' % (t))
        except:
            continue



    try:
        cmd.group('hotspot_%s' % (num), members='threshold_%s' % (t))
    except:
        continue
    
    for g in grids:
Пример #12
0
cmd.group("ligand_pharmacophore", members="CYS_pts")
cmd.group("ligand_pharmacophore", members="PHE_pts")
cmd.group("ligand_pharmacophore", members="LEU_pts")
cmd.group("ligand_pharmacophore", members="LYS_pts")
cmd.group("ligand_pharmacophore", members="ILE_pts")
cmd.group("ligand_pharmacophore", members="THR_pts")
cmd.group("ligand_pharmacophore", members="TRP_pts")
cmd.group("ligand_pharmacophore", members="ASN_pts")
cmd.group("ligand_pharmacophore", members="VAL_pts")
cmd.group("ligand_pharmacophore", members="HIS_pts")
cmd.group("ligand_pharmacophore", members="MET_pts")
cmd.group("ligand_pharmacophore", members="ARG_pts")
cmd.group("ligand_pharmacophore", members="GLU_pts")
cmd.set_color("ring_color", (0.33, 1.0, 0.0))
cmd.load("ring.grd", "ring_grid")
cmd.isosurface(name="surface_ring", map="ring_grid", level="1")

cmd.color("ring_color", "surface_ring")
cmd.set_color("acceptor_projected_color", (1.0, 0.0, 0.0))
cmd.load("acceptor_projected.grd", "acceptor_projected_grid")
cmd.isosurface(name="surface_acceptor_projected",
               map="acceptor_projected_grid",
               level="1")

cmd.color("acceptor_projected_color", "surface_acceptor_projected")
cmd.set_color("donor_projected_color", (0.0, 0.0, 1.0))
cmd.load("donor_projected.grd", "donor_projected_grid")
cmd.isosurface(name="surface_donor_projected",
               map="donor_projected_grid",
               level="1")
Пример #13
0
def set_atom_level(level,
                   selection='*',
                   state=None,
                   rec_map=None,
                   lig_map=None):

    if rec_map is None:
        rec_channels = atom_types.get_default_rec_channels()
    else:
        rec_channels = atom_types.get_channels_from_file(
            rec_map, name_prefix='Receptor')

    if lig_map is None:
        lig_channels = atom_types.get_default_lig_channels()
    else:
        lig_channels = atom_types.get_channels_from_file(lig_map,
                                                         name_prefix='Ligand')

    channels = rec_channels + lig_channels
    channels_by_name = dict((c.name, c) for c in channels)

    for c in channels:
        cmd.set_color(c.name + '$', atom_types.get_channel_color(c))

    dx_regex = re.compile(r'(.*)_(\d+)_({})\.dx'.format(
        '|'.join(channels_by_name)))

    surface_groups = OrderedDict()
    for dx_object in sorted(cmd.get_names('objects')):

        if not fnmatch.fnmatch(dx_object, selection):
            continue

        m = dx_regex.match(dx_object)
        if not m:
            continue

        grid_prefix = m.group(1)
        sample_idx = int(m.group(2))
        channel = channels_by_name[m.group(3)]

        if state is None:
            surface_state = sample_idx + 1
        else:
            surface_state = state

        surface_object = '{}_{}_surface'.format(grid_prefix, channel.name)
        cmd.isosurface(surface_object,
                       dx_object,
                       level=level,
                       state=surface_state)
        cmd.color(channel.name + '$', surface_object)

        if grid_prefix not in surface_groups:
            surface_groups[grid_prefix] = []

        if surface_object not in surface_groups[grid_prefix]:
            surface_groups[grid_prefix].append(surface_object)

    for grid_prefix, surface_objects in surface_groups.items():
        surface_group = '{}_surfaces'.format(grid_prefix)
        cmd.group(surface_group, ' '.join(surface_objects))
Пример #14
0
import zipfile
import math
from pymol import cmd, finish_launching, plugins
from pymol.cgo import *

finish_launching()

dirpath = tempfile.mkdtemp()
zip_dir = "out.zip"
wd = os.getcwd()
with zipfile.ZipFile(zip_dir) as hs_zip:
    hs_zip.extractall(dirpath)

os.chdir(dirpath)
cmd.load("hotspot/apolar.grd", "apolar_hotspot")
cmd.isosurface(name="surface_apolar_hotspot", map="apolar_hotspot", level="5")

cmd.color("yellow", "surface_apolar_hotspot")
cmd.set("transparency", 0.2, "surface_apolar_hotspot")
cmd.load("hotspot/donor.grd", "donor_hotspot")
cmd.isosurface(name="surface_donor_hotspot", map="donor_hotspot", level="5")

cmd.color("blue", "surface_donor_hotspot")
cmd.set("transparency", 0.2, "surface_donor_hotspot")
cmd.load("hotspot/acceptor.grd", "acceptor_hotspot")
cmd.isosurface(name="surface_acceptor_hotspot",
               map="acceptor_hotspot",
               level="5")

cmd.color("red", "surface_acceptor_hotspot")
cmd.set("transparency", 0.2, "surface_acceptor_hotspot")
Пример #15
0
def set_atom_level(level, selection='*', state=None):

    channels = atom_types.get_default_channels(True)
    channel_names = [c.name for c in channels]
    channels_by_name = {n: channels[i] for i, n in enumerate(channel_names)}

    for channel in channels:
        cmd.set_color(channel.name + '$',
                      atom_types.get_channel_color(channel))

    # first identify .dx atom density grids
    dx_pattern = r'(.*)_({})\.dx'.format('|'.join(channel_names))
    dx_groups = OrderedDict()
    for obj in sorted(cmd.get_names('objects')):

        match = re.match(dx_pattern, obj)
        if match:
            dx_prefix = match.group(1)
            if dx_prefix not in dx_groups:
                dx_groups[dx_prefix] = []
            dx_groups[dx_prefix].append(obj)

    surface_groups = OrderedDict()
    for dx_prefix in dx_groups:

        match = re.match(r'^(.*)_(\d+)$', dx_prefix)
        if match:
            surface_prefix = match.group(1)
            if state is None:
                state_ = int(match.group(2)) + 1
            else:
                state_ = state
        else:
            surface_prefix = dx_prefix
            state_ = state or 0

        for dx_object in dx_groups[dx_prefix]:

            if fnmatch.fnmatch(dx_object, selection):

                match = re.match(dx_pattern, dx_object)
                channel_name = match.group(2)
                channel = channels_by_name[channel_name]
                element = atom_types.get_name(channel.atomic_num)

                surface_object = '{}_{}_surface'.format(
                    surface_prefix, channel_name)
                cmd.isosurface(surface_object,
                               dx_object,
                               level=level,
                               state=state_)

                cmd.color(channel.name + '$', surface_object)

                if surface_prefix not in surface_groups:
                    surface_groups[surface_prefix] = []

                if surface_object not in surface_groups[surface_prefix]:
                    surface_groups[surface_prefix].append(surface_object)

    for surface_prefix in surface_groups:
        surface_group = '{}_surface'.format(surface_prefix)
        cmd.group(surface_group, ' '.join(surface_groups[surface_prefix]))
Пример #16
0
def show_iso(dname, iso, color="white"):
    sname = "%s%.4f" % (dname, iso)
    cmd.isosurface(sname, dname, iso)
    cmd.set("surface_color", color, sname)
    cmd.rebuild()
Пример #17
0
cmd.load_cgo(obj, 'axes')

cmd.bg_color('white')

#cmd.set_bond ('stick_color', 'white', 'clauc2h2', 'clauc2h2')
#cmd.set_bond ('stick_radius', -0.14, 'clauc2h2', 'clauc2h2')
#cmd.set ('stick_ball', 1)
#cmd.set ('stick_ball_ratio', -0.5)
#cmd.set ('stick_ball_color', 'atomic')
#cmd.show ('sticks', 'clauc2h2')
##cmd.set ('sphere_scale', 0.25, 'clauc2h2')
##cmd.show ('spheres', 'clauc2h2')

cmd.load('this.cube')
cmd.isosurface('sp', 'this', _iso)
cmd.color('green', 'sp')
cmd.isosurface('sm', 'this', -_iso)
cmd.color('_colorm', 'sm')

#cmd.load('dif_B1.cube')
#cmd.isosurface('spp', 'dif_B1', 0.00008)
#cmd.color('blue', 'spp')
#cmd.isosurface('smp', 'dif_B1', -0.00008)
#cmd.color('red', 'smp')

#cmd.set ('label_font_id', 16)
#cmd.set ('label_size', 24)
#cmd.pseudoatom('xatom', pos=[1,0,0], label="x")
#cmd.pseudoatom('yatom', pos=[0,1,0], label="y")
#cmd.pseudoatom('zatom', pos=[0,0,2], label="z")
Пример #18
0
cmd.load_cgo(obj, 'axes')

cmd.bg_color('white')

#cmd.set_bond ('stick_color', 'white', 'clauc2h2', 'clauc2h2')
#cmd.set_bond ('stick_radius', -0.14, 'clauc2h2', 'clauc2h2')
#cmd.set ('stick_ball', 1)
#cmd.set ('stick_ball_ratio', -0.5)
#cmd.set ('stick_ball_color', 'atomic')
#cmd.show ('sticks', 'clauc2h2')
##cmd.set ('sphere_scale', 0.25, 'clauc2h2')
##cmd.show ('spheres', 'clauc2h2')

cmd.load('this.cube')
cmd.isosurface('sp', 'this', 0.005)
cmd.color('gray90', 'sp')
cmd.isosurface('sm', 'this', -0.005)
cmd.color('red', 'sm')

#cmd.set ('label_font_id', 16)
#cmd.set ('label_size', 24)
#cmd.pseudoatom('xatom', pos=[1,0,0], label="x")
#cmd.pseudoatom('yatom', pos=[0,1,0], label="y")
#cmd.pseudoatom('zatom', pos=[0,0,2], label="z")
cmd.set('label_font_id', 16)
cmd.set('label_size', 20)
cmd.pseudoatom('xatom', pos=[2.5, 0, 0], label="x")
cmd.pseudoatom('yatom', pos=[0, 2.5, 0], label="y")
cmd.pseudoatom('zatom', pos=[0, 0, 5.5], label="z")
Пример #19
0
def set_atom_level(
    level,
    selection='*',
    state=None,
    rec_map=None,
    lig_map=None,
    interp=False,
    job_name=None,
    array_job=False,
):
    interp = as_bool(interp)
    array_job = as_bool(array_job)

    # get atom type channel info and set custom colors
    try:
        rec_channels = atom_types.get_channels_from_file(rec_map)
    except:
        rec_channels = atom_types.get_default_rec_channels()
    try:
        lig_channels = atom_types.get_channels_from_file(lig_map)
    except:
        lig_channels = atom_types.get_default_lig_channels()

    channels = rec_channels + lig_channels
    channels_by_name = {ch.name: ch for ch in channels}
    channel_names = channels_by_name.keys()

    for ch in channels:
        for grid_type in ['rec', 'lig', 'lig_gen', 'lig_fit', 'lig_gen_fit']:
            color_name = grid_type + '_' + ch.name
            cmd.set_color(color_name+'$', get_color(grid_type, ch.atomic_num))

    # We sort grids based on two different criteria before creating surfaces
    # for each grid. The first criteria determines what STATE to put the
    # surface in, the second determines what GROUP to put it in.

    # We expect grid names to store info in the following basic format:
    #   {job_name}_{lig_name}_{grid_type}_{sample_idx}_{channel_name}

    # By default,
    #   group=(job_name, lig_name, grid_type)
    #   state=(sample_idx,)

    # With interp=True,
    #   group=(job_name, grid_type)
    #   state=(lig_name, sample_idx)

    # get list of selected grid objects
    grids = []
    for obj in cmd.get_names('objects'):
        m = re.match(r'^(.*)(\.dx|_grid)$', obj)
        if m and fnmatch.fnmatch(obj, selection):
            grids.append(obj)

    # try to infer the job_name from working directory
    if job_name is None:
        job_name = os.path.basename(os.getcwd())

    # create a regex for parsing grid names
    grid_re_fields = [r'(?P<job_name>{})'.format(job_name)]

    if array_job:
        grid_re_fields += [r'(?P<array_idx>\d+)']

    grid_re_fields += [
        r'(?P<lig_name>.+)',
        r'(?P<grid_type>rec|lig(_gen)?(_conv|_fit)?)',
        r'(?P<sample_idx>\d+)',
        r'(?P<channel_name>{})'.format('|'.join(channel_names)),
    ]
    grid_re = re.compile('^' + '_'.join(grid_re_fields) + r'(\.dx|_grid)$')

    # assign grids to groups and states
    grouped_surfaces = OrderedDict()
    grouped_lig_names = OrderedDict()
    state_counter = OrderedDict()

    for i, grid in enumerate(grids):

        m = grid_re.match(grid)
        try:
            lig_name = m.group('lig_name')
            grid_type = m.group('grid_type')
            sample_idx = int(m.group('sample_idx'))
            channel_name = m.group('channel_name')
        except:
            print(grid_re)
            print(grid)
            raise

        if interp:
            group_criteria = (job_name, grid_type)
            state_criteria = (lig_name, sample_idx)
            surface_format = '{job_name}_{grid_type}_{channel_name}_surface'
        else:
            group_criteria = (job_name, lig_name, grid_type)
            state_criteria = sample_idx
            surface_format = '{job_name}_{lig_name}_{grid_type}_{channel_name}_surface'

        surface = surface_format.format(**m.groupdict())

        if state_criteria not in state_counter:
            state_counter[state_criteria] = len(state_counter) + 1
        s = state_counter[state_criteria]

        if group_criteria not in grouped_surfaces:
            grouped_surfaces[group_criteria] = []
            grouped_lig_names[group_criteria] = []

        if surface not in grouped_surfaces[group_criteria]:
            grouped_surfaces[group_criteria].append(surface)

        if lig_name not in grouped_lig_names[group_criteria]:
            grouped_lig_names[group_criteria].append(lig_name)

        channel = channels_by_name[channel_name]
        cmd.isosurface(surface, grid, level=level, state=s)
        cmd.color(grid_type + '_' + channel.name+'$', surface)
        print('[{}/{}] {}'.format(i+1, len(grids), surface, group_criteria, s))

    for group_criteria, surfaces in grouped_surfaces.items():
        if interp:
            job_name, grid_type = group_criteria
            lig_names = grouped_lig_names[group_criteria]
            surface_group = '_'.join(
                (job_name, '_to_'.join(lig_names), grid_type)
            ) + '_surfaces'
        else:
            surface_group = '_'.join(group_criteria) + '_surfaces'
        cmd.group(surface_group, ' '.join(surfaces))

    print('Done')