def asa_xtra(entities, mode='internal', xtra_key=None, **asa_kwargs): """Calculates accessible surface areas (ASA) and puts the results into the xtra dictionaries of entities. Arguments: - entities: an entity or sequence of entities - mode(str): 'internal' for calculations using the built-in cython code or 'stride' if the stride binary should be called to do the job. - xtra_key(str): Key in the xtra dictionary to hold the result for each entity Additional keyworded arguments are passed to the ``_prepare_asa`` and ``_run_asa`` functions. """ xtra_key = xtra_key or 'ASA' structures = einput(entities, 'S') if len(structures.values()) > 1: raise ValueError( 'Entities from multiple structures are not supported.') if mode == 'internal': _prepare_entities(entities) # mask waters result = _prepare_asa(entities, **asa_kwargs) # calculate ASA _postpare_entities(entities) # unmask waters result = dict([(id, {xtra_key: v}) for id, v in result.iteritems()]) xtradata(result, structures) elif mode == 'stride': models = einput(entities, 'M') stride_app = Stride() result = stride_app(entities)['StdOut'].readlines() result = stride_parser(result) xtradata(result, structures.values()[0][(0, )]) else: raise ValueError('Not a valid mode: "%s"' % mode) return result
def test_stdout_input_from_path(self): """Test Stride when input is an entity""" s = Stride(InputHandler='_input_as_path') res = s(self.input_file) self.assertEqual(res['ExitStatus'], 0) assert res['StdOut'] is not None self.assertTrue(res['StdOut'].readline().endswith('--------- 2E12\n')) self.assertEqual(len(res['StdOut'].readlines()), 267) res.cleanUp()
def test_get_result_path(self): """Tests stride result path""" s = Stride() fd, name = tempfile.mkstemp() os.close(fd) s.Parameters['-f'].on(name) res = s(self.input_structure) self.assertEqual(res['ExitStatus'], 0) self.assertEqualItems(res.keys(), ['StdOut', 'StdErr', 'ExitStatus', 'File']) self.assertTrue(res['File'].readline().endswith('--------- 2E12\n')) self.assertEquals(len(res['File'].readlines()), 267) res.cleanUp() self.assertFalse(os.path.exists(name))
def setUp(self): input_file = os.path.join('data', '2E12.pdb') self.input_structure = PDBParser(open(input_file)) stride_app = Stride() res = stride_app(self.input_structure) self.lines = res['StdOut'].readlines()