Skip to content

Commit

Permalink
Some Python 3 compatibility fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
benmwebb committed Oct 3, 2023
1 parent 5896bb0 commit efc54d5
Showing 47 changed files with 1,059 additions and 1,012 deletions.
13 changes: 7 additions & 6 deletions benchmark.py
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
SOAP benchmark module, calculating statistics on the scores.
"""
from __future__ import print_function
from env import *
from decoys import DecoySets
from rankScores import dsscore
@@ -77,8 +78,8 @@ def analyze_score(self,slevel='NativeSelection',dsscoreo=[],score=[], report='si

def report_stats(self,report):
csa=np.copy(self.statsarray)
#print csa
#print csa.mean()
#print(csa)
#print(csa.mean())
rv=0
#report a single number indicating the performance of the potential
for i in range(self.numofc):
@@ -351,7 +352,7 @@ def analyze_topmodels(self):
lowestctn=bottleneck.argpartsort(score,ctn)
lsind=np.argsort(score[lowestctn[:ctn]])
sortind=lowestctn[:ctn][lsind]
#print rmsds[sortind]
#print(rmsds[sortind])
for k,tpc in enumerate(topcd):
#set up filter:
if tpc['cf']:
@@ -366,10 +367,10 @@ def analyze_topmodels(self):
if tpc['cfd']['firstonly'] and len(bni)>0:
#if self.ds.codelist[i].endswith('1I2M'):
# pdb.set_trace()
# print self.ds.codelist[i]+' '+str(bni[0])+' '+str(rmsds['rmsd'][sortind[bni[0]]])+' '+str(rmsds['irmsd'][sortind[bni[0]]])
# print(self.ds.codelist[i]+' '+str(bni[0])+' '+str(rmsds['rmsd'][sortind[bni[0]]])+' '+str(rmsds['irmsd'][sortind[bni[0]]]))
bni=bni[0:1]
#else:
# print self.ds.codelist[i]+' '+str(-1)+' '+str(0)+' '+str(0)
# print(self.ds.codelist[i]+' '+str(-1)+' '+str(0)+' '+str(0))
else:
bni=range(0,tn[k])# index list for the sortind
#calculate property
@@ -424,7 +425,7 @@ def analyze_topmodels(self):
statsarray[tpc['ctsn']]=len(pa)>0
else:
raise Exception('can not handle benchmark criteria cs '+str(tpc['cs']))
#print self.statsarray
#print(self.statsarray)

def analyze_score_0(self):
#calculate benchmark statistics based on scores
25 changes: 13 additions & 12 deletions clustering.py
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
SOAP clustering module, for clustering recovery functions.
"""
from __future__ import print_function
import numpy as np
import scipy.cluster

@@ -31,7 +32,7 @@ def find_overlap(self,region):
return []

def get_pars_in_range(self,min2,max2):
print "not working"
print("not working")
pdb.set_trace()
ai=[]
for i in range(0,len(self.pars)):
@@ -72,7 +73,7 @@ def get_closest_to(self,value):
return self.pars[parindex]

def get_bestpar_close_to(self,value):
print "accessing middle of the cluster"
print("accessing middle of the cluster")
if self.allclusters.optscorer.assess_rrf(np.log(self.middle))==self.bestresult:
return value
else:
@@ -175,7 +176,7 @@ def find_overlap(self,regions):

def analyze(self):
if len(set(self.results))==1:
print "!!!!!!!!!!Search returns the same results for all the values tried!!!!!!!!!!!"
print("!!!!!!!!!!Search returns the same results for all the values tried!!!!!!!!!!!")
self.pickedpar=np.log(self.pars.mean(axis=0))
self.bestmodelresult=self.optscorer.assess_rrf(self.pickedpar,report='full')
self.testresult=self.testscorer.assess_rrf(self.pickedpar)
@@ -186,7 +187,7 @@ def analyze(self):
self.clustering_bestpars()
self.pick_best_cluster(self.clusters)
self.get_pickedpar()
print 'Best result '+str(self.bestresult)
print('Best result '+str(self.bestresult))
self.optscorer.assess_rrf(self.pickedpar)
if self.hasscorer:
self.testresult=self.testscorer.assess_rrf(self.pickedpar)
@@ -415,20 +416,20 @@ def analyze(self):
i=0
for optcluster in self.optclusterlist:
i=i+1
print "Analyzing cluster #"+str(i)
print("Analyzing cluster #"+str(i))
optcluster.analyze()

def find_overlap(self):
region=self.optclusterlist[-1].get_pars_region()
for optcluster in self.optclusterlist:
region=optcluster.clustering(region)
if region==[]:
print "No overlap regions"
print("No overlap regions")
break
return region

def plot(self):
print "ploting...... (can take a while)"
print("ploting...... (can take a while)")
ph=self.plot_all_bestpars()
ph.savefig(self.figpath+'all_bestpars.eps')
ph2,ph3=self.optclusterlist[-1].plot()
@@ -469,7 +470,7 @@ def dump(self,path):
fh.close()

def get_representative_pars(pars, cutoffdistance=0.001, maxcluster=0):
#print "orinial number: "+str(len(pars))
#print("orinial number: "+str(len(pars)))
if pars.shape[0]<10:
return range(len(pars))
pars=np.round(pars,4)
@@ -486,7 +487,7 @@ def get_representative_pars(pars, cutoffdistance=0.001, maxcluster=0):
for i in range(1,noc+1):
rl=np.nonzero(ca==i)[0]
rac.append(rl[0])
#print "representative par number: "+str(len(rac))+' at distance '+str(cutoffdistance)
#print("representative par number: "+str(len(rac))+' at distance '+str(cutoffdistance))
return rac

def get_representative_pars_maxlength(pars, cutoffdistance=0.001, maxlength=5000,maxcluster=5000):
@@ -499,12 +500,12 @@ def get_representative_pars_maxlength(pars, cutoffdistance=0.001, maxlength=5000
pars=np.random.permutation(pars)
nal=[]
apl=range(0,parshape[0],prn)+[parshape[0]]
print "total orinial number: "+str(parshape[0])
print("total orinial number: "+str(parshape[0]))
for i in range(0,numofrun):
spars=pars[apl[i]:apl[i+1]]
nal.append(spars[get_representative_pars(spars[:,:-1],cutoffdistance,maxcluster=int(takepercentage*(apl[i+1]-apl[i])))])
na=np.vstack(nal)
print "total representative par number: "+str(len(na))+' at distance '+str(cutoffdistance)+' max '+str(maxcluster)
print("total representative par number: "+str(len(na))+' at distance '+str(cutoffdistance)+' max '+str(maxcluster))
return na

def get_representative_pars_maxcluster(pars, cutoffdistance=0.001, maxlength=5000,maxcluster=5000):
@@ -532,7 +533,7 @@ def get_representative_pars_forall(na,distanceratio=0,maxcluster=5000,cutoffdist
spars=pars[fm]
pr=result[fm]
sparindex=parindex[fm]
print "reducing for performance pars "+str(res)
print("reducing for performance pars "+str(res))
na=get_representative_pars_maxcluster(spars,cutoffdistance=(cutoffdistance+(1-res)*distanceratio),maxcluster=maxcluster)
pl.append(np.hstack((na,ar.min()+res*(ar.max()-ar.min())*np.ones([na.shape[0],1]))))
return np.vstack(pl)
Loading

0 comments on commit efc54d5

Please sign in to comment.