def testGetSettingFloat(self): for v_ref in (0.0, 1.0): # bool as float cmd.set('orthoscopic', v_ref) v = cmd.get_setting_float('orthoscopic') self.assertTrue(isinstance(v, float)) self.assertEqual(v, v_ref) # float with 6 significant digits cmd.set('sphere_scale', 1.234565) v = cmd.get_setting_float('sphere_scale') self.assertEqual(int(v * 1e5), 123456)
def testStereo(self): for (k, v) in cmd.stereo_dict.items(): if v < 1: continue cmd.stereo(k) self.assertTrue(cmd.get_setting_int('stereo')) self.assertEqual(cmd.get_setting_int('stereo_mode'), v) cmd.stereo('off') self.assertFalse(cmd.get_setting_int('stereo')) cmd.stereo('on') self.assertTrue(cmd.get_setting_int('stereo')) shift = cmd.get_setting_float('stereo_shift') cmd.stereo('swap') self.assertAlmostEqual(cmd.get_setting_float('stereo_shift'), -shift)
def testStereo(self): for (k,v) in cmd.stereo_dict.items(): if v < 1: continue cmd.stereo(k) self.assertTrue(cmd.get_setting_int('stereo')) self.assertEqual(cmd.get_setting_int('stereo_mode'), v) cmd.stereo('off') self.assertFalse(cmd.get_setting_int('stereo')) cmd.stereo('on') self.assertTrue(cmd.get_setting_int('stereo')) shift = cmd.get_setting_float('stereo_shift') cmd.stereo('swap') self.assertAlmostEqual(cmd.get_setting_float('stereo_shift'), -shift)
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)
def get_sasa_mmtk(selection, state=-1, hydrogens='auto', quiet=1): ''' DESCRIPTION Get solvent accesible surface area using MMTK.MolecularSurface http://dirac.cnrs-orleans.fr/MMTK/ This command is very picky with missing atoms and wrong atom naming. SEE ALSO stub2ala, get_sasa, get_sasa_ball ''' try: import MMTK except ImportError: print(' ImportError: please install MMTK') raise CmdException from MMTK.PDB import PDBConfiguration from MMTK.Proteins import Protein from MMTK.MolecularSurface import surfaceAndVolume try: from cStringIO import StringIO except ImportError: from io import StringIO selection = selector.process(selection) state, quiet = int(state), int(quiet) radius = cmd.get_setting_float('solvent_radius') if hydrogens == 'auto': if cmd.count_atoms('(%s) and hydro' % selection) > 0: hydrogens = 'all' else: hydrogens = 'no_hydrogens' elif hydrogens == 'none': hydrogens = 'no_hydrogens' conf = PDBConfiguration(StringIO(cmd.get_pdbstr(selection))) system = Protein(conf.createPeptideChains(hydrogens)) try: area, volume = surfaceAndVolume(system, radius * 0.1) except: print(' Error: MMTK.MolecularSurface.surfaceAndVolume failed') raise CmdException if not quiet: print(' get_sasa_mmtk: %.3f Angstroms^2 (volume: %.3f Angstroms^3).' % (area * 1e2, volume * 1e3)) return area * 1e2
def get_sasa_ball(selection, state=-1, quiet=1): ''' DESCRIPTION Get solvent accesible surface area using BALL.NumericalSAS http://www.ball-project.org/ ''' try: import BALL except ImportError: print(' ImportError: please install BALL python bindings') raise CmdException import tempfile, os state, quiet = int(state), int(quiet) radius = cmd.get_setting_float('solvent_radius') filename = tempfile.mktemp('.pdb') cmd.save(filename, selection, state, 'pdb') system = BALL.System() BALL.PDBFile(filename) >> system os.remove(filename) fragment_db = BALL.FragmentDB('') system.apply(fragment_db.normalize_names) system.apply(BALL.AssignRadiusProcessor('radii/PARSE.siz')) sas = BALL.NumericalSAS() sas_options = BALL.Options() sas_options.setBool(sas.Option.COMPUTE_AREA, True) sas_options.setBool(sas.Option.COMPUTE_SURFACE, False) sas_options.setReal(sas.Option.PROBE_RADIUS, radius) sas.setOptions(sas_options) sas(system) area = sas.getTotalArea() if not quiet: print(' get_sasa_ball: %.3f Angstroms^2.' % (area)) return area
def testGetSettingFloatExact(self): # PyMOL 2.4 uses pymol::pretty_f2d which rounds 7 significant digits for v_ref in (1.234567, 1234567.e6, 9999999.0): cmd.set('sphere_scale', v_ref) v = cmd.get_setting_float('sphere_scale') self.assertEqual(v, v_ref)