10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-12-22 20:35:19 +01:00

Update qp_convert_qmcpack_to_ezfio.py

This commit is contained in:
Thomas Applencourt 2017-07-14 22:27:35 -05:00 committed by GitHub
parent 8c341dde9e
commit 1a2e605d08

View File

@ -91,7 +91,7 @@ process = subprocess.Popen(
stdout=subprocess.PIPE) stdout=subprocess.PIPE)
out, err = process.communicate() out, err = process.communicate()
basis_raw, sym_raw, _ , det_raw, _ = out.split("\n\n\n") basis_raw, sym_raw, _ = out.split("\n\n\n")
# _ __ # _ __
# |_) _. _ o _ (_ _ _|_ # |_) _. _ o _ (_ _ _|_
@ -113,8 +113,6 @@ for i, (a,b) in enumerate(zip(l_label,l_basis_raw)):
if a not in a_already_print: if a not in a_already_print:
l_basis_clean.append(b.replace('Atom {0}'.format(i + 1), a)) l_basis_clean.append(b.replace('Atom {0}'.format(i + 1), a))
a_already_print.append(a) a_already_print.append(a)
else:
continue
print "BEGIN_BASIS_SET\n" print "BEGIN_BASIS_SET\n"
print "\n\n".join(l_basis_clean) print "\n\n".join(l_basis_clean)
@ -129,25 +127,35 @@ print "END_BASIS_SET"
# #
# Function # Function
# #
d_gms_order ={ 0:["s"], def compute_L(str_):
return 0 if str_ == 's' else len(str_)
#Total angular momentum -> Angulaar momentun
d_order_gms ={ 0:["s"],
1:[ "x", "y", "z" ], 1:[ "x", "y", "z" ],
2:[ "xx", "yy", "zz", "xy", "xz", "yz" ], 2:[ "xx", "yy", "zz", "xy", "xz", "yz" ],
3:[ "xxx", "yyy", "zzz", "xxy", "xxz", "yyx", "yyz", "zzx", "zzy", "xyz"], 3:[ "xxx", "yyy", "zzz", "xxy", "xxz", "yyx", "yyz", "zzx", "zzy", "xyz"],
4:["xxxx", "yyyy", "zzzz", "xxxy", "xxxz", "yyyx", "yyyz", "zzzx", "zzzy", "xxyy", "xxzz", "yyzz", "xxyz", "yyxz", "zzxy", "xxxx", "yyyy", "zzzz", "xxxy", "xxxz", "yyyx", "yyyz", "zzzx", "zzzy", "xxyy", "xxzz", "yyzz", "xxyz", "yyxz","zzxy"] } 4:["xxxx", "yyyy", "zzzz", "xxxy", "xxxz", "yyyx", "yyyz", "zzzx", "zzzy", "xxyy", "xxzz", "yyzz", "xxyz", "yyxz", "zzxy", "xxxx", "yyyy", "zzzz", "xxxy", "xxxz", "yyyx", "yyyz", "zzzx", "zzzy", "xxyy", "xxzz", "yyzz", "xxyz", "yyxz","zzxy"] }
def compare_gamess_style(item1, item2): def compare_gamess_style(item1, item2):
n1,n2 = map(len,(item1,item2)) ''' Order by total angular momentum first
assert (n1 == n2) theb by the special gms order'''
n1,n2 = map(compute_L,(item1,item2))
if n1 != n2:
return cmp(n1,n2)
try: try:
l = d_gms_order[n1] l = d_order_gms[n1]
except KeyError: except KeyError:
raise (KeyError, "We dont handle L than 4") return 0
# raise (KeyError, "We dont handle L than 4")
else: else:
a = l.index(item1) a,b = map(l.index, (item1,item2))
b = l.index(item2)
return cmp( a, b ) return cmp( a, b )
def expend_sym_str(str_): def expend_angular_momentum(str_):
#Expend x2 -> xx #Expend x2 -> xx
# yx2 -> xxy # yx2 -> xxy
for i, c in enumerate(str_): for i, c in enumerate(str_):
@ -159,45 +167,7 @@ def expend_sym_str(str_):
str_ = str_[:i - 1] + str_[i - 1] * n + str_[i + 1:] str_ = str_[:i - 1] + str_[i - 1] * n + str_[i + 1:]
#Order by frequency #Order by frequency
return "".join(sorted(str_, key=str_.count, reverse=True)) return ''.join(sorted(str_, key=str_.count, reverse=True))
def expend_sym_l(l_l_sym):
for l in l_l_sym:
l[2] = expend_sym_str(l[2])
return l_l_sym
def n_orbital(n):
if n==0:
return 1
elif n==1:
return 3
else:
return 2*n_orbital(n-1)-n_orbital(n-2)+1
def get_nb_permutation(str_):
if (str_) == 's': return 1
else: return n_orbital(len(str_))
def order_l_l_sym(l_l_sym):
n = 1
iter_ = range(len(l_l_sym))
for i in iter_:
if n != 1:
n += -1
continue
l = l_l_sym[i]
n = get_nb_permutation(l[2])
l_l_sym[i:i + n] = sorted(l_l_sym[i:i + n],
key=lambda x: x[2],
cmp=compare_gamess_style)
return l_l_sym
#========================== #==========================
@ -206,8 +176,9 @@ def order_l_l_sym(l_l_sym):
l_sym_without_header = sym_raw.split("\n")[3:-2] l_sym_without_header = sym_raw.split("\n")[3:-2]
l_l_sym_raw = [i.split() for i in l_sym_without_header] l_l_sym_raw = [i.split() for i in l_sym_without_header]
l_l_sym_expend_sym = expend_sym_l(l_l_sym_raw) l_l_sym_expend_sym = [ [i,n, expend_angular_momentum(l)] for i,n,l in l_l_sym_raw]
l_l_sym_ordered = order_l_l_sym(l_l_sym_expend_sym) l_l_sym_ordered = sorted(l_l_sym_expend_sym, key=lambda x: x[2], cmp=compare_gamess_style)
#======== #========
#MO COEF #MO COEF
@ -331,6 +302,12 @@ if do_pseudo:
# | \ _ _|_ # | \ _ _|_
# |_/ (/_ |_ # |_/ (/_ |_
# #
psi_coef = ezfio.get_determinants_psi_coef()
psi_det = ezfio.get_determinants_psi_det()
bit_kind = ezfio.get_determinants_bit_kind()
print "" print ""
print "BEGIN_DET" print "BEGIN_DET"
print "" print ""
@ -338,27 +315,17 @@ print "mo_num", mo_num
print "det_num", n_det print "det_num", n_det
print "" print ""
state = 0
psi_coef = psi_coef[state]
encode = 8*bit_kind
token = "Determinants ::" decode = lambda det: ''.join("{0:b}".format(i)[::-1].ljust(encode,'0') for i in det)
pos = det_raw.rfind(token) + len(token) for coef, (det_a, det_b) in zip(psi_coef, psi_det):
det_without_header = det_raw[pos+2::] print coef
print decode(det_a)
from string import maketrans print decode(det_b)
trantab = maketrans("+-", "10") print ''
det_without_header = det_raw[pos+2::]
for line_raw in det_without_header.split("\n"):
line = line_raw
if line_raw:
try:
float(line)
except ValueError:
line = line_raw.translate(trantab)
print line.strip()
print "END_DET" print "END_DET"