From 04efd69700daf72384b40b28835c8465619cd3c7 Mon Sep 17 00:00:00 2001 From: Kohei Noda Date: Wed, 21 Jun 2023 23:59:58 +0900 Subject: [PATCH 1/5] Update yml --- .github/workflows/publish.yml | 13 +++++++++++-- .github/workflows/release-pr.yml | 3 +-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index b1bcefd..426db81 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -27,10 +27,19 @@ jobs: uses: pypa/gh-action-pypi-publish@release/v1 with: password: ${{ secrets.PYPI_API_TOKEN }} + - name: Get the tag name + id: get_tag_name + run: | + TAG_NAME=$(echo "${{ github.head_ref }}" | sed -e 's/release-//') + echo "tag_name=${TAG_NAME}" >> $GITHUB_ENV + - name: Create tag + run: | + git tag ${{ env.tag_name }} + git push origin ${{ env.tag_name }} - name: Create release uses: actions/create-release@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - tag_name: ${{ github.ref }} - release_name: ${{ github.ref }} + tag_name: ${{ env.tag_name }} + release_name: ${{ env.tag_name }} diff --git a/.github/workflows/release-pr.yml b/.github/workflows/release-pr.yml index a49f39a..8ca6c0e 100644 --- a/.github/workflows/release-pr.yml +++ b/.github/workflows/release-pr.yml @@ -1,4 +1,4 @@ -name: sum_dirac_dfcoef-release-pull-request +name: create-release-pull-request on: workflow_dispatch: @@ -63,7 +63,6 @@ jobs: git checkout -b "${{ env.BRANCH_NAME }}" git add . git commit -m "Release ${{ env.PACKAGE_NAME }} ${{ env.NEW_VERSION }}" - git tag "${{ env.TAG_NAME }}" git push origin "${{ env.BRANCH_NAME }}" gh pr create --title "Release ${{ env.PACKAGE_NAME }} ${{ env.NEW_VERSION }}" --body "Release ${{ env.PACKAGE_NAME }} ${{ env.NEW_VERSION }}" env: From 04fd41497b15f2ddf797480e2429024175b8e98b Mon Sep 17 00:00:00 2001 From: Kohei Noda Date: Thu, 22 Jun 2023 00:31:23 +0900 Subject: [PATCH 2/5] Rename test --- test/{unit_test.py => integration_test.py} | 38 +++++++++------------- 1 file changed, 16 insertions(+), 22 deletions(-) rename test/{unit_test.py => integration_test.py} (91%) diff --git a/test/unit_test.py b/test/integration_test.py similarity index 91% rename from test/unit_test.py rename to test/integration_test.py index dc2f383..6f903dd 100644 --- a/test/unit_test.py +++ b/test/integration_test.py @@ -45,18 +45,15 @@ def test_sum_dirac_dfcoeff_compress(ref_filename: str, result_filename: str, inp result_filepath = os.path.join(test_path, "results", result_filename) input_filepath = os.path.join(test_path, "data", input_filename) - test_command = f"sum_dirac_dfcoef -m {mol} -i {input_filepath} {options}" + test_command = f"sum_dirac_dfcoef -m {mol} -i {input_filepath} -o {result_filepath} {options}" print(test_command) - with open(result_filepath, "w") as file_output: - process = subprocess.run( - test_command, - shell=True, - stdout=file_output, - encoding="utf-8", - stderr=file_output, - ) - if process.returncode != 0: - sys.exit(f"{test_command} failed with return code {process.returncode}") + process = subprocess.run( + test_command, + shell=True, + encoding="utf-8", + ) + if process.returncode != 0: + sys.exit(f"{test_command} failed with return code {process.returncode}") ref_file: "list[list[str]]" = [re.split(" +", line.rstrip("\n")) for line in list(filter(lambda val: val != "", open(ref_filepath, "r").read().splitlines()))] out_file: "list[list[str]]" = [re.split(" +", line.rstrip("\n")) for line in list(filter(lambda val: val != "", open(result_filepath, "r").read().splitlines()))] @@ -108,18 +105,15 @@ def test_sum_dirac_dfcoeff(ref_filename: str, result_filename: str, input_filena result_filepath = os.path.join(test_path, "results", result_filename) input_filepath = os.path.join(test_path, "data", input_filename) - test_command = f"sum_dirac_dfcoef -m {mol} -i {input_filepath} {options}" + test_command = f"sum_dirac_dfcoef -m {mol} -i {input_filepath} -o {result_filepath} {options}" print(test_command) - with open(result_filepath, "w") as file_output: - process = subprocess.run( - test_command, - shell=True, - stdout=file_output, - encoding="utf-8", - stderr=file_output, - ) - if process.returncode != 0: - sys.exit(f"{test_command} failed with return code {process.returncode}") + process = subprocess.run( + test_command, + shell=True, + encoding="utf-8", + ) + if process.returncode != 0: + sys.exit(f"{test_command} failed with return code {process.returncode}") ref_file: "list[list[str]]" = [re.split(" +", line.rstrip("\n")) for line in list(filter(lambda val: val != "", open(ref_filepath, "r").read().splitlines()))] out_file: "list[list[str]]" = [re.split(" +", line.rstrip("\n")) for line in list(filter(lambda val: val != "", open(result_filepath, "r").read().splitlines()))] From ac145a32af38ba7581b753146921bc241dbdbfbc Mon Sep 17 00:00:00 2001 From: Kohei Noda Date: Thu, 22 Jun 2023 00:34:08 +0900 Subject: [PATCH 3/5] Add -o, --output option --- README.md | 12 +++++++ src/sum_dirac_dfcoef/sum_dirac_dfcoef.py | 40 +++++++++++++++++------- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index e451f5a..c6d4eab 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,10 @@ pip install sum_dirac_dfcoef You can use this program with the following command! ```sh +# Output to MOLECULE_NAME.out /path/to/sum_dirac_dfcoef -i DIRAC_OUPUT_FILE_PATH -m MOLECULE_NAME +# Specify output file name with -o option +/path/to/sum_dirac_dfcoef -i DIRAC_OUPUT_FILE_PATH -m MOLECULE_NAME -o OUTPUT_FILE_NAME ``` (e.g.) @@ -115,6 +118,9 @@ optional arguments (--input and --mol are required) (required) molecule specification. Write the molecular formula (e.g. Cu2O). **DON'T write the rational formula (e.g. CH3OH)** +- -o OUTPUT, --output OUTPUT + Output file name. Default: (-m or --mol option value).out (e.g) --m H2O => print to H2O.out + - -c, --compress Compress output. Display all coefficients on one line for each MO. @@ -130,6 +136,12 @@ optional arguments (--input and --mol are required) Set the decimal places. Default: 5 (e.g) --decimal=3 => print orbital with 3 decimal places (0.123, 2.456, ...). range: 1-15 +- -a, --all-write + Print all MOs(Positronic and Electronic). + +- -p, --positronic-write + Print only Positronic MOs. + - --debug print debug output (Normalization constant, Sum of MO coefficient) diff --git a/src/sum_dirac_dfcoef/sum_dirac_dfcoef.py b/src/sum_dirac_dfcoef/sum_dirac_dfcoef.py index 507dfe8..6f60fb4 100755 --- a/src/sum_dirac_dfcoef/sum_dirac_dfcoef.py +++ b/src/sum_dirac_dfcoef/sum_dirac_dfcoef.py @@ -1,6 +1,8 @@ #!/usr/bin/env python3 import argparse +from io import TextIOWrapper +import os import re import sys @@ -85,6 +87,7 @@ def parse_args() -> "argparse.Namespace": parser = argparse.ArgumentParser(description="Summarize the coefficients from DIRAC output file that *PRIVEC option is used. (c.f. http://www.diracprogram.org/doc/master/manual/analyze/privec.html)") parser.add_argument("-i", "--input", type=str, required=True, help="(required) file name of DIRAC output", dest="file") parser.add_argument("-m", "--mol", type=str, required=True, help="(required) molecule specification. Write the molecular formula (e.g. Cu2O). ** DON'T write the rational formula (e.g. CH3OH) **") + parser.add_argument("-o", "--output", type=str, help="Output file name. Default: (-m or --mol option value).out (e.g) --m H2O => print to H2O.out", dest="output") parser.add_argument("-c", "--compress", action="store_true", help="Compress output. Display all coefficients on one line for each MO. This options is useful when you want to use the result in a spreadsheet like Microsoft Excel.", dest="compress") parser.add_argument("-t", "--threshold", type=float, default=0.1, help="threshold. Default: 0.1 %% (e.g) --threshold=0.1 => print orbital with more than 0.1 %% contribution", dest="threshold") parser.add_argument("-d", "--decimal", type=int, default=5, choices=range(1, 16), help="Set the decimal places. Default: 5 (e.g) --decimal=3 => print orbital with 3 decimal places (0.123, 2.456, ...). range: 1-15", dest="decimal") @@ -342,28 +345,38 @@ def check_end_vector_print( return False -def write_results(args: "argparse.Namespace", data_all_mo: "list[Data_per_MO]") -> None: +def get_output_path(args: "argparse.Namespace") -> str: + if args.output is None: + output_name = f"{args.mol}.out" + output_path = os.path.join(os.getcwd(), output_name) + else: + output_name = args.output + output_path = os.path.abspath(output_name) + return output_path + + +def write_results(args: "argparse.Namespace", file: TextIOWrapper, data_all_mo: "list[Data_per_MO]") -> None: """ Write results to stdout """ + for mo in data_all_mo: digit_int = len(str(int(mo.mo_energy))) # number of digits of integer part - print( - f"{mo.mo_info} {mo.mo_energy:{digit_int}.{args.decimal}f}", - end="" if args.compress else "\n", - ) + # File write but if args.compress is True \n is not added + mo_info_energy = f"{mo.mo_info} {mo.mo_energy:{digit_int}.{args.decimal}f}" + ("\n" if not args.compress else "") + file.write(mo_info_energy) d: Data_per_orbital_types for d in mo.data_per_orbital_types: if args.compress: orb_type = str(d.orbital_type) output_str = f" {orb_type} {d.mo_percentage:.{args.decimal}f}" - print(output_str, end="") + file.write(output_str) else: orb_type = str(d.orbital_type).ljust(11, " ") - output_str = f"{orb_type} {d.mo_percentage:{args.decimal+4}.{args.decimal}f} %" - print(output_str) - print() # "\n" + output_str = f"{orb_type} {d.mo_percentage:{args.decimal+4}.{args.decimal}f} %\n" + file.write(output_str) + file.write("\n") # add empty line debug_print_wrapper(args, f"Normalization constant is {mo.norm_constant:.{args.decimal}f}") debug_print_wrapper(args, f"sum of coefficient {mo.sum_coefficients:.{args.decimal}f}") @@ -472,12 +485,15 @@ def main() -> None: is_reading_coefficients = True get_coefficient(words, atoms, coefficients, elements) # End of reading file + output_path = get_output_path(args) + file = open(output_path, "w") if args.all_write or args.positronic_write: if not args.no_sort: data_all_positronic_mo.sort(key=lambda x: x.mo_energy) - write_results(args, data_all_positronic_mo) - print() # Add a blank line + write_results(args, file, data_all_positronic_mo) + file.write("\n") # Add a blank line if args.all_write or not args.positronic_write: # Electronic if not args.no_sort: data_all_electronic_mo.sort(key=lambda x: x.mo_energy) - write_results(args, data_all_electronic_mo) + write_results(args, file, data_all_electronic_mo) + file.close() From a25fc6975f96fbd18491cc9bc1873e4bbcfdabb1 Mon Sep 17 00:00:00 2001 From: Kohei Noda Date: Thu, 22 Jun 2023 00:37:26 +0900 Subject: [PATCH 4/5] Fix usage --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c6d4eab..6cb8d15 100644 --- a/README.md +++ b/README.md @@ -21,15 +21,15 @@ You can use this program with the following command! ```sh # Output to MOLECULE_NAME.out -/path/to/sum_dirac_dfcoef -i DIRAC_OUPUT_FILE_PATH -m MOLECULE_NAME +sum_dirac_dfcoef -i DIRAC_OUPUT_FILE_PATH -m MOLECULE_NAME # Specify output file name with -o option -/path/to/sum_dirac_dfcoef -i DIRAC_OUPUT_FILE_PATH -m MOLECULE_NAME -o OUTPUT_FILE_NAME +sum_dirac_dfcoef -i DIRAC_OUPUT_FILE_PATH -m MOLECULE_NAME -o OUTPUT_FILE_NAME ``` (e.g.) ```sh -./sum_dirac_dfcoef -i x2c_uo2_238.out -m UO2 +sum_dirac_dfcoef -i x2c_uo2_238.out -m UO2 ``` A part of x2c_uo2_238.out (DIRAC output file, ... represents an omission) From 7093849cebb82a6063d174fab0067a7c78c9f99e Mon Sep 17 00:00:00 2001 From: Kohei Noda Date: Thu, 22 Jun 2023 00:40:22 +0900 Subject: [PATCH 5/5] Delete elements from parse_molecule_input --- src/sum_dirac_dfcoef/sum_dirac_dfcoef.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sum_dirac_dfcoef/sum_dirac_dfcoef.py b/src/sum_dirac_dfcoef/sum_dirac_dfcoef.py index 6f60fb4..a493656 100755 --- a/src/sum_dirac_dfcoef/sum_dirac_dfcoef.py +++ b/src/sum_dirac_dfcoef/sum_dirac_dfcoef.py @@ -151,7 +151,7 @@ def space_separated_parsing(line: str) -> "list[str]": return [word for word in words if word != ""] -def parse_molecule_input(args: "argparse.Namespace", elements: "list[str]") -> Atoms: +def parse_molecule_input(args: "argparse.Namespace") -> Atoms: """ Parse the molecule input and return the Atoms object. @@ -397,7 +397,7 @@ def main() -> None: args: "argparse.Namespace" = parse_args() dirac_file: str = get_dirac_filename(args) - atoms: Atoms = parse_molecule_input(args, elements) + atoms: Atoms = parse_molecule_input(args) data_all_electronic_mo: "list[Data_per_MO]" = [] data_all_positronic_mo: "list[Data_per_MO]" = []