Example #1
0
 def setUp(self):
     """
     fragment attached at 5' end of model.
     """
     self.m = RnaModel(data_type='file',data=MINI_TEMPLATE, seq=Sequence("GCGGAUUUALCUCAG"))
     self.s1 = ModernaStructure('file', SMALL_FRAGMENT, seq=Sequence("GCGG"))
     self.s2 = ModernaStructure('file',SMALL_FRAGMENT, seq=Sequence("GCGG"))
 def setUp(self):
     """Initializes class instances used for testing."""
     self.rna = ModernaStructure('file', RNA_TWO_PIECES)
     self.example1 = ModernaStructure('file', AC_BASEPAIR, '0')
     self.example1_dist = ModernaStructure('file', DISTANT_AC_BASEPAIR, '0')
     self.ehz = ModernaStructure('file', RNA_1EHZ, 'A')
     self.hb = HBondCalculator()
Example #3
0
    def get_structure(self, name, chain='A'):
        """Returns a ModernaStructure object from a PDB file."""
        key = (name, chain)
        if self.structures.has_key(key):
            seq = self.sequences[key]
            struc = ModernaStructure('file',
                                     self.path + name,
                                     chain,
                                     seq,
                                     new_atoms=False)
            # KR: the following lines are SLOWER
            #struc = self.structures[key]
            #struc = ModernaStructure('residues', [r for r in struc], seq)
        else:
            seq = self.sequences.get(key, None)
            struc = ModernaStructure('file',
                                     self.path + name,
                                     chain,
                                     seq,
                                     new_atoms=False)
            seq = struc.get_sequence()

            self.structures[key] = struc
            self.sequences[key] = seq
            struc = ModernaStructure('residues',
                                     [r for r in self.structures[key]], seq)
        return struc
 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)
Example #5
0
 def test_fill_doublegap(self):
     """Should insert fragments into correct sites."""
     # prepare model
     t = Template(DOUBLEGAP, 'file', 'A')
     m = RnaModel()
     for r in t:
         m.copy_residue(r)
     # insert first fragment
     struc = ModernaStructure('file', FRAGMENT1)
     f1 = ModernaFragment53(struc, anchor5=m['20'], anchor3=m['24'], \
         new_sequence=Sequence('AUA'), keep=keep_first_last)
     m.insert_fragment(f1)
     resids = [r.identifier for r in m]
     expected_resids1 = [
         '18', '19', '20', '21', '21A', '23', '24', '27', '28', '29', '30',
         '31', '32', '33', '34', '35'
     ]
     self.assertEqual(resids, expected_resids1)
     # insert second fragment
     struc = ModernaStructure('file', FRAGMENT2)
     f2 = ModernaFragment53(struc, anchor5=m['23'], anchor3=m['28'], \
         new_sequence=Sequence('AUUA'), keep=keep_first_last)
     m.insert_fragment(f2)
     resids = [r.identifier for r in m]
     expected_resids2 = [
         '18', '19', '20', '21', '21A', '23', '24', '24A', '24B', '27',
         '28', '29', '30', '31', '32', '33', '34', '35'
     ]
     self.assertEqual(resids, expected_resids2)
 def setUp(self):
     t = ModernaStructure('file', MINI_TEMPLATE)
     self.ga = GeometryAnalyzer(t)
     t = ModernaStructure('file',
                          BAD_TEMPLATE,
                          chain_name='A',
                          seq=t.get_sequence())
     self.bad_ga = GeometryAnalyzer(t)
    def test_clash_recognition_moderna_structure(self):
        """Should find clashes in ModernaStructure object"""
        s = ModernaStructure('file', CLASH)
        self.assertEqual(str(self.cr.find_clashes_in_residues(s)), \
        "[(<Residue 3 G>, <Residue 4 G>)]")

        s = ModernaStructure('file', NOCLASH)
        self.assertFalse(self.cr.find_clashes_in_residues(s))
 def setUp(self):
     """Loads the A residue to start with."""
     self.struc = ModernaStructure('file', A_RESIDUE)
     self.adenosine = self.struc['1']
     struc = ModernaStructure('file', C_RESIDUE, '0')
     self.cytosine = struc['494']
     self.chain = PDBParser().get_structure('test_struc',
                                            MINI_TEMPLATE)[0].child_list[0]
     self.unk = ModernaStructure('file', PDB_UNK)
Example #9
0
 def setUp(self):
     self.s1 = ModernaStructure('file',
                                SMALL_FRAGMENT,
                                seq=Sequence("GCGG"))
     self.s2 = ModernaStructure('file',
                                SMALL_FRAGMENT,
                                seq=Sequence("GCGG"))
     self.s3 = ModernaStructure('file',
                                MINI_TEMPLATE,
                                seq=Sequence("GCGGAUUUALCUCAG"))
Example #10
0
 def setUp(self):
     self.m = RnaModel(data_type='file',
                       data=MINI_TEMPLATE,
                       seq=Sequence("GCGGAUUUALCUCAG"))
     self.s1 = ModernaStructure('file',
                                SMALL_FRAGMENT,
                                seq=Sequence("GCGG"))
     self.s2 = ModernaStructure('file',
                                SMALL_FRAGMENT,
                                seq=Sequence("GCGG"))
 def test_get_modified_resis(self):
     s = ModernaStructure('file', RNA_1EHZ, 'A')
     resis = s.get_modified_residues()
     self.assertEqual(len(resis), 14)
     # water and ions should not be recognized
     s = ModernaStructure('file', RNA_1EHZ, ' ')
     resis = s.get_modified_residues()
     for r in resis:
         print r, s[r]
     self.assertEqual(len(resis), 0)
 def check_example(self, fn):
     ll = open(fn).readlines()
     ll = [l for l in ll if l.startswith('ATOM')]
     chain1 = ll[3][21]
     chain2 = ll[-3][21]
     bp1 = ModernaStructure('file', fn, chain1)
     bp2 = ModernaStructure('file', fn, chain2)
     resi1 = [r for r in bp1][0]
     resi2 = [r for r in bp2][-1]
     hbonds = self.hb.calc_hbond_list(resi1, resi2)
     return hbonds
Example #13
0
 def test_has_clashes(self):
     f1 = ModernaFragment(self.s1)
     clashes = f1.has_clashes(list(self.s2))
     self.assertEqual(len(clashes), 8)
     struc = ModernaStructure('file', FRAGMENT1)
     clashes = f1.has_clashes(list(struc))
     self.assertEqual(len(clashes), 0)
Example #14
0
 def test_validate_resi_list(self):
     m = ModernaStructure('file', MINI_TEMPLATE)
     expected = list(m)
     self.assertEqual(validate_resi_list(m), expected)
     self.assertEqual(validate_resi_list([m['2'], m['3']]), expected[1:3])
     self.assertRaises(ParameterError, validate_resi_list, ['not a residue'])
     self.assertRaises(ParameterError, validate_resi_list, 123)
 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())
Example #16
0
 def test_ligand_removal(self):
     """Should remove RNA ligand from 3FU2 when there is no ribose and phosphate group."""
     st2 = ModernaStructure('file',  PDB_WITH_LIGAND)
     pc2 = PdbController(st2)
     self.assertEqual(st2.get_sequence(), Sequence('AGAGGUUCUAG_._CACCCUCUAUAAAAAACUAA_x_._._._._._._._._._._._._.'))
     pc2.clean_structure()
     self.assertEqual(st2.get_sequence(), Sequence('AGAGGUUCUAG_CACCCUCUAUAAAAAACUAA'))
Example #17
0
 def test_missing_phosphates2(self):
     """Messy residues with missing phosphates are not delted."""
     st2 = ModernaStructure('file',  MISSING_PHOSPHATES2)
     pc = PdbController(st2)
     self.assertEqual(st2.get_sequence(), Sequence('C_C_G_A_C_C_U_U_C_G_G_C_C_A_C_C_U_G'))
     pc.clean_structure()
     self.assertEqual(st2.get_sequence(), Sequence('CCGACCUUCGGCCACC_UG'))
 def test_disconnected(self):
     """Structure example should not be OK"""
     # trna Leu by Marcin Skorupskiego
     struc = ModernaStructure('file',DISCONNECTED)
     self.assertFalse(is_chain_continuous(struc))
     bb = BackboneBuilder(struc['16'], struc['17'], struc)
     self.assertTrue(is_chain_continuous(struc))
 def test_multi(self):
     "Memory should not run full - this test should not terminate!"
     print 'THIS TEST RUNS FOREVER IF OK! - WATCH MEMORY'
     s = ModernaStructure('file', FIRST)
     while 1:
         cr = ClashRecognizer()
         cr.find_clashes_in_residues(s)
Example #20
0
    def force_superimpose(self, old_bp, new_bp):
        """
        Superimposes base pairs if there is no interaction between old_bp and force mode is True
        """
        min_rmsd = 100.0
        pdb_name = ''
        base_pair = None
        path = DATA_PATH+'base_pairs/'

        for pdb in os.listdir(path):
            if new_bp in pdb:
                moved_residues = ModernaStructure('file', path+pdb).moderna_residues
                moved, fixed, to_move = self.create_atoms_lists(moved_residues)
                rmsd = ModernaSuperimposer(fixed, moved, to_move).rmsd
                if rmsd < min_rmsd:
                    pdb_name = pdb      
                    min_rmsd = rmsd
                    base_pair = moved_residues

        log.write_message("The best RMSD ("+str(min_rmsd)+") with structure: "+pdb_name)  
        if min_rmsd <= self.cutoff:
            log.write_message("RMSD <= cutoff (" + str(self.cutoff) + ")")
            self.assign_residue_numbers(base_pair['1'], base_pair['2'])
        else:
            log.write_message("RMSD > cutoff (" + str(self.cutoff) + ") - starting backbone builder")
            self.run_backbone_builder()
Example #21
0
 def test_wc_pairs(self):
     """Should recognize W-C-pairs"""
     m = ModernaStructure('file', RNA_HAIRPIN, 'D')
     self.assertEqual(m['31'].get_bp(m['39']).type, '+/+')
     self.assertEqual(m['39'].get_bp(m['31']).type, '+/+')
     self.assertEqual(m['30'].get_bp(m['40']).type, '+/+')
     self.assertEqual(m['40'].get_bp(m['30']).type, '+/+')
 def test_fccd(self):
     struc = ModernaStructure('file',FCCD_EXAMPLE)
     resi1 = struc['5']
     resi2 = struc['6']
     struc.remove_residue('5A')
     bb = BackboneBuilder(resi1, resi2, struc)
     self.assertTrue(bb.is_intact())
Example #23
0
 def test_add_discontinuous(self):
     """Tries to add a helix to an end."""
     helix = ModernaStructure('file', 'test_data/rna_structures/helix.pdb')
     helix_frag = ModernaFragment3(helix, anchor3=self.m['1'], strict=False)
     self.m.insert_fragment(helix_frag)
     self.assertEqual(self.m.get_sequence(),
                      Sequence('CCGACCUUCGGCC_GGUGGCCGAAGGGCGGAUUUALCUCAG'))
Example #24
0
    def check_disconnected_residues(self):
        """
        Looks for residues that belong to the chain, are not connected to the chain 
        and represents synthetic residues, ligands or stereoisomers.
        """
        temp = []
        st = ModernaStructure('residues',
                              self.standard + self.unidentified_rna)
        all_resi = [x for x in st]
        if len(all_resi) == 1: temp.append(all_resi[0].identifier)
        elif not self.continuous:
            for x in range(len(all_resi) - 1):
                if not are_residues_connected(all_resi[x], all_resi[x + 1]):
                    if len(all_resi) == 2:
                        temp += [y.identifier for y in all_resi]
                    elif x + 1 == len(all_resi) - 1:
                        temp.append(all_resi[x + 1].identifier)
                    elif not are_residues_connected(all_resi[x + 1],
                                                    all_resi[x + 2]):
                        temp.append(all_resi[x + 1].identifier)

        # checking whether disconnected residues are not sandard or modified ones
        for resi in temp:
            if not self.is_typical_category_residue(st[resi]):
                self.disconnected_residues.append(st[resi])
Example #25
0
def create_fragment(pdb_path, anchor5=None, anchor3=None, chain_name='A', sequence=None):
    """*create_fragment(pdb_path, anchor5=None, anchor3=None, chain_name='A', sequence=None)*

To insert small pieces of custom PDB structures into models, fragments can be used. 
This command loads a fragment, and defines one or two connection points, to which 
the fragment will be inserted by superposition. It returns a ModernaFragment object.

To add a ModernaFragment object to a model, the insert_fragment command should be used.
The scenarios for adding either involve superposition of a single residue with the model
on the 5' end of the fragment, or on the 3' end, or both.
   
:Arguments:
    * path to pdb file with the fragment
    * residue to which the 5' end of the fragment will be superimposed
    * residue to which the 3' end of the fragment will be superimposed
    * chain name of the fragment in the file (optional; A by default)
    * sequence that should be modeled onto the fragment upon insertion (optional; the sequence should not include the 1-2 anchor residues, it therefore has to be shorter than the fragment)
    """
    pdb_path = validate_path(pdb_path)
    if anchor5: anchor5 = validate_resi(anchor5)
    if anchor3: anchor3 = validate_resi(anchor3)
    if sequence: sequence = validate_seq(sequence)
    struc = ModernaStructure(data_type='file', data=pdb_path, chain_name=chain_name)
    
    if anchor5 and anchor3:
        fr = ModernaFragment53(struc, anchor5=anchor5, anchor3=anchor3, new_sequence=sequence, strict=False)
    elif anchor5:
        fr = ModernaFragment5(struc, anchor5=anchor5, new_sequence=sequence, strict=False)
    elif anchor3:
        fr = ModernaFragment3(struc, anchor3=anchor3, new_sequence=sequence, strict=False)
    else:
        raise ModernaError("Anchor residues need to be specified.")
    return fr
Example #26
0
 def test_phosphate_detection_and_removal(self):
     """Should detect pfosphate group (P, OP1, OP2, O5') in 3FU2 (resi 12) and remove it."""
     st5 = ModernaStructure('file', PDB_WITH_PHOSPHATE)
     pc5 = PdbController(st5)
     self.assertEqual(len(pc5.phosphate), 1)
     pc5.clean_structure()
     self.assertEqual(len(pc5.phosphate), 0)
 def test_build(self):
     struc = ModernaStructure('file',FIXABLE_BACKBONE)
     resi1 = struc['4']
     resi2 = struc['5']
     bb = BackboneBuilder(resi1, resi2, struc)
     #struc.write_pdb_file('out.pdb')
     self.assertTrue(bb.is_intact())
Example #28
0
    def merge_region(self):
        """Merges the optimized residues with the memorized ones."""
        residues = [r for r in self.model]
        if self.model_passive:
            # apply old residue numbers
            print '\nRestoring original numeration in the optimized region.'
            for num, resi in zip(self.model_resnumbers, residues):
                #print resi, num
                #self.model.renumber_residue(resi.identifier, num)
                resi.change_number(num)
            self.model = ModernaStructure('residues',residues)
            # do the superposition
            print '\nSuperimposing the optimized part onto the rest of the model.'
            all_atoms = self.model.get_all_atoms()
            sup = ModernaSuperimposer(moved_atoms = all_atoms)
            sup.get_atoms([self.stem5, self.stem3], BACKBONE_ATOMS, 'fixed')
            resi5, resi3 = self.model[self.residues[0]], self.model[self.residues[1]]
            sup.get_atoms([resi5, resi3], BACKBONE_ATOMS, 'moved')
            sup.superimpose()

            # merge residues
            print '\nMerging the optimized part with the rest of the model.'
            resi = [r for r in self.model]
            for r in self.model_passive:
                if r.identifier not in self.residues:
                    resi.append(r)
            self.model = RnaModel(None, None, self.options.chain_name, 'residues', resi)
Example #29
0
 def test_double_coordinates_identification(self):
     """Should remove RNA ligand when there is no ribose and phosphate group."""
     st3 = ModernaStructure('file', PDB_WITH_DOUBLE_COORDINATES)
     pc3 = PdbController(st3)
     self.assertEqual(len(pc3.disordered), 3)
     pc3.clean_structure()
     self.assertEqual(len(pc3.disordered), 3)
 def setUp(self):
     """Loads the A residue to start with."""
     self.struc = ModernaStructure('file', MINI_TEMPLATE)
     self.resi1 = self.struc['3']
     self.resi2 = self.struc['4']
     # delete the atoms that should be re-built.
     self.resi2.detach_child("O5'")
     self.resi2.detach_child("P")