Beispiel #1
0
    def testRepsExist(self):
        cmd.viewport(200, 150)
        cmd.load(self.datafile('1oky-frag.pdb'), 'm1')

        # make some nonbonded
        cmd.unbond('resi 115-', 'resi 115-')

        # labels
        cmd.label('all', 'name')

        # measurements
        cmd.distance('measure1', 'index 1', 'index 10')
        cmd.angle('measure1', 'index 1', 'index 10', 'index 20')
        cmd.dihedral('measure1', 'index 1', 'index 10', 'index 20', 'index 30')

        # color test setup
        cmd.color('white', '*')
        cmd.set('ambient', 1)
        cmd.set('depth_cue', 0)
        cmd.set('antialias', 0)
        cmd.set('line_smooth', 0)
        cmd.orient()

        # test most reps
        for rep in REPS:
            cmd.show_as(rep)
            self.assertImageHasColor('white', msg='rep missing: ' + rep)

        # test cartoon
        cmd.show_as('cartoon')
        for cart in CARTOONS:
            cmd.cartoon(cart)
            self.assertImageHasColor('white', msg='cartoon missing: ' + cart)
Beispiel #2
0
    def testMeasureBetweenStates(self):
        cmd.load(self.datafile('1v5a-3models.cif'), 'm1')

        # distance
        d = cmd.distance('d1', '24/CZ', 'same', state1=2, state2=3)
        self.assertAlmostEqual(d, 3.0, delta=1e-1)

        # angle
        a = cmd.angle('a1',
                      '24/CZ',
                      'same',
                      'same',
                      state1=2,
                      state2=3,
                      state3=1)
        self.assertAlmostEqual(a, 73.5, delta=1e-1)

        # visual test
        cmd.viewport(100, 100)
        cmd.set('dash_radius', 1.0)
        self.ambientOnly()
        for name in ['d1', 'a1']:
            cmd.disable('*')
            cmd.enable(name)
            cmd.zoom(name)
            self.assertImageHasColor('yellow')
Beispiel #3
0
    def testAA(self):
        '''
        Make a black/white image and check if gray pixels are found with
        antialias_shader=1/2
        '''
        cmd.viewport(100, 100)

        cmd.set('use_shaders', True)

        self.ambientOnly()

        cmd.fragment('gly')
        cmd.show_as('spheres')
        cmd.color('white')
        cmd.zoom()

        # b/w image, we expect only two color values
        img = self.get_imagearray()
        self.assertNumColorsEqual(img, 2)

        for aa in (1, 2):
            cmd.set('antialias_shader', aa)

            # smoothed edges, we expect more than two color values
            img = self.get_imagearray()
            self.assertTrue(len(numpy.unique(img[..., :3])) > 2)
Beispiel #4
0
def pnghack(filepath, width=1024, height=768):
    #Workaround if cmd.png() doesn't work
    cmd.set('ray_trace_frames', 1)  # Frames are raytraced before saving an image.
    cmd.set('ray_shadows', 0)
    cmd.viewport(width, height)  # Set resolution
    cmd.mpng(filepath, 1, 1)  # Use batch png mode with 1 frame only
    cmd.mplay()  # cmd.mpng needs the animation to 'run'
Beispiel #5
0
    def testTrilines(self, trilines):
        cmd.viewport(100, 100)

        cmd.set('use_shaders', True)

        self.ambientOnly()

        cmd.set('dynamic_width', 0)
        cmd.set('line_width', 5)
        cmd.set('line_smooth', 0)

        cmd.fragment('ethylene')
        cmd.show_as('lines')
        cmd.color('white')
        cmd.orient()

        cmd.set('trilines', trilines)

        # check percentage of covered pixels
        img = self.get_imagearray()
        npixels = img.shape[0] * img.shape[1]
        covered = numpy.count_nonzero(img[..., :3])
        ratio = covered / float(npixels)
        msg = "covered=%d npixels=%d ratio=%f" % (covered, npixels, ratio)
        self.assertTrue(0.14 < ratio < 0.165, msg)
Beispiel #6
0
    def testTrilines(self, trilines):
        cmd.viewport(100, 100)

        cmd.set('use_shaders', True)

        self.ambientOnly()

        cmd.set('dynamic_width', 0)
        cmd.set('line_width', 5)
        cmd.set('line_smooth', 0)

        cmd.fragment('ethylene')
        cmd.show_as('lines')
        cmd.color('white')
        cmd.orient()

        cmd.set('trilines', trilines)

        # check percentage of covered pixels
        img = self.get_imagearray()
        npixels = img.shape[0] * img.shape[1]
        covered = numpy.count_nonzero(img[...,:3])
        ratio = covered / float(npixels)
        msg = "covered=%d npixels=%d ratio=%f" % (covered, npixels, ratio)
        self.assertTrue(0.14 < ratio < 0.165, msg)
def draw_ENM(structure_filepath, script_filepath, structure_name="CAonly", output_dir='.', view=None):
    """ Draws elastic network model of a structure and saves image.
    """

    cmd.delete('all')
    cmd.load(structure_filepath, "CAonly")
    cmd.run(script_filepath)

    # Set name
    if structure_name == "CAonly":
        pass
    else:
        cmd.set_name("CAonly", structure_name)

    # Set view
    if view == None:
        cmd.orient()
    else:
        cmd.set_view(view)
    
    cmd.viewport(width=1200, height=1200)
    cmd.zoom(complete=1)

    png_filepath = os.path.join(output_dir, structure_name) + ".png"
    pse_filepath = os.path.join(output_dir, structure_name) + ".pse"

    cmd.save(pse_filepath)
    cmd.set('ray_opaque_background', 0)
    cmd.png(png_filepath, width=1200, height=1200, ray=1)

    return (pse_filepath, png_filepath)
Beispiel #8
0
    def testLabelPositionZ(self, use_shaders, ray):
        '''
        Test label z position for regular labels
        '''
        if not ray and invocation.options.no_gui:
            self.skipTest('no gui')

        cmd.set('use_shaders', use_shaders)

        cmd.viewport(200, 200)

        cmd.pseudoatom('m1', vdw=10, label='X')
        cmd.zoom(buffer=12)

        cmd.show('spheres')
        cmd.color('blue')
        cmd.set('label_color', 'red')
        cmd.set('label_size', 20)
        cmd.set('label_font_id', 7) # bold
        self.ambientOnly()

        # label outside of sphere
        cmd.set('label_position', [0, 0, 11.1])
        img = self.get_imagearray(ray=ray)
        self.assertImageHasColor('blue', img)
        self.assertImageHasColor('red', img, delta=20)

        # label inside of sphere
        cmd.set('label_position', [0, 0, 10.5])
        img = self.get_imagearray(ray=ray)
        self.assertImageHasColor('blue', img)
        self.assertImageHasNotColor('red', img, delta=20)
    def test(self):
        cmd.viewport(100, 100)

        # make map
        cmd.fragment('gly', 'm1')
        cmd.set('gaussian_b_floor', 30)
        cmd.set('mesh_width', 5)
        cmd.map_new('map')
        cmd.delete('m1')

        # make mesh 
        cmd.isomesh('mesh', 'map')

        # check mesh presence by color
        meshcolor = 'red'
        cmd.color(meshcolor, 'mesh')
        self.ambientOnly()
        self.assertImageHasColor(meshcolor)

        # continue without map
        cmd.delete('map')

        with testing.mktemp('.pse') as filename:
            cmd.save(filename)

            cmd.delete('*')
            self.assertImageHasNotColor(meshcolor)

            cmd.load(filename)
            self.assertImageHasColor(meshcolor)
Beispiel #10
0
    def testRepsExist(self):
        cmd.viewport(200, 150)
        cmd.load(self.datafile('1oky-frag.pdb'), 'm1')

        # make some nonbonded
        cmd.unbond('resi 115-', 'resi 115-')

        # labels
        cmd.label('all', 'name')

        # measurements
        cmd.distance('measure1', 'index 1', 'index 10')
        cmd.angle('measure1', 'index 1', 'index 10', 'index 20')
        cmd.dihedral('measure1', 'index 1', 'index 10', 'index 20', 'index 30')

        # color test setup
        cmd.color('white', '*')
        cmd.set('ambient', 1)
        cmd.set('depth_cue', 0)
        cmd.set('antialias', 0)
        cmd.set('line_smooth', 0)
        cmd.orient()

        # test most reps
        for rep in REPS:
            cmd.show_as(rep)
            self.assertImageHasColor('white', msg='rep missing: ' + rep)

        # test cartoon
        cmd.show_as('cartoon')
        for cart in CARTOONS:
            cmd.cartoon(cart)
            self.assertImageHasColor('white', msg='cartoon missing: ' + cart)
Beispiel #11
0
    def testLabelRelativeMode(self):
        # +-----+-----+
        # |     |     |
        # +-----+-----+
        # | XYZ |     |
        # +-----+-----|

        self.ambientOnly()
        cmd.set('opaque_background')
        cmd.set('label_font_id', 7)  # bold
        cmd.set('label_color', 'white')
        cmd.set('label_size', -1)  # Angstrom sized
        cmd.pseudoatom('m1', label="XYZ")
        cmd.zoom()

        width = 400
        height = 200
        w4 = width // 4
        h4 = height // 4

        cmd.viewport(width, height)

        for x in (-1, 1):
            for y in (-1, 1):
                # relative position
                cmd.set('label_relative_mode', 1)
                cmd.set('label_screen_point', (0.5 * x, 0.5 * y, 0))
                self.assertColorInQuadrant(x, y, width, height)

                # absolute position in pixels
                cmd.set('label_relative_mode', 2)
                cmd.set('label_screen_point', ((2 + x) * w4, (2 + y) * h4, 0))
                self.assertColorInQuadrant(x, y, width, height)
Beispiel #12
0
    def testAA(self):
        '''
        Make a black/white image and check if gray pixels are found with
        antialias_shader=1/2
        '''
        cmd.viewport(100, 100)

        cmd.set('use_shaders', True)

        self.ambientOnly()

        cmd.fragment('gly')
        cmd.show_as('spheres')
        cmd.color('white')
        cmd.zoom()

        # b/w image, we expect only two color values
        img = self.get_imagearray()
        self.assertTrue(len(numpy.unique(img[...,:3])) == 2)

        for aa in (1, 2):
            cmd.set('antialias_shader', aa)

            # smoothed edges, we expect more than two color values
            img = self.get_imagearray()
            self.assertTrue(len(numpy.unique(img[...,:3])) > 2)
Beispiel #13
0
    def test_color_deep(self):
        cmd.viewport(100, 70)
        self.ambientOnly()

        cmd.fragment('trp', 'm1')
        cmd.orient('m1')
        cmd.show_as('sticks')
        cmd.show('spheres', 'name C')
        cmd.set('stick_color', 'blue', 'm1')
        cmd.set('stick_color', 'red', 'name CH2+CZ3+CE3+CD2')
        cmd.set('sphere_color', 'yellow', 'name C')

        cmd.color('green')

        img = self.get_imagearray()
        self.assertImageHasColor('blue', img)
        self.assertImageHasColor('red', img)
        self.assertImageHasColor('yellow', img)
        self.assertImageHasNotColor('green', img)

        cmd.color_deep('green')

        img = self.get_imagearray()
        self.assertImageHasNotColor('blue', img)
        self.assertImageHasNotColor('red', img)
        self.assertImageHasNotColor('yellow', img)
        self.assertImageHasColor('green', img)
    def test(self, matrix_mode):
        cmd.viewport(100, 100)
        cmd.set('matrix_mode', matrix_mode)
        cmd.set('ambient', 1.0)

        cmd.read_pdbstr(v_pdbstr_anisou, 'm1', zoom=0)
        cmd.read_pdbstr(v_pdbstr_rotated, 'm2', zoom=0)
        self._rep()

        cmd.set_view(views[0])
        ref = self.get_imagearray()
        self.assertImageHasColor('yellow')

        cmd.align('m1', 'm2')
        cmd.set_view(views[1])
        self.assertImageEqual(ref,
                              count=100,
                              delta=1,
                              msg='ANISOU not aligned on display')

        pdbstr = cmd.get_pdbstr('m1')
        cmd.delete('*')
        cmd.read_pdbstr(pdbstr, 'm1', zoom=0)
        self._rep()
        self.assertImageEqual(ref, count=100, msg='ANISOU not aligned in PDB')
Beispiel #15
0
    def testStickBall(self, use_shader):
        '''
        Test some stick_ball* settings
        '''
        cmd.viewport(100, 100)

        cmd.set('use_shaders', use_shader)

        self.ambientOnly()

        cmd.set('stick_ball')
        cmd.set('stick_ball_ratio', 2.0)
        cmd.set('stick_ball_color', 'blue')
        cmd.set('stick_color', 'red')

        cmd.fragment('gly')
        cmd.orient()

        cmd.color('green')
        cmd.show_as('sticks')

        img = self.get_imagearray()
        self.assertImageHasColor('blue', img)
        self.assertImageHasColor('red', img)
        self.assertImageHasNotColor('green', img)
    def test(self):
        cmd.viewport(100,100)

        cmd.set('gaussian_b_floor', 20)
        cmd.set('ambient', 1)
        cmd.set('specular', 0)
        cmd.set('mesh_color', 'blue')
        cmd.set('dot_color', 'green')

        cmd.fragment('gly')
        cmd.map_new('map1')
        cmd.disable('*')

        cmd.isomesh('o1', 'map1')
        cmd.color('red', 'o1')
        cmd.show('cell')
        self._check_colors('red', 'blue')
        cmd.delete('o1')
 
        cmd.isodot('o1', 'map1')
        cmd.color('red', 'o1')
        self._check_colors('green')
        cmd.delete('o1')

        cmd.gradient('o1', 'map1')
        cmd.color('yellow', 'o1')
        self._check_colors('yellow')
        cmd.delete('o1')
Beispiel #17
0
    def testStickBall(self, use_shader):
        '''
        Test some stick_ball* settings
        '''
        cmd.viewport(100, 100)

        cmd.set('use_shaders', use_shader)

        self.ambientOnly()

        cmd.set('stick_ball')
        cmd.set('stick_ball_ratio', 2.0)
        cmd.set('stick_ball_color', 'blue')
        cmd.set('stick_color', 'red')

        cmd.fragment('gly')
        cmd.orient()

        cmd.color('green')
        cmd.show_as('sticks')

        img = self.get_imagearray()
        self.assertImageHasColor('blue', img)
        self.assertImageHasColor('red', img)
        self.assertImageHasNotColor('green', img)
Beispiel #18
0
    def testIsosurface(self):
        cmd.viewport(100, 100)

        cmd.fragment('gly', 'm1')
        cmd.set('gaussian_b_floor', 30)
        cmd.set('mesh_width', 5)
        cmd.map_new('map')
        cmd.delete('m1')

        # make mesh
        cmd.isosurface('surface', 'map')
        cmd.isosurface('surface', 'map', source_state=1, state=-2)

        ## check mesh presence by color
        meshcolor = 'red'
        cmd.color(meshcolor, 'surface')
        self.ambientOnly()
        self.assertImageHasColor(meshcolor)
        cmd.frame(2)
        self.assertEqual(cmd.get_state(), 2)
        self.assertImageHasColor(meshcolor)

        with testing.mktemp('.pse') as filename:
            cmd.save(filename)

            cmd.delete('*')
            self.assertImageHasNotColor(meshcolor)

            cmd.load(filename)
            self.assertImageHasColor(meshcolor)
            cmd.frame(2)
            self.assertEqual(cmd.get_state(), 2)
            self.assertImageHasColor(meshcolor)
Beispiel #19
0
    def testLabelPositionZ(self, use_shaders, ray):
        '''
        Test label z position for regular labels
        '''
        if not ray and invocation.options.no_gui:
            self.skipTest('no gui')

        cmd.set('use_shaders', use_shaders)

        cmd.viewport(200, 200)

        cmd.pseudoatom('m1', vdw=10, label='X')
        cmd.zoom(buffer=12)

        cmd.show('spheres')
        cmd.color('blue')
        cmd.set('label_color', 'red')
        cmd.set('label_size', 20)
        cmd.set('label_font_id', 7)  # bold
        self.ambientOnly()

        # label outside of sphere
        cmd.set('label_position', [0, 0, 11.1])
        img = self.get_imagearray(ray=ray)
        self.assertImageHasColor('blue', img)
        self.assertImageHasColor('red', img, delta=20)

        # label inside of sphere
        cmd.set('label_position', [0, 0, 10.5])
        img = self.get_imagearray(ray=ray)
        self.assertImageHasColor('blue', img)
        self.assertImageHasNotColor('red', img, delta=20)
Beispiel #20
0
    def testIsolevel(self):
        cmd.viewport(100, 100)

        cmd.fragment('gly', 'm1')
        cmd.set('gaussian_b_floor', 30)
        cmd.set('mesh_width', 5)
        cmd.map_new('map')
        cmd.delete('m1')

        # make mesh
        cmd.isodot('dot', 'map')
        cmd.isodot('dot', 'map', source_state=1, state=-2)

        ## check mesh presence by color
        meshcolor = 'red'
        cmd.color(meshcolor, 'dot')
        self.ambientOnly()
        self.assertImageHasColor(meshcolor)
        cmd.frame(2)
        self.assertEqual(cmd.get_state(), 2)
        self.assertImageHasColor(meshcolor)

        for contourlvl in range(7):
            cmd.isolevel('dot', contourlvl)
            self.assertImageHasColor(meshcolor)

        cmd.isolevel('dot', 10)
        self.assertImageHasNotColor(meshcolor)
Beispiel #21
0
    def test(self):
        cmd.viewport(100, 100)

        # make map
        cmd.fragment('gly', 'm1')
        cmd.set('gaussian_b_floor', 30)
        cmd.set('mesh_width', 5)
        cmd.map_new('map')
        cmd.delete('m1')

        # make mesh
        cmd.isomesh('mesh', 'map')

        # check mesh presence by color
        meshcolor = 'red'
        cmd.color(meshcolor, 'mesh')
        self.ambientOnly()
        self.assertImageHasColor(meshcolor)

        # continue without map
        cmd.delete('map')

        with testing.mktemp('.pse') as filename:
            cmd.save(filename)

            cmd.delete('*')
            self.assertImageHasNotColor(meshcolor)

            cmd.load(filename)
            self.assertImageHasColor(meshcolor)
Beispiel #22
0
    def testLabelRelativeMode(self):
        # +-----+-----+
        # |     |     |
        # +-----+-----+
        # | XYZ |     |
        # +-----+-----|

        self.ambientOnly()
        cmd.set('opaque_background')
        cmd.set('label_font_id', 7)  # bold
        cmd.set('label_color', 'white')
        cmd.set('label_size', -1)  # Angstrom sized
        cmd.pseudoatom('m1', label="XYZ")
        cmd.zoom()

        width = 400
        height = 200
        w4 = width // 4
        h4 = height // 4

        cmd.viewport(width, height)

        for x in (-1, 1):
            for y in (-1, 1):
                # relative position
                cmd.set('label_relative_mode', 1)
                cmd.set('label_screen_point', (0.5 * x, 0.5 * y, 0))
                self.assertColorInQuadrant(x, y, width, height)

                # absolute position in pixels
                cmd.set('label_relative_mode', 2)
                cmd.set('label_screen_point', ((2 + x) * w4, (2 + y) * h4, 0))
                self.assertColorInQuadrant(x, y, width, height)
Beispiel #23
0
 def _testSpectrum_setup(self):
     cmd.pseudoatom('m1', pos=(-2, 0, 0))
     cmd.pseudoatom('m2', pos=(0, 0, 0))
     cmd.pseudoatom('m3', pos=(2, 0, 0))
     cmd.show_as('spheres')
     self.ambientOnly()
     cmd.viewport(40, 20)
     cmd.zoom()
Beispiel #24
0
 def _testSpectrum_setup(self):
     cmd.pseudoatom('m1', pos=(-2,0,0))
     cmd.pseudoatom('m2', pos=(0,0,0))
     cmd.pseudoatom('m3', pos=(2,0,0))
     cmd.show_as('spheres')
     self.ambientOnly()
     cmd.viewport(40,20)
     cmd.zoom()
Beispiel #25
0
    def png_workaround(filepath, width=1200, height=800):
        """Workaround for (a) severe bug(s) in PyMOL preventing ray-traced images to be produced in command-line mode.
        Use this function in case neither cmd.ray() or cmd.png() work.
        """
        sys.stdout = sys.__stdout__
        cmd.feedback('disable', 'movie', 'everything')
        cmd.viewport(width, height)
        cmd.zoom('visible', 1.5)  # Adapt the zoom to the viewport
        cmd.set('ray_trace_frames',
                1)  # Frames are raytraced before saving an image.
        cmd.mpng(filepath, config.MODEL,
                 config.MODEL)  # Use batch png mode with 1 frame only
        cmd.mplay()  # cmd.mpng needs the animation to 'run'
        cmd.refresh()
        originalfile = "".join([
            filepath,
            (4 - len(str(config.MODEL))) * '0' + str(config.MODEL) + '.png'
        ])
        newfile = "".join([filepath, '.png'])

        #################################################
        # Wait for file for max. 1 second and rename it #
        #################################################

        attempts = 0
        while not os.path.isfile(originalfile) and attempts <= 10:
            sleep(0.1)
            attempts += 1
        if os.name == 'nt':  # In Windows, make sure there is no file of the same name, cannot be overwritten as in Unix
            if os.path.isfile(newfile):
                os.remove(newfile)
        os.rename(originalfile, newfile)  # Remove frame number in filename

        #  Check if imagemagick is available and crop + resize the images
        if subprocess.call("type convert",
                           shell=True,
                           stdout=subprocess.PIPE,
                           stderr=subprocess.PIPE) == 0:
            attempts, ecode = 0, 1
            # Check if file is truncated and wait if that's the case
            while ecode != 0 and attempts <= 10:
                ecode = subprocess.call(['convert', newfile, '/dev/null'],
                                        stdout=open('/dev/null', 'w'),
                                        stderr=subprocess.STDOUT)
                sleep(0.1)
                attempts += 1
            trim = 'convert -trim ' + newfile + ' -bordercolor White -border 20x20 ' + newfile + ';'  # Trim the image
            os.system(trim)
            getwidth = 'w=`convert ' + newfile + ' -ping -format "%w" info:`;'  # Get the width of the new image
            getheight = 'h=`convert ' + newfile + ' -ping -format "%h" info:`;'  # Get the hight of the new image
            newres = 'if [ "$w" -gt "$h" ]; then newr="${w%.*}x$w"; else newr="${h%.*}x$h"; fi;'  # Set quadratic ratio
            quadratic = 'convert ' + newfile + ' -gravity center -extent "$newr" ' + newfile  # Fill with whitespace
            os.system(getwidth + getheight + newres + quadratic)
        else:
            sys.stderr.write(
                'Imagemagick not available. Images will not be resized or cropped.'
            )
def colour_by_heatmap(colour_data,
                      structure_path,
                      molecule_name="protein",
                      output_path="colour_by_heatmap",
                      view=None):
    '''
DESCRIPTION

    Colours PDB structure by colour map data.
    output_filepath
    >>> colour_by_heatmap(df, structure_filepath="xxxx.pdb", mol_name="protein", out_dir='.')
    '''

    # if not (isinstance(colour_data, pd.core.series.Series) or isinstance(colour_data, dict)):
    #     print('''
    #             Passed data must be either dictionary or Pandas Series object.
    #             Key = residue number
    #             Value = PyMOL hex code
    #             ''')
    #     return None

    cmd.load(structure_path, object=molecule_name)

    # Set view
    if view == None:
        cmd.reset()
        cmd.orient()
    else:
        cmd.set_view(view)

    cmd.viewport(width=1200, height=1200)
    cmd.zoom(complete=1)

    cmd.set('cartoon_discrete_colors', 1)
    cmd.set('sphere_scale', 1)

    cmd.show_as('cartoon', molecule_name)
    cmd.color('white', molecule_name)

    # Iterate over the alpha-carbons
    # residue_numbers = []
    # cmd.iterate('{} and name CA'.format(molecule_name) , 'residue_numbers.append(resi)')

    # Colour the structure
    for residue_number in colour_data.columns:
        # print(colour_data[residue_number].item())
        cmd.color(colour_data[residue_number].item(),
                  '{0} and resi {1}'.format(molecule_name, residue_number))

    png_out_path = output_path + ".png"
    pse_out_path = output_path + ".pse"

    cmd.save(pse_out_path)

    cmd.set('ray_opaque_background', 0)
    cmd.png(png_out_path, width=1200, height=1200, ray=1, quiet=0)
def png_workaround(filepath, width=1024, height=768):
    """Workaround for (a) severe bug(s) in PyMOL preventing ray-traced images to be produced in command-line mode.
    Use this function in case neither cmd.ray() or cmd.png() work.
    """
    cmd.set('ray_trace_frames', 1)  # Frames are raytraced before saving an image.
    cmd.viewport(width, height)  # Set resolution
    ### Workaround for raytracing in command-line mode
    cmd.mpng(filepath, 1, 1)  # Use batch png mode with 1 frame only
    cmd.mplay()  # cmd.mpng needs the animation to 'run'
    os.rename("".join([filepath[:-4], '0001.png']), "".join([filepath[:-4], '.png']))  # Remove frame number in filename
Beispiel #28
0
        def setUp(self):
            self.oldcwd = os.getcwd()
            cmd.reinitialize()
            cmd.viewport(640, 480)

            cwd = self.moddirs[type(self).__module__]
            os.chdir(cwd)

            cmd.feedback('push')
            cmd.feedback('disable', 'all', 'details actions')
            self.timings = []
def setup_pymol():
    """Sets up PyMOL for making animations."""
    pymol.finish_launching()  # Prevent threading errors
    # Configure global settings
    cmd.set('scene_buttons', 1)
    cmd.set('matrix_mode', 1)
    cmd.set('movie_panel', 1)
    # Configure quality settings
    cmd.mset("1 x500")
    cmd.set('ray_trace_frames', 1)
    cmd.viewport(800, 800)
Beispiel #30
0
 def _testSpectrum_setup(self):
     cmd.pseudoatom('m1', pos=(-2,0,0))
     cmd.pseudoatom('m2', pos=(0,0,0))
     cmd.pseudoatom('m3', pos=(2,0,0))
     cmd.show_as('spheres')
     cmd.set('ambient', 1)
     cmd.set('specular', 0)
     cmd.set('reflect', 0)
     cmd.set('direct', 0)
     cmd.viewport(40,20)
     cmd.zoom()
Beispiel #31
0
def setup_pymol():
    """Sets up PyMOL for making animations."""
    pymol.finish_launching()  # Prevent threading errors
    # Configure global settings
    cmd.set('scene_buttons', 1)
    cmd.set('matrix_mode', 1)
    cmd.set('movie_panel', 1)
    # Configure quality settings
    cmd.mset("1 x500")
    cmd.set('ray_trace_frames', 1)
    cmd.viewport(800, 800)
Beispiel #32
0
        def setUp(self):
            self.oldcwd = os.getcwd()
            cmd.reinitialize()
            cmd.viewport(640, 480)

            cwd = self.moddirs[type(self).__module__]
            os.chdir(cwd)

            cmd.feedback('push')
            cmd.feedback('disable', 'all', 'details actions')
            self.timings = []
Beispiel #33
0
 def testRegression2207(self):
     '''
     The initial fix for PYMOL-1697 crashed this example
     (PYMOL-2207)
     '''
     cmd.load(self.datafile('1oky-frag.pdb'))
     cmd.create('1oky-frag', 'resi 80-100', 1, 2)
     cmd.remove('resi 85-95')
     # keep ray efford low
     cmd.viewport(50, 50)
     # caused segfault
     img = self.get_imagearray(ray=1)
Beispiel #34
0
 def testRegression2207(self):
     '''
     The initial fix for PYMOL-1697 crashed this example
     (PYMOL-2207)
     '''
     cmd.load(self.datafile('1oky-frag.pdb'))
     cmd.create('1oky-frag', 'resi 80-100', 1, 2)
     cmd.remove('resi 85-95')
     # keep ray efford low
     cmd.viewport(50, 50)
     # caused segfault
     img = self.get_imagearray(ray=1)
def png_workaround(filepath, width=1024, height=768):
    """Workaround for (a) severe bug(s) in PyMOL preventing ray-traced images to be produced in command-line mode.
    Use this function in case neither cmd.ray() or cmd.png() work.
    """
    cmd.set('ray_trace_frames',
            1)  # Frames are raytraced before saving an image.
    cmd.viewport(width, height)  # Set resolution
    ### Workaround for raytracing in command-line mode
    cmd.mpng(filepath, 1, 1)  # Use batch png mode with 1 frame only
    cmd.mplay()  # cmd.mpng needs the animation to 'run'
    os.rename("".join([filepath[:-4], '0001.png']),
              "".join([filepath[:-4],
                       '.png']))  # Remove frame number in filename
Beispiel #36
0
        def setUp(self):
            self.oldcwd = os.getcwd()
            cmd.reinitialize()
            cmd.viewport(640, 480)

            if cliargs.no_undo:
                cmd.set('suspend_undo', updates=0)

            cwd = self.moddirs[type(self).__module__]
            os.chdir(cwd)

            cmd.feedback('push')
            cmd.feedback('disable', 'all', 'details actions')
            self.timings = []
Beispiel #37
0
def color_L1(arg0, arg1, arg2, arg3, arg4=1, MOVIE=0, bgcol='hydrogen'):
    '''
DESCRIPTION

    Brief description: Colors the identified L1 features 
    '''
    # Running on pymol cmdline
    #run ./pymol_scripts/color_L1.py
    #color_L1 pdb/1ruz.pdb, 78 137 158 188 241 292 573, green, 2
    filename = arg0

    cmd.load(filename)
    cmd.hide('everything')
    #cmd.cartoon('rectangle')
    cmd.show('cartoon')

    cmd.set('reflect', 0.5)

    Feature_set = [int(j) for j in np.array(arg1.split())]
    col = arg2
    L = int(arg3)

    #reset color to gray
    if arg4 == '1':
        print('coloring gray')
        cmd.do('color ' + bgcol)

    print(arg4)

    F = np.array([np.arange(i - L, i + L + 1) for i in Feature_set]).flatten()
    for feature in F:
        print("resi " + str(feature))
        cmd.color(col, "resi " + str(feature))

    cmd.viewport("2560,1920")

    if MOVIE == "0":
        MOVIE = False

    if MOVIE:
        cmd.show('surface')
        cmd.mset('1 x 10')
        cmd.util.mroll(1, 10, 1)

        cmd.mplay
        cmd.viewport("2560,1920")
        cmd.set("ray_trace_frames", 1)
        cmd.set("cache_frames", 0)
        cmd.mclear
        cmd.mpng('zXXXmov')
Beispiel #38
0
    def test(self, bb_rep, sc_rep, bb_set, n_a_m):
        cmd.viewport(100, 100)

        # color classes
        color = {'cartoon': 'blue', 'ribbon': 'red'}
        sc_color = 'white'
        op_color = 'green'
        p_color = 'yellow'

        # lighting setup for color testing
        self.ambientOnly()
        cmd.set('dynamic_width', 0)
        cmd.set('line_width', 4)
        cmd.set('ribbon_width', 4)

        # settings setup
        cmd.set(bb_set + '_side_chain_helper')
        cmd.set(bb_set + '_nucleic_acid_mode', n_a_m)
        cmd.set('ribbon_color', color['ribbon'])
        cmd.set('cartoon_color', color['cartoon'])

        # data
        cmd.load(self.datafile('1ehz-5.pdb'))
        cmd.orient()

        # atom colors
        cmd.color(sc_color)
        cmd.color(op_color, "name OP1+OP2")  # not visible with SCH
        cmd.color(p_color,
                  "name P+O3'+C5'+O5'")  # not visible with SCH and NAM=1

        # need to check for OP1 and O1P naming scheme, so alter some atoms
        cmd.alter('name OP1 & resi 1-2', 'name="O1P"')
        cmd.alter('name OP2 & resi 1-2', 'name="O2P"')

        # reps
        cmd.show_as(bb_rep)
        cmd.show(sc_rep)

        # test
        img = self.get_imagearray()
        self.assertImageHasColor(sc_color, img)  # always visible
        for bb_test in ['cartoon', 'ribbon']:
            self._assertImageHasColor(bb_rep == bb_test, color[bb_test], img,
                                      0, bb_test + ' wrong')
        self._assertImageHasColor(not (bb_rep == bb_set), op_color, img, 0,
                                  'OP wrong')
        self._assertImageHasColor(not (bb_rep == bb_set and n_a_m == 1),
                                  p_color, img, 0, 'NAM=1 wrong')
Beispiel #39
0
    def test(self, ribbon_as_cylinders):
        cmd.set('ribbon_as_cylinders', ribbon_as_cylinders)
        cmd.set('ribbon_width', 8)
        cmd.fab('AG')
        cmd.color('red', 'resn ALA')
        cmd.color('blue', 'resn GLY')
        cmd.show_as('ribbon')
        cmd.orient()

        self.ambientOnly()
        cmd.viewport(100, 100)
        cmd.draw(100, 100)
        img = self.get_imagearray()
        self.assertImageHasColor('red', img)
        self.assertImageHasColor('blue', img)
Beispiel #40
0
    def test(self, ribbon_as_cylinders):
        cmd.set('ribbon_as_cylinders', ribbon_as_cylinders)
        cmd.set('ribbon_width', 8)
        cmd.fab('AG')
        cmd.color('red', 'resn ALA')
        cmd.color('blue', 'resn GLY')
        cmd.show_as('ribbon')
        cmd.orient()

        self.ambientOnly()
        cmd.viewport(100, 100)
        cmd.draw(100, 100)
        img = self.get_imagearray()
        self.assertImageHasColor('red', img)
        self.assertImageHasColor('blue', img)
Beispiel #41
0
    def _testAtomCartoonTransparency(self):
        self.ambientOnly()
        cmd.viewport(100, 100)
        cmd.set('opaque_background')
        cmd.set('ray_shadow', 0)

        cmd.orient()

        cmd.color('0xFF0000')
        cmd.color('0x0000FF', 'sele')

        # all opaque
        img = self.get_imagearray()
        self.assertImageHasColor('0xFF0000', img)
        self.assertImageHasColor('0x0000FF', img)

        # object-level transparency
        cmd.set('cartoon_transparency', 0.4)
        img = self.get_imagearray()
        self.assertImageHasColor('0x990000', img)  # 40%
        self.assertImageHasColor('0x000099', img)  # 40%
        self.assertImageHasNotColor('0xFF0000', img)
        self.assertImageHasNotColor('0x0000FF', img)

        # atom-level full-opaque
        cmd.set('cartoon_transparency', 0.0, 'sele')
        img = self.get_imagearray()
        self.assertImageHasColor('0x990000', img)  # 40%
        self.assertImageHasColor('0x0000FF', img)  #  0%
        self.assertImageHasNotColor('0xFF0000', img)
        self.assertImageHasNotColor('0x000099', img)

        # atom-level semi-transparent
        cmd.set('cartoon_transparency', 0.6, 'sele')
        img = self.get_imagearray()
        self.assertImageHasColor('0x990000', img)  # 40%
        self.assertImageHasColor('0x000066', img, delta=1)  # 60%
        self.assertImageHasNotColor('0xFF0000', img)
        self.assertImageHasNotColor('0x0000FF', img)
        self.assertImageHasNotColor('0x000099', img)

        # atom-level full-transparent (expect only two color values)
        cmd.set('cartoon_transparency', 0.0)
        cmd.set('cartoon_transparency', 1.0, 'sele')
        img = self.get_imagearray()
        self.assertImageHasColor('0xFF0000', img)
        # need delta=1 with clang, but not with gcc
        self.assertNumColorsEqual(img, 2, delta=1)
Beispiel #42
0
    def _testAtomCartoonTransparency(self):
        self.ambientOnly()
        cmd.viewport(100, 100)
        cmd.set('opaque_background')
        cmd.set('ray_shadow', 0)

        cmd.orient()

        cmd.color('0xFF0000')
        cmd.color('0x0000FF', 'sele')

        # all opaque
        img = self.get_imagearray()
        self.assertImageHasColor('0xFF0000', img)
        self.assertImageHasColor('0x0000FF', img)

        # object-level transparency
        cmd.set('cartoon_transparency', 0.4)
        img = self.get_imagearray()
        self.assertImageHasColor('0x990000', img) # 40%
        self.assertImageHasColor('0x000099', img) # 40%
        self.assertImageHasNotColor('0xFF0000', img)
        self.assertImageHasNotColor('0x0000FF', img)

        # atom-level full-opaque
        cmd.set('cartoon_transparency', 0.0, 'sele')
        img = self.get_imagearray()
        self.assertImageHasColor('0x990000', img) # 40%
        self.assertImageHasColor('0x0000FF', img) #  0%
        self.assertImageHasNotColor('0xFF0000', img)
        self.assertImageHasNotColor('0x000099', img)

        # atom-level semi-transparent
        cmd.set('cartoon_transparency', 0.6, 'sele')
        img = self.get_imagearray()
        self.assertImageHasColor('0x990000', img) # 40%
        self.assertImageHasColor('0x000066', img, delta=1) # 60%
        self.assertImageHasNotColor('0xFF0000', img)
        self.assertImageHasNotColor('0x0000FF', img)
        self.assertImageHasNotColor('0x000099', img)

        # atom-level full-transparent (expect only two color values)
        cmd.set('cartoon_transparency', 0.0)
        cmd.set('cartoon_transparency', 1.0, 'sele')
        img = self.get_imagearray()
        self.assertImageHasColor('0xFF0000', img)
        self.assertTrue(len(numpy.unique(img[...,:3])) == 2)
    def test(self, bb_rep, sc_rep, bb_set, n_a_m):
        cmd.viewport(100, 100)

        # color classes
        color = {'cartoon': 'blue', 'ribbon': 'red'}
        sc_color = 'white'
        op_color = 'green'
        p_color = 'yellow'

        # lighting setup for color testing
        self.ambientOnly()
        cmd.set('dynamic_width', 0)
        cmd.set('line_width', 4)
        cmd.set('ribbon_width', 4)

        # settings setup
        cmd.set(bb_set + '_side_chain_helper')
        cmd.set(bb_set + '_nucleic_acid_mode', n_a_m)
        cmd.set('ribbon_color', color['ribbon'])
        cmd.set('cartoon_color', color['cartoon'])

        # data
        cmd.load(self.datafile('1ehz-5.pdb'))
        cmd.orient()

        # atom colors
        cmd.color(sc_color)
        cmd.color(op_color, "name OP1+OP2")         # not visible with SCH
        cmd.color(p_color, "name P+O3'+C5'+O5'")    # not visible with SCH and NAM=1

        # need to check for OP1 and O1P naming scheme, so alter some atoms
        cmd.alter('name OP1 & resi 1-2', 'name="O1P"')
        cmd.alter('name OP2 & resi 1-2', 'name="O2P"')

        # reps
        cmd.show_as(bb_rep)
        cmd.show(sc_rep)

        # test
        img = self.get_imagearray()
        self.assertImageHasColor(sc_color, img) # always visible
        for bb_test in ['cartoon', 'ribbon']:
            self._assertImageHasColor(bb_rep == bb_test, color[bb_test], img, 0, bb_test + ' wrong')
        self._assertImageHasColor(not (bb_rep == bb_set), op_color, img, 0, 'OP wrong')
        self._assertImageHasColor(not (bb_rep == bb_set and n_a_m == 1), p_color, img, 0, 'NAM=1 wrong')
Beispiel #44
0
    def _testTransparency(self, rep, setting_name):
        cmd.fab('GGGG')
        cmd.remove('resi 2+3')
        cmd.select('sele', 'resi 4', 0)

        self.ambientOnly()
        cmd.viewport(100, 100)
        cmd.set('opaque_background')
        cmd.set('ray_shadow', 0)

        cmd.orient()

        cmd.color('0xFF0000')
        cmd.show_as(rep)

        # all opaque
        img = self.get_imagearray()
        self.assertImageHasColor('0xFF0000', img)

        # object-level transparency
        cmd.set(setting_name, 0.4)
        img = self.get_imagearray()
        self.assertImageHasColor('0x990000', img)  # 40%
        self.assertImageHasNotColor('0xFF0000', img)

        # atom-level full-opaque
        cmd.set(setting_name, 0.0, 'sele')
        img = self.get_imagearray()
        self.assertImageHasColor('0x990000', img)  # 40%
        self.assertImageHasColor('0xFF0000', img)  #  0%

        # atom-level semi-transparent
        cmd.set(setting_name, 0.6, 'sele')
        img = self.get_imagearray()
        self.assertImageHasColor('0x990000', img)  # 40%
        self.assertImageHasColor('0x660000', img, delta=1)  # 60%
        self.assertImageHasNotColor('0xFF0000', img)

        # atom-level full-transparent (expect only two color values)
        cmd.set(setting_name, 0.0)
        cmd.set(setting_name, 1.0, 'sele')
        img = self.get_imagearray()
        self.assertImageHasColor('0xFF0000', img)
        # need delta=1 with clang, but not with gcc
        self.assertNumColorsEqual(img, 2, delta=1)
Beispiel #45
0
    def _testTransparency(self, rep, setting_name):
        cmd.fab('GGGG')
        cmd.remove('resi 2+3')
        cmd.select('sele', 'resi 4', 0)

        self.ambientOnly()
        cmd.viewport(100, 100)
        cmd.set('opaque_background')
        cmd.set('ray_shadow', 0)

        cmd.orient()

        cmd.color('0xFF0000')
        cmd.show_as(rep)

        # all opaque
        img = self.get_imagearray()
        self.assertImageHasColor('0xFF0000', img)

        # object-level transparency
        cmd.set(setting_name, 0.4)
        img = self.get_imagearray()
        self.assertImageHasColor('0x990000', img) # 40%
        self.assertImageHasNotColor('0xFF0000', img)

        # atom-level full-opaque
        cmd.set(setting_name, 0.0, 'sele')
        img = self.get_imagearray()
        self.assertImageHasColor('0x990000', img) # 40%
        self.assertImageHasColor('0xFF0000', img) #  0%

        # atom-level semi-transparent
        cmd.set(setting_name, 0.6, 'sele')
        img = self.get_imagearray()
        self.assertImageHasColor('0x990000', img) # 40%
        self.assertImageHasColor('0x660000', img, delta=1) # 60%
        self.assertImageHasNotColor('0xFF0000', img)

        # atom-level full-transparent (expect only two color values)
        cmd.set(setting_name, 0.0)
        cmd.set(setting_name, 1.0, 'sele')
        img = self.get_imagearray()
        self.assertImageHasColor('0xFF0000', img)
        self.assertTrue(len(numpy.unique(img[...,:3])) == 2)
Beispiel #46
0
    def testChromadepth(self):
        cmd.viewport(100, 100)

        self.ambientOnly()

        cmd.set('use_shaders')
        cmd.set('chromadepth')
        cmd.set('orthoscopic')

        cmd.pseudoatom(pos=(0, 0, -5))
        cmd.pseudoatom(pos=(0, 0, 5))
        cmd.color('gray')
        cmd.show_as('spheres')
        cmd.zoom()
        cmd.turn('y', 20)

        img = self.get_imagearray()
        self.assertImageHasColor('blue', img)
        self.assertImageHasColor('red', img)
Beispiel #47
0
    def testChromadepth(self):
        cmd.viewport(100, 100)

        self.ambientOnly()

        cmd.set('use_shaders')
        cmd.set('chromadepth')
        cmd.set('orthoscopic')

        cmd.pseudoatom(pos=(0, 0, -5))
        cmd.pseudoatom(pos=(0, 0, 5))
        cmd.color('gray')
        cmd.show_as('spheres')
        cmd.zoom()
        cmd.turn('y', 20)

        img = self.get_imagearray()
        self.assertImageHasColor('blue', img)
        self.assertImageHasColor('red', img)
Beispiel #48
0
    def test_pse(self):
        self.ambientOnly()

        viewport = (50, 50)
        cmd.viewport(*viewport)

        objname = 'simpletri'
        obj = []
        obj.extend([
            cgo.BEGIN, cgo.TRIANGLES, cgo.COLOR, 1.0, 0., 0., cgo.VERTEX, 0.0,
            0.0, 1.0, cgo.VERTEX, 1.0, 0.0, 0.0, cgo.VERTEX, 0.0, 1.0, 0.0,
            cgo.END
        ])
        cmd.load_cgo(obj, objname, 1)

        s = cmd.get_session()
        cmd.set_session(s)

        self.assertEqual([objname], cmd.get_names())
        self.assertImageHasColor('red')
Beispiel #49
0
    def test(self):
        if not (pymol.invocation.options.no_gui or cmd.get_setting_int('use_shaders')):
            self.skipTest('no ray or shaders')

        self.ambientOnly()
        cmd.set('valence', 0)

        cmd.viewport(350, 200)
        cmd.fragment('ile')
        cmd.remove('hydro')
        cmd.show_as('sticks')
        cmd.orient()

        cmd.set('stick_ball', 0)
        img1 = self.get_imagearray()

        cmd.set('stick_ball', 1)
        img2 = self.get_imagearray()

        self.assertImageEqual(img1, img2, count=10)
Beispiel #50
0
    def testTransparencyMode3(self):
        '''
        Test if something gets rendered in transparency_mode=3
        '''
        cmd.viewport(100, 100)

        cmd.fragment('gly')
        cmd.zoom()

        cmd.set('transparency_mode', 3)
        cmd.set('transparency', 0.5)
        cmd.set('stick_transparency', 0.5)
        cmd.set('sphere_transparency', 0.5)
        cmd.set('cartoon_transparency', 0.5)

        for rep in ['sphere', 'stick', 'surface']:
            cmd.show_as(rep)

            # check on black screen to see if any shader failed
            img = self.get_imagearray()
            self.assertTrue(img[...,:3].any())
    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 #52
0
    def test(self, matrix_mode):
        cmd.viewport(100,100)
        cmd.set('matrix_mode', matrix_mode)
        cmd.set('ambient', 1.0)

        cmd.read_pdbstr(v_pdbstr_anisou, 'm1', zoom=0)
        cmd.read_pdbstr(v_pdbstr_rotated, 'm2', zoom=0)
        self._rep()

        cmd.set_view(views[0])
        ref = self.get_imagearray()
        self.assertImageHasColor('yellow')

        cmd.align('m1', 'm2')
        cmd.set_view(views[1])
        self.assertImageEqual(ref, count=100, delta=1, msg='ANISOU not aligned on display')

        pdbstr = cmd.get_pdbstr('m1')
        cmd.delete('*')
        cmd.read_pdbstr(pdbstr, 'm1', zoom=0)
        self._rep()
        self.assertImageEqual(ref, count=100, msg='ANISOU not aligned in PDB')
Beispiel #53
0
    def testBumpsPSE(self):
        self.ambientOnly()
        cmd.viewport(100, 100)

        # expect some clashes in this helix
        cmd.fab('AAAAA', 'm1', ss=1)
        cmd.orient()

        cmd.set('sculpt_vdw_vis_mode', 1)
        cmd.set('sculpt_field_mask', 0x020)  # cSculptVDW
        cmd.sculpt_activate('m1')
        cmd.sculpt_iterate('m1', cycles=0)
        cmd.show_as('cgo')

        img = self.get_imagearray()
        self.assertImageHasColor('0xFF3333', img)

        with testing.mktemp('.pse') as filename:
            cmd.save(filename)
            cmd.load(filename)

        self.assertImageEqual(img)
Beispiel #54
0
    def test(self):
        cmd.set('cartoon_gap_cutoff', 0) # default varies by version

        self.ambientOnly()

        cmd.viewport(150, 150)
        cmd.load(self.datafile('1oky-frag.pdb'))
        cmd.cartoon('dash')
        cmd.show_as('cartoon')
        cmd.orient()

        # no gaps
        img_nogaps = self.get_imagearray()

        # gap of length 0
        cmd.unbond('96/C', '97/N')
        img_gap = self.get_imagearray()
        self.assertFalse((img_gap == img_nogaps).all())

        # close gap with setting, should match first image (special case)
        cmd.set('cartoon_gap_cutoff', 1) # exact cutoff
        img_gap = self.get_imagearray()
        self.assertTrue((img_gap == img_nogaps).all())

        # gap of length 1
        cmd.remove('92/')
        img_gap = self.get_imagearray()
        cmd.set('cartoon_gap_cutoff', 2) # exact cutoff
        img_nogaps = self.get_imagearray()
        self.assertFalse((img_gap == img_nogaps).all())

        # gap of length 3
        cmd.remove('102-104/')
        cmd.cartoon('auto') # default
        img_gap = self.get_imagearray()
        cmd.set('cartoon_gap_cutoff', 10) # arbitrary larger cutoff
        img_nogaps = self.get_imagearray()
        self.assertFalse((img_gap == img_nogaps).all())
Beispiel #55
0
    def testLog2(self):
        """
        Tests robustness of different logging methods:
        1) Python implementation (cmd.log) vs. C implementation (PLog, via cmd.do)
        2) pml vs. py syntax
        3) handling of quoted input (''' broken in 1.8.2)
        """
        self.ambientOnly()
        cmd.viewport(100, 100)
        cmd.fragment('gly')
        cmd.orient()
        cmd.show_as('spheres')

        for ext in ['.pml', '.py']:
            with testing.mktemp(ext) as logfile:
                cmd.log_open(logfile)
                cmd.do('_ color blue')
                cmd.do('/cmd.color("yellow", "elem O")')
                cmd.do('cmd.color("""green""",' " '''elem N''')")
                cmd.log('bg red\n')
                cmd.log('', 'cmd.color(\'magenta\', "hydro")\n')
                cmd.log_close()

                cmd.color('white')
                cmd.bg_color('white')

                if ext == '.pml':
                    cmd.do('@' + logfile)
                else:
                    cmd.do('run ' + logfile)

                img = self.get_imagearray()
                self.assertImageHasColor('blue', img)
                self.assertImageHasColor('yellow', img)
                self.assertImageHasColor('green', img)
                self.assertImageHasColor('red', img)
                self.assertImageHasColor('magenta', img)
                self.assertImageHasNotColor('white', img)
Beispiel #56
0
    def test_pse(self):
        self.ambientOnly()

        viewport = (50, 50)
        cmd.viewport(*viewport)

        objname = 'simpletri'
        obj = []
        obj.extend([
            cgo.BEGIN, cgo.TRIANGLES,
            cgo.COLOR, 1.0, 0., 0.,
            cgo.VERTEX, 0.0, 0.0, 1.0,
            cgo.VERTEX, 1.0, 0.0, 0.0,
            cgo.VERTEX, 0.0, 1.0, 0.0,
            cgo.END
            ])
        cmd.load_cgo(obj, objname, 1)

        s = cmd.get_session()
        cmd.set_session(s)

        self.assertEqual([objname], cmd.get_names())
        self.assertImageHasColor('red')
Beispiel #57
0
fullpath = os.path.join(source_directory, phase + '.nc')

# Open NetCDF file for reading.
print "Opening NetCDF trajectory file '%(fullpath)s' for reading..." % vars()
#ncfile = Scientific.IO.NetCDF.NetCDFFile(fullpath, 'r')
ncfile = NetCDF.Dataset(fullpath, 'r')

# DEBUG
print "dimensions:"
print ncfile.dimensions

# Read dimensions.
[niterations,nstates,natoms,ndim] = ncfile.variables['positions'].shape
print "Read %(niterations)d iterations, %(nstates)d states" % vars()

cmd.viewport(640,480)
#niterations = 10 # DEBUG

# Load frames
cmd.set('all_states', 0)
print "Loading frames..."
for iteration in range(niterations):
    # Set coordinates
    print "iteration %8d / %8d" % (iteration, niterations)
    positions = (10.0 * ncfile.variables['positions'][iteration, replica, :, :]).squeeze()
    positions = positions[pdb_mapping,:]
    xyz = positions.tolist()
    xyz_iter = iter(xyz)
    #cmd.load_model(model, 'complex', state=iteration+1)
    #cmd.frame(iteration+1)
    #model = cmd.get_model('complex', state=1)
Beispiel #58
0
from pymol import cmd
import os

if not ('pept' in cmd.get_names()):
   cmd.delete('all')
   util.ray_shadows('heavy')
   cmd.do('load $PYMOL_PATH/test/dat/pept.pdb')
   cmd.do('set surface_quality=1')
   cmd.do('show surface;hide lines;')
   cmd.zoom('all',10)
   cmd.do('clip far,-40;show surface;hide lines;set smooth_color=1')
   cmd.viewport(300,300)
pov = cmd.get_povray()

f=open("tmp_pymol.pov",'w')
f.write(pov[0])
f.write("#include \"colors.inc\"\n");
f.write("#include \"stones.inc\"\n");
f.write("#include \"woods.inc\"\n");
f.write(pov[1])
f.write("plane {<0,1,0.5>, -70 texture{T_Grnt10 scale 40}}\n");
f.write("sphere {<14,4,-132>, 7.0 pigment{color Grey} finish{reflection 1.0 metallic}}\n");
for x in range(-30,30,5):
   f.write("sphere {<%6.4f,-12,-100>, 2.0 texture{P_WoodGrain1B scale 8}}\n"%(x))
f.write("box {<-17,17,-120>,<13,15,-160> pigment {color Red}}\n")
f.close()
cmd.refresh()
os.system("x-povray +Itmp_pymol.pov +Otmp_pymol.png +W300 +H300 +A")
cmd.load_png('tmp_pymol.png')

Beispiel #59
0
def viewport():
   while 1:
      time.sleep(random.random()*5)
      cmd.viewport(640,480)
      time.sleep(random.random()*5)
      cmd.viewport(800,600)