def vis(res,
        path_prefix,
        c=["firebrick", "forest", 'purple', 'salmon', "gold", "red"]):

    for ind, r in enumerate(res):
        for a in r.atoms:
            cmd.show("spheres", "id " + str(a.id))
            cmd.set("sphere_color", c[ind], "id " + str(a.id))
        cmd.distance("d" + str(ind), "id " + str(r.atoms[0].id),
                     "id " + str(r.atoms[1].id))
        cmd.hide("labels")
        cmd.set("grid_slot", -2, "d" + str(ind))

    cmd.ray(1200)
    time.sleep(2)
    cmd.set("grid_mode", 0)
    cmd.png(path_prefix + "_restraints.png")
    #cmd.set("grid_mode", 1)
    cmd.move("zoom", -10)

    cmd.ray(1200, )
    time.sleep(4)
    cmd.png(path_prefix + "_grid_restraints.png")
    cmd.set("grid_mode", 0)
    cmd.hide("spheres")
    cmd.delete("d*")
def images_screw(images, distance, sweep, axis):

    global imagecount
    global ray
    global filename
    global ximage
    global yimage

    print "... Images %s - %s:" % (imagecount, imagecount + images - 1)
    print "Writing %s images moving along %s axis by %s Angstrom" % \
      (images, axis, distance/images)
    print "     and rotating %s degrees per image" % (sweep / images)

    for i in range(0, images):  #cycle for number of images

        # transformations
        cmd.move(axis, distance / images)
        cmd.turn(axis, sweep / images)

        #print image
        cmd.png("images/%s_%04d" % (filename, imagecount), ray=ray)

        #increment imagecounter
        imagecount = imagecount + 1
        cmd.refresh()
def additional_camera():
    # Add a rotation to the global view
    cmd.scene('001', animate=0)
    cmd.turn('y', -40)
    cmd.mview('store', 80)
    cmd.turn('y', 40)
    cmd.mview('store', 140)
    # Add panning to the close-up
    cmd.scene('002', animate=0)
    cmd.move('x', 5)
    cmd.mview('store', 320)
Beispiel #4
0
def additional_camera():
    # Add a rotation to the global view
    cmd.scene('001', animate=0)
    cmd.turn('y', -40)
    cmd.mview('store', 80)
    cmd.turn('y', 40)
    cmd.mview('store', 140)
    # Add panning to the close-up
    cmd.scene('002', animate=0)
    cmd.move('x', 5)
    cmd.mview('store', 320)
Beispiel #5
0
def loadPackingPDB(file, name=None, native=None):
    """
    usage: loadPackingPDB <file> , [<name for object>]
    loads a foo_packing.pdb file and colors it all pretty-like
    creates two selections along with the loaded object called
    NAMEcavities and NAMEprotein which are the heteratoms representing
    holes and everything else, respectively. Names can get pretty long,
    by pymol lets you do good stuff like "select NA*cav*", which will
    match a selection called NAMEISREALLYLONGcavities.
    """

    if name is None:
        name = name = os.path.basename(file)
    if name.endswith('.gz'):
        name = name[:-3]
    if name.endswith('.pdb'):
        name = name[:-4]
    if name.endswith('.'):
        name = name[:-1]
    if name.endswith("_packing"):
        name = name[:-8]

    zload(file, name)
    cmd.hide('everything', name)

    if native is not None:
        cmd.align(name, native)
        cmd.zoom(native)

    useRosettaRadii()

    cavselname = name + "cavities"
    protselname = name + "protein"

    cmd.select(cavselname, "resn WSS and %s" % (name))
    cmd.select(protselname, "(not resn WSS) and %s" % (name))

    useTempRadii(cavselname)
    useOccColors(cavselname)
    cmd.color("white", protselname)

    cmd.show('spheres', cavselname)
    cmd.show("cartoon", protselname)
    cmd.show("lines", protselname)

    cmd.select("none")
    cmd.delete("sele*")
    cmd.move('z', -50)

    return name
def loadPackingPDB(file,name=None,native=None):
	"""
	usage: loadPackingPDB <file> , [<name for object>]
	loads a foo_packing.pdb file and colors it all pretty-like
	creates two selections along with the loaded object called
	NAMEcavities and NAMEprotein which are the heteratoms representing
	holes and everything else, respectively. Names can get pretty long,
	by pymol lets you do good stuff like "select NA*cav*", which will
	match a selection called NAMEISREALLYLONGcavities.
	"""

	if name is None:
		name = name = os.path.basename(file)
	if name.endswith('.gz'):
		name = name[:-3] 
	if name.endswith('.pdb'):
		name = name[:-4] 
	if name.endswith('.'):
		name = name[:-1] 
	if name.endswith("_packing"):
		name = name[:-8]

	zload(file,name)
	cmd.hide('everything',name)
	
	if native is not None:
		cmd.align(name,native)	
		cmd.zoom(native)

	useRosettaRadii()

	cavselname  = name+"cavities"
	protselname = name+"protein"

	cmd.select(cavselname, "resn CAV and b > 0.1 and %s"%(name) )
	cmd.select(protselname,"(not resn CAV) and %s"%(name) )

	useTempRadii(cavselname)
	useOccColors(cavselname)
	cmd.color("white",protselname)

	cmd.show('spheres', cavselname )
	cmd.show("cartoon",protselname)
	cmd.show("lines",protselname)

	cmd.select("none")
	cmd.delete("sele*")
	cmd.move('z',-50)

	return name
Beispiel #7
0
 def testReset(self):
     # view
     v = cmd.get_view()
     cmd.turn('x', 10)
     cmd.move('y', 10)
     self.assertNotEqual(v, cmd.get_view())
     cmd.reset()
     self.assertEqual(v, cmd.get_view())
     # object
     cmd.pseudoatom("m1")
     x = cmd.get_object_matrix("m1")
     cmd.translate([1, 2, 3], object="m1")
     self.assertNotEqual(x, cmd.get_object_matrix("m1"))
     cmd.reset("m1")
     self.assertEqual(x, cmd.get_object_matrix("m1"))
Beispiel #8
0
 def testReset(self):
     # view
     v = cmd.get_view()
     cmd.turn('x', 10)
     cmd.move('y', 10)
     self.assertNotEqual(v, cmd.get_view())
     cmd.reset()
     self.assertEqual(v, cmd.get_view())
     # object
     cmd.pseudoatom("m1")
     x = cmd.get_object_matrix("m1")
     cmd.translate([1,2,3], object="m1")
     self.assertNotEqual(x, cmd.get_object_matrix("m1"))
     cmd.reset("m1")
     self.assertEqual(x, cmd.get_object_matrix("m1"))
Beispiel #9
0
 def testClip(self):
     for a in "xyz":
         cmd.turn(a, random.random() * 10 - 5)
         cmd.move(a, random.random() * 10 - 5)
     v = cmd.get_view()
     cmd.clip("near", -5)
     self.assertAlmostEqual(v[15] + 5, cmd.get_view()[15], delta=1e-3)
     cmd.clip("far", 10)
     self.assertAlmostEqual(v[16] - 10, cmd.get_view()[16], delta=1e-3)
     cmd.clip("move", -15)
     a = cmd.get_view()
     self.assertAlmostEqual(v[15], a[15] - 20, delta=1e-3)
     self.assertAlmostEqual(v[16], a[16] - 5, delta=1e-3)
     cmd.clip("slab", 20)
     v = cmd.get_view()
     self.assertAlmostEqual(v[16] - v[15], 20.0, delta=1e-3)
     cmd.pseudoatom()
     cmd.clip("atoms", 5, "all")
     v = cmd.get_view()
     self.assertAlmostEqual(v[16] - v[15], 10.0, delta=1e-3)
Beispiel #10
0
 def testClip(self):
     for a in "xyz":
         cmd.turn(a, random.random() * 10 - 5)
         cmd.move(a, random.random() * 10 - 5)
     v = cmd.get_view()
     cmd.clip("near", -5)
     self.assertAlmostEqual(v[15] + 5, cmd.get_view()[15], delta=1e-3)
     cmd.clip("far", 10)
     self.assertAlmostEqual(v[16] - 10, cmd.get_view()[16], delta=1e-3)
     cmd.clip("move", -15)
     a = cmd.get_view()
     self.assertAlmostEqual(v[15], a[15] - 20, delta=1e-3)
     self.assertAlmostEqual(v[16], a[16] - 5, delta=1e-3)
     cmd.clip("slab", 20)
     v = cmd.get_view()
     self.assertAlmostEqual(v[16] - v[15], 20.0, delta=1e-3)
     cmd.pseudoatom()
     cmd.clip("atoms", 5, "all")
     v = cmd.get_view()
     self.assertAlmostEqual(v[16] - v[15], 10.0, delta=1e-3)
def images_spin3_slide3(images, distance, sweep):

    global imagecount
    global ray
    global filename
    global ximage
    global yimage

    print "... Images %s - %s:" % (imagecount, imagecount + images - 1)
    print "Writing %s images turning about:" % images
    print "     x axis by %s degrees, then" % (sweep[0] / images)
    print "     y axis by %s degrees, and" % (sweep[1] / images)
    print "     z axis by %s degrees per image," % (sweep[2] / images)
    print "   while moving along:"
    print "     x axis by %s Angstrom," % (distance[0] / images)
    print "     y axis by %s Angstrom, and" % (distance[1] / images)
    print "     z axis by %s Angstrom per image" % (distance[2] / images)

    for i in range(0, images):  #cycle for number of images

        # transformations
        cmd.turn("x", sweep[0] / images)
        cmd.turn("y", sweep[1] / images)
        cmd.turn("z", sweep[2] / images)
        cmd.move("x", distance[0] / images)
        cmd.move("y", distance[1] / images)
        cmd.move("z", distance[2] / images)

        #print image
        cmd.png("images/%s_%04d" % (filename, imagecount), ray=ray)

        #increment imagecounter
        imagecount = imagecount + 1
        cmd.refresh()
Beispiel #12
0
def render_to_file(fname, top=True, side=True, vesicle=False,
                   zoom_obj="pbcbox",
                   zoom_distance=10):
    fname = os.path.splitext(fname)[0]

    cmd.reset()
    cmd.zoom(zoom_obj, zoom_distance)
    if vesicle:
        cmd.turn("z", -90)
        cmd.move("y", -50)
    if top:
        cmd.ray("2048")
        cmd.png("%s_top.png" % fname)

    if side:
        cmd.turn("x", -90)
        if vesicle:
            cmd.move("y", 150)
        cmd.ray("2048")
        cmd.png("%s_side.png" % fname)
    cmd.reset()
    cmd.zoom(zoom_obj, zoom_distance)
    if vesicle:
        cmd.turn("z", -90)
        cmd.move("y", -50)
    def test(self):
        cmd.viewport(200, 100)

        cmd.fragment('ethylene', 'm1')
        cmd.remove('hydro')
        cmd.pseudoatom('p1', 'index 1')
        cmd.disable('p1')
        cmd.ramp_new('r1', 'p1', [0.1, 1.2], ['red', 'blue'])
        cmd.disable('r1')
        cmd.color('r1')
        cmd.show_as('sticks', 'm1')

        cmd.orient('m1')
        cmd.move('z', 11)

        self.ambientOnly()

        img = self.get_imagearray()

        self.assertImageHasColor('red', img)
        self.assertImageHasColor('blue', img)
        self.assertImageHasColor([.5, .0, .5], img, delta=1)
Beispiel #14
0
    def initPymol(self):

        # set stereo mode
        cmd.set('stereo_mode', 3)
        cmd.stereo()

        # get rid of gui
        cmd.set('internal_gui', 0)

        # set resolution to HD for rift
        cmd.viewport(1920, 1080)

        # full screen?
        if self.fullscreen:
            cmd.full_screen('on')

        # load pdb
        if len(self.pdb) == 4 and self.pdb == re.match('[a-zA-Z0-9]*',
                                                       self.pdb).group(0):
            cmd.fetch(self.pdb, async=0)

        if self.editMolecule == True:
            cmd.hide('everything', 'all')
            cmd.show('cartoon', 'all')

        # color each chain differently
        if self.editMolecule:
            util.cbc()

        # set origin at camera
        if self.naturalRotation:
            self.setOriginAtCamera()

        # move slab away to give a comfortable viewing area
        cmd.clip('move', 10)

        # jiggle the camera to deal with blank screen error
        cmd.move('z', .0001)
Beispiel #15
0
 def testMove(self):
     for a in "xyz":
         cmd.turn(a, random.random() * 10 - 5)
         cmd.move(a, random.random() * 10 - 5)
     v = list(cmd.get_view())
     d = (2,4,6)
     cmd.move("x", d[0])
     cmd.move("y", d[1])
     cmd.move("z", d[2])
     m = cmd.get_view()
     v[9] += d[0]
     v[10] += d[1]
     v[11] += d[2]
     v[15] -= d[2]
     v[16] -= d[2]
     self.assertArrayEqual(v, m, delta=1e-3)
Beispiel #16
0
 def testMove(self):
     for a in "xyz":
         cmd.turn(a, random.random() * 10 - 5)
         cmd.move(a, random.random() * 10 - 5)
     v = list(cmd.get_view())
     d = (2, 4, 6)
     cmd.move("x", d[0])
     cmd.move("y", d[1])
     cmd.move("z", d[2])
     m = cmd.get_view()
     v[9] += d[0]
     v[10] += d[1]
     v[11] += d[2]
     v[15] -= d[2]
     v[16] -= d[2]
     self.assertArrayEqual(v, m, delta=1e-3)
Beispiel #17
0
def load():
    global last1, last2
    list = glob("pdb/*/*")
    list = map(lambda x: (random.random(), x), list)
    list.sort()
    list = map(lambda x: x[1], list)
    l = len(list)
    c = 0
    for file in list:
        c = c + 1
        try:
            cmd.set("suspend_updates", "1")
            cmd.delete('pdb')
            print file, last1, last2, c, "of", l
            last2 = last1
            last1 = file
            cmd.load(file, 'pdb')
            cmd.set_title('pdb', 1, os.path.split(file)[-1])
            cmd.rewind()
            #      cmd.refresh()
            #      cmd.hide()
            cmd.show('cartoon')
            cmd.color('auto', 'ss h')
            cmd.color('auto', 'ss s')
            cmd.orient('pdb')
            cmd.color('auto', 'organic and elem c')
            cmd.show('spheres', 'organic')
            cmd.move('z', -50.0)
            sys.__stderr__.write(".")
            sys.__stderr__.flush()
            n = cmd.count_states()
        finally:
            cmd.set("suspend_updates", "0")
        if cmd.count_atoms():
            start = time.time()
            if n > 1:
                while (time.time() - start) < cycle_time:
                    for a in range(1, n + 1):
                        cmd.refresh()
                        cmd.frame(a)
                        cmd.move('z', 2)
                        cmd.turn('y', 1)
                        time.sleep(0.025)
                sys.__stderr__.write(" %d of %d" % (c, l))
                sys.__stderr__.write("\n")
                sys.__stderr__.flush()
            else:
                cmd.refresh()
                while (time.time() - start) < cycle_time:
                    for a in range(1, n + 1):
                        time.sleep(0.05)
                        cmd.move('z', 1.0)
                        cmd.turn('y', 1)
Beispiel #18
0
def load():
    global last1, last2
    list = glob("pdb/*/*")
    list = map(lambda x: (random.random(), x), list)
    list.sort()
    list = map(lambda x: x[1], list)
    l = len(list)
    c = 0
    for file in list:
        c = c + 1
        try:
            cmd.set("suspend_updates", "1")
            cmd.delete("pdb")
            print file, last1, last2, c, "of", l
            last2 = last1
            last1 = file
            cmd.load(file, "pdb")
            cmd.set_title("pdb", 1, os.path.split(file)[-1])
            cmd.rewind()
            #      cmd.refresh()
            #      cmd.hide()
            cmd.show("cartoon")
            cmd.color("auto", "ss h")
            cmd.color("auto", "ss s")
            cmd.orient("pdb")
            cmd.color("auto", "organic and elem c")
            cmd.show("spheres", "organic")
            cmd.move("z", -50.0)
            sys.__stderr__.write(".")
            sys.__stderr__.flush()
            n = cmd.count_states()
        finally:
            cmd.set("suspend_updates", "0")
        if cmd.count_atoms():
            start = time.time()
            if n > 1:
                while (time.time() - start) < cycle_time:
                    for a in range(1, n + 1):
                        cmd.refresh()
                        cmd.frame(a)
                        cmd.move("z", 2)
                        cmd.turn("y", 1)
                        time.sleep(0.025)
                sys.__stderr__.write(" %d of %d" % (c, l))
                sys.__stderr__.write("\n")
                sys.__stderr__.flush()
            else:
                cmd.refresh()
                while (time.time() - start) < cycle_time:
                    for a in range(1, n + 1):
                        time.sleep(0.05)
                        cmd.move("z", 1.0)
                        cmd.turn("y", 1)
Beispiel #19
0
    def visualize(self):
        # load pdb into pymol and set up view
        self.initPymol()

        # TODO: check if this is necessary
        self.initCamera()

        # listen ...
        while True:
            # Rift support
            self.ocudump.getPose()

            #print ocudump.pose [pitch (x), yaw (z), roll (y)]
            pose = self.ocudump.pose

            # calculate head rotation
            xRot = pose[0] - self.previousOrientation[0]
            yRot = pose[1] - self.previousOrientation[1]
            zRot = pose[2] - self.previousOrientation[2]

            # update view
            cmd.turn('x', xRot * self.rotationScaling)
            cmd.turn('y', yRot * self.rotationScaling)
            cmd.turn('z', zRot * self.rotationScaling)

            # rift head tracking
            if self.ocudump.positionTracked:
                # move head if sensor detects head motion
                # not tested
                cmd.move('x', pose[3] - self.previousPosition[0])
                cmd.move('y', pose[4] - self.previousPosition[1])
                cmd.move('z', pose[5] - self.previousPosition[2])

            # update camera for "natural rotation"
            if self.naturalRotation:
                self.setOriginAtCamera()

            # record previous pose for accurate rotation diff
            self.previousOrientation = pose[0:3]

            time.sleep(1 / float(self.trackingRefresh))
Beispiel #20
0
def render_to_file(fname, top=True, side=True, vesicle=False, zoom_obj="pbcbox", zoom_distance=10):
    fname = os.path.splitext(fname)[0]

    cmd.reset()
    cmd.zoom(zoom_obj, zoom_distance)
    if vesicle:
        cmd.turn("z", -90)
        cmd.move("y", -50)
    if top:
        cmd.ray("2048")
        cmd.png("%s_top.png" % fname)

    if side:
        cmd.turn("x", -90)
        if vesicle:
            cmd.move("y", 150)
        cmd.ray("2048")
        cmd.png("%s_side.png" % fname)
    cmd.reset()
    cmd.zoom(zoom_obj, zoom_distance)
    if vesicle:
        cmd.turn("z", -90)
        cmd.move("y", -50)
    cmd.load(
        '/Users/choderaj/github/foldingathome/covid-moonshot/perses-figure/boronic_ester_enumeration_for_chodera_lab_FEP-permuted-dockscores-x10789.sdf',
        'conformer')
    cmd.set('all_states', 1)

# DEBUG
#cmd.load('nucleophilic_displacement_enumeration_for_FEP-sorted-x10789.mol2')
#cmd.load('sprint1-winners.mol2')
cmd.viewport(720, 720)

cmd.orient('N3-ligand')
cmd.turn('z', -90)  # TODO: Shift camera instead
cmd.turn('y', +20)  # TODO: Shift camera instead
cmd.zoom('N3-ligand')
#cmd.clip('far', -10)
cmd.move('y', +1)

cmd.show('sticks', 'not hydrogen and *-ligand')

# Hide all fragments
cmd.deselect()

cmd.disable('aminopyridines-*')
cmd.disable('quinolones-*')
cmd.disable('benzotriazoles-*')
cmd.disable('fragment-*')

if show_conformers:
    cmd.hide('sticks', 'hydrogen')
    cmd.hide('sticks', 'conformers')
    cmd.show('lines', 'conformers and not hydrogen')
    cmd.mview('store', 250)
    cmd.mview('store', 400)

setup_pymol()
cmd.load('../../input-files/Cathepsin.pdb')  # Load the PDB file
initial_representations()
set_up_scenes()
scenes_to_frames()

# Apart from moving between scenes, independent camera movements can be added to the animation
# One of them, the zoom (cmd.zoom) was already used
# Two other movements are rotation (cmd.turn) and panning (cmd.move)
# Let's add a rotation to the global view and a panning to the close-up to make them more interesting

cmd.scene('001', animate=0)  # Select the first scene again (we need the camera view as a starting point)
cmd.turn('y', -40)  # Turn the camera 40 degrees left around the y-axis
cmd.mview('store', 80)  # Store the changed view/assign it to frame 60
cmd.turn('y', 40)  # Turn the camera 40 degrees in the other direction around the y-axis
cmd.mview('store', 140)  # Assign the view to frame 120

cmd.scene('002', animate=0)  # Select the second scene
cmd.move('x', 5)  # Move along the x-axis
cmd.mview('store', 320)  # Assign the view to frame 320

# Rewind and turn off ray-tracing
cmd.rewind()  # Rewind the movie to frame 1
cmd.set('ray_trace_frames', 0)  # Turn ray-tracing for frames off

# Running the script, you should now see the additional camera movements additional to the scene transitions
# Note that there are also transitions back to original scene 001 and scene 002 views after the movements
cmd.load('../../input-files/Cathepsin.pdb')  # Load the PDB file
initial_representations()
set_up_scenes()
scenes_to_frames()

# Apart from moving between scenes, independent camera movements can be added to the animation
# One of them, the zoom (cmd.zoom) was already used
# Two other movements are rotation (cmd.turn) and panning (cmd.move)
# Let's add a rotation to the global view and a panning to the close-up to make them more interesting

cmd.scene(
    '001', animate=0
)  # Select the first scene again (we need the camera view as a starting point)
cmd.turn('y', -40)  # Turn the camera 40 degrees left around the y-axis
cmd.mview('store', 80)  # Store the changed view/assign it to frame 60
cmd.turn(
    'y',
    40)  # Turn the camera 40 degrees in the other direction around the y-axis
cmd.mview('store', 140)  # Assign the view to frame 120

cmd.scene('002', animate=0)  # Select the second scene
cmd.move('x', 5)  # Move along the x-axis
cmd.mview('store', 320)  # Assign the view to frame 320

# Rewind and turn off ray-tracing
cmd.rewind()  # Rewind the movie to frame 1
cmd.set('ray_trace_frames', 0)  # Turn ray-tracing for frames off

# Running the script, you should now see the additional camera movements additional to the scene transitions
# Note that there are also transitions back to original scene 001 and scene 002 views after the movements
Beispiel #24
0
print "BEGIN-LOG"

print cmd.set_key('F1',lambda :cmd.turn('x',10))
print cmd.set_key('F12',lambda :cmd.turn('x',10))

print cmd.set_key('left',lambda :cmd.turn('x',10))
print cmd.set_key('right',lambda :cmd.turn('x',10))
print cmd.set_key('pgup',lambda :cmd.turn('x',10))
print cmd.set_key('pgdn',lambda :cmd.turn('x',10))
print cmd.set_key('home',lambda :cmd.turn('x',10))
print cmd.set_key('insert',lambda :cmd.turn('x',10))

print cmd.set_key('ALT-A',lambda :cmd.turn('y',10))

print cmd.set_key('CTRL-C',lambda :cmd.turn('z',10))

print cmd.set_key('SHFT-F1', lambda :cmd.turn('z',10))

print cmd.set_key('ALT-F1', lambda :cmd.turn('y',10))

print cmd.set_key('CTRL-F8', lambda :cmd.move('x',1))


print "END-LOG"





# -c

from pymol import cmd

print "BEGIN-LOG"

print cmd.set_key('F1', lambda: cmd.turn('x', 10))
print cmd.set_key('F12', lambda: cmd.turn('x', 10))

print cmd.set_key('left', lambda: cmd.turn('x', 10))
print cmd.set_key('right', lambda: cmd.turn('x', 10))
print cmd.set_key('pgup', lambda: cmd.turn('x', 10))
print cmd.set_key('pgdn', lambda: cmd.turn('x', 10))
print cmd.set_key('home', lambda: cmd.turn('x', 10))
print cmd.set_key('insert', lambda: cmd.turn('x', 10))

print cmd.set_key('ALT-A', lambda: cmd.turn('y', 10))

print cmd.set_key('CTRL-C', lambda: cmd.turn('z', 10))

print cmd.set_key('SHFT-F1', lambda: cmd.turn('z', 10))

print cmd.set_key('ALT-F1', lambda: cmd.turn('y', 10))

print cmd.set_key('CTRL-F8', lambda: cmd.move('x', 1))

print "END-LOG"
Beispiel #26
0
def align_allfiles(target='',
                   files='*.pdb',
                   res_sel='i. 1-',
                   outfile='',
                   name='',
                   cutoff=2.0,
                   cycles=5,
                   method='align'):
    """
  Aligns all models in a list of files to one target using either align or super method. 
  Outputs: Rosetta energy terms,c-alpha, backbone, and all atom rmsd for each model 
  sorted by c-alpha rmsd

  usage:
    align_allfiles target=target name,files=name.pdb,res_sel='i. 1-,outfile='file name'
    cutoff=2,cycles=5 method=align
        where target specifies the model id you want to align all others against,
        and  cutoff and cycles are options passed to the align command.
        You can specify the files to load and align using a wildcard. You should specify same
	number of residues for the target and other models. if outfile is not given output is
        stddount

    	By default all residues in the structure are aligned,cutoff is 2,number of cycles is 5,        and align method is used.

    Example:
      pymol -cdq "run/$SCRIPTS/align_allfiles;align_allfiles <target name>,[none default 
      arguments eg res_sel= i. 100-120,...]"

  """
    cutoff = int(cutoff)
    cycles = int(cycles)
    cmd.load(target)  # change 1
    #print outfile, cutoff,cycles,res_sel
    #Define rmsd and residue selection for mobile and target
    all = 'all & %s' % res_sel
    ca = 'n. ca & %s' % res_sel
    bb = 'n. n+c+ca+o and %s' % res_sel
    #obtain files from folder and remove native
    #tar=tarfile.open('*.tgz','r:tgz')
    file_list = glob.glob(files)
    #file_list.remove(target)
    #file_list.sort()
    for file in file_list:
        if file == target:
            file_list.remove(file)
        else:
            file_list.sort()
    #print file_list
# print len(file_list)
    extension = re.compile('(^.*[\/]|\.(pdb|ent|brk))')
    object_list = []
    target = extension.sub('', target)  # change 3
    # Define rmsd storage variables
    rmsd_list = []
    for i in range(len(file_list)):
        obj_name1 = extension.sub('', file_list[i])
        object_list.append(extension.sub('', file_list[i]))
        #  energy=popen('grep "total_energy"' file_list[i])
        # print energy
        cmd.load(file_list[i], obj_name1)
        if method == 'align':
            rms_ca = cmd.align('%s & %s' % (object_list[i], ca),
                               '%s & %s' % (target, ca),
                               cutoff=cutoff,
                               cycles=cycles)
            rms_bb = cmd.align('%s & %s' % (object_list[i], bb),
                               '%s & %s' % (target, bb),
                               cutoff=cutoff,
                               cycles=cycles)
            rms_all = cmd.align('%s & %s' % (object_list[i], all),
                                '%s & %s' % (target, all),
                                cutoff=cutoff,
                                cycles=cycles)
            #print '%s,%6.2f,%6.2f,%6.2f' %(object_list[i],rms_bb[0],rms_ca[0],rms_all[0])
        elif method == 'super':
            rms_ca = cmd.super('%s & %s' % (object_list[i], ca),
                               '%s & %s' % (target, ca),
                               cutoff=cutoff,
                               cycles=cycles)
            rms_bb = cmd.super('%s & %s' % (object_list[i], bb),
                               '%s & %s' % (target, bb),
                               cutoff=cutoff,
                               cycles=cycles)
            rms_all = cmd.super('%s & %s' % (object_list[i], all),
                                '%s & %s' % (target, all),
                                cutoff=cutoff,
                                cycles=cycles)
            #print '%s,%6.2f,%6.2f,%6.2f' %(object_list[i],rms_ca[0],rms_bb[0],rms_all[0])
        elif method == 'cealign':
            rmsdict = cmd.cealign(
                '%s & %s' % (target, target_selection),
                '%s & %s' % (object_list[i], mobile_selection))
            rms = [rmsdict['RMSD'], rmsdict['alignment_length'], 1, 0, 0]
        else:
            print "only 'align', 'super' and 'cealign' are accepted as methods"
            sys.exit(-1)
#rms = cmd.align('%s & %s'%(object_list[i],mobile_selection),'%s & %s'%(target,target_selection),cutoff=cutoff,cycles=cycles,object=objectname)
#else:
#rms = cmd.align('%s & %s'%(object_list[i],mobile_selection),'%s & %s'%(target,target_selection),cutoff=cutoff,cycles=cycles)

#rmsd[object_list[i]] = (rms_ca[0],rms_ca[1],rms_bb[0],rms_bb[1],rms_all[0],rms_all[1])

        rmsd_list.append((object_list[i], rms_ca[0], rms_bb[0], rms_all[0]))
        cmd.delete(obj_name1)
    #print rmsd
    rmsd_list.sort(
        lambda x, y: cmp(x[2], y[2])
    )  #compare ca rms you can assign other rms indexes to sort  i.e index 2 for bb and index 3 for all atom
    # loop over dictionary and print out matrix of final rms values
    outfp = outfile
    table = False
    out = open(outfp + '_score_vs_rmsd.csv', 'w')
    out.write('model,score,ca,bb,all,fa_atr,fa_rep,fa_sol,fa_elec\n')
    for r in rmsd_list:
        for decoy in file_list:
            model = open(decoy, 'r')
            for line in model:
                line_split = line.split()
                if line_split[0] == '#BEGIN_POSE_ENERGIES_TABLE':
                    table = True
                    continue
                if table and line_split[0] == 'pose':
                    score = float(line_split[-1])
                    fa_atr = float(line_split[1])
                    fa_rep = float(line_split[2])
                    fa_elec = float(line_split[5])
                    fa_sol = float(line_split[3])
                    if r[0] == decoy.replace('.pdb', ''):
                        out.write(
                            '%s,%6.2f,%6.2f,%6.2f,%6.2f,%6.2f,%6.2f,%6.2f,%6.2f\n'
                            % (decoy, score, r[1], r[2], r[3], fa_atr, fa_rep,
                               fa_sol, fa_elec))
                        print '%s,%6.2f,%6.2f,%6.2f,%6.2f,%6.2f,%6.2f,%6.2f,%6.2f\n' % (
                            decoy, score, r[1], r[2], r[3], fa_atr, fa_rep,
                            fa_sol, fa_elec)
    out.close()
    #generate ensemble figure
    protocol = outfp.split('_')[1]
    cmd.bg_color(color='white')
    cmd.hide("all")
    cmd.show("cartoon")
    cmd.set("antialias", 1)
    cmd.set("ray_trace_mode", 0)
    cmd.set("depth_cue", 0)
    cmd.set("ray_trace_fog", 0)
    cmd.set("stick_radius", 0.1)
    cmd.set("cartoon_side_chain_helper", 1)
    cmd.set("cartoon_flat_sheets", 1)
    #  cmd.set("cartoon_transparency",0.8)
    cmd.set("ray_shadow", 0)
    if protocol == 'loopmodel':
        cmd.rotate("x", 70)
        cmd.zoom("resi 143-163")
        cmd.rotate("z", 20)
        cmd.rotate("y", 45)
        cmd.move("y", 8)
        cmd.move("x", 3)
        cmd.save(outfp + 'ensemble.pse')
        cmd.delete("all")
    elif protocol == 'fixed' or protocol == 'backrub':
        util.cbab("chain h")
        util.cbac("chain l")
        util.cbam("chain g")
        cmd.turn("y", -140)
        cmd.turn("x", -10)
        cmd.turn("z", 10)
        cmd.move("y", -5)
        cmd.move("z", 30)
        cmd.png(outfp + '_ensemble.png', 2400, 2400, dpi=300, ray=1)
        cmd.save(outfp + 'ensemble.pse')
        cmd.delete("all")


#generate score vs rmsd plot
    scorevsrmsd(outfp + '_score_vs_rmsd.csv', name=outfp)
Beispiel #27
0
	    # Distance between hands on each axis
            x=lloc[0]-rloc[0]
            y=lloc[1]-rloc[1]
            z=lloc[2]-rloc[2]

	    # Degrees to turn horizontally or vertically
	    hor=degrees(round(atan2(z, x), 2))-acchor
	    ver=degrees(round(atan2(x, y), 2))-accver
	    acchor+=hor
	    accver+=ver

	    cmd.turn('y', hor)
	    cmd.turn('z', ver)
	    

	    # Zoom selection

	    handist=sqrt(x*x + y*y + z*z)
#	    print handist
	    zomh=handist/5-acczom
#	    print zomh
	    cmd.move('z', zomh)
	    acczom+=zomh

	    # Refresh screen and wait for next iteration
	    cmd.refresh()
	    time.sleep(0.05)

#	    print "x={0}, y={1}, z={2}" .format(x, y, z)