mirror of
https://github.com/QuantumPackage/qp2.git
synced 2024-11-07 14:03:37 +01:00
pyscf converter for molecules
This commit is contained in:
parent
3806554438
commit
239c581073
66
src/utils_complex/Gen_Ezfio_from_pyscf_mol.sh
Executable file
66
src/utils_complex/Gen_Ezfio_from_pyscf_mol.sh
Executable file
@ -0,0 +1,66 @@
|
||||
#!/bin/bash
|
||||
|
||||
ezfio=$1
|
||||
h5file=$2
|
||||
# Create the integral
|
||||
echo 'Create Integral'
|
||||
|
||||
echo 'Create EZFIO'
|
||||
#read nel nmo natom <<< $(cat param)
|
||||
#read e_nucl <<< $(cat e_nuc)
|
||||
#read nao <<< $(cat num_ao)
|
||||
#read nkpts <<< $(cat kpt_num)
|
||||
#read ndf <<< $(cat num_df)
|
||||
##./create_ezfio_complex_4idx.py $ezfio $nel $natom $nmo $e_nucl $nao $nkpts
|
||||
./create_ezfio_pyscf_mol.py $ezfio $h5file #$nel $natom $nmo $e_nucl $nao $nkpts $ndf
|
||||
#Handle the orbital consitensy check
|
||||
#qp_edit -c $ezfio &> /dev/null
|
||||
#cp $ezfio/{ao,mo}_basis/ao_md5
|
||||
|
||||
#qp_run import_ao_2e_complex $ezfio
|
||||
#qp_run dump_ao_2e_from_df $ezfio
|
||||
#Read the integral
|
||||
#echo 'Read Integral'
|
||||
|
||||
|
||||
################################################
|
||||
## using AO mono, 4-idx from pyscf ##
|
||||
################################################
|
||||
#qp_run import_integrals_ao_periodic $ezfio
|
||||
|
||||
|
||||
################################################
|
||||
## using AO mono, 3-idx, mo coef from pyscf ##
|
||||
################################################
|
||||
|
||||
#qp_run read_ao_mono_complex $ezfio
|
||||
#qp_run read_kconserv $ezfio
|
||||
#qp_run read_ao_df_complex $ezfio
|
||||
#qp_run read_mo_coef_complex $ezfio #start from converged pyscf MOs
|
||||
#
|
||||
#qp_run save_mo_df_to_disk $ezfio
|
||||
#qp_run save_mo_bielec_to_disk $ezfio
|
||||
|
||||
#qp_run mo_from_ao_orth $ezfio #use canonical orthonormalized AOs as initial MO guess
|
||||
#qp_run print_H_matrix_restart $ezfio > hmat.out
|
||||
|
||||
|
||||
###############################################################
|
||||
## using AO mono, full 4-idx AO bielec, mo coef from pyscf ##
|
||||
###############################################################
|
||||
|
||||
#qp_run read_ao_mono_complex $ezfio
|
||||
#qp_run read_kconserv $ezfio
|
||||
#qp_run read_ao_eri_chunk_complex $ezfio
|
||||
#qp_run read_mo_coef_complex $ezfio #start from converged pyscf MOs
|
||||
##qp_run mo_from_ao_orth $ezfio #use canonical orthonormalized AOs as initial MO guess
|
||||
|
||||
|
||||
######################################################
|
||||
## using MO mono, full 4-idx MO bielec from pyscf ##
|
||||
######################################################
|
||||
|
||||
#qp_run read_mo_mono_complex $ezfio
|
||||
#qp_run read_kconserv $ezfio
|
||||
#qp_run read_mo_eri_chunk_complex $ezfio
|
||||
|
@ -835,6 +835,8 @@ def pyscf2QP2_mol(mf, cas_idx=None, int_threshold = 1E-8,
|
||||
qph5.create_group('electrons')
|
||||
qph5.create_group('ao_basis')
|
||||
qph5.create_group('mo_basis')
|
||||
qph5.create_group('pseudo')
|
||||
qph5['pseudo'].attrs['do_pseudo']=False
|
||||
|
||||
if mf.mol.cart:
|
||||
mo_coeff = mf.mo_coeff.copy()
|
||||
@ -951,6 +953,83 @@ def pyscf2QP2_mol(mf, cas_idx=None, int_threshold = 1E-8,
|
||||
for i in range(natom):
|
||||
atom_dset[i] = mol.atom_pure_symbol(i)
|
||||
|
||||
##########################################
|
||||
# #
|
||||
# ECP #
|
||||
# #
|
||||
##########################################
|
||||
|
||||
if (mol.has_ecp()):
|
||||
#atsymb = [mol.atom_pure_symbol(i) for i in range(natom)]
|
||||
#pyecp = mol._ecp
|
||||
## nelec to remove for each atom
|
||||
#nuc_z_remov = [pyecp[i][0] for i in atsymb]
|
||||
#nl_per_atom = [len(pyecp[i][1]) for i in atsymb]
|
||||
## list of l-values for channels of each atom
|
||||
#ecp_l = [[pyecp[i][1][j][0] for j in range(len(pyecp[i][1]))] for i in atsymb]
|
||||
## list of [exp,coef] for each channel (r**0,1,2,3,4,5,)
|
||||
#ecp_ac = [[pyecp[i][1][j][1] for j in range(len(pyecp[i][1]))] for i in atsymb]
|
||||
pyecp = [mol._ecp[mol.atom_pure_symbol(i)] for i in range(natom)]
|
||||
nzrmv=[0]*natom
|
||||
lmax=0
|
||||
klocmax=0
|
||||
knlmax=0
|
||||
for i,(nz,dat) in enumerate(pyecp):
|
||||
nzrmv[i]=nz
|
||||
for lval,ac in dat:
|
||||
if (lval==-1):
|
||||
klocmax=max(sum(len(j) for j in ac),klocmax)
|
||||
else:
|
||||
lmax=max(lval,lmax)
|
||||
knlmax=max(sum(len(j) for j in ac),knlmax)
|
||||
#psd_nk = np.zeros((natom,klocmax),dtype=int)
|
||||
#psd_vk = np.zeros((natom,klocmax),dtype=float)
|
||||
#psd_dzk = np.zeros((natom,klocmax),dtype=float)
|
||||
#psd_nkl = np.zeros((natom,knlmax,lmax+1),dtype=int)
|
||||
#psd_vkl = np.zeros((natom,knlmax,lmax+1),dtype=float)
|
||||
#psd_dzkl = np.zeros((natom,knlmax,lmax+1),dtype=float)
|
||||
klnlmax=max(klocmax,knlmax)
|
||||
psd_n = np.zeros((lmax+2,klnlmax,natom),dtype=int)
|
||||
psd_v = np.zeros((lmax+2,klnlmax,natom),dtype=float)
|
||||
psd_dz = np.zeros((lmax+2,klnlmax,natom),dtype=float)
|
||||
for i,(_,dat) in enumerate(pyecp):
|
||||
for lval,ac in dat:
|
||||
count=0
|
||||
for ri,aici in enumerate(ac):
|
||||
for ai,ci in aici:
|
||||
psd_n[lval+1,count,i] = ri-2
|
||||
psd_v[lval+1,count,i] = ci
|
||||
psd_dz[lval+1,count,i] = ai
|
||||
count += 1
|
||||
psd_nk = psd_n[0,:klocmax]
|
||||
psd_vk = psd_v[0,:klocmax]
|
||||
psd_dzk = psd_dz[0,:klocmax]
|
||||
psd_nkl = psd_n[1:,:knlmax]
|
||||
psd_vkl = psd_v[1:,:knlmax]
|
||||
psd_dzkl = psd_dz[1:,:knlmax]
|
||||
with h5py.File(qph5path,'a') as qph5:
|
||||
qph5['pseudo'].attrs['do_pseudo']=True
|
||||
qph5['pseudo'].attrs['pseudo_lmax']=lmax
|
||||
qph5['pseudo'].attrs['pseudo_klocmax']=klocmax
|
||||
qph5['pseudo'].attrs['pseudo_kmax']=knlmax
|
||||
qph5.create_dataset('pseudo/nucl_charge_remove',data=nzrmv)
|
||||
qph5.create_dataset('pseudo/pseudo_n_k',data=psd_nk)
|
||||
qph5.create_dataset('pseudo/pseudo_n_kl',data=psd_nkl)
|
||||
qph5.create_dataset('pseudo/pseudo_v_k',data=psd_vk)
|
||||
qph5.create_dataset('pseudo/pseudo_v_kl',data=psd_vkl)
|
||||
qph5.create_dataset('pseudo/pseudo_dz_k',data=psd_dzk)
|
||||
qph5.create_dataset('pseudo/pseudo_dz_kl',data=psd_dzkl)
|
||||
|
||||
## nelec to remove for each atom
|
||||
#nuc_z_remov = [i[0] for i in pyecp]
|
||||
#nl_per_atom = [len(i[1]) for i in pyecp]
|
||||
## list of l-values for channels of each atom
|
||||
#ecp_l = [[ j[0] for j in i[1] ] for i in pyecp]
|
||||
#lmax = max(map(max,ecp_l))
|
||||
## list of [exp,coef] for each channel (r**0,1,2,3,4,5,)
|
||||
#ecp_ac = [[ j[1] for j in i[1] ] for i in pyecp]
|
||||
|
||||
|
||||
##########################################
|
||||
# #
|
||||
# Basis #
|
||||
|
124
src/utils_complex/create_ezfio_pyscf_mol.py
Executable file
124
src/utils_complex/create_ezfio_pyscf_mol.py
Executable file
@ -0,0 +1,124 @@
|
||||
#!/usr/bin/env python
|
||||
from ezfio import ezfio
|
||||
import h5py
|
||||
|
||||
import sys
|
||||
import numpy as np
|
||||
fname = sys.argv[1]
|
||||
qph5name = sys.argv[2]
|
||||
|
||||
#qph5=h5py.File(qph5path,'r')
|
||||
|
||||
def convert_mol(filename,qph5path):
|
||||
ezfio.set_file(filename)
|
||||
ezfio.set_nuclei_is_complex(False)
|
||||
|
||||
with h5py.File(qph5path,'r') as qph5:
|
||||
nucl_num = qph5['nuclei'].attrs['nucl_num']
|
||||
ao_num = qph5['ao_basis'].attrs['ao_num']
|
||||
mo_num = qph5['mo_basis'].attrs['mo_num']
|
||||
elec_alpha_num = qph5['electrons'].attrs['elec_alpha_num']
|
||||
elec_beta_num = qph5['electrons'].attrs['elec_beta_num']
|
||||
|
||||
ezfio.set_nuclei_nucl_num(nucl_num)
|
||||
|
||||
ezfio.set_ao_basis_ao_num(ao_num)
|
||||
ezfio.set_mo_basis_mo_num(mo_num)
|
||||
ezfio.electrons_elec_alpha_num = elec_alpha_num
|
||||
ezfio.electrons_elec_beta_num = elec_beta_num
|
||||
|
||||
|
||||
|
||||
##ao_num = mo_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)
|
||||
|
||||
#(old)Important
|
||||
#ezfio.set_nuclei_nucl_num(nucl_num)
|
||||
#ezfio.set_nuclei_nucl_charge([0.]*nucl_num)
|
||||
#ezfio.set_nuclei_nucl_coord( [ [0.], [0.], [0.] ]*nucl_num )
|
||||
#ezfio.set_nuclei_nucl_label( ['He'] * nucl_num )
|
||||
|
||||
|
||||
with h5py.File(qph5path,'r') as qph5:
|
||||
nucl_charge=qph5['nuclei/nucl_charge'][()].tolist()
|
||||
nucl_coord=qph5['nuclei/nucl_coord'][()].T.tolist()
|
||||
nucl_label=qph5['nuclei/nucl_label'][()].tolist()
|
||||
nuclear_repulsion = qph5['nuclei'].attrs['nuclear_repulsion']
|
||||
|
||||
ezfio.set_nuclei_nucl_charge(nucl_charge)
|
||||
ezfio.set_nuclei_nucl_coord(nucl_coord)
|
||||
ezfio.set_nuclei_nucl_label(nucl_label)
|
||||
|
||||
ezfio.set_nuclei_io_nuclear_repulsion('Read')
|
||||
ezfio.set_nuclei_nuclear_repulsion(nuclear_repulsion)
|
||||
|
||||
|
||||
##########################################
|
||||
# #
|
||||
# Basis #
|
||||
# #
|
||||
##########################################
|
||||
|
||||
with h5py.File(qph5path,'r') as qph5:
|
||||
do_pseudo = qph5['pseudo'].attrs['do_pseudo']
|
||||
ezfio.set_pseudo_do_pseudo(do_pseudo)
|
||||
if (do_pseudo):
|
||||
ezfio.set_pseudo_pseudo_lmax(qph5['pseudo'].attrs['pseudo_lmax'])
|
||||
ezfio.set_pseudo_pseudo_klocmax(qph5['pseudo'].attrs['pseudo_klocmax'])
|
||||
ezfio.set_pseudo_pseudo_kmax(qph5['pseudo'].attrs['pseudo_kmax'])
|
||||
ezfio.set_pseudo_nucl_charge_remove(qph5['pseudo/nucl_charge_remove'][()].tolist())
|
||||
ezfio.set_pseudo_pseudo_n_k(qph5['pseudo/pseudo_n_k'][()].tolist())
|
||||
ezfio.set_pseudo_pseudo_n_kl(qph5['pseudo/pseudo_n_kl'][()].tolist())
|
||||
ezfio.set_pseudo_pseudo_v_k(qph5['pseudo/pseudo_v_k'][()].tolist())
|
||||
ezfio.set_pseudo_pseudo_v_kl(qph5['pseudo/pseudo_v_kl'][()].tolist())
|
||||
ezfio.set_pseudo_pseudo_dz_k(qph5['pseudo/pseudo_dz_k'][()].tolist())
|
||||
ezfio.set_pseudo_pseudo_dz_kl(qph5['pseudo/pseudo_dz_kl'][()].tolist())
|
||||
|
||||
##########################################
|
||||
# #
|
||||
# Basis #
|
||||
# #
|
||||
##########################################
|
||||
|
||||
with h5py.File(qph5path,'r') as qph5:
|
||||
coeftmp = qph5['ao_basis/ao_coef'][()]
|
||||
expotmp = qph5['ao_basis/ao_expo'][()]
|
||||
ezfio.set_ao_basis_ao_basis(qph5['ao_basis'].attrs['ao_basis'])
|
||||
ezfio.set_ao_basis_ao_nucl(qph5['ao_basis/ao_nucl'][()].tolist())
|
||||
ezfio.set_ao_basis_ao_prim_num(qph5['ao_basis/ao_prim_num'][()].tolist())
|
||||
ezfio.set_ao_basis_ao_power(qph5['ao_basis/ao_power'][()].tolist())
|
||||
ezfio.set_ao_basis_ao_coef(qph5['ao_basis/ao_coef'][()].tolist())
|
||||
ezfio.set_ao_basis_ao_expo(qph5['ao_basis/ao_expo'][()].tolist())
|
||||
|
||||
print(coeftmp)
|
||||
print(expotmp)
|
||||
|
||||
##########################################
|
||||
# #
|
||||
# MO Coef #
|
||||
# #
|
||||
##########################################
|
||||
|
||||
|
||||
with h5py.File(qph5path,'r') as qph5:
|
||||
mo_coef = qph5['mo_basis/mo_coef'][()].tolist()
|
||||
ezfio.set_mo_basis_mo_coef(mo_coef)
|
||||
#maybe fix qp so we don't need this?
|
||||
#ezfio.set_mo_basis_mo_coef([[i for i in range(mo_num)] * ao_num])
|
||||
|
||||
return
|
||||
|
||||
convert_mol(fname,qph5name)
|
Loading…
Reference in New Issue
Block a user