Пример #1
0
    def main(
        self, jobid, lines, atoms_hessian = ['CA'], frames = 51,
        cutoff_distance = 10.,
        path_html = None, path_python = None, verbose = False, paralleldir = '',
        biomolecule = None, chains = [], model = None,
        winsize = 1, stepsize = 1,
        ):

        '''
        Use first model if no model specified by user.
        chain(s): Y, biomolecule: Y; parse chains specified by user and apply transformation
        chain(s): Y, biomolecule: N; parse chains specified by user but don't apply transformation
        chain(s): N, biomolecule: Y; parse chains of biomolecule and apply transformation
        chain(s): N, biomolecule: N; parse chains of first biomolecule and apply transformation
        '''

        import os, Numeric, goodvibes_core

        if stepsize not in [1,winsize]:
            raise 'stepsize must be 1 or equal to winsize'

        results = []

        ## parse pdb
        (
            d_REMARK350,
            d_primary, ## i.e. SEQRES, MODRES
            d_secondary, ## i.e. HELIX, SHEET
            d_coordinates, ## i.e. ATOM, HETATM, TER, MODEL, ENDMDL
            ) = self.parse_pdb(lines, chains, model)

        ## assume multimeric biological unit if chains not specified by user
        if chains == []:
            chains = d_coordinates['chains'].keys()
            chains.sort()

        ##
        ## d_coordinates to l_coordinates
        ##
        l_coordinates = []
        for chain in chains:
            ## assuming sequential numbering of residues
            res_nos = d_coordinates['chains'][chain]['residues'].keys()
            res_nos.sort()
            for res_no in res_nos:
                for iCode in d_coordinates['chains'][chain]['residues'][res_no]['iCodes'].keys():
                    altloc = min(d_coordinates['chains'][chain]['residues'][res_no]['iCodes'][iCode]['altlocs'].keys())
                    for atom_name in d_coordinates['chains'][chain]['residues'][res_no]['iCodes'][iCode]['altlocs'][altloc]['atoms'].keys():
                        if atom_name in atoms_hessian:
                            coordinate = d_coordinates['chains'][chain]['residues'][res_no]['iCodes'][iCode]['altlocs'][altloc]['atoms'][atom_name]['coordinate']
                            d_coordinates['chains'][chain]['residues'][res_no]['iCodes'][iCode]['altlocs'][altloc]['atoms'][atom_name]['hessian'] = True
                            l_coordinates += [coordinate]

        ## cluster coordinates
        l_coordinates = [sum(l_coordinates[i:i+winsize])/winsize for i in range(0,len(l_coordinates),winsize)]
        N = len(l_coordinates)

        ## calculate intra-residue distances
        matrix_distance_residue_intra = self.distance_residue_intra(l_coordinates)

        ## for the non-disrupted structure: calculate and visualize eigenvectors
        matrix_hessian = self.hessian_calculation(l_coordinates, float(cutoff_distance), verbose)
        eigenvectors_nonperturbed, eigenvalues_nonperturbed, eigenvectors_combined_nonperturbed = self.eigenv_calccomb(matrix_hessian, jobid, verbose)
        import math
        d_energies = {}
        d_factors = {}


        ## read pdb2
        pdb2 = '2lzm'
        chains2 = ['A']
        fd = open('/oxygenase_local/data/pdb/%s/pdb%s.ent' %(pdb2[1:3],pdb2,),'r')
        lines2 = fd.readlines()
        fd.close()
        ## parse pdb2
        (
            d_REMARK350_2,
            d_primary2, ## i.e. SEQRES, MODRES
            d_secondary2, ## i.e. HELIX, SHEET
            d_coordinates2, ## i.e. ATOM, HETATM, TER, MODEL, ENDMDL
            d_ligands2,
            ) = goodvibes_core.parse_pdb(lines2, chains2)
        N2, d_hessian2, l_coordinates2 = goodvibes_core.parse_dictionary_of_coordinates(d_coordinates2, chains2, atoms_hessian)

        ## rotate coordinates2
        import sys, numpy
        sys.path.append('/home/people/tc/svn/Protool/')
        import geometry
        instance_geometry = geometry.geometry()
        rmsd = instance_geometry.superpose(l_coordinates[:-2],l_coordinates2)
        print 'rmsd', rmsd
        tv1 = instance_geometry.fitcenter
        rm = instance_geometry.rotation
        tv2 = instance_geometry.refcenter
        for i in range(len(l_coordinates2)):
            coord = l_coordinates2[i]
            tcoord = numpy.dot(coord-tv1,rm)+tv2
            l_coordinates2[i] = tcoord

        ## calculate coordinates2 energies
        V = 0
        E = 0
        l_E = []
        maxi = [0,'N/A',]
        mini = 9999
        lines_rasmol_colors = []
        for i in range(0,len(l_coordinates2)*3,3):

            res_index1 = i/3
            xa1 = l_coordinates[res_index1][0]
            ya1 = l_coordinates[res_index1][1]
            za1 = l_coordinates[res_index1][2]
            xa2 = l_coordinates2[res_index1][0]
            ya2 = l_coordinates2[res_index1][1]
            za2 = l_coordinates2[res_index1][2]

            E = 0

            for j in range(0,len(l_coordinates2)*3,3):

                if i == j:
                    continue

                res_index2 = j/3
                xb1 = l_coordinates[res_index2][0]
                yb1 = l_coordinates[res_index2][1]
                zb1 = l_coordinates[res_index2][2]
                xb2 = l_coordinates2[res_index2][0]
                yb2 = l_coordinates2[res_index2][1]
                zb2 = l_coordinates2[res_index2][2]

                kx = matrix_hessian[i+0][j+0]
                ky = matrix_hessian[i+1][j+1]
                kz = matrix_hessian[i+2][j+2]

##                        k = math.sqrt(kx**2+ky**2+kz**2)
##                        E = .5*kx*(vx**2)+.5*ky*(vy**2)+.5*kz*(vz**2)

##                        E -= .5*kx*((vxb-vxa)**2)+.5*ky*((vyb-vya)**2)+.5*kz*((vzb-vza)**2)
                E -= .5*kx*(((xb2-xa2)-(xb1-xa1))**2)+.5*ky*(((yb2-ya2)-(yb1-ya1))**2)+.5*kz*(((zb2-za2)-(zb1-za1))**2)

                if E < mini:
                    mini = E
                if E > maxi[0]:
                    maxi = [E,res_index1]

            l_E += [E/0.39]

            index = E/0.39

            h = 159.+80*index/100.
            s = 240.
            l = 120.+120.*(50-abs(index-50))/50.
            r,g,b = self.hsl2rgb(h,s,l,)

            lines_rasmol_colors += [
                'select %i\n' %(res_index1+1),
                'color [%i,%i,%i]\n' %(
                    r, g, b,
                    )
                ]


        lines_pdb2_rotated = []
        ## rotate pdb
        for line in lines2:
            record = line[:6].strip()
            if record == 'HETATM':
                continue
            elif record != 'ATOM':
                lines_pdb2_rotated += [line]
                continue
            if line[21] not in chains2:
                continue
            x = float(line[30:38])
            y = float(line[38:46])
            z = float(line[46:54])
            coordinate = numpy.array([x,y,z,])
            coordinate = numpy.dot(coordinate-tv1,rm)+tv2
            bfactor = float(line[60:66])
            line_rotated = '%s%8.3f%8.3f%8.3f%s%6.2f%s' %(
                line[:30],
                coordinate[0],coordinate[1],coordinate[2],
                line[54:60],bfactor,line[66:]
                )
            lines_pdb2_rotated += [line_rotated]
        fd = open('%s_rotated.pdb' %(pdb2),'w')
        fd.writelines(lines_pdb2_rotated)
        fd.close()
            
        ## write rasmol script
        lines = [
            'rasmol -nodisplay %s_rotated.pdb << EOF\n' %(pdb2),
            'cartoon\n',
            'wireframe 0\n',
##                    'ribbons\n',
##                    'color temperature\n',
            ]

        lines += lines_rasmol_colors

        lines += [
##                    'ribbons\n',
            'rotate x 100\n',
            'rotate z 30\n',
            'rotate x 100\n',
            'rotate z 90\n',
            'rotate x 40\n',
            'rotate y -20\n',
            'write 150l.ppm\n',
            'exit\n',
            ]
        ## write rasmol script to file
        fd = open('rasmol.src','w')
        fd.writelines(lines)
        fd.close()
        ## execute rasmol script
        os.system('source rasmol.src > rasmol.log')
        ## convert rasmol output
        os.system('convert 150l.ppm 150l.gif')
        ## clean up
        os.remove('150l.ppm')
        os.remove('rasmol.log')
##        os.remove('rasmol.src')

        print l_E
        print 'minmax', mini,maxi
            
##        self.morph(
##            eigenvectors_nonperturbed, frames, chains, d_coordinates, atoms_hessian, matrix_hessian, jobid,
##            d_energies,d_factors,
##            )

        return results
Пример #2
0
    def main(
        self, jobid, lines, atoms_hessian = ['CA'], frames = 50,
        cutoff_distance = 10.,
        path_python = None, verbose = False, paralleldir = '',
        biomolecule = None, chains = [], model = None,
        ):

        '''
        Use first model if no model specified by user.
        chain(s): Y, biomolecule: Y; parse chains specified by user and apply transformation
        chain(s): Y, biomolecule: N; parse chains specified by user but don't apply transformation
        chain(s): N, biomolecule: Y; parse chains of biomolecule and apply transformation
        chain(s): N, biomolecule: N; parse chains of first biomolecule and apply transformation
        '''

        import os, Numeric, goodvibes_core

        results = []

        ## parse pdb
        (
            d_REMARK350,
            d_primary, ## i.e. SEQRES, MODRES
            d_secondary, ## i.e. HELIX, SHEET
            d_coordinates, ## i.e. ATOM, HETATM, TER, MODEL, ENDMDL
            d_ligands,
            ) = goodvibes_core.parse_pdb(lines, chains)

        ## assume multimeric biological unit if chains not specified by user
        if chains == []:
            chains = d_coordinates['chains'].keys()
            chains.sort()

        ##
        ## calculate N and convert coordinates from dic to list
        ##
        N, d_hessian, l_coordinates = goodvibes_core.parse_dictionary_of_coordinates(d_coordinates, chains, atoms_hessian)

        ##
        ## calculate distance matrix
        ##
        matrix_distances = goodvibes_core.calculate_distance_matrix(l_coordinates)

        ##
        ## calculate hessian matrix
        ##
        matrix_hessian = self.hessian_calculation(N, d_coordinates, chains, atoms_hessian, float(cutoff_distance), d_secondary, matrix_distances, l_coordinates, verbose = verbose)

        ##
        ## diagonalize hessian matrix
        ##
        eigenvectors_nonperturbed, eigenvalues_nonperturbed, eigenvectors_comb_nonperturbed, = goodvibes_core.eigenv_calccomb(
                matrix_hessian, jobid, verbose,
                )

        ##
        ## visualize eigenvectors
        ##
        goodvibes_core.morph(
            eigenvectors_nonperturbed, frames, chains, d_coordinates,
            jobid, d_primary,
            )

        ##
        ## do plots prior to perturbation
        ##
##        goodvibes_core.pre_perturbation_plot(
##            jobid,cutoff_distance,chains,d_secondary,
##            eigenvectors_nonperturbed,eigenvectors_comb_nonperturbed,
##            )

        ##
        ## set data lists and append matrices to be plotted for each combination of modes 6-12 before initiating loops over the two axes of the plot
        ##
        datadic = goodvibes_core.datadic_return(N)

        prefix = 'wt'
        suffix = 'vmd'
        goodvibes_core.overlap2structure(
            eigenvectors_nonperturbed, eigenvectors_nonperturbed,
            d_coordinates,[],d_hessian,l_coordinates,prefix,suffix,
            )
        stop

################################################################################
##                        plotdata calculation section                        ##
################################################################################

        ## loop over remres1
        for remres1 in range(N):

            print remres1

            ## continue the remres1 loop if another processor is running calculations for that value of remres1
            filename = '%s/%s_residue%s.txt' %(paralleldir, jobid, remres1+1)
            datadic, Continue = goodvibes_core.multiple_cpus_read(datadic,filename,remres1)
            if Continue == True and remres1 not in [20,21,141,19,22,140,142,]:
                continue

            ## loop over remres2
            for remres2 in range(remres1+1,N):

                if remres2 not in [20,21,141,19,22,140,142,]:
                    continue

                print remres1, remres2

                l_rem = [remres1,remres2]

                l_coordinates_perturbed = l_coordinates[:remres1]+l_coordinates[remres1+1:remres2]+l_coordinates[remres2+1:]
            
                matrix_hessian_perturbed = self.hessian_calculation(
                    N-2, d_coordinates, chains, atoms_hessian, float(cutoff_distance), d_secondary, matrix_distances, l_coordinates_perturbed, verbose = verbose,
                    )

                (
                    eigenvectors_perturbed, eigenvalues_perturbed, eigenvectors_perturbed_combined,
                    ) = goodvibes_core.eigenv_calccomb(
                        matrix_hessian_perturbed, jobid, verbose
                        )

                eigenvectors_nonperturbed_aligned, eigenvectors_perturbed_aligned = goodvibes_core.align_vectors_of_different_length(eigenvectors_nonperturbed, eigenvectors_perturbed, l_rem = l_rem)
                eigenvectors_nonperturbed_aligned, eigenvectors_perturbed_combined_aligned = goodvibes_core.align_vectors_of_different_length(eigenvectors_nonperturbed, eigenvectors_perturbed_combined, l_rem = l_rem)

                (
                    overlaps_single, max_overlaps_single, perturbed_modes_of_max_overlap_single, delta_perturbed_eigenvalues_of_max_overlap,
                    ) = goodvibes_core.overlap_calculation(
                        eigenvectors_perturbed_aligned, eigenvectors_nonperturbed_aligned, eigenvalues_perturbed, eigenvalues_nonperturbed,
                        )

                (
                    overlaps_combined, max_overlaps_combined, perturbed_modes_of_max_overlap_combined,
                    ) = goodvibes_core.overlap_calculation(
                        eigenvectors_perturbed_combined_aligned, eigenvectors_nonperturbed_aligned, eigenvalues_perturbed, eigenvalues_nonperturbed,
                        )[:-1]

                datadic_loop = {
                    'eigenvalues_perturbed': eigenvalues_perturbed,
                    'emo': delta_perturbed_eigenvalues_of_max_overlap,
                    'overlaps_single': overlaps_single,
                    'overlaps_max': max_overlaps_single,
                    'mmo': perturbed_modes_of_max_overlap_single,
                    'overlaps_combined': overlaps_combined
                    }
                for key in datadic:
                    for mode in range(6,12):
                        datadic[key]['data'][mode][remres1][remres2] = datadic_loop[key][mode]
                        datadic[key]['data'][mode][remres2][remres1] = datadic_loop[key][mode]
                datadic['overlaps_combined']['data'][-1][remres1][remres2] = overlaps_combined[-1]
                datadic['overlaps_combined']['data'][-1][remres2][remres1] = overlaps_combined[-1]

                print overlaps_single[6]

                prefix = '%s' %(jobid)
                suffix = '%s_%s' %(remres1+1, remres2+1)
                goodvibes_core.overlap2structure(
                    eigenvectors_nonperturbed, eigenvectors_perturbed,
                    d_coordinates,l_rem,d_hessian,l_coordinates,prefix,suffix,
                    )

                prefix = '%s' %(jobid)
                suffix = '%s_%s' %(remres1+1, remres2+1)
                goodvibes_core.vmdarrow(
                    eigenvectors_perturbed,d_hessian,
                    prefix,suffix,l_rem=l_rem,
                    )
                if overlaps_single[6] > 0.9:
                    print overlaps_single[6]
                    print remres1+1, remres2+1
##                    stop

##            ##
##            ## write data to txt files in case of crash during loop over residues/clusters
##            ##
##            filename = '%s/%s_residue%s.txt' %(paralleldir, jobid, remres1+1)
##            goodvibes_core.multiple_cpus_write(datadic,filename,remres1)

##        ##
##        ## do plots for perturbation results
##        ##
##        if verbose == True:
##            print 'generating plots'
##        goodvibes_core.post_perturbation_plot(
##            datadic, jobid, chains, cutoff_distance, d_hessian, N, d_secondary, d_coordinates,
##            )

        return
    def main(
        self, jobid, lines, atoms_hessian = ['CA'], frames = 50,
        cutoff_distance = 10.,
        path_html = None, path_python = None, verbose = False, paralleldir = '',
        chains = None,
        ):

        import goodvibes_core

        ##
        ## parse pdb
        ##
        (
            d_REMARK350,
            d_primary, ## i.e. SEQRES, MODRES
            d_secondary, ## i.e. HELIX, SHEET
            d_coordinates, ## i.e. ATOM, HETATM, TER, MODEL, ENDMDL
            d_ligands,
            ) = goodvibes_core.parse_pdb(lines, chains)


        ##
        ## calculate N and convert coordinates from dic to list
        ##
        N, d_hessian, l_coordinates = goodvibes_core.parse_dictionary_of_coordinates(d_coordinates, chains, atoms_hessian)

        ##
        ## calculate distance matrix
        ##
        matrix_distances = goodvibes_core.calculate_distance_matrix(l_coordinates)

        ##
        ## calculate hessian matrix
        ##
        matrix_hessian = self.hessian_calculation(N, d_coordinates, chains, atoms_hessian, float(cutoff_distance), d_secondary, matrix_distances, l_coordinates, verbose = verbose)

        ##
        ## diagonalize hessian matrix
        ##
        eigenvectors_nonperturbed, eigenvalues_nonperturbed, eigenvectors_combined_nonperturbed = goodvibes_core.eigenv_calccomb(matrix_hessian, jobid, verbose)

        ##
        ## visualize eigenvectors
        ##
        goodvibes_core.morph(eigenvectors_nonperturbed, frames, chains, d_coordinates, jobid, d_primary)

        ##
        ## do plots prior to perturbation
        ##
        goodvibes_core.pre_perturbation_plot(
            jobid,cutoff_distance,chains,d_secondary,
            eigenvectors_nonperturbed,eigenvectors_combined_nonperturbed,
            )
        
        ##
        ## set data lists and append matrices to be plotted for each combination of modes 6-12 before initiating loops over the two axes of the plot
        ##
        datadic = goodvibes_core.datadic_return(N)

        ##
        ## loop over remres1
        ##
        for remres1 in range(N-1):

            ## continue the remres1 loop if another processor is running calculations for that value of remres1
            filename = '%s/%s_residue%s.txt' %(paralleldir, jobid, remres1+1)
            datadic, Continue = goodvibes_core.multiple_cpus_read(datadic,filename,remres1)
            if Continue == True:
                continue

            ##
            ## loop over remres2
            ##
            for remres2 in range(remres1+1,N):

                print remres1, remres2
                l_mod = [remres1,remres2]

                ##
                ## calculate hessian matrix
                ##
                matrix_hessian_perturbed = self.hessian_calculation(
                    N, d_coordinates, chains, atoms_hessian, float(cutoff_distance), d_secondary, matrix_distances, l_coordinates, verbose = verbose, l_mod = l_mod,
                    )

                ##
                ## diagonalize hessian matrix and calculate eigenvectors
                ##
                (
                    eigenvectors_perturbed, eigenvalues_perturbed, eigenvectors_perturbed_combined
                    ) = goodvibes_core.eigenv_calccomb(
                        matrix_hessian_perturbed, jobid, verbose
                        )

                ##
                ## calculate overlap between eigenvectors
                ##
                (
                    overlaps_single, max_overlaps_single, perturbed_modes_of_max_overlap_single, delta_perturbed_eigenvalues_of_max_overlap
                    ) = goodvibes_core.overlap_calculation(
                        eigenvectors_perturbed, eigenvectors_nonperturbed, eigenvalues_perturbed, eigenvalues_nonperturbed,
                        )
                
                (
                    overlaps_combined, max_overlaps_combined, perturbed_modes_of_max_overlap_combined
                    ) = goodvibes_core.overlap_calculation(
                        eigenvectors_perturbed_combined, eigenvectors_nonperturbed, eigenvalues_perturbed, eigenvalues_nonperturbed,
                        )[:-1]
                print overlaps_single[6]

                datadic_loop = {
                    'eigenvalues_perturbed': eigenvalues_perturbed,
                    'emo': delta_perturbed_eigenvalues_of_max_overlap,
                    'overlaps_single': overlaps_single,
                    'overlaps_max': max_overlaps_single,
                    'mmo': perturbed_modes_of_max_overlap_single,
                    'overlaps_combined': overlaps_combined
                    }
                for key in datadic:
                    for mode in range(6,12):
                        datadic[key]['data'][mode][remres1][remres2] = datadic_loop[key][mode]
                        datadic[key]['data'][mode][remres2][remres1] = datadic_loop[key][mode]
                datadic['overlaps_combined']['data'][-1][remres1][remres2] = overlaps_combined[-1]
                datadic['overlaps_combined']['data'][-1][remres2][remres1] = overlaps_combined[-1]

            ## write data to txt files in case of crash during loop over residues/clusters
            filename = '%s/%s_residue%s.txt' %(paralleldir, jobid, remres1+1)
            goodvibes_core.multiple_cpus_write(datadic,filename,remres1)

        ##
        ## do plots for perturbation results
        ##
        if verbose == True:
            print 'generating plots'
        goodvibes_core.post_perturbation_plot(
            datadic, jobid, chains, cutoff_distance, d_hessian, N, d_secondary, d_coordinates,
            )


        return
Пример #4
0
    def main(
        self,
        jobid,
        lines,
        atoms_hessian=['CA'],
        frames=50,
        cutoff_distance=10.,
        path_html=None,
        path_python=None,
        verbose=False,
        paralleldir='',
        chains=None,
        winsize=1,
        pre_perturbation_plot=True,
        polyhedron=None,
    ):

        import goodvibes_core

        ##
        ## parse pdb
        ##
        (
            d_REMARK350,
            d_primary,  ## i.e. SEQRES, MODRES
            d_secondary,  ## i.e. HELIX, SHEET
            d_coordinates,  ## i.e. ATOM, HETATM, TER, MODEL, ENDMDL
            d_ligands,
        ) = goodvibes_core.parse_pdb(lines, chains)

        ##
        ## calculate N and convert coordinates from dic to list
        ##
        N, d_hessian, l_coordinates = goodvibes_core.parse_dictionary_of_coordinates(
            d_coordinates, chains, atoms_hessian)

        ##
        ## calculate distance matrix
        ##
        matrix_distances = goodvibes_core.calculate_distance_matrix(
            l_coordinates)

        ##
        ## calculate hessian matrix
        ##
        matrix_hessian = self.hessian_calculation(N,
                                                  matrix_distances,
                                                  d_coordinates,
                                                  float(cutoff_distance),
                                                  l_coordinates,
                                                  verbose=verbose)

        ##
        ## diagonalize hessian matrix
        ##
        eigenvectors_nonperturbed, eigenvalues_nonperturbed, eigenvectors_combined_nonperturbed = goodvibes_core.eigenv_calccomb(
            matrix_hessian, jobid, verbose)

        ##
        ## visualize eigenvectors
        ##
        goodvibes_core.morph(eigenvectors_nonperturbed, frames, chains,
                             d_coordinates, jobid, d_primary)

        ##
        ## do plots prior to perturbation
        ##
        if pre_perturbation_plot == True:
            goodvibes_core.pre_perturbation_plot(
                jobid,
                cutoff_distance,
                chains,
                d_secondary,
                eigenvectors_nonperturbed,
                eigenvectors_combined_nonperturbed,
            )

        ##
        ## set data lists and append matrices to be plotted for each combination of modes 6-12 before initiating loops over the two axes of the plot
        ##
        datadic = goodvibes_core.datadic_return(N)

        d_vertices = {
            'tetrahedron': 4,
            'hexahedron': 8,
            'octahedron': 6,
            'icosahedron': 12,
        }

        ##
        ## loop over remres1
        ##
        for remres1 in range((winsize - 1) / 2,
                             N - winsize - (winsize - 1) / 2):

            resrange1 = range(remres1 - (winsize - 1) / 2,
                              remres1 + (winsize - 1) / 2 + 1)
            l_c1 = []
            for res1 in resrange1:
                c1 = l_coordinates[res1]
                l_c1 += goodvibes_core.platonicsolid(c1, polyhedron=polyhedron)

            ## continue the remres1 loop if another processor is running calculations for that value of remres1
            filename = '%s/%s_residue%s.txt' % (paralleldir, jobid,
                                                remres1 + 1)
            datadic, Continue = goodvibes_core.multiple_cpus_read(
                datadic, filename, remres1)
            if Continue == True:
                continue

            ##
            ## loop over remres2
            ##
            for remres2 in range(remres1 + 2 * (winsize - 1) / 2 + 1,
                                 N - (winsize - 1) / 2):

                print remres1, remres2

                resrange2 = range(remres2 - (winsize - 1) / 2,
                                  remres2 + (winsize - 1) / 2 + 1)
                l_c2 = []
                for res2 in resrange2:
                    c2 = l_coordinates[res2]
                    l_c2 += goodvibes_core.platonicsolid(c2,
                                                         polyhedron=polyhedron)

                l_add = []
                n_vertices = d_vertices[polyhedron]
                for i in range(n_vertices * (2 * winsize)):
                    l_add += [N + i]

                l_coordinates_perturbed = l_coordinates + l_c1 + l_c2

                matrix_hessian_perturbed = self.hessian_calculation(
                    N,
                    matrix_distances,
                    d_coordinates,
                    float(cutoff_distance),
                    l_coordinates_perturbed,
                    verbose=verbose,
                )

                (eigenvectors_perturbed, eigenvalues_perturbed,
                 eigenvectors_perturbed_combined
                 ) = goodvibes_core.eigenv_calccomb(matrix_hessian_perturbed,
                                                    jobid, verbose)

                (overlaps_single, max_overlaps_single,
                 perturbed_modes_of_max_overlap_single,
                 delta_perturbed_eigenvalues_of_max_overlap
                 ) = goodvibes_core.overlap_calculation(
                     eigenvectors_perturbed,
                     eigenvectors_nonperturbed,
                     eigenvalues_perturbed,
                     eigenvalues_nonperturbed,
                     l_add=l_add)

                (overlaps_combined, max_overlaps_combined,
                 perturbed_modes_of_max_overlap_combined
                 ) = goodvibes_core.overlap_calculation(
                     eigenvectors_perturbed_combined,
                     eigenvectors_nonperturbed,
                     eigenvalues_perturbed,
                     eigenvalues_nonperturbed,
                     l_add=l_add,
                 )[:-1]
                print overlaps_single[6]

                ##        ## do vmd of perturbed structure
                ##        self.morph(eigenvectors, frames, biomolecule, d_coordinates, atoms_hessian, cluster, matrix_hessian, jobid+'-'+str(xvalue)+'-'+str(yvalue), cutoff_distance)

                datadic_loop = {
                    'eigenvalues_perturbed': eigenvalues_perturbed,
                    'emo': delta_perturbed_eigenvalues_of_max_overlap,
                    'overlaps_single': overlaps_single,
                    'overlaps_max': max_overlaps_single,
                    'mmo': perturbed_modes_of_max_overlap_single,
                    'overlaps_combined': overlaps_combined
                }
                for key in datadic:
                    for mode in range(6, 12):
                        datadic[key]['data'][mode][remres1][
                            remres2] = datadic_loop[key][mode]
                        datadic[key]['data'][mode][remres2][
                            remres1] = datadic_loop[key][mode]
                datadic['overlaps_combined']['data'][-1][remres1][
                    remres2] = overlaps_combined[-1]
                datadic['overlaps_combined']['data'][-1][remres2][
                    remres1] = overlaps_combined[-1]

            ## write data to txt files in case of crash during loop over residues/clusters
            filename = '%s/%s_residue%s.txt' % (paralleldir, jobid,
                                                remres1 + 1)
            goodvibes_core.multiple_cpus_write(datadic, filename, remres1)

        ##
        ## do plots for perturbation results
        ##
        if verbose == True:
            print 'generating plots'
        goodvibes_core.post_perturbation_plot(
            datadic,
            jobid,
            chains,
            cutoff_distance,
            d_hessian,
            N,
            d_secondary,
            d_coordinates,
            winsize=winsize,
        )

        return
Пример #5
0
    def main(
        self,
        jobid,
        lines,
        atoms_hessian=['CA'],
        frames=50,
        cutoff_distance=10.,
        path_python=None,
        verbose=False,
        paralleldir='',
        biomolecule=None,
        chains=[],
        model=None,
        winsize=1,
        pre_perturbation_plot=True,
    ):
        '''
        Use first model if no model specified by user.
        chain(s): Y, biomolecule: Y; parse chains specified by user and apply transformation
        chain(s): Y, biomolecule: N; parse chains specified by user but don't apply transformation
        chain(s): N, biomolecule: Y; parse chains of biomolecule and apply transformation
        chain(s): N, biomolecule: N; parse chains of first biomolecule and apply transformation
        '''

        import os, Numeric, goodvibes_core

        results = []

        ## parse pdb
        (
            d_REMARK350,
            d_primary,  ## i.e. SEQRES, MODRES
            d_secondary,  ## i.e. HELIX, SHEET
            d_coordinates,  ## i.e. ATOM, HETATM, TER, MODEL, ENDMDL
            d_ligands,
        ) = goodvibes_core.parse_pdb(lines, chains)

        ## assume multimeric biological unit if chains not specified by user
        if chains == []:
            chains = d_coordinates['chains'].keys()
            chains.sort()

        ##
        ## calculate N and convert coordinates from dic to list
        ##
        N, d_hessian, l_coordinates = goodvibes_core.parse_dictionary_of_coordinates(
            d_coordinates, chains, atoms_hessian)

        ##
        ## calculate distance matrix
        ##
        matrix_distances = goodvibes_core.calculate_distance_matrix(
            l_coordinates)

        ##
        ## calculate hessian matrix
        ##
        matrix_hessian = self.hessian_calculation(N,
                                                  d_coordinates,
                                                  chains,
                                                  atoms_hessian,
                                                  float(cutoff_distance),
                                                  d_secondary,
                                                  matrix_distances,
                                                  l_coordinates,
                                                  verbose=verbose)

        ##
        ## diagonalize hessian matrix
        ##
        eigenvectors_nonperturbed, eigenvalues_nonperturbed, eigenvectors_comb_nonperturbed, = goodvibes_core.eigenv_calccomb(
            matrix_hessian,
            jobid,
            verbose,
        )

        ##
        ## visualize eigenvectors
        ##
        goodvibes_core.morph(
            eigenvectors_nonperturbed,
            frames,
            chains,
            d_coordinates,
            jobid,
            d_primary,
        )

        ##        ##
        ##        ## do plots prior to perturbation
        ##        ##
        ##        if pre_perturbation_plot == True:
        ##            goodvibes_core.pre_perturbation_plot(
        ##                jobid,cutoff_distance,chains,d_secondary,
        ##                eigenvectors_nonperturbed,eigenvectors_comb_nonperturbed,
        ##                )

        return
Пример #6
0
    def main(
        self, jobid, lines, atoms_hessian = ['CA'], frames = 50,
        cutoff_distance = 10.,
        path_python = None, verbose = False, paralleldir = '',
        biomolecule = None, chains = [], model = None,
        winsize = 1,
        pre_perturbation_plot = True,
        ):

        '''
        Use first model if no model specified by user.
        chain(s): Y, biomolecule: Y; parse chains specified by user and apply transformation
        chain(s): Y, biomolecule: N; parse chains specified by user but don't apply transformation
        chain(s): N, biomolecule: Y; parse chains of biomolecule and apply transformation
        chain(s): N, biomolecule: N; parse chains of first biomolecule and apply transformation
        '''

        import os, Numeric, goodvibes_core

        results = []

        ## parse pdb
        (
            d_REMARK350,
            d_primary, ## i.e. SEQRES, MODRES
            d_secondary, ## i.e. HELIX, SHEET
            d_coordinates, ## i.e. ATOM, HETATM, TER, MODEL, ENDMDL
            d_ligands,
            ) = goodvibes_core.parse_pdb(lines, chains)

        ## assume multimeric biological unit if chains not specified by user
        if chains == []:
            chains = d_coordinates['chains'].keys()
            chains.sort()

        ##
        ## calculate N and convert coordinates from dic to list
        ##
        N, d_hessian, l_coordinates = goodvibes_core.parse_dictionary_of_coordinates(d_coordinates, chains, atoms_hessian)

        ##
        ## calculate distance matrix
        ##
        matrix_distances = goodvibes_core.calculate_distance_matrix(l_coordinates)

        ##
        ## calculate hessian matrix
        ##
        matrix_hessian = self.hessian_calculation(N, d_coordinates, chains, atoms_hessian, float(cutoff_distance), d_secondary, matrix_distances, l_coordinates, verbose = verbose)

        ##
        ## diagonalize hessian matrix
        ##
        eigenvectors_nonperturbed, eigenvalues_nonperturbed, eigenvectors_comb_nonperturbed, = goodvibes_core.eigenv_calccomb(
                matrix_hessian, jobid, verbose,
                )

        ##
        ## visualize eigenvectors
        ##
        goodvibes_core.morph(
            eigenvectors_nonperturbed, frames, chains, d_coordinates,
            jobid, d_primary,
            )

##        ##
##        ## do plots prior to perturbation
##        ##
##        if pre_perturbation_plot == True:
##            goodvibes_core.pre_perturbation_plot(
##                jobid,cutoff_distance,chains,d_secondary,
##                eigenvectors_nonperturbed,eigenvectors_comb_nonperturbed,
##                )

        return
Пример #7
0
    def main(
        self,
        jobid,
        lines,
        atoms_hessian=['CA'],
        frames=50,
        cutoff_distance=10.,
        path_html=None,
        path_python=None,
        verbose=False,
        paralleldir='',
        chains=None,
    ):

        import goodvibes_core

        ##
        ## parse pdb
        ##
        (
            d_REMARK350,
            d_primary,  ## i.e. SEQRES, MODRES
            d_secondary,  ## i.e. HELIX, SHEET
            d_coordinates,  ## i.e. ATOM, HETATM, TER, MODEL, ENDMDL
            d_ligands,
        ) = goodvibes_core.parse_pdb(lines, chains)

        ##
        ## calculate N and convert coordinates from dic to list
        ##
        N, d_hessian, l_coordinates = goodvibes_core.parse_dictionary_of_coordinates(
            d_coordinates, chains, atoms_hessian)

        ##
        ## calculate distance matrix
        ##
        matrix_distances = goodvibes_core.calculate_distance_matrix(
            l_coordinates)

        ##
        ## calculate hessian matrix
        ##
        matrix_hessian = self.hessian_calculation(N,
                                                  d_coordinates,
                                                  chains,
                                                  atoms_hessian,
                                                  float(cutoff_distance),
                                                  d_secondary,
                                                  matrix_distances,
                                                  l_coordinates,
                                                  verbose=verbose)

        ##
        ## diagonalize hessian matrix
        ##
        eigenvectors_nonperturbed, eigenvalues_nonperturbed, eigenvectors_combined_nonperturbed = goodvibes_core.eigenv_calccomb(
            matrix_hessian, jobid, verbose)

        ##
        ## visualize eigenvectors
        ##
        goodvibes_core.morph(eigenvectors_nonperturbed, frames, chains,
                             d_coordinates, jobid, d_primary)

        ##
        ## do plots prior to perturbation
        ##
        goodvibes_core.pre_perturbation_plot(
            jobid,
            cutoff_distance,
            chains,
            d_secondary,
            eigenvectors_nonperturbed,
            eigenvectors_combined_nonperturbed,
        )

        ##
        ## set data lists and append matrices to be plotted for each combination of modes 6-12 before initiating loops over the two axes of the plot
        ##
        datadic = goodvibes_core.datadic_return(N)

        ##
        ## loop over remres1
        ##
        for remres1 in range(N - 1):

            ## continue the remres1 loop if another processor is running calculations for that value of remres1
            filename = '%s/%s_residue%s.txt' % (paralleldir, jobid,
                                                remres1 + 1)
            datadic, Continue = goodvibes_core.multiple_cpus_read(
                datadic, filename, remres1)
            if Continue == True:
                continue

            ##
            ## loop over remres2
            ##
            for remres2 in range(remres1 + 1, N):

                print remres1, remres2
                l_mod = [remres1, remres2]

                ##
                ## calculate hessian matrix
                ##
                matrix_hessian_perturbed = self.hessian_calculation(
                    N,
                    d_coordinates,
                    chains,
                    atoms_hessian,
                    float(cutoff_distance),
                    d_secondary,
                    matrix_distances,
                    l_coordinates,
                    verbose=verbose,
                    l_mod=l_mod,
                )

                ##
                ## diagonalize hessian matrix and calculate eigenvectors
                ##
                (eigenvectors_perturbed, eigenvalues_perturbed,
                 eigenvectors_perturbed_combined
                 ) = goodvibes_core.eigenv_calccomb(matrix_hessian_perturbed,
                                                    jobid, verbose)

                ##
                ## calculate overlap between eigenvectors
                ##
                (overlaps_single, max_overlaps_single,
                 perturbed_modes_of_max_overlap_single,
                 delta_perturbed_eigenvalues_of_max_overlap
                 ) = goodvibes_core.overlap_calculation(
                     eigenvectors_perturbed,
                     eigenvectors_nonperturbed,
                     eigenvalues_perturbed,
                     eigenvalues_nonperturbed,
                 )

                (overlaps_combined, max_overlaps_combined,
                 perturbed_modes_of_max_overlap_combined
                 ) = goodvibes_core.overlap_calculation(
                     eigenvectors_perturbed_combined,
                     eigenvectors_nonperturbed,
                     eigenvalues_perturbed,
                     eigenvalues_nonperturbed,
                 )[:-1]
                print overlaps_single[6]

                datadic_loop = {
                    'eigenvalues_perturbed': eigenvalues_perturbed,
                    'emo': delta_perturbed_eigenvalues_of_max_overlap,
                    'overlaps_single': overlaps_single,
                    'overlaps_max': max_overlaps_single,
                    'mmo': perturbed_modes_of_max_overlap_single,
                    'overlaps_combined': overlaps_combined
                }
                for key in datadic:
                    for mode in range(6, 12):
                        datadic[key]['data'][mode][remres1][
                            remres2] = datadic_loop[key][mode]
                        datadic[key]['data'][mode][remres2][
                            remres1] = datadic_loop[key][mode]
                datadic['overlaps_combined']['data'][-1][remres1][
                    remres2] = overlaps_combined[-1]
                datadic['overlaps_combined']['data'][-1][remres2][
                    remres1] = overlaps_combined[-1]

            ## write data to txt files in case of crash during loop over residues/clusters
            filename = '%s/%s_residue%s.txt' % (paralleldir, jobid,
                                                remres1 + 1)
            goodvibes_core.multiple_cpus_write(datadic, filename, remres1)

        ##
        ## do plots for perturbation results
        ##
        if verbose == True:
            print 'generating plots'
        goodvibes_core.post_perturbation_plot(
            datadic,
            jobid,
            chains,
            cutoff_distance,
            d_hessian,
            N,
            d_secondary,
            d_coordinates,
        )

        return
Пример #8
0
    def main(
        self,
        jobid,
        filename,
        atoms_hessian=['CA'],
        frames=50,
        cutoff_distance=10.,
        path_python=None,
        verbose=False,
        paralleldir='',
        biomolecule=None,
        chains=[],
        model=None,
        winsize=1,
        pre_perturbation_plot=True,
    ):
        '''
        Use first model if no model specified by user.
        chain(s): Y, biomolecule: Y; parse chains specified by user and apply transformation
        chain(s): Y, biomolecule: N; parse chains specified by user but don't apply transformation
        chain(s): N, biomolecule: Y; parse chains of biomolecule and apply transformation
        chain(s): N, biomolecule: N; parse chains of first biomolecule and apply transformation
        '''

        import os, Numeric, goodvibes_core

        results = []

        fd = open(filename, 'r')
        lines = fd.readlines()
        fd.close()

        ## parse pdb
        (
            d_REMARK350,
            d_primary,  ## i.e. SEQRES, MODRES
            d_secondary,  ## i.e. HELIX, SHEET
            d_coordinates,  ## i.e. ATOM, HETATM, TER, MODEL, ENDMDL
            d_ligands,
        ) = goodvibes_core.parse_pdb(lines, chains)

        ## assume multimeric biological unit if chains not specified by user
        if chains == []:
            chains = d_coordinates['chains'].keys()
            chains.sort()

        ##
        ## calculate N and convert coordinates from dic to list
        ##
        N, d_hessian, l_coordinates = goodvibes_core.parse_dictionary_of_coordinates(
            d_coordinates, chains, atoms_hessian)

        ##
        ## calculate distance matrix
        ##
        matrix_distances = goodvibes_core.calculate_distance_matrix(
            l_coordinates)

        ##
        ## calculate hessian matrix
        ##
        matrix_hessian = self.hessian_calculation(N,
                                                  d_coordinates,
                                                  chains,
                                                  atoms_hessian,
                                                  float(cutoff_distance),
                                                  d_secondary,
                                                  matrix_distances,
                                                  l_coordinates,
                                                  verbose=verbose)

        ##
        ## diagonalize hessian matrix
        ##
        eigenvectors_nonperturbed, eigenvalues_nonperturbed, eigenvectors_comb_nonperturbed, = goodvibes_core.eigenv_calccomb(
            matrix_hessian,
            jobid,
            verbose,
        )

        ##
        ## set data lists and append matrices to be plotted for each combination of modes 6-12 before initiating loops over the two axes of the plot
        ##
        datadic = goodvibes_core.datadic_return(N)

        ##
        ## loop over remres1
        ##
        for remres1 in range((winsize - 1) / 2,
                             N - winsize - (winsize - 1) / 2):

            ##
            ## loop over remres2
            ##
            for remres2 in range(remres1 + 2 * (winsize - 1) / 2 + 1,
                                 N - (winsize - 1) / 2):

                print remres1, remres2

                l_rem = []
                for i in range(-(winsize - 1) / 2, (winsize + 1) / 2):
                    l_rem += [remres1 + i, remres2 + i]
                l_rem.sort()

                ##
                ## remove selected alpha carbon atoms!!!
                ##
                l_coordinates_perturbed = l_coordinates[:remres1 - (
                    winsize - 1) / 2] + l_coordinates[
                        remres1 + 1 + (winsize - 1) / 2:remres2 -
                        (winsize - 1) / 2] + l_coordinates[remres2 + 1 +
                                                           (winsize - 1) / 2:]

                matrix_hessian_perturbed = self.hessian_calculation(
                    N - len(l_rem),
                    d_coordinates,
                    chains,
                    atoms_hessian,
                    float(cutoff_distance),
                    d_secondary,
                    matrix_distances,
                    l_coordinates_perturbed,
                    verbose=verbose,
                )

                (
                    eigenvectors_perturbed,
                    eigenvalues_perturbed,
                    eigenvectors_perturbed_combined,
                ) = goodvibes_core.eigenv_calccomb(matrix_hessian_perturbed,
                                                   jobid, verbose)

                (
                    overlaps_single,
                    max_overlaps_single,
                    perturbed_modes_of_max_overlap_single,
                    delta_perturbed_eigenvalues_of_max_overlap,
                ) = goodvibes_core.overlap_calculation(
                    eigenvectors_perturbed, eigenvectors_nonperturbed,
                    eigenvalues_perturbed, eigenvalues_nonperturbed, l_rem)

                (
                    overlaps_combined,
                    max_overlaps_combined,
                    perturbed_modes_of_max_overlap_combined,
                ) = goodvibes_core.overlap_calculation(
                    eigenvectors_perturbed_combined,
                    eigenvectors_nonperturbed,
                    eigenvalues_perturbed,
                    eigenvalues_nonperturbed,
                    l_rem,
                )[:-1]

                datadic_loop = {
                    'eigenvalues_perturbed': eigenvalues_perturbed,
                    'emo': delta_perturbed_eigenvalues_of_max_overlap,
                    'overlaps_single': overlaps_single,
                    'overlaps_max': max_overlaps_single,
                    'mmo': perturbed_modes_of_max_overlap_single,
                    'overlaps_combined': overlaps_combined
                }
                for key in datadic:
                    for mode in range(6, 12):
                        datadic[key]['data'][mode][remres1][
                            remres2] = datadic_loop[key][mode]
                        datadic[key]['data'][mode][remres2][
                            remres1] = datadic_loop[key][mode]
                datadic['overlaps_combined']['data'][-1][remres1][
                    remres2] = overlaps_combined[-1]
                datadic['overlaps_combined']['data'][-1][remres2][
                    remres1] = overlaps_combined[-1]

                print overlaps_single[6]

        l_averages = []
        for remres1 in range(len(datadic['overlaps_single']['data'][6])):
            l_overlaps = []
            for remres2 in range(
                    len(datadic['overlaps_single']['data'][6][remres1])):
                overlap = datadic['overlaps_single']['data'][6][remres1][
                    remres2]
                l_overlaps += [overlap]
            l_averages += [sum(l_overlaps) / len(l_overlaps)]

        return l_averages
Пример #9
0
    def main(
        self, jobid, lines, atoms_hessian = ['CA'], frames = 50,
        cutoff_distance = 10.,
        path_python = None, verbose = False, paralleldir = '',
        biomolecule = None, chains = [], model = None,
        ):

        '''
        Use first model if no model specified by user.
        chain(s): Y, biomolecule: Y; parse chains specified by user and apply transformation
        chain(s): Y, biomolecule: N; parse chains specified by user but don't apply transformation
        chain(s): N, biomolecule: Y; parse chains of biomolecule and apply transformation
        chain(s): N, biomolecule: N; parse chains of first biomolecule and apply transformation
        '''

        import os, Numeric, goodvibes_core

        results = []

        ## parse pdb
        (
            d_REMARK350,
            d_primary, ## i.e. SEQRES, MODRES
            d_secondary, ## i.e. HELIX, SHEET
            d_coordinates, ## i.e. ATOM, HETATM, TER, MODEL, ENDMDL
            d_ligands,
            ) = goodvibes_core.parse_pdb(lines, chains)

        ## assume multimeric biological unit if chains not specified by user
        if chains == []:
            chains = d_coordinates['chains'].keys()
            chains.sort()

        ##
        ## calculate N and convert coordinates from dic to list
        ##
        N, d_hessian, l_coordinates = goodvibes_core.parse_dictionary_of_coordinates(d_coordinates, chains, atoms_hessian)

        ##
        ## calculate distance matrix
        ##
        matrix_distances = goodvibes_core.calculate_distance_matrix(l_coordinates)

        ##
        ## calculate hessian matrix
        ##
        matrix_hessian = self.hessian_calculation(N, d_coordinates, chains, atoms_hessian, float(cutoff_distance), d_secondary, matrix_distances, l_coordinates, verbose = verbose)

        ##
        ## diagonalize hessian matrix
        ##
        eigenvectors_nonperturbed, eigenvalues_nonperturbed, eigenvectors_comb_nonperturbed, = goodvibes_core.eigenv_calccomb(
                matrix_hessian, jobid, verbose,
                )

##        fd = open('/oxygenase_local/data/pdb/50/pdb150l.ent','r')
        fd = open('/oxygenase_local/data/pdb/lz/pdb2lzm.ent','r')
        lines = fd.readlines()
        fd.close()
        (
            d_REMARK350,
            d_primary, ## i.e. SEQRES, MODRES
            d_secondary, ## i.e. HELIX, SHEET
            d_coordinates, ## i.e. ATOM, HETATM, TER, MODEL, ENDMDL
            d_ligands,
            ) = goodvibes_core.parse_pdb(lines, chains)
        N, d_hessian, l_coordinates2 = goodvibes_core.parse_dictionary_of_coordinates(d_coordinates, chains, atoms_hessian)
        if len(l_coordinates) != len(l_coordinates2):
            print len(l_coordinates), len(l_coordinates2)
            stop
        ## import geometry
        import sys
        sys.path.append('/home/people/tc/svn/Protool/trunk/')
        import geometry
        instance_geometry = geometry.geometry()
        ## superpose
        rmsd = instance_geometry.superpose(l_coordinates,l_coordinates2)
        tv1 = instance_geometry.fitcenter
        rm = instance_geometry.rotation
        tv2 = instance_geometry.refcenter
        print rmsd
        ## calculate differences
        l_differences = []
        for i in range(len(l_coordinates)):
            coord1 = l_coordinates[i]
            coord2 = Numeric.matrixmultiply(l_coordinates2[i]-tv1,rm)+tv2
            l_differences += [
                coord1[0]-coord2[0],
                coord1[1]-coord2[1],
                coord1[2]-coord2[2],
                ]
        vector_difference = Numeric.array(l_differences)
        import math
        for mode in range(20):
            vector_nonperturbed = eigenvectors_nonperturbed[mode]
            overlap = math.fabs(goodvibes_core.cosangle(vector_nonperturbed, vector_difference))
            overlaps = []
            for i in range(0,164,3):
                numerator = (
                    vector_nonperturbed[i+0]*vector_difference[i+0]+
                    vector_nonperturbed[i+1]*vector_difference[i+1]+
                    vector_nonperturbed[i+2]*vector_difference[i+2]
                    )
                denominator = (
                    math.sqrt(vector_nonperturbed[i+0]**2+vector_nonperturbed[i+1]**2+vector_nonperturbed[i+2]**2)*
                    math.sqrt(vector_difference[i+0]**2+vector_difference[i+1]**2+vector_difference[i+2]**2)
                    )
                overlaps += [numerator/denominator]
            if mode == 6:
                print sum(overlaps)/len(overlaps)
                
            print mode, overlap
        stop

        ##
        ## visualize eigenvectors
        ##
        goodvibes_core.morph(
            eigenvectors_nonperturbed, frames, chains, d_coordinates,
            jobid, d_primary,
            )

        ##
        ## do plots prior to perturbation
        ##
##        goodvibes_core.pre_perturbation_plot(
##            jobid,cutoff_distance,chains,d_secondary,
##            eigenvectors_nonperturbed,eigenvectors_comb_nonperturbed,
##            )

        ##
        ## set data lists and append matrices to be plotted for each combination of modes 6-12 before initiating loops over the two axes of the plot
        ##
        datadic = goodvibes_core.datadic_return(N)

        return
    def main(
        self,
        jobid,
        lines,
        atoms_hessian=['CA'],
        frames=50,
        cutoff_distance=10.,
        path_python=None,
        verbose=False,
        paralleldir='',
        biomolecule=None,
        chains=[],
        model=None,
        winsize=1,
        pre_perturbation_plot=True,
    ):
        '''
        Use first model if no model specified by user.
        chain(s): Y, biomolecule: Y; parse chains specified by user and apply transformation
        chain(s): Y, biomolecule: N; parse chains specified by user but don't apply transformation
        chain(s): N, biomolecule: Y; parse chains of biomolecule and apply transformation
        chain(s): N, biomolecule: N; parse chains of first biomolecule and apply transformation
        '''

        import os, Numeric, goodvibes_core

        results = []

        ## parse pdb
        (
            d_REMARK350,
            d_primary,  ## i.e. SEQRES, MODRES
            d_secondary,  ## i.e. HELIX, SHEET
            d_coordinates,  ## i.e. ATOM, HETATM, TER, MODEL, ENDMDL
            d_ligands,
        ) = goodvibes_core.parse_pdb(lines, chains)

        ## assume multimeric biological unit if chains not specified by user
        if chains == []:
            chains = d_coordinates['chains'].keys()
            chains.sort()

        ##
        ## calculate N and convert coordinates from dic to list
        ##
        N, d_hessian, l_coordinates = goodvibes_core.parse_dictionary_of_coordinates(
            d_coordinates, chains, atoms_hessian)

        ##
        ## calculate distance matrix
        ##
        matrix_distances = goodvibes_core.calculate_distance_matrix(
            l_coordinates)

        ##
        ## calculate hessian matrix
        ##
        matrix_hessian = self.hessian_calculation(N,
                                                  d_coordinates,
                                                  chains,
                                                  atoms_hessian,
                                                  float(cutoff_distance),
                                                  d_secondary,
                                                  matrix_distances,
                                                  l_coordinates,
                                                  verbose=verbose)

        ##
        ## diagonalize hessian matrix
        ##
        eigenvectors_nonperturbed, eigenvalues_nonperturbed, eigenvectors_comb_nonperturbed, = goodvibes_core.eigenv_calccomb(
            matrix_hessian,
            jobid,
            verbose,
        )

        ##
        ## visualize eigenvectors
        ##
        goodvibes_core.morph(
            eigenvectors_nonperturbed,
            frames,
            chains,
            d_coordinates,
            jobid,
            d_primary,
        )

        ##
        ## do plots prior to perturbation
        ##
        if pre_perturbation_plot == True:
            goodvibes_core.pre_perturbation_plot(
                jobid,
                cutoff_distance,
                chains,
                d_secondary,
                eigenvectors_nonperturbed,
                eigenvectors_comb_nonperturbed,
            )

        ##
        ## set data lists and append matrices to be plotted for each combination of modes 6-12 before initiating loops over the two axes of the plot
        ##
        range2 = [
            0,
            4,
            8,
            16,
        ]
        datadic = goodvibes_core.datadic_return(
            N,
            range2=range2,
        )

        ##
        ## loop over remres1
        ##
        for remres1 in range(N):

            ##
            ## continue the remres1 loop if another processor is running calculations for that value of remres1
            ##
            filename = '%s/%s_residue%s.txt' % (paralleldir, jobid,
                                                remres1 + 1)
            datadic, Continue = goodvibes_core.multiple_cpus_read(
                datadic, filename, remres1)
            if Continue == True:
                continue

            ##
            ## loop over remres2
            ##
            for remres2 in range2:

                sphere_radius = remres2

                sq_sphere_radius = sphere_radius**2

                print remres1, sphere_radius

                l_rem = []
                for res in range(len(matrix_distances[remres1])):
                    if matrix_distances[remres1][res] < sq_sphere_radius:
                        l_rem += [res]
                l_rem.sort()

                ##
                ## remove selected alpha carbon atoms!!!
                ##
                l_coordinates_perturbed = []
                for res in range(len(l_coordinates)):
                    if res not in l_rem:
                        l_coordinates_perturbed += [l_coordinates[res]]

                matrix_hessian_perturbed = self.hessian_calculation(
                    N - len(l_rem),
                    d_coordinates,
                    chains,
                    atoms_hessian,
                    float(cutoff_distance),
                    d_secondary,
                    matrix_distances,
                    l_coordinates_perturbed,
                    verbose=verbose,
                )

                (
                    eigenvectors_perturbed,
                    eigenvalues_perturbed,
                    eigenvectors_perturbed_combined,
                ) = goodvibes_core.eigenv_calccomb(matrix_hessian_perturbed,
                                                   jobid, verbose)

                (
                    overlaps_single,
                    max_overlaps_single,
                    perturbed_modes_of_max_overlap_single,
                    delta_perturbed_eigenvalues_of_max_overlap,
                ) = goodvibes_core.overlap_calculation(
                    eigenvectors_perturbed, eigenvectors_nonperturbed,
                    eigenvalues_perturbed, eigenvalues_nonperturbed, l_rem)

                (
                    overlaps_combined,
                    max_overlaps_combined,
                    perturbed_modes_of_max_overlap_combined,
                ) = goodvibes_core.overlap_calculation(
                    eigenvectors_perturbed_combined,
                    eigenvectors_nonperturbed,
                    eigenvalues_perturbed,
                    eigenvalues_nonperturbed,
                    l_rem,
                )[:-1]

                datadic_loop = {
                    'eigenvalues_perturbed': eigenvalues_perturbed,
                    'emo': delta_perturbed_eigenvalues_of_max_overlap,
                    'overlaps_single': overlaps_single,
                    'overlaps_max': max_overlaps_single,
                    'mmo': perturbed_modes_of_max_overlap_single,
                    'overlaps_combined': overlaps_combined
                }
                for key in datadic:
                    for mode in range(6, 12):
                        datadic[key]['data'][mode][remres1][
                            remres2] = datadic_loop[key][mode]
                        datadic[key]['data'][mode][remres2][
                            remres1] = datadic_loop[key][mode]
                datadic['overlaps_combined']['data'][-1][remres1][
                    remres2] = overlaps_combined[-1]
                datadic['overlaps_combined']['data'][-1][remres2][
                    remres1] = overlaps_combined[-1]

                print overlaps_single[6]

            ##
            ## write data to txt files in case of crash during loop over residues/clusters
            ##
            filename = '%s/%s_residue%s.txt' % (paralleldir, jobid,
                                                remres1 + 1)
            goodvibes_core.multiple_cpus_write(datadic, filename, remres1)

        ##
        ## do plots for perturbation results
        ##
        if verbose == True:
            print 'generating plots'
            goodvibes_core.post_perturbation_plot(
                datadic,
                jobid,
                chains,
                cutoff_distance,
                d_hessian,
                N,
                d_secondary,
                d_coordinates,
                winsize=winsize,
            )

        d_overlaps = {}
        for sphere in range2:
            d_overlaps[sphere] = []
        for res in range(N):
            fd = open('2lzm_residue%s.txt' % (res + 1))
            lines = fd.readlines()
            fd.close()
            parse = False
            for i in range(len(lines)):
                line = lines[i]
                if 'data overlaps_' in line:
                    for sphere in range2:
                        overlap = float(lines[i + 2 + sphere])
                        d_overlaps[sphere] += [overlap]
                    break

        for sphere_radius in range2:
            l_overlaps = d_overlaps[sphere_radius]
            goodvibes_core.write_overlaps_to_pdb_file(
                d_coordinates,
                d_hessian,
                l_overlaps,
                6,
                jobid + 'sphere%s' % (sphere_radius),
                winsize=winsize,
            )

        return
Пример #11
0
    def main(
        self,
        jobid,
        lines,
        atoms_hessian=["CA"],
        frames=50,
        cutoff_distance=10.0,
        path_html=None,
        path_python=None,
        verbose=False,
        paralleldir="",
        chains=None,
        winsize=1,
        pre_perturbation_plot=True,
        polyhedron=None,
    ):

        import goodvibes_core

        ##
        ## parse pdb
        ##
        (
            d_REMARK350,
            d_primary,  ## i.e. SEQRES, MODRES
            d_secondary,  ## i.e. HELIX, SHEET
            d_coordinates,  ## i.e. ATOM, HETATM, TER, MODEL, ENDMDL
            d_ligands,
        ) = goodvibes_core.parse_pdb(lines, chains)

        ##
        ## calculate N and convert coordinates from dic to list
        ##
        N, d_hessian, l_coordinates = goodvibes_core.parse_dictionary_of_coordinates(
            d_coordinates, chains, atoms_hessian
        )

        ##
        ## calculate distance matrix
        ##
        matrix_distances = goodvibes_core.calculate_distance_matrix(l_coordinates)

        ##
        ## calculate hessian matrix
        ##
        matrix_hessian = self.hessian_calculation(
            N, matrix_distances, d_coordinates, float(cutoff_distance), l_coordinates, verbose=verbose
        )

        ##
        ## diagonalize hessian matrix
        ##
        eigenvectors_nonperturbed, eigenvalues_nonperturbed, eigenvectors_combined_nonperturbed = goodvibes_core.eigenv_calccomb(
            matrix_hessian, jobid, verbose
        )

        ##
        ## visualize eigenvectors
        ##
        goodvibes_core.morph(eigenvectors_nonperturbed, frames, chains, d_coordinates, jobid, d_primary)

        ##
        ## do plots prior to perturbation
        ##
        if pre_perturbation_plot == True:
            goodvibes_core.pre_perturbation_plot(
                jobid,
                cutoff_distance,
                chains,
                d_secondary,
                eigenvectors_nonperturbed,
                eigenvectors_combined_nonperturbed,
            )

        ##
        ## set data lists and append matrices to be plotted for each combination of modes 6-12 before initiating loops over the two axes of the plot
        ##
        datadic = goodvibes_core.datadic_return(N)

        d_vertices = {"tetrahedron": 4, "hexahedron": 8, "octahedron": 6, "icosahedron": 12}

        ##
        ## loop over remres1
        ##
        for remres1 in range((winsize - 1) / 2, N - winsize - (winsize - 1) / 2):

            resrange1 = range(remres1 - (winsize - 1) / 2, remres1 + (winsize - 1) / 2 + 1)
            l_c1 = []
            for res1 in resrange1:
                c1 = l_coordinates[res1]
                l_c1 += goodvibes_core.platonicsolid(c1, polyhedron=polyhedron)

            ## continue the remres1 loop if another processor is running calculations for that value of remres1
            filename = "%s/%s_residue%s.txt" % (paralleldir, jobid, remres1 + 1)
            datadic, Continue = goodvibes_core.multiple_cpus_read(datadic, filename, remres1)
            if Continue == True:
                continue

            ##
            ## loop over remres2
            ##
            for remres2 in range(remres1 + 2 * (winsize - 1) / 2 + 1, N - (winsize - 1) / 2):

                print remres1, remres2

                resrange2 = range(remres2 - (winsize - 1) / 2, remres2 + (winsize - 1) / 2 + 1)
                l_c2 = []
                for res2 in resrange2:
                    c2 = l_coordinates[res2]
                    l_c2 += goodvibes_core.platonicsolid(c2, polyhedron=polyhedron)

                l_add = []
                n_vertices = d_vertices[polyhedron]
                for i in range(n_vertices * (2 * winsize)):
                    l_add += [N + i]

                l_coordinates_perturbed = l_coordinates + l_c1 + l_c2

                matrix_hessian_perturbed = self.hessian_calculation(
                    N, matrix_distances, d_coordinates, float(cutoff_distance), l_coordinates_perturbed, verbose=verbose
                )

                (
                    eigenvectors_perturbed,
                    eigenvalues_perturbed,
                    eigenvectors_perturbed_combined,
                ) = goodvibes_core.eigenv_calccomb(matrix_hessian_perturbed, jobid, verbose)

                (
                    overlaps_single,
                    max_overlaps_single,
                    perturbed_modes_of_max_overlap_single,
                    delta_perturbed_eigenvalues_of_max_overlap,
                ) = goodvibes_core.overlap_calculation(
                    eigenvectors_perturbed,
                    eigenvectors_nonperturbed,
                    eigenvalues_perturbed,
                    eigenvalues_nonperturbed,
                    l_add=l_add,
                )

                (
                    overlaps_combined,
                    max_overlaps_combined,
                    perturbed_modes_of_max_overlap_combined,
                ) = goodvibes_core.overlap_calculation(
                    eigenvectors_perturbed_combined,
                    eigenvectors_nonperturbed,
                    eigenvalues_perturbed,
                    eigenvalues_nonperturbed,
                    l_add=l_add,
                )[
                    :-1
                ]
                print overlaps_single[6]

                ##        ## do vmd of perturbed structure
                ##        self.morph(eigenvectors, frames, biomolecule, d_coordinates, atoms_hessian, cluster, matrix_hessian, jobid+'-'+str(xvalue)+'-'+str(yvalue), cutoff_distance)

                datadic_loop = {
                    "eigenvalues_perturbed": eigenvalues_perturbed,
                    "emo": delta_perturbed_eigenvalues_of_max_overlap,
                    "overlaps_single": overlaps_single,
                    "overlaps_max": max_overlaps_single,
                    "mmo": perturbed_modes_of_max_overlap_single,
                    "overlaps_combined": overlaps_combined,
                }
                for key in datadic:
                    for mode in range(6, 12):
                        datadic[key]["data"][mode][remres1][remres2] = datadic_loop[key][mode]
                        datadic[key]["data"][mode][remres2][remres1] = datadic_loop[key][mode]
                datadic["overlaps_combined"]["data"][-1][remres1][remres2] = overlaps_combined[-1]
                datadic["overlaps_combined"]["data"][-1][remres2][remres1] = overlaps_combined[-1]

            ## write data to txt files in case of crash during loop over residues/clusters
            filename = "%s/%s_residue%s.txt" % (paralleldir, jobid, remres1 + 1)
            goodvibes_core.multiple_cpus_write(datadic, filename, remres1)

        ##
        ## do plots for perturbation results
        ##
        if verbose == True:
            print "generating plots"
        goodvibes_core.post_perturbation_plot(
            datadic, jobid, chains, cutoff_distance, d_hessian, N, d_secondary, d_coordinates, winsize=winsize
        )

        return
    def main(
        self, jobid, lines, atoms_hessian = ['CA'], frames = 50,
        cutoff_distance = 10.,
        path_python = None, verbose = False, paralleldir = '',
        biomolecule = None, chains = [], model = None,
        winsize = 1,
        pre_perturbation_plot = True,
        ):

        '''
        Use first model if no model specified by user.
        chain(s): Y, biomolecule: Y; parse chains specified by user and apply transformation
        chain(s): Y, biomolecule: N; parse chains specified by user but don't apply transformation
        chain(s): N, biomolecule: Y; parse chains of biomolecule and apply transformation
        chain(s): N, biomolecule: N; parse chains of first biomolecule and apply transformation
        '''

        import os, Numeric, goodvibes_core

        results = []

        ## parse pdb
        (
            d_REMARK350,
            d_primary, ## i.e. SEQRES, MODRES
            d_secondary, ## i.e. HELIX, SHEET
            d_coordinates, ## i.e. ATOM, HETATM, TER, MODEL, ENDMDL
            d_ligands,
            ) = goodvibes_core.parse_pdb(lines, chains)

        ## assume multimeric biological unit if chains not specified by user
        if chains == []:
            chains = d_coordinates['chains'].keys()
            chains.sort()

        ##
        ## calculate N and convert coordinates from dic to list
        ##
        N, d_hessian, l_coordinates = goodvibes_core.parse_dictionary_of_coordinates(d_coordinates, chains, atoms_hessian)

        ##
        ## calculate distance matrix
        ##
        matrix_distances = goodvibes_core.calculate_distance_matrix(l_coordinates)

        ##
        ## calculate hessian matrix
        ##
        matrix_hessian = self.hessian_calculation(N, d_coordinates, chains, atoms_hessian, float(cutoff_distance), d_secondary, matrix_distances, l_coordinates, verbose = verbose)

        ##
        ## diagonalize hessian matrix
        ##
        eigenvectors_nonperturbed, eigenvalues_nonperturbed, eigenvectors_comb_nonperturbed, = goodvibes_core.eigenv_calccomb(
                matrix_hessian, jobid, verbose,
                )

        ##
        ## visualize eigenvectors
        ##
        goodvibes_core.morph(
            eigenvectors_nonperturbed, frames, chains, d_coordinates,
            jobid, d_primary,
            )

        ##
        ## do plots prior to perturbation
        ##
        if pre_perturbation_plot == True:
            goodvibes_core.pre_perturbation_plot(
                jobid,cutoff_distance,chains,d_secondary,
                eigenvectors_nonperturbed,eigenvectors_comb_nonperturbed,
                )

        ##
        ## set data lists and append matrices to be plotted for each combination of modes 6-12 before initiating loops over the two axes of the plot
        ##
        range2 = range(1,13,2)
        datadic = goodvibes_core.datadic_return(N,range2=range2,)

        ##
        ## loop over remres1
        ##
        for remres1 in range(N):

            ##
            ## continue the remres1 loop if another processor is running calculations for that value of remres1
            ##
            filename = '%s/%s_residue%s.txt' %(paralleldir, jobid, remres1+1)
            datadic, Continue = goodvibes_core.multiple_cpus_read(datadic,filename,remres1)
            if Continue == True:
                continue

            ##
            ## loop over winsize
            ##
            for remres2 in range2:

                winsize = remres2

                print remres1, winsize

                if remres1-(winsize-1)/2 < 0 or remres1+(winsize-1)/2 > N-1:
                    continue

                l_rem = range(remres1-(winsize-1)/2,remres1+(winsize+1)/2)
                print '*****', l_rem

                ##
                ## remove selected alpha carbon atoms!!!
                ##
                l_coordinates_perturbed = []
                for res in range(len(l_coordinates)):
                    if res not in l_rem:
                        l_coordinates_perturbed += [l_coordinates[res]]
            
                matrix_hessian_perturbed = self.hessian_calculation(
                    N-len(l_rem), d_coordinates, chains, atoms_hessian, float(cutoff_distance), d_secondary, matrix_distances, l_coordinates_perturbed, verbose = verbose,
                    )

                (
                    eigenvectors_perturbed, eigenvalues_perturbed, eigenvectors_perturbed_combined,
                    ) = goodvibes_core.eigenv_calccomb(
                        matrix_hessian_perturbed, jobid, verbose
                        )

                (
                    overlaps_single, max_overlaps_single, perturbed_modes_of_max_overlap_single, delta_perturbed_eigenvalues_of_max_overlap,
                    ) = goodvibes_core.overlap_calculation(
                        eigenvectors_perturbed, eigenvectors_nonperturbed, eigenvalues_perturbed, eigenvalues_nonperturbed, l_rem = l_rem,
                        )

                (
                    overlaps_combined, max_overlaps_combined, perturbed_modes_of_max_overlap_combined,
                    ) = goodvibes_core.overlap_calculation(
                        eigenvectors_perturbed_combined, eigenvectors_nonperturbed, eigenvalues_perturbed, eigenvalues_nonperturbed, l_rem = l_rem,
                        )[:-1]

                datadic_loop = {
                    'eigenvalues_perturbed': eigenvalues_perturbed,
                    'emo': delta_perturbed_eigenvalues_of_max_overlap,
                    'overlaps_single': overlaps_single,
                    'overlaps_max': max_overlaps_single,
                    'mmo': perturbed_modes_of_max_overlap_single,
                    'overlaps_combined': overlaps_combined
                    }
                for key in datadic:
                    for mode in range(6,12):
                        datadic[key]['data'][mode][remres1][remres2] = datadic_loop[key][mode]
                        datadic[key]['data'][mode][remres2][remres1] = datadic_loop[key][mode]
                datadic['overlaps_combined']['data'][-1][remres1][remres2] = overlaps_combined[-1]
                datadic['overlaps_combined']['data'][-1][remres2][remres1] = overlaps_combined[-1]

                print overlaps_single[6]

            ##
            ## write data to txt files in case of crash during loop over residues/clusters
            ##
            filename = '%s/%s_residue%s.txt' %(paralleldir, jobid, remres1+1)
            goodvibes_core.multiple_cpus_write(datadic,filename,remres1)

        ##
        ## do plots for perturbation results
        ##
        if verbose == True:
            print 'generating plots'
        goodvibes_core.post_perturbation_plot(
            datadic, jobid, chains, cutoff_distance, d_hessian, N, d_secondary, d_coordinates,
            winsize = winsize,
            )


        return
Пример #13
0
    def main(
        self, jobid, filename,
        atoms_hessian = ['CA'], frames = 50,
        cutoff_distance = 10.,
        path_python = None, verbose = False, paralleldir = '',
        biomolecule = None, chains = [], model = None,
        winsize = 1,
        pre_perturbation_plot = True,
        ):

        '''
        Use first model if no model specified by user.
        chain(s): Y, biomolecule: Y; parse chains specified by user and apply transformation
        chain(s): Y, biomolecule: N; parse chains specified by user but don't apply transformation
        chain(s): N, biomolecule: Y; parse chains of biomolecule and apply transformation
        chain(s): N, biomolecule: N; parse chains of first biomolecule and apply transformation
        '''

        import os, Numeric, goodvibes_core

        results = []

        fd = open(filename,'r')
        lines = fd.readlines()
        fd.close()

        ## parse pdb
        (
            d_REMARK350,
            d_primary, ## i.e. SEQRES, MODRES
            d_secondary, ## i.e. HELIX, SHEET
            d_coordinates, ## i.e. ATOM, HETATM, TER, MODEL, ENDMDL
            d_ligands,
            ) = goodvibes_core.parse_pdb(lines, chains)

        ## assume multimeric biological unit if chains not specified by user
        if chains == []:
            chains = d_coordinates['chains'].keys()
            chains.sort()

        ##
        ## calculate N and convert coordinates from dic to list
        ##
        N, d_hessian, l_coordinates = goodvibes_core.parse_dictionary_of_coordinates(d_coordinates, chains, atoms_hessian)

        ##
        ## calculate distance matrix
        ##
        matrix_distances = goodvibes_core.calculate_distance_matrix(l_coordinates)

        ##
        ## calculate hessian matrix
        ##
        matrix_hessian = self.hessian_calculation(N, d_coordinates, chains, atoms_hessian, float(cutoff_distance), d_secondary, matrix_distances, l_coordinates, verbose = verbose)

        ##
        ## diagonalize hessian matrix
        ##
        eigenvectors_nonperturbed, eigenvalues_nonperturbed, eigenvectors_comb_nonperturbed, = goodvibes_core.eigenv_calccomb(
                matrix_hessian, jobid, verbose,
                )

        ##
        ## set data lists and append matrices to be plotted for each combination of modes 6-12 before initiating loops over the two axes of the plot
        ##
        datadic = goodvibes_core.datadic_return(N)

        ##
        ## loop over remres1
        ##
        for remres1 in range((winsize-1)/2,N-winsize-(winsize-1)/2):

            ##
            ## loop over remres2
            ##
            for remres2 in range(remres1+2*(winsize-1)/2+1,N-(winsize-1)/2):

                print remres1, remres2

                l_rem = []
                for i in range(-(winsize-1)/2,(winsize+1)/2):
                    l_rem += [remres1+i,remres2+i]
                l_rem.sort()

                ##
                ## remove selected alpha carbon atoms!!!
                ##
                l_coordinates_perturbed = l_coordinates[:remres1-(winsize-1)/2]+l_coordinates[remres1+1+(winsize-1)/2:remres2-(winsize-1)/2]+l_coordinates[remres2+1+(winsize-1)/2:]
            
                matrix_hessian_perturbed = self.hessian_calculation(
                    N-len(l_rem), d_coordinates, chains, atoms_hessian, float(cutoff_distance), d_secondary, matrix_distances, l_coordinates_perturbed, verbose = verbose,
                    )

                (
                    eigenvectors_perturbed, eigenvalues_perturbed, eigenvectors_perturbed_combined,
                    ) = goodvibes_core.eigenv_calccomb(
                        matrix_hessian_perturbed, jobid, verbose
                        )

                (
                    overlaps_single, max_overlaps_single, perturbed_modes_of_max_overlap_single, delta_perturbed_eigenvalues_of_max_overlap,
                    ) = goodvibes_core.overlap_calculation(
                        eigenvectors_perturbed, eigenvectors_nonperturbed, eigenvalues_perturbed, eigenvalues_nonperturbed, l_rem
                        )

                (
                    overlaps_combined, max_overlaps_combined, perturbed_modes_of_max_overlap_combined,
                    ) = goodvibes_core.overlap_calculation(
                        eigenvectors_perturbed_combined, eigenvectors_nonperturbed, eigenvalues_perturbed, eigenvalues_nonperturbed, l_rem,
                        )[:-1]

                datadic_loop = {
                    'eigenvalues_perturbed': eigenvalues_perturbed,
                    'emo': delta_perturbed_eigenvalues_of_max_overlap,
                    'overlaps_single': overlaps_single,
                    'overlaps_max': max_overlaps_single,
                    'mmo': perturbed_modes_of_max_overlap_single,
                    'overlaps_combined': overlaps_combined
                    }
                for key in datadic:
                    for mode in range(6,12):
                        datadic[key]['data'][mode][remres1][remres2] = datadic_loop[key][mode]
                        datadic[key]['data'][mode][remres2][remres1] = datadic_loop[key][mode]
                datadic['overlaps_combined']['data'][-1][remres1][remres2] = overlaps_combined[-1]
                datadic['overlaps_combined']['data'][-1][remres2][remres1] = overlaps_combined[-1]

                print overlaps_single[6]

        l_averages = []
        for remres1 in range(len(datadic['overlaps_single']['data'][6])):
            l_overlaps = []
            for remres2 in range(len(datadic['overlaps_single']['data'][6][remres1])):
                overlap = datadic['overlaps_single']['data'][6][remres1][remres2]
                l_overlaps += [overlap]
            l_averages += [sum(l_overlaps)/len(l_overlaps)]

        return l_averages