예제 #1
0
def spawn(dets_p, dets_c, key_p, tau):
	"""Spawning of all parents on the determinant indexed by $key_p$."""
	
	# Spawning.
	p_sign = (dets_p[key_p].value > 0)
	p_u_num = abs(dets_p[key_p].value)
	count = 0
	
	for count in range(p_u_num):
		# Single or double excitation.
		rand_val = random.random()
		if rand_val < gl_consts.single_prob:
			# Single excitation.
			orbs_p, key_c, sign, p_gen, orbs_diff = key_ops.single_excite(key_p)
			p_sing_or_doub = gl_consts.single_prob
		else:
			# Double excitation.
			orbs_p, key_c, sign, p_gen, orbs_diff = key_ops.double_excite(key_p)
			p_sing_or_doub = 1 - gl_consts.single_prob
		mat_element = black_box.sandwich(orbs_p, orbs_diff)
		if not sign:
			# Accounts for a possible negative sign from permuting the spawned determinant.
			mat_element = -mat_element
		prob = tau * mat_element / p_gen / p_sing_or_doub
		
		# Gets the sign of children.
		if prob < 0:
			c_sign = p_sign
			prob = -prob
		else:
			c_sign = not p_sign
		
		c_num = int(prob)
		# At least we have $c_num$ children.
		
		prob_frac = prob - c_num
		rand_val = random.random()
		if rand_val < prob_frac:
			# One more child.
			c_num += 1
		
		if c_num != 0:
			# Add $c_num$ children to the list.
			if not c_sign:
				c_num = -c_num
			if key_c in dets_c:
				dets_c[key_c].value += c_num
				if dets_c[key_c].value == 0:
					del dets_c[key_c]
				else:
					dets_c[key_c].flag = dets_p[key_p].flag
			else:
				dets_c[key_c] =  det.Det(c_num, dets_p[key_p].flag)
예제 #2
0
def gen_matrix():
	"""Creates a MATLAB file of the full Hamiltonian as a sparse matrix."""
	
	dets_p = {}
	dets_c = {}
	
	spatial_orbs_list = []
	key_list = []
	
	for i in range(0, 8):
		for j in range(i+1, 8):
			for k in range(j+1, 8):
				spatial_orbs_list.append([k, j, i])
	for sp_orbs_i in spatial_orbs_list:
		for sp_orbs_j in spatial_orbs_list:
			sp_orbs_temp = sp_orbs_j[:]
			for k in range(3):
				sp_orbs_temp[k] += 8
			orbs = tuple(sp_orbs_temp + sp_orbs_i)
			key = key_ops.orbs_2_key(orbs)
			key_list.append(key)
	for key in key_list:
		dets_c[key] = det.Det(1, True)
	
	det_ops.merge(dets_p, dets_c)
	
	f = open('matrix_m8n6.m', 'w')
	f.write('data = [')
	for i in range(len(key_list)):
		key_i = key_list[i]
		for j in range(len(key_list)):
			key_j = key_list[j]
			orbs_i, sign, orbs_diff = key_ops.difference(key_i, key_j)
			if orbs_i != None:
				entry = black_box.sandwich(orbs_i, orbs_diff)
				if entry == 0:
					continue
				elif not sign:
					entry = -entry
				f.write(str(i+1))
				f.write(' ')
				f.write(str(j+1))
				f.write(' ')
				f.write('{0:.4f}'.format(entry))
				f.write(' ')
	f.write('];\r\ndata = reshape(data, 3, length(data)/3);\r\ni = data(1,:);\r\nj = data(2,:);\r\n')
	f.write('s = data(3,:);\r\nH = sparse(i,j,s);\r\neig_vals = eigs(H);\r\ngnd = min(eig_vals);')
	f.close()
	
	return dets_p
예제 #3
0
def corr_by_proj(dets_p, ref_key):
	"""Calculates correlation energy by projection."""
	
	# E_corr = sum_j(<D_j|H|D_0>*(<N_j>/<N_0>)) - E_0
	
	ref_orbs = key_ops.key_2_orbs(ref_key)
	
	numer = 0
	
	for key in dets_p:
		if key != ref_key:
			orbs_gnd, sign_exc, orbs_diff = key_ops.difference(ref_key, key)
			if orbs_gnd != None:
				term = black_box.sandwich(orbs_gnd, orbs_diff) * dets_p[key].value
				if not sign_exc:
					term = -term
				numer += term
	denom = float(dets_p[ref_key].value)
	return numer, denom
예제 #4
0
파일: det.py 프로젝트: yjjiangMIT/FCIQMC
	def set_diag_entry(self, key):
		"""Sets diagonal matrix element of this determinant."""
		orbs = key_ops.key_2_orbs(key)
		self.diag_entry = black_box.sandwich(orbs, ())