Esempio n. 1
0
    def align_sequences(self):
        aout, bout = self.align()
        list1 = []
        list2 = []

        for ind in range(len(aout)):
            if aout[ind] != '-' and bout[ind] != '-':
                aout[ind].vtk_arg_list['trace']['color'] = [1.0, 1.0, 1.0]
                bout[ind].vtk_arg_list['trace']['color'] = [1.0, 1.0, 1.0]
                list1.append(aout[ind].central_atom)
                list2.append(bout[ind].central_atom)
        ps = [self.target.atoms, self.template.atoms]
        tm, rm = Superimpose._fit_pair_atoms([list1, list2])
        Superimpose._transform(tm, rm, self.template.atoms)
        self.template.parent.save_pdb('target.pdb')
        self.target.parent.save_pdb('template.pdb')
        rms = Superimpose._get_atoms_rms([list1, list2])
        print 'initial rms = %s over %s atoms' % (rms, len(list1))

        target_central_atoms = copy.deepcopy(list1)
        template_central_atoms = copy.deepcopy(list2)
        new_target_atoms = []
        new_template_atoms = []
        for i in range(len(target_central_atoms)):
            #print '%s %s %s'%(target_central_atoms[i].dist(template_central_atoms[i]), target_central_atoms[i].res_type, template_central_atoms[i].res_type)
            if target_central_atoms[i].dist(template_central_atoms[i]) < 8.0:
                for atom in [list1[i], list2[i]]:
                    atom.parent.vtk_arg_list['trace']['color'] = [
                        1.0, 1.0, 0.0
                    ]
                    atom.vtk_arg_list['atoms']['color'] = [1.0, 1.0, 0.0]
                new_target_atoms.append(target_central_atoms[i])
                new_template_atoms.append(template_central_atoms[i])

        if len(new_target_atoms) > 5:
            tm, rm = Superimpose._fit_pair_atoms(
                [new_target_atoms, new_template_atoms])
            Superimpose._transform(tm, rm, self.template.atoms)
            self.template.parent.save_pdb('target.pdb')
            self.target.parent.save_pdb('template.pdb')
            rms = Superimpose._fit_atoms_rms(
                [new_target_atoms, new_template_atoms])
            print 'new rms = %s over %s atoms' % (rms, len(new_target_atoms))
        else:
            print 'fewer than 5 atoms fit good in second fit'

        identical_pairs = 0
        total_pairs = 0
        for ind in range(len(aout)):
            if aout[ind] != '-' and bout[ind] != '-':
                if aout[ind].res_type1 == bout[ind].res_type1:
                    identical_pairs += 1
            total_pairs += 1
        return (identical_pairs + 0.0) / total_pairs
    def align_sequences(self):
        aout, bout = self.align()
        list1 = []
        list2 = []
        
        for ind in range(len(aout)):
            if aout[ind] != '-' and bout[ind] != '-':
                aout[ind].vtk_arg_list['trace']['color'] = [1.0,1.0,1.0]
                bout[ind].vtk_arg_list['trace']['color'] = [1.0,1.0,1.0]
                list1.append(aout[ind].central_atom)
                list2.append(bout[ind].central_atom)
        ps = [self.target.atoms, self.template.atoms]
        tm, rm = Superimpose._fit_pair_atoms([list1,list2])
        Superimpose._transform(tm, rm, self.template.atoms)
        self.template.parent.save_pdb('target.pdb')
        self.target.parent.save_pdb('template.pdb')
        rms = Superimpose._get_atoms_rms([list1, list2])
        print 'initial rms = %s over %s atoms'%(rms, len(list1))
        
        target_central_atoms   = copy.deepcopy(list1)
        template_central_atoms = copy.deepcopy(list2)
        new_target_atoms       = []
        new_template_atoms     = []
        for i in range(len(target_central_atoms)):
            #print '%s %s %s'%(target_central_atoms[i].dist(template_central_atoms[i]), target_central_atoms[i].res_type, template_central_atoms[i].res_type)
            if target_central_atoms[i].dist(template_central_atoms[i]) < 8.0:
                for atom in [list1[i], list2[i]]:
                    atom.parent.vtk_arg_list['trace']['color'] = [1.0,1.0,0.0]
                    atom.vtk_arg_list['atoms']['color'] = [1.0,1.0,0.0]
                new_target_atoms.append(target_central_atoms[i])
                new_template_atoms.append(template_central_atoms[i])
        
        if len(new_target_atoms) > 5:
            tm, rm = Superimpose._fit_pair_atoms([new_target_atoms,new_template_atoms])
            Superimpose._transform(tm, rm, self.template.atoms)
            self.template.parent.save_pdb('target.pdb')
            self.target.parent.save_pdb('template.pdb')
            rms = Superimpose._fit_atoms_rms([new_target_atoms, new_template_atoms])
            print 'new rms = %s over %s atoms'%(rms, len(new_target_atoms))
        else:
            print 'fewer than 5 atoms fit good in second fit'


        
        identical_pairs = 0
        total_pairs     = 0
        for ind in range(len(aout)):
            if aout[ind] != '-' and bout[ind] != '-':
                if aout[ind].res_type1 == bout[ind].res_type1:
                    identical_pairs += 1
            total_pairs += 1
        return (identical_pairs + 0.0)/total_pairs
Esempio n. 3
0
    def align_structures(self):
        aout, bout = self.align()
        list1 = []
        list2 = []
        for ind in range(len(aout)):
            if aout[ind] != '-' and bout[ind] != '-':
                aout[ind].vtk_arg_list['trace']['color'] = [1.0, 1.0, 1.0]
                bout[ind].vtk_arg_list['trace']['color'] = [1.0, 1.0, 1.0]
                list1.append(aout[ind].central_atom)
                list2.append(bout[ind].central_atom)
        ps = [self.target.atoms, self.template.atoms]
        tm, rm = Superimpose._fit_pair_atoms([list1, list2])
        scores = 0.0
        cntr = 0
        for i in range(len(aout)):
            if aout[i] != '-' and bout[i] != '-':
                scores += self.score_by_key(aout[i].res_number,
                                            bout[i].res_number,
                                            [0.0, 0.11, 0.91, 0.0])
                cntr += 1
        print 'avg score %s' % (scores / cntr)
        Superimpose._transform(tm, rm, self.template.atoms)
        rms = Superimpose._get_atoms_rms([list1, list2])
        print 'initial rms = %s over %s atoms' % (rms, len(list1))

        for max_dist_for_pairing in [5.0, 4.0, 3.0]:
            target_central_atoms = copy.deepcopy(list1)
            template_central_atoms = copy.deepcopy(list2)
            new_target_atoms = []
            new_template_atoms = []
            for i in range(len(target_central_atoms)):
                #print '%s %s %s'%(target_central_atoms[i].dist(template_central_atoms[i]), target_central_atoms[i].res_type, template_central_atoms[i].res_type)
                if target_central_atoms[i].dist(
                        template_central_atoms[i]) < max_dist_for_pairing:
                    new_target_atoms.append(target_central_atoms[i])
                    new_template_atoms.append(template_central_atoms[i])
            if len(new_target_atoms) > 5:
                tm, rm = Superimpose._fit_pair_atoms(
                    [new_target_atoms, new_template_atoms])
                Superimpose._transform(tm, rm, self.template.atoms)
                rms = Superimpose._fit_atoms_rms(
                    [new_target_atoms, new_template_atoms])
                print 'new rms = %s over %s atom pairs < %s distance' % (
                    rms, len(new_target_atoms), max_dist_for_pairing)
            else:
                print 'fewer than 5 atoms fit good in fit'

        for res in self.target.residues:
            res.central_atom.vtk_arg_list['atoms']['color'] = [0.0, 0.0, 1.0]
        for res in self.template.residues:
            res.central_atom.vtk_arg_list['atoms']['color'] = [0.0, 0.0, 1.0]

        target_central_atoms = copy.deepcopy(list1)
        template_central_atoms = copy.deepcopy(list2)
        max_dist_for_pairing = 2.0
        for i in range(len(list1)):
            for atom in [list1[i], list2[i]]:
                atom.parent.vtk_arg_list['trace']['color'] = [1.0, 1.0, 1.0]
                atom.vtk_arg_list['atoms']['color'] = [1.0, 1.0, 1.0]
            if list1[i].dist(list2[i]) < max_dist_for_pairing:
                new_target_atoms.append(target_central_atoms[i])
                new_template_atoms.append(template_central_atoms[i])
                for atom in [list1[i], list2[i]]:
                    atom.parent.vtk_arg_list['trace']['color'] = [
                        1.0, 1.0, 0.0
                    ]
                    atom.vtk_arg_list['atoms']['color'] = [1.0, 1.0, 0.0]
        if len(new_target_atoms) > 5:
            # now transform the original list of equivalent (non-gap) alpha carbon
            # atoms to get the overall rms
            tm, rm = Superimpose._fit_pair_atoms(
                [new_target_atoms, new_template_atoms])
            Superimpose._transform(tm, rm, self.template.atoms)
            rms = Superimpose._get_atoms_rms(
                [new_target_atoms, new_template_atoms])
            print 'final rms = %s over %s atom pairs < %s distance' % (
                rms, len(new_target_atoms), max_dist_for_pairing)
        else:
            print 'fewer than 5 atoms fit good in final fit'

        return rms, len(new_target_atoms)
Esempio n. 4
0
    def align_structures(self):
        aout, bout = self.align()
        list1 = []
        list2 = []
        for ind in range(len(aout)):
            if aout[ind] != '-' and bout[ind] != '-':
                aout[ind].vtk_arg_list['trace']['color'] = [1.0,1.0,1.0]
                bout[ind].vtk_arg_list['trace']['color'] = [1.0,1.0,1.0]
                list1.append(aout[ind].central_atom)
                list2.append(bout[ind].central_atom)
        ps = [self.target.atoms, self.template.atoms]
        tm, rm = Superimpose._fit_pair_atoms([list1,list2])
        scores = 0.0
        cntr  = 0
        for i in range(len(aout)):
            if aout[i] != '-' and bout[i] != '-':
                scores += self.score_by_key(aout[i].res_number, bout[i].res_number, [0.0,0.11,0.91,0.0])
                cntr += 1
        print 'avg score %s'%(scores/cntr)
        Superimpose._transform(tm, rm, self.template.atoms)
        rms = Superimpose._get_atoms_rms([list1, list2])
        print 'initial rms = %s over %s atoms'%(rms, len(list1))

        for max_dist_for_pairing in [5.0,4.0,3.0]:
            target_central_atoms   = copy.deepcopy(list1)
            template_central_atoms = copy.deepcopy(list2)
            new_target_atoms       = []
            new_template_atoms     = []
            for i in range(len(target_central_atoms)):
                #print '%s %s %s'%(target_central_atoms[i].dist(template_central_atoms[i]), target_central_atoms[i].res_type, template_central_atoms[i].res_type)
                if target_central_atoms[i].dist(template_central_atoms[i]) < max_dist_for_pairing:
                    new_target_atoms.append(target_central_atoms[i])
                    new_template_atoms.append(template_central_atoms[i])
            if len(new_target_atoms) > 5:
                tm, rm = Superimpose._fit_pair_atoms([new_target_atoms,new_template_atoms])
                Superimpose._transform(tm, rm, self.template.atoms)
                rms = Superimpose._fit_atoms_rms([new_target_atoms, new_template_atoms])
                print 'new rms = %s over %s atom pairs < %s distance'%(rms, len(new_target_atoms), max_dist_for_pairing)
            else:
                print 'fewer than 5 atoms fit good in fit'
        
        for res in self.target.residues:
            res.central_atom.vtk_arg_list['atoms']['color'] = [0.0,0.0,1.0]
        for res in self.template.residues:
            res.central_atom.vtk_arg_list['atoms']['color'] = [0.0,0.0,1.0]
            
        target_central_atoms   = copy.deepcopy(list1)
        template_central_atoms = copy.deepcopy(list2)
        max_dist_for_pairing = 2.0
        for i in range(len(list1)):
            for atom in [list1[i], list2[i]]:
                atom.parent.vtk_arg_list['trace']['color'] = [1.0,1.0,1.0]
                atom.vtk_arg_list['atoms']['color'] = [1.0,1.0,1.0]
            if list1[i].dist(list2[i]) < max_dist_for_pairing:
                new_target_atoms.append(target_central_atoms[i])
                new_template_atoms.append(template_central_atoms[i])
                for atom in [list1[i], list2[i]]:
                    atom.parent.vtk_arg_list['trace']['color'] = [1.0,1.0,0.0]
                    atom.vtk_arg_list['atoms']['color'] = [1.0,1.0,0.0]
        if len(new_target_atoms) > 5:
            # now transform the original list of equivalent (non-gap) alpha carbon
            # atoms to get the overall rms
            tm, rm = Superimpose._fit_pair_atoms([new_target_atoms,new_template_atoms])
            Superimpose._transform(tm, rm, self.template.atoms)
            rms = Superimpose._get_atoms_rms([new_target_atoms, new_template_atoms])
            print 'final rms = %s over %s atom pairs < %s distance'%(rms, len(new_target_atoms), max_dist_for_pairing)
        else:
            print 'fewer than 5 atoms fit good in final fit'
        
        return rms, len(new_target_atoms)