├── .clang-format ├── .github └── workflows │ └── sonarcloud.yml ├── .travis.yml ├── CMakeLists.txt ├── LICENSE ├── README.md ├── docs ├── _config.yml └── images │ ├── BoltzmannConstant.jpg │ ├── CATNIPLong.png │ ├── DeltaG.jpg │ ├── Dimer1Ang.jpg │ ├── Dimer5Ang.jpg │ ├── Distance2VsJeff.jpg │ ├── Distance2VsJeffLog.jpg │ ├── DistanceVsJeff.jpg │ ├── DistanceVsJeffLog.jpg │ ├── Ei.jpg │ ├── Ej.jpg │ ├── Hab.jpg │ ├── J0.jpg │ ├── Jab.jpg │ ├── Marcus.jpg │ ├── MillerAndAbrahams.jpg │ ├── Temperature.jpg │ ├── TunnelingTerm.jpg │ ├── TunnelingTerm2.jpg │ ├── alpha.jpg │ ├── gamma.jpg │ ├── hbar.jpg │ ├── lambda.jpg │ ├── nu0.jpg │ └── rij.jpg ├── scripts ├── build.bash ├── deploy.bash ├── docker_clean.bash ├── release.bash ├── release_distros │ ├── centos7 │ │ └── Dockerfile │ ├── debian9 │ │ └── Dockerfile │ ├── fedora28 │ │ └── Dockerfile │ ├── package_release.bash │ └── ubuntu18 │ │ └── Dockerfile └── test_suite_install.bash ├── sonar-project.properties └── src ├── libcatnip ├── CMakeLists.txt ├── calcJconfig.hpp.in ├── constants.hpp ├── io │ ├── argumentparser.cpp │ ├── argumentparser.hpp │ ├── arguments │ │ ├── Makefile │ │ ├── README.md │ │ ├── argumentdouble.cpp │ │ ├── argumentdouble.hpp │ │ ├── argumentfile.cpp │ │ ├── argumentfile.hpp │ │ ├── argumentint.cpp │ │ ├── argumentint.hpp │ │ ├── argumentobject.hpp │ │ ├── argumentstring.cpp │ │ ├── argumentstring.hpp │ │ ├── argumentswitch.cpp │ │ ├── argumentswitch.hpp │ │ └── properties │ │ │ ├── propertydouble.cpp │ │ │ ├── propertydouble.hpp │ │ │ ├── propertyfileexist.cpp │ │ │ ├── propertyfileexist.hpp │ │ │ ├── propertyfileext.cpp │ │ │ ├── propertyfileext.hpp │ │ │ ├── propertyint.cpp │ │ │ ├── propertyint.hpp │ │ │ ├── propertyobject.hpp │ │ │ ├── propertysisterfile.cpp │ │ │ ├── propertysisterfile.hpp │ │ │ ├── propertystring.cpp │ │ │ ├── propertystring.hpp │ │ │ ├── propertystringchoice.cpp │ │ │ ├── propertystringchoice.hpp │ │ │ ├── propertyswitch.cpp │ │ │ └── propertyswitch.hpp │ ├── file_readers │ │ ├── filereader.cpp │ │ ├── filereader.hpp │ │ ├── logreader.cpp │ │ ├── logreader.hpp │ │ ├── punreader.cpp │ │ └── punreader.hpp │ ├── io.cpp │ └── io.hpp ├── log.hpp ├── matrix.cpp ├── matrix.hpp ├── parameters.cpp ├── parameters.hpp ├── qc_functions.cpp ├── qc_functions.hpp ├── string_support.cpp └── string_support.hpp ├── tests ├── CMakeLists.txt ├── test_argumentdouble.cpp ├── test_argumentfile.cpp ├── test_argumentint.cpp ├── test_argumentparser.cpp ├── test_argumentstring.cpp ├── test_argumentswitch.cpp ├── test_io.cpp ├── test_log.cpp ├── test_logreader.cpp ├── test_matrix.cpp ├── test_parameters.cpp ├── test_propertydouble.cpp ├── test_propertyfileexist.cpp ├── test_propertyfileext.cpp ├── test_propertyint.cpp ├── test_propertysisterfile.cpp ├── test_propertystring.cpp ├── test_propertystringchoice.cpp ├── test_propertyswitch.cpp ├── test_punreader.cpp ├── test_qc_functions.cpp ├── test_script_calc_J.sh ├── test_script_io.sh ├── test_string_support.cpp ├── testfile.log └── testfile.pun └── tools └── main.cpp /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | # BasedOnStyle: Google 3 | AccessModifierOffset: -1 4 | ConstructorInitializerIndentWidth: 4 5 | AlignConsecutiveAssignments: false 6 | AlignConsecutiveDeclarations: false 7 | AlignEscapedNewlinesLeft: true 8 | AlignTrailingComments: true 9 | AllowAllParametersOfDeclarationOnNextLine: true 10 | AlwaysBreakTemplateDeclarations: true 11 | AlwaysBreakBeforeMultilineStrings: true 12 | AllowShortIfStatementsOnASingleLine: true 13 | AllowShortLoopsOnASingleLine: true 14 | BreakBeforeBinaryOperators: false 15 | BreakBeforeTernaryOperators: true 16 | BreakConstructorInitializersBeforeComma: false 17 | BinPackParameters: true 18 | ColumnLimit: 80 19 | ConstructorInitializerAllOnOneLineOrOnePerLine: true 20 | DerivePointerBinding: true 21 | ExperimentalAutoDetectBinPacking: false 22 | IndentCaseLabels: true 23 | MaxEmptyLinesToKeep: 1 24 | NamespaceIndentation: None 25 | ObjCSpaceBeforeProtocolList: false 26 | PenaltyBreakBeforeFirstCallParameter: 1 27 | PenaltyBreakComment: 60 28 | PenaltyBreakString: 1000 29 | PenaltyBreakFirstLessLess: 120 30 | PenaltyExcessCharacter: 1000000 31 | PenaltyReturnTypeOnItsOwnLine: 200 32 | PointerBindsToType: true 33 | SpacesBeforeTrailingComments: 2 34 | Cpp11BracedListStyle: true 35 | Standard: Auto 36 | IndentWidth: 2 37 | TabWidth: 8 38 | UseTab: Never 39 | BreakBeforeBraces: Attach 40 | IndentFunctionDeclarationAfterType: true 41 | SpacesInParentheses: false 42 | SpacesInAngles: false 43 | SpaceInEmptyParentheses: false 44 | SpacesInCStyleCastParentheses: false 45 | SpaceAfterControlStatementKeyword: true 46 | SpaceBeforeAssignmentOperators: true 47 | ContinuationIndentWidth: 4 48 | ... 49 | -------------------------------------------------------------------------------- /.github/workflows/sonarcloud.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | on: 3 | push: 4 | branches: 5 | - master 6 | pull_request: 7 | types: [opened, synchronize, reopened] 8 | jobs: 9 | build: 10 | name: Build 11 | runs-on: ubuntu-latest 12 | env: 13 | SONAR_SCANNER_VERSION: 4.7.0.2747 14 | SONAR_SERVER_URL: "https://sonarcloud.io" 15 | BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed 16 | CFALGS: "-Wno-error" 17 | steps: 18 | - uses: actions/checkout@v2 19 | with: 20 | fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis 21 | - name: Set up JDK 11 22 | uses: actions/setup-java@v1 23 | with: 24 | java-version: 11 25 | - name: Download and set up sonar-scanner 26 | env: 27 | SONAR_SCANNER_DOWNLOAD_URL: https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${{ env.SONAR_SCANNER_VERSION }}-linux.zip 28 | run: | 29 | mkdir -p $HOME/.sonar 30 | curl -sSLo $HOME/.sonar/sonar-scanner.zip ${{ env.SONAR_SCANNER_DOWNLOAD_URL }} 31 | unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/ 32 | echo "$HOME/.sonar/sonar-scanner-${{ env.SONAR_SCANNER_VERSION }}-linux/bin" >> $GITHUB_PATH 33 | - name: Download and set up build-wrapper 34 | env: 35 | BUILD_WRAPPER_DOWNLOAD_URL: ${{ env.SONAR_SERVER_URL }}/static/cpp/build-wrapper-linux-x86.zip 36 | run: | 37 | curl -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip ${{ env.BUILD_WRAPPER_DOWNLOAD_URL }} 38 | unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/ 39 | echo "$HOME/.sonar/build-wrapper-linux-x86" >> $GITHUB_PATH 40 | - name: Run build-wrapper 41 | run: | 42 | mkdir build 43 | cmake -S . -B build 44 | build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build/ --config Release 45 | - name: Run sonar-scanner 46 | env: 47 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 48 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} 49 | run: | 50 | sonar-scanner --define sonar.host.url="${{ env.SONAR_SERVER_URL }}" --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" 51 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | 3 | dist: xenial 4 | addons: 5 | apt: 6 | update: true 7 | 8 | language: cpp 9 | 10 | compiler: 11 | - gcc 12 | - clang 13 | 14 | jobs: 15 | include: 16 | - stage: deploy 17 | compiler: gcc 18 | script: ./scripts/deploy.bash 19 | apt: 20 | packages: gcov 21 | packages: lcov 22 | 23 | before_install: 24 | - pwd 25 | - ls 26 | - ls scripts 27 | - chmod +x scripts/test_suite_install.bash 28 | - chmod +x scripts/deploy.bash 29 | 30 | install: 31 | - DEPS_DIR="${TRAVIS_BUILD_DIR}/deps" 32 | - mkdir ${DEPS_DIR} && cd ${DEPS_DIR} 33 | - | 34 | if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then 35 | CMAKE_URL="http://www.cmake.org/files/v3.3/cmake-3.3.2-Linux-x86_64.tar.gz" 36 | mkdir cmake && travis_retry wget --no-check-certificate --quiet -O - ${CMAKE_URL} | tar --strip-components=1 -xz -C cmake 37 | export PATH=${DEPS_DIR}/cmake/bin:${PATH} 38 | fi 39 | 40 | # Go to the Root directory 41 | - cd .. 42 | 43 | script: 44 | - mkdir build 45 | - cd build 46 | - ${DEPS_DIR}/cmake/bin/cmake -DENABLE_INTEGRATION_TESTS=ON -DENABLE_TESTS=ON .. && make && ctest --verbose 47 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 2.8) 2 | project (calc_J) 3 | 4 | ############################################################################## 5 | # Defining options 6 | ############################################################################## 7 | option(DOWNLOAD_TUTORIAL_FILES "Download tutorial files" OFF) 8 | option(ENABLE_INTEGRATION_TESTS "Enable integration tests" OFF) 9 | option(ENABLE_TESTS "Enable tests" OFF) 10 | option(CODE_COVERAGE "Enable coverage reporting" OFF) 11 | 12 | ############################################################################## 13 | # Defining settings 14 | ############################################################################## 15 | set(calcJ_VERSION_MAJOR 1 ) 16 | set(calcJ_VERSION_MINOR 9 ) 17 | set(calcJ_YEAR_PUBLISHED 2018 ) 18 | set(calcJ_AUTHOR_SURNAME "\"Brown\"" ) 19 | set(calcJ_AUTHOR_INITIALS "\"J. S.\"" ) 20 | set(calcJ_TITLE "\"CATNIP\"") 21 | set(calcJ_URL "\"https://github.com/JoshuaSBrown/QC_Tools\"" ) 22 | set(COVERAGE_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage") 23 | set(COMMON_LIBRARIES stdc++ m) 24 | set(LOG_LEVEL 0 CACHE INT "Choose the log level" ) 25 | # Prevents multiple file extensions from being appended one after the other 26 | # important for using gcov .o.gcno or .cpp.gcno now will be .gcno 27 | set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE 1) 28 | set(CMAKE_CXX_FLAGS "-Wall -Wextra -std=c++11 -pedantic") 29 | 30 | ############################################################################## 31 | # Configuring header file with cmake variables 32 | ############################################################################## 33 | # Configure header file to pass some of the CMake settings to the source code 34 | configure_file( 35 | "${PROJECT_SOURCE_DIR}/src/libcatnip/calcJconfig.hpp.in" 36 | "${PROJECT_SOURCE_DIR}/src/libcatnip/calcJconfig.hpp" 37 | ) 38 | 39 | ############################################################################## 40 | # Finding dependencies 41 | ############################################################################## 42 | # Find bash it is important for testing using scripts 43 | find_program (BASH_PROGRAM bash) 44 | find_library (GCOV gcov) 45 | add_definitions(-DLOG_LEVEL=${LOG_LEVEL}) 46 | 47 | ############################################################################## 48 | # Setting up testing 49 | ############################################################################## 50 | if(ENABLE_INTEGRATION_TESTS) 51 | if(EXISTS "${PROJECT_SOURCE_DIR}/GAUSSIANFILES") 52 | message("GAUSSIANFILES found will not download") 53 | set(DOWNLOAD_TUTORIAL_FILES OFF) 54 | else(EXISTS "${PROJECT_SOURCE_DIR}/GAUSSIANFILES") 55 | message("GAUSSIANFILES not found will download") 56 | set(DOWNLOAD_TUTORIAL_FILES ON) 57 | endif(EXISTS "${PROJECT_SOURCE_DIR}/GAUSSIANFILES") 58 | endif() 59 | 60 | if(DOWNLOAD_TUTORIAL_FILES) 61 | message("Downloading gaussian tutorial files") 62 | execute_process(COMMAND ${PROJECT_SOURCE_DIR}/scripts/test_suite_install.bash "${PROJECT_SOURCE_DIR}" ) 63 | endif() 64 | 65 | if(ENABLE_TESTS OR ENABLE_INTEGRATION_TESTS) 66 | enable_testing() 67 | add_subdirectory("${PROJECT_SOURCE_DIR}/src/tests") 68 | endif() 69 | 70 | if (ENABLE_INTEGRATION_TESTS) 71 | file( COPY "${PROJECT_SOURCE_DIR}/GAUSSIANFILES/90_unordered/90_pair.log" 72 | DESTINATION "${PROJECT_BINARY_DIR}/GAUSSIANFILES/90_unordered") 73 | file( COPY "${PROJECT_SOURCE_DIR}/GAUSSIANFILES/90_unordered/90_pair.pun" 74 | DESTINATION "${PROJECT_BINARY_DIR}/GAUSSIANFILES/90_unordered") 75 | 76 | file( COPY "${PROJECT_SOURCE_DIR}/GAUSSIANFILES/30_unordered/30_pair.pun" 77 | DESTINATION "${PROJECT_BINARY_DIR}/GAUSSIANFILES/30_unordered") 78 | file( COPY "${PROJECT_SOURCE_DIR}/GAUSSIANFILES/30_unordered/ref.pun" 79 | DESTINATION "${PROJECT_BINARY_DIR}/GAUSSIANFILES/30_unordered") 80 | file( COPY "${PROJECT_SOURCE_DIR}/GAUSSIANFILES/30_unordered/30_2.pun" 81 | DESTINATION "${PROJECT_BINARY_DIR}/GAUSSIANFILES/30_unordered") 82 | endif() 83 | 84 | if (ENABLE_TESTS) 85 | file( COPY "${PROJECT_SOURCE_DIR}/src/tests/testfile.pun" 86 | DESTINATION "${PROJECT_BINARY_DIR}/src/tests") 87 | file( COPY "${PROJECT_SOURCE_DIR}/src/tests/testfile.log" 88 | DESTINATION "${PROJECT_BINARY_DIR}/src/tests") 89 | endif() 90 | 91 | ############################################################################## 92 | # Compiling build tree/paths 93 | ############################################################################## 94 | # Add the binary tree to the search path for include files 95 | # so that we will find calcJconfig.hpp 96 | include_directories("${PROJECT_BINARY_DIR}/src") 97 | include_directories("${PROJECT_SOURCE_DIR}/src/libcatnip") 98 | include_directories("${PROJECT_SOURCE_DIR}/src/libcatnip/io/arguments/properties") 99 | include_directories("${PROJECT_SOURCE_DIR}/src/libcatnip/io/arguments") 100 | include_directories("${PROJECT_SOURCE_DIR}/src/libcatnip/io/file_readers") 101 | include_directories("${PROJECT_SOURCE_DIR}/src/libcatnip/io") 102 | 103 | link_directories("${PROJECT_SOURCE_DIR}/src/libcatnip/io/arguments/properties") 104 | link_directories("${PROJECT_SOURCE_DIR}/src/libcatnip/io/arguments") 105 | link_directories("${PROJECT_SOURCE_DIR}/src/libcatnip/io/file_readers") 106 | link_directories("${PROJECT_SOURCE_DIR}/src/libcatnip/io") 107 | link_directories("${PROJECT_SOURCE_DIR}/src/libcatnip") 108 | 109 | add_subdirectory("${PROJECT_SOURCE_DIR}/src/libcatnip") 110 | 111 | ############################################################################## 112 | # Creating calc_J and setting up code coverage if on 113 | ############################################################################## 114 | add_executable(calc_J src/tools/main.cpp) 115 | if(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") 116 | target_link_libraries(calc_J gcov) 117 | set_source_files_properties( src/tools/main.cpp PROPERTIES COMPILE_FLAGS ${COVERAGE_FLAGS}) 118 | endif(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") 119 | target_link_libraries(calc_J libcatnip ${COMMON_LIBRARIES}) 120 | install( TARGETS calc_J DESTINATION bin) 121 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Joshua S Brown 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![CATNIPLOGO](docs/images/CATNIPLong.png) 2 | 3 | # QC_Tools or CATNIP - ChArge TraNsfer Integral Package 4 | 5 | ## Badges 6 | 7 | [![Codacy Badge](https://app.codacy.com/project/badge/Grade/4523458aa098452ea9a1aeea172e5b71)](https://www.codacy.com/gh/JoshuaSBrown/QC_Tools/dashboard?utm_source=github.com&utm_medium=referral&utm_content=JoshuaSBrown/QC_Tools&utm_campaign=Badge_Grade) 8 | [![Join the chat at https://gitter.im/QC_Tools/Lobby](https://badges.gitter.im/QC_Tools/Lobby.svg)](https://gitter.im/QC_Tools/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 9 | [![Github All Releases](https://img.shields.io/github/downloads/JoshuaSBrown/QC_Tools/total.svg)]() 10 | [![Build Status](https://travis-ci.org/JoshuaSBrown/QC_Tools.svg?branch=master)](https://travis-ci.org/JoshuaSBrown/QC_Tools) 11 | [![codecov](https://codecov.io/gh/JoshuaSBrown/QC_Tools/branch/master/graph/badge.svg)](https://codecov.io/gh/JoshuaSBrown/QC_Tools) 12 | [![CodeFactor](https://www.codefactor.io/repository/github/joshuasbrown/qc_tools/badge)](https://www.codefactor.io/repository/github/joshuasbrown/qc_tools) 13 | [![Total alerts](https://img.shields.io/lgtm/alerts/g/JoshuaSBrown/QC_Tools.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/JoshuaSBrown/QC_Tools/alerts/) 14 | [![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/JoshuaSBrown/QC_Tools.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/JoshuaSBrown/QC_Tools/context:cpp) 15 | [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=JoshuaSBrown_QC_Tools&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=JoshuaSBrown_QC_Tools) 16 | 17 | # Updates 18 | 19 | Message to users: 20 | 21 | 0. NOTE - CATNIP is dependent on the precision of the log output of the Guassian files, if you need highly accurate calculations, this tool is probably not the best tool. It would be better to use something like NWChem that solves for the transfer integral self consistently. 22 | 1. The wiki has been ported to github pages, I have left the documentation in the wiki but it will become deprecated in the future. 23 | 2. Version 2.0 is in the works, will provide additional functionality. 24 | 25 | ## Documentation 26 | 27 | * [CATNIP Home](https://joshuasbrown.github.io/docs/CATNIP/catnip_home.html) 28 | * [Downloading & Building](https://joshuasbrown.github.io/docs/CATNIP/catnip_downloads.html) 29 | * [Theory](https://joshuasbrown.github.io/docs/CATNIP/catnip_theory.html) 30 | * [Gaussian Files](https://joshuasbrown.github.io/docs/CATNIP/catnip_gaussian_files.html) 31 | * [Tutorial 1](https://joshuasbrown.github.io/docs/CATNIP/catnip_tutorial1.html) 32 | * [Tutorial 2](https://joshuasbrown.github.io/docs/CATNIP/catnip_tutorial2.html) 33 | * [Tutorial 3](https://joshuasbrown.github.io/docs/CATNIP/catnip_tutorial3.html) 34 | * [Common Problems](https://joshuasbrown.github.io/docs/CATNIP/catnip_common_problems.html) 35 | * [Versions](https://joshuasbrown.github.io/docs/CATNIP/catnip_versions.html) 36 | * [Resources](https://joshuasbrown.github.io/docs/CATNIP/catnip_resources.html) 37 | * [Papers](https://joshuasbrown.github.io/docs/CATNIP/catnip_papers.html) 38 | 39 | ## Objective 40 | 41 | CATNIP is meant to make difficult calculations accessible to the masses. The focus is to accelerate science and industry by: 42 | * using an accessible license 43 | * providing good documentation 44 | * easy installation 45 | * sharing ownership and encouraging collaboration 46 | 47 | I welcome feedback and contributors. If you have suggestions for integrating CATNIP with other programs please do not hesitate to create an issue or contact me on gitter. You can do this by clicking on the gitter badge. 48 | 49 | If you run into a problem feel free to create an issue on [github](https://github.com/JoshuaSBrown/QC_Tools/issues), just be sure to give me enough information to reproduce the error, otherwise I won't be able to fix it. If I do not respond promptly feel free to reach out again. Often responses get filtered to my spam folder or I simply do not see them. 50 | 51 | ## Citing 52 | 53 | If you use CATNIP to get values for a paper it would be nice if you cited it. To know how to cite it you can simply pass the folloing -cite flag to `calc_J` as: 54 | 55 | ```calc_J -cite``` 56 | 57 | It would also be nice if you starred the repo... if you find it useful. 58 | 59 | ## Acknowledgements and Relevant Papers 60 | 61 | [1] B. Baumeier, J. Kirkpatrick, and D. Andrienko, “Density-functional based determination of intermolecular charge transfer properties for large-scale morphologies,” Phys. Chem. Chem. Phys., vol. 12, no. 36, p. 11103, 2010. 62 | [2] E. F. Valeev, V. Coropceanu, D. a da Silva Filho, S. Salman, and J.-L. Brédas, “Effect of electronic polarization on charge-transport parameters in molecular organic semiconductors.,” J. Am. Chem. Soc., vol. 128, no. 30, pp. 9882–6, Aug. 2006. 63 | 64 | The author would like to acknowledge insightful correspondence with E. F. Valeev and B. Baumeier. 65 | 66 | ### Thanks to the following for helping to make CATNIP better 67 | 68 | * NKUCodingCat 69 | * dwaipayanroni 70 | * rdft4e 71 | * ivorever 72 | * Caleb Wehrmann 73 | -------------------------------------------------------------------------------- /docs/_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-slate -------------------------------------------------------------------------------- /docs/images/BoltzmannConstant.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JoshuaSBrown/QC_Tools/52436c1f1aabfdaa92086657fd50cb32270f9056/docs/images/BoltzmannConstant.jpg -------------------------------------------------------------------------------- /docs/images/CATNIPLong.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JoshuaSBrown/QC_Tools/52436c1f1aabfdaa92086657fd50cb32270f9056/docs/images/CATNIPLong.png -------------------------------------------------------------------------------- /docs/images/DeltaG.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JoshuaSBrown/QC_Tools/52436c1f1aabfdaa92086657fd50cb32270f9056/docs/images/DeltaG.jpg -------------------------------------------------------------------------------- /docs/images/Dimer1Ang.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JoshuaSBrown/QC_Tools/52436c1f1aabfdaa92086657fd50cb32270f9056/docs/images/Dimer1Ang.jpg -------------------------------------------------------------------------------- /docs/images/Dimer5Ang.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JoshuaSBrown/QC_Tools/52436c1f1aabfdaa92086657fd50cb32270f9056/docs/images/Dimer5Ang.jpg -------------------------------------------------------------------------------- /docs/images/Distance2VsJeff.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JoshuaSBrown/QC_Tools/52436c1f1aabfdaa92086657fd50cb32270f9056/docs/images/Distance2VsJeff.jpg -------------------------------------------------------------------------------- /docs/images/Distance2VsJeffLog.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JoshuaSBrown/QC_Tools/52436c1f1aabfdaa92086657fd50cb32270f9056/docs/images/Distance2VsJeffLog.jpg -------------------------------------------------------------------------------- /docs/images/DistanceVsJeff.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JoshuaSBrown/QC_Tools/52436c1f1aabfdaa92086657fd50cb32270f9056/docs/images/DistanceVsJeff.jpg -------------------------------------------------------------------------------- /docs/images/DistanceVsJeffLog.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JoshuaSBrown/QC_Tools/52436c1f1aabfdaa92086657fd50cb32270f9056/docs/images/DistanceVsJeffLog.jpg -------------------------------------------------------------------------------- /docs/images/Ei.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JoshuaSBrown/QC_Tools/52436c1f1aabfdaa92086657fd50cb32270f9056/docs/images/Ei.jpg -------------------------------------------------------------------------------- /docs/images/Ej.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JoshuaSBrown/QC_Tools/52436c1f1aabfdaa92086657fd50cb32270f9056/docs/images/Ej.jpg -------------------------------------------------------------------------------- /docs/images/Hab.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JoshuaSBrown/QC_Tools/52436c1f1aabfdaa92086657fd50cb32270f9056/docs/images/Hab.jpg -------------------------------------------------------------------------------- /docs/images/J0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JoshuaSBrown/QC_Tools/52436c1f1aabfdaa92086657fd50cb32270f9056/docs/images/J0.jpg -------------------------------------------------------------------------------- /docs/images/Jab.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JoshuaSBrown/QC_Tools/52436c1f1aabfdaa92086657fd50cb32270f9056/docs/images/Jab.jpg -------------------------------------------------------------------------------- /docs/images/Marcus.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JoshuaSBrown/QC_Tools/52436c1f1aabfdaa92086657fd50cb32270f9056/docs/images/Marcus.jpg -------------------------------------------------------------------------------- /docs/images/MillerAndAbrahams.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JoshuaSBrown/QC_Tools/52436c1f1aabfdaa92086657fd50cb32270f9056/docs/images/MillerAndAbrahams.jpg -------------------------------------------------------------------------------- /docs/images/Temperature.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JoshuaSBrown/QC_Tools/52436c1f1aabfdaa92086657fd50cb32270f9056/docs/images/Temperature.jpg -------------------------------------------------------------------------------- /docs/images/TunnelingTerm.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JoshuaSBrown/QC_Tools/52436c1f1aabfdaa92086657fd50cb32270f9056/docs/images/TunnelingTerm.jpg -------------------------------------------------------------------------------- /docs/images/TunnelingTerm2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JoshuaSBrown/QC_Tools/52436c1f1aabfdaa92086657fd50cb32270f9056/docs/images/TunnelingTerm2.jpg -------------------------------------------------------------------------------- /docs/images/alpha.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JoshuaSBrown/QC_Tools/52436c1f1aabfdaa92086657fd50cb32270f9056/docs/images/alpha.jpg -------------------------------------------------------------------------------- /docs/images/gamma.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JoshuaSBrown/QC_Tools/52436c1f1aabfdaa92086657fd50cb32270f9056/docs/images/gamma.jpg -------------------------------------------------------------------------------- /docs/images/hbar.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JoshuaSBrown/QC_Tools/52436c1f1aabfdaa92086657fd50cb32270f9056/docs/images/hbar.jpg -------------------------------------------------------------------------------- /docs/images/lambda.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JoshuaSBrown/QC_Tools/52436c1f1aabfdaa92086657fd50cb32270f9056/docs/images/lambda.jpg -------------------------------------------------------------------------------- /docs/images/nu0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JoshuaSBrown/QC_Tools/52436c1f1aabfdaa92086657fd50cb32270f9056/docs/images/nu0.jpg -------------------------------------------------------------------------------- /docs/images/rij.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JoshuaSBrown/QC_Tools/52436c1f1aabfdaa92086657fd50cb32270f9056/docs/images/rij.jpg -------------------------------------------------------------------------------- /scripts/build.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -euo pipefail 4 | 5 | # Configure 6 | cmake -DCODE_COVERAGE=ON -DCMAKE_BUILD_TYPE=Debug .. 7 | # Build (for Make on Unix equivalent to `make -j $(nproc)`) 8 | cmake --build . --config Debug -- -j $(nproc) 9 | # Test 10 | ctest -j $(nproc) --output-on-failure 11 | 12 | -------------------------------------------------------------------------------- /scripts/deploy.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Make codecoverage build script executable 4 | chmod +x scripts/build.bash 5 | mkdir build 6 | cd build 7 | cmake -DENABLE_INTEGRATION_TESTS=ON -DENABLE_TESTS=ON -DCODE_COVERAGE=ON ../ 8 | make 9 | ctest --verbose 10 | lcov --capture --directory . --output-file coverage.info 11 | lcov --list coverage.info 12 | bash <(curl -s https://codecov.io/bash) -t "e0045700-7ee0-41a6-a907-70f6a530f431" 13 | -------------------------------------------------------------------------------- /scripts/docker_clean.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Will remove all docker containers and images 4 | docker container prune 5 | docker image prune -a 6 | -------------------------------------------------------------------------------- /scripts/release.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | directory=$(pwd) 4 | distros="centos7 fedora28 ubuntu18 debian9" 5 | for distro in $distros; do 6 | echo "Building ${distro}" 7 | cd ${directory}/release_distros/${distro} 8 | pwd 9 | ls 10 | cp ${directory}/release_distros/package_release.bash ${directory}/release_distros/${distro}/ 11 | docker build ${directory}/release_distros/${distro} -t "catnip${distro}" 12 | id=$(docker create "catnip${distro}") 13 | docker cp $id:TAR . 14 | rm ${directory}/release_distros/${distro}/package_release.bash 15 | done 16 | 17 | cd ${directory} 18 | 19 | binaries=$(find "$(pwd -P)" | grep tar.gz) 20 | mkdir release_packages 21 | cd release_packages 22 | git clone https://github.com/JoshuaSBrown/QC_Tools.git 23 | rm -rf QC_Tools/.git 24 | rm -rf QC_Tools/.clang-format 25 | rm -rf QC_Tools/.travis.yml 26 | rm -rf QC_Tools/docs 27 | MAJOR_VERSION=$(grep VERSION_MAJOR QC_Tools/CMakeLists.txt| grep -oP '\(\K[^\)]+' | awk '{print $2}') 28 | MINOR_VERSION=$(grep VERSION_MINOR QC_Tools/CMakeLists.txt | grep -oP '\(\K[^\)]+' | awk '{print $2}') 29 | zip -r calc_J_${MAJOR_VERSION}.${MINOR_VERSION}_source.zip QC_Tools 30 | tar -zcvf calc_J_${MAJOR_VERSION}.${MINOR_VERSION}_source.tar.gz QC_Tools 31 | rm -rf QC_Tools 32 | 33 | for binary in ${binaries} 34 | do 35 | echo "$binary" 36 | mv $binary . 37 | done 38 | -------------------------------------------------------------------------------- /scripts/release_distros/centos7/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM centos:7 2 | 3 | RUN yum update -y 4 | RUN yum install python curl unzip zip make cmake gcc-c++ git file redhat-lsb-core -y 5 | RUN curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py" 6 | RUN chmod +x get-pip.py 7 | RUN ./get-pip.py 8 | RUN pip install gdown 9 | RUN git clone https://github.com/JoshuaSBrown/QC_Tools.git 10 | RUN mkdir -p QC_Tools/build_test 11 | RUN mkdir -p QC_Tools/build 12 | # Build with tests and then test 13 | WORKDIR /QC_Tools/build 14 | RUN cmake -DENABLE_TESTS=ON -DENABLE_INTEGRATION_TESTS=ON ../ 15 | RUN make 16 | RUN make ARGS="-V" test 17 | # Build optimized release version 18 | RUN rm -rf * 19 | RUN cmake -DCMAKE_BUILD_TYPE=Release ../ 20 | RUN make 21 | # VERSION of calc_J 22 | # 64 or 32 bit architecture 23 | # Remove the comma from version 24 | WORKDIR / 25 | COPY package_release.bash . 26 | RUN chmod +x ./package_release.bash 27 | RUN ./package_release.bash 28 | -------------------------------------------------------------------------------- /scripts/release_distros/debian9/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:stretch 2 | 3 | RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections 4 | RUN apt-get update && apt-get install -y python curl bc zip unzip apt-utils ca-certificates make cmake gcc g++ git file lsb-release && apt-get clean && rm -rf /var/lib/apt/lists/* 5 | RUN curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py" 6 | RUN chmod +x get-pip.py 7 | RUN ./get-pip.py 8 | RUN pip install gdown 9 | RUN git clone https://github.com/JoshuaSBrown/QC_Tools.git 10 | RUN mkdir -p QC_Tools/build_test 11 | RUN mkdir -p QC_Tools/build 12 | 13 | # Build with tests and then test 14 | WORKDIR /QC_Tools/build 15 | RUN cmake -DENABLE_TESTS=ON -DENABLE_INTEGRATION_TESTS=ON ../ 16 | RUN make 17 | RUN make ARGS="-V" test 18 | # Build optimized release version 19 | RUN rm -rf * 20 | RUN cmake -DCMAKE_BUILD_TYPE=Release ../ 21 | RUN make 22 | # VERSION of calc_J 23 | # 64 or 32 bit architecture 24 | # Remove the comma from version 25 | WORKDIR / 26 | COPY package_release.bash . 27 | RUN chmod +x ./package_release.bash 28 | RUN ./package_release.bash 29 | -------------------------------------------------------------------------------- /scripts/release_distros/fedora28/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM fedora:28 2 | 3 | RUN dnf install python curl zip unzip make cmake gcc-c++ git file redhat-lsb-core -y 4 | RUN curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py" 5 | RUN chmod +x get-pip.py 6 | RUN ./get-pip.py 7 | RUN pip install gdown 8 | RUN git clone https://github.com/JoshuaSBrown/QC_Tools.git 9 | RUN mkdir -p QC_Tools/build_test 10 | RUN mkdir -p QC_Tools/build 11 | # Build with tests and then test 12 | WORKDIR /QC_Tools/build 13 | RUN cmake -DENABLE_TESTS=ON -DENABLE_INTEGRATION_TESTS=ON ../ 14 | RUN make 15 | RUN make ARGS="-V" test 16 | # Build optimized release version 17 | RUN rm -rf * 18 | RUN cmake -DCMAKE_BUILD_TYPE=Release ../ 19 | RUN make 20 | # VERSION of calc_J 21 | # 64 or 32 bit architecture 22 | # Remove the comma from version 23 | WORKDIR / 24 | COPY package_release.bash . 25 | RUN chmod +x ./package_release.bash 26 | RUN ./package_release.bash 27 | -------------------------------------------------------------------------------- /scripts/release_distros/package_release.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | VERSION=$(/QC_Tools/build/calc_J --version | awk '{ print $4 }' |tr -d '\n') 4 | FORMAT=$(file /QC_Tools/build/calc_J | awk '{ print $6}' ) 5 | FORMAT=${FORMAT%?} 6 | DISTRO=$(lsb_release -a | grep ID | awk '{print $3}') 7 | DISTRO_VERSION=$(lsb_release -a | grep Release | awk '{print $2}') 8 | tar_file=$(echo calc_J_${VERSION}_${DISTRO}_${DISTRO_VERSION}_${FORMAT}.tar.gz) 9 | echo "tar file name "${tar_file} 10 | ls /QC_Tools/build 11 | tar -zcvf "${tar_file}" QC_Tools/build/calc_J 12 | mkdir TAR 13 | mv *tar.gz TAR/ 14 | -------------------------------------------------------------------------------- /scripts/release_distros/ubuntu18/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:bionic 2 | 3 | RUN apt-get update && apt-get install -y bc python curl zip unzip apt-utils ca-certificates make cmake gcc g++ git file lsb-release && apt-get clean && rm -rf /var/lib/apt/lists/* 4 | RUN curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py" 5 | RUN chmod +x get-pip.py 6 | RUN ./get-pip.py 7 | RUN pip install gdown 8 | RUN git clone https://github.com/JoshuaSBrown/QC_Tools.git 9 | RUN mkdir -p QC_Tools/build_test 10 | RUN mkdir -p QC_Tools/build 11 | # Build with tests and then test 12 | WORKDIR /QC_Tools/build 13 | RUN cmake -DENABLE_TESTS=ON -DENABLE_INTEGRATION_TESTS=ON ../ 14 | RUN make 15 | RUN make ARGS="-V" test 16 | # Build optimized release version 17 | RUN rm -rf * 18 | RUN cmake -DCMAKE_BUILD_TYPE=Release ../ 19 | RUN make 20 | # VERSION of calc_J 21 | # 64 or 32 bit architecture 22 | # Remove the comma from version 23 | WORKDIR / 24 | COPY package_release.bash . 25 | RUN chmod +x package_release.bash 26 | RUN ./package_release.bash 27 | -------------------------------------------------------------------------------- /scripts/test_suite_install.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Pulls GAUSSIANFILES.zip from public google drive and unzips 4 | if [ -z "$1" ]; then 5 | DOWNLOAD_TO="." 6 | elif [ -d "$1" ]; then 7 | DOWNLOAD_TO=$1 8 | else 9 | echo "Directory does not exist "$1 10 | exit 1 11 | fi 12 | 13 | pip install --user --upgrade pip 14 | pip install --user gdown 15 | gdown https://drive.google.com/uc?id=1rCsj_jpMyE0S0cokFJDyBSA0aPNiIHNb 16 | 17 | unzip "GAUSSIANFILES.zip" 18 | #cleanup 19 | rm GAUSSIANFILES.zip 20 | 21 | if [ "$DOWNLOAD_TO" != "." ]; then 22 | mv GAUSSIANFILES $DOWNLOAD_TO 23 | fi 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /sonar-project.properties: -------------------------------------------------------------------------------- 1 | sonar.projectKey=JoshuaSBrown_QC_Tools 2 | sonar.organization=joshuasbrown 3 | 4 | # This is the name and version displayed in the SonarCloud UI. 5 | #sonar.projectName=QC_Tools 6 | #sonar.projectVersion=1.0 7 | 8 | # Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. 9 | #sonar.sources=. 10 | 11 | # Encoding of the source code. Default is default system encoding 12 | #sonar.sourceEncoding=UTF-8 13 | -------------------------------------------------------------------------------- /src/libcatnip/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | file(GLOB CATNIP_SOURCE_FILES 3 | *.cpp 4 | io/*.cpp 5 | io/arguments/*.cpp 6 | io/arguments/properties/*.cpp 7 | io/file_readers/*.cpp) 8 | 9 | add_library(libcatnip ${CATNIP_SOURCE_FILES}) 10 | -------------------------------------------------------------------------------- /src/libcatnip/calcJconfig.hpp.in: -------------------------------------------------------------------------------- 1 | // Configured options and settings for calcJ 2 | 3 | #ifndef CATNIP_CONFIG_HPP 4 | #define CATNIP_CONFIG_HPP 5 | 6 | #include 7 | 8 | namespace catnip { 9 | const int calcJ_VERSION_MAJOR = @calcJ_VERSION_MAJOR@; 10 | const int calcJ_VERSION_MINOR = @calcJ_VERSION_MINOR@; 11 | const int calcJ_YEAR_PUBLISHED = @calcJ_YEAR_PUBLISHED@; 12 | const std::string calcJ_AUTHOR_SURNAME = @calcJ_AUTHOR_SURNAME@; 13 | const std::string calcJ_AUTHOR_INITIALS = @calcJ_AUTHOR_INITIALS@; 14 | const std::string calcJ_TITLE = @calcJ_TITLE@; 15 | const std::string calcJ_URL = @calcJ_URL@; 16 | } // namespace catnip 17 | 18 | #endif // CATNIP_CONFIG_HPP 19 | -------------------------------------------------------------------------------- /src/libcatnip/constants.hpp: -------------------------------------------------------------------------------- 1 | 2 | namespace catnip { 3 | 4 | const double hartreeToeV = 27.2114; 5 | } 6 | -------------------------------------------------------------------------------- /src/libcatnip/io/argumentparser.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _CATNIP_ARGUMENTPARSER_HPP 2 | #define _CATNIP_ARGUMENTPARSER_HPP 3 | #include "../matrix.hpp" 4 | #include "../parameters.hpp" 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "arguments/argumentdouble.hpp" 11 | #include "arguments/argumentfile.hpp" 12 | #include "arguments/argumentint.hpp" 13 | #include "arguments/argumentstring.hpp" 14 | #include "arguments/argumentswitch.hpp" 15 | 16 | namespace catnip { 17 | 18 | class ArgumentParser { 19 | private: 20 | // 1 - flag name 21 | // 2 - type 22 | std::map str_arg_; 23 | std::map switch_arg_; 24 | std::map int_arg_; 25 | std::map double_arg_; 26 | std::map file_arg_; 27 | 28 | // Known rules 29 | std::set argument_types_; 30 | 31 | // Known flags and their description 32 | std::map> flags_; 33 | 34 | std::map defaults_set_; 35 | // Arguments that are stored when argc and argv are parsed 36 | std::map int_values_; 37 | std::map double_values_; 38 | std::map string_values_; 39 | std::map size_t_values_; 40 | 41 | void parseArg_(size_t& index, std::vector arguments); 42 | 43 | // Determine if the next value in arguments vector is a recognized flag 44 | bool nextParameterIsAFlag_(size_t index, std::vector arguments); 45 | 46 | size_t maxShortFlagSize; 47 | size_t maxFullFlagSize; 48 | size_t maxDescriptionSize; 49 | size_t maxLineLength = 80; 50 | 51 | public: 52 | // 1 - short flag 53 | // 2 - long flag 54 | // 3 - description 55 | explicit ArgumentParser(std::set> flags); 56 | 57 | // Set Defaults for the flags in the case that they are not found 58 | void setFlagDefaultValue(std::string flag,const int & val); 59 | void setFlagDefaultValue(std::string flag,const size_t & val); 60 | void setFlagDefaultValue(std::string flag,const double & val); 61 | void setFlagDefaultValue(std::string flag,const std::string & val); 62 | 63 | // Add a argument without setting any of the values 64 | void addFlagArg(std::string flag, std::string argname); 65 | // Set the rules for the flag and the type it is associated with types 66 | // include: 67 | // "FILE_EXT" 68 | // "FILE_EXIST" 69 | // "DOUBLE" 70 | // "INT" 71 | // "STRING" 72 | // The rules are dependent on the type 73 | void setFlagArgOpt(std::string flag, std::string argname, 74 | std::string property, std::string option, int val); 75 | 76 | void setFlagArgOpt(std::string flag, std::string argname, 77 | std::string property, std::string option, double val); 78 | 79 | void setFlagArgOpt(std::string flag, std::string argname, 80 | std::string property, std::string option, std::string val); 81 | 82 | void setFlagArgOpt(std::string flag, std::string argname, 83 | std::string property, std::string option, 84 | std::set vals); 85 | 86 | void setFlagArgOpt(std::string flag, std::string argname, 87 | std::string property, std::string option, 88 | std::vector vals); 89 | 90 | std::string getFlagArgOptValue(std::string flag, std::string argname, 91 | std::string property, std::string option); 92 | 93 | double getDouble(std::string flag); 94 | int getInt(std::string flag); 95 | std::string getStr(std::string flag); 96 | size_t getSize_t(std::string flag); 97 | 98 | void postParseCheck(void); 99 | 100 | void parse(const char* argv[], int argc); 101 | void showUsage(); 102 | }; 103 | 104 | } // namespace catnip 105 | #endif // _CATNIP_ARGUMENTPARSER_HPP 106 | -------------------------------------------------------------------------------- /src/libcatnip/io/arguments/Makefile: -------------------------------------------------------------------------------- 1 | CC=g++ 2 | CFLAGS= -Wall -Wextra -pedantic -std=c++11 3 | 4 | all: test_argumentfile test_argumentswitch test_argumentint test_argumentdouble test_argumentstring 5 | 6 | test_argumentswitch: test_argumentswitch.cpp string_support.o argumentswitch.o propertyswitch.o 7 | $(CC) $(CFLAGS) test_argumentswitch.cpp string_support.o argumentswitch.o propertyswitch.o -o test_argumentswitch 8 | 9 | argumentswitch.o : argumentswitch.cpp 10 | $(CC) $(CFLAGS) -c argumentswitch.cpp 11 | 12 | test_argumentstring: test_argumentstring.cpp argumentstring.o string_support.o propertystring.o propertystringchoice.o 13 | $(CC) $(CFLAGS) test_argumentstring.cpp argumentstring.o propertystring.o string_support.o propertystringchoice.o -o test_argumentstring 14 | 15 | argumentstring.o : argumentstring.cpp 16 | $(CC) $(CFLAGS) -c argumentstring.cpp 17 | 18 | propertystring.o : PROPERTIES/propertystring.cpp 19 | $(CC) $(CFLAGS) -c PROPERTIES/propertystring.cpp 20 | 21 | test_argumentdouble: test_argumentdouble.cpp argumentdouble.o string_support.o propertydouble.o 22 | $(CC) $(CFLAGS) test_argumentdouble.cpp argumentdouble.o propertydouble.o string_support.o -o test_argumentdouble 23 | 24 | argumentdouble.o : argumentdouble.cpp 25 | $(CC) $(CFLAGS) -c argumentdouble.cpp 26 | 27 | propertydouble.o : PROPERTIES/propertydouble.cpp 28 | $(CC) $(CFLAGS) -c PROPERTIES/propertydouble.cpp 29 | 30 | test_argumentint: test_argumentint.cpp argumentint.o string_support.o propertyint.o 31 | $(CC) $(CFLAGS) test_argumentint.cpp argumentint.o propertyint.o string_support.o -o test_argumentint 32 | 33 | argumentint.o : argumentint.cpp 34 | $(CC) $(CFLAGS) -c argumentint.cpp 35 | 36 | test_argumentfile: test_argumentfile.cpp propertysisterfile.o argumentfile.o string_support.o propertyfileexist.o propertyfileext.o 37 | $(CC) $(CFLAGS) test_argumentfile.cpp argumentfile.o propertysisterfile.o propertyfileexist.o propertyfileext.o string_support.o -o test_argumentfile 38 | 39 | argumentfile.o : argumentfile.cpp 40 | $(CC) $(CFLAGS) -c argumentfile.cpp 41 | 42 | propertyswitch.o : PROPERTIES/propertyswitch.cpp 43 | $(CC) $(CFLAGS) -c PROPERTIES/propertyswitch.cpp 44 | 45 | propertysisterfile.o : PROPERTIES/propertysisterfile.cpp 46 | $(CC) $(CFLAGS) -c PROPERTIES/propertysisterfile.cpp 47 | 48 | propertyint.o : PROPERTIES/propertyint.cpp 49 | $(CC) $(CFLAGS) -c PROPERTIES/propertyint.cpp 50 | 51 | propertyfileexist.o : PROPERTIES/propertyfileexist.cpp 52 | $(CC) $(CFLAGS) -c PROPERTIES/propertyfileexist.cpp 53 | 54 | propertystringchoice.o : PROPERTIES/propertystringchoice.cpp 55 | $(CC) $(CFLAGS) -c PROPERTIES/propertystringchoice.cpp 56 | 57 | propertyfileext.o : PROPERTIES/propertyfileext.cpp 58 | $(CC) $(CFLAGS) -c PROPERTIES/propertyfileext.cpp 59 | 60 | string_support.o: ../../STRING_SUPPORT/string_support.cpp 61 | $(CC) $(CFLAGS) -c ../../STRING_SUPPORT/string_support.cpp 62 | 63 | clean: 64 | rm *.o test_argumentfile test_argumentswitch test_argumentint test_argumentdouble test_argumentstring 65 | -------------------------------------------------------------------------------- /src/libcatnip/io/arguments/README.md: -------------------------------------------------------------------------------- 1 | 2 | # Arguments 3 | 4 | The arguments classes are used to define the criteria that the arguments passed in from the command line should meet. 5 | 6 | For instance if you are passing the a file name in then there will be an argument class for dealing with file names. If you are passing integer in there will be a argument class for deaing with integers. 7 | 8 | # Properties 9 | 10 | The properties classes are the criteria used to check the arguments. For instance if a file argument is passed in, for the file name to be valid maybe it needs to exist or have a relevant extension. There are properties defined for this kind of functionality. 11 | -------------------------------------------------------------------------------- /src/libcatnip/io/arguments/argumentdouble.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "argumentdouble.hpp" 3 | #include "properties/propertydouble.hpp" 4 | #include 5 | 6 | using namespace catnip; 7 | using namespace std; 8 | 9 | ArgumentDouble::ArgumentDouble(void) { registerProperties_(); } 10 | 11 | void ArgumentDouble::registerProperties_(void) { 12 | PropertyDouble* prop_double = new PropertyDouble(); 13 | double_propobjs_.push_back(prop_double); 14 | } 15 | -------------------------------------------------------------------------------- /src/libcatnip/io/arguments/argumentdouble.hpp: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _CATNIP_ARGUMENT_DOUBLE_HPP 3 | #define _CATNIP_ARGUMENT_DOUBLE_HPP 4 | 5 | #include "argumentobject.hpp" 6 | #include 7 | 8 | namespace catnip { 9 | 10 | class ArgumentDouble : public ArgumentObject { 11 | private: 12 | std::string getName_(void) const { return "ARGUMENT_DOUBLE"; } 13 | void registerProperties_(void); 14 | 15 | public: 16 | ArgumentDouble(void); 17 | }; 18 | 19 | } // namespace catnip 20 | #endif // _CATNIP_ARGUMENT_DOUBLE_HPP 21 | -------------------------------------------------------------------------------- /src/libcatnip/io/arguments/argumentfile.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "argumentfile.hpp" 3 | #include "properties/propertyfileexist.hpp" 4 | #include "properties/propertyfileext.hpp" 5 | #include "properties/propertysisterfile.hpp" 6 | #include 7 | 8 | using namespace catnip; 9 | using namespace std; 10 | 11 | ArgumentFile::ArgumentFile(void) { registerProperties_(); } 12 | 13 | void ArgumentFile::registerProperties_(void) { 14 | 15 | PropertyFileExist* prop_file_exist = new PropertyFileExist(); 16 | int_propobjs_.push_back(prop_file_exist); 17 | PropertyFileExt* prop_file_ext = new PropertyFileExt(); 18 | string_set_propobjs_.push_back(prop_file_ext); 19 | PropertySisterFile* prop_sis_file = new PropertySisterFile(); 20 | string_vec_propobjs_.push_back(prop_sis_file); 21 | } 22 | -------------------------------------------------------------------------------- /src/libcatnip/io/arguments/argumentfile.hpp: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _CATNIP_ARGUMENT_FILE_HPP 3 | #define _CATNIP_ARGUMENT_FILE_HPP 4 | 5 | #include "argumentobject.hpp" 6 | #include 7 | 8 | namespace catnip { 9 | 10 | class ArgumentFile : public ArgumentObject { 11 | private: 12 | std::string getName_(void) const { return "ARGUMENT_FILE"; } 13 | void registerProperties_(void); 14 | 15 | public: 16 | ArgumentFile(void); 17 | }; 18 | 19 | } // namespace catnip 20 | 21 | #endif // _CATNIP_ARGUMENT_FILE_HPP 22 | -------------------------------------------------------------------------------- /src/libcatnip/io/arguments/argumentint.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "argumentint.hpp" 3 | #include "properties/propertyint.hpp" 4 | #include 5 | 6 | using namespace catnip; 7 | using namespace std; 8 | 9 | ArgumentInt::ArgumentInt(void) { registerProperties_(); } 10 | 11 | void ArgumentInt::registerProperties_(void) { 12 | PropertyInt* prop_int = new PropertyInt; 13 | int_propobjs_.push_back(prop_int); 14 | } 15 | -------------------------------------------------------------------------------- /src/libcatnip/io/arguments/argumentint.hpp: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _CATNIP_ARGUMENT_INT_HPP 3 | #define _CATNIP_ARGUMENT_INT_HPP 4 | 5 | #include "argumentobject.hpp" 6 | #include 7 | 8 | namespace catnip { 9 | 10 | class ArgumentInt : public ArgumentObject { 11 | private: 12 | std::string getName_(void) const { return "ARGUMENT_INT"; } 13 | void registerProperties_(void); 14 | 15 | public: 16 | ArgumentInt(void); 17 | }; 18 | 19 | } // namespace catnip 20 | 21 | #endif // _CATNIP_ARGUMENT_INT_HPP 22 | -------------------------------------------------------------------------------- /src/libcatnip/io/arguments/argumentstring.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "argumentstring.hpp" 3 | #include "properties/propertystring.hpp" 4 | #include "properties/propertystringchoice.hpp" 5 | #include 6 | 7 | using namespace catnip; 8 | using namespace std; 9 | 10 | ArgumentString::ArgumentString(void) { registerProperties_(); } 11 | 12 | void ArgumentString::registerProperties_(void) { 13 | PropertyString* prop_string = new PropertyString; 14 | size_t_propobjs_.push_back(prop_string); 15 | PropertyStringChoice* prop_string_choice = new PropertyStringChoice; 16 | string_set_propobjs_.push_back(prop_string_choice); 17 | } 18 | -------------------------------------------------------------------------------- /src/libcatnip/io/arguments/argumentstring.hpp: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _CATNIP_ARGUMENT_STRING_HPP 3 | #define _CATNIP_ARGUMENT_STRING_HPP 4 | 5 | #include "argumentobject.hpp" 6 | #include 7 | 8 | namespace catnip { 9 | 10 | class ArgumentString : public ArgumentObject { 11 | private: 12 | std::string getName_(void) const { return "ARGUMENT_STRING"; } 13 | void registerProperties_(void); 14 | 15 | public: 16 | ArgumentString(void); 17 | }; 18 | 19 | } // namespace catnip 20 | 21 | #endif // _CATNIP_ARGUMENT_STRING_HPP 22 | -------------------------------------------------------------------------------- /src/libcatnip/io/arguments/argumentswitch.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "argumentswitch.hpp" 3 | #include "properties/propertyswitch.hpp" 4 | #include 5 | 6 | using namespace catnip; 7 | using namespace std; 8 | 9 | ArgumentSwitch::ArgumentSwitch(void) { registerProperties_(); } 10 | 11 | void ArgumentSwitch::registerProperties_(void) { 12 | PropertySwitch* prop_switch = new PropertySwitch; 13 | string_propobjs_.push_back(prop_switch); 14 | } 15 | 16 | bool ArgumentSwitch::positive(string val) const { 17 | if (val.compare("ON") == 0 || val.compare("TRUE") == 0 || 18 | val.compare("1") == 0) { 19 | return true; 20 | } else if (val.compare("OFF") == 0 || val.compare("FALSE") == 0 || 21 | val.compare("0") == 0) { 22 | return false; 23 | } 24 | throw invalid_argument("Argument value is unrecognized " + val); 25 | } 26 | -------------------------------------------------------------------------------- /src/libcatnip/io/arguments/argumentswitch.hpp: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _CATNIP_ARGUMENT_SWITCH_HPP 3 | #define _CATNIP_ARGUMENT_SWITCH_HPP 4 | 5 | #include "argumentobject.hpp" 6 | #include 7 | 8 | namespace catnip { 9 | class ArgumentSwitch : public ArgumentObject { 10 | private: 11 | std::string getName_(void) const { return "ARGUMENT_SWITCH"; } 12 | void registerProperties_(void); 13 | 14 | public: 15 | ArgumentSwitch(void); 16 | bool requiresParameter(void) { return false; } 17 | bool positive(int val) const { return ((val == 1) ? true : false); } 18 | bool positive(std::string val) const; 19 | }; 20 | 21 | } // namespace catnip 22 | #endif // _CATNIP_ARGUMENT_SWITCH_HPP 23 | -------------------------------------------------------------------------------- /src/libcatnip/io/arguments/properties/propertydouble.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "propertydouble.hpp" 3 | 4 | #include 5 | 6 | using namespace catnip; 7 | using namespace std; 8 | 9 | PropertyDouble::PropertyDouble() { 10 | setPropOption_("MIN", numeric_limits::lowest()); 11 | setPropOption_("MAX", numeric_limits::max()); 12 | } 13 | 14 | vector PropertyDouble::getOpts_(void) const { 15 | vector options{"MIN", "MAX"}; 16 | return options; 17 | } 18 | 19 | void PropertyDouble::doubleValid(const double& val) { 20 | if (val < getPropOption("MIN")) { 21 | string err = "The value is smaller than allowed " + to_string(val) + 22 | " the " 23 | "minimum allowed value is " + 24 | to_string(getPropOption("MIN")); 25 | throw invalid_argument(err); 26 | } else if (val > getPropOption("MAX")) { 27 | string err = "The value is greater than allowed " + to_string(val) + 28 | " the " 29 | "maximum allowed value is " + 30 | to_string(getPropOption("MAX")); 31 | throw invalid_argument(err); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/libcatnip/io/arguments/properties/propertydouble.hpp: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _CATNIP_PROPERTY_DOUBLE_HPP 3 | #define _CATNIP_PROPERTY_DOUBLE_HPP 4 | 5 | #include "propertyobject.hpp" 6 | 7 | namespace catnip { 8 | 9 | class PropertyDouble : public PropertyObject { 10 | private: 11 | void doubleValid(const double& val); 12 | std::string getName_(void) const { return "PROPERTY_DOUBLE"; } 13 | std::vector getOpts_(void) const; 14 | 15 | public: 16 | PropertyDouble(void); 17 | bool propValid(const double& value) { 18 | doubleValid(value); 19 | return true; 20 | } 21 | }; 22 | 23 | } // namespace catnip 24 | 25 | #endif // _CATNIP_PROPERTY_DOUBLE_HPP 26 | -------------------------------------------------------------------------------- /src/libcatnip/io/arguments/properties/propertyfileexist.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "propertyfileexist.hpp" 3 | #include "../../../string_support.hpp" 4 | #include 5 | #include 6 | 7 | using namespace catnip; 8 | using namespace std; 9 | 10 | PropertyFileExist::PropertyFileExist(void) { 11 | setPropOption_("FILE_MUST_EXIST", 0); 12 | setPropOption_("FILE_DOES_EXIST", 0); 13 | } 14 | 15 | PropertyFileExist::PropertyFileExist(int fileMustExist) { 16 | setPropOption_("FILE_MUST_EXIST", fileMustExist); 17 | } 18 | 19 | vector PropertyFileExist::getOpts_(void) const { 20 | vector options{"FILE_MUST_EXIST", "FILE_DOES_EXIST"}; 21 | return options; 22 | } 23 | 24 | bool PropertyFileExist::fileExist(const string& fileNamePath) const { 25 | struct stat buf; 26 | return (stat(fileNamePath.c_str(), &buf) == 0); 27 | } 28 | 29 | bool PropertyFileExist::propValid(const string& fileNamePath) { 30 | if (getPropOption("FILE_MUST_EXIST")) { 31 | if (!fileExist(fileNamePath)) { 32 | string err = "" + fileNamePath + " does not exist"; 33 | throw invalid_argument(err); 34 | } 35 | setPropOption_("FILE_DOES_EXIST", 1); 36 | } else { 37 | if (fileExist(fileNamePath)) { 38 | setPropOption_("FILE_DOES_EXIST", 1); 39 | } 40 | } 41 | return true; 42 | } 43 | 44 | void PropertyFileExist::postCheck(void) const { 45 | auto must_exist = getPropOption("FILE_MUST_EXIST"); 46 | auto exist = getPropOption("FILE_DOES_EXIST"); 47 | if (must_exist && exist == 0) { 48 | throw runtime_error("A necessary file is missing!"); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/libcatnip/io/arguments/properties/propertyfileexist.hpp: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _CATNIP_PROPERTY_FILEEXIST_HPP 3 | #define _CATNIP_PROPERTY_FILEEXIST_HPP 4 | 5 | #include "propertyobject.hpp" 6 | #include 7 | 8 | namespace catnip { 9 | 10 | class PropertyFileExist : public PropertyObject { 11 | private: 12 | bool fileExist(const std::string &) const; 13 | std::string getName_(void) const { return "PROPERTY_FILE_EXIST"; } 14 | std::vector getOpts_(void) const; 15 | 16 | public: 17 | explicit PropertyFileExist(void); 18 | PropertyFileExist(int fileMustExist); 19 | bool propValid(const std::string &fileName); 20 | void postCheck(void) const; 21 | }; 22 | 23 | } // namespace catnip 24 | 25 | #endif // _CATNIP_PROPERTY_FILEEXIST_HPP 26 | -------------------------------------------------------------------------------- /src/libcatnip/io/arguments/properties/propertyfileext.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "propertyfileext.hpp" 3 | #include "../../../string_support.hpp" 4 | #include 5 | #include 6 | 7 | using namespace catnip; 8 | using namespace std; 9 | 10 | PropertyFileExt::PropertyFileExt(void) { 11 | set exts_; 12 | exts_.insert("*"); 13 | setPropOption_("ALLOWED_FILE_EXT", exts_); 14 | } 15 | 16 | PropertyFileExt::PropertyFileExt(string ext) { 17 | checkExt(ext); 18 | set exts_; 19 | exts_.insert(ext); 20 | setPropOption_("ALLOWED_FILE_EXT", exts_); 21 | } 22 | 23 | PropertyFileExt::PropertyFileExt(set exts) { 24 | set exts_; 25 | for (auto ext : exts) { 26 | checkExt(ext); 27 | exts_.insert(ext); 28 | } 29 | setPropOption_("ALLOWED_FILE_EXT", exts_); 30 | } 31 | 32 | vector PropertyFileExt::getOpts_(void) const { 33 | vector options{"ALLOWED_FILE_EXT"}; 34 | return options; 35 | } 36 | 37 | void PropertyFileExt::extSupported(const string& ext) const { 38 | checkExt(ext); 39 | auto exts_ = getPropOption("ALLOWED_FILE_EXT"); 40 | for (auto ext_ : exts_) { 41 | if (ext_[0] == '*') { 42 | return; 43 | } else if (ext_.compare(ext) == 0) { 44 | return; 45 | } 46 | } 47 | string err = "The file ext " + ext + " is unsupported"; 48 | throw invalid_argument(err); 49 | } 50 | 51 | void PropertyFileExt::checkExt(const string& ext) const { 52 | if (ext.compare("") == 0) { 53 | return; 54 | } else if (ext[0] == '*') { 55 | return; 56 | } else { 57 | string excess = grabStrBeforeLastOccurance(ext, "."); 58 | if (excess.compare("") != 0) { 59 | throw invalid_argument( 60 | "An extension must be of type '.ext','*','', " 61 | "you have used " + 62 | ext); 63 | } 64 | } 65 | return; 66 | } 67 | 68 | void PropertyFileExt::setPropOption(std::string option, 69 | std::set vars) { 70 | PropertyObject::setPropOption(option, vars); 71 | } 72 | 73 | void PropertyFileExt::setPropOption(std::string option, std::string var) { 74 | set vars; 75 | vars.insert(var); 76 | PropertyObject::setPropOption(option, vars); 77 | } 78 | 79 | bool PropertyFileExt::propValid(const string& fileNamePath) { 80 | string fileName = lastStringInPath(fileNamePath); 81 | string ext = grabStrAfterLastOccuranceInclusive(fileName, "."); 82 | extSupported(ext); 83 | return true; 84 | } 85 | -------------------------------------------------------------------------------- /src/libcatnip/io/arguments/properties/propertyfileext.hpp: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _CATNIP_PROPERTY_FILEEXT_HPP 3 | #define _CATNIP_PROPERTY_FILEEXT_HPP 4 | 5 | #include "propertyobject.hpp" 6 | #include 7 | 8 | namespace catnip { 9 | 10 | class PropertyFileExt 11 | : public PropertyObject > { 12 | private: 13 | void checkExt(const std::string &) const; 14 | void extSupported(const std::string &) const; 15 | std::string getName_(void) const { return "PROPERTY_FILE_EXT"; } 16 | std::vector getOpts_(void) const; 17 | 18 | public: 19 | explicit PropertyFileExt(void); 20 | explicit PropertyFileExt(std::string ext); 21 | PropertyFileExt(std::set exts); 22 | bool propValid(const std::string &fileNamePath); 23 | void setPropOption(std::string option, std::string var); 24 | void setPropOption(std::string option, std::set var); 25 | }; 26 | 27 | } // namespace catnip 28 | #endif // _CATNIP_PROPERTY_FILEEXT_HPP 29 | -------------------------------------------------------------------------------- /src/libcatnip/io/arguments/properties/propertyint.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "propertyint.hpp" 3 | 4 | #include 5 | 6 | using namespace catnip; 7 | using namespace std; 8 | 9 | PropertyInt::PropertyInt() { 10 | setPropOption_("MIN", numeric_limits::min()); 11 | setPropOption_("MAX", numeric_limits::max()); 12 | } 13 | 14 | vector PropertyInt::getOpts_(void) const { 15 | vector options{"MIN", "MAX"}; 16 | return options; 17 | } 18 | 19 | void PropertyInt::intValid(const int& val) const { 20 | if (val < getPropOption("MIN")) { 21 | string err = "The value is smaller than allowed " + to_string(val) + 22 | " the " 23 | "minimum allowed value is " + 24 | to_string(getPropOption("MIN")); 25 | throw invalid_argument(err); 26 | } else if (val > getPropOption("MAX")) { 27 | string err = "The value is greater than allowed " + to_string(val) + 28 | " the " 29 | "maximum allowed value is " + 30 | to_string(getPropOption("MAX")); 31 | throw invalid_argument(err); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/libcatnip/io/arguments/properties/propertyint.hpp: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _CATNIP_PROPERTY_INT_HPP 3 | #define _CATNIP_PROPERTY_INT_HPP 4 | 5 | #include "propertyobject.hpp" 6 | 7 | namespace catnip { 8 | 9 | class PropertyInt : public PropertyObject { 10 | private: 11 | void intValid(const int& val) const; 12 | std::string getName_(void) const { return "PROPERTY_INT"; } 13 | std::vector getOpts_(void) const; 14 | 15 | public: 16 | PropertyInt(void); 17 | bool propValid(const int& value) { 18 | intValid(value); 19 | return true; 20 | } 21 | }; 22 | 23 | } // namespace catnip 24 | 25 | #endif // _CATNIP_PROPERTY_INT_HPP 26 | -------------------------------------------------------------------------------- /src/libcatnip/io/arguments/properties/propertyobject.hpp: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _CATNIP_PROPERTY_OBJECT_HPP 3 | #define _CATNIP_PROPERTY_OBJECT_HPP 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | namespace catnip { 15 | 16 | template 17 | class PropertyObject { 18 | protected: 19 | // Map key is the option name and the type "int, double etc" 20 | // void * points to the correct value for that type 21 | std::map options_; 22 | 23 | bool propOptionValid_(const std::string &option) const { 24 | for (const auto &opt : options_) { 25 | if (opt.first.compare(option) == 0) return true; 26 | } 27 | return false; 28 | } 29 | 30 | void setPropOption_(const std::string &option, const T &val) { 31 | 32 | if (options_.count(option) == 0) { 33 | T *opt = new T(val); 34 | options_[option] = static_cast(opt); 35 | } else { 36 | T *opt = static_cast(options_[option]); 37 | *opt = val; 38 | } 39 | } 40 | 41 | virtual std::string getName_(void) const { return "UNKNOWN"; } 42 | 43 | virtual std::vector getOpts_(void) const { 44 | std::vector options{"NO_OPTIONS"}; 45 | return options; 46 | } 47 | 48 | public: 49 | virtual ~PropertyObject(void) { 50 | for (auto itr : options_) { 51 | T *opt = static_cast(itr.second); 52 | delete opt; 53 | } 54 | options_.clear(); 55 | } 56 | 57 | virtual bool propValid(const S &value) = 0; 58 | 59 | std::string getPropertyName(void) const { return getName_(); } 60 | 61 | std::vector getPropertyOptions(void) const { return getOpts_(); } 62 | 63 | // Setup the valid options associated with the parameter 64 | void setPropOption(std::string option, const T & val) { 65 | if (!propOptionValid_(option)) { 66 | throw std::invalid_argument("Property option is unrecognized " + option); 67 | } 68 | setPropOption_(option, val); 69 | } 70 | 71 | T getPropOption(const std::string &option) const { 72 | if (!propOptionValid_(option)) { 73 | std::string err = "" + option + 74 | " is an unrecognized property option for " 75 | "property " + 76 | getName_(); 77 | throw std::invalid_argument(err); 78 | } 79 | return *(static_cast(options_.at(option))); 80 | } 81 | 82 | virtual void postCheck(void) const { return; } 83 | }; 84 | 85 | } // namespace catnip 86 | #endif // _CATNIP_PROPERTY_OBJECT_HPP 87 | -------------------------------------------------------------------------------- /src/libcatnip/io/arguments/properties/propertysisterfile.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "propertysisterfile.hpp" 3 | #include "../../../string_support.hpp" 4 | #include 5 | #include 6 | 7 | using namespace catnip; 8 | using namespace std; 9 | 10 | PropertySisterFile::PropertySisterFile(void) { 11 | string var = "NOT_DEFINED"; 12 | vector vec_var{var}; 13 | setPropOption_("ALLOWED_SISTER_FILE_EXT", vec_var); 14 | setPropOption_("SISTER_FILE_NAME", vec_var); 15 | setPropOption_("SISTER_FILE_PATH", vec_var); 16 | setPropOption_("SISTER_FILE_PATH_NAME", vec_var); 17 | vector vec_var2{"false"}; 18 | setPropOption_("SISTER_FILE_EXISTS", vec_var2); 19 | } 20 | 21 | vector PropertySisterFile::getOpts_(void) const { 22 | vector options; 23 | options.push_back("ALLOWED_SISTER_FILE_EXT"); 24 | options.push_back("SISTER_FILE_NAME"); 25 | options.push_back("SISTER_FILE_PATH"); 26 | options.push_back("SISTER_FILE_PATH_NAME"); 27 | options.push_back("SISTER_FILE_EXISTS"); 28 | return options; 29 | } 30 | 31 | bool PropertySisterFile::fileExist(const string& fileNamePath) const { 32 | struct stat buf; 33 | return (stat(fileNamePath.c_str(), &buf) == 0); 34 | } 35 | 36 | void PropertySisterFile::extSupported(const string& ext) const { 37 | checkExt(ext); 38 | auto exts_ = getPropOption("ALLOWED_SISTER_FILE_EXT"); 39 | for (auto ext_ : exts_) { 40 | if (ext_.compare(ext) == 0) { 41 | return; 42 | } 43 | } 44 | string err = "The file ext " + ext + " is unsupported"; 45 | throw invalid_argument(err); 46 | } 47 | 48 | void PropertySisterFile::checkExt(const string& ext) const { 49 | string excess = grabStrBeforeLastOccurance(ext, "."); 50 | if (excess.compare("") != 0) { 51 | throw invalid_argument( 52 | "An extension must be of type '.ext'" 53 | "you have used " + 54 | ext); 55 | } 56 | return; 57 | } 58 | 59 | void PropertySisterFile::setPropOption(std::string option, 60 | const std::string& var) { 61 | 62 | if (option.compare("ALLOWED_SISTER_FILE_EXT") == 0) { 63 | checkExt(var); 64 | vector vec_var{var}; 65 | setPropOption_(option, vec_var); 66 | return; 67 | } 68 | if (option.compare("SISTER_FILE_EXISTS") == 0 || 69 | option.compare("SISTER_FILE_NAME") == 0 || 70 | option.compare("SISTER_FILE_PATH") == 0 || 71 | option.compare("SISTER_FILE_PATH_NAME") == 0) { 72 | throw invalid_argument( 73 | "This option is determined internally you do not have permission to " 74 | "change it"); 75 | } 76 | throw invalid_argument("Unrecognized option value combo " + option + " " + 77 | var); 78 | } 79 | 80 | void PropertySisterFile::setPropOption(std::string option, 81 | vector vec_vars) { 82 | 83 | if (option.compare("ALLOWED_SISTER_FILE_EXT") == 0) { 84 | vector fileNames; 85 | vector filePaths; 86 | vector filePathNames; 87 | vector fileExists; 88 | string notdef = "NOT_DEFINED"; 89 | 90 | for (auto var : vec_vars) { 91 | checkExt(var); 92 | fileNames.push_back(notdef); 93 | filePaths.push_back(notdef); 94 | filePathNames.push_back(notdef); 95 | fileExists.push_back("false"); 96 | } 97 | setPropOption_(option, vec_vars); 98 | return; 99 | } 100 | if (option.compare("SISTER_FILE_EXISTS") == 0 || 101 | option.compare("SISTER_FILE_NAME") == 0 || 102 | option.compare("SISTER_FILE_PATH") == 0 || 103 | option.compare("SISTER_FILE_PATH_NAME") == 0) { 104 | throw invalid_argument( 105 | "This option is determined internally you do not have permission to " 106 | "change it"); 107 | } 108 | 109 | string vars = ""; 110 | for (auto var : vec_vars) { 111 | vars.append(var); 112 | vars.append(" "); 113 | } 114 | trim(vars); 115 | throw invalid_argument("Unrecognized option value combo " + option + " " + 116 | vars); 117 | } 118 | 119 | bool PropertySisterFile::propValid(const string& fileNamePath) { 120 | 121 | string fileName = lastStringInPath(fileNamePath); 122 | string path = getPath(fileNamePath); 123 | 124 | string sisterFileCore = grabStrBeforeLastOccurance(fileName, "."); 125 | auto sister_exts = getPropOption("ALLOWED_SISTER_FILE_EXT"); 126 | 127 | vector fileNames; 128 | vector filePaths; 129 | vector filePathNames; 130 | vector fileExists; 131 | 132 | for (auto sister_ext : sister_exts) { 133 | 134 | if (sister_ext.compare("NOT_DEFINED") != 0) { 135 | string sisterFileName = sisterFileCore + sister_ext; 136 | string sisterPath = path + sisterFileName; 137 | 138 | fileNames.push_back(sisterFileName); 139 | filePaths.push_back(path); 140 | filePathNames.push_back(sisterPath); 141 | if (fileExist(sisterPath)) { 142 | fileExists.push_back("true"); 143 | } else { 144 | fileExists.push_back("false"); 145 | } 146 | } 147 | } 148 | setPropOption_("SISTER_FILE_NAME", fileNames); 149 | setPropOption_("SISTER_FILE_PATH", filePaths); 150 | setPropOption_("SISTER_FILE_PATH_NAME", filePathNames); 151 | setPropOption_("SISTER_FILE_EXISTS", fileExists); 152 | return true; 153 | } 154 | -------------------------------------------------------------------------------- /src/libcatnip/io/arguments/properties/propertysisterfile.hpp: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _CATNIP_PROPERTY_SISTER_FILE_HPP 3 | #define _CATNIP_PROPERTY_SISTER_FILE_HPP 4 | 5 | #include "propertyobject.hpp" 6 | #include 7 | 8 | namespace catnip { 9 | 10 | class PropertySisterFile 11 | : public PropertyObject> { 12 | private: 13 | std::string getName_(void) const { return "PROPERTY_SISTER_FILE"; } 14 | std::vector getOpts_(void) const; 15 | bool fileExist(const std::string &) const; 16 | void extSupported(const std::string &) const; 17 | void checkExt(const std::string &) const; 18 | 19 | public: 20 | PropertySisterFile(void); 21 | void setPropOption(std::string option, const std::string &var); 22 | void setPropOption(std::string option, std::vector var); 23 | bool propValid(const std::string &fileNamePath); 24 | }; 25 | 26 | } // namespace catnip 27 | #endif // _CATNIP_PROPERTY_SISTER_FILE_HPP 28 | -------------------------------------------------------------------------------- /src/libcatnip/io/arguments/properties/propertystring.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "propertystring.hpp" 3 | #include 4 | 5 | using namespace catnip; 6 | using namespace std; 7 | 8 | PropertyString::PropertyString(void) { 9 | setPropOption_("MIN_LENGTH", 0); 10 | setPropOption_("MAX_LENGTH", (size_t)-1); 11 | } 12 | 13 | vector PropertyString::getOpts_(void) const { 14 | vector options{"MIN_LENGTH", "MAX_LENGTH"}; 15 | return options; 16 | } 17 | 18 | void PropertyString::stringValid(const string& val) const { 19 | if (val.size() > getPropOption("MAX_LENGTH")) { 20 | string err = "The string is larger than allowed " + val + 21 | " the " 22 | "maximum allowed value is " + 23 | to_string(getPropOption("MAX_LENGTH")); 24 | throw invalid_argument(err); 25 | } else if (val.size() < getPropOption("MIN_LENGTH")) { 26 | string err = "The string is smaller than allowed " + val + 27 | " the " 28 | "maximum allowed value is " + 29 | to_string(getPropOption("MIN_LENGTH")); 30 | throw invalid_argument(err); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/libcatnip/io/arguments/properties/propertystring.hpp: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _CATNIP_PROPERTY_STRING_HPP 3 | #define _CATNIP_PROPERTY_STRING_HPP 4 | 5 | #include "propertyobject.hpp" 6 | 7 | namespace catnip { 8 | 9 | class PropertyString : public PropertyObject { 10 | private: 11 | void stringValid(const std::string& val) const; 12 | std::string getName_(void) const { return "PROPERTY_STRING"; } 13 | std::vector getOpts_(void) const; 14 | 15 | public: 16 | PropertyString(void); 17 | bool propValid(const std::string& value) { 18 | stringValid(value); 19 | return true; 20 | } 21 | }; 22 | 23 | } // namespace catnip 24 | #endif // _CATNIP_PROPERTY_STRING_HPP 25 | -------------------------------------------------------------------------------- /src/libcatnip/io/arguments/properties/propertystringchoice.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "propertystringchoice.hpp" 3 | #include "../../../string_support.hpp" 4 | #include 5 | #include 6 | 7 | using namespace catnip; 8 | using namespace std; 9 | 10 | PropertyStringChoice::PropertyStringChoice(void) { 11 | set set_var1{"false"}; 12 | setPropOption_("STRING_CHOICE_ENFORCED", set_var1); 13 | string str = "NOT_DEFINED"; 14 | set set_var2{str}; 15 | setPropOption_("STRING_CHOICES", set_var2); 16 | } 17 | 18 | vector PropertyStringChoice::getOpts_(void) const { 19 | vector options; 20 | options.push_back("STRING_CHOICE_ENFORCED"); 21 | options.push_back("STRING_CHOICES"); 22 | return options; 23 | } 24 | 25 | void PropertyStringChoice::setPropOption(std::string option, std::string var) { 26 | 27 | if (option.compare("STRING_CHOICE_ENFORCED") == 0) { 28 | if (var.compare("false") == 0 || var.compare("true") == 0) { 29 | set set_var{var}; 30 | setPropOption_(option, set_var); 31 | return; 32 | } else { 33 | throw invalid_argument("The option " + option + 34 | " can only be set to values" 35 | " of true or false you have set it to " + 36 | var); 37 | } 38 | } else if (option.compare("STRING_CHOICES") == 0) { 39 | set set_var{var}; 40 | setPropOption_(option, set_var); 41 | } 42 | throw invalid_argument("Unrecognized option value combo " + option + " " + 43 | var); 44 | } 45 | 46 | void PropertyStringChoice::setPropOption(std::string option, 47 | set set_vars) { 48 | 49 | if (option.compare("STRING_CHOICES") == 0) { 50 | setPropOption_(option, set_vars); 51 | return; 52 | } else if (option.compare("STRING_CHOICE_ENFORCED") == 0) { 53 | if (set_vars.size() > 1) { 54 | string err = ""; 55 | for (auto var : set_vars) { 56 | err.append(var); 57 | err.append(" "); 58 | } 59 | trim(err); 60 | throw invalid_argument( 61 | "Option STRING_CHOICE_ENFORCED only accepts one " 62 | "value either true or false you have passed the following values " + 63 | err); 64 | } 65 | 66 | string var = *(set_vars.begin()); 67 | if (var.compare("false") == 0 || var.compare("true") == 0) { 68 | setPropOption_(option, set_vars); 69 | return; 70 | } else { 71 | throw invalid_argument("The option " + option + 72 | " can only be set to values" 73 | " of true or false you have set it to " + 74 | var); 75 | } 76 | } 77 | string vars = ""; 78 | for (auto var : set_vars) { 79 | vars.append(var); 80 | vars.append(" "); 81 | } 82 | trim(vars); 83 | throw invalid_argument("Unrecognized option value combo " + option + " " + 84 | vars); 85 | } 86 | 87 | bool PropertyStringChoice::propValid(const string& string_choice) { 88 | 89 | set opt_val = getPropOption("STRING_CHOICE_ENFORCED"); 90 | string val = *(opt_val.begin()); 91 | if (val.compare("true") == 0) { 92 | set str_choices = getPropOption("STRING_CHOICES"); 93 | if (str_choices.count(string_choice) > 0) return true; 94 | throw invalid_argument("The value " + string_choice + 95 | " is not a valid option"); 96 | } 97 | return true; 98 | } 99 | -------------------------------------------------------------------------------- /src/libcatnip/io/arguments/properties/propertystringchoice.hpp: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _CATNIP_PROPERTY_STRING_CHOICE_HPP 3 | #define _CATNIP_PROPERTY_STRING_CHOICE_HPP 4 | 5 | #include "propertyobject.hpp" 6 | #include 7 | 8 | namespace catnip { 9 | 10 | class PropertyStringChoice 11 | : public PropertyObject> { 12 | private: 13 | std::string getName_(void) const { return "PROPERTY_STRING_CHOICE"; } 14 | std::vector getOpts_(void) const; 15 | 16 | public: 17 | PropertyStringChoice(void); 18 | void setPropOption(std::string option, std::string var); 19 | void setPropOption(std::string option, std::set var); 20 | bool propValid(const std::string& string_choice); 21 | }; 22 | 23 | } // namespace catnip 24 | #endif // _CATNIP_PROPERTY_STRING_CHOICE_HPP 25 | -------------------------------------------------------------------------------- /src/libcatnip/io/arguments/properties/propertyswitch.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "propertyswitch.hpp" 3 | 4 | #include 5 | 6 | using namespace catnip; 7 | using namespace std; 8 | 9 | PropertySwitch::PropertySwitch() { setPropOption_("DEFAULT", "OFF"); } 10 | 11 | vector PropertySwitch::getOpts_(void) const { 12 | vector options{"DEFAULT"}; 13 | return options; 14 | } 15 | 16 | void PropertySwitch::switchValid(int val) const { 17 | if (val < 0 || val > 1) { 18 | string err = 19 | "Switches are only allowed to be on or off. By default they " 20 | "are set to off. An integer may be provided to the switch to " 21 | "toggle the behavior, however the integer is only allowed to " 22 | "be a 1 or a 0 you have provided a " + 23 | to_string(val); 24 | throw invalid_argument(err); 25 | } 26 | } 27 | 28 | void PropertySwitch::switchValid(std::string val) const { 29 | if (val.compare("0") != 0 && val.compare("1") != 0 && 30 | val.compare("ON") != 0 && val.compare("OFF") != 0 && 31 | val.compare("TRUE") != 0 && val.compare("FALSE") != 0) { 32 | string err = 33 | "Switches are only allowed to be on or off. By default they " 34 | "are set to off. A string may be provided to the switch to " 35 | "toggle the behavior, however the string is only allowed to " 36 | "be a TRUE/FALSE/ON/OFF you have provided a " + 37 | val; 38 | throw invalid_argument(err); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/libcatnip/io/arguments/properties/propertyswitch.hpp: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _CATNIP_PROPERTY_SWITCH_HPP 3 | #define _CATNIP_PROPERTY_SWITCH_HPP 4 | 5 | #include "propertyobject.hpp" 6 | 7 | namespace catnip { 8 | 9 | class PropertySwitch : public PropertyObject { 10 | private: 11 | std::string getName_(void) const { return "PROPERTY_SWITCH"; } 12 | std::vector getOpts_(void) const; 13 | void propOptionValueSettingValid_(); 14 | void switchValid(int val) const; 15 | void switchValid(std::string val) const; 16 | 17 | public: 18 | PropertySwitch(void); 19 | bool propValid(int value) { 20 | switchValid(value); 21 | return true; 22 | } 23 | bool propValid(const std::string& value) { 24 | switchValid(value); 25 | return true; 26 | } 27 | bool propValid() { return true; } 28 | }; 29 | 30 | } // namespace catnip 31 | #endif // _CATNIP_PROPERTY_SWITCH_HPP 32 | -------------------------------------------------------------------------------- /src/libcatnip/io/file_readers/filereader.cpp: -------------------------------------------------------------------------------- 1 | #include "filereader.hpp" 2 | #include "../../string_support.hpp" 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace catnip; 8 | using namespace std; 9 | 10 | // Public member functions 11 | 12 | string FileReader::getExt() const { return fileExt_(); } 13 | 14 | void FileReader::read() { 15 | open(); 16 | string line; 17 | while (getline(fid_, line)) { 18 | string tag = startSection_(line); 19 | if (!tag.empty()) { 20 | readSection_(tag); 21 | } 22 | pos_ = fid_.tellg(); 23 | } 24 | close(); 25 | } 26 | 27 | // Private member functions 28 | 29 | void FileReader::open() { 30 | if (!fileExist_()) { 31 | throw invalid_argument("File " + fileName_ + " does not exist."); 32 | } 33 | fid_.open(fileName_); 34 | fileOpen_ = true; 35 | } 36 | 37 | void FileReader::close() { 38 | fid_.close(); 39 | fileOpen_ = false; 40 | } 41 | 42 | void FileReader::registerSections_() { checkSections_(); } 43 | 44 | // Basically check that for a given tag both a section reader 45 | // as well as a section header pair exist 46 | void FileReader::checkSections_() { 47 | set tags; 48 | for (pair> &tag_and_header : sectionHeaders_) { 49 | tags.insert(tag_and_header.first); 50 | } 51 | for (auto pr : sectionReaders_) { 52 | tags.insert(pr.first); 53 | } 54 | for (auto t : tags) { 55 | if (sectionReaders_.count(t) == 0) { 56 | throw runtime_error("SectionReader function is missing for tag " + t); 57 | } 58 | if (sectionHeaders_.count(t) == 0) { 59 | throw runtime_error("SectionHeader pattern is missing for tag " + t); 60 | } 61 | } 62 | } 63 | 64 | string FileReader::fileExt_() const { 65 | string path = lastStringInPath(fileName_); 66 | path = trimmed(path); 67 | auto index = path.find("."); 68 | if (index == string::npos) throw invalid_argument("File has no extension"); 69 | return path.substr(index); 70 | } 71 | 72 | bool FileReader::fileExist_() const { 73 | struct stat buffer; 74 | return (stat(fileName_.c_str(), &buffer) == 0); 75 | } 76 | 77 | void FileReader::readSection_(string tag) { 78 | void *ptr = static_cast(this); 79 | sectionReaders_[tag](ptr); 80 | } 81 | 82 | string FileReader::startSection_(const string &line) { 83 | for (pair> &tag_and_header : sectionHeaders_) { 84 | for (const string &header : tag_and_header.second) { 85 | if (foundSubStrInStr(line, header)) { 86 | return tag_and_header.first; 87 | } 88 | } 89 | } 90 | return ""; 91 | } 92 | -------------------------------------------------------------------------------- /src/libcatnip/io/file_readers/filereader.hpp: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _CATNIP_FILEREADER_HPP_ 3 | #define _CATNIP_FILEREADER_HPP_ 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace catnip { 11 | 12 | struct FilePackage { 13 | void *ptr; 14 | }; 15 | 16 | class FileReader { 17 | public: 18 | FileReader(const std::string &fileName) : fileName_(fileName){}; 19 | std::string getExt() const; 20 | 21 | void read(); 22 | 23 | protected: 24 | typedef void (*FRfunc)(void *); 25 | 26 | // Private members 27 | void open(); 28 | void close(); 29 | virtual void registerSections_(); 30 | virtual void validFileName_(){}; 31 | void checkSections_(); 32 | void readSection_(std::string tag); 33 | std::string startSection_(const std::string &tag); 34 | std::string fileExt_() const; 35 | bool fileExist_() const; 36 | // Private attributes 37 | // key - stores tag of the section 38 | // value - stores the pattern used to identify the section 39 | std::map> sectionHeaders_; 40 | // key - stores tag of the section 41 | // value - stores the section reader function 42 | std::map sectionReaders_; 43 | 44 | std::string fileName_; 45 | std::ifstream fid_; 46 | std::streampos pos_; 47 | bool fileOpen_ = false; 48 | }; 49 | 50 | } // namespace catnip 51 | #endif // _CATNIP_FILEREADER_HPP_ 52 | -------------------------------------------------------------------------------- /src/libcatnip/io/file_readers/logreader.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "../../log.hpp" 11 | #include "../../string_support.hpp" 12 | #include "logreader.hpp" 13 | 14 | using namespace catnip; 15 | using namespace std; 16 | 17 | /** 18 | * \brief Specifically designed to split up energies in the log file 19 | **/ 20 | vector splitStEnergies(const string & line){ 21 | vector items = splitSt(line); 22 | if(items.size()==9) return items; 23 | 24 | // There should normally be 5 energies listed per line in a log file, if 25 | // there are fewer it may be the case that there are no spaces between 26 | // the doubles on the same line e.g. 27 | // col 1 col 2 col 3 col4 col 5 col 6 col 7 col 8 col 9 28 | // Alpha occ. eigenvalues -- -101.56324-101.56318-101.56026-101.56021-101.55975 29 | 30 | vector items2; 31 | std::string delimiter = "-"; 32 | 33 | for( size_t inc=0; inc{" Gross orbital populations:"}; 75 | sectionHeaders_["Overlap"] = set{" *** Overlap ***"}; 76 | sectionHeaders_["OEAlpha"] = set{" Alpha occ. eigenvalues --"}; 77 | sectionHeaders_["OEBeta"] = set{" Beta occ. eigenvalues --"}; 78 | sectionHeaders_["Coord"] = set{"Center Atomic Atomic", 79 | "Center Atomic Atomic"}; 80 | 81 | sectionReaders_["AOFunction"] = &LogReader::AOFunctionSectionReader; 82 | sectionReaders_["Overlap"] = &LogReader::OverlapSectionReader; 83 | sectionReaders_["OEAlpha"] = &LogReader::OrbitalEnergiesAlphaSectionReader; 84 | sectionReaders_["OEBeta"] = &LogReader::OrbitalEnergiesBetaSectionReader; 85 | sectionReaders_["Coord"] = &LogReader::CoordSectionReader; 86 | 87 | FileReader::registerSections_(); 88 | } 89 | 90 | void LogReader::validFileName_() { 91 | string ext = fileExt_(); 92 | if (ext.compare(".log") != 0) { 93 | throw invalid_argument("A log file must have the .log extension"); 94 | } 95 | } 96 | 97 | vector LogReader::getBasisFuncCount() { 98 | vector basisFuncCount; 99 | for (auto values : orb_) { 100 | basisFuncCount.push_back(values.second.size()); 101 | } 102 | return basisFuncCount; 103 | } 104 | 105 | void LogReader::AOFunctionSectionReader(void *ptr) { 106 | LOG("Reading atomic basis functions from .log file", 1); 107 | LogReader *LR_ptr = static_cast(ptr); 108 | 109 | int atom_num = 1; 110 | string end_pattern = " Condensed to atoms"; 111 | string line; 112 | getline(LR_ptr->fid_, line); 113 | getline(LR_ptr->fid_, line); 114 | bool sectionEnd = false; 115 | while (sectionEnd == false) { 116 | istringstream iss(line); 117 | string AOnum; 118 | iss >> AOnum; 119 | string elemType; 120 | iss >> elemType; 121 | iss >> elemType; 122 | 123 | string orbType; 124 | iss >> orbType; 125 | vector orbVals; 126 | while (!iss.eof()) { 127 | string Tot_Alpha_Beta_Spin; 128 | iss >> Tot_Alpha_Beta_Spin; 129 | orbVals.push_back(stod(Tot_Alpha_Beta_Spin)); 130 | } 131 | LR_ptr->orb_[make_pair(atom_num, elemType)][orbType] = orbVals; 132 | 133 | getline(LR_ptr->fid_, line); 134 | string elemType2 = ""; 135 | elemType2.append(string(1, line.at(9))); 136 | elemType2.append(string(1, line.at(10))); 137 | trim(elemType2); 138 | 139 | while (!isAlphabetical(elemType2)) { 140 | istringstream iss2(line); 141 | iss2 >> AOnum; 142 | iss2 >> orbType; 143 | 144 | orbVals.clear(); 145 | while (!iss2.eof()) { 146 | string Tot_Alpha_Beta_Spin; 147 | iss2 >> Tot_Alpha_Beta_Spin; 148 | orbVals.push_back(stod(Tot_Alpha_Beta_Spin)); 149 | } 150 | 151 | LR_ptr->orb_[make_pair(atom_num, elemType)][orbType] = orbVals; 152 | 153 | getline(LR_ptr->fid_, line); 154 | 155 | istringstream iss3(line); 156 | iss3 >> elemType2; 157 | iss3 >> elemType2; 158 | iss3 >> elemType2; 159 | trim(elemType2); 160 | 161 | if (foundSubStrInStr(line, end_pattern)) { 162 | sectionEnd = true; 163 | break; 164 | } 165 | } 166 | 167 | ++atom_num; 168 | // getline(LR_ptr->fid_,line); 169 | if (foundSubStrInStr(line, end_pattern)) { 170 | sectionEnd = true; 171 | } 172 | } 173 | 174 | LOG("Success reading atomic basis functions from .log file", 2); 175 | return; 176 | } 177 | 178 | void LogReader::OverlapSectionReader(void *ptr) { 179 | LOG("Reading Overlap Coefficients from .log file", 1); 180 | LogReader *LR_ptr = static_cast(ptr); 181 | 182 | // Phase one read in the first group of coordinates and count 183 | // to determien the number of AO coefficients there are 184 | int countCoef = 0; 185 | bool endFirstSection = false; 186 | // Skip first line simply has column numbers 187 | string line; 188 | getline(LR_ptr->fid_, line); 189 | string countC; 190 | 191 | // First group of coordinates will be stored in vector> 192 | vector> first_coefs; 193 | while (!endFirstSection) { 194 | getline(LR_ptr->fid_, line); 195 | istringstream iss(line); 196 | iss >> countC; 197 | int countCint = stoi(countC); 198 | if (countCint != (countCoef + 1)) { 199 | endFirstSection = true; 200 | } else { 201 | ++countCoef; 202 | vector row; 203 | 204 | // Safe to read in coordinates of first couple of columns 205 | while (!iss.eof()) { 206 | string s_coef; 207 | iss >> s_coef; 208 | string val = grabStrBeforeFirstOccurance(s_coef, "D"); 209 | string exp = grabStrAfterFirstOccurance(s_coef, "D"); 210 | row.push_back(stod(val) * pow(10.0, stod(exp))); 211 | } 212 | first_coefs.push_back(row); 213 | } 214 | } 215 | 216 | // Create a matrix and place all the current values in there 217 | Matrix *mat_S = new Matrix(countCoef, countCoef); 218 | for (size_t row_ind = 0; row_ind < first_coefs.size(); ++row_ind) { 219 | vector row = first_coefs.at(row_ind); 220 | size_t col_ind = 1; 221 | for (auto val : row) { 222 | mat_S->set_elem(val, row_ind + 1, col_ind); 223 | // Because diagonally symetric 224 | if (row_ind + 1 != col_ind) { 225 | mat_S->set_elem(val, col_ind, row_ind + 1); 226 | } 227 | ++col_ind; 228 | } 229 | } 230 | 231 | int sectionReads = countCoef / 5; 232 | if (countCoef % 5 > 0) { 233 | ++sectionReads; 234 | } 235 | 236 | int section = 2; 237 | int currentSectionStart = 5; 238 | while (section <= sectionReads) { 239 | 240 | int sectionCoef = currentSectionStart; 241 | while (sectionCoef < countCoef) { 242 | getline(LR_ptr->fid_, line); 243 | istringstream iss(line); 244 | string dummy; 245 | iss >> dummy; 246 | int localCoefCount = 1; 247 | while (!iss.eof()) { 248 | string s_coef; 249 | iss >> s_coef; 250 | string val = grabStrBeforeFirstOccurance(s_coef, "D"); 251 | string expon = grabStrAfterFirstOccurance(s_coef, "D"); 252 | double value = stod(val) * pow(10.0, stod(expon)); 253 | mat_S->set_elem(value, sectionCoef + 1, 254 | currentSectionStart + localCoefCount); 255 | if ((sectionCoef + 1) != (currentSectionStart + localCoefCount)) { 256 | 257 | mat_S->set_elem(value, currentSectionStart + localCoefCount, 258 | sectionCoef + 1); 259 | } 260 | ++localCoefCount; 261 | } 262 | ++sectionCoef; 263 | } 264 | ++section; 265 | currentSectionStart += 5; 266 | getline(LR_ptr->fid_, line); 267 | } 268 | LR_ptr->S_ = mat_S; 269 | LOG("Success reading Overlap coefficients from .log file", 2); 270 | return; 271 | } 272 | 273 | void LogReader::ReadOrbEnergies(const string &orb_type) { 274 | 275 | LOG("Reading Orbital Energies from .log file", 1); 276 | string line; 277 | homoLevel[orb_type] = 0; 278 | // May be multiple energy sections we only wanted the latest one 279 | OREnergies[orb_type].clear(); 280 | while (getline(fid_, line)) { 281 | 282 | bool occFound; 283 | bool virtFound; 284 | 285 | occFound = 286 | foundSubStrInStr(line, " " + orb_type + " occ. eigenvalues -- "); 287 | virtFound = 288 | foundSubStrInStr(line, " " + orb_type + " virt. eigenvalues -- "); 289 | 290 | if (occFound || virtFound) { 291 | 292 | auto vec_str = splitStEnergies(line); 293 | for (size_t inc = 4; inc < vec_str.size(); inc++) { 294 | OREnergies[orb_type].push_back((double)atof(vec_str.at(inc).c_str())); 295 | if (occFound) homoLevel[orb_type]++; 296 | } 297 | } else { 298 | break; 299 | } 300 | pos_ = fid_.tellg(); 301 | } 302 | // Reset the fid because Beta will come right after alpha 303 | fid_.seekg(pos_); 304 | LOG("Success reading Orbital Energies from .log file", 2); 305 | } 306 | 307 | void LogReader::OrbitalEnergiesAlphaSectionReader(void *ptr) { 308 | LogReader *LR_ptr = static_cast(ptr); 309 | string line; 310 | LR_ptr->fid_.seekg(LR_ptr->pos_); 311 | LR_ptr->ReadOrbEnergies("Alpha"); 312 | } 313 | 314 | void LogReader::OrbitalEnergiesBetaSectionReader(void *ptr) { 315 | LogReader *LR_ptr = static_cast(ptr); 316 | string line; 317 | LR_ptr->fid_.seekg(LR_ptr->pos_); 318 | LR_ptr->ReadOrbEnergies("Beta"); 319 | } 320 | 321 | void LogReader::CoordSectionReader(void *ptr) { 322 | LOG("Reading Coordinates from .log file", 1); 323 | LogReader *LR_ptr = static_cast(ptr); 324 | 325 | // Clear contents only want the most uptodate coordinates 326 | LR_ptr->xyz.clear(); 327 | vector X; 328 | vector Y; 329 | vector Z; 330 | 331 | string end_pattern = 332 | "-----------------------------------" 333 | "----------------------------------"; 334 | string line; 335 | // Skip the 2nd and third line 336 | getline(LR_ptr->fid_, line); 337 | getline(LR_ptr->fid_, line); 338 | getline(LR_ptr->fid_, line); 339 | 340 | // While the line does not match the end of the table read in the coordinates 341 | while (!foundSubStrInStr(line, end_pattern)) { 342 | auto vec_str = splitSt(line); 343 | X.push_back(stod(vec_str.at(3))); 344 | Y.push_back(stod(vec_str.at(4))); 345 | Z.push_back(stod(vec_str.at(5))); 346 | getline(LR_ptr->fid_, line); 347 | } 348 | LR_ptr->xyz.push_back(X); 349 | LR_ptr->xyz.push_back(Y); 350 | LR_ptr->xyz.push_back(Z); 351 | 352 | LOG("Success reading Coordinates from .log file", 2); 353 | } 354 | -------------------------------------------------------------------------------- /src/libcatnip/io/file_readers/logreader.hpp: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _CATNIP_LOGREADER_HPP_ 3 | #define _CATNIP_LOGREADER_HPP_ 4 | 5 | #include 6 | 7 | #include "../../matrix.hpp" 8 | #include "filereader.hpp" 9 | // Gaussian log file reader 10 | 11 | namespace catnip { 12 | 13 | typedef std::map, 14 | std::map>> 15 | orb_cont; 16 | 17 | class LogReader : public FileReader { 18 | public: 19 | explicit LogReader(const std::string &str); 20 | orb_cont getOrbitalInfo() const { return orb_; } 21 | Matrix *getOverlapMatrix() const { return S_; } 22 | std::vector getOE(const std::string &orb_type) const { 23 | return OREnergies.at(orb_type); 24 | } 25 | int getHOMOLevel(const std::string &orb_type) const { 26 | return homoLevel.at(orb_type); 27 | } 28 | std::vector getBasisFuncCount(); 29 | std::vector> getCoords() const { return xyz; } 30 | 31 | private: 32 | virtual void registerSections_(); 33 | virtual void validFileName_(); 34 | 35 | static void AOFunctionSectionReader(void *); 36 | static void OverlapSectionReader(void *); 37 | static void OrbitalEnergiesAlphaSectionReader(void *); 38 | static void OrbitalEnergiesBetaSectionReader(void *); 39 | static void CoordSectionReader(void *); 40 | 41 | void ReadOrbEnergies(const std::string &orb_type); 42 | // Contains the information as so: 43 | // each element in the map refers to an atom and its type C, H, N etc 44 | // The first element of the second map contains the orbital type 45 | // 1S, 2S, 3PY etc... 46 | // The vector contains the Total Alpha Beta and Spin if there are no 47 | // Beta's the vector will be one item shorter 48 | std::map homoLevel; 49 | orb_cont orb_; 50 | // Overlap matrix 51 | Matrix *S_; 52 | std::map> OREnergies; 53 | 54 | std::vector> xyz; 55 | }; 56 | 57 | } // namespace catnip 58 | 59 | #endif // _CATNIP_LOGREADER_HPP_ 60 | -------------------------------------------------------------------------------- /src/libcatnip/io/file_readers/punreader.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "../../log.hpp" 11 | #include "../../string_support.hpp" 12 | #include "punreader.hpp" 13 | 14 | using namespace catnip; 15 | using namespace std; 16 | 17 | PunReader::PunReader(const string &fileName) : FileReader(fileName) { 18 | validFileName_(); 19 | registerSections_(); 20 | } 21 | 22 | void PunReader::registerSections_() { 23 | sectionHeaders_["CoefAlpha"] = set{" 1 Alpha MO "}; 24 | sectionHeaders_["CoefBeta"] = set{" 1 Beta MO "}; 25 | 26 | sectionReaders_["CoefAlpha"] = &PunReader::OrbitalCoefAlphaSectionReader; 27 | sectionReaders_["CoefBeta"] = &PunReader::OrbitalCoefBetaSectionReader; 28 | 29 | FileReader::registerSections_(); 30 | } 31 | 32 | Matrix *PunReader::getCoefsMatrix(const string &orb_type) { 33 | if (coefs.count(orb_type) != 1) { 34 | throw invalid_argument("Coefficients for spin " + orb_type + 35 | " were not found"); 36 | } 37 | return coefs[orb_type]; 38 | } 39 | 40 | void PunReader::validFileName_() { 41 | string ext = fileExt_(); 42 | if (ext.compare(".pun") != 0) { 43 | throw invalid_argument("A pun file must have the .pun extension"); 44 | } 45 | } 46 | 47 | vector PunReader::readGausCoefLine(const string &line) { 48 | vector values; 49 | 50 | int indent = 0; 51 | while ((line.length() - indent) >= 15) { 52 | string str = line.substr(0 + indent, 11); 53 | str = trimmed(str); 54 | double temp_d = stod(str); 55 | str = line.substr(12 + indent, 3); 56 | str = trimmed(str); 57 | double temp_d2 = stod(str); 58 | values.push_back(temp_d * pow(10, temp_d2)); 59 | indent += 15; 60 | } 61 | return values; 62 | } 63 | 64 | void PunReader::ReadCoef(const string &orb_type) { 65 | 66 | LOG("Reading atomic orbital coefficients from .pun file.", 1); 67 | string pattern = " MO OE"; 68 | 69 | vector> v_vec; 70 | size_t count = 0; 71 | bool first_row_set = false; 72 | 73 | bool allCoefsRead = false; 74 | while (!allCoefsRead) { 75 | string line; 76 | getline(fid_, line); 77 | vector row; 78 | size_t current_count = 0; 79 | while (!foundSubStrInStr(line, pattern)) { 80 | 81 | if (first_row_set && current_count >= count) break; 82 | auto coef = readGausCoefLine(line); 83 | for (auto val : coef) { 84 | row.push_back(val); 85 | ++current_count; 86 | } 87 | getline(fid_, line); 88 | } 89 | first_row_set = true; 90 | count = row.size(); 91 | v_vec.push_back(row); 92 | 93 | allCoefsRead = !(foundSubStrInStr(line, orb_type)); 94 | } 95 | 96 | Matrix *Coefs = new Matrix(v_vec); 97 | coefs[orb_type] = Coefs; 98 | LOG("Success reading atomic orbital coefficients from .pun file.", 2); 99 | } 100 | 101 | void PunReader::OrbitalCoefAlphaSectionReader(void *ptr) { 102 | PunReader *PR_ptr = static_cast(ptr); 103 | PR_ptr->ReadCoef("Alpha"); 104 | } 105 | 106 | void PunReader::OrbitalCoefBetaSectionReader(void *ptr) { 107 | PunReader *PR_ptr = static_cast(ptr); 108 | PR_ptr->ReadCoef("Beta"); 109 | } 110 | -------------------------------------------------------------------------------- /src/libcatnip/io/file_readers/punreader.hpp: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _CATNIP_PUNREADER_HPP_ 3 | #define _CATNIP_PUNREADER_HPP_ 4 | 5 | #include 6 | 7 | #include "../../matrix.hpp" 8 | #include "filereader.hpp" 9 | // Gaussian fort.7/.pun file reader 10 | namespace catnip { 11 | 12 | class PunReader : public FileReader { 13 | public: 14 | explicit PunReader(const std::string &str); 15 | Matrix *getCoefsMatrix(const std::string &orb_type); 16 | bool restrictedShell() { return coefs.size() == 1; } 17 | 18 | private: 19 | virtual void registerSections_(); 20 | virtual void validFileName_(); 21 | 22 | static void OrbitalCoefAlphaSectionReader(void *); 23 | static void OrbitalCoefBetaSectionReader(void *); 24 | 25 | void ReadCoef(const std::string &orb_type); 26 | std::vector readGausCoefLine(const std::string &line); 27 | 28 | std::map coefs; 29 | }; 30 | 31 | } // namespace catnip 32 | #endif // _CATNIP_PUNREADER_HPP_ 33 | -------------------------------------------------------------------------------- /src/libcatnip/io/io.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _CATNIP_IO_HPP 2 | #define _CATNIP_IO_HPP 3 | #include "../matrix.hpp" 4 | #include "../parameters.hpp" 5 | #include "argumentparser.hpp" 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace catnip { 13 | 14 | std::unique_ptr prepareParser(void); 15 | 16 | std::unique_ptr prepareParameters( 17 | std::unique_ptr& ArgParse); 18 | 19 | } // namespace catnip 20 | 21 | #endif // _CATNIP_IO_HPP 22 | -------------------------------------------------------------------------------- /src/libcatnip/log.hpp: -------------------------------------------------------------------------------- 1 | // Taken from 2 | // https://stackoverflow.com/questions/19415845/a-better-log-macro-using-template-metaprogramming 3 | 4 | #ifndef _CATNIP_LOG_HPP_ 5 | #define _CATNIP_LOG_HPP_ 6 | 7 | #ifndef LOG_LEVEL 8 | #define LOG_LEVEL 0 9 | #endif 10 | 11 | #include 12 | 13 | namespace catnip { 14 | 15 | #define LOG(msg, log_level) \ 16 | (Log(__FILE__, __LINE__, LogData() << msg, log_level)) 17 | 18 | // Workaround GCC 4.7.2 not recognizing noinline attribute 19 | #ifndef NOINLINE_ATTRIBUTE 20 | #ifdef __ICC 21 | #define NOINLINE_ATTRIBUTE __attribute__((noinline)) 22 | #else 23 | #define NOINLINE_ATTRIBUTE 24 | #endif // __ICC 25 | #endif // NOINLINE_ATTRIBUTE 26 | 27 | struct None {}; 28 | 29 | template 30 | struct LogData { 31 | List list; 32 | }; 33 | 34 | template 35 | void Log(const char* file, int line, LogData&& data, 36 | int log_level) NOINLINE_ATTRIBUTE { 37 | if (log_level <= LOG_LEVEL) { 38 | std::cout << file << ":" << line << ": "; 39 | output(std::cout, std::move(data.list)); 40 | std::cout << std::endl; 41 | } 42 | } 43 | 44 | template 45 | constexpr LogData> operator<<( 46 | LogData&& begin, Value&& value) noexcept { 47 | return {{std::forward(begin.list), std::forward(value)}}; 48 | } 49 | 50 | template 51 | constexpr LogData> operator<<( 52 | LogData&& begin, const char (&value)[n]) noexcept { 53 | return {{std::forward(begin.list), value}}; 54 | } 55 | 56 | typedef std::ostream& (*PfnManipulator)(std::ostream&); 57 | 58 | template 59 | constexpr LogData> operator<<( 60 | LogData&& begin, PfnManipulator value) noexcept { 61 | return {{std::forward(begin.list), value}}; 62 | } 63 | 64 | template 65 | void output(std::ostream& os, std::pair&& data) { 66 | output(os, std::move(data.first)); 67 | os << data.second; 68 | } 69 | 70 | inline void output(std::ostream& os, None) { os << ""; } 71 | 72 | } // namespace catnip 73 | #endif // _CATNIP_LOG_HPP_ 74 | -------------------------------------------------------------------------------- /src/libcatnip/matrix.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _CATNIP_Matrix_HPP 2 | #define _CATNIP_Matrix_HPP 3 | #include 4 | #include 5 | #include 6 | 7 | namespace catnip { 8 | 9 | class Matrix { 10 | private: 11 | int rows; 12 | int cols; 13 | int shel; 14 | double *elem; 15 | 16 | public: 17 | // constructors 18 | explicit Matrix(void); 19 | explicit Matrix(std::vector); 20 | explicit Matrix(std::vector); 21 | explicit Matrix(std::vector>); 22 | explicit Matrix(const int r); 23 | Matrix(const int r, const int c); 24 | Matrix(const int r, const int c, const int s); 25 | 26 | Matrix &operator=(const Matrix &m); 27 | // manipulators 28 | void set_rows(int r); 29 | void set_cols(int c); 30 | void set_shel(int s); 31 | void set_row(std::vector row, int r); 32 | void set_col(std::vector col, int c); 33 | int resize(int r, int c); 34 | void set_elem(double val); 35 | void set_elem(double val, int r); 36 | void set_elem(double val, int r, int c); 37 | void set_elem(double val, int r, int c, int s); 38 | // accessors 39 | int index(const int r, const int c, const int s) const; 40 | int get_rows() const; 41 | int get_cols() const; 42 | int get_shel() const; 43 | int total_elem(); 44 | double get_elem() const; 45 | double get_elem(const int r) const; 46 | double get_elem(const int r, const int c) const; 47 | double get_elem(const int r, const int c, const int s) const; 48 | double *get_elem_ptr(const int r, const int c) const; 49 | std::vector get_col(int c) const; 50 | std::vector get_row(int r) const; 51 | 52 | // WARNING This is not a swap row operation 53 | // All rows are shifted to make way 54 | // for the new row/col. 'r_from' is moved to 'r_to' while 55 | // all rows are appropriately shifted to make this happen. 56 | void move_row(int r_from, int r_to); 57 | void move_col(int c_from, int c_to); 58 | 59 | // The intial and final row/col simply change places 60 | // none of the rows and cols other than the ones swapped 61 | // are affected 62 | void swap_row(int r_from, int r_to); 63 | void swap_col(int c_from, int c_to); 64 | 65 | Matrix getCol(int c) const; 66 | Matrix getRow(int r) const; 67 | // Basically switches the rows and columns 68 | Matrix invert(void) const; 69 | // Responsible for matching the rows between two matrices they do not need 70 | // Returns which row in the current matrix matches which row in the one 71 | // passed in, -1 means there is no match 72 | // sf is the number of significant figures that will be checked to ensure 73 | // the same value 74 | std::vector matchRow(const Matrix & mat, int sf); 75 | std::vector matchCol(const Matrix &mat, const int sf) const; 76 | }; 77 | 78 | std::ostream &operator<<(std::ostream &out, Matrix &mat); 79 | 80 | Matrix &operator*(const Matrix &mat1, const Matrix &mat2); 81 | 82 | // Takes a vector and diagonalized the 83 | // vector in a 2 dimensional matrix where 84 | // everything but the diagonal is assigned 85 | // a 0 86 | Matrix Matrix_diag(const Matrix &mat); 87 | 88 | // Copies a matrix and returns the new 89 | // matrix 90 | Matrix Matrix_copy(const Matrix &mat); 91 | 92 | // Add two matrices together to create a third 93 | // mat1 will always appear above mat2 in the rows 94 | // of the matrix that is returned. 95 | Matrix Matrix_concatenate_rows(Matrix mat1,const Matrix & mat2); 96 | Matrix Matrix_concatenate_cols(const Matrix &mat1, const Matrix &mat2); 97 | 98 | } // namespace catnip 99 | 100 | #endif // _CATNIP_Matrix_HPP 101 | -------------------------------------------------------------------------------- /src/libcatnip/parameters.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "parameters.hpp" 3 | #include "string_support.hpp" 4 | #include 5 | #include 6 | 7 | using namespace catnip; 8 | using namespace std; 9 | 10 | void Parameters::setLog1(const string& log1) { 11 | string ext = lastN(log1, 4); 12 | if (ext.compare(".log")) 13 | throw invalid_argument("log file has wrong extension"); 14 | log1_ = log1; 15 | } 16 | void Parameters::setLog2(const string& log2) { 17 | string ext = lastN(log2, 4); 18 | if (ext.compare(".log")) 19 | throw invalid_argument("log file has wrong extension"); 20 | log2_ = log2; 21 | } 22 | void Parameters::setLogP(const string& logP) { 23 | string ext = lastN(logP, 4); 24 | if (ext.compare(".log")) 25 | throw invalid_argument("log file has wrong extension"); 26 | logP_ = logP; 27 | } 28 | void Parameters::setPun1(const string& pun1) { 29 | string ext = lastN(pun1, 4); 30 | if (ext.compare(".pun")) 31 | throw invalid_argument("pun file has wrong extension"); 32 | pun1_ = pun1; 33 | } 34 | void Parameters::setPun2(const string& pun2) { 35 | string ext = lastN(pun2, 4); 36 | if (ext.compare(".pun")) 37 | throw invalid_argument("pun file has wrong extension"); 38 | pun2_ = pun2; 39 | } 40 | void Parameters::setPunP(const string& punP) { 41 | string ext = lastN(punP, 4); 42 | if (ext.compare(".pun")) 43 | throw invalid_argument("pun file has wrong extension"); 44 | punP_ = punP; 45 | } 46 | -------------------------------------------------------------------------------- /src/libcatnip/parameters.hpp: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _CATNIP_PARAMETERS_HPP_ 3 | #define _CATNIP_PARAMETERS_HPP_ 4 | 5 | #include 6 | 7 | namespace catnip { 8 | 9 | class Parameters { 10 | private: 11 | std::string log1_; 12 | std::string log2_; 13 | std::string logP_; 14 | std::string pun1_; 15 | std::string pun2_; 16 | std::string punP_; 17 | 18 | std::string spinP; 19 | std::string spin1; 20 | std::string spin2; 21 | 22 | std::string orb_typeP; 23 | std::string orb_type1; 24 | std::string orb_type2; 25 | 26 | int orb_numP; 27 | int orb_num1; 28 | int orb_num2; 29 | 30 | bool citation; 31 | bool counterPoise; 32 | 33 | public: 34 | Parameters() 35 | : log1_(""), 36 | log2_(""), 37 | logP_(""), 38 | pun1_(""), 39 | pun2_(""), 40 | punP_(""), 41 | spinP(""), 42 | spin1(""), 43 | spin2(""), 44 | orb_typeP(""), 45 | orb_type1(""), 46 | orb_type2(""), 47 | orb_numP(0), 48 | orb_num1(0), 49 | orb_num2(0), 50 | counterPoise(false){}; 51 | 52 | std::string getLog1() const { return log1_; } 53 | std::string getLog2() const { return log2_; } 54 | std::string getLogP() const { return logP_; } 55 | std::string getPun1() const { return pun1_; } 56 | std::string getPun2() const { return pun2_; } 57 | std::string getPunP() const { return punP_; } 58 | 59 | std::string getSpinP() const { return spinP; } 60 | std::string getSpin1() const { return spin1; } 61 | std::string getSpin2() const { return spin2; } 62 | 63 | std::string getOrbTypeP() const { return orb_typeP; } 64 | std::string getOrbType1() const { return orb_type1; } 65 | std::string getOrbType2() const { return orb_type2; } 66 | 67 | int getOrbNumP() const { return orb_numP; } 68 | int getOrbNum1() const { return orb_num1; } 69 | int getOrbNum2() const { return orb_num2; } 70 | bool getCounterPoise() const { return counterPoise; } 71 | bool getCitation() const { return citation; } 72 | 73 | void setLog1(const std::string& log1); 74 | void setLog2(const std::string& log2); 75 | void setLogP(const std::string& logP); 76 | void setPun1(const std::string& pun1); 77 | void setPun2(const std::string& pun2); 78 | void setPunP(const std::string& punP); 79 | 80 | void setSpinP(const std::string& spin) { spinP = spin; } 81 | void setSpin1(const std::string& spin) { spin1 = spin; } 82 | void setSpin2(const std::string& spin) { spin2 = spin; } 83 | 84 | void setOrbTypeP(const std::string& orb) { orb_typeP = orb; } 85 | void setOrbType1(const std::string& orb) { orb_type1 = orb; } 86 | void setOrbType2(const std::string& orb) { orb_type2 = orb; } 87 | 88 | void setOrbNumP(const int& num) { orb_numP = num; } 89 | void setOrbNum1(const int& num) { orb_num1 = num; } 90 | void setOrbNum2(const int& num) { orb_num2 = num; } 91 | void setCounterPoise(bool cp) { counterPoise = cp; } 92 | void setCitation(bool cite) { citation = cite; } 93 | }; 94 | 95 | } // namespace catnip 96 | #endif // _CATNIP_PARAMETERS_HPP_ 97 | -------------------------------------------------------------------------------- /src/libcatnip/qc_functions.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _CATNIP_QC_FUNCTIONS_HPP 2 | #define _CATNIP_QC_FUNCTIONS_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "matrix.hpp" 11 | 12 | namespace catnip { 13 | 14 | class TransferComplex { 15 | private: 16 | Matrix* mat_1_Coef; 17 | Matrix* mat_2_Coef; 18 | Matrix* mat_P_Coef; 19 | // Stores the number of Molecular orbitals 20 | // and the HOMO for both monomer 1 and 2 21 | std::pair Orbs1; 22 | std::pair Orbs2; 23 | Matrix* mat_S; 24 | Matrix* mat_P_OE; 25 | // If unscrambaling is required 26 | bool unscrambled; 27 | bool counterPoise_; 28 | 29 | public: 30 | TransferComplex(Matrix* mat1Coef, Matrix* mat2Coef, Matrix* matPCoef, 31 | std::pair MOs1, std::pair MOs2, 32 | Matrix* matS, Matrix* matPOE, bool cp); 33 | 34 | void unscramble(const Matrix& coord_1_mat, const Matrix& coord_2_mat, 35 | const Matrix& coord_P_mat, const std::vector& basisP, 36 | const std::vector& basis2); 37 | 38 | // Orbital type and a map of the corresponding number 39 | // E.g. 40 | // orbital type orbital number 41 | // "mon1" "LUMO" "mon1" -3 42 | // "mon2" "HOMO" "mon2" 0 43 | // 44 | // monomer1 LUMO-3 45 | // monomer2 HOMO 46 | double calcJ(const std::map& orbitaltype, 47 | const std::map& orbitalnum); 48 | }; 49 | 50 | std::unordered_map> findRank( 51 | Matrix& Orb_E_Alpha, Matrix& Orb_E_Beta); 52 | 53 | double calculate_transfer_integral(const Matrix & mat_1_Coef, const Matrix & mat_2_Coef, 54 | Matrix mat_P_Coef,const Matrix & mat_S, 55 | const Matrix& mat_P_OE, bool counterPoise_); 56 | 57 | // Reorganize the dimer coefficients to match up with the monomers 58 | Matrix organize_P_Coef(std::vector matchDimerA, 59 | std::vector matchDimerB, 60 | std::vector basisFuncA, std::vector basisFuncB, 61 | std::vector basisFuncDimer, Matrix dimerCoef); 62 | 63 | // Unscramble the coefficients of the dimer matrix 64 | // Assumes that the match vectors describe swaps looking at a single 65 | // instance of the dimerCoef matrix 66 | Matrix* unscramble_Coef(const std::vector& matchDimerA, 67 | const std::vector& matchDimerB, 68 | const std::vector& basisFuncDimer, 69 | Matrix* dimerCoef); 70 | 71 | Matrix* unscramble_Coef(const std::vector& matchDimerA, 72 | const std::vector& basisFuncDimer, Matrix* dimerCoef); 73 | 74 | // Reorganize the dimer overlap matrix to line up with the monomer 75 | // coefficients. 76 | Matrix* unscramble_S(const std::vector& matchDimerA, 77 | const std::vector& matchDimerB, 78 | const std::vector& basisFuncDimer, Matrix* S); 79 | 80 | Matrix* unscramble_S(const std::vector& matchDimerA, 81 | const std::vector& basisFuncDimer, Matrix* S); 82 | 83 | Matrix* unscramble_OE(std::vector matchDimerA, 84 | std::vector matchDimerB, 85 | std::vector basisFuncDimer, Matrix* OE); 86 | 87 | } // namespace catnip 88 | #endif // _CATNIP_QC_FUNCTIONS_HPP 89 | -------------------------------------------------------------------------------- /src/libcatnip/string_support.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "string_support.hpp" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | using namespace std; 13 | ///////////////////////////////////// 14 | // Internal functions 15 | ///////////////////////////////////// 16 | 17 | namespace catnip { 18 | 19 | const string PATH_SEPERATOR_ = 20 | #ifdef _WIN32 21 | "\\/"; 22 | #else 23 | "/"; 24 | #endif 25 | // const std::string PATH_SEPERATOR_; 26 | // FROM 27 | // https://stackoverflow.com/questions/12971499/how-to-get-the-file-separator-symbol-in-standard-c-c-or 28 | // A compatible edit for running on windows Command line 29 | 30 | // trim from start (in place) 31 | void ltrim_(string &s) { 32 | s.erase(s.begin(), 33 | find_if(s.begin(), s.end(), not1(ptr_fun(isspace)))); 34 | } 35 | 36 | // trim from end (in place) 37 | void rtrim_(string &s) { 38 | s.erase( 39 | find_if(s.rbegin(), s.rend(), not1(ptr_fun(isspace))).base(), 40 | s.end()); 41 | } 42 | 43 | // Split a string up by spaces 44 | vector splitSt(const string & input) { 45 | istringstream iss(input); 46 | list tokens; 47 | copy(istream_iterator(iss), istream_iterator(), 48 | back_inserter(tokens)); 49 | 50 | vector values; 51 | for (std::string item : tokens) { 52 | if (!item.empty()) values.push_back(item); 53 | } 54 | return values; 55 | } 56 | 57 | string lastStringInPath(const string& input) { 58 | size_t found; 59 | string line; 60 | line = input; 61 | while ( 62 | (int)(found = line.find_first_of(PATH_SEPERATOR_)) != 63 | -1) { // http://www.cplusplus.com/reference/string/string/find_first_of/ 64 | line = line.substr(found + 1, line.size()); 65 | } 66 | return line; 67 | } 68 | 69 | string getPath(string input) { 70 | size_t found = 0; 71 | size_t found2 = found; 72 | string val = ""; 73 | string line = input; 74 | while ((int)found != -1) { 75 | found = line.find_first_of( 76 | PATH_SEPERATOR_); // http://www.cplusplus.com/reference/string/string/find_first_of/ 77 | line = line.substr(found + 1, line.size()); 78 | found2 += found + 1; 79 | val = input.substr(0, found2); 80 | } 81 | return val; 82 | } 83 | 84 | string lastN(string input, int n) { return input.substr(input.size() - n); } 85 | 86 | string cut_end(string input, int n) { 87 | return input.substr(0, input.size() - n); 88 | } 89 | 90 | string firstN(string input, int n) { return input.substr(0, n); } 91 | 92 | string cut_beg(string input, int n) { return input.substr(n, input.size()); } 93 | 94 | // trim from both ends (in place) 95 | void trim(string &s) { 96 | ltrim_(s); 97 | rtrim_(s); 98 | } 99 | 100 | // trim from start (copying) 101 | string ltrimmed(string s) { 102 | ltrim_(s); 103 | return s; 104 | } 105 | 106 | // trim from end (copying) 107 | string rtrimmed(string s) { 108 | rtrim_(s); 109 | return s; 110 | } 111 | 112 | // trim from both ends (copying) 113 | string trimmed(string s) { 114 | trim(s); 115 | return s; 116 | } 117 | 118 | void removeSpace(char *s) { 119 | char *s2 = s; 120 | do { 121 | if (*s2 != ' ') *s++ = *s2; 122 | } while (*s2++); 123 | } 124 | 125 | string grabStrAfterFirstOccurance(string s, string occ) { 126 | size_t str_len = occ.length(); 127 | size_t pos = s.find(occ); 128 | if (pos == string::npos) { 129 | return ""; 130 | } 131 | return s.substr(pos + str_len); 132 | } 133 | 134 | string grabStrAfterLastOccurance(string s, string occ) { 135 | auto pos = s.find_last_of(occ); 136 | if (pos == string::npos) return ""; 137 | return s.substr(pos + 1); 138 | } 139 | 140 | string grabStrAfterLastOccuranceInclusive(string s, string occ) { 141 | auto pos = s.find_last_of(occ); 142 | if (pos == string::npos) return ""; 143 | return s.substr(pos); 144 | } 145 | 146 | string grabStrBeforeFirstOccurance(string s, string occ) { 147 | size_t pos = s.find(occ); 148 | if (pos == string::npos) return s; 149 | return s.substr(0, pos); 150 | } 151 | 152 | string grabStrBeforeLastOccurance(string s, string occ) { 153 | auto pos = s.find_last_of(occ); 154 | if (pos == string::npos) return s; 155 | return s.substr(0, pos); 156 | } 157 | 158 | string grabStrBeforeLastOccuranceInclusive(string s, string occ) { 159 | auto pos = s.find_last_of(occ); 160 | if (pos == string::npos) return s; 161 | return s.substr(0, pos + 1); 162 | } 163 | 164 | bool foundSubStrInStr(string s, string sub_s) { 165 | return s.find(sub_s) != string::npos; 166 | } 167 | 168 | bool isAlphabetical(std::string s) { 169 | return find_if(s.begin(), s.end(), not1(ptr_fun((int (*)(int))isalpha))) == 170 | s.end() && 171 | !s.empty(); 172 | } 173 | 174 | } // namespace catnip 175 | -------------------------------------------------------------------------------- /src/libcatnip/string_support.hpp: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _CATNIP_STRING_SUPPORT_HPP_ 3 | #define _CATNIP_STRING_SUPPORT_HPP_ 4 | 5 | #include 6 | #include 7 | 8 | namespace catnip { 9 | 10 | // Split a std::string up by spaces 11 | std::vector splitSt(const std::string & input); 12 | 13 | // Given a path name this function finds the last part 14 | // in the path which should be associated with the path 15 | // /director/structure/File.cc 16 | // passing this path into the function will return File.cc 17 | std::string lastStringInPath(const std::string& input); 18 | 19 | // Grab Path only leave off the file name 20 | std::string getPath(std::string input); 21 | 22 | // Grabs the last n characters of a string 23 | std::string lastN(std::string input, int n); 24 | 25 | // Removes the last n characters from a string 26 | std::string cut_end(std::string input, int n); 27 | 28 | std::string firstN(std::string input, int n); 29 | 30 | std::string cut_beg(std::string input, int n); 31 | 32 | // trim from both ends (in place) 33 | void trim(std::string &s); 34 | 35 | // trim from start (copying) 36 | std::string ltrimmed(std::string s); 37 | 38 | // trim from end (copying) 39 | std::string rtrimmed(std::string s); 40 | 41 | // trim from both ends (copying) 42 | std::string trimmed(std::string s); 43 | 44 | void removeSpace(std::string s); 45 | 46 | // Grab everything after the first occurance of a string. 47 | std::string grabStrAfterFirstOccurance(std::string s, std::string occ); 48 | 49 | std::string grabStrAfterLastOccurance(std::string s, std::string occ); 50 | 51 | std::string grabStrAfterLastOccuranceInclusive(std::string s, std::string occ); 52 | 53 | // Grab everything before first occurance of a string 54 | std::string grabStrBeforeFirstOccurance(std::string s, std::string occ); 55 | 56 | std::string grabStrBeforeLastOccurance(std::string s, std::string occ); 57 | 58 | std::string grabStrBeforeLastOccuranceInclusive(std::string s, std::string occ); 59 | 60 | // Determine if the sub string exists within the string 61 | bool foundSubStrInStr(std::string s, std::string sub_s); 62 | 63 | // Determine if whole string is alphabetical characters 64 | bool isAlphabetical(std::string s); 65 | 66 | } // namespace catnip 67 | #endif // _CATNIP_STRING_SUPPORT_HPP_ 68 | -------------------------------------------------------------------------------- /src/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | list( APPEND UNIT_TEST_SOURCE_FILES 2 | test_argumentdouble 3 | test_argumentfile 4 | test_argumentint 5 | test_argumentparser 6 | test_argumentstring 7 | test_argumentswitch 8 | test_log 9 | test_matrix 10 | test_parameters 11 | test_propertydouble 12 | test_propertyfileexist 13 | test_propertyfileext 14 | test_propertyint 15 | test_propertysisterfile 16 | test_propertystringchoice 17 | test_propertystring 18 | test_propertyswitch 19 | test_qc_functions 20 | test_string_support) 21 | 22 | if(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") 23 | link_libraries(gcov) 24 | endif(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") 25 | 26 | if(ENABLE_TESTS) 27 | foreach(PROG IN LISTS UNIT_TEST_SOURCE_FILES) 28 | add_executable(unit_${PROG} ${PROG}.cpp) 29 | if(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") 30 | set_source_files_properties( ${PROG}.cpp PROPERTIES COMPILE_FLAGS ${COVERAGE_FLAGS} ) 31 | endif(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") 32 | target_link_libraries(unit_${PROG} libcatnip) 33 | add_test(unit_${PROG} unit_${PROG}) 34 | endforeach(PROG) 35 | endif(ENABLE_TESTS) 36 | 37 | if(ENABLE_INTEGRATION_TESTS) 38 | 39 | foreach(PROG 40 | test_logreader 41 | test_punreader) 42 | 43 | add_executable(integration${PROG} ${PROG}.cpp) 44 | if(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") 45 | set_source_files_properties( ${PROG}.cpp PROPERTIES COMPILE_FLAGS ${COVERAGE_FLAGS}) 46 | endif(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") 47 | 48 | target_link_libraries(integration${PROG} libcatnip) 49 | add_test(integration${PROG} integration${PROG}) 50 | 51 | endforeach(PROG) 52 | 53 | add_executable(test_io test_io.cpp) 54 | if(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") 55 | set_source_files_properties( test_io.cpp PROPERTIES COMPILE_FLAGS ${COVERAGE_FLAGS}) 56 | endif(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") 57 | target_link_libraries(test_io libcatnip) 58 | add_test(regression_test_io test_io -p_P "${PROJECT_SOURCE_DIR}/GAUSSIANFILES/30/30_pair.pun" -p_1 "${PROJECT_SOURCE_DIR}/GAUSSIANFILES/30/ref.pun" -p_2 "${PROJECT_SOURCE_DIR}/GAUSSIANFILES/30/30_2.pun") 59 | 60 | add_custom_command(TARGET test_io 61 | POST_BUILD 62 | COMMAND ${CMAKE_COMMAND} -E copy $ ${CMAKE_CURRENT_SOURCE_DIR}) 63 | 64 | if(BASH_PROGRAM) 65 | add_test(regression_test_io_script ${BASH_PROGRAM} ${PROJECT_SOURCE_DIR}/src/tests/test_script_io.sh ${CMAKE_CURRENT_SOURCE_DIR}) 66 | 67 | add_test(integration_test_calc_J_script ${BASH_PROGRAM} ${PROJECT_SOURCE_DIR}/src/tests/test_script_calc_J.sh ${CMAKE_SOURCE_DIR}) 68 | 69 | endif(BASH_PROGRAM) 70 | 71 | endif(ENABLE_INTEGRATION_TESTS) 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /src/tests/test_argumentdouble.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "../libcatnip/io/arguments/argumentdouble.hpp" 3 | #include 4 | #include 5 | 6 | using namespace catnip; 7 | using namespace std; 8 | 9 | int main(void) { 10 | 11 | cerr << "Testing: argumentdouble" << endl; 12 | cerr << "Testing: constructor" << endl; 13 | { ArgumentDouble argDouble; } 14 | 15 | cerr << "Testing: getArgumentName" << endl; 16 | { 17 | ArgumentDouble argDouble; 18 | string name = "ARGUMENT_DOUBLE"; 19 | assert(name.compare(argDouble.getArgumentName()) == 0); 20 | } 21 | 22 | cerr << "Testing: getProperties" << endl; 23 | { 24 | ArgumentDouble argDouble; 25 | auto props = argDouble.getProperties(); 26 | 27 | bool double_prop = false; 28 | 29 | for (auto prop : props) { 30 | if (prop.compare("PROPERTY_DOUBLE") == 0) { 31 | double_prop = true; 32 | } 33 | } 34 | assert(double_prop); 35 | } 36 | 37 | cerr << "Testing: getPropertyOptions" << endl; 38 | { 39 | ArgumentDouble argDouble; 40 | auto prop_opts = argDouble.getPropertyOptions(); 41 | 42 | bool opt_min = false; 43 | bool opt_max = false; 44 | 45 | for (auto opt : prop_opts) { 46 | if (opt.compare("MIN") == 0) { 47 | opt_min = true; 48 | } 49 | if (opt.compare("MAX") == 0) { 50 | opt_max = true; 51 | } 52 | } 53 | 54 | assert(opt_min); 55 | assert(opt_max); 56 | } 57 | 58 | cerr << "Testing: getArgPropertyValues" << endl; 59 | { 60 | ArgumentDouble argDouble; 61 | auto prop_values = argDouble.getPropertyValues(); 62 | 63 | bool opt_min = false; 64 | bool opt_max = false; 65 | bool opt_min_val = false; 66 | bool opt_max_val = false; 67 | 68 | for (auto val : prop_values) { 69 | if (val.first.compare("MIN") == 0) { 70 | opt_min = true; 71 | if (val.second.compare(to_string(numeric_limits::lowest())) == 72 | 0) { 73 | opt_min_val = true; 74 | } 75 | } 76 | if (val.first.compare("MAX") == 0) { 77 | opt_max = true; 78 | if (val.second.compare(to_string(numeric_limits::max())) == 0) { 79 | opt_max_val = true; 80 | } 81 | } 82 | } 83 | 84 | assert(opt_min); 85 | assert(opt_max); 86 | assert(opt_min_val); 87 | assert(opt_max_val); 88 | } 89 | 90 | return 0; 91 | } 92 | -------------------------------------------------------------------------------- /src/tests/test_argumentfile.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "../libcatnip/io/arguments/argumentfile.hpp" 3 | #include 4 | 5 | using namespace catnip; 6 | using namespace std; 7 | 8 | int main(void) { 9 | 10 | cerr << "Testing: argumentfile" << endl; 11 | cerr << "Testing: constructor" << endl; 12 | { ArgumentFile argFile; } 13 | 14 | cerr << "Testing: getArgumentName" << endl; 15 | { 16 | ArgumentFile argFile; 17 | string name = "ARGUMENT_FILE"; 18 | assert(name.compare(argFile.getArgumentName()) == 0); 19 | } 20 | 21 | cerr << "Testing: getProperties" << endl; 22 | { 23 | ArgumentFile argFile; 24 | auto props = argFile.getProperties(); 25 | 26 | bool file_exist = false; 27 | bool file_ext = false; 28 | bool sister_file = false; 29 | 30 | for (auto prop : props) { 31 | if (prop.compare("PROPERTY_FILE_EXIST") == 0) { 32 | file_exist = true; 33 | } 34 | if (prop.compare("PROPERTY_FILE_EXT") == 0) { 35 | file_ext = true; 36 | } 37 | if (prop.compare("PROPERTY_SISTER_FILE") == 0) { 38 | sister_file = true; 39 | } 40 | } 41 | assert(file_exist); 42 | assert(file_ext); 43 | assert(sister_file); 44 | } 45 | 46 | cerr << "Testing: getPropertyOptions" << endl; 47 | { 48 | ArgumentFile argFile; 49 | auto prop_opts = argFile.getPropertyOptions(); 50 | 51 | bool file_must_exist = false; 52 | bool sis_file_name = false; 53 | bool sis_file_path = false; 54 | bool sis_file_path_name = false; 55 | bool sis_file_exists = false; 56 | bool allowed_ext = false; 57 | bool allowed_sister_ext = false; 58 | for (auto opt : prop_opts) { 59 | if (opt.compare("ALLOWED_FILE_EXT") == 0) { 60 | allowed_ext = true; 61 | } 62 | if (opt.compare("ALLOWED_SISTER_FILE_EXT") == 0) { 63 | allowed_sister_ext = true; 64 | } 65 | if (opt.compare("FILE_MUST_EXIST") == 0) { 66 | file_must_exist = true; 67 | } 68 | if (opt.compare("SISTER_FILE_NAME") == 0) { 69 | sis_file_name = true; 70 | } 71 | if (opt.compare("SISTER_FILE_PATH") == 0) { 72 | sis_file_path = true; 73 | } 74 | if (opt.compare("SISTER_FILE_PATH_NAME") == 0) { 75 | sis_file_path_name = true; 76 | } 77 | if (opt.compare("SISTER_FILE_EXISTS") == 0) { 78 | sis_file_exists = true; 79 | } 80 | } 81 | 82 | assert(file_must_exist); 83 | assert(allowed_ext); 84 | assert(allowed_sister_ext); 85 | assert(sis_file_name); 86 | assert(sis_file_path); 87 | assert(sis_file_path_name); 88 | assert(sis_file_exists); 89 | } 90 | 91 | cerr << "Testing: getArgPropertyValues" << endl; 92 | { 93 | ArgumentFile argFile; 94 | auto prop_values = argFile.getPropertyValues(); 95 | 96 | bool file_must_exist = false; 97 | bool allowed_ext = false; 98 | bool file_must_exist_val = false; 99 | bool allowed_ext_val = false; 100 | 101 | for (auto val : prop_values) { 102 | if (val.first.compare("ALLOWED_FILE_EXT") == 0) { 103 | allowed_ext = true; 104 | if (val.second[0] == '*') { 105 | allowed_ext_val = true; 106 | } 107 | } 108 | if (val.first.compare("FILE_MUST_EXIST") == 0) { 109 | file_must_exist = true; 110 | if (val.second.compare("0") == 0) { 111 | file_must_exist_val = true; 112 | } 113 | } 114 | } 115 | 116 | assert(file_must_exist); 117 | assert(file_must_exist_val); 118 | 119 | assert(allowed_ext); 120 | assert(allowed_ext_val); 121 | } 122 | 123 | cerr << "Testing: setArgPropertyValues" << endl; 124 | { 125 | ArgumentFile argFile; 126 | auto prop_values = argFile.getPropertyValues(); 127 | 128 | bool file_must_exist = false; 129 | bool allowed_ext = false; 130 | bool file_must_exist_val = false; 131 | bool allowed_ext_val = false; 132 | 133 | for (auto val : prop_values) { 134 | if (val.first.compare("ALLOWED_FILE_EXT") == 0) { 135 | allowed_ext = true; 136 | if (val.second[0] == '*') { 137 | allowed_ext_val = true; 138 | } 139 | } 140 | if (val.first.compare("FILE_MUST_EXIST") == 0) { 141 | file_must_exist = true; 142 | if (val.second.compare("0") == 0) { 143 | file_must_exist_val = true; 144 | } 145 | } 146 | } 147 | 148 | assert(file_must_exist); 149 | assert(file_must_exist_val); 150 | 151 | assert(allowed_ext); 152 | assert(allowed_ext_val); 153 | 154 | set exts{".pun", ".7", ".orb"}; 155 | argFile.setArgPropertyOpt("PROPERTY_FILE_EXT", "ALLOWED_FILE_EXT", exts); 156 | 157 | auto str_exts = 158 | argFile.getPropertyValues("PROPERTY_FILE_EXT", "ALLOWED_FILE_EXT"); 159 | cerr << "extensions " << str_exts << endl; 160 | } 161 | 162 | return 0; 163 | } 164 | -------------------------------------------------------------------------------- /src/tests/test_argumentint.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "../libcatnip/io/arguments/argumentint.hpp" 3 | #include 4 | #include 5 | 6 | using namespace catnip; 7 | using namespace std; 8 | 9 | int main(void) { 10 | 11 | cerr << "Testing: argumentint" << endl; 12 | cerr << "Testing: constructor" << endl; 13 | { ArgumentInt argInt; } 14 | 15 | cerr << "Testing: getArgumentName" << endl; 16 | { 17 | ArgumentInt argInt; 18 | string name = "ARGUMENT_INT"; 19 | assert(name.compare(argInt.getArgumentName()) == 0); 20 | } 21 | 22 | cerr << "Testing: getProperties" << endl; 23 | { 24 | ArgumentInt argInt; 25 | auto props = argInt.getProperties(); 26 | 27 | bool int_prop = false; 28 | 29 | for (auto prop : props) { 30 | if (prop.compare("PROPERTY_INT") == 0) { 31 | int_prop = true; 32 | } 33 | } 34 | assert(int_prop); 35 | } 36 | 37 | cerr << "Testing: getPropertyOptions" << endl; 38 | { 39 | ArgumentInt argInt; 40 | auto prop_opts = argInt.getPropertyOptions(); 41 | 42 | bool opt_min = false; 43 | bool opt_max = false; 44 | 45 | for (auto opt : prop_opts) { 46 | if (opt.compare("MIN") == 0) { 47 | opt_min = true; 48 | } 49 | if (opt.compare("MAX") == 0) { 50 | opt_max = true; 51 | } 52 | } 53 | 54 | assert(opt_min); 55 | assert(opt_max); 56 | } 57 | 58 | cerr << "Testing: getArgPropertyValues" << endl; 59 | { 60 | ArgumentInt argInt; 61 | auto prop_values = argInt.getPropertyValues(); 62 | 63 | bool opt_min = false; 64 | bool opt_max = false; 65 | bool opt_min_val = false; 66 | bool opt_max_val = false; 67 | 68 | for (auto val : prop_values) { 69 | if (val.first.compare("MIN") == 0) { 70 | opt_min = true; 71 | if (val.second.compare(to_string(numeric_limits::min())) == 0) { 72 | opt_min_val = true; 73 | } 74 | } 75 | if (val.first.compare("MAX") == 0) { 76 | opt_max = true; 77 | if (val.second.compare(to_string(numeric_limits::max())) == 0) { 78 | opt_max_val = true; 79 | } 80 | } 81 | } 82 | 83 | assert(opt_min); 84 | assert(opt_max); 85 | assert(opt_min_val); 86 | assert(opt_max_val); 87 | } 88 | 89 | return 0; 90 | } 91 | -------------------------------------------------------------------------------- /src/tests/test_argumentparser.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "../libcatnip/io/argumentparser.hpp" 4 | #include "../libcatnip/matrix.hpp" 5 | #include "../libcatnip/string_support.hpp" 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | using namespace catnip; 12 | using namespace std; 13 | 14 | int main(void) { 15 | 16 | cerr << "Testing: ArgumentParser" << endl; 17 | cerr << "Testing: constructor" << endl; 18 | { 19 | vector flag = { 20 | "-p_P", "--punfile-pair", 21 | "File containing dimer of two " 22 | "monomers. This file should have the .pun extension."}; 23 | set> flags; 24 | flags.insert(flag); 25 | ArgumentParser ArgPars(flags); 26 | } 27 | 28 | cerr << "Testing: showUsage" << endl; 29 | { 30 | vector flag1 = { 31 | "-p_P", "--punfile-pair", 32 | "File containing dimer of two " 33 | "monomers. This file should have the .pun extension."}; 34 | vector flag2 = {"-p_1", "--punfile-mon1", 35 | "File containing monomer 1"}; 36 | vector flag3 = {"-homo", "--homo-level", "HOMO molecular orbital"}; 37 | 38 | set> flags; 39 | flags.insert(flag1); 40 | flags.insert(flag2); 41 | flags.insert(flag3); 42 | 43 | ArgumentParser ArgPars(flags); 44 | ArgPars.showUsage(); 45 | } 46 | 47 | cerr << "Testing: setFlagArgOpt" << endl; 48 | { 49 | vector flag1 = { 50 | "-p_P", "--punfile-pair", 51 | "File containing dimer of two " 52 | "monomers. This file should have the .pun extension."}; 53 | vector flag2 = {"-p_1", "--punfile-mon1", 54 | "File containing monomer 1"}; 55 | vector flag3 = {"-homo", "--homo-level", "HOMO molecular orbital"}; 56 | 57 | set> flags; 58 | flags.insert(flag1); 59 | flags.insert(flag2); 60 | flags.insert(flag3); 61 | 62 | ArgumentParser ArgPars(flags); 63 | 64 | string val = ".pun"; 65 | ArgPars.setFlagArgOpt("--punfile-pair", "ARGUMENT_FILE", 66 | "PROPERTY_FILE_EXT", "ALLOWED_FILE_EXT", val); 67 | string val2 = ".7"; 68 | ArgPars.setFlagArgOpt("--punfile-pair", "ARGUMENT_FILE", 69 | "PROPERTY_FILE_EXT", "ALLOWED_FILE_EXT", val2); 70 | string val3 = ".orb"; 71 | ArgPars.setFlagArgOpt("--punfile-pair", "ARGUMENT_FILE", 72 | "PROPERTY_FILE_EXT", "ALLOWED_FILE_EXT", val3); 73 | } 74 | 75 | cerr << "Testing: parse" << endl; 76 | { 77 | vector flag1 = { 78 | "-p_P", "--punfile-pair", 79 | "File containing dimer of two " 80 | "monomers. This file should have the .pun extension."}; 81 | vector flag2 = {"-p_1", "--punfile-mon1", 82 | "File containing monomer 1"}; 83 | vector flag3 = {"-homo", "--homo-level", "HOMO molecular orbital"}; 84 | 85 | set> flags; 86 | flags.insert(flag1); 87 | flags.insert(flag2); 88 | flags.insert(flag3); 89 | 90 | ArgumentParser ArgPars(flags); 91 | 92 | string val = ".pun"; 93 | string val2 = ".7"; 94 | string val3 = ".orb"; 95 | set exts = {val, val2, val3}; 96 | ArgPars.setFlagArgOpt("--punfile-pair", "ARGUMENT_FILE", 97 | "PROPERTY_FILE_EXT", "ALLOWED_FILE_EXT", exts); 98 | ArgPars.setFlagArgOpt("--punfile-mon1", "ARGUMENT_FILE", 99 | "PROPERTY_FILE_EXT", "ALLOWED_FILE_EXT", exts); 100 | ArgPars.setFlagArgOpt("--punfile-mon2", "ARGUMENT_FILE", 101 | "PROPERTY_FILE_EXT", "ALLOWED_FILE_EXT", exts); 102 | 103 | ArgPars.setFlagArgOpt("--punfile-pair", "ARGUMENT_FILE", 104 | "PROPERTY_FILE_EXIST", "FILE_MUST_EXIST", true); 105 | ArgPars.setFlagArgOpt("--punfile-mon1", "ARGUMENT_FILE", 106 | "PROPERTY_FILE_EXIST", "FILE_MUST_EXIST", false); 107 | ArgPars.setFlagArgOpt("--punfile-mon2", "ARGUMENT_FILE", 108 | "PROPERTY_FILE_EXIST", "FILE_MUST_EXIST", true); 109 | 110 | int argc = 7; 111 | const char* argv[7]; // = {"calc_J","--punfile-pair", "testfile.pun", 112 | // "--punfile-mon1","file.orb"}; 113 | argv[0] = "calc_J"; 114 | argv[1] = "--punfile-pair"; 115 | argv[2] = "testfile.pun"; 116 | argv[3] = "--punfile-mon1"; 117 | argv[4] = "file.orb"; 118 | argv[5] = "--punfile-mon2"; 119 | argv[6] = "testfile.pun"; 120 | ArgPars.parse(argv, argc); 121 | 122 | argc = 7; 123 | const char* argv2[7]; 124 | argv2[0] = "calc_J"; 125 | argv2[1] = "--punfile-pair"; 126 | argv2[2] = "testfile.pun"; 127 | argv2[3] = "--punfile-mon1"; 128 | argv2[4] = "file.orb"; 129 | argv2[5] = "--punfile-mon2"; 130 | argv2[6] = "fort.7"; 131 | 132 | bool excep = false; 133 | try { 134 | ArgPars.parse(argv2, argc); 135 | } catch (...) { 136 | excep = true; 137 | } 138 | assert(excep); 139 | cout << "Except thrown: " << excep << endl; 140 | } 141 | 142 | cerr << "Testing: get" << endl; 143 | { 144 | vector flag1 = { 145 | "-p_P", "--punfile-pair", 146 | "File containing dimer of two " 147 | "monomers. This file should have the .pun extension."}; 148 | vector flag2 = {"-p_1", "--punfile-mon1", 149 | "File containing monomer 1"}; 150 | vector flag3 = {"-homo", "--homo-level", "HOMO molecular orbital"}; 151 | 152 | set> flags; 153 | flags.insert(flag1); 154 | flags.insert(flag2); 155 | flags.insert(flag3); 156 | 157 | ArgumentParser ArgPars(flags); 158 | 159 | string val = ".pun"; 160 | string val2 = ".7"; 161 | string val3 = ".orb"; 162 | set exts = {val, val2, val3}; 163 | ArgPars.setFlagArgOpt("--punfile-pair", "ARGUMENT_FILE", 164 | "PROPERTY_FILE_EXT", "ALLOWED_FILE_EXT", exts); 165 | ArgPars.setFlagArgOpt("--punfile-mon1", "ARGUMENT_FILE", 166 | "PROPERTY_FILE_EXT", "ALLOWED_FILE_EXT", exts); 167 | vector sis_exts{".log"}; 168 | ArgPars.setFlagArgOpt("--punfile-mon1", "ARGUMENT_FILE", 169 | "PROPERTY_SISTER_FILE", "ALLOWED_SISTER_FILE_EXT", 170 | ".log"); 171 | 172 | const int argc = 5; 173 | const char* argv[argc]; 174 | argv[0] = "calc_J"; 175 | argv[1] = "--punfile-pair"; 176 | argv[2] = "file.orb"; 177 | argv[3] = "--punfile-mon1"; 178 | argv[4] = "testfile.pun"; 179 | ArgPars.parse(argv, argc); 180 | 181 | string fileName = ArgPars.getStr("--punfile-pair"); 182 | assert(fileName.compare("file.orb") == 0); 183 | string fileName2 = ArgPars.getStr("--punfile-mon1"); 184 | assert(fileName2.compare("testfile.pun") == 0); 185 | string sisFileNamePath = ArgPars.getFlagArgOptValue( 186 | "--punfile-mon1", "ARGUMENT_FILE", "PROPERTY_SISTER_FILE", 187 | "SISTER_FILE_PATH_NAME"); 188 | 189 | cerr << "File name " << sisFileNamePath << endl; 190 | assert(sisFileNamePath.compare("testfile.log") == 0); 191 | } 192 | 193 | return 0; 194 | } 195 | -------------------------------------------------------------------------------- /src/tests/test_argumentstring.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "../libcatnip/io/arguments/argumentstring.hpp" 3 | #include 4 | #include 5 | 6 | using namespace catnip; 7 | using namespace std; 8 | 9 | int main(void) { 10 | 11 | cerr << "Testing: argumentstring" << endl; 12 | cerr << "Testing: constructor" << endl; 13 | { ArgumentString argString; } 14 | 15 | cerr << "Testing: getArgumentName" << endl; 16 | { 17 | ArgumentString argString; 18 | string name = "ARGUMENT_STRING"; 19 | assert(name.compare(argString.getArgumentName()) == 0); 20 | } 21 | 22 | cerr << "Testing: getProperties" << endl; 23 | { 24 | ArgumentString argString; 25 | auto props = argString.getProperties(); 26 | 27 | bool string_prop = false; 28 | bool string_choice = false; 29 | 30 | for (auto prop : props) { 31 | if (prop.compare("PROPERTY_STRING") == 0) { 32 | string_prop = true; 33 | } 34 | if (prop.compare("PROPERTY_STRING_CHOICE") == 0) { 35 | string_choice = true; 36 | } 37 | } 38 | assert(string_prop); 39 | assert(string_choice); 40 | } 41 | 42 | cerr << "Testing: getPropertyOptions" << endl; 43 | { 44 | ArgumentString argString; 45 | auto prop_opts = argString.getPropertyOptions(); 46 | 47 | bool opt_min = false; 48 | bool opt_max = false; 49 | bool opt_enforced = false; 50 | bool opt_choices = false; 51 | 52 | for (auto opt : prop_opts) { 53 | if (opt.compare("MIN_LENGTH") == 0) { 54 | opt_min = true; 55 | } 56 | if (opt.compare("MAX_LENGTH") == 0) { 57 | opt_max = true; 58 | } 59 | if (opt.compare("STRING_CHOICE_ENFORCED") == 0) { 60 | opt_enforced = true; 61 | } 62 | if (opt.compare("STRING_CHOICES") == 0) { 63 | opt_choices = true; 64 | } 65 | } 66 | 67 | assert(opt_min); 68 | assert(opt_max); 69 | assert(opt_enforced); 70 | assert(opt_choices); 71 | } 72 | 73 | cerr << "Testing: getArgPropertyValues" << endl; 74 | { 75 | ArgumentString argString; 76 | auto prop_values = argString.getPropertyValues(); 77 | 78 | bool opt_min = false; 79 | bool opt_max = false; 80 | bool opt_enforced = false; 81 | bool opt_choices = false; 82 | 83 | bool opt_min_val = false; 84 | bool opt_max_val = false; 85 | bool opt_enforced_val = false; 86 | bool opt_choices_val = false; 87 | 88 | for (auto val : prop_values) { 89 | if (val.first.compare("MIN_LENGTH") == 0) { 90 | opt_min = true; 91 | if (val.second.compare(to_string(0)) == 0) { 92 | opt_min_val = true; 93 | } 94 | } 95 | if (val.first.compare("MAX_LENGTH") == 0) { 96 | opt_max = true; 97 | if (val.second.compare(to_string((size_t)-1)) == 0) { 98 | opt_max_val = true; 99 | } 100 | } 101 | if (val.first.compare("STRING_CHOICE_ENFORCED") == 0) { 102 | opt_enforced = true; 103 | if (val.second.compare("false") == 0) { 104 | opt_enforced_val = true; 105 | } 106 | } 107 | if (val.first.compare("STRING_CHOICES") == 0) { 108 | opt_choices = true; 109 | if (val.second.compare("NOT_DEFINED") == 0) { 110 | opt_choices_val = true; 111 | } 112 | } 113 | } 114 | 115 | assert(opt_min); 116 | assert(opt_max); 117 | assert(opt_min_val); 118 | assert(opt_max_val); 119 | assert(opt_enforced); 120 | assert(opt_choices); 121 | assert(opt_enforced_val); 122 | assert(opt_choices_val); 123 | } 124 | 125 | return 0; 126 | } 127 | -------------------------------------------------------------------------------- /src/tests/test_argumentswitch.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "../libcatnip/io/arguments/argumentswitch.hpp" 3 | #include 4 | #include 5 | 6 | using namespace catnip; 7 | using namespace std; 8 | 9 | int main(void) { 10 | 11 | cerr << "Testing: argumentswitch" << endl; 12 | cerr << "Testing: constructor" << endl; 13 | { ArgumentSwitch argSwitch; } 14 | 15 | cerr << "Testing: getArgumentName" << endl; 16 | { 17 | ArgumentSwitch argSwitch; 18 | string name = "ARGUMENT_SWITCH"; 19 | assert(name.compare(argSwitch.getArgumentName()) == 0); 20 | } 21 | 22 | cerr << "Testing: getProperties" << endl; 23 | { 24 | ArgumentSwitch argSwitch; 25 | auto props = argSwitch.getProperties(); 26 | 27 | bool int_prop = false; 28 | 29 | for (auto prop : props) { 30 | if (prop.compare("PROPERTY_SWITCH") == 0) { 31 | int_prop = true; 32 | } 33 | } 34 | assert(int_prop); 35 | } 36 | 37 | cerr << "Testing: getPropertyOptions" << endl; 38 | { 39 | ArgumentSwitch argSwitch; 40 | auto prop_opts = argSwitch.getPropertyOptions(); 41 | 42 | bool opt_def = false; 43 | 44 | for (auto opt : prop_opts) { 45 | if (opt.compare("DEFAULT") == 0) { 46 | opt_def = true; 47 | } 48 | } 49 | 50 | assert(opt_def); 51 | } 52 | 53 | cerr << "Testing: getArgPropertyValues" << endl; 54 | { 55 | ArgumentSwitch argSwitch; 56 | auto prop_values = argSwitch.getPropertyValues(); 57 | 58 | bool opt_def = false; 59 | bool opt_def_val = false; 60 | 61 | for (auto val : prop_values) { 62 | if (val.first.compare("DEFAULT") == 0) { 63 | opt_def = true; 64 | if (val.second.compare("OFF") == 0) { 65 | opt_def_val = true; 66 | } 67 | } 68 | } 69 | 70 | assert(opt_def); 71 | assert(opt_def_val); 72 | } 73 | 74 | return 0; 75 | } 76 | -------------------------------------------------------------------------------- /src/tests/test_io.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "../libcatnip/io/argumentparser.hpp" 4 | #include "../libcatnip/io/io.hpp" 5 | #include "../libcatnip/matrix.hpp" 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | using namespace catnip; 12 | using namespace std; 13 | 14 | int main(int argc, const char* argv[]) { 15 | 16 | auto ArgParse = prepareParser(); 17 | 18 | ArgParse->parse(argv, argc); 19 | vector flags{"--pun_P", "--pun_1", "--pun_2", 20 | "--log_P", "--log_1", "--log_2"}; 21 | 22 | for (auto flag : flags) { 23 | cout << endl; 24 | string argu = "ARGUMENT_FILE"; 25 | string prop = "PROPERTY_FILE_EXT"; 26 | string opt = "ALLOWED_FILE_EXT"; 27 | auto val = ArgParse->getFlagArgOptValue(flag, argu, prop, opt); 28 | cout << flag << " " << argu << " " << prop << " " << opt << " " << val 29 | << endl; 30 | 31 | prop = "PROPERTY_SISTER_FILE"; 32 | opt = "ALLOWED_SISTER_FILE_EXT"; 33 | auto val1 = ArgParse->getFlagArgOptValue(flag, argu, prop, opt); 34 | cout << flag << " " << argu << " " << prop << " " << opt << " " << val1 35 | << endl; 36 | 37 | opt = "SISTER_FILE_NAME"; 38 | auto val2 = ArgParse->getFlagArgOptValue(flag, argu, prop, opt); 39 | cout << flag << " " << argu << " " << prop << " " << opt << " " << val2 40 | << endl; 41 | opt = "SISTER_FILE_PATH"; 42 | auto val3 = ArgParse->getFlagArgOptValue(flag, argu, prop, opt); 43 | cout << flag << " " << argu << " " << prop << " " << opt << " " << val3 44 | << endl; 45 | opt = "SISTER_FILE_PATH_NAME"; 46 | auto val4 = ArgParse->getFlagArgOptValue(flag, argu, prop, opt); 47 | cout << flag << " " << argu << " " << prop << " " << opt << " " << val4 48 | << endl; 49 | opt = "SISTER_FILE_EXISTS"; 50 | auto val5 = ArgParse->getFlagArgOptValue(flag, argu, prop, opt); 51 | cout << flag << " " << argu << " " << prop << " " << opt << " " << val5 52 | << endl; 53 | 54 | prop = "PROPERTY_FILE_EXIST"; 55 | opt = "FILE_MUST_EXIST"; 56 | auto val6 = ArgParse->getFlagArgOptValue(flag, argu, prop, opt); 57 | cout << flag << " " << argu << " " << prop << " " << opt << " " << val6 58 | << endl; 59 | opt = "FILE_DOES_EXIST"; 60 | auto val7 = ArgParse->getFlagArgOptValue(flag, argu, prop, opt); 61 | cout << flag << " " << argu << " " << prop << " " << opt << " " << val7 62 | << endl; 63 | } 64 | 65 | auto Par = prepareParameters(ArgParse); 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /src/tests/test_log.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "../libcatnip/log.hpp" 3 | 4 | using namespace catnip; 5 | 6 | int main(void) { 7 | LOG("Testing log message", 1); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /src/tests/test_logreader.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "../libcatnip/io/file_readers/logreader.hpp" 10 | #include "../libcatnip/io/io.hpp" 11 | 12 | using namespace catnip; 13 | using namespace std; 14 | 15 | int main(void) { 16 | 17 | cerr << "Testing: LogReader Constructor" << endl; 18 | { LogReader lr("file.log"); } 19 | 20 | cerr << "Testing: LogReader read" << endl; 21 | { 22 | 23 | LogReader lr("../../../GAUSSIANFILES/90_unordered/90_pair.log"); 24 | lr.read(); 25 | auto orb_info = lr.getOrbitalInfo(); 26 | 27 | auto Soverlap = lr.getOverlapMatrix(); 28 | cout << Soverlap->get_rows() << endl; 29 | auto Alpha = lr.getOE("Alpha"); 30 | 31 | auto basisFuncCount = lr.getBasisFuncCount(); 32 | for (auto c : basisFuncCount) { 33 | cout << c << endl; 34 | } 35 | auto xyz = lr.getCoords(); 36 | auto x = xyz.at(0); 37 | auto y = xyz.at(1); 38 | auto z = xyz.at(2); 39 | for (size_t ind = 0; ind < x.size(); ++ind) { 40 | cout << x.at(ind) << " " << y.at(ind) << " " << z.at(ind) << endl; 41 | } 42 | } 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /src/tests/test_matrix.cpp: -------------------------------------------------------------------------------- 1 | #include "../libcatnip/matrix.hpp" 2 | #include 3 | #include 4 | 5 | using namespace catnip; 6 | using namespace std; 7 | 8 | int main() { 9 | 10 | cout << "Testing Constructors\n" << endl; 11 | 12 | cout << "Testing: Matrix::Matrix()\n" << endl; 13 | { 14 | Matrix mat0; 15 | cout << mat0 << endl; 16 | } 17 | 18 | cout << "Testing: Matrix::Matrix(int r)\n" << endl; 19 | { 20 | Matrix mat1(3); 21 | cout << mat1 << endl; 22 | } 23 | 24 | cout << "Testing: Matrix::Matrix(int r, int c)\n" << endl; 25 | { 26 | Matrix mat2(2, 3); 27 | cout << mat2 << endl; 28 | } 29 | 30 | cout << "Testing: Matrix::Matrix(int r, int c, int s)\n" << endl; 31 | { 32 | Matrix mat3(3, 1, 2); 33 | cout << mat3 << endl; 34 | } 35 | 36 | cout << "Testing: Matrix::Matrix(vector v_data)\n" << endl; 37 | { 38 | vector v = {1.2, 324.4, 23}; 39 | Matrix mat3(v); 40 | } 41 | 42 | cout << "Testing: Matrix::Matrix(vector> vv_data)\n" << endl; 43 | { 44 | vector> vv_data; 45 | vector v = {1.2, 324.4, 23}; 46 | vv_data.push_back(v); 47 | v.at(1) = -12.5; 48 | vv_data.push_back(v); 49 | Matrix mat3(vv_data); 50 | } 51 | 52 | cout << "\nTesting: Matrix::set_rows(int r)\n" << endl; 53 | { 54 | Matrix mat0; 55 | mat0.set_rows(3); 56 | cout << mat0 << endl; 57 | } 58 | 59 | cout << "\nTesting: Matrix::set_cols(int c)\n" << endl; 60 | { 61 | Matrix mat0; 62 | mat0.set_cols(4); 63 | cout << mat0 << endl; 64 | } 65 | 66 | cout << "\nTesting: Matrix::set_shel(int s)\n" << endl; 67 | { 68 | Matrix mat0; 69 | mat0.set_shel(2); 70 | cout << mat0 << endl; 71 | } 72 | 73 | cout << "\nTesting: Matrix::operator=(const Matrix mat)\n" << endl; 74 | { 75 | vector> vv_data; 76 | vector v = {1.2, 324.4, 23}; 77 | vv_data.push_back(v); 78 | v.at(1) = -12.5; 79 | vv_data.push_back(v); 80 | Matrix mat3(vv_data); 81 | Matrix mat1; 82 | mat1 = mat3; 83 | assert(static_cast(mat1.get_elem(1, 1) * 10) == 12); 84 | assert(static_cast(mat1.get_elem(1, 2) * 10) == 3244); 85 | assert(static_cast(mat1.get_elem(1, 3)) == 23); 86 | assert(static_cast(mat1.get_elem(2, 1) * 10) == 12); 87 | assert(static_cast(mat1.get_elem(2, 2) * 10) == -125); 88 | assert(static_cast(mat1.get_elem(2, 3)) == 23); 89 | } 90 | cout << "\nTesting: Matrix::set_elem(double val)\n" << endl; 91 | { 92 | Matrix mat0; 93 | mat0.set_elem(5.4); 94 | cout << mat0 << endl; 95 | } 96 | 97 | cout << "\nTesting: Matrix::set_elem(double val, int r)\n" << endl; 98 | { 99 | Matrix mat0; 100 | mat0.set_rows(3); 101 | mat0.set_elem(4.4, 3); 102 | cout << mat0 << endl; 103 | } 104 | 105 | cout << "\nTesting: Matrix::set_elem(double val, int r, int c)\n" << endl; 106 | { 107 | Matrix mat0; 108 | mat0.set_rows(3); 109 | mat0.set_cols(4); 110 | mat0.set_elem(4.2, 3, 4); 111 | cout << mat0 << endl; 112 | } 113 | 114 | cout << "\nTesting: Matrix::set_elem(double val, int r, int c)\n" << endl; 115 | { 116 | Matrix mat0; 117 | mat0.set_rows(3); 118 | mat0.set_cols(4); 119 | mat0.set_shel(2); 120 | mat0.set_elem(0.3, 3, 4, 2); 121 | cout << mat0 << endl; 122 | } 123 | 124 | { 125 | Matrix mat4(2, 3); 126 | Matrix mat5(3, 2); 127 | 128 | mat4.set_elem(5, 1, 1); 129 | mat4.set_elem(3, 1, 2); 130 | mat4.set_elem(1, 1, 3); 131 | mat4.set_elem(2, 2, 2); 132 | mat4.set_elem(1, 2, 3); 133 | 134 | mat5.set_elem(2, 1, 1); 135 | mat5.set_elem(1, 1, 2); 136 | mat5.set_elem(1, 2, 1); 137 | mat5.set_elem(3, 3, 1); 138 | mat5.set_elem(4, 3, 2); 139 | 140 | cout << mat4 << endl; 141 | cout << mat5 << endl; 142 | 143 | Matrix mat6 = mat4 * mat5; 144 | cout << mat6 << endl; 145 | 146 | cout << "\nResizing matrix 6" << endl; 147 | mat6.resize(3, 3); 148 | cout << mat6 << endl; 149 | } 150 | 151 | cerr << "Testing: matchRow" << endl; 152 | { 153 | Matrix mat4(2, 3); 154 | Matrix mat5(3, 3); 155 | 156 | // mat4 157 | // 5 3 1 158 | // 0 2 1 159 | 160 | mat4.set_elem(5, 1, 1); 161 | mat4.set_elem(3, 1, 2); 162 | mat4.set_elem(1, 1, 3); 163 | mat4.set_elem(2, 2, 2); 164 | mat4.set_elem(1, 2, 3); 165 | 166 | // mat5 167 | // 2 1 0 168 | // 1 0 0 169 | // 5 3 1 170 | mat5.set_elem(2, 1, 1); 171 | mat5.set_elem(1, 1, 2); 172 | mat5.set_elem(1, 2, 1); 173 | mat5.set_elem(5, 3, 1); 174 | mat5.set_elem(3, 3, 2); 175 | mat5.set_elem(1, 3, 3); 176 | 177 | auto m_vec = mat4.matchRow(mat5, 4); 178 | assert(m_vec.at(0) == 3); 179 | } 180 | 181 | cerr << "Testing: set_row & set_col" << endl; 182 | { 183 | // mat5 184 | // 2 1 0 185 | // 1 0 0 186 | // 5 3 1 187 | Matrix mat5(3, 3); 188 | mat5.set_elem(2, 1, 1); 189 | mat5.set_elem(1, 1, 2); 190 | mat5.set_elem(0, 1, 3); 191 | mat5.set_elem(1, 2, 1); 192 | mat5.set_elem(0, 2, 2); 193 | mat5.set_elem(0, 2, 3); 194 | mat5.set_elem(5, 3, 1); 195 | mat5.set_elem(3, 3, 2); 196 | mat5.set_elem(1, 3, 3); 197 | 198 | vector values{9, 12, 13}; 199 | mat5.set_row(values, 1); 200 | assert(mat5.get_elem(1, 1) == 9); 201 | assert(mat5.get_elem(1, 2) == 12); 202 | assert(mat5.get_elem(1, 3) == 13); 203 | assert(mat5.get_elem(2, 1) == 1); 204 | assert(mat5.get_elem(2, 2) == 0); 205 | assert(mat5.get_elem(2, 3) == 0); 206 | assert(mat5.get_elem(3, 1) == 5); 207 | assert(mat5.get_elem(3, 2) == 3); 208 | assert(mat5.get_elem(3, 3) == 1); 209 | 210 | vector values2{-12, 23, 101}; 211 | mat5.set_col(values2, 2); 212 | assert(mat5.get_elem(1, 1) == 9); 213 | assert(mat5.get_elem(1, 2) == -12); 214 | assert(mat5.get_elem(1, 3) == 13); 215 | assert(mat5.get_elem(2, 1) == 1); 216 | assert(mat5.get_elem(2, 2) == 23); 217 | assert(mat5.get_elem(2, 3) == 0); 218 | assert(mat5.get_elem(3, 1) == 5); 219 | assert(mat5.get_elem(3, 2) == 101); 220 | assert(mat5.get_elem(3, 3) == 1); 221 | } 222 | 223 | cerr << "Testing: move_row & move_col" << endl; 224 | { 225 | // mat5 226 | // 2 1 0 227 | // 1 0 0 228 | // 5 3 1 229 | Matrix mat5(3, 3); 230 | mat5.set_elem(2, 1, 1); 231 | mat5.set_elem(1, 1, 2); 232 | mat5.set_elem(0, 1, 3); 233 | mat5.set_elem(1, 2, 1); 234 | mat5.set_elem(0, 2, 2); 235 | mat5.set_elem(0, 2, 3); 236 | mat5.set_elem(5, 3, 1); 237 | mat5.set_elem(3, 3, 2); 238 | mat5.set_elem(1, 3, 3); 239 | 240 | // 5 3 1 241 | // 2 1 0 242 | // 1 0 0 243 | mat5.move_row(3, 1); 244 | assert(mat5.get_elem(1, 1) == 5); 245 | assert(mat5.get_elem(1, 2) == 3); 246 | assert(mat5.get_elem(1, 3) == 1); 247 | assert(mat5.get_elem(2, 1) == 2); 248 | assert(mat5.get_elem(2, 2) == 1); 249 | assert(mat5.get_elem(2, 3) == 0); 250 | assert(mat5.get_elem(3, 1) == 1); 251 | assert(mat5.get_elem(3, 2) == 0); 252 | assert(mat5.get_elem(3, 3) == 0); 253 | 254 | // 1 5 3 255 | // 0 2 1 256 | // 0 1 0 257 | mat5.move_col(3, 1); 258 | cerr << mat5 << endl; 259 | assert(mat5.get_elem(1, 1) == 1); 260 | assert(mat5.get_elem(1, 2) == 5); 261 | assert(mat5.get_elem(1, 3) == 3); 262 | assert(mat5.get_elem(2, 1) == 0); 263 | assert(mat5.get_elem(2, 2) == 2); 264 | assert(mat5.get_elem(2, 3) == 1); 265 | assert(mat5.get_elem(3, 1) == 0); 266 | assert(mat5.get_elem(3, 2) == 1); 267 | assert(mat5.get_elem(3, 3) == 0); 268 | 269 | // 0 2 1 270 | // 0 1 0 271 | // 1 5 3 272 | mat5.move_row(1, 3); 273 | assert(mat5.get_elem(1, 1) == 0); 274 | assert(mat5.get_elem(1, 2) == 2); 275 | assert(mat5.get_elem(1, 3) == 1); 276 | assert(mat5.get_elem(2, 1) == 0); 277 | assert(mat5.get_elem(2, 2) == 1); 278 | assert(mat5.get_elem(2, 3) == 0); 279 | assert(mat5.get_elem(3, 1) == 1); 280 | assert(mat5.get_elem(3, 2) == 5); 281 | assert(mat5.get_elem(3, 3) == 3); 282 | 283 | // 2 1 0 284 | // 1 0 0 285 | // 5 3 1 286 | mat5.move_col(1, 3); 287 | assert(mat5.get_elem(1, 1) == 2); 288 | assert(mat5.get_elem(1, 2) == 1); 289 | assert(mat5.get_elem(1, 3) == 0); 290 | assert(mat5.get_elem(2, 1) == 1); 291 | assert(mat5.get_elem(2, 2) == 0); 292 | assert(mat5.get_elem(2, 3) == 0); 293 | assert(mat5.get_elem(3, 1) == 5); 294 | assert(mat5.get_elem(3, 2) == 3); 295 | assert(mat5.get_elem(3, 3) == 1); 296 | } 297 | return 0; 298 | } 299 | -------------------------------------------------------------------------------- /src/tests/test_parameters.cpp: -------------------------------------------------------------------------------- 1 | #include "../libcatnip/parameters.hpp" 2 | 3 | using namespace catnip; 4 | 5 | int main(void) { 6 | 7 | Parameters Par; 8 | 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /src/tests/test_propertydouble.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "../libcatnip/io/arguments/properties/propertydouble.hpp" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace catnip; 10 | using namespace std; 11 | 12 | int main(void) { 13 | 14 | cerr << "Testing: PropertyDouble" << endl; 15 | cerr << "Testing: constructor" << endl; 16 | { PropertyDouble propDouble; } 17 | 18 | cerr << "Testing: getPropertyName" << endl; 19 | { 20 | PropertyDouble propDouble; 21 | string name = propDouble.getPropertyName(); 22 | assert(name.compare("PROPERTY_DOUBLE") == 0); 23 | } 24 | 25 | cerr << "Testing: getPropertyOptions" << endl; 26 | { 27 | 28 | PropertyDouble propDouble; 29 | auto options = propDouble.getPropertyOptions(); 30 | string opt = options.at(0); 31 | assert(opt.compare("MIN") == 0); 32 | opt = options.at(1); 33 | assert(opt.compare("MAX") == 0); 34 | } 35 | 36 | cerr << "Testing: propValid" << endl; 37 | { 38 | PropertyDouble propDouble; 39 | bool valid = propDouble.propValid(0.0); 40 | assert(valid); 41 | } 42 | 43 | cerr << "Testing: setPropOption" << endl; 44 | { 45 | PropertyDouble propDouble; 46 | double val = -1.2; 47 | propDouble.setPropOption("MIN", val); 48 | propDouble.propValid(0.0); 49 | bool excep = false; 50 | try { 51 | val = -2.3; 52 | propDouble.propValid(val); 53 | } catch (...) { 54 | excep = true; 55 | } 56 | assert(excep); 57 | 58 | excep = false; 59 | try { 60 | val = 3.5; 61 | propDouble.setPropOption("MAXimum", val); 62 | } catch (...) { 63 | excep = true; 64 | } 65 | assert(excep); 66 | } 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /src/tests/test_propertyfileexist.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "../libcatnip/io/arguments/properties/propertyfileexist.hpp" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace catnip; 10 | using namespace std; 11 | 12 | int main(void) { 13 | 14 | cerr << "Testing: PropertyFileExist" << endl; 15 | cerr << "Testing: constructor" << endl; 16 | { 17 | PropertyFileExist propFileExist1(true); 18 | PropertyFileExist propFileExist2(false); 19 | } 20 | 21 | cerr << "Testing: getPropertyName" << endl; 22 | { 23 | PropertyFileExist propFileExist; 24 | string name = propFileExist.getPropertyName(); 25 | assert(name.compare("PROPERTY_FILE_EXIST") == 0); 26 | } 27 | 28 | cerr << "Testing: getPropertyOptions" << endl; 29 | { 30 | 31 | PropertyFileExist propFileExist; 32 | auto options = propFileExist.getPropertyOptions(); 33 | string opt = options.at(0); 34 | assert(opt.compare("FILE_MUST_EXIST") == 0); 35 | } 36 | 37 | cerr << "Testing: propValid" << endl; 38 | { 39 | PropertyFileExist propFileExist1(false); 40 | PropertyFileExist propFileExist2(true); 41 | PropertyFileExist propFileExist3(true); 42 | 43 | bool valid = propFileExist1.propValid("test_propertyfileexist.cpp"); 44 | assert(valid); 45 | 46 | bool excep = false; 47 | try { 48 | valid = propFileExist2.propValid("fake"); 49 | } catch (...) { 50 | excep = true; 51 | } 52 | assert(excep); 53 | 54 | valid = propFileExist3.propValid("testfile.pun"); 55 | assert(valid); 56 | } 57 | 58 | cerr << "Testing: getPropOption" << endl; 59 | { 60 | PropertyFileExist propFileExist1(true); 61 | PropertyFileExist propFileExist2(false); 62 | 63 | bool fileExist = propFileExist1.getPropOption("FILE_MUST_EXIST"); 64 | assert(fileExist); 65 | 66 | fileExist = propFileExist2.getPropOption("FILE_MUST_EXIST"); 67 | assert(fileExist == false); 68 | } 69 | 70 | return 0; 71 | } 72 | -------------------------------------------------------------------------------- /src/tests/test_propertyfileext.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "../libcatnip/io/arguments/properties/propertyfileext.hpp" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace catnip; 10 | using namespace std; 11 | 12 | int main(void) { 13 | 14 | cerr << "Testing: PropertyFileExt" << endl; 15 | cerr << "Testing: constructor" << endl; 16 | { 17 | PropertyFileExt propFileExt1("*"); 18 | PropertyFileExt propFileExt2(""); 19 | PropertyFileExt propFileExt3(".jpg"); 20 | bool excep = false; 21 | try { 22 | PropertyFileExt propFileExt4("ffda.fd"); 23 | } catch (...) { 24 | excep = true; 25 | } 26 | assert(excep); 27 | 28 | set exts = {".png", ".gjf"}; 29 | PropertyFileExt propFileExt5(exts); 30 | } 31 | 32 | cerr << "Testing: getPropertyName" << endl; 33 | { 34 | PropertyFileExt propFileExt; 35 | string name = propFileExt.getPropertyName(); 36 | assert(name.compare("PROPERTY_FILE_EXT") == 0); 37 | } 38 | 39 | cerr << "Testing: getPropertyOptions" << endl; 40 | { 41 | 42 | PropertyFileExt propFileExt; 43 | auto options = propFileExt.getPropertyOptions(); 44 | string opt = options.at(0); 45 | assert(opt.compare("ALLOWED_FILE_EXT") == 0); 46 | } 47 | 48 | cerr << "Testing: propValid" << endl; 49 | { 50 | PropertyFileExt propFileExt(".jpg"); 51 | bool valid = propFileExt.propValid("dir/file.jpg"); 52 | assert(valid); 53 | bool excep = false; 54 | try { 55 | propFileExt.propValid("dir/file.jp"); 56 | } catch (...) { 57 | excep = true; 58 | } 59 | assert(excep); 60 | 61 | PropertyFileExt propFileExt2("*"); 62 | valid = propFileExt2.propValid("dir/file.jpg"); 63 | assert(valid); 64 | valid = propFileExt2.propValid("dir/file.jp"); 65 | assert(valid); 66 | 67 | set exts = {".png", ".gjf"}; 68 | PropertyFileExt propFileExt3(exts); 69 | valid = propFileExt3.propValid("Dir2/Path/File.png"); 70 | assert(valid); 71 | valid = propFileExt3.propValid("Dir2/Path/File.gjf"); 72 | assert(valid); 73 | excep = false; 74 | try { 75 | propFileExt3.propValid("dir/file.com"); 76 | } catch (...) { 77 | excep = true; 78 | } 79 | assert(excep); 80 | } 81 | return 0; 82 | } 83 | -------------------------------------------------------------------------------- /src/tests/test_propertyint.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "../libcatnip/io/arguments/properties/propertyint.hpp" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace catnip; 10 | using namespace std; 11 | 12 | int main(void) { 13 | 14 | cerr << "Testing: PropertyInt" << endl; 15 | cerr << "Testing: constructor" << endl; 16 | { PropertyInt propInt; } 17 | 18 | cerr << "Testing: getPropertyName" << endl; 19 | { 20 | PropertyInt propInt; 21 | string name = propInt.getPropertyName(); 22 | assert(name.compare("PROPERTY_INT") == 0); 23 | } 24 | 25 | cerr << "Testing: getPropertyOptions" << endl; 26 | { 27 | 28 | PropertyInt propInt; 29 | auto options = propInt.getPropertyOptions(); 30 | string opt = options.at(0); 31 | assert(opt.compare("MIN") == 0); 32 | opt = options.at(1); 33 | assert(opt.compare("MAX") == 0); 34 | } 35 | 36 | cerr << "Testing: propValid" << endl; 37 | { 38 | PropertyInt propInt; 39 | bool valid = propInt.propValid(0); 40 | assert(valid); 41 | } 42 | 43 | cerr << "Testing: setPropOption" << endl; 44 | { 45 | PropertyInt propInt; 46 | propInt.setPropOption("MIN", 0); 47 | propInt.propValid(0); 48 | bool excep = false; 49 | try { 50 | propInt.propValid(-1); 51 | } catch (...) { 52 | excep = true; 53 | } 54 | assert(excep); 55 | 56 | excep = false; 57 | try { 58 | propInt.setPropOption("MAXimum", 3); 59 | } catch (...) { 60 | excep = true; 61 | } 62 | assert(excep); 63 | } 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /src/tests/test_propertysisterfile.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "../libcatnip/io/arguments/properties/propertysisterfile.hpp" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace catnip; 11 | using namespace std; 12 | 13 | int main(void) { 14 | fstream fs; 15 | fs.open("testfile.pun", ios::out); 16 | fs.close(); 17 | 18 | cerr << "Testing: PropertySisterFile" << endl; 19 | cerr << "Testing: constructor" << endl; 20 | { PropertySisterFile propSisterFile1; } 21 | 22 | cerr << "Testing: getPropertyName" << endl; 23 | { 24 | PropertySisterFile propSisterFile; 25 | string name = propSisterFile.getPropertyName(); 26 | assert(name.compare("PROPERTY_SISTER_FILE") == 0); 27 | } 28 | 29 | cerr << "Testing: getPropertyOptions" << endl; 30 | { 31 | 32 | PropertySisterFile propSisterFile; 33 | auto options = propSisterFile.getPropertyOptions(); 34 | 35 | bool allowed_file = false; 36 | bool sister_name = false; 37 | bool sister_path = false; 38 | bool sister_name_path = false; 39 | bool sister_exists = false; 40 | 41 | for (auto opt : options) { 42 | if (opt.compare("ALLOWED_SISTER_FILE_EXT") == 0) { 43 | allowed_file = true; 44 | } 45 | if (opt.compare("SISTER_FILE_NAME") == 0) { 46 | sister_name = true; 47 | } 48 | if (opt.compare("SISTER_FILE_PATH") == 0) { 49 | sister_path = true; 50 | } 51 | if (opt.compare("SISTER_FILE_PATH_NAME") == 0) { 52 | sister_name_path = true; 53 | } 54 | if (opt.compare("SISTER_FILE_EXISTS") == 0) { 55 | sister_exists = true; 56 | } 57 | } 58 | assert(allowed_file); 59 | assert(sister_name); 60 | assert(sister_path); 61 | assert(sister_name_path); 62 | assert(sister_exists); 63 | } 64 | 65 | cerr << "Testing: getPropOption" << endl; 66 | { 67 | PropertySisterFile propSisterFile1; 68 | 69 | vector allowed_ext = 70 | propSisterFile1.getPropOption("ALLOWED_SISTER_FILE_EXT"); 71 | vector file_name = 72 | propSisterFile1.getPropOption("SISTER_FILE_NAME"); 73 | vector file_path = 74 | propSisterFile1.getPropOption("SISTER_FILE_PATH"); 75 | vector file_path_name = 76 | propSisterFile1.getPropOption("SISTER_FILE_PATH_NAME"); 77 | vector fileExist = 78 | propSisterFile1.getPropOption("SISTER_FILE_EXISTS"); 79 | 80 | assert(allowed_ext.at(0).compare("NOT_DEFINED") == 0); 81 | assert(file_name.at(0).compare("NOT_DEFINED") == 0); 82 | assert(file_path.at(0).compare("NOT_DEFINED") == 0); 83 | assert(file_path_name.at(0).compare("NOT_DEFINED") == 0); 84 | assert(fileExist.at(0).compare("false") == 0); 85 | } 86 | 87 | cerr << "Testing: getPropOption" << endl; 88 | { 89 | PropertySisterFile propSisterFile1; 90 | 91 | propSisterFile1.setPropOption("ALLOWED_SISTER_FILE_EXT", ".pun"); 92 | 93 | string fileName = "testfile.log"; 94 | propSisterFile1.propValid(fileName); 95 | vector allowed_ext = 96 | propSisterFile1.getPropOption("ALLOWED_SISTER_FILE_EXT"); 97 | vector file_name = 98 | propSisterFile1.getPropOption("SISTER_FILE_NAME"); 99 | vector file_path = 100 | propSisterFile1.getPropOption("SISTER_FILE_PATH"); 101 | vector file_path_name = 102 | propSisterFile1.getPropOption("SISTER_FILE_PATH_NAME"); 103 | vector fileExist = 104 | propSisterFile1.getPropOption("SISTER_FILE_EXISTS"); 105 | 106 | assert(allowed_ext.at(0).compare(".pun") == 0); 107 | 108 | assert(file_name.at(0).compare("testfile.pun") == 0); 109 | assert(file_path.at(0).compare("") == 0); 110 | assert(file_path_name.at(0).compare("testfile.pun") == 0); 111 | assert(fileExist.at(0).compare("true") == 0); 112 | } 113 | return 0; 114 | } 115 | -------------------------------------------------------------------------------- /src/tests/test_propertystring.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "../libcatnip/io/arguments/properties/propertystring.hpp" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace catnip; 10 | using namespace std; 11 | 12 | int main(void) { 13 | 14 | cerr << "Testing: PropertyString" << endl; 15 | cerr << "Testing: constructor" << endl; 16 | { PropertyString propString; } 17 | 18 | cerr << "Testing: getPropertyName" << endl; 19 | { 20 | PropertyString propString; 21 | string name = propString.getPropertyName(); 22 | assert(name.compare("PROPERTY_STRING") == 0); 23 | } 24 | 25 | cerr << "Testing: getPropertyOptions" << endl; 26 | { 27 | 28 | PropertyString propString; 29 | auto options = propString.getPropertyOptions(); 30 | string opt = options.at(0); 31 | assert(opt.compare("MIN_LENGTH") == 0); 32 | opt = options.at(1); 33 | assert(opt.compare("MAX_LENGTH") == 0); 34 | } 35 | 36 | cerr << "Testing: propValid" << endl; 37 | { 38 | PropertyString propString; 39 | bool valid = propString.propValid("Hello"); 40 | assert(valid); 41 | } 42 | 43 | cerr << "Testing: setPropOption" << endl; 44 | { 45 | PropertyString propString; 46 | size_t val = 3; 47 | propString.setPropOption("MAX_LENGTH", val); 48 | propString.propValid(""); 49 | bool excep = false; 50 | try { 51 | propString.propValid("Hello"); 52 | } catch (...) { 53 | excep = true; 54 | } 55 | assert(excep); 56 | 57 | excep = false; 58 | try { 59 | val = 4; 60 | propString.setPropOption("MAXimum", val); 61 | } catch (...) { 62 | excep = true; 63 | } 64 | assert(excep); 65 | } 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /src/tests/test_propertystringchoice.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "../libcatnip/io/arguments/properties/propertystringchoice.hpp" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace catnip; 11 | using namespace std; 12 | 13 | int main(void) { 14 | cerr << "Testing: PropertyStringChoice" << endl; 15 | cerr << "Testing: constructor" << endl; 16 | { PropertyStringChoice propStrChoice; } 17 | 18 | cerr << "Testing: getPropertyName" << endl; 19 | { 20 | PropertyStringChoice propStrChoice; 21 | string name = propStrChoice.getPropertyName(); 22 | assert(name.compare("PROPERTY_STRING_CHOICE") == 0); 23 | } 24 | 25 | cerr << "Testing: getPropertyOptions" << endl; 26 | { 27 | 28 | PropertyStringChoice propStrChoice; 29 | auto options = propStrChoice.getPropertyOptions(); 30 | 31 | bool choice_enforced = false; 32 | bool str_choices = false; 33 | 34 | for (auto opt : options) { 35 | if (opt.compare("STRING_CHOICE_ENFORCED") == 0) { 36 | choice_enforced = true; 37 | } 38 | if (opt.compare("STRING_CHOICES") == 0) { 39 | str_choices = true; 40 | } 41 | } 42 | assert(choice_enforced); 43 | assert(str_choices); 44 | } 45 | 46 | cerr << "Testing: getPropOption" << endl; 47 | { 48 | PropertyStringChoice propStrChoice; 49 | 50 | set choice_enforced = 51 | propStrChoice.getPropOption("STRING_CHOICE_ENFORCED"); 52 | set choices = propStrChoice.getPropOption("STRING_CHOICES"); 53 | 54 | string enforced = *(choice_enforced.begin()); 55 | string choice = *(choices.begin()); 56 | assert(enforced.compare("false") == 0); 57 | assert(choice.compare("NOT_DEFINED") == 0); 58 | } 59 | 60 | cerr << "Testing: getPropOption" << endl; 61 | { 62 | PropertyStringChoice propStrChoice; 63 | 64 | propStrChoice.setPropOption("STRING_CHOICE_ENFORCED", "true"); 65 | set choices{"true", "false"}; 66 | propStrChoice.setPropOption("STRING_CHOICES", choices); 67 | 68 | string choice = "true"; 69 | propStrChoice.propValid(choice); 70 | choice = "false"; 71 | propStrChoice.propValid(choice); 72 | 73 | choice = "blah"; 74 | bool throwerror = false; 75 | try { 76 | propStrChoice.propValid(choice); 77 | } catch (...) { 78 | throwerror = true; 79 | } 80 | assert(throwerror); 81 | 82 | set allowed_choices = propStrChoice.getPropOption("STRING_CHOICES"); 83 | set choice_on = 84 | propStrChoice.getPropOption("STRING_CHOICE_ENFORCED"); 85 | 86 | bool false_str = false; 87 | bool true_str = false; 88 | for (auto item : allowed_choices) { 89 | if (item.compare("false") == 0) false_str = true; 90 | if (item.compare("true") == 0) true_str = true; 91 | } 92 | assert(false_str); 93 | assert(true_str); 94 | 95 | string on = *(choice_on.begin()); 96 | assert(on.compare("true") == 0); 97 | } 98 | return 0; 99 | } 100 | -------------------------------------------------------------------------------- /src/tests/test_propertyswitch.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "../libcatnip/io/arguments/properties/propertyswitch.hpp" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace catnip; 10 | using namespace std; 11 | 12 | int main(void) { 13 | 14 | cerr << "Testing: PropertySwitch" << endl; 15 | cerr << "Testing: constructor" << endl; 16 | { PropertySwitch propSwitch; } 17 | 18 | cerr << "Testing: getPropertyName" << endl; 19 | { 20 | PropertySwitch propSwitch; 21 | string name = propSwitch.getPropertyName(); 22 | assert(name.compare("PROPERTY_SWITCH") == 0); 23 | } 24 | 25 | cerr << "Testing: getPropertyOptions" << endl; 26 | { 27 | 28 | PropertySwitch propSwitch; 29 | auto options = propSwitch.getPropertyOptions(); 30 | string opt = options.at(0); 31 | assert(opt.compare("DEFAULT") == 0); 32 | } 33 | 34 | cerr << "Testing: propValid" << endl; 35 | { 36 | PropertySwitch propSwitch; 37 | bool valid = propSwitch.propValid(0); 38 | assert(valid); 39 | valid = propSwitch.propValid(1); 40 | assert(valid); 41 | valid = propSwitch.propValid(); 42 | assert(valid); 43 | bool excep = false; 44 | try { 45 | propSwitch.propValid(-1); 46 | } catch (...) { 47 | excep = true; 48 | } 49 | assert(excep); 50 | 51 | excep = false; 52 | try { 53 | propSwitch.propValid(2); 54 | } catch (...) { 55 | excep = true; 56 | } 57 | assert(excep); 58 | 59 | valid = propSwitch.propValid("ON"); 60 | assert(valid); 61 | valid = propSwitch.propValid("OFF"); 62 | assert(valid); 63 | valid = propSwitch.propValid("TRUE"); 64 | assert(valid); 65 | valid = propSwitch.propValid("FALSE"); 66 | assert(valid); 67 | valid = propSwitch.propValid("0"); 68 | assert(valid); 69 | valid = propSwitch.propValid("1"); 70 | assert(valid); 71 | } 72 | 73 | cerr << "Testing: setPropOption" << endl; 74 | { 75 | PropertySwitch propSwitch; 76 | propSwitch.setPropOption("DEFAULT", "ON"); 77 | propSwitch.setPropOption("DEFAULT", "OFF"); 78 | // propSwitch.propValid(0); 79 | // bool excep = false; 80 | // try { 81 | // propSwitch.propValid(-1); 82 | // } catch (...) { 83 | // excep = true; 84 | // } 85 | // assert(excep); 86 | } 87 | return 0; 88 | } 89 | -------------------------------------------------------------------------------- /src/tests/test_punreader.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "../libcatnip/io/file_readers/punreader.hpp" 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace catnip; 9 | using namespace std; 10 | 11 | int main(void) { 12 | 13 | cerr << "Testing: PunReader Constructor" << endl; 14 | { PunReader pr("file.pun"); } 15 | 16 | cerr << "Testing: PunReader read" << endl; 17 | { 18 | PunReader pr("../../../GAUSSIANFILES/90_unordered/90_pair.pun"); 19 | pr.read(); 20 | 21 | auto m = pr.getCoefsMatrix("Alpha"); 22 | assert(m->get_rows() == 92); 23 | assert(pr.restrictedShell()); 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /src/tests/test_qc_functions.cpp: -------------------------------------------------------------------------------- 1 | #include "../libcatnip/matrix.hpp" 2 | #include "../libcatnip/qc_functions.hpp" 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace catnip; 8 | using namespace std; 9 | 10 | int main(void) { 11 | 12 | cout << "Testing: unscramble_Coef" << endl; 13 | { 14 | Matrix* dimerCoef = new Matrix(8, 8); 15 | for (int i = 1; i <= 8; ++i) { 16 | dimerCoef->set_elem(1.3, i, 1); 17 | dimerCoef->set_elem(0.2, i, 3); 18 | dimerCoef->set_elem(82.4, i, 4); 19 | dimerCoef->set_elem(9.4, i, 5); 20 | dimerCoef->set_elem(3.4, i, 6); 21 | dimerCoef->set_elem(-3.0, i, 8); 22 | } 23 | 24 | // Our coefficient matrix should look like this 25 | // 26 | // col 1 col 2 col 3 col 4 col 5 col 6 col 7 col 8 27 | // _______________________________________________________ 28 | // row 1 | 1.3 0.0 0.2 82.4 9.4 3.4 0.0 -3.0 29 | // row 2 | 1.3 0.0 0.2 82.4 9.4 3.4 0.0 -3.0 30 | // row 3 | 1.3 0.0 0.2 82.4 9.4 3.4 0.0 -3.0 31 | // row 4 | 1.3 0.0 0.2 82.4 9.4 3.4 0.0 -3.0 32 | // row 5 | 1.3 0.0 0.2 82.4 9.4 3.4 0.0 -3.0 33 | // row 6 | 1.3 0.0 0.2 82.4 9.4 3.4 0.0 -3.0 34 | // row 7 | 1.3 0.0 0.2 82.4 9.4 3.4 0.0 -3.0 35 | // row 8 | 1.3 0.0 0.2 82.4 9.4 3.4 0.0 -3.0 36 | // atm3 atm1 atm1 atm5 atm4 atm4 atm2 atm2 37 | 38 | // Contains the x y and z position of atoms in monomer A 39 | Matrix* coordA = new Matrix(2, 3); 40 | // Atom 1 at (1.0,1.0,1.0) 41 | // Atom 2 at (0.0,0.0,0.0) 42 | coordA->set_elem(1.0, 1, 1); 43 | coordA->set_elem(1.0, 1, 2); 44 | coordA->set_elem(1.0, 1, 3); 45 | 46 | // Contains the x y and z position of atoms in monomer B 47 | Matrix* coordB = new Matrix(3, 3); 48 | // Atom 3 at (1.0,0.0,0.0) 49 | // Atom 4 at (2.0,0.0,0.0) 50 | // Atom 5 at (3.0,0.0,0.0) 51 | coordB->set_elem(1.0, 1, 1); 52 | coordB->set_elem(2.0, 2, 1); 53 | coordB->set_elem(3.0, 3, 1); 54 | 55 | Matrix* coordDimer = new Matrix(5, 3); 56 | // Arrange atoms in the dimer so they do not appear in the 57 | // same order as the monomers 58 | 59 | // row1 Atom 3 60 | coordDimer->set_elem(1.0, 1, 1); 61 | // row2 Atom 1 62 | coordDimer->set_elem(1.0, 2, 1); 63 | coordDimer->set_elem(1.0, 2, 2); 64 | coordDimer->set_elem(1.0, 2, 3); 65 | // row3 Atom 5 66 | coordDimer->set_elem(3.0, 3, 1); 67 | // row4 Atom 4 68 | coordDimer->set_elem(2.0, 4, 1); 69 | // row5 Atom 2 (0.0,0.0,0.0) 70 | 71 | vector matchA = coordA->matchRow(*coordDimer, 2); 72 | vector matchB = coordB->matchRow(*coordDimer, 2); 73 | 74 | assert(matchA.at(0) == 2); 75 | assert(matchA.at(1) == 5); 76 | 77 | assert(matchB.at(0) == 1); 78 | assert(matchB.at(1) == 4); 79 | assert(matchB.at(2) == 3); 80 | 81 | vector basisFuncDimer; 82 | // Basis functions per atom 83 | // 84 | // Atom 1 2 85 | // Atom 2 2 86 | // Atom 3 1 87 | // Atom 4 2 88 | // Atom 5 1 89 | 90 | // According to the dimer coordinates they will appear in the following 91 | // order 92 | // Atom 3 1 93 | // Atom 1 2 94 | // Atom 5 1 95 | // Atom 4 2 96 | // Atom 2 2 97 | 98 | basisFuncDimer.push_back(1); 99 | basisFuncDimer.push_back(2); 100 | basisFuncDimer.push_back(1); 101 | basisFuncDimer.push_back(2); 102 | basisFuncDimer.push_back(2); 103 | 104 | // According to the basis functions and the atom positions the current 105 | // coef table for monomer A should look like this 106 | // col 1 col 2 col 3 col 4 107 | // ____________________________ 108 | // row 1 | 0.0 0.2 0.0 -3.0 109 | // row 2 | 0.0 0.2 0.0 -3.0 110 | // row 3 | 0.0 0.2 0.0 -3.0 111 | // row 4 | 0.0 0.2 0.0 -3.0 112 | // row 5 | 0.0 0.2 0.0 -3.0 113 | // row 6 | 0.0 0.2 0.0 -3.0 114 | // row 7 | 0.0 0.2 0.0 -3.0 115 | // row 8 | 0.0 0.2 0.0 -3.0 116 | // atm1 atm1 atm2 atm2 117 | 118 | cerr << "Before passing in" << endl; 119 | for (auto it : matchA) cerr << it << endl; 120 | for (auto it : matchB) cerr << it << endl; 121 | for (auto it : basisFuncDimer) cerr << it << endl; 122 | // If we correct the dimer coefficient matrix to line up with the 123 | // coefficients of the monomers it should look like this 124 | // 125 | // Col 1 Col 2 Col 3 Col 4 Col 5 Col 6 Col 7 Col 8 126 | // Row 1 1.3 9.4 3.4 82.4 0 0.2 0 -3 127 | // Row 2 1.3 9.4 3.4 82.4 0 0.2 0 -3 128 | // Row 3 1.3 9.4 3.4 82.4 0 0.2 0 -3 129 | // Row 4 1.3 9.4 3.4 82.4 0 0.2 0 -3 130 | // Row 5 1.3 9.4 3.4 82.4 0 0.2 0 -3 131 | // Row 6 1.3 9.4 3.4 82.4 0 0.2 0 -3 132 | // Row 7 1.3 9.4 3.4 82.4 0 0.2 0 -3 133 | // Row 8 1.3 9.4 3.4 82.4 0 0.2 0 -3 134 | 135 | cerr << "Calling unscramble" << endl; 136 | auto NewCoef = unscramble_Coef(matchB, matchA, basisFuncDimer, dimerCoef); 137 | 138 | cerr << *NewCoef << endl; 139 | 140 | for (int i = 1; i <= 8; ++i) { 141 | assert(static_cast(NewCoef->get_elem(i, 1) * 10) == 13); 142 | assert(static_cast(NewCoef->get_elem(i, 2) * 10) == 94); 143 | assert(static_cast(NewCoef->get_elem(i, 3) * 10) == 34); 144 | assert(static_cast(NewCoef->get_elem(i, 4) * 10) == 824); 145 | assert(static_cast(NewCoef->get_elem(i, 5)) == 0); 146 | assert(static_cast(NewCoef->get_elem(i, 6) * 10) == 2); 147 | assert(static_cast(NewCoef->get_elem(i, 7)) == 0); 148 | assert(static_cast(NewCoef->get_elem(i, 8)) == -3); 149 | } 150 | } 151 | 152 | cout << "Testing: unscramble_S_Coef" << endl; 153 | { 154 | Matrix* SCoef = new Matrix(8, 8); 155 | for (int i = 1; i <= 8; ++i) { 156 | SCoef->set_elem(1.3, i, 2); 157 | SCoef->set_elem(1.3, i, 3); 158 | SCoef->set_elem(4.0, i, 4); 159 | } 160 | 161 | for (int i = 1; i <= 8; ++i) { 162 | SCoef->set_elem(1.3, 2, i); 163 | SCoef->set_elem(1.3, 3, i); 164 | SCoef->set_elem(4.0, 4, i); 165 | } 166 | 167 | SCoef->set_elem(6.0, 2, 4); 168 | SCoef->set_elem(6.0, 3, 4); 169 | SCoef->set_elem(6.0, 4, 2); 170 | SCoef->set_elem(6.0, 4, 3); 171 | 172 | // Our coefficient matrix should look like this 173 | // 174 | // col 1 col 2 col 3 col 4 col 5 col 6 col 7 col 8 175 | // _______________________________________________________ 176 | // atm 3 row 1 | 0.0 1.3 1.3 4.0 0.0 0.0 0.0 0.0 177 | // atm 1 row 2 | 1.3 1.3 1.3 6.0 1.3 1.3 1.3 1.3 178 | // atm 1 row 3 | 1.3 1.3 1.3 6.0 1.3 1.3 1.3 1.3 179 | // atm 5 row 4 | 4.0 6.0 6.0 4.0 4.0 4.0 4.0 4.0 180 | // atm 4 row 5 | 0.0 1.3 1.3 4.0 0.0 0.0 0.0 0.0 181 | // atm 4 row 6 | 0.0 1.3 1.3 4.0 0.0 0.0 0.0 0.0 182 | // atm 2 row 7 | 0.0 1.3 1.3 4.0 0.0 0.0 0.0 0.0 183 | // atm 2 row 8 | 0.0 1.3 1.3 4.0 0.0 0.0 0.0 0.0 184 | // atm3 atm1 atm1 atm5 atm4 atm4 atm2 atm2 185 | 186 | // Contains the x y and z position of atoms in monomer A 187 | Matrix* coordA = new Matrix(2, 3); 188 | // Atom 1 at (1.0,1.0,1.0) 189 | // Atom 2 at (0.0,0.0,0.0) 190 | coordA->set_elem(1.0, 1, 1); 191 | coordA->set_elem(1.0, 1, 2); 192 | coordA->set_elem(1.0, 1, 3); 193 | 194 | // Contains the x y and z position of atoms in monomer B 195 | Matrix* coordB = new Matrix(3, 3); 196 | // Atom 3 at (1.0,0.0,0.0) 197 | // Atom 4 at (2.0,0.0,0.0) 198 | // Atom 5 at (3.0,0.0,0.0) 199 | coordB->set_elem(1.0, 1, 1); 200 | coordB->set_elem(2.0, 2, 1); 201 | coordB->set_elem(3.0, 3, 1); 202 | 203 | Matrix* coordDimer = new Matrix(5, 3); 204 | // Arrange atoms in the dimer so they do not appear in the 205 | // same order as the monomers 206 | 207 | // row1 Atom 3 208 | coordDimer->set_elem(1.0, 1, 1); 209 | // row2 Atom 1 210 | coordDimer->set_elem(1.0, 2, 1); 211 | coordDimer->set_elem(1.0, 2, 2); 212 | coordDimer->set_elem(1.0, 2, 3); 213 | // row3 Atom 5 214 | coordDimer->set_elem(3.0, 3, 1); 215 | // row4 Atom 4 216 | coordDimer->set_elem(2.0, 4, 1); 217 | // row5 Atom 2 (0.0,0.0,0.0) 218 | 219 | vector matchA = coordA->matchRow(*coordDimer, 2); 220 | vector matchB = coordB->matchRow(*coordDimer, 2); 221 | 222 | assert(matchA.at(0) == 2); 223 | assert(matchA.at(1) == 5); 224 | 225 | assert(matchB.at(0) == 1); 226 | assert(matchB.at(1) == 4); 227 | assert(matchB.at(2) == 3); 228 | 229 | vector basisFuncDimer; 230 | // Basis functions per atom 231 | // 232 | // Atom 1 2 233 | // Atom 2 2 234 | // Atom 3 1 235 | // Atom 4 2 236 | // Atom 5 1 237 | 238 | // According to the dimer coordinates they will appear in the following 239 | // order 240 | // Atom 3 1 241 | // Atom 1 2 242 | // Atom 5 1 243 | // Atom 4 2 244 | // Atom 2 2 245 | 246 | basisFuncDimer.push_back(1); 247 | basisFuncDimer.push_back(2); 248 | basisFuncDimer.push_back(1); 249 | basisFuncDimer.push_back(2); 250 | basisFuncDimer.push_back(2); 251 | 252 | cerr << "Before passing in" << endl; 253 | for (auto it : matchA) cerr << it << endl; 254 | for (auto it : matchB) cerr << it << endl; 255 | for (auto it : basisFuncDimer) cerr << it << endl; 256 | // If we correct the dimer coefficient matrix to line up with the 257 | // coefficients of the monomers it should look like this 258 | // 259 | // Col 1 Col 2 Col 3 Col 4 Col 5 Col 6 Col 7 Col 8 260 | // Row 1 0 0 0 4 1.3 1.3 0 0 261 | // Row 2 0 0 0 4 1.3 1.3 0 0 262 | // Row 3 0 0 0 4 1.3 1.3 0 0 263 | // Row 4 4 4 4 4 6 6 4 4 264 | // Row 5 1.3 1.3 1.3 6 1.3 1.3 1.3 1.3 265 | // Row 6 1.3 1.3 1.3 6 1.3 1.3 1.3 1.3 266 | // Row 7 0 0 0 4 1.3 1.3 0 0 267 | // Row 8 0 0 0 4 1.3 1.3 0 0 268 | cerr << "Calling unscramble" << endl; 269 | auto NewCoef = unscramble_S(matchB, matchA, basisFuncDimer, SCoef); 270 | 271 | cerr << *NewCoef << endl; 272 | 273 | for (int i = 1; i <= 8; ++i) { 274 | if (i != 4) { 275 | assert(static_cast(NewCoef->get_elem(i, 5) * 10) == 13); 276 | assert(static_cast(NewCoef->get_elem(i, 6) * 10) == 13); 277 | 278 | assert(static_cast(NewCoef->get_elem(5, i) * 10) == 13); 279 | assert(static_cast(NewCoef->get_elem(6, i) * 10) == 13); 280 | } 281 | } 282 | 283 | for (int i = 1; i <= 8; ++i) { 284 | if (i == 5 || i == 6) { 285 | assert(static_cast(NewCoef->get_elem(i, 4)) == 6); 286 | assert(static_cast(NewCoef->get_elem(4, i)) == 6); 287 | } else { 288 | assert(static_cast(NewCoef->get_elem(4, i)) == 4); 289 | assert(static_cast(NewCoef->get_elem(i, 4)) == 4); 290 | } 291 | } 292 | } 293 | return 0; 294 | } 295 | -------------------------------------------------------------------------------- /src/tests/test_script_calc_J.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ $# -eq 0 ]; then 4 | path="./../" 5 | else 6 | path=$1 7 | fi 8 | 9 | fileOut="test_script.out" 10 | 11 | # Ensure that the bc calculator is installed 12 | Is_bc_installed=$(command -v bc) 13 | if [ -z "$Is_bc_installed" ] 14 | then 15 | echo "To run the test script you must have bc installed!" 16 | exit 1 17 | fi 18 | 19 | echo "PATH "$path 20 | 21 | red=$(tput setaf 1) 22 | green=$(tput setaf 2) 23 | reset=$(tput sgr0) 24 | count_fails=0 25 | 26 | findJeff() { 27 | values=$data 28 | values=($values) 29 | echo "Num array "${#values[@]} 30 | for (( i=0; i < ${#values[@]}; i++ )) 31 | do 32 | if [ "${values[$i]}" == "J_eff" ] 33 | then 34 | J_val=${values[$i+1]} 35 | break 36 | fi 37 | done 38 | } 39 | 40 | # The following commands should work 41 | exec_command="${path}/build/calc_J -h" 42 | ${exec_command} > $fileOut 43 | if [ $? -eq 0 ]; then 44 | echo "${green}[SUCCESS]${reset} ${exec_command}" 45 | else 46 | echo "${red}[FAILURE]${reset} ${exec_command}" 47 | count_fails=$((count_fails+1)) 48 | fi 49 | 50 | exec_command="${path}/build/calc_J -p_P ${path}/GAUSSIANFILES/30/30_pair.pun -p_1 ${path}/GAUSSIANFILES/30/ref.pun -p_2 ${path}/GAUSSIANFILES/30/30_2.pun" 51 | data=$(${exec_command} ) 52 | if [ $? -eq 0 ]; then 53 | 54 | findJeff 55 | if (( $( bc <<< "$J_val > 0.04973" ) )) && (( $( bc <<< "$J_val < 0.04975" ) )) 56 | then 57 | echo "${green}[SUCCESS]${reset} ${exec_command}" 58 | else 59 | echo "${red}[FAILURE]${reset} ${exec_command} expected output 0.0497444" 60 | echo "actual output $J_val" 61 | echo $( bc <<< "$J_val > 0.04973" ) 62 | echo $( bc <<< "$J_val < 0.04975" ) 63 | count_fails=$(($count_fails+1)) 64 | fi 65 | else 66 | echo "${red}[FAILURE]${reset} ${exec_command}" 67 | count_fails=$(($count_fails+1)) 68 | fi 69 | echo $data >> $fileOut 70 | 71 | exec_command="${path}/build/calc_J -p_P ${path}/GAUSSIANFILES/P_test/AB.pun -p_1 ${path}/GAUSSIANFILES/P_test/A.pun -p_2 ${path}/GAUSSIANFILES/P_test/B.pun" 72 | data=$(${exec_command} ) 73 | if [ $? -eq 0 ]; then 74 | 75 | findJeff 76 | if (( $( bc <<< "$J_val > 0.02617" ) )) && (( $( bc <<< "$J_val < 0.02619" ) )) 77 | then 78 | echo "${green}[SUCCESS]${reset} ${exec_command}" 79 | else 80 | echo "${red}[FAILURE]${reset} ${exec_command} expected output 0.0261851" 81 | echo "actual output $J_val" 82 | echo $( bc <<< "$J_val > 0.02617" ) 83 | echo $( bc <<< "$J_val < 0.02619" ) 84 | count_fails=$(($count_fails+1)) 85 | fi 86 | else 87 | echo "${red}[FAILURE]${reset} ${exec_command}" 88 | count_fails=$(($count_fails+1)) 89 | fi 90 | echo $data >> $fileOut 91 | 92 | exec_command="${path}/build/calc_J -p_P ${path}/GAUSSIANFILES/Square_Matrix_test/dimer.pun -p_1 ${path}/GAUSSIANFILES/Square_Matrix_test/monomer1.pun -p_2 ${path}/GAUSSIANFILES/Square_Matrix_test/monomer2.pun" 93 | data=$(${exec_command} ) 94 | if [ $? -eq 0 ]; then 95 | 96 | findJeff 97 | if (( $( bc <<< "$J_val > 0.001245" ) )) && (( $( bc <<< "$J_val < 0.001247" ) )) 98 | then 99 | echo "${green}[SUCCESS]${reset} ${exec_command}" 100 | else 101 | echo "${red}[FAILURE]${reset} ${exec_command} expected output 0.00124623" 102 | echo "actual output $J_val" 103 | echo $( bc <<< "$J_val > 0.001245" ) 104 | echo $( bc <<< "$J_val < 0.001247" ) 105 | count_fails=$(($count_fails+1)) 106 | fi 107 | else 108 | echo "${red}[FAILURE]${reset} ${exec_command}" 109 | count_fails=$(($count_fails+1)) 110 | fi 111 | echo $data >> $fileOut 112 | 113 | 114 | 115 | exec_command="${path}/build/calc_J -l_P ${path}/GAUSSIANFILES/30/30_pair.log -l_1 ${path}/GAUSSIANFILES/30/ref.log -l_2 ${path}/GAUSSIANFILES/30/30_2.log" 116 | data=$(${exec_command}) 117 | if [ $? -eq 0 ]; then 118 | findJeff 119 | if (( $(bc <<< "$J_val > 0.04973" ) )) && (( $(bc <<< "$J_val < 0.04975" ) )) 120 | then 121 | echo "${green}[SUCCESS]${reset} ${exec_command}" 122 | else 123 | echo "${red}[FAILURE]${reset} ${exec_command} expected output 0.0497444" 124 | echo "actual output $J_val" 125 | count_fails=$(($count_fails+1)) 126 | fi 127 | else 128 | echo "${red}[FAILURE]${reset} ${exec_command}" 129 | count_fails=$(($count_fails+1)) 130 | fi 131 | echo $data >> $fileOut 132 | 133 | exec_command="${path}/build/calc_J -l_P ${path}/GAUSSIANFILES/30/30_pair.log -l_1 ${path}/GAUSSIANFILES/30/ref.log -l_2 ${path}/GAUSSIANFILES/30/30_2.log -p_1 ${path}/GAUSSIANFILES/30/ref.pun" 134 | data=$(${exec_command}) 135 | if [ $? -eq 0 ]; then 136 | echo "${green}[SUCCESS]${reset} ${exec_command}" 137 | else 138 | echo "${red}[FAILURE]${reset} ${exec_command}" 139 | count_fails=$(($count_fails+1)) 140 | fi 141 | echo $data >> $fileOut 142 | 143 | exec_command="${path}/build/calc_J -l_P ${path}/GAUSSIANFILES/30/30_pair.log -orb_ty_1 LUMO -l_1 ${path}/GAUSSIANFILES/30/ref.log -l_2 ${path}/GAUSSIANFILES/30/30_2.log" 144 | data=$(${exec_command}) 145 | if [ $? -eq 0 ]; then 146 | echo "${green}[SUCCESS]${reset} ${exec_command}" 147 | else 148 | echo "${red}[FAILURE]${reset} ${exec_command}" 149 | count_fails=$(($count_fails+1)) 150 | fi 151 | echo $data >> $fileOut 152 | 153 | exec_command="${path}/build/calc_J -l_P ${path}/GAUSSIANFILES/30/30_pair.log -orb_ty_1 LUMO -l_1 ${path}/GAUSSIANFILES/30/ref.log -orb_ty_2 LUMO -l_2 ${path}/GAUSSIANFILES/30/30_2.log" 154 | data=$(${exec_command}) 155 | if [ $? -eq 0 ]; then 156 | findJeff 157 | if (( $(bc <<< "$J_val > 0.1270" ) )) && (( $(bc <<< "$J_val < 0.1272" ) )) 158 | then 159 | echo "${green}[SUCCESS]${reset} ${exec_command}" 160 | else 161 | echo "${red}[FAILURE]${reset} ${exec_command} expected output 0.127182" 162 | echo "actual output $J_val" 163 | count_fails=$(($count_fails+1)) 164 | fi 165 | else 166 | echo "${red}[FAILURE]${reset} ${exec_command}" 167 | count_fails=$(($count_fails+1)) 168 | fi 169 | echo $data >> $fileOut 170 | 171 | exec_command="${path}/build/calc_J -p_P ${path}/GAUSSIANFILES/CounterPoise/Dist_1Ang/1_pair.pun -p_1 ${path}/GAUSSIANFILES/CounterPoise/Dist_1Ang/ref.pun -p_2 ${path}/GAUSSIANFILES/CounterPoise/Dist_1Ang/1_B.pun -cp" 172 | data=$(${exec_command}) 173 | if [ $? -eq 0 ]; then 174 | findJeff 175 | if (( $(bc <<< "$J_val > 4.505" ) )) && (( $(bc <<< "$J_val < 4.506" ) )) 176 | then 177 | echo "${green}[SUCCESS]${reset} ${exec_command}" 178 | else 179 | echo "${red}[FAILURE]${reset} ${exec_command} expected output 4.50589" 180 | echo "actual output $J_val" 181 | count_fails=$(($count_fails+1)) 182 | fi 183 | else 184 | echo "${red}[FAILURE]${reset} ${exec_command}" 185 | count_fails=$(($count_fails+1)) 186 | fi 187 | echo $data >> $fileOut 188 | 189 | exec_command="${path}/build/calc_J -cp -p_P ${path}/GAUSSIANFILES/CounterPoise/Dist_1Ang/1_pair.pun -p_1 ${path}/GAUSSIANFILES/CounterPoise/Dist_1Ang/ref.pun -p_2 ${path}/GAUSSIANFILES/CounterPoise/Dist_1Ang/1_B.pun " 190 | data=$(${exec_command}) 191 | if [ $? -eq 0 ]; then 192 | findJeff 193 | if (( $(bc <<< "$J_val > 4.505" ) )) && (( $(bc <<< "$J_val < 4.506" ) )) 194 | then 195 | echo "${green}[SUCCESS]${reset} ${exec_command}" 196 | else 197 | echo "${red}[FAILURE]${reset} ${exec_command} expected output 4.50589" 198 | echo "actual output $J_val" 199 | count_fails=$(($count_fails+1)) 200 | fi 201 | else 202 | echo "${red}[FAILURE]${reset} ${exec_command}" 203 | count_fails=$(($count_fails+1)) 204 | fi 205 | echo $data >> $fileOut 206 | 207 | exec_command="${path}/build/calc_J -p_P ${path}/GAUSSIANFILES/CuBr2_Py/CuBr2-Py.pun -p_1 ${path}/GAUSSIANFILES/CuBr2_Py/CuBr2.pun -p_2 ${path}/GAUSSIANFILES/CuBr2_Py/Py.pun" 208 | data=$(${exec_command}) 209 | if [ $? -eq 0 ]; then 210 | findJeff 211 | if (( $(bc <<< "$J_val > -0.0055" ) )) && (( $(bc <<< "$J_val < -0.0053" ) )) 212 | then 213 | echo "${green}[SUCCESS]${reset} ${exec_command}" 214 | else 215 | echo "${red}[FAILURE]${reset} ${exec_command} expected output -0.00542741" 216 | echo "actual output $J_val" 217 | count_fails=$(($count_fails+1)) 218 | fi 219 | else 220 | echo "${red}[FAILURE]${reset} ${exec_command}" 221 | count_fails=$((count_fails+1)) 222 | fi 223 | echo $data >> $fileOut 224 | 225 | 226 | # The following commands should not work 227 | 228 | exit $count_fails 229 | -------------------------------------------------------------------------------- /src/tests/test_script_io.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ $# -eq 0 ]; then 4 | path="." 5 | else 6 | path=$1 7 | fi 8 | 9 | echo "PATH "$path 10 | 11 | red=$(tput setaf 1) 12 | green=$(tput setaf 2) 13 | reset=$(tput sgr0) 14 | count_fails=0 15 | 16 | ${path}/test_io -h > test_script.out 17 | if [ $? -eq 0 ]; then 18 | echo "${green}[SUCCESS]${reset} ${path}/test_io -h" 19 | else 20 | echo "${red}[FAILURE]${reset} ${path}/test_io -h" 21 | count_fails=$(($count_fails+1)) 22 | fi 23 | 24 | ${path}/test_io -cite > test_script.out 25 | if [ $? -eq 0 ]; then 26 | echo "${green}[SUCCESS]${reset} ${path}/test_io -cite" 27 | else 28 | echo "${red}[FAILURE]${reset} ${path}/test_io -cite" 29 | count_fails=$(($count_fails+1)) 30 | fi 31 | 32 | ${path}/test_io -p_P ${path}/../../GAUSSIANFILES/30/30_pair.pun -p_1 ${path}/../../GAUSSIANFILES/30/ref.pun -p_2 ${path}/../../GAUSSIANFILES/30/30_2.pun >> test_script.out 33 | if [ $? -eq 0 ]; then 34 | echo "${green}[SUCCESS]${reset} ${path}/test_io -p_P ${path}/../../GAUSSIANFILES/30/30_pair.pun -p_1 ${path}/../../GAUSSIANFILES/30/ref.pun -p_2 ${path}/../../GAUSSIANFILES/30/30_2.pun" 35 | else 36 | echo "${red}[FAILURE]${reset} ${path}/test_io -p_P ${path}/../../GAUSSIANFILES/30/30_pair.pun -p_1 ${path}/../../GAUSSIANFILES/30/ref.pun -p_2 ${path}/../../GAUSSIANFILES/30/30_2.pun" 37 | count_fails=$((count_fails+1)) 38 | fi 39 | 40 | ${path}/test_io -l_P ${path}/../../GAUSSIANFILES/30/30_pair.log -l_1 ${path}/../../GAUSSIANFILES/30/ref.log -l_2 ${path}/../../GAUSSIANFILES/30/30_2.log >> test_script.out 41 | if [ $? -eq 0 ]; then 42 | echo "${green}[SUCCESS]${reset} ${path}/test_io -l_P ${path}/../../GAUSSIANFILES/30/30_pair.log -l_1 ${path}/../../GAUSSIANFILES/30/ref.log -l_2 ${path}/../../GAUSSIANFILES/30/30_2.log" 43 | else 44 | echo "${red}[FAILURE]${reset} ${path}/test_io -l_P ${path}/../../GAUSSIANFILES/30/30_pair.log -l_1 ${path}/../../GAUSSIANFILES/30/ref.log -l_2 ${path}/../../GAUSSIANFILES/30/30_2.log" 45 | count_fails=$((count_fails+1)) 46 | fi 47 | 48 | exit $count_fails 49 | -------------------------------------------------------------------------------- /src/tests/test_string_support.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "../libcatnip/string_support.hpp" 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace catnip; 9 | using namespace std; 10 | 11 | int main(void) { 12 | 13 | cerr << "Testing: splitSt" << endl; 14 | { 15 | string str = "Hello World Lot of space"; 16 | vector v_str = splitSt(str); 17 | assert(v_str.at(0).compare("Hello") == 0); 18 | assert(v_str.at(1).compare("World") == 0); 19 | assert(v_str.at(2).compare("Lot") == 0); 20 | assert(v_str.at(3).compare("of") == 0); 21 | assert(v_str.at(4).compare("space") == 0); 22 | } 23 | 24 | cerr << "Testing: lastN" << endl; 25 | { 26 | string str = "Hi there!"; 27 | string var = lastN(str, 3); 28 | assert(var.compare("re!") == 0); 29 | } 30 | 31 | cerr << "Testing: lastStringInPath" << endl; 32 | { 33 | string str = "Path/To/Important/File.cc"; 34 | string fileName = lastStringInPath(str); 35 | assert(fileName.compare("File.cc") == 0); 36 | } 37 | 38 | cerr << "Testing: getPath" << endl; 39 | { 40 | string str = "Path/To/Important/File.cc"; 41 | string filePath = getPath(str); 42 | cerr << filePath << endl; 43 | assert(filePath.compare("Path/To/Important/") == 0); 44 | string str2 = "File.cc"; 45 | string str3 = getPath(str2); 46 | assert(str3.compare("") == 0); 47 | } 48 | 49 | cerr << "Testing: cut_end" << endl; 50 | { 51 | string str = "Important words"; 52 | string var = cut_end(str, 3); 53 | assert(var.compare("Important wo") == 0); 54 | } 55 | 56 | cerr << "Testing: foundStrInSubStr" << endl; 57 | { 58 | string str = "This is my world."; 59 | assert(foundSubStrInStr(str, "my")); 60 | assert(!foundSubStrInStr(str, "nothing")); 61 | 62 | string str2 = 63 | " Alpha occ. eigenvalues -- -10.20023 -10.19942 -10.19578 -10.19497 " 64 | "-0.76368"; 65 | assert(foundSubStrInStr(str2, " Alpha occ. eigenvalues --")); 66 | } 67 | 68 | cerr << "Testing: isAlphabetical" << endl; 69 | { 70 | string str = "This has spaces"; 71 | assert(isAlphabetical(str) == false); 72 | string str2 = "JustLetters"; 73 | assert(isAlphabetical(str2) == true); 74 | string str3 = ""; 75 | assert(isAlphabetical(str3) == false); 76 | } 77 | 78 | cerr << "Testing: grabStrAfterFisrtOccurance" << endl; 79 | { 80 | string str = "Words and Numbers 023D-23 blah"; 81 | string str2 = grabStrAfterFirstOccurance(str, "D"); 82 | assert(str2.compare("-23 blah") == 0); 83 | string str3 = grabStrAfterFirstOccurance(str, "MOM"); 84 | assert(str3.compare("") == 0); 85 | } 86 | 87 | cerr << "Testing: grabStrAfterLastOccurance" << endl; 88 | { 89 | string str = "This.is.a.file.name"; 90 | string str2 = grabStrAfterLastOccurance(str, "."); 91 | assert(str2.compare("name") == 0); 92 | string str3 = "NoExtfilename"; 93 | string str4 = grabStrAfterLastOccurance(str3, "."); 94 | assert(str4.compare("") == 0); 95 | } 96 | 97 | cerr << "Testing: grabStrBeforeFisrtOccurance" << endl; 98 | { 99 | string str = "Words and Numbers 023D-23 blah"; 100 | string str2 = grabStrBeforeFirstOccurance(str, "D"); 101 | assert(str2.compare("Words and Numbers 023") == 0); 102 | string str3 = grabStrBeforeFirstOccurance(str, "DADA"); 103 | assert(str3.compare(str) == 0); 104 | } 105 | 106 | return 0; 107 | } 108 | -------------------------------------------------------------------------------- /src/tests/testfile.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JoshuaSBrown/QC_Tools/52436c1f1aabfdaa92086657fd50cb32270f9056/src/tests/testfile.log -------------------------------------------------------------------------------- /src/tests/testfile.pun: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JoshuaSBrown/QC_Tools/52436c1f1aabfdaa92086657fd50cb32270f9056/src/tests/testfile.pun -------------------------------------------------------------------------------- /src/tools/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "../libcatnip/io/argumentparser.hpp" 16 | #include "../libcatnip/io/file_readers/logreader.hpp" 17 | #include "../libcatnip/io/file_readers/punreader.hpp" 18 | #include "../libcatnip/io/io.hpp" 19 | #include "../libcatnip/log.hpp" 20 | #include "../libcatnip/matrix.hpp" 21 | #include "../libcatnip/parameters.hpp" 22 | #include "../libcatnip/qc_functions.hpp" 23 | 24 | #include "../libcatnip/calcJconfig.hpp" 25 | 26 | using namespace catnip; 27 | using namespace std; 28 | 29 | int main(int argc, const char *argv[]) { 30 | cout << endl; 31 | cout << "Running calc_J VERSION " << calcJ_VERSION_MAJOR << "."; 32 | cout << calcJ_VERSION_MINOR << endl; 33 | 34 | string line; 35 | LOG("Preparing parser", 1); 36 | auto ArgPars = prepareParser(); 37 | LOG("Parsing arguments", 1); 38 | ArgPars->parse(argv, argc); 39 | LOG("Preparing parameter object", 1); 40 | auto par = prepareParameters(ArgPars); 41 | 42 | cout << "log file for first monomer is: " + par->getLog1() + '\n'; 43 | cout << "log file for second monomer is: " + par->getLog2() + '\n'; 44 | cout << "log file for dimer is: " + par->getLogP() + '\n'; 45 | cout << "pun file for the first monomer is: " + par->getPun1() + '\n'; 46 | cout << "pun file for the second monomer is: " + par->getPun2() + '\n'; 47 | cout << "pun file for the dimer is: " + par->getPunP() + '\n'; 48 | 49 | // Open the .pun file find the total number of molecular orbitals 50 | 51 | LOG("Reading pun files", 1); 52 | LOG("Reading pun file: " + par->getPunP(), 2); 53 | PunReader pr_P(par->getPunP()); 54 | pr_P.read(); 55 | LOG("Reading pun file: " + par->getPun1(), 2); 56 | PunReader pr_1(par->getPun1()); 57 | pr_1.read(); 58 | LOG("Reading pun file: " + par->getPun2(), 2); 59 | PunReader pr_2(par->getPun2()); 60 | pr_2.read(); 61 | 62 | LOG("Reading log files", 1); 63 | LOG("Reading log file: " + par->getLogP(), 2); 64 | LogReader lr_P(par->getLogP()); 65 | lr_P.read(); 66 | LOG("Reading log file: " + par->getLog1(), 2); 67 | LogReader lr_1(par->getLog1()); 68 | lr_1.read(); 69 | LOG("Reading log file: " + par->getLog2(), 2); 70 | LogReader lr_2(par->getLog2()); 71 | lr_2.read(); 72 | // Load in general coefficients 73 | 74 | // If there are only alpha orbitals then we can assume that restricted HF 75 | // was used 76 | 77 | // No need to worry about beta orbitals 78 | 79 | { 80 | Matrix *mat_S = lr_P.getOverlapMatrix(); 81 | 82 | Matrix *mat_P_Coef = pr_P.getCoefsMatrix(par->getSpinP()); 83 | auto vec_P_OE = lr_P.getOE(par->getSpinP()); 84 | Matrix *mat_P_OE = new Matrix(vec_P_OE); 85 | 86 | int HOMO1 = lr_1.getHOMOLevel(par->getSpin1()); 87 | LOG("Getting " + par->getSpin1() + " of monomer 1", 2); 88 | Matrix *mat_1_Coef = pr_1.getCoefsMatrix(par->getSpin1()); 89 | auto vec_1_OE = lr_1.getOE(par->getSpin1()); 90 | Matrix *mat_1_OE = new Matrix(vec_1_OE); 91 | 92 | int HOMO2 = lr_2.getHOMOLevel(par->getSpin2()); 93 | LOG("Getting " + par->getSpin2() + " of monomer 2", 2); 94 | Matrix *mat_2_Coef = pr_2.getCoefsMatrix(par->getSpin2()); 95 | auto vec_2_OE = lr_2.getOE(par->getSpin2()); 96 | Matrix *mat_2_OE = new Matrix(vec_2_OE); 97 | 98 | // Unscramble dimer coef and energies first need to see how the dimer 99 | // and monomer coefficients line up. To determine how the ceofficients 100 | // line up we will first look at how the atoms appear in each of the 101 | // .gjf files. We will also check to see how many coefficients are 102 | // assocaited with each of the atoms by checking the .log files. Given 103 | // the position of the atoms in the monomer unit and the positions of 104 | // the atoms in the dimer we can determine how the coefficients need 105 | // to be rearranged. 106 | auto coord_P = lr_P.getCoords(); 107 | auto coord_1 = lr_1.getCoords(); 108 | auto coord_2 = lr_2.getCoords(); 109 | 110 | // Convert coords to matrices 111 | Matrix coord_P_mat(coord_P); 112 | Matrix coord_1_mat(coord_1); 113 | Matrix coord_2_mat(coord_2); 114 | 115 | auto basis_P = lr_P.getBasisFuncCount(); 116 | auto basis_1 = lr_1.getBasisFuncCount(); 117 | auto basis_2 = lr_2.getBasisFuncCount(); 118 | 119 | int MO1 = mat_1_OE->get_rows(); 120 | int MO2 = mat_2_OE->get_rows(); 121 | 122 | pair Orbs1 = {MO1, HOMO1}; 123 | pair Orbs2 = {MO2, HOMO2}; 124 | 125 | LOG("Creating transfercomplex", 1); 126 | TransferComplex TC(mat_1_Coef, mat_2_Coef, mat_P_Coef, Orbs1, Orbs2, mat_S, 127 | mat_P_OE, par->getCounterPoise()); 128 | 129 | // Set the transfer complex to counterpoise if it is the case. 130 | 131 | // If the basis function search returns 0 for any of the components then 132 | // we cannot automatically determine what the transfer integral is 133 | if (basis_1.size() != 0 && basis_2.size() != 0 && basis_P.size() != 0) { 134 | LOG("Unscrambling matrices", 1); 135 | TC.unscramble(coord_1_mat, coord_2_mat, coord_P_mat, basis_P, basis_2); 136 | } 137 | 138 | cout << endl; 139 | cout << "Dimer Spin " << par->getSpinP() << endl; 140 | 141 | cout << "Monomer 1 Spin " << par->getSpin1() << " "; 142 | if (par->getOrbNum1() == 0) { 143 | cout << "Orbital " << par->getOrbType1() << endl; 144 | } else if (par->getOrbNum1() > 0) { 145 | cout << "Orbital " << par->getOrbType1(); 146 | cout << "+" << par->getOrbNum1() << endl; 147 | } else { 148 | cout << "Orbital " << par->getOrbType1(); 149 | cout << par->getOrbNum1() << endl; 150 | } 151 | 152 | cout << "Monomer 2 Spin " << par->getSpin2() << " "; 153 | if (par->getOrbNum2() == 0) { 154 | cout << "Orbital " << par->getOrbType2() << endl; 155 | } else if (par->getOrbNum2() > 0) { 156 | cout << "Orbital " << par->getOrbType2(); 157 | cout << "+" << par->getOrbNum2() << endl; 158 | } else { 159 | cout << "Orbital " << par->getOrbType2(); 160 | cout << par->getOrbNum2() << endl; 161 | } 162 | 163 | map orbitaltypes; 164 | map orbitalnums; 165 | orbitaltypes["mon1"] = par->getOrbType1(); 166 | orbitaltypes["mon2"] = par->getOrbType2(); 167 | orbitalnums["mon1"] = par->getOrbNum1(); 168 | orbitalnums["mon2"] = par->getOrbNum2(); 169 | 170 | LOG("Calculating transfer integral", 1); 171 | TC.calcJ(orbitaltypes, orbitalnums); 172 | } 173 | 174 | return 0; 175 | } 176 | --------------------------------------------------------------------------------