Skip to content

Add eigen dependency #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
34ea81b
Removed matrix files
JoshuaSBrown Apr 27, 2019
e7f1564
Switched file readers to using eigen matrices as opposed to local mat…
JoshuaSBrown Apr 27, 2019
094177e
Switched to eigen matrices in main
JoshuaSBrown Apr 27, 2019
47257b0
Removed matrix tests
JoshuaSBrown Apr 28, 2019
0ad1283
Updated main and qc_functions to use Eigen matrix and vector classes
JoshuaSBrown Apr 28, 2019
f99db21
Added matrix helper functions
JoshuaSBrown Apr 28, 2019
e77984a
Updated tests and qc_functions.cpp
JoshuaSBrown Apr 28, 2019
8239b14
Fixing compiler errors
JoshuaSBrown Apr 29, 2019
23f393f
First successful compile
JoshuaSBrown Apr 29, 2019
47e3078
Add testing to log reader
JoshuaSBrown Apr 30, 2019
3bcf329
Added test for overlap
JoshuaSBrown Apr 30, 2019
9d70476
Added overlap test
JoshuaSBrown Apr 30, 2019
c84823d
checkpoint
JoshuaSBrown Apr 30, 2019
54b55e5
Fixed error that was introduced
JoshuaSBrown Apr 30, 2019
e13daaa
Updated print statment and fixed error
JoshuaSBrown May 1, 2019
eae3804
Updated version
JoshuaSBrown May 1, 2019
c9ba317
Added switch for printing all transfer integrals
JoshuaSBrown May 1, 2019
7797dae
Add eigen as a package to ci
JoshuaSBrown May 1, 2019
9cbfb04
Added eigen to ci development stage
JoshuaSBrown May 1, 2019
ab1c42b
Corrected formatting of print all
JoshuaSBrown May 1, 2019
c71c9ae
UPdate eigen install in travis
JoshuaSBrown May 2, 2019
43745c9
fixing eigen includes
JoshuaSBrown May 3, 2019
71238ec
Fix cmake eigen call
JoshuaSBrown May 3, 2019
4188483
Fixed problem when reading overlap matrix with only a few coefficients
JoshuaSBrown May 14, 2019
e97a27d
Fixed error in script with J and, dimensions of matrices
JoshuaSBrown May 22, 2019
95fd3bd
fixed script
JoshuaSBrown May 22, 2019
c458d90
Temporary changes
JoshuaSBrown May 23, 2019
fcc12f2
Removed unused function
JoshuaSBrown May 23, 2019
6a801be
Fixed error, removed cout lines unneeded, added extra test
JoshuaSBrown May 23, 2019
1d8fcc5
Cleanup comments
JoshuaSBrown May 30, 2019
84ec750
Merge branch 'master' into add-eigen-dependency
JoshuaSBrown Jul 12, 2022
1c68110
Update CMakeLists.txt
JoshuaSBrown Jul 12, 2022
eea60fb
Update sonarcloud.yml
JoshuaSBrown Jul 12, 2022
336f378
Change name of step to install eigen
JoshuaSBrown Jul 12, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ jobs:
curl -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip ${{ env.BUILD_WRAPPER_DOWNLOAD_URL }}
unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/
echo "$HOME/.sonar/build-wrapper-linux-x86" >> $GITHUB_PATH
- name: Install eigen
run: sudo apt-get install -y libeigen3-dev
- name: Run build-wrapper
run: |
mkdir build
Expand Down
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ dist: xenial
addons:
apt:
update: true
packages: libeigen3-dev

language: cpp

Expand All @@ -17,6 +18,7 @@ jobs:
compiler: gcc
script: ./scripts/deploy.bash
apt:
packages: libeigen3-dev
packages: gcov
packages: lcov

Expand Down
10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required (VERSION 2.8)
cmake_minimum_required (VERSION 3.12)
project (calc_J)

##############################################################################
Expand All @@ -12,8 +12,8 @@ option(CODE_COVERAGE "Enable coverage reporting" OFF)
##############################################################################
# Defining settings
##############################################################################
set(calcJ_VERSION_MAJOR 1 )
set(calcJ_VERSION_MINOR 9 )
set(calcJ_VERSION_MAJOR 2 )
set(calcJ_VERSION_MINOR 0 )
set(calcJ_YEAR_PUBLISHED 2018 )
set(calcJ_AUTHOR_SURNAME "\"Brown\"" )
set(calcJ_AUTHOR_INITIALS "\"J. S.\"" )
Expand Down Expand Up @@ -42,6 +42,10 @@ configure_file(
# Find bash it is important for testing using scripts
find_program (BASH_PROGRAM bash)
find_library (GCOV gcov)
#find_package (Eigen3 3.3 REQUIRED NO_MODULE)
#if (TARGET Eigen3::Eigen)
# message("-- Eigen found")
#endif(TARGET Eigen3::Eigen)
add_definitions(-DLOG_LEVEL=${LOG_LEVEL})

##############################################################################
Expand Down
3 changes: 1 addition & 2 deletions src/libcatnip/io/file_readers/filereader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ void FileReader::read() {
close();
}

// Private member functions

void FileReader::open() {
if (!fileExist_()) {
throw invalid_argument("File " + fileName_ + " does not exist.");
Expand All @@ -39,6 +37,7 @@ void FileReader::close() {
fileOpen_ = false;
}

// Private member functions
void FileReader::registerSections_() { checkSections_(); }

// Basically check that for a given tag both a section reader
Expand Down
2 changes: 1 addition & 1 deletion src/libcatnip/io/file_readers/filereader.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

#pragma once
#ifndef _CATNIP_FILEREADER_HPP_
#define _CATNIP_FILEREADER_HPP_

Expand Down
42 changes: 19 additions & 23 deletions src/libcatnip/io/file_readers/logreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <sstream>
#include <string>

#include <eigen3/Eigen/Core>
#include "../../log.hpp"
#include "../../string_support.hpp"
#include "logreader.hpp"
Expand Down Expand Up @@ -126,6 +127,7 @@ void LogReader::AOFunctionSectionReader(void *ptr) {
while (!iss.eof()) {
string Tot_Alpha_Beta_Spin;
iss >> Tot_Alpha_Beta_Spin;
trim(Tot_Alpha_Beta_Spin);
orbVals.push_back(stod(Tot_Alpha_Beta_Spin));
}
LR_ptr->orb_[make_pair(atom_num, elemType)][orbType] = orbVals;
Expand Down Expand Up @@ -165,7 +167,6 @@ void LogReader::AOFunctionSectionReader(void *ptr) {
}

++atom_num;
// getline(LR_ptr->fid_,line);
if (foundSubStrInStr(line, end_pattern)) {
sectionEnd = true;
}
Expand Down Expand Up @@ -194,9 +195,12 @@ void LogReader::OverlapSectionReader(void *ptr) {
getline(LR_ptr->fid_, line);
istringstream iss(line);
iss >> countC;
if( line.find("Kinetic")!=string::npos){
break;
}
int countCint = stoi(countC);
if (countCint != (countCoef + 1)) {
endFirstSection = true;
break;
} else {
++countCoef;
vector<double> row;
Expand All @@ -214,20 +218,14 @@ void LogReader::OverlapSectionReader(void *ptr) {
}

// Create a matrix and place all the current values in there
Matrix *mat_S = new Matrix(countCoef, countCoef);

Eigen::MatrixXd matrix_S(countCoef,countCoef);

for (size_t row_ind = 0; row_ind < first_coefs.size(); ++row_ind) {
vector<double> row = first_coefs.at(row_ind);
size_t col_ind = 1;
for (auto val : row) {
mat_S->set_elem(val, row_ind + 1, col_ind);
// Because diagonally symetric
if (row_ind + 1 != col_ind) {
mat_S->set_elem(val, col_ind, row_ind + 1);
}
++col_ind;
}
Eigen::Map<Eigen::RowVectorXd> eigen_row((first_coefs.at(row_ind).data()),first_coefs.at(row_ind).size());
matrix_S.block(row_ind,0,1,eigen_row.size()) = eigen_row;
matrix_S.block(0,row_ind,eigen_row.size(),1) = eigen_row.transpose();
}

int sectionReads = countCoef / 5;
if (countCoef % 5 > 0) {
++sectionReads;
Expand All @@ -243,19 +241,16 @@ void LogReader::OverlapSectionReader(void *ptr) {
istringstream iss(line);
string dummy;
iss >> dummy;
int localCoefCount = 1;
int localCoefCount = 0;
while (!iss.eof()) {
string s_coef;
iss >> s_coef;
string val = grabStrBeforeFirstOccurance(s_coef, "D");
string expon = grabStrAfterFirstOccurance(s_coef, "D");
double value = stod(val) * pow(10.0, stod(expon));
mat_S->set_elem(value, sectionCoef + 1,
currentSectionStart + localCoefCount);
if ((sectionCoef + 1) != (currentSectionStart + localCoefCount)) {

mat_S->set_elem(value, currentSectionStart + localCoefCount,
sectionCoef + 1);
matrix_S(sectionCoef,currentSectionStart + localCoefCount) = value;
if ((sectionCoef) != (currentSectionStart + localCoefCount)) {
matrix_S(currentSectionStart + localCoefCount,sectionCoef) = value;
}
++localCoefCount;
}
Expand All @@ -265,7 +260,8 @@ void LogReader::OverlapSectionReader(void *ptr) {
currentSectionStart += 5;
getline(LR_ptr->fid_, line);
}
LR_ptr->S_ = mat_S;

LR_ptr->S_ = matrix_S;
LOG("Success reading Overlap coefficients from .log file", 2);
return;
}
Expand All @@ -291,7 +287,7 @@ void LogReader::ReadOrbEnergies(const string &orb_type) {

auto vec_str = splitStEnergies(line);
for (size_t inc = 4; inc < vec_str.size(); inc++) {
OREnergies[orb_type].push_back((double)atof(vec_str.at(inc).c_str()));
OREnergies[orb_type].push_back(stod(vec_str.at(inc)));
if (occFound) homoLevel[orb_type]++;
}
} else {
Expand Down
16 changes: 10 additions & 6 deletions src/libcatnip/io/file_readers/logreader.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@

#pragma once
#ifndef _CATNIP_LOGREADER_HPP_
#define _CATNIP_LOGREADER_HPP_

#include <map>
#include <string>
#include <vector>

#include "../../matrix.hpp"
#include "filereader.hpp"

#include <eigen3/Eigen/Core>
// Gaussian log file reader

namespace catnip {
Expand All @@ -18,9 +21,9 @@ class LogReader : public FileReader {
public:
explicit LogReader(const std::string &str);
orb_cont getOrbitalInfo() const { return orb_; }
Matrix *getOverlapMatrix() const { return S_; }
std::vector<double> getOE(const std::string &orb_type) const {
return OREnergies.at(orb_type);
Eigen::MatrixXd getOverlapMatrix() const { return S_; }
Eigen::VectorXd getOE(const std::string &orb_type) {
return Eigen::Map<Eigen::VectorXd>(OREnergies.at(orb_type).data(),OREnergies.at(orb_type).size());
}
int getHOMOLevel(const std::string &orb_type) const {
return homoLevel.at(orb_type);
Expand Down Expand Up @@ -48,7 +51,8 @@ class LogReader : public FileReader {
std::map<std::string, int> homoLevel;
orb_cont orb_;
// Overlap matrix
Matrix *S_;
//Matrix *S_;
Eigen::MatrixXd S_;
std::map<std::string, std::vector<double>> OREnergies;

std::vector<std::vector<double>> xyz;
Expand Down
15 changes: 11 additions & 4 deletions src/libcatnip/io/file_readers/punreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
#include <fstream>
#include <iostream>
#include <map>
#include <memory>
#include <sstream>
#include <string>

#include "../../log.hpp"
#include "../../string_support.hpp"
#include "punreader.hpp"

#include <eigen3/Eigen/Core>

using namespace catnip;
using namespace std;

Expand All @@ -29,12 +32,12 @@ void PunReader::registerSections_() {
FileReader::registerSections_();
}

Matrix *PunReader::getCoefsMatrix(const string &orb_type) {
Eigen::MatrixXd PunReader::getCoefsMatrix(const string &orb_type) {
if (coefs.count(orb_type) != 1) {
throw invalid_argument("Coefficients for spin " + orb_type +
" were not found");
}
return coefs[orb_type];
return *(coefs[orb_type]);
}

void PunReader::validFileName_() {
Expand Down Expand Up @@ -93,8 +96,12 @@ void PunReader::ReadCoef(const string &orb_type) {
allCoefsRead = !(foundSubStrInStr(line, orb_type));
}

Matrix *Coefs = new Matrix(v_vec);
coefs[orb_type] = Coefs;
coefs[orb_type] = unique_ptr<Eigen::MatrixXd>(new Eigen::MatrixXd(v_vec.size(),v_vec.at(0).size()));
for( size_t row_ind=0; row_ind<v_vec.size();++row_ind){
Eigen::Map<Eigen::VectorXd> eigen_vec(v_vec.at(row_ind).data(),v_vec.at(row_ind).size());
coefs[orb_type]->row(row_ind) = eigen_vec;
}

LOG("Success reading atomic orbital coefficients from .pun file.", 2);
}

Expand Down
9 changes: 5 additions & 4 deletions src/libcatnip/io/file_readers/punreader.hpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@

#pragma once
#ifndef _CATNIP_PUNREADER_HPP_
#define _CATNIP_PUNREADER_HPP_

#include <memory>
#include <vector>

#include "../../matrix.hpp"
#include "filereader.hpp"
#include <eigen3/Eigen/Dense>
// Gaussian fort.7/.pun file reader
namespace catnip {

class PunReader : public FileReader {
public:
explicit PunReader(const std::string &str);
Matrix *getCoefsMatrix(const std::string &orb_type);
Eigen::MatrixXd getCoefsMatrix(const std::string &orb_type);
bool restrictedShell() { return coefs.size() == 1; }

private:
Expand All @@ -25,7 +26,7 @@ class PunReader : public FileReader {
void ReadCoef(const std::string &orb_type);
std::vector<double> readGausCoefLine(const std::string &line);

std::map<std::string, Matrix *> coefs;
std::map<std::string, std::unique_ptr<Eigen::MatrixXd>> coefs;
};

} // namespace catnip
Expand Down
17 changes: 17 additions & 0 deletions src/libcatnip/io/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ unique_ptr<ArgumentParser> prepareParser(void) {
desc = "Print the version";
flag18.push_back(desc);

vector<string> flag19;
flag19.push_back("--all");
flag19.push_back("-a");
desc = "Print all transfer integrals, in matrix form";
flag19.push_back(desc);

set<vector<string>> flags;
flags.insert(flag1);
flags.insert(flag2);
Expand All @@ -184,6 +190,7 @@ unique_ptr<ArgumentParser> prepareParser(void) {
flags.insert(flag16);
flags.insert(flag17);
flags.insert(flag18);
flags.insert(flag19);

unique_ptr<ArgumentParser> ArgPars(new ArgumentParser(flags));

Expand Down Expand Up @@ -303,6 +310,15 @@ unique_ptr<ArgumentParser> prepareParser(void) {
ArgPars->setFlagDefaultValue("--counter_poise", "OFF");
}

// Set argument for allowing printing of all transfer integrals
{
ArgPars->setFlagArgOpt("--all", "ARGUMENT_SWITCH",
"PROPERTY_SWITCH", "DEFAULT", "OFF");

// By default the flag counter poise is turned off
ArgPars->setFlagDefaultValue("--all", "OFF");
}

{
ArgPars->setFlagArgOpt("--citation", "ARGUMENT_SWITCH", "PROPERTY_SWITCH",
"DEFAULT", "OFF");
Expand Down Expand Up @@ -424,6 +440,7 @@ unique_ptr<Parameters> prepareParameters(unique_ptr<ArgumentParser>& ArgParse) {

// Determine if we are doing a counterpoise calculation
Par->setCounterPoise(ArgParse->getInt("--counter_poise"));
Par->setPrintSwitch(ArgParse->getInt("--all"));
Par->setCitation(ArgParse->getInt("--citation"));
// Read Orbital related flags
{
Expand Down
1 change: 0 additions & 1 deletion src/libcatnip/io/io.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#ifndef _CATNIP_IO_HPP
#define _CATNIP_IO_HPP
#include "../matrix.hpp"
#include "../parameters.hpp"
#include "argumentparser.hpp"
#include <map>
Expand Down
Loading