Exemplo n.º 1
0
	def write_ezfio(self,filename):
		ezfio.set_file(filename)
		ezfio.set_ao_basis_used_ao_num(self.nb_ao)
		ezfio.set_ao_basis_slater_ao_num(self.nb_ao) 
		ezfio.set_ao_basis_slater_ao_prim_num(self.ao_prim_num_list)
		ezfio.set_ao_basis_slater_ao_nucl(self.ao_nucl_list)
		
		ezfio.set_ao_basis_slater_ao_n(self.n_list)
		ezfio.set_ao_basis_slater_ao_m(self.m_list)
		ezfio.set_ao_basis_slater_ao_l(self.l_list)
		ezfio.set_ao_basis_slater_ao_gamma(self.g_list)
		ezfio.set_ao_basis_slater_ao_coef(self.ao_coef_list)
		
		ezfio.set_mo_basis_mo_tot_num(self.nb_ao) 
		ezfio.set_mo_basis_mo_coef(self.m_coef_list) 
		
		ezfio.set_nuclei_nucl_num(1)
		ezfio.set_nuclei_nucl_charge([self.Z])
		ezfio.set_nuclei_nucl_coord([0.,0.,0.])
		
		ezfio.set_electrons_elec_beta_num(self.Z // 2)
		ezfio.set_electrons_elec_alpha_num(self.Z // 2 + self.Z % 2)
			
		ezfio.set_parameters_n_act(self.n_act)
		ezfio.set_parameters_n_virt(0)
		ezfio.set_parameters_n_core(0)
Exemplo n.º 2
0
def check_convert(path_out):
    '''
    Path_out is the out_file
    '''

    # ~#~#~#~#~#~#~#~#~#~ #
    # R e f _ e n e r g y #
    # ~#~#~#~#~#~#~#~#~#~ #

    ref_energy = defaultdict(dict)

    ref_energy["HBO.out"] = -100.0185822589

    # ~#~#~#~#~#~#~#~#~#~#~#~#~ #
    # S e t _ p a r a m e t e r #
    # ~#~#~#~#~#~#~#~#~#~#~#~#~ #

    cmd = "cp {0}/tests/{1} .".format(qpackage_root, path_out)
    subprocess.check_call([cmd], shell=True)

    cmd = "qp_convert_output_to_ezfio.py {0}".format(path_out)
    subprocess.check_call([cmd], shell=True)

    # Test 2
    cmd = "qp_edit -c {0}.ezfio".format(path_out)
    subprocess.check_call([cmd], shell=True)

    cmd = "qp_run SCF {0}.ezfio".format(path_out)
    subprocess.check_call([cmd], shell=True)

    # ~#~#~#~#~ #
    # C h e c k #
    # ~#~#~#~#~ #

    ezfio.set_file("{0}.ezfio".format(path_out))

    cur_e = ezfio.get_hartree_fock_energy()
    ref_e = ref_energy[path_out]

    if abs(cur_e - ref_e) <= precision:
        subprocess.call(["rm {0}".format(path_out)], shell=True)
        subprocess.call(["rm -R {0}.ezfio".format(path_out)], shell=True)
        return True
    else:
        raise ValueError(get_error_message([ref_e], [cur_e]))
Exemplo n.º 3
0
def check_convert(path_out):
    '''
    Path_out is the out_file
    '''

    # ~#~#~#~#~#~#~#~#~#~ #
    # R e f _ e n e r g y #
    # ~#~#~#~#~#~#~#~#~#~ #

    ref_energy = defaultdict(dict)

    ref_energy["HBO.out"] = -100.0185822589

    # ~#~#~#~#~#~#~#~#~#~#~#~#~ #
    # S e t _ p a r a m e t e r #
    # ~#~#~#~#~#~#~#~#~#~#~#~#~ #
    cmd = "qp_convert_output_to_ezfio.py {0}".format(path_out)
    subprocess.check_call([cmd], shell=True)

    # Test 2
    cmd = "qp_edit -c {0}.ezfio".format(path_out)
    subprocess.check_call([cmd], shell=True)

    cmd = "qp_run SCF {0}.ezfio".format(path_out)
    subprocess.check_call([cmd], shell=True)

    # ~#~#~#~#~ #
    # C h e c k #
    # ~#~#~#~#~ #

    ezfio.set_file("{0}.ezfio".format(path_out))

    cur_e = ezfio.get_hartree_fock_energy()
    ref_e = ref_energy[path_out]

    if abs(cur_e - ref_e) <= precision:
        subprocess.call(["rm -R {0}.ezfio".format(path_out)], shell=True)
        return True
    else:
        raise ValueError(get_error_message([ref_e], [cur_e]))
Exemplo n.º 4
0
def check_disk_acess(geo, basis, mult=1):

    import uuid
    filename = str(uuid.uuid4())

    # ~#~#~#~ #
    # I n i t #
    # ~#~#~#~ #

    init_folder(geo, basis, mult, ezfio_name=filename)
    ezfio.set_file("{0}.ezfio".format(filename))

    # ~#~#~#~#~#~#~#~#~#~#~#~#~ #
    # S e t _ p a r a m e t e r #
    # ~#~#~#~#~#~#~#~#~#~#~#~#~ #

    # Test 1
    ezfio.integrals_bielec_disk_access_ao_integrals = "Write"
    cmd = "qp_edit -c {0}.ezfio".format(filename)
    subprocess.check_call([cmd], shell=True)

    # Test 2
    ezfio.integrals_bielec_disk_access_ao_integrals = "IculeAcess"
    cmd = "qp_edit -c {0}.ezfio".format(filename)

    try:
        subprocess.check_call([cmd], shell=True)
        return_code = False
    except subprocess.CalledProcessError:
        return_code = True

    # ~#~#~#~#~#~#~#~ #
    # F i n a l i z e #
    # ~#~#~#~#~#~#~#~ #

    if return_code:
        subprocess.call(["rm -R {0}.ezfio".format(filename)], shell=True)
    return return_code
Exemplo n.º 5
0
def check_mo_guess(geo, basis, mult=1):

    import uuid
    filename = str(uuid.uuid4())

    # ~#~#~#~ #
    # I n i t #
    # ~#~#~#~ #

    init_folder(geo, basis, mult, ezfio_name=filename)
    ezfio.set_file("{0}.ezfio".format(filename))

    # ~#~#~#~#~#~#~#~#~#~#~#~#~ #
    # S e t _ p a r a m e t e r #
    # ~#~#~#~#~#~#~#~#~#~#~#~#~ #

    # Test 1
    ezfio.hartree_fock_mo_guess_type = "Huckel"
    cmd = "qp_edit -c {0}.ezfio".format(filename)
    subprocess.check_call([cmd], shell=True)

    # Test 2
    ezfio.hartree_fock_mo_guess_type = "IculeGuess"
    cmd = "qp_edit -c {0}.ezfio".format(filename)

    try:
        subprocess.check_call([cmd], shell=True)
        return_code = False
    except subprocess.CalledProcessError:
        return_code = True

    # ~#~#~#~#~#~#~#~ #
    # F i n a l i z e #
    # ~#~#~#~#~#~#~#~ #

    if return_code:
        subprocess.call(["rm -R {0}.ezfio".format(filename)], shell=True)
    return return_code
Exemplo n.º 6
0
def check_mo_guess(geo, basis, mult=1):

    import uuid
    filename = str(uuid.uuid4())

    # ~#~#~#~ #
    # I n i t #
    # ~#~#~#~ #

    init_folder(geo, basis, mult, ezfio_name=filename)
    ezfio.set_file("{0}.ezfio".format(filename))

    # ~#~#~#~#~#~#~#~#~#~#~#~#~ #
    # S e t _ p a r a m e t e r #
    # ~#~#~#~#~#~#~#~#~#~#~#~#~ #

    # Test 1
    ezfio.hartree_fock_mo_guess_type = "Huckel"
    cmd = "qp_edit -c {0}.ezfio".format(filename)
    subprocess.check_call([cmd], shell=True)

    # Test 2
    ezfio.hartree_fock_mo_guess_type = "IculeGuess"
    cmd = "qp_edit -c {0}.ezfio".format(filename)

    try:
        subprocess.check_call([cmd], shell=True)
        return_code = False
    except subprocess.CalledProcessError:
        return_code = True

    # ~#~#~#~#~#~#~#~ #
    # F i n a l i z e #
    # ~#~#~#~#~#~#~#~ #

    if return_code:
        subprocess.call(["rm -R {0}.ezfio".format(filename)], shell=True)
    return return_code
Exemplo n.º 7
0
def check_disk_acess(geo, basis, mult=1):

    import uuid
    filename = str(uuid.uuid4())

    # ~#~#~#~ #
    # I n i t #
    # ~#~#~#~ #

    init_folder(geo, basis, mult, ezfio_name=filename)
    ezfio.set_file("{0}.ezfio".format(filename))

    # ~#~#~#~#~#~#~#~#~#~#~#~#~ #
    # S e t _ p a r a m e t e r #
    # ~#~#~#~#~#~#~#~#~#~#~#~#~ #

    # Test 1
    ezfio.integrals_bielec_disk_access_ao_integrals = "Write"
    cmd = "qp_edit -c {0}.ezfio".format(filename)
    subprocess.check_call([cmd], shell=True)

    # Test 2
    ezfio.integrals_bielec_disk_access_ao_integrals = "IculeAcess"
    cmd = "qp_edit -c {0}.ezfio".format(filename)

    try:
        subprocess.check_call([cmd], shell=True)
        return_code = False
    except subprocess.CalledProcessError:
        return_code = True

    # ~#~#~#~#~#~#~#~ #
    # F i n a l i z e #
    # ~#~#~#~#~#~#~#~ #

    if return_code:
        subprocess.call(["rm -R {0}.ezfio".format(filename)], shell=True)
    return return_code
Exemplo n.º 8
0
    arguments = docopt(__doc__)
    # ___
    #  |  ._  o _|_
    # _|_ | | |  |_
    #

    # ~#~#~#~#~ #
    # E Z F I O #
    # ~#~#~#~#~ #

    ezfio_path = arguments["<ezfio_path>"]
    ezfio_path = os.path.expanduser(ezfio_path)
    ezfio_path = os.path.expandvars(ezfio_path)
    ezfio_path = os.path.abspath(ezfio_path)

    ezfio.set_file("{0}".format(ezfio_path))

    # ~#~#~#~#~#~#~#~#~#~#~ #
    # P s e u d o _ d a t a #
    # ~#~#~#~#~#~#~#~#~#~#~ #

    l_ele = ezfio.get_nuclei_nucl_label()
    str_ = get_pseudo_str(l_ele)

    #  _
    # |_) _. ._ _  _
    # |  (_| | _> (/_
    #

    l_str_ele = [
        str_ele for str_ele in str_.split("Element Symbol: ") if str_ele
Exemplo n.º 9
0
    arguments = docopt(__doc__)
    # ___
    #  |  ._  o _|_
    # _|_ | | |  |_
    #

    # ~#~#~#~#~ #
    # E Z F I O #
    # ~#~#~#~#~ #

    ezfio_path = arguments["<ezfio_path>"]
    ezfio_path = os.path.expanduser(ezfio_path)
    ezfio_path = os.path.expandvars(ezfio_path)
    ezfio_path = os.path.abspath(ezfio_path)

    ezfio.set_file("{0}".format(ezfio_path))

    # ~#~#~#~#~#~#~#~#~#~#~ #
    # P s e u d o _ d a t a #
    # ~#~#~#~#~#~#~#~#~#~#~ #

    l_ele = ezfio.get_nuclei_nucl_label()
    str_ = get_pseudo_str(l_ele)

    #  _
    # |_) _. ._ _  _
    # |  (_| | _> (/_
    #

    l_str_ele = [str_ele for str_ele in str_.split("Element Symbol: ")
                 if str_ele]
#!/usr/bin/env python2

print "#QP -> QMCPACK"

# ___
#  |  ._  o _|_
# _|_ | | |  |_
#

from ezfio import ezfio

import os
import sys
ezfio_path = sys.argv[1]

ezfio.set_file(ezfio_path)

do_pseudo = ezfio.get_pseudo_do_pseudo()
if do_pseudo:
    print "do_pseudo True"
    from qp_path import QP_ROOT

    l_ele_path = os.path.join(QP_ROOT, "data", "list_element.txt")
    with open(l_ele_path, "r") as f:
        data_raw = f.read()

    l_element_raw = data_raw.split("\n")
    l_element = [element_raw.split() for element_raw in l_element_raw]
    d_z = dict(
        (abr, z) for (z, abr, ele, _) in filter(lambda x: x != [], l_element))
else:
Exemplo n.º 11
0
def write_ezfio(res, filename):

    res.clean_uncontractions()
    ezfio.set_file(filename)

    #  _
    # |_ |  _   _ _|_ ._ _  ._   _
    # |_ | (/_ (_  |_ | (_) | | _>
    #
    ezfio.set_electrons_elec_alpha_num(res.num_alpha)
    ezfio.set_electrons_elec_beta_num(res.num_beta)

    #
    # |\ |      _ |  _  o
    # | \| |_| (_ | (/_ |
    #

    # ~#~#~#~ #
    # I n i t #
    # ~#~#~#~ #

    charge = []
    coord_x = []
    coord_y = []
    coord_z = []

    # ~#~#~#~#~#~#~ #
    # P a r s i n g #
    # ~#~#~#~#~#~#~ #

    for a in res.geometry:
        charge.append(a.charge)
        if res.units == 'BOHR':
            coord_x.append(a.coord[0])
            coord_y.append(a.coord[1])
            coord_z.append(a.coord[2])
        else:
            coord_x.append(a.coord[0] / a0)
            coord_y.append(a.coord[1] / a0)
            coord_z.append(a.coord[2] / a0)

    # ~#~#~#~#~ #
    # W r i t e #
    # ~#~#~#~#~ #

    ezfio.set_nuclei_nucl_num(len(res.geometry))
    ezfio.set_nuclei_nucl_charge(charge)

    # Transformt H1 into H
    import re
    p = re.compile(ur'(\d*)$')
    label = [p.sub("", x.name).capitalize() for x in res.geometry]
    ezfio.set_nuclei_nucl_label(label)

    ezfio.set_nuclei_nucl_coord(coord_x + coord_y + coord_z)

    #                 _
    #   /\   _   _   |_)  _.  _ o  _
    #  /--\ (_) _>   |_) (_| _> | _>
    #

    # ~#~#~#~ #
    # I n i t #
    # ~#~#~#~ #

    import string
    at = []
    num_prim = []
    power_x = []
    power_y = []
    power_z = []
    coefficient = []
    exponent = []

    res.clean_contractions()
    res.convert_to_cartesian()

    # ~#~#~#~#~#~#~ #
    # P a r s i n g #
    # ~#~#~#~#~#~#~ #

    for b in res.basis:
        c = b.center
        for i, atom in enumerate(res.geometry):
            if atom.coord == c:
                at.append(i + 1)
        num_prim.append(len(b.prim))
        s = b.sym
        power_x.append(string.count(s, "x"))
        power_y.append(string.count(s, "y"))
        power_z.append(string.count(s, "z"))
        coefficient.append(b.coef)
        exponent.append([p.expo for p in b.prim])

    # ~#~#~#~#~ #
    # W r i t e #
    # ~#~#~#~#~ #

    ezfio.set_ao_basis_ao_num(len(res.basis))
    ezfio.set_ao_basis_ao_nucl(at)
    ezfio.set_ao_basis_ao_prim_num(num_prim)
    ezfio.set_ao_basis_ao_power(power_x + power_y + power_z)

    # ~#~#~#~#~#~#~ #
    # P a r s i n g #
    # ~#~#~#~#~#~#~ #

    prim_num_max = ezfio.get_ao_basis_ao_prim_num_max()

    for i in range(len(res.basis)):
        coefficient[i] += [
            0. for j in range(len(coefficient[i]), prim_num_max)
        ]
        exponent[i] += [0. for j in range(len(exponent[i]), prim_num_max)]

    coefficient = reduce(lambda x, y: x + y, coefficient, [])
    exponent = reduce(lambda x, y: x + y, exponent, [])

    coef = []
    expo = []
    for i in range(prim_num_max):
        for j in range(i, len(coefficient), prim_num_max):
            coef.append(coefficient[j])
            expo.append(exponent[j])

    # ~#~#~#~#~ #
    # W r i t e #
    # ~#~#~#~#~ #

    ezfio.set_ao_basis_ao_coef(coef)
    ezfio.set_ao_basis_ao_expo(expo)
    ezfio.set_ao_basis_ao_basis("Read by resultsFile")

    #                _
    # |\/|  _   _   |_)  _.  _ o  _
    # |  | (_) _>   |_) (_| _> | _>
    #

    # ~#~#~#~ #
    # I n i t #
    # ~#~#~#~ #

    MoTag = res.determinants_mo_type
    ezfio.set_mo_basis_mo_label('Orthonormalized')
    MO_type = MoTag
    allMOs = res.mo_sets[MO_type]

    # ~#~#~#~#~#~#~ #
    # P a r s i n g #
    # ~#~#~#~#~#~#~ #

    try:
        closed = [(allMOs[i].eigenvalue, i) for i in res.closed_mos]
        active = [(allMOs[i].eigenvalue, i) for i in res.active_mos]
        virtual = [(allMOs[i].eigenvalue, i) for i in res.virtual_mos]
    except:
        closed = []
        virtual = []
        active = [(allMOs[i].eigenvalue, i) for i in range(len(allMOs))]

    closed = map(lambda x: x[1], closed)
    active = map(lambda x: x[1], active)
    virtual = map(lambda x: x[1], virtual)
    MOindices = closed + active + virtual

    MOs = []
    for i in MOindices:
        MOs.append(allMOs[i])

    mo_tot_num = len(MOs)
    while len(MOindices) < mo_tot_num:
        MOindices.append(len(MOindices))

    MOmap = list(MOindices)
    for i in range(len(MOindices)):
        MOmap[i] = MOindices.index(i)

    energies = []
    for i in xrange(mo_tot_num):
        energies.append(MOs[i].eigenvalue)

    if res.occ_num is not None:
        OccNum = []
        for i in MOindices:
            OccNum.append(res.occ_num[MO_type][i])

        while len(OccNum) < mo_tot_num:
            OccNum.append(0.)

    MoMatrix = []
    sym0 = [i.sym for i in res.mo_sets[MO_type]]
    sym = [i.sym for i in res.mo_sets[MO_type]]
    for i in xrange(len(sym)):
        sym[MOmap[i]] = sym0[i]

    MoMatrix = []
    for i in xrange(len(MOs)):
        m = MOs[i]
        for coef in m.vector:
            MoMatrix.append(coef)

    while len(MoMatrix) < len(MOs[0].vector)**2:
        MoMatrix.append(0.)

    # ~#~#~#~#~ #
    # W r i t e #
    # ~#~#~#~#~ #

    ezfio.set_mo_basis_mo_tot_num(mo_tot_num)
    ezfio.set_mo_basis_mo_occ(OccNum)
    ezfio.set_mo_basis_mo_coef(MoMatrix)

    # ______                   _
    # | ___ \                 | |
    # | |_/ /__  ___ _   _  __| | ___
    # |  __/ __|/ _ \ | | |/ _` |/ _ \
    # | |  \__ \  __/ |_| | (_| | (_) |
    # \_|  |___/\___|\__,_|\__,_|\___/
    #

    # INPUT
    # {% for lanel,zcore, l_block in l_atom  $}
    #       #local l_block l=0}
    #       {label} GEN {zcore} {len(l_block)-1 #lmax_block}
    #       {% for l_param in l_block%}
    #                {len(l_param) # list of parameter aka n_max_bock_max(n)}
    #                {% for coef,n,zeta for l_param}
    #                    {coef,n, zeta}

    # OUTPUT

    # Local are 1 array padded by max(n_max_block) when l == 0  (output:k_loc_max)
    # v_k[n-2][atom] = value

    #Non Local are 2 array padded with max of lmax_block when l!=0 (output:lmax+1)  and max(n_max_block)whem l !=0 (kmax)
    # v_kl[l][n-2][atom] = value

    def pad(array, size, value=0):
        new_array = array
        for add in xrange(len(array), size):
            new_array.append(value)

        return new_array

    def parse_str(pseudo_str):
        '''Return 4d array  atom,l,n, attribute (attribute is coef, n, zeta)'''
        matrix = []
        array_l_max_block = []
        array_z_remove = []

        for block in [b for b in pseudo_str.split('\n\n') if b]:
            #First element is header, the rest are l_param
            array_party = [i for i in re.split(r"\n\d+\n", block) if i]

            z_remove, l_max_block = map(int, array_party[0].split()[-2:])
            array_l_max_block.append(l_max_block)
            array_z_remove.append(z_remove)

            x = []
            for l in array_party[1:]:
                y = []
                for coef_n_zeta in l.split('\n'):
                    z = coef_n_zeta.split()
                    if z: y.append(z)
                x.append(y)
            matrix.append(x)
        return (matrix, array_l_max_block, array_z_remove)

    def get_local_stuff(matrix):

        matrix_local_unpad = [atom[0] for atom in matrix]
        k_loc_max = max(len(i) for i in matrix_local_unpad)

        matrix_local = [
            pad(ll, k_loc_max, [0., 2, 0.]) for ll in matrix_local_unpad
        ]
        m_coef = [[float(i[0]) for i in atom] for atom in matrix_local]
        m_n = [[int(i[1]) - 2 for i in atom] for atom in matrix_local]
        m_zeta = [[float(i[2]) for i in atom] for atom in matrix_local]
        return (k_loc_max, m_coef, m_n, m_zeta)

    def get_non_local_stuff(matrix):

        matrix_unlocal_unpad = [atom[1:] for atom in matrix]
        l_max_block = max(len(i) for i in matrix_unlocal_unpad)
        k_max = max(
            [len(item) for row in matrix_unlocal_unpad for item in row])

        matrix_unlocal_semipaded = [[
            pad(item, k_max, [0., 2, 0.]) for item in row
        ] for row in matrix_unlocal_unpad]

        empty_row = [[0., 2, 0.] for k in range(l_max_block)]
        matrix_unlocal = [
            pad(ll, l_max_block, empty_row) for ll in matrix_unlocal_semipaded
        ]

        m_coef_noloc = [[[float(k[0]) for k in j] for j in i]
                        for i in matrix_unlocal]
        m_n_noloc = [[[int(k[1]) - 2 for k in j] for j in i]
                     for i in matrix_unlocal]
        m_zeta_noloc = [[[float(k[2]) for k in j] for j in i]
                        for i in matrix_unlocal]

        return (l_max_block, k_max, m_coef_noloc, m_n_noloc, m_zeta_noloc)

    try:
        pseudo_str = []
        label = ezfio.get_nuclei_nucl_label()
        for ecp in res.pseudo:
            pseudo_str += [
                "%(label)s GEN %(zcore)d %(lmax)d" % {
                    "label": label[ecp["atom"] - 1],
                    "zcore": ecp["zcore"],
                    "lmax": ecp["lmax"]
                }
            ]
            lmax = ecp["lmax"]
            for l in [lmax] + list(range(0, lmax)):
                pseudo_str += ["%d" % len(ecp[str(l)])]
                for t in ecp[str(l)]:
                    pseudo_str += ["%f  %d  %f" % t]
            pseudo_str += [""]
        pseudo_str = "\n".join(pseudo_str)

        matrix, array_l_max_block, array_z_remove = parse_str(pseudo_str)
        array_z_remove = map(float, array_z_remove)
    except:
        ezfio.set_pseudo_do_pseudo(False)
    else:
        ezfio.set_pseudo_do_pseudo(True)

        # ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~ #
        # Z _ e f f , a l p h a / b e t a _ e l e c #
        # ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~ #

        ezfio.set_pseudo_nucl_charge_remove(array_z_remove)
        charge = ezfio.get_nuclei_nucl_charge()
        charge = [i - j for i, j in zip(charge, array_z_remove)]
        ezfio.set_nuclei_nucl_charge(charge)

        import math
        num_elec_diff = sum(array_z_remove) / 2
        nalpha = ezfio.get_electrons_elec_alpha_num() - num_elec_diff
        nbeta = ezfio.get_electrons_elec_beta_num() - num_elec_diff

        ezfio.set_electrons_elec_alpha_num(nalpha)
        ezfio.set_electrons_elec_beta_num(nbeta)

        # Change all the array 'cause EZFIO
        #   v_kl (v, l) => v_kl(l,v)
        #    v_kl => zip(*_v_kl)
        # [[7.0, 79.74474797, -49.45159098], [1.0, 5.41040609, -4.60151975]]
        # [(7.0, 1.0), (79.74474797, 5.41040609), (-49.45159098, -4.60151975)]

        # ~#~#~#~#~ #
        # L o c a l #
        # ~#~#~#~#~ #

        klocmax, m_coef, m_n, m_zeta = get_local_stuff(matrix)
        ezfio.pseudo_pseudo_klocmax = klocmax

        ezfio.pseudo_pseudo_v_k = zip(*m_coef)
        ezfio.pseudo_pseudo_n_k = zip(*m_n)
        ezfio.pseudo_pseudo_dz_k = zip(*m_zeta)

        # ~#~#~#~#~#~#~#~#~ #
        # N o n _ L o c a l #
        # ~#~#~#~#~#~#~#~#~ #

        l_max_block, k_max, m_coef_noloc, m_n_noloc, m_zeta_noloc = get_non_local_stuff(
            matrix)

        ezfio.pseudo_pseudo_lmax = l_max_block - 1
        ezfio.pseudo_pseudo_kmax = k_max

        ezfio.pseudo_pseudo_v_kl = zip(*m_coef_noloc)
        ezfio.pseudo_pseudo_n_kl = zip(*m_n_noloc)
        ezfio.pseudo_pseudo_dz_kl = zip(*m_zeta_noloc)
#!/usr/bin/python

print "#QP -> QMCPACK"

# ___           
#  |  ._  o _|_ 
# _|_ | | |  |_ 
#

from ezfio import ezfio

import os
import sys
ezfio_path = sys.argv[1]

ezfio.set_file(ezfio_path)

do_pseudo = ezfio.get_pseudo_do_pseudo()
if do_pseudo:
    print "do_pseudo True"
    from qp_path import QP_ROOT

    l_ele_path = os.path.join(QP_ROOT,"data","list_element.txt")
    with open(l_ele_path, "r") as f:
        data_raw = f.read()

    l_element_raw = data_raw.split("\n")
    l_element = [element_raw.split() for element_raw in l_element_raw]
    d_z = dict((abr, z) for (z, abr, ele) in l_element)
else:
    print "do_pseudo False"
def write_ezfio(res, filename):

    res.clean_uncontractions()
    ezfio.set_file(filename)

    #  _
    # |_ |  _   _ _|_ ._ _  ._   _
    # |_ | (/_ (_  |_ | (_) | | _>
    #
    ezfio.set_electrons_elec_alpha_num(res.num_alpha)
    ezfio.set_electrons_elec_beta_num(res.num_beta)

    #
    # |\ |      _ |  _  o
    # | \| |_| (_ | (/_ |
    #

    # ~#~#~#~ #
    # I n i t #
    # ~#~#~#~ #

    charge = []
    coord_x = []
    coord_y = []
    coord_z = []

    # ~#~#~#~#~#~#~ #
    # P a r s i n g #
    # ~#~#~#~#~#~#~ #

    for a in res.geometry:
        charge.append(a.charge)
        if res.units == 'BOHR':
            coord_x.append(a.coord[0])
            coord_y.append(a.coord[1])
            coord_z.append(a.coord[2])
        else:
            coord_x.append(a.coord[0] / a0)
            coord_y.append(a.coord[1] / a0)
            coord_z.append(a.coord[2] / a0)

    # ~#~#~#~#~ #
    # W r i t e #
    # ~#~#~#~#~ #

    ezfio.set_nuclei_nucl_num(len(res.geometry))
    ezfio.set_nuclei_nucl_charge(charge)

    # Transformt H1 into H
    import re
    p = re.compile(ur'(\d*)$')
    label = [p.sub("", x.name).capitalize() for x in res.geometry]
    ezfio.set_nuclei_nucl_label(label)

    ezfio.set_nuclei_nucl_coord(coord_x + coord_y + coord_z)

    #                 _
    #   /\   _   _   |_)  _.  _ o  _
    #  /--\ (_) _>   |_) (_| _> | _>
    #

    # ~#~#~#~ #
    # I n i t #
    # ~#~#~#~ #

    import string
    at = []
    num_prim = []
    power_x = []
    power_y = []
    power_z = []
    coefficient = []
    exponent = []

    res.clean_contractions()
    res.convert_to_cartesian()

    # ~#~#~#~#~#~#~ #
    # P a r s i n g #
    # ~#~#~#~#~#~#~ #

    for b in res.basis:
        c = b.center
        for i, atom in enumerate(res.geometry):
            if atom.coord == c:
                at.append(i + 1)
        num_prim.append(len(b.prim))
        s = b.sym
        power_x.append(string.count(s, "x"))
        power_y.append(string.count(s, "y"))
        power_z.append(string.count(s, "z"))
        coefficient.append(b.coef)
        exponent.append([p.expo for p in b.prim])

    # ~#~#~#~#~ #
    # W r i t e #
    # ~#~#~#~#~ #

    ezfio.set_ao_basis_ao_num(len(res.basis))
    ezfio.set_ao_basis_ao_nucl(at)
    ezfio.set_ao_basis_ao_prim_num(num_prim)
    ezfio.set_ao_basis_ao_power(power_x + power_y + power_z)

    # ~#~#~#~#~#~#~ #
    # P a r s i n g #
    # ~#~#~#~#~#~#~ #

    prim_num_max = ezfio.get_ao_basis_ao_prim_num_max()

    for i in range(len(res.basis)):
        coefficient[
            i] += [0. for j in range(len(coefficient[i]), prim_num_max)]
        exponent[i] += [0. for j in range(len(exponent[i]), prim_num_max)]

    coefficient = reduce(lambda x, y: x + y, coefficient, [])
    exponent = reduce(lambda x, y: x + y, exponent, [])

    coef = []
    expo = []
    for i in range(prim_num_max):
        for j in range(i, len(coefficient), prim_num_max):
            coef.append(coefficient[j])
            expo.append(exponent[j])

    # ~#~#~#~#~ #
    # W r i t e #
    # ~#~#~#~#~ #

    ezfio.set_ao_basis_ao_coef(coef)
    ezfio.set_ao_basis_ao_expo(expo)
    ezfio.set_ao_basis_ao_basis("Read by resultsFile")

    #                _
    # |\/|  _   _   |_)  _.  _ o  _
    # |  | (_) _>   |_) (_| _> | _>
    #

    # ~#~#~#~ #
    # I n i t #
    # ~#~#~#~ #

    MoTag = res.determinants_mo_type
    ezfio.set_mo_basis_mo_label('Orthonormalized')
    MO_type = MoTag
    allMOs = res.mo_sets[MO_type]

    # ~#~#~#~#~#~#~ #
    # P a r s i n g #
    # ~#~#~#~#~#~#~ #

    try:
        closed = [(allMOs[i].eigenvalue, i) for i in res.closed_mos]
        active = [(allMOs[i].eigenvalue, i) for i in res.active_mos]
        virtual = [(allMOs[i].eigenvalue, i) for i in res.virtual_mos]
    except:
        closed = []
        virtual = []
        active = [(allMOs[i].eigenvalue, i) for i in range(len(allMOs))]

    closed = map(lambda x: x[1], closed)
    active = map(lambda x: x[1], active)
    virtual = map(lambda x: x[1], virtual)
    MOindices = closed + active + virtual

    MOs = []
    for i in MOindices:
        MOs.append(allMOs[i])

    mo_tot_num = len(MOs)
    while len(MOindices) < mo_tot_num:
        MOindices.append(len(MOindices))

    MOmap = list(MOindices)
    for i in range(len(MOindices)):
        MOmap[i] = MOindices.index(i)

    energies = []
    for i in xrange(mo_tot_num):
        energies.append(MOs[i].eigenvalue)

    if res.occ_num is not None:
        OccNum = []
        for i in MOindices:
            OccNum.append(res.occ_num[MO_type][i])

        while len(OccNum) < mo_tot_num:
            OccNum.append(0.)

    MoMatrix = []
    sym0 = [i.sym for i in res.mo_sets[MO_type]]
    sym = [i.sym for i in res.mo_sets[MO_type]]
    for i in xrange(len(sym)):
        sym[MOmap[i]] = sym0[i]

    MoMatrix = []
    for i in xrange(len(MOs)):
        m = MOs[i]
        for coef in m.vector:
            MoMatrix.append(coef)

    while len(MoMatrix) < len(MOs[0].vector) ** 2:
        MoMatrix.append(0.)

    # ~#~#~#~#~ #
    # W r i t e #
    # ~#~#~#~#~ #

    ezfio.set_mo_basis_mo_tot_num(mo_tot_num)
    ezfio.set_mo_basis_mo_occ(OccNum)
    ezfio.set_mo_basis_mo_coef(MoMatrix)

    # ______                   _
    # | ___ \                 | |
    # | |_/ /__  ___ _   _  __| | ___
    # |  __/ __|/ _ \ | | |/ _` |/ _ \
    # | |  \__ \  __/ |_| | (_| | (_) |
    # \_|  |___/\___|\__,_|\__,_|\___/
    #

    ezfio.set_pseudo_do_pseudo(False)
Exemplo n.º 14
0
def run_full_ci_10k_pt2_end(geo, basis, pseudo):
    """
    Run a Full_ci with 10k with the TruePT2
    EZFIO path = geo.ezfio
    """

    # ~#~#~#~#~#~#~#~#~#~ #
    # R e f _ e n e r g y #
    # ~#~#~#~#~#~#~#~#~#~ #

    ref_energy_var = defaultdict(dict)
    ref_energy_pt2 = defaultdict(dict)

    ref_energy_var["sto-3g"]["methane"] = Energy(-39.8058687211, None)
    ref_energy_pt2["sto-3g"]["methane"] = Energy(-39.8059180427, None)

    # ~#~#~#~ #
    # I n i t #
    # ~#~#~#~ #

    ezfio.set_file("{0}.ezfio".format(geo))

    # ~#~#~#~#~#~#~#~#~#~#~#~#~ #
    # S e t _ p a r a m e t e r #
    # ~#~#~#~#~#~#~#~#~#~#~#~#~ #

    ezfio.determinants_n_det_max = 10000
    ezfio.determinants_n_det_max_jacobi = 10000
    ezfio.determinants_n_states = 1
    ezfio.determinants_read_wf = 1
    ezfio.determinants_s2_eig = False

    ezfio.determinants_threshold_generators = 0.99
    ezfio.determinants_threshold_selectors = 0.999

    ezfio.perturbation_do_pt2_end = True
    ezfio.perturbation_pt2_max = 1.e-4

    # ~#~#~ #
    # R u n #
    # ~#~#~ #

    #    cmd = "{0}/Full_CI/full_ci {1}.ezfio/".format(QP_src,geo)
    cmd = "qp_run full_ci {0}.ezfio/".format(geo)
    subprocess.check_call([cmd], shell=True)

    # ~#~#~#~#~ #
    # C h e c k #
    # ~#~#~#~#~ #

    cur_var = ezfio.get_full_ci_energy()
    cur_pt2 = ezfio.get_full_ci_energy_pt2()

    ref_var = ref_energy_var[basis][geo]
    ref_pt2 = ref_energy_pt2[basis][geo]

    if pseudo:
        ref_var = ref_var.with_pseudo
        ref_pt2 = ref_pt2.with_pseudo
    else:
        ref_var = ref_var.without_pseudo
        ref_pt2 = ref_pt2.without_pseudo

    t = [
        abs(cur_var - ref_var) <= precision,
        abs(cur_pt2 - ref_pt2) <= precision
    ]

    if all(t):
        return True
    else:
        raise ValueError(
            get_error_message([ref_var, ref_pt2], [cur_var, cur_pt2]))
Exemplo n.º 15
0
def run_hf(geo, basis, mult=1, pseudo=False, remove_after_sucess=True):
    """
    Run a simle by default hf
    EZFIO path = geo.ezfio
    """

    # ~#~#~#~#~#~#~#~#~#~ #
    # R e f _ e n e r g y #
    # ~#~#~#~#~#~#~#~#~#~ #

    ref_energy = defaultdict(defaultdict)

    ref_energy["sto-3g"]["methane"] = Energy(-39.7267433402, None)
    ref_energy["vdz"]["SO2"] = Energy(None, -41.48912297776174)
    ref_energy["vdz"]["HBO"] = Energy(None, -19.11982530413317)

    # ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~ #
    # G l o b a l _ v a r i a b l e #
    # ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~ #

    global has_hf_alredy
    has_hf_alredy = True

    # ~#~#~#~ #
    # I n i t #
    # ~#~#~#~ #

    init_folder(geo, basis, mult, pseudo)
    ezfio.set_file("{0}.ezfio".format(geo))

    # ~#~#~#~#~#~#~#~#~#~#~#~#~ #
    # S e t _ p a r a m e t e r #
    # ~#~#~#~#~#~#~#~#~#~#~#~#~ #
    ezfio.bielec_integrals_direct = False
    ezfio.bielec_integrals_threshold_ao = 1.e-15
    ezfio.bielec_integrals_disk_access_ao_integrals = "None"

    ezfio.bielec_integrals_threshold_mo = 1.e-15
    ezfio.bielec_integrals_disk_access_mo_integrals = "None"

    ezfio.hartree_fock_mo_guess_type = "Huckel"
    ezfio.hartree_fock_thresh_scf = 1.e-10
    ezfio.hartree_fock_n_it_scf_max = 100

    ezfio.pseudo_do_pseudo = pseudo

    # ~#~#~ #
    # R u n #
    # ~#~#~ #

    cmd = "qp_run SCF {0}.ezfio/".format(geo)
    subprocess.check_call([cmd], shell=True)

    # ~#~#~#~#~ #
    # C h e c k #
    # ~#~#~#~#~ #

    cur_e = ezfio.get_hartree_fock_energy()

    ref_e = ref_energy[basis][geo]
    if pseudo:
        ref_e = ref_e.with_pseudo
    else:
        ref_e = ref_e.without_pseudo

    if abs(cur_e - ref_e) <= precision:

        if remove_after_sucess:
            subprocess.call(["rm -R {0}.ezfio".format(geo)], shell=True)

        return True

    else:
        raise ValueError(get_error_message([ref_e], [cur_e]))
Exemplo n.º 16
0
def run_full_ci_10k_pt2_end(geo, basis, pseudo):
    """
    Run a Full_ci with 10k with the TruePT2
    EZFIO path = geo.ezfio
    """

    # ~#~#~#~#~#~#~#~#~#~ #
    # R e f _ e n e r g y #
    # ~#~#~#~#~#~#~#~#~#~ #

    ref_energy_var = defaultdict(dict)
    ref_energy_pt2 = defaultdict(dict)

    ref_energy_var["sto-3g"]["methane"] = Energy(-39.8058687211, None)
    ref_energy_pt2["sto-3g"]["methane"] = Energy(-39.8059180427, None)

    # ~#~#~#~ #
    # I n i t #
    # ~#~#~#~ #

    ezfio.set_file("{0}.ezfio".format(geo))

    # ~#~#~#~#~#~#~#~#~#~#~#~#~ #
    # S e t _ p a r a m e t e r #
    # ~#~#~#~#~#~#~#~#~#~#~#~#~ #

    ezfio.full_ci_do_pt2_end = True
    ezfio.full_ci_n_det_max_fci = 10000
    ezfio.full_ci_pt2_max = 1.e-8

    # ~#~#~ #
    # R u n #
    # ~#~#~ #

    cmd = "qp_run full_ci {0}.ezfio/".format(geo)
    subprocess.check_call([cmd], shell=True)

    # ~#~#~#~#~ #
    # C h e c k #
    # ~#~#~#~#~ #

    cur_var = ezfio.get_full_ci_energy()
    cur_pt2 = ezfio.get_full_ci_energy_pt2()

    ref_var = ref_energy_var[basis][geo]
    ref_pt2 = ref_energy_pt2[basis][geo]

    if pseudo:
        ref_var = ref_var.with_pseudo
        ref_pt2 = ref_pt2.with_pseudo
    else:
        ref_var = ref_var.without_pseudo
        ref_pt2 = ref_pt2.without_pseudo

    t = [abs(cur_var - ref_var) <= precision,
         abs(cur_pt2 - ref_pt2) <= precision]

    if all(t):
        return True
    else:
        raise ValueError(get_error_message([ref_var, ref_pt2],
                                           [cur_var, cur_pt2]))
Exemplo n.º 17
0
def run_hf(geo, basis, mult=1, pseudo=False, remove_after_sucess=True):
    """
    Run a simle by default hf
    EZFIO path = geo.ezfio
    """

    # ~#~#~#~#~#~#~#~#~#~ #
    # R e f _ e n e r g y #
    # ~#~#~#~#~#~#~#~#~#~ #

    ref_energy = defaultdict(defaultdict)

    ref_energy["sto-3g"]["methane"] = Energy(-39.7267433402, None)
    ref_energy["vdz"]["SO2"] = Energy(None, -41.48912297776174)
    #   ref_energy["vdz"]["HBO"] = Energy(None, -19.1198231418)
    ref_energy["vdz"]["HBO"] = Energy(None, -19.1198254041)

    # ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~ #
    # G l o b a l _ v a r i a b l e #
    # ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~ #

    global has_hf_alredy
    has_hf_alredy = True

    # ~#~#~#~ #
    # I n i t #
    # ~#~#~#~ #

    init_folder(geo, basis, mult, pseudo)
    ezfio.set_file("{0}.ezfio".format(geo))

    # ~#~#~#~#~#~#~#~#~#~#~#~#~ #
    # S e t _ p a r a m e t e r #
    # ~#~#~#~#~#~#~#~#~#~#~#~#~ #
    ezfio.integrals_bielec_direct = False
    ezfio.integrals_bielec_threshold_ao = 1.e-15
    ezfio.integrals_bielec_disk_access_ao_integrals = "None"

    ezfio.integrals_bielec_threshold_mo = 1.e-15
    ezfio.integrals_bielec_disk_access_mo_integrals = "None"

    ezfio.hartree_fock_mo_guess_type = "Huckel"
    ezfio.hartree_fock_thresh_scf = 1.e-10
    ezfio.hartree_fock_n_it_scf_max = 100

    ezfio.pseudo_do_pseudo = pseudo

    # ~#~#~ #
    # R u n #
    # ~#~#~ #

    #    cmd = "{0}/Hartree_Fock/SCF {1}.ezfio/".format(QP_src,geo)
    cmd = "qp_run SCF {0}.ezfio/".format(geo)
    subprocess.check_call([cmd], shell=True)

    # ~#~#~#~#~ #
    # C h e c k #
    # ~#~#~#~#~ #

    cur_e = ezfio.get_hartree_fock_energy()

    ref_e = ref_energy[basis][geo]
    if pseudo:
        ref_e = ref_e.with_pseudo
    else:
        ref_e = ref_e.without_pseudo

    if abs(cur_e - ref_e) <= precision:

        if remove_after_sucess:
            subprocess.call(["rm -R {0}.ezfio".format(geo)], shell=True)

        return True

    else:
        raise ValueError(get_error_message([ref_e], [cur_e]))
def write_ezfio(res, filename):

    res.clean_uncontractions()
    ezfio.set_file(filename)

    #  _
    # |_ |  _   _ _|_ ._ _  ._   _
    # |_ | (/_ (_  |_ | (_) | | _>
    #
    ezfio.set_electrons_elec_alpha_num(res.num_alpha)
    ezfio.set_electrons_elec_beta_num(res.num_beta)

    #
    # |\ |      _ |  _  o
    # | \| |_| (_ | (/_ |
    #

    # ~#~#~#~ #
    # I n i t #
    # ~#~#~#~ #

    charge = []
    coord_x = []
    coord_y = []
    coord_z = []

    # ~#~#~#~#~#~#~ #
    # P a r s i n g #
    # ~#~#~#~#~#~#~ #

    for a in res.geometry:
        charge.append(a.charge)
        if res.units == 'BOHR':
            coord_x.append(a.coord[0])
            coord_y.append(a.coord[1])
            coord_z.append(a.coord[2])
        else:
            coord_x.append(a.coord[0] / a0)
            coord_y.append(a.coord[1] / a0)
            coord_z.append(a.coord[2] / a0)

    # ~#~#~#~#~ #
    # W r i t e #
    # ~#~#~#~#~ #

    ezfio.set_nuclei_nucl_num(len(res.geometry))
    ezfio.set_nuclei_nucl_charge(charge)

    # Transformt H1 into H
    import re
    p = re.compile(ur'(\d*)$')
    label = [p.sub("", x.name).capitalize() for x in res.geometry]
    ezfio.set_nuclei_nucl_label(label)

    ezfio.set_nuclei_nucl_coord(coord_x + coord_y + coord_z)

    #                 _
    #   /\   _   _   |_)  _.  _ o  _
    #  /--\ (_) _>   |_) (_| _> | _>
    #

    # ~#~#~#~ #
    # I n i t #
    # ~#~#~#~ #

    import string
    at = []
    num_prim = []
    power_x = []
    power_y = []
    power_z = []
    coefficient = []
    exponent = []

    res.convert_to_cartesian()
    # ~#~#~#~#~#~#~ #
    # P a r s i n g #
    # ~#~#~#~#~#~#~ #

    for b in res.basis:
        c = b.center
        for i, atom in enumerate(res.geometry):
            if atom.coord == c:
                at.append(i + 1)
        num_prim.append(len(b.prim))
        s = b.sym
        power_x.append(string.count(s, "x"))
        power_y.append(string.count(s, "y"))
        power_z.append(string.count(s, "z"))
        coefficient.append(b.coef)
        exponent.append([p.expo for p in b.prim])

    # ~#~#~#~#~ #
    # W r i t e #
    # ~#~#~#~#~ #

    ezfio.set_ao_basis_ao_num(len(res.basis))
    ezfio.set_ao_basis_ao_nucl(at)
    ezfio.set_ao_basis_ao_prim_num(num_prim)
    ezfio.set_ao_basis_ao_power(power_x + power_y + power_z)

    # ~#~#~#~#~#~#~ #
    # P a r s i n g #
    # ~#~#~#~#~#~#~ #

    prim_num_max = ezfio.get_ao_basis_ao_prim_num_max()

    for i in range(len(res.basis)):
        coefficient[i] += [
            0. for j in range(len(coefficient[i]), prim_num_max)
        ]
        exponent[i] += [0. for j in range(len(exponent[i]), prim_num_max)]

    coefficient = reduce(lambda x, y: x + y, coefficient, [])
    exponent = reduce(lambda x, y: x + y, exponent, [])

    coef = []
    expo = []
    for i in range(prim_num_max):
        for j in range(i, len(coefficient), prim_num_max):
            coef.append(coefficient[j])
            expo.append(exponent[j])

    # ~#~#~#~#~ #
    # W r i t e #
    # ~#~#~#~#~ #

    ezfio.set_ao_basis_ao_coef(coef)
    ezfio.set_ao_basis_ao_expo(expo)
    ezfio.set_ao_basis_ao_basis("Read by resultsFile")

    #                _
    # |\/|  _   _   |_)  _.  _ o  _
    # |  | (_) _>   |_) (_| _> | _>
    #

    # ~#~#~#~ #
    # I n i t #
    # ~#~#~#~ #

    MoTag = res.determinants_mo_type
    ezfio.set_mo_basis_mo_label('Orthonormalized')
    MO_type = MoTag
    allMOs = res.mo_sets[MO_type]

    # ~#~#~#~#~#~#~ #
    # P a r s i n g #
    # ~#~#~#~#~#~#~ #

    try:
        closed = [(allMOs[i].eigenvalue, i) for i in res.closed_mos]
        active = [(allMOs[i].eigenvalue, i) for i in res.active_mos]
        virtual = [(allMOs[i].eigenvalue, i) for i in res.virtual_mos]
    except:
        closed = []
        virtual = []
        active = [(allMOs[i].eigenvalue, i) for i in range(len(allMOs))]

    closed = map(lambda x: x[1], closed)
    active = map(lambda x: x[1], active)
    virtual = map(lambda x: x[1], virtual)
    MOindices = closed + active + virtual

    MOs = []
    for i in MOindices:
        MOs.append(allMOs[i])

    mo_tot_num = len(MOs)
    while len(MOindices) < mo_tot_num:
        MOindices.append(len(MOindices))

    MOmap = list(MOindices)
    for i in range(len(MOindices)):
        MOmap[i] = MOindices.index(i)

    energies = []
    for i in xrange(mo_tot_num):
        energies.append(MOs[i].eigenvalue)

    if res.occ_num is not None:
        OccNum = []
        for i in MOindices:
            OccNum.append(res.occ_num[MO_type][i])

        while len(OccNum) < mo_tot_num:
            OccNum.append(0.)

    MoMatrix = []
    sym0 = [i.sym for i in res.mo_sets[MO_type]]
    sym = [i.sym for i in res.mo_sets[MO_type]]
    for i in xrange(len(sym)):
        sym[MOmap[i]] = sym0[i]

    MoMatrix = []
    for i in xrange(len(MOs)):
        m = MOs[i]
        for coef in m.vector:
            MoMatrix.append(coef)

    while len(MoMatrix) < len(MOs[0].vector)**2:
        MoMatrix.append(0.)

    # ~#~#~#~#~ #
    # W r i t e #
    # ~#~#~#~#~ #

    ezfio.set_mo_basis_mo_tot_num(mo_tot_num)
    ezfio.set_mo_basis_mo_occ(OccNum)
    ezfio.set_mo_basis_mo_coef(MoMatrix)

    try:
        lmax = 0
        nucl_charge_remove = []
        klocmax = 0
        kmax = 0
        nucl_num = len(res.geometry)
        for ecp in res.pseudo:
            lmax_local = ecp['lmax']
            lmax = max(lmax_local, lmax)
            nucl_charge_remove.append(ecp['zcore'])
            klocmax = max(klocmax, len(ecp[str(lmax_local)]))
            for l in range(lmax_local):
                kmax = max(kmax, len(ecp[str(l)]))
        lmax = lmax - 1
        ezfio.set_pseudo_pseudo_lmax(lmax)
        ezfio.set_pseudo_nucl_charge_remove(nucl_charge_remove)
        ezfio.set_pseudo_pseudo_klocmax(klocmax)
        ezfio.set_pseudo_pseudo_kmax(kmax)
        pseudo_n_k = [[0 for _ in range(nucl_num)] for _ in range(klocmax)]
        pseudo_v_k = [[0. for _ in range(nucl_num)] for _ in range(klocmax)]
        pseudo_dz_k = [[0. for _ in range(nucl_num)] for _ in range(klocmax)]
        pseudo_n_kl = [[[0 for _ in range(nucl_num)] for _ in range(kmax)]
                       for _ in range(lmax + 1)]
        pseudo_v_kl = [[[0. for _ in range(nucl_num)] for _ in range(kmax)]
                       for _ in range(lmax + 1)]
        pseudo_dz_kl = [[[0. for _ in range(nucl_num)] for _ in range(kmax)]
                        for _ in range(lmax + 1)]
        for ecp in res.pseudo:
            lmax_local = ecp['lmax']
            klocmax = len(ecp[str(lmax_local)])
            atom = ecp['atom'] - 1
            for kloc in range(klocmax):
                try:
                    v, n, dz = ecp[str(lmax_local)][kloc]
                    pseudo_n_k[kloc][atom] = n - 2
                    pseudo_v_k[kloc][atom] = v
                    pseudo_dz_k[kloc][atom] = dz
                except:
                    pass
            for l in range(lmax_local):
                for k in range(kmax):
                    try:
                        v, n, dz = ecp[str(l)][k]
                        pseudo_n_kl[l][k][atom] = n - 2
                        pseudo_v_kl[l][k][atom] = v
                        pseudo_dz_kl[l][k][atom] = dz
                    except:
                        pass
        ezfio.set_pseudo_pseudo_n_k(pseudo_n_k)
        ezfio.set_pseudo_pseudo_v_k(pseudo_v_k)
        ezfio.set_pseudo_pseudo_dz_k(pseudo_dz_k)
        ezfio.set_pseudo_pseudo_n_kl(pseudo_n_kl)
        ezfio.set_pseudo_pseudo_v_kl(pseudo_v_kl)
        ezfio.set_pseudo_pseudo_dz_kl(pseudo_dz_kl)

        n_alpha = res.num_alpha
        n_beta = res.num_beta
        for i in range(nucl_num):
            charge[i] -= nucl_charge_remove[i]
            n_alpha -= nucl_charge_remove[i] / 2
            n_beta -= nucl_charge_remove[i] / 2
        ezfio.set_nuclei_nucl_charge(charge)
        ezfio.set_electrons_elec_alpha_num(n_alpha)
        ezfio.set_electrons_elec_beta_num(n_beta)

    except:
        ezfio.set_pseudo_do_pseudo(False)
    else:
        ezfio.set_pseudo_do_pseudo(True)
def write_ezfio(res, filename):

    res.clean_uncontractions()
    ezfio.set_file(filename)

    #  _
    # |_ |  _   _ _|_ ._ _  ._   _
    # |_ | (/_ (_  |_ | (_) | | _>
    #
    ezfio.set_electrons_elec_alpha_num(res.num_alpha)
    ezfio.set_electrons_elec_beta_num(res.num_beta)

    #
    # |\ |      _ |  _  o
    # | \| |_| (_ | (/_ |
    #

    # ~#~#~#~ #
    # I n i t #
    # ~#~#~#~ #

    charge = []
    coord_x = []
    coord_y = []
    coord_z = []

    # ~#~#~#~#~#~#~ #
    # P a r s i n g #
    # ~#~#~#~#~#~#~ #

    for a in res.geometry:
        charge.append(a.charge)
        if res.units == 'BOHR':
            coord_x.append(a.coord[0])
            coord_y.append(a.coord[1])
            coord_z.append(a.coord[2])
        else:
            coord_x.append(a.coord[0] / a0)
            coord_y.append(a.coord[1] / a0)
            coord_z.append(a.coord[2] / a0)

    # ~#~#~#~#~ #
    # W r i t e #
    # ~#~#~#~#~ #

    ezfio.set_nuclei_nucl_num(len(res.geometry))
    ezfio.set_nuclei_nucl_charge(charge)

    # Transformt H1 into H
    import re
    p = re.compile(ur'(\d*)$')
    label = [p.sub("", x.name).capitalize() for x in res.geometry]
    ezfio.set_nuclei_nucl_label(label)

    ezfio.set_nuclei_nucl_coord(coord_x + coord_y + coord_z)

    #                 _
    #   /\   _   _   |_)  _.  _ o  _
    #  /--\ (_) _>   |_) (_| _> | _>
    #

    # ~#~#~#~ #
    # I n i t #
    # ~#~#~#~ #

    import string
    at = []
    num_prim = []
    power_x = []
    power_y = []
    power_z = []
    coefficient = []
    exponent = []

    res.clean_contractions()
    res.convert_to_cartesian()

    # ~#~#~#~#~#~#~ #
    # P a r s i n g #
    # ~#~#~#~#~#~#~ #

    for b in res.basis:
        c = b.center
        for i, atom in enumerate(res.geometry):
            if atom.coord == c:
                at.append(i + 1)
        num_prim.append(len(b.prim))
        s = b.sym
        power_x.append(string.count(s, "x"))
        power_y.append(string.count(s, "y"))
        power_z.append(string.count(s, "z"))
        coefficient.append(b.coef)
        exponent.append([p.expo for p in b.prim])

    # ~#~#~#~#~ #
    # W r i t e #
    # ~#~#~#~#~ #

    ezfio.set_ao_basis_ao_num(len(res.basis))
    ezfio.set_ao_basis_ao_nucl(at)
    ezfio.set_ao_basis_ao_prim_num(num_prim)
    ezfio.set_ao_basis_ao_power(power_x + power_y + power_z)

    # ~#~#~#~#~#~#~ #
    # P a r s i n g #
    # ~#~#~#~#~#~#~ #

    prim_num_max = ezfio.get_ao_basis_ao_prim_num_max()

    for i in range(len(res.basis)):
        coefficient[
            i] += [0. for j in range(len(coefficient[i]), prim_num_max)]
        exponent[i] += [0. for j in range(len(exponent[i]), prim_num_max)]

    coefficient = reduce(lambda x, y: x + y, coefficient, [])
    exponent = reduce(lambda x, y: x + y, exponent, [])

    coef = []
    expo = []
    for i in range(prim_num_max):
        for j in range(i, len(coefficient), prim_num_max):
            coef.append(coefficient[j])
            expo.append(exponent[j])

    # ~#~#~#~#~ #
    # W r i t e #
    # ~#~#~#~#~ #

    ezfio.set_ao_basis_ao_coef(coef)
    ezfio.set_ao_basis_ao_expo(expo)
    ezfio.set_ao_basis_ao_basis("Read by resultsFile")

    #                _
    # |\/|  _   _   |_)  _.  _ o  _
    # |  | (_) _>   |_) (_| _> | _>
    #

    # ~#~#~#~ #
    # I n i t #
    # ~#~#~#~ #

    MoTag = res.determinants_mo_type
    ezfio.set_mo_basis_mo_label('Orthonormalized')
    MO_type = MoTag
    allMOs = res.mo_sets[MO_type]

    # ~#~#~#~#~#~#~ #
    # P a r s i n g #
    # ~#~#~#~#~#~#~ #

    try:
        closed = [(allMOs[i].eigenvalue, i) for i in res.closed_mos]
        active = [(allMOs[i].eigenvalue, i) for i in res.active_mos]
        virtual = [(allMOs[i].eigenvalue, i) for i in res.virtual_mos]
    except:
        closed = []
        virtual = []
        active = [(allMOs[i].eigenvalue, i) for i in range(len(allMOs))]

    closed = map(lambda x: x[1], closed)
    active = map(lambda x: x[1], active)
    virtual = map(lambda x: x[1], virtual)
    MOindices = closed + active + virtual

    MOs = []
    for i in MOindices:
        MOs.append(allMOs[i])

    mo_tot_num = len(MOs)
    while len(MOindices) < mo_tot_num:
        MOindices.append(len(MOindices))

    MOmap = list(MOindices)
    for i in range(len(MOindices)):
        MOmap[i] = MOindices.index(i)

    energies = []
    for i in xrange(mo_tot_num):
        energies.append(MOs[i].eigenvalue)

    if res.occ_num is not None:
        OccNum = []
        for i in MOindices:
            OccNum.append(res.occ_num[MO_type][i])

        while len(OccNum) < mo_tot_num:
            OccNum.append(0.)

    MoMatrix = []
    sym0 = [i.sym for i in res.mo_sets[MO_type]]
    sym = [i.sym for i in res.mo_sets[MO_type]]
    for i in xrange(len(sym)):
        sym[MOmap[i]] = sym0[i]

    MoMatrix = []
    for i in xrange(len(MOs)):
        m = MOs[i]
        for coef in m.vector:
            MoMatrix.append(coef)

    while len(MoMatrix) < len(MOs[0].vector)**2:
        MoMatrix.append(0.)

    # ~#~#~#~#~ #
    # W r i t e #
    # ~#~#~#~#~ #

    ezfio.set_mo_basis_mo_tot_num(mo_tot_num)
    ezfio.set_mo_basis_mo_occ(OccNum)
    ezfio.set_mo_basis_mo_coef(MoMatrix)

    # ______                   _
    # | ___ \                 | |
    # | |_/ /__  ___ _   _  __| | ___
    # |  __/ __|/ _ \ | | |/ _` |/ _ \
    # | |  \__ \  __/ |_| | (_| | (_) |
    # \_|  |___/\___|\__,_|\__,_|\___/
    #

    # INPUT
    # {% for lanel,zcore, l_block in l_atom  $}
    #       #local l_block l=0}
    #       {label} GEN {zcore} {len(l_block)-1 #lmax_block}
    #       {% for l_param in l_block%}
    #                {len(l_param) # list of parameter aka n_max_bock_max(n)}
    #                {% for coef,n,zeta for l_param}
    #                    {coef,n, zeta}


    # OUTPUT

    # Local are 1 array padded by max(n_max_block) when l == 0  (output:k_loc_max)
    # v_k[n-2][atom] = value

    #Non Local are 2 array padded with max of lmax_block when l!=0 (output:lmax+1)  and max(n_max_block)whem l !=0 (kmax)
    # v_kl[l][n-2][atom] = value

    def pad(array, size, value=0):
        new_array = array
        for add in xrange(len(array), size):
            new_array.append(value)

        return new_array

    def parse_str(pseudo_str):
        '''Return 4d array  atom,l,n, attribute (attribute is coef, n, zeta)'''
        matrix = []
        array_l_max_block = []
        array_z_remove = []

        for block in [b for b in pseudo_str.split('\n\n') if b]:
            #First element is header, the rest are l_param 
            array_party = [i for i in re.split(r"\n\d+\n", block) if i]

            z_remove, l_max_block = map(int, array_party[0].split()[-2:])
            array_l_max_block.append(l_max_block)
            array_z_remove.append(z_remove)

            x = []
            for l in array_party[1:]:
              y = []
              for coef_n_zeta in l.split('\n'):
                z = coef_n_zeta.split()
                if z : y.append(z)
              x.append(y)
            matrix.append(x)
        return (matrix, array_l_max_block, array_z_remove)

    def get_local_stuff(matrix):

        matrix_local_unpad = [atom[0] for atom in matrix]
        k_loc_max = max(len(i) for i in matrix_local_unpad)

        matrix_local = [ pad(ll, k_loc_max, [0., 2, 0.]) for ll in matrix_local_unpad]
        m_coef = [[float(i[0]) for i in atom] for atom in matrix_local]
        m_n = [[int(i[1]) - 2 for i in atom] for atom in matrix_local]
        m_zeta = [[float(i[2]) for i in atom] for atom in matrix_local]
        return (k_loc_max, m_coef, m_n, m_zeta)

    def get_non_local_stuff(matrix):

        matrix_unlocal_unpad = [atom[1:] for atom in matrix]
        l_max_block = max(len(i) for i in matrix_unlocal_unpad)
        k_max = max([len(item) for row in matrix_unlocal_unpad for item in row])

        matrix_unlocal_semipaded = [[pad(item, k_max, [0., 2, 0.]) for item in row] for row in matrix_unlocal_unpad]

        empty_row = [[0., 2, 0.] for k in range(l_max_block)]
        matrix_unlocal = [  pad(ll, l_max_block, empty_row) for ll in matrix_unlocal_semipaded ]

        m_coef_noloc = [[[float(k[0]) for k in j] for j in i] for i in matrix_unlocal]
        m_n_noloc =    [[[int(k[1]) - 2 for k in j] for j in i]  for i in matrix_unlocal]
        m_zeta_noloc = [[[float(k[2]) for k in j] for j in i] for i in matrix_unlocal]

        return (l_max_block, k_max, m_coef_noloc, m_n_noloc, m_zeta_noloc)

    try:
        pseudo_str = []
        label = ezfio.get_nuclei_nucl_label()
        for ecp in res.pseudo:
          pseudo_str += [ "%(label)s GEN %(zcore)d %(lmax)d" % { "label": label[ ecp["atom"]-1 ],
                "zcore": ecp["zcore"], "lmax": ecp["lmax"] } ]
          lmax = ecp["lmax"]
          for l in [lmax] + list(range(0,lmax)):
            pseudo_str += [ "%d"%len(ecp[str(l)]) ]
            for t in ecp[str(l)]:
              pseudo_str += [ "%f  %d  %f"%t ]
          pseudo_str += [""]
        pseudo_str = "\n".join(pseudo_str)
             
        matrix, array_l_max_block, array_z_remove = parse_str(pseudo_str)
        array_z_remove = map(float,array_z_remove)
    except:
        ezfio.set_pseudo_do_pseudo(False)
    else:
        ezfio.set_pseudo_do_pseudo(True)
        
        # ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~ #
        # Z _ e f f , a l p h a / b e t a _ e l e c #
        # ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~ #

        ezfio.set_pseudo_nucl_charge_remove(array_z_remove)
        charge = ezfio.get_nuclei_nucl_charge()
        charge = [ i - j for i, j in zip(charge, array_z_remove) ] 
        ezfio.set_nuclei_nucl_charge (charge)

        import math
        num_elec_diff = sum(array_z_remove)/2
        nalpha = ezfio.get_electrons_elec_alpha_num() - num_elec_diff
        nbeta  = ezfio.get_electrons_elec_beta_num() - num_elec_diff

        ezfio.set_electrons_elec_alpha_num(nalpha)
        ezfio.set_electrons_elec_beta_num( nbeta )

        # Change all the array 'cause EZFIO
        #   v_kl (v, l) => v_kl(l,v)
        #    v_kl => zip(*_v_kl)
        # [[7.0, 79.74474797, -49.45159098], [1.0, 5.41040609, -4.60151975]]
        # [(7.0, 1.0), (79.74474797, 5.41040609), (-49.45159098, -4.60151975)]

        # ~#~#~#~#~ #
        # L o c a l #
        # ~#~#~#~#~ #

        klocmax, m_coef, m_n, m_zeta = get_local_stuff(matrix)
        ezfio.pseudo_pseudo_klocmax = klocmax

        ezfio.pseudo_pseudo_v_k  = zip(*m_coef)
        ezfio.pseudo_pseudo_n_k  = zip(*m_n)
        ezfio.pseudo_pseudo_dz_k = zip(*m_zeta)

        # ~#~#~#~#~#~#~#~#~ #
        # N o n _ L o c a l #
        # ~#~#~#~#~#~#~#~#~ #

        l_max_block, k_max, m_coef_noloc, m_n_noloc, m_zeta_noloc = get_non_local_stuff(
            matrix)

        ezfio.pseudo_pseudo_lmax = l_max_block - 1
        ezfio.pseudo_pseudo_kmax = k_max

        ezfio.pseudo_pseudo_v_kl = zip(*m_coef_noloc)
        ezfio.pseudo_pseudo_n_kl = zip(*m_n_noloc)
        ezfio.pseudo_pseudo_dz_kl = zip(*m_zeta_noloc)
#!/usr/bin/env python
from ezfio import ezfio

import sys
filename = sys.argv[1]
num_elec, nucl_num, mo_tot_num = map(int, sys.argv[2:5])

nuclear_repulsion = float(sys.argv[5])
ao_num = int(sys.argv[6])
n_kpts = int(sys.argv[7])
n_aux = int(sys.argv[8])
ezfio.set_file(filename)

#ao_num = mo_tot_num
#Important !
import math
nelec_per_kpt = num_elec // n_kpts
nelec_alpha_per_kpt = int(math.ceil(nelec_per_kpt / 2.))
nelec_beta_per_kpt = int(math.floor(nelec_per_kpt / 2.))

ezfio.electrons_elec_alpha_num = int(nelec_alpha_per_kpt * n_kpts)
ezfio.electrons_elec_beta_num = int(nelec_beta_per_kpt * n_kpts)

#ezfio.electrons_elec_alpha_num = int(math.ceil(num_elec / 2.))
#ezfio.electrons_elec_beta_num = int(math.floor(num_elec / 2.))

ezfio.set_utils_num_kpts(n_kpts)
ezfio.set_integrals_bielec_df_num(n_aux)

#Important
ezfio.set_nuclei_nucl_num(nucl_num)
Exemplo n.º 21
0
def run_full_ci_10k_pt2_end(geo, basis, pseudo):
    """
    Run a Full_ci with 10k with the TruePT2
    EZFIO path = geo.ezfio
    """

    # ~#~#~#~#~#~#~#~#~#~ #
    # R e f _ e n e r g y #
    # ~#~#~#~#~#~#~#~#~#~ #

    ref_energy_var = defaultdict(dict)
    ref_energy_pt2 = defaultdict(dict)

    ref_energy_var["sto-3g"]["methane"] = Energy(-39.8058687211, None)
    ref_energy_pt2["sto-3g"]["methane"] = Energy(-39.8059180427, None)

    # ~#~#~#~ #
    # I n i t #
    # ~#~#~#~ #

    ezfio.set_file("{0}.ezfio".format(geo))

    # ~#~#~#~#~#~#~#~#~#~#~#~#~ #
    # S e t _ p a r a m e t e r #
    # ~#~#~#~#~#~#~#~#~#~#~#~#~ #

    ezfio.determinants_n_det_max = 10000
    ezfio.determinants_n_det_max_jacobi = 10000
    ezfio.determinants_n_states = 1
    ezfio.determinants_read_wf = 1
    ezfio.determinants_s2_eig = False

    ezfio.determinants_threshold_generators = 0.99
    ezfio.determinants_threshold_selectors = 0.999

    ezfio.perturbation_do_pt2_end = True
    ezfio.perturbation_pt2_max = 1.e-4

    # ~#~#~ #
    # R u n #
    # ~#~#~ #

#    cmd = "{0}/Full_CI/full_ci {1}.ezfio/".format(QP_src,geo)
    cmd = "qp_run full_ci {0}.ezfio/".format(geo)
    subprocess.check_call([cmd], shell=True)

    # ~#~#~#~#~ #
    # C h e c k #
    # ~#~#~#~#~ #

    cur_var = ezfio.get_full_ci_energy()
    cur_pt2 = ezfio.get_full_ci_energy_pt2()

    ref_var = ref_energy_var[basis][geo]
    ref_pt2 = ref_energy_pt2[basis][geo]

    if pseudo:
        ref_var = ref_var.with_pseudo
        ref_pt2 = ref_pt2.with_pseudo
    else:
        ref_var = ref_var.without_pseudo
        ref_pt2 = ref_pt2.without_pseudo

    t = [abs(cur_var - ref_var) <= precision,
         abs(cur_pt2 - ref_pt2) <= precision]

    if all(t):
        return True
    else:
        raise ValueError(get_error_message([ref_var, ref_pt2],
                                           [cur_var, cur_pt2]))