コード例 #1
0
ファイル: writeFile.py プロジェクト: ABorrel/ionic
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
コード例 #2
0
ファイル: writeFile.py プロジェクト: ABorrel/ionic
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)