Ejemplo n.º 1
0
def MakePlot(mask,title,filename):
  fig=plt.figure(figsize=(16, 12))
  fig.subplots_adjust(wspace=.15,right=.95, left=.05,top=.93, bottom=.05, hspace=.35)
  for iface_index,iface_name in enumerate(['X','Y','Z','XZ','XY','YZ']):
    ax = fig.add_subplot(3,2,iface_index+1)
    import commands
    files=commands.getoutput(mask %iface_name).split()
    
    for index, file in enumerate(files):
      residues=file.split('_')
      residues=[i for i in residues if 'ASU' in i]
      residues=residues[0].split('ASU')
      data=genfromtxt(file)
      plot_label=[i for i in file.split('_') if 'ASU' in i][0]
      ax.plot(data[1:,0]*0.2,smooth(data[:,1],50),colors[index],linewidth=2,label=plot_label)
    
    ax.plot ([1,data[-1,0]*0.2],[data[0,1],data[0,1]],'k',linewidth=2) 
    for label in ax.xaxis.get_ticklabels():
      label.set_fontsize(8)
    for label in ax.yaxis.get_ticklabels():
      label.set_fontsize(8)
    plt.title(title %iface_name,fontsize=12)
    plt.xlabel('Time (ns)',fontsize=8, labelpad=0)
    #ax.set_xticklabels([0,1.0,2.0,3.0,4.0,5.0])
    plt.ylabel(r"Distace ($\AA$)",fontsize=8, labelpad=0)
    #~ plt.ylim((0,6))
    #plt.xlim(xmax=51) #modify to trajectory length
    ax.yaxis.set_ticks_position('left')
    ax.xaxis.set_ticks_position('bottom')
    for line in ax.get_xticklines() + ax.get_yticklines():
      line.set_markeredgewidth(4)
      line.set_markersize(10)
    from matplotlib.font_manager import fontManager, FontProperties
    font=FontProperties(size=8)
    if iface_index==5:
      ax.legend(bbox_to_anchor=(0, 0, 1.1, .3),prop=font,ncol=3)
  #~ plt.show()
  plt.savefig(filename) 
totalp=0.0
contactp=0
print "crystal contacts:"
for i in range(len(contact_names)):
    name=contact_names[i]
    data=all_data[:,i]
    totalp+=average(data)
    if data[-1]==ASUS:
      print name
      is_cryst=1
    else:
      is_cryst=0
    if average(data) <4 and is_cryst!=1:
        continue
    fig=plt.figure(figsize=(16, 12))
    plt.ylim((0,ASUS+1))
    ax = fig.add_subplot(111)  
    ax.plot(smooth(data,10),'k')
    plt.title('%s' %name, fontsize=24)
    fig.suptitle('%s' %iface, fontsize=18)
    plt.legend(["%5.2f" %average(data)])
    contactp+=1
    if is_cryst:
      plt.annotate('crystal contact',xy=(5000,12.1), xytext=(5000,12.1),fontsize=18)
    plt.savefig('residContact_plots_tmp/%s/%s.png' %(iface,name))

#~ totalp=totalp/contactp
#~ totalp=totalp/
print "%s %5.4f\n" %(iface, totalp)
Ejemplo n.º 3
0
p = 0.15 # edge probability
env = MVC(n,p)
cuda_flag = True
alg = DiscreteActorCritic(env,cuda_flag)


num_episodes = 4000
for i in range(num_episodes):
    T1 = time.time()
    log = alg.train()
    T2 = time.time()
    print('Epoch: {}. R: {}. TD error: {}. H: {}. T: {}'.format(i,np.round(log.get_current('tot_return'),2),np.round(log.get_current('TD_error'),3),np.round(log.get_current('entropy'),3),np.round(T2-T1,3)))
    

Y = np.asarray(log.get_log('tot_return'))
Y2 = smooth(Y)
x = np.linspace(0, len(Y), len(Y))
fig2 = plt.figure()
ax2 = plt.axes()
ax2.plot(x, Y , Y2)
plt.xlabel('episodes')
plt.ylabel('episode return')

Y = np.asarray(log.get_log('TD_error'))
Y2 = smooth(Y)
x = np.linspace(0, len(Y), len(Y))
fig2 = plt.figure()
ax2 = plt.axes()
ax2.plot(x, Y , Y2)
plt.xlabel('episodes')
plt.ylabel('mean TD error')
Ejemplo n.º 4
0
    T1 = time.time()
    log = alg.run_epoch()
    T2 = time.time()
    distances.append(log.get_current('final_dist'))
    Y = np.asarray(distances)
    Y[Y > 1] = 1.0
    Y = 1 - Y
    print('done: {} of {}. loss: {}. success rate: {}. time: {}'.format(
        i, epochs, np.round(log.get_current('avg_loss'), 2),
        np.round(np.mean(Y), 2), np.round(T2 - T1, 3)))
    if (i % 100) == 0:
        torch.save(alg.model.state_dict(), 'model.pt')
        torch.save(alg.image_mean, 'norm.pt')

Y = np.asarray(log.get_log('final_dist'))
Y2 = smooth(Y)
x = np.linspace(0, len(Y), len(Y))
fig1 = plt.figure()
ax1 = plt.axes()
ax1.plot(x, Y, Y2)
plt.xlabel('episodes')
plt.ylabel('minimum episode distance')

Y = np.asarray(log.get_log('avg_loss'))
Y2 = smooth(Y)
x = np.linspace(0, len(Y), len(Y))
fig2 = plt.figure()
ax2 = plt.axes()
ax2.plot(x, Y, Y2)
plt.xlabel('episodes')
plt.ylabel('average loss')
Ejemplo n.º 5
0
    #get experimental name and value
    c_name = angle_names[angle]
    c_exp = float(angle_exp[angle])
    fig = plt.figure(figsize=(16, 12))
    ax = fig.add_subplot(111)
    ax.plot([0, 800], [0, 0], 'k')
    #for each asu
    for asu in range(12):
        #get simulation value
        c_sim = angle_sim[asu, ::10, angle]
        #zero around experimental value
        c_sim = c_sim - c_exp
        #wrap values <-180 or >180
        index = c_sim > 180
        c_sim[index] = c_sim[index] - 360
        index = c_sim < -180
        c_sim[index] = c_sim[index] + 360
        #apply hanning smoother
        ax.plot(smooth(c_sim), colors[asu], label=asu + 1)
        #~ ax.plot(c_sim,label=asu)
        plt.title(c_name, fontsize=28)
        ax.legend(bbox_to_anchor=(0, 0, 1.08, 1))
        plt.xlabel('time', fontsize=28, labelpad=10)
        plt.ylabel(r"degrees", fontsize=28, labelpad=10)
        plt.ylim((-180, 180))
    ##~ plt.show()
    plt.savefig('PerResidue/%s_%s.png' %
                (c_name.split(':')[1], c_name.split(':')[0]))
    print angle
print "i am done"