コード例 #1
0
	def checkForceDistr(self, fileIn):	

		with open(fileIn, "r") as fin:
			if self.ndims == 1:
				# use xmgrace instead
				pass	

			if self.ndims == 2:	
				force_x  = np.zeros((self.binNum, self.binNum), dtype=np.float64) 
				force_y  = np.zeros((self.binNum, self.binNum), dtype=np.float64) 
				i        = 0
				j        = 0

				for line in fin:
					line = line.split()
					force_x[i][j] = float(line[2])
					force_y[i][j] = float(line[4]) 
					j += 1
					if j == self.binNum:
						j = 0
						i += 1
				
				force_x = np.delete(force_x, -1, 1) # rendering; prevent boundary error
				force_x = np.delete(force_x, -1, 0)
				force_y = np.delete(force_y, -1, 1)
				force_y = np.delete(force_y, -1, 0)
					
				r = rendering(self.ndims, self.half_boxboundary, self.binNum)
				r.render(force_x, name=str(self.abfCheckFlag + "_" + self.nnCheckFlag + "_" + "forcex2D"))			
				r.render(force_y, name=str(self.abfCheckFlag + "_" + self.nnCheckFlag + "_" + "forcey2D"))			
コード例 #2
0
def integrator(ndims, cv, force, half_boxboundary, outputfile):

  cv    = np.array(cv)
  force = np.array(force)

  if ndims == 1: # OK

    intg_interval = abs(cv[0] - cv[1])
    accIntg       = 0
    FE            = np.zeros(force.shape[0]) 
    factor        = intg_interval * 0.5 

    for i in range(len(force) - 1):
      accIntg -= (force[i] + force[i+1])  # freeE = -Sf(x)dx
      FE[i] = accIntg * factor 

    FE = paddingRightMostBin(FE)

    with open(outputfile, "w") as fout:
      for i, j in zip(cv, FE):
        fout.write(str(i) + " " + str(j) + "\n")

#---------------------------------------------------------------------#

  if ndims == 2: # probably OK? 

    intg_interval = abs(cv[1][0][0] - cv[1][0][1])
    factor   = intg_interval * 0.5 
    FE_X     = 0
    FE_Y     = 0
    acc_at_x = np.zeros((force.shape[1]))
    acc_at_y = np.zeros((force.shape[1], force.shape[2]))
    FE       = np.zeros((force.shape[1], force.shape[2]))

    for i in range(force.shape[1] - 1):
      FE_X = (force[0][i][0] + force[0][i+1][0])
      acc_at_x[i] -= FE_X 
      for j in range(force.shape[2]- 1):
        FE_Y -= (force[1][i][j] + force[1][i][j+1])
        acc_at_y[i][j] = FE_Y
      FE_Y = 0

    acc_at_x = np.append(acc_at_x, acc_at_x[-1])

    for i in range(force.shape[1]):
      for j in range(force.shape[2]):
        FE[i][j] = (acc_at_x[i] + acc_at_y[i][j]) * factor

    FE += 29.5 
    FE = paddingRightMostBin(FE)

    with open(outputfile, "w") as fout:
      for i in range(force.shape[1]):
        for j in range(force.shape[2]):
          fout.write(str(cv[0][i][j]) + " " + str(cv[1][i][j]) + " " + str(FE[i][j]) +  "\n")

    s = rendering(ndims, half_boxboundary, force.shape[1] - 1)
    s.render(FE, name="FreeE_2D")
コード例 #3
0
	def checkBoltzDistr(self, fileIn, fileOut):

		with open(fileIn, "r") as fin:

			if self.ndims == 1: # use xmgrace instead
				prob_x = np.zeros((self.binNum), dtype = np.int32)  
				nsamples = 0

				for line in fin:
					line = line.split()
					if line[0] != "#":	
						nsamples += 1	
						prob_x[getIndices(truncateFloat(float(line[2])), self.x_axis)] += 1 

				prob_x = np.array(prob_x)
				prob_x = (prob_x / nsamples) # final probability distribution 

				with open(fileOut, "w") as fout:
					for i in range(len(prob_x)): # in xmgrace, one can discard the point on pi (boundary error)
						fout.write(str(self.x_axis[i]) + " " + str(prob_x[i]) + "\n")

			if self.ndims == 2:

				prob_xy  = np.zeros((self.binNum, self.binNum), dtype = np.float64)  
				nsamples = 0

				for line in fin:
					line = line.split()
					if line[0] != "#":	
						nsamples += 1
						prob_xy[getIndices(truncateFloat(float(line[2])), self.x_axis)][getIndices(truncateFloat(float(line[4])), self.y_axis)] += 1 # 2 for cartcoord_1D, 2 4 for cartcoord_2D

				prob_xy = (prob_xy / nsamples) # final probability distribution 

				with open(fileOut, "w") as fout:
					for i in range(self.binNum): # discard the point on the positive boundary (PBC issues)
						for j in range(self.binNum): # discard the point on the positive boundary (PBC issues)
							fout.write(str(self.x_axis[i]) + " ")
							fout.write(str(self.y_axis[j]) + " " +  str(prob_xy[i][j]) + "\n")

				prob_xy = np.delete(prob_xy, -1, 0) # rendering; prevent boundary error
				prob_xy = np.delete(prob_xy, -1, 1)

				r = rendering(self.ndims, self.half_boxboundary, self.binNum, self.temperature)
				r.render(prob_xy, name=str(self.abfCheckFlag + "_" + self.nnCheckFlag + "_" + "boltz2D"))			
コード例 #4
0
    variation = 4
    betas = np.random.rand(10) * variation * 2 - variation
    # betas[0] = np.random.rand() * 8 * 2 -8
    variation = 2
    betas[1] = np.random.rand() * variation * 2 - variation
    # betas[3] = np.random.rand() * 8 * 2 -8
    # betas[6] = np.random.rand() * 8 * 2 -8
    # print(betas)

    parameters = np.append(pose[:], betas[:])
    # save frontal view image
    img_name = '%d_0' % i
    parameters = np.append(pose[:], betas[:])
    angle = np.pi
    axis = np.array([0, 1, 0])
    rendering(m, parameters, batch_size, path, img_name,
              args.width, args.height, angle, axis)
    image = Image.open(join(path,img_name+'.png'))
    output = scale_fixed_height(image,args.output_height,args.output_width)
    output_name = join(path, img_name+'.png')
    output.save(output_name)


    # save side view image
    img_name = '%d_1' % i
    angle = np.pi/2
    axis = np.array([0, 1, 0])
    rendering(m, parameters, batch_size, path, img_name,
              args.width, args.height, angle, axis)
    image = Image.open(join(path,img_name+'.png'))
    output = scale_fixed_height(image,args.output_height,args.output_width)
    output_name = join(path, img_name+'.png')
コード例 #5
0
                #parameters = np.append(np.zeros(3),parameters)
                #parameters[0] = np.pi
                
                
                # generate mesh
                img_name = '%d'%i
                generate_mesh(parameters,batch_size,path,img_name)
                # render silhouettes
                '''
                img_name = '%d'%(n) # set_0_predict
                rendering(parameters,batch_size,path,img_name,400,400)
                '''
                img_name = '%d_0_p' % i
                angle = np.pi
                axis = np.array([0, 1, 0])
                rendering(m, parameters, batch_size, path, img_name,
                        400, 400, angle, axis)
                '''
                img_name = '%d_0_p.png'%i
                img_name = os.path.join(path, img_name)
                image = Image.open(img_name)
                output = scale_fixed_height(image,264,192)
                img_name = '%d_0_p_s.png'%i
                img_name = os.path.join(path, img_name)
                output.save(img_name)
                '''
                

                # save side view image
                img_name = '%d_1_p' % i
                angle = np.pi/2
                axis = np.array([0, 1, 0])