diff --git a/Makefile b/Makefile index ec555670..4aa24d00 100644 --- a/Makefile +++ b/Makefile @@ -45,5 +45,5 @@ ocaml: veryclean: rm -rf EZFIO - $(MAKE) EZFIO + rm -rf resultsFile $(MAKE) -C src veryclean diff --git a/ocaml/.merlin b/ocaml/.merlin new file mode 100644 index 00000000..3683fed6 --- /dev/null +++ b/ocaml/.merlin @@ -0,0 +1,4 @@ +PKG core ZMQ cryptokit +B _build/ + + diff --git a/ocaml/Input.ml b/ocaml/Input.ml index 2da3ba59..5e012996 100644 --- a/ocaml/Input.ml +++ b/ocaml/Input.ml @@ -8,4 +8,4 @@ include Input_determinants_by_hand;; include Input_electrons;; include Input_mo_basis;; include Input_nuclei;; -include Input_auto_generated;; \ No newline at end of file +include Input_auto_generated;; diff --git a/ocaml/Makefile b/ocaml/Makefile index eaa8e382..ce932bfc 100644 --- a/ocaml/Makefile +++ b/ocaml/Makefile @@ -35,7 +35,7 @@ default: $(ALL_TESTS) $(ALL_EXE) .gitignore executables: $(QPACKAGE_ROOT)/data/executables $(QPACKAGE_ROOT)/data/executables: - $(QPACKAGE_ROOT)/scripts/create_executables_list.sh + $(QPACKAGE_ROOT)/scripts/create/create_executables_list.sh external_libs: opam install cryptokit core diff --git a/ocaml/qp_create_ezfio_from_xyz.ml b/ocaml/qp_create_ezfio_from_xyz.ml index dfc9b4bd..6ec6e0d0 100644 --- a/ocaml/qp_create_ezfio_from_xyz.ml +++ b/ocaml/qp_create_ezfio_from_xyz.ml @@ -5,18 +5,20 @@ open Core.Std;; let spec = let open Command.Spec in empty - +> flag "o" (optional string) + +> flag "o" (optional string) ~doc:"file Name of the created EZFIO file." +> flag "b" (required string) ~doc:"string Name of basis set." +> flag "c" (optional_with_default 0 int) ~doc:"int Total charge of the molecule. Default is 0." - +> flag "m" (optional_with_default 1 int) + +> flag "m" (optional_with_default 1 int) ~doc:"int Spin multiplicity (2S+1) of the molecule. Default is 1." + +> flag "p" no_arg + ~doc:"Using pseudo." +> anon ("xyz_file" %: string) ;; -let run ?o b c m xyz_file = +let run ?o b c m p xyz_file = (* Read molecule *) let molecule = @@ -60,6 +62,10 @@ let run ?o b c m xyz_file = | None -> (* Principal basis *) let basis = elem_and_basis_name in let command = + if (p) then + Qpackage.root ^ "/scripts/get_basis.sh \"" ^ temp_filename + ^ "\" \"" ^ basis ^"\" pseudo" + else Qpackage.root ^ "/scripts/get_basis.sh \"" ^ temp_filename ^ "\" \"" ^ basis ^"\"" in @@ -246,7 +252,14 @@ let run ?o b c m xyz_file = Ezfio.set_ao_basis_ao_expo(Ezfio.ezfio_array_of_list ~rank:2 ~dim:[| ao_num ; ao_prim_num_max |] ~data:ao_expo) ; - + + (* Doesn't work... *) + if (p) then + begin + Qpackage.root ^ "/scripts/pseudo/put_pseudo_in_ezfio.py " ^ ezfio_file + |> Sys.command_exn + end; + match Input.Ao_basis.read () with | None -> failwith "Error in basis" | Some x -> Input.Ao_basis.write x @@ -266,8 +279,8 @@ elements can be defined as follows: ") spec - (fun o b c m xyz_file () -> - run ?o b c m xyz_file ) + (fun o b c m p xyz_file () -> + run ?o b c m p xyz_file ) ;; let () = diff --git a/scripts/.gitignore b/scripts/.gitignore index 52e4e611..e456a8d3 100644 --- a/scripts/.gitignore +++ b/scripts/.gitignore @@ -1,2 +1,3 @@ *.pyc *.pyo +docopt.py \ No newline at end of file diff --git a/scripts/check_dependencies.sh b/scripts/check_dependencies.sh deleted file mode 100755 index f21dbc40..00000000 --- a/scripts/check_dependencies.sh +++ /dev/null @@ -1,63 +0,0 @@ -#!/bin/bash -# -# usage: -# check_dependencies.sh MOs AOs Electrons -# -# Checks that the list of dependencies given in -# argument is consistent. If the dependencies -# are OK the exit code is 0, otherwise it is 1. -# If no argument is given, the dependencies are -# read in the Makefile. -# Thu Apr 3 01:44:23 CEST 2014 - -if [[ -z ${QPACKAGE_ROOT} ]] -then - print "The QPACKAGE_ROOT environment variable is not set." - print "Please reload the quantum_package.rc file." - exit -1 -fi -source ${QPACKAGE_ROOT}/scripts/qp_include.sh - -if [[ -z $1 ]] -then - exit 0 -fi - -if [[ $1 == "-" ]] -then - COMMAND_LINE=$(cat NEEDED_MODULES) -else - COMMAND_LINE=$(unique_list $@) -fi - -for d in $COMMAND_LINE -do - if [[ ! -d ${QPACKAGE_ROOT}/src/$d ]] - then - echo Error: Directory $d does not exist - exit 2 - fi - -done - -DEPS_LONG="" -for i in $COMMAND_LINE -do - DEPS_LONG+=" $i " - DEPS_LONG+=$(cat "${QPACKAGE_ROOT}/src/${i}/NEEDED_MODULES") -done - -DEPS=$(unique_list $DEPS_LONG) - -if [[ ! "$COMMAND_LINE" == "$DEPS" ]] -then - DEPS=$(${QPACKAGE_ROOT}/scripts/check_dependencies.sh ${DEPS}) -fi -echo "$DEPS" - -if [[ "$COMMAND_LINE" == "$DEPS" ]] -then - exit 0 -else - exit 1 -fi diff --git a/scripts/docopt.py b/scripts/docopt.py deleted file mode 100755 index 59830d53..00000000 --- a/scripts/docopt.py +++ /dev/null @@ -1,590 +0,0 @@ -"""Pythonic command-line interface parser that will make you smile. - - * http://docopt.org - * Repository and issue-tracker: https://github.com/docopt/docopt - * Licensed under terms of MIT license (see LICENSE-MIT) - * Copyright (c) 2013 Vladimir Keleshev, vladimir@keleshev.com - -""" -import sys -import re - - -__all__ = ['docopt'] -__version__ = '0.6.1' - - -class DocoptLanguageError(Exception): - - """Error in construction of usage-message by developer.""" - - -class DocoptExit(SystemExit): - - """Exit in case user invoked program with incorrect arguments.""" - - usage = '' - - def __init__(self, message=''): - SystemExit.__init__(self, (message + '\n' + self.usage).strip()) - - -class Pattern(object): - - def __eq__(self, other): - return repr(self) == repr(other) - - def __hash__(self): - return hash(repr(self)) - - def fix(self): - self.fix_identities() - self.fix_repeating_arguments() - return self - - def fix_identities(self, uniq=None): - """Make pattern-tree tips point to same object if they are equal.""" - if not hasattr(self, 'children'): - return self - uniq = list(set(self.flat())) if uniq is None else uniq - for i, child in enumerate(self.children): - if not hasattr(child, 'children'): - assert child in uniq - self.children[i] = uniq[uniq.index(child)] - else: - child.fix_identities(uniq) - - def fix_repeating_arguments(self): - """Fix elements that should accumulate/increment values.""" - either = [list(child.children) for child in transform(self).children] - for case in either: - for e in [child for child in case if case.count(child) > 1]: - if isinstance( - e, - Argument) or isinstance( - e, - Option) and e.argcount: - if e.value is None: - e.value = [] - elif not isinstance(e.value, list): - e.value = e.value.split() - if isinstance( - e, - Command) or isinstance( - e, - Option) and e.argcount == 0: - e.value = 0 - return self - - -def transform(pattern): - """Expand pattern into an (almost) equivalent one, but with single Either. - - Example: ((-a | -b) (-c | -d)) => (-a -c | -a -d | -b -c | -b -d) - Quirks: [-a] => (-a), (-a...) => (-a -a) - - """ - result = [] - groups = [[pattern]] - while groups: - children = groups.pop(0) - parents = [Required, Optional, OptionsShortcut, Either, OneOrMore] - if any(t in map(type, children) for t in parents): - child = [c for c in children if type(c) in parents][0] - children.remove(child) - if isinstance(child, Either): - for c in child.children: - groups.append([c] + children) - elif isinstance(child, OneOrMore): - groups.append(child.children * 2 + children) - else: - groups.append(child.children + children) - else: - result.append(children) - return Either(*[Required(*e) for e in result]) - - -class LeafPattern(Pattern): - - """Leaf/terminal node of a pattern tree.""" - - def __init__(self, name, value=None): - self.name, self.value = name, value - - def __repr__(self): - return '%s(%r, %r)' % (self.__class__.__name__, self.name, self.value) - - def flat(self, *types): - return [self] if not types or type(self) in types else [] - - def match(self, left, collected=None): - collected = [] if collected is None else collected - pos, match = self.single_match(left) - if match is None: - return False, left, collected - left_ = left[:pos] + left[pos + 1:] - same_name = [a for a in collected if a.name == self.name] - if type(self.value) in (int, list): - if isinstance(self.value, int): - increment = 1 - else: - increment = ([match.value] if isinstance(match.value, str) - else match.value) - if not same_name: - match.value = increment - return True, left_, collected + [match] - same_name[0].value += increment - return True, left_, collected - return True, left_, collected + [match] - - -class BranchPattern(Pattern): - - """Branch/inner node of a pattern tree.""" - - def __init__(self, *children): - self.children = list(children) - - def __repr__(self): - return '%s(%s)' % (self.__class__.__name__, - ', '.join(repr(a) for a in self.children)) - - def flat(self, *types): - if type(self) in types: - return [self] - return sum([child.flat(*types) for child in self.children], []) - - -class Argument(LeafPattern): - - def single_match(self, left): - for n, pattern in enumerate(left): - if isinstance(pattern, Argument): - return n, Argument(self.name, pattern.value) - return None, None - - @classmethod - def parse(class_, source): - name = re.findall('(<\S*?>)', source)[0] - value = re.findall('\[default: (.*)\]', source, flags=re.I) - return class_(name, value[0] if value else None) - - -class Command(Argument): - - def __init__(self, name, value=False): - self.name, self.value = name, value - - def single_match(self, left): - for n, pattern in enumerate(left): - if isinstance(pattern, Argument): - if pattern.value == self.name: - return n, Command(self.name, True) - else: - break - return None, None - - -class Option(LeafPattern): - - def __init__(self, short=None, long=None, argcount=0, value=False): - assert argcount in (0, 1) - self.short, self.long, self.argcount = short, long, argcount - self.value = None if value is False and argcount else value - - @classmethod - def parse(class_, option_description): - short, long, argcount, value = None, None, 0, False - options, _, description = option_description.strip().partition(' ') - options = options.replace(',', ' ').replace('=', ' ') - for s in options.split(): - if s.startswith('--'): - long = s - elif s.startswith('-'): - short = s - else: - argcount = 1 - if argcount: - matched = re.findall('\[default: (.*)\]', description, flags=re.I) - value = matched[0] if matched else None - return class_(short, long, argcount, value) - - def single_match(self, left): - for n, pattern in enumerate(left): - if self.name == pattern.name: - return n, pattern - return None, None - - @property - def name(self): - return self.long or self.short - - def __repr__(self): - return 'Option(%r, %r, %r, %r)' % (self.short, self.long, - self.argcount, self.value) - - -class Required(BranchPattern): - - def match(self, left, collected=None): - collected = [] if collected is None else collected - l = left - c = collected - for pattern in self.children: - matched, l, c = pattern.match(l, c) - if not matched: - return False, left, collected - return True, l, c - - -class Optional(BranchPattern): - - def match(self, left, collected=None): - collected = [] if collected is None else collected - for pattern in self.children: - m, left, collected = pattern.match(left, collected) - return True, left, collected - - -class OptionsShortcut(Optional): - - """Marker/placeholder for [options] shortcut.""" - - -class OneOrMore(BranchPattern): - - def match(self, left, collected=None): - assert len(self.children) == 1 - collected = [] if collected is None else collected - l = left - c = collected - l_ = None - matched = True - times = 0 - while matched: - # could it be that something didn't match but changed l or c? - matched, l, c = self.children[0].match(l, c) - times += 1 if matched else 0 - if l_ == l: - break - l_ = l - if times >= 1: - return True, l, c - return False, left, collected - - -class Either(BranchPattern): - - def match(self, left, collected=None): - collected = [] if collected is None else collected - outcomes = [] - for pattern in self.children: - matched, _, _ = outcome = pattern.match(left, collected) - if matched: - outcomes.append(outcome) - if outcomes: - return min(outcomes, key=lambda outcome: len(outcome[1])) - return False, left, collected - - -class Tokens(list): - - def __init__(self, source, error=DocoptExit): - self += source.split() if hasattr(source, 'split') else source - self.error = error - - @staticmethod - def from_pattern(source): - source = re.sub(r'([\[\]\(\)\|]|\.\.\.)', r' \1 ', source) - source = [s for s in re.split('\s+|(\S*<.*?>)', source) if s] - return Tokens(source, error=DocoptLanguageError) - - def move(self): - return self.pop(0) if len(self) else None - - def current(self): - return self[0] if len(self) else None - - -def parse_long(tokens, options): - """long ::= '--' chars [ ( ' ' | '=' ) chars ] ;""" - long, eq, value = tokens.move().partition('=') - assert long.startswith('--') - value = None if eq == value == '' else value - similar = [o for o in options if o.long == long] - if tokens.error is DocoptExit and similar == []: # if no exact match - similar = [o for o in options if o.long and o.long.startswith(long)] - if len(similar) > 1: # might be simply specified ambiguously 2+ times? - raise tokens.error('%s is not a unique prefix: %s?' % - (long, ', '.join(o.long for o in similar))) - elif len(similar) < 1: - argcount = 1 if eq == '=' else 0 - o = Option(None, long, argcount) - options.append(o) - if tokens.error is DocoptExit: - o = Option(None, long, argcount, value if argcount else True) - else: - o = Option(similar[0].short, similar[0].long, - similar[0].argcount, similar[0].value) - if o.argcount == 0: - if value is not None: - raise tokens.error('%s must not have an argument' % o.long) - else: - if value is None: - if tokens.current() in [None, '--']: - raise tokens.error('%s requires argument' % o.long) - value = tokens.move() - if tokens.error is DocoptExit: - o.value = value if value is not None else True - return [o] - - -def parse_shorts(tokens, options): - """shorts ::= '-' ( chars )* [ [ ' ' ] chars ] ;""" - token = tokens.move() - assert token.startswith('-') and not token.startswith('--') - left = token.lstrip('-') - parsed = [] - while left != '': - short, left = '-' + left[0], left[1:] - similar = [o for o in options if o.short == short] - if len(similar) > 1: - raise tokens.error('%s is specified ambiguously %d times' % - (short, len(similar))) - elif len(similar) < 1: - o = Option(short, None, 0) - options.append(o) - if tokens.error is DocoptExit: - o = Option(short, None, 0, True) - else: # why copying is necessary here? - o = Option(short, similar[0].long, - similar[0].argcount, similar[0].value) - value = None - if o.argcount != 0: - if left == '': - if tokens.current() in [None, '--']: - raise tokens.error('%s requires argument' % short) - value = tokens.move() - else: - value = left - left = '' - if tokens.error is DocoptExit: - o.value = value if value is not None else True - parsed.append(o) - return parsed - - -def parse_pattern(source, options): - tokens = Tokens.from_pattern(source) - result = parse_expr(tokens, options) - if tokens.current() is not None: - raise tokens.error('unexpected ending: %r' % ' '.join(tokens)) - return Required(*result) - - -def parse_expr(tokens, options): - """expr ::= seq ( '|' seq )* ;""" - seq = parse_seq(tokens, options) - if tokens.current() != '|': - return seq - result = [Required(*seq)] if len(seq) > 1 else seq - while tokens.current() == '|': - tokens.move() - seq = parse_seq(tokens, options) - result += [Required(*seq)] if len(seq) > 1 else seq - return [Either(*result)] if len(result) > 1 else result - - -def parse_seq(tokens, options): - """seq ::= ( atom [ '...' ] )* ;""" - result = [] - while tokens.current() not in [None, ']', ')', '|']: - atom = parse_atom(tokens, options) - if tokens.current() == '...': - atom = [OneOrMore(*atom)] - tokens.move() - result += atom - return result - - -def parse_atom(tokens, options): - """atom ::= '(' expr ')' | '[' expr ']' | 'options' - | long | shorts | argument | command ; - """ - token = tokens.current() - result = [] - if token in '([': - tokens.move() - matching, pattern = {'(': [')', Required], '[': [']', Optional]}[token] - result = pattern(*parse_expr(tokens, options)) - if tokens.move() != matching: - raise tokens.error("unmatched '%s'" % token) - return [result] - elif token == 'options': - tokens.move() - return [OptionsShortcut()] - elif token.startswith('--') and token != '--': - return parse_long(tokens, options) - elif token.startswith('-') and token not in ('-', '--'): - return parse_shorts(tokens, options) - elif token.startswith('<') and token.endswith('>') or token.isupper(): - return [Argument(tokens.move())] - else: - return [Command(tokens.move())] - - -def parse_argv(tokens, options, options_first=False): - """Parse command-line argument vector. - - If options_first: - argv ::= [ long | shorts ]* [ argument ]* [ '--' [ argument ]* ] ; - else: - argv ::= [ long | shorts | argument ]* [ '--' [ argument ]* ] ; - - """ - parsed = [] - while tokens.current() is not None: - if tokens.current() == '--': - return parsed + [Argument(None, v) for v in tokens] - elif tokens.current().startswith('--'): - parsed += parse_long(tokens, options) - elif tokens.current().startswith('-') and tokens.current() != '-': - parsed += parse_shorts(tokens, options) - elif options_first: - return parsed + [Argument(None, v) for v in tokens] - else: - parsed.append(Argument(None, tokens.move())) - return parsed - - -def parse_defaults(doc): - defaults = [] - for s in parse_section('options:', doc): - # FIXME corner case "bla: options: --foo" - _, _, s = s.partition(':') # get rid of "options:" - split = re.split('\n[ \t]*(-\S+?)', '\n' + s)[1:] - split = [s1 + s2 for s1, s2 in zip(split[::2], split[1::2])] - options = [Option.parse(s) for s in split if s.startswith('-')] - defaults += options - return defaults - - -def parse_section(name, source): - pattern = re.compile('^([^\n]*' + name + '[^\n]*\n?(?:[ \t].*?(?:\n|$))*)', - re.IGNORECASE | re.MULTILINE) - return [s.strip() for s in pattern.findall(source)] - - -def formal_usage(section): - _, _, section = section.partition(':') # drop "usage:" - pu = section.split() - return '( ' + ' '.join(') | (' if s == pu[0] else s for s in pu[1:]) + ' )' - - -def extras(help, version, options, doc): - if help and any((o.name in ('-h', '--help')) and o.value for o in options): - print(doc.strip("\n")) - sys.exit() - if version and any(o.name == '--version' and o.value for o in options): - print(version) - sys.exit() - - -class Dict(dict): - - def __repr__(self): - return '{%s}' % ',\n '.join('%r: %r' % i for i in sorted(self.items())) - - -def docopt(doc, argv=None, help=True, version=None, options_first=False): - """Parse `argv` based on command-line interface described in `doc`. - - `docopt` creates your command-line interface based on its - description that you pass as `doc`. Such description can contain - --options, , commands, which could be - [optional], (required), (mutually | exclusive) or repeated... - - Parameters - ---------- - doc : str - Description of your command-line interface. - argv : list of str, optional - Argument vector to be parsed. sys.argv[1:] is used if not - provided. - help : bool (default: True) - Set to False to disable automatic help on -h or --help - options. - version : any object - If passed, the object will be printed if --version is in - `argv`. - options_first : bool (default: False) - Set to True to require options precede positional arguments, - i.e. to forbid options and positional arguments intermix. - - Returns - ------- - args : dict - A dictionary, where keys are names of command-line elements - such as e.g. "--verbose" and "", and values are the - parsed values of those elements. - - Example - ------- - >>> from docopt import docopt - >>> doc = ''' - ... Usage: - ... my_program tcp [--timeout=] - ... my_program serial [--baud=] [--timeout=] - ... my_program (-h | --help | --version) - ... - ... Options: - ... -h, --help Show this screen and exit. - ... --baud= Baudrate [default: 9600] - ... ''' - >>> argv = ['tcp', '127.0.0.1', '80', '--timeout', '30'] - >>> docopt(doc, argv) - {'--baud': '9600', - '--help': False, - '--timeout': '30', - '--version': False, - '': '127.0.0.1', - '': '80', - 'serial': False, - 'tcp': True} - - See also - -------- - * For video introduction see http://docopt.org - * Full documentation is available in README.rst as well as online - at https://github.com/docopt/docopt#readme - - """ - argv = sys.argv[1:] if argv is None else argv - - usage_sections = parse_section('usage:', doc) - if len(usage_sections) == 0: - raise DocoptLanguageError('"usage:" (case-insensitive) not found.') - if len(usage_sections) > 1: - raise DocoptLanguageError('More than one "usage:" (case-insensitive).') - DocoptExit.usage = usage_sections[0] - - options = parse_defaults(doc) - pattern = parse_pattern(formal_usage(DocoptExit.usage), options) - # [default] syntax for argument is disabled - # for a in pattern.flat(Argument): - # same_name = [d for d in arguments if d.name == a.name] - # if same_name: - # a.value = same_name[0].value - argv = parse_argv(Tokens(argv), list(options), options_first) - pattern_options = set(pattern.flat(Option)) - for options_shortcut in pattern.flat(OptionsShortcut): - doc_options = parse_defaults(doc) - options_shortcut.children = list(set(doc_options) - pattern_options) - # if any_options: - # options_shortcut.children += [Option(o.short, o.long, o.argcount) - # for o in argv if type(o) is Option] - extras(help, version, argv, doc) - matched, left, collected = pattern.fix().match(argv) - if matched and left == []: # better error message if left? - return Dict((a.name, a.value) for a in (pattern.flat() + collected)) - raise DocoptExit() diff --git a/scripts/ezfio_interface/ei_handler.py b/scripts/ezfio_interface/ei_handler.py index 6d18d071..4667478f 100755 --- a/scripts/ezfio_interface/ei_handler.py +++ b/scripts/ezfio_interface/ei_handler.py @@ -62,6 +62,9 @@ import ConfigParser from collections import defaultdict from collections import namedtuple + +from qp_utils import cache + Type = namedtuple('Type', 'fancy ocaml fortran') @@ -78,6 +81,7 @@ def is_bool(str_): raise TypeError +@cache def get_type_dict(): """ This function makes the correspondance between the type of value read in @@ -89,17 +93,7 @@ def get_type_dict(): # ~#~#~#~#~ # # 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/ezfio_interface/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 # @@ -148,9 +142,7 @@ def get_type_dict(): b = r.find('let untouched = "') e = r.find(';;', b) - l_un = [ - i for i in r[ - b:e].splitlines() if i.strip().startswith("module")] + l_un = [i for i in r[b:e].splitlines() if i.strip().startswith("module")] # ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~ # # q p _ t y p e s _ g e n e r a t e # @@ -174,9 +166,6 @@ def get_type_dict(): # ~#~#~#~#~#~#~#~ # # F i n a l i z e # # ~#~#~#~#~#~#~#~ # - - pickle.dump(dict(fancy_type), open(fancy_type_pickle, "wb")) - return dict(fancy_type) diff --git a/scripts/prepare_ezfio.sh b/scripts/ezfio_interface/prepare_ezfio.sh similarity index 100% rename from scripts/prepare_ezfio.sh rename to scripts/ezfio_interface/prepare_ezfio.sh diff --git a/scripts/ezfio_interface/qp_convert_output_to_ezfio.py b/scripts/ezfio_interface/qp_convert_output_to_ezfio.py index 6b5c5fcd..400def37 100755 --- a/scripts/ezfio_interface/qp_convert_output_to_ezfio.py +++ b/scripts/ezfio_interface/qp_convert_output_to_ezfio.py @@ -105,7 +105,7 @@ def write_ezfio(res, filename): # Transformt H1 into H import re p = re.compile(ur'(\d*)$') - label = [p.sub("", x.name) for x in res.geometry] + label = [p.sub("", x.name).capitalize() for x in res.geometry] ezfio.set_nuclei_nucl_label(label) ezfio.set_nuclei_nucl_coord(coord_x + coord_y + coord_z) @@ -265,6 +265,16 @@ def write_ezfio(res, filename): ezfio.set_mo_basis_mo_occ(OccNum) ezfio.set_mo_basis_mo_coef(MoMatrix) + # ______ _ + # | ___ \ | | + # | |_/ /__ ___ _ _ __| | ___ + # | __/ __|/ _ \ | | |/ _` |/ _ \ + # | | \__ \ __/ |_| | (_| | (_) | + # \_| |___/\___|\__,_|\__,_|\___/ + # + + ezfio.set_pseudo_integrals_do_pseudo(False) + def get_full_path(file_path): file_path = os.path.expanduser(file_path) diff --git a/scripts/ezfio_interface/upgrade_1.0_2.0.sh b/scripts/ezfio_interface/upgrade_1.0_2.0.sh new file mode 100755 index 00000000..ec0ab770 --- /dev/null +++ b/scripts/ezfio_interface/upgrade_1.0_2.0.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# Convert a old ezfio file (with option.irp.f ezfio_default) +# into a new EZFIO.cfg type + +# Hartree Fock +# Changin the case, don't know if is needed or not +mv $1/Hartree_Fock $1/hartree_fock 2> /dev/null + +mv $1/hartree_Fock/thresh_SCF $1/hartree_fock/thresh_scf 2> /dev/null + +# BiInts +mv $1/bi_integrals $1/bielect_integrals 2> /dev/null + +if [ -f $1/bielect_integrals/read_ao_integrals ]; then + if [ `cat $1/bielect_integrals/read_ao_integrals` -eq "True" ] + then + echo "Read" > $1/bielect_integrals/disk_access_ao_integrals + + elif [ `cat bielect_integrals/write_ao_integrals` -eq "True" ] + then + echo "Write" > $1/bielect_integrals/disk_access_ao_integrals + + else + echo "None" > $1/bielect_integrals/disk_access_ao_integrals + + fi +fi \ No newline at end of file diff --git a/scripts/generate_h_apply.py b/scripts/generate_h_apply.py index 072a8f1e..0c680e3a 100755 --- a/scripts/generate_h_apply.py +++ b/scripts/generate_h_apply.py @@ -141,7 +141,7 @@ class H_apply(object): def set_filter_2h_2p(self): self["filter2h2p"] = """ ! ! DIR$ FORCEINLINE - if(is_a_two_holes_two_particles(key))cycle + if (is_a_two_holes_two_particles(key)) cycle """ diff --git a/scripts/get_basis.sh b/scripts/get_basis.sh index 51b0a4f0..a2f07e4e 100755 --- a/scripts/get_basis.sh +++ b/scripts/get_basis.sh @@ -42,9 +42,14 @@ then echo "ERROR" exit 1 fi -${EMSL_API_ROOT}/EMSL_api.py get_basis_data --treat_l --save --path="${tmpfile}" --basis="${basis}" $atoms - - +pseudo="$1" +shift +if [[ -z $pseudo ]] +then + ${EMSL_API_ROOT}/EMSL_api.py get_basis_data --treat_l --save --path="${tmpfile}" --basis="${basis}" +else + ${EMSL_API_ROOT}/EMSL_api.py get_basis_data --save --path="${tmpfile}" --basis="${basis}" --db_path="${EMSL_API_ROOT}/db/Pseudo.db" +fi diff --git a/scripts/install_curl.sh b/scripts/install/install_curl.sh similarity index 83% rename from scripts/install_curl.sh rename to scripts/install/install_curl.sh index 20033f77..b2e47481 100755 --- a/scripts/install_curl.sh +++ b/scripts/install/install_curl.sh @@ -8,8 +8,8 @@ CURL_URL="http://qmcchem.ups-tlse.fr/files/scemama/${CURL}.tar.bz2" if [[ -z ${QPACKAGE_ROOT} ]] then - print "The QPACKAGE_ROOT environment variable is not set." - print "Please reload the quantum_package.rc file." + echo "The QPACKAGE_ROOT environment variable is not set." + echo "Please reload the quantum_package.rc file." exit -1 fi diff --git a/scripts/install/install_docopt.sh b/scripts/install/install_docopt.sh new file mode 100755 index 00000000..6f799c47 --- /dev/null +++ b/scripts/install/install_docopt.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# +# Installs docopt +# lundi 27 avril 2015, 16:51:34 (UTC+0200) + +DOCOPT="docopt.py" +DOCOPT_URL="https://raw.githubusercontent.com/docopt/docopt/master/${DOCOPT}" + +if [[ -z ${QPACKAGE_ROOT} ]] +then + echo "The QPACKAGE_ROOT environment variable is not set." + echo "Please reload the quantum_package.rc file." + exit -1 +fi + +cd ${QPACKAGE_ROOT} + +rm -f -- scripts/${DOCOPT}{,c} +${QPACKAGE_ROOT}/scripts/fetch_from_web.py ${DOCOPT_URL} ${DOCOPT} + +mv ${DOCOPT} scripts/${DOCOPT} \ No newline at end of file diff --git a/scripts/install_emsl.sh b/scripts/install/install_emsl.sh similarity index 79% rename from scripts/install_emsl.sh rename to scripts/install/install_emsl.sh index dff002a1..b01afb6e 100755 --- a/scripts/install_emsl.sh +++ b/scripts/install/install_emsl.sh @@ -8,8 +8,8 @@ URL="https://github.com/LCPQ/${BASE}/archive/master.tar.gz" if [[ -z ${QPACKAGE_ROOT} ]] then - print "The QPACKAGE_ROOT environment variable is not set." - print "Please reload the quantum_package.rc file." + echo "The QPACKAGE_ROOT environment variable is not set." + echo "Please reload the quantum_package.rc file." exit -1 fi diff --git a/scripts/install_ezfio.sh b/scripts/install/install_ezfio.sh similarity index 77% rename from scripts/install_ezfio.sh rename to scripts/install/install_ezfio.sh index 0f7a6505..c0033ca8 100755 --- a/scripts/install_ezfio.sh +++ b/scripts/install/install_ezfio.sh @@ -8,8 +8,8 @@ URL="https://github.com/LCPQ/${BASE}/archive/master.tar.gz" if [[ -z ${QPACKAGE_ROOT} ]] then - print "The QPACKAGE_ROOT environment variable is not set." - print "Please reload the quantum_package.rc file." + echo "The QPACKAGE_ROOT environment variable is not set." + echo "Please reload the quantum_package.rc file." exit -1 fi diff --git a/scripts/install_irpf90.sh b/scripts/install/install_irpf90.sh similarity index 100% rename from scripts/install_irpf90.sh rename to scripts/install/install_irpf90.sh diff --git a/scripts/install_m4.sh b/scripts/install/install_m4.sh similarity index 100% rename from scripts/install_m4.sh rename to scripts/install/install_m4.sh diff --git a/scripts/install_ocaml.sh b/scripts/install/install_ocaml.sh similarity index 100% rename from scripts/install_ocaml.sh rename to scripts/install/install_ocaml.sh diff --git a/scripts/install_resultsFile.sh b/scripts/install/install_resultsFile.sh similarity index 95% rename from scripts/install_resultsFile.sh rename to scripts/install/install_resultsFile.sh index 4b5debc0..6f279ffa 100755 --- a/scripts/install_resultsFile.sh +++ b/scripts/install/install_resultsFile.sh @@ -16,6 +16,7 @@ fi cd ${QPACKAGE_ROOT} +rm -rf resultsFile-master ${QPACKAGE_ROOT}/scripts/fetch_from_web.py ${URL} ${QPACKAGE_ROOT}/resultsFile.tar.gz tar -zxf resultsFile.tar.gz && rm resultsFile.tar.gz ||exit 1 mv resultsFile-master resultsFile diff --git a/scripts/install_zlib.sh b/scripts/install/install_zlib.sh similarity index 100% rename from scripts/install_zlib.sh rename to scripts/install/install_zlib.sh diff --git a/scripts/build_modules.sh b/scripts/module/build_modules.sh similarity index 84% rename from scripts/build_modules.sh rename to scripts/module/build_modules.sh index c3e0cda5..1b69a920 100755 --- a/scripts/build_modules.sh +++ b/scripts/module/build_modules.sh @@ -30,7 +30,7 @@ Build failed for module $MODULE " fi fi - ${QPACKAGE_ROOT}/scripts/create_gitignore.sh + ${QPACKAGE_ROOT}/scripts/module/create_gitignore.sh cd ${OLDPWD} done -${QPACKAGE_ROOT}/scripts/create_executables_list.sh +${QPACKAGE_ROOT}/scripts/module/create_executables_list.sh diff --git a/scripts/clean_modules.sh b/scripts/module/clean_modules.sh similarity index 81% rename from scripts/clean_modules.sh rename to scripts/module/clean_modules.sh index 452724f2..a11deb70 100755 --- a/scripts/clean_modules.sh +++ b/scripts/module/clean_modules.sh @@ -13,8 +13,11 @@ source ${QPACKAGE_ROOT}/scripts/qp_include.sh function do_clean() { rm -rf -- \ - IRPF90_temp IRPF90_man Makefile.depend $(cat NEEDED_MODULES) include \ + IRPF90_temp IRPF90_man Makefile.depend \ + $(module_handler.py print_genealogy) include \ ezfio_interface.irp.f irpf90.make irpf90_entities tags $(ls_exe) *.mod + + touch -c EZFIO.cfg *.ezfio_config } if [[ -z $1 ]] diff --git a/scripts/create_Makefile.sh b/scripts/module/create_Makefile.sh similarity index 100% rename from scripts/create_Makefile.sh rename to scripts/module/create_Makefile.sh diff --git a/scripts/create_Makefile_depend.sh b/scripts/module/create_Makefile_depend.sh similarity index 100% rename from scripts/create_Makefile_depend.sh rename to scripts/module/create_Makefile_depend.sh diff --git a/scripts/create_Needed_modules.sh b/scripts/module/create_Needed_modules.sh similarity index 77% rename from scripts/create_Needed_modules.sh rename to scripts/module/create_Needed_modules.sh index 026eadab..61ea5839 100755 --- a/scripts/create_Needed_modules.sh +++ b/scripts/module/create_Needed_modules.sh @@ -14,7 +14,9 @@ source ${QPACKAGE_ROOT}/scripts/qp_include.sh check_current_dir_is_module -OUTPUT=$(${QPACKAGE_ROOT}/scripts/check_dependencies.sh $@) -echo ${OUTPUT} > NEEDED_MODULES - +OUTPUT=$(module_handler.py check_dependencies $@) +if [[ $? -eq 0 ]] +then + echo $@ > NEEDED_CHILDREN_MODULES +fi \ No newline at end of file diff --git a/scripts/create_executables_list.sh b/scripts/module/create_executables_list.sh similarity index 100% rename from scripts/create_executables_list.sh rename to scripts/module/create_executables_list.sh diff --git a/scripts/create_gitignore.sh b/scripts/module/create_gitignore.sh similarity index 100% rename from scripts/create_gitignore.sh rename to scripts/module/create_gitignore.sh diff --git a/scripts/create_rst_templates.sh b/scripts/module/create_rst_templates.sh similarity index 100% rename from scripts/create_rst_templates.sh rename to scripts/module/create_rst_templates.sh diff --git a/scripts/module/module_handler.py b/scripts/module/module_handler.py new file mode 100755 index 00000000..a35dbe2c --- /dev/null +++ b/scripts/module/module_handler.py @@ -0,0 +1,185 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +Create the NEEDED_MODULE + aka the genealogy (children module, subchildren module and so on), +of a NEEDED_CHILDREN_MODULES file + +Usage: + module_handler.py print_genealogy [] + module_handler.py check_dependencies [...] + module_handler.py create_png [] + +Options: + print_genealogy Print the genealogy of the NEEDED_CHILDREN_MODULES + aka (children, subchildren, etc) + create_png Create a png of the file + NEEDED_CHILDREN_MODULES The path of NEEDED_CHILDREN_MODULES + by default try to open the file in the current path +""" + +from docopt import docopt + +import os +import sys +import os.path +from qp_utils import cache + + +@cache +def get_dict_genealogy(): + """Loop over MODULE in QPACKAGE_ROOT/src, open all the NEEDED_CHILDREN_MODULES + and create a dict[MODULE] = [sub module needed, ...] + """ + d_ref = dict() + + qpackage_root = os.environ['QPACKAGE_ROOT'] + dir_ = os.path.join(qpackage_root, 'src') + + for o in os.listdir(dir_): + + try: + with open(os.path.join(dir_, o, "NEEDED_CHILDREN_MODULES"), "r") as f: + l_children = f.read().split() + except IOError: + pass + else: + d_ref[o] = l_children + + return d_ref + + +def module_genealogy(path): + """ + Take a name of a NEEDED_CHILDREN_MODULES + and return a list of all the {sub, subsub, ...}children + """ + try: + with open(path, "r") as f: + l_children = f.read().split() + except IOError as e: + print >> sys.stderr, e + sys.exit(1) + else: + + needed_module = get_it_and_children(l_children) + + return needed_module + + +def get_it_and_children(l_module): + """ + From a list of module return the module and all of the genealogy + """ + d_ref = get_dict_genealogy() + + l = [] + for module in l_module: + if module not in l: + l.append(module) + try: + l.extend(get_it_and_children(d_ref[module])) + except KeyError: + print >> sys.stderr, "`{0}` in not a good submodule name".format(module) + print >> sys.stderr, "Check the corresponding NEEDED_CHILDREN_MODULES" + sys.exit(1) + + return list(set(l)) + + +def get_all_children(l_module): + """ + From a list of module return all the genealogy + """ + + it_and_all = get_it_and_children(l_module) + return [children for children in it_and_all if children not in l_module] + + +def reduce_(l_module): + """ + Take a l_module and try to find the lower combinaitions + of module with the same genealogy + """ + import itertools + d_ref = get_dict_genealogy() + + target_genealogy = sorted(get_all_children(l_module)) + + for i in xrange(len(d_ref)): + for c in itertools.combinations(d_ref, i): + + guess_genealogy = sorted(get_it_and_children(d_ref, c)) + + if target_genealogy == guess_genealogy: + return c + + +def create_png_from_path(path): + " Change a path like this into a module list" + "path = /home/razoa/quantum_package/src/Molden/NEEDED_CHILDREN_MODULES" + + l_module = os.path.split(path)[0].split("/")[-1] + create_png([l_module]) + + +def create_png(l_module): + """Create the png of the dependancy tree for a l_module""" + + # Init + import pydot + all_ready_done = [] + + def draw_module_edge(module, l_children): + "Draw all the module recursifly" + + if module not in all_ready_done: + for children in l_children: + # Add Edge + edge = pydot.Edge(module, children) + graph.add_edge(edge) + # Recurs + draw_module_edge(children, d_ref[children]) + all_ready_done.append(module) + + # Init + graph = pydot.Dot(graph_type='digraph') + d_ref = get_dict_genealogy() + + # Create all the edge + for module in l_module: + node_a = pydot.Node(module, fontcolor="red") + graph.add_node(node_a) + draw_module_edge(module, d_ref[module]) + + # Save + path = '{0}.png'.format("_".join(l_module)) + print "png saved in {0}".format(path) + graph.write_png(path) + +if __name__ == '__main__': + + arguments = docopt(__doc__) + + if not arguments['']: + dir_ = os.getcwd() + path = os.path.join(dir_, "NEEDED_CHILDREN_MODULES") + else: + path = os.path.abspath(arguments['']) + path = os.path.expanduser(path) + path = os.path.expandvars(path) + + if arguments['print_genealogy']: + l_all_needed_molule = module_genealogy(path) + print " ".join(sorted(l_all_needed_molule)) + + elif arguments["check_dependencies"]: + l_module = arguments[''] + if l_module: + l_all_needed_molule = get_it_and_children(l_module) + else: + l_all_needed_molule = module_genealogy(path) + + elif arguments["create_png"]: + create_png_from_path(path) diff --git a/scripts/module/pydot.py b/scripts/module/pydot.py new file mode 100644 index 00000000..c788c137 --- /dev/null +++ b/scripts/module/pydot.py @@ -0,0 +1,2125 @@ +# -*- coding: Latin-1 -*- +"""Graphviz's dot language Python interface. + +This module provides with a full interface to create handle modify +and process graphs in Graphviz's dot language. + +References: + +pydot Homepage: http://code.google.com/p/pydot/ +Graphviz: http://www.graphviz.org/ +DOT Language: http://www.graphviz.org/doc/info/lang.html + +Programmed and tested with Graphviz 2.26.3 and Python 2.6 on OSX 10.6.4 + +Copyright (c) 2005-2011 Ero Carrera + +Distributed under MIT license [http://opensource.org/licenses/mit-license.html]. +""" + +__author__ = 'Ero Carrera' +__version__ = '1.0.*' +__license__ = 'MIT' + +import os +import re +import subprocess +import tempfile +import copy +import sys + +try: + import dot_parser +except Exception as e: + print >> sys.stderr, "Couldn't import dot_parser, loading of dot files will not be possible." + + +GRAPH_ATTRIBUTES = set(['Damping', 'K', 'URL', 'aspect', 'bb', 'bgcolor', + 'center', 'charset', 'clusterrank', 'colorscheme', 'comment', 'compound', + 'concentrate', 'defaultdist', 'dim', 'dimen', 'diredgeconstraints', + 'dpi', 'epsilon', 'esep', 'fontcolor', 'fontname', 'fontnames', + 'fontpath', 'fontsize', 'id', 'label', 'labeljust', 'labelloc', + 'landscape', 'layers', 'layersep', 'layout', 'levels', 'levelsgap', + 'lheight', 'lp', 'lwidth', 'margin', 'maxiter', 'mclimit', 'mindist', + 'mode', 'model', 'mosek', 'nodesep', 'nojustify', 'normalize', 'nslimit', + 'nslimit1', 'ordering', 'orientation', 'outputorder', 'overlap', + 'overlap_scaling', 'pack', 'packmode', 'pad', 'page', 'pagedir', + 'quadtree', 'quantum', 'rankdir', 'ranksep', 'ratio', 'remincross', + 'repulsiveforce', 'resolution', 'root', 'rotate', 'searchsize', 'sep', + 'showboxes', 'size', 'smoothing', 'sortv', 'splines', 'start', + 'stylesheet', 'target', 'truecolor', 'viewport', 'voro_margin', + # for subgraphs + 'rank']) + + +EDGE_ATTRIBUTES = set(['URL', + 'arrowhead', + 'arrowsize', + 'arrowtail', + 'color', + 'colorscheme', + 'comment', + 'constraint', + 'decorate', + 'dir', + 'edgeURL', + 'edgehref', + 'edgetarget', + 'edgetooltip', + 'fontcolor', + 'fontname', + 'fontsize', + 'headURL', + 'headclip', + 'headhref', + 'headlabel', + 'headport', + 'headtarget', + 'headtooltip', + 'href', + 'id', + 'label', + 'labelURL', + 'labelangle', + 'labeldistance', + 'labelfloat', + 'labelfontcolor', + 'labelfontname', + 'labelfontsize', + 'labelhref', + 'labeltarget', + 'labeltooltip', + 'layer', + 'len', + 'lhead', + 'lp', + 'ltail', + 'minlen', + 'nojustify', + 'penwidth', + 'pos', + 'samehead', + 'sametail', + 'showboxes', + 'style', + 'tailURL', + 'tailclip', + 'tailhref', + 'taillabel', + 'tailport', + 'tailtarget', + 'tailtooltip', + 'target', + 'tooltip', + 'weight', + 'rank']) + + +NODE_ATTRIBUTES = set(['URL', 'color', 'colorscheme', 'comment', + 'distortion', 'fillcolor', 'fixedsize', 'fontcolor', 'fontname', + 'fontsize', 'group', 'height', 'id', 'image', 'imagescale', 'label', + 'labelloc', 'layer', 'margin', 'nojustify', 'orientation', 'penwidth', + 'peripheries', 'pin', 'pos', 'rects', 'regular', 'root', 'samplepoints', + 'shape', 'shapefile', 'showboxes', 'sides', 'skew', 'sortv', 'style', + 'target', 'tooltip', 'vertices', 'width', 'z', + # The following are attributes dot2tex + 'texlbl', 'texmode']) + + +CLUSTER_ATTRIBUTES = set(['K', + 'URL', + 'bgcolor', + 'color', + 'colorscheme', + 'fillcolor', + 'fontcolor', + 'fontname', + 'fontsize', + 'label', + 'labeljust', + 'labelloc', + 'lheight', + 'lp', + 'lwidth', + 'nojustify', + 'pencolor', + 'penwidth', + 'peripheries', + 'sortv', + 'style', + 'target', + 'tooltip']) + + +# +# Extented version of ASPN's Python Cookbook Recipe: +# Frozen dictionaries. +# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/414283 +# +# This version freezes dictionaries used as values within dictionaries. +# +class frozendict(dict): + + def _blocked_attribute(obj): + raise AttributeError("A frozendict cannot be modified.") + _blocked_attribute = property(_blocked_attribute) + + __delitem__ = __setitem__ = clear = _blocked_attribute + pop = popitem = setdefault = update = _blocked_attribute + + def __new__(cls, *args, **kw): + new = dict.__new__(cls) + + args_ = [] + for arg in args: + if isinstance(arg, dict): + arg = copy.copy(arg) + for k, v in arg.iteritems(): + if isinstance(v, frozendict): + arg[k] = v + elif isinstance(v, dict): + arg[k] = frozendict(v) + elif isinstance(v, list): + v_ = list() + for elm in v: + if isinstance(elm, dict): + v_.append(frozendict(elm)) + else: + v_.append(elm) + arg[k] = tuple(v_) + args_.append(arg) + else: + args_.append(arg) + + dict.__init__(new, *args_, **kw) + return new + + def __init__(self, *args, **kw): + pass + + def __hash__(self): + try: + return self._cached_hash + except AttributeError: + h = self._cached_hash = hash(tuple(sorted(self.iteritems()))) + return h + + def __repr__(self): + return "frozendict(%s)" % dict.__repr__(self) + + +dot_keywords = ['graph', 'subgraph', 'digraph', 'node', 'edge', 'strict'] + +id_re_alpha_nums = re.compile('^[_a-zA-Z][a-zA-Z0-9_,]*$', re.UNICODE) +id_re_alpha_nums_with_ports = re.compile( + '^[_a-zA-Z][a-zA-Z0-9_,:\"]*[a-zA-Z0-9_,\"]+$', + re.UNICODE) +id_re_num = re.compile('^[0-9,]+$', re.UNICODE) +id_re_with_port = re.compile('^([^:]*):([^:]*)$', re.UNICODE) +id_re_dbl_quoted = re.compile('^\".*\"$', re.S | re.UNICODE) +id_re_html = re.compile('^<.*>$', re.S | re.UNICODE) + + +def needs_quotes(s): + """Checks whether a string is a dot language ID. + + It will check whether the string is solely composed + by the characters allowed in an ID or not. + If the string is one of the reserved keywords it will + need quotes too but the user will need to add them + manually. + """ + + # If the name is a reserved keyword it will need quotes but pydot + # can't tell when it's being used as a keyword or when it's simply + # a name. Hence the user needs to supply the quotes when an element + # would use a reserved keyword as name. This function will return + # false indicating that a keyword string, if provided as-is, won't + # need quotes. + if s in dot_keywords: + return False + + chars = [ord(c) for c in s if ord(c) > 0x7f or ord(c) == 0] + if chars and not id_re_dbl_quoted.match(s) and not id_re_html.match(s): + return True + + for test_re in [ + id_re_alpha_nums, + id_re_num, + id_re_dbl_quoted, + id_re_html, + id_re_alpha_nums_with_ports]: + if test_re.match(s): + return False + + m = id_re_with_port.match(s) + if m: + return needs_quotes(m.group(1)) or needs_quotes(m.group(2)) + + return True + + +def quote_if_necessary(s): + + if isinstance(s, bool): + if s is True: + return 'True' + return 'False' + + if not isinstance(s, basestring): + return s + + if not s: + return s + + if needs_quotes(s): + replace = {'"': r'\"', + "\n": r'\n', + "\r": r'\r'} + for (a, b) in replace.items(): + s = s.replace(a, b) + + return '"' + s + '"' + + return s + + +def graph_from_dot_data(data): + """Load graph as defined by data in DOT format. + + The data is assumed to be in DOT format. It will + be parsed and a Dot class will be returned, + representing the graph. + """ + + return dot_parser.parse_dot_data(data) + + +def graph_from_dot_file(path): + """Load graph as defined by a DOT file. + + The file is assumed to be in DOT format. It will + be loaded, parsed and a Dot class will be returned, + representing the graph. + """ + + fd = file(path, 'rb') + data = fd.read() + fd.close() + + return graph_from_dot_data(data) + + +def graph_from_edges(edge_list, node_prefix='', directed=False): + """Creates a basic graph out of an edge list. + + The edge list has to be a list of tuples representing + the nodes connected by the edge. + The values can be anything: bool, int, float, str. + + If the graph is undirected by default, it is only + calculated from one of the symmetric halves of the matrix. + """ + + if directed: + graph = Dot(graph_type='digraph') + + else: + graph = Dot(graph_type='graph') + + for edge in edge_list: + + if isinstance(edge[0], str): + src = node_prefix + edge[0] + else: + src = node_prefix + str(edge[0]) + + if isinstance(edge[1], str): + dst = node_prefix + edge[1] + else: + dst = node_prefix + str(edge[1]) + + e = Edge(src, dst) + graph.add_edge(e) + + return graph + + +def graph_from_adjacency_matrix(matrix, node_prefix=u'', directed=False): + """Creates a basic graph out of an adjacency matrix. + + The matrix has to be a list of rows of values + representing an adjacency matrix. + The values can be anything: bool, int, float, as long + as they can evaluate to True or False. + """ + + node_orig = 1 + + if directed: + graph = Dot(graph_type='digraph') + else: + graph = Dot(graph_type='graph') + + for row in matrix: + if not directed: + skip = matrix.index(row) + r = row[skip:] + else: + skip = 0 + r = row + node_dest = skip + 1 + + for e in r: + if e: + graph.add_edge( + Edge(node_prefix + node_orig, + node_prefix + node_dest)) + node_dest += 1 + node_orig += 1 + + return graph + + +def graph_from_incidence_matrix(matrix, node_prefix='', directed=False): + """Creates a basic graph out of an incidence matrix. + + The matrix has to be a list of rows of values + representing an incidence matrix. + The values can be anything: bool, int, float, as long + as they can evaluate to True or False. + """ + + node_orig = 1 + + if directed: + graph = Dot(graph_type='digraph') + else: + graph = Dot(graph_type='graph') + + for row in matrix: + nodes = [] + c = 1 + + for node in row: + if node: + nodes.append(c * node) + c += 1 + nodes.sort() + + if len(nodes) == 2: + graph.add_edge( + Edge(node_prefix + abs(nodes[0]), + node_prefix + nodes[1])) + + if not directed: + graph.set_simplify(True) + + return graph + + +def __find_executables(path): + """Used by find_graphviz + + path - single directory as a string + + If any of the executables are found, it will return a dictionary + containing the program names as keys and their paths as values. + + Otherwise returns None + """ + + success = False + progs = { + 'dot': '', + 'twopi': '', + 'neato': '', + 'circo': '', + 'fdp': '', + 'sfdp': ''} + + was_quoted = False + path = path.strip() + if path.startswith('"') and path.endswith('"'): + path = path[1:-1] + was_quoted = True + + if os.path.isdir(path): + + for prg in progs.iterkeys(): + + if progs[prg]: + continue + + if os.path.exists(os.path.join(path, prg)): + + if was_quoted: + progs[prg] = '"' + os.path.join(path, prg) + '"' + else: + progs[prg] = os.path.join(path, prg) + + success = True + + elif os.path.exists(os.path.join(path, prg + '.exe')): + + if was_quoted: + progs[prg] = '"' + os.path.join(path, prg + '.exe') + '"' + else: + progs[prg] = os.path.join(path, prg + '.exe') + + success = True + + if success: + + return progs + + else: + + return None + + +# The multi-platform version of this 'find_graphviz' function was +# contributed by Peter Cock +# +def find_graphviz(): + """Locate Graphviz's executables in the system. + + Tries three methods: + + First: Windows Registry (Windows only) + This requires Mark Hammond's pywin32 is installed. + + Secondly: Search the path + It will look for 'dot', 'twopi' and 'neato' in all the directories + specified in the PATH environment variable. + + Thirdly: Default install location (Windows only) + It will look for 'dot', 'twopi' and 'neato' in the default install + location under the "Program Files" directory. + + It will return a dictionary containing the program names as keys + and their paths as values. + + If this fails, it returns None. + """ + + # Method 1 (Windows only) + # + if os.sys.platform == 'win32': + + HKEY_LOCAL_MACHINE = 0x80000002 + KEY_QUERY_VALUE = 0x0001 + + RegOpenKeyEx = None + RegQueryValueEx = None + RegCloseKey = None + + try: + import win32api + import win32con + RegOpenKeyEx = win32api.RegOpenKeyEx + RegQueryValueEx = win32api.RegQueryValueEx + RegCloseKey = win32api.RegCloseKey + + except ImportError: + # Print a messaged suggesting they install these? + # + pass + + try: + import ctypes + + def RegOpenKeyEx(key, subkey, opt, sam): + result = ctypes.c_uint(0) + ctypes.windll.advapi32.RegOpenKeyExA( + key, + subkey, + opt, + sam, + ctypes.byref(result)) + return result.value + + def RegQueryValueEx(hkey, valuename): + data_type = ctypes.c_uint(0) + data_len = ctypes.c_uint(1024) + data = ctypes.create_string_buffer(1024) + + res = ctypes.windll.advapi32.RegQueryValueExA( + hkey, + valuename, + 0, + ctypes.byref(data_type), + data, + ctypes.byref(data_len)) + + return data.value + + RegCloseKey = ctypes.windll.advapi32.RegCloseKey + + except ImportError: + # Print a messaged suggesting they install these? + # + pass + + if RegOpenKeyEx is not None: + + # Get the GraphViz install path from the registry + # + hkey = None + potentialKeys = [ + "SOFTWARE\\ATT\\Graphviz", + "SOFTWARE\\AT&T Research Labs\\Graphviz", + ] + for potentialKey in potentialKeys: + + try: + hkey = RegOpenKeyEx(HKEY_LOCAL_MACHINE, + potentialKey, 0, KEY_QUERY_VALUE) + + if hkey is not None: + path = RegQueryValueEx(hkey, "InstallPath") + RegCloseKey(hkey) + + # The regitry variable might exist, left by old installations + # but with no value, in those cases we keep + # searching... + if not path: + continue + + # Now append the "bin" subdirectory: + # + path = os.path.join(path, "bin") + progs = __find_executables(path) + if progs is not None: + # print "Used Windows registry" + return progs + + except Exception as excp: + #raise excp + pass + else: + break + + # Method 2 (Linux, Windows etc) + # + if 'PATH' in os.environ: + + for path in os.environ['PATH'].split(os.pathsep): + progs = __find_executables(path) + if progs is not None: + # print "Used path" + return progs + + # Method 3 (Windows only) + # + if os.sys.platform == 'win32': + + # Try and work out the equivalent of "C:\Program Files" on this + # machine (might be on drive D:, or in a different language) + # + + if 'PROGRAMFILES' in os.environ: + + # Note, we could also use the win32api to get this + # information, but win32api may not be installed. + + path = os.path.join( + os.environ['PROGRAMFILES'], + 'ATT', + 'GraphViz', + 'bin') + + else: + + # Just in case, try the default... + path = r"C:\Program Files\att\Graphviz\bin" + + progs = __find_executables(path) + + if progs is not None: + + # print "Used default install location" + return progs + + for path in ( + '/usr/bin', '/usr/local/bin', + '/opt/local/bin', + '/opt/bin', '/sw/bin', '/usr/share', + '/Applications/Graphviz.app/Contents/MacOS/'): + + progs = __find_executables(path) + if progs is not None: + # print "Used path" + return progs + + # Failed to find GraphViz + # + return None + + +class Common: + + """Common information to several classes. + + Should not be directly used, several classes are derived from + this one. + """ + + def __getstate__(self): + + dict = copy.copy(self.obj_dict) + + return dict + + def __setstate__(self, state): + + self.obj_dict = state + + def __get_attribute__(self, attr): + """Look for default attributes for this node""" + + attr_val = self.obj_dict['attributes'].get(attr, None) + + if attr_val is None: + # get the defaults for nodes/edges + + default_node_name = self.obj_dict['type'] + + # The defaults for graphs are set on a node named 'graph' + if default_node_name in ('subgraph', 'digraph', 'cluster'): + default_node_name = 'graph' + + g = self.get_parent_graph() + if g is not None: + defaults = g.get_node(default_node_name) + else: + return None + + # Multiple defaults could be set by having repeated 'graph [...]' + # 'node [...]', 'edge [...]' statements. In such case, if the + # same attribute is set in different statements, only the first + # will be returned. In order to get all, one would call the + # get_*_defaults() methods and handle those. Or go node by node + # (of the ones specifying defaults) and modify the attributes + # individually. + # + if not isinstance(defaults, (list, tuple)): + defaults = [defaults] + + for default in defaults: + attr_val = default.obj_dict['attributes'].get(attr, None) + if attr_val: + return attr_val + else: + return attr_val + + return None + + def set_parent_graph(self, parent_graph): + + self.obj_dict['parent_graph'] = parent_graph + + def get_parent_graph(self): + + return self.obj_dict.get('parent_graph', None) + + def set(self, name, value): + """Set an attribute value by name. + + Given an attribute 'name' it will set its value to 'value'. + There's always the possibility of using the methods: + + set_'name'(value) + + which are defined for all the existing attributes. + """ + + self.obj_dict['attributes'][name] = value + + def get(self, name): + """Get an attribute value by name. + + Given an attribute 'name' it will get its value. + There's always the possibility of using the methods: + + get_'name'() + + which are defined for all the existing attributes. + """ + + return self.obj_dict['attributes'].get(name, None) + + def get_attributes(self): + """""" + + return self.obj_dict['attributes'] + + def set_sequence(self, seq): + + self.obj_dict['sequence'] = seq + + def get_sequence(self): + + return self.obj_dict['sequence'] + + def create_attribute_methods(self, obj_attributes): + + # for attr in self.obj_dict['attributes']: + for attr in obj_attributes: + + # Generate all the Setter methods. + # + self.__setattr__( + 'set_' + + attr, + lambda x, + a=attr: self.obj_dict['attributes'].__setitem__( + a, + x)) + + # Generate all the Getter methods. + # + self.__setattr__( + 'get_' + attr, + lambda a=attr: self.__get_attribute__(a)) + + +class Error(Exception): + + """General error handling class. + """ + + def __init__(self, value): + self.value = value + + def __str__(self): + return self.value + + +class InvocationException(Exception): + + """To indicate that a ploblem occurred while running any of the GraphViz executables. + """ + + def __init__(self, value): + self.value = value + + def __str__(self): + return self.value + + +class Node(object, Common): + + """A graph node. + + This class represents a graph's node with all its attributes. + + node(name, attribute=value, ...) + + name: node's name + + All the attributes defined in the Graphviz dot language should + be supported. + """ + + def __init__(self, name='', obj_dict=None, **attrs): + + # + # Nodes will take attributes of all other types because the defaults + # for any GraphViz object are dealt with as if they were Node definitions + # + + if obj_dict is not None: + + self.obj_dict = obj_dict + + else: + + self.obj_dict = dict() + + # Copy the attributes + # + self.obj_dict['attributes'] = dict(attrs) + self.obj_dict['type'] = 'node' + self.obj_dict['parent_graph'] = None + self.obj_dict['parent_node_list'] = None + self.obj_dict['sequence'] = None + + # Remove the compass point + # + port = None + if isinstance(name, basestring) and not name.startswith('"'): + idx = name.find(':') + if idx > 0 and idx + 1 < len(name): + name, port = name[:idx], name[idx:] + + if isinstance(name, (long, int)): + name = str(name) + + self.obj_dict['name'] = quote_if_necessary(name) + self.obj_dict['port'] = port + + self.create_attribute_methods(NODE_ATTRIBUTES) + + def set_name(self, node_name): + """Set the node's name.""" + + self.obj_dict['name'] = node_name + + def get_name(self): + """Get the node's name.""" + + return self.obj_dict['name'] + + def get_port(self): + """Get the node's port.""" + + return self.obj_dict['port'] + + def add_style(self, style): + + styles = self.obj_dict['attributes'].get('style', None) + if not styles and style: + styles = [style] + else: + styles = styles.split(',') + styles.append(style) + + self.obj_dict['attributes']['style'] = ','.join(styles) + + def to_string(self): + """Returns a string representation of the node in dot language. + """ + + # RMF: special case defaults for node, edge and graph properties. + # + node = quote_if_necessary(self.obj_dict['name']) + + node_attr = list() + + for attr, value in self.obj_dict['attributes'].iteritems(): + if value is not None: + node_attr.append('%s=%s' % (attr, quote_if_necessary(value))) + else: + node_attr.append(attr) + + # No point in having nodes setting any defaults if the don't set + # any attributes... + # + if node in ('graph', 'node', 'edge') and len(node_attr) == 0: + return '' + + node_attr = ', '.join(node_attr) + + if node_attr: + node += ' [' + node_attr + ']' + + return node + ';' + + +class Edge(object, Common): + + """A graph edge. + + This class represents a graph's edge with all its attributes. + + edge(src, dst, attribute=value, ...) + + src: source node's name + dst: destination node's name + + All the attributes defined in the Graphviz dot language should + be supported. + + Attributes can be set through the dynamically generated methods: + + set_[attribute name], i.e. set_label, set_fontname + + or directly by using the instance's special dictionary: + + Edge.obj_dict['attributes'][attribute name], i.e. + + edge_instance.obj_dict['attributes']['label'] + edge_instance.obj_dict['attributes']['fontname'] + + """ + + def __init__(self, src='', dst='', obj_dict=None, **attrs): + + if isinstance(src, (list, tuple)) and dst == '': + src, dst = src + + if obj_dict is not None: + + self.obj_dict = obj_dict + + else: + + self.obj_dict = dict() + + # Copy the attributes + # + self.obj_dict['attributes'] = dict(attrs) + self.obj_dict['type'] = 'edge' + self.obj_dict['parent_graph'] = None + self.obj_dict['parent_edge_list'] = None + self.obj_dict['sequence'] = None + + if isinstance(src, Node): + src = src.get_name() + + if isinstance(dst, Node): + dst = dst.get_name() + + points = (quote_if_necessary(src), quote_if_necessary(dst)) + + self.obj_dict['points'] = points + + self.create_attribute_methods(EDGE_ATTRIBUTES) + + def get_source(self): + """Get the edges source node name.""" + + return self.obj_dict['points'][0] + + def get_destination(self): + """Get the edge's destination node name.""" + + return self.obj_dict['points'][1] + + def __hash__(self): + + return hash(hash(self.get_source()) + hash(self.get_destination())) + + def __eq__(self, edge): + """Compare two edges. + + If the parent graph is directed, arcs linking + node A to B are considered equal and A->B != B->A + + If the parent graph is undirected, any edge + connecting two nodes is equal to any other + edge connecting the same nodes, A->B == B->A + """ + + if not isinstance(edge, Edge): + raise Error("Can't compare and edge to a non-edge object.") + + if self.get_parent_graph().get_top_graph_type() == 'graph': + + # If the graph is undirected, the edge has neither + # source nor destination. + # + if ((self.get_source() == edge.get_source() and self.get_destination() == edge.get_destination()) or ( + edge.get_source() == self.get_destination() and edge.get_destination() == self.get_source())): + return True + + else: + + if self.get_source() == edge.get_source( + ) and self.get_destination() == edge.get_destination(): + return True + + return False + + def parse_node_ref(self, node_str): + + if not isinstance(node_str, str): + return node_str + + if node_str.startswith('"') and node_str.endswith('"'): + + return node_str + + node_port_idx = node_str.rfind(':') + + if node_port_idx > 0 and node_str[0] == '"' and node_str[ + node_port_idx - + 1] == '"': + + return node_str + + if node_port_idx > 0: + + a = node_str[:node_port_idx] + b = node_str[node_port_idx + 1:] + + node = quote_if_necessary(a) + + node += ':' + quote_if_necessary(b) + + return node + + return node_str + + def to_string(self): + """Returns a string representation of the edge in dot language. + """ + + src = self.parse_node_ref(self.get_source()) + dst = self.parse_node_ref(self.get_destination()) + + if isinstance(src, frozendict): + edge = [Subgraph(obj_dict=src).to_string()] + elif isinstance(src, (int, long)): + edge = [str(src)] + else: + edge = [src] + + if (self.get_parent_graph() and + self.get_parent_graph().get_top_graph_type() and + self.get_parent_graph().get_top_graph_type() == 'digraph'): + + edge.append('->') + + else: + edge.append('--') + + if isinstance(dst, frozendict): + edge.append(Subgraph(obj_dict=dst).to_string()) + elif isinstance(dst, (int, long)): + edge.append(str(dst)) + else: + edge.append(dst) + + edge_attr = list() + + for attr, value in self.obj_dict['attributes'].iteritems(): + + if value is not None: + edge_attr.append('%s=%s' % (attr, quote_if_necessary(value))) + else: + edge_attr.append(attr) + + edge_attr = ', '.join(edge_attr) + + if edge_attr: + edge.append(' [' + edge_attr + ']') + + return ' '.join(edge) + ';' + + +class Graph(object, Common): + + """Class representing a graph in Graphviz's dot language. + + This class implements the methods to work on a representation + of a graph in Graphviz's dot language. + + graph( graph_name='G', graph_type='digraph', + strict=False, suppress_disconnected=False, attribute=value, ...) + + graph_name: + the graph's name + graph_type: + can be 'graph' or 'digraph' + suppress_disconnected: + defaults to False, which will remove from the + graph any disconnected nodes. + simplify: + if True it will avoid displaying equal edges, i.e. + only one edge between two nodes. removing the + duplicated ones. + + All the attributes defined in the Graphviz dot language should + be supported. + + Attributes can be set through the dynamically generated methods: + + set_[attribute name], i.e. set_size, set_fontname + + or using the instance's attributes: + + Graph.obj_dict['attributes'][attribute name], i.e. + + graph_instance.obj_dict['attributes']['label'] + graph_instance.obj_dict['attributes']['fontname'] + """ + + def __init__( + self, + graph_name='G', + obj_dict=None, + graph_type='digraph', + strict=False, + suppress_disconnected=False, + simplify=False, + **attrs): + + if obj_dict is not None: + self.obj_dict = obj_dict + + else: + + self.obj_dict = dict() + + self.obj_dict['attributes'] = dict(attrs) + + if graph_type not in ['graph', 'digraph']: + raise Error( + 'Invalid type "%s". Accepted graph types are: graph, digraph, subgraph' % + graph_type) + + self.obj_dict['name'] = quote_if_necessary(graph_name) + self.obj_dict['type'] = graph_type + + self.obj_dict['strict'] = strict + self.obj_dict['suppress_disconnected'] = suppress_disconnected + self.obj_dict['simplify'] = simplify + + self.obj_dict['current_child_sequence'] = 1 + self.obj_dict['nodes'] = dict() + self.obj_dict['edges'] = dict() + self.obj_dict['subgraphs'] = dict() + + self.set_parent_graph(self) + + self.create_attribute_methods(GRAPH_ATTRIBUTES) + + def get_graph_type(self): + + return self.obj_dict['type'] + + def get_top_graph_type(self): + + parent = self + while True: + parent_ = parent.get_parent_graph() + if parent_ == parent: + break + parent = parent_ + + return parent.obj_dict['type'] + + def set_graph_defaults(self, **attrs): + + self.add_node(Node('graph', **attrs)) + + def get_graph_defaults(self, **attrs): + + graph_nodes = self.get_node('graph') + + if isinstance(graph_nodes, (list, tuple)): + return [node.get_attributes() for node in graph_nodes] + + return graph_nodes.get_attributes() + + def set_node_defaults(self, **attrs): + + self.add_node(Node('node', **attrs)) + + def get_node_defaults(self, **attrs): + + graph_nodes = self.get_node('node') + + if isinstance(graph_nodes, (list, tuple)): + return [node.get_attributes() for node in graph_nodes] + + return graph_nodes.get_attributes() + + def set_edge_defaults(self, **attrs): + + self.add_node(Node('edge', **attrs)) + + def get_edge_defaults(self, **attrs): + + graph_nodes = self.get_node('edge') + + if isinstance(graph_nodes, (list, tuple)): + return [node.get_attributes() for node in graph_nodes] + + return graph_nodes.get_attributes() + + def set_simplify(self, simplify): + """Set whether to simplify or not. + + If True it will avoid displaying equal edges, i.e. + only one edge between two nodes. removing the + duplicated ones. + """ + + self.obj_dict['simplify'] = simplify + + def get_simplify(self): + """Get whether to simplify or not. + + Refer to set_simplify for more information. + """ + + return self.obj_dict['simplify'] + + def set_type(self, graph_type): + """Set the graph's type, 'graph' or 'digraph'.""" + + self.obj_dict['type'] = graph_type + + def get_type(self): + """Get the graph's type, 'graph' or 'digraph'.""" + + return self.obj_dict['type'] + + def set_name(self, graph_name): + """Set the graph's name.""" + + self.obj_dict['name'] = graph_name + + def get_name(self): + """Get the graph's name.""" + + return self.obj_dict['name'] + + def set_strict(self, val): + """Set graph to 'strict' mode. + + This option is only valid for top level graphs. + """ + + self.obj_dict['strict'] = val + + def get_strict(self, val): + """Get graph's 'strict' mode (True, False). + + This option is only valid for top level graphs. + """ + + return self.obj_dict['strict'] + + def set_suppress_disconnected(self, val): + """Suppress disconnected nodes in the output graph. + + This option will skip nodes in the graph with no incoming or outgoing + edges. This option works also for subgraphs and has effect only in the + current graph/subgraph. + """ + + self.obj_dict['suppress_disconnected'] = val + + def get_suppress_disconnected(self, val): + """Get if suppress disconnected is set. + + Refer to set_suppress_disconnected for more information. + """ + + return self.obj_dict['suppress_disconnected'] + + def get_next_sequence_number(self): + + seq = self.obj_dict['current_child_sequence'] + + self.obj_dict['current_child_sequence'] += 1 + + return seq + + def add_node(self, graph_node): + """Adds a node object to the graph. + + It takes a node object as its only argument and returns + None. + """ + + if not isinstance(graph_node, Node): + raise TypeError( + 'add_node() received a non node class object: ' + + str(graph_node)) + + node = self.get_node(graph_node.get_name()) + + if not node: + + self.obj_dict['nodes'][ + graph_node.get_name()] = [ + graph_node.obj_dict] + + #self.node_dict[graph_node.get_name()] = graph_node.attributes + graph_node.set_parent_graph(self.get_parent_graph()) + + else: + + self.obj_dict['nodes'][ + graph_node.get_name()].append( + graph_node.obj_dict) + + graph_node.set_sequence(self.get_next_sequence_number()) + + def del_node(self, name, index=None): + """Delete a node from the graph. + + Given a node's name all node(s) with that same name + will be deleted if 'index' is not specified or set + to None. + If there are several nodes with that same name and + 'index' is given, only the node in that position + will be deleted. + + 'index' should be an integer specifying the position + of the node to delete. If index is larger than the + number of nodes with that name, no action is taken. + + If nodes are deleted it returns True. If no action + is taken it returns False. + """ + + if isinstance(name, Node): + name = name.get_name() + + if name in self.obj_dict['nodes']: + + if index is not None and index < len(self.obj_dict['nodes'][name]): + del self.obj_dict['nodes'][name][index] + return True + else: + del self.obj_dict['nodes'][name] + return True + + return False + + def get_node(self, name): + """Retrieve a node from the graph. + + Given a node's name the corresponding Node + instance will be returned. + + If one or more nodes exist with that name a list of + Node instances is returned. + An empty list is returned otherwise. + """ + + match = list() + + if name in self.obj_dict['nodes']: + + match.extend([Node(obj_dict=obj_dict) + for obj_dict in self.obj_dict['nodes'][name]]) + + return match + + def get_nodes(self): + """Get the list of Node instances.""" + + return self.get_node_list() + + def get_node_list(self): + """Get the list of Node instances. + + This method returns the list of Node instances + composing the graph. + """ + + node_objs = list() + + for node, obj_dict_list in self.obj_dict['nodes'].iteritems(): + node_objs.extend([Node(obj_dict=obj_d) for obj_d in obj_dict_list]) + + return node_objs + + def add_edge(self, graph_edge): + """Adds an edge object to the graph. + + It takes a edge object as its only argument and returns + None. + """ + + if not isinstance(graph_edge, Edge): + raise TypeError( + 'add_edge() received a non edge class object: ' + + str(graph_edge)) + + edge_points = (graph_edge.get_source(), graph_edge.get_destination()) + + if edge_points in self.obj_dict['edges']: + + edge_list = self.obj_dict['edges'][edge_points] + edge_list.append(graph_edge.obj_dict) + + else: + + self.obj_dict['edges'][edge_points] = [graph_edge.obj_dict] + + graph_edge.set_sequence(self.get_next_sequence_number()) + + graph_edge.set_parent_graph(self.get_parent_graph()) + + def del_edge(self, src_or_list, dst=None, index=None): + """Delete an edge from the graph. + + Given an edge's (source, destination) node names all + matching edges(s) will be deleted if 'index' is not + specified or set to None. + If there are several matching edges and 'index' is + given, only the edge in that position will be deleted. + + 'index' should be an integer specifying the position + of the edge to delete. If index is larger than the + number of matching edges, no action is taken. + + If edges are deleted it returns True. If no action + is taken it returns False. + """ + + if isinstance(src_or_list, (list, tuple)): + if dst is not None and isinstance(dst, (int, long)): + index = dst + src, dst = src_or_list + else: + src, dst = src_or_list, dst + + if isinstance(src, Node): + src = src.get_name() + + if isinstance(dst, Node): + dst = dst.get_name() + + if (src, dst) in self.obj_dict['edges']: + + if index is not None and index < len( + self.obj_dict['edges'][ + (src, dst)]): + del self.obj_dict['edges'][(src, dst)][index] + return True + else: + del self.obj_dict['edges'][(src, dst)] + return True + + return False + + def get_edge(self, src_or_list, dst=None): + """Retrieved an edge from the graph. + + Given an edge's source and destination the corresponding + Edge instance(s) will be returned. + + If one or more edges exist with that source and destination + a list of Edge instances is returned. + An empty list is returned otherwise. + """ + + if isinstance(src_or_list, (list, tuple)) and dst is None: + edge_points = tuple(src_or_list) + edge_points_reverse = (edge_points[1], edge_points[0]) + else: + edge_points = (src_or_list, dst) + edge_points_reverse = (dst, src_or_list) + + match = list() + + if edge_points in self.obj_dict['edges'] or ( + self.get_top_graph_type() == 'graph' and edge_points_reverse in self.obj_dict['edges']): + + edges_obj_dict = self.obj_dict['edges'].get( + edge_points, + self.obj_dict['edges'].get(edge_points_reverse, None)) + + for edge_obj_dict in edges_obj_dict: + match.append( + Edge( + edge_points[0], + edge_points[1], + obj_dict=edge_obj_dict)) + + return match + + def get_edges(self): + return self.get_edge_list() + + def get_edge_list(self): + """Get the list of Edge instances. + + This method returns the list of Edge instances + composing the graph. + """ + + edge_objs = list() + + for edge, obj_dict_list in self.obj_dict['edges'].iteritems(): + edge_objs.extend([Edge(obj_dict=obj_d) for obj_d in obj_dict_list]) + + return edge_objs + + def add_subgraph(self, sgraph): + """Adds an subgraph object to the graph. + + It takes a subgraph object as its only argument and returns + None. + """ + + if not isinstance( + sgraph, + Subgraph) and not isinstance( + sgraph, + Cluster): + raise TypeError( + 'add_subgraph() received a non subgraph class object:' + + str(sgraph)) + + if sgraph.get_name() in self.obj_dict['subgraphs']: + + sgraph_list = self.obj_dict['subgraphs'][sgraph.get_name()] + sgraph_list.append(sgraph.obj_dict) + + else: + self.obj_dict['subgraphs'][sgraph.get_name()] = [sgraph.obj_dict] + + sgraph.set_sequence(self.get_next_sequence_number()) + + sgraph.set_parent_graph(self.get_parent_graph()) + + def get_subgraph(self, name): + """Retrieved a subgraph from the graph. + + Given a subgraph's name the corresponding + Subgraph instance will be returned. + + If one or more subgraphs exist with the same name, a list of + Subgraph instances is returned. + An empty list is returned otherwise. + """ + + match = list() + + if name in self.obj_dict['subgraphs']: + + sgraphs_obj_dict = self.obj_dict['subgraphs'].get(name) + + for obj_dict_list in sgraphs_obj_dict: + #match.extend( Subgraph( obj_dict = obj_d ) for obj_d in obj_dict_list ) + match.append(Subgraph(obj_dict=obj_dict_list)) + + return match + + def get_subgraphs(self): + + return self.get_subgraph_list() + + def get_subgraph_list(self): + """Get the list of Subgraph instances. + + This method returns the list of Subgraph instances + in the graph. + """ + + sgraph_objs = list() + + for sgraph, obj_dict_list in self.obj_dict['subgraphs'].iteritems(): + sgraph_objs.extend([Subgraph(obj_dict=obj_d) + for obj_d in obj_dict_list]) + + return sgraph_objs + + def set_parent_graph(self, parent_graph): + + self.obj_dict['parent_graph'] = parent_graph + + for obj_list in self.obj_dict['nodes'].itervalues(): + for obj in obj_list: + obj['parent_graph'] = parent_graph + + for obj_list in self.obj_dict['edges'].itervalues(): + for obj in obj_list: + obj['parent_graph'] = parent_graph + + for obj_list in self.obj_dict['subgraphs'].itervalues(): + for obj in obj_list: + Graph(obj_dict=obj).set_parent_graph(parent_graph) + + def to_string(self): + """Returns a string representation of the graph in dot language. + + It will return the graph and all its subelements in string from. + """ + + graph = list() + + if self.obj_dict.get('strict', None) is not None: + + if self == self.get_parent_graph() and self.obj_dict['strict']: + + graph.append('strict ') + + if self.obj_dict['name'] == '': + if 'show_keyword' in self.obj_dict and self.obj_dict[ + 'show_keyword']: + graph.append('subgraph {\n') + else: + graph.append('{\n') + else: + graph.append( + '%s %s {\n' % + (self.obj_dict['type'], self.obj_dict['name'])) + + for attr in self.obj_dict['attributes'].iterkeys(): + + if self.obj_dict['attributes'].get(attr, None) is not None: + + val = self.obj_dict['attributes'].get(attr) + if val is not None: + graph.append('%s=%s' % (attr, quote_if_necessary(val))) + else: + graph.append(attr) + + graph.append(';\n') + + edges_done = set() + + edge_obj_dicts = list() + for e in self.obj_dict['edges'].itervalues(): + edge_obj_dicts.extend(e) + + if edge_obj_dicts: + edge_src_set, edge_dst_set = zip( + *[obj['points'] for obj in edge_obj_dicts]) + edge_src_set, edge_dst_set = set(edge_src_set), set(edge_dst_set) + else: + edge_src_set, edge_dst_set = set(), set() + + node_obj_dicts = list() + for e in self.obj_dict['nodes'].itervalues(): + node_obj_dicts.extend(e) + + sgraph_obj_dicts = list() + for sg in self.obj_dict['subgraphs'].itervalues(): + sgraph_obj_dicts.extend(sg) + + obj_list = sorted([(obj['sequence'], obj) for obj in ( + edge_obj_dicts + node_obj_dicts + sgraph_obj_dicts)]) + + for idx, obj in obj_list: + + if obj['type'] == 'node': + + node = Node(obj_dict=obj) + + if self.obj_dict.get('suppress_disconnected', False): + + if (node.get_name() not in edge_src_set and + node.get_name() not in edge_dst_set): + + continue + + graph.append(node.to_string() + '\n') + + elif obj['type'] == 'edge': + + edge = Edge(obj_dict=obj) + + if self.obj_dict.get('simplify', False) and edge in edges_done: + continue + + graph.append(edge.to_string() + '\n') + edges_done.add(edge) + + else: + + sgraph = Subgraph(obj_dict=obj) + + graph.append(sgraph.to_string() + '\n') + + graph.append('}\n') + + return ''.join(graph) + + +class Subgraph(Graph): + + """Class representing a subgraph in Graphviz's dot language. + + This class implements the methods to work on a representation + of a subgraph in Graphviz's dot language. + + subgraph(graph_name='subG', suppress_disconnected=False, attribute=value, ...) + + graph_name: + the subgraph's name + suppress_disconnected: + defaults to false, which will remove from the + subgraph any disconnected nodes. + All the attributes defined in the Graphviz dot language should + be supported. + + Attributes can be set through the dynamically generated methods: + + set_[attribute name], i.e. set_size, set_fontname + + or using the instance's attributes: + + Subgraph.obj_dict['attributes'][attribute name], i.e. + + subgraph_instance.obj_dict['attributes']['label'] + subgraph_instance.obj_dict['attributes']['fontname'] + """ + + # RMF: subgraph should have all the attributes of graph so it can be passed + # as a graph to all methods + # + def __init__( + self, + graph_name='', + obj_dict=None, + suppress_disconnected=False, + simplify=False, + **attrs): + + Graph.__init__( + self, + graph_name=graph_name, + obj_dict=obj_dict, + suppress_disconnected=suppress_disconnected, + simplify=simplify, + **attrs) + + if obj_dict is None: + + self.obj_dict['type'] = 'subgraph' + + +class Cluster(Graph): + + """Class representing a cluster in Graphviz's dot language. + + This class implements the methods to work on a representation + of a cluster in Graphviz's dot language. + + cluster(graph_name='subG', suppress_disconnected=False, attribute=value, ...) + + graph_name: + the cluster's name (the string 'cluster' will be always prepended) + suppress_disconnected: + defaults to false, which will remove from the + cluster any disconnected nodes. + All the attributes defined in the Graphviz dot language should + be supported. + + Attributes can be set through the dynamically generated methods: + + set_[attribute name], i.e. set_color, set_fontname + + or using the instance's attributes: + + Cluster.obj_dict['attributes'][attribute name], i.e. + + cluster_instance.obj_dict['attributes']['label'] + cluster_instance.obj_dict['attributes']['fontname'] + """ + + def __init__( + self, + graph_name='subG', + obj_dict=None, + suppress_disconnected=False, + simplify=False, + **attrs): + + Graph.__init__( + self, + graph_name=graph_name, + obj_dict=obj_dict, + suppress_disconnected=suppress_disconnected, + simplify=simplify, + **attrs) + + if obj_dict is None: + + self.obj_dict['type'] = 'subgraph' + self.obj_dict['name'] = 'cluster_' + graph_name + + self.create_attribute_methods(CLUSTER_ATTRIBUTES) + + +class Dot(Graph): + + """A container for handling a dot language file. + + This class implements methods to write and process + a dot language file. It is a derived class of + the base class 'Graph'. + """ + + def __init__(self, *argsl, **argsd): + Graph.__init__(self, *argsl, **argsd) + + self.shape_files = list() + + self.progs = None + + self.formats = [ + 'canon', + 'cmap', + 'cmapx', + 'cmapx_np', + 'dia', + 'dot', + 'fig', + 'gd', + 'gd2', + 'gif', + 'hpgl', + 'imap', + 'imap_np', + 'ismap', + 'jpe', + 'jpeg', + 'jpg', + 'mif', + 'mp', + 'pcl', + 'pdf', + 'pic', + 'plain', + 'plain-ext', + 'png', + 'ps', + 'ps2', + 'svg', + 'svgz', + 'vml', + 'vmlz', + 'vrml', + 'vtx', + 'wbmp', + 'xdot', + 'xlib'] + + self.prog = 'dot' + + # Automatically creates all the methods enabling the creation + # of output in any of the supported formats. + for frmt in self.formats: + self.__setattr__( + 'create_' + frmt, + lambda f=frmt, + prog=self.prog: self.create( + format=f, + prog=prog)) + f = self.__dict__['create_' + frmt] + f.__doc__ = '''Refer to the docstring accompanying the 'create' method for more information.''' + + for frmt in self.formats + ['raw']: + self.__setattr__( + 'write_' + frmt, + lambda path, + f=frmt, + prog=self.prog: self.write( + path, + format=f, + prog=prog)) + + f = self.__dict__['write_' + frmt] + f.__doc__ = '''Refer to the docstring accompanying the 'write' method for more information.''' + + def __getstate__(self): + + dict = copy.copy(self.obj_dict) + + return dict + + def __setstate__(self, state): + + self.obj_dict = state + + def set_shape_files(self, file_paths): + """Add the paths of the required image files. + + If the graph needs graphic objects to be used as shapes or otherwise + those need to be in the same folder as the graph is going to be rendered + from. Alternatively the absolute path to the files can be specified when + including the graphics in the graph. + + The files in the location pointed to by the path(s) specified as arguments + to this method will be copied to the same temporary location where the + graph is going to be rendered. + """ + + if isinstance(file_paths, basestring): + self.shape_files.append(file_paths) + + if isinstance(file_paths, (list, tuple)): + self.shape_files.extend(file_paths) + + def set_prog(self, prog): + """Sets the default program. + + Sets the default program in charge of processing + the dot file into a graph. + """ + self.prog = prog + + def set_graphviz_executables(self, paths): + """This method allows to manually specify the location of the GraphViz executables. + + The argument to this method should be a dictionary where the keys are as follows: + + {'dot': '', 'twopi': '', 'neato': '', 'circo': '', 'fdp': ''} + + and the values are the paths to the corresponding executable, including the name + of the executable itself. + """ + + self.progs = paths + + def write(self, path, prog=None, format='raw'): + """Writes a graph to a file. + + Given a filename 'path' it will open/create and truncate + such file and write on it a representation of the graph + defined by the dot object and in the format specified by + 'format'. + The format 'raw' is used to dump the string representation + of the Dot object, without further processing. + The output can be processed by any of graphviz tools, defined + in 'prog', which defaults to 'dot' + Returns True or False according to the success of the write + operation. + + There's also the preferred possibility of using: + + write_'format'(path, prog='program') + + which are automatically defined for all the supported formats. + [write_ps(), write_gif(), write_dia(), ...] + """ + + if prog is None: + prog = self.prog + + dot_fd = file(path, "w+b") + if format == 'raw': + data = self.to_string() + if isinstance(data, basestring): + if not isinstance(data, unicode): + try: + data = unicode(data, 'utf-8') + except: + pass + + try: + data = data.encode('utf-8') + except: + pass + dot_fd.write(data) + else: + dot_fd.write(self.create(prog, format)) + dot_fd.close() + + return True + + def create(self, prog=None, format='ps'): + """Creates and returns a Postscript representation of the graph. + + create will write the graph to a temporary dot file and process + it with the program given by 'prog' (which defaults to 'twopi'), + reading the Postscript output and returning it as a string is the + operation is successful. + On failure None is returned. + + There's also the preferred possibility of using: + + create_'format'(prog='program') + + which are automatically defined for all the supported formats. + [create_ps(), create_gif(), create_dia(), ...] + + If 'prog' is a list instead of a string the fist item is expected + to be the program name, followed by any optional command-line + arguments for it: + + [ 'twopi', '-Tdot', '-s10' ] + """ + + if prog is None: + prog = self.prog + + if isinstance(prog, (list, tuple)): + prog, args = prog[0], prog[1:] + else: + args = [] + + if self.progs is None: + self.progs = find_graphviz() + if self.progs is None: + raise InvocationException( + 'GraphViz\'s executables not found') + + if prog not in self.progs: + raise InvocationException( + 'GraphViz\'s executable "%s" not found' % prog) + + if not os.path.exists( + self.progs[prog]) or not os.path.isfile( + self.progs[prog]): + raise InvocationException( + 'GraphViz\'s executable "%s" is not a file or doesn\'t exist' % + self.progs[prog]) + + tmp_fd, tmp_name = tempfile.mkstemp() + os.close(tmp_fd) + self.write(tmp_name) + tmp_dir = os.path.dirname(tmp_name) + + # For each of the image files... + # + for img in self.shape_files: + + # Get its data + # + f = file(img, 'rb') + f_data = f.read() + f.close() + + # And copy it under a file with the same name in the temporary directory + # + f = file(os.path.join(tmp_dir, os.path.basename(img)), 'wb') + f.write(f_data) + f.close() + + cmdline = [self.progs[prog], '-T' + format, tmp_name] + args + + p = subprocess.Popen( + cmdline, + cwd=tmp_dir, + stderr=subprocess.PIPE, stdout=subprocess.PIPE) + + stderr = p.stderr + stdout = p.stdout + + stdout_output = list() + while True: + data = stdout.read() + if not data: + break + stdout_output.append(data) + stdout.close() + + stdout_output = ''.join(stdout_output) + + if not stderr.closed: + stderr_output = list() + while True: + data = stderr.read() + if not data: + break + stderr_output.append(data) + stderr.close() + + if stderr_output: + stderr_output = ''.join(stderr_output) + + #pid, status = os.waitpid(p.pid, 0) + status = p.wait() + + if status != 0: + raise InvocationException( + 'Program terminated with status: %d. stderr follows: %s' % ( + status, stderr_output)) + elif stderr_output: + print stderr_output + + # For each of the image files... + # + for img in self.shape_files: + + # remove it + # + os.unlink(os.path.join(tmp_dir, os.path.basename(img))) + + os.unlink(tmp_name) + + return stdout_output diff --git a/scripts/create_module.sh b/scripts/module/qp_create_module.sh similarity index 85% rename from scripts/create_module.sh rename to scripts/module/qp_create_module.sh index dbddc3d3..1a456e67 100755 --- a/scripts/create_module.sh +++ b/scripts/module/qp_create_module.sh @@ -71,7 +71,7 @@ debug "Module does not already exist: OK" # Set up dependencies -ALL_MODULES="${NEEDED_MODULES}" +ALL_MODULES="$(cat NEEDED_MODULES)" echo "Select which modules you are sure you will need: (press q to quit)" NEEDED_MODULES="" select M in ${ALL_MODULES} @@ -117,7 +117,7 @@ debug "Module directory is created." # Create the Makefile -"${QPACKAGE_ROOT}/scripts/create_Makefile.sh" || fail "Unable to create Makefile" +"${QPACKAGE_ROOT}/scripts/module/create_Makefile.sh" || fail "Unable to create Makefile" if [[ ! -f Makefile ]] then fail "Makefile was not created" @@ -125,8 +125,8 @@ fi debug "Makefile created" # Create the NEEDED_MODULES file -"${QPACKAGE_ROOT}/scripts/create_Needed_modules.sh" ${NEEDED_MODULES} || fail "Unable to create the NEEDED_MODULES file" -if [[ ! -f NEEDED_MODULES ]] +"${QPACKAGE_ROOT}/scripts/module/create_Needed_modules.sh" ${NEEDED_MODULES} || fail "Unable to create the NEEDED_MODULES file" +if [[ ! -f NEEDED_CHILDREN_MODULES ]] then fail "NEEDED_MODULES was not created" fi @@ -135,7 +135,7 @@ debug "NEEDED_MODULES created" # Create rst templates -"${QPACKAGE_ROOT}/scripts/create_rst_templates.sh" || fail "Unable to create rst templates" +"${QPACKAGE_ROOT}/scripts/module/create_rst_templates.sh" || fail "Unable to create rst templates" # Update module list in main NEEDED_MODULES diff --git a/scripts/pseudo/elts_num_ele.py b/scripts/pseudo/elts_num_ele.py new file mode 100644 index 00000000..3c4ad09f --- /dev/null +++ b/scripts/pseudo/elts_num_ele.py @@ -0,0 +1,118 @@ +name_to_elec = {"H": 1, + "He": 2, + "Li": 3, + "Be": 4, + "B": 5, + "C": 6, + "N": 7, + "O": 8, + "F": 9, + "Ne": 10, + "Na": 11, + "Mg": 12, + "Al": 13, + "Si": 14, + "P": 15, + "S": 16, + "Cl": 17, + "Ar": 18, + "K": 19, + "Ca": 20, + "Sc": 21, + "Ti": 22, + "V": 23, + "Cr": 24, + "Mn": 25, + "Fe": 26, + "Co": 27, + "Ni": 28, + "Cu": 29, + "Zn": 30, + "Ga": 31, + "Ge": 32, + "As": 33, + "Se": 34, + "Br": 35, + "Kr": 36, + "Rb": 37, + "Sr": 38, + "Y": 39, + "Zr": 40, + "Nb": 41, + "Mo": 42, + "Tc": 43, + "Ru": 44, + "Rh": 45, + "Pd": 46, + "Ag": 47, + "Cd": 48, + "In": 49, + "Sn": 50, + "Sb": 51, + "Te": 52, + "I": 53, + "Xe": 54, + "Cs": 55, + "Ba": 56, + "La": 57, + "Ce": 58, + "Pr": 59, + "Nd": 60, + "Pm": 61, + "Sm": 62, + "Eu": 63, + "Gd": 64, + "Tb": 65, + "Dy": 66, + "Ho": 67, + "Er": 68, + "Tm": 69, + "Yb": 70, + "Lu": 71, + "Hf": 72, + "Ta": 73, + "W": 74, + "Re": 75, + "Os": 76, + "Ir": 77, + "Pt": 78, + "Au": 79, + "Hg": 80, + "Tl": 81, + "Pb": 82, + "Bi": 83, + "Po": 84, + "At": 85, + "Rn": 86, + "Fr": 87, + "Ra": 88, + "Ac": 89, + "Th": 90, + "Pa": 91, + "U": 92, + "Np": 93, + "Pu": 94, + "Am": 95, + "Cm": 96, + "Bk": 97, + "Cf": 98, + "Es": 99, + "Fm": 100, + "Md": 101, + "No": 102, + "Lr": 103, + "Rf": 104, + "Db": 105, + "Sg": 106, + "Bh": 107, + "Hs": 108, + "Mt": 109, + "Ds": 110, + "Rg": 111, + "Cn": 112, + "Uut": 113, + "Fl": 114, + "Uup": 115, + "Lv": 116, + "Uus": 117, + "Uuo": 118} diff --git a/scripts/pseudo/put_pseudo_in_ezfio.py b/scripts/pseudo/put_pseudo_in_ezfio.py new file mode 100755 index 00000000..1f8594c5 --- /dev/null +++ b/scripts/pseudo/put_pseudo_in_ezfio.py @@ -0,0 +1,338 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +""" +Create the pseudo potential for a given atom + +Usage: + put_pseudo_in_ezfio.py + +Help: + atom is the Abreviation of the atom +""" + + +import os +import sys +from docopt import docopt + +from subprocess import Popen, PIPE + +qpackage_root = os.environ['QPACKAGE_ROOT'] + +EZFIO = "{0}/EZFIO".format(qpackage_root) +sys.path = [EZFIO + "/Python"] + sys.path + +from ezfio import ezfio + +import re +p = re.compile(ur'\|(\d+)><\d+\|') + + +def get_pseudo_str(l_atom): + """ + Run EMSL_local for geting the str of the speudo potential + + str_ele : + Element Symbol: Na + Number of replaced protons: 10 + Number of projectors: 2 + + Pseudopotential data: + + Local component: + Coeff. r^n Exp. + 1.00000000 -1 5.35838717 + 5.35838717 1 3.67918975 + -2.07764789 0 1.60507673 + + Non-local component: + Coeff. r^n Exp. Proj. + 10.69640234 0 1.32389367 |0><0| + 10.11238853 0 1.14052020 |1><1| + """ + + EMSL_root = "{0}/EMSL_Basis/".format(qpackage_root) + EMSL_path = "{0}/EMSL_api.py".format(EMSL_root) + db_path = "{0}/db/Pseudo.db".format(EMSL_root) + + str_ = "" + + for a in l_atom: + l_cmd_atom = ["--atom", a] + + l_cmd_head = [EMSL_path, "get_basis_data", + "--db_path", db_path, + "--basis", "BFD-Pseudo"] + + process = Popen(l_cmd_head + l_cmd_atom, stdout=PIPE, stderr=PIPE) + + stdout, _ = process.communicate() + str_ += stdout.strip() + "\n" + + return str_ + + +def get_v_n_dz_local(str_ele): + """ + From a str_ele of the pseudo (aka only one ele in the str) + get the list ussefull for the Local potential : v_k n_k and dz_k + """ + l_v_k = [] + l_n_k = [] + l_dz_k = [] + + for l in str_ele.splitlines(): + try: + v, n, dz = l.split() + v = float(v) + n = int(n) + dz = float(dz) + except ValueError: + pass + else: + l_v_k.append(v) + l_n_k.append(n) + l_dz_k.append(dz) + + return l_v_k, l_n_k, l_dz_k + + +def get_v_n_dz_l_nonlocal(str_ele): + """ + From a str_ele of the pseudo (aka only one ele in the str) + get the list ussefull for the non Local potential + v_kl (v, l) + n_k (v, l) + dz_k (dz ,l) + """ + l_v_kl = [] + l_n_kl = [] + l_dz_kl = [] + + for l in str_ele.splitlines(): + try: + v, n, dz, proj = l.split() + v = float(v) + n = int(n) + dz = float(dz) + l = int(p.match(proj).group(1)) + + except ValueError: + pass + else: + l_v_kl.append([v]) + l_n_kl.append([n]) + l_dz_kl.append([dz]) + + if not l_v_kl: + l_v_kl.append([0.]) + l_n_kl.append([0]) + l_dz_kl.append([0.]) + + return l_v_kl, l_n_kl, l_dz_kl + + +def get_zeff_alpha_beta(str_ele): + """ + Return the the zeff, alpha num elec and beta num elec + Assert ezfio_set_file alredy defined + """ + + import re + + # ___ + # | ._ o _|_ + # _|_ | | | |_ + # + + # ~#~#~#~#~#~#~ # + # s t r _ e l e # + # ~#~#~#~#~#~#~ # + +# m = re.search('Element Symbol: ([a-zA-Z]+)', str_ele) +# name = m.group(1).capitalize() + name = str_ele.split("\n")[0].strip().capitalize() + + m = re.search('Number of replaced protons: (\d+)', str_ele) + z_remove = int(m.group(1)) + + # _ + # |_) _. ._ _ _ + # | (_| | _> (/_ + # + + from elts_num_ele import name_to_elec + z = name_to_elec[name] + + z_eff = z - z_remove + + alpha = (z_remove / 2) + beta = (z_remove / 2) + + # _ + # |_) _ _|_ ._ ._ + # | \ (/_ |_ |_| | | | + # + + return [z_eff, alpha, beta] + + +def add_zero(array, size, type): + for add in xrange(len(array), size): + array.append([type(0)]) + + return array + + +def make_it_square(matrix, dim, type=float): + """ + matix the matrix to squate + dim array [lmax, kmax] + type the null value you want + [[[28.59107316], [19.37583724]], [[50.25646328]]] + => + [[[28.59107316], [19.37583724]], [[50.25646328], [0.0]]] + """ + + lmax = dim[0] + kmax = dim[1] + + for l_list in matrix: + + l_list = add_zero(l_list, lmax, type) + + for k_list in list_: + k_list = add_zero(k_list, kmax, type) + + return matrix + +if __name__ == "__main__": + arguments = docopt(__doc__) + # ___ + # | ._ o _|_ + # _|_ | | | |_ + # + + # ~#~#~#~#~ # + # E Z F I O # + # ~#~#~#~#~ # + + ezfio_path = arguments[""] + ezfio_path = os.path.expanduser(ezfio_path) + ezfio_path = os.path.expandvars(ezfio_path) + ezfio_path = os.path.abspath(ezfio_path) + + ezfio.set_file("{0}".format(ezfio_path)) + + # ~#~#~#~#~#~#~#~#~#~#~ # + # P s e u d o _ d a t a # + # ~#~#~#~#~#~#~#~#~#~#~ # + + l_ele = ezfio.get_nuclei_nucl_label() + str_ = get_pseudo_str(l_ele) + + # _ + # |_) _. ._ _ _ + # | (_| | _> (/_ + # + + l_str_ele = [str_ele for str_ele in str_.split("Element Symbol: ") + if str_ele] + + for i in "l_zeff v_k n_k dz_k v_kl n_kl dz_kl".split(): + exec("{0} = []".format(i)) + + alpha_tot = 0 + beta_tot = 0 + + for str_ele in l_str_ele: + + # ~#~#~#~#~ # + # S p l i t # + # ~#~#~#~#~ # + + l = str_ele.find("Local component:") + nl = str_ele.find("Non-local component") + + # ~#~#~#~#~ # + # L o c a l # + # ~#~#~#~#~ # + + l_v, l_n, l_dz = get_v_n_dz_local(str_ele[l:nl]) + + v_k.append(l_v) + n_k.append(l_n) + dz_k.append(l_dz) + + # ~#~#~#~#~#~#~#~#~ # + # N o n _ L o c a l # + # ~#~#~#~#~#~#~#~#~ # + + l_v_kl, l_n_kl, l_dz_kl = get_v_n_dz_l_nonlocal(str_ele[nl:]) + + v_kl.append(l_v_kl) + n_kl.append(l_n_kl) + dz_kl.append(l_dz_kl) + + # ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~ # + # Z _ e f f , a l p h a / b e t a _ e l e c # + # ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~ # + + zeff, alpha, beta = get_zeff_alpha_beta(str_ele) + + alpha_tot += alpha + beta_tot += beta + l_zeff.append(zeff) + # _ + # /\ _| _| _|_ _ _ _ _|_ o _ + # /--\ (_| (_| |_ (_) (/_ /_ | | (_) + # + + # ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~ # + # Z _ e f f , a l p h a / b e t a _ e l e c # + # ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~ # + + ezfio.nuclei_nucl_charge = l_zeff + + alpha_tot = ezfio.get_electrons_elec_alpha_num() - alpha_tot + beta_tot = ezfio.get_electrons_elec_beta_num() - beta_tot + + ezfio.electrons_elec_alpha_num = alpha_tot + ezfio.electrons_elec_beta_num = beta_tot + + # Change all the array 'cause EZFIO + # v_kl (v, l) => v_kl(l,v) + # v_kl => zip(*_v_kl) + # [[7.0, 79.74474797, -49.45159098], [1.0, 5.41040609, -4.60151975]] + # [(7.0, 1.0), (79.74474797, 5.41040609), (-49.45159098, -4.60151975)] + + # ~#~#~#~#~ # + # L o c a l # + # ~#~#~#~#~ # + + klocmax = max([len(i) for i in v_k]) + ezfio.pseudo_integrals_klocmax = klocmax + + ezfio.pseudo_integrals_v_k = zip(*v_k) + ezfio.pseudo_integrals_n_k = zip(*n_k) + ezfio.pseudo_integrals_dz_k = zip(*dz_k) + + # ~#~#~#~#~#~#~#~#~ # + # N o n _ L o c a l # + # ~#~#~#~#~#~#~#~#~ # + + lmax = max([len(i) for i in v_kl]) + kmax = max([len(sublist) for list_ in v_kl for sublist in list_]) + + ezfio.pseudo_integrals_lmaxpo = lmax + ezfio.pseudo_integrals_kmax = kmax + + v_kl = make_it_square(v_kl, [lmax, kmax]) + n_kl = make_it_square(n_kl, [lmax, kmax], int) + dz_kl = make_it_square(dz_kl, [lmax, kmax]) + + ezfio.pseudo_integrals_v_kl = zip(*v_kl) + ezfio.pseudo_integrals_n_kl = zip(*n_kl) + ezfio.pseudo_integrals_dz_kl = zip(*dz_kl) + + ezfio.pseudo_integrals_do_pseudo = True diff --git a/scripts/qp_include.sh b/scripts/qp_include.sh index 467baca8..8e2d4f9f 100644 --- a/scripts/qp_include.sh +++ b/scripts/qp_include.sh @@ -35,9 +35,10 @@ function check_current_dir_is_module() exit -1 fi } -if [[ -f NEEDED_MODULES ]] + +if [[ -f NEEDED_CHILDREN_MODULES ]] then - NEEDED_MODULES=$(cat NEEDED_MODULES) + NEEDED_MODULES=$(module_handler.py print_genealogy NEEDED_CHILDREN_MODULES) fi # List of executables in the current directory diff --git a/scripts/qp_utils.py b/scripts/qp_utils.py new file mode 100644 index 00000000..9be4ea2c --- /dev/null +++ b/scripts/qp_utils.py @@ -0,0 +1,17 @@ +from functools import wraps + +def cache(func): + """ + A decorator for lazy evaluation off true function + """ + saved = {} + + @wraps(func) + def newfunc(*args): + if args in saved: + return saved[args] + + result = func(*args) + saved[args] = result + return result + return newfunc diff --git a/scripts/run_Makefile_common.sh b/scripts/run_Makefile_common.sh index 82e898ac..859cc8d0 100755 --- a/scripts/run_Makefile_common.sh +++ b/scripts/run_Makefile_common.sh @@ -14,7 +14,7 @@ check_current_dir_is_module # Check if the NEEDED_MODULES file is consistent INCLUDE_DIRS="${NEEDED_MODULES} include" -NEEDED_MODULES_OK=$( ${QPACKAGE_ROOT}/scripts/check_dependencies.sh ${NEEDED_MODULES} ) +NEEDED_MODULES_OK=$(module_handler.py check_dependencies ${NEEDED_MODULES} ) if [[ $? -ne 0 ]] then error " @@ -28,7 +28,7 @@ fi # Check if README.rst exists if [[ ! -f README.rst ]] then - ${QPACKAGE_ROOT}/scripts/create_rst_templates.sh + ${QPACKAGE_ROOT}/scripts/module/create_rst_templates.sh error " README.rst was not present, so I created a default one for you. @@ -62,7 +62,7 @@ then fi # Update Makefile.depend -${QPACKAGE_ROOT}/scripts/create_Makefile_depend.sh +${QPACKAGE_ROOT}/scripts/module/create_Makefile_depend.sh # Update EZFIO interface - ${QPACKAGE_ROOT}/scripts/ezfio_interface/ei_handler.py +${QPACKAGE_ROOT}/scripts/ezfio_interface/ei_handler.py diff --git a/scripts/run_Makefile_global.sh b/scripts/run_Makefile_global.sh index fc9e168a..869172a2 100755 --- a/scripts/run_Makefile_global.sh +++ b/scripts/run_Makefile_global.sh @@ -52,7 +52,7 @@ ${IRPF90_VERSION}. IRPF90 version >= ${IRPF90_REQUIRED_VERSION} is required. To upgrade IRPF90, run : - ${QPACKAGE_ROOT}/scripts/upgrade_irpf90.sh + ${QPACKAGE_ROOT}/scripts/upgrade/upgrade_irpf90.sh " else info "irpf90 version is OK" @@ -75,7 +75,7 @@ then Current EZFIO version : ${EZFIO_VERSION} EZFIO version >= ${EZFIO_REQUIRED_VERSION} is required. To upgrade EZFIO, run : - ${QPACKAGE_ROOT}/scripts/upgrade_ezfio.sh + ${QPACKAGE_ROOT}/scripts/upgrade/upgrade_ezfio.sh " else info "EZFIO version is OK" diff --git a/scripts/update_README.py b/scripts/update_README.py index 0f32404d..177d57a4 100755 --- a/scripts/update_README.py +++ b/scripts/update_README.py @@ -83,7 +83,7 @@ def update_needed(data): """Read the NEEDED_MODULES file, and replace the data with it. Create the links to the GitHub pages.""" - file = open('NEEDED_MODULES', 'r') + file = open('NEEDED_CHILDREN_MODULES', 'r') modules = file.read() file.close() diff --git a/scripts/upgrade_ezfio.sh b/scripts/upgrade/upgrade_ezfio.sh similarity index 91% rename from scripts/upgrade_ezfio.sh rename to scripts/upgrade/upgrade_ezfio.sh index 4a9af403..c35a2dbd 100755 --- a/scripts/upgrade_ezfio.sh +++ b/scripts/upgrade/upgrade_ezfio.sh @@ -12,7 +12,7 @@ fi cd -- ${QPACKAGE_ROOT} mv -- ${QPACKAGE_ROOT}/EZFIO ${QPACKAGE_ROOT}/EZFIO.old -${QPACKAGE_ROOT}/scripts/install_ezfio.sh +${QPACKAGE_ROOT}/scripts/install/install_ezfio.sh if [[ $? -eq 0 ]] then diff --git a/scripts/upgrade_irpf90.sh b/scripts/upgrade/upgrade_irpf90.sh similarity index 91% rename from scripts/upgrade_irpf90.sh rename to scripts/upgrade/upgrade_irpf90.sh index 5735754f..dea48014 100755 --- a/scripts/upgrade_irpf90.sh +++ b/scripts/upgrade/upgrade_irpf90.sh @@ -12,7 +12,7 @@ fi cd -- ${QPACKAGE_ROOT} mv -f -- ${QPACKAGE_ROOT}/irpf90 ${QPACKAGE_ROOT}/irpf90.old -${QPACKAGE_ROOT}/scripts/install_irpf90.sh +${QPACKAGE_ROOT}/scripts/install/install_irpf90.sh if [[ $? -eq 0 ]] then diff --git a/setup_environment.sh b/setup_environment.sh index be4bae64..878c23e1 100755 --- a/setup_environment.sh +++ b/setup_environment.sh @@ -12,13 +12,15 @@ QPACKAGE_ROOT="$( cd "$(dirname "$BASH_SOURCE")" ; pwd -P )" cat << EOF > quantum_package.rc -export IRPF90="${IRPF90}" export QPACKAGE_ROOT=\$( cd \$(dirname "\${BASH_SOURCE}") ; pwd -P ) +export IRPF90="\${QPACKAGE_ROOT}/bin/irpf90" 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:"\${QPACKAGE_ROOT}"/scripts/ezfio_interface -export PATH=\${PATH}:"\${QPACKAGE_ROOT}"/scripts:"\${QPACKAGE_ROOT}"/scripts/ezfio_interface + +export PYTHONPATH=\${PYTHONPATH}\$(find "\${QPACKAGE_ROOT}"/scripts -type d -printf ":%p") + +export PATH=\${PATH}\$(find "\${QPACKAGE_ROOT}"/scripts -type d -printf ":%p") export PATH=\${PATH}:"\${QPACKAGE_ROOT}"/bin export PATH=\${PATH}:"\${QPACKAGE_ROOT}"/ocaml source "\${QPACKAGE_ROOT}"/bin/irpman &> /dev/null @@ -28,37 +30,29 @@ EOF source quantum_package.rc echo "${BLUE}===== Installing IRPF90 ===== ${BLACK}" -${QPACKAGE_ROOT}/scripts/install_irpf90.sh | tee install_irpf90.log -if [[ ! -d ${QPACKAGE_ROOT}/irpf90 ]] -then - echo $RED "Error in IRPF90 installation" $BLACK - exit 1 -fi - -if [[ ! -x ${QPACKAGE_ROOT}/bin/irpf90 ]] -then - echo $RED "Error in IRPF90 installation" $BLACK - exit 1 -fi - -if [[ ! -x ${QPACKAGE_ROOT}/bin/irpman ]] +${QPACKAGE_ROOT}/scripts/install/install_irpf90.sh | tee ${QPACKAGE_ROOT}/install_logs/install_irpf90.log +if [[ ! -d ${QPACKAGE_ROOT}/irpf90 ]] || [[ ! -x ${QPACKAGE_ROOT}/bin/irpf90 ]] || [[ ! -x ${QPACKAGE_ROOT}/bin/irpman ]] then echo $RED "Error in IRPF90 installation" $BLACK exit 1 fi +mkdir -p ${QPACKAGE_ROOT}/install_logs echo "${BLUE}===== Installing Zlib ===== ${BLACK}" -${QPACKAGE_ROOT}/scripts/install_zlib.sh | tee install_zlib.log +${QPACKAGE_ROOT}/scripts/install/install_zlib.sh | tee ${QPACKAGE_ROOT}/install_logs/install_zlib.log echo "${BLUE}===== Installing Curl ===== ${BLACK}" -${QPACKAGE_ROOT}/scripts/install_curl.sh | tee install_curl.log +${QPACKAGE_ROOT}/scripts/install/install_curl.sh | tee ${QPACKAGE_ROOT}/install_logs/install_curl.log echo "${BLUE}===== Installing M4 ===== ${BLACK}" -${QPACKAGE_ROOT}/scripts/install_m4.sh | tee install_m4.log +${QPACKAGE_ROOT}/scripts/install/install_m4.sh | tee ${QPACKAGE_ROOT}/install_logs/install_m4.log + +echo "${BLUE}===== Installing Docopt ===== ${BLACK}" +${QPACKAGE_ROOT}/scripts/install/install_docopt.sh | tee ${QPACKAGE_ROOT}/install_logs/install_docopt.log echo "${BLUE}===== Installing EMSL Basis set library ===== ${BLACK}" -${QPACKAGE_ROOT}/scripts/install_emsl.sh | tee install_emsl.log +${QPACKAGE_ROOT}/scripts/install/install_emsl.sh | tee ${QPACKAGE_ROOT}/install_logs/install_emsl.log if [[ ! -d ${QPACKAGE_ROOT}/EMSL_Basis ]] then @@ -68,7 +62,7 @@ fi echo "${BLUE}===== Installing EZFIO ===== ${BLACK}" -${QPACKAGE_ROOT}/scripts/install_ezfio.sh | tee install_ezfio.log +${QPACKAGE_ROOT}/scripts/install/install_ezfio.sh | tee ${QPACKAGE_ROOT}/install_logs/install_ezfio.log if [[ ! -d ${QPACKAGE_ROOT}/EZFIO ]] then echo $RED "Error in EZFIO installation" $BLACK @@ -78,7 +72,7 @@ fi echo "${BLUE}===== Installing Ocaml compiler and libraries ===== ${BLACK}" rm -f -- ocaml/Qptypes.ml -${QPACKAGE_ROOT}/scripts/install_ocaml.sh | tee install_ocaml.log +${QPACKAGE_ROOT}/scripts/install/install_ocaml.sh | tee ${QPACKAGE_ROOT}/install_logs/install_ocaml.log if [[ ! -f ${QPACKAGE_ROOT}/ocaml/Qptypes.ml ]] then @@ -87,7 +81,7 @@ then fi echo "${BLUE}===== Installing resultsFile Python library ===== ${BLACK}" -${QPACKAGE_ROOT}/scripts/install_resultsFile.sh +${QPACKAGE_ROOT}/scripts/install/install_resultsFile.sh if [[ ! -d ${QPACKAGE_ROOT}/resultsFile ]] then echo $RED "Error in resultsFile installation" $BLACK @@ -106,8 +100,7 @@ source ${QPACKAGE_ROOT}/quantum_package.rc " $BLACK -mkdir -p ${QPACKAGE_ROOT}/install_logs -mv ${QPACKAGE_ROOT}/*.log ${QPACKAGE_ROOT}/install_logs/ + if [[ $1 == "--robot" ]] ; then diff --git a/src/AOs/ASSUMPTIONS.rst b/src/AOs/ASSUMPTIONS.rst index 0c8e0ccc..cede1de9 100644 --- a/src/AOs/ASSUMPTIONS.rst +++ b/src/AOs/ASSUMPTIONS.rst @@ -1,8 +1 @@ -* The atomic orbitals are normalized: - - .. math:: - - \int \left(\chi_i({\bf r}) \right)^2 dr = 1 - * The AO coefficients in the EZFIO files are not necessarily normalized and are normalized after reading -* The AO coefficients and exponents are ordered in increasing order of exponents diff --git a/src/AOs/NEEDED_CHILDREN_MODULES b/src/AOs/NEEDED_CHILDREN_MODULES new file mode 100644 index 00000000..2c80725f --- /dev/null +++ b/src/AOs/NEEDED_CHILDREN_MODULES @@ -0,0 +1 @@ +Nuclei diff --git a/src/AOs/NEEDED_MODULES b/src/AOs/NEEDED_MODULES deleted file mode 100644 index 9f7ccbcc..00000000 --- a/src/AOs/NEEDED_MODULES +++ /dev/null @@ -1,2 +0,0 @@ -Ezfio_files Nuclei Output Utils - diff --git a/src/AOs/README.rst b/src/AOs/README.rst index f9f81f5f..3b1675ba 100644 --- a/src/AOs/README.rst +++ b/src/AOs/README.rst @@ -17,20 +17,20 @@ The AO coefficients are normalized as: {\tilde c}_{ki} = \frac{c_{ki}}{ \int \left( (x-X_A)^a (y-Y_A)^b (z-Z_A)^c e^{-\gamma_{ki} |{\bf r} - {\bf R}_A|^2} \right)^2} dr +Warning: ``ao_coef`` contains the AO coefficients given in input. These do not +include the normalization constant of the AO. The ``ao_coef_normalized`` includes +this normalization factor. + +The AOs are also sorted by increasing exponent to accelerate the calculation of +the two electron integrals. + Assumptions =========== .. Do not edit this section. It was auto-generated from the .. NEEDED_MODULES file. -* The atomic orbitals are normalized: - - .. math:: - - \int \left(\chi_i({\bf r}) \right)^2 dr = 1 - * The AO coefficients in the EZFIO files are not necessarily normalized and are normalized after reading -* The AO coefficients and exponents are ordered in increasing order of exponents Needed Modules @@ -39,10 +39,7 @@ Needed Modules .. Do not edit this section. It was auto-generated from the .. NEEDED_MODULES file. -* `Ezfio_files `_ * `Nuclei `_ -* `Output `_ -* `Utils `_ Documentation ============= @@ -70,45 +67,41 @@ Documentation Overlap between atomic basis functions: :math:`\int \chi_i(r) \chi_j(r) dr)` -`ao_coef `_ - Coefficients, exponents and powers of x,y and z +`ao_coef `_ + AO Coefficients, read from input. Those should not be used directly, as + the MOs are expressed on the basis of **normalized** AOs. -`ao_coef_transp `_ - Transposed ao_coef and ao_expo +`ao_coef_normalized `_ + Coefficients including the AO normalization -`ao_coef_unnormalized `_ - Coefficients, exponents and powers of x,y and z as in the EZFIO file - ao_coef(i,j) = coefficient of the jth primitive on the ith ao +`ao_coef_normalized_ordered `_ + Sorted primitives to accelerate 4 index MO transformation + +`ao_coef_normalized_ordered_transp `_ + Transposed ao_coef_normalized_ordered + +`ao_expo `_ + AO Exponents read from input + +`ao_expo_ordered `_ + Sorted primitives to accelerate 4 index MO transformation + +`ao_expo_ordered_transp `_ + Transposed ao_expo_ordered + +`ao_l `_ ao_l = l value of the AO: a+b+c in x^a y^b z^c -`ao_expo `_ - Coefficients, exponents and powers of x,y and z - -`ao_expo_transp `_ - Transposed ao_coef and ao_expo - -`ao_expo_unsorted `_ - Coefficients, exponents and powers of x,y and z as in the EZFIO file - ao_coef(i,j) = coefficient of the jth primitive on the ith ao +`ao_l_char `_ ao_l = l value of the AO: a+b+c in x^a y^b z^c -`ao_l `_ - Coefficients, exponents and powers of x,y and z as in the EZFIO file - ao_coef(i,j) = coefficient of the jth primitive on the ith ao - ao_l = l value of the AO: a+b+c in x^a y^b z^c - -`ao_l_char `_ - Coefficients, exponents and powers of x,y and z as in the EZFIO file - ao_coef(i,j) = coefficient of the jth primitive on the ith ao - ao_l = l value of the AO: a+b+c in x^a y^b z^c - -`ao_l_char_space `_ +`ao_l_char_space `_ Undocumented -`ao_md5 `_ +`ao_md5 `_ MD5 key characteristic of the AO basis -`ao_nucl `_ +`ao_nucl `_ Index of the nuclei on which the ao is centered `ao_num `_ @@ -118,35 +111,35 @@ Documentation Number of atomic orbitals `ao_power `_ - Coefficients, exponents and powers of x,y and z + Powers of x,y and z read from input -`ao_prim_num `_ +`ao_prim_num `_ Number of primitives per atomic orbital -`ao_prim_num_max `_ +`ao_prim_num_max `_ Undocumented -`ao_prim_num_max_align `_ +`ao_prim_num_max_align `_ Undocumented -`l_to_charater `_ +`l_to_charater `_ character corresponding to the "L" value of an AO orbital -`n_aos_max `_ +`n_aos_max `_ Number of AOs per atom -`nucl_aos `_ +`nucl_aos `_ List of AOs attached on each atom -`nucl_list_shell_aos `_ +`nucl_list_shell_aos `_ Index of the shell type Aos and of the corresponding Aos Per convention, for P,D,F and G AOs, we take the index of the AO with the the corresponding power in the "X" axis -`nucl_n_aos `_ +`nucl_n_aos `_ Number of AOs per atom -`nucl_num_shell_aos `_ +`nucl_num_shell_aos `_ Index of the shell type Aos and of the corresponding Aos Per convention, for P,D,F and G AOs, we take the index of the AO with the the corresponding power in the "X" axis diff --git a/src/AOs/ao_overlap.irp.f b/src/AOs/ao_overlap.irp.f index f77924d3..737f03f7 100644 --- a/src/AOs/ao_overlap.irp.f +++ b/src/AOs/ao_overlap.irp.f @@ -21,8 +21,8 @@ !$OMP overlap_x,overlap_y, overlap_z, overlap, & !$OMP alpha, beta,i,j,c) & !$OMP SHARED(nucl_coord,ao_power,ao_prim_num, & - !$OMP ao_overlap_x,ao_overlap_y,ao_overlap_z,ao_overlap,ao_num,ao_coef_transp,ao_nucl, & - !$OMP ao_expo_transp,dim1) + !$OMP ao_overlap_x,ao_overlap_y,ao_overlap_z,ao_overlap,ao_num,ao_coef_normalized_ordered_transp,ao_nucl, & + !$OMP ao_expo_ordered_transp,dim1) do j=1,ao_num A_center(1) = nucl_coord( ao_nucl(j), 1 ) A_center(2) = nucl_coord( ao_nucl(j), 2 ) @@ -44,12 +44,12 @@ power_B(2) = ao_power( i, 2 ) power_B(3) = ao_power( i, 3 ) do n = 1,ao_prim_num(j) - alpha = ao_expo_transp(n,j) + alpha = ao_expo_ordered_transp(n,j) !DEC$ VECTOR ALIGNED do l = 1, ao_prim_num(i) - beta = ao_expo_transp(l,i) + beta = ao_expo_ordered_transp(l,i) call overlap_gaussian_xyz(A_center,B_center,alpha,beta,power_A,power_B,overlap_x,overlap_y,overlap_z,overlap,dim1) - c = ao_coef_transp(n,j) * ao_coef_transp(l,i) + c = ao_coef_normalized_ordered_transp(n,j) * ao_coef_normalized_ordered_transp(l,i) ao_overlap(i,j) += c * overlap ao_overlap_x(i,j) += c * overlap_x ao_overlap_y(i,j) += c * overlap_y @@ -84,8 +84,8 @@ BEGIN_PROVIDER [ double precision, ao_overlap_abs,(ao_num_align,ao_num) ] !$OMP overlap_x,overlap_y, overlap_z, overlap, & !$OMP alpha, beta,i,j,dx) & !$OMP SHARED(nucl_coord,ao_power,ao_prim_num, & - !$OMP ao_overlap_abs,ao_num,ao_coef_transp,ao_nucl, & - !$OMP ao_expo_transp,dim1,lower_exp_val) + !$OMP ao_overlap_abs,ao_num,ao_coef_normalized_ordered_transp,ao_nucl, & + !$OMP ao_expo_ordered_transp,dim1,lower_exp_val) do j=1,ao_num A_center(1) = nucl_coord( ao_nucl(j), 1 ) A_center(2) = nucl_coord( ao_nucl(j), 2 ) @@ -104,14 +104,14 @@ BEGIN_PROVIDER [ double precision, ao_overlap_abs,(ao_num_align,ao_num) ] power_B(2) = ao_power( i, 2 ) power_B(3) = ao_power( i, 3 ) do n = 1,ao_prim_num(j) - alpha = ao_expo_transp(n,j) + alpha = ao_expo_ordered_transp(n,j) !DEC$ VECTOR ALIGNED do l = 1, ao_prim_num(i) - beta = ao_expo_transp(l,i) + beta = ao_expo_ordered_transp(l,i) call overlap_x_abs(A_center(1),B_center(1),alpha,beta,power_A(1),power_B(1),overlap_x,lower_exp_val,dx,dim1) call overlap_x_abs(A_center(2),B_center(2),alpha,beta,power_A(2),power_B(2),overlap_y,lower_exp_val,dx,dim1) call overlap_x_abs(A_center(3),B_center(3),alpha,beta,power_A(3),power_B(3),overlap_z,lower_exp_val,dx,dim1) - ao_overlap_abs(i,j) += abs(ao_coef_transp(n,j) * ao_coef_transp(l,i)) * overlap_x * overlap_y * overlap_z + ao_overlap_abs(i,j) += abs(ao_coef_normalized_ordered_transp(n,j) * ao_coef_normalized_ordered_transp(l,i)) * overlap_x * overlap_y * overlap_z enddo enddo enddo diff --git a/src/AOs/aos.irp.f b/src/AOs/aos.irp.f index c75694fb..b9c82327 100644 --- a/src/AOs/aos.irp.f +++ b/src/AOs/aos.irp.f @@ -1,152 +1,171 @@ BEGIN_PROVIDER [ integer, ao_num ] &BEGIN_PROVIDER [ integer, ao_num_align ] - implicit none - - BEGIN_DOC -! Number of atomic orbitals - END_DOC - - ao_num = -1 - PROVIDE ezfio_filename - call ezfio_get_ao_basis_ao_num(ao_num) - if (ao_num <= 0) then - stop 'Number of contracted gaussians should be > 0' - endif - integer :: align_double - ao_num_align = align_double(ao_num) + implicit none + + BEGIN_DOC + ! Number of atomic orbitals + END_DOC + + ao_num = -1 + PROVIDE ezfio_filename + call ezfio_get_ao_basis_ao_num(ao_num) + if (ao_num <= 0) then + stop 'Number of contracted gaussians should be > 0' + endif + integer :: align_double + ao_num_align = align_double(ao_num) +END_PROVIDER + +BEGIN_PROVIDER [ integer, ao_power, (ao_num_align,3) ] + implicit none + BEGIN_DOC + ! Powers of x,y and z read from input + END_DOC + PROVIDE ezfio_filename + + integer :: i,j,k + integer, allocatable :: ibuffer(:,:) + allocate ( ibuffer(ao_num,3) ) + ibuffer = 0 + call ezfio_get_ao_basis_ao_power(ibuffer) + ao_power = 0 + do j = 1, 3 + do i = 1, ao_num + ao_power(i,j) = ibuffer(i,j) + enddo + enddo + deallocate(ibuffer) + END_PROVIDER - BEGIN_PROVIDER [ integer, ao_power, (ao_num_align,3) ] -&BEGIN_PROVIDER [ double precision, ao_expo, (ao_num_align,ao_prim_num_max) ] -&BEGIN_PROVIDER [ double precision, ao_coef, (ao_num_align,ao_prim_num_max) ] - implicit none - - BEGIN_DOC -! Coefficients, exponents and powers of x,y and z - END_DOC - PROVIDE ezfio_filename - - double precision, allocatable :: buffer(:,:) - allocate ( buffer(ao_num,ao_prim_num_max) ) - integer :: ibuffer(ao_num,3) - integer :: i,j,k - character*(128) :: give_ao_character_space - ibuffer = 0 - call ezfio_get_ao_basis_ao_power(ibuffer) - ao_power = 0 - do j = 1, 3 - do i = 1, ao_num - ao_power(i,j) = ibuffer(i,j) +BEGIN_PROVIDER [ double precision, ao_expo, (ao_num_align,ao_prim_num_max) ] + implicit none + BEGIN_DOC + ! AO Exponents read from input + END_DOC + PROVIDE ezfio_filename + + double precision, allocatable :: buffer(:,:) + allocate ( buffer(ao_num,ao_prim_num_max) ) + integer :: i,j,k + ao_expo = 0.d0 + buffer = 0.d0 + call ezfio_get_ao_basis_ao_expo(buffer) + do j = 1, ao_prim_num_max + do i = 1, ao_num + ao_expo(i,j) = buffer(i,j) + enddo enddo - enddo - ao_expo = 0.d0 - buffer = 0.d0 - call ezfio_get_ao_basis_ao_expo(buffer) - do j = 1, ao_prim_num_max - do i = 1, ao_num - ao_expo(i,j) = buffer(i,j) - enddo - enddo + deallocate(buffer) +END_PROVIDER - ao_coef = 0.d0 - buffer = 0.d0 - call ezfio_get_ao_basis_ao_coef(buffer) - do j = 1, ao_prim_num_max - do i = 1, ao_num - ao_coef(i,j) = buffer(i,j) +BEGIN_PROVIDER [ double precision, ao_coef, (ao_num_align,ao_prim_num_max) ] + implicit none + BEGIN_DOC + ! AO Coefficients, read from input. Those should not be used directly, as + ! the MOs are expressed on the basis of **normalized** AOs. + END_DOC + PROVIDE ezfio_filename + + double precision, allocatable :: buffer(:,:) + allocate ( buffer(ao_num,ao_prim_num_max) ) + integer :: i,j,k + ao_coef = 0.d0 + buffer = 0.d0 + call ezfio_get_ao_basis_ao_coef(buffer) + do j = 1, ao_prim_num_max + do i = 1, ao_num + ao_coef(i,j) = buffer(i,j) + enddo enddo - enddo + deallocate(buffer) +END_PROVIDER - deallocate(buffer) +BEGIN_PROVIDER [ double precision, ao_coef_normalized, (ao_num_align,ao_prim_num_max) ] + implicit none + BEGIN_DOC + ! Coefficients including the AO normalization + END_DOC + double precision :: norm, norm2,overlap_x,overlap_y,overlap_z,C_A(3) + integer :: l, powA(3), nz + integer :: i,j + nz=100 + C_A(1) = 0.d0 + C_A(2) = 0.d0 + C_A(3) = 0.d0 + do i=1,ao_num + powA(1) = ao_power(i,1) + powA(2) = ao_power(i,2) + powA(3) = ao_power(i,3) + do j=1,ao_prim_num(i) + call overlap_gaussian_xyz(C_A,C_A,ao_expo(i,j),ao_expo(i,j),powA,powA,overlap_x,overlap_y,overlap_z,norm,nz) + ao_coef_normalized(i,j) = ao_coef(i,j)/sqrt(norm) + enddo + enddo +END_PROVIDER -! Normalization of the AO coefficients -! ------------------------------------ - double precision :: norm, norm2,overlap_x,overlap_y,overlap_z,C_A(3) - integer :: l, powA(3), nz - nz=100 - C_A(1) = 0.d0 - C_A(2) = 0.d0 - C_A(3) = 0.d0 - do i=1,ao_num - powA(1) = ao_power(i,1) - powA(2) = ao_power(i,2) - powA(3) = ao_power(i,3) - do j=1,ao_prim_num(i) - call overlap_gaussian_xyz(C_A,C_A,ao_expo(i,j),ao_expo(i,j),powA,powA,overlap_x,overlap_y,overlap_z,norm,nz) - ao_coef(i,j) = ao_coef(i,j)/sqrt(norm) - enddo - enddo - - ! Sorting of the exponents for efficient integral calculations - integer :: iorder(ao_prim_num_max) - double precision :: d(ao_prim_num_max,2) - do i=1,ao_num - do j=1,ao_prim_num(i) - iorder(j) = j - d(j,1) = ao_expo(i,j) - d(j,2) = ao_coef(i,j) - enddo - call dsort(d(1,1),iorder,ao_prim_num(i)) - call dset_order(d(1,2),iorder,ao_prim_num(i)) - do j=1,ao_prim_num(i) - ao_expo(i,j) = d(j,1) - ao_coef(i,j) = d(j,2) - enddo - enddo + BEGIN_PROVIDER [ double precision, ao_coef_normalized_ordered, (ao_num_align,ao_prim_num_max) ] +&BEGIN_PROVIDER [ double precision, ao_expo_ordered, (ao_num_align,ao_prim_num_max) ] + implicit none + BEGIN_DOC + ! Sorted primitives to accelerate 4 index MO transformation + END_DOC + + integer :: iorder(ao_prim_num_max) + double precision :: d(ao_prim_num_max,2) + integer :: i,j + do i=1,ao_num + do j=1,ao_prim_num(i) + iorder(j) = j + d(j,1) = ao_expo(i,j) + d(j,2) = ao_coef_normalized(i,j) + enddo + call dsort(d(1,1),iorder,ao_prim_num(i)) + call dset_order(d(1,2),iorder,ao_prim_num(i)) + do j=1,ao_prim_num(i) + ao_expo_ordered(i,j) = d(j,1) + ao_coef_normalized_ordered(i,j) = d(j,2) + enddo + enddo END_PROVIDER - BEGIN_PROVIDER [ double precision, ao_coef_transp, (ao_prim_num_max_align,ao_num) ] -&BEGIN_PROVIDER [ double precision, ao_expo_transp, (ao_prim_num_max_align,ao_num) ] - implicit none - BEGIN_DOC -! Transposed ao_coef and ao_expo - END_DOC - integer :: i,j - do j=1, ao_num - do i=1, ao_prim_num_max - ao_coef_transp(i,j) = ao_coef(j,i) - ao_expo_transp(i,j) = ao_expo(j,i) +BEGIN_PROVIDER [ double precision, ao_coef_normalized_ordered_transp, (ao_prim_num_max_align,ao_num) ] + implicit none + BEGIN_DOC + ! Transposed ao_coef_normalized_ordered + END_DOC + integer :: i,j + do j=1, ao_num + do i=1, ao_prim_num_max + ao_coef_normalized_ordered_transp(i,j) = ao_coef_normalized_ordered(j,i) + enddo enddo - enddo - - + END_PROVIDER - BEGIN_PROVIDER [ double precision, ao_coef_unnormalized, (ao_num_align,ao_prim_num_max) ] -&BEGIN_PROVIDER [ double precision, ao_expo_unsorted, (ao_num_align,ao_prim_num_max) ] -&BEGIN_PROVIDER [ integer, ao_l, (ao_num) ] +BEGIN_PROVIDER [ double precision, ao_expo_ordered_transp, (ao_prim_num_max_align,ao_num) ] + implicit none + BEGIN_DOC + ! Transposed ao_expo_ordered + END_DOC + integer :: i,j + do j=1, ao_num + do i=1, ao_prim_num_max + ao_expo_ordered_transp(i,j) = ao_expo_ordered(j,i) + enddo + enddo + +END_PROVIDER + + + BEGIN_PROVIDER [ integer, ao_l, (ao_num) ] &BEGIN_PROVIDER [ character*(128), ao_l_char, (ao_num) ] implicit none - BEGIN_DOC -! Coefficients, exponents and powers of x,y and z as in the EZFIO file -! ao_coef(i,j) = coefficient of the jth primitive on the ith ao ! ao_l = l value of the AO: a+b+c in x^a y^b z^c END_DOC - PROVIDE ezfio_filename - - double precision, allocatable :: buffer(:,:) - allocate ( buffer(ao_num,ao_prim_num_max) ) - integer :: i,j,k - character*(128) :: give_ao_character_space - buffer = 0.d0 - call ezfio_get_ao_basis_ao_expo(buffer) - do j = 1, ao_prim_num_max - do i = 1, ao_num - ao_expo_unsorted(i,j) = buffer(i,j) - enddo - enddo - - buffer = 0.d0 - call ezfio_get_ao_basis_ao_coef(buffer) - do j = 1, ao_prim_num_max - do i = 1, ao_num - ao_coef_unnormalized(i,j) = buffer(i,j) - enddo - enddo - deallocate(buffer) - + integer :: i do i=1,ao_num ao_l(i) = ao_power(i,1) + ao_power(i,2) + ao_power(i,3) ao_l_char(i) = l_to_charater(ao_l(i)) @@ -154,23 +173,6 @@ END_PROVIDER END_PROVIDER - BEGIN_PROVIDER [ double precision, ao_coef_transp, (ao_prim_num_max_align,ao_num) ] -&BEGIN_PROVIDER [ double precision, ao_expo_transp, (ao_prim_num_max_align,ao_num) ] - implicit none - BEGIN_DOC -! Transposed ao_coef and ao_expo - END_DOC - integer :: i,j - do j=1, ao_num - do i=1, ao_prim_num_max - ao_coef_transp(i,j) = ao_coef(j,i) - ao_expo_transp(i,j) = ao_expo(j,i) - enddo - enddo - - -END_PROVIDER - BEGIN_PROVIDER [ integer, ao_prim_num, (ao_num_align) ] implicit none @@ -303,10 +305,10 @@ END_PROVIDER enddo enddo - END_PROVIDER +END_PROVIDER - BEGIN_PROVIDER [ character*(4), ao_l_char_space, (ao_num) ] +BEGIN_PROVIDER [ character*(4), ao_l_char_space, (ao_num) ] implicit none integer :: i character*(4) :: give_ao_character_space @@ -397,6 +399,7 @@ END_PROVIDER ao_l_char_space(i) = give_ao_character_space enddo END_PROVIDER + BEGIN_PROVIDER [ character*(32), ao_md5 ] BEGIN_DOC ! MD5 key characteristic of the AO basis diff --git a/src/Bielec_integrals/NEEDED_CHILDREN_MODULES b/src/Bielec_integrals/NEEDED_CHILDREN_MODULES new file mode 100644 index 00000000..24979463 --- /dev/null +++ b/src/Bielec_integrals/NEEDED_CHILDREN_MODULES @@ -0,0 +1 @@ +MonoInts Bitmask diff --git a/src/Bielec_integrals/NEEDED_MODULES b/src/Bielec_integrals/NEEDED_MODULES deleted file mode 100644 index 5f709ce4..00000000 --- a/src/Bielec_integrals/NEEDED_MODULES +++ /dev/null @@ -1 +0,0 @@ -AOs Bitmask Electrons Ezfio_files MOs Nuclei Output Utils MonoInts diff --git a/src/Bielec_integrals/README.rst b/src/Bielec_integrals/README.rst index 38dc9e96..d4bbb16b 100644 --- a/src/Bielec_integrals/README.rst +++ b/src/Bielec_integrals/README.rst @@ -16,15 +16,8 @@ Needed Modules .. Do not edit this section. It was auto-generated from the .. NEEDED_MODULES file. -* `AOs `_ -* `Bitmask `_ -* `Electrons `_ -* `Ezfio_files `_ -* `MOs `_ -* `Nuclei `_ -* `Output `_ -* `Utils `_ * `MonoInts `_ +* `Bitmask `_ Documentation ============= @@ -36,7 +29,7 @@ Documentation integral of the AO basis or (ij|kl) i(r1) j(r1) 1/r12 k(r2) l(r2) -`ao_bielec_integral_schwartz `_ +`ao_bielec_integral_schwartz `_ Needed to compute Schwartz inequalities `ao_bielec_integral_schwartz_accel `_ @@ -53,48 +46,48 @@ Documentation `compute_ao_bielec_integrals `_ Compute AO 1/r12 integrals for all i and fixed j,k,l -`eri `_ +`eri `_ ATOMIC PRIMTIVE bielectronic integral between the 4 primitives :: primitive_1 = x1**(a_x) y1**(a_y) z1**(a_z) exp(-alpha * r1**2) primitive_2 = x1**(b_x) y1**(b_y) z1**(b_z) exp(- beta * r1**2) primitive_3 = x2**(c_x) y2**(c_y) z2**(c_z) exp(-delta * r2**2) primitive_4 = x2**(d_x) y2**(d_y) z2**(d_z) exp(- gama * r2**2) -`general_primitive_integral `_ +`general_primitive_integral `_ Computes the integral where p,q,r,s are Gaussian primitives -`give_polynom_mult_center_x `_ +`give_polynom_mult_center_x `_ subroutine that returns the explicit polynom in term of the "t" variable of the following polynomw : I_x1(a_x, d_x,p,q) * I_x1(a_y, d_y,p,q) * I_x1(a_z, d_z,p,q) -`i_x1_new `_ +`i_x1_new `_ recursive function involved in the bielectronic integral -`i_x1_pol_mult `_ +`i_x1_pol_mult `_ recursive function involved in the bielectronic integral -`i_x1_pol_mult_a1 `_ +`i_x1_pol_mult_a1 `_ recursive function involved in the bielectronic integral -`i_x1_pol_mult_a2 `_ +`i_x1_pol_mult_a2 `_ recursive function involved in the bielectronic integral -`i_x1_pol_mult_recurs `_ +`i_x1_pol_mult_recurs `_ recursive function involved in the bielectronic integral -`i_x2_new `_ +`i_x2_new `_ recursive function involved in the bielectronic integral -`i_x2_pol_mult `_ +`i_x2_pol_mult `_ recursive function involved in the bielectronic integral -`integrale_new `_ +`integrale_new `_ calculate the integral of the polynom :: I_x1(a_x+b_x, c_x+d_x,p,q) * I_x1(a_y+b_y, c_y+d_y,p,q) * I_x1(a_z+b_z, c_z+d_z,p,q) between ( 0 ; 1) -`n_pt_sup `_ +`n_pt_sup `_ Returns the upper boundary of the degree of the polynomial involved in the bielctronic integral : Ix(a_x,b_x,c_x,d_x) * Iy(a_y,b_y,c_y,d_y) * Iz(a_z,b_z,c_z,d_z) @@ -172,32 +165,32 @@ Documentation `add_integrals_to_map `_ Adds integrals to tha MO map according to some bitmask -`mo_bielec_integral_jj `_ +`mo_bielec_integral_jj `_ mo_bielec_integral_jj(i,j) = J_ij mo_bielec_integral_jj_exchange(i,j) = K_ij mo_bielec_integral_jj_anti(i,j) = J_ij - K_ij -`mo_bielec_integral_jj_anti `_ +`mo_bielec_integral_jj_anti `_ mo_bielec_integral_jj(i,j) = J_ij mo_bielec_integral_jj_exchange(i,j) = K_ij mo_bielec_integral_jj_anti(i,j) = J_ij - K_ij -`mo_bielec_integral_jj_anti_from_ao `_ +`mo_bielec_integral_jj_anti_from_ao `_ mo_bielec_integral_jj_from_ao(i,j) = J_ij mo_bielec_integral_jj_exchange_from_ao(i,j) = J_ij mo_bielec_integral_jj_anti_from_ao(i,j) = J_ij - K_ij -`mo_bielec_integral_jj_exchange `_ +`mo_bielec_integral_jj_exchange `_ mo_bielec_integral_jj(i,j) = J_ij mo_bielec_integral_jj_exchange(i,j) = K_ij mo_bielec_integral_jj_anti(i,j) = J_ij - K_ij -`mo_bielec_integral_jj_exchange_from_ao `_ +`mo_bielec_integral_jj_exchange_from_ao `_ mo_bielec_integral_jj_from_ao(i,j) = J_ij mo_bielec_integral_jj_exchange_from_ao(i,j) = J_ij mo_bielec_integral_jj_anti_from_ao(i,j) = J_ij - K_ij -`mo_bielec_integral_jj_from_ao `_ +`mo_bielec_integral_jj_from_ao `_ mo_bielec_integral_jj_from_ao(i,j) = J_ij mo_bielec_integral_jj_exchange_from_ao(i,j) = J_ij mo_bielec_integral_jj_anti_from_ao(i,j) = J_ij - K_ij diff --git a/src/Bielec_integrals/ao_bi_integrals.irp.f b/src/Bielec_integrals/ao_bi_integrals.irp.f index 0da76021..77f9a098 100644 --- a/src/Bielec_integrals/ao_bi_integrals.irp.f +++ b/src/Bielec_integrals/ao_bi_integrals.irp.f @@ -42,24 +42,24 @@ double precision function ao_bielec_integral(i,j,k,l) do p = 1, ao_prim_num(i) double precision :: coef1 - coef1 = ao_coef_transp(p,i) + coef1 = ao_coef_normalized_ordered_transp(p,i) do q = 1, ao_prim_num(j) double precision :: coef2 - coef2 = coef1*ao_coef_transp(q,j) + coef2 = coef1*ao_coef_normalized_ordered_transp(q,j) double precision :: p_inv,q_inv call give_explicit_poly_and_gaussian(P_new,P_center,pp,fact_p,iorder_p,& - ao_expo_transp(p,i),ao_expo_transp(q,j), & + ao_expo_ordered_transp(p,i),ao_expo_ordered_transp(q,j), & I_power,J_power,I_center,J_center,dim1) p_inv = 1.d0/pp do r = 1, ao_prim_num(k) double precision :: coef3 - coef3 = coef2*ao_coef_transp(r,k) + coef3 = coef2*ao_coef_normalized_ordered_transp(r,k) do s = 1, ao_prim_num(l) double precision :: coef4 - coef4 = coef3*ao_coef_transp(s,l) + coef4 = coef3*ao_coef_normalized_ordered_transp(s,l) double precision :: general_primitive_integral call give_explicit_poly_and_gaussian(Q_new,Q_center,qq,fact_q,iorder_q,& - ao_expo_transp(r,k),ao_expo_transp(s,l), & + ao_expo_ordered_transp(r,k),ao_expo_ordered_transp(s,l), & K_power,L_power,K_center,L_center,dim1) q_inv = 1.d0/qq integral = general_primitive_integral(dim1, & @@ -82,15 +82,15 @@ double precision function ao_bielec_integral(i,j,k,l) double precision :: ERI do p = 1, ao_prim_num(i) - coef1 = ao_coef_transp(p,i) + coef1 = ao_coef_normalized_ordered_transp(p,i) do q = 1, ao_prim_num(j) - coef2 = coef1*ao_coef_transp(q,j) + coef2 = coef1*ao_coef_normalized_ordered_transp(q,j) do r = 1, ao_prim_num(k) - coef3 = coef2*ao_coef_transp(r,k) + coef3 = coef2*ao_coef_normalized_ordered_transp(r,k) do s = 1, ao_prim_num(l) - coef4 = coef3*ao_coef_transp(s,l) + coef4 = coef3*ao_coef_normalized_ordered_transp(s,l) integral = ERI( & - ao_expo_transp(p,i),ao_expo_transp(q,j),ao_expo_transp(r,k),ao_expo_transp(s,l),& + ao_expo_ordered_transp(p,i),ao_expo_ordered_transp(q,j),ao_expo_ordered_transp(r,k),ao_expo_ordered_transp(s,l),& I_power(1),J_power(1),K_power(1),L_power(1), & I_power(2),J_power(2),K_power(2),L_power(2), & I_power(3),J_power(3),K_power(3),L_power(3)) @@ -149,12 +149,12 @@ double precision function ao_bielec_integral_schwartz_accel(i,j,k,l) schwartz_kl(0,0) = 0.d0 do r = 1, ao_prim_num(k) - coef1 = ao_coef_transp(r,k)*ao_coef_transp(r,k) + coef1 = ao_coef_normalized_ordered_transp(r,k)*ao_coef_normalized_ordered_transp(r,k) schwartz_kl(0,r) = 0.d0 do s = 1, ao_prim_num(l) - coef2 = coef1 * ao_coef_transp(s,l) * ao_coef_transp(s,l) + coef2 = coef1 * ao_coef_normalized_ordered_transp(s,l) * ao_coef_normalized_ordered_transp(s,l) call give_explicit_poly_and_gaussian(Q_new,Q_center,qq,fact_q,iorder_q,& - ao_expo_transp(r,k),ao_expo_transp(s,l), & + ao_expo_ordered_transp(r,k),ao_expo_ordered_transp(s,l), & K_power,L_power,K_center,L_center,dim1) q_inv = 1.d0/qq schwartz_kl(s,r) = general_primitive_integral(dim1, & @@ -168,13 +168,13 @@ double precision function ao_bielec_integral_schwartz_accel(i,j,k,l) do p = 1, ao_prim_num(i) double precision :: coef1 - coef1 = ao_coef_transp(p,i) + coef1 = ao_coef_normalized_ordered_transp(p,i) do q = 1, ao_prim_num(j) double precision :: coef2 - coef2 = coef1*ao_coef_transp(q,j) + coef2 = coef1*ao_coef_normalized_ordered_transp(q,j) double precision :: p_inv,q_inv call give_explicit_poly_and_gaussian(P_new,P_center,pp,fact_p,iorder_p,& - ao_expo_transp(p,i),ao_expo_transp(q,j), & + ao_expo_ordered_transp(p,i),ao_expo_ordered_transp(q,j), & I_power,J_power,I_center,J_center,dim1) p_inv = 1.d0/pp schwartz_ij = general_primitive_integral(dim1, & @@ -189,16 +189,16 @@ double precision function ao_bielec_integral_schwartz_accel(i,j,k,l) cycle endif double precision :: coef3 - coef3 = coef2*ao_coef_transp(r,k) + coef3 = coef2*ao_coef_normalized_ordered_transp(r,k) do s = 1, ao_prim_num(l) double precision :: coef4 if (schwartz_kl(s,r)*schwartz_ij < thresh) then cycle endif - coef4 = coef3*ao_coef_transp(s,l) + coef4 = coef3*ao_coef_normalized_ordered_transp(s,l) double precision :: general_primitive_integral call give_explicit_poly_and_gaussian(Q_new,Q_center,qq,fact_q,iorder_q,& - ao_expo_transp(r,k),ao_expo_transp(s,l), & + ao_expo_ordered_transp(r,k),ao_expo_ordered_transp(s,l), & K_power,L_power,K_center,L_center,dim1) q_inv = 1.d0/qq integral = general_primitive_integral(dim1, & @@ -222,12 +222,12 @@ double precision function ao_bielec_integral_schwartz_accel(i,j,k,l) schwartz_kl(0,0) = 0.d0 do r = 1, ao_prim_num(k) - coef1 = ao_coef_transp(r,k)*ao_coef_transp(r,k) + coef1 = ao_coef_normalized_ordered_transp(r,k)*ao_coef_normalized_ordered_transp(r,k) schwartz_kl(0,r) = 0.d0 do s = 1, ao_prim_num(l) - coef2 = coef1*ao_coef_transp(s,l)*ao_coef_transp(s,l) + coef2 = coef1*ao_coef_normalized_ordered_transp(s,l)*ao_coef_normalized_ordered_transp(s,l) schwartz_kl(s,r) = ERI( & - ao_expo_transp(r,k),ao_expo_transp(s,l),ao_expo_transp(r,k),ao_expo_transp(s,l),& + ao_expo_ordered_transp(r,k),ao_expo_ordered_transp(s,l),ao_expo_ordered_transp(r,k),ao_expo_ordered_transp(s,l),& K_power(1),L_power(1),K_power(1),L_power(1), & K_power(2),L_power(2),K_power(2),L_power(2), & K_power(3),L_power(3),K_power(3),L_power(3)) * & @@ -238,11 +238,11 @@ double precision function ao_bielec_integral_schwartz_accel(i,j,k,l) enddo do p = 1, ao_prim_num(i) - coef1 = ao_coef_transp(p,i) + coef1 = ao_coef_normalized_ordered_transp(p,i) do q = 1, ao_prim_num(j) - coef2 = coef1*ao_coef_transp(q,j) + coef2 = coef1*ao_coef_normalized_ordered_transp(q,j) schwartz_ij = ERI( & - ao_expo_transp(p,i),ao_expo_transp(q,j),ao_expo_transp(p,i),ao_expo_transp(q,j),& + ao_expo_ordered_transp(p,i),ao_expo_ordered_transp(q,j),ao_expo_ordered_transp(p,i),ao_expo_ordered_transp(q,j),& I_power(1),J_power(1),I_power(1),J_power(1), & I_power(2),J_power(2),I_power(2),J_power(2), & I_power(3),J_power(3),I_power(3),J_power(3))*coef2*coef2 @@ -253,14 +253,14 @@ double precision function ao_bielec_integral_schwartz_accel(i,j,k,l) if (schwartz_kl(0,r)*schwartz_ij < thresh) then cycle endif - coef3 = coef2*ao_coef_transp(r,k) + coef3 = coef2*ao_coef_normalized_ordered_transp(r,k) do s = 1, ao_prim_num(l) if (schwartz_kl(s,r)*schwartz_ij < thresh) then cycle endif - coef4 = coef3*ao_coef_transp(s,l) + coef4 = coef3*ao_coef_normalized_ordered_transp(s,l) integral = ERI( & - ao_expo_transp(p,i),ao_expo_transp(q,j),ao_expo_transp(r,k),ao_expo_transp(s,l),& + ao_expo_ordered_transp(p,i),ao_expo_ordered_transp(q,j),ao_expo_ordered_transp(r,k),ao_expo_ordered_transp(s,l),& I_power(1),J_power(1),K_power(1),L_power(1), & I_power(2),J_power(2),K_power(2),L_power(2), & I_power(3),J_power(3),K_power(3),L_power(3)) @@ -481,6 +481,7 @@ IRP_ENDIF COARRAY ao_bielec_integrals_in_map = .True. if (write_ao_integrals) then call dump_ao_integrals(trim(ezfio_filename)//'/work/ao_integrals.bin') + call ezfio_set_bielec_integrals_disk_access_ao_integrals(.True.) endif END_PROVIDER diff --git a/src/Bielec_integrals/mo_bi_integrals.irp.f b/src/Bielec_integrals/mo_bi_integrals.irp.f index 5adc980b..4e4c70aa 100644 --- a/src/Bielec_integrals/mo_bi_integrals.irp.f +++ b/src/Bielec_integrals/mo_bi_integrals.irp.f @@ -312,6 +312,7 @@ IRP_ENDIF if (write_mo_integrals) then call dump_mo_integrals(trim(ezfio_filename)//'/work/mo_integrals.bin') + call ezfio_set_bielec_integrals_disk_access_mo_integrals(.True.) endif diff --git a/src/Bitmask/NEEDED_CHILDREN_MODULES b/src/Bitmask/NEEDED_CHILDREN_MODULES new file mode 100644 index 00000000..b936db90 --- /dev/null +++ b/src/Bitmask/NEEDED_CHILDREN_MODULES @@ -0,0 +1 @@ +MOs diff --git a/src/Bitmask/NEEDED_MODULES b/src/Bitmask/NEEDED_MODULES deleted file mode 100644 index 190f8c6e..00000000 --- a/src/Bitmask/NEEDED_MODULES +++ /dev/null @@ -1 +0,0 @@ -AOs Electrons Ezfio_files MOs Nuclei Output Utils diff --git a/src/Bitmask/README.rst b/src/Bitmask/README.rst index b8e3aa57..7eeac8c9 100644 --- a/src/Bitmask/README.rst +++ b/src/Bitmask/README.rst @@ -40,13 +40,7 @@ Needed Modules .. Do not edit this section. It was auto-generated from the .. NEEDED_MODULES file. -* `AOs `_ -* `Electrons `_ -* `Ezfio_files `_ * `MOs `_ -* `Nuclei `_ -* `Output `_ -* `Utils `_ Documentation ============= @@ -134,6 +128,10 @@ Documentation Subroutine to print the content of a determinant in '+-' notation and hexadecimal representation. +`debug_spindet `_ + Subroutine to print the content of a determinant in '+-' notation and + hexadecimal representation. + `list_to_bitstring `_ Returns the physical string "string(N_int,2)" from the array of occupations "list(N_int*bit_kind_size,2) @@ -141,5 +139,8 @@ Documentation `print_det `_ Subroutine to print the content of a determinant using the '+-' notation +`print_spindet `_ + Subroutine to print the content of a determinant using the '+-' notation + diff --git a/src/Bitmask/bitmasks_routines.irp.f b/src/Bitmask/bitmasks_routines.irp.f index 8694f93f..1b3186b1 100644 --- a/src/Bitmask/bitmasks_routines.irp.f +++ b/src/Bitmask/bitmasks_routines.irp.f @@ -126,7 +126,7 @@ subroutine debug_det(string,Nint) END_DOC integer, intent(in) :: Nint integer(bit_kind), intent(in) :: string(Nint,2) - character*(512) :: output(2) + character*(2048) :: output(2) call bitstring_to_hexa( output(1), string(1,1), Nint ) call bitstring_to_hexa( output(2), string(1,2), Nint ) print *, trim(output(1)) , '|', trim(output(2)) @@ -143,7 +143,7 @@ subroutine print_det(string,Nint) END_DOC integer, intent(in) :: Nint integer(bit_kind), intent(in) :: string(Nint,2) - character*(512) :: output(2) + character*(2048) :: output(2) call bitstring_to_str( output(1), string(1,1), Nint ) call bitstring_to_str( output(2), string(1,2), Nint ) @@ -151,3 +151,34 @@ subroutine print_det(string,Nint) print *, trim(output(2)) end + +subroutine debug_spindet(string,Nint) + use bitmasks + implicit none + BEGIN_DOC + ! Subroutine to print the content of a determinant in '+-' notation and + ! hexadecimal representation. + END_DOC + integer, intent(in) :: Nint + integer(bit_kind), intent(in) :: string(Nint,2) + character*(2048) :: output(1) + call bitstring_to_hexa( output(1), string(1,1), Nint ) + print *, trim(output(1)) + call print_spindet(string,Nint) + +end + +subroutine print_spindet(string,Nint) + use bitmasks + implicit none + BEGIN_DOC + ! Subroutine to print the content of a determinant using the '+-' notation + END_DOC + integer, intent(in) :: Nint + integer(bit_kind), intent(in) :: string(Nint,2) + character*(2048) :: output(1) + + call bitstring_to_str( output(1), string(1,1), Nint ) + print *, trim(output(1)) + +end diff --git a/src/CAS_SD/NEEDED_CHILDREN_MODULES b/src/CAS_SD/NEEDED_CHILDREN_MODULES new file mode 100644 index 00000000..f7264a0f --- /dev/null +++ b/src/CAS_SD/NEEDED_CHILDREN_MODULES @@ -0,0 +1 @@ +Perturbation Selectors_full Generators_CAS diff --git a/src/CAS_SD/NEEDED_MODULES b/src/CAS_SD/NEEDED_MODULES deleted file mode 100644 index f20d16a0..00000000 --- a/src/CAS_SD/NEEDED_MODULES +++ /dev/null @@ -1,2 +0,0 @@ -AOs Bielec_integrals Bitmask Determinants Electrons Ezfio_files Generators_CAS Hartree_Fock MOGuess MonoInts MOs Nuclei Output Perturbation Properties Selectors_full Utils - diff --git a/src/CAS_SD/README.rst b/src/CAS_SD/README.rst index 0b3293d5..2e56e56e 100644 --- a/src/CAS_SD/README.rst +++ b/src/CAS_SD/README.rst @@ -24,21 +24,7 @@ Needed Modules .. Do not edit this section. It was auto-generated from the .. NEEDED_MODULES file. -* `AOs `_ -* `Bielec_integrals `_ -* `Bitmask `_ -* `Determinants `_ -* `Electrons `_ -* `Ezfio_files `_ -* `Generators_CAS `_ -* `Hartree_Fock `_ -* `MOGuess `_ -* `MonoInts `_ -* `MOs `_ -* `Nuclei `_ -* `Output `_ * `Perturbation `_ -* `Properties `_ * `Selectors_full `_ -* `Utils `_ +* `Generators_CAS `_ diff --git a/src/CAS_SD/cas_sd.irp.f b/src/CAS_SD/cas_sd.irp.f index 144eec88..e28334b2 100644 --- a/src/CAS_SD/cas_sd.irp.f +++ b/src/CAS_SD/cas_sd.irp.f @@ -1,6 +1,7 @@ program full_ci implicit none integer :: i,k + integer :: N_det_old double precision, allocatable :: pt2(:), norm_pert(:), H_pert_diag(:) @@ -9,6 +10,7 @@ program full_ci allocate (pt2(N_st), norm_pert(N_st),H_pert_diag(N_st)) character*(64) :: perturbation + N_det_old = 0 pt2 = 1.d0 diag_algorithm = "Lapack" if (N_det > n_det_max_cas_sd) then @@ -29,6 +31,7 @@ program full_ci endif do while (N_det < n_det_max_cas_sd.and.maxval(abs(pt2(1:N_st))) > pt2_max) + N_det_old = N_det call H_apply_CAS_SD(pt2, norm_pert, H_pert_diag, N_st) PROVIDE psi_coef @@ -53,10 +56,11 @@ program full_ci if (abort_all) then exit endif + if (N_det == N_det_old) then + exit + endif enddo - ! Check that it is a CAS-SD - logical :: in_cas integer :: exc_max, degree_min exc_max = 0 print *, 'CAS determinants : ', N_det_generators @@ -69,18 +73,4 @@ program full_ci print *, '' enddo print *, 'Max excitation degree in the CAS :', exc_max - do i=1,N_det - in_cas = .False. - degree_min = 1000 - do k=1,N_det_generators - call get_excitation_degree(psi_det_generators(1,1,k),psi_det(1,1,i),degree,N_int) - degree_min = min(degree_min,degree) - enddo - if (degree_min > 2) then - print *, 'Error : This is not a CAS-SD : ' - print *, 'Excited determinant:', degree_min - call debug_det(psi_det(1,1,k),N_int) - stop - endif - enddo end diff --git a/src/CAS_SD/cas_sd_selected.irp.f b/src/CAS_SD/cas_sd_selected.irp.f index 86cac969..c3abadf4 100644 --- a/src/CAS_SD/cas_sd_selected.irp.f +++ b/src/CAS_SD/cas_sd_selected.irp.f @@ -50,14 +50,30 @@ program full_ci print *, 'E = ', CI_energy print *, 'E+PT2 = ', CI_energy+pt2 print *, '-----' - call ezfio_set_full_ci_energy(CI_energy) + call ezfio_set_cas_sd_energy(CI_energy(1)) if (abort_all) then exit endif enddo + call diagonalize_CI + + if(do_pt2_end)then + print*,'Last iteration only to compute the PT2' + threshold_selectors = 1.d0 + threshold_generators = 0.999d0 + call H_apply_CAS_SD_PT2(pt2, norm_pert, H_pert_diag, N_st) + + print *, 'Final step' + print *, 'N_det = ', N_det + print *, 'N_states = ', N_states + print *, 'PT2 = ', pt2 + print *, 'E = ', CI_energy + print *, 'E+PT2 = ', CI_energy+pt2 + print *, '-----' + call ezfio_set_cas_sd_energy_pt2(CI_energy(1)+pt2(1)) + endif + - ! Check that it is a CAS-SD - logical :: in_cas integer :: exc_max, degree_min exc_max = 0 print *, 'CAS determinants : ', N_det_cas @@ -70,18 +86,4 @@ program full_ci print *, '' enddo print *, 'Max excitation degree in the CAS :', exc_max - do i=1,N_det - in_cas = .False. - degree_min = 1000 - do k=1,N_det_cas - call get_excitation_degree(psi_cas(1,1,k),psi_det(1,1,i),degree,N_int) - degree_min = min(degree_min,degree) - enddo - if (degree_min > 2) then - print *, 'Error : This is not a CAS-SD : ' - print *, 'Excited determinant:', degree_min - call debug_det(psi_det(1,1,k),N_int) - stop - endif - enddo end diff --git a/src/CID/NEEDED_CHILDREN_MODULES b/src/CID/NEEDED_CHILDREN_MODULES new file mode 100644 index 00000000..afc8cfd4 --- /dev/null +++ b/src/CID/NEEDED_CHILDREN_MODULES @@ -0,0 +1 @@ +Selectors_full SingleRefMethod diff --git a/src/CID/NEEDED_MODULES b/src/CID/NEEDED_MODULES deleted file mode 100644 index f7a1831f..00000000 --- a/src/CID/NEEDED_MODULES +++ /dev/null @@ -1,3 +0,0 @@ -AOs Bielec_integrals Bitmask Determinants Electrons Ezfio_files Hartree_Fock MOGuess MonoInts MOs Nuclei Output Selectors_full SingleRefMethod Utils - - diff --git a/src/CID/README.rst b/src/CID/README.rst index 47cbc40b..5d2fa851 100644 --- a/src/CID/README.rst +++ b/src/CID/README.rst @@ -15,21 +15,8 @@ Needed Modules .. Do not edit this section. It was auto-generated from the .. NEEDED_MODULES file. -* `AOs `_ -* `Bielec_integrals `_ -* `Bitmask `_ -* `Determinants `_ -* `Electrons `_ -* `Ezfio_files `_ -* `Hartree_Fock `_ -* `MOGuess `_ -* `MonoInts `_ -* `MOs `_ -* `Nuclei `_ -* `Output `_ * `Selectors_full `_ * `SingleRefMethod `_ -* `Utils `_ Documentation ============= diff --git a/src/CID_SC2_selected/NEEDED_CHILDREN_MODULES b/src/CID_SC2_selected/NEEDED_CHILDREN_MODULES new file mode 100644 index 00000000..7be053d7 --- /dev/null +++ b/src/CID_SC2_selected/NEEDED_CHILDREN_MODULES @@ -0,0 +1 @@ +CID_selected diff --git a/src/CID_SC2_selected/NEEDED_MODULES b/src/CID_SC2_selected/NEEDED_MODULES deleted file mode 100644 index 67f77e87..00000000 --- a/src/CID_SC2_selected/NEEDED_MODULES +++ /dev/null @@ -1,2 +0,0 @@ -AOs Bielec_integrals Bitmask CISD CISD_selected Determinants Electrons Ezfio_files Hartree_Fock MOGuess MonoInts MOs Nuclei Output Perturbation Properties Selectors_full SingleRefMethod Utils - diff --git a/src/CID_SC2_selected/README.rst b/src/CID_SC2_selected/README.rst index 37680ebb..ec9e7a3f 100644 --- a/src/CID_SC2_selected/README.rst +++ b/src/CID_SC2_selected/README.rst @@ -19,23 +19,5 @@ Needed Modules .. Do not edit this section. It was auto-generated from the .. NEEDED_MODULES file. -* `AOs `_ -* `Bielec_integrals `_ -* `Bitmask `_ -* `CISD `_ -* `CISD_selected `_ -* `Determinants `_ -* `Electrons `_ -* `Ezfio_files `_ -* `Hartree_Fock `_ -* `MOGuess `_ -* `MonoInts `_ -* `MOs `_ -* `Nuclei `_ -* `Output `_ -* `Perturbation `_ -* `Properties `_ -* `Selectors_full `_ -* `SingleRefMethod `_ -* `Utils `_ +* `CID_selected `_ diff --git a/src/CID_selected/NEEDED_CHILDREN_MODULES b/src/CID_selected/NEEDED_CHILDREN_MODULES new file mode 100644 index 00000000..1e0c52c2 --- /dev/null +++ b/src/CID_selected/NEEDED_CHILDREN_MODULES @@ -0,0 +1 @@ +Perturbation CID diff --git a/src/CID_selected/NEEDED_MODULES b/src/CID_selected/NEEDED_MODULES deleted file mode 100644 index ca89c5f3..00000000 --- a/src/CID_selected/NEEDED_MODULES +++ /dev/null @@ -1,2 +0,0 @@ -AOs Bielec_integrals Bitmask CISD Determinants Electrons Ezfio_files Hartree_Fock MOGuess MonoInts MOs Nuclei Output Perturbation Properties Selectors_full SingleRefMethod Utils - diff --git a/src/CID_selected/README.rst b/src/CID_selected/README.rst index d8f054ac..50cc701f 100644 --- a/src/CID_selected/README.rst +++ b/src/CID_selected/README.rst @@ -22,22 +22,6 @@ Needed Modules .. Do not edit this section. It was auto-generated from the .. NEEDED_MODULES file. -* `AOs `_ -* `Bielec_integrals `_ -* `Bitmask `_ -* `CISD `_ -* `Determinants `_ -* `Electrons `_ -* `Ezfio_files `_ -* `Hartree_Fock `_ -* `MOGuess `_ -* `MonoInts `_ -* `MOs `_ -* `Nuclei `_ -* `Output `_ * `Perturbation `_ -* `Properties `_ -* `Selectors_full `_ -* `SingleRefMethod `_ -* `Utils `_ +* `CID `_ diff --git a/src/CIS/NEEDED_CHILDREN_MODULES b/src/CIS/NEEDED_CHILDREN_MODULES new file mode 100644 index 00000000..afc8cfd4 --- /dev/null +++ b/src/CIS/NEEDED_CHILDREN_MODULES @@ -0,0 +1 @@ +Selectors_full SingleRefMethod diff --git a/src/CIS/NEEDED_MODULES b/src/CIS/NEEDED_MODULES deleted file mode 100644 index 5cdee2e5..00000000 --- a/src/CIS/NEEDED_MODULES +++ /dev/null @@ -1,2 +0,0 @@ -AOs Bielec_integrals Bitmask Determinants Electrons Ezfio_files Hartree_Fock MOGuess MonoInts MOs Nuclei Output Selectors_full SingleRefMethod Utils - diff --git a/src/CIS/README.rst b/src/CIS/README.rst index 59558a31..e3b2478a 100644 --- a/src/CIS/README.rst +++ b/src/CIS/README.rst @@ -31,19 +31,6 @@ Needed Modules .. Do not edit this section. It was auto-generated from the .. NEEDED_MODULES file. -* `AOs `_ -* `Bielec_integrals `_ -* `Bitmask `_ -* `Determinants `_ -* `Electrons `_ -* `Ezfio_files `_ -* `Hartree_Fock `_ -* `MOGuess `_ -* `MonoInts `_ -* `MOs `_ -* `Nuclei `_ -* `Output `_ * `Selectors_full `_ * `SingleRefMethod `_ -* `Utils `_ diff --git a/src/CISD/NEEDED_CHILDREN_MODULES b/src/CISD/NEEDED_CHILDREN_MODULES new file mode 100644 index 00000000..afc8cfd4 --- /dev/null +++ b/src/CISD/NEEDED_CHILDREN_MODULES @@ -0,0 +1 @@ +Selectors_full SingleRefMethod diff --git a/src/CISD/NEEDED_MODULES b/src/CISD/NEEDED_MODULES deleted file mode 100644 index 5cdee2e5..00000000 --- a/src/CISD/NEEDED_MODULES +++ /dev/null @@ -1,2 +0,0 @@ -AOs Bielec_integrals Bitmask Determinants Electrons Ezfio_files Hartree_Fock MOGuess MonoInts MOs Nuclei Output Selectors_full SingleRefMethod Utils - diff --git a/src/CISD/README.rst b/src/CISD/README.rst index bcf7aee2..68ab4cfb 100644 --- a/src/CISD/README.rst +++ b/src/CISD/README.rst @@ -15,21 +15,8 @@ Needed Modules .. Do not edit this section. It was auto-generated from the .. NEEDED_MODULES file. -* `AOs `_ -* `Bielec_integrals `_ -* `Bitmask `_ -* `Determinants `_ -* `Electrons `_ -* `Ezfio_files `_ -* `Hartree_Fock `_ -* `MOGuess `_ -* `MonoInts `_ -* `MOs `_ -* `Nuclei `_ -* `Output `_ * `Selectors_full `_ * `SingleRefMethod `_ -* `Utils `_ Documentation ============= diff --git a/src/CISD_SC2_selected/NEEDED_CHILDREN_MODULES b/src/CISD_SC2_selected/NEEDED_CHILDREN_MODULES new file mode 100644 index 00000000..fa61747b --- /dev/null +++ b/src/CISD_SC2_selected/NEEDED_CHILDREN_MODULES @@ -0,0 +1 @@ +CISD_selected diff --git a/src/CISD_SC2_selected/NEEDED_MODULES b/src/CISD_SC2_selected/NEEDED_MODULES deleted file mode 100644 index 67f77e87..00000000 --- a/src/CISD_SC2_selected/NEEDED_MODULES +++ /dev/null @@ -1,2 +0,0 @@ -AOs Bielec_integrals Bitmask CISD CISD_selected Determinants Electrons Ezfio_files Hartree_Fock MOGuess MonoInts MOs Nuclei Output Perturbation Properties Selectors_full SingleRefMethod Utils - diff --git a/src/CISD_SC2_selected/README.rst b/src/CISD_SC2_selected/README.rst index 915c85f1..b4f4fac1 100644 --- a/src/CISD_SC2_selected/README.rst +++ b/src/CISD_SC2_selected/README.rst @@ -19,23 +19,5 @@ Needed Modules .. Do not edit this section. It was auto-generated from the .. NEEDED_MODULES file. -* `AOs `_ -* `Bielec_integrals `_ -* `Bitmask `_ -* `CISD `_ * `CISD_selected `_ -* `Determinants `_ -* `Electrons `_ -* `Ezfio_files `_ -* `Hartree_Fock `_ -* `MOGuess `_ -* `MonoInts `_ -* `MOs `_ -* `Nuclei `_ -* `Output `_ -* `Perturbation `_ -* `Properties `_ -* `Selectors_full `_ -* `SingleRefMethod `_ -* `Utils `_ diff --git a/src/CISD_selected/NEEDED_CHILDREN_MODULES b/src/CISD_selected/NEEDED_CHILDREN_MODULES new file mode 100644 index 00000000..2b104007 --- /dev/null +++ b/src/CISD_selected/NEEDED_CHILDREN_MODULES @@ -0,0 +1 @@ +Perturbation CISD diff --git a/src/CISD_selected/NEEDED_MODULES b/src/CISD_selected/NEEDED_MODULES deleted file mode 100644 index ca89c5f3..00000000 --- a/src/CISD_selected/NEEDED_MODULES +++ /dev/null @@ -1,2 +0,0 @@ -AOs Bielec_integrals Bitmask CISD Determinants Electrons Ezfio_files Hartree_Fock MOGuess MonoInts MOs Nuclei Output Perturbation Properties Selectors_full SingleRefMethod Utils - diff --git a/src/CISD_selected/README.rst b/src/CISD_selected/README.rst index e2b6989e..a72c5a21 100644 --- a/src/CISD_selected/README.rst +++ b/src/CISD_selected/README.rst @@ -28,22 +28,6 @@ Needed Modules .. Do not edit this section. It was auto-generated from the .. NEEDED_MODULES file. -* `AOs `_ -* `Bielec_integrals `_ -* `Bitmask `_ -* `CISD `_ -* `Determinants `_ -* `Electrons `_ -* `Ezfio_files `_ -* `Hartree_Fock `_ -* `MOGuess `_ -* `MonoInts `_ -* `MOs `_ -* `Nuclei `_ -* `Output `_ * `Perturbation `_ -* `Properties `_ -* `Selectors_full `_ -* `SingleRefMethod `_ -* `Utils `_ +* `CISD `_ diff --git a/src/DDCI_selected/NEEDED_CHILDREN_MODULES b/src/DDCI_selected/NEEDED_CHILDREN_MODULES new file mode 100644 index 00000000..f7264a0f --- /dev/null +++ b/src/DDCI_selected/NEEDED_CHILDREN_MODULES @@ -0,0 +1 @@ +Perturbation Selectors_full Generators_CAS diff --git a/src/DDCI_selected/NEEDED_MODULES b/src/DDCI_selected/NEEDED_MODULES deleted file mode 100644 index f20d16a0..00000000 --- a/src/DDCI_selected/NEEDED_MODULES +++ /dev/null @@ -1,2 +0,0 @@ -AOs Bielec_integrals Bitmask Determinants Electrons Ezfio_files Generators_CAS Hartree_Fock MOGuess MonoInts MOs Nuclei Output Perturbation Properties Selectors_full Utils - diff --git a/src/DDCI_selected/README.rst b/src/DDCI_selected/README.rst index 2b5823c7..9cfdbefa 100644 --- a/src/DDCI_selected/README.rst +++ b/src/DDCI_selected/README.rst @@ -19,21 +19,7 @@ Needed Modules .. Do not edit this section. It was auto-generated from the .. NEEDED_MODULES file. -* `AOs `_ -* `Bielec_integrals `_ -* `Bitmask `_ -* `Determinants `_ -* `Electrons `_ -* `Ezfio_files `_ -* `Generators_CAS `_ -* `Hartree_Fock `_ -* `MOGuess `_ -* `MonoInts `_ -* `MOs `_ -* `Nuclei `_ -* `Output `_ * `Perturbation `_ -* `Properties `_ * `Selectors_full `_ -* `Utils `_ +* `Generators_CAS `_ diff --git a/src/Determinants/EZFIO.cfg b/src/Determinants/EZFIO.cfg index 5f63404b..eab4ea0e 100644 --- a/src/Determinants/EZFIO.cfg +++ b/src/Determinants/EZFIO.cfg @@ -100,4 +100,4 @@ size: (determinants_det_num) [expected_s2] interface: OCaml doc: expcted_s2 -type: double precision \ No newline at end of file +type: double precision diff --git a/src/Determinants/H_apply.irp.f b/src/Determinants/H_apply.irp.f index 801d00a5..6e2b3a5a 100644 --- a/src/Determinants/H_apply.irp.f +++ b/src/Determinants/H_apply.irp.f @@ -53,13 +53,17 @@ subroutine resize_H_apply_buffer(new_size,iproc) double precision, pointer :: buffer_e2(:,:) integer :: i,j,k integer :: Ndet + + BEGIN_DOC +! Resizes the H_apply buffer of proc iproc. The buffer lock should +! be set before calling this function. + END_DOC PROVIDE H_apply_buffer_allocated ASSERT (new_size > 0) ASSERT (iproc >= 0) ASSERT (iproc < nproc) - call omp_set_lock(H_apply_buffer_lock(1,iproc)) allocate ( buffer_det(N_int,2,new_size), & buffer_coef(new_size,N_states), & buffer_e2(new_size,N_states) ) @@ -93,7 +97,6 @@ subroutine resize_H_apply_buffer(new_size,iproc) H_apply_buffer(iproc)%sze = new_size H_apply_buffer(iproc)%N_det = min(new_size,H_apply_buffer(iproc)%N_det) - call omp_unset_lock(H_apply_buffer_lock(1,iproc)) end @@ -101,8 +104,7 @@ subroutine copy_H_apply_buffer_to_wf use omp_lib implicit none BEGIN_DOC -! Copies the H_apply buffer to psi_coef. You need to touch psi_det, psi_coef and N_det -! after calling this function. +! Copies the H_apply buffer to psi_coef. ! After calling this subroutine, N_det, psi_det and psi_coef need to be touched END_DOC integer(bit_kind), allocatable :: buffer_det(:,:,:) @@ -181,8 +183,77 @@ subroutine copy_H_apply_buffer_to_wf call normalize(psi_coef,N_det) SOFT_TOUCH N_det psi_det psi_coef + logical :: found_duplicates + call remove_duplicates_in_psi_det(found_duplicates) end +subroutine remove_duplicates_in_psi_det(found_duplicates) + implicit none + logical, intent(out) :: found_duplicates + BEGIN_DOC +! Removes duplicate determinants in the wave function. + END_DOC + integer :: i,j,k + integer(bit_kind), allocatable :: bit_tmp(:) + logical,allocatable :: duplicate(:) + + allocate (duplicate(N_det), bit_tmp(N_det)) + + do i=1,N_det + integer, external :: det_search_key + !$DIR FORCEINLINE + bit_tmp(i) = det_search_key(psi_det_sorted_bit(1,1,i),N_int) + duplicate(i) = .False. + enddo + + do i=1,N_det-1 + if (duplicate(i)) then + cycle + endif + j = i+1 + do while (bit_tmp(j)==bit_tmp(i)) + if (duplicate(j)) then + j += 1 + cycle + endif + duplicate(j) = .True. + do k=1,N_int + if ( (psi_det_sorted_bit(k,1,i) /= psi_det_sorted_bit(k,1,j) ) & + .or. (psi_det_sorted_bit(k,2,i) /= psi_det_sorted_bit(k,2,j) ) ) then + duplicate(j) = .False. + exit + endif + enddo + j += 1 + if (j > N_det) then + exit + endif + enddo + enddo + + found_duplicates = .False. + do i=1,N_det + if (duplicate(i)) then + found_duplicates = .True. + exit + endif + enddo + + if (found_duplicates) then + call write_bool(output_determinants,found_duplicates,'Found duplicate determinants') + k=0 + do i=1,N_det + if (.not.duplicate(i)) then + k += 1 + psi_det(:,:,k) = psi_det_sorted_bit (:,:,i) + psi_coef(k,:) = psi_coef_sorted_bit(i,:) + endif + enddo + N_det = k + TOUCH N_det psi_det psi_coef + endif + deallocate (duplicate,bit_tmp) +end subroutine fill_H_apply_buffer_no_selection(n_selected,det_buffer,Nint,iproc) use bitmasks @@ -196,11 +267,11 @@ subroutine fill_H_apply_buffer_no_selection(n_selected,det_buffer,Nint,iproc) integer :: i,j,k integer :: new_size PROVIDE H_apply_buffer_allocated + call omp_set_lock(H_apply_buffer_lock(1,iproc)) new_size = H_apply_buffer(iproc)%N_det + n_selected if (new_size > H_apply_buffer(iproc)%sze) then call resize_h_apply_buffer(max(2*H_apply_buffer(iproc)%sze,new_size),iproc) endif - call omp_set_lock(H_apply_buffer_lock(1,iproc)) do i=1,H_apply_buffer(iproc)%N_det ASSERT (sum(popcnt(H_apply_buffer(iproc)%det(:,1,i)) )== elec_alpha_num) ASSERT (sum(popcnt(H_apply_buffer(iproc)%det(:,2,i))) == elec_beta_num) @@ -215,7 +286,7 @@ subroutine fill_H_apply_buffer_no_selection(n_selected,det_buffer,Nint,iproc) enddo do j=1,N_states do i=1,N_selected - H_apply_buffer(iproc)%coef(i,j) = 0.d0 + H_apply_buffer(iproc)%coef(i+H_apply_buffer(iproc)%N_det,j) = 0.d0 enddo enddo H_apply_buffer(iproc)%N_det = new_size diff --git a/src/Determinants/NEEDED_CHILDREN_MODULES b/src/Determinants/NEEDED_CHILDREN_MODULES new file mode 100644 index 00000000..afc397de --- /dev/null +++ b/src/Determinants/NEEDED_CHILDREN_MODULES @@ -0,0 +1 @@ +Bielec_integrals diff --git a/src/Determinants/NEEDED_MODULES b/src/Determinants/NEEDED_MODULES deleted file mode 100644 index 824c75ed..00000000 --- a/src/Determinants/NEEDED_MODULES +++ /dev/null @@ -1 +0,0 @@ -AOs Bielec_integrals Bitmask Electrons Ezfio_files MonoInts MOs Nuclei Output Utils diff --git a/src/Determinants/README.rst b/src/Determinants/README.rst index 445c8b5e..e9307357 100644 --- a/src/Determinants/README.rst +++ b/src/Determinants/README.rst @@ -32,16 +32,7 @@ Needed Modules .. Do not edit this section. It was auto-generated from the .. NEEDED_MODULES file. -* `AOs `_ * `Bielec_integrals `_ -* `Bitmask `_ -* `Electrons `_ -* `Ezfio_files `_ -* `MonoInts `_ -* `MOs `_ -* `Nuclei `_ -* `Output `_ -* `Utils `_ Documentation ============= @@ -49,12 +40,11 @@ Documentation .. Do not edit this section. It was auto-generated from the .. NEEDED_MODULES file. -`copy_h_apply_buffer_to_wf `_ - Copies the H_apply buffer to psi_coef. You need to touch psi_det, psi_coef and N_det - after calling this function. +`copy_h_apply_buffer_to_wf `_ + Copies the H_apply buffer to psi_coef. After calling this subroutine, N_det, psi_det and psi_coef need to be touched -`fill_h_apply_buffer_no_selection `_ +`fill_h_apply_buffer_no_selection `_ Fill the H_apply buffer with determiants for CISD `h_apply_buffer_allocated `_ @@ -65,8 +55,12 @@ Documentation Buffer of determinants/coefficients/perturbative energy for H_apply. Uninitialized. Filled by H_apply subroutines. +`remove_duplicates_in_psi_det `_ + Removes duplicate determinants in the wave function. + `resize_h_apply_buffer `_ - Undocumented + Resizes the H_apply buffer of proc iproc. The buffer lock should + be set before calling this function. `cisd_sc2 `_ CISD+SC2 method :: take off all the disconnected terms of a CISD (selected or not) @@ -193,10 +187,10 @@ Documentation `det_svd `_ Computes the SVD of the Alpha x Beta determinant coefficient matrix -`filter_3_highest_electrons `_ +`filter_3_highest_electrons `_ Returns a determinant with only the 3 highest electrons -`int_of_3_highest_electrons `_ +`int_of_3_highest_electrons `_ Returns an integer*8 as : .br |_<--- 21 bits ---><--- 21 bits ---><--- 21 bits --->| @@ -213,26 +207,26 @@ Documentation `n_det `_ Number of determinants in the wave function -`psi_average_norm_contrib `_ +`psi_average_norm_contrib `_ Contribution of determinants to the state-averaged density -`psi_average_norm_contrib_sorted `_ +`psi_average_norm_contrib_sorted `_ Wave function sorted by determinants contribution to the norm (state-averaged) -`psi_coef `_ +`psi_coef `_ The wave function coefficients. Initialized with Hartree-Fock if the EZFIO file is empty -`psi_coef_sorted `_ +`psi_coef_sorted `_ Wave function sorted by determinants contribution to the norm (state-averaged) -`psi_coef_sorted_ab `_ +`psi_coef_sorted_ab `_ Determinants on which we apply . They are sorted by the 3 highest electrons in the alpha part, then by the 3 highest electrons in the beta part to accelerate the research of connected determinants. -`psi_coef_sorted_bit `_ +`psi_coef_sorted_bit `_ Determinants on which we apply for perturbation. They are sorted by determinants interpreted as integers. Useful to accelerate the search of a random determinant in the wave @@ -245,46 +239,46 @@ Documentation `psi_det_size `_ Size of the psi_det/psi_coef arrays -`psi_det_sorted `_ +`psi_det_sorted `_ Wave function sorted by determinants contribution to the norm (state-averaged) -`psi_det_sorted_ab `_ +`psi_det_sorted_ab `_ Determinants on which we apply . They are sorted by the 3 highest electrons in the alpha part, then by the 3 highest electrons in the beta part to accelerate the research of connected determinants. -`psi_det_sorted_bit `_ +`psi_det_sorted_bit `_ Determinants on which we apply for perturbation. They are sorted by determinants interpreted as integers. Useful to accelerate the search of a random determinant in the wave function. -`psi_det_sorted_next_ab `_ +`psi_det_sorted_next_ab `_ Determinants on which we apply . They are sorted by the 3 highest electrons in the alpha part, then by the 3 highest electrons in the beta part to accelerate the research of connected determinants. -`read_dets `_ +`read_dets `_ Reads the determinants from the EZFIO file -`save_wavefunction `_ +`save_wavefunction `_ Save the wave function into the EZFIO file -`save_wavefunction_general `_ +`save_wavefunction_general `_ Save the wave function into the EZFIO file -`save_wavefunction_unsorted `_ +`save_wavefunction_unsorted `_ Save the wave function into the EZFIO file -`sort_dets_by_3_highest_electrons `_ +`sort_dets_by_3_highest_electrons `_ Determinants on which we apply . They are sorted by the 3 highest electrons in the alpha part, then by the 3 highest electrons in the beta part to accelerate the research of connected determinants. -`sort_dets_by_det_search_key `_ +`sort_dets_by_det_search_key `_ Determinants are sorted are sorted according to their det_search_key. Useful to accelerate the search of a random determinant in the wave function. @@ -322,7 +316,7 @@ Documentation `diag_algorithm `_ Diagonalization algorithm (Davidson or Lapack) -`diagonalize_ci `_ +`diagonalize_ci `_ Replace the coefficients of the CI states by the coefficients of the eigenstates of the CI matrix @@ -335,7 +329,7 @@ Documentation `ci_sc2_energy `_ N_states_diag lowest eigenvalues of the CI matrix -`diagonalize_ci_sc2 `_ +`diagonalize_ci_sc2 `_ Replace the coefficients of the CI states_diag by the coefficients of the eigenstates of the CI matrix @@ -351,7 +345,7 @@ Documentation `ci_electronic_energy_mono `_ Eigenvectors/values of the CI matrix -`diagonalize_ci_mono `_ +`diagonalize_ci_mono `_ Replace the coefficients of the CI states by the coefficients of the eigenstates of the CI matrix @@ -538,7 +532,7 @@ Documentation `save_dets_qmcchem `_ Undocumented -`save_for_qmc `_ +`save_for_qmc `_ Undocumented `save_natorb `_ @@ -629,61 +623,49 @@ Documentation `n_con_int `_ Number of integers to represent the connections between determinants -`create_wf_of_psi_svd_matrix `_ +`create_wf_of_psi_svd_matrix `_ Matrix of wf coefficients. Outer product of alpha and beta determinants -`generate_all_alpha_beta_det_products `_ +`generate_all_alpha_beta_det_products `_ Create a wave function from all possible alpha x beta determinants -`get_index_in_psi_det_alpha_unique `_ +`get_index_in_psi_det_alpha_unique `_ Returns the index of the determinant in the ``psi_det_alpha_unique`` array -`get_index_in_psi_det_beta_unique `_ +`get_index_in_psi_det_beta_unique `_ Returns the index of the determinant in the ``psi_det_beta_unique`` array -`n_det_alpha_unique `_ - Unique alpha determinants - -`n_det_beta_unique `_ - Unique beta determinants - `psi_det_alpha `_ List of alpha determinants of psi_det -`psi_det_alpha_unique `_ - Unique alpha determinants - `psi_det_beta `_ List of beta determinants of psi_det -`psi_det_beta_unique `_ - Unique beta determinants - -`psi_svd_alpha `_ +`psi_svd_alpha `_ SVD wave function -`psi_svd_beta `_ +`psi_svd_beta `_ SVD wave function -`psi_svd_coefs `_ +`psi_svd_coefs `_ SVD wave function -`psi_svd_matrix `_ +`psi_svd_matrix `_ Matrix of wf coefficients. Outer product of alpha and beta determinants -`psi_svd_matrix_columns `_ +`psi_svd_matrix_columns `_ Matrix of wf coefficients. Outer product of alpha and beta determinants -`psi_svd_matrix_rows `_ +`psi_svd_matrix_rows `_ Matrix of wf coefficients. Outer product of alpha and beta determinants -`psi_svd_matrix_values `_ +`psi_svd_matrix_values `_ Matrix of wf coefficients. Outer product of alpha and beta determinants `spin_det_search_key `_ Return an integer*8 corresponding to a determinant index for searching -`write_spindeterminants `_ +`write_spindeterminants `_ Undocumented `cisd `_ diff --git a/src/Determinants/determinants.irp.f b/src/Determinants/determinants.irp.f index a70d0fe8..8cc545f5 100644 --- a/src/Determinants/determinants.irp.f +++ b/src/Determinants/determinants.irp.f @@ -147,9 +147,7 @@ END_PROVIDER !$DIR FORCEINLINE bit_tmp(i) = occ_pattern_search_key(psi_occ_pattern(1,1,i),N_int) enddo - print*,'passed 1' call i8sort(bit_tmp,iorder,N_det) - print*,'passed 2' !DIR$ IVDEP do i=1,N_det do k=1,N_int @@ -189,7 +187,6 @@ END_PROVIDER endif enddo enddo - print*,'passed 3' N_occ_pattern=0 do i=1,N_det diff --git a/src/Determinants/diagonalize_CI.irp.f b/src/Determinants/diagonalize_CI.irp.f index 0e697ab3..7c017956 100644 --- a/src/Determinants/diagonalize_CI.irp.f +++ b/src/Determinants/diagonalize_CI.irp.f @@ -66,28 +66,32 @@ END_PROVIDER enddo integer :: i_state double precision :: s2 - i_state = 0 - do j=1,N_det - call get_s2_u0(psi_det,eigenvectors(1,j),N_det,N_det,s2) - if(dabs(s2-expected_s2).le.0.3d0)then - i_state += 1 - do i=1,N_det - CI_eigenvectors(i,i_state) = eigenvectors(i,j) - enddo - CI_electronic_energy(i_state) = eigenvalues(j) - CI_eigenvectors_s2(i_state) = s2 - endif - if (i_state.ge.N_states_diag) then - exit - endif - enddo -! if(i_state < min(N_states_diag,N_det))then -! print *, 'pb with the number of states' -! print *, 'i_state = ',i_state -! print *, 'N_states_diag ',N_states_diag -! print *,'stopping ...' -! stop -! endif + if (s2_eig) then + i_state = 0 + do j=1,N_det + call get_s2_u0(psi_det,eigenvectors(1,j),N_det,N_det,s2) + if(dabs(s2-expected_s2).le.0.3d0)then + i_state += 1 + do i=1,N_det + CI_eigenvectors(i,i_state) = eigenvectors(i,j) + enddo + CI_electronic_energy(i_state) = eigenvalues(j) + CI_eigenvectors_s2(i_state) = s2 + endif + if (i_state.ge.N_states_diag) then + exit + endif + enddo + else + do j=1,N_states_diag + call get_s2_u0(psi_det,eigenvectors(1,j),N_det,N_det,s2) + do i=1,N_det + CI_eigenvectors(i,j) = eigenvectors(i,j) + enddo + CI_electronic_energy(j) = eigenvalues(j) + CI_eigenvectors_s2(j) = s2 + enddo + endif deallocate(eigenvectors,eigenvalues) endif diff --git a/src/Determinants/diagonalize_CI_SC2.irp.f b/src/Determinants/diagonalize_CI_SC2.irp.f index 3b0d7904..97161ad3 100644 --- a/src/Determinants/diagonalize_CI_SC2.irp.f +++ b/src/Determinants/diagonalize_CI_SC2.irp.f @@ -35,8 +35,7 @@ END_PROVIDER do i=1,N_det CI_SC2_eigenvectors(i,j) = psi_coef(i,j) enddo -! TODO : check comment -! CI_SC2_electronic_energy(j) = CI_electronic_energy(j) + CI_SC2_electronic_energy(j) = CI_electronic_energy(j) enddo call CISD_SC2(psi_det,CI_SC2_eigenvectors,CI_SC2_electronic_energy, & diff --git a/src/Determinants/diagonalize_CI_mono.irp.f b/src/Determinants/diagonalize_CI_mono.irp.f index 1c9a4de3..3f9b94ec 100644 --- a/src/Determinants/diagonalize_CI_mono.irp.f +++ b/src/Determinants/diagonalize_CI_mono.irp.f @@ -32,25 +32,39 @@ integer :: i_state double precision :: s2 i_state = 0 - do j=1,N_det - call get_s2_u0(psi_det,eigenvectors(1,j),N_det,N_det,s2) - if(dabs(s2-expected_s2).le.0.3d0)then - print*,'j = ',j - print*,'e = ',eigenvalues(j) - print*,'c = ',dabs(eigenvectors(1,j)) - if(dabs(eigenvectors(1,j)).gt.0.9d0)then - i_state += 1 - do i=1,N_det - CI_eigenvectors_mono(i,i_state) = eigenvectors(i,j) - enddo - CI_electronic_energy_mono(i_state) = eigenvalues(j) - CI_eigenvectors_s2_mono(i_state) = s2 - endif - endif - if (i_state.ge.N_states_diag) then - exit - endif - enddo + if (s2_eig) then + do j=1,N_det + call get_s2_u0(psi_det,eigenvectors(1,j),N_det,N_det,s2) + if(dabs(s2-expected_s2).le.0.3d0)then + print*,'j = ',j + print*,'e = ',eigenvalues(j) + print*,'c = ',dabs(eigenvectors(1,j)) + if(dabs(eigenvectors(1,j)).gt.0.9d0)then + i_state += 1 + do i=1,N_det + CI_eigenvectors_mono(i,i_state) = eigenvectors(i,j) + enddo + CI_electronic_energy_mono(i_state) = eigenvalues(j) + CI_eigenvectors_s2_mono(i_state) = s2 + endif + endif + if (i_state.ge.N_states_diag) then + exit + endif + enddo + else + do j=1,N_states_diag + call get_s2_u0(psi_det,eigenvectors(1,j),N_det,N_det,s2) + if(dabs(eigenvectors(1,j)).gt.0.9d0)then + i_state += 1 + do i=1,N_det + CI_eigenvectors_mono(i,i_state) = eigenvectors(i,j) + enddo + CI_electronic_energy_mono(i_state) = eigenvalues(j) + CI_eigenvectors_s2_mono(i_state) = s2 + endif + enddo + endif deallocate(eigenvectors,eigenvalues) endif diff --git a/src/Determinants/filter_connected.irp.f b/src/Determinants/filter_connected.irp.f index 93a6ee7b..c3d333ad 100644 --- a/src/Determinants/filter_connected.irp.f +++ b/src/Determinants/filter_connected.irp.f @@ -235,8 +235,8 @@ subroutine filter_connected_davidson(key1,key2,Nint,sze,idx) else if (Nint==3) then - !DIR$ LOOP COUNT (1000) i = idx(0) + !DIR$ LOOP COUNT (1000) do j_int=1,N_con_int itmp = det_connections(j_int,i) do while (itmp /= 0_8) @@ -261,8 +261,8 @@ subroutine filter_connected_davidson(key1,key2,Nint,sze,idx) else - !DIR$ LOOP COUNT (1000) i = idx(0) + !DIR$ LOOP COUNT (1000) do j_int=1,N_con_int itmp = det_connections(j_int,i) do while (itmp /= 0_8) diff --git a/src/Determinants/s2.irp.f b/src/Determinants/s2.irp.f index cd1d9fda..760893e0 100644 --- a/src/Determinants/s2.irp.f +++ b/src/Determinants/s2.irp.f @@ -88,19 +88,19 @@ subroutine get_s2_u0(psi_keys_tmp,psi_coefs_tmp,n,nmax,s2) double precision, intent(out) :: s2 integer :: i,j,l double precision :: s2_tmp - s2 = S_z2_Sz + s2 = 0.d0 !$OMP PARALLEL DO DEFAULT(NONE) & !$OMP PRIVATE(i,j,s2_tmp) SHARED(n,psi_coefs_tmp,psi_keys_tmp,N_int) & !$OMP REDUCTION(+:s2) SCHEDULE(dynamic) - do i = 1, n + do i=1,n call get_s2(psi_keys_tmp(1,1,i),psi_keys_tmp(1,1,i),s2_tmp,N_int) -! print*,'s2_tmp = ',s2_tmp - do j = 1, n - call get_s2(psi_keys_tmp(1,1,i),psi_keys_tmp(1,1,j),s2_tmp,N_int) - if (s2_tmp == 0.d0) cycle - s2 += psi_coefs_tmp(i)*psi_coefs_tmp(j)*s2_tmp - enddo + s2 += psi_coefs_tmp(i)*psi_coefs_tmp(i)*s2_tmp + do j=i+1,n + call get_s2(psi_keys_tmp(1,1,i),psi_keys_tmp(1,1,j),s2_tmp,N_int) + s2 += (psi_coefs_tmp(i)+psi_coefs_tmp(i))*psi_coefs_tmp(j)*s2_tmp + enddo enddo !$OMP END PARALLEL DO + s2 += S_z2_Sz end diff --git a/src/Determinants/save_for_casino.irp.f b/src/Determinants/save_for_casino.irp.f index 631f79bd..35c0c3a7 100644 --- a/src/Determinants/save_for_casino.irp.f +++ b/src/Determinants/save_for_casino.irp.f @@ -161,7 +161,7 @@ subroutine save_casino if (ao_l(i) == ao_power(i,1)) then do j=1,ao_prim_num(i) l+=1 - rtmp(l) = ao_coef(i,ao_prim_num(i)-j+1) + rtmp(l) = ao_coef_normalized(i,ao_prim_num(i)) enddo endif enddo diff --git a/src/Determinants/save_for_qmcchem.irp.f b/src/Determinants/save_for_qmcchem.irp.f index b707ff7c..93a9778d 100644 --- a/src/Determinants/save_for_qmcchem.irp.f +++ b/src/Determinants/save_for_qmcchem.irp.f @@ -7,8 +7,6 @@ subroutine save_dets_qmcchem integer, allocatable :: occ(:,:,:), occ_tmp(:,:) !DIR$ ATTRIBUTES ALIGN : $IRP_ALIGN :: occ, occ_tmp - read_wf = .True. - TOUCH read_wf call ezfio_set_determinants_det_num(N_det) call ezfio_set_determinants_det_coef(psi_coef_sorted(1,1)) @@ -46,6 +44,8 @@ subroutine save_dets_qmcchem end program save_for_qmc - call save_dets_qmcchem + read_wf = .True. + TOUCH read_wf +! call save_dets_qmcchem call write_spindeterminants end diff --git a/src/Determinants/spindeterminants.irp.f b/src/Determinants/spindeterminants.irp.f index ffd28f85..5daf4e2c 100644 --- a/src/Determinants/spindeterminants.irp.f +++ b/src/Determinants/spindeterminants.irp.f @@ -50,80 +50,88 @@ BEGIN_PROVIDER [ integer(bit_kind), psi_det_beta, (N_int,psi_det_size) ] enddo END_PROVIDER - BEGIN_PROVIDER [ integer(bit_kind), psi_det_alpha_unique, (N_int,psi_det_size) ] -&BEGIN_PROVIDER [ integer, N_det_alpha_unique ] + +BEGIN_TEMPLATE + + BEGIN_PROVIDER [ integer(bit_kind), psi_det_$alpha_unique, (N_int,psi_det_size) ] +&BEGIN_PROVIDER [ integer, N_det_$alpha_unique ] implicit none BEGIN_DOC - ! Unique alpha determinants + ! Unique $alpha determinants END_DOC - integer :: i,k + integer :: i,j,k integer, allocatable :: iorder(:) integer*8, allocatable :: bit_tmp(:) integer*8 :: last_key integer*8, external :: spin_det_search_key + logical,allocatable :: duplicate(:) - allocate ( iorder(N_det), bit_tmp(N_det)) + allocate ( iorder(N_det), bit_tmp(N_det), duplicate(N_det) ) do i=1,N_det iorder(i) = i - bit_tmp(i) = spin_det_search_key(psi_det_alpha(1,i),N_int) + bit_tmp(i) = spin_det_search_key(psi_det_$alpha(1,i),N_int) enddo call i8sort(bit_tmp,iorder,N_det) - N_det_alpha_unique = 0 + N_det_$alpha_unique = 0 last_key = 0_8 do i=1,N_det - if (bit_tmp(i) /= last_key) then - last_key = bit_tmp(i) - N_det_alpha_unique += 1 - do k=1,N_int - psi_det_alpha_unique(k,N_det_alpha_unique) = psi_det_alpha(k,iorder(i)) - enddo + last_key = bit_tmp(i) + N_det_$alpha_unique += 1 + do k=1,N_int + psi_det_$alpha_unique(k,N_det_$alpha_unique) = psi_det_$alpha(k,iorder(i)) + enddo + duplicate(i) = .False. + enddo + + j=1 + do i=1,N_det_$alpha_unique-1 + if (duplicate(i)) then + cycle + endif + j = i+1 + do while (bit_tmp(j)==bit_tmp(i)) + if (duplicate(j)) then + j += 1 + cycle + endif + duplicate(j) = .True. + do k=1,N_int + if (psi_det_$alpha_unique(k,i) /= psi_det_$alpha_unique(k,j)) then + duplicate(j) = .False. + exit + endif + enddo + j+=1 + if (j > N_det_$alpha_unique) then + exit + endif + enddo + enddo + + j=1 + do i=2,N_det_$alpha_unique + if (duplicate(i)) then + cycle + else + j += 1 + psi_det_$alpha_unique(:,j) = psi_det_$alpha_unique(:,i) endif enddo + N_det_$alpha_unique = j - deallocate (iorder, bit_tmp) + deallocate (iorder, bit_tmp, duplicate) END_PROVIDER - BEGIN_PROVIDER [ integer(bit_kind), psi_det_beta_unique, (N_int,psi_det_size) ] -&BEGIN_PROVIDER [ integer, N_det_beta_unique ] - implicit none - BEGIN_DOC - ! Unique beta determinants - END_DOC +SUBST [ alpha ] - integer :: i,k - integer, allocatable :: iorder(:) - integer*8, allocatable :: bit_tmp(:) - integer*8 :: last_key - integer*8, external :: spin_det_search_key - - allocate ( iorder(N_det), bit_tmp(N_det)) - - do i=1,N_det - iorder(i) = i - bit_tmp(i) = spin_det_search_key(psi_det_beta(1,i),N_int) - enddo - - call i8sort(bit_tmp,iorder,N_det) - - N_det_beta_unique = 0 - last_key = 0_8 - do i=1,N_det - if (bit_tmp(i) /= last_key) then - last_key = bit_tmp(i) - N_det_beta_unique += 1 - do k=1,N_int - psi_det_beta_unique(k,N_det_beta_unique) = psi_det_beta(k,iorder(i)) - enddo - endif - enddo - - deallocate (iorder, bit_tmp) -END_PROVIDER +alpha ;; +beta ;; +END_TEMPLATE @@ -150,6 +158,7 @@ integer function get_index_in_psi_det_alpha_unique(key,Nint) !DIR$ FORCEINLINE det_ref = spin_det_search_key(key,Nint) + !DIR$ FORCEINLINE det_search = spin_det_search_key(psi_det_alpha_unique(1,1),Nint) @@ -337,52 +346,52 @@ subroutine write_spindeterminants call ezfio_set_spindeterminants_psi_coef_matrix_rows(psi_svd_matrix_rows) call ezfio_set_spindeterminants_psi_coef_matrix_columns(psi_svd_matrix_columns) - integer :: n_svd_coefs - double precision :: norm, f - f = 1.d0/dble(N_states) - norm = 1.d0 - do n_svd_coefs=1,N_det_alpha_unique - do k=1,N_states - norm -= psi_svd_coefs(n_svd_coefs,k)*psi_svd_coefs(n_svd_coefs,k) - enddo - if (norm < 1.d-4) then - exit - endif - enddo - n_svd_coefs -= 1 - call ezfio_set_spindeterminants_n_svd_coefs(n_svd_coefs) - - double precision, allocatable :: dtmp(:,:,:) - allocate(dtmp(N_det_alpha_unique,n_svd_coefs,N_states)) - do k=1,N_states - do j=1,n_svd_coefs - do i=1,N_det_alpha_unique - dtmp(i,j,k) = psi_svd_alpha(i,j,k) - enddo - enddo - enddo - call ezfio_set_spindeterminants_psi_svd_alpha(dtmp) - deallocate(dtmp) - - allocate(dtmp(N_det_beta_unique,n_svd_coefs,N_states)) - do k=1,N_states - do j=1,n_svd_coefs - do i=1,N_det_beta_unique - dtmp(i,j,k) = psi_svd_beta(i,j,k) - enddo - enddo - enddo - call ezfio_set_spindeterminants_psi_svd_beta(dtmp) - deallocate(dtmp) - - allocate(dtmp(n_svd_coefs,N_states,1)) - do k=1,N_states - do j=1,n_svd_coefs - dtmp(j,k,1) = psi_svd_coefs(j,k) - enddo - enddo - call ezfio_set_spindeterminants_psi_svd_coefs(dtmp) - deallocate(dtmp) +! integer :: n_svd_coefs +! double precision :: norm, f +! f = 1.d0/dble(N_states) +! norm = 1.d0 +! do n_svd_coefs=1,N_det_alpha_unique +! do k=1,N_states +! norm -= psi_svd_coefs(n_svd_coefs,k)*psi_svd_coefs(n_svd_coefs,k) +! enddo +! if (norm < 1.d-4) then +! exit +! endif +! enddo +! n_svd_coefs -= 1 +! call ezfio_set_spindeterminants_n_svd_coefs(n_svd_coefs) +! +! double precision, allocatable :: dtmp(:,:,:) +! allocate(dtmp(N_det_alpha_unique,n_svd_coefs,N_states)) +! do k=1,N_states +! do j=1,n_svd_coefs +! do i=1,N_det_alpha_unique +! dtmp(i,j,k) = psi_svd_alpha(i,j,k) +! enddo +! enddo +! enddo +! call ezfio_set_spindeterminants_psi_svd_alpha(dtmp) +! deallocate(dtmp) +! +! allocate(dtmp(N_det_beta_unique,n_svd_coefs,N_states)) +! do k=1,N_states +! do j=1,n_svd_coefs +! do i=1,N_det_beta_unique +! dtmp(i,j,k) = psi_svd_beta(i,j,k) +! enddo +! enddo +! enddo +! call ezfio_set_spindeterminants_psi_svd_beta(dtmp) +! deallocate(dtmp) +! +! allocate(dtmp(n_svd_coefs,N_states,1)) +! do k=1,N_states +! do j=1,n_svd_coefs +! dtmp(j,k,1) = psi_svd_coefs(j,k) +! enddo +! enddo +! call ezfio_set_spindeterminants_psi_svd_coefs(dtmp) +! deallocate(dtmp) end @@ -439,6 +448,7 @@ BEGIN_PROVIDER [ double precision, psi_svd_matrix_values, (N_det,N_states) ] do k=1,N_det i = get_index_in_psi_det_alpha_unique(psi_det(1,1,k),N_int) j = get_index_in_psi_det_beta_unique (psi_det(1,2,k),N_int) + do l=1,N_states psi_svd_matrix_values(k,l) = psi_coef(k,l) enddo diff --git a/src/Electrons/NEEDED_CHILDREN_MODULES b/src/Electrons/NEEDED_CHILDREN_MODULES new file mode 100644 index 00000000..83260f86 --- /dev/null +++ b/src/Electrons/NEEDED_CHILDREN_MODULES @@ -0,0 +1 @@ +Output diff --git a/src/Electrons/NEEDED_MODULES b/src/Electrons/NEEDED_MODULES deleted file mode 100644 index e9594555..00000000 --- a/src/Electrons/NEEDED_MODULES +++ /dev/null @@ -1 +0,0 @@ -Ezfio_files Output Utils diff --git a/src/Electrons/README.rst b/src/Electrons/README.rst index ffd6d21b..e71a552d 100644 --- a/src/Electrons/README.rst +++ b/src/Electrons/README.rst @@ -24,9 +24,7 @@ Needed Modules .. Do not edit this section. It was auto-generated from the .. NEEDED_MODULES file. -* `Ezfio_files `_ * `Output `_ -* `Utils `_ Documentation ============= diff --git a/src/Utils/NEEDED_MODULES b/src/Ezfio_files/NEEDED_CHILDREN_MODULES similarity index 100% rename from src/Utils/NEEDED_MODULES rename to src/Ezfio_files/NEEDED_CHILDREN_MODULES diff --git a/src/Ezfio_files/README.rst b/src/Ezfio_files/README.rst index 274eff11..e0ef23da 100644 --- a/src/Ezfio_files/README.rst +++ b/src/Ezfio_files/README.rst @@ -30,3 +30,4 @@ Documentation + diff --git a/src/FCIdump/NEEDED_CHILDREN_MODULES b/src/FCIdump/NEEDED_CHILDREN_MODULES new file mode 100644 index 00000000..aae89501 --- /dev/null +++ b/src/FCIdump/NEEDED_CHILDREN_MODULES @@ -0,0 +1 @@ +Determinants diff --git a/src/FCIdump/NEEDED_MODULES b/src/FCIdump/NEEDED_MODULES deleted file mode 100644 index c5e6c2d3..00000000 --- a/src/FCIdump/NEEDED_MODULES +++ /dev/null @@ -1 +0,0 @@ -AOs Bielec_integrals Bitmask Determinants Electrons Ezfio_files MonoInts MOs Nuclei Output Utils diff --git a/src/FCIdump/README.rst b/src/FCIdump/README.rst index bf39955b..8a467b16 100644 --- a/src/FCIdump/README.rst +++ b/src/FCIdump/README.rst @@ -21,15 +21,5 @@ Needed Modules .. Do not edit this section. It was auto-generated from the .. NEEDED_MODULES file. -* `AOs `_ -* `Bielec_integrals `_ -* `Bitmask `_ * `Determinants `_ -* `Electrons `_ -* `Ezfio_files `_ -* `MonoInts `_ -* `MOs `_ -* `Nuclei `_ -* `Output `_ -* `Utils `_ diff --git a/src/Full_CI/NEEDED_CHILDREN_MODULES b/src/Full_CI/NEEDED_CHILDREN_MODULES new file mode 100644 index 00000000..04ce9e78 --- /dev/null +++ b/src/Full_CI/NEEDED_CHILDREN_MODULES @@ -0,0 +1 @@ +Perturbation Selectors_full Generators_full diff --git a/src/Full_CI/NEEDED_MODULES b/src/Full_CI/NEEDED_MODULES deleted file mode 100644 index f225090c..00000000 --- a/src/Full_CI/NEEDED_MODULES +++ /dev/null @@ -1,2 +0,0 @@ -AOs Bielec_integrals Bitmask Determinants Electrons Ezfio_files Generators_full Hartree_Fock MOGuess MonoInts MOs Nuclei Output Perturbation Properties Selectors_full Utils - diff --git a/src/Full_CI/README.rst b/src/Full_CI/README.rst index 53fdc1d5..51bb05d2 100644 --- a/src/Full_CI/README.rst +++ b/src/Full_CI/README.rst @@ -24,21 +24,7 @@ Needed Modules .. Do not edit this section. It was auto-generated from the .. NEEDED_MODULES file. -* `AOs `_ -* `Bielec_integrals `_ -* `Bitmask `_ -* `Determinants `_ -* `Electrons `_ -* `Ezfio_files `_ -* `Generators_full `_ -* `Hartree_Fock `_ -* `MOGuess `_ -* `MonoInts `_ -* `MOs `_ -* `Nuclei `_ -* `Output `_ * `Perturbation `_ -* `Properties `_ * `Selectors_full `_ -* `Utils `_ +* `Generators_full `_ diff --git a/src/Generators_CAS/NEEDED_CHILDREN_MODULES b/src/Generators_CAS/NEEDED_CHILDREN_MODULES new file mode 100644 index 00000000..aae89501 --- /dev/null +++ b/src/Generators_CAS/NEEDED_CHILDREN_MODULES @@ -0,0 +1 @@ +Determinants diff --git a/src/Generators_CAS/NEEDED_MODULES b/src/Generators_CAS/NEEDED_MODULES deleted file mode 100644 index c5e6c2d3..00000000 --- a/src/Generators_CAS/NEEDED_MODULES +++ /dev/null @@ -1 +0,0 @@ -AOs Bielec_integrals Bitmask Determinants Electrons Ezfio_files MonoInts MOs Nuclei Output Utils diff --git a/src/Generators_CAS/README.rst b/src/Generators_CAS/README.rst index 3fca0916..b729212c 100644 --- a/src/Generators_CAS/README.rst +++ b/src/Generators_CAS/README.rst @@ -43,15 +43,5 @@ Needed Modules .. Do not edit this section. It was auto-generated from the .. NEEDED_MODULES file. -* `AOs `_ -* `Bielec_integrals `_ -* `Bitmask `_ * `Determinants `_ -* `Electrons `_ -* `Ezfio_files `_ -* `MonoInts `_ -* `MOs `_ -* `Nuclei `_ -* `Output `_ -* `Utils `_ diff --git a/src/Generators_full/NEEDED_CHILDREN_MODULES b/src/Generators_full/NEEDED_CHILDREN_MODULES new file mode 100644 index 00000000..54f54203 --- /dev/null +++ b/src/Generators_full/NEEDED_CHILDREN_MODULES @@ -0,0 +1 @@ +Determinants Hartree_Fock diff --git a/src/Generators_full/NEEDED_MODULES b/src/Generators_full/NEEDED_MODULES deleted file mode 100644 index a848a687..00000000 --- a/src/Generators_full/NEEDED_MODULES +++ /dev/null @@ -1,2 +0,0 @@ -AOs Bielec_integrals Bitmask Determinants Electrons Ezfio_files Hartree_Fock MOGuess MonoInts MOs Nuclei Output Utils - diff --git a/src/Generators_full/README.rst b/src/Generators_full/README.rst index 79f4037c..e558f48b 100644 --- a/src/Generators_full/README.rst +++ b/src/Generators_full/README.rst @@ -40,17 +40,6 @@ Needed Modules .. Do not edit this section. It was auto-generated from the .. NEEDED_MODULES file. -* `AOs `_ -* `Bielec_integrals `_ -* `Bitmask `_ * `Determinants `_ -* `Electrons `_ -* `Ezfio_files `_ * `Hartree_Fock `_ -* `MOGuess `_ -* `MonoInts `_ -* `MOs `_ -* `Nuclei `_ -* `Output `_ -* `Utils `_ diff --git a/src/Generators_restart/NEEDED_CHILDREN_MODULES b/src/Generators_restart/NEEDED_CHILDREN_MODULES new file mode 100644 index 00000000..aae89501 --- /dev/null +++ b/src/Generators_restart/NEEDED_CHILDREN_MODULES @@ -0,0 +1 @@ +Determinants diff --git a/src/Generators_restart/NEEDED_MODULES b/src/Generators_restart/NEEDED_MODULES deleted file mode 100644 index c5e6c2d3..00000000 --- a/src/Generators_restart/NEEDED_MODULES +++ /dev/null @@ -1 +0,0 @@ -AOs Bielec_integrals Bitmask Determinants Electrons Ezfio_files MonoInts MOs Nuclei Output Utils diff --git a/src/Hartree_Fock/NEEDED_CHILDREN_MODULES b/src/Hartree_Fock/NEEDED_CHILDREN_MODULES new file mode 100644 index 00000000..b779faec --- /dev/null +++ b/src/Hartree_Fock/NEEDED_CHILDREN_MODULES @@ -0,0 +1 @@ +Bielec_integrals MOGuess diff --git a/src/Hartree_Fock/NEEDED_MODULES b/src/Hartree_Fock/NEEDED_MODULES deleted file mode 100644 index 8f7f21c6..00000000 --- a/src/Hartree_Fock/NEEDED_MODULES +++ /dev/null @@ -1 +0,0 @@ -AOs Bielec_integrals Bitmask Electrons Ezfio_files MonoInts MOGuess MOs Nuclei Output Utils diff --git a/src/Hartree_Fock/README.rst b/src/Hartree_Fock/README.rst index a1030e4a..2b470e9f 100644 --- a/src/Hartree_Fock/README.rst +++ b/src/Hartree_Fock/README.rst @@ -10,17 +10,8 @@ Needed Modules .. Do not edit this section. It was auto-generated from the .. NEEDED_MODULES file. -* `AOs `_ * `Bielec_integrals `_ -* `Bitmask `_ -* `Electrons `_ -* `Ezfio_files `_ -* `MonoInts `_ * `MOGuess `_ -* `MOs `_ -* `Nuclei `_ -* `Output `_ -* `Utils `_ Documentation ============= diff --git a/src/MOGuess/NEEDED_CHILDREN_MODULES b/src/MOGuess/NEEDED_CHILDREN_MODULES new file mode 100644 index 00000000..88d7352e --- /dev/null +++ b/src/MOGuess/NEEDED_CHILDREN_MODULES @@ -0,0 +1 @@ +MonoInts diff --git a/src/MOGuess/NEEDED_MODULES b/src/MOGuess/NEEDED_MODULES deleted file mode 100644 index 59b334d4..00000000 --- a/src/MOGuess/NEEDED_MODULES +++ /dev/null @@ -1 +0,0 @@ -AOs Electrons Ezfio_files MonoInts MOs Nuclei Output Utils diff --git a/src/MOGuess/README.rst b/src/MOGuess/README.rst index cb1702ab..771825ee 100644 --- a/src/MOGuess/README.rst +++ b/src/MOGuess/README.rst @@ -8,14 +8,7 @@ Needed Modules .. Do not edit this section. It was auto-generated from the .. NEEDED_MODULES file. -* `AOs `_ -* `Electrons `_ -* `Ezfio_files `_ * `MonoInts `_ -* `MOs `_ -* `Nuclei `_ -* `Output `_ -* `Utils `_ Documentation ============= diff --git a/src/MOs/ASSUMPTIONS.rst b/src/MOs/ASSUMPTIONS.rst index e69de29b..8514ef73 100644 --- a/src/MOs/ASSUMPTIONS.rst +++ b/src/MOs/ASSUMPTIONS.rst @@ -0,0 +1,4 @@ +ASSUMPTONS +========== + +* The AO basis functions are normalized. diff --git a/src/MOs/NEEDED_CHILDREN_MODULES b/src/MOs/NEEDED_CHILDREN_MODULES new file mode 100644 index 00000000..4692ec21 --- /dev/null +++ b/src/MOs/NEEDED_CHILDREN_MODULES @@ -0,0 +1 @@ +AOs Electrons diff --git a/src/MOs/NEEDED_MODULES b/src/MOs/NEEDED_MODULES deleted file mode 100644 index 5ca73603..00000000 --- a/src/MOs/NEEDED_MODULES +++ /dev/null @@ -1,3 +0,0 @@ -AOs Electrons Ezfio_files Nuclei Output Utils - - diff --git a/src/MOs/README.rst b/src/MOs/README.rst index d7a15219..5ddd7928 100644 --- a/src/MOs/README.rst +++ b/src/MOs/README.rst @@ -8,6 +8,8 @@ Molecular orbitals are expressed as \phi_k({\bf r}) = \sum_i C_{ik} \chi_k({\bf r}) +where :math:`\chi_k` are *normalized* atomic basis set. + The current set of molecular orbitals has a label ``mo_label``. When the orbitals are modified, the label should also be updated to keep everything consistent. @@ -16,6 +18,18 @@ When saving the MOs, the ``mo_basis`` directory of the EZFIO file is copied in the ``save`` directory, named by the current ``mo_label``. All this is done with the script named ``save_current_mos.sh`` in the ``scripts`` directory. +Assumptions +=========== + +.. Do not edit this section. It was auto-generated from the +.. NEEDED_MODULES file. + +ASSUMPTONS +========== + +* The AO basis functions are normalized. + + Needed Modules ============== @@ -24,10 +38,6 @@ Needed Modules * `AOs `_ * `Electrons `_ -* `Ezfio_files `_ -* `Nuclei `_ -* `Output `_ -* `Utils `_ Documentation ============= diff --git a/src/MP2/NEEDED_CHILDREN_MODULES b/src/MP2/NEEDED_CHILDREN_MODULES new file mode 100644 index 00000000..d26e4dee --- /dev/null +++ b/src/MP2/NEEDED_CHILDREN_MODULES @@ -0,0 +1 @@ +Perturbation Selectors_full SingleRefMethod diff --git a/src/MP2/NEEDED_MODULES b/src/MP2/NEEDED_MODULES deleted file mode 100644 index b7a006c3..00000000 --- a/src/MP2/NEEDED_MODULES +++ /dev/null @@ -1,2 +0,0 @@ -AOs Bielec_integrals Bitmask Determinants Electrons Ezfio_files Hartree_Fock MOGuess MonoInts MOs Nuclei Output Perturbation Properties Selectors_full SingleRefMethod Utils - diff --git a/src/MP2/README.rst b/src/MP2/README.rst index 74db8039..f68d5936 100644 --- a/src/MP2/README.rst +++ b/src/MP2/README.rst @@ -19,21 +19,7 @@ Needed Modules .. Do not edit this section. It was auto-generated from the .. NEEDED_MODULES file. -* `AOs `_ -* `Bielec_integrals `_ -* `Bitmask `_ -* `Determinants `_ -* `Electrons `_ -* `Ezfio_files `_ -* `Hartree_Fock `_ -* `MOGuess `_ -* `MonoInts `_ -* `MOs `_ -* `Nuclei `_ -* `Output `_ * `Perturbation `_ -* `Properties `_ * `Selectors_full `_ * `SingleRefMethod `_ -* `Utils `_ diff --git a/src/MRCC/NEEDED_CHILDREN_MODULES b/src/MRCC/NEEDED_CHILDREN_MODULES new file mode 100644 index 00000000..04ce9e78 --- /dev/null +++ b/src/MRCC/NEEDED_CHILDREN_MODULES @@ -0,0 +1 @@ +Perturbation Selectors_full Generators_full diff --git a/src/MRCC/NEEDED_MODULES b/src/MRCC/NEEDED_MODULES deleted file mode 100644 index f225090c..00000000 --- a/src/MRCC/NEEDED_MODULES +++ /dev/null @@ -1,2 +0,0 @@ -AOs Bielec_integrals Bitmask Determinants Electrons Ezfio_files Generators_full Hartree_Fock MOGuess MonoInts MOs Nuclei Output Perturbation Properties Selectors_full Utils - diff --git a/src/MRCC/README.rst b/src/MRCC/README.rst index f96f329f..5bb2009c 100644 --- a/src/MRCC/README.rst +++ b/src/MRCC/README.rst @@ -8,23 +8,9 @@ Needed Modules .. Do not edit this section. It was auto-generated from the .. NEEDED_MODULES file. -* `AOs `_ -* `Bielec_integrals `_ -* `Bitmask `_ -* `Determinants `_ -* `Electrons `_ -* `Ezfio_files `_ -* `Generators_full `_ -* `Hartree_Fock `_ -* `MOGuess `_ -* `MonoInts `_ -* `MOs `_ -* `Nuclei `_ -* `Output `_ * `Perturbation `_ -* `Properties `_ * `Selectors_full `_ -* `Utils `_ +* `Generators_full `_ Documentation ============= @@ -65,7 +51,7 @@ Documentation `ci_electronic_energy_dressed `_ Eigenvectors/values of the CI matrix -`ci_energy_dressed `_ +`ci_energy_dressed `_ N_states lowest eigenvalues of the dressed CI matrix `delta_ij `_ @@ -74,7 +60,7 @@ Documentation `delta_ij_non_cas `_ Dressing matrix in SD basis -`diagonalize_ci_dressed `_ +`diagonalize_ci_dressed `_ Replace the coefficients of the CI states by the coefficients of the eigenstates of the CI matrix diff --git a/src/MRCC/mrcc_utils.irp.f b/src/MRCC/mrcc_utils.irp.f index 9b4add38..611a70be 100644 --- a/src/MRCC/mrcc_utils.irp.f +++ b/src/MRCC/mrcc_utils.irp.f @@ -110,20 +110,32 @@ END_PROVIDER integer :: i_state double precision :: s2 i_state = 0 - do j=1,N_det - call get_s2_u0(psi_det,eigenvectors(1,j),N_det,N_det,s2) - if(dabs(s2-expected_s2).le.0.3d0)then - i_state += 1 - do i=1,N_det - CI_eigenvectors_dressed(i,i_state) = eigenvectors(i,j) - enddo - CI_electronic_energy_dressed(i_state) = eigenvalues(j) - CI_eigenvectors_s2_dressed(i_state) = s2 - endif - if (i_state.ge.N_states_diag) then - exit - endif - enddo + if (s2_eig) then + do j=1,N_det + call get_s2_u0(psi_det,eigenvectors(1,j),N_det,N_det,s2) + if(dabs(s2-expected_s2).le.0.3d0)then + i_state += 1 + do i=1,N_det + CI_eigenvectors_dressed(i,i_state) = eigenvectors(i,j) + enddo + CI_electronic_energy_dressed(i_state) = eigenvalues(j) + CI_eigenvectors_s2_dressed(i_state) = s2 + endif + if (i_state.ge.N_states_diag) then + exit + endif + enddo + else + do j=1,N_states_diag + call get_s2_u0(psi_det,eigenvectors(1,j),N_det,N_det,s2) + i_state += 1 + do i=1,N_det + CI_eigenvectors_dressed(i,i_state) = eigenvectors(i,j) + enddo + CI_electronic_energy_dressed(i_state) = eigenvalues(j) + CI_eigenvectors_s2_dressed(i_state) = s2 + enddo + endif deallocate(eigenvectors,eigenvalues) endif diff --git a/src/Makefile b/src/Makefile index 237b3ae4..1bb5aa87 100644 --- a/src/Makefile +++ b/src/Makefile @@ -12,21 +12,17 @@ EZFIO=$(EZFIO_DIR)/lib/libezfio_irp.a default: ezfio - $(QPACKAGE_ROOT)/scripts/build_modules.sh $(ALL_MODULES) + $(QPACKAGE_ROOT)/scripts/module/build_modules.sh $(ALL_MODULES) veryclean: - $(QPACKAGE_ROOT)/scripts/clean_modules.sh $(ALL_MODULES) - # Define the dict [type in EZFIO.cfg] = ocaml type , f90 type - # If you change the qptypes_generator.ml, you need to rm this - # For simplicity add this to the veryclean rule - rm $(QPACKAGE_ROOT)/scripts/ezfio_interface/fancy_type.p + $(QPACKAGE_ROOT)/scripts/module/clean_modules.sh $(ALL_MODULES) $(ALL_MODULES): ezfio - $(QPACKAGE_ROOT)/scripts/build_modules.sh $@ + $(QPACKAGE_ROOT)/scripts/module/build_modules.sh $@ # Define the EZFIO rules $(EZFIO): $(wildcard $(QPACKAGE_ROOT)/src/*/*.ezfio_config) $(wildcard $(QPACKAGE_ROOT)/src/*/EZFIO.cfg) - $(QPACKAGE_ROOT)/scripts/prepare_ezfio.sh + $(QPACKAGE_ROOT)/scripts/ezfio_interface/prepare_ezfio.sh cd $(EZFIO_DIR);\ export FC="$(FC)" ; export FCFLAGS="$(FCFLAGS)" ; export IRPF90="$(IRPF90)" ;\ $(MAKE) ;\ diff --git a/src/Makefile.common b/src/Makefile.common index eddaa481..606e6f7c 100644 --- a/src/Makefile.common +++ b/src/Makefile.common @@ -18,8 +18,8 @@ default: all .gitignore # Include the user's config include $(QPACKAGE_ROOT)/src/Makefile.config -# Create the NEEDED_MODULES variable, needed for IRPF90 -NEEDED_MODULES=$(shell cat NEEDED_MODULES) +# Create the NEEDED_CHILDREN_MODULES variable, needed for IRPF90 +NEEDED_CHILDREN_MODULES=$(shell module_handler.py print_genealogy) # Check and update dependencies include Makefile.depend @@ -28,7 +28,7 @@ include Makefile.depend # Define the Makefile common variables EZFIO_DIR=$(QPACKAGE_ROOT)/EZFIO EZFIO=$(EZFIO_DIR)/lib/libezfio_irp.a -INCLUDE_DIRS=$(NEEDED_MODULES) include +INCLUDE_DIRS=$(NEEDED_CHILDREN_MODULES) include clean_links: rm -f $(INCLUDE_DIRS) $$(basename $$PWD) @@ -36,7 +36,7 @@ clean_links: LIB+=$(EZFIO) $(MKL) IRPF90+=$(patsubst %, -I %, $(INCLUDE_DIRS)) $(IRPF90_FLAGS) -irpf90.make: $(filter-out IRPF90_temp/%, $(wildcard */*.irp.f)) $(wildcard *.irp.f) $(wildcard *.inc.f) Makefile $(EZFIO) NEEDED_MODULES $(wildcard *.py) +irpf90.make: $(filter-out IRPF90_temp/%, $(wildcard */*.irp.f)) $(wildcard *.irp.f) $(wildcard *.inc.f) Makefile $(EZFIO) NEEDED_CHILDREN_MODULES $(wildcard *.py) - $(IRPF90) - update_README.py @@ -45,7 +45,7 @@ include irpf90.make endif .gitignore: - $(QPACKAGE_ROOT)/scripts/create_gitignore.sh + $(QPACKAGE_ROOT)/scripts/create/create_gitignore.sh # Frequent typos clena: clean diff --git a/src/Molden/NEEDED_CHILDREN_MODULES b/src/Molden/NEEDED_CHILDREN_MODULES new file mode 100644 index 00000000..b936db90 --- /dev/null +++ b/src/Molden/NEEDED_CHILDREN_MODULES @@ -0,0 +1 @@ +MOs diff --git a/src/Molden/NEEDED_MODULES b/src/Molden/NEEDED_MODULES deleted file mode 100644 index 190f8c6e..00000000 --- a/src/Molden/NEEDED_MODULES +++ /dev/null @@ -1 +0,0 @@ -AOs Electrons Ezfio_files MOs Nuclei Output Utils diff --git a/src/Molden/README.rst b/src/Molden/README.rst index d0e2343d..128a020a 100644 --- a/src/Molden/README.rst +++ b/src/Molden/README.rst @@ -31,11 +31,5 @@ Needed Modules .. Do not edit this section. It was auto-generated from the .. NEEDED_MODULES file. -* `AOs `_ -* `Electrons `_ -* `Ezfio_files `_ * `MOs `_ -* `Nuclei `_ -* `Output `_ -* `Utils `_ diff --git a/src/Molden/print_mo.irp.f b/src/Molden/print_mo.irp.f index 9cec8fbd..b147fe50 100644 --- a/src/Molden/print_mo.irp.f +++ b/src/Molden/print_mo.irp.f @@ -92,9 +92,9 @@ subroutine write_Ao_basis(i_unit_output) do k = 1, ao_prim_num(i_ao) i_prim +=1 if(i_prim.lt.100)then - write(i_unit_output,'(4X,I3,3X,A1,6X,I2,6X,F16.7,2X,F16.12)')i_shell,character_shell,i_prim,ao_expo_unsorted(i_ao,k),ao_coef_unnormalized(i_ao,k) + write(i_unit_output,'(4X,I3,3X,A1,6X,I2,6X,F16.7,2X,F16.12)')i_shell,character_shell,i_prim,ao_expo(i_ao,k),ao_coef(i_ao,k) else - write(i_unit_output,'(4X,I3,3X,A1,5X,I3,6X,F16.7,2X,F16.12)')i_shell,character_shell,i_prim,ao_expo_unsorted(i_ao,k),ao_coef_unnormalized(i_ao,k) + write(i_unit_output,'(4X,I3,3X,A1,5X,I3,6X,F16.7,2X,F16.12)')i_shell,character_shell,i_prim,ao_expo(i_ao,k),ao_coef(i_ao,k) endif enddo write(i_unit_output,*)'' diff --git a/src/MonoInts/EZFIO.cfg b/src/MonoInts/EZFIO.cfg new file mode 100644 index 00000000..33a8d619 --- /dev/null +++ b/src/MonoInts/EZFIO.cfg @@ -0,0 +1,6 @@ +[do_pseudo] +type: logical +doc: Using pseudo potential integral of not +interface: input +default: False + diff --git a/src/MonoInts/Makefile b/src/MonoInts/Makefile index 06dc50ff..b1f3b02c 100644 --- a/src/MonoInts/Makefile +++ b/src/MonoInts/Makefile @@ -3,4 +3,4 @@ SRC= OBJ= -include $(QPACKAGE_ROOT)/src/Makefile.common +include $(QPACKAGE_ROOT)/src/Makefile.common \ No newline at end of file diff --git a/src/MonoInts/NEEDED_CHILDREN_MODULES b/src/MonoInts/NEEDED_CHILDREN_MODULES new file mode 100644 index 00000000..be46a359 --- /dev/null +++ b/src/MonoInts/NEEDED_CHILDREN_MODULES @@ -0,0 +1 @@ +MOs Pseudo_integrals diff --git a/src/MonoInts/NEEDED_MODULES b/src/MonoInts/NEEDED_MODULES deleted file mode 100644 index 67230c44..00000000 --- a/src/MonoInts/NEEDED_MODULES +++ /dev/null @@ -1 +0,0 @@ -AOs Electrons Ezfio_files MOs Nuclei Output Utils diff --git a/src/MonoInts/README.rst b/src/MonoInts/README.rst index fdbb086b..ac4983a9 100644 --- a/src/MonoInts/README.rst +++ b/src/MonoInts/README.rst @@ -4,13 +4,8 @@ Needed Modules .. Do not edit this section. It was auto-generated from the .. NEEDED_MODULES file. -* `AOs `_ -* `Electrons `_ -* `Ezfio_files `_ * `MOs `_ -* `Nuclei `_ -* `Output `_ -* `Utils `_ +* `Pseudo_integrals `_ Documentation ============= @@ -69,38 +64,38 @@ Documentation `ao_nucl_elec_integral `_ interaction nuclear electron -`ao_nucl_elec_integral_per_atom `_ +`ao_nucl_elec_integral_per_atom `_ ao_nucl_elec_integral_per_atom(i,j,k) = - where Rk is the geometry of the kth atom -`give_polynom_mult_center_mono_elec `_ +`give_polynom_mult_center_mono_elec `_ Undocumented -`i_x1_pol_mult_mono_elec `_ +`i_x1_pol_mult_mono_elec `_ Undocumented -`i_x2_pol_mult_mono_elec `_ +`i_x2_pol_mult_mono_elec `_ Undocumented -`int_gaus_pol `_ +`int_gaus_pol `_ Undocumented -`nai_pol_mult `_ +`nai_pol_mult `_ Undocumented -`v_e_n `_ +`v_e_n `_ Undocumented -`v_phi `_ +`v_phi `_ Undocumented -`v_r `_ +`v_r `_ Undocumented -`v_theta `_ +`v_theta `_ Undocumented -`wallis `_ +`wallis `_ Undocumented `mo_nucl_elec_integral `_ diff --git a/src/MonoInts/kin_ao_ints.irp.f b/src/MonoInts/kin_ao_ints.irp.f index 444c3880..10b065b4 100644 --- a/src/MonoInts/kin_ao_ints.irp.f +++ b/src/MonoInts/kin_ao_ints.irp.f @@ -36,8 +36,8 @@ !$OMP alpha, beta,i,j,c,d_a_2,d_2,deriv_tmp, & !$OMP overlap_x0,overlap_y0,overlap_z0) & !$OMP SHARED(nucl_coord,ao_power,ao_prim_num, & - !$OMP ao_deriv2_x,ao_deriv2_y,ao_deriv2_z,ao_num,ao_coef_transp,ao_nucl, & - !$OMP ao_expo_transp,dim1) + !$OMP ao_deriv2_x,ao_deriv2_y,ao_deriv2_z,ao_num,ao_coef_normalized_ordered_transp,ao_nucl, & + !$OMP ao_expo_ordered_transp,dim1) do j=1,ao_num A_center(1) = nucl_coord( ao_nucl(j), 1 ) A_center(2) = nucl_coord( ao_nucl(j), 2 ) @@ -58,12 +58,12 @@ power_B(2) = ao_power( i, 2 ) power_B(3) = ao_power( i, 3 ) do n = 1,ao_prim_num(j) - alpha = ao_expo_transp(n,j) + alpha = ao_expo_ordered_transp(n,j) !DEC$ VECTOR ALIGNED do l = 1, ao_prim_num(i) - beta = ao_expo_transp(l,i) + beta = ao_expo_ordered_transp(l,i) call overlap_gaussian_xyz(A_center,B_center,alpha,beta,power_A,power_B,overlap_x0,overlap_y0,overlap_z0,overlap,dim1) - c = ao_coef_transp(n,j) * ao_coef_transp(l,i) + c = ao_coef_normalized_ordered_transp(n,j) * ao_coef_normalized_ordered_transp(l,i) ! if (abs(c) < 1.d-8) then ! cycle ! endif diff --git a/src/MonoInts/pot_ao_ints.irp.f b/src/MonoInts/pot_ao_ints.irp.f index f430ace9..a9e72e57 100644 --- a/src/MonoInts/pot_ao_ints.irp.f +++ b/src/MonoInts/pot_ao_ints.irp.f @@ -4,65 +4,74 @@ END_DOC implicit none double precision :: alpha, beta, gama, delta - integer :: i_c,num_A,num_B - double precision :: A_center(3),B_center(3),C_center(3) - integer :: power_A(3),power_B(3) - integer :: i,j,k,l,n_pt_in,m - double precision ::overlap_x,overlap_y,overlap_z,overlap,dx,NAI_pol_mult - integer :: nucl_numC - ! Important for OpenMP + integer :: num_A,num_B + double precision :: A_center(3),B_center(3),C_center(3) + integer :: power_A(3),power_B(3) + integer :: i,j,k,l,n_pt_in,m + double precision ::overlap_x,overlap_y,overlap_z,overlap,dx,NAI_pol_mult - ao_nucl_elec_integral = 0.d0 + if (do_pseudo) then + ao_nucl_elec_integral = ao_nucl_elec_integral_pseudo + else + ao_nucl_elec_integral = 0.d0 + endif + ! _ + ! /| / |_) + ! | / | \ + ! - !$OMP PARALLEL & - !$OMP DEFAULT (NONE) & - !$OMP PRIVATE (i,j,k,l,m,alpha,beta,A_center,B_center,C_center,power_A,power_B, & - !$OMP num_A,num_B,Z,c,n_pt_in) & - !$OMP SHARED (ao_num,ao_prim_num,ao_expo_transp,ao_power,ao_nucl,nucl_coord,ao_coef_transp, & - !$OMP n_pt_max_integrals,ao_nucl_elec_integral,nucl_num,nucl_charge) - n_pt_in = n_pt_max_integrals - !$OMP DO SCHEDULE (guided) - do j = 1, ao_num - power_A(1)= ao_power(j,1) - power_A(2)= ao_power(j,2) - power_A(3)= ao_power(j,3) - num_A = ao_nucl(j) - A_center(1) = nucl_coord(num_A,1) - A_center(2) = nucl_coord(num_A,2) - A_center(3) = nucl_coord(num_A,3) - do i = 1, ao_num - power_B(1)= ao_power(i,1) - power_B(2)= ao_power(i,2) - power_B(3)= ao_power(i,3) - num_B = ao_nucl(i) - B_center(1) = nucl_coord(num_B,1) - B_center(2) = nucl_coord(num_B,2) - B_center(3) = nucl_coord(num_B,3) - do l=1,ao_prim_num(j) - alpha = ao_expo_transp(l,j) - do m=1,ao_prim_num(i) - beta = ao_expo_transp(m,i) - c = 0.d0 - do k = 1, nucl_num - double precision :: Z,c - Z = nucl_charge(k) - C_center(1) = nucl_coord(k,1) - C_center(2) = nucl_coord(k,2) - C_center(3) = nucl_coord(k,3) - c = c+Z*NAI_pol_mult(A_center,B_center,power_A,power_B,alpha,beta,C_center,n_pt_in) - enddo - ao_nucl_elec_integral(i,j) = ao_nucl_elec_integral(i,j) - & - ao_coef_transp(l,j)*ao_coef_transp(m,i)*c + !$OMP PARALLEL & + !$OMP DEFAULT (NONE) & + !$OMP PRIVATE (i,j,k,l,m,alpha,beta,A_center,B_center,C_center,power_A,power_B, & + !$OMP num_A,num_B,Z,c,n_pt_in) & + !$OMP SHARED (ao_num,ao_prim_num,ao_expo_ordered_transp,ao_power,ao_nucl,nucl_coord,ao_coef_normalized_ordered_transp, & + !$OMP n_pt_max_integrals,ao_nucl_elec_integral,nucl_num,nucl_charge) + + n_pt_in = n_pt_max_integrals + + !$OMP DO SCHEDULE (guided) + + do j = 1, ao_num + num_A = ao_nucl(j) + power_A(1:3)= ao_power(j,1:3) + A_center(1:3) = nucl_coord(num_A,1:3) + + do i = 1, ao_num + + num_B = ao_nucl(i) + power_B(1:3)= ao_power(i,1:3) + B_center(1:3) = nucl_coord(num_B,1:3) + + do l=1,ao_prim_num(j) + alpha = ao_expo_ordered_transp(l,j) + + do m=1,ao_prim_num(i) + beta = ao_expo_ordered_transp(m,i) + + double precision :: c + c = 0.d0 + + do k = 1, nucl_num + double precision :: Z + Z = nucl_charge(k) + + C_center(1:3) = nucl_coord(k,1:3) + + c = c - Z*NAI_pol_mult(A_center,B_center,power_A,power_B,alpha,beta,C_center,n_pt_in) + + enddo + ao_nucl_elec_integral(i,j) = ao_nucl_elec_integral(i,j) + & + ao_coef_normalized_ordered_transp(l,j)*ao_coef_normalized_ordered_transp(m,i)*c + enddo + enddo enddo - enddo enddo - enddo + !$OMP END DO !$OMP END PARALLEL -END_PROVIDER - + END_PROVIDER BEGIN_PROVIDER [ double precision, ao_nucl_elec_integral_per_atom, (ao_num_align,ao_num,nucl_num)] BEGIN_DOC @@ -76,7 +85,6 @@ END_PROVIDER integer :: power_A(3),power_B(3) integer :: i,j,k,l,n_pt_in,m double precision ::overlap_x,overlap_y,overlap_z,overlap,dx,NAI_pol_mult - integer :: nucl_numC ! Important for OpenMP ao_nucl_elec_integral_per_atom = 0.d0 @@ -90,7 +98,7 @@ END_PROVIDER !$OMP DEFAULT (NONE) & !$OMP PRIVATE (i,j,l,m,alpha,beta,A_center,B_center,power_A,power_B, & !$OMP num_A,num_B,c,n_pt_in) & - !$OMP SHARED (k,ao_num,ao_prim_num,ao_expo_transp,ao_power,ao_nucl,nucl_coord,ao_coef_transp, & + !$OMP SHARED (k,ao_num,ao_prim_num,ao_expo_ordered_transp,ao_power,ao_nucl,nucl_coord,ao_coef_normalized_ordered_transp, & !$OMP n_pt_max_integrals,ao_nucl_elec_integral_per_atom,nucl_num,C_center) n_pt_in = n_pt_max_integrals !$OMP DO SCHEDULE (guided) @@ -114,11 +122,11 @@ END_PROVIDER B_center(3) = nucl_coord(num_B,3) c = 0.d0 do l=1,ao_prim_num(j) - alpha = ao_expo_transp(l,j) + alpha = ao_expo_ordered_transp(l,j) do m=1,ao_prim_num(i) - beta = ao_expo_transp(m,i) + beta = ao_expo_ordered_transp(m,i) c = c + NAI_pol_mult(A_center,B_center,power_A,power_B,alpha,beta,C_center,n_pt_in) & - * ao_coef_transp(l,j)*ao_coef_transp(m,i) + * ao_coef_normalized_ordered_transp(l,j)*ao_coef_normalized_ordered_transp(m,i) enddo enddo ao_nucl_elec_integral_per_atom(i,j,k) = -c diff --git a/src/MonoInts/spread_dipole_ao.irp.f b/src/MonoInts/spread_dipole_ao.irp.f index c0d7c88e..d7aa738a 100644 --- a/src/MonoInts/spread_dipole_ao.irp.f +++ b/src/MonoInts/spread_dipole_ao.irp.f @@ -26,8 +26,8 @@ !$OMP overlap_x,overlap_y, overlap_z, overlap, & !$OMP alpha, beta,i,j,dx,tmp,c,accu_x,accu_y,accu_z) & !$OMP SHARED(nucl_coord,ao_power,ao_prim_num, & - !$OMP ao_spread_x,ao_spread_y,ao_spread_z,ao_num,ao_coef_transp,ao_nucl, & - !$OMP ao_expo_transp,dim1,lower_exp_val) + !$OMP ao_spread_x,ao_spread_y,ao_spread_z,ao_num,ao_coef_normalized_ordered_transp,ao_nucl, & + !$OMP ao_expo_ordered_transp,dim1,lower_exp_val) do j=1,ao_num A_center(1) = nucl_coord( ao_nucl(j), 1 ) A_center(2) = nucl_coord( ao_nucl(j), 2 ) @@ -48,11 +48,11 @@ accu_y = 0.d0 accu_z = 0.d0 do n = 1,ao_prim_num(j) - alpha = ao_expo_transp(n,j) + alpha = ao_expo_ordered_transp(n,j) !DEC$ VECTOR ALIGNED do l = 1, ao_prim_num(i) - c = ao_coef_transp(n,j)*ao_coef_transp(l,i) - beta = ao_expo_transp(l,i) + c = ao_coef_normalized_ordered_transp(n,j)*ao_coef_normalized_ordered_transp(l,i) + beta = ao_expo_ordered_transp(l,i) call overlap_gaussian_xyz(A_center,B_center,alpha,beta,power_A,power_B,overlap_x,overlap_y,overlap_z,overlap,dim1) call overlap_bourrin_spread(A_center(1),B_center(1),alpha,beta,power_A(1),power_B(1),tmp,lower_exp_val,dx,dim1) accu_x += c*(tmp*overlap_y*overlap_z) @@ -100,8 +100,8 @@ !$OMP overlap_x,overlap_y, overlap_z, overlap, & !$OMP alpha, beta,i,j,dx,tmp,c,accu_x,accu_y,accu_z) & !$OMP SHARED(nucl_coord,ao_power,ao_prim_num, & - !$OMP ao_dipole_x,ao_dipole_y,ao_dipole_z,ao_num,ao_coef_transp,ao_nucl, & - !$OMP ao_expo_transp,dim1,lower_exp_val) + !$OMP ao_dipole_x,ao_dipole_y,ao_dipole_z,ao_num,ao_coef_normalized_ordered_transp,ao_nucl, & + !$OMP ao_expo_ordered_transp,dim1,lower_exp_val) do j=1,ao_num A_center(1) = nucl_coord( ao_nucl(j), 1 ) A_center(2) = nucl_coord( ao_nucl(j), 2 ) @@ -122,11 +122,11 @@ accu_y = 0.d0 accu_z = 0.d0 do n = 1,ao_prim_num(j) - alpha = ao_expo_transp(n,j) + alpha = ao_expo_ordered_transp(n,j) !DEC$ VECTOR ALIGNED do l = 1, ao_prim_num(i) - beta = ao_expo_transp(l,i) - c = ao_coef_transp(l,i)*ao_coef_transp(n,j) + beta = ao_expo_ordered_transp(l,i) + c = ao_coef_normalized_ordered_transp(l,i)*ao_coef_normalized_ordered_transp(n,j) call overlap_gaussian_xyz(A_center,B_center,alpha,beta,power_A,power_B,overlap_x,overlap_y,overlap_z,overlap,dim1) call overlap_bourrin_dipole(A_center(1),B_center(1),alpha,beta,power_A(1),power_B(1),tmp,lower_exp_val,dx,dim1) @@ -174,8 +174,8 @@ !$OMP overlap_x,overlap_y, overlap_z, overlap, & !$OMP alpha, beta,i,j,dx,tmp,c,i_component,accu_x,accu_y,accu_z) & !$OMP SHARED(nucl_coord,ao_power,ao_prim_num, & - !$OMP ao_deriv_1_x,ao_deriv_1_y,ao_deriv_1_z,ao_num,ao_coef_transp,ao_nucl, & - !$OMP ao_expo_transp,dim1,lower_exp_val) + !$OMP ao_deriv_1_x,ao_deriv_1_y,ao_deriv_1_z,ao_num,ao_coef_normalized_ordered_transp,ao_nucl, & + !$OMP ao_expo_ordered_transp,dim1,lower_exp_val) do j=1,ao_num A_center(1) = nucl_coord( ao_nucl(j), 1 ) A_center(2) = nucl_coord( ao_nucl(j), 2 ) @@ -196,12 +196,12 @@ accu_y = 0.d0 accu_z = 0.d0 do n = 1,ao_prim_num(j) - alpha = ao_expo_transp(n,j) + alpha = ao_expo_ordered_transp(n,j) !DEC$ VECTOR ALIGNED do l = 1, ao_prim_num(i) - beta = ao_expo_transp(l,i) + beta = ao_expo_ordered_transp(l,i) call overlap_gaussian_xyz(A_center,B_center,alpha,beta,power_A,power_B,overlap_x,overlap_y,overlap_z,overlap,dim1) - c = ao_coef_transp(l,i) * ao_coef_transp(n,j) + c = ao_coef_normalized_ordered_transp(l,i) * ao_coef_normalized_ordered_transp(n,j) i_component = 1 call overlap_bourrin_deriv_x(i_component,A_center,B_center,alpha,beta,power_A,power_B,dx,lower_exp_val,tmp,dim1) accu_x += c*(tmp*overlap_y*overlap_z) diff --git a/src/NEEDED_MODULES b/src/NEEDED_MODULES index 80176c68..4533ccfe 100644 --- a/src/NEEDED_MODULES +++ b/src/NEEDED_MODULES @@ -1 +1 @@ -AOs Bielec_integrals Bitmask CID CID_SC2_selected CID_selected CIS CISD CISD_selected CISD_SC2_selected Determinants Electrons Ezfio_files Full_CI Generators_full Hartree_Fock MOGuess MonoInts MOs MP2 Nuclei Output Selectors_full Utils Molden FCIdump Generators_CAS CAS_SD DDCI_selected MRCC +AOs Bielec_integrals Bitmask CID CID_SC2_selected CID_selected CIS CISD CISD_selected CISD_SC2_selected Determinants Electrons Ezfio_files Full_CI Generators_full Hartree_Fock MOGuess MonoInts MOs MP2 Nuclei Output Selectors_full Utils Molden FCIdump Generators_CAS CAS_SD DDCI_selected MRCC Pseudo_integrals diff --git a/src/Nuclei/NEEDED_CHILDREN_MODULES b/src/Nuclei/NEEDED_CHILDREN_MODULES new file mode 100644 index 00000000..83260f86 --- /dev/null +++ b/src/Nuclei/NEEDED_CHILDREN_MODULES @@ -0,0 +1 @@ +Output diff --git a/src/Nuclei/NEEDED_MODULES b/src/Nuclei/NEEDED_MODULES deleted file mode 100644 index 516a2a11..00000000 --- a/src/Nuclei/NEEDED_MODULES +++ /dev/null @@ -1 +0,0 @@ -Ezfio_files Utils Output diff --git a/src/Nuclei/README.rst b/src/Nuclei/README.rst index b21d02ee..aaad706d 100644 --- a/src/Nuclei/README.rst +++ b/src/Nuclei/README.rst @@ -12,8 +12,6 @@ Needed Modules .. Do not edit this section. It was auto-generated from the .. NEEDED_MODULES file. -* `Ezfio_files `_ -* `Utils `_ * `Output `_ Documentation diff --git a/src/Output/NEEDED_CHILDREN_MODULES b/src/Output/NEEDED_CHILDREN_MODULES new file mode 100644 index 00000000..dcdb5f86 --- /dev/null +++ b/src/Output/NEEDED_CHILDREN_MODULES @@ -0,0 +1 @@ +Ezfio_files Utils diff --git a/src/Output/NEEDED_MODULES b/src/Output/NEEDED_MODULES deleted file mode 100644 index f684b5aa..00000000 --- a/src/Output/NEEDED_MODULES +++ /dev/null @@ -1 +0,0 @@ -Utils Ezfio_files diff --git a/src/Output/README.rst b/src/Output/README.rst index 7b510fc1..5fe93f50 100644 --- a/src/Output/README.rst +++ b/src/Output/README.rst @@ -31,8 +31,8 @@ Needed Modules .. Do not edit this section. It was auto-generated from the .. NEEDED_MODULES file. -* `Utils `_ * `Ezfio_files `_ +* `Utils `_ Documentation ============= diff --git a/src/Perturbation/NEEDED_CHILDREN_MODULES b/src/Perturbation/NEEDED_CHILDREN_MODULES new file mode 100644 index 00000000..e29a6721 --- /dev/null +++ b/src/Perturbation/NEEDED_CHILDREN_MODULES @@ -0,0 +1 @@ +Properties Hartree_Fock diff --git a/src/Perturbation/NEEDED_MODULES b/src/Perturbation/NEEDED_MODULES deleted file mode 100644 index 4e0f218e..00000000 --- a/src/Perturbation/NEEDED_MODULES +++ /dev/null @@ -1,2 +0,0 @@ -AOs Bielec_integrals Bitmask Determinants Electrons Ezfio_files Hartree_Fock MOGuess MonoInts MOs Nuclei Output Properties Utils - diff --git a/src/Perturbation/selection.irp.f b/src/Perturbation/selection.irp.f index 77313888..84cc59ae 100644 --- a/src/Perturbation/selection.irp.f +++ b/src/Perturbation/selection.irp.f @@ -19,6 +19,7 @@ subroutine fill_H_apply_buffer_selection(n_selected,det_buffer,e_2_pert_buffer,c ASSERT (Nint > 0) ASSERT (N_int == N_int) ASSERT (N_selected >= 0) + call omp_set_lock(H_apply_buffer_lock(1,iproc)) smax = selection_criterion smin = selection_criterion_min new_size = H_apply_buffer(iproc)%N_det + n_selected @@ -26,7 +27,6 @@ subroutine fill_H_apply_buffer_selection(n_selected,det_buffer,e_2_pert_buffer,c if (new_size > h_apply_buffer(iproc)%sze) then call resize_h_apply_buffer(max(h_apply_buffer(iproc)%sze*2,new_size),iproc) endif - call omp_set_lock(H_apply_buffer_lock(1,iproc)) do i=1,H_apply_buffer(iproc)%N_det ASSERT (sum(popcnt(h_apply_buffer(iproc)%det(:,1,i)) )== elec_alpha_num) ASSERT (sum(popcnt(h_apply_buffer(iproc)%det(:,2,i))) == elec_beta_num) diff --git a/src/Properties/NEEDED_CHILDREN_MODULES b/src/Properties/NEEDED_CHILDREN_MODULES new file mode 100644 index 00000000..aae89501 --- /dev/null +++ b/src/Properties/NEEDED_CHILDREN_MODULES @@ -0,0 +1 @@ +Determinants diff --git a/src/Properties/NEEDED_MODULES b/src/Properties/NEEDED_MODULES deleted file mode 100644 index 62dbbe42..00000000 --- a/src/Properties/NEEDED_MODULES +++ /dev/null @@ -1 +0,0 @@ -AOs Bielec_integrals Bitmask Determinants Electrons Ezfio_files MonoInts MOs Nuclei Output Utils diff --git a/src/Properties/delta_rho.irp.f b/src/Properties/delta_rho.irp.f index 3cfe136c..69894c38 100644 --- a/src/Properties/delta_rho.irp.f +++ b/src/Properties/delta_rho.irp.f @@ -79,7 +79,7 @@ BEGIN_PROVIDER [ double precision, ao_integrated_delta_rho_all_points, (ao_num_a !$OMP PARALLEL DO DEFAULT(none) & !$OMP PRIVATE(i,j,n,l,A_center,power_A,B_center,power_B,accu_z, & !$OMP overlap_x,overlap_y,overlap_z,overlap,c,alpha,beta) & - !$OMP SHARED(ao_num,nucl_coord,ao_nucl,ao_power,ao_prim_num,ao_expo_transp,ao_coef_transp, & + !$OMP SHARED(ao_num,nucl_coord,ao_nucl,ao_power,ao_prim_num,ao_expo_ordered_transp,ao_coef_normalized_ordered_transp, & !$OMP ao_integrated_delta_rho_all_points,N_z_pts,dim1,i_z,z,delta_z) do j=1,ao_num A_center(1) = nucl_coord( ao_nucl(j), 1 ) @@ -98,12 +98,12 @@ BEGIN_PROVIDER [ double precision, ao_integrated_delta_rho_all_points, (ao_num_a accu_z = 0.d0 do n = 1,ao_prim_num(j) - alpha = ao_expo_transp(n,j) + alpha = ao_expo_ordered_transp(n,j) do l = 1, ao_prim_num(i) - beta = ao_expo_transp(l,i) + beta = ao_expo_ordered_transp(l,i) call overlap_gaussian_xyz(A_center,B_center,alpha,beta,power_A,power_B,overlap_x,overlap_y,overlap_z,overlap,dim1) - c = ao_coef_transp(n,j) * ao_coef_transp(l,i) + c = ao_coef_normalized_ordered_transp(n,j) * ao_coef_normalized_ordered_transp(l,i) accu_z += c* overlap_x * overlap_y * SABpartial(z,z+delta_z,A_center,B_center,power_A,power_B,alpha,beta) enddo enddo @@ -147,7 +147,7 @@ BEGIN_PROVIDER [ double precision, ao_integrated_delta_rho_one_point, (ao_num_al !$OMP PARALLEL DO DEFAULT(none) & !$OMP PRIVATE(i,j,n,l,A_center,power_A,B_center,power_B,accu_z, & !$OMP overlap_x,overlap_y,overlap_z,overlap,c,alpha,beta) & - !$OMP SHARED(ao_num,nucl_coord,ao_nucl,ao_power,ao_prim_num,ao_expo_transp,ao_coef_transp, & + !$OMP SHARED(ao_num,nucl_coord,ao_nucl,ao_power,ao_prim_num,ao_expo_ordered_transp,ao_coef_normalized_ordered_transp, & !$OMP ao_integrated_delta_rho_one_point,dim1,z,delta_z) do j=1,ao_num A_center(1) = nucl_coord( ao_nucl(j), 1 ) @@ -166,12 +166,12 @@ BEGIN_PROVIDER [ double precision, ao_integrated_delta_rho_one_point, (ao_num_al accu_z = 0.d0 do n = 1,ao_prim_num(j) - alpha = ao_expo_transp(n,j) + alpha = ao_expo_ordered_transp(n,j) do l = 1, ao_prim_num(i) - beta = ao_expo_transp(l,i) + beta = ao_expo_ordered_transp(l,i) call overlap_gaussian_xyz(A_center,B_center,alpha,beta,power_A,power_B,overlap_x,overlap_y,overlap_z,overlap,dim1) - c = ao_coef_transp(n,j) * ao_coef_transp(l,i) + c = ao_coef_normalized_ordered_transp(n,j) * ao_coef_normalized_ordered_transp(l,i) accu_z += c* overlap_x * overlap_y * SABpartial(z,z+delta_z,A_center,B_center,power_A,power_B,alpha,beta) enddo enddo diff --git a/src/Ezfio_files/NEEDED_MODULES b/src/Pseudo_integrals/ASSUMPTIONS.rst similarity index 100% rename from src/Ezfio_files/NEEDED_MODULES rename to src/Pseudo_integrals/ASSUMPTIONS.rst diff --git a/src/Pseudo_integrals/EZFIO.cfg b/src/Pseudo_integrals/EZFIO.cfg new file mode 100644 index 00000000..f56bc325 --- /dev/null +++ b/src/Pseudo_integrals/EZFIO.cfg @@ -0,0 +1,5 @@ +[do_pseudo] +type: logical +doc: Using pseudo potential integral of not +interface: input +default: False \ No newline at end of file diff --git a/src/Pseudo_integrals/Makefile b/src/Pseudo_integrals/Makefile new file mode 100644 index 00000000..5cf11b78 --- /dev/null +++ b/src/Pseudo_integrals/Makefile @@ -0,0 +1,6 @@ +# Define here all new external source files and objects.Don't forget to prefix the +# object files with IRPF90_temp/ +SRC=int.f90 +OBJ=IRPF90_temp/int.o + +include $(QPACKAGE_ROOT)/src/Makefile.common diff --git a/src/Pseudo_integrals/NEEDED_CHILDREN_MODULES b/src/Pseudo_integrals/NEEDED_CHILDREN_MODULES new file mode 100644 index 00000000..88c6f86b --- /dev/null +++ b/src/Pseudo_integrals/NEEDED_CHILDREN_MODULES @@ -0,0 +1 @@ +AOs Electrons diff --git a/src/Pseudo_integrals/README.rst b/src/Pseudo_integrals/README.rst new file mode 100644 index 00000000..08076556 --- /dev/null +++ b/src/Pseudo_integrals/README.rst @@ -0,0 +1,24 @@ +======================= +Pseudo_integrals Module +======================= + +Documentation +============= + +.. Do not edit this section. It was auto-generated from the +.. NEEDED_MODULES file. + +`ao_nucl_elec_integral_pseudo `_ + interaction nuclear electron + + + +Needed Modules +============== + +.. Do not edit this section. It was auto-generated from the +.. NEEDED_MODULES file. + +* `AOs `_ +* `Electrons `_ + diff --git a/src/Pseudo_integrals/int.f90 b/src/Pseudo_integrals/int.f90 new file mode 100644 index 00000000..4eb9d2ae --- /dev/null +++ b/src/Pseudo_integrals/int.f90 @@ -0,0 +1,2090 @@ +!! INFO : You can display equations using : http://www.codecogs.com/latex/eqneditor.php + +!! +!! {\tt Vps}(C) = \langle \Phi_A|{\tt Vloc}(C)+{\tt Vpp}(C)| \Phi_B \rangle +!! +!! with : +!! +!! {\tt Vloc}(C)=\sum_{k=1}^{\tt klocmax} v_k r_C^{n_k} \exp(-dz_k r_C^2) \\ +!! +!! {\tt Vpp}(C)=\sum_{l=0}^{\tt lmax}\left( \sum_{k=1}^{\tt kmax} v_{kl} +!! r_C^{n_{kl}} \exp(-dz_{kl} r_C)^2 \right) |l\rangle \langle l| +!! +double precision function Vps & +(a,n_a,g_a,b,n_b,g_b,c,klocmax,v_k,n_k,dz_k,lmax,kmax,v_kl,n_kl,dz_kl) +implicit none +integer n_a(3),n_b(3) +double precision g_a,g_b,a(3),b(3),c(3) +integer kmax_max,lmax_max +parameter (kmax_max=2,lmax_max=2) +integer lmax,kmax,n_kl(kmax_max,0:lmax_max) +double precision v_kl(kmax_max,0:lmax_max),dz_kl(kmax_max,0:lmax_max) +integer klocmax_max +parameter (klocmax_max=10) +integer klocmax,n_k(klocmax_max) +double precision v_k(klocmax_max),dz_k(klocmax_max) +double precision Vloc,Vpseudo + +Vps=Vloc(klocmax,v_k,n_k,dz_k,a,n_a,g_a,b,n_b,g_b,c) & + +Vpseudo(lmax,kmax,v_kl,n_kl,dz_kl,a,n_a,g_a,b,n_b,g_b,c) +end +!! +!! Vps_num: brute force numerical evaluation of the same matrix element Vps +!! +double precision function Vps_num & +(npts,rmax,a,n_a,g_a,b,n_b,g_b,c,klocmax,v_k,n_k,dz_k,lmax,kmax,v_kl,n_kl,dz_kl) +implicit none +integer n_a(3),n_b(3) +double precision g_a,g_b,a(3),b(3),c(3),rmax +integer kmax_max,lmax_max +parameter (kmax_max=2,lmax_max=2) +integer lmax,kmax,n_kl(kmax_max,0:lmax_max) +double precision v_kl(kmax_max,0:lmax_max),dz_kl(kmax_max,0:lmax_max) +integer klocmax_max;parameter (klocmax_max=10) +integer klocmax,n_k(klocmax_max) +double precision v_k(klocmax_max),dz_k(klocmax_max) +double precision Vloc_num,Vpseudo_num,v1,v2 +integer npts,nptsgrid +nptsgrid=50 +call initpseudos(nptsgrid) +v1=Vloc_num(npts,rmax,klocmax,v_k,n_k,dz_k,a,n_a,g_a,b,n_b,g_b,c) +v2=Vpseudo_num(nptsgrid,rmax,lmax,kmax,v_kl,n_kl,dz_kl,a,n_a,g_a,b,n_b,g_b,c) +Vps_num=v1+v2 +end + +double precision function Vloc_num(npts_over,xmax,klocmax,v_k,n_k,dz_k,a,n_a,g_a,b,n_b,g_b,c) +implicit none +integer klocmax_max +parameter (klocmax_max=10) +integer klocmax +double precision v_k(klocmax_max),dz_k(klocmax_max) +integer n_k(klocmax_max) +integer npts_over,ix,iy,iz +double precision xmax,dx,x,y,z +double precision a(3),b(3),c(3),term,r,orb_phi,g_a,g_b,ac(3),bc(3) +integer n_a(3),n_b(3),k,l +do l=1,3 + ac(l)=a(l)-c(l) + bc(l)=b(l)-c(l) +enddo +dx=2.d0*xmax/npts_over +Vloc_num=0.d0 +do ix=1,npts_over +do iy=1,npts_over +do iz=1,npts_over + x=-xmax+dx*ix+dx/2.d0 + y=-xmax+dx*iy+dx/2.d0 + z=-xmax+dx*iz+dx/2.d0 + term=orb_phi(x,y,z,n_a,ac,g_a)*orb_phi(x,y,z,n_b,bc,g_b) + r=dsqrt(x**2+y**2+z**2) + do k=1,klocmax + Vloc_num=Vloc_num+dx**3*v_k(k)*r**n_k(k)*dexp(-dz_k(k)*r**2)*term + enddo +enddo +enddo +enddo +end + +double precision function orb_phi(x,y,z,npower,center,gamma) +implicit none +integer npower(3) +double precision x,y,z,r2,gamma,center(3) +r2=(x-center(1))**2+(y-center(2))**2+(z-center(3))**2 +orb_phi=(x-center(1))**npower(1)*(y-center(2))**npower(2)*(z-center(3))**npower(3) +orb_phi=orb_phi*dexp(-gamma*r2) +end + +!! Real spherical harmonics Ylm + +! factor = ([(2l+1)*(l-|m|)!]/[4pi*(l+|m|)!])^1/2 +! Y_lm(theta,phi) = +! m > 0 factor* P_l^|m|(cos(theta)) cos (|m| phi) +! m = 0 1/sqrt(2) *factor* P_l^0(cos(theta)) +! m < 0 factor* P_l^|m|(cos(theta)) sin (|m| phi) +! +! x=cos(theta) + + double precision function ylm_real(l,m,x,phi) + implicit double precision (a-h,o-z) + DIMENSION PM(0:100,0:100) + MM=100 + pi=dacos(-1.d0) + iabs_m=iabs(m) + if(iabs_m.gt.l)stop 'm must be between -l and l' + factor= dsqrt( ((2*l+1)*fact(l-iabs_m))/(4.d0*pi*fact(l+iabs_m)) ) + if(dabs(x).gt.1.d0)then + print*,'pb. in ylm_no' + print*,'x=',x + stop + endif + call LPMN(MM,l,l,X,PM) + plm=PM(iabs_m,l) + coef=factor*plm + if(m.gt.0)ylm_real=dsqrt(2.d0)*coef*dcos(iabs_m*phi) + if(m.eq.0)ylm_real=coef + if(m.lt.0)ylm_real=dsqrt(2.d0)*coef*dsin(iabs_m*phi) + + fourpi=4.d0*dacos(-1.d0) + if(l.eq.0)ylm_real=dsqrt(1.d0/fourpi) + + xchap=dsqrt(1.d0-x**2)*dcos(phi) + ychap=dsqrt(1.d0-x**2)*dsin(phi) + zchap=x + if(l.eq.1.and.m.eq.1)ylm_real=dsqrt(3.d0/fourpi)*xchap + if(l.eq.1.and.m.eq.0)ylm_real=dsqrt(3.d0/fourpi)*zchap + if(l.eq.1.and.m.eq.-1)ylm_real=dsqrt(3.d0/fourpi)*ychap + + if(l.eq.2.and.m.eq.2)ylm_real=dsqrt(15.d0/16.d0/pi)*(xchap**2-ychap**2) + if(l.eq.2.and.m.eq.1)ylm_real=dsqrt(15.d0/fourpi)*xchap*zchap + if(l.eq.2.and.m.eq.0)ylm_real=dsqrt(5.d0/16.d0/pi)*(-xchap**2-ychap**2+2.d0*zchap**2) + if(l.eq.2.and.m.eq.-1)ylm_real=dsqrt(15.d0/fourpi)*ychap*zchap + if(l.eq.2.and.m.eq.-2)ylm_real=dsqrt(15.d0/fourpi)*xchap*ychap + + if(l.gt.2)stop 'l > 2 not coded!' + + end +! _ +! | | +! __ __ _ __ ___ ___ _ _ __| | ___ +! \ \ / / | '_ \/ __|/ _ \ | | |/ _` |/ _ \ +! \ V / | |_) \__ \ __/ |_| | (_| | (_) | +! \_/ | .__/|___/\___|\__,_|\____|\___/ +! | | +! |_| + +!! Routine Vpseudo is based on formumla (66) +!! of Kahn Baybutt TRuhlar J.Chem.Phys. vol.65 3826 (1976): +!! +!! Vpseudo= (4pi)**2* \sum_{l=0}^lmax \sum_{m=-l}^{l} +!! \sum{lambda=0}^{l+nA} \sum_{mu=-lambda}^{lambda} +!! \sum{k1=0}^{nAx} \sum{k2=0}^{nAy} \sum{k3=0}^{nAz} +!! binom(nAx,k1)*binom(nAy,k2)*binom(nAz,k3)* Y_{lambda mu}(AC_unit) +!! *CAx**(nAx-k1)*CAy**(nAy-k2)*CAz**(nAz-k3)* +!! bigI(lambda,mu,l,m,k1,k2,k3) +!! \sum{lambdap=0}^{l+nB} \sum_{mup=-lambdap}^{lambdap} +!! \sum{k1p=0}^{nBx} \sum{k2p=0}^{nBy} \sum{k3p=0}^{nBz} +!! binom(nBx,k1p)*binom(nBy,k2p)*binom(nBz,k3p)* Y_{lambdap mup}(BC_unit) +!! *CBx**(nBx-k1p)*CBy**(nBy-k2p)*CBz**(nBz-k3p)* +!! bigI(lambdap,mup,l,m,k1p,k2p,k3p)* +!! \sum_{k=1}^{kmax} v_kl(k,l)* +!! bigR(lambda,lambdap,k1+k2+k3+k1p+k2p+k3p+n_kl(k,l),g_a,g_b,AC,BC,dz_kl(k,l)) +!! +!! nA=nAx+nAy+nAz +!! nB=nBx+nBy+nBz +!! AC=|A-C| +!! AC_x= A_x-C_x, etc. +!! BC=|B-C| +!! AC_unit= vect(AC)/AC +!! BC_unit= vect(BC)/BC +!! bigI(lambda,mu,l,m,k1,k2,k3)= +!! \int dOmega Y_{lambda mu}(Omega) xchap^k1 ychap^k2 zchap^k3 Y_{l m}(Omega) +!! +!! bigR(lambda,lambdap,N,g_a,g_b,gamm_k,AC,BC) +!! = exp(-g_a* AC**2 -g_b* BC**2) * int_prod_bessel_loc(ktot+2,g_a+g_b+dz_k(k),l,dreal) +!! /int dx x^{ktot} exp(-g_k)*x**2) M_lambda(2 g_k D x) + +double precision function Vpseudo & +(lmax,kmax,v_kl,n_kl,dz_kl,a,n_a,g_a,b,n_b,g_b,c) +implicit none + +! ___ +! | ._ ._ _|_ +! _|_ | | |_) |_| |_ +! | +double precision, intent(in) :: a(3),g_a,b(3),g_b,c(3) +integer, intent(in) :: lmax,kmax,n_kl(kmax,0:lmax) +integer, intent(in) :: n_a(3),n_b(3) +double precision, intent(in) :: v_kl(kmax,0:lmax),dz_kl(kmax,0:lmax) + +! +! | _ _ _. | _ +! |_ (_) (_ (_| | (/_ +! + +double precision :: fourpi,f,prod,prodp,binom,accu,bigR,bigI,ylm +double precision :: theta_AC0,phi_AC0,theta_BC0,phi_BC0,ac,bc,big +double precision :: areal,freal,breal,t1,t2,int_prod_bessel +double precision :: arg + +integer :: ntot,ntotA,m,mu,mup,k1,k2,k3,ntotB,k1p,k2p,k3p,lambda,lambdap,ktot +integer :: l,k, nkl_max + +! _ +! |_) o _ _. ._ ._ _. +! |_) | (_| (_| | | (_| \/ +! _| / + +double precision, allocatable :: array_coefs_A(:,:,:) +double precision, allocatable :: array_coefs_B(:,:,:) + +double precision, allocatable :: array_R(:,:,:,:,:) +double precision, allocatable :: array_I_A(:,:,:,:,:) +double precision, allocatable :: array_I_B(:,:,:,:,:) + + +! _ +! / _. | _ | +! \_ (_| | (_ |_| | +! + +if (kmax.eq.1.and.lmax.eq.0.and.v_kl(1,0).eq.0.d0) then + Vpseudo=0.d0 + return +end if + +fourpi=4.d0*dacos(-1.d0) +ac=dsqrt((a(1)-c(1))**2+(a(2)-c(2))**2+(a(3)-c(3))**2) +bc=dsqrt((b(1)-c(1))**2+(b(2)-c(2))**2+(b(3)-c(3))**2) +arg=g_a*ac**2+g_b*bc**2 + +if(arg.gt.-dlog(1.d-20))then + Vpseudo=0.d0 + return +endif + +freal=dexp(-arg) + +areal=2.d0*g_a*ac +breal=2.d0*g_b*bc +ntotA=n_a(1)+n_a(2)+n_a(3) +ntotB=n_b(1)+n_b(2)+n_b(3) +ntot=ntotA+ntotB + +nkl_max=4 +!=!=!=!=!=!=!=!=!=! +! A l l o c a t e ! +!=!=!=!=!=!=!=!=!=! + +allocate (array_coefs_A(0:ntot,0:ntot,0:ntot)) +allocate (array_coefs_B(0:ntot,0:ntot,0:ntot)) + +allocate (array_R(0:ntot+nkl_max,kmax,0:lmax,0:lmax+ntot,0:lmax+ntot)) + +allocate (array_I_A(0:lmax+ntot,-(lmax+ntot):lmax+ntot,0:ntot,0:ntot,0:ntot)) + +allocate (array_I_B(0:lmax+ntot,-(lmax+ntot):lmax+ntot,0:ntot,0:ntot,0:ntot)) + +if(ac.eq.0.d0.and.bc.eq.0.d0)then + + + !=!=!=!=!=! + ! I n i t ! + !=!=!=!=!=! + + accu=0.d0 + + !=!=!=!=!=!=!=! + ! c a l c u l ! + !=!=!=!=!=!=!=! + + do k=1,kmax + do l=0,lmax + ktot=ntot+n_kl(k,l) + do m=-l,l + prod=bigI(0,0,l,m,n_a(1),n_a(2),n_a(3)) + prodp=bigI(0,0,l,m,n_b(1),n_b(2),n_b(3)) + + accu=accu+prod*prodp*v_kl(k,l)*int_prod_bessel(ktot+2,g_a+g_b+dz_kl(k,l),0,0,areal,breal,arg) + + enddo + enddo + enddo + + !=!=!=!=! + ! E n d ! + !=!=!=!=! + + Vpseudo=accu*fourpi + +else if(ac.ne.0.d0.and.bc.ne.0.d0)then + + !=!=!=!=!=! + ! I n i t ! + !=!=!=!=!=! + + f=fourpi**2 + + theta_AC0=dacos( (a(3)-c(3))/ac ) + phi_AC0=datan2((a(2)-c(2))/ac,(a(1)-c(1))/ac) + theta_BC0=dacos( (b(3)-c(3))/bc ) + phi_BC0=datan2((b(2)-c(2))/bc,(b(1)-c(1))/bc) + + + + + do ktot=0,ntotA+ntotB+nkl_max + do lambda=0,lmax+ntotA + do lambdap=0,lmax+ntotB + do k=1,kmax + do l=0,lmax + array_R(ktot,k,l,lambda,lambdap)= int_prod_bessel(ktot+2,g_a+g_b+dz_kl(k,l),lambda,lambdap,areal,breal,arg) + enddo + enddo + enddo + enddo + enddo + + do k1=0,n_a(1) + do k2=0,n_a(2) + do k3=0,n_a(3) + array_coefs_A(k1,k2,k3)=binom(n_a(1),k1)*binom(n_a(2),k2)*binom(n_a(3),k3) & + *(c(1)-a(1))**(n_a(1)-k1)*(c(2)-a(2))**(n_a(2)-k2)*(c(3)-a(3))**(n_a(3)-k3) + enddo + enddo + enddo + + do k1p=0,n_b(1) + do k2p=0,n_b(2) + do k3p=0,n_b(3) + array_coefs_B(k1p,k2p,k3p)=binom(n_b(1),k1p)*binom(n_b(2),k2p)*binom(n_b(3),k3p) & + *(c(1)-b(1))**(n_b(1)-k1p)*(c(2)-b(2))**(n_b(2)-k2p)*(c(3)-b(3))**(n_b(3)-k3p) + enddo + enddo + enddo + + !=!=!=!=!=!=!=! + ! c a l c u l ! + !=!=!=!=!=!=!=! + + accu=0.d0 + do l=0,lmax + do m=-l,l + + do lambda=0,l+ntotA + do mu=-lambda,lambda + do k1=0,n_a(1) + do k2=0,n_a(2) + do k3=0,n_a(3) + array_I_A(lambda,mu,k1,k2,k3)=bigI(lambda,mu,l,m,k1,k2,k3) + enddo + enddo + enddo + enddo + enddo + + do lambdap=0,l+ntotB + do mup=-lambdap,lambdap + do k1p=0,n_b(1) + do k2p=0,n_b(2) + do k3p=0,n_b(3) + array_I_B(lambdap,mup,k1p,k2p,k3p)=bigI(lambdap,mup,l,m,k1p,k2p,k3p) + enddo + enddo + enddo + enddo + enddo + + do lambda=0,l+ntotA + do mu=-lambda,lambda + + do k1=0,n_a(1) + do k2=0,n_a(2) + do k3=0,n_a(3) + + prod=ylm(lambda,mu,theta_AC0,phi_AC0)*array_coefs_A(k1,k2,k3)*array_I_A(lambda,mu,k1,k2,k3) + + do lambdap=0,l+ntotB + do mup=-lambdap,lambdap + + do k1p=0,n_b(1) + do k2p=0,n_b(2) + do k3p=0,n_b(3) + + prodp=ylm(lambdap,mup,theta_BC0,phi_BC0)*array_coefs_B(k1p,k2p,k3p)*array_I_B(lambdap,mup,k1p,k2p,k3p) + + do k=1,kmax + ktot=k1+k2+k3+k1p+k2p+k3p+n_kl(k,l) + accu=accu+prod*prodp*v_kl(k,l)*array_R(ktot,k,l,lambda,lambdap) + enddo + + enddo + enddo + enddo + + enddo + enddo + + enddo + enddo + enddo + + enddo + enddo + + enddo + enddo + + !=!=!=!=! + ! E n d ! + !=!=!=!=! + + Vpseudo=f*accu + +else if(ac.eq.0.d0.and.bc.ne.0.d0)then + + !=!=!=!=!=! + ! I n i t ! + !=!=!=!=!=! + + f=fourpi**1.5d0 + theta_BC0=dacos( (b(3)-c(3))/bc ) + phi_BC0=datan2((b(2)-c(2))/bc,(b(1)-c(1))/bc) + + areal=2.d0*g_a*ac + breal=2.d0*g_b*bc + freal=dexp(-g_a*ac**2-g_b*bc**2) + + do ktot=0,ntotA+ntotB+nkl_max + do lambdap=0,lmax+ntotB + do k=1,kmax + do l=0,lmax + array_R(ktot,k,l,0,lambdap)= int_prod_bessel(ktot+2,g_a+g_b+dz_kl(k,l),0,lambdap,areal,breal,arg) + enddo + enddo + enddo + enddo + + do k1p=0,n_b(1) + do k2p=0,n_b(2) + do k3p=0,n_b(3) + + array_coefs_B(k1p,k2p,k3p)=binom(n_b(1),k1p)*binom(n_b(2),k2p)*binom(n_b(3),k3p) & + *(c(1)-b(1))**(n_b(1)-k1p)*(c(2)-b(2))**(n_b(2)-k2p)*(c(3)-b(3))**(n_b(3)-k3p) + enddo + enddo + enddo + + !=!=!=!=!=!=!=! + ! c a l c u l ! + !=!=!=!=!=!=!=! + + accu=0.d0 + do l=0,lmax + do m=-l,l + + do lambdap=0,l+ntotB + do mup=-lambdap,lambdap + do k1p=0,n_b(1) + do k2p=0,n_b(2) + do k3p=0,n_b(3) + array_I_B(lambdap,mup,k1p,k2p,k3p)=bigI(lambdap,mup,l,m,k1p,k2p,k3p) + enddo + enddo + enddo + enddo + enddo + + prod=bigI(0,0,l,m,n_a(1),n_a(2),n_a(3)) + + do lambdap=0,l+ntotB + do mup=-lambdap,lambdap + do k1p=0,n_b(1) + do k2p=0,n_b(2) + do k3p=0,n_b(3) + + prodp=array_coefs_B(k1p,k2p,k3p)*ylm(lambdap,mup,theta_BC0,phi_BC0)*array_I_B(lambdap,mup,k1p,k2p,k3p) + + do k=1,kmax + + ktot=ntotA+k1p+k2p+k3p+n_kl(k,l) + accu=accu+prod*prodp*v_kl(k,l)*array_R(ktot,k,l,0,lambdap) + + enddo + + enddo + enddo + enddo + enddo + enddo + enddo + enddo + + !=!=!=!=! + ! E n d ! + !=!=!=!=! + + Vpseudo=f*accu + +else if(ac.ne.0.d0.and.bc.eq.0.d0)then + + !=!=!=!=!=! + ! I n i t ! + !=!=!=!=!=! + + f=fourpi**1.5d0 + theta_AC0=dacos( (a(3)-c(3))/ac ) + phi_AC0=datan2((a(2)-c(2))/ac,(a(1)-c(1))/ac) + + areal=2.d0*g_a*ac + breal=2.d0*g_b*bc + freal=dexp(-g_a*ac**2-g_b*bc**2) + + do ktot=0,ntotA+ntotB+nkl_max + do lambda=0,lmax+ntotA + do k=1,kmax + do l=0,lmax + + array_R(ktot,k,l,lambda,0)= int_prod_bessel(ktot+2,g_a+g_b+dz_kl(k,l),lambda,0,areal,breal,arg) + enddo + enddo + enddo + enddo + + do k1=0,n_a(1) + do k2=0,n_a(2) + do k3=0,n_a(3) + + array_coefs_A(k1,k2,k3)=binom(n_a(1),k1)*binom(n_a(2),k2)*binom(n_a(3),k3) & + *(c(1)-a(1))**(n_a(1)-k1)*(c(2)-a(2))**(n_a(2)-k2)*(c(3)-a(3))**(n_a(3)-k3) + + enddo + enddo + enddo + + !=!=!=!=!=!=!=! + ! c a l c u l ! + !=!=!=!=!=!=!=! + + accu=0.d0 + do l=0,lmax + do m=-l,l + + do lambda=0,l+ntotA + do mu=-lambda,lambda + do k1=0,n_a(1) + do k2=0,n_a(2) + do k3=0,n_a(3) + array_I_A(lambda,mu,k1,k2,k3)=bigI(lambda,mu,l,m,k1,k2,k3) + enddo + enddo + enddo + enddo + enddo + + do lambda=0,l+ntotA + do mu=-lambda,lambda + do k1=0,n_a(1) + do k2=0,n_a(2) + do k3=0,n_a(3) + + prod=array_coefs_A(k1,k2,k3)*ylm(lambda,mu,theta_AC0,phi_AC0)*array_I_A(lambda,mu,k1,k2,k3) + prodp=bigI(0,0,l,m,n_b(1),n_b(2),n_b(3)) + + do k=1,kmax + ktot=k1+k2+k3+ntotB+n_kl(k,l) + accu=accu+prod*prodp*v_kl(k,l)*array_R(ktot,k,l,lambda,0) + enddo + + enddo + enddo + enddo + enddo + enddo + + enddo + enddo + + !=!=!=!=! + ! E n d ! + !=!=!=!=! + + Vpseudo=f*accu +endif + +! _ +! |_ o ._ _. | o _ _ +! | | | | (_| | | _> (/_ +! + deallocate (array_R, array_I_A, array_I_B) + deallocate (array_coefs_A, array_coefs_B) + return +end + +! _ +! | | +!__ __ _ __ ___ ___ _ _ __| | ___ _ __ _ _ _ __ ___ +!\ \ / / | '_ \/ __|/ _ \ | | |/ _` |/ _ \ | '_ \| | | | '_ ` _ \ +! \ V / | |_) \__ \ __/ |_| | (_| | (_) | | | | | |_| | | | | | | +! \_/ | .__/|___/\___|\__,_|\__,_|\___/ |_| |_|\__,_|_| |_| |_| +! | | +! |_| + +double precision function Vpseudo_num(npts,rmax,lmax,kmax,v_kl,n_kl,dz_kl,a,n_a,g_a,b,n_b,g_b,c) +implicit none + + +! ___ +! | ._ ._ _|_ +! _|_ | | |_) |_| |_ +! | +double precision, intent(in) :: a(3),g_a,b(3),g_b,c(3) +integer, intent(in) :: lmax,kmax,npts +integer, intent(in) :: n_a(3),n_b(3), n_kl(kmax,0:lmax) +double precision, intent(in) :: v_kl(kmax,0:lmax),dz_kl(kmax,0:lmax) +double precision, intent(in) :: rmax + +! +! | _ _ _. | _ +! |_ (_) (_ (_| | (/_ +! + +integer :: l,m,k,kk +double precision ac(3),bc(3) +double precision dr,sum,rC +double precision overlap_orb_ylm_brute + +! _ +! / _. | _ | +! \_ (_| | (_ |_| | +! + +do l=1,3 + ac(l)=a(l)-c(l) + bc(l)=b(l)-c(l) +enddo + +dr=rmax/npts +sum=0.d0 +do l=0,lmax + do m=-l,l + do k=1,npts + rC=(k-1)*dr+dr/2.d0 + do kk=1,kmax + sum=sum+dr*v_kl(kk,l)*rC**(n_kl(kk,l)+2)*dexp(-dz_kl(kk,l)*rC**2) & + *overlap_orb_ylm_brute(npts,rC,n_a,ac,g_a,l,m) & + *overlap_orb_ylm_brute(npts,rC,n_b,bc,g_b,l,m) + enddo + enddo + enddo +enddo +Vpseudo_num=sum +return +end +!! Routine Vloc is a variation of formumla (66) +!! of Kahn Baybutt TRuhlar J.Chem.Phys. vol.65 3826 (1976) +!! without the projection operator +!! +!! Vloc= (4pi)**3/2* \sum_{k=1}^{klocmax} \sum_{l=0}^lmax \sum_{m=-l}^{l} +!!\sum{k1=0}^{nAx} \sum{k2=0}^{nAy} \sum{k3=0}^{nAz} +!! binom(nAx,k1)*binom(nAy,k2)*binom(nAz,k3) +!! *CAx**(nAx-k1)*CAy**(nAy-k2)*CAz**(nAz-k3)* +!! \sum{k1p=0}^{nBx} \sum{k2p=0}^{nBy} \sum{k3p=0}^{nBz} +!! binom(nBx,k1p)*binom(nBy,k2p)*binom(nBz,k3p) +!! *CBx**(nBx-k1p)*CBy**(nBy-k2p)*CBz**(nBz-k3p)* +!!\sum_{l=0}^lmax \sum_{m=-l}^{l} + +!! bigI(0,0,l,m,k1+k1p,k2+k2p,k3+k3p)*Y_{l m}(D_unit) +!! *v_k(k)* bigR(lambda,k1+k2+k3+k1p+k2p+k3p+n_k(k),g_a,g_b,AC,BC,dz_k(k)) +!! +!! nA=nAx+nAy+nAz +!! nB=nBx+nBy+nBz +!! D=(g_a AC+g_b BC) +!! D_unit= vect(D)/D +!! AC_x= A_x-C_x, etc. +!! BC=|B-C| +!! AC_unit= vect(AC)/AC +!! BC_unit= vect(BC)/BCA +!! +!! bigR(lambda,g_a,g_b,g_k,AC,BC) +!! = exp(-g_a* AC**2 -g_b* BC**2)* +!! I_loc= \int dx x**l *exp(-gam*x**2) M_n(ax) l=ktot+2 gam=g_a+g_b+dz_k(k) a=dreal n=l +!! M_n(x) modified spherical bessel function + + +double precision function Vloc(klocmax,v_k,n_k,dz_k,a,n_a,g_a,b,n_b,g_b,c) +implicit none +integer klocmax_max,lmax_max,ntot_max +parameter (klocmax_max=10,lmax_max=2) +parameter (ntot_max=10) +integer klocmax +double precision v_k(klocmax_max),dz_k(klocmax_max),crochet,bigA +integer n_k(klocmax_max) +double precision a(3),g_a,b(3),g_b,c(3),d(3) +integer n_a(3),n_b(3),ntotA,ntotB,ntot,m +integer i,l,k,ktot,k1,k2,k3,k1p,k2p,k3p +double precision f,fourpi,ac,bc,freal,d2,dreal,theta_DC0,phi_DC0 +double precision,allocatable :: array_R_loc(:,:,:) +double precision,allocatable :: array_coefs(:,:,:,:,:,:) +double precision int_prod_bessel_loc,binom,accu,prod,ylm,bigI,arg + + fourpi=4.d0*dacos(-1.d0) + f=fourpi**1.5d0 + ac=dsqrt((a(1)-c(1))**2+(a(2)-c(2))**2+(a(3)-c(3))**2) + bc=dsqrt((b(1)-c(1))**2+(b(2)-c(2))**2+(b(3)-c(3))**2) + arg=g_a*ac**2+g_b*bc**2 + if(arg.gt.-dlog(10.d-20))then + Vloc=0.d0 + return + endif + + ntotA=n_a(1)+n_a(2)+n_a(3) + ntotB=n_b(1)+n_b(2)+n_b(3) + ntot=ntotA+ntotB + + if(ac.eq.0.d0.and.bc.eq.0.d0)then + accu=0.d0 + + do k=1,klocmax + accu=accu+v_k(k)*crochet(n_k(k)+2+ntot,g_a+g_b+dz_k(k)) + enddo + Vloc=accu*fourpi*bigI(0,0,0,0,n_a(1)+n_b(1),n_a(2)+n_b(2),n_a(3)+n_b(3)) + !bigI frequantly is null + return + endif + + freal=dexp(-g_a*ac**2-g_b*bc**2) + + d2=0.d0 + do i=1,3 + d(i)=g_a*(a(i)-c(i))+g_b*(b(i)-c(i)) + d2=d2+d(i)**2 + enddo + d2=dsqrt(d2) + dreal=2.d0*d2 + + theta_DC0=dacos(d(3)/d2) + phi_DC0=datan2(d(2)/d2,d(1)/d2) + +allocate (array_R_loc(-2:ntot_max+klocmax_max,klocmax_max,0:ntot_max)) +allocate (array_coefs(0:ntot_max,0:ntot_max,0:ntot_max,0:ntot_max,0:ntot_max,0:ntot_max)) + + do ktot=-2,ntotA+ntotB+klocmax + do l=0,ntot + do k=1,klocmax + array_R_loc(ktot,k,l)=freal*int_prod_bessel_loc(ktot+2,g_a+g_b+dz_k(k),l,dreal) + enddo + enddo + enddo + + do k1=0,n_a(1) + do k2=0,n_a(2) + do k3=0,n_a(3) + do k1p=0,n_b(1) + do k2p=0,n_b(2) + do k3p=0,n_b(3) + array_coefs(k1,k2,k3,k1p,k2p,k3p)=binom(n_a(1),k1)*binom(n_a(2),k2)*binom(n_a(3),k3) & + *(c(1)-a(1))**(n_a(1)-k1)*(c(2)-a(2))**(n_a(2)-k2)*(c(3)-a(3))**(n_a(3)-k3) & + *binom(n_b(1),k1p)*binom(n_b(2),k2p)*binom(n_b(3),k3p) & + *(c(1)-b(1))**(n_b(1)-k1p)*(c(2)-b(2))**(n_b(2)-k2p)*(c(3)-b(3))**(n_b(3)-k3p) + enddo + enddo + enddo + enddo + enddo + enddo + + accu=0.d0 + do k=1,klocmax + do k1=0,n_a(1) + do k2=0,n_a(2) + do k3=0,n_a(3) + do k1p=0,n_b(1) + do k2p=0,n_b(2) + do k3p=0,n_b(3) + + do l=0,ntot + do m=-l,l + prod=ylm(l,m,theta_DC0,phi_DC0)*array_coefs(k1,k2,k3,k1p,k2p,k3p) & + *bigI(l,m,0,0,k1+k1p,k2+k2p,k3+k3p) + ktot=k1+k2+k3+k1p+k2p+k3p+n_k(k) + accu=accu+prod*v_k(k)*array_R_loc(ktot,k,l) + enddo + enddo + + enddo + enddo + enddo + enddo + enddo + enddo + enddo + Vloc=f*accu + + deallocate (array_R_loc) + deallocate (array_coefs) +end + +double precision function bigA(i,j,k) +implicit none +integer i,j,k +double precision fourpi,dble_fact +fourpi=4.d0*dacos(-1.d0) +bigA=0.d0 +if(mod(i,2).eq.1)return +if(mod(j,2).eq.1)return +if(mod(k,2).eq.1)return +bigA=fourpi*dble_fact(i-1)*dble_fact(j-1)*dble_fact(k-1)/dble_fact(i+j+k+1) +end +!! +!! I_{lambda,mu,l,m}^{k1,k2,k3} = /int dOmega Y_{lambda mu} xchap^k1 ychap^k2 zchap^k3 Y_{lm} +!! + +double precision function bigI(lambda,mu,l,m,k1,k2,k3) +implicit none +integer lambda,mu,l,m,k1,k2,k3 +integer k,i,kp,ip +double precision pi,sum,factor1,factor2,cylm,cylmp,bigA,binom,fact,coef_pm +pi=dacos(-1.d0) + +if(mu.gt.0.and.m.gt.0)then +sum=0.d0 +factor1=dsqrt((2*lambda+1)*fact(lambda-iabs(mu))/(4.d0*pi*fact(lambda+iabs(mu)))) +factor2=dsqrt((2*l+1)*fact(l-iabs(m))/(4.d0*pi*fact(l+iabs(m)))) +do k=0,mu/2 + do i=0,lambda-mu + do kp=0,m/2 + do ip=0,l-m + cylm=(-1.d0)**k*factor1*dsqrt(2.d0)*binom(mu,2*k)*fact(mu+i)/fact(i)*coef_pm(lambda,i+mu) + cylmp=(-1.d0)**kp*factor2*dsqrt(2.d0)*binom(m,2*kp)*fact(m+ip)/fact(ip)*coef_pm(l,ip+m) + sum=sum+cylm*cylmp*bigA(mu-2*k+m-2*kp+k1,2*k+2*kp+k2,i+ip+k3) + enddo + enddo + enddo +enddo +bigI=sum +return +endif + +if(mu.eq.0.and.m.eq.0)then +factor1=dsqrt((2*lambda+1)/(4.d0*pi)) +factor2=dsqrt((2*l+1)/(4.d0*pi)) +sum=0.d0 +do i=0,lambda + do ip=0,l + cylm=factor1*coef_pm(lambda,i) + cylmp=factor2*coef_pm(l,ip) + sum=sum+cylm*cylmp*bigA(k1,k2,i+ip+k3) + enddo +enddo +bigI=sum +return +endif + +if(mu.eq.0.and.m.gt.0)then +factor1=dsqrt((2*lambda+1)/(4.d0*pi)) +factor2=dsqrt((2*l+1)*fact(l-iabs(m))/(4.d0*pi*fact(l+iabs(m)))) +sum=0.d0 +do i=0,lambda + do kp=0,m/2 + do ip=0,l-m + cylm=factor1*coef_pm(lambda,i) + cylmp=(-1.d0)**kp*factor2*dsqrt(2.d0)*binom(m,2*kp)*fact(m+ip)/fact(ip)*coef_pm(l,ip+m) + sum=sum+cylm*cylmp*bigA(m-2*kp+k1,2*kp+k2,i+ip+k3) + enddo + enddo +enddo +bigI=sum +return +endif + +if(mu.gt.0.and.m.eq.0)then +sum=0.d0 +factor1=dsqrt((2*lambda+1)*fact(lambda-iabs(mu))/(4.d0*pi*fact(lambda+iabs(mu)))) +factor2=dsqrt((2*l+1)/(4.d0*pi)) +do k=0,mu/2 + do i=0,lambda-mu + do ip=0,l + cylm=(-1.d0)**k*factor1*dsqrt(2.d0)*binom(mu,2*k)*fact(mu+i)/fact(i)*coef_pm(lambda,i+mu) + cylmp=factor2*coef_pm(l,ip) + sum=sum+cylm*cylmp*bigA(mu-2*k +k1,2*k +k2,i+ip +k3) + enddo + enddo +enddo +bigI=sum +return +endif + +if(mu.lt.0.and.m.lt.0)then +mu=-mu +m=-m +factor1=dsqrt((2*lambda+1)*fact(lambda-iabs(mu))/(4.d0*pi*fact(lambda+iabs(mu)))) +factor2=dsqrt((2*l+1)*fact(l-iabs(m))/(4.d0*pi*fact(l+iabs(m)))) +sum=0.d0 +do k=0,(mu-1)/2 + do i=0,lambda-mu + do kp=0,(m-1)/2 + do ip=0,l-m + cylm=(-1.d0)**k*factor1*dsqrt(2.d0)*binom(mu,2*k+1)*fact(mu+i)/fact(i)*coef_pm(lambda,i+mu) + cylmp=(-1.d0)**kp*factor2*dsqrt(2.d0)*binom(m,2*kp+1)*fact(m+ip)/fact(ip)*coef_pm(l,ip+m) + sum=sum+cylm*cylmp*bigA(mu-(2*k+1)+m-(2*kp+1)+k1,(2*k+1)+(2*kp+1)+k2,i+ip+k3) + enddo + enddo + enddo +enddo +mu=-mu +m=-m +bigI=sum +return +endif + +if(mu.eq.0.and.m.lt.0)then +m=-m +factor1=dsqrt((2*lambda+1)/(4.d0*pi)) +factor2=dsqrt((2*l+1)*fact(l-iabs(m))/(4.d0*pi*fact(l+iabs(m)))) +sum=0.d0 +do i=0,lambda + do kp=0,(m-1)/2 + do ip=0,l-m + cylm=factor1*coef_pm(lambda,i) + cylmp=(-1.d0)**kp*factor2*dsqrt(2.d0)*binom(m,2*kp+1)*fact(m+ip)/fact(ip)*coef_pm(l,ip+m) + sum=sum+cylm*cylmp*bigA(m-(2*kp+1)+k1,2*kp+1+k2,i+ip+k3) + enddo + enddo +enddo +m=-m +bigI=sum +return +endif + +if(mu.lt.0.and.m.eq.0)then +sum=0.d0 +mu=-mu +factor1=dsqrt((2*lambda+1)*fact(lambda-iabs(mu))/(4.d0*pi*fact(lambda+iabs(mu)))) +factor2=dsqrt((2*l+1)/(4.d0*pi)) +do k=0,(mu-1)/2 + do i=0,lambda-mu + do ip=0,l + cylm=(-1.d0)**k*factor1*dsqrt(2.d0)*binom(mu,2*k+1)*fact(mu+i)/fact(i)*coef_pm(lambda,i+mu) + cylmp=factor2*coef_pm(l,ip) + sum=sum+cylm*cylmp*bigA(mu-(2*k+1)+k1,2*k+1+k2,i+ip+k3) + enddo + enddo +enddo +mu=-mu +bigI=sum +return +endif + +if(mu.gt.0.and.m.lt.0)then +sum=0.d0 +factor1=dsqrt((2*lambda+1)*fact(lambda-iabs(mu))/(4.d0*pi*fact(lambda+iabs(mu)))) +factor2=dsqrt((2*l+1)*fact(l-iabs(m))/(4.d0*pi*fact(l+iabs(m)))) +m=-m +do k=0,mu/2 + do i=0,lambda-mu + do kp=0,(m-1)/2 + do ip=0,l-m + cylm=(-1.d0)**k*factor1*dsqrt(2.d0)*binom(mu,2*k)*fact(mu+i)/fact(i)*coef_pm(lambda,i+mu) + cylmp=(-1.d0)**kp*factor2*dsqrt(2.d0)*binom(m,2*kp+1)*fact(m+ip)/fact(ip)*coef_pm(l,ip+m) + sum=sum+cylm*cylmp*bigA(mu-2*k+m-(2*kp+1)+k1,2*k+2*kp+1+k2,i+ip+k3) + enddo + enddo + enddo +enddo +m=-m +bigI=sum +return +endif + +if(mu.lt.0.and.m.gt.0)then +mu=-mu +factor1=dsqrt((2*lambda+1)*fact(lambda-iabs(mu))/(4.d0*pi*fact(lambda+iabs(mu)))) +factor2=dsqrt((2*l+1)*fact(l-iabs(m))/(4.d0*pi*fact(l+iabs(m)))) +sum=0.d0 +do k=0,(mu-1)/2 + do i=0,lambda-mu + do kp=0,m/2 + do ip=0,l-m + cylm=(-1.d0)**k*factor1*dsqrt(2.d0)*binom(mu,2*k+1)*fact(mu+i)/fact(i)*coef_pm(lambda,i+mu) + cylmp=(-1.d0)**kp*factor2*dsqrt(2.d0)*binom(m,2*kp)*fact(m+ip)/fact(ip)*coef_pm(l,ip+m) + sum=sum+cylm*cylmp*bigA(mu-(2*k+1)+m-2*kp+k1,2*k+1+2*kp+k2,i+ip+k3) + enddo + enddo + enddo +enddo +bigI=sum +mu=-mu +return +endif + +stop 'pb in bigI!' +end + +double precision function crochet(n,g) +implicit none +integer n +double precision g,pi,dble_fact,expo +pi=dacos(-1.d0) +expo=0.5d0*dfloat(n+1) +crochet=dble_fact(n-1)/(2.d0*g)**expo +if(mod(n,2).eq.0)crochet=crochet*dsqrt(pi/2.d0) +end + +!! +!! overlap= = /int dOmega Ylm (x-center_x)**nx*(y-center_y)**nx*(z-center)**nx +!! *exp(-g*(r-center)**2) +!! +double precision function overlap_orb_ylm_brute(npts,r,npower_orb,center_orb,g_orb,l,m) +implicit none +integer npower_orb(3),l,m,i,j,npts +double precision u,g_orb,du,dphi,term,orb_phi,ylm_real,sintheta,r_orb,phi,center_orb(3) +double precision x_orb,y_orb,z_orb,twopi,r +twopi=2.d0*dacos(-1.d0) +du=2.d0/npts +dphi=twopi/npts +overlap_orb_ylm_brute=0.d0 +do i=1,npts + u=-1.d0+du*(i-1)+du/2.d0 + sintheta=dsqrt(1.d0-u**2) + do j=1,npts + phi=dphi*(j-1)+dphi/2.d0 + x_orb=r*dcos(phi)*sintheta + y_orb=r*dsin(phi)*sintheta + z_orb=r*u + term=orb_phi(x_orb,y_orb,z_orb,npower_orb,center_orb,g_orb)*ylm_real(l,m,u,phi) + overlap_orb_ylm_brute= overlap_orb_ylm_brute+term*du*dphi + enddo +enddo +end + +double precision function overlap_orb_ylm_grid(nptsgrid,r_orb,npower_orb,center_orb,g_orb,l,m) +implicit none +!! PSEUDOS +integer nptsgridmax,nptsgrid +double precision coefs_pseudo,ptsgrid +parameter(nptsgridmax=50) +common/pseudos/coefs_pseudo(nptsgridmax),ptsgrid(nptsgridmax,3) +!!!!! +integer npower_orb(3),l,m,i +double precision x,g_orb,two_pi,dx,dphi,term,orb_phi,ylm_real,sintheta,r_orb,phi,center_orb(3) +double precision x_orb,y_orb,z_orb,twopi,pi,cosphi,sinphi,xbid +pi=dacos(-1.d0) +twopi=2.d0*pi +overlap_orb_ylm_grid=0.d0 +do i=1,nptsgrid + x_orb=r_orb*ptsgrid(i,1) + y_orb=r_orb*ptsgrid(i,2) + z_orb=r_orb*ptsgrid(i,3) + x=ptsgrid(i,3) + phi=datan2(ptsgrid(i,2),ptsgrid(i,1)) + term=orb_phi(x_orb,y_orb,z_orb,npower_orb,center_orb,g_orb)*ylm_real(l,m,x,phi) + overlap_orb_ylm_grid= overlap_orb_ylm_grid+coefs_pseudo(i)*term +enddo +overlap_orb_ylm_grid=2.d0*twopi*overlap_orb_ylm_grid +end + +! Y_l^m(theta,phi) = i^(m+|m|) ([(2l+1)*(l-|m|)!]/[4pi*(l+|m|)!])^1/2 P_l^|m|(cos(theta)) exp(i m phi) +! l=0,1,2,.... +! m=0,1,...,l +! Here: +! n=l (n=0,1,...) +! m=0,1,...,n +! x=cos(theta) 0 < x < 1 +! +! +! This routine computes: PM(m,n) for n=0,...,N (number N in input) and m=0,..,n + +! Exemples (see 'Associated Legendre Polynomilas wikipedia') +! P_{0}^{0}(x)=1 +! P_{1}^{-1}(x)=-1/2 P_{1}^{1}(x) +! P_{1}^{0}(x)=x +! P_{1}^{1}(x)=-(1-x^2)^{1/2} +! P_{2}^{-2}(x)=1/24 P_{2}^{2}(x) +! P_{2}^{-1}(x)=-1/6 P_{2}^{1}(x) +! P_{2}^{0}(x)=1/2 (3x^{2}-1) +! P_{2}^{1}(x)=-3x(1-x^2)^{1/2} +! P_{2}^{2}(x)=3(1-x^2) + + + SUBROUTINE LPMN(MM,M,N,X,PM) +! +! Here N = LMAX +! Here M= MMAX (we take M=LMAX in input) +! +! ===================================================== +! Purpose: Compute the associated Legendre functions Pmn(x) +! Input : x --- Argument of Pmn(x) +! m --- Order of Pmn(x), m = 0,1,2,...,n +! n --- Degree of Pmn(x), n = 0,1,2,...,N +! mm --- Physical dimension of PM +! Output: PM(m,n) --- Pmn(x) +! ===================================================== +! + IMPLICIT DOUBLE PRECISION (P,X) + DIMENSION PM(0:MM,0:(N+1)) + DO 10 I=0,N + DO 10 J=0,M +10 PM(J,I)=0.0D0 + PM(0,0)=1.0D0 + IF (DABS(X).EQ.1.0D0) THEN + DO 15 I=1,N +15 PM(0,I)=X**I + RETURN + ENDIF + LS=1 + IF (DABS(X).GT.1.0D0) LS=-1 + XQ=DSQRT(LS*(1.0D0-X*X)) + XS=LS*(1.0D0-X*X) + DO 30 I=1,M +30 PM(I,I)=-LS*(2.0D0*I-1.0D0)*XQ*PM(I-1,I-1) + DO 35 I=0,M +35 PM(I,I+1)=(2.0D0*I+1.0D0)*X*PM(I,I) + + DO 40 I=0,M + DO 40 J=I+2,N + PM(I,J)=((2.0D0*J-1.0D0)*X*PM(I,J-1)- (I+J-1.0D0)*PM(I,J-2))/(J-I) +40 CONTINUE + END + + +! Y_l^m(theta,phi) = i^(m+|m|) ([(2l+1)*(l-|m|)!]/[4pi*(l+|m|)!])^1/2 +! P_l^|m|(cos(theta)) exp(i m phi) + + subroutine erreur(x,n,rmoy,error) + implicit double precision(a-h,o-z) + dimension x(n) +! calcul de la moyenne + rmoy=0.d0 + do i=1,n + rmoy=rmoy+x(i) + enddo + rmoy=rmoy/dfloat(n) +! calcul de l'erreur + error=0.d0 + do i=1,n + error=error+(x(i)-rmoy)**2 + enddo + if(n.gt.1)then + rn=dfloat(n) + rn1=dfloat(n-1) + error=dsqrt(error)/dsqrt(rn*rn1) + else + write(2,*)'Seulement un block Erreur nondefinie' + error=0.d0 + endif + end + + subroutine initpseudos(nptsgrid) + implicit none + integer nptsgridmax,nptsgrid,ik + double precision coefs_pseudo,ptsgrid + double precision p,q,r,s + parameter(nptsgridmax=50) + common/pseudos/coefs_pseudo(nptsgridmax),ptsgrid(nptsgridmax,3) + + p=1.d0/dsqrt(2.d0) + q=1.d0/dsqrt(3.d0) + r=1.d0/dsqrt(11.d0) + s=3.d0/dsqrt(11.d0) + + if(nptsgrid.eq.4)then + + ptsgrid(1,1)=q + ptsgrid(1,2)=q + ptsgrid(1,3)=q + + ptsgrid(2,1)=q + ptsgrid(2,2)=-q + ptsgrid(2,3)=-q + + ptsgrid(3,1)=-q + ptsgrid(3,2)=q + ptsgrid(3,3)=-q + + ptsgrid(4,1)=-q + ptsgrid(4,2)=-q + ptsgrid(4,3)=q + + do ik=1,4 + coefs_pseudo(ik)=1.d0/4.d0 + enddo + return + endif + + ptsgrid(1,1)=1.d0 + ptsgrid(1,2)=0.d0 + ptsgrid(1,3)=0.d0 + + ptsgrid(2,1)=-1.d0 + ptsgrid(2,2)=0.d0 + ptsgrid(2,3)=0.d0 + + ptsgrid(3,1)=0.d0 + ptsgrid(3,2)=1.d0 + ptsgrid(3,3)=0.d0 + + ptsgrid(4,1)=0.d0 + ptsgrid(4,2)=-1.d0 + ptsgrid(4,3)=0.d0 + + ptsgrid(5,1)=0.d0 + ptsgrid(5,2)=0.d0 + ptsgrid(5,3)=1.d0 + + ptsgrid(6,1)=0.d0 + ptsgrid(6,2)=0.d0 + ptsgrid(6,3)=-1.d0 + + do ik=1,6 + coefs_pseudo(ik)=1.d0/6.d0 + enddo + + if(nptsgrid.eq.6)return + + ptsgrid(7,1)=p + ptsgrid(7,2)=p + ptsgrid(7,3)=0.d0 + + ptsgrid(8,1)=p + ptsgrid(8,2)=-p + ptsgrid(8,3)=0.d0 + + ptsgrid(9,1)=-p + ptsgrid(9,2)=p + ptsgrid(9,3)=0.d0 + + ptsgrid(10,1)=-p + ptsgrid(10,2)=-p + ptsgrid(10,3)=0.d0 + + ptsgrid(11,1)=p + ptsgrid(11,2)=0.d0 + ptsgrid(11,3)=p + + ptsgrid(12,1)=p + ptsgrid(12,2)=0.d0 + ptsgrid(12,3)=-p + + ptsgrid(13,1)=-p + ptsgrid(13,2)=0.d0 + ptsgrid(13,3)=p + + ptsgrid(14,1)=-p + ptsgrid(14,2)=0.d0 + ptsgrid(14,3)=-p + + ptsgrid(15,1)=0.d0 + ptsgrid(15,2)=p + ptsgrid(15,3)=p + + ptsgrid(16,1)=0.d0 + ptsgrid(16,2)=p + ptsgrid(16,3)=-p + + ptsgrid(17,1)=0.d0 + ptsgrid(17,2)=-p + ptsgrid(17,3)=p + + ptsgrid(18,1)=0.d0 + ptsgrid(18,2)=-p + ptsgrid(18,3)=-p + + do ik=1,6 + coefs_pseudo(ik)=1.d0/30.d0 + enddo + do ik=7,18 + coefs_pseudo(ik)=1.d0/15.d0 + enddo + + if(nptsgrid.eq.18)return + + ptsgrid(19,1)=q + ptsgrid(19,2)=q + ptsgrid(19,3)=q + + ptsgrid(20,1)=-q + ptsgrid(20,2)=q + ptsgrid(20,3)=q + + ptsgrid(21,1)=q + ptsgrid(21,2)=-q + ptsgrid(21,3)=q + + ptsgrid(22,1)=q + ptsgrid(22,2)=q + ptsgrid(22,3)=-q + + ptsgrid(23,1)=-q + ptsgrid(23,2)=-q + ptsgrid(23,3)=q + + ptsgrid(24,1)=-q + ptsgrid(24,2)=q + ptsgrid(24,3)=-q + + ptsgrid(25,1)=q + ptsgrid(25,2)=-q + ptsgrid(25,3)=-q + + ptsgrid(26,1)=-q + ptsgrid(26,2)=-q + ptsgrid(26,3)=-q + + do ik=1,6 + coefs_pseudo(ik)=1.d0/21.d0 + enddo + do ik=7,18 + coefs_pseudo(ik)=4.d0/105.d0 + enddo + do ik=19,26 + coefs_pseudo(ik)=27.d0/840.d0 + enddo + + if(nptsgrid.eq.26)return + + ptsgrid(27,1)=r + ptsgrid(27,2)=r + ptsgrid(27,3)=s + + ptsgrid(28,1)=r + ptsgrid(28,2)=-r + ptsgrid(28,3)=s + + ptsgrid(29,1)=-r + ptsgrid(29,2)=r + ptsgrid(29,3)=s + + ptsgrid(30,1)=-r + ptsgrid(30,2)=-r + ptsgrid(30,3)=s + + ptsgrid(31,1)=r + ptsgrid(31,2)=r + ptsgrid(31,3)=-s + + ptsgrid(32,1)=r + ptsgrid(32,2)=-r + ptsgrid(32,3)=-s + + ptsgrid(33,1)=-r + ptsgrid(33,2)=r + ptsgrid(33,3)=-s + + ptsgrid(34,1)=-r + ptsgrid(34,2)=-r + ptsgrid(34,3)=-s + + ptsgrid(35,1)=r + ptsgrid(35,2)=s + ptsgrid(35,3)=r + + ptsgrid(36,1)=-r + ptsgrid(36,2)=s + ptsgrid(36,3)=r + + ptsgrid(37,1)=r + ptsgrid(37,2)=s + ptsgrid(37,3)=-r + + ptsgrid(38,1)=-r + ptsgrid(38,2)=s + ptsgrid(38,3)=-r + + ptsgrid(39,1)=r + ptsgrid(39,2)=-s + ptsgrid(39,3)=r + + ptsgrid(40,1)=r + ptsgrid(40,2)=-s + ptsgrid(40,3)=-r + + ptsgrid(41,1)=-r + ptsgrid(41,2)=-s + ptsgrid(41,3)=r + + ptsgrid(42,1)=-r + ptsgrid(42,2)=-s + ptsgrid(42,3)=-r + + ptsgrid(43,1)=s + ptsgrid(43,2)=r + ptsgrid(43,3)=r + + ptsgrid(44,1)=s + ptsgrid(44,2)=r + ptsgrid(44,3)=-r + + ptsgrid(45,1)=s + ptsgrid(45,2)=-r + ptsgrid(45,3)=r + + ptsgrid(46,1)=s + ptsgrid(46,2)=-r + ptsgrid(46,3)=-r + + ptsgrid(47,1)=-s + ptsgrid(47,2)=r + ptsgrid(47,3)=r + + ptsgrid(48,1)=-s + ptsgrid(48,2)=r + ptsgrid(48,3)=-r + + ptsgrid(49,1)=-s + ptsgrid(49,2)=-r + ptsgrid(49,3)=r + + ptsgrid(50,1)=-s + ptsgrid(50,2)=-r + ptsgrid(50,3)=-r + + do ik=1,6 + coefs_pseudo(ik)=4.d0/315.d0 + enddo + do ik=7,18 + coefs_pseudo(ik)=64.d0/2835.d0 + enddo + do ik=19,26 + coefs_pseudo(ik)=27.d0/1280.d0 + enddo + do ik=27,50 + coefs_pseudo(ik)=14641.d0/725760.d0 + enddo + + if(nptsgrid.eq.50)return + + write(*,*)'Grid for pseudos not available!' + write(*,*)'N=4-6-18-26-50 only!' + stop + end + +!! +!! R_{lambda,lamba',N}= exp(-ga_a AC**2 -g_b BC**2) /int_{0}{+infty} r**(2+n) exp(-(g_a+g_b+g_k)r**2) +!! * M_{lambda}( 2g_a ac r) M_{lambda'}(2g_b bc r) +!! + double precision function bigR(lambda,lambdap,n,g_a,g_b,ac,bc,g_k) + implicit none + integer lambda,lambdap,n,npts,i + double precision g_a,g_b,ac,bc,g_k,arg,factor,delta1,delta2,cc,rmax,dr,sum,x1,x2,r + double precision bessel_mod + arg=g_a*ac**2+g_b*bc**2 + factor=dexp(-arg) + delta1=2.d0*g_a*ac + delta2=2.d0*g_b*bc + cc=g_a+g_b+g_k + if(cc.eq.0.d0)stop 'pb. in bigR' + rmax=dsqrt(-dlog(10.d-20)/cc) + npts=500 + dr=rmax/npts + sum=0.d0 + do i=1,npts + r=(i-1)*dr + x1=delta1*r + x2=delta2*r + sum=sum+dr*r**(n+2)*dexp(-cc*r**2)*bessel_mod(x1,lambda)*bessel_mod(x2,lambdap) + enddo + bigR=sum*factor + end + + double precision function bessel_mod(x,n) + implicit none + integer n + double precision x,bessel_mod_exp,bessel_mod_recur + if(x.le.0.8d0)then + bessel_mod=bessel_mod_exp(n,x) + else + bessel_mod=bessel_mod_recur(n,x) + endif + end + + recursive function bessel_mod_recur(n,x) result(a) + implicit none + integer n + double precision x,a,bessel_mod_exp + if(x.le.0.8d0)then + a=bessel_mod_exp(n,x) + return + endif + if(n.eq.0)a=dsinh(x)/x + if(n.eq.1)a=(x*dcosh(x)-dsinh(x))/x**2 + if(n.ge.2)a=bessel_mod_recur(n-2,x)-(2*n-1)/x*bessel_mod_recur(n-1,x) + end + + double precision function bessel_mod_exp(n,x) + implicit none + integer n,k + double precision x,coef,accu,fact,dble_fact + accu=0.d0 + do k=0,10 + coef=1.d0/fact(k)/dble_fact(2*(n+k)+1) + accu=accu+(x**2/2.d0)**k*coef + enddo + bessel_mod_exp=x**n*accu + end + +! double precision function bessel_mod(x,n) +! IMPLICIT DOUBLE PRECISION (A-H,O-Z) +! parameter(NBESSMAX=100) +! dimension SI(0:NBESSMAX),DI(0:NBESSMAX) +! if(n.lt.0.or.n.gt.NBESSMAX)stop 'pb with argument of bessel_mod' +! CALL SPHI(N,X,NBESSMAX,SI,DI) +! bessel_mod=si(n) +! end + + SUBROUTINE SPHI(N,X,NMAX,SI,DI) +! +! ======================================================== +! Purpose: Compute modified spherical Bessel functions +! of the first kind, in(x) and in'(x) +! Input : x --- Argument of in(x) +! n --- Order of in(x) ( n = 0,1,2,... ) +! Output: SI(n) --- in(x) +! DI(n) --- in'(x) +! NM --- Highest order computed +! Routines called: +! MSTA1 and MSTA2 for computing the starting +! point for backward recurrence +! ======================================================== +! + IMPLICIT DOUBLE PRECISION (A-H,O-Z) + DIMENSION SI(0:NMAX),DI(0:NMAX) + NM=N + IF (DABS(X).LT.1.0D-100) THEN + DO 10 K=0,N + SI(K)=0.0D0 +10 DI(K)=0.0D0 + SI(0)=1.0D0 + DI(1)=0.333333333333333D0 + RETURN + ENDIF + SI(0)=DSINH(X)/X + SI(1)=-(DSINH(X)/X-DCOSH(X))/X + SI0=SI(0) + IF (N.GE.2) THEN + M=MSTA1(X,200) + + write(34,*)'m=',m + + IF (M.LT.N) THEN + NM=M + ELSE + M=MSTA2(X,N,15) + write(34,*)'m=',m + ENDIF + F0=0.0D0 + F1=1.0D0-100 + DO 15 K=M,0,-1 + F=(2.0D0*K+3.0D0)*F1/X+F0 + IF (K.LE.NM) SI(K)=F + F0=F1 +15 F1=F + CS=SI0/F + write(34,*)'cs=',cs + DO 20 K=0,NM +20 SI(K)=CS*SI(K) + ENDIF + DI(0)=SI(1) + DO 25 K=1,NM +25 DI(K)=SI(K-1)-(K+1.0D0)/X*SI(K) + RETURN + END + + + INTEGER FUNCTION MSTA1(X,MP) +! +! =================================================== +! Purpose: Determine the starting point for backward +! recurrence such that the magnitude of +! Jn(x) at that point is about 10^(-MP) +! Input : x --- Argument of Jn(x) +! MP --- Value of magnitude +! Output: MSTA1 --- Starting point +! =================================================== +! + IMPLICIT DOUBLE PRECISION (A-H,O-Z) + A0=DABS(X) + N0=INT(1.1*A0)+1 + F0=ENVJ(N0,A0)-MP + N1=N0+5 + F1=ENVJ(N1,A0)-MP + DO 10 IT=1,20 + NN=N1-(N1-N0)/(1.0D0-F0/F1) + F=ENVJ(NN,A0)-MP + IF(ABS(NN-N1).LT.1) GO TO 20 + N0=N1 + F0=F1 + N1=NN + 10 F1=F + 20 MSTA1=NN + RETURN + END + + + INTEGER FUNCTION MSTA2(X,N,MP) +! +! =================================================== +! Purpose: Determine the starting point for backward +! recurrence such that all Jn(x) has MP +! significant digits +! Input : x --- Argument of Jn(x) +! n --- Order of Jn(x) +! MP --- Significant digit +! Output: MSTA2 --- Starting point +! =================================================== +! + IMPLICIT DOUBLE PRECISION (A-H,O-Z) + A0=DABS(X) + HMP=0.5D0*MP + EJN=ENVJ(N,A0) + IF (EJN.LE.HMP) THEN + OBJ=MP + N0=INT(1.1*A0) + ELSE + OBJ=HMP+EJN + N0=N + ENDIF + F0=ENVJ(N0,A0)-OBJ + N1=N0+5 + F1=ENVJ(N1,A0)-OBJ + DO 10 IT=1,20 + NN=N1-(N1-N0)/(1.0D0-F0/F1) + F=ENVJ(NN,A0)-OBJ + IF (iABS(NN-N1).LT.1) GO TO 20 + N0=N1 + F0=F1 + N1=NN +10 F1=F +20 MSTA2=NN+10 + RETURN + END + + double precision FUNCTION ENVJ(N,X) + DOUBLE PRECISION X + integer N + ENVJ=0.5D0*DLOG10(6.28D0*N)-N*DLOG10(1.36D0*X/N) + RETURN + END + +!c Computation of real spherical harmonics Ylm(theta,phi) +!c +!c l=0,1,.... +!c m=-l,l +!c +!c m>0: Y_lm = sqrt(2) ([(2l+1)*(l-|m|)!]/[4pi*(l+|m|)!])^1/2 P_l^|m|(cos(theta)) cos(m phi) +!c m=0: Y_l0 = ([(2l+1)*(l-|m|)!]/[4pi*(l+|m|)!])^1/2 P_l^0 (cos(theta)) +!c m<0: Y_lm = sqrt(2) ([(2l+1)*(l-|m|)!]/[4pi*(l+|m|)!])^1/2 P_l^|m|(cos(theta)) sin(|m|phi) + +!Examples(wikipedia http://en.wikipedia.org/wiki/Table_of_spherical_harmonics#Real_spherical_harmonics) + +! l = 0 + +! Y_00 = \sqrt{1/(4pi)} + +! l = 1 + +! Y_1-1= \sqrt{3/(4pi)} y/r +! Y_10 = \sqrt{3/(4pi)} z/r +! Y_11 = \sqrt{3/(4pi)} x/r +! +! l = 2 +! +! Y_2,-2= 1/2 \sqrt{15/pi} xy/r^2 +! Y_2,-1= 1/2 \sqrt{15/pi} yz/r^2 +! Y_20 = 1/4 \sqrt{15/pi} (-x^2-y^2 +2z^2)/r^2 +! Y_21 = 1/2 \sqrt{15/pi} zx/r^2 +! Y_22 = 1/4 \sqrt{15/pi} (x^2-y^2)/r^2 +! +!c +double precision function ylm(l,m,theta,phi) +implicit none +integer l,m +double precision theta,phi,pm,factor,pi,x,fact,sign +DIMENSION PM(0:100,0:100) +pi=dacos(-1.d0) +x=dcos(theta) +sign=(-1.d0)**m +CALL LPMN(100,l,l,X,PM) +factor=dsqrt( (2*l+1)*fact(l-iabs(m)) /(4.d0*pi*fact(l+iabs(m))) ) +if(m.gt.0)ylm=sign*dsqrt(2.d0)*factor*pm(m,l)*dcos(dfloat(m)*phi) +if(m.eq.0)ylm=factor*pm(m,l) +if(m.lt.0)ylm=sign*dsqrt(2.d0)*factor*pm(iabs(m),l)*dsin(dfloat(iabs(m))*phi) +end + +!c Explicit representation of Legendre polynomials P_n(x) +!! +!! P_n0(x) = P_n(x)= \sum_{k=0}^n a_k x^k +!! +!! with a_k= 2^n binom(n,k) binom( (n+k-1)/2, n ) +!! coef_pm(n,k) is the k_th coefficient of P_n(x) +double precision function coef_pm(n,k) +implicit none +integer n,k +double precision arg,binom,binom_gen +if(n.eq.0.and.k.ne.0)stop 'coef_pm not defined' +if(n.eq.0.and.k.eq.0)then +coef_pm=1.d0 +return +endif +arg=0.5d0*dfloat(n+k-1) +coef_pm=2.d0**n*binom(n,k)*binom_gen(arg,n) +end + +!! Ylm_bis uses the series expansion of Ylm in xchap^i ychap^j zchap^k +!! xchap=x/r etc. +!c m>0: Y_lm = sqrt(2)*factor* P_l^|m|(cos(theta)) cos(m phi) +!c m=0: Y_l0 = factor* P_l^0 (cos(theta)) +!c m<0: Y_lm = sqrt(2) factor* P_l^|m|(cos(theta)) sin(|m|phi) +!c factor= ([(2l+1)*(l-|m|)!]/[4pi*(l+|m|)!])^1/2 + +!! P_l^m (x) = (-1)**m (1-x**2)^m/2 d^m/dx^m P_l(x) m >0 or 0 +!! the series expansion of P_m (x) is known +!! +!! sin(theta)**m cos(mphi) = \sum_0^[m/2] binom(m,2k) x^(m-2k) y^2k (-1)**k (easy to proove with +!! Moivre formula) +!! (here x = xchap...) +!! +!! Ylm m> 0 = \sum_{k=0}^[m/2] \sum_{i=0}^(l-m) c_ki x^(m-2k) y^2k z^i +!! +!! c_ki= (-1)^k sqrt(2)*factor*binom(m,2k)*(m+i)!/i!*coef_pm(l,i+m) +!! +!! Ylm m< 0 = \sum_{k=0}^[(m-1)/2] \sum_{i=0}^(l-m) c_ki x^(m-(2k+1)) y^(2k+1) z^i +!! +!! c_ki= (-1)^k sqrt(2)*factor*binom(m,2k+1)*(m+i)!/i!*coef_pm(l,i+m) + + +double precision function ylm_bis(l,m,theta,phi) +implicit none +integer l,m,k,i +double precision x,y,z,theta,phi,sum,factor,pi,binom,fact,coef_pm,cylm +pi=dacos(-1.d0) +x=dsin(theta)*dcos(phi) +y=dsin(theta)*dsin(phi) +z=dcos(theta) +factor=dsqrt((2*l+1)*fact(l-iabs(m))/(4.d0*pi*fact(l+iabs(m)))) +if(m.gt.0)then +sum=0.d0 +do k=0,m/2 + do i=0,l-m + cylm=(-1.d0)**k*factor*dsqrt(2.d0)*binom(m,2*k)*fact(m+i)/fact(i)*coef_pm(l,i+m) + sum=sum+cylm*x**(m-2*k)*y**(2*k)*z**i + enddo +enddo +ylm_bis=sum +return +endif +if(m.eq.0)then +sum=0.d0 +do i=0,l + sum=sum+factor*coef_pm(l,i)*z**i +enddo +ylm_bis=sum +return +endif +if(m.lt.0)then +m=-m +sum=0.d0 +do k=0,(m-1)/2 + do i=0,l-m + cylm=(-1.d0)**k*factor*dsqrt(2.d0)*binom(m,2*k+1)*fact(m+i)/fact(i)*coef_pm(l,i+m) + sum=sum+cylm*x**(m-(2*k+1))*y**(2*k+1)*z**i + enddo +enddo +ylm_bis=sum +m=-m +return +endif +end + +!c +!c Computation of associated Legendre Polynomials PM(m,n) for n=0,...,N +!c Here: +!c n=l (n=0,1,...) +!c m=0,1,...,n +!c x=cos(theta) 0 < x < 1 +!c +!c This routine computes: PM(m,n) for n=0,...,N (number N in input) and m=0,..,n +!c Exemples (see 'Associated Legendre Polynomilas wikipedia') +!c P_{0}^{0}(x)=1 +!c P_{1}^{-1}(x)=-1/2 P_{1}^{1}(x) +!c P_{1}^{0}(x)=x +!c P_{1}^{1}(x)=-(1-x^2)^{1/2} +!c P_{2}^{-2}(x)=1/24 P_{2}^{2}(x) +!c P_{2}^{-1}(x)=-1/6 P_{2}^{1}(x) +!c P_{2}^{0}(x)=1/2 (3x^{2}-1) +!c P_{2}^{1}(x)=-3x(1-x^2)^{1/2} +!c P_{2}^{2}(x)=3(1-x^2) +!c +!c Explicit representation: +!! +!! P_n0(x) = P_n(x)= \sum_{k=0}^n a_k x^k +!! +!! with a_k= 2^n binom(n,k) binom( (n+k-1)/2, n ) + +double precision function binom(i,j) + implicit none + integer :: i,j + double precision :: fact + binom = fact(i)/(fact(j)*fact(i-j)) +end + +double precision function binom_gen(alpha,n) + implicit none + integer :: n,k + double precision :: fact,alpha,prod + prod=1.d0 + do k=0,n-1 + prod=prod*(alpha-k) + binom_gen = prod/(fact(n)) + enddo +end + + double precision FUNCTION ERF(X) + implicit double precision(a-h,o-z) + IF(X.LT.0.d0)THEN + ERF=-GAMMP(.5d0,X**2) + ELSE + ERF=GAMMP(.5d0,X**2) + ENDIF + RETURN + END + +double precision function coef_nk(n,k) + implicit none + integer n,k, ISHFT + + double precision gam,dble_fact,fact + + gam=dble_fact(2*(n+k)+1) + +! coef_nk=1.d0/(dble(ISHFT(1,k))*fact(k)*gam) + + coef_nk=1.d0/(2.d0**k*fact(k)*gam) + + return + +end + +!! Calculation of +!! +!! I= \int dx x**l *exp(-gam*x**2) M_n(ax) M_m(bx) +!! +!! M_n(x) modified spherical bessel function +!! + +double precision function int_prod_bessel(l,gam,n,m,a,b,arg) + + implicit none + integer n,k,m,q,l,kcp + double precision gam,dble_fact,fact,pi,a,b + double precision int,intold,sum,coef_nk,crochet,u,int_prod_bessel_large,freal,arg + + integer :: n_1,m_1,nlm + double precision :: term_A, term_B, term_rap, expo + double precision :: s_q_0, s_q_k, s_0_0, a_over_b_square + double precision :: int_prod_bessel_loc + + logical done + + u=(a+b)/(2.d0*dsqrt(gam)) + freal=dexp(-arg) + + if(a.eq.0.d0.and.b.eq.0.d0)then + if(n.ne.0.or.m.ne.0)then + int_prod_bessel=0.d0 + return + endif + + int_prod_bessel=crochet(l,gam)*freal + return + endif + + if(u.gt.6.d0)then + int_prod_bessel=int_prod_bessel_large(l,gam,n,m,a,b,arg) + return + endif + + if(a.ne.0.d0.and.b.ne.0.d0)then + + q=0 + intold=-1.d0 + int=0.d0 + done=.false. + + n_1 = 2*(n)+1 + m_1 = 2*m+1 + nlm = n+m+l + pi=dacos(-1.d0) + a_over_b_square = (a/b)**2 + + ! Calcul first term of the sequence + + term_a =dble_fact(nlm-1) / (dble_fact(n_1)*dble_fact(m_1)) + expo=0.5d0*dfloat(nlm+1) + term_rap = term_a / (2.d0*gam)**expo + + s_0_0=term_rap*a**(n)*b**(m) + if(mod(nlm,2).eq.0)s_0_0=s_0_0*dsqrt(pi/2.d0) + + ! Initialise the first recurence terme for the q loop + s_q_0 = s_0_0 + + ! Loop over q for the convergence of the sequence + do while (.not.done) + + ! Init + sum=0 + s_q_k=s_q_0 + + ! Iteration of k + do k=0,q + sum=sum+s_q_k + s_q_k = a_over_b_square * ( dble(2*(q-k+m)+1)/dble(2*(k+n)+3) ) * ( dble(q-k)/dble(k+1)) * s_q_k + enddo + + int=int+sum + + if(dabs(int-intold).lt.1d-15)then + done=.true. + else + + !Compute the s_q+1_0 + s_q_0=s_q_0*(2.d0*q+nlm+1)*b**2/((2.d0*(m+q)+3)*4.d0*(q+1)*gam) + + if(mod(n+m+l,2).eq.1)s_q_0=s_q_0*dsqrt(pi/2.d0) + ! Increment q + q=q+1 + intold=int + endif + + enddo + + int_prod_bessel=int*freal + + return + endif + + if(a.eq.0.d0.and.b.ne.0.d0)then + + int = int_prod_bessel_loc(l,gam,m,b) + int_prod_bessel=int*freal + return + endif + + if(a.ne.0.d0.and.b.eq.0.d0)then + + int = int_prod_bessel_loc(l,gam,n,a) + int_prod_bessel=int*freal + return + + endif + + stop 'pb in int_prod_bessel!!' +end + +double precision function int_prod_bessel_large(l,gam,n,m,a,b,arg) + implicit none + integer n,m,i,npts,l + double precision gam,a,b + double precision sum,x,bessel_mod,u,factor,arg + double precision xq(100),wq(100) + + u=(a+b)/(2.d0*dsqrt(gam)) + factor=dexp(u**2-arg)/dsqrt(gam) + +xq(1)= 5.38748089001123 +xq(2)= 4.60368244955074 +xq(3)= 3.94476404011563 +xq(4)= 3.34785456738322 +xq(5)= 2.78880605842813 +xq(6)= 2.25497400208928 +xq(7)= 1.73853771211659 +xq(8)= 1.23407621539532 +xq(9)= 0.737473728545394 +xq(10)= 0.245340708300901 +xq(11)=-0.245340708300901 +xq(12)=-0.737473728545394 +xq(13)=-1.23407621539532 +xq(14)=-1.73853771211659 +xq(15)=-2.25497400208928 +xq(16)=-2.78880605842813 +xq(17)=-3.34785456738322 +xq(18)=-3.94476404011563 +xq(19)=-4.60368244955074 +xq(20)=-5.38748089001123 +wq(1)= 2.229393645534151E-013 +wq(2)= 4.399340992273176E-010 +wq(3)= 1.086069370769280E-007 +wq(4)= 7.802556478532063E-006 +wq(5)= 2.283386360163528E-004 +wq(6)= 3.243773342237853E-003 +wq(7)= 2.481052088746362E-002 +wq(8)= 0.109017206020022 +wq(9)= 0.286675505362834 +wq(10)= 0.462243669600610 +wq(11)= 0.462243669600610 +wq(12)= 0.286675505362834 +wq(13)= 0.109017206020022 +wq(14)= 2.481052088746362E-002 +wq(15)= 3.243773342237853E-003 +wq(16)= 2.283386360163528E-004 +wq(17)= 7.802556478532063E-006 +wq(18)= 1.086069370769280E-007 +wq(19)= 4.399340992273176E-010 +wq(20)= 2.229393645534151E-013 + + npts=20 +! call gauher(xq,wq,npts) + + sum=0.d0 + do i=1,npts + x=(xq(i)+u)/dsqrt(gam) + sum=sum+wq(i)*x**l*bessel_mod(a*x,n)*bessel_mod(b*x,m)*dexp(-(a+b)*x) + enddo + int_prod_bessel_large=sum*factor +end + +!! Calculation of +!! +!! I= \int dx x**l *exp(-gam*x**2) M_n(ax) +!! +!! M_n(x) modified spherical bessel function +!! +double precision function int_prod_bessel_loc(l,gam,n,a) + implicit none + integer n,k,l,kcp + double precision gam,a + double precision int,intold,coef_nk,crochet,dble_fact, fact, pi, expo + double precision :: f_0, f_k + logical done + + pi=dacos(-1.d0) + intold=-1.d0 + done=.false. + int=0 + + ! Int f_0 + coef_nk=1.d0/dble_fact(2*n+1) + expo=0.5d0*dfloat(n+l+1) + crochet=dble_fact(n+l-1)/(2.d0*gam)**expo + if(mod(n+l,2).eq.0)crochet=crochet*dsqrt(pi/2.d0) + + f_0 = coef_nk*a**n*crochet + + k=0 + + f_k=f_0 + do while (.not.done) + + int=int+f_k + + f_k = f_k*(a**2*(2*(k+1)+n+l-1)) / (2*(k+1)*(2*(n+k+1)+1)*2*gam) + + if(dabs(int-intold).lt.1d-15)then + done=.true. + else + k=k+1 + intold=int + endif + + enddo + + int_prod_bessel_loc=int +end + + double precision function int_prod_bessel_num(l,gam,n,m,a,b) + implicit none + integer n,m,l,i,npoints + double precision gam,a,b + double precision sum,dx,x,bessel_mod + sum=0.d0 + npoints=20000 + dx=30.d0/npoints + do i=1,npoints + x=(i-1)*dx+0.5d0*dx + sum=sum+dx*x**l*dexp(-gam*x**2)*bessel_mod(a*x,n)*bessel_mod(b*x,m) + enddo + int_prod_bessel_num=sum + end + + + diff --git a/src/Pseudo_integrals/pot_ao_ints_pseudo.irp.f b/src/Pseudo_integrals/pot_ao_ints_pseudo.irp.f new file mode 100644 index 00000000..37dc7591 --- /dev/null +++ b/src/Pseudo_integrals/pot_ao_ints_pseudo.irp.f @@ -0,0 +1,167 @@ + BEGIN_PROVIDER [ double precision, ao_nucl_elec_integral_pseudo, (ao_num_align,ao_num)] + BEGIN_DOC +! interaction nuclear electron + END_DOC + implicit none + double precision :: alpha, beta, gama, delta + integer :: num_A,num_B + double precision :: A_center(3),B_center(3),C_center(3) + integer :: power_A(3),power_B(3) + integer :: i,j,k,l,n_pt_in,m + double precision :: Vloc, Vpseudo + + double precision :: cpu_1, cpu_2, wall_1, wall_2, wall_0 + integer :: thread_num + + ao_nucl_elec_integral_pseudo = 0.d0 + + ! + ! | _ _ _. | + ! |_ (_) (_ (_| | + ! + !! Parameters of the local part of pseudo: + + integer klocmax + integer, allocatable :: n_k(:,:) + double precision, allocatable :: v_k(:,:), dz_k(:,:) + + call ezfio_get_pseudo_integrals_klocmax(klocmax) + + allocate(n_k(nucl_num,klocmax),v_k(nucl_num,klocmax), dz_k(nucl_num,klocmax)) + + call ezfio_get_pseudo_integrals_v_k(v_k) + call ezfio_get_pseudo_integrals_n_k(n_k) + call ezfio_get_pseudo_integrals_dz_k(dz_k) + + !! Dump array + integer, allocatable :: n_k_dump(:) + double precision, allocatable :: v_k_dump(:), dz_k_dump(:) + + allocate(n_k_dump(1:klocmax), v_k_dump(1:klocmax), dz_k_dump(1:klocmax)) + + + ! + ! |\ | _ ._ | _ _ _. | + ! | \| (_) | | | (_) (_ (_| | + ! + !! Parameters of non local part of pseudo: + + integer :: kmax,lmax + integer, allocatable :: n_kl(:,:,:) + double precision, allocatable :: v_kl(:,:,:), dz_kl(:,:,:) + + call ezfio_get_pseudo_integrals_lmaxpo(lmax) + call ezfio_get_pseudo_integrals_kmax(kmax) + !lmax plus one -> lmax + lmax = lmax - 1 + + allocate(n_kl(nucl_num,kmax,0:lmax), v_kl(nucl_num,kmax,0:lmax), dz_kl(nucl_num,kmax,0:lmax)) + + call ezfio_get_pseudo_integrals_n_kl(n_kl) + call ezfio_get_pseudo_integrals_v_kl(v_kl) + call ezfio_get_pseudo_integrals_dz_kl(dz_kl) + + + !! Dump array + integer, allocatable :: n_kl_dump(:,:) + double precision, allocatable :: v_kl_dump(:,:), dz_kl_dump(:,:) + + allocate(n_kl_dump(kmax,0:lmax), v_kl_dump(kmax,0:lmax), dz_kl_dump(kmax,0:lmax)) + + ! _ + ! / _. | _ | + ! \_ (_| | (_ |_| | + ! + + write(output_monoints,*) 'Providing the nuclear electron pseudo integrals ' + + call wall_time(wall_1) + call cpu_time(cpu_1) + + !$OMP PARALLEL & + !$OMP DEFAULT (NONE) & + !$OMP PRIVATE (i,j,k,l,m,alpha,beta,A_center,B_center,C_center,power_A,power_B, & + !$OMP num_A,num_B,Z,c,n_pt_in, & + !$OMP v_k_dump,n_k_dump, dz_k_dump, n_kl_dump, v_kl_dump, dz_kl_dump, & + !$OMP wall_0,wall_2,thread_num, output_monoints) & + !$OMP SHARED (ao_num,ao_prim_num,ao_expo_ordered_transp,ao_power,ao_nucl,nucl_coord,ao_coef_normalized_ordered_transp, & + !$OMP ao_nucl_elec_integral_pseudo,nucl_num,nucl_charge, & + !$OMP klocmax,lmax,kmax,v_k,n_k, dz_k, n_kl, v_kl, dz_kl, & + !$OMP wall_1) + + !$OMP DO SCHEDULE (guided) + + do j = 1, ao_num + + num_A = ao_nucl(j) + power_A(1:3)= ao_power(j,1:3) + A_center(1:3) = nucl_coord(num_A,1:3) + + do i = 1, ao_num + + num_B = ao_nucl(i) + power_B(1:3)= ao_power(i,1:3) + B_center(1:3) = nucl_coord(num_B,1:3) + + do l=1,ao_prim_num(j) + alpha = ao_expo_ordered_transp(l,j) + + do m=1,ao_prim_num(i) + beta = ao_expo_ordered_transp(m,i) + double precision :: c + c = 0.d0 + + do k = 1, nucl_num + double precision :: Z + Z = nucl_charge(k) + + C_center(1:3) = nucl_coord(k,1:3) + + v_k_dump = v_k(k,1:klocmax) + n_k_dump = n_k(k,1:klocmax) + dz_k_dump = dz_k(k,1:klocmax) + + c = c + Vloc(klocmax, v_k_dump,n_k_dump, dz_k_dump, & + A_center,power_A,alpha,B_center,power_B,beta,C_center) + + + n_kl_dump = n_kl(k,1:kmax,0:lmax) + v_kl_dump = v_kl(k,1:kmax,0:lmax) + dz_kl_dump = dz_kl(k,1:kmax,0:lmax) + + c = c + Vpseudo(lmax,kmax,v_kl_dump,n_kl_dump,dz_kl_dump,A_center,power_A,alpha,B_center,power_B,beta,C_center) + + enddo + ao_nucl_elec_integral_pseudo(i,j) = ao_nucl_elec_integral_pseudo(i,j) + & + ao_coef_normalized_ordered_transp(l,j)*ao_coef_normalized_ordered_transp(m,i)*c + enddo + enddo + enddo + + call wall_time(wall_2) + if (thread_num == 0) then + if (wall_2 - wall_0 > 1.d0) then + wall_0 = wall_2 + write(output_monoints,*) 100.*float(j)/float(ao_num), '% in ', & + wall_2-wall_1, 's' + endif + endif + enddo + + !$OMP END DO + !$OMP END PARALLEL + + +! _ +! | \ _ _. | | _ _ _. _|_ _ +! |_/ (/_ (_| | | (_) (_ (_| |_ (/_ +! + + deallocate(n_k,v_k, dz_k) + deallocate(n_k_dump,v_k_dump, dz_k_dump) + + deallocate(n_kl,v_kl, dz_kl) + deallocate(n_kl_dump,v_kl_dump, dz_kl_dump) + + +END_PROVIDER diff --git a/src/Pseudo_integrals/pseudo.ezfio_config b/src/Pseudo_integrals/pseudo.ezfio_config new file mode 100644 index 00000000..a01bc2c0 --- /dev/null +++ b/src/Pseudo_integrals/pseudo.ezfio_config @@ -0,0 +1,10 @@ +pseudo_integrals + klocmax integer + v_k double precision (nuclei_nucl_num,pseudo_integrals_klocmax) + n_k integer (nuclei_nucl_num,pseudo_integrals_klocmax) + dz_k double precision (nuclei_nucl_num,pseudo_integrals_klocmax) + lmaxpo integer + kmax integer + v_kl double precision (nuclei_nucl_num,pseudo_integrals_kmax,pseudo_integrals_lmaxpo) + n_kl integer (nuclei_nucl_num,pseudo_integrals_kmax,pseudo_integrals_lmaxpo) + dz_kl double precision (nuclei_nucl_num,pseudo_integrals_kmax,pseudo_integrals_lmaxpo) diff --git a/src/Selectors_full/NEEDED_CHILDREN_MODULES b/src/Selectors_full/NEEDED_CHILDREN_MODULES new file mode 100644 index 00000000..54f54203 --- /dev/null +++ b/src/Selectors_full/NEEDED_CHILDREN_MODULES @@ -0,0 +1 @@ +Determinants Hartree_Fock diff --git a/src/Selectors_full/NEEDED_MODULES b/src/Selectors_full/NEEDED_MODULES deleted file mode 100644 index a848a687..00000000 --- a/src/Selectors_full/NEEDED_MODULES +++ /dev/null @@ -1,2 +0,0 @@ -AOs Bielec_integrals Bitmask Determinants Electrons Ezfio_files Hartree_Fock MOGuess MonoInts MOs Nuclei Output Utils - diff --git a/src/Selectors_full/README.rst b/src/Selectors_full/README.rst index 2ca9380a..11286fce 100644 --- a/src/Selectors_full/README.rst +++ b/src/Selectors_full/README.rst @@ -165,17 +165,6 @@ Needed Modules .. Do not edit this section. It was auto-generated from the .. NEEDED_MODULES file. -* `AOs `_ -* `Bielec_integrals `_ -* `Bitmask `_ * `Determinants `_ -* `Electrons `_ -* `Ezfio_files `_ * `Hartree_Fock `_ -* `MOGuess `_ -* `MonoInts `_ -* `MOs `_ -* `Nuclei `_ -* `Output `_ -* `Utils `_ diff --git a/src/Selectors_no_sorted/NEEDED_CHILDREN_MODULES b/src/Selectors_no_sorted/NEEDED_CHILDREN_MODULES new file mode 100644 index 00000000..aae89501 --- /dev/null +++ b/src/Selectors_no_sorted/NEEDED_CHILDREN_MODULES @@ -0,0 +1 @@ +Determinants diff --git a/src/Selectors_no_sorted/NEEDED_MODULES b/src/Selectors_no_sorted/NEEDED_MODULES deleted file mode 100644 index c5e6c2d3..00000000 --- a/src/Selectors_no_sorted/NEEDED_MODULES +++ /dev/null @@ -1 +0,0 @@ -AOs Bielec_integrals Bitmask Determinants Electrons Ezfio_files MonoInts MOs Nuclei Output Utils diff --git a/src/SingleRefMethod/NEEDED_CHILDREN_MODULES b/src/SingleRefMethod/NEEDED_CHILDREN_MODULES new file mode 100644 index 00000000..bf459a13 --- /dev/null +++ b/src/SingleRefMethod/NEEDED_CHILDREN_MODULES @@ -0,0 +1 @@ +Bitmask diff --git a/src/SingleRefMethod/NEEDED_MODULES b/src/SingleRefMethod/NEEDED_MODULES deleted file mode 100644 index bdcbdf7d..00000000 --- a/src/SingleRefMethod/NEEDED_MODULES +++ /dev/null @@ -1 +0,0 @@ -AOs Bitmask Electrons Ezfio_files MOs Nuclei Output Utils diff --git a/src/Utils/NEEDED_CHILDREN_MODULES b/src/Utils/NEEDED_CHILDREN_MODULES new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/src/Utils/NEEDED_CHILDREN_MODULES @@ -0,0 +1 @@ + diff --git a/src/Utils/README.rst b/src/Utils/README.rst index 68a4f080..ff16f3ed 100644 --- a/src/Utils/README.rst +++ b/src/Utils/README.rst @@ -160,6 +160,39 @@ Documentation `rint_sum `_ Needed for the calculation of two-electron integrals. +`a_coef `_ + Undocumented + +`b_coef `_ + Undocumented + +`ddfact2 `_ + Undocumented + +`erf0 `_ + Undocumented + +`gammln `_ + Undocumented + +`gammp `_ + Undocumented + +`gcf `_ + Undocumented + +`gser `_ + Undocumented + +`rinteg `_ + Undocumented + +`rintgauss `_ + Undocumented + +`sabpartial `_ + Undocumented + `overlap_a_b_c `_ Undocumented diff --git a/src/Properties/need.irp.f b/src/Utils/need.irp.f similarity index 100% rename from src/Properties/need.irp.f rename to src/Utils/need.irp.f diff --git a/src/Utils/util.irp.f b/src/Utils/util.irp.f index 1186d789..7a78ad59 100644 --- a/src/Utils/util.irp.f +++ b/src/Utils/util.irp.f @@ -134,7 +134,46 @@ BEGIN_PROVIDER [ double precision, fact_inv, (128) ] enddo END_PROVIDER -double precision function dble_fact(n) result(fact2) + +double precision function dble_fact(n) + implicit none + integer :: n + double precision :: dble_fact_peer, dble_fact_odd + + dble_fact = 1.d0 + + if(n.lt.0) return + + if(iand(n,1).eq.0)then + dble_fact = dble_fact_peer(n) + else + dble_fact= dble_fact_odd(n) + endif + +end function + +double precision function dble_fact_peer(n) result(fact2) + implicit none + BEGIN_DOC + ! n!! + END_DOC + integer :: n,k + double precision, save :: memo(1:100) + integer, save :: memomax = 2 + double precision :: prod + + ASSERT (iand(n,1) /= 1) + + prod=1.d0 + do k=2,n,2 + prod=prod*dfloat(k) + enddo + fact2=prod + return + +end function + +double precision function dble_fact_odd(n) result(fact2) implicit none BEGIN_DOC ! n!! diff --git a/tests/HBO.xyz b/tests/HBO.xyz new file mode 100644 index 00000000..796a1e19 --- /dev/null +++ b/tests/HBO.xyz @@ -0,0 +1,5 @@ +3 +HBO Geo: Experiment Mult: 1 symmetry: 14 +B 0.0 0.0 1.166 +H 0.0 0.0 0.0 +O 0.0 0.0 2.366 diff --git a/tests/SO2.xyz b/tests/SO2.xyz new file mode 100644 index 00000000..5b6fca03 --- /dev/null +++ b/tests/SO2.xyz @@ -0,0 +1,5 @@ +3 +SO2 Geo: Experiment Mult: 1 symmetry: 32 +O 0.0 1.2371 0.7215 +O 0.0 -1.2371 0.7215 +S 0.0 0.0 0.0 diff --git a/tests/unit_test/unit_test.py b/tests/unit_test/unit_test.py index c01b4974..23e831ec 100755 --- a/tests/unit_test/unit_test.py +++ b/tests/unit_test/unit_test.py @@ -12,12 +12,15 @@ sys.path = [EZFIO + "/Python"] + sys.path from ezfio import ezfio from collections import defaultdict +from collections import namedtuple + +Energy = namedtuple('Energy', ['without_pseudo', 'with_pseudo']) # ~#~#~ # # O p t # # ~#~#~ # -precision = 5.e-8 +precision = 1.e-7 # A test get a geo file and a basis file. # A global dict containt the result for this test @@ -34,7 +37,7 @@ has_hf_alredy = False global filename_check -def init_folder(geo, basis, mult=1, ezfio_name=None): +def init_folder(geo, basis, mult=1, pseudo=False, ezfio_name=None): ''' Take a geo in arg (aka a existing geo.xyz in test/) And create the geo.ezfio with the adeguate basis and multipliciti @@ -47,15 +50,21 @@ def init_folder(geo, basis, mult=1, ezfio_name=None): if not ezfio_name: ezfio_name = geo - cmd = "qp_create_ezfio_from_xyz -b {0} -m {1} {2}.xyz -o {3}.ezfio" + if pseudo: + cmd = "qp_create_ezfio_from_xyz -b {0} -m {1} {2}.xyz -p -o {3}.ezfio" + else: + cmd = "qp_create_ezfio_from_xyz -b {0} -m {1} {2}.xyz -o {3}.ezfio" + subprocess.check_call([cmd.format(basis, mult, geo, ezfio_name)], shell=True) + subprocess.call(["rm {0}.xyz".format(geo)], shell=True) + def get_error_message(l_exepected, l_cur): l_msg = ["Need {0} get {1} error is {2}".format(i, j, abs(i - j)) for i, j in zip(l_exepected, l_cur)] - return "\n".join(l_msg) + return "\n" + "\n".join(l_msg) # _ @@ -146,18 +155,21 @@ def check_mo_guess(geo, basis, mult=1): # / |_ _ _ | _. | _ _ # \_ | | (/_ (_ |< \/ (_| | |_| (/_ _> # -def run_hf(geo, basis, mult=1): +def run_hf(geo, basis, mult=1, pseudo=False, remove_after_sucess=True): """ Run a simle by default hf EZFIO path = geo.ezfio """ + # ~#~#~#~#~#~#~#~#~#~ # # R e f _ e n e r g y # # ~#~#~#~#~#~#~#~#~#~ # - ref_energy = defaultdict(dict) + ref_energy = defaultdict(defaultdict) - ref_energy["sto-3g"]["methane"] = -39.7267433402 + ref_energy["sto-3g"]["methane"] = Energy(-39.7267433402, None) + ref_energy["vdz"]["SO2"] = Energy(None, -41.48912297776174) + ref_energy["vdz"]["HBO"] = Energy(None, -19.11982540413317) # ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~ # # G l o b a l _ v a r i a b l e # @@ -170,7 +182,7 @@ def run_hf(geo, basis, mult=1): # I n i t # # ~#~#~#~ # - init_folder(geo, basis, mult) + init_folder(geo, basis, mult, pseudo) ezfio.set_file("{0}.ezfio".format(geo)) # ~#~#~#~#~#~#~#~#~#~#~#~#~ # @@ -187,6 +199,8 @@ def run_hf(geo, basis, mult=1): ezfio.hartree_fock_thresh_scf = 1.e-10 ezfio.hartree_fock_n_it_scf_max = 100 + ezfio.pseudo_integrals_do_pseudo = pseudo + # ~#~#~ # # R u n # # ~#~#~ # @@ -199,15 +213,25 @@ def run_hf(geo, basis, mult=1): # ~#~#~#~#~ # cur_e = ezfio.get_hartree_fock_energy() + ref_e = ref_energy[basis][geo] + if pseudo: + ref_e = ref_e.with_pseudo + else: + ref_e = ref_e.without_pseudo if abs(cur_e - ref_e) <= precision: + + if remove_after_sucess: + subprocess.call(["rm -R {0}.ezfio".format(geo)], shell=True) + return True + else: raise ValueError(get_error_message([ref_e], [cur_e])) -def run_full_ci_10k_pt2_end(geo, basis): +def run_full_ci_10k_pt2_end(geo, basis, pseudo): """ Run a Full_ci with 10k with the TruePT2 EZFIO path = geo.ezfio @@ -220,8 +244,8 @@ def run_full_ci_10k_pt2_end(geo, 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 + ref_energy_var["sto-3g"]["methane"] = Energy(-0.398058753535695E+02, None) + ref_energy_pt2["sto-3g"]["methane"] = Energy(-0.398059182483741E+02, None) # ~#~#~#~ # # I n i t # @@ -254,6 +278,13 @@ def run_full_ci_10k_pt2_end(geo, basis): ref_var = ref_energy_var[basis][geo] ref_pt2 = ref_energy_pt2[basis][geo] + if pseudo: + ref_var = ref_var.with_pseudo + ref_pt2 = ref_pt2.with_pseudo + else: + ref_var = ref_var.without_pseudo + ref_pt2 = ref_pt2.without_pseudo + t = [abs(cur_var - ref_var) <= precision, abs(cur_pt2 - ref_pt2) <= precision] @@ -264,15 +295,16 @@ def run_full_ci_10k_pt2_end(geo, basis): [cur_var, cur_pt2])) -def hf_then_10k_test(geo, basis): - if not has_hf_alredy: - run_hf(geo, basis) +def hf_then_10k_test(geo, basis, mult=1, pseudo=False): + + run_hf(geo, basis, mult, pseudo, remove_after_sucess=False) try: - run_full_ci_10k_pt2_end(geo, basis) - return_code = True + run_full_ci_10k_pt2_end(geo, basis, pseudo) except: - return_code = False + raise + else: + return_code = True # ~#~#~#~#~#~#~#~ # # F i n a l i z e # @@ -333,15 +365,27 @@ def check_convert(path_out): else: raise ValueError(get_error_message([ref_e], [cur_e])) + # ___ # | _ _ _|_ # | (/_ _> |_ # class ValueTest(unittest.TestCase): - def test_full_ci_10k_pt2_end(self): - self.assertTrue(hf_then_10k_test("methane", "sto-3g")) + def test_hf_then_full_ci_10k_pt2_end(self): + self.assertTrue(hf_then_10k_test(geo="methane", + basis="sto-3g", + mult=1, + pseudo=False)) + def test_hf(self): + self.assertTrue(run_hf(geo="HBO", + basis="vdz", + mult=1, + pseudo=True)) + + +class ConvertTest(unittest.TestCase): def test_check_convert_hf_energy(self): self.assertTrue(check_convert("HBO.out")) @@ -349,11 +393,12 @@ class ValueTest(unittest.TestCase): class InputTest(unittest.TestCase): def test_check_disk_acess(self): - self.assertTrue(check_disk_acess("methane", "un-ccemd-ref")) + self.assertTrue(check_disk_acess(geo="methane", + basis="un-ccemd-ref")) def test_check_mo_guess(self): - self.assertTrue(check_mo_guess("methane", "maug-cc-pVDZ")) - + self.assertTrue(check_mo_guess(geo="methane", + basis="maug-cc-pVDZ")) if __name__ == '__main__': unittest.main()