def test_add_write(self): """A modified base should be written to PDB.""" s = ModernaStructure('file', A_RESIDUE) add_modification(s['1'], 'm1A') s.write_pdb_file(OUTPUT) t = ModernaStructure('file', OUTPUT) self.assertEqual(t['1'].long_abbrev, s['1'].long_abbrev)
def test_helix(self): struc = ModernaStructure('file', BROKEN_HELIX_EXAMPLE) resi1 = struc['0Z'] resi2 = struc['1'] bb = BackboneBuilder(resi1, resi2, struc) struc.write_pdb_file('out.pdb') self.assertTrue(bb.is_intact())
def _test_repair_congested(self): """Should avoid clashes between atoms.""" #TODO: reactivate test struc = ModernaStructure('file',BB_MESSED_UP) self.assertFalse(struc['33'].is_phosphate_intact()) bb = BackboneBuilder(struc['32'], struc['33'], struc) struc.write_pdb_file('out.pdb') self.assertTrue(bb.is_intact()) #TODO: criteria are now more strict, therefore test fails. self.assertTrue(struc['32'].is_backbone_intact()) self.assertTrue(struc['33'].is_backbone_intact()) self.assertTrue(struc['33'].is_phosphate_intact()) self.assertFalse(struc['33'].is_backbone_congested()) self.assertFalse(struc['32'].is_backbone_congested())
def create_modification_files(): """ Builds a model for each modification. """ f=open(OUTPUT_PATH+'create_modifications_log','w') for mod_name in get_modifications(): f.write(mod_name+'\n') # modifications_to_add=get_all_modifications_names() s=ModernaStructure('file',NORMAL_BASE) print s try: print s['1'] s['1'].add_modification(mod_name) f.write('created structure for %s'%mod_name) f.write('\n'+'-'*30+'\n') except: f.write('no rule for %s.'%(mod_name)) f.write('\n'+'-'*30+'\n') s.write_pdb_file(OUTPUT_PATH + mod_name+'.pdb')
class WritePDBTests(TestCase): def get_resnames(self, fn, chain='A'): """Returns a list of residue names from a PDB file.""" result = [] struc = PDBParser().get_structure('test_struc', fn) chain = struc[0][chain] for resi in chain.child_list: result.append(resi.resname) return result def setUp(self): self.s = ModernaStructure('file', MINI_TEMPLATE) def test_res_names(self): """Names of written residues should be standard.""" self.s.write_pdb_file(TEST_OUTPUT) rn = self.get_resnames(TEST_OUTPUT) self.assertEqual(rn, [ ' G', ' C', ' G', ' G', ' A', ' U', ' U', ' U', ' A', '2MG', ' C', ' U', ' C', ' A', ' G' ]) def test_res_names_mod(self): """Names of modifications should be standard.""" # I'll check file with amber names manualy. # There are some conflicts and inconsistents. pass def test_res_names_exchanged(self): """Names should be consistent after base exchanges.""" exchange_base(self.s['5'], 'C') self.s.write_pdb_file(TEST_OUTPUT) rn = self.get_resnames(TEST_OUTPUT) self.assertEqual(rn[4], ' C') def test_res_names_add_modif(self): """Names should be consistent after adding modifications.""" add_modification(self.s['5'], 'm7G') self.s.write_pdb_file(TEST_OUTPUT) rn = self.get_resnames(TEST_OUTPUT) self.assertEqual(rn[4], '7MG') def test_res_names_remove_modif(self): """Names should be consistent after adding modifications.""" remove_modification(self.s['10']) self.s.write_pdb_file(TEST_OUTPUT) rn = self.get_resnames(TEST_OUTPUT) self.assertEqual(rn[4], ' A') def test_atom_number(self): pass
def write_hit_structure(self, file_name='LirHit.pdb', with_anchor_residues=False, with_model=False, write_anchors_to_file=True): """ Writes structure of hit to a pdb file. Optioonaly it can write hit with anchor residues or with whole model. Arguments: - with_anchor_residues - True/False (by default False) - with_model - True/False (by default False) """ if not self.fragment_instance: self.get_fragment() if not self.rmsd: self.fragment_instance.superimpose() if write_anchors_to_file: self.write_anchors_to_separate_file(file_name) if with_anchor_residues and not with_model: resis = list(self.fragment_instance.struc) elif not with_anchor_residues and not with_model: #with model or without model and without anchor residues resis = self.fragment_instance.nonanchor_residues if with_model: # get a variable with the class because it cant be imported; looks ugly but works. rm_class = self.query.model_instance.__class__ m = rm_class(None, None, self.query.model_instance.chain_name, 'residues', self.query.model_instance) m.insert_fragment(self.fragment_instance) m.fix_backbone() resis = m.moderna_residues.values( ) # MM: or resi = m.moderna_residues m = ModernaStructure('residues', resis, 'A') m.sort_residues() m.write_pdb_file(file_name)
__credits__ = ["Janusz Bujnicki"] __license__ = "GPL" __version__ = "0.1.0" __maintainer__ = "Magdalena Musielak" __email__ = "*****@*****.**" __status__ = "Prototype" from moderna.ModernaStructure import ModernaResidue, ModernaStructure from moderna.BaseRecognizer import BaseRecognizer NUC_PATH = 'standard_nucleotides/' A_RESIDUE = NUC_PATH + 'a.ent' if __name__ == '__main__': # Loads the A residue to start with. struc = ModernaStructure('file', A_RESIDUE) ade = struc[1] # exchange to G ade.exchange_base('G') assert (BaseRecognizer().identify_resi(ade), 'G') struc.write_pdb_file(NUC_PATH + 'g.ent') # exchange to C ade.exchange_base('C') assert (BaseRecognizer().identify_resi(ade), 'C') struc.write_pdb_file(NUC_PATH + 'c.ent') # exchange to U ade.exchange_base('U') assert (BaseRecognizer().identify_resi(ade), 'U') struc.write_pdb_file(NUC_PATH + 'u.ent')
def test_all(self): """Adding should work for all modifications.""" a = Alphabet() br = BaseRecognizer() not_working = [] errors = [] EXCLUDED = [ 'A', 'G', 'C', 'U', '?A', '?G', '?C', '?U', # exclude unknown 'X', '?X', 'Xm', 'x', 'preQ0base', 'Qbase', 'preQ1base', 'galQtRNA', # indistinguishable from ManQtRNA '-', '_', 'yW-58', 'yW-72', 'yW-86', 'm8A', 'fa7d7G', # new in Modomics 2009, not yet in ModeRNA. 'm7Gpp_cap', # not implemented yet ] SYNONYMS = { 'm42C': 'm44C', 'm42Cm': 'm44Cm', 'm62A': 'm66A', 'm62Am': 'm66Am' } for k in a: if k not in EXCLUDED and a[k].category not in [ 'unknown', 'standard', 'ligand', 'synthetic', 'stereoisomer', 'insertion', 'missing', ' ' ]: struc = ModernaStructure('file', A_RESIDUE) r = struc['1'] try: add_modification(r, k) right = SYNONYMS.get(k, k) if br.identify_resi(r) != right: not_working.append(k + ',' + br.identify_resi(r)) # write file for checking struc.write_pdb_file('dummies/' + k + '.pdb') except ModernaResidueError: raise errors.append(k) if not_working or errors: print '\nTest failed for modifications.' print 'Different base was recognized:' print ', '.join(not_working) print 'ERROR occured:' print ', '.join(errors) self.assertEqual(len(not_working) + len(errors), 0)
def test_read_write_phosphate(self): """extra 2'3' phosphate is recognized and read correctly""" struc = ModernaStructure('file', THREEPRIME_PHOSPHATE, 'B') struc.write_pdb_file('temp.pdb') struc = ModernaStructure('file', 'temp.pdb', 'B') self.assertEqual(struc['190'].long_abbrev, '23pA')