Example #1
0
def proportionByPositionNeighbors (stCount, pr_result):

    l_out = []    
    l_typeatom = structure.classificationATOM("", out_list= 1)

    # directory result
    for substruct in stCount.keys() : 
        p_filout = pr_result + "proportion_" + substruct
        l_out.append (p_filout)
        
        filout = open(p_filout, "w")
        filout.write ("\t".join(l_typeatom) + "\n")
        for nb_neighbor in range(1,8) : 
            if not nb_neighbor in stCount[substruct].keys () : 
                continue
            else : 
                filout.write(str(nb_neighbor))
                print substruct, nb_neighbor
                print stCount[substruct][nb_neighbor]
                sum_neighbor = tool.sumDict(stCount[substruct][nb_neighbor])
                for class_atom in l_typeatom :
                    filout.write("\t" + str(stCount[substruct][nb_neighbor][class_atom] / sum_neighbor)) 
                filout.write("\n")
        filout.close ()
    return l_out
Example #2
0
def amine(listAmine, count):
    """Count numbers of neighbor with atom type
    in: list atom global
    out: count with keys -> numbers of neighbors"""
    
    for type in listAmine.keys():
        for nitrogen in listAmine[type]:
            nbNeighbor = numberNeigthbor(nitrogen["neighbors"])
            
            for neighbor in nitrogen["neighbors"]:
                neighbor_classif = structure.classificationATOM(neighbor)
                count[type]["allNumberNeighbors"][neighbor_classif] = count[type]["allNumberNeighbors"][neighbor_classif] + 1
                
                if not nbNeighbor in count[type].keys():
                    count[type][nbNeighbor] = structure.countClassificationAtoms()
                if not nbNeighbor in count["GlobalAmine"].keys():
                    count["GlobalAmine"][nbNeighbor] = structure.countClassificationAtoms()


                if neighbor_classif in count[type][nbNeighbor].keys():
                    count[type][nbNeighbor][neighbor_classif] = count[type][nbNeighbor][neighbor_classif] + 1
                    count["GlobalAmine"][nbNeighbor][neighbor_classif] = count["GlobalAmine"][nbNeighbor][neighbor_classif] + 1

                else:
                    count[type][nbNeighbor]["others"] = count[type][nbNeighbor]["others"] + 1
                    count["GlobalAmine"][nbNeighbor]["others"] = count["GlobalAmine"][nbNeighbor]["others"] + 1
Example #3
0
def barplotThreeAtomBarplot (countStruct, dir_out):
    """
    Barplot for distance function type atoms
    """
    l_typeatom = structure.classificationATOM("", out_list= 1)
    
    for substruct in countStruct.keys () : 
        for nb_neighbor in countStruct[substruct].keys() :
            if type (nb_neighbor) != type(int()) or countStruct[substruct][nb_neighbor]["distance"] == []:
                continue 
            filout = open (dir_out + "barplot_" + substruct + "_" + str(nb_neighbor), "w")
            
            # header
            filout.write ("\t".join(l_typeatom) + "\n")
            
            #count
            d_cout = {}
#             min_distance = min(countStruct[substruct][nb_neighbor]["distance"])
            max_distance = float(max(countStruct[substruct][nb_neighbor]["distance"]))
            
            d_temp = 2
            l_dist = []
            
            while d_temp <= max_distance + 0.4 : 
                l_dist.append (d_temp)
                
                d_cout[d_temp] = {}
                for classe_atom in l_typeatom : 
                    d_cout[d_temp][classe_atom] = 0
                
                # implement count struct
                i = 0
                len_neighbor = len (countStruct[substruct][nb_neighbor]["classe"])
                print d_temp
                while i < len_neighbor : 
                    
                    if float(countStruct[substruct][nb_neighbor]["distance"][i]) <= d_temp  and float(countStruct[substruct][nb_neighbor]["distance"][i]) > d_temp - 0.2 : 
                        d_cout[d_temp][countStruct[substruct][nb_neighbor]["classe"][i]] = d_cout[d_temp][countStruct[substruct][nb_neighbor]["classe"][i]] + 1
                    else : 
                        pass
                    
                    i = i + 1
                    
                d_temp = d_temp + 0.2

            
            for dist in l_dist : 
                filout.write (str (dist))
                for class_atom in l_typeatom : 
                    filout.write ("\t" + str(d_cout[dist][class_atom]))
                filout.write ("\n")
        filout.close ()
Example #4
0
def coordinates3DPDBbyNeighborType (l_atom_in, ll_atom_subs, subs, pr_init) : 
    
    d_file = {}
    l_type_neighbors = structure.classificationATOM (out_list = 1)
    l_atom_sub_ref =  structure.substructureCoord(subs)
    for type_neighbors in l_type_neighbors : 
        d_file[type_neighbors] = open (pr_init + subs + "_" + type_neighbors + ".pdb", "w")
        writePDBfile.coordinateSection(d_file [type_neighbors], l_atom_sub_ref , "HETATM") 
        
        #writePDBfile.coordinateSection(d_file [type_neighbors], ll_atom_subs[0] , "HETATM")
        
        #l_write = []
        #for l_atom_subs in ll_atom_subs : 
        #    writePDBfile.coordinateSection(d_file [type_neighbors], l_atom_subs , "HETATM")
#             l_write = l_write + l_atom_subs
#         writePDBfile.coordinateSection(d_file [type_neighbors], l_write , "HETATM")
    
    
    for atom in l_atom_in : 
        type_neighbor = structure.classificationATOM (atom)
        writePDBfile.coordinateSection(d_file [type_neighbor], [atom] , "ATOM", header = 0)
        
    for type_neighbors in l_type_neighbors : 
        d_file[type_neighbors].close ()
Example #5
0
def countFirstNeighbor (stCount, pr_result):
    
    l_typeatom = structure.classificationATOM("", out_list= 1)   
    filout = open (pr_result + "countFirst", "w")
    filout.write ("\t".join(l_typeatom) + "\n")
    
    for sub_struct in stCount.keys() : 
        filout.write (sub_struct)
        for class_atom in l_typeatom : 
            #print "***", stCount[sub_struct]
            try : filout.write("\t" + str(stCount[sub_struct][1][class_atom])) # first neighbors
            except : filout.write("\tNA") # first neighbors
        filout.write("\n")
    filout.close ()
    return [pr_result + "countFirst"]
Example #6
0
def resultNeighbor (countStruct, pr_result) : 
    """
    Three neighbors analysis -> write files
    """
    # distance list
    l_typeatom = structure.classificationATOM("", out_list= 1)
    
    # directory result
    for sub_struct in countStruct.keys() : 
        filout_neighbor = open (pr_result + "neighbor_" + sub_struct, "w")
        filout_neighbor_count = open (pr_result + "neighbor_count_" + sub_struct, "w")
        filout_distance = open (pr_result + "distance_" + sub_struct, "w")
        filout_angle = open (pr_result + "angle_neighbors" + sub_struct, "w")
        filout_neighbor.write ("\t".join(l_typeatom) + "\n")
        filout_neighbor_count.write ("\t".join(l_typeatom) + "\n")
        # barplot class of neighbors -> but not dynamic nb neighbor
        for nb_neighbor in range(1,8) : 
            if nb_neighbor == "angle1_2" or nb_neighbor == "angle2_3" or nb_neighbor == "angle1_3" : 
                continue
            filout_neighbor.write(str(nb_neighbor))
            filout_neighbor_count.write(str(nb_neighbor))
            filout_distance.write(str(nb_neighbor))
            sum_neigbor = tool.sumDict(countStruct[sub_struct][nb_neighbor])
            for class_atom in l_typeatom : 
                filout_neighbor.write("\t" + str(countStruct[sub_struct][nb_neighbor][class_atom] / sum_neigbor)) 
                filout_neighbor_count.write("\t" + str(countStruct[sub_struct][nb_neighbor][class_atom])) 
            filout_neighbor.write("\n")
            filout_neighbor_count.write("\n")
            filout_distance.write("\t" + "\t".join(countStruct[sub_struct][nb_neighbor]["distance"]) + "\n")
            filout_distance.write ("Classe\t" + "\t".join(countStruct[sub_struct][nb_neighbor]["classe"]) + "\n")
    
    
        # angles between neighbors
        nb_angle = len (countStruct[sub_struct]["angle1_2"])
        i = 0
        while i < nb_angle : 
            filout_angle.write (str (countStruct[sub_struct]["angle1_2"][i]) + "\t" +str (countStruct[sub_struct]["angle1_3"][i]) + "\t" +str (countStruct[sub_struct]["angle2_3"][i])  + "\n" )
            i = i + 1
    
    filout_distance.close ()
    filout_neighbor.close ()
    filout_neighbor_count.close ()
    filout_angle.close ()
    
    # write barplot file
    barplotThreeAtomBarplot (countStruct, pr_result)   
Example #7
0
def globalNeighbors (listAtom, count):
    """Count numbers of neighbor with atom type
    in: list atom global
    out: count with keys -> numbers of neighbors"""

    for atom in listAtom:
        nbNeighbor = numberNeigthbor(atom["neighbors"])
        for neighbor in atom["neighbors"]:
            # print count
            neighbor_classif = structure.classificationATOM(neighbor)
            count["allNumberNeighbors"][neighbor_classif] = count["allNumberNeighbors"][neighbor_classif] + 1
            if not nbNeighbor in count.keys():
                count[nbNeighbor] = structure.countClassificationAtoms()

            if neighbor_classif in count[nbNeighbor].keys():
                count[nbNeighbor][neighbor_classif] = count[nbNeighbor][neighbor_classif] + 1

            else:
                count[nbNeighbor]["others"] = count[nbNeighbor]["others"] + 1
Example #8
0
def neighbors(rayon, atom_central, pdb, subs = "global", l_atom_lig = [] ): # change the name because in the same time function and variable
    """Search neighbors for all ligand
    in : rayon where is atoms, central atom, pdb file
    out : list atoms found"""

    l_atom = []
    linesPDB = loadFile.openPdbFile(pdb)
    for line in linesPDB:
        if search("^ATOM", line) or search("^HETATM", line): 
            atom = parsing.lineCoords(line)
            if atom != {} and atom["element"] != "H":
                distance = calcul.distanceTwoatoms(atom_central, atom)
                if distance <= rayon and distance != 0.0:
                    if atom_central["resSeq"] != atom["resSeq"]: # check if variation
                        if tool.atomInList(l_atom, atom) == 0:
                            atom["distance"] = distance
                            atom["angleSubs"] = calcul.angleSubs(atom_central, atom, l_atom_lig, subs)
                            atom["classification"] = structure.classificationATOM(atom)
                            l_atom.append(atom)

    return l_atom
Example #9
0
def dAngleType (count, directory_in):
    
    listClasse = structure.classificationATOM("", out_list = 1)
    for type_substruct in count.keys() : 
        for distance in count[type_substruct].keys() : 
            pr_angle_type = pathManage.resultAngle(directory_in, type_substruct)
            filout = open(pr_angle_type + "angle_" + type_substruct + "_" + distance, "w")
            
            ### HEADER ###
            filout.write (str(listClasse[0]))
            for classe in listClasse[1:] : 
                filout.write ("\t" + classe)
            filout.write("\n")
            ##############
            
            for angleSubs in count[type_substruct][distance].keys() : 
                filout.write(str(angleSubs))
                for classe in listClasse : 
                    try : filout.write("\t" + str(count[type_substruct][distance][angleSubs][classe]))
                    except : filout.write("\t0")
                filout.write("\n")
        filout.close()    
Example #10
0
def colorAtomType (l_superimpose) : 
    
    for atom in l_superimpose : 
        type_atom = structure.classificationATOM(atom)
        if type_atom == "Oox" or type_atom == "Cox": 
            atom ["tempFactor"] = 100 - 8.33
        elif type_atom == "Oh" : 
            atom ["tempFactor"] = 100 - (2* 8.33)
        elif type_atom ==  "Oc": 
            atom ["tempFactor"] = 100 - (3* 8.33) 
        elif type_atom == "Car"  : 
            atom ["tempFactor"] = 100 - (7* 8.33)  
        elif type_atom == "Nam"  : 
            atom ["tempFactor"] = 100 - (8* 8.33)
        elif type_atom == "Nim"  : 
            atom ["tempFactor"] = 100 - (9* 8.33)
        elif type_atom == "Ngu" or type_atom == "NaI" or type_atom == "Cgu"  : 
            atom ["tempFactor"] = 100 - (9* 8.33)   
        elif type_atom == "Xot"  : 
            atom ["tempFactor"] = 100 - (11* 8.33) 
        elif type_atom == "Ow"  : 
            atom ["tempFactor"] = 100 - (12* 8.33)    
Example #11
0
def countNeighborsAll(stCount, pr_result):
    """
    -> need optimized to pass in argument the folder
    """
    l_typeatom = structure.classificationATOM("", out_list= 1)   
    filout_count = open (pr_result + "countAll", "w")
    filout_count.write ("\t".join(l_typeatom) + "\n")
    
    l_subs = structure.ListSub()
    l_subs.append ("global")
    
    for sub_struct in l_subs : 
        filout_count.write (sub_struct)
        for class_atom in l_typeatom : 
            count = 0
            for i_neighbor in stCount[sub_struct].keys () :
                print i_neighbor, ">-----<" 
                if type(stCount[sub_struct][i_neighbor]) == dict and class_atom in stCount[sub_struct][i_neighbor].keys () : 
                    count = count + stCount[sub_struct][i_neighbor][class_atom]
            filout_count.write("\t" + str(count)) # first neighbors
        filout_count.write("\n")
    filout_count.close ()
    return [pr_result + "countAll"]
Example #12
0
def coordinates3D (l_atom, p_filout, type_substruct) : 
    
    filout = open (p_filout, "w") 
    
    substruct =  structure.substructureCoord(type_substruct)
    
    for atom in substruct : 
        filout.write (str(atom["x"]) + "\t" + str(atom["y"]) + "\t" + str(atom["z"]) + "\t" + "REF" + "\n")
    
    for atom in l_atom : 
        if not "occupancy" in atom.keys () : 
            filout.write (str(atom["x"]) + "\t" + str(atom["y"]) + "\t" + str(atom["z"]) + "\t" + structure.classificationATOM (atom) + "\n")
    filout.close () 
    
    return  p_filout