From a7da480d6628290d6c25379f16ebe950c8083931 Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Thu, 26 Mar 2015 09:08:58 +0100 Subject: [PATCH 01/41] Cleanning ezfio_interface.py and SIZE keyword support --- scripts/ezfio_interface.py | 44 ++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/scripts/ezfio_interface.py b/scripts/ezfio_interface.py index 6bcb518e..7617d735 100755 --- a/scripts/ezfio_interface.py +++ b/scripts/ezfio_interface.py @@ -47,12 +47,6 @@ def get_type_dict(): # I n i t # # ~#~#~#~ # - # Dict to change ocaml LowLevel type into FortranLowLevel type - ocaml_to_fortran = {"int": "integer", - "float": "double precision", - "logical": "logical", - "string": "character*60"} - fancy_type = defaultdict(dict) # ~#~#~#~#~#~#~#~ # @@ -68,21 +62,32 @@ def get_type_dict(): fancy_type['logical'] = Type("bool", "logical") fancy_type['bool'] = Type("bool", "logical") + fancy_type['character*32'] = Type("string", "character*32") + fancy_type['character*60'] = Type("string", "character*60") + fancy_type['character*256'] = Type("string", "character*256") + # ~#~#~#~#~#~#~#~ # # q p _ t y p e s # # ~#~#~#~#~#~#~#~ # - src = os.environ['QPACKAGE_ROOT'] + "/ocaml/qptypes_generator.ml" + # Dict to change ocaml LowLevel type into FortranLowLevel type + ocaml_to_fortran = {"int": "integer", + "float": "double precision", + "logical": "logical", + "string": "character*32"} + # Read and parse qptype + src = os.environ['QPACKAGE_ROOT'] + "/ocaml/qptypes_generator.ml" with open(src, "r") as f: l = [i for i in f.read().splitlines() if i.strip().startswith("*")] + # Read the fancy_type, the ocaml. and convert the ocam to the fortran for i in l: - ocaml_fancy_type = i.split()[1].strip() - ocaml_type = i.split()[3] - fortran_type = ocaml_to_fortran[ocaml_type] + str_fancy_type = i.split()[1].strip() + str_ocaml_type = i.split()[3] + str_fortran_type = ocaml_to_fortran[str_ocaml_type] - fancy_type[ocaml_fancy_type] = Type(ocaml_type, fortran_type) + fancy_type[str_fancy_type] = Type(str_ocaml_type, str_fortran_type) return dict(fancy_type) @@ -102,6 +107,7 @@ def get_dict_config_file(config_file_path, module_lower): doc, ezfio_name, ezfio_dir, + size, interface, default} @@ -122,7 +128,7 @@ def get_dict_config_file(config_file_path, module_lower): d = defaultdict(dict) l_info_required = ["doc", "interface"] - l_info_optional = ["ezfio_name"] + l_info_optional = ["ezfio_name", "size"] # ~#~#~#~#~#~#~#~#~#~#~ # # L o a d _ C o n f i g # @@ -144,7 +150,7 @@ def get_dict_config_file(config_file_path, module_lower): pvd = section.lower() # Create the dictionary who containt the value per default - d_default = {"ezfio_name": pvd} + d_default = {"ezfio_name": pvd, "size": 1} # Set the ezfio_dir d[pvd]["ezfio_dir"] = module_lower @@ -241,12 +247,12 @@ def create_ezfio_config(dict_ezfio_cfg, opt, module_lower): result = [module_lower] lenmax = max([len(i) for i in dict_ezfio_cfg]) + 2 - l = sorted(dict_ezfio_cfg.keys()) - for provider_name in l: - provider_info = dict_ezfio_cfg[provider_name] - s = " {0} {1}".format( - provider_name.lower().ljust(lenmax), - provider_info["type"].fortran) + +# l = sorted(dict_ezfio_cfg.keys()) + for provider_name, provider_info in sorted(dict_ezfio_cfg.iteritems()): + + s = " {0} {1}".format(provider_name.lower().ljust(lenmax), + provider_info["type"].fortran) result.append(s) return "\n".join(result) From d3d2430c7422cb1a5eefc5c33faf2641ee7b2ba0 Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Thu, 26 Mar 2015 09:24:58 +0100 Subject: [PATCH 02/41] Create SIZE in ezfio_interface --- scripts/ezfio_interface.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/scripts/ezfio_interface.py b/scripts/ezfio_interface.py index 7617d735..085629d4 100755 --- a/scripts/ezfio_interface.py +++ b/scripts/ezfio_interface.py @@ -228,7 +228,7 @@ def save_ezfio_provider(path_head, dict_code_provider): path = "{0}/ezfio_interface.irp.f".format(path_head) - print "Path = {}".format(path) + print "Path = {0}".format(path) with open(path, "w") as f: f.write("!DO NOT MODIFY BY HAND \n") @@ -244,15 +244,21 @@ def create_ezfio_config(dict_ezfio_cfg, opt, module_lower): From dict_ezfio_cfg[provider_name] = {type, default, ezfio_name,ezfio_dir,doc} Return the string ezfio_interface_config """ - result = [module_lower] lenmax = max([len(i) for i in dict_ezfio_cfg]) + 2 -# l = sorted(dict_ezfio_cfg.keys()) for provider_name, provider_info in sorted(dict_ezfio_cfg.iteritems()): - s = " {0} {1}".format(provider_name.lower().ljust(lenmax), - provider_info["type"].fortran) + name = provider_name.lower() + fortran_type = provider_info["type"].fortran + size_raw = str(provider_info["size"]) + + if size_raw.startswith('='): + size = size_raw + else: + size = "({0})".format(size_raw) + + s = " {0} {1} {2}".format(name.ljust(lenmax), fortran_type, size) result.append(s) return "\n".join(result) @@ -267,7 +273,7 @@ def save_ezfio_config(module_lower, str_ezfio_config): path = "{0}/config/{1}.ezfio_interface_config".format(ezfio_dir, module_lower) - print "Path = {}".format(path) + print "Path = {0}".format(path) with open(path, "w") as f: f.write(str_ezfio_config) From cd518019ab266446646098db82ca7699af5d43b8 Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Thu, 26 Mar 2015 10:01:02 +0100 Subject: [PATCH 03/41] Amazing fancy ezfio_interface_config --- scripts/ezfio_interface.py | 57 ++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 9 deletions(-) diff --git a/scripts/ezfio_interface.py b/scripts/ezfio_interface.py index 085629d4..0756ad91 100755 --- a/scripts/ezfio_interface.py +++ b/scripts/ezfio_interface.py @@ -244,22 +244,61 @@ def create_ezfio_config(dict_ezfio_cfg, opt, module_lower): From dict_ezfio_cfg[provider_name] = {type, default, ezfio_name,ezfio_dir,doc} Return the string ezfio_interface_config """ + + def size_format_to_ezfio(size_raw): + """If = is a formula do nothing + Else but the parenthsesis because is the ezfio_ format + """ + size_raw = str(size_raw) + if size_raw.startswith('='): + size_convert = size_raw + else: + size_convert = "({0})".format(size_raw) + return size_convert + + def create_format_string(size): + """ + Take a size and return the string format for bewing right align + Example size = 10 + Return '{:<10}'.format + """ + + return "{{:<{0}}}".format(size).format + + # ~#~#~#~#~#~#~#~#~#~#~# # + # F o r m a t _ i n f o # + # ~#~#~#~#~#~#~#~#~#~#~# # + + lenmax_name = max([len(i) for i in dict_ezfio_cfg]) + lenmax_type = max([len(i["type"].fortran) for i in dict_ezfio_cfg.values()]) + + str_name_format = create_format_string(lenmax_name + 2) + str_type_format = create_format_string(lenmax_type + 2) + + # ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~# # + # C r e a t e _ t h e _ s t r i n g # + # ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~# # + result = [module_lower] - lenmax = max([len(i) for i in dict_ezfio_cfg]) + 2 for provider_name, provider_info in sorted(dict_ezfio_cfg.iteritems()): - name = provider_name.lower() - fortran_type = provider_info["type"].fortran - size_raw = str(provider_info["size"]) + # Get the value from dict + name_raw = provider_name.lower() + fortran_type_raw = provider_info["type"].fortran + size_raw = size_format_to_ezfio(provider_info["size"]) - if size_raw.startswith('='): - size = size_raw - else: - size = "({0})".format(size_raw) + # Get the string in to good format (left align and co) + str_name = str_name_format(name_raw) + str_fortran_type = str_type_format(fortran_type_raw) + str_size = size_raw - s = " {0} {1} {2}".format(name.ljust(lenmax), fortran_type, size) + # Return the string + s = " {0} {1} {2}".format(str_name, str_fortran_type, str_size) + + # Append result.append(s) + return "\n".join(result) From 01a7a9c345cf37301a926fe10228b532c70d5a20 Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Thu, 26 Mar 2015 12:02:58 +0100 Subject: [PATCH 04/41] Cleaning, Need to add EZFIO creation support --- scripts/ezfio_interface.py | 56 +++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 16 deletions(-) diff --git a/scripts/ezfio_interface.py b/scripts/ezfio_interface.py index dab258fd..ba735fbf 100755 --- a/scripts/ezfio_interface.py +++ b/scripts/ezfio_interface.py @@ -7,17 +7,33 @@ EZFIO.cfg are in MODULE directories. create : ezfio_interface.irp.f folder_ezfio_inteface_config +Format specification : + [provider_name] : the name of the provider in irp.f90 + - doc : Is the doc + - Type : Is a fancy_type support by the ocaml + - ezfio_name : Will be the name of the file for the ezfio + (optional by default is the name of the provider) + - interface : The provider is a imput or a output + - default : The default value if interface == output: + - size : Is the string read in ezfio.cgf who containt the size information + (like 1 or =sum(ao_num) or (ao_num,3) ) + Example EZFIO.cfg: ``` [thresh_SCF] doc: Threshold on the convergence of the Hartree Fock energy type: Threshold default: 1.e-10 +interface: output +default: 10000 +size : ao_num, 3 [do_pt2_end] type: logical doc: If true, compute the PT2 at the end of the selection default: true +interface: input +size : 1 ``` """ @@ -111,16 +127,16 @@ def get_dict_config_file(config_file_path, module_lower): interface, default} - Type : Is a fancy_type named typle who containt fortran and ocaml type - doc : Is the doc - ezfio_name : Will be the name of the file - ezfio_dir : Will be the folder who containt the ezfio_name + - Type : Is a fancy_type named typle who containt fortran and ocaml type + - doc : Is the doc + - ezfio_name : Will be the name of the file + - ezfio_dir : Will be the folder who containt the ezfio_name * /ezfio_dir/ezfio_name * equal to MODULE_lower name for the moment. - interface : The provider is a imput or a output - if is a output: - default : The default value - + - interface : The provider is a imput or a output + - default : The default value if interface == output: + - size : Is the string read in ezfio.cgf who containt the size information + (like 1 or =sum(ao_num)) """ # ~#~#~#~ # # I n i t # @@ -150,7 +166,7 @@ def get_dict_config_file(config_file_path, module_lower): pvd = section.lower() # Create the dictionary who containt the value per default - d_default = {"ezfio_name": pvd, "size": 1} + d_default = {"ezfio_name": pvd} # Set the ezfio_dir d[pvd]["ezfio_dir"] = module_lower @@ -177,7 +193,8 @@ def get_dict_config_file(config_file_path, module_lower): try: d[pvd][option] = config_file.get(section, option).lower() except ConfigParser.NoOptionError: - d[pvd][option] = d_default[option] + if option in d_default: + d[pvd][option] = d_default[option] # If interface is output we need a default value information if d[pvd]["interface"] == "output": @@ -197,7 +214,8 @@ def create_ezfio_provider(dict_ezfio_cfg): ezfio_name, ezfio_dir, interface, - default} + default + size} create the a list who containt all the code for the provider return [code, ...] """ @@ -259,11 +277,13 @@ def create_ezfio_config(dict_ezfio_cfg, opt, module_lower): """ def size_format_to_ezfio(size_raw): - """If = is a formula do nothing - Else but the parenthsesis because is the ezfio_ format + """If = is a formula so do nothing + If the value are between parenthsesis donothing + Else put the parenthsesis """ size_raw = str(size_raw) - if size_raw.startswith('='): + if any([size_raw.startswith('='), + size_raw.startswith("(") and size_raw.endswith(")")]): size_convert = size_raw else: size_convert = "({0})".format(size_raw) @@ -300,12 +320,16 @@ def create_ezfio_config(dict_ezfio_cfg, opt, module_lower): # Get the value from dict name_raw = provider_name.lower() fortran_type_raw = provider_info["type"].fortran - size_raw = size_format_to_ezfio(provider_info["size"]) + + if "size" in provider_info and not provider_info["size"] == "1": + size_raw = provider_info["size"] + else: + size_raw = None # Get the string in to good format (left align and co) str_name = str_name_format(name_raw) str_fortran_type = str_type_format(fortran_type_raw) - str_size = size_raw + str_size = size_format_to_ezfio(size_raw) if size_raw else "" # Return the string s = " {0} {1} {2}".format(str_name, str_fortran_type, str_size) From 246cc669368ee2554aac1deeeda5feaebc0e3779 Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Thu, 26 Mar 2015 12:27:53 +0100 Subject: [PATCH 05/41] Typo and remove print --- scripts/ezfio_interface.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/scripts/ezfio_interface.py b/scripts/ezfio_interface.py index ba735fbf..a6ab92fb 100755 --- a/scripts/ezfio_interface.py +++ b/scripts/ezfio_interface.py @@ -246,7 +246,7 @@ def save_ezfio_provider(path_head, dict_code_provider): path = "{0}/ezfio_interface.irp.f".format(path_head) - print "Path = {0}".format(path) + # print "Path = {0}".format(path) try: f = open(path, "r") @@ -369,6 +369,9 @@ def main(): -Take the EZFIO.cfg path in arg or -Look if EZFIO.cfg is present in the pwd + + Return : - ezfio_interface.irp.f + - folder_ezfio_inteface_config """ try: @@ -381,28 +384,28 @@ def main(): config_file_path = os.path.expanduser(config_file_path) config_file_path = os.path.expandvars(config_file_path) config_file_path = os.path.abspath(config_file_path) -# print config_file_path + # print config_file_path path_dirname = os.path.dirname(config_file_path) module = [i for i in path_dirname.split("/") if i][-1] module_lower = module.lower() -# print "Read {0}".format(config_file_path) + # print "Read {0}".format(config_file_path) dict_info_provider = get_dict_config_file(config_file_path, module_lower) -# print "Generating the ezfio_interface.irp.f: \n" + # print "Generating the ezfio_interface.irp.f: \n" d_config = create_ezfio_provider(dict_info_provider) -# print "Saving the ezfio_interface.irp.f" + # print "Saving the ezfio_interface.irp.f" save_ezfio_provider(path_dirname, d_config) -# print "Generating the ezfio_config" + # print "Generating the ezfio_config" config_ezfio = create_ezfio_config( dict_info_provider, "config", module_lower) -# print "Saving ezfio_config" + # print "Saving ezfio_config" save_ezfio_config(module_lower, config_ezfio) From 22bae157946a7e7b693ce60c862acbcbbb48cf6a Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Thu, 26 Mar 2015 12:52:07 +0100 Subject: [PATCH 06/41] PEP 8 in ezfio_with_default and typo --- scripts/ezfio_with_default.py | 184 +++++++++++++++++----------------- 1 file changed, 92 insertions(+), 92 deletions(-) diff --git a/scripts/ezfio_with_default.py b/scripts/ezfio_with_default.py index 1208f4b7..5db1e707 100755 --- a/scripts/ezfio_with_default.py +++ b/scripts/ezfio_with_default.py @@ -1,7 +1,7 @@ #!/usr/bin/env python -__author__ = "Anthony Scemama" -__date__ = "Tue Jul 29 12:20:00 CEST 2014" +__author__ = "Anthony Scemama and Applencourt for the amazing PEP8" +__date__ = "jeudi 26 mars 2015, 12:49:35 (UTC+0100)" """ Creates the provider of a variable that has to be @@ -14,9 +14,9 @@ import os class EZFIO_Provider(object): - data = """BEGIN_PROVIDER [ %(type)s, %(name)s ] + data = """BEGIN_PROVIDER [ %(type)s, %(name)s ] implicit none - BEGIN_DOC + BEGIN_DOC ! %(doc)s END_DOC @@ -33,109 +33,109 @@ class EZFIO_Provider(object): END_PROVIDER """ - write_correspondance = { - "integer" : "write_int", - "logical" : "write_bool", - "double precision" : "write_double" } + write_correspondance = {"integer": "write_int", + "logical": "write_bool", + "double precision": "write_double"} - def __init__(self): - self.values = "type doc default name ezfio_dir ezfio_name write output".split() - for v in self.values: - exec "self.%s = None"%(v) in locals() - - def __repr__(self): - self.get_default() - self.set_write() - for v in self.values: - exec "test = self.%s is None"%(v) in locals() - if test: - print >>sys.stderr, "Error : %s is not set in ezfio_with_default.py"%(v) + def __init__(self): + self.values = "type doc default name ezfio_dir ezfio_name write output".split() for v in self.values: - exec "x = str(self.%s)"%(v) in locals() - print >>sys.stderr, "%s : %s"%(v, x) - sys.exit(1) - return self.data%self.__dict__ + exec "self.%s = None" % (v) in locals() - def set_write(self): - self.write = "" - if self.type in self.write_correspondance: - write = self.write_correspondance[self.type] - output = self.output - name = self.name - self.write = """ + def __repr__(self): + self.get_default() + self.set_write() + for v in self.values: + exec "test = self.%s is None" % (v) in locals() + if test: + msg = "Error : %s is not set in ezfio_with_default.py" % (v) + print >>sys.stderr, msg + for v in self.values: + exec "x = str(self.%s)" % (v) in locals() + print >>sys.stderr, "%s : %s" % (v, x) + sys.exit(1) + return self.data % self.__dict__ + + def set_write(self): + self.write = "" + if self.type in self.write_correspondance: + write = self.write_correspondance[self.type] + output = self.output + name = self.name + self.write = """ call write_time(%(output)s) call %(write)s(%(output)s, %(name)s, & - '%(name)s') - """%locals() + '%(name)s')""" % locals() - def set_type(self,t): - self.type = t.lower() + def set_type(self, t): + self.type = t.lower() - def set_doc(self,t): - self.doc = t.replace('\n', '\n! ') + def set_doc(self, t): + self.doc = t.replace('\n', '\n! ') - def set_name(self,t): - self.name = t + def set_name(self, t): + self.name = t - def set_ezfio_dir(self,t): - self.ezfio_dir = t.lower() + def set_ezfio_dir(self, t): + self.ezfio_dir = t.lower() - def set_ezfio_name(self,t): - self.ezfio_name = t.lower() + def set_ezfio_name(self, t): + self.ezfio_name = t.lower() - def set_output(self,t): - self.output = t + def set_output(self, t): + self.output = t - def set_default(self,t): - self.default = t + def set_default(self, t): + self.default = t - def get_default(self): - filename = '/'.join( [os.environ['QPACKAGE_ROOT'], 'data', 'ezfio_defaults'] ) - file = open(filename,'r') - lines = file.readlines() - file.close() - # Search directory - for k,line in enumerate(lines): - if line[0] != ' ': - if line.strip().lower() == self.ezfio_dir: - break - if k+1 == len(lines): - return - # Search name - while k < len(lines): - k+=1 - buffer = lines[k].split() - if len(buffer) == 0: - return - if buffer[0].lower() == self.ezfio_name: - break - v = buffer[1] - name = self.name - try: - v_eval = eval(v) - if type(v_eval) == bool: - v = '.%s.'%(v) - elif type(v_eval) == float: - v = v.replace('e','d') - v = v.replace('E','D') - v = "%(name)s = %(v)s"%locals() - except: - v = "call ezfio_get_%(v)s(%(name)s)"%locals() - self.default = v + def get_default(self): + filename = '/'.join([os.environ['QPACKAGE_ROOT'], + 'data', + 'ezfio_defaults']) + + with open(filename, 'r') as f: + lines = f.readlines() + + # Search directory + for k, line in enumerate(lines): + if line[0] != ' ': + if line.strip().lower() == self.ezfio_dir: + break + if k + 1 == len(lines): + return + # Search name + while k < len(lines): + k += 1 + buffer = lines[k].split() + if len(buffer) == 0: + return + if buffer[0].lower() == self.ezfio_name: + break + v = buffer[1] + name = self.name + try: + v_eval = eval(v) + if isinstance(v_eval, bool): + v = '.%s.' % (v) + elif isinstance(v_eval, float): + v = v.replace('e', 'd') + v = v.replace('E', 'D') + v = "%(name)s = %(v)s" % locals() + except: + v = "call ezfio_get_%(v)s(%(name)s)" % locals() + self.default = v def test_module(): - T = EZFIO_Provider() - T.set_type ( "double precision" ) - T.set_name ( "thresh_SCF" ) - T.set_doc ( "Threshold on the convergence of the Hartree Fock energy" ) - T.set_ezfio_dir ( "Hartree_Fock" ) - T.set_ezfio_name( "thresh_SCF" ) - T.set_output ( "output_Hartree_Fock" ) - print T - + T = EZFIO_Provider() + T.set_type("double precision") + T.set_name("thresh_SCF") + T.set_doc("Threshold on the convergence of the Hartree Fock energy") + T.set_ezfio_dir("Hartree_Fock") + T.set_ezfio_name("thresh_SCF") + T.set_output("output_Hartree_Fock") + print T + if __name__ == '__main__': - test_module() - - + test_module() From 8ffdd3bc4f1de910ec131e768e19c2679b63d244 Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Thu, 26 Mar 2015 14:28:32 +0100 Subject: [PATCH 07/41] provider.irp.f90 only read value in ezfio. Is value is not set, just exit --- scripts/ezfio_interface.py | 27 ++++++++++++++++++++++++--- scripts/ezfio_with_default.py | 3 ++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/scripts/ezfio_interface.py b/scripts/ezfio_interface.py index a6ab92fb..2eb47320 100755 --- a/scripts/ezfio_interface.py +++ b/scripts/ezfio_interface.py @@ -50,6 +50,15 @@ from collections import namedtuple Type = namedtuple('Type', 'ocaml fortran') +def is_bool(str_): + if str_.lower() in ['true', '.true.']: + return Type("true", ".True.") + elif str_.lower() in ['false', '.False.']: + return Type("false", ".False") + else: + raise TypeError + + def get_type_dict(): """ This function makes the correspondance between the type of value read in @@ -199,11 +208,16 @@ def get_dict_config_file(config_file_path, module_lower): # If interface is output we need a default value information if d[pvd]["interface"] == "output": try: - d[pvd]["default"] = config_file.get(section, "default") + default_raw = config_file.get(section, "default") except ConfigParser.NoOptionError: error("default", pvd, config_file_path) sys.exit(1) + try: + d[pvd]["default"] = is_bool(default_raw) + except: + d[pvd]["default"] = Type(default_raw, default_raw) + return dict(d) @@ -231,7 +245,11 @@ def create_ezfio_provider(dict_ezfio_cfg): ez_p.set_doc(dict_info['doc']) ez_p.set_ezfio_dir(dict_info['ezfio_dir']) ez_p.set_ezfio_name(dict_info['ezfio_name']) - ez_p.set_default(dict_info['default']) + + # default = "{0} = {1}".format(provider_name, + # dict_info['default'].fortran) + # ez_p.set_default(default) + ez_p.set_default("stop 1") ez_p.set_output("output_%s" % dict_info['ezfio_dir']) dict_code_provider[provider_name] = str(ez_p) @@ -281,6 +299,7 @@ def create_ezfio_config(dict_ezfio_cfg, opt, module_lower): If the value are between parenthsesis donothing Else put the parenthsesis """ + size_raw = str(size_raw) if any([size_raw.startswith('='), size_raw.startswith("(") and size_raw.endswith(")")]): @@ -326,10 +345,12 @@ def create_ezfio_config(dict_ezfio_cfg, opt, module_lower): else: size_raw = None + # It is the last so we don't need to right align it + str_size = size_format_to_ezfio(size_raw) if size_raw else "" + # Get the string in to good format (left align and co) str_name = str_name_format(name_raw) str_fortran_type = str_type_format(fortran_type_raw) - str_size = size_format_to_ezfio(size_raw) if size_raw else "" # Return the string s = " {0} {1} {2}".format(str_name, str_fortran_type, str_size) diff --git a/scripts/ezfio_with_default.py b/scripts/ezfio_with_default.py index 5db1e707..5b2b07e5 100755 --- a/scripts/ezfio_with_default.py +++ b/scripts/ezfio_with_default.py @@ -43,7 +43,8 @@ END_PROVIDER exec "self.%s = None" % (v) in locals() def __repr__(self): - self.get_default() + if not self.default: + self.get_default() self.set_write() for v in self.values: exec "test = self.%s is None" % (v) in locals() From 69490976fda91d4b2dcc77fe48cd30794d4a73db Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Thu, 26 Mar 2015 14:35:09 +0100 Subject: [PATCH 08/41] Doc and typo --- scripts/ezfio_interface.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/scripts/ezfio_interface.py b/scripts/ezfio_interface.py index 2eb47320..d4ecf58a 100755 --- a/scripts/ezfio_interface.py +++ b/scripts/ezfio_interface.py @@ -136,14 +136,16 @@ def get_dict_config_file(config_file_path, module_lower): interface, default} - - Type : Is a fancy_type named typle who containt fortran and ocaml type + - Type : Is a Type named tuple who containt + fortran and ocaml type - doc : Is the doc - ezfio_name : Will be the name of the file - ezfio_dir : Will be the folder who containt the ezfio_name * /ezfio_dir/ezfio_name * equal to MODULE_lower name for the moment. - interface : The provider is a imput or a output - - default : The default value if interface == output: + - default : The default value /!\ stored in a Type named type! + if interface == output - size : Is the string read in ezfio.cgf who containt the size information (like 1 or =sum(ao_num)) """ @@ -295,9 +297,10 @@ def create_ezfio_config(dict_ezfio_cfg, opt, module_lower): """ def size_format_to_ezfio(size_raw): - """If = is a formula so do nothing - If the value are between parenthsesis donothing - Else put the parenthsesis + """ + If size_raw == "=" is a formula -> do nothing; return + If the value are between parenthses -> do nothing; return + Else put it in parenthsesis """ size_raw = str(size_raw) @@ -310,9 +313,8 @@ def create_ezfio_config(dict_ezfio_cfg, opt, module_lower): def create_format_string(size): """ - Take a size and return the string format for bewing right align - Example size = 10 - Return '{:<10}'.format + Take a size number and + return the string format for being right align with this ofset """ return "{{:<{0}}}".format(size).format From 91ac5cc2a8cb53776812312cf9615022113146fa Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Thu, 26 Mar 2015 14:50:19 +0100 Subject: [PATCH 09/41] Add pickle to ezfio_interface.py --- scripts/ezfio_interface.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/scripts/ezfio_interface.py b/scripts/ezfio_interface.py index d4ecf58a..6f6ec9b4 100755 --- a/scripts/ezfio_interface.py +++ b/scripts/ezfio_interface.py @@ -51,6 +51,10 @@ Type = namedtuple('Type', 'ocaml fortran') def is_bool(str_): + """ + Take a string, if is a bool return the convert into + fortran and ocaml one. + """ if str_.lower() in ['true', '.true.']: return Type("true", ".True.") elif str_.lower() in ['false', '.False.']: @@ -67,6 +71,21 @@ def get_type_dict(): For example fancy_type['Ndet'].fortran = interger .ocaml = int """ + # ~#~#~#~#~ # + # P i c l e # + # ~#~#~#~#~ # + + import cPickle as pickle + + from os import listdir + + qpackage_root = os.environ['QPACKAGE_ROOT'] + + fancy_type_pickle = qpackage_root + "/scripts/fancy_type.p" + + if fancy_type_pickle in listdir(os.getcwd()): + fancy_type = pickle.load(open(fancy_type_pickle, "rb")) + return fancy_type # ~#~#~#~ # # I n i t # @@ -102,7 +121,7 @@ def get_type_dict(): "string": "character*32"} # Read and parse qptype - src = os.environ['QPACKAGE_ROOT'] + "/ocaml/qptypes_generator.ml" + src = qpackage_root + "/ocaml/qptypes_generator.ml" with open(src, "r") as f: l = [i for i in f.read().splitlines() if i.strip().startswith("*")] @@ -114,6 +133,12 @@ def get_type_dict(): fancy_type[str_fancy_type] = Type(str_ocaml_type, str_fortran_type) + # ~#~#~#~#~#~#~#~ # + # F i n a l i z e # + # ~#~#~#~#~#~#~#~ # + + pickle.dump(dict(fancy_type), open(fancy_type_pickle, "wb")) + return dict(fancy_type) @@ -217,7 +242,7 @@ def get_dict_config_file(config_file_path, module_lower): try: d[pvd]["default"] = is_bool(default_raw) - except: + except TypeError: d[pvd]["default"] = Type(default_raw, default_raw) return dict(d) From 1a2a61edbcb246c036817ebef15bf8724f7661f4 Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Thu, 26 Mar 2015 17:04:57 +0100 Subject: [PATCH 10/41] Spaces --- scripts/ezfio_interface.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/ezfio_interface.py b/scripts/ezfio_interface.py index 6f6ec9b4..8ff6ddd5 100755 --- a/scripts/ezfio_interface.py +++ b/scripts/ezfio_interface.py @@ -273,10 +273,13 @@ def create_ezfio_provider(dict_ezfio_cfg): ez_p.set_ezfio_dir(dict_info['ezfio_dir']) ez_p.set_ezfio_name(dict_info['ezfio_name']) - # default = "{0} = {1}".format(provider_name, - # dict_info['default'].fortran) - # ez_p.set_default(default) - ez_p.set_default("stop 1") + str_ = "\n".join([" print *, '{0}/{1} not found in EZFIO file'", + " stop 1" ]) + + str_ = str_.format(dict_info['ezfio_dir'], + dict_info['ezfio_name']) + + ez_p.set_default(str_) ez_p.set_output("output_%s" % dict_info['ezfio_dir']) dict_code_provider[provider_name] = str(ez_p) From 94e06e2a5b593d9ecbbe30a3966daa14adf802dc Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Thu, 26 Mar 2015 18:24:40 +0100 Subject: [PATCH 11/41] Ocaml default on multiple files --- data/ezfio_defaults | 60 -------------------------------------- data/ezfio_defaults/.empty | 0 ocaml/Input_full_ci.ml | 2 +- ocaml/Input_mo_basis.ml | 26 +++++++---------- ocaml/Qpackage.ml | 30 ++++++++++++++++--- 5 files changed, 37 insertions(+), 81 deletions(-) delete mode 100644 data/ezfio_defaults create mode 100644 data/ezfio_defaults/.empty diff --git a/data/ezfio_defaults b/data/ezfio_defaults deleted file mode 100644 index 5da4d813..00000000 --- a/data/ezfio_defaults +++ /dev/null @@ -1,60 +0,0 @@ -bielec_integrals - read_ao_integrals False - read_mo_integrals False - write_ao_integrals False - write_mo_integrals False - threshold_ao 1.e-15 - threshold_mo 1.e-15 - direct False - -cis_dressed - n_state_cis 10 - n_core_cis 0 - n_act_cis mo_basis_mo_tot_num - mp2_dressing False - standard_doubles True - en_2_2 False - -determinants - n_states 1 - n_states_diag determinants_n_states - n_det_max_jacobi 1000 - threshold_generators 0.99 - threshold_selectors 0.999 - read_wf False - s2_eig False - only_single_double_dm False - -full_ci - n_det_max_fci 10000 - n_det_max_fci_property 50000 - pt2_max 1.e-4 - do_pt2_end True - var_pt2_ratio 0.75 - -all_singles - n_det_max_fci 50000 - pt2_max 1.e-8 - do_pt2_end False - -cassd - n_det_max_cassd 10000 - pt2_max 1.e-4 - do_pt2_end True - -hartree_fock - n_it_scf_max 200 - thresh_scf 1.e-10 - guess "Huckel" - -cisd_selected - n_det_max_cisd 10000 - pt2_max 1.e-4 - -cisd_sc2_selected - n_det_max_cisd_sc2 10000 - pt2_max 1.e-4 - do_pt2_end True - -properties - z_one_point 3.9 diff --git a/data/ezfio_defaults/.empty b/data/ezfio_defaults/.empty new file mode 100644 index 00000000..e69de29b diff --git a/ocaml/Input_full_ci.ml b/ocaml/Input_full_ci.ml index 01548e88..f963ee7e 100644 --- a/ocaml/Input_full_ci.ml +++ b/ocaml/Input_full_ci.ml @@ -3,7 +3,7 @@ open Qputils;; open Core.Std;; module Full_ci : sig - type t = + type t = { n_det_max_fci : Det_number_max.t; pt2_max : PT2_energy.t; do_pt2_end : bool; diff --git a/ocaml/Input_mo_basis.ml b/ocaml/Input_mo_basis.ml index f02dbfa9..ab75b869 100644 --- a/ocaml/Input_mo_basis.ml +++ b/ocaml/Input_mo_basis.ml @@ -2,27 +2,21 @@ open Qptypes;; open Qputils;; open Core.Std;; +type t_mo = + { mo_tot_num : MO_number.t ; + mo_label : MO_label.t; + mo_occ : MO_occ.t array; + mo_coef : (MO_coef.t array) array; + ao_md5 : MD5.t; + } with sexp + module Mo_basis : sig - type t = - { mo_tot_num : MO_number.t ; - mo_label : MO_label.t; - mo_occ : MO_occ.t array; - mo_coef : (MO_coef.t array) array; - ao_md5 : MD5.t; - } with sexp - ;; + type t = t_mo val read : unit -> t option val to_string : t -> string val to_rst : t -> Rst_string.t end = struct - type t = - { mo_tot_num : MO_number.t ; - mo_label : MO_label.t; - mo_occ : MO_occ.t array; - mo_coef : (MO_coef.t array) array; - ao_md5 : MD5.t; - } with sexp - ;; + type t = t_mo let get_default = Qpackage.get_ezfio_default "mo_basis";; diff --git a/ocaml/Qpackage.ml b/ocaml/Qpackage.ml index 143cff28..4d08192a 100644 --- a/ocaml/Qpackage.ml +++ b/ocaml/Qpackage.ml @@ -71,8 +71,8 @@ let executables = lazy ( ) -let get_ezfio_default directory data = - let filename = root^"/data/ezfio_defaults" in + +let get_ezfio_default_in_file ~directory ~data ~filename = let lines = In_channel.with_file filename ~f:(fun in_channel -> In_channel.input_lines in_channel) in let rec find_dir = function @@ -93,8 +93,10 @@ let get_ezfio_default directory data = begin match (String.lsplit2 ~on:' ' (String.strip line)) with | Some (l,r) -> - if (l = data) then (String.lowercase (String.strip r)) - else find_data rest + if (l = data) then + String.lowercase (String.strip r) + else + find_data rest | None -> raise Not_found end | [] -> raise Not_found @@ -102,3 +104,23 @@ let get_ezfio_default directory data = find_dir lines |> find_data ; ;; + +let get_ezfio_default directory data = + let dirname = root^"/data/ezfio_defaults/" in + + let rec aux = function + | [] -> raise Not_found + | filename :: tail -> + let filename = + dirname^filename + in + try + get_ezfio_default_in_file ~directory ~data ~filename + with + | Not_found -> aux tail + in + Sys.readdir dirname + |> Array.to_list + |> aux +;; + From b72f6a813c2a3549ea7a20cb1821dfb6db1835a9 Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Thu, 26 Mar 2015 19:04:19 +0100 Subject: [PATCH 12/41] Add python 2.6 in travis --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 6b29a49e..1a1b3701 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,9 @@ sudo: true +language: python +python: + - "2.6" + before_script: - sudo apt-get update - sudo apt-get install gfortran liblapack-dev zip From 7e1c45bedd60ff6375a0ceb4ae4ca90601acc318 Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Thu, 26 Mar 2015 19:26:48 +0100 Subject: [PATCH 13/41] Now ezfio_interface.py work in Python 2.6 --- scripts/ezfio_interface.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/ezfio_interface.py b/scripts/ezfio_interface.py index 8ff6ddd5..f875d326 100755 --- a/scripts/ezfio_interface.py +++ b/scripts/ezfio_interface.py @@ -342,10 +342,9 @@ def create_ezfio_config(dict_ezfio_cfg, opt, module_lower): def create_format_string(size): """ Take a size number and - return the string format for being right align with this ofset + return the string format for being right align with this offset """ - - return "{{:<{0}}}".format(size).format + return "{{0:<{0}}}".format(size).format # ~#~#~#~#~#~#~#~#~#~#~# # # F o r m a t _ i n f o # From 3c368023e95ce907400dbcaecd0b737f0e892350 Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Thu, 26 Mar 2015 20:04:05 +0100 Subject: [PATCH 14/41] Modif ezfio_default for reflection the new change in default. Add ezfio_generate_provider who is the new version of the program --- scripts/ezfio_generate_provider.py | 142 +++++++++++++++++++++ scripts/ezfio_interface.py | 10 +- scripts/ezfio_with_default.py | 190 +++++++++++++++-------------- 3 files changed, 246 insertions(+), 96 deletions(-) create mode 100755 scripts/ezfio_generate_provider.py diff --git a/scripts/ezfio_generate_provider.py b/scripts/ezfio_generate_provider.py new file mode 100755 index 00000000..5b2b07e5 --- /dev/null +++ b/scripts/ezfio_generate_provider.py @@ -0,0 +1,142 @@ +#!/usr/bin/env python + +__author__ = "Anthony Scemama and Applencourt for the amazing PEP8" +__date__ = "jeudi 26 mars 2015, 12:49:35 (UTC+0100)" + +""" +Creates the provider of a variable that has to be +fetched from the EZFIO file. +""" + +import sys +import os + + +class EZFIO_Provider(object): + + data = """BEGIN_PROVIDER [ %(type)s, %(name)s ] + implicit none + BEGIN_DOC +! %(doc)s + END_DOC + + logical :: has + PROVIDE ezfio_filename + call ezfio_has_%(ezfio_dir)s_%(ezfio_name)s(has) + if (has) then + call ezfio_get_%(ezfio_dir)s_%(ezfio_name)s(%(name)s) + else + %(default)s + endif + %(write)s + +END_PROVIDER +""" + + write_correspondance = {"integer": "write_int", + "logical": "write_bool", + "double precision": "write_double"} + + def __init__(self): + self.values = "type doc default name ezfio_dir ezfio_name write output".split() + for v in self.values: + exec "self.%s = None" % (v) in locals() + + def __repr__(self): + if not self.default: + self.get_default() + self.set_write() + for v in self.values: + exec "test = self.%s is None" % (v) in locals() + if test: + msg = "Error : %s is not set in ezfio_with_default.py" % (v) + print >>sys.stderr, msg + for v in self.values: + exec "x = str(self.%s)" % (v) in locals() + print >>sys.stderr, "%s : %s" % (v, x) + sys.exit(1) + return self.data % self.__dict__ + + def set_write(self): + self.write = "" + if self.type in self.write_correspondance: + write = self.write_correspondance[self.type] + output = self.output + name = self.name + self.write = """ + call write_time(%(output)s) + call %(write)s(%(output)s, %(name)s, & + '%(name)s')""" % locals() + + def set_type(self, t): + self.type = t.lower() + + def set_doc(self, t): + self.doc = t.replace('\n', '\n! ') + + def set_name(self, t): + self.name = t + + def set_ezfio_dir(self, t): + self.ezfio_dir = t.lower() + + def set_ezfio_name(self, t): + self.ezfio_name = t.lower() + + def set_output(self, t): + self.output = t + + def set_default(self, t): + self.default = t + + def get_default(self): + filename = '/'.join([os.environ['QPACKAGE_ROOT'], + 'data', + 'ezfio_defaults']) + + with open(filename, 'r') as f: + lines = f.readlines() + + # Search directory + for k, line in enumerate(lines): + if line[0] != ' ': + if line.strip().lower() == self.ezfio_dir: + break + if k + 1 == len(lines): + return + # Search name + while k < len(lines): + k += 1 + buffer = lines[k].split() + if len(buffer) == 0: + return + if buffer[0].lower() == self.ezfio_name: + break + v = buffer[1] + name = self.name + try: + v_eval = eval(v) + if isinstance(v_eval, bool): + v = '.%s.' % (v) + elif isinstance(v_eval, float): + v = v.replace('e', 'd') + v = v.replace('E', 'D') + v = "%(name)s = %(v)s" % locals() + except: + v = "call ezfio_get_%(v)s(%(name)s)" % locals() + self.default = v + + +def test_module(): + T = EZFIO_Provider() + T.set_type("double precision") + T.set_name("thresh_SCF") + T.set_doc("Threshold on the convergence of the Hartree Fock energy") + T.set_ezfio_dir("Hartree_Fock") + T.set_ezfio_name("thresh_SCF") + T.set_output("output_Hartree_Fock") + print T + + +if __name__ == '__main__': + test_module() diff --git a/scripts/ezfio_interface.py b/scripts/ezfio_interface.py index f875d326..6f6d654f 100755 --- a/scripts/ezfio_interface.py +++ b/scripts/ezfio_interface.py @@ -260,7 +260,7 @@ def create_ezfio_provider(dict_ezfio_cfg): create the a list who containt all the code for the provider return [code, ...] """ - from ezfio_with_default import EZFIO_Provider + from ezfio_generate_provider import EZFIO_Provider dict_code_provider = dict() @@ -274,11 +274,11 @@ def create_ezfio_provider(dict_ezfio_cfg): ez_p.set_ezfio_name(dict_info['ezfio_name']) str_ = "\n".join([" print *, '{0}/{1} not found in EZFIO file'", - " stop 1" ]) - + " stop 1"]) + str_ = str_.format(dict_info['ezfio_dir'], - dict_info['ezfio_name']) - + dict_info['ezfio_name']) + ez_p.set_default(str_) ez_p.set_output("output_%s" % dict_info['ezfio_dir']) diff --git a/scripts/ezfio_with_default.py b/scripts/ezfio_with_default.py index 5b2b07e5..46981132 100755 --- a/scripts/ezfio_with_default.py +++ b/scripts/ezfio_with_default.py @@ -1,7 +1,7 @@ #!/usr/bin/env python -__author__ = "Anthony Scemama and Applencourt for the amazing PEP8" -__date__ = "jeudi 26 mars 2015, 12:49:35 (UTC+0100)" +__author__ = "Anthony Scemama" +__date__ = "Tue Jul 29 12:20:00 CEST 2014" """ Creates the provider of a variable that has to be @@ -14,9 +14,9 @@ import os class EZFIO_Provider(object): - data = """BEGIN_PROVIDER [ %(type)s, %(name)s ] + data = """BEGIN_PROVIDER [ %(type)s, %(name)s ] implicit none - BEGIN_DOC + BEGIN_DOC ! %(doc)s END_DOC @@ -33,110 +33,118 @@ class EZFIO_Provider(object): END_PROVIDER """ - write_correspondance = {"integer": "write_int", - "logical": "write_bool", - "double precision": "write_double"} + write_correspondance = { + "integer" : "write_int", + "logical" : "write_bool", + "double precision" : "write_double" } - def __init__(self): - self.values = "type doc default name ezfio_dir ezfio_name write output".split() + def __init__(self): + self.values = "type doc default name ezfio_dir ezfio_name write output".split() + for v in self.values: + exec "self.%s = None"%(v) in locals() + + def __repr__(self): + self.get_default() + self.set_write() + for v in self.values: + exec "test = self.%s is None"%(v) in locals() + if test: + print >>sys.stderr, "Error : %s is not set in ezfio_with_default.py"%(v) for v in self.values: - exec "self.%s = None" % (v) in locals() + exec "x = str(self.%s)"%(v) in locals() + print >>sys.stderr, "%s : %s"%(v, x) + sys.exit(1) + return self.data%self.__dict__ - def __repr__(self): - if not self.default: - self.get_default() - self.set_write() - for v in self.values: - exec "test = self.%s is None" % (v) in locals() - if test: - msg = "Error : %s is not set in ezfio_with_default.py" % (v) - print >>sys.stderr, msg - for v in self.values: - exec "x = str(self.%s)" % (v) in locals() - print >>sys.stderr, "%s : %s" % (v, x) - sys.exit(1) - return self.data % self.__dict__ - - def set_write(self): - self.write = "" - if self.type in self.write_correspondance: - write = self.write_correspondance[self.type] - output = self.output - name = self.name - self.write = """ + def set_write(self): + self.write = "" + if self.type in self.write_correspondance: + write = self.write_correspondance[self.type] + output = self.output + name = self.name + self.write = """ call write_time(%(output)s) call %(write)s(%(output)s, %(name)s, & - '%(name)s')""" % locals() + '%(name)s') + """%locals() - def set_type(self, t): - self.type = t.lower() + def set_type(self,t): + self.type = t.lower() - def set_doc(self, t): - self.doc = t.replace('\n', '\n! ') + def set_doc(self,t): + self.doc = t.replace('\n', '\n! ') - def set_name(self, t): - self.name = t + def set_name(self,t): + self.name = t - def set_ezfio_dir(self, t): - self.ezfio_dir = t.lower() + def set_ezfio_dir(self,t): + self.ezfio_dir = t.lower() - def set_ezfio_name(self, t): - self.ezfio_name = t.lower() + def set_ezfio_name(self,t): + self.ezfio_name = t.lower() - def set_output(self, t): - self.output = t + def set_output(self,t): + self.output = t - def set_default(self, t): - self.default = t + def set_default(self,t): + self.default = t - def get_default(self): - filename = '/'.join([os.environ['QPACKAGE_ROOT'], - 'data', - 'ezfio_defaults']) + def get_default(self): - with open(filename, 'r') as f: - lines = f.readlines() + from os import listdir + from os.path import isfile, join - # Search directory - for k, line in enumerate(lines): - if line[0] != ' ': - if line.strip().lower() == self.ezfio_dir: - break - if k + 1 == len(lines): - return - # Search name - while k < len(lines): - k += 1 - buffer = lines[k].split() - if len(buffer) == 0: - return - if buffer[0].lower() == self.ezfio_name: - break - v = buffer[1] - name = self.name - try: - v_eval = eval(v) - if isinstance(v_eval, bool): - v = '.%s.' % (v) - elif isinstance(v_eval, float): - v = v.replace('e', 'd') - v = v.replace('E', 'D') - v = "%(name)s = %(v)s" % locals() - except: - v = "call ezfio_get_%(v)s(%(name)s)" % locals() - self.default = v + mypath = '/'.join( [os.environ['QPACKAGE_ROOT'], 'data', 'ezfio_defaults','/']) + onlyfiles = [ f for f in listdir(mypath) if isfile(join(mypath,f)) ] + + lines= [] + for filename in onlyfiles: + file = open(mypath+filename,'r') + lines.extend(file.readlines()[:]) + file.close() + + # Search directory + for k,line in enumerate(lines): + if line[0] != ' ': + if line.strip().lower() == self.ezfio_dir: + break + if k+1 == len(lines): + return + # Search name + while k < len(lines): + k+=1 + buffer = lines[k].split() + if len(buffer) == 0: + return + if buffer[0].lower() == self.ezfio_name: + break + v = buffer[1] + name = self.name + try: + v_eval = eval(v) + if type(v_eval) == bool: + v = '.%s.'%(v) + elif type(v_eval) == float: + v = v.replace('e','d') + v = v.replace('E','D') + v = "%(name)s = %(v)s"%locals() + except: + v = "call ezfio_get_%(v)s(%(name)s)"%locals() + self.default = v def test_module(): - T = EZFIO_Provider() - T.set_type("double precision") - T.set_name("thresh_SCF") - T.set_doc("Threshold on the convergence of the Hartree Fock energy") - T.set_ezfio_dir("Hartree_Fock") - T.set_ezfio_name("thresh_SCF") - T.set_output("output_Hartree_Fock") - print T - + T = EZFIO_Provider() + T.set_type ( "double precision" ) + T.set_name ( "thresh_SCF" ) + T.set_doc ( "Threshold on the convergence of the Hartree Fock energy" ) + T.set_ezfio_dir ( "Hartree_Fock" ) + T.set_ezfio_name( "thresh_SCF" ) + T.set_output ( "output_Hartree_Fock" ) + print T + if __name__ == '__main__': - test_module() + test_module() + + From 9d27774df1935322bd52ca1995dd0785d6d4749c Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Thu, 26 Mar 2015 20:26:20 +0100 Subject: [PATCH 15/41] Cleaning of ezfio_generate_provider.py --- scripts/ezfio_generate_provider.py | 80 +++++++----------------------- scripts/ezfio_interface.py | 10 +--- src/Full_CI/EZFIO.cfg | 2 +- 3 files changed, 19 insertions(+), 73 deletions(-) diff --git a/scripts/ezfio_generate_provider.py b/scripts/ezfio_generate_provider.py index 5b2b07e5..d18710d7 100755 --- a/scripts/ezfio_generate_provider.py +++ b/scripts/ezfio_generate_provider.py @@ -8,16 +8,14 @@ Creates the provider of a variable that has to be fetched from the EZFIO file. """ -import sys -import os - class EZFIO_Provider(object): - data = """BEGIN_PROVIDER [ %(type)s, %(name)s ] + data = """ +BEGIN_PROVIDER [ %(type)s, %(name)s ] implicit none BEGIN_DOC -! %(doc)s +! %(doc)s END_DOC logical :: has @@ -26,34 +24,30 @@ class EZFIO_Provider(object): if (has) then call ezfio_get_%(ezfio_dir)s_%(ezfio_name)s(%(name)s) else - %(default)s + print *, '%(ezfio_dir)s/%(ezfio_name)s not found in EZFIO file' + stop 1 endif - %(write)s + +%(write)s END_PROVIDER -""" +""".strip() write_correspondance = {"integer": "write_int", "logical": "write_bool", "double precision": "write_double"} def __init__(self): - self.values = "type doc default name ezfio_dir ezfio_name write output".split() + self.values = "type doc name ezfio_dir ezfio_name write output".split() for v in self.values: - exec "self.%s = None" % (v) in locals() + exec "self.{0} = None".format(v) def __repr__(self): - if not self.default: - self.get_default() self.set_write() for v in self.values: - exec "test = self.%s is None" % (v) in locals() - if test: + if not v: msg = "Error : %s is not set in ezfio_with_default.py" % (v) print >>sys.stderr, msg - for v in self.values: - exec "x = str(self.%s)" % (v) in locals() - print >>sys.stderr, "%s : %s" % (v, x) sys.exit(1) return self.data % self.__dict__ @@ -63,16 +57,17 @@ END_PROVIDER write = self.write_correspondance[self.type] output = self.output name = self.name - self.write = """ - call write_time(%(output)s) - call %(write)s(%(output)s, %(name)s, & - '%(name)s')""" % locals() + + l_write = [" call write_time(%(output)s)", + " call %(write)s(%(output)s, %(name)s, &", + " '%(name)s')"] + self.write = "\n".join(l_write) % locals() def set_type(self, t): self.type = t.lower() def set_doc(self, t): - self.doc = t.replace('\n', '\n! ') + self.doc = t.strip().replace('\n', '\n! ') def set_name(self, t): self.name = t @@ -86,46 +81,6 @@ END_PROVIDER def set_output(self, t): self.output = t - def set_default(self, t): - self.default = t - - def get_default(self): - filename = '/'.join([os.environ['QPACKAGE_ROOT'], - 'data', - 'ezfio_defaults']) - - with open(filename, 'r') as f: - lines = f.readlines() - - # Search directory - for k, line in enumerate(lines): - if line[0] != ' ': - if line.strip().lower() == self.ezfio_dir: - break - if k + 1 == len(lines): - return - # Search name - while k < len(lines): - k += 1 - buffer = lines[k].split() - if len(buffer) == 0: - return - if buffer[0].lower() == self.ezfio_name: - break - v = buffer[1] - name = self.name - try: - v_eval = eval(v) - if isinstance(v_eval, bool): - v = '.%s.' % (v) - elif isinstance(v_eval, float): - v = v.replace('e', 'd') - v = v.replace('E', 'D') - v = "%(name)s = %(v)s" % locals() - except: - v = "call ezfio_get_%(v)s(%(name)s)" % locals() - self.default = v - def test_module(): T = EZFIO_Provider() @@ -137,6 +92,5 @@ def test_module(): T.set_output("output_Hartree_Fock") print T - if __name__ == '__main__': test_module() diff --git a/scripts/ezfio_interface.py b/scripts/ezfio_interface.py index 6f6d654f..b826598f 100755 --- a/scripts/ezfio_interface.py +++ b/scripts/ezfio_interface.py @@ -272,16 +272,8 @@ def create_ezfio_provider(dict_ezfio_cfg): ez_p.set_doc(dict_info['doc']) ez_p.set_ezfio_dir(dict_info['ezfio_dir']) ez_p.set_ezfio_name(dict_info['ezfio_name']) - - str_ = "\n".join([" print *, '{0}/{1} not found in EZFIO file'", - " stop 1"]) - - str_ = str_.format(dict_info['ezfio_dir'], - dict_info['ezfio_name']) - - ez_p.set_default(str_) - ez_p.set_output("output_%s" % dict_info['ezfio_dir']) + dict_code_provider[provider_name] = str(ez_p) return dict_code_provider diff --git a/src/Full_CI/EZFIO.cfg b/src/Full_CI/EZFIO.cfg index febd0530..8146ff81 100644 --- a/src/Full_CI/EZFIO.cfg +++ b/src/Full_CI/EZFIO.cfg @@ -19,7 +19,7 @@ default: true [PT2_max] type: PT2_energy doc: The selection process stops when the largest PT2 (for all the state is lower - than pt2_max in absolute value + than pt2_max in absolute value) interface: output default: 0.0001 From f55e5cf88f0ddd003166636641154bdf488476ad Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Thu, 26 Mar 2015 20:32:59 +0100 Subject: [PATCH 16/41] with the default_file is beter --- .../ezfio_defaults/bi_integrals.ezfio_default | 9 +++ data/ezfio_defaults/cisd.ezfio_default | 4 ++ data/ezfio_defaults/cisd_sc2.ezfio_default | 5 ++ .../ezfio_defaults/determinants.ezfio_default | 9 +++ data/ezfio_defaults/full_ci.ezfio_default | 6 ++ .../ezfio_defaults/hartree_fock.ezfio_default | 4 ++ data/ezfio_defaults/properties.ezfio_default | 2 + data/ezfio_defaults/q_package.ezfio_default | 60 +++++++++++++++++++ 8 files changed, 99 insertions(+) create mode 100644 data/ezfio_defaults/bi_integrals.ezfio_default create mode 100644 data/ezfio_defaults/cisd.ezfio_default create mode 100644 data/ezfio_defaults/cisd_sc2.ezfio_default create mode 100644 data/ezfio_defaults/determinants.ezfio_default create mode 100644 data/ezfio_defaults/full_ci.ezfio_default create mode 100644 data/ezfio_defaults/hartree_fock.ezfio_default create mode 100644 data/ezfio_defaults/properties.ezfio_default create mode 100644 data/ezfio_defaults/q_package.ezfio_default diff --git a/data/ezfio_defaults/bi_integrals.ezfio_default b/data/ezfio_defaults/bi_integrals.ezfio_default new file mode 100644 index 00000000..7cdf7a9b --- /dev/null +++ b/data/ezfio_defaults/bi_integrals.ezfio_default @@ -0,0 +1,9 @@ +bielec_integrals + read_ao_integrals False + read_mo_integrals False + write_ao_integrals False + write_mo_integrals False + threshold_ao 1.e-15 + threshold_mo 1.e-15 + direct False + diff --git a/data/ezfio_defaults/cisd.ezfio_default b/data/ezfio_defaults/cisd.ezfio_default new file mode 100644 index 00000000..95991f8f --- /dev/null +++ b/data/ezfio_defaults/cisd.ezfio_default @@ -0,0 +1,4 @@ +cisd_selected + n_det_max_cisd 10000 + pt2_max 1.e-4 + diff --git a/data/ezfio_defaults/cisd_sc2.ezfio_default b/data/ezfio_defaults/cisd_sc2.ezfio_default new file mode 100644 index 00000000..624ac35d --- /dev/null +++ b/data/ezfio_defaults/cisd_sc2.ezfio_default @@ -0,0 +1,5 @@ +cisd_sc2_selected + n_det_max_cisd_sc2 10000 + pt2_max 1.e-4 + do_pt2_end True + diff --git a/data/ezfio_defaults/determinants.ezfio_default b/data/ezfio_defaults/determinants.ezfio_default new file mode 100644 index 00000000..42f6b384 --- /dev/null +++ b/data/ezfio_defaults/determinants.ezfio_default @@ -0,0 +1,9 @@ +determinants + n_states 1 + n_states_diag determinants_n_states + n_det_max_jacobi 1000 + threshold_generators 0.99 + threshold_selectors 0.999 + read_wf False + s2_eig False + only_single_double_dm False diff --git a/data/ezfio_defaults/full_ci.ezfio_default b/data/ezfio_defaults/full_ci.ezfio_default new file mode 100644 index 00000000..359cc4d2 --- /dev/null +++ b/data/ezfio_defaults/full_ci.ezfio_default @@ -0,0 +1,6 @@ +full_ci + n_det_max_fci 10000 + n_det_max_fci_property 50000 + pt2_max 1.e-4 + do_pt2_end True + var_pt2_ratio 0.75 diff --git a/data/ezfio_defaults/hartree_fock.ezfio_default b/data/ezfio_defaults/hartree_fock.ezfio_default new file mode 100644 index 00000000..048a3c77 --- /dev/null +++ b/data/ezfio_defaults/hartree_fock.ezfio_default @@ -0,0 +1,4 @@ +hartree_fock + n_it_scf_max 200 + thresh_scf 1.e-10 + guess "Huckel" diff --git a/data/ezfio_defaults/properties.ezfio_default b/data/ezfio_defaults/properties.ezfio_default new file mode 100644 index 00000000..ce06d413 --- /dev/null +++ b/data/ezfio_defaults/properties.ezfio_default @@ -0,0 +1,2 @@ +properties + z_one_point 3.9 diff --git a/data/ezfio_defaults/q_package.ezfio_default b/data/ezfio_defaults/q_package.ezfio_default new file mode 100644 index 00000000..5da4d813 --- /dev/null +++ b/data/ezfio_defaults/q_package.ezfio_default @@ -0,0 +1,60 @@ +bielec_integrals + read_ao_integrals False + read_mo_integrals False + write_ao_integrals False + write_mo_integrals False + threshold_ao 1.e-15 + threshold_mo 1.e-15 + direct False + +cis_dressed + n_state_cis 10 + n_core_cis 0 + n_act_cis mo_basis_mo_tot_num + mp2_dressing False + standard_doubles True + en_2_2 False + +determinants + n_states 1 + n_states_diag determinants_n_states + n_det_max_jacobi 1000 + threshold_generators 0.99 + threshold_selectors 0.999 + read_wf False + s2_eig False + only_single_double_dm False + +full_ci + n_det_max_fci 10000 + n_det_max_fci_property 50000 + pt2_max 1.e-4 + do_pt2_end True + var_pt2_ratio 0.75 + +all_singles + n_det_max_fci 50000 + pt2_max 1.e-8 + do_pt2_end False + +cassd + n_det_max_cassd 10000 + pt2_max 1.e-4 + do_pt2_end True + +hartree_fock + n_it_scf_max 200 + thresh_scf 1.e-10 + guess "Huckel" + +cisd_selected + n_det_max_cisd 10000 + pt2_max 1.e-4 + +cisd_sc2_selected + n_det_max_cisd_sc2 10000 + pt2_max 1.e-4 + do_pt2_end True + +properties + z_one_point 3.9 From e620921ba0caf8129bccdd43cdb785670d15ac24 Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Thu, 26 Mar 2015 20:34:02 +0100 Subject: [PATCH 17/41] Add *.mod and *.p in gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index cdcdc6d8..2a924323 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ bin/ quantum_package_static.tar.gz resultsFile opam_installer.sh +*.mod +*.p \ No newline at end of file From b2f3e32e3cd98b2090756d4bd398e42a405b2e0e Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Thu, 26 Mar 2015 20:45:25 +0100 Subject: [PATCH 18/41] Behing AGILE : Remove a non using opt --- scripts/ezfio_interface.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/ezfio_interface.py b/scripts/ezfio_interface.py index b826598f..9233a6c5 100755 --- a/scripts/ezfio_interface.py +++ b/scripts/ezfio_interface.py @@ -310,7 +310,7 @@ def save_ezfio_provider(path_head, dict_code_provider): f.write(output) -def create_ezfio_config(dict_ezfio_cfg, opt, module_lower): +def create_ezfio_config(dict_ezfio_cfg, module_lower): """ From dict_ezfio_cfg[provider_name] = {type, default, ezfio_name,ezfio_dir,doc} Return the string ezfio_interface_config @@ -405,6 +405,10 @@ def save_ezfio_config(module_lower, str_ezfio_config): f.write(str_ezfio_config) +def create_ocaml_check(dict_code_provider): + pass + + def main(): """ Two condition: @@ -442,10 +446,8 @@ def main(): save_ezfio_provider(path_dirname, d_config) # print "Generating the ezfio_config" - config_ezfio = create_ezfio_config( - dict_info_provider, - "config", - module_lower) + config_ezfio = create_ezfio_config(dict_info_provider, + module_lower) # print "Saving ezfio_config" save_ezfio_config(module_lower, config_ezfio) From 55580d8eb6d1e983cf8e243eeb2c5b9e30a7470f Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Thu, 26 Mar 2015 21:08:55 +0100 Subject: [PATCH 19/41] Doc in ezfio_interace.py --- scripts/ezfio_interface.py | 63 ++++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 16 deletions(-) diff --git a/scripts/ezfio_interface.py b/scripts/ezfio_interface.py index 9233a6c5..94e7ae47 100755 --- a/scripts/ezfio_interface.py +++ b/scripts/ezfio_interface.py @@ -6,6 +6,8 @@ Check if EZFIO.cfg exists. EZFIO.cfg are in MODULE directories. create : ezfio_interface.irp.f folder_ezfio_inteface_config +Ezfio_dir : is equal to MODULE.lower! + Format specification : [provider_name] : the name of the provider in irp.f90 @@ -310,7 +312,7 @@ def save_ezfio_provider(path_head, dict_code_provider): f.write(output) -def create_ezfio_config(dict_ezfio_cfg, module_lower): +def create_ezfio_config(dict_ezfio_cfg): """ From dict_ezfio_cfg[provider_name] = {type, default, ezfio_name,ezfio_dir,doc} Return the string ezfio_interface_config @@ -353,7 +355,14 @@ def create_ezfio_config(dict_ezfio_cfg, module_lower): # C r e a t e _ t h e _ s t r i n g # # ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~# # - result = [module_lower] + # Checking is many ezfio_dir provided + l_ezfio_dir = [d['ezfio_dir'] for d in dict_ezfio_cfg.values()] + + if not l_ezfio_dir.count(l_ezfio_dir[0]) == len(l_ezfio_dir): + print >> sys.stderr, "You have many ezfio_dir. Not supported yet" + raise TypeError + else: + result = [l_ezfio_dir[0]] for provider_name, provider_info in sorted(dict_ezfio_cfg.iteritems()): @@ -388,8 +397,8 @@ def save_ezfio_config(module_lower, str_ezfio_config): $QPACKAGE_ROOT/EZFIO/{0}.ezfio_interface_config".format(module_lower) """ - ezfio_dir = "{0}/EZFIO".format(os.environ['QPACKAGE_ROOT']) - path = "{0}/config/{1}.ezfio_interface_config".format(ezfio_dir, + root_ezfio = "{0}/EZFIO".format(os.environ['QPACKAGE_ROOT']) + path = "{0}/config/{1}.ezfio_interface_config".format(root_ezfio, module_lower) try: @@ -407,6 +416,19 @@ def save_ezfio_config(module_lower, str_ezfio_config): def create_ocaml_check(dict_code_provider): pass +# def create_creade(): +# +#""" +# let read_{ezfio_name} () = +# if not (Ezfio.has_{ezfio_dir}_{ezfio_name} ()) then +# get_default "{ezfio_name}" +# |> Float.of_string +# |> Ezfio.set_{ezfio_dir}_{ezfio_name} +# ; +# Ezfio.get_{ezfio_dir}_{ezfio_name} () +# |> Normalized_float.of_float +# ;; +#""" def main(): @@ -420,6 +442,10 @@ def main(): - folder_ezfio_inteface_config """ + # ~#~#~#~# # + # I n i t # + # ~#~#~#~# # + try: config_file_path = sys.argv[1] except: @@ -430,27 +456,32 @@ def main(): config_file_path = os.path.expanduser(config_file_path) config_file_path = os.path.expandvars(config_file_path) config_file_path = os.path.abspath(config_file_path) - # print config_file_path + + # ~#~#~#~#~#~#~#~#~#~#~#~#~#~# # + # G e t _ m o d u l e _ d i r # + # ~#~#~#~#~#~#~#~#~#~#~#~#~#~# # path_dirname = os.path.dirname(config_file_path) module = [i for i in path_dirname.split("/") if i][-1] module_lower = module.lower() - # print "Read {0}".format(config_file_path) - dict_info_provider = get_dict_config_file(config_file_path, module_lower) + # Because we only authorise this right now! + ezfio_dir = module_lower + dict_info_provider = get_dict_config_file(config_file_path, ezfio_dir) - # print "Generating the ezfio_interface.irp.f: \n" - d_config = create_ezfio_provider(dict_info_provider) + # ~#~#~#~#~#~#~#~# # + # I R P . f 9 0 # + # ~#~#~#~#~#~#~#~# # - # print "Saving the ezfio_interface.irp.f" - save_ezfio_provider(path_dirname, d_config) + l_str_code = create_ezfio_provider(dict_info_provider) + save_ezfio_provider(path_dirname, l_str_code) - # print "Generating the ezfio_config" - config_ezfio = create_ezfio_config(dict_info_provider, - module_lower) + # ~#~#~#~#~#~#~#~#~#~#~#~# # + # e z f i o _ c o n f i g # + # ~#~#~#~#~#~#~#~#~#~#~#~# # - # print "Saving ezfio_config" - save_ezfio_config(module_lower, config_ezfio) + str_ezfio_config = create_ezfio_config(dict_info_provider) + save_ezfio_config(module_lower, str_ezfio_config) if __name__ == "__main__": From 04514b5b4f5313c2535e43e202fb33b255ebb220 Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Thu, 26 Mar 2015 22:07:44 +0100 Subject: [PATCH 20/41] First try for read snipet --- scripts/ezfio_interface.py | 109 +++++++++++++++++++++++++------------ 1 file changed, 73 insertions(+), 36 deletions(-) diff --git a/scripts/ezfio_interface.py b/scripts/ezfio_interface.py index 94e7ae47..11e5a7cd 100755 --- a/scripts/ezfio_interface.py +++ b/scripts/ezfio_interface.py @@ -49,7 +49,7 @@ import ConfigParser from collections import defaultdict from collections import namedtuple -Type = namedtuple('Type', 'ocaml fortran') +Type = namedtuple('Type', 'fancy ocaml fortran') def is_bool(str_): @@ -58,9 +58,9 @@ def is_bool(str_): fortran and ocaml one. """ if str_.lower() in ['true', '.true.']: - return Type("true", ".True.") + return Type(None, "true", ".True.") elif str_.lower() in ['false', '.False.']: - return Type("false", ".False") + return Type(None, "false", ".False") else: raise TypeError @@ -99,18 +99,18 @@ def get_type_dict(): # R a w _ t y p e # # ~#~#~#~#~#~#~#~ # - fancy_type['integer'] = Type("int", "integer") - fancy_type['int'] = Type("int", "integer") + fancy_type['integer'] = Type(None, "int", "integer") + fancy_type['int'] = Type(None, "int", "integer") - fancy_type['float'] = Type("float", "double precision") - fancy_type['double precision'] = Type("float", "double precision") + fancy_type['float'] = Type(None, "float", "double precision") + fancy_type['double precision'] = Type(None, "float", "double precision") - fancy_type['logical'] = Type("bool", "logical") - fancy_type['bool'] = Type("bool", "logical") + fancy_type['logical'] = Type(None, "bool", "logical") + fancy_type['bool'] = Type(None, "bool", "logical") - fancy_type['character*32'] = Type("string", "character*32") - fancy_type['character*60'] = Type("string", "character*60") - fancy_type['character*256'] = Type("string", "character*256") + fancy_type['character*32'] = Type(None, "string", "character*32") + fancy_type['character*60'] = Type(None, "string", "character*60") + fancy_type['character*256'] = Type(None, "string", "character*256") # ~#~#~#~#~#~#~#~ # # q p _ t y p e s # @@ -133,7 +133,9 @@ def get_type_dict(): str_ocaml_type = i.split()[3] str_fortran_type = ocaml_to_fortran[str_ocaml_type] - fancy_type[str_fancy_type] = Type(str_ocaml_type, str_fortran_type) + fancy_type[str_fancy_type] = Type(str_fancy_type, + str_ocaml_type, + str_fortran_type) # ~#~#~#~#~#~#~#~ # # F i n a l i z e # @@ -245,7 +247,7 @@ def get_dict_config_file(config_file_path, module_lower): try: d[pvd]["default"] = is_bool(default_raw) except TypeError: - d[pvd]["default"] = Type(default_raw, default_raw) + d[pvd]["default"] = Type(None, default_raw, default_raw) return dict(d) @@ -288,8 +290,6 @@ def save_ezfio_provider(path_head, dict_code_provider): path = "{0}/ezfio_interface.irp.f".format(path_head) - # print "Path = {0}".format(path) - try: f = open(path, "r") except IOError: @@ -414,21 +414,52 @@ def save_ezfio_config(module_lower, str_ezfio_config): f.write(str_ezfio_config) -def create_ocaml_check(dict_code_provider): - pass -# def create_creade(): -# -#""" -# let read_{ezfio_name} () = -# if not (Ezfio.has_{ezfio_dir}_{ezfio_name} ()) then -# get_default "{ezfio_name}" -# |> Float.of_string -# |> Ezfio.set_{ezfio_dir}_{ezfio_name} -# ; -# Ezfio.get_{ezfio_dir}_{ezfio_name} () -# |> Normalized_float.of_float -# ;; -#""" +def create_ocaml_check(dict_ezfio_cfg): + + # ~#~#~#~#~#~#~#~# # + # F u n c t i o n # + # ~#~#~#~#~#~#~#~# # + + def create_read(d_format): + + template = """ + (* Read snippet for {ezfio_name} *) + let read_{ezfio_name} () = + if not (Ezfio.has_{ezfio_dir}_{ezfio_name} ()) then + get_default "{ezfio_name}" + |> {Ocaml_type}.of_string + |> Ezfio.set_{ezfio_dir}_{ezfio_name} + ; + Ezfio.get_{ezfio_dir}_{ezfio_name} () +""" + fancy_type = d_format["type"] + if d_format["type"].fancy: + template += " |> {0}.of_{1}".format(fancy_type.fancy, + fancy_type.ocaml) + + template += """ + ;; + """ + return template.strip().format(**d_format) + + # ~#~#~#~#~#~#~#~# # + # C r e a t i o n # + # ~#~#~#~#~#~#~#~# # + + for provider_name, d_val in sorted(dict_ezfio_cfg.iteritems()): + + ocaml_type = d_val["type"].ocaml.capitalize() + ezfio_dir = d_val["ezfio_dir"] + ezfio_name = d_val["ezfio_name"] + + d = {"ezfio_dir": ezfio_dir, + "ezfio_name": ezfio_name, + "type": d_val["type"], + "Ocaml_type": ocaml_type} + + template = create_read(d) + + print template def main(): @@ -467,20 +498,26 @@ def main(): # Because we only authorise this right now! ezfio_dir = module_lower - dict_info_provider = get_dict_config_file(config_file_path, ezfio_dir) + dict_ezfio_cfg = get_dict_config_file(config_file_path, ezfio_dir) - # ~#~#~#~#~#~#~#~# # + # ~#~#~#~#~#~# + # O c a m l # + # ~#~#~#~#~#~# + + _ = create_ocaml_check(dict_ezfio_cfg) + + # ~#~#~#~#~#~#~#~# # I R P . f 9 0 # - # ~#~#~#~#~#~#~#~# # + # ~#~#~#~#~#~#~#~# - l_str_code = create_ezfio_provider(dict_info_provider) + l_str_code = create_ezfio_provider(dict_ezfio_cfg) save_ezfio_provider(path_dirname, l_str_code) # ~#~#~#~#~#~#~#~#~#~#~#~# # # e z f i o _ c o n f i g # # ~#~#~#~#~#~#~#~#~#~#~#~# # - str_ezfio_config = create_ezfio_config(dict_info_provider) + str_ezfio_config = create_ezfio_config(dict_ezfio_cfg) save_ezfio_config(module_lower, str_ezfio_config) From 7db2751cdb2272de34d24c84abe6417795fb2828 Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Fri, 27 Mar 2015 10:44:39 +0100 Subject: [PATCH 21/41] Add directory for ezfio_interface, first apparition of ezfio_generate_ocaml --- .../ei_handler.py} | 37 +++--------- .../ezfio_interface/ezfio_generate_ocaml.py | 59 +++++++++++++++++++ .../ezfio_generate_provider.py | 2 +- scripts/prepare_ezfio.sh | 2 +- scripts/run_Makefile_common.sh | 3 +- setup_environment.sh | 4 +- 6 files changed, 71 insertions(+), 36 deletions(-) rename scripts/{ezfio_interface.py => ezfio_interface/ei_handler.py} (94%) create mode 100755 scripts/ezfio_interface/ezfio_generate_ocaml.py rename scripts/{ => ezfio_interface}/ezfio_generate_provider.py (97%) diff --git a/scripts/ezfio_interface.py b/scripts/ezfio_interface/ei_handler.py similarity index 94% rename from scripts/ezfio_interface.py rename to scripts/ezfio_interface/ei_handler.py index 11e5a7cd..0852eb79 100755 --- a/scripts/ezfio_interface.py +++ b/scripts/ezfio_interface/ei_handler.py @@ -83,7 +83,7 @@ def get_type_dict(): qpackage_root = os.environ['QPACKAGE_ROOT'] - fancy_type_pickle = qpackage_root + "/scripts/fancy_type.p" + fancy_type_pickle = qpackage_root + "/scripts/ezfio_interface/fancy_type.p" if fancy_type_pickle in listdir(os.getcwd()): fancy_type = pickle.load(open(fancy_type_pickle, "rb")) @@ -416,36 +416,14 @@ def save_ezfio_config(module_lower, str_ezfio_config): def create_ocaml_check(dict_ezfio_cfg): - # ~#~#~#~#~#~#~#~# # - # F u n c t i o n # - # ~#~#~#~#~#~#~#~# # - - def create_read(d_format): - - template = """ - (* Read snippet for {ezfio_name} *) - let read_{ezfio_name} () = - if not (Ezfio.has_{ezfio_dir}_{ezfio_name} ()) then - get_default "{ezfio_name}" - |> {Ocaml_type}.of_string - |> Ezfio.set_{ezfio_dir}_{ezfio_name} - ; - Ezfio.get_{ezfio_dir}_{ezfio_name} () -""" - fancy_type = d_format["type"] - if d_format["type"].fancy: - template += " |> {0}.of_{1}".format(fancy_type.fancy, - fancy_type.ocaml) - - template += """ - ;; - """ - return template.strip().format(**d_format) - # ~#~#~#~#~#~#~#~# # # C r e a t i o n # # ~#~#~#~#~#~#~#~# # + from ezfio_generate_ocaml import EZFIO_ocaml + + e = EZFIO_ocaml() + for provider_name, d_val in sorted(dict_ezfio_cfg.iteritems()): ocaml_type = d_val["type"].ocaml.capitalize() @@ -454,10 +432,9 @@ def create_ocaml_check(dict_ezfio_cfg): d = {"ezfio_dir": ezfio_dir, "ezfio_name": ezfio_name, - "type": d_val["type"], - "Ocaml_type": ocaml_type} + "type": d_val["type"]} - template = create_read(d) + template = e.create_read(**d) print template diff --git a/scripts/ezfio_interface/ezfio_generate_ocaml.py b/scripts/ezfio_interface/ezfio_generate_ocaml.py new file mode 100755 index 00000000..07eaee6e --- /dev/null +++ b/scripts/ezfio_interface/ezfio_generate_ocaml.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python + +import sys + + +class EZFIO_ocaml(object): + + def __init__(self): + pass + + def create_read(self, **param): + ''' + Take an imput a list of keyword argument + ezfio_dir = str + ezfio_name = str + type = Named_tuple(fancy_type, ocaml_type, fortrant_type) + + Return the read template + ''' + + l_name_need = "ezfio_dir ezfio_name type".split() + + for key in l_name_need: + if key not in param: + print "You need to provide {0} at keyword argument".format(key) + sys.exit(1) + + # ~#~#~#~#~#~#~#~#~#~#~#~#~#~# # + # C r e a t e _ t e m pl a t e # + # ~#~#~#~#~#~#~#~#~#~#~#~#~#~# # + + l_template = ['(* Read snippet for {ezfio_name} *)', + 'let read_{ezfio_name} () =', + ' if not (Ezfio.has_{ezfio_dir}_{ezfio_name} ()) then', + ' get_default "{ezfio_name}"', + ' |> {Ocaml_type}.of_string', + ' |> Ezfio.set_{ezfio_dir}_{ezfio_name}', + ' ;', + ' Ezfio.get_{ezfio_dir}_{ezfio_name} ()'] + + if param["type"].fancy: + l_template += [" |> {fancy_type}.of_{Ocaml_type}"] + + l_template += [";;;"] + + template = "\n ".join(l_template) + + # ~#~#~#~#~#~ # + # R e n d e r # + # ~#~#~#~#~#~ # + + param["Ocaml_type"] = param["type"].ocaml.capitalize() + param["fancy_type"] = param["type"].fancy + template_rendered = template.format(**param) + + # ~#~#~#~#~#~ # + # R e t u r n # + # ~#~#~#~#~#~ # + return template_rendered diff --git a/scripts/ezfio_generate_provider.py b/scripts/ezfio_interface/ezfio_generate_provider.py similarity index 97% rename from scripts/ezfio_generate_provider.py rename to scripts/ezfio_interface/ezfio_generate_provider.py index d18710d7..21dc8450 100755 --- a/scripts/ezfio_generate_provider.py +++ b/scripts/ezfio_interface/ezfio_generate_provider.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -__author__ = "Anthony Scemama and Applencourt for the amazing PEP8" +__author__ = "Applencourt PEP8" __date__ = "jeudi 26 mars 2015, 12:49:35 (UTC+0100)" """ diff --git a/scripts/prepare_ezfio.sh b/scripts/prepare_ezfio.sh index c01bacd3..96ba3cdc 100755 --- a/scripts/prepare_ezfio.sh +++ b/scripts/prepare_ezfio.sh @@ -9,7 +9,7 @@ echo "=-=-=-=-=-=-=-=-=-=-=-" for dir in ${QPACKAGE_ROOT}/src/*/ do cd $dir || exit -1 - ${QPACKAGE_ROOT}/scripts/ezfio_interface.py + ${QPACKAGE_ROOT}/scripts/ezfio_interface/ei_handler.py done # For old-style directories. Will be removed some day... diff --git a/scripts/run_Makefile_common.sh b/scripts/run_Makefile_common.sh index 0a579a94..82e898ac 100755 --- a/scripts/run_Makefile_common.sh +++ b/scripts/run_Makefile_common.sh @@ -65,5 +65,4 @@ fi ${QPACKAGE_ROOT}/scripts/create_Makefile_depend.sh # Update EZFIO interface -${QPACKAGE_ROOT}/scripts/ezfio_interface.py - + ${QPACKAGE_ROOT}/scripts/ezfio_interface/ei_handler.py diff --git a/setup_environment.sh b/setup_environment.sh index ca853fdf..8db6a11c 100755 --- a/setup_environment.sh +++ b/setup_environment.sh @@ -34,8 +34,8 @@ export QPACKAGE_ROOT=\$( cd \$(dirname "\${BASH_SOURCE}") ; pwd -P ) export LD_LIBRARY_PATH="\${QPACKAGE_ROOT}"/lib:\${LD_LIBRARY_PATH} export LIBRARY_PATH="\${QPACKAGE_ROOT}"/lib:\${LIBRARY_PATH} export C_INCLUDE_PATH="\${QPACKAGE_ROOT}"/include:\${C_INCLUDE_PATH} -export PYTHONPATH=\${PYTHONPATH}:"\${QPACKAGE_ROOT}"/scripts -export PATH=\${PATH}:"\${QPACKAGE_ROOT}"/scripts +export PYTHONPATH=\${PYTHONPATH}:"\${QPACKAGE_ROOT}"/scripts:"\${QPACKAGE_ROOT}"/scripts/ezfio_interface +export PATH=\${PATH}:"\${QPACKAGE_ROOT}"/scripts:"\${QPACKAGE_ROOT}"/scripts/ezfio_interface export PATH=\${PATH}:"\${QPACKAGE_ROOT}"/bin export PATH=\${PATH}:"\${QPACKAGE_ROOT}"/ocaml source "\${QPACKAGE_ROOT}"/bin/irpman &> /dev/null From 5845768b31ee952bc6c382dd6e0981851bf20692 Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Fri, 27 Mar 2015 11:15:55 +0100 Subject: [PATCH 22/41] Cleaning ezfio_generate_ocaml --- scripts/ezfio_interface/ei_handler.py | 7 +-- .../ezfio_interface/ezfio_generate_ocaml.py | 56 ++++++++++++------- 2 files changed, 38 insertions(+), 25 deletions(-) diff --git a/scripts/ezfio_interface/ei_handler.py b/scripts/ezfio_interface/ei_handler.py index 0852eb79..7b631721 100755 --- a/scripts/ezfio_interface/ei_handler.py +++ b/scripts/ezfio_interface/ei_handler.py @@ -422,11 +422,8 @@ def create_ocaml_check(dict_ezfio_cfg): from ezfio_generate_ocaml import EZFIO_ocaml - e = EZFIO_ocaml() - for provider_name, d_val in sorted(dict_ezfio_cfg.iteritems()): - ocaml_type = d_val["type"].ocaml.capitalize() ezfio_dir = d_val["ezfio_dir"] ezfio_name = d_val["ezfio_name"] @@ -434,7 +431,9 @@ def create_ocaml_check(dict_ezfio_cfg): "ezfio_name": ezfio_name, "type": d_val["type"]} - template = e.create_read(**d) + e = EZFIO_ocaml(**d) + + template = e.create_read() print template diff --git a/scripts/ezfio_interface/ezfio_generate_ocaml.py b/scripts/ezfio_interface/ezfio_generate_ocaml.py index 07eaee6e..bbed9685 100755 --- a/scripts/ezfio_interface/ezfio_generate_ocaml.py +++ b/scripts/ezfio_interface/ezfio_generate_ocaml.py @@ -5,10 +5,23 @@ import sys class EZFIO_ocaml(object): - def __init__(self): - pass + def __init__(self, **kwargs): - def create_read(self, **param): + for k, v in kwargs.iteritems(): + if k == "type": + self.type = kwargs["type"] + else: + exec "self.{0} = '{1}'".format(k, v) + + @property + def Ocaml_type(self): + return self.type.ocaml.capitalize() + + @property + def fancy_type(self): + return self.type.fancy + + def create_read(self): ''' Take an imput a list of keyword argument ezfio_dir = str @@ -18,28 +31,28 @@ class EZFIO_ocaml(object): Return the read template ''' - l_name_need = "ezfio_dir ezfio_name type".split() - - for key in l_name_need: - if key not in param: - print "You need to provide {0} at keyword argument".format(key) - sys.exit(1) + for i in ["ezfio_dir", "ezfio_name", "type"]: + try: + "exec self.{0}".format(i) + except NameError: + msg = "You need to provide a '{0}' for creating read function" + raise KeyError(msg.format(i)) # ~#~#~#~#~#~#~#~#~#~#~#~#~#~# # # C r e a t e _ t e m pl a t e # # ~#~#~#~#~#~#~#~#~#~#~#~#~#~# # - l_template = ['(* Read snippet for {ezfio_name} *)', - 'let read_{ezfio_name} () =', - ' if not (Ezfio.has_{ezfio_dir}_{ezfio_name} ()) then', - ' get_default "{ezfio_name}"', - ' |> {Ocaml_type}.of_string', - ' |> Ezfio.set_{ezfio_dir}_{ezfio_name}', + l_template = ['(* Read snippet for {self.ezfio_name} *)', + 'let read_{self.ezfio_name} () =', + ' if not (Ezfio.has_{self.ezfio_dir}_{self.ezfio_name} ()) then', + ' get_default "{self.ezfio_name}"', + ' |> {self.Ocaml_type}.of_string', + ' |> Ezfio.set_{self.ezfio_dir}_{self.ezfio_name}', ' ;', - ' Ezfio.get_{ezfio_dir}_{ezfio_name} ()'] + ' Ezfio.get_{self.ezfio_dir}_{self.ezfio_name} ()'] - if param["type"].fancy: - l_template += [" |> {fancy_type}.of_{Ocaml_type}"] + if self.fancy_type: + l_template += [" |> {self.fancy_type}.of_{self.Ocaml_type}"] l_template += [";;;"] @@ -49,11 +62,12 @@ class EZFIO_ocaml(object): # R e n d e r # # ~#~#~#~#~#~ # - param["Ocaml_type"] = param["type"].ocaml.capitalize() - param["fancy_type"] = param["type"].fancy - template_rendered = template.format(**param) + template_rendered = template.format(**locals()) # ~#~#~#~#~#~ # # R e t u r n # # ~#~#~#~#~#~ # return template_rendered + + def create_write(self): + pass From fe93782666ab6595563ff507aec3e1855f695962 Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Fri, 27 Mar 2015 16:12:47 +0100 Subject: [PATCH 23/41] ei_handler write Input_full_ci.ml --- ocaml/Input_full_ci.ml | 153 --------------- scripts/ezfio_interface/ei_handler.py | 85 +++++++- .../ezfio_interface/ezfio_generate_ocaml.py | 183 ++++++++++++++++-- src/Full_CI/EZFIO.cfg | 4 +- 4 files changed, 254 insertions(+), 171 deletions(-) delete mode 100644 ocaml/Input_full_ci.ml diff --git a/ocaml/Input_full_ci.ml b/ocaml/Input_full_ci.ml deleted file mode 100644 index f963ee7e..00000000 --- a/ocaml/Input_full_ci.ml +++ /dev/null @@ -1,153 +0,0 @@ -open Qptypes;; -open Qputils;; -open Core.Std;; - -module Full_ci : sig - type t = - { n_det_max_fci : Det_number_max.t; - pt2_max : PT2_energy.t; - do_pt2_end : bool; - var_pt2_ratio : Normalized_float.t; - } with sexp - ;; - val read : unit -> t option - val write : t-> unit - val to_string : t -> string - val to_rst : t -> Rst_string.t - val of_rst : Rst_string.t -> t option -end = struct - type t = - { n_det_max_fci : Det_number_max.t; - pt2_max : PT2_energy.t; - do_pt2_end : bool; - var_pt2_ratio : Normalized_float.t; - } with sexp - ;; - - let get_default = Qpackage.get_ezfio_default "full_ci";; - - let read_n_det_max_fci () = - if not (Ezfio.has_full_ci_n_det_max_fci ()) then - get_default "n_det_max_fci" - |> Int.of_string - |> Ezfio.set_full_ci_n_det_max_fci - ; - Ezfio.get_full_ci_n_det_max_fci () - |> Det_number_max.of_int - ;; - - let write_n_det_max_fci ndet = - Det_number_max.to_int ndet - |> Ezfio.set_full_ci_n_det_max_fci - ;; - - let read_var_pt2_ratio () = - if not (Ezfio.has_full_ci_var_pt2_ratio ()) then - get_default "var_pt2_ratio" - |> Float.of_string - |> Ezfio.set_full_ci_var_pt2_ratio - ; - Ezfio.get_full_ci_var_pt2_ratio () - |> Normalized_float.of_float - ;; - - let write_var_pt2_ratio ratio = - Normalized_float.to_float ratio - |> Ezfio.set_full_ci_var_pt2_ratio - ;; - - let read_pt2_max () = - if not (Ezfio.has_full_ci_pt2_max ()) then - get_default "pt2_max" - |> Float.of_string - |> Ezfio.set_full_ci_pt2_max - ; - Ezfio.get_full_ci_pt2_max () - |> PT2_energy.of_float - ;; - - let write_pt2_max pt2_max = - PT2_energy.to_float pt2_max - |> Ezfio.set_full_ci_pt2_max - ;; - - let read_do_pt2_end () = - if not (Ezfio.has_full_ci_do_pt2_end ()) then - get_default "do_pt2_end" - |> Bool.of_string - |> Ezfio.set_full_ci_do_pt2_end - ; - Ezfio.get_full_ci_do_pt2_end () - ;; - - let write_do_pt2_end = - Ezfio.set_full_ci_do_pt2_end - ;; - - - let read () = - Some - { n_det_max_fci = read_n_det_max_fci (); - pt2_max = read_pt2_max (); - do_pt2_end = read_do_pt2_end (); - var_pt2_ratio = read_var_pt2_ratio (); - } - ;; - - - let write { n_det_max_fci ; - pt2_max ; - do_pt2_end ; - var_pt2_ratio ; - } = - write_n_det_max_fci n_det_max_fci; - write_pt2_max pt2_max; - write_do_pt2_end do_pt2_end; - write_var_pt2_ratio var_pt2_ratio; - ;; - - let to_string b = - Printf.sprintf " -n_det_max_fci = %s -pt2_max = %s -do_pt2_end = %s -var_pt2_ratio = %s -" - (Det_number_max.to_string b.n_det_max_fci) - (PT2_energy.to_string b.pt2_max) - (Bool.to_string b.do_pt2_end) - (Normalized_float.to_string b.var_pt2_ratio) - ;; - - let to_rst b = - Printf.sprintf " -Stop when the `n_det` > `n_det_max_fci` :: - - n_det_max_fci = %s - -Stop when -E(PT2) < `pt2_max` :: - - pt2_max = %s - -Compute E(PT2) at the end :: - - do_pt2_end = %s - -Target energy ratio variational/(variational+PT2) :: - - var_pt2_ratio = %s -" - (Det_number_max.to_string b.n_det_max_fci) - (PT2_energy.to_string b.pt2_max) - (Bool.to_string b.do_pt2_end) - (Normalized_float.to_string b.var_pt2_ratio) - |> Rst_string.of_string - ;; - - include Generic_input_of_rst;; - let of_rst = of_rst t_of_sexp;; - - -end - - diff --git a/scripts/ezfio_interface/ei_handler.py b/scripts/ezfio_interface/ei_handler.py index 7b631721..3396e6db 100755 --- a/scripts/ezfio_interface/ei_handler.py +++ b/scripts/ezfio_interface/ei_handler.py @@ -414,7 +414,11 @@ def save_ezfio_config(module_lower, str_ezfio_config): f.write(str_ezfio_config) -def create_ocaml_check(dict_ezfio_cfg): +def create_ocaml_input(dict_ezfio_cfg): + + l_provider = [k for k, v in dict_ezfio_cfg.iteritems() if 'default' in v] + l_type = [v["type"] for k, v in dict_ezfio_cfg.iteritems() if 'default' in v] + l_doc = [v["doc"] for k, v in dict_ezfio_cfg.iteritems() if 'default' in v] # ~#~#~#~#~#~#~#~# # # C r e a t i o n # @@ -422,8 +426,42 @@ def create_ocaml_check(dict_ezfio_cfg): from ezfio_generate_ocaml import EZFIO_ocaml + template = ['(* =~=~ *)', + '(* Init *)', + '(* =~=~ *)', + ""] + + template += ["open Qptypes;;", + "open Qputils;;", + "open Core.Std;;", + "", + "module Full_ci : sig"] + + template += [EZFIO_ocaml.create_type(l_provider, l_type)] + + template += [" val read : unit -> t option", + " val write : t-> unit", + " val to_string : t -> string", + " val to_rst : t -> Rst_string.t", + " val of_rst : Rst_string.t -> t option", + "end = struct"] + + template += [EZFIO_ocaml.create_type(l_provider, l_type)] + + template += ['', + ' let get_default = Qpackage.get_ezfio_default "full_ci";;', + ''] + + template += ['(* =~=~=~=~=~=~==~=~=~=~=~=~ *)', + '(* Generate Special Function *)', + '(* =~=~=~==~=~~=~=~=~=~=~=~=~ *)', + ""] + for provider_name, d_val in sorted(dict_ezfio_cfg.iteritems()): + if 'default' not in d_val: + continue + ezfio_dir = d_val["ezfio_dir"] ezfio_name = d_val["ezfio_name"] @@ -433,10 +471,48 @@ def create_ocaml_check(dict_ezfio_cfg): e = EZFIO_ocaml(**d) - template = e.create_read() + template += [e.create_read(), + e.create_write(), + ""] - print template + template += ['(* =~=~=~=~=~=~=~=~=~=~=~=~ *)', + '(* Generate Global Function *)', + '(* =~=~=~=~=~=~=~=~=~=~=~=~ *)', + ""] + template += [EZFIO_ocaml.create_read_global(l_provider), + EZFIO_ocaml.create_write_global(l_provider), + EZFIO_ocaml.create_to_string(l_provider, l_type), + EZFIO_ocaml.create_to_rst(l_provider, l_type, l_doc)] + + template += [" include Generic_input_of_rst;;", + " let of_rst = of_rst t_of_sexp;;", + "", + "end"] + + return "\n".join(template) + + +def save_ocaml_input(module_lower, str_ocaml_input): + """ + Write the str_ocaml_input in + $QPACKAGE_ROOT/ocaml/Input_{0}.ml".format(module_lower) + """ + + path = "{0}/ocaml/Input_{1}.ml".format(os.environ['QPACKAGE_ROOT'], + module_lower) + + try: + f = open(path, "r") + except IOError: + old_output = "" + else: + old_output = f.read() + f.close() + + if str_ocaml_input != old_output: + with open(path, "w") as f: + f.write(str_ocaml_input) def main(): """ @@ -480,7 +556,8 @@ def main(): # O c a m l # # ~#~#~#~#~#~# - _ = create_ocaml_check(dict_ezfio_cfg) + str_ocaml_input = create_ocaml_input(dict_ezfio_cfg) + save_ocaml_input(module_lower, str_ocaml_input) # ~#~#~#~#~#~#~#~# # I R P . f 9 0 # diff --git a/scripts/ezfio_interface/ezfio_generate_ocaml.py b/scripts/ezfio_interface/ezfio_generate_ocaml.py index bbed9685..fc71ddbe 100755 --- a/scripts/ezfio_interface/ezfio_generate_ocaml.py +++ b/scripts/ezfio_interface/ezfio_generate_ocaml.py @@ -17,13 +17,17 @@ class EZFIO_ocaml(object): def Ocaml_type(self): return self.type.ocaml.capitalize() + @property + def ocaml_type(self): + return self.type.ocaml + @property def fancy_type(self): return self.type.fancy def create_read(self): ''' - Take an imput a list of keyword argument + You need to instantiate the EZFIO_ocaml with this keyword argument ezfio_dir = str ezfio_name = str type = Named_tuple(fancy_type, ocaml_type, fortrant_type) @@ -42,19 +46,20 @@ class EZFIO_ocaml(object): # C r e a t e _ t e m pl a t e # # ~#~#~#~#~#~#~#~#~#~#~#~#~#~# # - l_template = ['(* Read snippet for {self.ezfio_name} *)', - 'let read_{self.ezfio_name} () =', - ' if not (Ezfio.has_{self.ezfio_dir}_{self.ezfio_name} ()) then', - ' get_default "{self.ezfio_name}"', - ' |> {self.Ocaml_type}.of_string', - ' |> Ezfio.set_{self.ezfio_dir}_{self.ezfio_name}', - ' ;', - ' Ezfio.get_{self.ezfio_dir}_{self.ezfio_name} ()'] + l_template = [ + '(* Read snippet for {self.ezfio_name} *)', + 'let read_{self.ezfio_name} () =', + ' if not (Ezfio.has_{self.ezfio_dir}_{self.ezfio_name} ()) then', + ' get_default "{self.ezfio_name}"', + ' |> {self.Ocaml_type}.of_string', + ' |> Ezfio.set_{self.ezfio_dir}_{self.ezfio_name}', + ' ;', + ' Ezfio.get_{self.ezfio_dir}_{self.ezfio_name} ()'] if self.fancy_type: - l_template += [" |> {self.fancy_type}.of_{self.Ocaml_type}"] + l_template += [" |> {self.fancy_type}.of_{self.ocaml_type}"] - l_template += [";;;"] + l_template += [";;"] template = "\n ".join(l_template) @@ -70,4 +75,158 @@ class EZFIO_ocaml(object): return template_rendered def create_write(self): - pass + ''' + You need to instantiate the EZFIO_ocaml with this keyword argument + ezfio_dir = str + ezfio_name = str + type = Named_tuple(fancy_type, ocaml_type, fortrant_type) + + Return the read template + ''' + + for i in ["ezfio_dir", "ezfio_name", "type"]: + try: + "exec self.{0}".format(i) + except NameError: + msg = "You need to provide a '{0}' for creating read function" + raise KeyError(msg.format(i)) + + # ~#~#~#~#~#~#~#~#~#~#~#~#~#~# # + # C r e a t e _ t e m pl a t e # + # ~#~#~#~#~#~#~#~#~#~#~#~#~#~# # + + l_template = ['(* Write snippet for {self.ezfio_name} *)'] + + if self.fancy_type: + l_template += ['let write_{self.ezfio_name} var = ', + ' {self.fancy_type}.to_{self.ocaml_type} var', + ' |> Ezfio.set_{self.ezfio_dir}_{self.ezfio_name}'] + else: + l_template += ['let write_{self.ezfio_name} =', + ' Ezfio.set_{self.ezfio_dir}_{self.ezfio_name}'] + + l_template += [';;'] + + template = "\n ".join(l_template) + + # ~#~#~#~#~#~ # + # R e n d e r # + # ~#~#~#~#~#~ # + + template_rendered = template.format(**locals()) + + # ~#~#~#~#~#~ # + # R e t u r n # + # ~#~#~#~#~#~ # + return template_rendered + + @staticmethod + def create_type(l_provider, l_type): + + l_template = ["(* Generate type *)", + "type t = ", + " {"] + + for p, t in zip(l_provider, l_type): + + if t.fancy: + l_template += [" {0:<30} : {1}.t;".format(p, t.fancy)] + else: + l_template += [" {0:<30} : {1};".format(p, t.ocaml)] + l_template += [" } with sexp", + ";;"] + + # ~#~#~#~#~#~ # + # R e t u r n # + # ~#~#~#~#~#~ # + return "\n ".join(l_template) + + @staticmethod + def create_read_global(l_provider): + + l_template = ["(* Read all *)", + "let read() = ", + " Some", + " {"] + l_template += [" {0:<30} = read_{0} ();".format(p) for p in l_provider] + + l_template += [" }", + ";;"] + + # ~#~#~#~#~#~ # + # R e t u r n # + # ~#~#~#~#~#~ # + return "\n ".join(l_template) + + @staticmethod + def create_write_global(l_provider): + + l_template = ["(* Write all *)", + "let write{ "] + l_template += [" {0};".format(p) for p in l_provider] + l_template += [" } ="] + l_template += [" write_{0:<30} {0};".format(p) for p in l_provider] + l_template += [";;"] + + # ~#~#~#~#~#~ # + # R e t u r n # + # ~#~#~#~#~#~ # + return "\n ".join(l_template) + + @staticmethod + def create_to_string(l_provider, l_type): + + l_template = ['(* to_string*)', + 'let to_string b =', + ' Printf.sprintf "'] + + l_template += ["{0} = %s".format(p) for p in l_provider] + l_template += ['"'] + + for p, t in zip(l_provider, l_type): + + if t.fancy: + str_ = t.fancy + else: + str_ = t.ocaml.capitalize() + + l_template += [" ({0}.to_string b.{1})".format(str_, p)] + + l_template += [";;"] + + # ~#~#~#~#~#~ # + # R e t u r n # + # ~#~#~#~#~#~ # + return "\n ".join(l_template) + + @staticmethod + def create_to_rst(l_provider, l_type, l_doc): + + l_template = ['(* to_rst*)', + 'let to_rst b =', + ' Printf.sprintf "'] + + for p, d in zip(l_provider, l_doc): + + l_template += ["{0} ::".format(d), + "", + " {0} = %s".format(p), + ""] + l_template += ['"'] + + for p, t in zip(l_provider, l_type): + + if t.fancy: + str_ = t.fancy + else: + str_ = t.ocaml.capitalize() + + l_template += [" ({0}.to_string b.{1})".format(str_, p)] + + l_template += ["|> Rst_string.of_string", + ";;"] + + # ~#~#~#~#~#~ # + # R e t u r n # + # ~#~#~#~#~#~ # + return "\n ".join(l_template) diff --git a/src/Full_CI/EZFIO.cfg b/src/Full_CI/EZFIO.cfg index 8146ff81..1f701ad8 100644 --- a/src/Full_CI/EZFIO.cfg +++ b/src/Full_CI/EZFIO.cfg @@ -18,8 +18,8 @@ default: true [PT2_max] type: PT2_energy -doc: The selection process stops when the largest PT2 (for all the state is lower - than pt2_max in absolute value) +doc: The selection process stops when the largest PT2 (for all the state) is lower + than pt2_max in absolute value interface: output default: 0.0001 From 5f84af566c4962eec07318a20d5d2f9a8b7ffe2d Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Fri, 27 Mar 2015 16:16:28 +0100 Subject: [PATCH 24/41] Fix veryclean in QPROOT --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index a59dac50..bced5d0f 100644 --- a/Makefile +++ b/Makefile @@ -93,6 +93,6 @@ ocaml/Qptypes.ml: QPACKAGE_ROOT=$$PWD ./scripts/install_ocaml.sh | tee install_ocaml.log veryclean: - rm -f EZFIO + rm -rf EZFIO $(MAKE) EZFIO $(MAKE) -C src veryclean From b281ab1248753fb1bcb0aec7b667c921e6c2fbec Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Fri, 27 Mar 2015 16:56:35 +0100 Subject: [PATCH 25/41] Input need a default, not output ! --- scripts/ezfio_interface/ei_handler.py | 21 ++++++++++++------- .../ezfio_interface/ezfio_generate_ocaml.py | 9 ++++---- src/Full_CI/EZFIO.cfg | 14 ++++++------- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/scripts/ezfio_interface/ei_handler.py b/scripts/ezfio_interface/ei_handler.py index 3396e6db..72ee2b93 100755 --- a/scripts/ezfio_interface/ei_handler.py +++ b/scripts/ezfio_interface/ei_handler.py @@ -16,7 +16,7 @@ Format specification : - ezfio_name : Will be the name of the file for the ezfio (optional by default is the name of the provider) - interface : The provider is a imput or a output - - default : The default value if interface == output: + - default : The default value if interface == input: - size : Is the string read in ezfio.cgf who containt the size information (like 1 or =sum(ao_num) or (ao_num,3) ) @@ -26,7 +26,7 @@ Example EZFIO.cfg: doc: Threshold on the convergence of the Hartree Fock energy type: Threshold default: 1.e-10 -interface: output +interface: input default: 10000 size : ao_num, 3 @@ -34,7 +34,7 @@ size : ao_num, 3 type: logical doc: If true, compute the PT2 at the end of the selection default: true -interface: input +interface: output size : 1 ``` @@ -237,7 +237,7 @@ def get_dict_config_file(config_file_path, module_lower): d[pvd][option] = d_default[option] # If interface is output we need a default value information - if d[pvd]["interface"] == "output": + if d[pvd]["interface"] == "input": try: default_raw = config_file.get(section, "default") except ConfigParser.NoOptionError: @@ -416,9 +416,15 @@ def save_ezfio_config(module_lower, str_ezfio_config): def create_ocaml_input(dict_ezfio_cfg): - l_provider = [k for k, v in dict_ezfio_cfg.iteritems() if 'default' in v] - l_type = [v["type"] for k, v in dict_ezfio_cfg.iteritems() if 'default' in v] - l_doc = [v["doc"] for k, v in dict_ezfio_cfg.iteritems() if 'default' in v] + l_provider = [] + l_type = [] + l_doc = [] + + for k, v in dict_ezfio_cfg.iteritems(): + if v['interface'] == "output": + l_provider.append(k) + l_type.append(v["type"]) + l_doc.append(v["doc"]) # ~#~#~#~#~#~#~#~# # # C r e a t i o n # @@ -514,6 +520,7 @@ def save_ocaml_input(module_lower, str_ocaml_input): with open(path, "w") as f: f.write(str_ocaml_input) + def main(): """ Two condition: diff --git a/scripts/ezfio_interface/ezfio_generate_ocaml.py b/scripts/ezfio_interface/ezfio_generate_ocaml.py index fc71ddbe..f3eb3d27 100755 --- a/scripts/ezfio_interface/ezfio_generate_ocaml.py +++ b/scripts/ezfio_interface/ezfio_generate_ocaml.py @@ -148,7 +148,8 @@ class EZFIO_ocaml(object): "let read() = ", " Some", " {"] - l_template += [" {0:<30} = read_{0} ();".format(p) for p in l_provider] + l_template += [" {0:<30} = read_{0} ();".format(p) + for p in l_provider] l_template += [" }", ";;"] @@ -161,8 +162,8 @@ class EZFIO_ocaml(object): @staticmethod def create_write_global(l_provider): - l_template = ["(* Write all *)", - "let write{ "] + l_template = ["(* Write all *)", + "let write{ "] l_template += [" {0};".format(p) for p in l_provider] l_template += [" } ="] l_template += [" write_{0:<30} {0};".format(p) for p in l_provider] @@ -180,7 +181,7 @@ class EZFIO_ocaml(object): 'let to_string b =', ' Printf.sprintf "'] - l_template += ["{0} = %s".format(p) for p in l_provider] + l_template += ["{0} = %s".format(p) for p in l_provider] l_template += ['"'] for p, t in zip(l_provider, l_type): diff --git a/src/Full_CI/EZFIO.cfg b/src/Full_CI/EZFIO.cfg index 1f701ad8..30528fd8 100644 --- a/src/Full_CI/EZFIO.cfg +++ b/src/Full_CI/EZFIO.cfg @@ -1,42 +1,42 @@ [N_det_max_fci] type: Det_number_max doc: Max number of determinants in the wave function -interface: output +interface: input default: 10000 [N_det_max_fci_property] type: Det_number_max doc: Max number of determinants in the wave function when you select for a given property -interface: output +interface: input default: 10000 [do_pt2_end] type: logical doc: If true, compute the PT2 at the end of the selection -interface: output +interface: input default: true [PT2_max] type: PT2_energy doc: The selection process stops when the largest PT2 (for all the state) is lower than pt2_max in absolute value -interface: output +interface: input default: 0.0001 [var_pt2_ratio] type: Normalized_float doc: The selection process stops when the energy ratio variational/(variational+PT2) is equal to var_pt2_ratio -interface: output +interface: input default: 0.75 [energy] type: double precision doc: "Calculated Full CI energy" -interface: input +interface: output [energy_pt2] type: double precision doc: "Calculated Full CI energy" -interface: input +interface: output From ba190353e839a7f296b819dacfd4e384abc4a339 Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Fri, 27 Mar 2015 17:25:57 +0100 Subject: [PATCH 26/41] ei_handler now handle ezfio_default --- data/ezfio_defaults/full_ci.ezfio_default | 6 --- scripts/ezfio_interface/ei_handler.py | 63 ++++++++++++++++++++--- 2 files changed, 56 insertions(+), 13 deletions(-) delete mode 100644 data/ezfio_defaults/full_ci.ezfio_default diff --git a/data/ezfio_defaults/full_ci.ezfio_default b/data/ezfio_defaults/full_ci.ezfio_default deleted file mode 100644 index 359cc4d2..00000000 --- a/data/ezfio_defaults/full_ci.ezfio_default +++ /dev/null @@ -1,6 +0,0 @@ -full_ci - n_det_max_fci 10000 - n_det_max_fci_property 50000 - pt2_max 1.e-4 - do_pt2_end True - var_pt2_ratio 0.75 diff --git a/scripts/ezfio_interface/ei_handler.py b/scripts/ezfio_interface/ei_handler.py index 72ee2b93..02d6d667 100755 --- a/scripts/ezfio_interface/ei_handler.py +++ b/scripts/ezfio_interface/ei_handler.py @@ -58,9 +58,9 @@ def is_bool(str_): fortran and ocaml one. """ if str_.lower() in ['true', '.true.']: - return Type(None, "true", ".True.") + return Type(None, "True", ".True.") elif str_.lower() in ['false', '.False.']: - return Type(None, "false", ".False") + return Type(None, "False", ".False") else: raise TypeError @@ -236,7 +236,7 @@ def get_dict_config_file(config_file_path, module_lower): if option in d_default: d[pvd][option] = d_default[option] - # If interface is output we need a default value information + # If interface is input we need a default value information if d[pvd]["interface"] == "input": try: default_raw = config_file.get(section, "default") @@ -312,7 +312,7 @@ def save_ezfio_provider(path_head, dict_code_provider): f.write(output) -def create_ezfio_config(dict_ezfio_cfg): +def create_ezfio_stuff(dict_ezfio_cfg, config_or_default="config"): """ From dict_ezfio_cfg[provider_name] = {type, default, ezfio_name,ezfio_dir,doc} Return the string ezfio_interface_config @@ -383,18 +383,32 @@ def create_ezfio_config(dict_ezfio_cfg): str_fortran_type = str_type_format(fortran_type_raw) # Return the string - s = " {0} {1} {2}".format(str_name, str_fortran_type, str_size) - + if config_or_default == "config": + s = " {0} {1} {2}".format(str_name, str_fortran_type, str_size) + elif config_or_default == "default": + try: + str_value = provider_info["default"].ocaml + except KeyError: + continue + else: + s = " {0} {1}".format(str_name, str_value) + else: + raise KeyError # Append result.append(s) return "\n".join(result) +def create_ezfio_config(dict_ezfio_cfg): + return create_ezfio_stuff(dict_ezfio_cfg, + config_or_default="config") + + def save_ezfio_config(module_lower, str_ezfio_config): """ Write the str_ezfio_config in - $QPACKAGE_ROOT/EZFIO/{0}.ezfio_interface_config".format(module_lower) + "$QPACKAGE_ROOT/EZFIO/{0}.ezfio_interface_config".format(module_lower) """ root_ezfio = "{0}/EZFIO".format(os.environ['QPACKAGE_ROOT']) @@ -414,6 +428,34 @@ def save_ezfio_config(module_lower, str_ezfio_config): f.write(str_ezfio_config) +def create_ezfio_default(dict_ezfio_cfg): + return create_ezfio_stuff(dict_ezfio_cfg, + config_or_default="default") + + +def save_ezfio_default(module_lower, str_ezfio_default): + """ + Write the str_ezfio_config in + "$QPACKAGE_ROOT/data/ezfio_defaults/{0}.ezfio_interface_default".format(module_lower) + """ + + root_ezfio_default = "{0}/data/ezfio_defaults/".format(os.environ['QPACKAGE_ROOT']) + path = "{0}/{1}.ezfio_interface_default".format(root_ezfio_default, + module_lower) + + try: + f = open(path, "r") + except IOError: + old_output = "" + else: + old_output = f.read() + f.close() + + if str_ezfio_default != old_output: + with open(path, "w") as f: + f.write(str_ezfio_default) + + def create_ocaml_input(dict_ezfio_cfg): l_provider = [] @@ -580,6 +622,13 @@ def main(): str_ezfio_config = create_ezfio_config(dict_ezfio_cfg) save_ezfio_config(module_lower, str_ezfio_config) + # ~#~#~#~#~#~#~#~#~#~#~#~#~#~ # + # e z f i o _ d e f a u l t # + # ~#~#~#~#~#~#~#~#~#~#~#~#~#~ # + + str_ezfio_default = create_ezfio_default(dict_ezfio_cfg) + save_ezfio_default(module_lower, str_ezfio_default) + if __name__ == "__main__": main() From d76f3683e1095da06f71d1196fe6e88e5237166b Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Fri, 27 Mar 2015 18:15:23 +0100 Subject: [PATCH 27/41] Fixed ocaml generator --- scripts/ezfio_interface/ei_handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ezfio_interface/ei_handler.py b/scripts/ezfio_interface/ei_handler.py index 02d6d667..0b8cca3f 100755 --- a/scripts/ezfio_interface/ei_handler.py +++ b/scripts/ezfio_interface/ei_handler.py @@ -463,7 +463,7 @@ def create_ocaml_input(dict_ezfio_cfg): l_doc = [] for k, v in dict_ezfio_cfg.iteritems(): - if v['interface'] == "output": + if v['interface'] == "input": l_provider.append(k) l_type.append(v["type"]) l_doc.append(v["doc"]) From d9e6c9f708dc626e14e6775aca5b090a8084c304 Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Fri, 27 Mar 2015 19:03:15 +0100 Subject: [PATCH 28/41] First try of unit test --- .travis.yml | 2 +- tests/unit_test/unit_test.py | 86 ++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 1 deletion(-) create mode 100755 tests/unit_test/unit_test.py diff --git a/.travis.yml b/.travis.yml index 1a1b3701..0ca4d142 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,4 +13,4 @@ script: - source ./quantum_package.rc - cp ./src/Makefile.config.gfortran ./src/Makefile.config - make build - + - ./tests/unit_test/unit_test.py diff --git a/tests/unit_test/unit_test.py b/tests/unit_test/unit_test.py new file mode 100755 index 00000000..f13abba6 --- /dev/null +++ b/tests/unit_test/unit_test.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import unittest +import subprocess +import os + +qpackage_root = os.environ['QPACKAGE_ROOT'] + +import sys +EZFIO = "{0}/EZFIO".format(qpackage_root) + +sys.path = [EZFIO + "/Python"] + sys.path + +from ezfio import ezfio + +precision = 1.e-8 + +from collections import defaultdict + + +def init_folder(name, basis): + + cmd = "cp {0}/tests/{1}.xyz .".format(qpackage_root, name) + subprocess.check_call([cmd], shell=True) + + cmd = "qp_create_ezfio_from_xyz -b {0} {1}.xyz".format(basis, name) + subprocess.check_call([cmd], shell=True) + + +def run_hf(name, basis): + + ref_energy = defaultdict(dict) + + ref_energy["sto-3g"]["methane"] = -39.7267433402 + + init_folder(name, basis) + + cmd = "qp_run SCF {0}.ezfio/".format(name) + subprocess.check_call([cmd], shell=True) + + ezfio.set_file("{0}.ezfio".format(name)) + cur_e = ezfio.get_hartree_fock_energy() + + return abs(cur_e - ref_energy[basis][name]) <= precision + + +def run_full_ci_10k_pt2_end(name, basis): + + ref_energy_var = defaultdict(dict) + ref_energy_pt2 = defaultdict(dict) + + ref_energy_var["sto-3g"]["methane"] = -0.398058753535695E+02 + ref_energy_pt2["sto-3g"]["methane"] = -0.398059182483741E+02 + + ezfio.set_file("{0}.ezfio".format(name)) + + ezfio.full_ci_do_pt2_end = True + ezfio.full_ci_n_det_max_fci = 10000 + ezfio.full_ci_pt2_max = 1.e-8 + + cmd = "qp_run full_ci {0}.ezfio/".format(name) + subprocess.check_call([cmd], shell=True) + + cur_var = ezfio.get_full_ci_energy() + cur_pt2 = ezfio.get_full_ci_energy_pt2() + + t = [abs(cur_var - ref_energy_var[basis][name]) <= precision, + abs(cur_pt2 - ref_energy_pt2[basis][name]) <= precision] + + return all(t) + + +def run_big_test(name, basis): + if run_hf(name, basis): + return run_full_ci_10k_pt2_end(name, basis) + else: + raise ValueError("Fail un run_hf") + + +class SimplisticTest(unittest.TestCase): + + def test_full_ci_10k_pt2_end(self): + self.assertTrue(run_big_test("methane", "sto-3g")) + +if __name__ == '__main__': + unittest.main() From 6bdbe6a78c5c9ab00e4793e95698e46c2dc0355d Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Mon, 30 Mar 2015 09:42:12 +0200 Subject: [PATCH 29/41] Cleaning ei_handler.py --- scripts/ezfio_interface/ei_handler.py | 35 ++-- .../ezfio_interface/ezfio_generate_ocaml.py | 158 ++++++++++++++---- 2 files changed, 146 insertions(+), 47 deletions(-) diff --git a/scripts/ezfio_interface/ei_handler.py b/scripts/ezfio_interface/ei_handler.py index 0b8cca3f..7ad415b2 100755 --- a/scripts/ezfio_interface/ei_handler.py +++ b/scripts/ezfio_interface/ei_handler.py @@ -439,7 +439,8 @@ def save_ezfio_default(module_lower, str_ezfio_default): "$QPACKAGE_ROOT/data/ezfio_defaults/{0}.ezfio_interface_default".format(module_lower) """ - root_ezfio_default = "{0}/data/ezfio_defaults/".format(os.environ['QPACKAGE_ROOT']) + root_ezfio_default = "{0}/data/ezfio_defaults/".format( + os.environ['QPACKAGE_ROOT']) path = "{0}/{1}.ezfio_interface_default".format(root_ezfio_default, module_lower) @@ -458,6 +459,12 @@ def save_ezfio_default(module_lower, str_ezfio_default): def create_ocaml_input(dict_ezfio_cfg): + # ~#~#~#~# # + # I n i t # + # ~#~#~#~# # + + from ezfio_generate_ocaml import EZFIO_ocaml + l_provider = [] l_type = [] l_doc = [] @@ -468,12 +475,14 @@ def create_ocaml_input(dict_ezfio_cfg): l_type.append(v["type"]) l_doc.append(v["doc"]) + e_glob = EZFIO_ocaml(l_provider=l_provider, + l_type=l_type, + l_doc=l_doc) + # ~#~#~#~#~#~#~#~# # # C r e a t i o n # # ~#~#~#~#~#~#~#~# # - from ezfio_generate_ocaml import EZFIO_ocaml - template = ['(* =~=~ *)', '(* Init *)', '(* =~=~ *)', @@ -485,7 +494,7 @@ def create_ocaml_input(dict_ezfio_cfg): "", "module Full_ci : sig"] - template += [EZFIO_ocaml.create_type(l_provider, l_type)] + template += [e_glob.create_type()] template += [" val read : unit -> t option", " val write : t-> unit", @@ -494,7 +503,7 @@ def create_ocaml_input(dict_ezfio_cfg): " val of_rst : Rst_string.t -> t option", "end = struct"] - template += [EZFIO_ocaml.create_type(l_provider, l_type)] + template += [e_glob.create_type()] template += ['', ' let get_default = Qpackage.get_ezfio_default "full_ci";;', @@ -513,11 +522,9 @@ def create_ocaml_input(dict_ezfio_cfg): ezfio_dir = d_val["ezfio_dir"] ezfio_name = d_val["ezfio_name"] - d = {"ezfio_dir": ezfio_dir, - "ezfio_name": ezfio_name, - "type": d_val["type"]} - - e = EZFIO_ocaml(**d) + e = EZFIO_ocaml(ezfio_dir=ezfio_dir, + ezfio_name=ezfio_name, + type=d_val["type"]) template += [e.create_read(), e.create_write(), @@ -528,10 +535,10 @@ def create_ocaml_input(dict_ezfio_cfg): '(* =~=~=~=~=~=~=~=~=~=~=~=~ *)', ""] - template += [EZFIO_ocaml.create_read_global(l_provider), - EZFIO_ocaml.create_write_global(l_provider), - EZFIO_ocaml.create_to_string(l_provider, l_type), - EZFIO_ocaml.create_to_rst(l_provider, l_type, l_doc)] + template += [e_glob.create_read_global(), + e_glob.create_write_global(), + e_glob.create_to_string(), + e_glob.create_to_rst()] template += [" include Generic_input_of_rst;;", " let of_rst = of_rst t_of_sexp;;", diff --git a/scripts/ezfio_interface/ezfio_generate_ocaml.py b/scripts/ezfio_interface/ezfio_generate_ocaml.py index f3eb3d27..9dd4c640 100755 --- a/scripts/ezfio_interface/ezfio_generate_ocaml.py +++ b/scripts/ezfio_interface/ezfio_generate_ocaml.py @@ -2,15 +2,19 @@ import sys +# If type in **kwargs +from ei_handler import Type + class EZFIO_ocaml(object): def __init__(self, **kwargs): for k, v in kwargs.iteritems(): - if k == "type": - self.type = kwargs["type"] - else: + + try: + exec "self.{0} = {1}".format(k, v) + except NameError: exec "self.{0} = '{1}'".format(k, v) @property @@ -25,6 +29,14 @@ class EZFIO_ocaml(object): def fancy_type(self): return self.type.fancy + def check_if_init(self, l_arg, name): + for i in l_arg: + try: + exec "self.{0}".format(i) + except AttributeError: + msg = "You need to provide a '{0}' for creating {1}" + raise KeyError(msg.format(i, name)) + def create_read(self): ''' You need to instantiate the EZFIO_ocaml with this keyword argument @@ -35,12 +47,12 @@ class EZFIO_ocaml(object): Return the read template ''' - for i in ["ezfio_dir", "ezfio_name", "type"]: - try: - "exec self.{0}".format(i) - except NameError: - msg = "You need to provide a '{0}' for creating read function" - raise KeyError(msg.format(i)) + # ~#~#~#~#~#~#~#~ # + # C h e c k i n g # + # ~#~#~#~#~#~#~#~ # + + self.check_if_init(["ezfio_dir", "ezfio_name", "type"], + sys._getframe().f_code.co_name) # ~#~#~#~#~#~#~#~#~#~#~#~#~#~# # # C r e a t e _ t e m pl a t e # @@ -84,12 +96,12 @@ class EZFIO_ocaml(object): Return the read template ''' - for i in ["ezfio_dir", "ezfio_name", "type"]: - try: - "exec self.{0}".format(i) - except NameError: - msg = "You need to provide a '{0}' for creating read function" - raise KeyError(msg.format(i)) + # ~#~#~#~#~#~#~#~ # + # C h e c k i n g # + # ~#~#~#~#~#~#~#~ # + + self.check_if_init(["ezfio_dir", "ezfio_name", "type"], + sys._getframe().f_code.co_name) # ~#~#~#~#~#~#~#~#~#~#~#~#~#~# # # C r e a t e _ t e m pl a t e # @@ -120,14 +132,31 @@ class EZFIO_ocaml(object): # ~#~#~#~#~#~ # return template_rendered - @staticmethod - def create_type(l_provider, l_type): + def create_type(self): + ''' + You need to instantiate the EZFIO_ocaml with this keyword argument + l_provider = [provider_name, ...] + l_type = [Named_tuple(fancy_type, ocaml_type, fortrant_type), ...] + + Return the type template + ''' + + # ~#~#~#~#~#~#~#~ # + # C h e c k i n g # + # ~#~#~#~#~#~#~#~ # + + self.check_if_init(["l_provider", "l_type"], + sys._getframe().f_code.co_name) + + # ~#~#~#~#~#~#~#~#~#~#~#~#~#~# # + # C r e a t e _ t e m pl a t e # + # ~#~#~#~#~#~#~#~#~#~#~#~#~#~# # l_template = ["(* Generate type *)", "type t = ", " {"] - for p, t in zip(l_provider, l_type): + for p, t in zip(self.l_provider, self.l_type): if t.fancy: l_template += [" {0:<30} : {1}.t;".format(p, t.fancy)] @@ -141,15 +170,31 @@ class EZFIO_ocaml(object): # ~#~#~#~#~#~ # return "\n ".join(l_template) - @staticmethod - def create_read_global(l_provider): + def create_read_global(self): + ''' + You need to instantiate the EZFIO_ocaml with this keyword argument + l_provider = [provider_name, ...] + + Return the read_global template + ''' + # ~#~#~#~#~#~#~#~ # + # C h e c k i n g # + # ~#~#~#~#~#~#~#~ # + + self.check_if_init(["l_provider"], + sys._getframe().f_code.co_name) + + # ~#~#~#~#~#~#~#~#~#~#~#~#~#~# # + # C r e a t e _ t e m pl a t e # + # ~#~#~#~#~#~#~#~#~#~#~#~#~#~# # l_template = ["(* Read all *)", "let read() = ", " Some", " {"] + l_template += [" {0:<30} = read_{0} ();".format(p) - for p in l_provider] + for p in self.l_provider] l_template += [" }", ";;"] @@ -159,14 +204,29 @@ class EZFIO_ocaml(object): # ~#~#~#~#~#~ # return "\n ".join(l_template) - @staticmethod - def create_write_global(l_provider): + def create_write_global(self): + ''' + You need to instantiate the EZFIO_ocaml with this keyword argument + l_provider = [provider_name, ...] + + Return the type template + ''' + # ~#~#~#~#~#~#~#~ # + # C h e c k i n g # + # ~#~#~#~#~#~#~#~ # + + self.check_if_init(["l_provider"], + sys._getframe().f_code.co_name) + + # ~#~#~#~#~#~#~#~#~#~#~#~#~#~# # + # C r e a t e _ t e m pl a t e # + # ~#~#~#~#~#~#~#~#~#~#~#~#~#~# # l_template = ["(* Write all *)", "let write{ "] - l_template += [" {0};".format(p) for p in l_provider] + l_template += [" {0};".format(p) for p in self.l_provider] l_template += [" } ="] - l_template += [" write_{0:<30} {0};".format(p) for p in l_provider] + l_template += [" write_{0:<30} {0};".format(p) for p in self.l_provider] l_template += [";;"] # ~#~#~#~#~#~ # @@ -174,17 +234,33 @@ class EZFIO_ocaml(object): # ~#~#~#~#~#~ # return "\n ".join(l_template) - @staticmethod - def create_to_string(l_provider, l_type): + def create_to_string(self): + ''' + You need to instantiate the EZFIO_ocaml with this keyword argument + l_provider = [provider_name, ...] + l_type = [Named_tuple(fancy_type, ocaml_type, fortrant_type), ...] + + Return the type template + ''' + # ~#~#~#~#~#~#~#~ # + # C h e c k i n g # + # ~#~#~#~#~#~#~#~ # + + self.check_if_init(["l_provider", "l_type"], + sys._getframe().f_code.co_name) + + # ~#~#~#~#~#~#~#~#~#~#~#~#~#~# # + # C r e a t e _ t e m pl a t e # + # ~#~#~#~#~#~#~#~#~#~#~#~#~#~# # l_template = ['(* to_string*)', 'let to_string b =', ' Printf.sprintf "'] - l_template += ["{0} = %s".format(p) for p in l_provider] + l_template += ["{0} = %s".format(p) for p in self.l_provider] l_template += ['"'] - for p, t in zip(l_provider, l_type): + for p, t in zip(self.l_provider, self.l_type): if t.fancy: str_ = t.fancy @@ -200,14 +276,30 @@ class EZFIO_ocaml(object): # ~#~#~#~#~#~ # return "\n ".join(l_template) - @staticmethod - def create_to_rst(l_provider, l_type, l_doc): + def create_to_rst(self): + ''' + You need to instantiate the EZFIO_ocaml with this keyword argument + l_provider = [provider_name, ...] + l_type = [Named_tuple(fancy_type, ocaml_type, fortrant_type), ...] + + Return the type template + ''' + # ~#~#~#~#~#~#~#~ # + # C h e c k i n g # + # ~#~#~#~#~#~#~#~ # + + self.check_if_init(["l_provider", "l_type", "l_doc"], + sys._getframe().f_code.co_name) + + # ~#~#~#~#~#~#~#~#~#~#~#~#~#~# # + # C r e a t e _ t e m pl a t e # + # ~#~#~#~#~#~#~#~#~#~#~#~#~#~# # l_template = ['(* to_rst*)', 'let to_rst b =', ' Printf.sprintf "'] - for p, d in zip(l_provider, l_doc): + for p, d in zip(self.l_provider, self.l_doc): l_template += ["{0} ::".format(d), "", @@ -215,7 +307,7 @@ class EZFIO_ocaml(object): ""] l_template += ['"'] - for p, t in zip(l_provider, l_type): + for p, t in zip(self.l_provider, self.l_type): if t.fancy: str_ = t.fancy From aa7bfdc46d55260e499379288ea25725654a58fc Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Mon, 30 Mar 2015 10:15:35 +0200 Subject: [PATCH 30/41] Beter unit test --- tests/unit_test/unit_test.py | 84 ++++++++++++++++++++++++++---------- 1 file changed, 62 insertions(+), 22 deletions(-) diff --git a/tests/unit_test/unit_test.py b/tests/unit_test/unit_test.py index f13abba6..d08a8baa 100755 --- a/tests/unit_test/unit_test.py +++ b/tests/unit_test/unit_test.py @@ -3,48 +3,81 @@ import unittest import subprocess import os +import sys qpackage_root = os.environ['QPACKAGE_ROOT'] -import sys EZFIO = "{0}/EZFIO".format(qpackage_root) - sys.path = [EZFIO + "/Python"] + sys.path from ezfio import ezfio +from collections import defaultdict + +# ~#~#~ # +# O p t # +# ~#~#~ # precision = 1.e-8 -from collections import defaultdict +# A test get a geo file and a basis file. +# A global dict containt the result for this test +# A test return True or Raise a error ! +# More ezfio condition you set, beter it is -def init_folder(name, basis): +def init_folder(geo, basis, mult=1): + ''' + Take a geo in arg (aka a existing geo.xyz in test/) + And create the geo.ezfio with the adeguate basis and multipliciti + DO NOT CHECK IS THE EZFIO FOLDER ALREADY EXIST + ''' - cmd = "cp {0}/tests/{1}.xyz .".format(qpackage_root, name) + cmd = "cp {0}/tests/{1}.xyz .".format(qpackage_root, geo) subprocess.check_call([cmd], shell=True) - cmd = "qp_create_ezfio_from_xyz -b {0} {1}.xyz".format(basis, name) + cmd = "qp_create_ezfio_from_xyz -b {0} -m {1} {2}.xyz".format(basis, + mult, + geo) subprocess.check_call([cmd], shell=True) -def run_hf(name, basis): +def get_error_message(l_exepected, l_cur): + l_msg = ["Need {0} get {1}".format(i,j) for i,j in zip(l_exepected,l_cur)] + return "\n".join(l_msg) + + +def run_hf(geo, basis): + """ + Run a simle by default hf + EZFIO path = geo.ezfio + + """ ref_energy = defaultdict(dict) ref_energy["sto-3g"]["methane"] = -39.7267433402 - init_folder(name, basis) + init_folder(geo, basis) - cmd = "qp_run SCF {0}.ezfio/".format(name) + cmd = "qp_run SCF {0}.ezfio/".format(geo) subprocess.check_call([cmd], shell=True) - ezfio.set_file("{0}.ezfio".format(name)) + ezfio.set_file("{0}.ezfio".format(geo)) + cur_e = ezfio.get_hartree_fock_energy() + ref_e = ref_energy[basis][geo] - return abs(cur_e - ref_energy[basis][name]) <= precision + if abs(cur_e - ref_e) <= precision: + return True + else: + raise ValueError(get_error_message([ref_e], [cur_e])) -def run_full_ci_10k_pt2_end(name, basis): +def run_full_ci_10k_pt2_end(geo, basis): + """ + Run a Full_ci with 10k with the TruePT2 + EZFIO path = geo.ezfio + """ ref_energy_var = defaultdict(dict) ref_energy_pt2 = defaultdict(dict) @@ -52,29 +85,36 @@ def run_full_ci_10k_pt2_end(name, basis): ref_energy_var["sto-3g"]["methane"] = -0.398058753535695E+02 ref_energy_pt2["sto-3g"]["methane"] = -0.398059182483741E+02 - ezfio.set_file("{0}.ezfio".format(name)) + ezfio.set_file("{0}.ezfio".format(geo)) ezfio.full_ci_do_pt2_end = True ezfio.full_ci_n_det_max_fci = 10000 ezfio.full_ci_pt2_max = 1.e-8 - cmd = "qp_run full_ci {0}.ezfio/".format(name) + cmd = "qp_run full_ci {0}.ezfio/".format(geo) subprocess.check_call([cmd], shell=True) cur_var = ezfio.get_full_ci_energy() cur_pt2 = ezfio.get_full_ci_energy_pt2() - t = [abs(cur_var - ref_energy_var[basis][name]) <= precision, - abs(cur_pt2 - ref_energy_pt2[basis][name]) <= precision] + ref_var = ref_energy_var[basis][geo] + ref_pt2 = ref_energy_pt2[basis][geo] - return all(t) + t = [abs(cur_var - ref_var) <= precision, + abs(cur_pt2 - ref_pt2) <= precision] - -def run_big_test(name, basis): - if run_hf(name, basis): - return run_full_ci_10k_pt2_end(name, basis) + if all(t): + return True else: - raise ValueError("Fail un run_hf") + raise ValueError(get_error_message([ref_var, ref_pt2], + [cur_var, cur_pt2])) + + +def run_big_test(geo, basis): + + run_hf(geo, basis) + run_full_ci_10k_pt2_end(geo, basis) + return True class SimplisticTest(unittest.TestCase): From 125e7d4c8f093ef617ea157552c620d5a66735c9 Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Mon, 30 Mar 2015 10:37:11 +0200 Subject: [PATCH 31/41] Add doc and global varialbe in unit_test --- tests/unit_test/unit_test.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/unit_test/unit_test.py b/tests/unit_test/unit_test.py index d08a8baa..f4934c63 100755 --- a/tests/unit_test/unit_test.py +++ b/tests/unit_test/unit_test.py @@ -25,6 +25,12 @@ precision = 1.e-8 # More ezfio condition you set, beter it is +# You cannot order the test flow. +# So if you dont whant to remarque on test (for example the HF), set +# a global variable and check for it +global has_hf_alredy +has_hf_alredy = False + def init_folder(geo, basis, mult=1): ''' Take a geo in arg (aka a existing geo.xyz in test/) @@ -50,8 +56,9 @@ def run_hf(geo, basis): """ Run a simle by default hf EZFIO path = geo.ezfio - """ + global has_hf_alredy + has_hf_alredy = True ref_energy = defaultdict(dict) @@ -111,8 +118,9 @@ def run_full_ci_10k_pt2_end(geo, basis): def run_big_test(geo, basis): + if not has_hf_alredy: + run_hf(geo, basis) - run_hf(geo, basis) run_full_ci_10k_pt2_end(geo, basis) return True From 94b0209b0113ed1881d74a17fd9a1809c28f2437 Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Mon, 30 Mar 2015 10:38:13 +0200 Subject: [PATCH 32/41] I guess with Input_full_ci is beter... --- ocaml/Input_full_ci.ml | 201 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 201 insertions(+) create mode 100644 ocaml/Input_full_ci.ml diff --git a/ocaml/Input_full_ci.ml b/ocaml/Input_full_ci.ml new file mode 100644 index 00000000..0b9dbda0 --- /dev/null +++ b/ocaml/Input_full_ci.ml @@ -0,0 +1,201 @@ +(* =~=~ *) +(* Init *) +(* =~=~ *) + +open Qptypes;; +open Qputils;; +open Core.Std;; + +module Full_ci : sig +(* Generate type *) + type t = + { + do_pt2_end : bool; + var_pt2_ratio : Normalized_float.t; + n_det_max_fci_property : Det_number_max.t; + n_det_max_fci : Det_number_max.t; + pt2_max : PT2_energy.t; + } with sexp + ;; + val read : unit -> t option + val write : t-> unit + val to_string : t -> string + val to_rst : t -> Rst_string.t + val of_rst : Rst_string.t -> t option +end = struct +(* Generate type *) + type t = + { + do_pt2_end : bool; + var_pt2_ratio : Normalized_float.t; + n_det_max_fci_property : Det_number_max.t; + n_det_max_fci : Det_number_max.t; + pt2_max : PT2_energy.t; + } with sexp + ;; + + let get_default = Qpackage.get_ezfio_default "full_ci";; + +(* =~=~=~=~=~=~==~=~=~=~=~=~ *) +(* Generate Special Function *) +(* =~=~=~==~=~~=~=~=~=~=~=~=~ *) + +(* Read snippet for do_pt2_end *) + let read_do_pt2_end () = + if not (Ezfio.has_full_ci_do_pt2_end ()) then + get_default "do_pt2_end" + |> Bool.of_string + |> Ezfio.set_full_ci_do_pt2_end + ; + Ezfio.get_full_ci_do_pt2_end () + ;; +(* Write snippet for do_pt2_end *) + let write_do_pt2_end = + Ezfio.set_full_ci_do_pt2_end + ;; + +(* Read snippet for n_det_max_fci *) + let read_n_det_max_fci () = + if not (Ezfio.has_full_ci_n_det_max_fci ()) then + get_default "n_det_max_fci" + |> Int.of_string + |> Ezfio.set_full_ci_n_det_max_fci + ; + Ezfio.get_full_ci_n_det_max_fci () + |> Det_number_max.of_int + ;; +(* Write snippet for n_det_max_fci *) + let write_n_det_max_fci var = + Det_number_max.to_int var + |> Ezfio.set_full_ci_n_det_max_fci + ;; + +(* Read snippet for n_det_max_fci_property *) + let read_n_det_max_fci_property () = + if not (Ezfio.has_full_ci_n_det_max_fci_property ()) then + get_default "n_det_max_fci_property" + |> Int.of_string + |> Ezfio.set_full_ci_n_det_max_fci_property + ; + Ezfio.get_full_ci_n_det_max_fci_property () + |> Det_number_max.of_int + ;; +(* Write snippet for n_det_max_fci_property *) + let write_n_det_max_fci_property var = + Det_number_max.to_int var + |> Ezfio.set_full_ci_n_det_max_fci_property + ;; + +(* Read snippet for pt2_max *) + let read_pt2_max () = + if not (Ezfio.has_full_ci_pt2_max ()) then + get_default "pt2_max" + |> Float.of_string + |> Ezfio.set_full_ci_pt2_max + ; + Ezfio.get_full_ci_pt2_max () + |> PT2_energy.of_float + ;; +(* Write snippet for pt2_max *) + let write_pt2_max var = + PT2_energy.to_float var + |> Ezfio.set_full_ci_pt2_max + ;; + +(* Read snippet for var_pt2_ratio *) + let read_var_pt2_ratio () = + if not (Ezfio.has_full_ci_var_pt2_ratio ()) then + get_default "var_pt2_ratio" + |> Float.of_string + |> Ezfio.set_full_ci_var_pt2_ratio + ; + Ezfio.get_full_ci_var_pt2_ratio () + |> Normalized_float.of_float + ;; +(* Write snippet for var_pt2_ratio *) + let write_var_pt2_ratio var = + Normalized_float.to_float var + |> Ezfio.set_full_ci_var_pt2_ratio + ;; + +(* =~=~=~=~=~=~=~=~=~=~=~=~ *) +(* Generate Global Function *) +(* =~=~=~=~=~=~=~=~=~=~=~=~ *) + +(* Read all *) + let read() = + Some + { + do_pt2_end = read_do_pt2_end (); + var_pt2_ratio = read_var_pt2_ratio (); + n_det_max_fci_property = read_n_det_max_fci_property (); + n_det_max_fci = read_n_det_max_fci (); + pt2_max = read_pt2_max (); + } + ;; +(* Write all *) + let write{ + do_pt2_end; + var_pt2_ratio; + n_det_max_fci_property; + n_det_max_fci; + pt2_max; + } = + write_do_pt2_end do_pt2_end; + write_var_pt2_ratio var_pt2_ratio; + write_n_det_max_fci_property n_det_max_fci_property; + write_n_det_max_fci n_det_max_fci; + write_pt2_max pt2_max; + ;; +(* to_string*) + let to_string b = + Printf.sprintf " + do_pt2_end = %s + var_pt2_ratio = %s + n_det_max_fci_property = %s + n_det_max_fci = %s + pt2_max = %s + " + (Bool.to_string b.do_pt2_end) + (Normalized_float.to_string b.var_pt2_ratio) + (Det_number_max.to_string b.n_det_max_fci_property) + (Det_number_max.to_string b.n_det_max_fci) + (PT2_energy.to_string b.pt2_max) + ;; +(* to_rst*) + let to_rst b = + Printf.sprintf " + If true, compute the PT2 at the end of the selection :: + + do_pt2_end = %s + + The selection process stops when the energy ratio variational/(variational+PT2) +is equal to var_pt2_ratio :: + + var_pt2_ratio = %s + + Max number of determinants in the wave function when you select for a given property :: + + n_det_max_fci_property = %s + + Max number of determinants in the wave function :: + + n_det_max_fci = %s + + The selection process stops when the largest PT2 (for all the state) is lower +than pt2_max in absolute value :: + + pt2_max = %s + + " + (Bool.to_string b.do_pt2_end) + (Normalized_float.to_string b.var_pt2_ratio) + (Det_number_max.to_string b.n_det_max_fci_property) + (Det_number_max.to_string b.n_det_max_fci) + (PT2_energy.to_string b.pt2_max) + |> Rst_string.of_string + ;; + include Generic_input_of_rst;; + let of_rst = of_rst t_of_sexp;; + +end \ No newline at end of file From 1cb8a7bdd9b2c3a40e6dc70b1675908bd5fefdff Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Mon, 30 Mar 2015 10:48:52 +0200 Subject: [PATCH 33/41] Remove --- ocaml/Input_full_ci.ml | 201 ----------------------------------------- 1 file changed, 201 deletions(-) delete mode 100644 ocaml/Input_full_ci.ml diff --git a/ocaml/Input_full_ci.ml b/ocaml/Input_full_ci.ml deleted file mode 100644 index 0b9dbda0..00000000 --- a/ocaml/Input_full_ci.ml +++ /dev/null @@ -1,201 +0,0 @@ -(* =~=~ *) -(* Init *) -(* =~=~ *) - -open Qptypes;; -open Qputils;; -open Core.Std;; - -module Full_ci : sig -(* Generate type *) - type t = - { - do_pt2_end : bool; - var_pt2_ratio : Normalized_float.t; - n_det_max_fci_property : Det_number_max.t; - n_det_max_fci : Det_number_max.t; - pt2_max : PT2_energy.t; - } with sexp - ;; - val read : unit -> t option - val write : t-> unit - val to_string : t -> string - val to_rst : t -> Rst_string.t - val of_rst : Rst_string.t -> t option -end = struct -(* Generate type *) - type t = - { - do_pt2_end : bool; - var_pt2_ratio : Normalized_float.t; - n_det_max_fci_property : Det_number_max.t; - n_det_max_fci : Det_number_max.t; - pt2_max : PT2_energy.t; - } with sexp - ;; - - let get_default = Qpackage.get_ezfio_default "full_ci";; - -(* =~=~=~=~=~=~==~=~=~=~=~=~ *) -(* Generate Special Function *) -(* =~=~=~==~=~~=~=~=~=~=~=~=~ *) - -(* Read snippet for do_pt2_end *) - let read_do_pt2_end () = - if not (Ezfio.has_full_ci_do_pt2_end ()) then - get_default "do_pt2_end" - |> Bool.of_string - |> Ezfio.set_full_ci_do_pt2_end - ; - Ezfio.get_full_ci_do_pt2_end () - ;; -(* Write snippet for do_pt2_end *) - let write_do_pt2_end = - Ezfio.set_full_ci_do_pt2_end - ;; - -(* Read snippet for n_det_max_fci *) - let read_n_det_max_fci () = - if not (Ezfio.has_full_ci_n_det_max_fci ()) then - get_default "n_det_max_fci" - |> Int.of_string - |> Ezfio.set_full_ci_n_det_max_fci - ; - Ezfio.get_full_ci_n_det_max_fci () - |> Det_number_max.of_int - ;; -(* Write snippet for n_det_max_fci *) - let write_n_det_max_fci var = - Det_number_max.to_int var - |> Ezfio.set_full_ci_n_det_max_fci - ;; - -(* Read snippet for n_det_max_fci_property *) - let read_n_det_max_fci_property () = - if not (Ezfio.has_full_ci_n_det_max_fci_property ()) then - get_default "n_det_max_fci_property" - |> Int.of_string - |> Ezfio.set_full_ci_n_det_max_fci_property - ; - Ezfio.get_full_ci_n_det_max_fci_property () - |> Det_number_max.of_int - ;; -(* Write snippet for n_det_max_fci_property *) - let write_n_det_max_fci_property var = - Det_number_max.to_int var - |> Ezfio.set_full_ci_n_det_max_fci_property - ;; - -(* Read snippet for pt2_max *) - let read_pt2_max () = - if not (Ezfio.has_full_ci_pt2_max ()) then - get_default "pt2_max" - |> Float.of_string - |> Ezfio.set_full_ci_pt2_max - ; - Ezfio.get_full_ci_pt2_max () - |> PT2_energy.of_float - ;; -(* Write snippet for pt2_max *) - let write_pt2_max var = - PT2_energy.to_float var - |> Ezfio.set_full_ci_pt2_max - ;; - -(* Read snippet for var_pt2_ratio *) - let read_var_pt2_ratio () = - if not (Ezfio.has_full_ci_var_pt2_ratio ()) then - get_default "var_pt2_ratio" - |> Float.of_string - |> Ezfio.set_full_ci_var_pt2_ratio - ; - Ezfio.get_full_ci_var_pt2_ratio () - |> Normalized_float.of_float - ;; -(* Write snippet for var_pt2_ratio *) - let write_var_pt2_ratio var = - Normalized_float.to_float var - |> Ezfio.set_full_ci_var_pt2_ratio - ;; - -(* =~=~=~=~=~=~=~=~=~=~=~=~ *) -(* Generate Global Function *) -(* =~=~=~=~=~=~=~=~=~=~=~=~ *) - -(* Read all *) - let read() = - Some - { - do_pt2_end = read_do_pt2_end (); - var_pt2_ratio = read_var_pt2_ratio (); - n_det_max_fci_property = read_n_det_max_fci_property (); - n_det_max_fci = read_n_det_max_fci (); - pt2_max = read_pt2_max (); - } - ;; -(* Write all *) - let write{ - do_pt2_end; - var_pt2_ratio; - n_det_max_fci_property; - n_det_max_fci; - pt2_max; - } = - write_do_pt2_end do_pt2_end; - write_var_pt2_ratio var_pt2_ratio; - write_n_det_max_fci_property n_det_max_fci_property; - write_n_det_max_fci n_det_max_fci; - write_pt2_max pt2_max; - ;; -(* to_string*) - let to_string b = - Printf.sprintf " - do_pt2_end = %s - var_pt2_ratio = %s - n_det_max_fci_property = %s - n_det_max_fci = %s - pt2_max = %s - " - (Bool.to_string b.do_pt2_end) - (Normalized_float.to_string b.var_pt2_ratio) - (Det_number_max.to_string b.n_det_max_fci_property) - (Det_number_max.to_string b.n_det_max_fci) - (PT2_energy.to_string b.pt2_max) - ;; -(* to_rst*) - let to_rst b = - Printf.sprintf " - If true, compute the PT2 at the end of the selection :: - - do_pt2_end = %s - - The selection process stops when the energy ratio variational/(variational+PT2) -is equal to var_pt2_ratio :: - - var_pt2_ratio = %s - - Max number of determinants in the wave function when you select for a given property :: - - n_det_max_fci_property = %s - - Max number of determinants in the wave function :: - - n_det_max_fci = %s - - The selection process stops when the largest PT2 (for all the state) is lower -than pt2_max in absolute value :: - - pt2_max = %s - - " - (Bool.to_string b.do_pt2_end) - (Normalized_float.to_string b.var_pt2_ratio) - (Det_number_max.to_string b.n_det_max_fci_property) - (Det_number_max.to_string b.n_det_max_fci) - (PT2_energy.to_string b.pt2_max) - |> Rst_string.of_string - ;; - include Generic_input_of_rst;; - let of_rst = of_rst t_of_sexp;; - -end \ No newline at end of file From 53f473cfae2dcd58778aa244be47618685a05f10 Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Mon, 30 Mar 2015 11:16:15 +0200 Subject: [PATCH 34/41] Add EZFIO.cfg to Hartree_fock --- .../ezfio_defaults/hartree_fock.ezfio_default | 4 - ocaml/Input_hartree_fock.ml | 128 ------------------ scripts/ezfio_interface/ei_handler.py | 12 +- src/Hartree_Fock/EZFIO.cfg | 22 +++ src/Hartree_Fock/hartree_fock.ezfio_config | 6 - src/Hartree_Fock/options.irp.f | 35 ----- 6 files changed, 28 insertions(+), 179 deletions(-) delete mode 100644 data/ezfio_defaults/hartree_fock.ezfio_default delete mode 100644 ocaml/Input_hartree_fock.ml create mode 100644 src/Hartree_Fock/EZFIO.cfg delete mode 100644 src/Hartree_Fock/hartree_fock.ezfio_config delete mode 100644 src/Hartree_Fock/options.irp.f diff --git a/data/ezfio_defaults/hartree_fock.ezfio_default b/data/ezfio_defaults/hartree_fock.ezfio_default deleted file mode 100644 index 048a3c77..00000000 --- a/data/ezfio_defaults/hartree_fock.ezfio_default +++ /dev/null @@ -1,4 +0,0 @@ -hartree_fock - n_it_scf_max 200 - thresh_scf 1.e-10 - guess "Huckel" diff --git a/ocaml/Input_hartree_fock.ml b/ocaml/Input_hartree_fock.ml deleted file mode 100644 index 82110647..00000000 --- a/ocaml/Input_hartree_fock.ml +++ /dev/null @@ -1,128 +0,0 @@ -open Qptypes;; -open Qputils;; -open Core.Std;; - -module Hartree_fock : sig - type t = - { n_it_scf_max : Strictly_positive_int.t; - thresh_scf : Threshold.t; - guess : MO_guess.t; - } with sexp - ;; - val read : unit -> t option - val write : t -> unit - val to_string : t -> string - val to_rst : t -> Rst_string.t - val of_rst : Rst_string.t -> t option -end = struct - type t = - { n_it_scf_max : Strictly_positive_int.t; - thresh_scf : Threshold.t; - guess : MO_guess.t; - } with sexp - ;; - - let get_default = Qpackage.get_ezfio_default "hartree_fock";; - - let read_n_it_scf_max () = - if not (Ezfio.has_hartree_fock_n_it_scf_max ()) then - get_default "n_it_scf_max" - |> Int.of_string - |> Ezfio.set_hartree_fock_n_it_scf_max - ; - Ezfio.get_hartree_fock_n_it_scf_max () - |> Strictly_positive_int.of_int - ;; - - let write_n_it_scf_max n_it_scf_max = - Strictly_positive_int.to_int n_it_scf_max - |> Ezfio.set_hartree_fock_n_it_scf_max - ;; - - let read_thresh_scf () = - if not (Ezfio.has_hartree_fock_thresh_scf()) then - get_default "thresh_scf" - |> Float.of_string - |> Ezfio.set_hartree_fock_thresh_scf - ; - Ezfio.get_hartree_fock_thresh_scf () - |> Threshold.of_float - ;; - - let write_thresh_scf thresh_scf = - Threshold.to_float thresh_scf - |> Ezfio.set_hartree_fock_thresh_scf - ;; - - let read_guess () = - if not (Ezfio.has_hartree_fock_guess ()) then - get_default "guess" - |> String.strip ~drop:(fun x -> x = '"') - |> Ezfio.set_hartree_fock_guess - ; - Ezfio.get_hartree_fock_guess () - |> MO_guess.of_string - ;; - - let write_guess guess = - MO_guess.to_string guess - |> Ezfio.set_hartree_fock_guess - ;; - - let read () = - Some - { n_it_scf_max = read_n_it_scf_max (); - thresh_scf = read_thresh_scf (); - guess = read_guess (); - } - ;; - - - let write { n_it_scf_max ; - thresh_scf ; - guess ; - } = - write_n_it_scf_max n_it_scf_max; - write_thresh_scf thresh_scf; - write_guess guess - ;; - - - let to_string b = - Printf.sprintf " -n_it_scf_max = %s -thresh_scf = %s -guess = %s -" - (Strictly_positive_int.to_string b.n_it_scf_max) - (Threshold.to_string b.thresh_scf) - (MO_guess.to_string b.guess) - ;; - - let to_rst b = - Printf.sprintf " -Type of MO guess [ Huckel | HCore ] :: - - guess = %s - -Max number of SCF iterations :: - - n_it_scf_max = %s - -SCF convergence criterion (on energy) :: - - thresh_scf = %s - -" - (MO_guess.to_string b.guess) - (Strictly_positive_int.to_string b.n_it_scf_max) - (Threshold.to_string b.thresh_scf) - |> Rst_string.of_string - ;; - - include Generic_input_of_rst;; - let of_rst = of_rst t_of_sexp;; - -end - - diff --git a/scripts/ezfio_interface/ei_handler.py b/scripts/ezfio_interface/ei_handler.py index 7ad415b2..ca7eee70 100755 --- a/scripts/ezfio_interface/ei_handler.py +++ b/scripts/ezfio_interface/ei_handler.py @@ -108,9 +108,9 @@ def get_type_dict(): fancy_type['logical'] = Type(None, "bool", "logical") fancy_type['bool'] = Type(None, "bool", "logical") - fancy_type['character*32'] = Type(None, "string", "character*32") - fancy_type['character*60'] = Type(None, "string", "character*60") - fancy_type['character*256'] = Type(None, "string", "character*256") + fancy_type['character*(32)'] = Type(None, "string", "character*(32)") + fancy_type['character*(60)'] = Type(None, "string", "character*(60)") + fancy_type['character*(256)'] = Type(None, "string", "character*(256)") # ~#~#~#~#~#~#~#~ # # q p _ t y p e s # @@ -457,7 +457,7 @@ def save_ezfio_default(module_lower, str_ezfio_default): f.write(str_ezfio_default) -def create_ocaml_input(dict_ezfio_cfg): +def create_ocaml_input(dict_ezfio_cfg,module_lower): # ~#~#~#~# # # I n i t # @@ -492,7 +492,7 @@ def create_ocaml_input(dict_ezfio_cfg): "open Qputils;;", "open Core.Std;;", "", - "module Full_ci : sig"] + "module {0} : sig".format(module_lower.capitalize())] template += [e_glob.create_type()] @@ -612,7 +612,7 @@ def main(): # O c a m l # # ~#~#~#~#~#~# - str_ocaml_input = create_ocaml_input(dict_ezfio_cfg) + str_ocaml_input = create_ocaml_input(dict_ezfio_cfg, module_lower) save_ocaml_input(module_lower, str_ocaml_input) # ~#~#~#~#~#~#~#~# diff --git a/src/Hartree_Fock/EZFIO.cfg b/src/Hartree_Fock/EZFIO.cfg new file mode 100644 index 00000000..376ef315 --- /dev/null +++ b/src/Hartree_Fock/EZFIO.cfg @@ -0,0 +1,22 @@ +[thresh_SCF] +type: Threshold +doc: Threshold on the convergence of the Hartree Fock energy +interface: input +default: 1.e-10 + +[n_it_scf_max] +type: Strictly_positive_int +doc: Maximum number of SCF iterations +interface: input +default: 200 + +[mo_guess_type] +type: character*(32) +doc: Initial MO guess. Can be [ Huckel | HCore ] +interface: input +default: Huckel + +[energy] +type: double precision +doc: "Calculated HF energy" +interface: output \ No newline at end of file diff --git a/src/Hartree_Fock/hartree_fock.ezfio_config b/src/Hartree_Fock/hartree_fock.ezfio_config deleted file mode 100644 index 3909f652..00000000 --- a/src/Hartree_Fock/hartree_fock.ezfio_config +++ /dev/null @@ -1,6 +0,0 @@ -hartree_fock - thresh_scf double precision - n_it_scf_max integer - energy double precision - guess character*(32) - diff --git a/src/Hartree_Fock/options.irp.f b/src/Hartree_Fock/options.irp.f deleted file mode 100644 index 22f86d6c..00000000 --- a/src/Hartree_Fock/options.irp.f +++ /dev/null @@ -1,35 +0,0 @@ -BEGIN_SHELL [ /usr/bin/python ] -from ezfio_with_default import EZFIO_Provider -T = EZFIO_Provider() -T.set_type ( "double precision" ) -T.set_name ( "thresh_SCF" ) -T.set_doc ( "Threshold on the convergence of the Hartree Fock energy" ) -T.set_ezfio_dir ( "Hartree_Fock" ) -T.set_ezfio_name( "thresh_SCF" ) -T.set_output ( "output_Hartree_Fock" ) -print T - -T = EZFIO_Provider() -T.set_type ( "integer" ) -T.set_name ( "n_it_scf_max" ) -T.set_doc ( "Maximum number of SCF iterations" ) -T.set_ezfio_dir ( "Hartree_Fock" ) -T.set_ezfio_name( "n_it_scf_max" ) -T.set_output ( "output_Hartree_Fock" ) -print T - -T = EZFIO_Provider() -T.set_type ( "character*(32)" ) -T.set_name ( "mo_guess_type" ) -T.set_doc ( "Initial MO guess. Can be [ Huckel | HCore ]" ) -T.set_ezfio_dir ( "Hartree_Fock" ) -T.set_ezfio_name( "guess" ) -T.set_output ( "output_Hartree_Fock" ) -print T - - -END_SHELL - - - - From d458696fcbc1314c661bc00001c243ed5f0c875a Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Mon, 30 Mar 2015 11:21:34 +0200 Subject: [PATCH 35/41] Add convert_ezfio.sh --- scripts/ezfio_interface/convert_ezfio.sh | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 scripts/ezfio_interface/convert_ezfio.sh diff --git a/scripts/ezfio_interface/convert_ezfio.sh b/scripts/ezfio_interface/convert_ezfio.sh new file mode 100644 index 00000000..a1f8fc88 --- /dev/null +++ b/scripts/ezfio_interface/convert_ezfio.sh @@ -0,0 +1,4 @@ +#!/bin/bash +# Convert a old ezfio file (with option.irp.f ezfio_default) +# into a new EZFIO.cfg type +mv $1/Hartree_Fock $1/hartree_fock \ No newline at end of file From 757b785f30979eaa7b6fea5130b4a3493181ec70 Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Mon, 30 Mar 2015 11:47:56 +0200 Subject: [PATCH 36/41] Fix unit_test --- scripts/ezfio_interface/convert_ezfio.sh | 3 ++- src/Hartree_Fock/EZFIO.cfg | 2 +- tests/unit_test/unit_test.py | 7 +++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/scripts/ezfio_interface/convert_ezfio.sh b/scripts/ezfio_interface/convert_ezfio.sh index a1f8fc88..71b68fcc 100644 --- a/scripts/ezfio_interface/convert_ezfio.sh +++ b/scripts/ezfio_interface/convert_ezfio.sh @@ -1,4 +1,5 @@ #!/bin/bash # Convert a old ezfio file (with option.irp.f ezfio_default) # into a new EZFIO.cfg type -mv $1/Hartree_Fock $1/hartree_fock \ No newline at end of file +mv $1/Hartree_Fock $1/hartree_fock +mv $1/hartree_Fock/thresh_SCF $1/hartree_fock/thresh_scf diff --git a/src/Hartree_Fock/EZFIO.cfg b/src/Hartree_Fock/EZFIO.cfg index 376ef315..53a17c73 100644 --- a/src/Hartree_Fock/EZFIO.cfg +++ b/src/Hartree_Fock/EZFIO.cfg @@ -1,4 +1,4 @@ -[thresh_SCF] +[thresh_scf] type: Threshold doc: Threshold on the convergence of the Hartree Fock energy interface: input diff --git a/tests/unit_test/unit_test.py b/tests/unit_test/unit_test.py index f4934c63..7057640b 100755 --- a/tests/unit_test/unit_test.py +++ b/tests/unit_test/unit_test.py @@ -66,11 +66,14 @@ def run_hf(geo, basis): init_folder(geo, basis) + ezfio.set_file("{0}.ezfio".format(geo)) + ezfio.set_hartree_fock_mo_guess_type("Huckel") + ezfio.set_hartree_fock_thresh_scf("1.e-10") + ezfio.set_hartree_fock_n_it_scf_max("100") + cmd = "qp_run SCF {0}.ezfio/".format(geo) subprocess.check_call([cmd], shell=True) - ezfio.set_file("{0}.ezfio".format(geo)) - cur_e = ezfio.get_hartree_fock_energy() ref_e = ref_energy[basis][geo] From c484b9cf9327e5a029dd48fd579dd610f0df8a8c Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Mon, 30 Mar 2015 11:57:42 +0200 Subject: [PATCH 37/41] Set parameter in unit_test.py --- tests/unit_test/unit_test.py | 56 ++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/tests/unit_test/unit_test.py b/tests/unit_test/unit_test.py index 7057640b..8e00d4c3 100755 --- a/tests/unit_test/unit_test.py +++ b/tests/unit_test/unit_test.py @@ -57,23 +57,47 @@ def run_hf(geo, basis): Run a simle by default hf EZFIO path = geo.ezfio """ - global has_hf_alredy - has_hf_alredy = True + # ~#~#~#~#~#~#~#~#~#~ # + # R e f _ e n e r g y # + # ~#~#~#~#~#~#~#~#~#~ # ref_energy = defaultdict(dict) ref_energy["sto-3g"]["methane"] = -39.7267433402 - init_folder(geo, basis) + # ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~ # + # 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) ezfio.set_file("{0}.ezfio".format(geo)) - ezfio.set_hartree_fock_mo_guess_type("Huckel") - ezfio.set_hartree_fock_thresh_scf("1.e-10") - ezfio.set_hartree_fock_n_it_scf_max("100") + + # ~#~#~#~#~#~#~#~#~#~#~#~#~ # + # S e t _ p a r a m e t e r # + # ~#~#~#~#~#~#~#~#~#~#~#~#~ # + + ezfio.hartree_fock_mo_guess_type = "Huckel" + ezfio.hartree_fock_thresh_scf = 1.e-10 + ezfio.hartree_fock_n_it_scf_max = 100 + + # ~#~#~ # + # 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] @@ -89,21 +113,41 @@ def run_full_ci_10k_pt2_end(geo, basis): 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"] = -0.398058753535695E+02 ref_energy_pt2["sto-3g"]["methane"] = -0.398059182483741E+02 + # ~#~#~#~ # + # 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() From 96d69921ffce9019e79d3f554bddbe501de8fb96 Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Mon, 30 Mar 2015 14:53:13 +0200 Subject: [PATCH 38/41] Beter doc for ei_handler --- scripts/ezfio_interface/ei_handler.py | 11 ++++------- src/Hartree_Fock/EZFIO.cfg | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/scripts/ezfio_interface/ei_handler.py b/scripts/ezfio_interface/ei_handler.py index ca7eee70..4424be6a 100755 --- a/scripts/ezfio_interface/ei_handler.py +++ b/scripts/ezfio_interface/ei_handler.py @@ -27,15 +27,12 @@ doc: Threshold on the convergence of the Hartree Fock energy type: Threshold default: 1.e-10 interface: input -default: 10000 -size : ao_num, 3 +size: 1 -[do_pt2_end] -type: logical -doc: If true, compute the PT2 at the end of the selection -default: true +[energy] +type: double precision +doc: Calculated HF energy interface: output -size : 1 ``` """ diff --git a/src/Hartree_Fock/EZFIO.cfg b/src/Hartree_Fock/EZFIO.cfg index 53a17c73..5bb96a7f 100644 --- a/src/Hartree_Fock/EZFIO.cfg +++ b/src/Hartree_Fock/EZFIO.cfg @@ -18,5 +18,5 @@ default: Huckel [energy] type: double precision -doc: "Calculated HF energy" +doc: Calculated HF energy interface: output \ No newline at end of file From 4c3803f383307d2d92c1fb353132668f1ba75b11 Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Mon, 30 Mar 2015 16:50:27 +0200 Subject: [PATCH 39/41] Add mo_guess into EZFIO.cfg --- scripts/ezfio_interface/ei_handler.py | 4 +++- scripts/ezfio_interface/ezfio_generate_ocaml.py | 2 ++ src/Hartree_Fock/EZFIO.cfg | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/ezfio_interface/ei_handler.py b/scripts/ezfio_interface/ei_handler.py index 4424be6a..bdb52244 100755 --- a/scripts/ezfio_interface/ei_handler.py +++ b/scripts/ezfio_interface/ei_handler.py @@ -105,6 +105,8 @@ def get_type_dict(): fancy_type['logical'] = Type(None, "bool", "logical") fancy_type['bool'] = Type(None, "bool", "logical") + fancy_type['MO_guess'] = Type("MO_guess", "string", "character*(32)") + fancy_type['character*(32)'] = Type(None, "string", "character*(32)") fancy_type['character*(60)'] = Type(None, "string", "character*(60)") fancy_type['character*(256)'] = Type(None, "string", "character*(256)") @@ -212,7 +214,7 @@ def get_dict_config_file(config_file_path, module_lower): type_ = config_file.get(section, "type") if type_ not in type_dict: print "{0} not avalaible. Choose in:".format(type_) - print ", ".join([i for i in type_dict]) + print ", ".join(sorted([i for i in type_dict])) sys.exit(1) else: d[pvd]["type"] = type_dict[type_] diff --git a/scripts/ezfio_interface/ezfio_generate_ocaml.py b/scripts/ezfio_interface/ezfio_generate_ocaml.py index 9dd4c640..18863e7d 100755 --- a/scripts/ezfio_interface/ezfio_generate_ocaml.py +++ b/scripts/ezfio_interface/ezfio_generate_ocaml.py @@ -162,6 +162,8 @@ class EZFIO_ocaml(object): l_template += [" {0:<30} : {1}.t;".format(p, t.fancy)] else: l_template += [" {0:<30} : {1};".format(p, t.ocaml)] + + print p, t, l_template l_template += [" } with sexp", ";;"] diff --git a/src/Hartree_Fock/EZFIO.cfg b/src/Hartree_Fock/EZFIO.cfg index 5bb96a7f..87f1a878 100644 --- a/src/Hartree_Fock/EZFIO.cfg +++ b/src/Hartree_Fock/EZFIO.cfg @@ -11,7 +11,7 @@ interface: input default: 200 [mo_guess_type] -type: character*(32) +type: MO_guess doc: Initial MO guess. Can be [ Huckel | HCore ] interface: input default: Huckel From ac7490635a685cf30b8725d29256c1c7cff433a7 Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Mon, 30 Mar 2015 17:36:39 +0200 Subject: [PATCH 40/41] Add EZFIO.cfg to ezfio_generate_ocaml --- .../ezfio_interface/ezfio_generate_ocaml.py | 1 - src/CISD_SC2_selected/EZFIO.cfg | 29 +++++++++++ src/CISD_SC2_selected/cisd_sc2.ezfio_config | 4 -- src/CISD_SC2_selected/options.irp.f | 51 ------------------- 4 files changed, 29 insertions(+), 56 deletions(-) create mode 100644 src/CISD_SC2_selected/EZFIO.cfg delete mode 100644 src/CISD_SC2_selected/cisd_sc2.ezfio_config delete mode 100644 src/CISD_SC2_selected/options.irp.f diff --git a/scripts/ezfio_interface/ezfio_generate_ocaml.py b/scripts/ezfio_interface/ezfio_generate_ocaml.py index 18863e7d..4590f9b9 100755 --- a/scripts/ezfio_interface/ezfio_generate_ocaml.py +++ b/scripts/ezfio_interface/ezfio_generate_ocaml.py @@ -163,7 +163,6 @@ class EZFIO_ocaml(object): else: l_template += [" {0:<30} : {1};".format(p, t.ocaml)] - print p, t, l_template l_template += [" } with sexp", ";;"] diff --git a/src/CISD_SC2_selected/EZFIO.cfg b/src/CISD_SC2_selected/EZFIO.cfg new file mode 100644 index 00000000..84cefe2f --- /dev/null +++ b/src/CISD_SC2_selected/EZFIO.cfg @@ -0,0 +1,29 @@ +[N_det_max_cisd_sc2] +type: Det_number_max +doc: Get n_det_max_cisd_sc2 from EZFIO file +interface: input +default: 10000 + +[do_pt2_end] +type: logical +doc: If true, compute the PT2 at the end of the selection +interface: input +default: true + +[PT2_max] +type: PT2_energy +doc: The selection process stops when the largest PT2 (for all the state) is lower + than pt2_max in absolute value +interface: input +default: 0.0001 + +[energy] +type: double precision +doc: "Calculated Full CI energy" +interface: output + +[energy_pt2] +type: double precision +doc: "Calculated Full CI energy" +interface: output + diff --git a/src/CISD_SC2_selected/cisd_sc2.ezfio_config b/src/CISD_SC2_selected/cisd_sc2.ezfio_config deleted file mode 100644 index 35008968..00000000 --- a/src/CISD_SC2_selected/cisd_sc2.ezfio_config +++ /dev/null @@ -1,4 +0,0 @@ -cisd_sc2_selected - n_det_max_cisd_sc2 integer - pt2_max double precision - do_pt2_end logical diff --git a/src/CISD_SC2_selected/options.irp.f b/src/CISD_SC2_selected/options.irp.f deleted file mode 100644 index 1fe3e158..00000000 --- a/src/CISD_SC2_selected/options.irp.f +++ /dev/null @@ -1,51 +0,0 @@ - BEGIN_PROVIDER [ integer, n_det_max_cisd_sc2 ] - implicit none - BEGIN_DOC - ! Get n_det_max_cisd_sc2 from EZFIO file - END_DOC - logical :: has_n_det_max_cisd_sc2 - PROVIDE ezfio_filename - call ezfio_has_cisd_sc2_selected_n_det_max_cisd_sc2(has_n_det_max_cisd_sc2) - if (has_n_det_max_cisd_sc2) then - call ezfio_get_cisd_sc2_selected_n_det_max_cisd_sc2(n_det_max_cisd_sc2) - else - n_det_max_cisd_sc2 = 1000 - call ezfio_set_cisd_sc2_selected_n_det_max_cisd_sc2(n_det_max_cisd_sc2) - endif - print*,'n_det_max_cisd_sc2 = ',n_det_max_cisd_sc2 - END_PROVIDER - - BEGIN_PROVIDER [ double precision , pt2_max ] - implicit none - BEGIN_DOC - ! Get pt2_max from EZFIO file - END_DOC - logical :: has_pt2_max - PROVIDE ezfio_filename - call ezfio_has_cisd_sc2_selected_pt2_max(has_pt2_max) - if (has_pt2_max) then - call ezfio_get_cisd_sc2_selected_pt2_max(pt2_max) - else - pt2_max = 1.d-3 - call ezfio_set_cisd_sc2_selected_pt2_max(pt2_max) - endif - print*,'pt2_max = ',pt2_max - END_PROVIDER - - BEGIN_PROVIDER [ logical, do_pt2_end ] - implicit none - BEGIN_DOC - ! Get do_pt2_end from EZFIO file - END_DOC - logical :: has_do_pt2_end - PROVIDE ezfio_filename - call ezfio_has_cisd_sc2_selected_do_pt2_end(has_do_pt2_end) - if (has_do_pt2_end) then - call ezfio_get_cisd_sc2_selected_do_pt2_end(do_pt2_end) - else - do_pt2_end = .True. - call ezfio_set_cisd_sc2_selected_do_pt2_end(do_pt2_end) - endif - print*,'do_pt2_end = ',do_pt2_end - END_PROVIDER - From e9665c276ca124ae8574b48248e90ca3a06d5f11 Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Mon, 30 Mar 2015 17:56:17 +0200 Subject: [PATCH 41/41] Add cisd_sc2_selected to qp_edit --- ocaml/Input.ml | 2 +- ocaml/qp_edit.ml | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ocaml/Input.ml b/ocaml/Input.ml index df293cc7..62de42f8 100644 --- a/ocaml/Input.ml +++ b/ocaml/Input.ml @@ -7,6 +7,7 @@ include Input_ao_basis;; include Input_bi_integrals;; include Input_bitmasks;; include Input_cisd_sc2;; +include Input_cisd_sc2_selected;; include Input_determinants;; include Input_electrons;; include Input_full_ci;; @@ -14,4 +15,3 @@ include Input_hartree_fock;; include Input_mo_basis;; include Input_nuclei;; - diff --git a/ocaml/qp_edit.ml b/ocaml/qp_edit.ml index 2fc13e8c..c60db6e2 100644 --- a/ocaml/qp_edit.ml +++ b/ocaml/qp_edit.ml @@ -13,6 +13,7 @@ type keyword = | Ao_basis | Bielec_integrals | Cisd_sc2 +| Cisd_sc2_selected | Determinants | Electrons | Full_ci @@ -26,6 +27,7 @@ let keyword_to_string = function | Ao_basis -> "AO basis" | Bielec_integrals -> "Two electron integrals" | Cisd_sc2 -> "CISD (SC)^2" +| Cisd_sc2_selected -> "CISD (SC)^2 selected" | Determinants -> "Determinants" | Electrons -> "Electrons" | Full_ci -> "Selected Full-CI" @@ -80,6 +82,8 @@ let get s = f Electrons.(read, to_rst) | Cisd_sc2 -> f Cisd_sc2.(read, to_rst) + | Cisd_sc2_selected -> + f Cisd_sc2_selected.(read, to_rst) | Nuclei -> f Nuclei.(read, to_rst) | Ao_basis -> @@ -129,6 +133,7 @@ let set str s = | Full_ci -> write Full_ci.(of_rst, write) s | Electrons -> write Electrons.(of_rst, write) s | Cisd_sc2 -> write Cisd_sc2.(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 | Nuclei -> write Nuclei.(of_rst, write) s @@ -179,6 +184,7 @@ let run check_only ezfio_filename = Bielec_integrals ; Hartree_fock ; Cisd_sc2 ; + Cisd_sc2_selected ; Full_ci ; Mo_basis; Determinants ;