10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-11-03 20:54:00 +01:00

Autobuild qp_edit.ml

This commit is contained in:
Thomas Applencourt 2015-04-02 11:30:03 +02:00
parent 295579b7d9
commit 11c0013992
4 changed files with 293 additions and 61 deletions

View File

@ -2,15 +2,10 @@ open Qputils;;
open Qptypes;; open Qptypes;;
open Core.Std;; open Core.Std;;
include Input_ao_basis;; include Input_ao_basis;;
include Input_bielec_integrals;;
include Input_bitmasks;; include Input_bitmasks;;
include Input_cisd_sc2_selected;;
include Input_determinants;; include Input_determinants;;
include Input_electrons;; include Input_electrons;;
include Input_full_ci;;
include Input_hartree_fock;;
include Input_mo_basis;; include Input_mo_basis;;
include Input_nuclei;; include Input_nuclei;;
include Input_auto_generated;;

View File

@ -5,7 +5,7 @@ Welcom the ei_handler.
We will create all the ezfio related stuff from a EZFIO.cfg file. We will create all the ezfio related stuff from a EZFIO.cfg file.
Usage: Usage:
ei_handler.py [--path] [--irpf90] [--ezfio_config] [--ocaml] [--ezfio_default] ei_handler.py [--path] [--irpf90] [--ezfio_config] [--ocaml] [--ezfio_default] [--global]
By default all the option are executed. By default all the option are executed.
@ -23,6 +23,8 @@ Options:
--ezfio_default Create the `${module_lower}_ezfio_interface_default` in --ezfio_default Create the `${module_lower}_ezfio_interface_default` in
`${QPACKAGE_ROOT}/data/ezfio_defaults` needed by `${QPACKAGE_ROOT}/data/ezfio_defaults` needed by
the ocaml the ocaml
--global Create all the stuff who need all the EZFIO.cfg
Format specification : Format specification :
[provider_name] | the name of the provider in irp.f90 [provider_name] | the name of the provider in irp.f90
doc:{str} | Is the doc doc:{str} | Is the doc
@ -93,7 +95,6 @@ def get_type_dict():
from os import listdir from os import listdir
qpackage_root = os.environ['QPACKAGE_ROOT'] qpackage_root = os.environ['QPACKAGE_ROOT']
fancy_type_pickle = qpackage_root + "/scripts/ezfio_interface/fancy_type.p" fancy_type_pickle = qpackage_root + "/scripts/ezfio_interface/fancy_type.p"
if fancy_type_pickle in listdir(os.getcwd()): if fancy_type_pickle in listdir(os.getcwd()):
@ -145,7 +146,9 @@ def get_type_dict():
b = r.find('let untouched = "') b = r.find('let untouched = "')
e = r.find(';;', b) e = r.find(';;', b)
l_un = [i for i in r[b:e].splitlines() if i.strip().startswith("module")] l_un = [
i for i in r[
b:e].splitlines() if i.strip().startswith("module")]
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~ # # ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~ #
# q p _ t y p e s _ g e n e r a t e # # q p _ t y p e s _ g e n e r a t e #
@ -294,7 +297,6 @@ def create_ezfio_provider(dict_ezfio_cfg):
return [code, ...] return [code, ...]
""" """
from ezfio_generate_provider import EZFIO_Provider from ezfio_generate_provider import EZFIO_Provider
dict_code_provider = dict() dict_code_provider = dict()
ez_p = EZFIO_Provider() ez_p = EZFIO_Provider()
@ -600,6 +602,93 @@ def save_ocaml_input(module_lower, str_ocaml_input):
f.write(str_ocaml_input) f.write(str_ocaml_input)
def create_ocaml_input_global():
"""
Check for all the EZFIO.cfg get the module lower
then create incule {module_lower}.ml
"""
# ~#~#~#~# #
# I n i t #
# ~#~#~#~# #
from os import listdir
from os.path import isdir, join, exists
mypath = "{0}/src".format(os.environ['QPACKAGE_ROOT'])
onlyfodler = [f for f in listdir(mypath) if isdir(join(mypath, f))]
l_module_lower = [f.lower() for f in onlyfodler
if exists("{0}/{1}/EZFIO.cfg".format(mypath, f))]
# ~#~#~#~#~#~#~#~# #
# C r e a t i o n #
# ~#~#~#~#~#~#~#~# #
from ezfio_generate_ocaml import EZFIO_ocaml
qpackage_root = os.environ['QPACKAGE_ROOT']
path = qpackage_root + "/scripts/ezfio_interface/qp_edit_template"
with open(path, "r") as f:
template_raw = f.read()
e = EZFIO_ocaml(l_module_lower=l_module_lower)
template = template_raw.format(keywords=e.create_qp_keywords(),
keywords_to_string=e.create_qp_keywords_to_string(),
section_to_rst=e.create_qp_section_to_rst(),
write=e.create_qp_write(),
tasks=e.create_qp_tasks())
input_auto = e.create_input_auto_generated()
return (template, input_auto)
def save_ocaml_input_auto(str_ocaml_input_global):
"""
Write the str_ocaml_input in
$QPACKAGE_ROOT/ocaml/Input_auto_generated.ml
"""
path = "{0}/ocaml/Input_auto_generated.ml".format(os.environ['QPACKAGE_ROOT'])
try:
f = open(path, "r")
except IOError:
old_output = ""
else:
old_output = f.read()
f.close()
if str_ocaml_input_global != old_output:
with open(path, "w+") as f:
f.write(str_ocaml_input_global)
def save_ocaml_qp_edit(str_ocaml_qp_edit):
"""
Write the str_ocaml_qp_edit in
$QPACKAGE_ROOT/ocaml/qp_edit.ml
"""
path = "{0}/ocaml/qp_edit.ml".format(os.environ['QPACKAGE_ROOT'])
try:
f = open(path, "r")
except IOError:
old_output = ""
else:
old_output = f.read()
f.close()
if str_ocaml_qp_edit != old_output:
with open(path, "w+") as f:
f.write(str_ocaml_qp_edit)
if __name__ == "__main__": if __name__ == "__main__":
arguments = docopt(__doc__) arguments = docopt(__doc__)
@ -608,6 +697,7 @@ if __name__ == "__main__":
# _|_ | | | |_ # _|_ | | | |_
# #
if not arguments["--global"]:
if not arguments["--path"]: if not arguments["--path"]:
config_file_path = "EZFIO.cfg" config_file_path = "EZFIO.cfg"
if "EZFIO.cfg" not in os.listdir(os.getcwd()): if "EZFIO.cfg" not in os.listdir(os.getcwd()):
@ -644,7 +734,7 @@ if __name__ == "__main__":
"--ezfio_config", "--ezfio_config",
"--ocaml", "--ocaml",
"--ezfio_default", "--ezfio_default",
]]): "--global"]]):
# User changer somme argument, do what he want # User changer somme argument, do what he want
do_all = False do_all = False
else: else:
@ -670,13 +760,22 @@ if __name__ == "__main__":
# ~#~#~#~#~#~# # ~#~#~#~#~#~#
# O c a m l # # O c a m l #
# ~#~#~#~#~#~# # ~#~#~#~#~#~#
if do_all or arguments["--ocaml"]:
str_ocaml_input = create_ocaml_input(dict_ezfio_cfg, module_lower) str_ocaml_input = create_ocaml_input(dict_ezfio_cfg, module_lower)
save_ocaml_input(module_lower, str_ocaml_input) save_ocaml_input(module_lower, str_ocaml_input)
# ~#~#~#~#~#~#~#~#~#~#~#~#~ # # ~#~#~#~#~#~#~#~#~#~#~#~#~ #
# e z f i o _ d e f a u l t # # e z f i o _ d e f a u l t #
# ~#~#~#~#~#~#~#~#~#~#~#~#~ # # ~#~#~#~#~#~#~#~#~#~#~#~#~ #
if do_all or arguments["--ezfio_default"]:
str_ezfio_default = create_ezfio_default(dict_ezfio_cfg) str_ezfio_default = create_ezfio_default(dict_ezfio_cfg)
save_ezfio_default(module_lower, str_ezfio_default) save_ezfio_default(module_lower, str_ezfio_default)
# ~#~#~#~#~#~#~#~#~#~#~#~#~ #
# e z f i o _ d e f a u l t #
# ~#~#~#~#~#~#~#~#~#~#~#~#~ #
if do_all or arguments["--global"]:
str_ocaml_qp_edit, str_ocaml_input_auto = create_ocaml_input_global()
save_ocaml_input_auto(str_ocaml_input_auto)
save_ocaml_qp_edit(str_ocaml_qp_edit)

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
import os
# If type in **kwargs # If type in **kwargs
from ei_handler import Type from ei_handler import Type
@ -227,7 +228,8 @@ class EZFIO_ocaml(object):
"let write{ "] "let write{ "]
l_template += [" {0};".format(p) for p in self.l_ezfio_name] l_template += [" {0};".format(p) for p in self.l_ezfio_name]
l_template += [" } ="] l_template += [" } ="]
l_template += [" write_{0:<30} {0};".format(p) for p in self.l_ezfio_name] l_template += [" write_{0:<30} {0};".format(p)
for p in self.l_ezfio_name]
l_template += [";;"] l_template += [";;"]
# ~#~#~#~#~#~ # # ~#~#~#~#~#~ #
@ -324,3 +326,158 @@ class EZFIO_ocaml(object):
# R e t u r n # # R e t u r n #
# ~#~#~#~#~#~ # # ~#~#~#~#~#~ #
return "\n ".join(l_template) return "\n ".join(l_template)
def create_input_auto_generated(self):
"""
Generate the include of all the Input_module.lower template
"""
# ~#~#~#~#~#~#~#~ #
# C h e c k i n g #
# ~#~#~#~#~#~#~#~ #
self.check_if_init(["l_module_lower"],
sys._getframe().f_code.co_name)
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
# C r e a t e _ t e m pl a t e #
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
l_template = ['open Qputils;;',
'open Qptypes;;',
'open Core.Std;;',
'']
for m in self.l_module_lower:
l_template += ["include Input_{0}".format(m)]
# ~#~#~#~#~#~ #
# R e t u r n #
# ~#~#~#~#~#~ #
return "\n".join(l_template)
def create_qp_keywords(self):
"""
Generate keywords template
"""
# ~#~#~#~#~#~#~#~ #
# C h e c k i n g #
# ~#~#~#~#~#~#~#~ #
self.check_if_init(["l_module_lower"],
sys._getframe().f_code.co_name)
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
# C r e a t e _ t e m pl a t e #
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
l_template = ["| {0}".format(m.capitalize())
for m in self.l_module_lower]
# ~#~#~#~#~#~ #
# R e t u r n #
# ~#~#~#~#~#~ #
return "\n".join(l_template)
def create_qp_keywords_to_string(self):
"""
Generate keywords to string template
"""
# ~#~#~#~#~#~#~#~ #
# C h e c k i n g #
# ~#~#~#~#~#~#~#~ #
self.check_if_init(["l_module_lower"],
sys._getframe().f_code.co_name)
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
# C r e a t e _ t e m pl a t e #
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
l_template = ['| {0} -> "{0}"'.format(m.capitalize())
for m in self.l_module_lower]
# ~#~#~#~#~#~ #
# R e t u r n #
# ~#~#~#~#~#~ #
return "\n".join(l_template)
def create_qp_section_to_rst(self):
"""
Generate section to rst
"""
# ~#~#~#~#~#~#~#~ #
# C h e c k i n g #
# ~#~#~#~#~#~#~#~ #
self.check_if_init(["l_module_lower"],
sys._getframe().f_code.co_name)
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
# C r e a t e _ t e m pl a t e #
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
l_template = []
for m in self.l_module_lower:
m_cap = m.capitalize()
l_template += [" | {0} ->".format(m_cap),
" f {0}.(read, to_rst)".format(m_cap)]
# ~#~#~#~#~#~ #
# R e t u r n #
# ~#~#~#~#~#~ #
return "\n".join(l_template)
def create_qp_write(self):
"""
Generate write
"""
# ~#~#~#~#~#~#~#~ #
# C h e c k i n g #
# ~#~#~#~#~#~#~#~ #
self.check_if_init(["l_module_lower"],
sys._getframe().f_code.co_name)
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
# C r e a t e _ t e m pl a t e #
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
str_ = " | {0} -> write {0}.(of_rst, write) s"
l_template = [str_.format(m.capitalize()) for m in self.l_module_lower]
# ~#~#~#~#~#~ #
# R e t u r n #
# ~#~#~#~#~#~ #
return "\n".join(l_template)
def create_qp_tasks(self):
"""
Generate taks
"""
# ~#~#~#~#~#~#~#~ #
# C h e c k i n g #
# ~#~#~#~#~#~#~#~ #
self.check_if_init(["l_module_lower"],
sys._getframe().f_code.co_name)
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
# C r e a t e _ t e m pl a t e #
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
l_template = [" {0} ; ".format(m.capitalize())
for m in self.l_module_lower]
# ~#~#~#~#~#~ #
# R e t u r n #
# ~#~#~#~#~#~ #
return "\n".join(l_template)

View File

@ -11,27 +11,21 @@ open Core.Std;;
(** Keywords used to define input sections *) (** Keywords used to define input sections *)
type keyword = type keyword =
| Ao_basis | Ao_basis
| Bielec_integrals
| Cisd_sc2_selected
| Determinants | Determinants
| Electrons | Electrons
| Full_ci
| Hartree_fock
| Mo_basis | Mo_basis
| Nuclei | Nuclei
{keywords}
;; ;;
let keyword_to_string = function let keyword_to_string = function
| Ao_basis -> "AO basis" | Ao_basis -> "AO basis"
| Bielec_integrals -> "Two electron integrals"
| Cisd_sc2_selected -> "CISD (SC)^2"
| Determinants -> "Determinants" | Determinants -> "Determinants"
| Electrons -> "Electrons" | Electrons -> "Electrons"
| Full_ci -> "Selected Full-CI"
| Hartree_fock -> "Hartree-Fock"
| Mo_basis -> "MO basis" | Mo_basis -> "MO basis"
| Nuclei -> "Molecule" | Nuclei -> "Molecule"
{keywords_to_string}
;; ;;
@ -70,24 +64,17 @@ let get s =
begin begin
let open Input in let open Input in
match s with match s with
| Full_ci ->
f Full_ci.(read, to_rst)
| Hartree_fock ->
f Hartree_fock.(read, to_rst)
| Mo_basis -> | Mo_basis ->
f Mo_basis.(read, to_rst) f Mo_basis.(read, to_rst)
| Electrons -> | Electrons ->
f Electrons.(read, to_rst) f Electrons.(read, to_rst)
| Cisd_sc2_selected ->
f Cisd_sc2_selected.(read, to_rst)
| Nuclei -> | Nuclei ->
f Nuclei.(read, to_rst) f Nuclei.(read, to_rst)
| Ao_basis -> | Ao_basis ->
f Ao_basis.(read, to_rst) f Ao_basis.(read, to_rst)
| Bielec_integrals ->
f Bielec_integrals.(read, to_rst)
| Determinants -> | Determinants ->
f Determinants.(read, to_rst) f Determinants.(read, to_rst)
{section_to_rst}
end end
with with
| Sys_error msg -> (Printf.eprintf "Info: %s\n%!" msg ; "") | Sys_error msg -> (Printf.eprintf "Info: %s\n%!" msg ; "")
@ -125,11 +112,8 @@ let set str s =
in in
let open Input in let open Input in
match s with match s with
| Hartree_fock -> write Hartree_fock.(of_rst, write) s {write}
| Full_ci -> write Full_ci.(of_rst, write) s
| Electrons -> write Electrons.(of_rst, write) s | Electrons -> write Electrons.(of_rst, write) s
| Cisd_sc2_selected -> write Cisd_sc2_selected.(of_rst, write) s
| Bielec_integrals -> write Bielec_integrals.(of_rst, write) s
| Determinants -> write Determinants.(of_rst, write) s | Determinants -> write Determinants.(of_rst, write) s
| Nuclei -> write Nuclei.(of_rst, write) s | Nuclei -> write Nuclei.(of_rst, write) s
| Ao_basis -> () (* TODO *) | Ao_basis -> () (* TODO *)
@ -176,10 +160,7 @@ let run check_only ezfio_filename =
Nuclei ; Nuclei ;
Ao_basis; Ao_basis;
Electrons ; Electrons ;
Bielec_integrals ; {tasks}
Hartree_fock ;
Cisd_sc2_selected ;
Full_ci ;
Mo_basis; Mo_basis;
Determinants ; Determinants ;
] ]