Here's what I did: I copied what Brian G did in the
sympy.physics.secondquant module:
class TensorSymbol(sympy.Expr):
is_commutative=True
class SymmetricTensor(TensorSymbol):
def __new__(cls,symbol,inds1,inds2):
symbol = sympy.sympify(symbol)
inds1 = list(sympy.ordered(list(inds1)))
inds2 = list(sympy.ordered(list(inds2)))
inds1,inds2 = list(sympy.ordered([inds1,inds2]))
return TensorSymbol.__new__(cls,symbol,inds1,inds2)
def __str__(self):
return "%s(%s,%s)" % self.args
>>> a,b,c,d = sympy.symbols('a b c d')
>>> SymmetricTensor('I2',(a,b),(c,d))
I2([a,b],[c,d])
>>> SymmetricTensor('I2',(c,d),(a,b))
I2([a,b],[c,d])
>>> SymmetricTensor('I1',(a,),(b,))
I1([a],[b])
>>> SymmetricTensor('I1',(b,),(a,))
I1([a],[b])
This is pretty ugly, but it works. Can anyone suggest improving it, for
example using something more formal with the sympy.tensor module?
On Thursday, May 4, 2017 at 8:51:42 AM UTC-6, Rick Muller wrote:
>
> I was hoping that someone could give me some help getting started with the
> sympy tensor objects. I'd like to define symbolic objects to represent one-
> and two-electron integrals in quantum chemistry with the proper index
> permutation symmetries. These are real-valued integrals, so commutation
> relations aren't a problem (and, when they are, can be handled by the
> physics.secondquant module.
>
> The one-electron integrals are symmetric, i.e. I1[i,j] = I1[j,i], which I
> assume should be straightforward.
>
> The two-electron integrals are a little trickier, for I2[i,j,k,l] the
> integral is symmetric when i,j are permuted, and/or k,l are permuted,
> and/or i,j is permuted with k,l. I've never been able to derive a symbolic
> object that captures this, and it would be really convenient, for example,
> to derive equations for orbital optimization for different MC-SCF wave
> functions.
>
> I'm familiar with techniques to compute the orbitals numerically, e.g.,
> https://github.com/rpmuller/pyquante2. What I'm interested here is to
> derive and simplify equations for the symbolic manipulations of equations
> containing these terms. Has anyone done any work on this?
>
> Thanks in advance,
>
> Rick
>
>
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/b6ca02e0-1c38-4978-8dac-a748a3e77fa0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.