Ejemplo n.º 1
0
def getDerivExpression(formula, deriv, order, final_result):
	"""
	for the given formula, as well as the derivative var(something like
	XXXX, XXYZ etc. generated in derivorder.py). We can get the derivatives 
	expression for the current formula. We note that this process continues
	in recursively way until all of the derivatives are processed. If the 
	final order is arrived, we will push the result into the final_result
	"""
	result = { }
	axis   = deriv[order]
	nunderscore = 1
	for k, bas in formula.iteritems():

		# to get rid of the "-" sign first
		k = k.replace("-","")

		# get the first term in the derivative expression
		# the first term is "(l,m,n)*chi(l,m,n - delta)"
		(l,m,n) = bas.loweringAng(axis)

                # add a comment: if the loweringAng produce new 
                # l,m,n no matter which one is smaller than 0;
                # then l,m,n are all none
                # we only need to check that whether l is none or not
                # so that to know the new basis set exist or not
		if l is not None:
			newBasis = basis.basis(l,m,n)
			com = bas.getComponent(axis)
			newkey1  = k + "_" + str(com)
			if result.has_key(newkey1):
				for i in range(nunderscore):
					newkey1 = newkey1 + "-"
				nunderscore = nunderscore + 1
				result[newkey1] = newBasis
			else:
				result[newkey1] = newBasis

		# get the second term
		# the second term is 2alpha*chi(l,m,n + delta)
		(l,m,n) = bas.raisingAng(axis)
		newBasis = basis.basis(l,m,n)
		newkey2  = k + "_" + "2alpha"
		if result.has_key(newkey2):
			for i in range(nunderscore):
				newkey2 = newkey2 + "_"
			nunderscore = nunderscore + 1
			result[newkey2] = newBasis
		else:
			result[newkey2] = newBasis

	# now let's judge whether we need to proceed it
	order = order + 1
	desire_order = len(deriv)
	if order == desire_order:
		for k, bas in result.iteritems():
			final_result[k] = bas
	else:
		getDerivExpression(result, deriv, order, final_result)
Ejemplo n.º 2
0
 def __init__(self, device, new_basis=None, nphotons=None):
     self.device=device
     if new_basis==None:
         self.basis=basis(nphotons, device.nmodes)
     else:
         self.basis=new_basis
     self.nmodes=self.basis.nmodes
     self.nphotons=self.basis.nphotons
     self.visibility=1.0
     self.set_mode('quantum')
Ejemplo n.º 3
0
 def __init__(self, device, new_basis=None, nphotons=None):
     self.device = device
     if new_basis == None:
         self.basis = basis(nphotons, device.nmodes)
     else:
         self.basis = new_basis
     self.nmodes = self.basis.nmodes
     self.nphotons = self.basis.nphotons
     self.visibility = 1.0
     self.set_mode('quantum')
Ejemplo n.º 4
0
sys.path.insert(0, '../core')
import CGTOs
import basis
import rhf
import pp

H1s_exp = 1.24
H1s = CGTOs.getH1s()
He1s_exp = 1.6875 * 1.24
He1s = CGTOs.getHe1s()

title = 'HeH+, spacing: 0.1 a.u.'
label = 'STO-3G\nexp(H1s): ' + str(H1s_exp) + '\nexp(He1s): ' + str(He1s_exp)

basis_set = []
basis_set.append(basis.basis(H1s))
basis_set.append(basis.basis(He1s))

basis_per_nuclei = [1, 1]

N_charge = [1, 2]

e_count = 2

x = np.arange(0.1, 3.5, 0.1)

rhf = rhf.rhf(basis_set, basis_per_nuclei, N_charge, e_count, x)

E = rhf.solve()

pp = pp.pp(title, label)
Ejemplo n.º 5
0
        else:
            raise TypeError, 'Invalid state index'

    def __str__(self):
        s=''
        if len(self.nonzero_terms)==0: s+='No nonzero terms in this state'
        st=sorted(self.nonzero_terms)
        for index in st:
            a=self.vector[index]
            s+='%.2f + %.2fi  ' % (a.real, a.imag)
            if self.nphotons<10: s+='  ('+ket(self.basis.modes_from_index(index))+')'
            s+='\n'
        return s

if __name__=='__main__':
    ''' Test out the state class '''
    from basis import basis
    b=basis(5, 25)
    print 'Hilbert space dimension:', b.hilbert_space_dimension
    s=state(b)
    print 'Empty state'

    # Add a bit of probability amplitude
    s[1,2,3,4,5]+=.1
    s[2,3,4,5,6]+=.1
    s[0]+=.1
    print s
    print s[0]
    print s[1,2,3,4,5]

Ejemplo n.º 6
0
            raise TypeError, 'Invalid state index'

    def __str__(self):
        s = ''
        if len(self.nonzero_terms) == 0: s += 'No nonzero terms in this state'
        st = sorted(self.nonzero_terms)
        for index in st:
            a = self.vector[index]
            s += '%.2f + %.2fi  ' % (a.real, a.imag)
            if self.nphotons < 10:
                s += '  (' + ket(self.basis.modes_from_index(index)) + ')'
            s += '\n'
        return s


if __name__ == '__main__':
    ''' Test out the state class '''
    from basis import basis
    b = basis(5, 25)
    print 'Hilbert space dimension:', b.hilbert_space_dimension
    s = state(b)
    print 'Empty state'

    # Add a bit of probability amplitude
    s[1, 2, 3, 4, 5] += .1
    s[2, 3, 4, 5, 6] += .1
    s[0] += .1
    print s
    print s[0]
    print s[1, 2, 3, 4, 5]