def split_states_chains_save( sel1 ):
    '''
    Simple script to split states of NMR ensemble and then save the complex and chain A separately for each state
    '''
    cmd.remove("resn hoh")

    for ind in range(1,cmd.count_states(sel1)+1):
        if cmd.count_states(sel1) > 1:
            cmd.split_states(sel1)
            file_prefix="{0}_{1:04d}".format(sel1, ind)
        else:
            file_prefix=sel1   
        cmd.save(file_prefix + "_complex.pdb", file_prefix)
        cmd.split_chains(file_prefix)
        cmd.save(file_prefix + ".pdb", file_prefix + "_A")
Beispiel #2
0
def display_graphkernel(pdb_id, pdb_path):
    '''
    '''
    # Load PDB
    cmd.bg_color('white')
    cmd.load(pdb_path + pdb_id[:-2] + '.pdb')
    cmd.split_chains(pdb_id[:-2])
    for name in cmd.get_names('objects', 0, '(all)'):
        if not name.endswith(pdb_id[-1].upper()) and name.startswith(
                pdb_id[:4]):
            cmd.delete(name)
        else:
            zero_residues(name)
    cmd.reset()

    pdb_id2 = pdb_id + 'copy'
    cmd.create(pdb_id2, pdb_id)

    cmd.hide('everything', pdb_id)
    cmd.show_as('lines', pdb_id + ' and (name ca or name c or name n)')
    cmd.set('line_width', 5)
    cmd.set_bond('line_width', 5,
                 pdb_id + ' and (name ca or name c or name n)')
    cmd.show('spheres', pdb_id + ' and name ca')
    cmd.set('sphere_transparency', 0.0, pdb_id + ' and name ca')
    cmd.set('sphere_scale', 0.5, pdb_id + ' and name ca')

    cmd.hide('everything', pdb_id2)
    cmd.show('spheres', pdb_id2 + ' and name ca')
    cmd.set('sphere_transparency', 0.8, pdb_id2 + ' and name ca')
    cmd.set('sphere_scale', code2[elem], elem + '&' + selection)
    #cmd.set('sphere_scale', 2, pdb_id2 + ' and name ca')

    data = cmd.get_coords(selection=pdb_id + ' and name ca', state=1)

    j = 55
    cmd.set('dash_width', 1.0)
    cmd.set('dash_color', 'marine')
    for i in range(len(data)):
        cmd.distance('d' + str(i) + str(j),
                     pdb_id2 + ' and name ca and res ' + str(i),
                     pdb_id2 + ' and name ca and res ' + str(j))
        cmd.hide('labels', 'd' + str(i) + str(j))
    resicolor(pdb_id)

    resicolor(pdb_id)
    resicolor(pdb_id2, True)
Beispiel #3
0
def stucture_attribution(pdb_id, attributions_path, pdb_path, flag=False):
    '''
    '''
    data = np.load(attributions_path)
    attributions = data['data']
    kernels = data['kernels']
    labels = data['labels']
    offsets = data['offsets']
    ind = np.where(labels == pdb_id)
    #attribution = attributions[ind][0][:,-1]
    if flag:
        a_ = data["all_"][0]
        a_[a_ <= 0] = 0.0
        attribution = data['all_'][0] + data['all_'][1]
        attribution[attribution <= 0] = 0.0
        attribution = a_ * attribution
    else:
        a_ = data["all_"][1]
        a_[a_ <= 0] = 0.0
        attribution = data['all_'][0] + data['all_'][1]
        attribution[attribution <= 0] = 0.0
        attribution = a_ * attribution

    # Load PDB
    cmd.load(pdb_path + pdb_id[:-2] + '.pdb')
    cmd.split_chains(pdb_id[:-2])
    for name in cmd.get_names('objects', 0, '(all)'):
        if not name.endswith(pdb_id[-1].upper()) and name.startswith(
                pdb_id[:4]):
            cmd.delete(name)
        else:
            zero_residues(name)
    cmd.reset()

    cmd.color('white', pdb_id)
    for i, _ in enumerate(attribution):
        #if flag: _ = _ *-1
        cmd.select('toBecolored',
                   pdb_id + ' and res ' + str(i + offsets[ind][0]))
        cmd.set_color('saliency' + str(i) + pdb_id, list(cmap(norm(_)))[:3])
        #else: cmd.set_color('saliency'+str(i)+pdb_id, list(cmap2(norm(_)))[:3])
        cmd.color('saliency' + str(i) + pdb_id, 'toBecolored')

    cmd.select('selected', pdb_id)
    #cmd.show('mesh', 'selected')
    #cmd.show('sticks', 'selected')
    cmd.deselect()
Beispiel #4
0
def kernels(pdb_id, data_path, pdb_path, flag=False):
    '''
    '''
    data = np.load(data_path)
    kernels = data['kernels']
    labels = data['labels']
    offsets = data['offsets']
    ind = np.where(labels == pdb_id)
    kernels = kernels[ind][0][0]

    # Load PDB
    cmd.load(pdb_path + pdb_id[:-2] + '.pdb')
    cmd.split_chains(pdb_id[:-2])
    for name in cmd.get_names('objects', 0, '(all)'):
        if not name.endswith(pdb_id[-1].upper()) and name.startswith(
                pdb_id[:4]):
            cmd.delete(name)
        else:
            zero_residues(name)
    cmd.reset()

    pdb_id2 = pdb_id + 'kernel'
    cmd.create(pdb_id2, pdb_id)
    cmd.delete(pdb_id)
    '''
    cmd.hide('everything',pdb_id)
    cmd.show_as('lines', pdb_id + ' and (name ca or name c or name n)')
    cmd.set('line_width', 5)
    cmd.set_bond('line_width', 5,  pdb_id + ' and (name ca or name c or name n)')
    cmd.show('spheres', pdb_id + ' and name ca')
    cmd.set('sphere_transparency', 0.0, pdb_id + ' and name ca')
    cmd.set('sphere_scale', 0.5, pdb_id + ' and name ca')
    '''

    cmd.hide('everything', pdb_id2)
    cmd.show('spheres', pdb_id2 + ' and name ca')
    cmd.set('sphere_transparency', 0.9, pdb_id2 + ' and name ca')

    for i, _ in enumerate(kernels):
        print(_)
        cmd.set(
            'sphere_scale', _ / (1.7 * 2),
            pdb_id2 + ' and res ' + str(i + offsets[ind][0]) + ' and name ca')
    cmd.deselect()
Beispiel #5
0
    def structure_attribution(self, pdb_id, flag=False):

        # Load Attribution
        data = np.load(self.attribution_path, allow_pickle=True)
        attributions = data['data']
        offsets = data['offsets']
        labels = data['labels']
        ind = np.where(labels == pdb_id)
        attribution = attributions[ind][0][:, -1]

        cmd.bg_color('white')
        cmd.load(self.data_path + pdb_id[:-2] + '.pdb')
        cmd.split_chains()
        for name in cmd.get_names('objects', 0, '(all)'):
            if not name.endswith(pdb_id[-1].upper()):
                cmd.delete(name)
            else:
                zero_residues(name)
        cmd.reset()

        cmd.color('white', pdb_id)
        for i, _ in enumerate(attribution):
            cmd.select('toBecolored', 'res ' + str(i + offsets[ind][0]))
            cmd.set_color('saliency' + str(i), list(cmap(norm(_)))[:3])
            cmd.color('saliency' + str(i), 'toBecolored')

        cmd.select('selected', 'chain ' + pdb_id[-1].upper())
        #cmd.show('mesh', 'selected')
        cmd.deselect()
        cmd.save(self.output_path + pdb_id + '.pse')
        return self.output_path + pdb_id + '.pse'


#############################################################
# pdb_id = '4q9z_a'
# attributions_path = 'Output/Kinases/seed1/attributions.npz'
# data_path = 'pdb_extractor/Kinases/PDB/'

# cmd.reinitialize()
# cmd.bg_color('black')
# sA = StructureAttribution(attributions_path,data_path)
# sA.structure_attribution(pdb_id)
Beispiel #6
0
def display_graphconv(pdb_id, pdb_path):
    '''
    '''
    cmd.bg_color('white')
    cmd.load(pdb_path + pdb_id[:-2] + '.pdb')
    cmd.split_chains(pdb_id[:-2])
    for name in cmd.get_names('objects', 0, '(all)'):
        if not name.endswith(pdb_id[-1].upper()) and name.startswith(
                pdb_id[:4]):
            cmd.delete(name)
        else:
            zero_residues(name)
    cmd.reset()

    pdb_id2 = pdb_id + 'copy'
    cmd.create(pdb_id2, pdb_id)

    cmd.color('white', pdb_id)
    cmd.hide('everything', pdb_id)
    cmd.show('spheres', pdb_id + ' and name ca')
    cmd.set('sphere_transparency', 0.0, pdb_id + ' and name ca')
    cmd.set('sphere_scale', 0.5, pdb_id + ' and name ca')
    data = cmd.get_coords(selection=pdb_id + ' and name ca', state=1)

    j = 55
    cmd.set('dash_width', 1.0)
    cmd.set('dash_color', 'marine')
    data = np.random.uniform(0, 0.25, len(data))
    for i in range(len(data)):
        cmd.distance('d' + str(i) + str(j),
                     pdb_id + ' and name ca and res ' + str(i),
                     pdb_id + ' and name ca and res ' + str(j))
        cmd.hide('labels', 'd' + str(i) + str(j))
        cmd.select('toBecolored', pdb_id + ' and name ca and res ' + str(i))
        if i == j:
            cmd.set_color('saliency' + str(i) + pdb_id,
                          list(cmap(norm(1)))[:3])
        else:
            cmd.set_color('saliency' + str(i) + pdb_id,
                          list(cmap(norm(data[i])))[:3])
        cmd.color('saliency' + str(i) + pdb_id, 'toBecolored')

    cmd.color('white', pdb_id2)
    cmd.hide('everything', pdb_id2)
    cmd.show('spheres', pdb_id2 + ' and name ca')
    cmd.set('sphere_transparency', 0.0, pdb_id2 + ' and name ca')
    cmd.set('sphere_scale', 0.5, pdb_id2 + ' and name ca')

    j = 55
    cmd.set('dash_width', 1.0)
    cmd.set('dash_color', 'marine')
    #data = np.random.uniform(0,0.25,len(data))
    for i in range(len(data)):
        cmd.distance('d' + str(i) + str(j),
                     pdb_id2 + ' and name ca and res ' + str(i),
                     pdb_id2 + ' and name ca and res ' + str(j))
        cmd.hide('labels', 'd' + str(i) + str(j))
        cmd.select('toBecolored', pdb_id2 + ' and name ca and res ' + str(i))
        if i == j:
            cmd.set_color('saliency' + str(i) + pdb_id2,
                          list(cmap(norm(0)))[:3])
        else:
            cmd.set_color('saliency' + str(i) + pdb_id2,
                          list(cmap(norm(data[i])))[:3])
        cmd.color('saliency' + str(i) + pdb_id2, 'toBecolored')
Beispiel #7
0
def display_graphpool(pdb_id, pdb_path):
    '''
    '''
    # Load PDB
    cmd.bg_color('white')
    cmd.load(pdb_path + pdb_id[:-2] + '.pdb')
    cmd.split_chains(pdb_id[:-2])
    for name in cmd.get_names('objects', 0, '(all)'):
        if not name.endswith(pdb_id[-1].upper()) and name.startswith(
                pdb_id[:4]):
            cmd.delete(name)
        else:
            zero_residues(name)
    cmd.reset()

    pdb_id2 = pdb_id + 'copy'
    cmd.create(pdb_id2, pdb_id)

    cmd.color('grey', pdb_id)
    cmd.hide('everything', pdb_id)
    cmd.show_as('lines', pdb_id + ' and (name ca)')
    cmd.set('line_width', 5)
    cmd.set_bond('line_width', 5, pdb_id + ' and (name ca)')
    cmd.show('spheres', pdb_id + ' and name ca')
    cmd.set('sphere_transparency', 0.0, pdb_id + ' and name ca')
    cmd.set('sphere_scale', 0.5, pdb_id + ' and name ca')
    data = cmd.get_coords(selection=pdb_id + ' and name ca', state=1)
    data_ = []
    cmd.set('dash_color', 'marine')
    cmd.set('dash_width', 1.0)
    j = 55
    for i in range(len(data)):
        if i % 2 == 0 and i + 1 < len(data):
            data[i] = np.mean(data[i:i + 2], axis=0)
            data[i + 1] = np.array([10000, 10000, 10000])

        #cmd.distance('d'+str(i)+str(j), pdb_id + ' and name ca and res ' + str(i), pdb_id + ' and name ca and res ' + str(j))
        #cmd.hide('labels', 'd'+str(i)+str(j))

    cmd.color('red', pdb_id2)
    cmd.hide('everything', pdb_id2)
    cmd.show_as('lines', pdb_id2 + ' and (name ca)')
    cmd.set('line_width', 5)
    cmd.set_bond('line_width', 5, pdb_id2 + ' and (name ca)')
    cmd.show('spheres', pdb_id2 + ' and name ca')
    cmd.set('sphere_transparency', 0.0, pdb_id2 + ' and name ca')
    cmd.set('sphere_scale', 0.5, pdb_id2 + ' and name ca')
    for i in range(len(data)):
        if i % 2 == 0 and i + 1 < len(data):
            cmd.alter_state(1, pdb_id2 + ' and name ca and res ' + str(i),
                            '(x,y,z)=' + str(tuple(data[i])))
        else:
            cmd.hide('spheres', pdb_id2 + ' and name ca and res ' + str(i))

    pdb_id3 = pdb_id + 'copy2'
    cmd.create(pdb_id3, pdb_id2)
    cmd.color('red', pdb_id3)
    cmd.hide('everything', pdb_id3)
    cmd.show_as('lines', pdb_id3 + ' and (name ca)')
    cmd.set('line_width', 5)
    cmd.set_bond('line_width', 5, pdb_id3 + ' and (name ca)')
    cmd.show('spheres', pdb_id3 + ' and name ca')
    cmd.set('sphere_transparency', 0.8, pdb_id3 + ' and name ca')
    for i in range(len(data)):
        if i % 2 == 0 and i + 1 < len(data):
            cmd.set('sphere_scale', np.random.uniform(1.0, 4.5),
                    pdb_id3 + ' and name ca and res ' + str(i))
        else:
            cmd.hide('spheres', pdb_id2 + ' and name ca and res ' + str(i))
Beispiel #8
0
pdb_id = '4m21_a'
attributions_path = 'out/krashras_graph_new/interpret/attributions.npz'
data_path = 'data/KrasHras/pdb/'


# Load Attribution
data = np.load(attributions_path)
attributions = data['data']
labels = data['labels']
ind = np.where(labels == pdb_id)
attribution = attributions[ind][0][:,-4]

# Load PDB
cmd.reinitialize()
cmd.bg_color('white')
cmd.load(data_path+pdb_id[:-2]+'.pdb')
cmd.split_chains()
for name in cmd.get_names('objects', 0, '(all)'):
    if not name.endswith(pdb_id[-1].upper()):
        cmd.delete(name)
cmd.reset()

for i, _ in enumerate(attribution):
    cmd.select('toBecolored', 'res ' + str(i))
    cmd.set_color('saliency'+str(i), list(cmap(norm(_)))[:3])
    cmd.color('saliency'+str(i), 'toBecolored')

cmd.select('selected','chain '+pdb_id[-1].upper())
cmd.show('mesh', 'selected')
cmd.deselect()