10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-09-27 03:51:01 +02:00

qp_plugins improved

This commit is contained in:
Anthony Scemama 2018-12-21 12:38:44 +01:00
parent 485dcb83b0
commit 69f98a8160
8 changed files with 63 additions and 550 deletions

4
TODO
View File

@ -1,12 +1,10 @@
* Virer tous les modules qui sont dans plugins
* Separer integrales ERF
# qp_module
* Permettre aux utilisateurs de facilement deposer des plugins dans plugins via une commande
* Permettre de descendre plus bas dans l'arborescence de plugins pour permettre des `git clone` dans le repertoire plugins
* Mettre les fichiers de test dans le directory source
* Mettre le fichier LIB
* Mettre les fichiers install.sh dans les modules externes
# Web/doc

View File

@ -1,29 +1,32 @@
IRPF90_temp/
IRPF90_man/
irpf90.make
irpf90_entities
tags
# Automatically created by $QP_ROOT/scripts/module/module_handler.py
.ninja_deps
.ninja_log
/home/scemama/quantum_package/src/tools/diagonalize_h
/home/scemama/quantum_package/src/tools/fcidump
/home/scemama/quantum_package/src/tools/four_idx_transform
/home/scemama/quantum_package/src/tools/molden
/home/scemama/quantum_package/src/tools/save_natorb
/home/scemama/quantum_package/src/tools/save_ortho_mos
/home/scemama/quantum_package/src/tools/write_integrals_erf
IRPF90_man
IRPF90_temp
Makefile
Makefile.depend
ao_basis
ao_one_e_integrals
ao_two_e_integrals
becke_numerical_grid
bitmask
cis
cisd
davidson
davidson_dressed
davidson_undressed
determinants
dressing
dummy
electrons
ezfio_files
ezfio_interface.irp.f
fci
generators_cas
generators_full
hartree_fock
integrals_bielec
irpf90.make
irpf90_entities
iterations
mo_basis
mo_guess
@ -36,11 +39,9 @@ perturbation
pseudo
psiref_cas
psiref_utils
selectors_cassd
scf_utils
selectors_full
selectors_utils
single_ref_method
slave
tools
tags
utils
zmq
zmq

View File

@ -1,106 +0,0 @@
! DO NOT MODIFY BY HAND
! Created by $QP_ROOT/scripts/ezfio_interface/ei_handler.py
! from file /home/loos/quantum_package/src/NOFT/EZFIO.cfg
BEGIN_PROVIDER [ logical, do_jk_functionals ]
implicit none
BEGIN_DOC
! Compute energies for JK-only functionals
END_DOC
logical :: has
PROVIDE ezfio_filename
if (mpi_master) then
call ezfio_has_noft_do_jk_functionals(has)
if (has) then
call ezfio_get_noft_do_jk_functionals(do_jk_functionals)
else
print *, 'noft/do_jk_functionals not found in EZFIO file'
stop 1
endif
endif
IRP_IF MPI
include 'mpif.h'
integer :: ierr
call MPI_BCAST( do_jk_functionals, 1, MPI_LOGICAL, 0, MPI_COMM_WORLD, ierr)
if (ierr /= MPI_SUCCESS) then
stop 'Unable to read do_jk_functionals with MPI'
endif
IRP_ENDIF
call write_time(6)
if (mpi_master) then
write(6, *) 'Read do_jk_functionals'
endif
END_PROVIDER
BEGIN_PROVIDER [ logical, do_jkl_functionals ]
implicit none
BEGIN_DOC
! Compute energies for JKL-only functionals (PNOFs)
END_DOC
logical :: has
PROVIDE ezfio_filename
if (mpi_master) then
call ezfio_has_noft_do_jkl_functionals(has)
if (has) then
call ezfio_get_noft_do_jkl_functionals(do_jkl_functionals)
else
print *, 'noft/do_jkl_functionals not found in EZFIO file'
stop 1
endif
endif
IRP_IF MPI
include 'mpif.h'
integer :: ierr
call MPI_BCAST( do_jkl_functionals, 1, MPI_LOGICAL, 0, MPI_COMM_WORLD, ierr)
if (ierr /= MPI_SUCCESS) then
stop 'Unable to read do_jkl_functionals with MPI'
endif
IRP_ENDIF
call write_time(6)
if (mpi_master) then
write(6, *) 'Read do_jkl_functionals'
endif
END_PROVIDER
BEGIN_PROVIDER [ logical, do_pt2_noft ]
implicit none
BEGIN_DOC
! Compute PT2 correction for NOFT
END_DOC
logical :: has
PROVIDE ezfio_filename
if (mpi_master) then
call ezfio_has_noft_do_pt2_noft(has)
if (has) then
call ezfio_get_noft_do_pt2_noft(do_pt2_noft)
else
print *, 'noft/do_pt2_noft not found in EZFIO file'
stop 1
endif
endif
IRP_IF MPI
include 'mpif.h'
integer :: ierr
call MPI_BCAST( do_pt2_noft, 1, MPI_LOGICAL, 0, MPI_COMM_WORLD, ierr)
if (ierr /= MPI_SUCCESS) then
stop 'Unable to read do_pt2_noft with MPI'
endif
IRP_ENDIF
call write_time(6)
if (mpi_master) then
write(6, *) 'Read do_pt2_noft'
endif
END_PROVIDER

View File

@ -16,8 +16,11 @@ Options:
import os
import sys
import os.path
from collections import namedtuple
import shutil
try:
from docopt import docopt
from qp_path import QP_SRC, QP_ROOT, QP_PLUGINS
@ -34,8 +37,30 @@ def is_plugin(path_module_rel):
return os.path.isfile(os.path.join(QP_PLUGINS, path_module_rel, "NEED"))
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK) and not fpath.endswith(".py")
def get_binaries(path_module):
"""
Return the list of binaries
"""
import subprocess
try:
cmd = 'grep -l -i --regexp="^\\s*program\\s" {0}/*.irp.f'.format(path_module)
process = subprocess.Popen([cmd],
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
except OSError:
return []
else:
if not stdout:
return []
elif "No such file or directory" not in stdout:
l_bin = [i.replace(".irp.f", "", 1) for i in stdout.split()]
return [os.path.realpath(bin_) for bin_ in l_bin]
else:
return []
def get_dict_child(l_root_abs=None):
@ -210,8 +235,7 @@ if __name__ == '__main__':
for module in l_module:
module_abs = os.path.realpath(os.path.join(QP_SRC, module))
l_symlink = m.l_descendant_unique([module])
l_exe = [f for f in os.listdir(module_abs)
if is_exe(os.path.join(module_abs, f))]
l_exe = get_binaries(module_abs)
if arguments["clean"]:
for f in l_dir:
@ -241,11 +265,6 @@ if __name__ == '__main__':
if arguments["create_git_ignore"]:
# Don't update if we are not in the main repository
from is_master_repository import is_master_repository
if not is_master_repository:
sys.exit(0)
path = os.path.join(module_abs, ".gitignore")
with open(path, "w+") as f:
@ -253,3 +272,5 @@ if __name__ == '__main__':
l_text = l_dir + l_file + l_symlink + l_exe
l_text.sort()
f.write("\n".join(l_text))

View File

@ -23,6 +23,7 @@ Options:
uninstall Uninstall a plugin
create -n <name> Create a new plugin named <name>
"""
import sys
@ -154,7 +155,7 @@ def main(arguments):
)
os.chdir(QP_PLUGINS)
if is_repo:
os.system("git clone %s"%(url))
subprocess.check_call(["git", "clone", url])
else:
filename = url.split('/')[-1]
@ -171,7 +172,7 @@ def main(arguments):
filename.endswith(".tgz") or \
filename.endswith(".tar.bz2") or \
filename.endswith(".tar"):
os.system("tar xf "+filename)
subprocess.check_call(["tar", "xf", filename])
os.remove(filename)
elif arguments["install"]:
@ -214,18 +215,13 @@ def main(arguments):
des = os.path.join(QP_SRC, module_to_cp)
try:
os.symlink(src, des)
install = os.path.join(src,"install")
if os.path.isfile(install):
subprocess.check_call([install])
except OSError:
print "Your src directory is broken. Please remove %s" % des
print "The src directory is broken. Please remove %s" % des
raise
try:
subprocess.check_call(["qp_create_ninja", "update"])
except:
raise
print "[ OK ]"
print ""
print "You can now compile as usual"
print "`cd {0} ; ninja` for example".format(QP_ROOT)
elif arguments["uninstall"]:
@ -250,13 +246,15 @@ def main(arguments):
for module in set(l_name_to_remove):
try:
subprocess.check_call(["module_handler.py", "clean", module])
except:
raise
subprocess.check_call(["module_handler.py", "clean", module])
for module in set(l_name_to_remove):
uninstall = os.path.join(QP_SRC,module,"uninstall")
print uninstall
if os.path.isfile(uninstall):
subprocess.check_call([uninstall])
try:
os.unlink(os.path.join(QP_SRC, module))
except OSError:

View File

@ -1,15 +0,0 @@
#!/usr/bin/env python2
import os
QP_ROOT=os.environ["QP_ROOT"]
name_to_elec = {}
with open(QP_ROOT+"/data/list_element.txt","r") as f:
data = f.readlines()
for line in data:
b = line.split()
name_to_elec[b[1]] = int(b[0])
if __name__ == '__main__':
print name_to_elec

View File

@ -1,370 +0,0 @@
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Create the pseudo potential for a given atom
Usage:
put_pseudo_in_ezfio.py <ezfio_path> <pseudo_name> [<db_dump_path>]
Help:
atom is the Abreviation of the atom
"""
import os
import sys
from docopt import docopt
from subprocess import Popen, PIPE
qpackage_root = os.environ['QP_ROOT']
EZFIO = "{0}/install/EZFIO".format(qpackage_root)
sys.path = [EZFIO + "/Python"] + sys.path
from ezfio import ezfio
import re
p = re.compile(ur'\|(\d+)><\d+\|')
def get_pseudo_str(db_dump_path,pseudo_name,l_atom):
"""
Run EMSL_local for getting the str of the pseudo potential
str_ele :
Element Symbol: Na
Number of replaced protons: 10
Number of projectors: 2
Pseudopotential data:
Local component:
Coeff. r^n Exp.
1.00000000 -1 5.35838717
5.35838717 1 3.67918975
-2.07764789 0 1.60507673
Non-local component:
Coeff. r^n Exp. Proj.
10.69640234 0 1.32389367 |0><0|
10.11238853 0 1.14052020 |1><1|
"""
EMSL_root = "{0}/install/emsl/".format(qpackage_root)
EMSL_path = "{0}/EMSL_api.py".format(EMSL_root)
str_ = ""
for a in l_atom:
if a is not 'X':
l_cmd_atom = ["--atom", a]
l_cmd_head = [EMSL_path, "get_basis_data",
"--db_dump_path", db_dump_path,
"--basis", pseudo_name]
process = Popen(l_cmd_head + l_cmd_atom, stdout=PIPE, stderr=PIPE)
stdout, _ = process.communicate()
str_ += stdout.strip() + "\n"
else: # Dummy atoms
str_ += """Element Symbol: X
Number of replaced protons: 0
Number of projectors: 0
Pseudopotential data:
Local component:
Coeff. r^n Exp.
0.0 -1 0.
0.0 1 0.
0.0 0 0.
Non-local component:
Coeff. r^n Exp. Proj.
"""
return str_
def get_v_n_dz_local(str_ele):
"""
From a str_ele of the pseudo (aka only one ele in the str)
get the list ussefull for the Local potential : v_k n_k and dz_k
"""
l_v_k = []
l_n_k = []
l_dz_k = []
for l in str_ele.splitlines():
try:
v, n, dz = l.split()
v = float(v)
n = int(n)
dz = float(dz)
except ValueError:
pass
else:
l_v_k.append(v)
l_n_k.append(n)
l_dz_k.append(dz)
return l_v_k, l_n_k, l_dz_k
def get_v_n_dz_l_nonlocal(str_ele):
"""
From a str_ele of the pseudo (aka only one ele in the str)
get the list ussefull for the non Local potential
v_kl (v, l)
n_k (v, l)
dz_k (dz ,l)
"""
l_v_kl = []
l_n_kl = []
l_dz_kl = []
for l in str_ele.splitlines():
try:
v, n, dz, proj = l.split()
v = float(v)
n = int(n)
dz = float(dz)
l = int(p.match(proj).group(1))
except ValueError:
pass
else:
l_v_kl.append([v])
l_n_kl.append([n])
l_dz_kl.append([dz])
if not l_v_kl:
l_v_kl.append([0.])
l_n_kl.append([0])
l_dz_kl.append([0.])
return l_v_kl, l_n_kl, l_dz_kl
def get_zeff_alpha_beta(str_ele):
"""
Return the the zeff, alpha num elec and beta num elec
Assert ezfio_set_file alredy defined
"""
import re
# ___
# | ._ o _|_
# _|_ | | | |_
#
# ~#~#~#~#~#~#~ #
# s t r _ e l e #
# ~#~#~#~#~#~#~ #
# m = re.search('Element Symbol: ([a-zA-Z]+)', str_ele)
# name = m.group(1).capitalize()
name = str_ele.split("\n")[0].strip().capitalize()
m = re.search('Number of replaced protons: (\d+)', str_ele)
z_remove = int(m.group(1))
# _
# |_) _. ._ _ _
# | (_| | _> (/_
#
from elts_num_ele import name_to_elec
from math import ceil, floor
z = name_to_elec[name]
z_eff = z - z_remove
alpha = int(ceil(z_remove / 2.))
beta = int(floor(z_remove / 2.))
# Remove more alpha, than beta
# _
# |_) _ _|_ ._ ._
# | \ (/_ |_ |_| | | |
#
return [z_remove, z_eff, alpha, beta]
def add_zero(array, size, type):
for add in xrange(len(array), size):
array.append([type(0)])
return array
def make_it_square(matrix, dim, type=float):
"""
matix the matrix to square
dim array [lmax, kmax]
type the null value you want
[[[28.59107316], [19.37583724]], [[50.25646328]]]
=>
[[[28.59107316], [19.37583724]], [[50.25646328], [0.0]]]
"""
lmax = dim[0]
kmax = dim[1]
for l_list in matrix:
l_list = add_zero(l_list, lmax, type)
for k_list in list_:
k_list = add_zero(k_list, kmax, type)
return matrix
def full_path(path):
path = os.path.expanduser(path)
path = os.path.expandvars(path)
path = os.path.abspath(path)
return path
if __name__ == "__main__":
arguments = docopt(__doc__)
# ___
# | ._ o _|_
# _|_ | | | |_
#
# ~#~#~#~#~ #
# E Z F I O #
# ~#~#~#~#~ #
ezfio_path = full_path(arguments["<ezfio_path>"])
ezfio.set_file("{0}".format(ezfio_path))
# ~#~#~#~#~#~#~#~#~#~#~ #
# P s e u d o _ d a t a #
# ~#~#~#~#~#~#~#~#~#~#~ #
if arguments["<db_dump_path>"]:
db_dump_path = full_path(arguments["<db_dump_path>"])
else:
db_dump_path= full_path("{0}/data/BFD-Pseudo.dump".format(qpackage_root))
pseudo_name = arguments["<pseudo_name>"]
l_ele = ezfio.get_nuclei_nucl_label()
str_ = get_pseudo_str(db_dump_path,pseudo_name,l_ele)
# _
# |_) _. ._ _ _
# | (_| | _> (/_
#
l_str_ele = [str_ele for str_ele in str_.split("Element Symbol: ")
if str_ele]
for i in "l_zeff l_remove v_k n_k dz_k v_kl n_kl dz_kl".split():
exec("{0} = []".format(i))
alpha_tot = 0
beta_tot = 0
for str_ele in l_str_ele:
# ~#~#~#~#~ #
# S p l i t #
# ~#~#~#~#~ #
l = str_ele.find("Local component:")
nl = str_ele.find("Non-local component")
# ~#~#~#~#~ #
# L o c a l #
# ~#~#~#~#~ #
l_v, l_n, l_dz = get_v_n_dz_local(str_ele[l:nl])
v_k.append(l_v)
n_k.append(l_n)
dz_k.append(l_dz)
# ~#~#~#~#~#~#~#~#~ #
# N o n _ L o c a l #
# ~#~#~#~#~#~#~#~#~ #
l_v_kl, l_n_kl, l_dz_kl = get_v_n_dz_l_nonlocal(str_ele[nl:])
v_kl.append(l_v_kl)
n_kl.append(l_n_kl)
dz_kl.append(l_dz_kl)
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~ #
# Z _ e f f , a l p h a / b e t a _ e l e c #
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~ #
zremove, zeff, alpha, beta = get_zeff_alpha_beta(str_ele)
alpha_tot += alpha
beta_tot += beta
l_zeff.append(zeff)
l_remove.append(zremove)
# _
# /\ _| _| _|_ _ _ _ _|_ o _
# /--\ (_| (_| |_ (_) (/_ /_ | | (_)
#
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~ #
# Z _ e f f , a l p h a / b e t a _ e l e c #
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~ #
ezfio.nuclei_nucl_charge = l_zeff
ezfio.pseudo_nucl_charge_remove = l_remove
alpha_tot = ezfio.get_electrons_elec_alpha_num() - alpha_tot
beta_tot = ezfio.get_electrons_elec_beta_num() - beta_tot
ezfio.electrons_elec_alpha_num = alpha_tot
ezfio.electrons_elec_beta_num = beta_tot
# 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 = max([len(i) for i in v_k])
ezfio.pseudo_pseudo_klocmax = klocmax
ezfio.pseudo_pseudo_v_k = zip(*v_k)
ezfio.pseudo_pseudo_n_k = zip(*n_k)
ezfio.pseudo_pseudo_dz_k = zip(*dz_k)
# ~#~#~#~#~#~#~#~#~ #
# N o n _ L o c a l #
# ~#~#~#~#~#~#~#~#~ #
lmax = max([len(i) for i in v_kl])
kmax = max([len(sublist) for list_ in v_kl for sublist in list_])
ezfio.pseudo_pseudo_lmax = lmax - 1
ezfio.pseudo_pseudo_kmax = kmax
v_kl = make_it_square(v_kl, [lmax, kmax])
n_kl = make_it_square(n_kl, [lmax, kmax], int)
dz_kl = make_it_square(dz_kl, [lmax, kmax])
ezfio.pseudo_pseudo_v_kl = zip(*v_kl)
ezfio.pseudo_pseudo_n_kl = zip(*n_kl)
ezfio.pseudo_pseudo_dz_kl = zip(*dz_kl)
ezfio.pseudo_do_pseudo = True

View File

@ -1,14 +0,0 @@
#!/usr/bin/env python2
import subprocess
pipe = subprocess.Popen("git config --get remote.origin.url", \
shell=True, stdout=subprocess.PIPE)
result = pipe.stdout.read()
is_master_repository = "LCPQ/quantum_package" in result
if __name__ == "__main__":
import sys
if is_master_repository:
sys.exit(0)
else:
sys.exit(-1)