def test_xtradata(self): """tests if an full_id's in the data dict are correctly parsed.""" structure = einput(self.input_structure, 'S')[('2E12',)] model = einput(self.input_structure, 'M')[('2E12', 0)] chain = einput(self.input_structure, 'C')[('2E12', 0, 'B')] residue = einput(self.input_structure, 'R')[('2E12', 0, 'B', ('LEU', 24, ' '))] atom = einput(self.input_structure, 'A')[('2E12', 0, 'B', ('LEU', 24, ' '), ('CD1', ' '))] data_model = {(None, 0):{'model':1}} xtradata(data_model, structure) self.assertEquals(model.xtra, {'model': 1}) data_chain = {(None, None, 'B'):{'chain':1}} xtradata(data_chain, model) self.assertEquals(chain.xtra, {'chain': 1}) data_chain = {(None, 0, 'B'):{'chain': 2}} xtradata(data_chain, structure) self.assertEquals(chain.xtra['chain'], 2) data_residue = {(None, None, 'B', ('LEU', 24, ' ')):{'residue':1}} xtradata(data_residue, model) self.assertEquals(residue.xtra, {'residue': 1}) data_residue = {(None, 0, 'B', ('LEU', 24, ' ')):{'residue':2}} xtradata(data_residue, structure) self.assertEquals(residue.xtra, {'residue': 2})
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 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 stride_xtra(entities, **kwargs): """Runs the stride application and maps the result on the residue xtra dictionaries. """ structures = einput(entities, 'S') if len(structures.values()) > 1: raise ValueError('Entities from multiple structures are not supported.') stride_app = Stride(**kwargs) result = stride_app(entities)['StdOut'].readlines() result = stride_parser(result) xtradata(result, structures.values()[0][(0,)]) return result
def contacts_xtra(query, xtra_key=None, **cnt_kwargs): """Finds distance contacts between entities. This function searches for contacts for query entities (query) either within the asymmetric unit, biological molecule, unit-cell or crystal. Arguments: - query (entitie[s]): query entity or sequence entities - xtra_key (str): name of the key Additional keyworded arguments are passed to the ``_prepare_contacts`` functon. """ xtra_key = xtra_key or 'CONTACTS' structures = einput(query, 'S') if len(structures.values()) > 1: raise ValueError('Entities from multiple structures are not supported.') result = _prepare_contacts(query, **cnt_kwargs) # calculate CONTACTS result = dict([(id, {xtra_key:v}) for id, v in result.iteritems()]) xtradata(result, structures) return result
def contacts_xtra(query, xtra_key=None, **cnt_kwargs): """Finds distance contacts between entities. This function searches for contacts for query entities (query) either within the asymmetric unit, biological molecule, unit-cell or crystal. Arguments: - query (entitie[s]): query entity or sequence entities - xtra_key (str): name of the key Additional keyworded arguments are passed to the ``_prepare_contacts`` functon. """ xtra_key = xtra_key or 'CONTACTS' structures = einput(query, 'S') if len(list(structures.values())) > 1: raise ValueError('Entities from multiple structures are not supported.') result = _prepare_contacts(query, **cnt_kwargs) # calculate CONTACTS result = dict([(id, {xtra_key:v}) for id, v in result.items()]) xtradata(result, structures) return result