10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-12-23 12:56:14 +01:00

Update qp_convert_qmcpack_from_ezfio.py

This commit is contained in:
Thomas Applencourt 2016-02-03 17:46:14 +01:00
parent 56ec2abe21
commit 0dbd2ad08b

View File

@ -2,6 +2,11 @@
print "#QP -> QMCPACK" print "#QP -> QMCPACK"
# ___
# | ._ o _|_
# _|_ | | | |_
#
from ezfio import ezfio from ezfio import ezfio
import sys import sys
@ -9,7 +14,6 @@ ezfio_path = sys.argv[1]
ezfio.set_file(ezfio_path) ezfio.set_file(ezfio_path)
do_pseudo = ezfio.get_pseudo_do_pseudo() do_pseudo = ezfio.get_pseudo_do_pseudo()
if do_pseudo: if do_pseudo:
print "do_pseudo True" print "do_pseudo True"
@ -17,19 +21,31 @@ if do_pseudo:
else: else:
print "do_pseudo False" print "do_pseudo False"
try:
n_det = ezfio.get_determinants_n_det() n_det = ezfio.get_determinants_n_det()
except IOError:
n_det = 1
if n_det == 1: if n_det == 1:
print "multi_det False" print "multi_det False"
else: else:
print "multi_det True" print "multi_det True"
#
# |\/| o _ _
# | | | _> (_
#
def list_to_string(l):
return " ".join(map(str, l))
ao_num = ezfio.get_ao_basis_ao_num() ao_num = ezfio.get_ao_basis_ao_num()
print "ao_num", ao_num print "ao_num", ao_num
mo_num = ezfio.get_mo_basis_mo_tot_num() mo_num = ezfio.get_mo_basis_mo_tot_num()
print "mo_num", mo_num print "mo_num", mo_num
alpha = ezfio.get_electrons_elec_alpha_num() alpha = ezfio.get_electrons_elec_alpha_num()
beta = ezfio.get_electrons_elec_beta_num() beta = ezfio.get_electrons_elec_beta_num()
print "elec_alpha_num", alpha print "elec_alpha_num", alpha
@ -41,41 +57,74 @@ l_label = ezfio.get_nuclei_nucl_label()
l_charge = ezfio.get_nuclei_nucl_charge() l_charge = ezfio.get_nuclei_nucl_charge()
l_coord = ezfio.get_nuclei_nucl_coord() l_coord = ezfio.get_nuclei_nucl_coord()
l_coord_str = [" ".join(map(str,i)) for i in l_coord] l_coord_str = [list_to_string(i) for i in zip(*l_coord)]
print "nucl_num", len(l_label) print "nucl_num", len(l_label)
# _
# / _ _ ._ _|
# \_ (_) (_) | (_|
#
print "Atomic coord in Bohr" print "Atomic coord in Bohr"
for i, t in enumerate(zip(l_label, l_charge, l_coord_str)): for i, t in enumerate(zip(l_label, l_charge, l_coord_str)):
try: try:
l = (t[0],t[1]+zcore[i],t[1]) l = (t[0], t[1] + zcore[i], t[2])
except NameError: except NameError:
l = t l = t
print " ".join(map(str,l)) print list_to_string(l)
#
# Call externet process to get the sysmetry
#
import subprocess import subprocess
process = subprocess.Popen(['qp_print_basis', ezfio_path], stdout=subprocess.PIPE) process = subprocess.Popen(
['qp_print_basis', ezfio_path],
stdout=subprocess.PIPE)
out, err = process.communicate() out, err = process.communicate()
basis_raw, sym_raw, mo_raw = out.split("\n\n\n") basis_raw, sym_raw, _= out.split("\n\n\n")
# _ __
# |_) _. _ o _ (_ _ _|_
# |_) (_| _> | _> __) (/_ |_
#
basis_without_header = "\n".join(basis_raw.split("\n")[7:]) basis_without_header = "\n".join(basis_raw.split("\n")[7:])
for i,l in enumerate(l_label):
basis_without_header=basis_without_header.replace('Atom {0}'.format(i+1),l)
print "BEGIN_BASIS_SET" import re
print "" l_basis_raw = re.split('\n\s*\n', basis_without_header)
print basis_without_header
a_already_print = []
l_basis_clean = []
for i, (a,b) in enumerate(zip(l_label,l_basis_raw)):
if a not in a_already_print:
l_basis_clean.append(b.replace('Atom {0}'.format(i + 1), a))
a_already_print.append(a)
else:
continue
print "BEGIN_BASIS_SET\n"
print "\n\n".join(l_basis_clean)
print "END_BASIS_SET" print "END_BASIS_SET"
# _ # _
# |\/| / \ _ # |\/| / \ _
# | | \_/ _> # | | \_/ _>
# #
#
# Function
#
def same_character(item1): def same_character(item1):
return item1 == item1[0] * len(item1) return item1 == item1[0] * len(item1)
def compare_gamess_style(item1, item2): def compare_gamess_style(item1, item2):
if len(item1) < len(item2): if len(item1) < len(item2):
return -1 return -1
@ -93,8 +142,10 @@ def compare_gamess_style(item1, item2):
else: else:
return compare_gamess_style(item1[:-1], item2[:-1]) return compare_gamess_style(item1[:-1], item2[:-1])
def expend_and_order_sym(str_):
#Expend def expend_sym_str(str_):
#Expend x2 -> xx
# yx2 -> xxy
for i, c in enumerate(str_): for i, c in enumerate(str_):
try: try:
n = int(c) n = int(c)
@ -106,6 +157,14 @@ def expend_and_order_sym(str_):
#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 get_nb_permutation(str_): def get_nb_permutation(str_):
l = len(str_) - 1 l = len(str_) - 1
@ -114,45 +173,108 @@ def get_nb_permutation(str_):
else: else:
return 2 * (2 * l + 1) return 2 * (2 * l + 1)
## We will order the symetry
l_sym_without_header = sym_raw.split("\n")[3:-2]
l_l_sym = [i.split() for i in l_sym_without_header]
for l in l_l_sym:
l[2] = expend_and_order_sym(l[2])
def order_l_l_sym(l_l_sym):
l_l_sym_iter = iter(l_l_sym) l_l_sym_iter = iter(l_l_sym)
for i, l in enumerate(l_l_sym_iter): for i, l in enumerate(l_l_sym_iter):
n = get_nb_permutation(l[2]) n = get_nb_permutation(l[2])
if n != 1: if n != 1:
l_l_sym[i:i+n] = sorted(l_l_sym[i:i+n],key=lambda x : x[2], cmp=compare_gamess_style) l_l_sym[i:i + n] = sorted(l_l_sym[i:i + n],
key=lambda x: x[2],
cmp=compare_gamess_style)
for next_ in range(n - 1): for next_ in range(n - 1):
next(l_l_sym_iter) next(l_l_sym_iter)
return l_l_sym
#Is orderd now #==========================
# We will order the symetry
#==========================
l_block = mo_raw.split("\n\n")[5:-1] 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_expend_sym = expend_sym_l(l_l_sym_raw)
l_l_sym_ordered = order_l_l_sym(l_l_sym_expend_sym)
l_block_format=[] #========
#MO COEF
#========
def order_phase(mo_coef):
#Order
mo_coef_phase = []
import math
for i in mo_coef:
if abs(max(i)) > abs(min(i)):
sign_max = math.copysign(1, max(i))
else:
sign_max = math.copysign(1, min(i))
if sign_max == -1:
ii = [-1 * l for l in i]
else:
ii = i
mo_coef_phase.append(ii)
return mo_coef_phase
def order_by_sim(mo_coef, l_l_sym):
l_sym_oder = [int(l[0]) - 1 for l in l_l_sym]
mo_coef_order = [[x for (y, x) in sorted(zip(l_sym_oder, i))]
for i in mo_coef]
return mo_coef_order
def chunked(l, chunks_size):
l_block = []
for i in l:
chunks = [i[x:x + chunks_size] for x in xrange(0, len(i), chunks_size)]
l_block.append(chunks)
return l_block
def print_mo_coef(mo_coef_block, l_l_sym):
print "" print ""
print "BEGIN_MO" print "BEGIN_MO"
for block in l_block:
print "" print ""
l_ligne = block.split("\n") len_block_curent = 0
print l_ligne.pop(0) nb_block = len(mo_coef_block[0])
for i_block in range(0, nb_block):
a = [i[i_block] for i in mo_coef_block]
r_ = range(len_block_curent, len_block_curent + len(a[0]))
print " ".join([str(i + 1) for i in r_])
len_block_curent += len(a[0])
for l in l_l_sym: for l in l_l_sym:
i = int(l[0]) - 1 i = int(l[0]) - 1
i_a = int(l[1]) - 1 i_a = int(l[1]) - 1
sym = l[2] sym = l[2]
print l_label[i_a],sym,l_ligne[i] print l_label[i_a], sym, " ".join('{: 3.8f}'.format(i)
for i in a[i])
if i_block != nb_block - 1:
print ""
else:
print "END_MO" print "END_MO"
mo_coef = ezfio.get_mo_basis_mo_coef()
#mo_coef_phase = order_phase(mo_coef)
mo_coef_phase = mo_coef
mo_coef_phase_order = order_by_sim(mo_coef_phase, l_l_sym_ordered)
mo_coef_transp = zip(*mo_coef_phase_order)
mo_coef_block = chunked(mo_coef_transp, 4)
print_mo_coef(mo_coef_block, l_l_sym_ordered)
# _
# |_) _ _ _| _
# | _> (/_ |_| (_| (_)
#
if do_pseudo: if do_pseudo:
print "" print ""
print "BEGIN_PSEUDO" print "BEGIN_PSEUDO"
@ -160,7 +282,6 @@ if do_pseudo:
kmax = ezfio.get_pseudo_pseudo_kmax() kmax = ezfio.get_pseudo_pseudo_kmax()
lmax = ezfio.get_pseudo_pseudo_lmax() lmax = ezfio.get_pseudo_pseudo_lmax()
n_k = ezfio.get_pseudo_pseudo_n_k() n_k = ezfio.get_pseudo_pseudo_n_k()
v_k = ezfio.get_pseudo_pseudo_v_k() v_k = ezfio.get_pseudo_pseudo_v_k()
dz_k = ezfio.get_pseudo_pseudo_dz_k() dz_k = ezfio.get_pseudo_pseudo_dz_k()
@ -169,13 +290,11 @@ if do_pseudo:
v_kl = ezfio.get_pseudo_pseudo_v_kl() v_kl = ezfio.get_pseudo_pseudo_v_kl()
dz_kl = ezfio.get_pseudo_pseudo_dz_kl() dz_kl = ezfio.get_pseudo_pseudo_dz_kl()
def list_to_string(l):
return " ".join(map(str,l))
for i, a in enumerate(l_label): for i, a in enumerate(l_label):
l_str = [] l_str = []
#Local
l_dump = [] l_dump = []
for k in range(klocmax): for k in range(klocmax):
if v_k[k][i]: if v_k[k][i]:
@ -183,21 +302,24 @@ if do_pseudo:
l_dump.append(l_) l_dump.append(l_)
l_str.append(l_dump) l_str.append(l_dump)
#Non local
for l in range(lmax + 1): for l in range(lmax + 1):
l_dump = [] l_dump = []
for k in range(kmax): for k in range(kmax):
if v_kl[l][k][i]: if v_kl[l][k][i]:
l_ = list_to_string([v_kl[l][k][i], n_kl[l][k][i]+2, dz_kl[l][k][i]]) l_ = list_to_string([v_kl[l][k][i], n_kl[l][k][i] + 2,
dz_kl[l][k][i]])
l_dump.append(l_) l_dump.append(l_)
if l_dump: if l_dump:
l_str.append(l_dump) l_str.append(l_dump)
str_ = "PARAMETERS FOR {0} ON ATOM {1} WITH ZCORE {2} AND LMAX {3} ARE" str_ = "PARAMETERS FOR {0} ON ATOM {1} WITH ZCORE {2} AND LMAX {3} ARE"
print str_.format(a,i+1,zcore[i],len(l_str)) print str_.format(a, i + 1, int(zcore[i]), int(len(l_str) - 1))
for i, l in enumerate(l_str): for i, l in enumerate(l_str):
str_ = "FOR L= {0} COEFF N ZETA" str_ = "FOR L= {0} COEFF N ZETA"
print str_.format(len(l_str)-i-1) print str_.format(int(len(l_str) - i - 1))
for ii, ll in enumerate(l): for ii, ll in enumerate(l):
print " ", ii + 1, ll print " ", ii + 1, ll
@ -205,6 +327,10 @@ if do_pseudo:
print str_.format(sum(zcore)) print str_.format(sum(zcore))
print "END_PSEUDO" print "END_PSEUDO"
# _
# | \ _ _|_
# |_/ (/_ |_
#
print "" print ""
print "BEGIN_DET" print "BEGIN_DET"
print "" print ""
@ -215,7 +341,6 @@ print ""
psi_det = ezfio.get_determinants_psi_det() psi_det = ezfio.get_determinants_psi_det()
psi_coef = ezfio.get_determinants_psi_coef()[0] psi_coef = ezfio.get_determinants_psi_coef()[0]
for c, (l_det_bit_alpha, l_det_bit_beta) in zip(psi_coef, psi_det): for c, (l_det_bit_alpha, l_det_bit_beta) in zip(psi_coef, psi_det):
print c print c
for det in l_det_bit_alpha: for det in l_det_bit_alpha: