2015-01-19 17:04:24 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# resultsFile is a library which allows to read output files of quantum
|
|
|
|
# chemistry codes and write input files.
|
|
|
|
# Copyright (C) 2007 Anthony SCEMAMA
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
#
|
|
|
|
# Anthony Scemama
|
|
|
|
# LCPQ - IRSAMC
|
|
|
|
# Universite Paul Sabatier
|
|
|
|
# 118, route de Narbonne
|
|
|
|
# 31062 Toulouse Cedex 4
|
|
|
|
# scemama@irsamc.ups-tlse.fr
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-01-27 20:29:00 +01:00
|
|
|
from .library import *
|
2015-01-19 17:04:24 +01:00
|
|
|
from math import *
|
|
|
|
|
|
|
|
class orbital(object):
|
|
|
|
"""Class for an orbital."""
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self._set = None
|
|
|
|
self._eigenvalue = None
|
|
|
|
self._vector = []
|
|
|
|
self._basis = None
|
|
|
|
self._sym = None
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
out = "%10s %6s %10.6f\n"%(\
|
|
|
|
self.set, self.sym, self.eigenvalue)
|
|
|
|
count=0
|
|
|
|
for c in self.vector:
|
|
|
|
out += "%17.8e "%(c,)
|
|
|
|
count += 1
|
|
|
|
if count == 5:
|
|
|
|
count = 0
|
|
|
|
out += '\n'
|
|
|
|
return out
|
|
|
|
|
|
|
|
def __repr__debug__(self):
|
|
|
|
out = ""
|
|
|
|
out += "Orbital:\n"
|
|
|
|
out += " Set : "+str(self.set)+'\n'
|
|
|
|
out += " Sym : "+str(self.sym)+'\n'
|
|
|
|
out += " Basis : "+str(self.basis)+'\n'
|
|
|
|
out += " Eigenvalue : "+str(self.eigenvalue)+'\n'
|
|
|
|
out += " Vector : "+str(self.vector)+'\n'
|
|
|
|
return out
|
|
|
|
|
|
|
|
def __cmp__(self,other):
|
|
|
|
assert ( isinstance(other,orbital) )
|
|
|
|
if self.eigenvalue < other.eigenvalue:
|
|
|
|
return -1
|
|
|
|
elif self.eigenvalue > other.eigenvalue:
|
|
|
|
return 1
|
|
|
|
elif self.eigenvalue == other.eigenvalue:
|
|
|
|
return 0
|
|
|
|
|
|
|
|
def dot(self,other):
|
|
|
|
assert ( isinstance(other,orbital) )
|
|
|
|
result = 0.
|
|
|
|
for i,j in zip(self.vector,other.vector):
|
|
|
|
result += i*j
|
|
|
|
return sqrt(result)
|
|
|
|
|
|
|
|
def is_ortho(self,other):
|
|
|
|
assert ( isinstance(other,orbital) )
|
|
|
|
if self.dot(other) == 0. :
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
|
|
|
def norm(self):
|
|
|
|
return self.dot(self)
|
|
|
|
|
|
|
|
def value(self,r):
|
|
|
|
"""Value at r."""
|
|
|
|
x, y, z = r
|
|
|
|
result = 0.
|
|
|
|
for c,chi in zip(self.vector,self.basis):
|
|
|
|
result += c*chi.value(r)
|
|
|
|
return result
|
|
|
|
|
|
|
|
for i in "eigenvalue vector basis set sym".split():
|
2020-01-27 20:29:00 +01:00
|
|
|
exec("""
|
2015-01-19 17:04:24 +01:00
|
|
|
def get_%(i)s(self): return self._%(i)s
|
|
|
|
def set_%(i)s(self,value): self._%(i)s = value
|
2020-01-27 20:29:00 +01:00
|
|
|
%(i)s = property(fget=get_%(i)s,fset=set_%(i)s) """%locals())
|
2015-01-19 17:04:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
l = []
|
|
|
|
l.append(orbital())
|
|
|
|
l.append(orbital())
|
|
|
|
l.append(orbital())
|
|
|
|
l[0].eigenvalue = 2.
|
|
|
|
l[1].eigenvalue = 1.
|
|
|
|
l[2].eigenvalue = 3.
|
|
|
|
for i in l:
|
2020-01-27 20:29:00 +01:00
|
|
|
print(i.eigenvalue)
|
2015-01-19 17:04:24 +01:00
|
|
|
l.sort()
|
2020-01-27 20:29:00 +01:00
|
|
|
print("")
|
2015-01-19 17:04:24 +01:00
|
|
|
for i in l:
|
2020-01-27 20:29:00 +01:00
|
|
|
print(i.eigenvalue)
|
2015-01-19 17:04:24 +01:00
|
|
|
l[0].vector = [1., 0., 0.]
|
|
|
|
l[1].vector = [0., 1., 0.]
|
|
|
|
l[2].vector = [0., 1., 1.]
|
2020-01-27 20:29:00 +01:00
|
|
|
print(l[0].is_ortho(l[1]))
|
|
|
|
print(l[1].is_ortho(l[2]))
|
|
|
|
print(l[1].dot(l[2]))
|
|
|
|
print(l[1].dot(l[0]))
|
|
|
|
print(l[1].norm())
|
|
|
|
print(l[2].norm())
|
2015-01-19 17:04:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
|