mardi 2 mars 2021

python: filter based on IF condition

I am operating with simple python condition aimed at filtering of the values > or equal to zero, and store filtered values in the list

  # make a object contained all clusters
    clustering = d.clusterer.clustering_dict[cut_off]
    # list of ignored objects
    banned_conf=[]
 for clust in clustering:
        clustStr = str(clustering.index(clust))
        clustStr = int(clustStr) + 1
        # get the value of energy for the clust
        ener=clust[0].energy
        # set up filter to ignore conformations with positive energies
        if ener > 0:
            print('Conformation in ' + str(clustStr) + ' cluster poses positive energy')
            banned_conf.append(ener)
            print('Nonsence: It is ignored!')
            continue
        elif ener == 0:
            print('Conformation in ' + str(clustStr) + ' cluster poses ZERO energy')
            banned_conf.append(ener)
            print('Very rare case: it is ignored!')
            continue
        #else:
            #print("Ain't no wrong conformations in "  + str(clustStr) + " cluster")

How would it be possible to ignore all values > or = 0 within the same IF statement (without elif)? Which filtering would be better (with elif or in single IF statement)?

Aucun commentaire:

Enregistrer un commentaire