class ResiduesTest(ut.TestCase): def setUp(self): self.structure = Structure([nts.nt77_9, nts.nt78_9, nts.nt79_9, nts.nt80_9], pdb="1S72") def test_can_get_sequence_from_all_residues(self): self.assertEquals(['A', 'G', 'U', 'A'], self.structure.sequence) def test_can_iterate_over_all_residues(self): val = list(self.structure.residues()) self.assertEquals([nts.nt77_9, nts.nt78_9, nts.nt79_9, nts.nt80_9], val) def test_can_select_residues(self): val = list(self.structure.residues(sequence='A')) self.assertEquals([nts.nt77_9, nts.nt80_9], val) def test_skip_iterating_over_nonpolymeric_by_default(self): self.structure._residues.append(nts.nt212_0) val = list(self.structure.residues()) self.assertEquals([nts.nt77_9, nts.nt78_9, nts.nt79_9, nts.nt80_9], val) def test_giving_polymeric_is_none_iterates_overall(self): self.structure._residues.append(nts.nt212_0) val = list(self.structure.residues(polymeric=None)) ans = [nts.nt77_9, nts.nt78_9, nts.nt79_9, nts.nt80_9, nts.nt212_0] self.assertEquals(ans, val)
def setUp(self): self.nt1 = Component(atoms=[ Atom(x=0, y=0, z=1, name='C1'), Atom(x=0, y=0, z=0, name='C2'), Atom(x=1, y=0, z=1, name='N'), ], sequence='A', model=1, chain='A', number=1, polymeric=True) self.nt2 = Component(atoms=[ Atom(x=5, y=5, z=5, name='C1'), Atom(x=5, y=5, z=5, name='C2'), Atom(x=5, y=5, z=5, name='N'), ], sequence='U', model=1, chain='A', number=2, polymeric=True) self.nt3 = Component(atoms=[ Atom(x=-5, y=-5, z=-5, name='C1'), Atom(x=-5, y=-5, z=-5, name='C2'), Atom(x=-5, y=-5, z=-5, name='N'), ], sequence='C', model=1, chain='A', number=3, polymeric=True) self.nt4 = Component(atoms=[ Atom(x=0, y=0, z=3, name='C1'), Atom(x=0, y=0, z=3, name='C2'), Atom(x=0, y=0, z=3, name='N'), ], sequence='U', model=1, chain='A', number=4, polymeric=True) self.nt5 = Component(atoms=[ Atom(x=0, y=0, z=8, name='C1'), Atom(x=0, y=0, z=8, name='C2'), Atom(x=0, y=0, z=3, name='N'), ], sequence='G', model=1, chain='A', number=5, polymeric=True) structure = Structure([self.nt1, self.nt2, self.nt3, self.nt4, self.nt5], pdb='0000', model='1') self.pairs = Pairs(structure)
def structure(self): """Get the structure from the Cif file. :returns: The first structure in the cif file. """ pdb = self.data.getName() residues = self.__residues__(pdb) return Structure(list(residues), pdb=pdb)
class FindingAResidueTest(ut.TestCase): def setUp(self): self.structure = Structure([nts.nt77_9, nts.nt78_9, nts.nt79_9, nts.nt80_9], pdb="1S72") def test_can_find_residue_by_unit_id(self): val = self.structure.residue('1S72||9|U|79') self.assertEquals(nts.nt79_9, val) def test_can_find_residue_by_index(self): val = self.structure.residue(1) self.assertEquals(nts.nt78_9, val) def test_can_find_residues_by_negative_index(self): val = self.structure.residue(-1) self.assertEquals(nts.nt80_9, val) def test_can_find_by_unit_id_residue_even_when_unordered(self): shuffle(self.structure._residues) val = self.structure.residue('1S72||9|U|79') self.assertEquals(nts.nt79_9, val) def test_raises_exception_if_missing_unit_id(self): self.assertRaises(IndexError, lambda: self.structure.residue('bob')) def test_raises_exception_if_missing_index(self): self.assertRaises(IndexError, lambda: self.structure.residue(1000000))
def coordinates(self, pdb, residue): """Compute a string of the coordinates in CIF format (the atom_site block) for the given residue. Exclude the header and trailing lines that are part of the atom_site entries, because these entries are meant to be concatenated together for the coordinate server later. Parameters ---------- pdb : str The PDB id to use. residue : fr3d.data.Component The residue to convert. Returns ------- coordinates : str A string that represents CIF-formatted data for the given residue. """ structure = Structure([residue], pdb=pdb) sio = StringIO() writer = CifAtom(sio, unit_ids=False, protect_lists_of_lists=True) writer(structure) raw = sio.getvalue() coords = [] for line in raw.split('\n'): # Exclude header/comment lines that start with: 1) "data_", # 2) "loop_", 3) "_", or 4) "#". if not line or \ line.startswith('data_') or \ line.startswith('loop_') or \ line[0] in set('_#'): continue coords.append(line) return '\n'.join(coords)
def test_empty_structure_is_false(self): val = Structure([]) self.assertFalse(bool(val))
def setUp(self): self.structure = Structure([nts.nt77_9, nts.nt78_9, nts.nt79_9, nts.nt80_9], pdb="1S72")
def test_selecting_a_subset_updates_unit_id(self): val = Structure([], pdb='1S72').select(model=1).unit_id() self.assertEquals('1S72|1', val)
def test_has_a_unit_id(self): val = Structure([], pdb='1S72').unit_id() self.assertEquals('1S72', val)
def test_no_residues_is_0_length(self): val = Structure([]) self.assertEquals(0, len(val))
def test_length_is_number_of_residues(self): val = Structure([1]) self.assertEquals(1, len(val))
def test_non_empty_structure_is_true(self): val = Structure([1]) self.assertTrue(bool(val))