Пример #1
0
class Data:

    index_ligand = []
    index_receptor = []
    cg_atoms = []

    def __init__(self, params):

        self.ligand = Protein()
        self.ligand.import_pdb(params.ligand_file_name)

        self.receptor = Protein()
        self.receptor.import_pdb(params.receptor_file_name)

        self.cg_atoms = []

        if params.energy_type == "vdw":
            [self.index_ligand, self.index_receptor] = self.get_index(["CA", "CB"])

    def get_index(self, atoms=["CA", "CB"]):

        # generate a dummy assembly and extract the indexes where atoms of interest are located
        assembly = A.Assembly(self.ligand, self.receptor)
        assembly.place_ligand(np.array([0.0, 0.0, 0.0, 0.0, 0.0, 0.0]))

        ligand_index = []
        receptor_index = []
        for aname in atoms:
            # append indexes of an element in atoms list for ligand
            [m, index] = assembly.atomselect_ligand("*", "*", aname, True)
            for i in index:
                ligand_index.append(i)

                # append indexes of an element in atoms list for receptor
            [m, index] = assembly.atomselect_receptor("*", "*", aname, True)
            for i in index:
                receptor_index.append(i)

        return [ligand_index, receptor_index]
Пример #2
0
class Structure():

    def __init__ (self):
            # initialising the values
        self.monomer = "NA" # the monomeric unit
        self.pdb_file_name = "NA"
        self.index_CA_monomer = "NA"
        self.flexibility = "NA"
        self.init_coords = "NA"

    def read_pdb (self, pdb):
        self.pdb_file_name = pdb
        self.monomer = Protein()
        self.monomer.import_pdb(pdb)
        self.init_coords = self.monomer.get_xyz()

    def compute_PCA (self, topology,trajectory,align,ratio,mode, proj_file):
        self.flexibility = F.Flexibility_PCA()
        self.flexibility.compute_eigenvectors(topology,trajectory,align,ratio,mode, proj_file)


    def setCoords (self):
        self.init_coords = self.monomer.get_xyz()
Пример #3
0
class Data:

    index_ligand=[]
    index_receptor=[]
    cg_atoms=[]

    def __init__(self,params):

        self.structure_hash = {}
        self.structure_list = []
        volume_structure_hash = {} # this is used to get the biggest structure


        # GIORGIO_CODE create structure instances of the rigid monomers
        for nickName,pdb_file in params.monomer_file_name:
            # create instance of the structure class
            s = Structure()
            s.read_pdb (pdb_file)

            volume_structure_hash[len(s.monomer.get_xyz())] = [s, nickName]


        # create structure instance for the flexible monomers
        if params.assembly_style=="flexible":
            print ">> flexible docking requested for structures, launching PCA..."

            for nickName, traj_file in params.trajectory:
                try:
                    # get the topology file:
                    for nickName2, top_file in params.topology:
                        if nickName2 == nickName:
                            break

                    # create the structure and compute the PCA
                    s = Structure()
                    s.compute_PCA(top_file, traj_file, params.align, params.ratio, params.mode, params.proj_file)
                    s.read_pdb("protein.pdb")

                    volume_structure_hash[len(s.monomer.get_xyz())] = [s, nickName]

                except ImportError, e:
                    sys.exit(1)

                # TODO: work on the deform mode, but ask Matteo before
                if params.mode=="deform":
                    self.structure_ligand=Protein()
                    self.structure_ligand.import_pdb("protein.pdb")
                    self.ligand.import_pdb("CA.pdb")

        # getting the biggest structure and putting at the beginning so that it is fixed
        sorted_volumes = volume_structure_hash.keys()
        sorted_volumes.sort()
        sorted_volumes.reverse()

        for i in sorted_volumes:

            # insert the elements in a list
            self.structure_list.append( volume_structure_hash[i][0] ) # insert the structure
            self.structure_hash[volume_structure_hash[i][1]] = self.structure_list.index(volume_structure_hash[i][0])

        self.structure_list_and_name = [self.structure_list, self.structure_hash]
        print self.structure_list_and_name

        #LIGAND STRUCTURE
        #self.ligand = Protein()

#               if params.assembly_style=="flexible":
#                       print ">> flexible docking requested for ligand, launching PCA..."
#                       try:
#                               self.flex_ligand=F.Flexibility_PCA()
#                               self.flex_ligand.compute_eigenvectors(params.ligand_topology,params.ligand_trajectory,params.ligand_align,params.ligand_ratio,params.mode,params.ligand_proj_file)
#                               self.ligand.import_pdb("protein.pdb") # importing the middle structure
#                       except ImportError, e:
#                               sys.exit(1)
#
#                       if params.mode=="deform":
#                               self.structure_ligand=Protein()
#                               self.structure_ligand.import_pdb("protein.pdb")
#                               self.ligand.import_pdb("CA.pdb")

        #else:
            #load monomeric structure (the pdb file)
            #self.ligand.import_pdb(params.ligand_file_name)

        if params.energy_type=="vdw":
            self.CA_index_of_structures = self.get_index(["CA"])
            #[self.index_ligand,self.index_receptor]=self.get_index(["CA","CB"])

        # if the density map docking is on load the structure into data:
        if params.map_dock_OnOff:
            self.density_map_fileName = params.density_map
Пример #4
0
    def run(self):

        exec "import %s as constraint" % (self.constraint)

        # create output directory for generated PDB
        self.OUTPUT_DIRECTORY = "result"
        if os.path.isdir(self.OUTPUT_DIRECTORY) != 1:
            os.mkdir(self.OUTPUT_DIRECTORY)

        clusters_file = open("%s/solutions.dat" % self.params.output_folder, "w")

        # use superclass method to filter acceptable solutions
        self.log = self.select_solutions(self.params)
        print ">> %s solutions filtered" % len(self.log)
        if len(self.log) == 0:
            return

        # generate a dummy multimer and extract the indexes of C alpha
        multimer = A.Assembly(self.data.ligand, self.data.receptor, self.data.cg_atoms)
        multimer.place_ligand(np.array([0.0, 0.0, 0.0, 0.0, 0.0, 0.0]))
        [m, index] = multimer.atomselect_ligand("*", "*", "CA", True)

        # load the monomeric structure positions
        s = Protein()
        s.import_pdb(self.params.ligand_file_name)
        coords = s.get_xyz()

        print ">> clustering best solutions..."
        P = self.log[:, 0 : len(self.log[0, :])]  # points list
        V = self.log[:, -1]  # values of best hits
        C = []  # centroids array
        P_C = np.zeros(len(P))  # points-to-cluster mapping
        C_V = []  # centroids values
        cnt = 0  # centroids counter

        # cluster accepted solutions
        while True:
            # check if new clustering loop is needed
            k = np.nonzero(P_C == 0)[0]
            if len(k) != 0:
                cnt = cnt + 1
                P_C[k[0]] = cnt
                a = P[k[0]]
                C.append(a)
            else:
                break

                # create multimer
            pos = np.array(C[cnt - 1])[0:6].astype(float)
            multimer1 = A.Assembly(self.data.ligand, self.data.receptor, self.data.cg_atoms)
            multimer1.place_ligand(pos)

            # write multimer
            multimer1.write_PDB("%s/assembly%s.pdb" % (self.OUTPUT_DIRECTORY, cnt))

            # clustering loop
            m1 = multimer1.get_ligand_xyz()[index]
            cnt2 = 1
            for i in xrange(0, len(k), 1):

                self.data.ligand.set_xyz(coords)
                # multimer2 = A.Assembly(self.data.ligand)
                multimer2 = A.Assembly(self.data.ligand, self.data.receptor, self.data.cg_atoms)
                multimer2.place_ligand(
                    np.array([P[k[i]][0], P[k[i]][1], P[k[i]][2], P[k[i]][3], P[k[i]][4], P[k[i]][5]])
                )
                m2 = multimer2.get_ligand_xyz()[index]

                rmsd = self.align(m1, m2)

                if rmsd < self.params.cluster_threshold:
                    cnt2 += 1
                    P_C[k[i]] = cnt

            print ">>> clustered %s solutions on multimer %s" % (cnt2, cnt)

            # set centroid score with score of closes neighbor in set
            q = np.nonzero(P_C == cnt)[0]
            distance = 10000
            targ = 0
            for i in xrange(0, len(q), 1):
                d = np.sqrt(np.dot(C[cnt - 1] - P[q[i]], C[cnt - 1] - P[q[i]]))
                if d < distance:
                    distance = d
                    targ = q[i]
            C_V.append(V[targ])

            # extract constraint values calculated for selected centroid
            measure = constraint.constraint_check(multimer1)

            ###generate output log (prepare data and formatting line, then dump in output file)###
            l = []
            f = []
            for item in C[cnt - 1][0 : len(C[cnt - 1]) - 1]:
                l.append(item)
                f.append("%8.3f ")
                # write constraint values
            f.append("| ")
            for item in measure:
                l.append(item)
                f.append("%8.3f ")
                # write fitness
            f.append("| %8.3f\n")
            l.append(C_V[cnt - 1])

            formatting = "".join(f)

            clusters_file.write(formatting % tuple(l))

        clusters_file.close()

        ####generate output log###
        ##write solution values
        # for item in C[cnt-1]:
        #    clusters_file.write("%s "%item)
        ##write constraint values
        # for item in measure:
        #    clusters_file.write("%s "%item)
        ##write fitness
        # clusters_file.write("%s\n"%C_V[cnt-1])

        return