Exemplo n.º 1
0
def builderNanodisc(protein, membrane, scaffold, prefixName, runNumber, x=0, y=0, refine=False):
    """
    builds a MP-nanodisc systems
    scaffold in this case is a double belt of MSP
    """
    # Checking time of builder function execution
    if protein != None:
        print('protein is: ' + protein)
    print('scaffold is: ' + scaffold)
    print('membrane is: ' + membrane)
    empty = False
    if protein is None: empty = True
    if not empty:
        tmp_prot = "tmp_prot" + str(runNumber)
        cmd.copy(tmp_prot, protein)  # store initial
        cmd.translate("[{},{},0]".format(x, y), tmp_prot)
    print("State of empty/not-empty: {}".format(empty))
    # copies to delete later
    tmp_scaffold = "tmp_scaffold" + str(runNumber)
    tmp_memb = "tmp_memb" + str(runNumber)
    tmp_origin = "origin" + str(runNumber)
    cmd.copy(tmp_scaffold, scaffold)  # store initial
    cmd.copy(tmp_memb, membrane)  # store initial

    center(tmp_memb)
    center(tmp_scaffold)
    cmd.pseudoatom(tmp_origin, pos=[0, 0, 0])
    cmd.origin(tmp_origin)
    #outRadius = findAverDist(tmp_scaffold) #doubles time for each run
    outRadius = TMdistCheck(tmp_scaffold, 0.2)
    print("Max distance from origin to scaffold in xy plane: {}".format(outRadius))
    # remove lipids beyond border encased by MSP
    cmd.remove("br. org and {} beyond {} of {}".format(tmp_memb, outRadius, tmp_origin))

    # remove lipids clashing with tmp_protein core
    if not empty:
        avXY = TMdistCheck(tmp_prot, 0.2)
        if avXY == -1: return "bad model"
        minXY = avXY / 2.0
        # remove lipids inside pore
        cmd.remove("br. org and {} within {} of {}".format(tmp_memb, minXY, tmp_origin))
        print("Mean distance if TM cross-section in xy plane: {}".format(avXY))

    if empty:
        cmd.remove("br. org and {} within 0.4 of {} and not hydro".format(tmp_memb, tmp_scaffold))
        s = "empty_{}_{}".format(membrane, scaffold)
    else:
        cmd.remove("br. org and {} within 0.3 of pol. and not hydro".format(tmp_memb))
        s = "{}_{}_{}".format(protein, membrane, scaffold)
    if refine: s += "{}_{}".format(int(x), int(y))
    if prefixName:
        s = "{}{}".format(prefixName, s)
    cmd.create(s, "({},{}, {})".format(protein, tmp_scaffold, tmp_memb))
    cmd.save(s + ".pdb", s)

    cmd.delete(tmp_memb)
    cmd.delete(tmp_scaffold)
    cmd.delete(tmp_prot)
    cmd.delete(tmp_origin)
    return s
Exemplo n.º 2
0
 def zoom_to_ligand(self):
     """Zoom in too ligand and its interactions."""
     cmd.center(self.ligname)
     cmd.orient(self.ligname)
     cmd.turn('x', 110)  # If the ligand is aligned with the longest axis, aromatic rings are hidden
     if 'AllBSRes' in cmd.get_names("selections"):
         cmd.zoom('%s or AllBSRes' % self.ligname, 3)
     else:
         if self.object_exists(self.ligname):
             cmd.zoom(self.ligname, 3)
     cmd.origin(self.ligname)
Exemplo n.º 3
0
def builderNanodisc(protein,
                    membrane,
                    scaffold,
                    prefixName,
                    offset=0,
                    refine=False):
    """
    builds a MP-nanodisc systems
    scaffold in this case is a double belt of MSP
    """
    # Checking time of builder function execution
    print(f'protein is: {protein}')
    print(f'scaffold is: {scaffold}')
    print(f'membrane is: {membrane}')
    empty = False
    if protein == None: empty = True
    # copies to delete later
    cmd.copy("tmp_scaffold", scaffold)  # store initial
    cmd.copy("tmp_memb", membrane)  # store initial
    cmd.copy("tmp_prot", protein)  # store initial
    center("tmp_memb")
    center("tmp_scaffold")
    cmd.pseudoatom("origin0", pos=[0, 0, 0])
    cmd.origin("origin0")
    outRadius = findAverDist("tmp_scaffold")
    cmd.translate(f"[0,0,{offset}]", f"tmp_scaffold")
    print(f"Max distance from origin to scaffold in xy plane: {outRadius}")
    # remove lipids beyond border encased by MSP
    cmd.remove(f"org and tmp_memb beyond {outRadius} of origin0")
    print(f"State of empty/not-empty: {empty}")
    # remove lipids clashing with tmp_protein core
    if not empty:
        avXY = TMdistCheck("tmp_prot", 0.2)
        minXY = avXY / 2.0
        # remove lipids inside pore
        cmd.remove(f"org and tmp_memb within {minXY} of origin0")
        print(f"Mean distance if TM cross-section in xy plane: {avXY}")

    if empty:
        cmd.remove("org and tmp_memb within 0.4 of tmp_scaffold and not hydro")
        s = f"{prefixName}empty_{membrane}_{scaffold}"
    else:
        cmd.remove("org and tmp_memb within 0.3 of pol. and not hydro")
        s = f"{prefixName}{protein}_{membrane}_{scaffold}"
    if refine: s += str(int(offset))
    cmd.create(s, f"({protein},tmp_scaffold, tmp_memb)")
    cmd.save(s + ".pdb", s)

    cmd.delete("tmp_memb")
    cmd.delete("tmp_scaffold")
    cmd.delete("tmp_prot")
    cmd.delete("origin0")
    return s
Exemplo n.º 4
0
 def testOrigin(self):
     from chempy import cpv
     cmd.pseudoatom('m1')
     cmd.pseudoatom('m2')
     cmd.pseudoatom('m3', pos=[1,0,0])
     # by selection
     cmd.origin('m3')
     cmd.rotate('y', 90, 'm1')
     # by position
     cmd.origin(position=[-1,0,0])
     cmd.rotate('y', 90, 'm2')
     coords = []
     cmd.iterate_state(1, 'm1 m2', 'coords.append([x,y,z])', space=locals())
     d = cpv.distance(*coords)
     self.assertAlmostEqual(d, 2 * 2**0.5)
Exemplo n.º 5
0
 def testOrigin(self):
     from chempy import cpv
     cmd.pseudoatom('m1')
     cmd.pseudoatom('m2')
     cmd.pseudoatom('m3', pos=[1, 0, 0])
     # by selection
     cmd.origin('m3')
     cmd.rotate('y', 90, 'm1')
     # by position
     cmd.origin(position=[-1, 0, 0])
     cmd.rotate('y', 90, 'm2')
     coords = []
     cmd.iterate_state(1, 'm1 m2', 'coords.append([x,y,z])', space=locals())
     d = cpv.distance(*coords)
     self.assertAlmostEqual(d, 2 * 2**0.5)
Exemplo n.º 6
0
def builderSalipro(protein,
                   scaffold,
                   membrane,
                   prefixName,
                   n_sym=9,
                   initRotAngle=45,
                   refine=False):
    """
    builds and refines MP-salipro systems
    """
    # Checking time of builder function execution
    print(f'protein is: {protein}')
    print(f'scaffold is: {scaffold}')
    print(f'membrane is: {membrane}')
    print(f'copies of scaffold: {n_sym}')

    print(f'rotation angle of scaffold is: {initRotAngle}')

    empty = False
    if protein == None: empty = True
    cmd.reset()
    # copies to delete later
    cmd.copy("tmp_scaffold", scaffold)  # store initial
    cmd.copy("tmp_memb", membrane)  # store initial
    cmd.copy("tmp_prot", protein)  # store initial
    center("tmp_memb")
    center("tmp_scaffold")
    cmd.pseudoatom("origin0", pos=[0, 0, 0])
    cmd.origin("origin0")
    t_sap = 10  # findMaxDist("tmp_scaffold")/2.0     # approximate half thickness of saposin monomer

    print(f"State of empty/not-empty: {empty}")

    if not empty:
        avXY = TMdistCheck("tmp_prot", 0.2)
        radXY = avXY / 2.0
        # remove lipids inside pore
        cmd.remove(f"tmp_memb within {radXY} of origin0")
        r_lipHead = 4.7  # Area(POPC) = 65 A^2 => radius = sqrt(A/pi); reasonable estimate
        numLipLayers = 2.0  # number of lipid layers between TM of core and Saposin tmp_scaffold
        inRadius = avXY + numLipLayers * r_lipHead + t_sap  # equatorial position of tmp_scaffold center of mass
    else:
        inRadius = 27.0  # equatorial position of tmp_scaffold center of mass
    outRadius = inRadius + t_sap  # cut-lipids beyond this distance
    print(f"Inner radius: {inRadius}")
    print(f"Outer radius: {outRadius}")

    n_sym = int(n_sym)
    rotAng = 360. / float(n_sym)

    # chain ID
    id = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    s0 = range(0, n_sym, 1)
    # Build symmates with desired rotations
    cmd.rotate("x", "90", "tmp_scaffold")
    for i in s0:
        angle = +i * rotAng
        cmd.copy(f"seg{i}", "tmp_scaffold")
        cmd.origin("origin0")
        cmd.rotate("y", str(initRotAngle), f"seg{i}")
        cmd.origin("origin0")
        cmd.translate(f"[0,{inRadius},0]", f"seg{i}")
        chn = id[i + len(s0)]
        cmd.alter(f"seg{i}", f"chain = '{chn}'")
        cmd.origin("origin0")
        cmd.rotate("z", str(angle), f"seg{i}")

    # remove lipids beyond border encase by saposins
    cmd.remove(f"br. org and tmp_memb beyond {outRadius} of origin0")
    # remove lipids clashing with tmp_protein core and saposins
    if not empty:
        cmd.remove("br. org and tmp_memb within 0.3 of pol. and not hydro")
    else:
        cmd.remove("br. org and tmp_memb within 0.3 of seg* and not hydro")

    # Combine into a single PyMol object
    if empty == True:
        s = f"{prefixName}empty_{membrane}_{scaffold}_{(int)(initRotAngle)}"
    else:
        s = f"{prefixName}{protein}_{membrane}_{scaffold}_{(int)(initRotAngle)}"
    if refine:
        s = f"{prefixName}{protein}_{membrane}_{scaffold}_{(int)(initRotAngle)}_{(int)(n_sym)}"

    cmd.create(s, f"{protein}, tmp_memb, seg*")
    cmd.save(s + ".pdb", s)

    cmd.delete("tmp_memb")
    cmd.delete("tmp_scaffold")
    cmd.delete("tmp_prot")
    cmd.delete("seg*")
    cmd.delete("origin0")

    return s
Exemplo n.º 7
0
    def reps(self,cleanup=0):
        rep_list = [ "lines","sticks","spheres","surface","mesh","dots","ribbon","cartoon" ]
        try:
            if not cleanup:
                cmd.disable()
                cmd.set("suspend_updates",1,quiet=1)
                cmd.load("$PYMOL_DATA/demo/pept.pdb","rep1")
                cmd.alter("rep1///1-5+8-13/","ss='S'")
                cmd.cartoon("auto")
                cmd.hide("everything","rep1")
                for a in range(2,9):
                    cmd.create("rep%d"%a,"rep1")
                for x, y in enumerate(rep_list, 1):
                    cmd.show(x, "rep%d" % y)
                cmd.reset()
                cmd.zoom("rep1",24)
                util.cbay("rep2")
                util.cbac("rep3")
                util.cbas("rep4")
                util.cbab("rep5")
                util.cbaw("rep6")            
                util.cbay("rep8")


                cmd.set("suspend_updates",0,quiet=1)
                scale=0.5
                for b in range(1,20):
                    cmd.set("suspend_updates",0,quiet=1)
                    cmd.refresh()
                    cmd.set("suspend_updates",1,quiet=1)
                    xt=-3.2
                    yt=1.6
                    for a in range(1,5):
                        cmd.translate([xt*scale,yt*scale,0],object="rep%d"%a,camera=0)
                        xt=xt+2
                    yt=-yt
                    xt=-3.2
                    for a in range(5,9):
                        cmd.translate([xt*scale,yt*scale,0],object="rep%d"%a,camera=0)
                        xt=xt+2
                for a in range(1,9):
                    cmd.origin("rep%d"%a,object="rep%d"%a)
                cmd.mset("1")
                st = ' '.join(map(lambda x,y:"rotate angle=-3,object=rep%d,axis=%s;"%(x,y),list(range(1,9)),
                                            ['x','y','x','y','x','y','x','y']))
                cmd.mdo(1,st)
                cmd.set("suspend_updates",0,quiet=1)
                cmd.mplay()

                cgo = []
                axes = [[4.5,0.0,0.0],[0.0,3.0,0.0],[0.0,0.0,3.0]]

                c = 1
                for a in rep_list:
                    ext = cmd.get_extent("rep%d"%c)
                    pos = [(ext[0][0]+ext[1][0])/2,
                             (ext[0][1]+ext[1][1])/2+14,
                             (ext[0][2]+ext[1][2])/2]
                    c = c + 1
                    pos[0]=pos[0]-(measure_text(plain,a,axes)/2)
                    wire_text(cgo,plain,pos,a,axes)
                cmd.set("cgo_line_width",1.5)
                cmd.set("auto_zoom",0)
                cmd.load_cgo(cgo,'reps')
                cmd.set("auto_zoom",1)
            else:
                cmd.delete("rep*")
                cmd.mset()
                cmd.mstop()
        except:
            traceback.print_exc()
Exemplo n.º 8
0
def builderBicelle(protein, membrane, detergent, prefixName, runNumber, refine=False, ang=None, densAng=None):
    """
    builds MP - bicelle complex using a membrane and a single detergent molecule
    """
    # Checking object names
    print('protein   is: ' + protein)
    print('membrane  is: ' + membrane)
    print('detergent is: ' + detergent)
    empty = False
    if protein is None: empty = True
    if not empty:
        tmp_prot = "tmp_prot" + str(runNumber)
        cmd.copy(tmp_prot, protein)  # store initial
    print("State of empty/not-empty: {}".format(empty))
    # copies to delete later
    tmp_memb = "tmp_memb" + str(runNumber)
    tmp_deter =  "tmp_deter"  + str(runNumber)
    cmd.copy(tmp_memb, membrane)  # store initial
    cmd.copy(tmp_deter, detergent)  # store initial

    center(tmp_memb)
    center(tmp_deter)
    tmp_origin = "origin" + str(runNumber)
    cmd.pseudoatom(tmp_origin, pos=[0, 0, 0])
    cmd.origin(tmp_origin)
    # Determine max distance of TM cross-section (xy plane)
    r = TMdistCheck(tmp_prot, 2.0)
    if r == -1: return "bad model"
    detR = findMaxDist(tmp_deter)
    print("Max distance if TM cross-section is in a xy plane: " + str(r))
    print("Max distance of detergent : " + str(detR))

    ## Shrink detergent along z axis to match ry
    # stretch = r / detR
    # affineStretch("tmp_deter", stretch)
    # find new
    # detR = detR * stretch
    # print(f"Max distance of detergent after shrinking: {detR}")
    # Create a ring of detergents using spherical coordinates
    # FIXME: find automatically?
    if refine:
        # stochastic
        # theta = random.sample(range(-ang, ang), 10)
        # phi = random.sample(range(0, 360), densAng)
        # geometrical
        theta = np.arange(-ang, ang, 3)
        phi = np.arange(0, 361, densAng)
    else:
        # stochastic
        # theta = random.sample(range(-20, 20), 10)
        # phi = random.sample(range(0, 361), 100)
        # geometrical
        theta = range(-14, 14, 3)
        phi = range(0, 361, 10)  # find angular step from average density?

    builderCorona(theta, phi, tmp_deter, r, detR)
    #affineStretch("corona", 1.1)
    # remove lipids inside pore
    cmd.remove("br. {} within {} of {}".format(tmp_memb, r / 2.0, tmp_origin))
    cmd.origin(tmp_origin)
    # remove lipids beyond border encased by MSP
    #print("org and tmp_memb beyond {} of origin0".format(r))
    cmd.remove("br. org and {} beyond {} of {}".format(tmp_memb, r, tmp_origin))
    # remove lipids clashing with tmp_protein core and MSP scaffold and combine into a single PyMol object
    cmd.remove("br. org and {} within 0.3 of pol. and not hydro".format(tmp_memb))
    s = "{}_{}_{}".format(protein, membrane, detergent)
    if prefixName: s = "{}{}".format(prefixName, s)
    cmd.create(s, "({}, corona, {})".format(protein, tmp_memb))
    cmd.save(s + ".pdb", s)
    cmd.delete("{}, {}, {}, corona".format(tmp_prot, tmp_memb, tmp_deter))
    cmd.delete(tmp_origin)
    return s
Exemplo n.º 9
0
 def setOriginAtMolecule(self):
     view = np.array(cmd.get_view())
     #cmd.origin(position=view[9:12])
     cmd.origin(position=self.getMoleculeCoM())
Exemplo n.º 10
0
def save_shell_figures(mol_pdb_file,
                       shell_pdb_files,
                       graph,
                       atom_colors,
                       dpi=3000,
                       overwrite=False,
                       out_dir=""):
    """Save all mol/shell/substructure figures."""
    cmd.reinitialize()
    sleep(0.5)

    mol_color_hetero_img = os.path.join(out_dir, "mol_plain.png")
    mol_color_types_img = os.path.join(out_dir, "mol_atom_types.png")
    pymol_load_with_defaults(mol_pdb_file)
    cmd.zoom('all', complete=1, buffer=1)
    if overwrite or not os.path.isfile(mol_color_hetero_img):
        cmd.util.cbaw()
        pymol_color_atoms_by_elem()
        cmd.ray(dpi)
        cmd.png(mol_color_hetero_img)
        partial_opaque_to_opaque(mol_color_hetero_img)
        sleep(0.5)

    if overwrite or not os.path.isfile(mol_color_types_img):
        pymol_color_by_atom_types(atom_colors)
        cmd.ray(dpi)
        cmd.png(mol_color_types_img)
        partial_opaque_to_opaque(mol_color_types_img)
        sleep(0.5)

    stored.names_ids = []
    cmd.iterate("all", "stored.names_ids.append((ID, name))")
    ids_names_map = dict(stored.names_ids)
    atom_colors = {
        ids_names_map[atom_id + 1]: color
        for atom_id, color in atom_colors.items()
    }

    vector_shell_pdb_file = None
    vector_shell = None
    radii = set()
    for pdb_file in shell_pdb_files:
        identifier = int(os.path.basename(pdb_file).split('.')[0])
        shell_image_file = os.path.join(out_dir,
                                        "{}_shell.png".format(identifier))
        graph.node[identifier]["image"] = shell_image_file
        if not overwrite and os.path.isfile(shell_image_file):
            continue
        cmd.reinitialize()
        pymol_load_with_defaults(pdb_file)
        shell = list(graph.node[identifier]["shell"])[0]
        radius = shell.radius
        if radius > 0:
            radii.add(radius)
            draw_shell_sphere(radius, linespacing=radius * .15 / 1.5)
            cmd.center('sphere_*')
            cmd.origin('sphere_*')
            if vector_shell is None and round(
                    radius / RADIUS_MULTIPLIER) == 1.:
                vector_shell_pdb_file = pdb_file
                vector_shell = shell

        pymol_color_by_atom_types(atom_colors, mode="name")
        cmd.turn('y', 90)
        cmd.turn('x', 35)
        cmd.zoom('all', complete=1)
        cmd.ray(dpi)
        cmd.png(shell_image_file)
        partial_opaque_to_opaque(shell_image_file)
        sleep(0.5)

    vector_figure = os.path.join(out_dir, "vector_axes.png")
    if overwrite or not os.path.isfile(vector_figure):
        cmd.reinitialize()
        pymol_load_with_defaults(vector_shell_pdb_file)
        radius = vector_shell.radius
        draw_shell_sphere(radius, linespacing=radius * .15 / 1.5)
        center_atom = vector_shell.center_atom
        for atom in vector_shell.atoms:
            dist = cmd.get_distance(
                "{} and id {}".format(vector_shell.identifier, center_atom),
                "{} and id {}".format(vector_shell.identifier, atom),
                state=1)
            if dist <= radius:
                coords = cmd.get_coords("{} and id {}".format(
                    vector_shell.identifier, atom),
                                        state=1)[0]
                draw_sphere_marker(radius, coords)
        cmd.center('sphere_*')
        cmd.origin('sphere_*')

        pymol_color_by_atom_types(atom_colors, mode="name")
        cmd.turn('y', 90)
        cmd.turn('x', 35)
        cmd.delete(str(vector_shell.identifier))
        cmd.zoom('all', complete=1)
        cmd.ray(dpi)
        cmd.png(vector_figure)
        partial_opaque_to_opaque(vector_figure)
        sleep(0.5)

    axes_figure = os.path.join(out_dir, "axes.png")
    if overwrite or not os.path.isfile(axes_figure):
        cmd.reinitialize()
        pymol_load_with_defaults()
        draw_shell_sphere(min(radii), linespacing=min(radii) * .15 / 1.5)
        sleep(.1)
        draw_xy_axes(scale=min(radii))
        sleep(.1)
        cmd.turn('y', 90)
        cmd.turn('x', 35)
        cmd.zoom('all', complete=1)
        cmd.ray(dpi)
        cmd.png(axes_figure)
        partial_opaque_to_opaque(axes_figure)
        sleep(0.5)
Exemplo n.º 11
0
def main():
    print 'The default filename is points.'
    fileName = raw_input('Input file name:')
    inputFile = open(fileName,'r')
    inputFileList = inputFile.read().splitlines()
    pointMap = {}
    for i in inputFileList:
        tempList = i.split()
        pointMap[int(tempList[3])] = Point(float(tempList[0]),float(tempList[1]),float(tempList[2]),int(tempList[3]))
    
    Radius = float(inputFileList[0].split()[2])
    r = distance(pointMap[1],pointMap[2])
    print 'Eg: R.pdb or R.pse'
    outPutFile = raw_input('Input output file name:')

    # cmd.pseudoatom('center')

    # cmd.set('surface_mode', 1)
    # cmd.translate([0,0,0], 'center', camera=1)
    # cmd.ramp_new('test', 'center', [640, 646, 647], ['black', 'forest', 'green'])
    # cmd.set('surface_color', 'test', 't*')

    #Plot the first 4 trimer-center's coordinates.
    cmd.load('t1.pdb')
    #first trimerIndex
    cmd.select('/t1/PSDO')
    # cmd.color('blue','t1')
    cmd.show('line', 't1')
    cmd.rotate ('z', -30, 't1', camera=1)
    cmd.translate([0,0,Radius],'t1',camera=1)

    #second trimerIndex
    cmd.create('t2', 't1')
    # cmd.color('red', 't2')
    cmd.select('/t2/PSDO')
    # cmd.color('yellow', 't2')
    cmd.show('line', 't2')
    cmd.translate([r, 0, 0], 't2', camera=1)
    cmd.orient('t2')
    cmd.rotate('z', 60, 't2', camera=1)
    cmd.rotate('z', -30 )
    #this angle changes to bring involved pseudo atoms to horizontal positions
    cmd.rotate('y', 4.726, 't2', camera=1)
    cmd.rotate('x', 0.004, 't2', camera=1)
    # because we are rotating only one trimer, the 2 central pseudo atoms will not align. correction commands are:
    cmd.translate([0, -0.0440605685747639, -2.14176156973178], 't2', camera=1)
    # cmd.alter('/t2//A', chain='D')
    # cmd.alter('/t2//B', chain='E')
    # cmd.alter('/t2//C', chain='F')

    #third trimerIndex
    cmd.create('t3','t2')
    cmd.select('/t3/PSDO')
    cmd.show('line','t3')
    cmd.origin('t1')
    cmd.rotate(pointMap[1].getCoordinate(),120,'t3',camera=1)

    #forth trimerIndex
    cmd.create('t4','t2')
    cmd.select('/t4/PSDO')
    cmd.show('line','t4')
    cmd.origin('t1')
    cmd.rotate(pointMap[1].getCoordinate(),240,'t4',camera=1)

    #According to the first 4 trimer-center coordinates, to plot the following trimers.
    keyList = pointMap.keys()
    keyList.sort()
    # testCount = 1
    for i in keyList:
        if (i>4):
            # testCount += 1
            tempTName = 't'+str(i)
            if (i%2)==1:
                tempTFatherName = 't'+str((i-1)/2)
                tempDegree = 120
            else:
                tempTFatherName = 't'+str((i-2)/2)
                tempDegree = 240
            tempTGrandFatherIndex = ((i-1)//2-1)//2
            if tempTGrandFatherIndex == 0:
                tempTGrandFatherIndex = 1
            tempTGrandFatherName = 't'+str(tempTGrandFatherIndex)
            cmd.create(tempTName,tempTGrandFatherName)
            cmd.select('/'+tempTName+'/PSDO')
            cmd.show('line',tempTName)
            cmd.origin(tempTFatherName)
            cmd.rotate(pointMap[(i-1)//2].getCoordinate(),tempDegree,tempTName,camera=1)

    cmd.save(outPutFile)
Exemplo n.º 12
0
def main(d1, d2):
    ## Make an output folder
    outdir = 'output_dd/' + input_protein + '+' + d1 + '+' + d2 + '/'
    #print (outdir)
    if os.path.isdir(outdir) == False:
        os.system('mkdir ' + outdir)

    domains = d1 + '+' + d2
    for pdb in dd[domains]:
        download_pdb_cif(pdb)
        for coordinates in dd[domains][pdb]:
            #print (pdb, domains, dd[domains][pdb][coordinates])
            chainA = coordinates.split('+')[0].split(':')[0]
            chainA_res = coordinates.split('+')[0].split(':')[1]
            chainB = coordinates.split('+')[1].split(':')[0]
            chainB_res = coordinates.split('+')[1].split(':')[1]
            cmd.load('pdbs/' + pdb.upper() + '.pdb')
            cmd.hide('everything')
            cmd.show('cartoon', 'chain ' + chainA + '+' + chainB)
            cmd.set('cartoon_fancy_helices', 1)
            print(pdb, chainA, chainA_res, chainB, chainB_res)
            try:
                x = cmd.centerofmass('chain ' + chainA)
                print('Success chainA')
                cmd.pseudoatom('chainA_label', pos=x)
                global nameA
                nameA = id_to_name[d1] + '(' + d1 + ')'
                cmd.label('chainA_label', 'nameA')
            except:
                print('Failed chainA')
            try:
                x = cmd.centerofmass('chain ' + chainB)
                print('Success chainB')
                cmd.pseudoatom('chainB_label', pos=x)
                global nameB
                nameB = id_to_name[d2] + '(' + d2 + ')'
                cmd.label('chainB_label', 'nameB')
                x = cmd.centerofmass('chain ' + chainA + '+' + chainB)
                cmd.origin(position=x)
                cmd.center('origin')
            except:
                print('Failed chainB')
            cmd.set('label_size', 7.5)
            cmd.set('cartoon_fancy_helices', 1)
            cmd.color('red', 'chain ' + chainA)
            cmd.color('orange', 'chain ' + chainB)
            for row in dd[domains][pdb][coordinates]:
                res1 = row[2]
                res2 = row[3]
                #cmd.distance('chain '+chainA+' and i. '+res1+' and n. CB', 'chain '+chainB+' and i. '+res2+' and n. CB')
                cutoff = 6.5
                m = cmd.distance(
                    'dist',
                    'chain ' + chainA + ' and i. ' + res1 + ' and n. CB',
                    'chain ' + chainB + ' and i. ' + res2 + ' and n. CB',
                    cutoff, 0)
                #m = cmd.get_distance(atom1='chain '+chainA+' and i. '+res1+' and n. CB',atom2='chain '+chainB+' and i. '+res2+' and n. CB',state=0)
                #print (pdb, m, chainA, res1, chainB, res2)
                cmd.select('res1', 'chain ' + chainA + ' and resi ' + res1)
                cmd.select('res2', 'chain ' + chainB + ' and resi ' + res2)

                if float(m) != 0.0:
                    cmd.show('sticks', 'res1')
                    cmd.show('sticks', 'res2')
                    cmd.color('cyan', 'res1')
                    cmd.color('yellow', 'res2')

            cmd.save(outdir + pdb + '_' + input_protein + '_' + d1 + '_' +
                     d2 + '_' + coordinates.replace(':', '_').replace(
                         '+', '_').replace('-', '_') + '.pse')
            cmd.save(outdir + pdb + '_' + input_protein + '_' + d1 + '_' +
                     d2 + '_' + coordinates.replace(':', '_').replace(
                         '+', '_').replace('-', '_') + '.pdb')
            cmd.delete('all')
        #break
    '''
Exemplo n.º 13
0
    #cmd.cd(path)
    #else:
    #print "No Path specified"
except ValueError:
    print "No Path specified"

for file in glob("*.pdb"):
    print "file: ", file
    listname = file.split(".")
    name = listname[0]
    cmd.load(file, name)
    cmd.system("mv " + file + " ../pdb/")
    cmd.hide("all")
    cmd.show("sticks")
    cmd.reset()
    cmd.origin(position=[0.0, 0.0, 0.0])
    cmd.save(name + "stix.wrl")
    cmd.hide("all")
    cmd.show("ribbon")
    cmd.reset()
    cmd.origin(position=[0.0, 0.0, 0.0])
    cmd.save(name + "rib.wrl")
    cmd.hide("all")
    preset.pretty(name)
    cmd.reset()
    cmd.origin(position=[0.0, 0.0, 0.0])
    cmd.save(name + "cart.wrl")
    cmd.hide("all")
    cmd.show("surface")
    cmd.reset()
    cmd.origin(position=[0.0, 0.0, 0.0])
Exemplo n.º 14
0
        #cmd.cd(path)
    #else:
        #print "No Path specified"
except ValueError:
    print "No Path specified"

for file in glob("*.pdb"):
    print "file: ", file
    listname = file.split(".")
    name = listname[0];
    cmd.load(file, name)
    cmd.system("mv " + file + " ../pdb/")
    cmd.hide("all")
    cmd.show("sticks")
    cmd.reset()
    cmd.origin(position=[0.0,0.0,0.0])
    cmd.save(name + "stix.wrl")
    cmd.hide("all")
    cmd.show("ribbon")
    cmd.reset()
    cmd.origin(position=[0.0,0.0,0.0])
    cmd.save(name + "rib.wrl")
    cmd.hide("all")
    preset.pretty(name)
    cmd.reset()
    cmd.origin(position=[0.0,0.0,0.0])
    cmd.save(name + "cart.wrl")
    cmd.hide("all")
    cmd.show("surface")
    cmd.reset()
    cmd.origin(position=[0.0,0.0,0.0])
Exemplo n.º 15
0
from pymol import cmd
from m2_7 import calc_gc
filename = "data/1buw.pdb"
cmd.load(filename)
cmd.hide("everything")
c = cmd.centerofmass("chain A")
cmd.origin(position=c)
cmd.center('origin')
print(cmd.get_position())
cmd.select(
    "inside",
    "chain A within {:.2f} of origin".format(calc_gc(filename, "chain A")))
cmd.select("outside", "not inside")

cmd.color("red", "inside")
cmd.color("blue", "outside")

cmd.show("sphere", "inside")
cmd.show("sphere", "outside")
Exemplo n.º 16
0
    def runSurfStamp_(self):
        import tempfile
        tmpdir = tempfile.TemporaryDirectory()
        tmp_outfile = tmpdir.name + "/tmpout.obj"

        if len(re.sub("[\s]*", "", self.text_outprefix.text())) > 0:
            tmp_outfile = self.text_outprefix.text()

        my_view = cmd.get_view()

        modelname = self.combo_model.currentText()

        output_modelname = re.sub("[^A-Za-z0-9\\.\\-]", "_",
                                  modelname) + "_obj"
        output_modelname = cmd.get_unused_name(output_modelname)

        surf_args = ["java", "-jar", surfstamp_jar]

        surf_args.extend(["-out", tmp_outfile])
        tmpmodel_created = ""

        if self.check_cartoon.isChecked() or (
                not self.check_builtin.isChecked()):
            #Use .obj generated by PyMOL. If this step is skipped, built-in generator is used.
            tmpmodel_created = cmd.get_unused_name("tmpmodel_")
            cmd.load_model(cmd.get_model(modelname), tmpmodel_created)

            cmd.set_view((0.9999905824661255, -0.00367919635027647,
                          -0.002306032460182905, 0.003680833615362644,
                          0.9999929666519165, 0.0007080769282765687,
                          0.0023034177720546722, -0.0007165365968830884,
                          0.999997079372406, 0.0, 0.0, -50.0, 0.0, 0.0, 0.0,
                          40.0, 100.0, -20.0))

            activeobjects = cmd.get_names('public_objects', enabled_only=1)
            for aa in list(activeobjects):
                cmd.disable(aa)
            cmd.enable(tmpmodel_created)
            modelname = tmpmodel_created
            cmd.hide("everything", modelname)

            if self.check_cartoon.isChecked():
                cmd.show("cartoon", modelname)
                surf_args.extend(["-use_ca", "-force", "-sep_block"])
            else:
                cmd.show("surface", modelname)
                surf_args.extend(["-force"])

            cmd.reset()
            cmd.origin(position=[0.0, 0.0, 0.0])
            cmd.center(origin=0)
            unusedname = cmd.get_unused_name("pseudo_")
            unused_selectionname = cmd.get_unused_name("pseudo_sel_")
            cmd.pseudoatom(unusedname, pos=[0, 0, 0])
            cmd.select(unused_selectionname, "/pseudo_//P/PSD`1/PS1")
            cmd.center(selection=unused_selectionname)
            cmd.save(tmpdir.name + "/tmpin.obj", modelname)
            cmd.delete(unusedname)
            cmd.delete(unused_selectionname)

            for aa in list(activeobjects):
                cmd.enable(aa)

            surf_args.extend(["-obj", tmpdir.name + "/tmpin.obj"])
            cmd.hide("everything", modelname)
        if self.check_mmcif.isChecked():
            tmp_infile = tmpdir.name + "/tmpin.cif"
            surf_args.extend(["-mmcif_use_label", "-mmcif", tmp_infile])
            cmd.save(tmp_infile, modelname)
        else:
            tmp_infile = tmpdir.name + "/tmpin.pdb"
            cmd.save(tmp_infile, modelname)
            surf_args.extend(["-pdb", tmp_infile])

        if len(tmpmodel_created) > 0:
            cmd.delete(tmpmodel_created)

        surf_args.extend(["-surface_resolution",
                          str(self.spin_reso.value())])
        surf_args.extend(["-image_size",
                          str(self.spin_imagesize.value())])

        if not self.check_outline.isChecked():
            surf_args.extend(["-nooutline"])
        if self.check_nowater.isChecked():
            surf_args.extend(["-nowater"])
        if self.check_oneletter.isChecked():
            surf_args.extend(["-residue_oneletter"])
        if self.check_nochainname.isChecked():
            surf_args.extend(["-nochainname"])

        if self.check_tile.isChecked():
            if self.check_cartoon.isChecked():
                surf_args.extend(
                    ["-tile", "-font_size",
                     str(self.spin_fontsize.value())])
            else:
                surf_args.extend([
                    "-tile", "-no_sep", "-font_size",
                    str(self.spin_fontsize.value())
                ])

        if self.check_colorall.isChecked():
            surf_args.extend(["-color_missing", "-color_chainbreak"])
        if self.check_ignore_occupancy.isChecked():
            surf_args.extend(["-ignore_occupancy"])

        surf_args.extend(["-quiet", "1"])
        import subprocess
        process = subprocess.run(surf_args,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.STDOUT)
        #process = subprocess.run(surf_args, stdout=None, stderr=subprocess.PIPE);
        print(process.stdout.decode("utf-8"))
        #os.system(" ".join(surf_args)+" >&2 ");

        self.label_message.setText("Finished.")
        print("Finished.")
        self.text_outprefix.setText("")
        self.button_ok.setEnabled(True)
        self.update()

        if not re.search("\.obj$", tmp_outfile):
            tmp_outfile = tmp_outfile + ".obj"
        cmd.load_callback(pymol_obj_loader.myOBJCallback(tmp_outfile),
                          output_modelname)
        cmd.set_view(my_view)
Exemplo n.º 17
0
def builderBicelle(protein,
                   membrane,
                   detergent,
                   prefixName,
                   refine=False,
                   ang=None,
                   densAng=None):
    """
    builds MP - bicelle complex using a membrane and a single detergent molecule
    """
    # Checking object names
    print(f'protein   is: {protein}')
    print(f'membrane  is: {membrane}')
    print(f'detergent is: {detergent}')

    cmd.copy("tmp_prot", protein)  # store initial
    cmd.copy("tmp_memb", membrane)  # store initial
    cmd.copy("tmp_deter", detergent)  # store initial
    center("tmp_memb")
    center("tmp_deter")
    cmd.pseudoatom("origin0", pos=[0, 0, 0])

    center("tmp_prot")
    # Determine max distance of TM cross-section (xy plane)
    r = TMdistCheck("tmp_prot", 2.0)
    detR = findMaxDist("tmp_deter")
    print(f"Max distance if TM cross-section is in a xy plane: {r}")
    print(f"Max distance of detergent : {detR}")

    # Shrink detergent along z axis to match ry
    stretch = r / detR
    affineStretch("tmp_deter", stretch)
    # find new
    detR = detR * stretch
    print(f"Max distance of detergent after shrinking: {detR}")
    # Create a ring of detergents using spherical coordinates
    # FIXME: find automatically?
    if refine:
        # stochastic
        # theta = random.sample(range(-ang, ang), 10)
        # phi = random.sample(range(0, 360), densAng)
        # geometrical
        theta = np.arange(-ang, ang + 1, 5)
        phi = np.arange(0, 360, densAng)
    else:
        # stochastic
        # theta = random.sample(range(-20, 20), 10)
        # phi = random.sample(range(0, 361), 100)
        # geometrical
        theta = range(-20, 21, 5)
        phi = range(0, 361, 5)  # find angular step from average density?

    builderCorona(theta, phi, "tmp_deter", r, detR)
    affineStretch("corona", 1.1)
    # remove lipids inside pore
    cmd.remove(f"tmp_memb within {r/2.0} of origin0")
    cmd.origin("origin0")
    # remove lipids beyond border encased by MSP
    print(f"org and tmp_memb beyond {r} of origin0")
    cmd.remove(f"org and tmp_memb beyond {r} of origin0")
    # remove lipids clashing with tmp_protein core and MSP scaffold and combine into a single PyMol object
    cmd.remove("org and tmp_memb within 0.3 of pol. and not hydro")
    s = f"{prefixName}{protein}_{membrane}_{detergent}"

    cmd.create(s, f"({protein}, corona, tmp_memb)")
    cmd.save(s + ".pdb", s)
    cmd.delete("tmp_prot, tmp_memb, tmp_deter, corona")
    cmd.delete("origin0")
    return s
Exemplo n.º 18
0
def builderSalipro(protein, scaffold, membrane, prefixName, runNumber, n_sym=9, initRotAngle=45, refine=False):
    """
    builds and refines MP-salipro systems
    """
    # Checking time of builder function execution
    if protein != None:
        print('protein is: ' + protein)
    print('scaffold is: ' + scaffold)
    print('membrane is: ' + membrane)
    print('copies of scaffold: ' + str(n_sym))

    print('rotation angle of scaffold is: ' + str(initRotAngle))

    empty = False
    if protein is None: empty = True
    print("State of empty/not-empty: {}".format(empty))
    cmd.reset()
    tmp_prot = "tmp_prot" + str(runNumber)
    tmp_scaffold = "tmp_scaffold" + str(runNumber)
    tmp_memb = "tmp_memb" + str(runNumber)
    tmp_origin = "origin" + str(runNumber)
    # copies to delete later
    cmd.copy(tmp_scaffold, scaffold)  # store initial
    cmd.copy(tmp_memb, membrane)  # store initial
    if not empty:
        cmd.copy(tmp_prot, protein)  # store initial
    center(tmp_memb)
    center(tmp_scaffold)
    cmd.pseudoatom(tmp_origin, pos=[0, 0, 0])
    cmd.origin(tmp_origin)
    t_sap = 10  # findMaxDist("tmp_scaffold")/2.0     # approximate half thickness of saposin monomer

    if not empty:
        avXY = TMdistCheck(tmp_prot, 0.2)
        if avXY == -1: return "bad model"
        radXY = avXY / 2.0
        # remove lipids inside pore
        cmd.remove("br. {} within {} of {}".format(tmp_memb, radXY, tmp_origin))
        r_lipHead = 4.7  # Area(POPC) = 65 A^2 => radius = sqrt(A/pi); reasonable estimate
        numLipLayers = 2.0  # number of lipid layers between TM of core and Saposin tmp_scaffold
        inRadius = avXY + numLipLayers * r_lipHead + t_sap  # equatorial position of tmp_scaffold center of mass
    else:
        inRadius = 27.0  # equatorial position of tmp_scaffold center of mass
    outRadius = inRadius + t_sap  # cut-lipids beyond this distance
    print("Inner radius: {}".format(inRadius))
    print("Outer radius: {}".format(outRadius))

    n_sym = int(n_sym)
    rotAng = 360. / float(n_sym)

    # chain ID
    id = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    s0 = range(0, n_sym, 1)
    # Build symmates with desired rotations
    cmd.rotate("x", "90", tmp_scaffold)
    for i in s0:
        angle = + i * rotAng
        cmd.copy("seg{}".format(i), tmp_scaffold)
        cmd.origin(tmp_origin)
        cmd.rotate("y", str(initRotAngle), "seg{}".format(i))
        cmd.origin(tmp_origin)
        cmd.translate("[0,{},0]".format(inRadius), "seg{}".format(i))
        chn = id[i + len(s0)]
        cmd.alter("seg{}".format(i), "chain = '{}'".format(chn))
        cmd.origin(tmp_origin)
        cmd.rotate("z", str(angle), "seg{}".format(i))

    # remove lipids beyond border encase by saposins
    cmd.remove("br. org and {} beyond {} of {}".format(tmp_memb, outRadius, tmp_origin))
    # remove lipids clashing with tmp_protein core and saposins
    if not empty:
        cmd.remove("br. org and {} within 0.35 of pol. and not hydro".format(tmp_memb))
    else:
        cmd.remove("br. org and {} within 0.3 of seg* and not hydro".format(tmp_memb))

    # Combine into a single PyMol object
    if empty:
        s = "empty_{}_{}_{}".format(membrane, scaffold, int(initRotAngle))
    else:
        s = "{}_{}_{}_{}".format(protein, membrane, scaffold, int(initRotAngle))
    if refine:
        s = "{}_{}_{}_{}_{}".format(protein, membrane, scaffold, int(initRotAngle), int(n_sym))
    if prefixName:
        s = "{}{}".format(prefixName, s)
    # cmd.create(s, protein, tmp_memb, "seg*")
    cmd.create(s, "({},{}, seg*)".format(protein, tmp_memb))
    cmd.save(s + ".pdb", s)

    cmd.delete(tmp_memb)
    cmd.delete(tmp_scaffold)
    cmd.delete(tmp_prot)
    cmd.delete("seg*")
    cmd.delete(tmp_origin)

    return s
Exemplo n.º 19
0
    def reps(self, cleanup=0):
        rep_list = [
            "lines", "sticks", "spheres", "surface", "mesh", "dots", "ribbon",
            "cartoon"
        ]
        try:
            if not cleanup:
                cmd.disable()
                cmd.set("suspend_updates", 1, quiet=1)
                cmd.load("$PYMOL_DATA/demo/pept.pdb", "rep1")
                cmd.alter("rep1///1-5+8-13/", "ss='S'")
                cmd.cartoon("auto")
                cmd.hide("everything", "rep1")
                for a in range(2, 9):
                    cmd.create("rep%d" % a, "rep1")
                for x, y in enumerate(rep_list, 1):
                    cmd.show(x, "rep%d" % y)
                cmd.reset()
                cmd.zoom("rep1", 24)
                util.cbay("rep2")
                util.cbac("rep3")
                util.cbas("rep4")
                util.cbab("rep5")
                util.cbaw("rep6")
                util.cbay("rep8")

                cmd.set("suspend_updates", 0, quiet=1)
                scale = 0.5
                for b in range(1, 20):
                    cmd.set("suspend_updates", 0, quiet=1)
                    cmd.refresh()
                    cmd.set("suspend_updates", 1, quiet=1)
                    xt = -3.2
                    yt = 1.6
                    for a in range(1, 5):
                        cmd.translate([xt * scale, yt * scale, 0],
                                      object="rep%d" % a,
                                      camera=0)
                        xt = xt + 2
                    yt = -yt
                    xt = -3.2
                    for a in range(5, 9):
                        cmd.translate([xt * scale, yt * scale, 0],
                                      object="rep%d" % a,
                                      camera=0)
                        xt = xt + 2
                for a in range(1, 9):
                    cmd.origin("rep%d" % a, object="rep%d" % a)
                cmd.mset("1")
                st = ' '.join(
                    map(
                        lambda x, y: "rotate angle=-3,object=rep%d,axis=%s;" %
                        (x, y), list(range(1, 9)),
                        ['x', 'y', 'x', 'y', 'x', 'y', 'x', 'y']))
                cmd.mdo(1, st)
                cmd.set("suspend_updates", 0, quiet=1)
                cmd.mplay()

                cgo = []
                axes = [[4.5, 0.0, 0.0], [0.0, 3.0, 0.0], [0.0, 0.0, 3.0]]

                c = 1
                for a in rep_list:
                    ext = cmd.get_extent("rep%d" % c)
                    pos = [(ext[0][0] + ext[1][0]) / 2,
                           (ext[0][1] + ext[1][1]) / 2 + 14,
                           (ext[0][2] + ext[1][2]) / 2]
                    c = c + 1
                    pos[0] = pos[0] - (measure_text(plain, a, axes) / 2)
                    wire_text(cgo, plain, pos, a, axes)
                cmd.set("cgo_line_width", 1.5)
                cmd.set("auto_zoom", 0)
                cmd.load_cgo(cgo, 'reps')
                cmd.set("auto_zoom", 1)
            else:
                cmd.delete("rep*")
                cmd.mset()
                cmd.mstop()
        except:
            traceback.print_exc()
Exemplo n.º 20
0
    def setOriginAtCamera(self):
        view = np.array(cmd.get_view())

        # concise version
        cmd.origin(position=view[12:15] -
                   view[9:12].dot(view[0:9].reshape((3, 3)).T))