def test__to_dict_2(self): contact = Contact(1, 2, 1.0) contact.define_match() contact.lower_bound = 4 answer_dict = { 'id': (1, 2), 'is_match': True, 'is_mismatch': False, 'is_unknown': False, 'distance_bound': (4.0, 8.0), 'lower_bound': 4.0, 'upper_bound': 8.0, 'raw_score': 1.0, 'res1': 'X', 'res2': 'X', 'res1_chain': '', 'res2_chain': '', 'res1_seq': 1, 'res2_seq': 2, 'res1_altseq': 0, 'res2_altseq': 0, 'scalar_score': 0.0, 'status': 1, 'weight': 1.0, } contact_dict = contact._to_dict() for k in answer_dict.keys(): self.assertEqual(answer_dict[k], contact_dict[k], "Key %s differs" % k)
def test_is_match_1(self): contact = Contact(1, 2, 1.0) contact.define_match() self.assertTrue(contact.is_match) self.assertFalse(contact.is_mismatch) self.assertFalse(contact.is_unknown)
def test_status_1(self): contact = Contact(1, 2000000, 1.0) self.assertEqual(ContactMatchState.unknown.value, contact.status) contact.define_match() self.assertEqual(ContactMatchState.matched.value, contact.status)
def _read(self, structure, f_id, distance_cutoff, atom_type): """Read a contact file Parameters ---------- structure A :obj:`Structure <Bio.PDB.Structure.Structure>` instance f_id : str Unique contact file identifier distance_cutoff : int Distance cutoff for which to determine contacts atom_type : str Atom type between which distances are calculated Returns ------- :obj:`ContactFile <conkit.core.contactfile.ContactFile>` """ hierarchies = [] for model in structure: hierarchy = ContactFile(f_id + '_' + str(model.id)) chains = list(chain for chain in model) for chain in chains: self._remove_hetatm(chain) self._remove_atom(chain, atom_type) for chain1, chain2 in itertools.product(chains, chains): if chain1.id == chain2.id: # intra contact_map = ContactMap(chain1.id) else: # inter contact_map = ContactMap(chain1.id + chain2.id) for (atom1, atom2, distance) in self._chain_contacts(chain1, chain2): contact = Contact( atom1.resseq, atom2.resseq, round(1.0 - (distance / 100), 6), distance_bound=(0., float(distance_cutoff))) contact.res1_altseq = atom1.resseq_alt contact.res2_altseq = atom2.resseq_alt contact.res1 = atom1.resname contact.res2 = atom2.resname contact.res1_chain = atom1.reschain contact.res2_chain = atom2.reschain if distance_cutoff == 0 or distance < distance_cutoff: contact.define_match() contact_map.add(contact) if contact_map.empty: del contact_map else: if len(contact_map.id) == 1: contact_map.sequence = self._build_sequence(chain1) assert len(contact_map.sequence.seq) == len(chain1) else: contact_map.sequence = self._build_sequence(chain1) \ + self._build_sequence(chain2) assert len(contact_map.sequence.seq) \ == len(chain1) + len(chain2) hierarchy.add(contact_map) hierarchy.method = 'Contact map extracted from PDB ' + str(model.id) hierarchy.remark = [ 'The model id is the chain identifier, i.e XY equates to chain X and chain Y.', 'Residue numbers in column 1 are chain X, and numbers in column 2 are chain Y.' ] hierarchies.append(hierarchy) if len(hierarchies) > 1: msg = "Super-level to contact file not yet implemented. " \ "Parser returns hierarchy for top model only!" warnings.warn(msg, FutureWarning) return hierarchies[0]