mirror of
https://gitlab.com/scemama/resultsFile.git
synced 2024-11-13 01:23:44 +01:00
Python3
This commit is contained in:
parent
c4bbfa23b8
commit
806544a778
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
|
|
||||||
import resultsFile
|
import resultsFile
|
||||||
|
from lib import *
|
||||||
|
|
||||||
import struct
|
import struct
|
||||||
import re
|
import re
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
|
|
||||||
import resultsFile
|
import resultsFile
|
||||||
|
from lib import *
|
||||||
|
|
||||||
import struct
|
import struct
|
||||||
import re
|
import re
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
|
|
||||||
import resultsFile
|
import resultsFile
|
||||||
|
from lib import *
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import struct
|
import struct
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
|
|
||||||
import resultsFile
|
import resultsFile
|
||||||
|
from lib import *
|
||||||
|
|
||||||
import struct
|
import struct
|
||||||
import re
|
import re
|
||||||
|
@ -1,51 +0,0 @@
|
|||||||
#!/usr/bin/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
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
from distutils.core import setup
|
|
||||||
from distutils.extension import Extension
|
|
||||||
from Cython.Distutils import build_ext
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
|
||||||
./cython_setup build_ext --inplace
|
|
||||||
"""
|
|
||||||
|
|
||||||
ext_modules = [Extension("resultsFile_cython", ["resultsFile_cython.pyx"])]
|
|
||||||
|
|
||||||
import os
|
|
||||||
setup(name="resultsFile",
|
|
||||||
version=os.getenv("VERSION","1.0"),
|
|
||||||
author="Anthony Scemama",
|
|
||||||
author_email="scemama@irsamc.ups-tlse.fr",
|
|
||||||
license="gpl-license",
|
|
||||||
description="Module for I/O on Quantum Chemistry files.",
|
|
||||||
packages=["resultsFile","resultsFile.lib","resultsFile.Modules"],
|
|
||||||
cmdclass = {'build_ext': build_ext},
|
|
||||||
ext_modules = ext_modules
|
|
||||||
)
|
|
||||||
|
|
@ -142,7 +142,7 @@ def rintgauss(n):
|
|||||||
if n == 0: return res
|
if n == 0: return res
|
||||||
elif n == 1: return 0.
|
elif n == 1: return 0.
|
||||||
elif n%2 == 1: return 0.
|
elif n%2 == 1: return 0.
|
||||||
res /= 2.**(n/2)
|
res /= 2.**(n//2)
|
||||||
res *= ddfact2(n-1)
|
res *= ddfact2(n-1)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
@ -227,8 +227,11 @@ def xyz_from_lm(l,m):
|
|||||||
coef = []
|
coef = []
|
||||||
absm = abs(m)
|
absm = abs(m)
|
||||||
nb2 = absm
|
nb2 = absm
|
||||||
nb1 = (l-absm)/2
|
nb1 = (l-absm)//2
|
||||||
clmt = [ (-0.25)**t * binom(l,t) * binom(l-t,absm+t) for t in range(nb1+1) ]
|
clmt = [ (-0.25)**t *
|
||||||
|
binom(l,t) *
|
||||||
|
binom(l-t,absm+t)
|
||||||
|
for t in range(nb1+1) ]
|
||||||
mod_absm_2 = absm % 2
|
mod_absm_2 = absm % 2
|
||||||
if m>=0:
|
if m>=0:
|
||||||
nb2_start = mod_absm_2
|
nb2_start = mod_absm_2
|
||||||
@ -239,7 +242,7 @@ def xyz_from_lm(l,m):
|
|||||||
else:
|
else:
|
||||||
norm = 1.
|
norm = 1.
|
||||||
for n1 in range(nb2_start,nb2+1,2):
|
for n1 in range(nb2_start,nb2+1,2):
|
||||||
k = (absm-n1)/2
|
k = (absm-n1)//2
|
||||||
factor = (-1.)**k * binom(absm,n1) * norm
|
factor = (-1.)**k * binom(absm,n1) * norm
|
||||||
for t in range(nb1+1):
|
for t in range(nb1+1):
|
||||||
for n2 in range(t+1):
|
for n2 in range(t+1):
|
||||||
|
@ -1,89 +0,0 @@
|
|||||||
#!/usr/bin/python
|
|
||||||
from math import *
|
|
||||||
|
|
||||||
powersave = { 's':(0,0,0) }
|
|
||||||
def powers(sym):
|
|
||||||
if sym in powersave:
|
|
||||||
return powersave[sym]
|
|
||||||
result = (sym.count('x'),sym.count('y'),sym.count('z'))
|
|
||||||
powersave[sym] = result
|
|
||||||
return result
|
|
||||||
|
|
||||||
fact_ = [1.]
|
|
||||||
cpdef fact(int n):
|
|
||||||
global fact_
|
|
||||||
cdef int nstart = len(fact_)
|
|
||||||
cdef int i
|
|
||||||
if n >= nstart :
|
|
||||||
for i in range(nstart,n+1):
|
|
||||||
fact_.append(float(fact_[i-1]*i))
|
|
||||||
return fact_[n]
|
|
||||||
|
|
||||||
def binom(int n,int m):
|
|
||||||
return fact(n)/(fact(m)*fact(n-m))
|
|
||||||
|
|
||||||
|
|
||||||
cdef ddfact2(int n):
|
|
||||||
if n%2 == 0: print 'error in ddfact2'
|
|
||||||
cdef double res=1.
|
|
||||||
cdef int i
|
|
||||||
for i in range(1,n+1,2):
|
|
||||||
res*=float(i)
|
|
||||||
return res
|
|
||||||
|
|
||||||
cdef double sqpi = sqrt(pi)
|
|
||||||
|
|
||||||
cpdef rintgauss(int n):
|
|
||||||
res = sqpi
|
|
||||||
if n == 0: return res
|
|
||||||
elif n == 1: return 0.
|
|
||||||
elif n%2 == 1: return 0.
|
|
||||||
res /= 2.**(n/2)
|
|
||||||
res *= ddfact2(n-1)
|
|
||||||
return res
|
|
||||||
|
|
||||||
cpdef GoverlapCart(fA,fB):
|
|
||||||
cdef double gamA=fA.expo
|
|
||||||
cdef double gamB=fB.expo
|
|
||||||
cdef double gamtot = gamA+gamB
|
|
||||||
cdef double SAB=1.0
|
|
||||||
cdef int l, n, m
|
|
||||||
cdef double u, arg, alpha, temp, wA, wB, accu
|
|
||||||
cdef int integ
|
|
||||||
A = fA.center
|
|
||||||
B = fB.center
|
|
||||||
nA = powers(fA.sym)
|
|
||||||
nB = powers(fB.sym)
|
|
||||||
for l in range(3):
|
|
||||||
Al = A[l]
|
|
||||||
Bl = B[l]
|
|
||||||
nAl = nA[l]
|
|
||||||
nBl = nB[l]
|
|
||||||
u=gamA/gamtot*Al+gamB/gamtot*Bl
|
|
||||||
arg=gamtot*u*u-gamA*Al*Al-gamB*Bl*Bl
|
|
||||||
alpha=exp(arg)/gamtot**((1.+float(nAl)+float(nBl))*0.5)
|
|
||||||
temp = sqrt(gamtot)
|
|
||||||
wA=temp*(u-Al)
|
|
||||||
wB=temp*(u-Bl)
|
|
||||||
accu=0.
|
|
||||||
for n in range (nAl+1):
|
|
||||||
for m in range (nBl+1):
|
|
||||||
integ=nAl+nBl-n-m
|
|
||||||
accu+=wA**n*wB**m*binom(nAl,n)*binom(nBl,m)*rintgauss(integ)
|
|
||||||
SAB*=accu*alpha
|
|
||||||
return SAB
|
|
||||||
|
|
||||||
cpdef GoverlapCartNorm2(fA,fB):
|
|
||||||
cdef double gamA=fA.expo
|
|
||||||
cdef double gamB=fB.expo
|
|
||||||
cdef double gamtot = gamA+gamB
|
|
||||||
cdef double SAB=1.0
|
|
||||||
cdef int l
|
|
||||||
nA = powers(fA.sym)
|
|
||||||
nB = powers(fB.sym)
|
|
||||||
for l in range(3):
|
|
||||||
nAl = nA[l]
|
|
||||||
nBl = nB[l]
|
|
||||||
SAB*=rintgauss(nAl+nBl)/(gamA+gamB)**((1.+float(nAl)+float(nBl))/2.)
|
|
||||||
return SAB
|
|
||||||
|
|
@ -1,241 +0,0 @@
|
|||||||
#!/usr/bin/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
|
|
||||||
|
|
||||||
|
|
||||||
from lib import *
|
|
||||||
import lib.basis as Basis
|
|
||||||
|
|
||||||
def get_uncontracted_basis(basis):
|
|
||||||
uncontr = []
|
|
||||||
for contr in basis:
|
|
||||||
for b in contr.prim:
|
|
||||||
uncontr.append(b)
|
|
||||||
return uncontr
|
|
||||||
|
|
||||||
def get_uncontracted_mo_sets(basis,uncontracted_basis,mo_sets,mo_types):
|
|
||||||
cdef dict uncontr = {}
|
|
||||||
cdef int lenmovector
|
|
||||||
cdef int lenbasis = len(basis)
|
|
||||||
cdef double ci
|
|
||||||
cdef int i, j
|
|
||||||
for motype in mo_types:
|
|
||||||
uncontr[motype] = []
|
|
||||||
for mo in mo_sets[motype]:
|
|
||||||
lenmovector = len(mo.vector)
|
|
||||||
monew = orbital()
|
|
||||||
monew.basis = uncontracted_basis
|
|
||||||
monew.eigenvalue = mo.eigenvalue
|
|
||||||
monew.set = motype
|
|
||||||
v = []
|
|
||||||
for i in range(lenbasis):
|
|
||||||
contr = basis[i]
|
|
||||||
if i<lenmovector:
|
|
||||||
ci = mo.vector[i]
|
|
||||||
if ci == 0.:
|
|
||||||
for j in range(len(contr.prim)):
|
|
||||||
v.append(0.)
|
|
||||||
else:
|
|
||||||
for p, c in zip(contr.prim,contr.coef):
|
|
||||||
v.append(c*ci/p.norm)
|
|
||||||
monew.vector = v
|
|
||||||
uncontr[motype].append(monew)
|
|
||||||
return uncontr
|
|
||||||
|
|
||||||
|
|
||||||
def clean_contractions(basis):
|
|
||||||
newbasis = []
|
|
||||||
cdef int i, k, l, lenmovector
|
|
||||||
idx = range(len(basis))
|
|
||||||
for k,b1 in enumerate(basis):
|
|
||||||
addBasis=True
|
|
||||||
for l, b2 in enumerate(basis[:k]):
|
|
||||||
if b2 == b1:
|
|
||||||
idx[k] = l
|
|
||||||
addBasis=False
|
|
||||||
break
|
|
||||||
if addBasis:
|
|
||||||
newbasis.append(b1)
|
|
||||||
self._basis = newbasis
|
|
||||||
|
|
||||||
mo_sets = self.mo_sets
|
|
||||||
for motype in self.mo_types:
|
|
||||||
for mo in mo_sets[motype]:
|
|
||||||
lenmovector = len(mo.vector)
|
|
||||||
newvec = [None for i in idx]
|
|
||||||
for i in idx:
|
|
||||||
newvec[i] = 0.
|
|
||||||
for k,l in enumerate(idx):
|
|
||||||
if k < lenmovector:
|
|
||||||
newvec[l] += mo.vector[k]
|
|
||||||
mo.vector = []
|
|
||||||
for c in newvec:
|
|
||||||
if c is not None:
|
|
||||||
mo.vector.append(c)
|
|
||||||
|
|
||||||
# def clean_uncontractions(self):
|
|
||||||
# basis = self.uncontracted_basis
|
|
||||||
# newbasis = []
|
|
||||||
# idx = range(len(basis))
|
|
||||||
# for k,b1 in enumerate(basis):
|
|
||||||
# addBasis=True
|
|
||||||
# for l, b2 in enumerate(basis[:k]):
|
|
||||||
# if b2 == b1:
|
|
||||||
# idx[k] = l
|
|
||||||
# addBasis=False
|
|
||||||
# break
|
|
||||||
# if addBasis:
|
|
||||||
# newbasis.append(b1)
|
|
||||||
# self._uncontracted_basis = newbasis
|
|
||||||
|
|
||||||
# mo_sets = self.uncontracted_mo_sets
|
|
||||||
# for motype in self.mo_types:
|
|
||||||
# for mo in mo_sets[motype]:
|
|
||||||
# lenmovector = len(mo.vector)
|
|
||||||
# newvec = [None for i in idx]
|
|
||||||
# for i in idx:
|
|
||||||
# newvec[i] = 0.
|
|
||||||
# for k,l in enumerate(idx):
|
|
||||||
# if k < lenmovector:
|
|
||||||
# newvec[l] += mo.vector[k]
|
|
||||||
# mo.vector = []
|
|
||||||
# for c in newvec:
|
|
||||||
# if c is not None:
|
|
||||||
# mo.vector.append(c)
|
|
||||||
#
|
|
||||||
# def convert_to_cartesian(self):
|
|
||||||
# basis = self.basis
|
|
||||||
# newbasis = []
|
|
||||||
# idx = range(len(basis))
|
|
||||||
# map = []
|
|
||||||
# weight = []
|
|
||||||
# for i,b in enumerate(basis):
|
|
||||||
# l, m = Basis.get_lm(b.sym)
|
|
||||||
# if l is None:
|
|
||||||
# newbasis.append(b)
|
|
||||||
# map.append(i)
|
|
||||||
# weight.append(1.)
|
|
||||||
# else:
|
|
||||||
# powers, coefs = xyz_from_lm(l,m)
|
|
||||||
# for j,prim in enumerate(b.prim):
|
|
||||||
# b.coef[j] /= prim.norm
|
|
||||||
# for c, p in zip(coefs, powers):
|
|
||||||
# contr = copy.deepcopy(b)
|
|
||||||
# sym = ''
|
|
||||||
# for l,letter in enumerate('xyz'):
|
|
||||||
# sym += p[l]*letter
|
|
||||||
# contr.sym = sym
|
|
||||||
# for j,prim in enumerate(contr.prim):
|
|
||||||
# prim.sym = sym
|
|
||||||
# contr.coef[j] *= prim.norm
|
|
||||||
# newbasis.append(contr)
|
|
||||||
# map.append(i)
|
|
||||||
# weight.append(c)
|
|
||||||
|
|
||||||
# mo_sets = self.mo_sets
|
|
||||||
# for motype in self.mo_types:
|
|
||||||
# for mo in mo_sets[motype]:
|
|
||||||
# newvec = []
|
|
||||||
# vec = mo.vector
|
|
||||||
# for i,w in zip(map,weight):
|
|
||||||
# newvec.append(vec[i]*w)
|
|
||||||
# mo.vector = newvec
|
|
||||||
|
|
||||||
# same_as = {}
|
|
||||||
# for i,b1 in enumerate(newbasis):
|
|
||||||
# for j,b2 in enumerate(newbasis[:i]):
|
|
||||||
# if b1 == b2:
|
|
||||||
# same_as[i] = j
|
|
||||||
# weight[j] += weight[i]
|
|
||||||
# break
|
|
||||||
# to_remove = same_as.keys()
|
|
||||||
# to_remove.sort()
|
|
||||||
# to_remove.reverse()
|
|
||||||
# for i in to_remove:
|
|
||||||
# newbasis.pop(i)
|
|
||||||
# weight.pop(i)
|
|
||||||
# map.pop(i)
|
|
||||||
|
|
||||||
|
|
||||||
# for motype in self.mo_types:
|
|
||||||
# for mo in mo_sets[motype]:
|
|
||||||
# for i in to_remove:
|
|
||||||
# index = same_as[i]
|
|
||||||
# value = mo.vector.pop(i)
|
|
||||||
# mo.vector[index] += value
|
|
||||||
|
|
||||||
# self._basis = newbasis
|
|
||||||
# self._mo_sets = mo_sets
|
|
||||||
|
|
||||||
# def find_string(self,chars):
|
|
||||||
# """Finds the 1st occurence of chars.
|
|
||||||
# """
|
|
||||||
# self._pos = 0
|
|
||||||
# self.find_next_string(chars)
|
|
||||||
|
|
||||||
# def find_last_string(self,chars):
|
|
||||||
# """Finds the 1st occurence of chars.
|
|
||||||
# """
|
|
||||||
# self._pos = len(self.text)-1
|
|
||||||
# self.find_prev_string(chars)
|
|
||||||
|
|
||||||
# def find_next_string(self,chars):
|
|
||||||
# """Finds the next occurence of chars.
|
|
||||||
# """
|
|
||||||
# pos = self._pos
|
|
||||||
# text = self.text
|
|
||||||
# found = False
|
|
||||||
# while not found and pos < len(text):
|
|
||||||
# if chars in text[pos]:
|
|
||||||
# found = True
|
|
||||||
# else:
|
|
||||||
# pos += 1
|
|
||||||
# if not found:
|
|
||||||
# raise IndexError
|
|
||||||
# self._pos = pos
|
|
||||||
|
|
||||||
# def find_prev_string(self,chars):
|
|
||||||
# """Finds the next occurence of chars.
|
|
||||||
# """
|
|
||||||
# pos = self._pos
|
|
||||||
# text = self.text
|
|
||||||
# found = False
|
|
||||||
# while not found and pos < len(text):
|
|
||||||
# if chars in text[pos]:
|
|
||||||
# found = True
|
|
||||||
# else:
|
|
||||||
# pos -= 1
|
|
||||||
# if not found:
|
|
||||||
# raise IndexError
|
|
||||||
# self._pos = pos
|
|
||||||
|
|
||||||
|
|
||||||
# for i, j in local_vars:
|
|
||||||
# if i not in defined_vars:
|
|
||||||
# exec build_get_funcs(i) in locals()
|
|
||||||
# exec build_property(i,j) in locals()
|
|
||||||
# del i,j
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user