Пример #1
0
    def testSaveRef(self, format):
        # for rms_cur (not all formats save all identifiers)
        m = -1
        cmd.set('retain_order')

        cmd.fragment('ala', 'm1')
        cmd.copy('m2', 'm1')
        cmd.copy('m3', 'm1')

        cmd.rotate('y', 90, 'm2')
        cmd.align('m3', 'm2')

        # with ref=m3
        with testing.mktemp('.' + format) as filename:
            cmd.save(filename, 'm2', ref='m3')
            cmd.load(filename, 'm4')
            self.assertAlmostEqual(cmd.rms_cur('m4', 'm1', matchmaker=m), 0.00, delta=1e-2)
            self.assertAlmostEqual(cmd.rms_cur('m4', 'm2', matchmaker=m), 1.87, delta=1e-2)

        # without ref
        with testing.mktemp('.' + format) as filename:
            cmd.save(filename, 'm2')
            cmd.load(filename, 'm5')
            self.assertAlmostEqual(cmd.rms_cur('m5', 'm2', matchmaker=m), 0.00, delta=1e-2)
            self.assertAlmostEqual(cmd.rms_cur('m5', 'm1', matchmaker=m), 1.87, delta=1e-2)
Пример #2
0
    def testSaveRef(self, format):
        # for rms_cur (not all formats save all identifiers)
        m = -1
        cmd.set('retain_order')

        cmd.fragment('ala', 'm1')
        cmd.copy('m2', 'm1')
        cmd.copy('m3', 'm1')

        cmd.rotate('y', 90, 'm2')
        cmd.align('m3', 'm2')

        # with ref=m3
        with testing.mktemp('.' + format) as filename:
            cmd.save(filename, 'm2', ref='m3')
            cmd.load(filename, 'm4')
            self.assertAlmostEqual(cmd.rms_cur('m4', 'm1', matchmaker=m), 0.00, delta=1e-2)
            self.assertAlmostEqual(cmd.rms_cur('m4', 'm2', matchmaker=m), 1.87, delta=1e-2)

        # without ref
        with testing.mktemp('.' + format) as filename:
            cmd.save(filename, 'm2')
            cmd.load(filename, 'm5')
            self.assertAlmostEqual(cmd.rms_cur('m5', 'm2', matchmaker=m), 0.00, delta=1e-2)
            self.assertAlmostEqual(cmd.rms_cur('m5', 'm1', matchmaker=m), 1.87, delta=1e-2)
Пример #3
0
    def test2638(self):
        cmd.set('retain_order')
        cmd.fragment('ala', 'm1')
        n = cmd.count_atoms()

        ##
        ## Make long identifiers
        ##

        chain = [randhex()] * n
        resn = [randhex()] * n
        resv = [randint(10**4, 10**6 - 1)] * n
        names = [randhex(4) + str(i) for i in range(n)]

        identif_str = '(chain, resn, resv, name)'
        identifiers = list(zip(chain, resn, resv, names))
        afterload = []

        cmd.alter('m1',
                  identif_str + ' = _next()',
                  space={'_next': next_decorator(identifiers)})

        ##
        ## Test if cif in/out preserves identifiers
        ##

        with testing.mktemp('.cif') as filename:
            cmd.save(filename, 'm1')
            cmd.load(filename, 'm2')

        cmd.iterate('m2',
                    '_afterload.append(' + identif_str + ')',
                    space={'_afterload': afterload})

        self.assertEqual(identifiers, afterload)

        ##
        ## Test if various formats preserve coordinates
        ##

        coords = cmd.get_coordset('m1')

        for ext in ['.pdb', '.xyz', '.mol2', '.sdf']:
            cmd.delete('m2')

            with testing.mktemp(ext) as filename:
                cmd.save(filename, 'm1')
                cmd.load(filename, 'm2')

            self.assertArrayEqual(coords,
                                  cmd.get_coordset('m2'),
                                  delta=1e-3,
                                  msg='not preserving coordinates: ' + ext)
Пример #4
0
    def test2638(self):
        cmd.set('retain_order')
        cmd.fragment('ala', 'm1')
        n = cmd.count_atoms()

        ##
        ## Make long identifiers
        ##

        chain = [randhex()] * n
        resn = [randhex()] * n
        resv = [randint(10**4, 10**6 - 1)] * n
        names = [randhex(4) + str(i) for i in range(n)]

        identif_str = '(chain, resn, resv, name)'
        identifiers = list(zip(chain, resn, resv, names))
        afterload = []

        cmd.alter('m1', identif_str + ' = _next()',
                space={'_next': next_decorator(identifiers)})

        ##
        ## Test if cif in/out preserves identifiers
        ##

        with testing.mktemp('.cif') as filename:
            cmd.save(filename, 'm1')
            cmd.load(filename, 'm2')

        cmd.iterate('m2', '_afterload.append(' + identif_str + ')',
                space={'_afterload': afterload})

        self.assertEqual(identifiers, afterload)

        ##
        ## Test if various formats preserve coordinates
        ##

        coords = cmd.get_coordset('m1')

        for ext in ['.pdb', '.xyz', '.mol2', '.sdf']:
            cmd.delete('m2')

            with testing.mktemp(ext) as filename:
                cmd.save(filename, 'm1')
                cmd.load(filename, 'm2')

            self.assertArrayEqual(coords, cmd.get_coordset('m2'), delta=1e-3,
                    msg='not preserving coordinates: ' + ext)
Пример #5
0
    def test(self):
        cmd.set('opaque_background')
        with testing.mktemp('tmp.pse') as session_filename:
            with testing.mktemp('bg.png') as bg_image_filename:
                cmd.bg_color('red')
                cmd.png(bg_image_filename)
                cmd.bg_color('blue')
                cmd.set('bg_image_filename', bg_image_filename)
                cmd.save(session_filename)

            cmd.load(session_filename)
        x = cmd.get('bg_image_filename')
        self.assertTrue(x.startswith('data:'))
        self.assertImageHasColor('red', delta=4,
                msg='bg_image_filename=data: not rendered')
Пример #6
0
    def testMMTF(self):
        '''Styled MMTF export/import'''
        S = 0b10            # 1 << 1 spheres
        D = 0b1000000000    # 1 << 9 dots
        B = 2 # blue
        R = 4 # red

        cmd.fragment('gly')
        cmd.color(B)
        cmd.color(R, 'elem C')
        cmd.show_as('spheres')
        cmd.show_as('dots', 'elem C')

        with testing.mktemp('.mmtf') as filename:
            cmd.save(filename)
            cmd.delete('*')
            cmd.load(filename)

        color_list = []
        reps_list = []

        cmd.iterate('*', 'color_list.append(color)', space=locals())
        cmd.iterate('*', 'reps_list.append(reps)', space=locals())

        self.assertEqual(color_list, [B, R, R, B, B, B, B])
        self.assertEqual(reps_list, [S, D, D, S, S, S, S])
Пример #7
0
 def testMAEsaveLoadSessions(self):
     cmd.load(self.datafile('1d_smiles.mae'), '1d_smiles', object_props='*')
     allpropdata = {}
     objs = cmd.get_object_list()
     for obj in objs:
         props = cmd.get_property_list(obj)
         allpropdata[obj] = {}
         for prop in props:
             allpropdata[obj][prop] = cmd.get_property(prop, obj)
     with testing.mktemp('.pse') as psefilename:
         cmd.save(psefilename)
         cmd.load(psefilename)
     # this is to fail the test on purpose
     #        cmd.set_property('i_m_ct_format', 3, '1d_smiles.mol_13')
     objs = cmd.get_object_list()
     for obj in objs:
         props = cmd.get_property_list(obj)
         # test to make sure there are no extra properties or not enough properties
         self.assertEqual(set(props), set(allpropdata[obj].keys()))
         # test to make sure all property values are the same
         for prop in props:
             try:
                 self.assertTrue(allpropdata[obj][prop] == cmd.get_property(prop, obj))
             except:
                 self.fail('properties are not the same: obj=%s prop=%s' % (obj, prop))
Пример #8
0
 def testPseSupport(self):
     cmd.load_callback(callback.Callback(), 'c1')
     with testing.mktemp('tmp.pse') as session_filename:
         cmd.save(session_filename)
         cmd.delete('*')
         cmd.load(session_filename)
         self.assertTrue('c1' in cmd.get_names())
Пример #9
0
 def testMAEsaveLoadSessions(self):
     cmd.load(self.datafile('1d_smiles.mae'), '1d_smiles', object_props='*')
     allpropdata = {}
     objs = cmd.get_object_list()
     for obj in objs:
         props = cmd.get_property_list(obj)
         allpropdata[obj] = {}
         for prop in props:
             allpropdata[obj][prop] = cmd.get_property(prop, obj)
     with testing.mktemp('.pse') as psefilename:
         cmd.save(psefilename)
         cmd.load(psefilename)
     # this is to fail the test on purpose
     #        cmd.set_property('i_m_ct_format', 3, '1d_smiles.mol_13')
     objs = cmd.get_object_list()
     for obj in objs:
         props = cmd.get_property_list(obj)
         # test to make sure there are no extra properties or not enough properties
         self.assertEqual(set(props), set(allpropdata[obj].keys()))
         # test to make sure all property values are the same
         for prop in props:
             try:
                 self.assertTrue(allpropdata[obj][prop] == cmd.get_property(prop, obj))
             except:
                 self.fail('properties are not the same: obj=%s prop=%s' % (obj, prop))
Пример #10
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)
Пример #11
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)
Пример #12
0
    def testMMTFExportEmpty(self):
        with testing.mktemp('.mmtf') as filename:
            cmd.save(filename)
            cmd.load(filename, 'm1')

        self.assertEqual(cmd.count_atoms(), 0)
        self.assertEqual(cmd.get_names(), ['m1'])
Пример #13
0
    def testMMTFExportEmpty(self):
        with testing.mktemp('.mmtf') as filename:
            cmd.save(filename)
            cmd.load(filename, 'm1')

        self.assertEqual(cmd.count_atoms(), 0)
        self.assertEqual(cmd.get_names(), ['m1'])
Пример #14
0
    def testMMTF(self):
        '''Styled MMTF export/import'''
        S = 0b10            # 1 << 1 spheres
        D = 0b1000000000    # 1 << 9 dots
        B = 2 # blue
        R = 4 # red

        cmd.fragment('gly')
        cmd.color(B)
        cmd.color(R, 'elem C')
        cmd.show_as('spheres')
        cmd.show_as('dots', 'elem C')

        with testing.mktemp('.mmtf') as filename:
            cmd.save(filename)
            cmd.delete('*')
            cmd.load(filename)

        color_list = []
        reps_list = []

        cmd.iterate('*', 'color_list.append(color)', space=locals())
        cmd.iterate('*', 'reps_list.append(reps)', space=locals())

        self.assertEqual(color_list, [B, R, R, B, B, B, B])
        self.assertEqual(reps_list, [S, D, D, S, S, S, S])
Пример #15
0
    def testSaveSelection(self, format, pymol_version):
        if pymol_version > testing.PYMOL_VERSION[1]:
            self.skipTest("version %f" % (pymol_version))

        cmd.fragment('trp', 'm1')
        cmd.fragment('glu', 'm2')

        n_O = cmd.count_atoms('elem O')
        n_N = cmd.count_atoms('elem N')

        with testing.mktemp('.' + format) as filename:
            cmd.set('raise_exceptions',
                    0)  # 1.7.6 save xyz doesn't set r=DEFAULT_SUCCESS
            cmd.save(filename, 'elem O+N')
            cmd.set('raise_exceptions', 1)

            if format == 'mae' and not pymol.invocation.options.incentive_product:
                format = 'cms'

            cmd.delete('*')
            cmd.load(filename, 'm2', discrete=1,
                     format=format)  # avoid merging of atoms

        self.assertEqual(n_O, cmd.count_atoms('elem O'))
        self.assertEqual(n_N, cmd.count_atoms('elem N'))
        self.assertEqual(n_O + n_N, cmd.count_atoms())
Пример #16
0
    def testglTF(self):
        '''glTF export'''
        cmd.fragment('gly')

        with testing.mktemp('.gltf') as filename:
            self.assertEqual(cmd.save(filename), 0)
            cmd.delete('*')
Пример #17
0
    def test(self):
        cmd.set('opaque_background')
        with testing.mktemp('tmp.pse') as session_filename:
            with testing.mktemp('bg.png') as bg_image_filename:
                cmd.bg_color('red')
                cmd.png(bg_image_filename)
                cmd.bg_color('blue')
                cmd.set('bg_image_filename', bg_image_filename)
                cmd.save(session_filename)

            cmd.load(session_filename)
        x = cmd.get('bg_image_filename')
        self.assertTrue(x.startswith('data:'))
        self.assertImageHasColor('red',
                                 delta=4,
                                 msg='bg_image_filename=data: not rendered')
Пример #18
0
    def testExportStyle(self):
        cmd.fab('ACDEF', 'm1')
        cmd.hide()
        cmd.show('cartoon', 'resi 1-3')
        cmd.show('lines', 'resn CYS')
        cmd.show('sticks', 'resn ASP+PHE')
        cmd.show('spheres', 'resn GLU')
        cmd.set('stick_ball', 1, 'resn PHE')
        cmd.set('stick_ball_ratio', 1.5, 'm1')
        testlabel = 'Hello "World"'
        cmd.label('name SG', repr(testlabel))

        with testing.mktemp('.mae') as filename:
            cmd.save(filename)
            cmd.delete('*')
            cmd.load(filename, 'm2')

        g_labels = []
        cmd.iterate('name SG', 'g_labels.append(label)', space=locals())
        cmd.alter('*', 'b = 1 if s.stick_ball else 0')

        self._assertCountEqual('rep cartoon & guide', 'resi 1-3 & guide')
        self._assertCountEqual('rep lines', 'resn CYS', delta=1)
        self._assertCountEqual('rep sticks', 'resn ASP+PHE')
        self._assertCountEqual('rep spheres', 'resn GLU')
        self._assertCountEqual('b > 0.5', 'resn PHE')
        self.assertTrue(cmd.get_setting_float('stick_ball_ratio', 'm2') > 1.1)
        self.assertEqual(g_labels[0], testlabel)
Пример #19
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)
Пример #20
0
 def testLog(self):
     with testing.mktemp('.pml') as logfile:
         cmd.log_open(logfile)
         cmd.do('_ color blue')
         cmd.log('hello world')
         cmd.log_close()
         lines = filter(None, map(str.strip, open(logfile)))
         self.assertEqual(lines, ['color blue', 'hello world'])
Пример #21
0
 def testLog(self):
     with testing.mktemp('.pml') as logfile:
         cmd.log_open(logfile)
         cmd.do('_ color blue')
         cmd.log('hello world')
         cmd.log_close()
         lines = [_f for _f in map(str.strip, open(logfile)) if _f]
         self.assertEqual(lines, ['color blue', 'hello world'])
Пример #22
0
 def testCOLLADA(self):
     cmd.fragment('gly')
     for rep in ['spheres', 'sticks', 'surface']:
         cmd.show_as(rep)
         with testing.mktemp('.dae') as filename:
             cmd.save(filename)
             contents = file_get_contents(filename)
             self.assertTrue('<COLLADA' in contents)
Пример #23
0
 def testVRML(self):
     cmd.fragment('gly')
     for rep in ['spheres', 'sticks', 'surface']:
         cmd.show_as(rep)
         with testing.mktemp('.wrl') as filename:
             cmd.save(filename)
             contents = file_get_contents(filename)
             self.assertTrue(contents.startswith('#VRML V2'))
Пример #24
0
 def testSTL(self):
     cmd.fragment('gly')
     for rep in ['spheres', 'sticks', 'surface']:
         cmd.show_as(rep)
         with testing.mktemp('.stl') as filename:
             cmd.save(filename)
             contents = file_get_contents(filename, 'rb')
             # 80 bytes header
             # 4 bytes (uint32) number of triangles
             self.assertTrue(len(contents) > 84)
Пример #25
0
 def testResume(self):
     with testing.mktemp('.pml') as logfile:
         with open(logfile, 'w') as f:
             print >> f, 'bg yellow'
         cmd.resume(logfile)
         self.assertEqual('yellow', cmd.get('bg_rgb'))
         cmd.log('hello world')
         cmd.log_close()
         lines = filter(None, map(str.strip, open(logfile)))
         self.assertEqual(lines, ['bg yellow', 'hello world'])
Пример #26
0
 def testResume(self):
     with testing.mktemp('.pml') as logfile:
         with open(logfile, 'w') as f:
             print('bg yellow', file=f)
         cmd.resume(logfile)
         self.assertEqual('yellow', cmd.get('bg_rgb'))
         cmd.log('hello world')
         cmd.log_close()
         lines = [_f for _f in map(str.strip, open(logfile)) if _f]
         self.assertEqual(lines, ['bg yellow', 'hello world'])
Пример #27
0
 def testResume(self):
     with testing.mktemp('.pml') as logfile:
         with open(logfile, 'w') as f:
             print('bg yellow', file=f)
         cmd.resume(logfile)
         self.assertEqual('yellow', cmd.get('bg_rgb'))
         cmd.log('hello world')
         cmd.log_close()
         lines = [_f for _f in map(str.strip, open(logfile)) if _f]
         self.assertEqual(lines, ['bg yellow', 'hello world'])
Пример #28
0
 def testPSEBulkExportImport(self, pse_export_version, pse_binary_dump):
     with testing.mktemp('.pse') as filename:
         cmd.load(self.datafile("1oky-frag.pdb"))
         m1 = cmd.get_model()
         cmd.set("pse_export_version", pse_export_version)
         cmd.set("pse_binary_dump", pse_binary_dump)
         cmd.save(filename)
         cmd.reinitialize()
         cmd.load(filename)
         m2 = cmd.get_model()
         self.assertModelsAreSame(m1, m2)
Пример #29
0
    def testMol2FormalChargeAssignment(self):
        cmd.fragment('lys')
        cmd.fragment('lys')

        with testing.mktemp('.mol2') as filename:
            cmd.save(filename, state=0)
            cmd.delete('*')
            cmd.load(filename)

        self.assertEqual(cmd.get_model('name NZ', state=1).atom[0].formal_charge, 1)
        self.assertEqual(cmd.get_model('name NZ', state=2).atom[0].formal_charge, 1)
Пример #30
0
 def testPSEBulkExportImport(self, pse_export_version, pse_binary_dump):
     with testing.mktemp('.pse') as filename:
         cmd.load(self.datafile("1oky-frag.pdb"))
         m1 = cmd.get_model()
         cmd.set("pse_export_version", pse_export_version)
         cmd.set("pse_binary_dump", pse_binary_dump)
         cmd.save(filename)
         cmd.reinitialize()
         cmd.load(filename)
         m2 = cmd.get_model()
         self.assertModelsAreSame(m1, m2)
Пример #31
0
    def testSdfV3000(self):
        cmd.load(self.datafile('1rx1.pdb'))
        with testing.mktemp('.sdf') as filename:
            cmd.save(filename)
            cmd.delete('*')
            cmd.load(filename)
        self.assertEqual(cmd.count_atoms(), 1435)

        # check for capitalized element symbols
        cmd.set('ignore_case', 0)
        self.assertEqual(cmd.count_atoms('elem Ca'), 1)
Пример #32
0
    def testSdfV3000(self):
        cmd.load(self.datafile('1rx1.pdb'))
        with testing.mktemp('.sdf') as filename:
            cmd.save(filename)
            cmd.delete('*')
            cmd.load(filename)
        self.assertEqual(cmd.count_atoms(), 1435)

        # check for capitalized element symbols
        cmd.set('ignore_case', 0)
        self.assertEqual(cmd.count_atoms('elem Ca'), 1)
Пример #33
0
    def testPngExists(self):
        '''
        Save a PNG image with width/height specified and
        check if the file exists.
        '''
        cmd.pseudoatom('m1')
        cmd.show('spheres')

        with testing.mktemp('.png') as filename:
            cmd.png(filename, width=100, height=100, ray=0)
            cmd.draw()
            self.assertTrue(os.path.exists(filename), 'png file not written')
Пример #34
0
 def testSaveAln(self):
     cmd.fab('ACDEFGH', 'm1')
     cmd.fab('ACDFGH', 'm2')
     cmd.align('m1', 'm2', cycles=0, object='aln')
     with testing.mktemp('.aln') as filename:
         cmd.save(filename)
         with open(filename) as handle:
             lines = list(handle)
     self.assertEqual(lines[0].split(), ['CLUSTAL'])
     self.assertEqual(lines[1].split(), [])
     self.assertEqual(lines[2].split(), ['m1', 'ACDEFGH'])
     self.assertEqual(lines[3].split(), ['m2', 'ACD-FGH'])
Пример #35
0
 def testSaveAln(self):
     cmd.fab('ACDEFGH', 'm1')
     cmd.fab('ACDFGH', 'm2')
     cmd.align('m1', 'm2', cycles=0, object='aln')
     with testing.mktemp('.aln') as filename:
         cmd.save(filename)
         with open(filename) as handle:
             lines = list(handle)
     self.assertEqual(lines[0].split(), ['CLUSTAL'])
     self.assertEqual(lines[1].split(), [])
     self.assertEqual(lines[2].split(), ['m1', 'ACDEFGH'])
     self.assertEqual(lines[3].split(), ['m2', 'ACD-FGH'])
Пример #36
0
    def testSaveState(self, format, pymol_version):
        if pymol_version > testing.PYMOL_VERSION[1]:
            self.skipTest("version %f" % (pymol_version))

        # for rms_cur (not all formats save all identifiers)
        m = -1
        cmd.set('retain_order')

        # create a multistate object
        cmd.fragment('ala', 'm1')
        cmd.create('m1', 'm1', 1, 2)
        cmd.create('m1', 'm1', 1, 3)
        cmd.translate([5, 0, 0], 'm1', state=2)
        cmd.translate([0, 5, 0], 'm1', state=3)
        n_states = cmd.count_states('m1')

        with testing.mktemp('.' + format) as filename:
            if format == 'mae' and not pymol.invocation.options.incentive_product:
                format = 'cms'

            # explicit
            for state in range(1, n_states + 1):
                cmd.delete('m2')
                cmd.save(filename, 'm1', state=state)
                cmd.load(filename, 'm2', format=format)
                rms = cmd.rms_cur('m1', 'm2', state, 1, matchmaker=m)
                self.assertAlmostEqual(rms, 0.00, delta=1e-2)

            # current state
            for state in range(1, n_states + 1):
                cmd.frame(state)
                cmd.delete('m2')
                cmd.save(filename, 'm1')
                cmd.load(filename, 'm2', 1, format=format)
                rms = cmd.rms_cur('m1', 'm2', state, 1, matchmaker=m)
                self.assertAlmostEqual(rms, 0.00, delta=1e-2)

            if format in ('mol', 'cms'):
                # no multi support
                return

            # all states
            cmd.delete('m2')
            cmd.save(filename, 'm1', state=0)
            cmd.load(filename, 'm2', 1, discrete=1, multiplex=0)
            self.assertEqual(cmd.count_states('m2'), n_states)
            for state in range(1, n_states + 1):
                rms = cmd.rms_cur('m1',
                                  'm2 and state %d' % state,
                                  state,
                                  state,
                                  matchmaker=m)
                self.assertAlmostEqual(rms, 0.00, delta=1e-2)
Пример #37
0
    def test(self):
        cmd.read_pdbstr(v_pdbstr_anisou, 'm1')

        with testing.mktemp('.mae') as maefilename:
            cmd.save(maefilename, 'm1')
            cmd.delete('*')
            cmd.load(maefilename, 'm1')

        self.assertEqual(cmd.get_pdbstr('m1'), v_pdbstr_anisou)

        cmd.read_pdbstr(v_pdbstr_rotated, 'm2')
        cmd.align('m1', 'm2')

        with testing.mktemp('.mae') as maefilename:
            cmd.save(maefilename, 'm1')
            cmd.delete('*')
            cmd.load(maefilename, 'm1')

        # Attention: Not sure if rotation is numerically stable across
        # platforms. Fuzzy comparison might be needed.
        self.assertEqual(cmd.get_pdbstr('m1'), v_pdbstr_rotated)
Пример #38
0
    def testMol2FormalChargeAssignment(self):
        cmd.fragment('lys')
        cmd.fragment('lys')

        with testing.mktemp('.mol2') as filename:
            cmd.save(filename, state=0)
            cmd.delete('*')
            cmd.load(filename)

        self.assertEqual(
            cmd.get_model('name NZ', state=1).atom[0].formal_charge, 1)
        self.assertEqual(
            cmd.get_model('name NZ', state=2).atom[0].formal_charge, 1)
Пример #39
0
    def testMMTFExportSele(self):
        cmd.fab('ACDE')

        with testing.mktemp('.mmtf') as filename:
            cmd.save(filename, 'resn CYS+ASP')
            cmd.delete('*')
            cmd.load(filename)

        self.assertEqual(cmd.count_atoms(), 23)
        self.assertEqual(cmd.count_atoms('bound_to ASP/CG'), 3)
        self.assertEqual(cmd.get_model('ASP/CG ASP/OD1').bond[0].order, 2)
        self.assertEqual(cmd.get_model('ASP/CG ASP/OD2').bond[0].order, 1)
        self.assertEqual(cmd.get_model('CYS/C ASP/N').bond[0].order, 1)
Пример #40
0
    def testMMTFExportSele(self):
        cmd.fab('ACDE')

        with testing.mktemp('.mmtf') as filename:
            cmd.save(filename, 'resn CYS+ASP')
            cmd.delete('*')
            cmd.load(filename)

        self.assertEqual(cmd.count_atoms(), 23)
        self.assertEqual(cmd.count_atoms('bound_to ASP/CG'), 3)
        self.assertEqual(cmd.get_model('ASP/CG ASP/OD1').bond[0].order, 2)
        self.assertEqual(cmd.get_model('ASP/CG ASP/OD2').bond[0].order, 1)
        self.assertEqual(cmd.get_model('CYS/C ASP/N').bond[0].order, 1)
Пример #41
0
    def testMultisave(self):
        names = ['ala', 'gly', 'his', 'arg']

        for name in names:
            cmd.fragment(name)

        with testing.mktemp('.pdb') as filename:
            cmd.multisave(filename, names[0])                       # new
            cmd.multisave(filename, names[1])                       # new (overwrite)
            cmd.multisave(filename, ' '.join(names[2:]), append=1)  # append
            cmd.delete('*')
            cmd.load(filename)

        self.assertEqual(cmd.get_object_list(), names[1:])
Пример #42
0
    def testMultisave(self):
        names = ['ala', 'gly', 'his', 'arg']

        for name in names:
            cmd.fragment(name)

        with testing.mktemp('.pdb') as filename:
            cmd.multisave(filename, names[0])                       # new
            cmd.multisave(filename, names[1])                       # new (overwrite)
            cmd.multisave(filename, ' '.join(names[2:]), append=1)  # append
            cmd.delete('*')
            cmd.load(filename)

        self.assertEqual(cmd.get_object_list(), names[1:])
Пример #43
0
    def testSaveState(self, format, pymol_version):
        if pymol_version > testing.PYMOL_VERSION[1]:
            self.skipTest("version %f" % (pymol_version))

        # for rms_cur (not all formats save all identifiers)
        m = -1
        cmd.set('retain_order')

        # create a multistate object
        cmd.fragment('ala', 'm1')
        cmd.create('m1', 'm1', 1, 2)
        cmd.create('m1', 'm1', 1, 3)
        cmd.translate([5, 0, 0], 'm1', state=2)
        cmd.translate([0, 5, 0], 'm1', state=3)
        n_states = cmd.count_states('m1')

        with testing.mktemp('.' + format) as filename:
            if format == 'mae' and not pymol.invocation.options.incentive_product:
                format = 'cms'

            # explicit
            for state in range(1, n_states + 1):
                cmd.delete('m2')
                cmd.save(filename, 'm1', state=state)
                cmd.load(filename, 'm2', format=format)
                rms = cmd.rms_cur('m1', 'm2', state, 1, matchmaker=m)
                self.assertAlmostEqual(rms, 0.00, delta=1e-2)

            # current state
            for state in range(1, n_states + 1):
                cmd.frame(state)
                cmd.delete('m2')
                cmd.save(filename, 'm1')
                cmd.load(filename, 'm2', 1, format=format)
                rms = cmd.rms_cur('m1', 'm2', state, 1, matchmaker=m)
                self.assertAlmostEqual(rms, 0.00, delta=1e-2)

            if format in ('mol', 'cms'):
                # no multi support
                return

            # all states
            cmd.delete('m2')
            cmd.save(filename, 'm1', state=0)
            cmd.load(filename, 'm2', 1, discrete=1, multiplex=0)
            self.assertEqual(cmd.count_states('m2'), n_states)
            for state in range(1, n_states + 1):
                rms = cmd.rms_cur('m1', 'm2 and state %d' % state,
                        state, state, matchmaker=m)
                self.assertAlmostEqual(rms, 0.00, delta=1e-2)
Пример #44
0
    def test(self, filename):
        cmd.load(self.datafile(filename), 'map')

        ori = ORIGINS[filename]
        ext = [ori, cpv.add(ori, EDGELENGTHS)]

        self.assertArrayEqual(cmd.get_extent('map'), ext, delta=1e-3)

        with testing.mktemp('.map') as filename:
            cmd.save(filename, 'map')
            cmd.delete('*')
            cmd.load(filename, 'map')

        self.assertArrayEqual(cmd.get_extent('map'), ext, delta=1e-3)
Пример #45
0
 def testSaveAlnNucleic(self):
     cmd.load(self.datafile('1rna.cif'))
     cmd.create('m1', 'chain A and not resi 6-7')
     cmd.create('m2', 'chain B')
     cmd.alter('m1 and resi 1', 'resn = "DT"')  # mimic DNA
     cmd.alter('m2 and resi 20', 'resn = "UNK"')  # mimic nonstd residue
     cmd.align('m1', 'm2', cycles=0, object='aln')
     with testing.mktemp('.aln') as filename:
         cmd.save(filename)
         with open(filename) as handle:
             lines = list(handle)
     self.assertEqual(lines[0].split(), ['CLUSTAL'])
     self.assertEqual(lines[1].split(), [])
     self.assertEqual(lines[2].split(), ['m1', 'TUAUA--UAUAUAA'])
     self.assertEqual(lines[3].split(), ['m2', 'UUAUA?AUAUAUAA'])
Пример #46
0
 def testSaveAlnNucleic(self):
     cmd.load(self.datafile('1rna.cif'))
     cmd.create('m1', 'chain A and not resi 6-7')
     cmd.create('m2', 'chain B')
     cmd.alter('m1 and resi 1', 'resn = "DT"') # mimic DNA
     cmd.alter('m2 and resi 20', 'resn = "UNK"') # mimic nonstd residue
     cmd.align('m1', 'm2', cycles=0, object='aln')
     with testing.mktemp('.aln') as filename:
         cmd.save(filename)
         with open(filename) as handle:
             lines = list(handle)
     self.assertEqual(lines[0].split(), ['CLUSTAL'])
     self.assertEqual(lines[1].split(), [])
     self.assertEqual(lines[2].split(), ['m1', 'TUAUA--UAUAUAA'])
     self.assertEqual(lines[3].split(), ['m2', 'UUAUA?AUAUAUAA'])
Пример #47
0
 def testRun(self, namespace, mod, rw):
     stored.tmp = False
     with testing.mktemp('.py') as filename:
         varname = '_tmp_' + namespace
         with open(filename, 'w') as handle:
             print('from pymol import stored', file=handle)
             if mod:
                 print('stored.tmp = (__name__ == "%s")' % (mod), file=handle)
             else:
                 print('stored.tmp = True', file=handle)
             print(varname + ' = True', file=handle)
         cmd.do('run %s, %s' % (filename, namespace), 0, 0)
         self.assertTrue(stored.tmp)
         if mod:
             self.assertEqual(rw, hasattr(sys.modules[mod], varname))
Пример #48
0
 def testRun(self, namespace, mod, rw):
     stored.tmp = False
     with testing.mktemp('.py') as filename:
         varname = '_tmp_' + namespace
         with open(filename, 'w') as handle:
             print('from pymol import stored', file=handle)
             if mod:
                 print('stored.tmp = (__name__ == "%s")' % (mod),
                       file=handle)
             else:
                 print('stored.tmp = True', file=handle)
             print(varname + ' = True', file=handle)
         cmd.do('run %s, %s' % (filename, namespace), 0, 0)
         self.assertTrue(stored.tmp)
         if mod:
             self.assertEqual(rw, hasattr(sys.modules[mod], varname))
Пример #49
0
    def test_undefined(self):
        cmd.fragment('gly')
        cmd.alter('name C', 'p["s_p_foo"] = "bar"')
        cmd.alter('name N', 'p["r_p_bar"] = 1.234')

        # save/load round-trip
        with testing.mktemp('.mae') as filename:
            cmd.save(filename)
            cmd.delete('*')
            cmd.load(filename, 'm1')

        myprops = {}
        cmd.iterate('all', 'myprops[name] = (p.s_p_foo, p.r_p_bar)', space=locals())

        self.assertEqual(myprops['O'], (None, None))
        self.assertEqual(myprops['C'], ("bar", None))
        self.assertEqual(myprops['N'], (None, 1.234))
Пример #50
0
 def testMAEsaveLoadSessionsWithAtomProperties(self):
     cmd.load(self.datafile('1molecule.mae'), '1molecule', atom_props='*')
     allpropdata = {}
     objs = cmd.get_object_list()
     stored.prop_lookup = {}
     for obj in objs:
         stored.prop_lookup[obj] = {}
         cmd.iterate(obj, "stored.prop_lookup['%s'][index-1] = properties.all" % obj)
     prop_lookup = stored.prop_lookup
     with testing.mktemp('.pse') as psefilename:
         cmd.save(psefilename)
         cmd.load(psefilename)
     stored.prop_lookup = {}
     for obj in objs:
         stored.prop_lookup[obj] = {}
         cmd.iterate(obj, "stored.prop_lookup['%s'][index-1] = properties.all" % obj)
     #test to make sure the properties are exactly the same from the saved session as the loaded session
     self.assertEqual(prop_lookup, stored.prop_lookup)
Пример #51
0
    def testMol2PartialChargeExport(self):
        cmd.fragment('gly')

        charges_pre = []
        cmd.iterate('*', 'charges_pre.append(partial_charge)', space=locals())

        # fragment library has charges, but better check...
        self.assertTrue(sum(abs(c) for c in charges_pre) > 0.0)

        with testing.mktemp('.mol2') as filename:
            cmd.save(filename)
            cmd.delete('*')
            cmd.load(filename)

        charges_post = []
        cmd.iterate('*', 'charges_post.append(partial_charge)', space=locals())

        self.assertArrayEqual(charges_pre, charges_post, delta=1e-2)
Пример #52
0
 def testPngExists(self, sync_in_main_thread, sync_in_thread):
     '''
     Save a PNG image with width/height specified and
     check if the file exists. a valid workaround would
     be to call sync(), but if sync() is called inside the
     thread, then it still doesnt work.  ideally we shouldnt
     need to call sync() at all, the png call should just do
     it
     '''
     cmd.pseudoatom('m1')
     cmd.show('spheres')
     with testing.mktemp('.png') as filename:
         th = threading.Thread(target=self._pngExistsAsync, args=[filename, sync_in_thread])
         th.start()
         th.join()
         if sync_in_main_thread:
             cmd.sync()
         self.assertTrue(os.path.exists(filename), 'png file not written')
Пример #53
0
    def test(self):
        cmd.fragment('gly')

        # atom properties
        cmd.alter('index 2-4', 'p.r_custom_indexhalve = index / 2.0')
        cmd.alter('index 3-5', 'p.neg_index = -index')
        cmd.alter('elem C', 'p["spaced resn name"] = resn + " " + name')

        # object properties
        objprops = [
            ('first', 'Max'),
            ('last', 'Mustermann'),
            ('full name', 'Max Mustermann'),
            ('quoted "name"', 'Max "Mustermann"'),
        ]
        for (key, value) in objprops:
            cmd.set_property(key, value)

        # save/load round-trip
        with testing.mktemp('.mae') as filename:
            cmd.save(filename)
            cmd.delete('*')
            cmd.set('load_object_props_default', '*')
            cmd.set('load_atom_props_default', '*')
            cmd.load(filename, 'm1')

        # type conversions
        cmd.alter('m1', 'p.neg_index = int(p.s_pymol_neg_index or 0)')

        # atom properties
        self.assertEqual(2, cmd.count_atoms('p.neg_index < -3'))
        self.assertEqual(2, cmd.count_atoms('p.r_custom_indexhalve > 1.0'))

        # changed in 2.3.1: undefined (<>) -> None
        resnname = set()
        cmd.iterate('m1', 'resnname.add(p["s_pymol_spaced resn name"] or "")', space=locals())
        self.assertEqual(resnname, set(['GLY C', 'GLY CA', '']))

        # object properties
        for (key, value) in objprops:
            self.assertEqual(cmd.get_property('s_pymol_' + key, 'm1'), value)