From 1cff15163d52f73d6a4f035d69befc0ca08a25b7 Mon Sep 17 00:00:00 2001 From: Murat Keceli Date: Fri, 24 May 2024 06:27:24 +0000 Subject: [PATCH 1/5] Add ASE to elstruct reader program_modules --- .../elstruct/reader/program_modules.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/autoio-interfaces/elstruct/reader/program_modules.py b/autoio-interfaces/elstruct/reader/program_modules.py index 91e8023..bf60551 100644 --- a/autoio-interfaces/elstruct/reader/program_modules.py +++ b/autoio-interfaces/elstruct/reader/program_modules.py @@ -22,6 +22,8 @@ def _rename_prog(prog): prog = 'molpro2015' elif prog in ('gaussian03'): prog = 'gaussian09' + elif prog.startswith('ase'): + prog = 'ase' return prog new_name = _rename_prog(prog) @@ -83,6 +85,27 @@ class Job(): # Dictionaries that dictate what writer/reader functionality READER_MODULE_DCT = { + par.Program.ASE: ( + Job.ENERGY, Job.GRADIENT, + Job.OPT_GEO, Job.OPT_ZMA, + Job.EXIT_MSG, Job.ERR_LST, Job.SUCCESS_LST, + Job.ERR_MSG, Job.CONV_MSG, + Job.PROG_NAME, Job.PROG_VERS + ), + par.Program.ASE_PSI4: ( + Job.ENERGY, Job.GRADIENT, + Job.OPT_GEO, Job.OPT_ZMA, + Job.EXIT_MSG, Job.ERR_LST, Job.SUCCESS_LST, + Job.ERR_MSG, Job.CONV_MSG, + Job.PROG_NAME, Job.PROG_VERS + ), + par.Program.ASE_NWX: ( + Job.ENERGY, Job.GRADIENT, + Job.OPT_GEO, Job.OPT_ZMA, + Job.EXIT_MSG, Job.ERR_LST, Job.SUCCESS_LST, + Job.ERR_MSG, Job.CONV_MSG, + Job.PROG_NAME, Job.PROG_VERS + ), par.Program.CFOUR2: ( Job.ENERGY, Job.GRADIENT, Job.OPT_GEO, Job.OPT_ZMA, From 2bf1ae8eae745d617f8fc24d085b817768443dcb Mon Sep 17 00:00:00 2001 From: Murat Keceli Date: Fri, 24 May 2024 06:28:57 +0000 Subject: [PATCH 2/5] Add ASE run into direct function --- autoio-interfaces/elstruct/par.py | 3 ++ autoio-interfaces/elstruct/run.py | 50 ++++++++++++++++++++++++++----- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/autoio-interfaces/elstruct/par.py b/autoio-interfaces/elstruct/par.py index 04ceb98..179f8b9 100644 --- a/autoio-interfaces/elstruct/par.py +++ b/autoio-interfaces/elstruct/par.py @@ -24,6 +24,9 @@ class Module(): class Program(): """ Programs supported in elstruct """ + ASE = 'ase' + ASE_PSI4 = 'ase_psi4' + ASE_NWX = 'ase_nwx' CFOUR2 = 'cfour2' GAUSSIAN09 = 'gaussian09' GAUSSIAN03 = 'gaussian03' diff --git a/autoio-interfaces/elstruct/run.py b/autoio-interfaces/elstruct/run.py index 9cca5b4..53b055e 100644 --- a/autoio-interfaces/elstruct/run.py +++ b/autoio-interfaces/elstruct/run.py @@ -1,8 +1,11 @@ """ core run function """ +from email.mime import audio from autorun import from_input_string - +import automol +import ase +from ase.units import Hartree def direct(input_writer, script_str, run_dir, prog, geo, charge, mult, method, basis, **kwargs): @@ -29,13 +32,44 @@ def direct(input_writer, script_str, run_dir, prog, :returns: the input string, the output string, and the run directory :rtype: (str, str) """ + if prog.startswith('ase'): + atoms = geom_to_atoms(geo) + tokens = prog.split('_') + if len(tokens) > 1: + calculator = tokens[1] + else: + pass + if calculator == 'psi4': + from ase.calculators.psi4 import Psi4 + calc = Psi4() + calc.parameters['basis'] = basis + calc.parameters['method'] = method + calc.parameters['multiplicity'] = mult + atoms.calc = calc + atoms.get_potential_energy() + version_str = f'ase_{ase.__version__}-psi4_{calc.psi4.__version__}' + calc.results['version'] = version_str + input_str = str(calc.parameters) + output_str = str(calc.results) + else: + input_str = input_writer( + prog=prog, + geo=geo, charge=charge, mult=mult, method=method, basis=basis, + **kwargs) - input_str = input_writer( - prog=prog, - geo=geo, charge=charge, mult=mult, method=method, basis=basis, - **kwargs) - - output_strs = from_input_string(script_str, run_dir, input_str) - output_str = output_strs[0] + output_strs = from_input_string(script_str, run_dir, input_str) + output_str = output_strs[0] return input_str, output_str + + +def geom_to_atoms(geo): + from ase import Atoms + if automol.zmat.is_valid(geo): + geo = automol.zmat.geometry(geo) + atoms = Atoms(symbols = automol.geom.symbols(geo), positions = automol.geom.coordinates(geo, angstrom=True) ) + return atoms + + +def atoms_to_geom(atoms): + pass \ No newline at end of file From 209dc92e43e302d37bcbf02446a3535970731aff Mon Sep 17 00:00:00 2001 From: Murat Keceli Date: Fri, 24 May 2024 06:35:09 +0000 Subject: [PATCH 3/5] Add ASE readers --- .../elstruct/reader/_ase/__init__.py | 21 ++++++++++++++++ .../elstruct/reader/_ase/status.py | 25 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 autoio-interfaces/elstruct/reader/_ase/__init__.py create mode 100644 autoio-interfaces/elstruct/reader/_ase/status.py diff --git a/autoio-interfaces/elstruct/reader/_ase/__init__.py b/autoio-interfaces/elstruct/reader/_ase/__init__.py new file mode 100644 index 0000000..516cf6f --- /dev/null +++ b/autoio-interfaces/elstruct/reader/_ase/__init__.py @@ -0,0 +1,21 @@ +from elstruct.reader._ase.status import has_normal_exit_message, check_convergence_messages +from ase.units import Hartree +import ase +from ase.calculators.psi4 import Psi4 + +def program_version(out_str): + import ast + results = ast.literal_eval(out_str) + return results['version'] + +def energy(method, out_str): + import ast + results = ast.literal_eval(out_str) + return results['energy'] / Hartree + +__all__ = [ + + 'has_normal_exit_message', + 'check_convergence_messages', +'program_version' +] diff --git a/autoio-interfaces/elstruct/reader/_ase/status.py b/autoio-interfaces/elstruct/reader/_ase/status.py new file mode 100644 index 0000000..cd566f9 --- /dev/null +++ b/autoio-interfaces/elstruct/reader/_ase/status.py @@ -0,0 +1,25 @@ +""" status checkers +""" +import autoparse.pattern as app +import autoparse.find as apf +import elstruct.par + + +# Exit message for the program +def has_normal_exit_message(output_str): + """ does this output string have a normal exit message? + """ + return True + # pattern = app.escape('*** ASE exiting successfully.') + # return apf.has_match(pattern, output_str, case=False) + +def check_convergence_messages(error, success, output_str): + """ Assess whether the output file string contains messages + denoting all of the requested procedures in the job have converged. + + :param output_str: string of the program's output file + :type output_str: str + :rtype: bool + """ + + return True \ No newline at end of file From 3528d0d72f6c0f792fe10020db7e9c7b945ae2b4 Mon Sep 17 00:00:00 2001 From: Murat Keceli Date: Fri, 24 May 2024 06:43:13 +0000 Subject: [PATCH 4/5] Move ev to Hartree conversion to run --- autoio-interfaces/elstruct/reader/_ase/__init__.py | 5 +---- autoio-interfaces/elstruct/run.py | 1 + 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/autoio-interfaces/elstruct/reader/_ase/__init__.py b/autoio-interfaces/elstruct/reader/_ase/__init__.py index 516cf6f..858b3a7 100644 --- a/autoio-interfaces/elstruct/reader/_ase/__init__.py +++ b/autoio-interfaces/elstruct/reader/_ase/__init__.py @@ -1,7 +1,4 @@ from elstruct.reader._ase.status import has_normal_exit_message, check_convergence_messages -from ase.units import Hartree -import ase -from ase.calculators.psi4 import Psi4 def program_version(out_str): import ast @@ -11,7 +8,7 @@ def program_version(out_str): def energy(method, out_str): import ast results = ast.literal_eval(out_str) - return results['energy'] / Hartree + return results['energy'] __all__ = [ diff --git a/autoio-interfaces/elstruct/run.py b/autoio-interfaces/elstruct/run.py index 53b055e..9b68a84 100644 --- a/autoio-interfaces/elstruct/run.py +++ b/autoio-interfaces/elstruct/run.py @@ -49,6 +49,7 @@ def direct(input_writer, script_str, run_dir, prog, atoms.get_potential_energy() version_str = f'ase_{ase.__version__}-psi4_{calc.psi4.__version__}' calc.results['version'] = version_str + calc.results['energy'] = calc.results['energy'] / Hartree input_str = str(calc.parameters) output_str = str(calc.results) else: From 4e1d388ddaf15d1421f4c9f2566c1e1386e56a1e Mon Sep 17 00:00:00 2001 From: Murat Keceli Date: Fri, 24 May 2024 06:53:49 +0000 Subject: [PATCH 5/5] Remove import --- autoio-interfaces/elstruct/run.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/autoio-interfaces/elstruct/run.py b/autoio-interfaces/elstruct/run.py index 9b68a84..fd8379b 100644 --- a/autoio-interfaces/elstruct/run.py +++ b/autoio-interfaces/elstruct/run.py @@ -1,7 +1,6 @@ """ core run function """ -from email.mime import audio from autorun import from_input_string import automol import ase @@ -73,4 +72,4 @@ def geom_to_atoms(geo): def atoms_to_geom(atoms): - pass \ No newline at end of file + pass