├── examples ├── he.in ├── ch.in ├── co.in ├── n2.in ├── h2.in ├── h2_sto6g.in ├── h2o.in ├── ch4.in ├── nh3.in ├── ethane.in └── benzene.in ├── src ├── test │ ├── molecules │ │ ├── h2.in │ │ ├── ch4.in │ │ └── benzene.in │ ├── test_molecule.h │ ├── unittest.cpp │ ├── test_molecule.cpp │ └── CMakeLists.txt ├── config.h.in ├── version.h ├── canorg.h ├── kinetic.h ├── matfunc.h ├── eigsym.h ├── overlap.h ├── clock.h ├── clock.cpp ├── vec3.cpp ├── cgf.h ├── cgf.cpp ├── vec3.h ├── output.h ├── strfunc.h ├── version.cpp ├── gamma.h ├── gto.h ├── nuclear.h ├── func.h ├── canorg.cpp ├── molecule.h ├── readfile.h ├── matfunc.cpp ├── eigsym.cpp ├── gto.cpp ├── basis.h ├── factorial.h ├── atom.h ├── main.cpp ├── readfile.cpp ├── eispack.h ├── kinetic.cpp ├── func.cpp ├── overlap.cpp ├── repulsion.h ├── CMakeLists.txt ├── basis.cpp ├── cmake │ └── modules │ │ └── FindCPPUNIT.cmake ├── nuclear.cpp ├── hf.h ├── molecule.cpp ├── strfunc.cpp ├── atom.cpp ├── gamma.cpp ├── repulsion.cpp ├── output.cpp ├── basis-sto3g.cpp ├── matrix.h ├── hf.cpp └── basis-sto6g.cpp ├── .gitignore ├── .editorconfig ├── .github └── workflows │ └── build.yml ├── README.md └── CONTRIBUTING.md /examples/he.in: -------------------------------------------------------------------------------- 1 | basis = sto-3g 2 | charge = 0 3 | atoms = 1 4 | units = bohr 5 | He 0 0 0 6 | -------------------------------------------------------------------------------- /examples/ch.in: -------------------------------------------------------------------------------- 1 | basis = sto-3g 2 | charge = 0 3 | atoms = 2 4 | units = bohr 5 | C 0 0 0.000 6 | H 0 0 2 7 | -------------------------------------------------------------------------------- /examples/co.in: -------------------------------------------------------------------------------- 1 | basis = sto-6g 2 | charge = 0 3 | atoms = 2 4 | units = angstrom 5 | C 0 0 0.000 6 | O 0 0 1.12 7 | -------------------------------------------------------------------------------- /examples/n2.in: -------------------------------------------------------------------------------- 1 | basis = sto-3g 2 | charge = 0 3 | atoms = 2 4 | units = bohr 5 | N 0.0000 0.0000 0.0000 6 | N 2.147932 0.0000 0.0000 7 | -------------------------------------------------------------------------------- /examples/h2.in: -------------------------------------------------------------------------------- 1 | basis = sto-3g 2 | charge = 0 3 | atoms = 2 4 | units = bohr 5 | H -0.70 0.5860 0.0000 6 | H 0.700 0.5860 0.0000 7 | -------------------------------------------------------------------------------- /examples/h2_sto6g.in: -------------------------------------------------------------------------------- 1 | basis = sto-6g 2 | charge = 0 3 | atoms = 2 4 | units = bohr 5 | H -0.70 0.5860 0.0000 6 | H 0.700 0.5860 0.0000 7 | -------------------------------------------------------------------------------- /src/test/molecules/h2.in: -------------------------------------------------------------------------------- 1 | basis = sto-3g 2 | charge = 0 3 | atoms = 2 4 | units = bohr 5 | H -0.70 0.5860 0.0000 6 | H 0.700 0.5860 0.0000 7 | -------------------------------------------------------------------------------- /examples/h2o.in: -------------------------------------------------------------------------------- 1 | basis = sto-6g 2 | charge = 0 3 | atoms = 3 4 | units = bohr 5 | O 0.0000 0.0000 0.0000 6 | H 0.7570 0.5860 0.0000 7 | H -0.757 0.5860 0.0000 8 | -------------------------------------------------------------------------------- /examples/ch4.in: -------------------------------------------------------------------------------- 1 | basis = sto-3g 2 | charge = 0 3 | atoms = 5 4 | units = bohr 5 | C -0.213 0.154 0.000 6 | H -0.213 2.304 0.000 7 | H 1.814 -0.563 0.000 8 | H -1.226 -0.563 1.755 9 | H -1.226 -0.563 -1.755 10 | -------------------------------------------------------------------------------- /src/test/molecules/ch4.in: -------------------------------------------------------------------------------- 1 | basis = sto-3g 2 | charge = 0 3 | atoms = 5 4 | units = bohr 5 | C -0.213 0.154 0.000 6 | H -0.213 2.304 0.000 7 | H 1.814 -0.563 0.000 8 | H -1.226 -0.563 1.755 9 | H -1.226 -0.563 -1.755 10 | -------------------------------------------------------------------------------- /examples/nh3.in: -------------------------------------------------------------------------------- 1 | basis = sto-3g 2 | charge = 0 3 | atoms = 4 4 | units = angstrom 5 | N 0.000000 0.000000 0.000000 6 | H 0.000000 0.000000 1.010001 7 | H 0.952175 0.000000 -0.336846 8 | H -0.476467 -0.824388 -0.336846 9 | -------------------------------------------------------------------------------- /examples/ethane.in: -------------------------------------------------------------------------------- 1 | basis = sto-3g 2 | charge = 0 3 | atoms = 8 4 | units = angstrom 5 | H 0.0998334 0.995004 -0.6 6 | H 0.911616 0.411044 1.6 7 | H 0.811782 -0.58396 -0.6 8 | H -0.0998334 -0.995004 1.6 9 | H -0.911616 -0.411044 -0.6 10 | H -0.811782 0.583961 1.6 11 | C 0 0 0 12 | C 0 0 1 13 | -------------------------------------------------------------------------------- /examples/benzene.in: -------------------------------------------------------------------------------- 1 | basis = sto-3g 2 | charge = 0 3 | atoms = 12 4 | units = angstrom 5 | C 0.000 1.396 0.000 6 | C 1.209 0.698 0.000 7 | C 1.209 -0.698 0.000 8 | C 0.000 -1.396 0.000 9 | C -1.209 -0.698 0.000 10 | C -1.209 0.698 0.000 11 | H 0.000 2.479 0.000 12 | H 2.147 1.240 0.000 13 | H 2.147 -1.240 0.000 14 | H 0.000 -2.479 0.000 15 | H -2.147 -1.240 0.000 16 | H -2.147 1.240 0.000 17 | -------------------------------------------------------------------------------- /src/test/molecules/benzene.in: -------------------------------------------------------------------------------- 1 | basis = sto-6g 2 | charge = 0 3 | atoms = 12 4 | units = angstrom 5 | C 0.000 1.396 0.000 6 | C 1.209 0.698 0.000 7 | C 1.209 -0.698 0.000 8 | C 0.000 -1.396 0.000 9 | C -1.209 -0.698 0.000 10 | C -1.209 0.698 0.000 11 | H 0.000 2.479 0.000 12 | H 2.147 1.240 0.000 13 | H 2.147 -1.240 0.000 14 | H 0.000 -2.479 0.000 15 | H -2.147 -1.240 0.000 16 | H -2.147 1.240 0.000 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.Po 6 | 7 | # Compiled Dynamic libraries 8 | *.so 9 | 10 | # Compiled Static libraries 11 | *.lai 12 | *.la 13 | *.a 14 | 15 | # Output files from the program 16 | *.out 17 | 18 | # Autotools 19 | src/.deps 20 | 21 | # Executable 22 | hfcxx 23 | 24 | # Temporary files 25 | *.cpp~ 26 | *.ac~ 27 | *.in~ 28 | *.h~ 29 | *.am~ 30 | 31 | compile 32 | test-driver 33 | build/* 34 | !empty 35 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | ; This file is for unifying the coding style for different editors and IDEs. 2 | ; More information at http://editorconfig.org 3 | 4 | root = true 5 | 6 | [*] 7 | indent_style = space 8 | end_of_line = lf 9 | insert_final_newline = true 10 | trim_trailing_whitespace = true 11 | indent_style = space 12 | indent_size = 4 13 | 14 | [Makefile] 15 | indent_style = tab 16 | end_of_line = lf 17 | insert_final_newline = true 18 | trim_trailing_whitespace = true 19 | indent_style = tab 20 | indent_size = 4 21 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: build 2 | 3 | on: 4 | push: 5 | branches: [ "master", "develop" ] 6 | pull_request: 7 | branches: [ "master", "develop" ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v3 16 | - name: Install dependencies 17 | run: sudo apt install -y build-essential cmake libcppunit-dev 18 | - name: Configure CMake 19 | run: mkdir build && cd build && cmake ../src 20 | - name: Building and testing 21 | run: cd build && make -j3 && make test 22 | -------------------------------------------------------------------------------- /src/config.h.in: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * config.h -- This file is part of Dosplotter. * 3 | * * 4 | * Copyright (C) 2017, Ivo Filot * 5 | * * 6 | * Dosplotter is free software: you can redistribute it and/or modify * 7 | * it under the terms of the GNU General Public License as published * 8 | * by the Free Software Foundation, either version 3 of the License, * 9 | * or (at your option) any later version. * 10 | * * 11 | * Dosplotter is distributed in the hope that it will be useful, * 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 13 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 14 | * See the GNU General Public License for more details. * 15 | * * 16 | * You should have received a copy of the GNU General Public License * 17 | * along with this program. If not, see http://www.gnu.org/licenses/. * 18 | * * 19 | **************************************************************************/ 20 | 21 | #ifndef _CONFIG_H 22 | #define _CONFIG_H 23 | 24 | #cmakedefine HAS_OPENMP 25 | 26 | #endif //_CONFIG_H 27 | -------------------------------------------------------------------------------- /src/version.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * version.h -- This file is part of HFCXX. * 3 | * * 4 | * Copyright (C) 2012, Ivo Filot * 5 | * * 6 | * HFCXX is free software: * 7 | * you can redistribute it and/or modify it under the terms of the * 8 | * GNU General Public License as published by the Free Software * 9 | * Foundation, either version 3 of the License, or (at your option) * 10 | * any later version. * 11 | * * 12 | * HFCXX is distributed in the hope that it will be useful, * 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | * See the GNU General Public License for more details. * 16 | * * 17 | * You should have received a copy of the GNU General Public License * 18 | * along with this program. If not, see http://www.gnu.org/licenses/. * 19 | * * 20 | **************************************************************************/ 21 | 22 | #ifndef _VERSION_H 23 | #define _VERSION_H 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #define PACKAGE_VERSION "1.5.0" 30 | 31 | std::string version(); 32 | 33 | #endif //_VERSION_H 34 | -------------------------------------------------------------------------------- /src/canorg.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * canorg.h -- This file is part of HFCXX. * 3 | * * 4 | * Copyright (C) 2012, Ivo Filot * 5 | * * 6 | * HFCXX is free software: * 7 | * you can redistribute it and/or modify it under the terms of the * 8 | * GNU General Public License as published by the Free Software * 9 | * Foundation, either version 3 of the License, or (at your option) * 10 | * any later version. * 11 | * * 12 | * HFCXX is distributed in the hope that it will be useful, * 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | * See the GNU General Public License for more details. * 16 | * * 17 | * You should have received a copy of the GNU General Public License * 18 | * along with this program. If not, see http://www.gnu.org/licenses/. * 19 | * * 20 | **************************************************************************/ 21 | 22 | #ifndef _CANORG_H 23 | #define _CANORG_H 24 | 25 | #include "matrix.h" 26 | #include "matfunc.h" 27 | #include "eigsym.h" 28 | 29 | Xmatrix canorg(const Smatrix &S); 30 | MatDoub transpose(MatDoub &a); 31 | 32 | #endif //_CANORG_H 33 | -------------------------------------------------------------------------------- /src/kinetic.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * kinetic.h -- This file is part of HFCXX. * 3 | * * 4 | * Copyright (C) 2012, Ivo Filot * 5 | * * 6 | * HFCXX is free software: * 7 | * you can redistribute it and/or modify it under the terms of the * 8 | * GNU General Public License as published by the Free Software * 9 | * Foundation, either version 3 of the License, or (at your option) * 10 | * any later version. * 11 | * * 12 | * HFCXX is distributed in the hope that it will be useful, * 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | * See the GNU General Public License for more details. * 16 | * * 17 | * You should have received a copy of the GNU General Public License * 18 | * along with this program. If not, see http://www.gnu.org/licenses/. * 19 | * * 20 | **************************************************************************/ 21 | 22 | #ifndef _KINETIC_H 23 | #define _KINETIC_H 24 | 25 | #include "gto.h" 26 | #include "cgf.h" 27 | #include "overlap.h" 28 | 29 | double cgf_kinetic(CGF &cgf1, CGF &cgf2); 30 | double gto_kinetic(GTO >o1, GTO >o2); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/matfunc.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * matfunc.h -- This file is part of HFCXX. * 3 | * * 4 | * Copyright (C) 2012, Ivo Filot * 5 | * * 6 | * HFCXX is free software: * 7 | * you can redistribute it and/or modify it under the terms of the * 8 | * GNU General Public License as published by the Free Software * 9 | * Foundation, either version 3 of the License, or (at your option) * 10 | * any later version. * 11 | * * 12 | * HFCXX is distributed in the hope that it will be useful, * 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | * See the GNU General Public License for more details. * 16 | * * 17 | * You should have received a copy of the GNU General Public License * 18 | * along with this program. If not, see http://www.gnu.org/licenses/. * 19 | * * 20 | **************************************************************************/ 21 | 22 | #ifndef _MATPROD_H 23 | #define _MATPROD_H 24 | 25 | #include "matrix.h" 26 | 27 | MatDoub matprod(MatDoub &a, MatDoub &b); 28 | MatDoub matsum(MatDoub &a, MatDoub &b); 29 | MatDoub trimatprod(MatDoub &a, MatDoub &b, MatDoub &c); 30 | 31 | #endif //_MATPROD_H 32 | -------------------------------------------------------------------------------- /src/eigsym.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * eigsym.h -- This file is part of HFCXX. * 3 | * * 4 | * Copyright (C) 2012, Ivo Filot * 5 | * * 6 | * HFCXX is free software: * 7 | * you can redistribute it and/or modify it under the terms of the * 8 | * GNU General Public License as published by the Free Software * 9 | * Foundation, either version 3 of the License, or (at your option) * 10 | * any later version. * 11 | * * 12 | * HFCXX is distributed in the hope that it will be useful, * 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | * See the GNU General Public License for more details. * 16 | * * 17 | * You should have received a copy of the GNU General Public License * 18 | * along with this program. If not, see http://www.gnu.org/licenses/. * 19 | * * 20 | **************************************************************************/ 21 | 22 | #ifndef _EIGSYM_H 23 | #define _EIGSYM_H 24 | 25 | #include "matrix.h" 26 | #include "vec3.h" 27 | #include "eispack.h" 28 | #include 29 | 30 | class Eigsym{ 31 | public: 32 | Eigsym(); 33 | Eigsym(const MatDoub &A, MatDoub &V, VecDoub &lambda); 34 | void eig(const MatDoub &A, MatDoub &V, VecDoub &lamda); 35 | }; 36 | 37 | #endif //_EIGSYM_H 38 | -------------------------------------------------------------------------------- /src/overlap.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * overlap.h -- This file is part of HFCXX. * 3 | * * 4 | * Copyright (C) 2012, Ivo Filot * 5 | * * 6 | * HFCXX is free software: * 7 | * you can redistribute it and/or modify it under the terms of the * 8 | * GNU General Public License as published by the Free Software * 9 | * Foundation, either version 3 of the License, or (at your option) * 10 | * any later version. * 11 | * * 12 | * HFCXX is distributed in the hope that it will be useful, * 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | * See the GNU General Public License for more details. * 16 | * * 17 | * You should have received a copy of the GNU General Public License * 18 | * along with this program. If not, see http://www.gnu.org/licenses/. * 19 | * * 20 | **************************************************************************/ 21 | 22 | #ifndef _OVERLAP_H 23 | #define _OVERLAP_H 24 | 25 | #include "gto.h" 26 | #include "cgf.h" 27 | #include "func.h" 28 | 29 | double cgf_overlap(CGF &cgf1, CGF &cgf2); 30 | double gto_overlap(GTO >o1, GTO >o2); 31 | double overlap(double alpha1, int l1, int m1, int n1, Vec3 &a, 32 | double alpha2, int l2, int m2, int n2, Vec3 &b); 33 | double overlap_1D(int l1, int l2, double x1, double x2, double gamma); 34 | 35 | #endif //_OVERLAP_H 36 | -------------------------------------------------------------------------------- /src/clock.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * clock.h -- This file is part of HFCXX. * 3 | * * 4 | * Copyright (C) 2012, Ivo Filot * 5 | * * 6 | * HFCXX is free software: * 7 | * you can redistribute it and/or modify it under the terms of the * 8 | * GNU General Public License as published by the Free Software * 9 | * Foundation, either version 3 of the License, or (at your option) * 10 | * any later version. * 11 | * * 12 | * HFCXX is distributed in the hope that it will be useful, * 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | * See the GNU General Public License for more details. * 16 | * * 17 | * You should have received a copy of the GNU General Public License * 18 | * along with this program. If not, see http://www.gnu.org/licenses/. * 19 | * * 20 | **************************************************************************/ 21 | 22 | #ifndef _CLOCK_H 23 | #define _CLOCK_H 24 | 25 | #include 26 | #include 27 | 28 | class Clock{ 29 | private: 30 | struct timeval time1,time2; 31 | long mtime, seconds, useconds; 32 | public: 33 | Clock(); /* default constructor */ 34 | void tic(); /* starts / resets the clock */ 35 | void toc(); /* pauses the clock */ 36 | double passed(); /* returns the time in seconds */ 37 | }; 38 | 39 | #endif //_CLOCK_H 40 | -------------------------------------------------------------------------------- /src/clock.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * clock.cpp -- This file is part of HFCXX. * 3 | * * 4 | * Copyright (C) 2012, Ivo Filot * 5 | * * 6 | * HFCXX is free software: * 7 | * you can redistribute it and/or modify it under the terms of the * 8 | * GNU General Public License as published by the Free Software * 9 | * Foundation, either version 3 of the License, or (at your option) * 10 | * any later version. * 11 | * * 12 | * HFCXX is distributed in the hope that it will be useful, * 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | * See the GNU General Public License for more details. * 16 | * * 17 | * You should have received a copy of the GNU General Public License * 18 | * along with this program. If not, see http://www.gnu.org/licenses/. * 19 | * * 20 | **************************************************************************/ 21 | 22 | #include "clock.h" 23 | 24 | Clock::Clock() { 25 | this->tic(); 26 | } 27 | 28 | void Clock::tic() { 29 | gettimeofday(&time1, NULL); 30 | } 31 | 32 | void Clock::toc() { 33 | gettimeofday(&time2, NULL); 34 | } 35 | 36 | double Clock::passed() { 37 | seconds = time2.tv_sec - time1.tv_sec; 38 | useconds = time2.tv_usec - time1.tv_usec; 39 | mtime = ((seconds) * 1000 + useconds / 1000.0) + 0.5; 40 | 41 | return double(mtime); 42 | } 43 | -------------------------------------------------------------------------------- /src/test/test_molecule.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * Copyright (C) 2023, Ivo Filot * 3 | * * 4 | * HFCXX is free software: * 5 | * you can redistribute it and/or modify it under the terms of the * 6 | * GNU General Public License as published by the Free Software * 7 | * Foundation, either version 3 of the License, or (at your option) * 8 | * any later version. * 9 | * * 10 | * HFCXX is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 12 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 13 | * See the GNU General Public License for more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with this program. If not, see http://www.gnu.org/licenses/. * 17 | * * 18 | **************************************************************************/ 19 | 20 | #ifndef _TEST_MOLECULE 21 | #define _TEST_MOLECULE 22 | 23 | #include 24 | 25 | #include "output.h" 26 | #include "hf.h" 27 | #include "molecule.h" 28 | 29 | class TestMolecule : public CppUnit::TestFixture 30 | { 31 | CPPUNIT_TEST_SUITE( TestMolecule ); 32 | CPPUNIT_TEST( testH2 ); 33 | CPPUNIT_TEST( testCH4 ); 34 | CPPUNIT_TEST( testBenzene ); 35 | CPPUNIT_TEST_SUITE_END(); 36 | 37 | public: 38 | void setUp(); 39 | void tearDown(); 40 | 41 | void testH2(); 42 | void testCH4(); 43 | void testBenzene(); 44 | 45 | private: 46 | }; 47 | 48 | #endif // _TEST_MOLECULE 49 | -------------------------------------------------------------------------------- /src/vec3.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * vec3.cpp -- This file is part of HFCXX. * 3 | * * 4 | * Copyright (C) 2012, Ivo Filot * 5 | * * 6 | * HFCXX is free software: * 7 | * you can redistribute it and/or modify it under the terms of the * 8 | * GNU General Public License as published by the Free Software * 9 | * Foundation, either version 3 of the License, or (at your option) * 10 | * any later version. * 11 | * * 12 | * HFCXX is distributed in the hope that it will be useful, * 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | * See the GNU General Public License for more details. * 16 | * * 17 | * You should have received a copy of the GNU General Public License * 18 | * along with this program. If not, see http://www.gnu.org/licenses/. * 19 | * * 20 | **************************************************************************/ 21 | 22 | #include "vec3.h" 23 | 24 | Vec3::Vec3() { /* default constructor */ 25 | x = y = z =0; 26 | } 27 | 28 | Vec3::Vec3(const double xx, const double yy, const double zz) { 29 | x = xx; 30 | y = yy; 31 | z = zz; 32 | } 33 | 34 | Vec3::Vec3(const Vec3 &rhs) { 35 | x = rhs.x; 36 | y = rhs.y; 37 | z = rhs.z; 38 | } 39 | 40 | const double Vec3::getx() const { 41 | return x; 42 | } 43 | 44 | const double Vec3::gety() const { 45 | return y; 46 | } 47 | 48 | const double Vec3::getz() const { 49 | return z; 50 | } 51 | -------------------------------------------------------------------------------- /src/cgf.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * cgf.h -- This file is part of HFCXX. * 3 | * * 4 | * Copyright (C) 2012, Ivo Filot * 5 | * * 6 | * HFCXX is free software: * 7 | * you can redistribute it and/or modify it under the terms of the * 8 | * GNU General Public License as published by the Free Software * 9 | * Foundation, either version 3 of the License, or (at your option) * 10 | * any later version. * 11 | * * 12 | * HFCXX is distributed in the hope that it will be useful, * 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | * See the GNU General Public License for more details. * 16 | * * 17 | * You should have received a copy of the GNU General Public License * 18 | * along with this program. If not, see http://www.gnu.org/licenses/. * 19 | * * 20 | **************************************************************************/ 21 | 22 | #ifndef _CGF_H 23 | #define _CGF_H 24 | 25 | #include 26 | #include 27 | #include 28 | #include "vec3.h" 29 | #include "gto.h" 30 | 31 | /* 32 | Contracted Gaussian Function 33 | */ 34 | 35 | class CGF{ 36 | public: 37 | std::vector gtos; 38 | Vec3 r; 39 | std::string type; 40 | 41 | public: 42 | CGF(const std::string typee, const unsigned int z, const Vec3 &rr, std::vector gtoss); 43 | const std::string orb() const; 44 | 45 | friend std::ostream& operator <<(std::ostream &os,const CGF &rhs); 46 | }; 47 | 48 | #endif //_CGF_H 49 | -------------------------------------------------------------------------------- /src/cgf.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * cgf.cpp -- This file is part of HFCXX. * 3 | * * 4 | * Copyright (C) 2012, Ivo Filot * 5 | * * 6 | * HFCXX is free software: * 7 | * you can redistribute it and/or modify it under the terms of the * 8 | * GNU General Public License as published by the Free Software * 9 | * Foundation, either version 3 of the License, or (at your option) * 10 | * any later version. * 11 | * * 12 | * HFCXX is distributed in the hope that it will be useful, * 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | * See the GNU General Public License for more details. * 16 | * * 17 | * You should have received a copy of the GNU General Public License * 18 | * along with this program. If not, see http://www.gnu.org/licenses/. * 19 | * * 20 | **************************************************************************/ 21 | 22 | #include "cgf.h" 23 | 24 | CGF::CGF(const std::string typee, const unsigned int z, const Vec3 &rr, std::vector gtoss) { 25 | r = rr; 26 | type = typee; 27 | gtos = gtoss; 28 | } 29 | 30 | std::ostream& operator <<(std::ostream &os,const CGF &rhs) { 31 | 32 | os << "\t\t******* "; 33 | 34 | os << rhs.type << " orbital"; 35 | os << " *******" << std::endl; 36 | 37 | for(unsigned int i=0; i 26 | #include 27 | #include 28 | 29 | class Vec3{ 30 | private: 31 | double x,y,z; 32 | 33 | public: 34 | Vec3(); /* default constructor */ 35 | Vec3(const double xx, const double yy, const double zz); 36 | Vec3(const Vec3 &rhs); 37 | 38 | const double getx() const; 39 | const double gety() const; 40 | const double getz() const; 41 | }; 42 | 43 | /* typedefs */ 44 | typedef std::vector VecDoub; 45 | typedef std::vector VecInt; 46 | 47 | #endif // _HFCXX_VEC3_HH 48 | -------------------------------------------------------------------------------- /src/output.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * output.h -- This file is part of HFCXX. * 3 | * * 4 | * Copyright (C) 2012, Ivo Filot * 5 | * * 6 | * HFCXX is free software: * 7 | * you can redistribute it and/or modify it under the terms of the * 8 | * GNU General Public License as published by the Free Software * 9 | * Foundation, either version 3 of the License, or (at your option) * 10 | * any later version. * 11 | * * 12 | * HFCXX is distributed in the hope that it will be useful, * 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | * See the GNU General Public License for more details. * 16 | * * 17 | * You should have received a copy of the GNU General Public License * 18 | * along with this program. If not, see http://www.gnu.org/licenses/. * 19 | * * 20 | **************************************************************************/ 21 | 22 | #ifndef _OUTPUT_H 23 | #define _OUTPUT_H 24 | 25 | #include 26 | #include 27 | #include 28 | #include "version.h" 29 | #include "molecule.h" 30 | #include "matrix.h" 31 | 32 | class Output{ 33 | private: 34 | std::string spacer; 35 | 36 | public: 37 | Output(); 38 | void print_version(); 39 | void print_geometry(Molecule &mol); 40 | void print_summary(unsigned int iter, double en, unsigned int nrat, unsigned int nrorbs, unsigned int bss); 41 | void print_calculation_time(double time); 42 | void print_orbitals(const std::vector &molorben, const std::vector &orblist, const MatDoub &C, unsigned int nrelec); 43 | }; 44 | 45 | #endif //_OUTPUT_H 46 | -------------------------------------------------------------------------------- /src/strfunc.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * strfunc.h -- This file is part of HFCXX. * 3 | * * 4 | * Copyright (C) 2012, Ivo Filot * 5 | * * 6 | * HFCXX is free software: * 7 | * you can redistribute it and/or modify it under the terms of the * 8 | * GNU General Public License as published by the Free Software * 9 | * Foundation, either version 3 of the License, or (at your option) * 10 | * any later version. * 11 | * * 12 | * HFCXX is distributed in the hope that it will be useful, * 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | * See the GNU General Public License for more details. * 16 | * * 17 | * You should have received a copy of the GNU General Public License * 18 | * along with this program. If not, see http://www.gnu.org/licenses/. * 19 | * * 20 | **************************************************************************/ 21 | 22 | #ifndef _STRFUNC_H 23 | #define _STRFUNC_H 24 | 25 | #include 26 | #include 27 | 28 | /* strpos */ 29 | size_t strpos(const std::string &haystack, const std::string &needle); 30 | 31 | /* strreplace */ 32 | std::string& str_replace(const std::string &search, const std::string 33 | &replace, std::string &subject); 34 | 35 | /* substring (two variants) */ 36 | std::string substr(const std::string &str, int start); 37 | std::string substr(const std::string &str, int start, int length); 38 | 39 | /* strtrim */ 40 | std::string& strtrim(std::string &subject); 41 | 42 | /* explode */ 43 | std::vector explode( const std::string &delimiter, const std::string &explodeme); 44 | 45 | #endif // _STRFUNC_H 46 | -------------------------------------------------------------------------------- /src/version.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * version.cpp -- This file is part of HFCXX. * 3 | * * 4 | * Copyright (C) 2012, Ivo Filot * 5 | * * 6 | * HFCXX is free software: * 7 | * you can redistribute it and/or modify it under the terms of the * 8 | * GNU General Public License as published by the Free Software * 9 | * Foundation, either version 3 of the License, or (at your option) * 10 | * any later version. * 11 | * * 12 | * HFCXX is distributed in the hope that it will be useful, * 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | * See the GNU General Public License for more details. * 16 | * * 17 | * You should have received a copy of the GNU General Public License * 18 | * along with this program. If not, see http://www.gnu.org/licenses/. * 19 | * * 20 | **************************************************************************/ 21 | 22 | #include "version.h" 23 | 24 | std::string version() { 25 | std::stringstream str; 26 | std::string prog_name = "hfcxx"; 27 | std::string version_number = PACKAGE_VERSION; 28 | std::string author = "Ivo Filot "; 29 | std::string date = __DATE__; 30 | std::string time = __TIME__; 31 | std::string compiler_version = __VERSION__; 32 | 33 | str << "executing: " << prog_name << " version " << version_number << std::endl; 34 | //std::cout << "tracking number: " << compile_counter << std::endl; 35 | str << "compiled on: " << date << " " << time << std::endl; 36 | str << "compiler: gcc " << compiler_version << std::endl; 37 | str << "author: " << author << std::endl; 38 | str << std::endl; 39 | 40 | std::string out = str.str(); 41 | return out; 42 | } 43 | -------------------------------------------------------------------------------- /src/gamma.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * gamma.h -- This file is part of HFCXX. * 3 | * * 4 | * Copyright (C) 2012, Ivo Filot * 5 | * * 6 | * HFCXX is free software: * 7 | * you can redistribute it and/or modify it under the terms of the * 8 | * GNU General Public License as published by the Free Software * 9 | * Foundation, either version 3 of the License, or (at your option) * 10 | * any later version. * 11 | * * 12 | * HFCXX is distributed in the hope that it will be useful, * 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | * See the GNU General Public License for more details. * 16 | * * 17 | * You should have received a copy of the GNU General Public License * 18 | * along with this program. If not, see http://www.gnu.org/licenses/. * 19 | * * 20 | **************************************************************************/ 21 | 22 | /* 23 | * 24 | * References: 25 | * [1] Numerical Recipes 26 | * William H. Press, Saul A. Teukolsky, William T., 27 | * Vetterling and Brian P. Flannery 28 | * 3rd edition page 261 29 | * ISBN-13: 978-0521880688 30 | * 31 | * The functions below have all been obtained using ref [1] 32 | */ 33 | 34 | #ifndef _GAMMA_H 35 | #define _GAMMA_H 36 | 37 | #include 38 | #include 39 | #include "func.h" 40 | 41 | double Fgamma(const double m, double x); 42 | double gamm_inc(const double a, const double x); 43 | double gammp(const double m, const double x); 44 | double gser(const double a, const double x); 45 | double gammln(const double xx); 46 | double gcf(const double a, const double x); 47 | double gammpapprox(double a, double x, int psig); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /src/gto.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * gto.h -- This file is part of HFCXX. * 3 | * * 4 | * Copyright (C) 2012, Ivo Filot * 5 | * * 6 | * HFCXX is free software: * 7 | * you can redistribute it and/or modify it under the terms of the * 8 | * GNU General Public License as published by the Free Software * 9 | * Foundation, either version 3 of the License, or (at your option) * 10 | * any later version. * 11 | * * 12 | * HFCXX is distributed in the hope that it will be useful, * 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | * See the GNU General Public License for more details. * 16 | * * 17 | * You should have received a copy of the GNU General Public License * 18 | * along with this program. If not, see http://www.gnu.org/licenses/. * 19 | * * 20 | **************************************************************************/ 21 | 22 | #ifndef _GTO_H 23 | #define _GTO_H 24 | 25 | #include 26 | #include 27 | #include "vec3.h" 28 | #include "factorial.h" 29 | 30 | /* 31 | Gaussian Type Orbital 32 | 33 | x^l * y^m * z^n * exp(-alpha * r^2) 34 | */ 35 | 36 | class GTO{ 37 | public: 38 | double c; /* coefficient */ 39 | unsigned int l,m,n; /* powers */ 40 | double x,y,z; /* positions */ 41 | double alpha; /* alpha value in the exponent */ 42 | Vec3 r; /* position vector */ 43 | double norm; 44 | 45 | public: 46 | GTO(const double c, const Vec3 rr, const double alphaa, const unsigned int ll, const unsigned int mm, const unsigned int nn); 47 | friend std::ostream& operator <<(std::ostream &os,const GTO &rhs); 48 | 49 | private: 50 | double calcnorm() const; 51 | }; 52 | 53 | #endif //_GTO_H 54 | -------------------------------------------------------------------------------- /src/nuclear.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * nuclear.h -- This file is part of HFCXX. * 3 | * * 4 | * Copyright (C) 2012, Ivo Filot * 5 | * * 6 | * HFCXX is free software: * 7 | * you can redistribute it and/or modify it under the terms of the * 8 | * GNU General Public License as published by the Free Software * 9 | * Foundation, either version 3 of the License, or (at your option) * 10 | * any later version. * 11 | * * 12 | * HFCXX is distributed in the hope that it will be useful, * 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | * See the GNU General Public License for more details. * 16 | * * 17 | * You should have received a copy of the GNU General Public License * 18 | * along with this program. If not, see http://www.gnu.org/licenses/. * 19 | * * 20 | **************************************************************************/ 21 | 22 | #ifndef _NUCLEAR_H 23 | #define _NUCLEAR_H 24 | 25 | #include 26 | #include 27 | 28 | #include "config.h" 29 | #include "gamma.h" 30 | #include "func.h" 31 | #include "vec3.h" 32 | #include "cgf.h" 33 | #include "atom.h" 34 | 35 | double cgf_nuclear(CGF &cgf1, CGF &cgf2, const Atom &a); 36 | double gto_nuclear(GTO >o1, GTO >o2, const Vec3 &c); 37 | double nuclear(const Vec3 a, double norm1, int l1, int m1, int n1, double alpha1, const Vec3 b, double norm2, int l2, int m2, int n2, double alpha2, const Vec3 c); 38 | std::vector A_array(const int l1, const int l2, const double pa, const double pb, const double cp, const double g); 39 | double A_term(const int i, const int r, const int u, const int l1, const int l2, const double pax, const double pbx, const double cpx, const double gamma); 40 | 41 | #endif //_NUCLEAR_H 42 | -------------------------------------------------------------------------------- /src/func.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * func.h -- This file is part of HFCXX. * 3 | * * 4 | * Copyright (C) 2012, Ivo Filot * 5 | * * 6 | * HFCXX is free software: * 7 | * you can redistribute it and/or modify it under the terms of the * 8 | * GNU General Public License as published by the Free Software * 9 | * Foundation, either version 3 of the License, or (at your option) * 10 | * any later version. * 11 | * * 12 | * HFCXX is distributed in the hope that it will be useful, * 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | * See the GNU General Public License for more details. * 16 | * * 17 | * You should have received a copy of the GNU General Public License * 18 | * along with this program. If not, see http://www.gnu.org/licenses/. * 19 | * * 20 | **************************************************************************/ 21 | 22 | #ifndef _FUNC_H 23 | #define _FUNC_H 24 | 25 | #include 26 | #include "vec3.h" 27 | #include "factorial.h" 28 | 29 | /* sign and square */ 30 | double sign(const double &a, const double &b); 31 | double sqr(const double x); 32 | 33 | /* min, max, abs functions */ 34 | double min(const double &a, const double &b); 35 | double max(const double &a, const double &b); 36 | double abs(const double &x); 37 | 38 | /* functions for binomial expansion */ 39 | double binomial_prefactor(int s, int m1, int m2, double x1, double x2); 40 | int binomial(int a, int b); 41 | 42 | /* functions for vectors */ 43 | double dist2(const Vec3 &a, const Vec3 &b); 44 | Vec3 gaussian_product_center(const double &alpha1, const Vec3 &a, 45 | const double &alpha2, const Vec3 &b); 46 | 47 | /* swap functions */ 48 | void swap(unsigned int &i, unsigned int &j); 49 | 50 | #endif //_FUNC_H 51 | -------------------------------------------------------------------------------- /src/test/unittest.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * basis-sto3g.cpp -- This file is part of HFCXX. * 3 | * * 4 | * Copyright (C) 2012, Ivo Filot * 5 | * * 6 | * HFCXX is free software: * 7 | * you can redistribute it and/or modify it under the terms of the * 8 | * GNU General Public License as published by the Free Software * 9 | * Foundation, either version 3 of the License, or (at your option) * 10 | * any later version. * 11 | * * 12 | * HFCXX is distributed in the hope that it will be useful, * 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | * See the GNU General Public License for more details. * 16 | * * 17 | * You should have received a copy of the GNU General Public License * 18 | * along with this program. If not, see http://www.gnu.org/licenses/. * 19 | * * 20 | **************************************************************************/ 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | int main(int argc, char* argv[]) { 27 | // Get the top level suite from the registry 28 | CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest(); 29 | 30 | // Adds the test to the list of test to run 31 | CppUnit::TextUi::TestRunner runner; 32 | runner.addTest( suite ); 33 | 34 | // Change the default outputter to a compiler error format outputter 35 | runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(), 36 | std::cerr ) ); 37 | // Run the tests. 38 | bool wasSucessful = runner.run(); 39 | 40 | // Return error code 1 if the one of test failed. 41 | return wasSucessful ? 0 : 1; 42 | } 43 | -------------------------------------------------------------------------------- /src/canorg.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * canorg.cpp -- This file is part of HFCXX. * 3 | * * 4 | * Copyright (C) 2012, Ivo Filot * 5 | * * 6 | * HFCXX is free software: * 7 | * you can redistribute it and/or modify it under the terms of the * 8 | * GNU General Public License as published by the Free Software * 9 | * Foundation, either version 3 of the License, or (at your option) * 10 | * any later version. * 11 | * * 12 | * HFCXX is distributed in the hope that it will be useful, * 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | * See the GNU General Public License for more details. * 16 | * * 17 | * You should have received a copy of the GNU General Public License * 18 | * along with this program. If not, see http://www.gnu.org/licenses/. * 19 | * * 20 | **************************************************************************/ 21 | 22 | #include "canorg.h" 23 | 24 | Xmatrix canorg(const Smatrix &S) { 25 | unsigned int size = S.nrows(); 26 | MatDoub mat(S); 27 | MatDoub U; 28 | VecDoub l; 29 | 30 | //Symmeig eig(mat,true); 31 | Eigsym es(mat,U,l); 32 | 33 | MatDoub D(size, size, 0.0); /* create diagonal matrix */ 34 | /* populate diagonal matrix */ 35 | for(unsigned int i=0; i 26 | #include 27 | #include "atom.h" 28 | #include "basis.h" 29 | #include "strfunc.h" 30 | #include "readfile.h" 31 | 32 | class Molecule{ 33 | private: 34 | std::vector atoms; 35 | unsigned int nrat; 36 | Basis basis; 37 | std::string basisset; 38 | unsigned int charge; 39 | 40 | public: 41 | Molecule(); /* default constructor */ 42 | void read(std::string file); /* read molecule from file */ 43 | void addAtom(const Atom &at); 44 | void addAtom(const std::string symbolin, const double xx, const double yy, const double zz); 45 | void addAtom(const unsigned int Zz, const double xx, const double yy, const double zz); 46 | friend std::ostream & operator << (std::ostream &os, const Molecule &rhs); 47 | const unsigned int nratoms() const; 48 | const Atom& operator[](const unsigned int i) const; 49 | }; 50 | 51 | #endif //_MOLECULE_H 52 | -------------------------------------------------------------------------------- /src/readfile.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * readfile.h -- This file is part of HFCXX. * 3 | * * 4 | * Copyright (C) 2012, Ivo Filot * 5 | * * 6 | * HFCXX is free software: * 7 | * you can redistribute it and/or modify it under the terms of the * 8 | * GNU General Public License as published by the Free Software * 9 | * Foundation, either version 3 of the License, or (at your option) * 10 | * any later version. * 11 | * * 12 | * HFCXX is distributed in the hope that it will be useful, * 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | * See the GNU General Public License for more details. * 16 | * * 17 | * You should have received a copy of the GNU General Public License * 18 | * along with this program. If not, see http://www.gnu.org/licenses/. * 19 | * * 20 | **************************************************************************/ 21 | 22 | #ifndef _READFILE_H 23 | #define _READFILE_H 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include "strfunc.h" 31 | 32 | class InputFile { 33 | private: 34 | std::string filename; 35 | std::ifstream infile; 36 | std::vector lines; 37 | bool isOpen; 38 | 39 | public: 40 | InputFile(); /* default constructor */ 41 | InputFile(std::string); /* constructor taking filename as input */ 42 | ~InputFile(); /* default destructor */ 43 | void readFile(std::vector &); 44 | void dump(); 45 | 46 | private: /* utility functions */ 47 | void init(); /* initialization functions */ 48 | void open(); /* open file for reading */ 49 | void read(); /* read the file */ 50 | void close(); /* close the file */ 51 | void reset(); /* resets the pointer to the start of the file */ 52 | }; 53 | 54 | #endif // _READFILE_H 55 | -------------------------------------------------------------------------------- /src/matfunc.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * matfunc.cpp -- This file is part of HFCXX. * 3 | * * 4 | * Copyright (C) 2012, Ivo Filot * 5 | * * 6 | * HFCXX is free software: * 7 | * you can redistribute it and/or modify it under the terms of the * 8 | * GNU General Public License as published by the Free Software * 9 | * Foundation, either version 3 of the License, or (at your option) * 10 | * any later version. * 11 | * * 12 | * HFCXX is distributed in the hope that it will be useful, * 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | * See the GNU General Public License for more details. * 16 | * * 17 | * You should have received a copy of the GNU General Public License * 18 | * along with this program. If not, see http://www.gnu.org/licenses/. * 19 | * * 20 | **************************************************************************/ 21 | 22 | #include "matfunc.h" 23 | 24 | MatDoub matprod(MatDoub &a, MatDoub &b) { 25 | unsigned int n = a.nrows(); 26 | unsigned int m = b.ncols(); 27 | unsigned int r = a.ncols(); 28 | 29 | MatDoub ans(n,m,0.0); 30 | 31 | for(unsigned int i=0; i **Note**: This program is mainly made for educational purposes. There are some 12 | > (obvious) things to improve as suggested by others (e.g. loading of basis 13 | > set coefficients from external files). My aim is however to keep this code 14 | > simple and not use too many additional features. 15 | 16 | * Interested in learning Density Functional Theory? Have a look at 17 | [DFTCXX](https://github.com/ifilot/dftcxx). 18 | * Want to know more about electronic structure calculations, have a look at my 19 | [free lecture book](https://ifilot.pages.tue.nl/elements-of-electronic-structure-theory/). 20 | 21 | ## Compilation 22 | 23 | ### Linux 24 | 25 | Ensure you have all the required packages installed 26 | 27 | ``` 28 | sudo apt install build-essential cmake libcppunit-dev 29 | ``` 30 | 31 | ``` 32 | mkdir build && cd build 33 | cmake ../src 34 | make -j9 35 | ``` 36 | 37 | ### For Apple Silicon 38 | 39 | Install the compilation toolchain via [brew](https://brew.sh/). 40 | 41 | ``` 42 | brew install make gcc cmake cppunit 43 | ``` 44 | 45 | You also have to make sure that you have xCode installed 46 | 47 | ``` 48 | xcode-select --install 49 | ``` 50 | 51 | Packages are located in a different folder compared to linux 52 | 53 | ``` 54 | mkdir build && cd build 55 | cmake -DCMAKE_CXX_FLAGS="-I/opt/homebrew/opt/cppunit/include" ../src 56 | make -j9 57 | ``` 58 | ## Testing 59 | 60 | After compilation, you can test the `hfccc` executable by running the 61 | test suite. 62 | 63 | > **Note**: The testsuite contains a HF calculation of benzene using the 64 | > STO-6g basis set. Since HFCXX is not optimized for speed, running the 65 | > tests can take a few minutes to complete. 66 | 67 | ``` 68 | make test 69 | ``` 70 | 71 | A successful test should give an output similar to the following 72 | 73 | ``` 74 | Running tests... 75 | Test project /mnt/d/PROGRAMMING/CPP/hfcxx/build 76 | Start 1: TestMolecules 77 | 1/1 Test #1: TestMolecules .................... Passed 50.70 sec 78 | 79 | 100% tests passed, 0 tests failed out of 1 80 | 81 | Total Test time (real) = 50.72 sec 82 | ``` 83 | 84 | ## Usage 85 | 86 | ``` 87 | ./hfcxx _input_file_ > _output_file_ 88 | ``` 89 | 90 | For example, to run a HF calculation for H2, run 91 | 92 | ``` 93 | ./hfcxx molecules/h2.in > h2.out 94 | ``` 95 | -------------------------------------------------------------------------------- /src/test/test_molecule.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * Copyright (C) 2023, Ivo Filot * 3 | * * 4 | * HFCXX is free software: * 5 | * you can redistribute it and/or modify it under the terms of the * 6 | * GNU General Public License as published by the Free Software * 7 | * Foundation, either version 3 of the License, or (at your option) * 8 | * any later version. * 9 | * * 10 | * HFCXX is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 12 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 13 | * See the GNU General Public License for more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with this program. If not, see http://www.gnu.org/licenses/. * 17 | * * 18 | **************************************************************************/ 19 | 20 | #include "test_molecule.h" 21 | 22 | CPPUNIT_TEST_SUITE_REGISTRATION( TestMolecule ); 23 | 24 | void TestMolecule::setUp() { 25 | } 26 | 27 | void TestMolecule::tearDown() { 28 | } 29 | 30 | void TestMolecule::testH2() { 31 | Output out; 32 | 33 | Molecule mol; 34 | mol.read("h2.in"); 35 | out.print_geometry(mol); 36 | 37 | /* perform HF calculation */ 38 | HF hf; 39 | hf.debug = false; 40 | hf.molecule(mol); 41 | hf.run(); 42 | 43 | double energy = hf.get_energy(); 44 | CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.11671432, energy, 1e-4); 45 | } 46 | 47 | void TestMolecule::testCH4() { 48 | Output out; 49 | 50 | Molecule mol; 51 | mol.read("ch4.in"); 52 | out.print_geometry(mol); 53 | 54 | /* perform HF calculation */ 55 | HF hf; 56 | hf.debug = false; 57 | hf.molecule(mol); 58 | hf.run(); 59 | 60 | double energy = hf.get_energy(); 61 | CPPUNIT_ASSERT_DOUBLES_EQUAL(-39.717589987190621, energy, 1e-4); 62 | } 63 | 64 | void TestMolecule::testBenzene() { 65 | Output out; 66 | 67 | Molecule mol; 68 | mol.read("benzene.in"); 69 | out.print_geometry(mol); 70 | 71 | /* perform HF calculation */ 72 | HF hf; 73 | hf.debug = false; 74 | hf.molecule(mol); 75 | hf.run(); 76 | 77 | double energy = hf.get_energy(); 78 | CPPUNIT_ASSERT_DOUBLES_EQUAL(-230.13033852795101, energy, 1e-4); 79 | } 80 | -------------------------------------------------------------------------------- /src/basis.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * basis.h -- This file is part of HFCXX. * 3 | * * 4 | * Copyright (C) 2012, Ivo Filot * 5 | * * 6 | * HFCXX is free software: * 7 | * you can redistribute it and/or modify it under the terms of the * 8 | * GNU General Public License as published by the Free Software * 9 | * Foundation, either version 3 of the License, or (at your option) * 10 | * any later version. * 11 | * * 12 | * HFCXX is distributed in the hope that it will be useful, * 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | * See the GNU General Public License for more details. * 16 | * * 17 | * You should have received a copy of the GNU General Public License * 18 | * along with this program. If not, see http://www.gnu.org/licenses/. * 19 | * * 20 | **************************************************************************/ 21 | 22 | #ifndef _BASIS_H 23 | #define _BASIS_H 24 | 25 | #include 26 | #include 27 | #include "gto.h" 28 | #include "vec3.h" 29 | 30 | class Basis{ 31 | private: 32 | std::vector gtos; 33 | std::string basisset; 34 | 35 | public: 36 | Basis(); 37 | Basis(std::string basisset); 38 | void set(std::string type, unsigned int z, Vec3 r); 39 | void setType(std::string basissett); 40 | std::vector getGTOs() const; 41 | 42 | private: 43 | void addGTOs_sto3g(std::string type, unsigned int z, Vec3 r); 44 | void addGTOs_sto6g(std::string type, unsigned int z, Vec3 r); 45 | 46 | /* GTOs for sto-xg basis sets */ 47 | void addGTO_s(double alpha, double c, Vec3 r); 48 | void addGTO_px(double alpha, double c, Vec3 r); 49 | void addGTO_py(double alpha, double c, Vec3 r); 50 | void addGTO_pz(double alpha, double c, Vec3 r); 51 | void addGTO_dx2(double alpha, double c, Vec3 r); 52 | void addGTO_dxy(double alpha, double c, Vec3 r); 53 | void addGTO_dxz(double alpha, double c, Vec3 r); 54 | void addGTO_dy2(double alpha, double c, Vec3 r); 55 | void addGTO_dyz(double alpha, double c, Vec3 r); 56 | void addGTO_dz2(double alpha, double c, Vec3 r); 57 | }; 58 | 59 | #endif //_BASIS_H 60 | -------------------------------------------------------------------------------- /src/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #/************************************************************************** 2 | # CMakeLists.txt -- This file is part of HFCXX. * 3 | # * 4 | # Copyright (C) 2012, Ivo Filot * 5 | # * 6 | # HFCXX is free software: * 7 | # you can redistribute it and/or modify it under the terms of the * 8 | # GNU General Public License as published by the Free Software * 9 | # Foundation, either version 3 of the License, or (at your option) * 10 | # any later version. * 11 | # * 12 | # HFCXX is distributed in the hope that it will be useful, * 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | # See the GNU General Public License for more details. * 16 | # * 17 | # You should have received a copy of the GNU General Public License * 18 | # along with this program. If not, see http://www.gnu.org/licenses/. * 19 | # * 20 | #**************************************************************************/ 21 | 22 | add_library(unittest STATIC unittest.cpp) 23 | 24 | # set executables 25 | SET(EXECUTABLES TestMolecules) 26 | 27 | ####################################################### 28 | # Add executables 29 | ####################################################### 30 | add_executable(TestMolecules test_molecule.cpp) 31 | 32 | ####################################################### 33 | # Link mkmsources and other dependencies 34 | ####################################################### 35 | if(CMAKE_BUILD_TYPE MATCHES Debug) 36 | SET(CPPUNIT_LIB ${CPPUNIT_DEBUG_LIBRARY}) 37 | else() 38 | SET(CPPUNIT_LIB ${CPPUNIT_LIBRARY}) 39 | endif() 40 | 41 | # configure common settings for test executables 42 | foreach(testexec ${EXECUTABLES}) 43 | target_link_libraries(${testexec} 44 | unittest 45 | hfcxxsources 46 | ${CPPUNIT_LIB}) 47 | add_test(NAME ${testexec} COMMAND ${testexec}) 48 | endforeach() 49 | 50 | ####################################################### 51 | # add testinput files 52 | ####################################################### 53 | configure_file(molecules/h2.in h2.in COPYONLY) 54 | configure_file(molecules/ch4.in ch4.in COPYONLY) 55 | configure_file(molecules/benzene.in benzene.in COPYONLY) 56 | -------------------------------------------------------------------------------- /src/factorial.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * factorial.h -- This file is part of HFCXX. * 3 | * * 4 | * Copyright (C) 2012, Ivo Filot * 5 | * * 6 | * HFCXX is free software: * 7 | * you can redistribute it and/or modify it under the terms of the * 8 | * GNU General Public License as published by the Free Software * 9 | * Foundation, either version 3 of the License, or (at your option) * 10 | * any later version. * 11 | * * 12 | * HFCXX is distributed in the hope that it will be useful, * 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | * See the GNU General Public License for more details. * 16 | * * 17 | * You should have received a copy of the GNU General Public License * 18 | * along with this program. If not, see http://www.gnu.org/licenses/. * 19 | * * 20 | **************************************************************************/ 21 | 22 | #ifndef _FACTORIAL_H 23 | #define _FACTORIAL_H 24 | 25 | inline static const int fact_recursive(int n){ 26 | return n <= 1 ? 1 : n * fact_recursive(n-1); 27 | } 28 | 29 | static const int fact(int n){ 30 | static const int factorials[11] = { 31 | 1, 32 | 1, 33 | 2, 34 | 6, 35 | 24, 36 | 120, 37 | 720, 38 | 5040, 39 | 40320, 40 | 362880, 41 | 3628880 42 | }; 43 | 44 | if(n < 11) { 45 | if(n < 0) { 46 | return 1; 47 | } else { 48 | return factorials[n]; 49 | } 50 | } else { 51 | return fact_recursive(n); 52 | } 53 | } 54 | 55 | inline static const int fact2_recursive(int n){ 56 | return n <= 1 ? 1 : n * fact2_recursive(n-2); 57 | } 58 | 59 | /* double factorial function = 1*3*5*...*n */ 60 | static const int fact2(int n){ 61 | static const int factorials2[11] = { 62 | 1, 63 | 1, 64 | 2, 65 | 3, 66 | 8, 67 | 15, 68 | 48, 69 | 105, 70 | 384, 71 | 945, 72 | 3840 73 | }; 74 | 75 | if(n < 11) { 76 | if(n < 0) { 77 | return 1; 78 | } else { 79 | return factorials2[n]; 80 | } 81 | } else { 82 | return fact2_recursive(n); 83 | } 84 | } 85 | 86 | #endif //_FACTORIAL_H 87 | -------------------------------------------------------------------------------- /src/atom.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * atom.h -- This file is part of HFCXX. * 3 | * * 4 | * Copyright (C) 2012, Ivo Filot * 5 | * * 6 | * HFCXX is free software: * 7 | * you can redistribute it and/or modify it under the terms of the * 8 | * GNU General Public License as published by the Free Software * 9 | * Foundation, either version 3 of the License, or (at your option) * 10 | * any later version. * 11 | * * 12 | * HFCXX is distributed in the hope that it will be useful, * 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | * See the GNU General Public License for more details. * 16 | * * 17 | * You should have received a copy of the GNU General Public License * 18 | * along with this program. If not, see http://www.gnu.org/licenses/. * 19 | * * 20 | **************************************************************************/ 21 | 22 | #ifndef _ATOM_H 23 | #define _ATOM_H 24 | 25 | #include 26 | #include 27 | #include 28 | #include "vec3.h" 29 | #include "cgf.h" 30 | #include "basis.h" 31 | 32 | class Atom{ 33 | private: 34 | unsigned int Z; /* atomic number, i.e. H=1, He=2, Li=3... */ 35 | Vec3 r; /* position of atom */ 36 | std::string element; 37 | std::vector wavefunctions; 38 | unsigned int nrwav; /* number of wavefunctions */ 39 | unsigned int nrelec; /* number of electrons */ 40 | 41 | public: 42 | Atom(const std::string symbolin, const double xx, const double yy, const double zz, Basis &basis); 43 | Atom(const unsigned int Zz, const double xx, const double yy, const double zz, Basis &basis); 44 | 45 | friend std::ostream & operator << (std::ostream &os, const Atom &rhs); 46 | 47 | private: 48 | const double x() const; 49 | const double y() const; 50 | const double z() const; 51 | unsigned int e2z(const std::string &elementin) const; 52 | std::string z2e(const unsigned int &z) const; 53 | void addWavefunctions(Basis &basis); 54 | 55 | public: 56 | const std::string ps() const; /* print symbol */ 57 | const Vec3 gr() const; 58 | const unsigned int nrorbs() const; 59 | const CGF& operator[](const unsigned int i) const; 60 | const unsigned int nrelecs() const; 61 | const unsigned int nucl_chg() const; 62 | }; 63 | 64 | #endif // _ATOM_H 65 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * main.cpp -- This file is part of HFCXX. * 3 | * * 4 | * Copyright (C) 2012, Ivo Filot * 5 | * * 6 | * HFCXX is free software: * 7 | * you can redistribute it and/or modify it under the terms of the * 8 | * GNU General Public License as published by the Free Software * 9 | * Foundation, either version 3 of the License, or (at your option) * 10 | * any later version. * 11 | * * 12 | * HFCXX is distributed in the hope that it will be useful, * 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | * See the GNU General Public License for more details. * 16 | * * 17 | * You should have received a copy of the GNU General Public License * 18 | * along with this program. If not, see http://www.gnu.org/licenses/. * 19 | * * 20 | **************************************************************************/ 21 | 22 | #include 23 | #include 24 | #include 25 | #include "hf.h" 26 | #include "clock.h" 27 | #include "output.h" 28 | 29 | int main(int argc, char *argv[]) { 30 | // parse the arguments 31 | if(argc == 1) { 32 | std::cout << "Usage: " << argv[0] << " " << std::endl; 33 | std::cout << "Please provide a valid input file" << std::endl; 34 | return 0; 35 | } 36 | 37 | // initialize an output object 38 | Output out; 39 | // print the version to 40 | out.print_version(); 41 | 42 | std::string filename; 43 | bool debug = false; 44 | 45 | /* parse arguments */ 46 | if(!strcmp(argv[argc-2],"-m")) { 47 | debug = true; 48 | } 49 | 50 | if(argc > 1) { 51 | filename = argv[argc-1]; 52 | } 53 | 54 | /* output compile information on execution */ 55 | version(); 56 | 57 | /* keep track of the time */ 58 | Clock clock; 59 | 60 | /* read molecule from geometry file */ 61 | Molecule mol; 62 | mol.read(filename); 63 | out.print_geometry(mol); 64 | 65 | /* perform HF calculation */ 66 | HF hf; 67 | hf.debug = debug; 68 | hf.molecule(mol); 69 | hf.run(); 70 | 71 | /* output calculation time */ 72 | clock.toc(); 73 | out.print_calculation_time(clock.passed()); 74 | 75 | #ifdef _WIN32 76 | std::cout << "Press ENTER to close" << std::endl; 77 | std::cin.get(); 78 | #endif //_check if compiled on Win32 79 | 80 | return 0; 81 | } 82 | -------------------------------------------------------------------------------- /src/readfile.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * readfile.cpp -- This file is part of HFCXX. * 3 | * * 4 | * Copyright (C) 2012, Ivo Filot * 5 | * * 6 | * HFCXX is free software: * 7 | * you can redistribute it and/or modify it under the terms of the * 8 | * GNU General Public License as published by the Free Software * 9 | * Foundation, either version 3 of the License, or (at your option) * 10 | * any later version. * 11 | * * 12 | * HFCXX is distributed in the hope that it will be useful, * 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | * See the GNU General Public License for more details. * 16 | * * 17 | * You should have received a copy of the GNU General Public License * 18 | * along with this program. If not, see http://www.gnu.org/licenses/. * 19 | * * 20 | **************************************************************************/ 21 | 22 | #include "readfile.h" 23 | 24 | InputFile::InputFile() { 25 | this->init(); 26 | }; 27 | 28 | InputFile::InputFile(std::string in) { 29 | this->init(); 30 | this->filename = in; 31 | } 32 | 33 | void InputFile::init() { 34 | isOpen = false; 35 | } 36 | 37 | InputFile::~InputFile() { 38 | this->close(); 39 | } 40 | 41 | void InputFile::open() { 42 | if(!isOpen) { 43 | //std::cout << "Opening file" << std::endl; 44 | isOpen = true; 45 | infile.open(filename.c_str() ); 46 | } else { 47 | std::cout << "Error, file already opened" << std::endl; 48 | } 49 | } 50 | 51 | void InputFile::close() { 52 | if(isOpen) { 53 | //std::cout << "Closing file" << std::endl; 54 | infile.close(); 55 | } 56 | } 57 | 58 | void InputFile::read() { 59 | this->open(); 60 | std::string line; 61 | 62 | if(infile.is_open() ) { 63 | while(infile.good() ) { 64 | getline(infile,line); 65 | lines.push_back(line); 66 | } 67 | } 68 | 69 | this->reset(); 70 | } 71 | 72 | void InputFile::readFile(std::vector &output) { 73 | this->read(); 74 | output = lines; 75 | } 76 | 77 | void InputFile::dump() { 78 | unsigned int i = 0; 79 | for(std::vector::iterator it = lines.begin(); 80 | it != lines.end(); ++it) { 81 | i++; 82 | std::cout << i << "\t" << *it << std::endl; 83 | } 84 | } 85 | 86 | void InputFile::reset() { 87 | infile.seekg(0); 88 | } 89 | -------------------------------------------------------------------------------- /src/eispack.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * eispack.h -- This file is part of HFCXX. * 3 | * * 4 | * Copyright (C) 2012, Ivo Filot * 5 | * * 6 | * HFCXX is free software: * 7 | * you can redistribute it and/or modify it under the terms of the * 8 | * GNU General Public License as published by the Free Software * 9 | * Foundation, either version 3 of the License, or (at your option) * 10 | * any later version. * 11 | * * 12 | * HFCXX is distributed in the hope that it will be useful, * 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | * See the GNU General Public License for more details. * 16 | * * 17 | * You should have received a copy of the GNU General Public License * 18 | * along with this program. If not, see http://www.gnu.org/licenses/. * 19 | * * 20 | **************************************************************************/ 21 | 22 | #ifndef _EISPACK_H 23 | #define _EISPACK_H 24 | 25 | int bakvec ( int n, double t[], double e[], int m, double z[] ); 26 | void cbabk2 ( int n, int low, int igh, double scale[], int m, double zr[], 27 | double zi[] ); 28 | void bandr ( int n, int mb, double a[], double d[], double e[], double e2[], 29 | int matz, double z[] ); 30 | void csroot ( double xr, double xi, double &yr, double &yi ); 31 | int i4_max ( int i1, int i2 ); 32 | int i4_min ( int i1, int i2 ); 33 | double pythag ( double a, double b ); 34 | double r8_abs ( double x ); 35 | double r8_epsilon ( ); 36 | double r8_max ( double x, double y ); 37 | double r8_min ( double x, double y ); 38 | double r8_sign ( double x ); 39 | void r8mat_identity ( int n, double a[] ); 40 | double *r8mat_mm_new ( int n1, int n2, int n3, double a[], double b[] ); 41 | void r8mat_print ( int m, int n, double a[], std::string title ); 42 | void r8mat_print_some ( int m, int n, double a[], int ilo, int jlo, int ihi, 43 | int jhi, std::string title ); 44 | double *r8mat_uniform_01_new ( int m, int n, int &seed ); 45 | void r8vec_print ( int n, double a[], std::string title ); 46 | int rs ( int n, double a[], double w[], int matz, double z[] ); 47 | int rsb ( int n, int mb, double a[], double w[], int matz, double z[] ); 48 | void timestamp ( ); 49 | int tql2 ( int n, double d[], double e[], double z[] ); 50 | int tqlrat ( int n, double w[], double fv2[] ); 51 | void tred1 ( int n, double a[], double w[], double fv1[], double fv2[] ); 52 | void tred2 ( int n, double a[], double d[], double e[], double z[] ); 53 | 54 | #endif //_EISPACK_H 55 | -------------------------------------------------------------------------------- /src/kinetic.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * kinetic.cpp -- This file is part of HFCXX. * 3 | * * 4 | * Copyright (C) 2012, Ivo Filot * 5 | * * 6 | * HFCXX is free software: * 7 | * you can redistribute it and/or modify it under the terms of the * 8 | * GNU General Public License as published by the Free Software * 9 | * Foundation, either version 3 of the License, or (at your option) * 10 | * any later version. * 11 | * * 12 | * HFCXX is distributed in the hope that it will be useful, * 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | * See the GNU General Public License for more details. * 16 | * * 17 | * You should have received a copy of the GNU General Public License * 18 | * along with this program. If not, see http://www.gnu.org/licenses/. * 19 | * * 20 | **************************************************************************/ 21 | 22 | #include "kinetic.h" 23 | 24 | double gto_kinetic(GTO >o1, GTO >o2) { 25 | double term0 = gto2.alpha * (2 * ( gto2.l + gto2.m + gto2.n ) + 3 ) * 26 | gto_overlap(gto1, gto2); 27 | 28 | double term1 = -2 * pow(gto2.alpha,2.0) * ( 29 | overlap(gto1.alpha, gto1.l, gto1.m, gto1.n, gto1.r, gto2.alpha, gto2.l+2, gto2.m, gto2.n, gto2.r) + 30 | overlap(gto1.alpha, gto1.l, gto1.m, gto1.n, gto1.r, gto2.alpha, gto2.l, gto2.m+2, gto2.n, gto2.r) + 31 | overlap(gto1.alpha, gto1.l, gto1.m, gto1.n, gto1.r, gto2.alpha, gto2.l, gto2.m, gto2.n+2, gto2.r) 32 | ); 33 | double term2 = -0.5 * (gto2.l * (gto2.l - 1) * 34 | overlap(gto1.alpha, gto1.l, gto1.m, gto1.n, gto1.r, gto2.alpha, gto2.l-2, gto2.m, gto2.n, gto2.r) + 35 | gto2.m * (gto2.m - 1) * 36 | overlap(gto1.alpha, gto1.l, gto1.m, gto1.n, gto1.r, gto2.alpha, gto2.l, gto2.m-2, gto2.n, gto2.r) + 37 | gto2.n * (gto2.n - 1) * 38 | overlap(gto1.alpha, gto1.l, gto1.m, gto1.n, gto1.r, gto2.alpha, gto2.l, gto2.m, gto2.n-2, gto2.r) ); 39 | 40 | return term0 + term1 + term2; 41 | } 42 | 43 | double cgf_kinetic(CGF &cgf1, CGF &cgf2) { 44 | unsigned int i = cgf1.gtos.size(); 45 | unsigned int j = cgf2.gtos.size(); 46 | 47 | double sum = 0; 48 | double norm1, norm2; 49 | 50 | for(unsigned int k = 0; k < i; k++) { 51 | for(unsigned int l = 0; l < j; l++) { 52 | norm1 = cgf1.gtos[k].norm; 53 | norm2 = cgf2.gtos[l].norm; 54 | sum += cgf1.gtos[k].c * cgf2.gtos[l].c * norm1 * norm2 * gto_kinetic(cgf1.gtos[k], cgf2.gtos[l]); 55 | } 56 | } 57 | 58 | return sum; 59 | } 60 | -------------------------------------------------------------------------------- /src/func.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * func.cpp -- This file is part of HFCXX. * 3 | * * 4 | * Copyright (C) 2012, Ivo Filot * 5 | * * 6 | * HFCXX is free software: * 7 | * you can redistribute it and/or modify it under the terms of the * 8 | * GNU General Public License as published by the Free Software * 9 | * Foundation, either version 3 of the License, or (at your option) * 10 | * any later version. * 11 | * * 12 | * HFCXX is distributed in the hope that it will be useful, * 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | * See the GNU General Public License for more details. * 16 | * * 17 | * You should have received a copy of the GNU General Public License * 18 | * along with this program. If not, see http://www.gnu.org/licenses/. * 19 | * * 20 | **************************************************************************/ 21 | 22 | #include "func.h" 23 | 24 | double sign(const double &a, const double &b) { 25 | return b >= 0 ? (a >= 0 ? a : -a) : (a >= 0 ? -a : a); 26 | } 27 | 28 | double sqr(const double x) { 29 | return x * x; 30 | } 31 | 32 | double min(const double &a, const double &b) { 33 | if(a > b) { 34 | return b; 35 | } else { 36 | return a; 37 | } 38 | } 39 | 40 | double max(const double &a, const double &b) { 41 | if(a < b) { 42 | return b; 43 | } else { 44 | return a; 45 | } 46 | } 47 | 48 | double abs(const double &x) { 49 | if(x < 0) { 50 | return -x; 51 | } else { 52 | return x; 53 | } 54 | } 55 | 56 | double binomial_prefactor(int s, int ia, int ib, double xpa, double xpb){ 57 | int t; 58 | double sum=0.; 59 | for (t=0; t 26 | 27 | #include "config.h" 28 | #include "gamma.h" 29 | #include "func.h" 30 | #include "vec3.h" 31 | #include "gto.h" 32 | #include "cgf.h" 33 | 34 | double cgf_repulsion(const CGF &cgf1, const CGF &cgf2, const CGF &cgf3, const CGF &cgf4); 35 | double gto_repulsion(const GTO >o1, const GTO >o2, const GTO >o3, const GTO >o4); 36 | 37 | double coulomb_repulsion(const Vec3 &a, const double &norma, const int la, const int ma, const int na, const double &alphaa, 38 | const Vec3 &b, const double &normb, const int lb, const int mb, const int nb, const double &alphab, 39 | const Vec3 &c, const double &normc, const int lc, const int mc, const int nc, const double &alphac, 40 | const Vec3 &d, const double &normd, const int ld, const int md, const int nd, const double &alphad); 41 | 42 | std::vector B_array(const int l1,const int l2,const int l3,const int l4, 43 | const double &p, const double &a, const double &b, const double &q, const double &c, const double &d, 44 | const double g1, const double g2, const double delta); 45 | 46 | double B_term(const int i1, const int i2, const int r1, const int r2, const int u, const int l1, const int l2, const int l3, const int l4, 47 | const double &px, const double &ax, const double &bx, const double &qx, const double &cx, const double &dx, const double &gamma1, 48 | const double &gamma2, const double &delta); 49 | 50 | double fB(const int i, const int l1, const int l2, const double &p, const double &a, const double &b, const int r, const double &q); 51 | double B0(int i, int r, double q); 52 | double fact_ratio2(const int a, const int b); 53 | 54 | const unsigned int teindex(unsigned int i, unsigned int j, unsigned int k, unsigned int l); 55 | 56 | #endif //_REPULSION_H 57 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #/************************************************************************** 2 | # CMakeLists.txt -- This file is part of HFCXX. * 3 | # * 4 | # Copyright (C) 2012, Ivo Filot * 5 | # * 6 | # HFCXX is free software: * 7 | # you can redistribute it and/or modify it under the terms of the * 8 | # GNU General Public License as published by the Free Software * 9 | # Foundation, either version 3 of the License, or (at your option) * 10 | # any later version. * 11 | # * 12 | # HFCXX is distributed in the hope that it will be useful, * 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | # See the GNU General Public License for more details. * 16 | # * 17 | # You should have received a copy of the GNU General Public License * 18 | # along with this program. If not, see http://www.gnu.org/licenses/. * 19 | # * 20 | #**************************************************************************/ 21 | 22 | # set minimum cmake requirements 23 | cmake_minimum_required(VERSION 2.8.12) 24 | project (hfcxx) 25 | 26 | # add custom directory to look for .cmake files 27 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/modules ) 28 | 29 | # Enable release build 30 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 31 | message(STATUS "Setting build type to 'Release' as none was specified.") 32 | set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) 33 | # Set the possible values of build type for cmake-gui 34 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") 35 | endif() 36 | 37 | # Configure header file 38 | configure_file("config.h.in" "config.h") 39 | 40 | # Check for OpenMP 41 | find_package(OpenMP) 42 | if (OPENMP_FOUND) 43 | option(HAS_OPENMP "OpenMP enabled" ON) 44 | set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") 45 | set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") 46 | endif() 47 | 48 | # find libcppunit for unit testing 49 | find_package(CPPUNIT REQUIRED) # for unit tests 50 | 51 | # Set include folders 52 | include_directories(${CMAKE_CURRENT_SOURCE_DIR} 53 | ${CMAKE_BINARY_DIR}) 54 | 55 | # Add sources 56 | file(GLOB SOURCES "*.cpp") 57 | list(REMOVE_ITEM SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp) 58 | add_library(hfcxxsources STATIC ${SOURCES}) 59 | 60 | # Set executable 61 | add_executable(hfcxx ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp) 62 | 63 | # Set C++17 64 | add_definitions(-std=c++17 -march=native) 65 | 66 | # Link libraries 67 | target_link_libraries(hfcxx hfcxxsources) 68 | 69 | if(NOT DISABLE_TEST) 70 | message("[USER] Performing unit tests") 71 | enable_testing () 72 | add_subdirectory("test") 73 | else() 74 | message("[USER] Testing routine disabled") 75 | endif() 76 | 77 | ### 78 | # Installing 79 | ## 80 | install (TARGETS hfcxx DESTINATION bin) 81 | -------------------------------------------------------------------------------- /src/basis.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * basis.cpp -- This file is part of HFCXX. * 3 | * * 4 | * Copyright (C) 2012, Ivo Filot * 5 | * * 6 | * HFCXX is free software: * 7 | * you can redistribute it and/or modify it under the terms of the * 8 | * GNU General Public License as published by the Free Software * 9 | * Foundation, either version 3 of the License, or (at your option) * 10 | * any later version. * 11 | * * 12 | * HFCXX is distributed in the hope that it will be useful, * 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | * See the GNU General Public License for more details. * 16 | * * 17 | * You should have received a copy of the GNU General Public License * 18 | * along with this program. If not, see http://www.gnu.org/licenses/. * 19 | * * 20 | **************************************************************************/ 21 | 22 | #include "basis.h" 23 | 24 | Basis::Basis() { 25 | basisset = "undefined"; 26 | } 27 | 28 | Basis::Basis(std::string basissett) { 29 | basisset = basissett; 30 | } 31 | 32 | void Basis::setType(std::string basissett) { 33 | basisset = basissett; 34 | } 35 | 36 | void Basis::set(std::string type, unsigned int z, Vec3 r) { 37 | gtos.clear(); 38 | if(basisset.compare("sto-3g") == 0) { 39 | addGTOs_sto3g(type, z, r); 40 | } else if(basisset.compare("sto-6g") == 0) { 41 | addGTOs_sto6g(type, z, r); 42 | } else { 43 | std::cout << "Unrecognized basis set" << std::endl; 44 | exit(1); 45 | } 46 | }; 47 | 48 | std::vector Basis::getGTOs() const{ 49 | return gtos; 50 | } 51 | 52 | void Basis::addGTO_s(double alpha, double c, Vec3 r) { 53 | gtos.push_back(GTO(c, r, alpha, 0,0,0)); 54 | } 55 | 56 | void Basis::addGTO_px(double alpha, double c, Vec3 r) { 57 | gtos.push_back(GTO(c, r, alpha, 1,0,0)); 58 | } 59 | 60 | void Basis::addGTO_py(double alpha, double c, Vec3 r) { 61 | gtos.push_back(GTO(c, r, alpha, 0,1,0)); 62 | } 63 | 64 | void Basis::addGTO_pz(double alpha, double c, Vec3 r) { 65 | gtos.push_back(GTO(c, r, alpha, 0,0,1)); 66 | } 67 | 68 | void Basis::addGTO_dx2(double alpha, double c, Vec3 r) { 69 | gtos.push_back(GTO(c, r, alpha, 2,0,0)); 70 | } 71 | 72 | void Basis::addGTO_dxy(double alpha, double c, Vec3 r) { 73 | gtos.push_back(GTO(c, r, alpha, 1,1,0)); 74 | } 75 | 76 | void Basis::addGTO_dxz(double alpha, double c, Vec3 r) { 77 | gtos.push_back(GTO(c, r, alpha, 1,0,1)); 78 | } 79 | 80 | void Basis::addGTO_dy2(double alpha, double c, Vec3 r) { 81 | gtos.push_back(GTO(c, r, alpha, 0,2,0)); 82 | } 83 | 84 | void Basis::addGTO_dyz(double alpha, double c, Vec3 r) { 85 | gtos.push_back(GTO(c, r, alpha, 0,1,1)); 86 | } 87 | 88 | void Basis::addGTO_dz2(double alpha, double c, Vec3 r) { 89 | gtos.push_back(GTO(c, r, alpha, 0,0,2)); 90 | } 91 | -------------------------------------------------------------------------------- /src/cmake/modules/FindCPPUNIT.cmake: -------------------------------------------------------------------------------- 1 | #/************************************************************************** 2 | # CMakeLists.txt -- This file is part of HFCXX. * 3 | # * 4 | # Copyright (C) 2012, Ivo Filot * 5 | # * 6 | # HFCXX is free software: * 7 | # you can redistribute it and/or modify it under the terms of the * 8 | # GNU General Public License as published by the Free Software * 9 | # Foundation, either version 3 of the License, or (at your option) * 10 | # any later version. * 11 | # * 12 | # HFCXX is distributed in the hope that it will be useful, * 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | # See the GNU General Public License for more details. * 16 | # * 17 | # You should have received a copy of the GNU General Public License * 18 | # along with this program. If not, see http://www.gnu.org/licenses/. * 19 | # * 20 | #**************************************************************************/ 21 | 22 | # 23 | # Find the CppUnit includes and library 24 | # 25 | # This module defines 26 | # CPPUNIT_INCLUDE_DIR, where to find tiff.h, etc. 27 | # CPPUNIT_LIBRARIES, the libraries to link against to use CppUnit. 28 | # CPPUNIT_FOUND, If false, do not try to use CppUnit. 29 | 30 | # also defined, but not for general use are 31 | # CPPUNIT_LIBRARY, where to find the CppUnit library. 32 | # CPPUNIT_DEBUG_LIBRARY, where to find the CppUnit library in debug 33 | # mode. 34 | 35 | SET(CPPUNIT_FOUND "NO") 36 | 37 | FIND_PATH(CPPUNIT_INCLUDE_DIR cppunit/TestCase.h /usr/local/include /usr/include ../../../Libraries/cppunit-1.14.0-win-x64/include) 38 | 39 | # With Win32, important to have both 40 | IF(WIN32) 41 | FIND_LIBRARY(CPPUNIT_LIBRARY cppunit 42 | ${CPPUNIT_INCLUDE_DIR}/../lib 43 | /usr/local/lib 44 | /usr/lib) 45 | FIND_LIBRARY(CPPUNIT_DEBUG_LIBRARY cppunitd 46 | ${CPPUNIT_INCLUDE_DIR}/../lib 47 | /usr/local/lib 48 | /usr/lib) 49 | ELSE(WIN32) 50 | # On unix system, debug and release have the same name 51 | FIND_LIBRARY(CPPUNIT_LIBRARY cppunit 52 | ${CPPUNIT_INCLUDE_DIR}/../lib 53 | /usr/local/lib 54 | /usr/lib) 55 | FIND_LIBRARY(CPPUNIT_DEBUG_LIBRARY cppunit 56 | ${CPPUNIT_INCLUDE_DIR}/../lib 57 | /usr/local/lib 58 | /usr/lib) 59 | ENDIF(WIN32) 60 | 61 | IF(CPPUNIT_INCLUDE_DIR) 62 | IF(CPPUNIT_LIBRARY) 63 | SET(CPPUNIT_FOUND "YES") 64 | SET(CPPUNIT_LIBRARIES ${CPPUNIT_LIBRARY} ${CMAKE_DL_LIBS}) 65 | SET(CPPUNIT_DEBUG_LIBRARIES ${CPPUNIT_DEBUG_LIBRARY} ${CMAKE_DL_LIBS}) 66 | ELSE (CPPUNIT_LIBRARY) 67 | IF (CPPUNIT_FIND_REQUIRED) 68 | MESSAGE(SEND_ERROR "Could not find library CppUnit.") 69 | ENDIF (CPPUNIT_FIND_REQUIRED) 70 | ENDIF(CPPUNIT_LIBRARY) 71 | ELSE(CPPUNIT_INCLUDE_DIR) 72 | IF (CPPUNIT_FIND_REQUIRED) 73 | MESSAGE(SEND_ERROR "Could not find library CppUnit.") 74 | ENDIF(CPPUNIT_FIND_REQUIRED) 75 | ENDIF(CPPUNIT_INCLUDE_DIR) 76 | 77 | -------------------------------------------------------------------------------- /src/nuclear.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * nuclear.cpp -- This file is part of HFCXX. * 3 | * * 4 | * Copyright (C) 2012, Ivo Filot * 5 | * * 6 | * HFCXX is free software: * 7 | * you can redistribute it and/or modify it under the terms of the * 8 | * GNU General Public License as published by the Free Software * 9 | * Foundation, either version 3 of the License, or (at your option) * 10 | * any later version. * 11 | * * 12 | * HFCXX is distributed in the hope that it will be useful, * 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | * See the GNU General Public License for more details. * 16 | * * 17 | * You should have received a copy of the GNU General Public License * 18 | * along with this program. If not, see http://www.gnu.org/licenses/. * 19 | * * 20 | **************************************************************************/ 21 | 22 | #include "nuclear.h" 23 | 24 | double cgf_nuclear(CGF &cgf1, CGF &cgf2, const Atom &a) { 25 | unsigned int i = cgf1.gtos.size(); 26 | unsigned int j = cgf2.gtos.size(); 27 | 28 | double sum = 0; 29 | 30 | #ifdef HAS_OPENMP 31 | #pragma omp parallel for collapse(2) reduction ( + : sum) 32 | #endif 33 | for(unsigned int k = 0; k < i; k++) { 34 | for(unsigned int l = 0; l < j; l++) { 35 | sum += cgf1.gtos[k].c * cgf2.gtos[l].c * gto_nuclear(cgf1.gtos[k], cgf2.gtos[l], a.gr() ); 36 | } 37 | } 38 | 39 | return sum * a.nucl_chg(); 40 | } 41 | 42 | double gto_nuclear(GTO >o1, GTO >o2, const Vec3 &c) { 43 | 44 | return nuclear(gto1.r, gto1.norm, gto1.l, gto1.m, gto1.n, gto1.alpha, gto2.r, gto2.norm, gto2.l, gto2.m, gto2.n, gto2.alpha, c); 45 | } 46 | 47 | double nuclear(const Vec3 a, double norm1, int l1, int m1, int n1, double alpha1, const Vec3 b, double norm2, int l2, int m2, int n2, double alpha2, const Vec3 c) { 48 | static const double pi = 3.14159265359; 49 | double gamma = alpha1 + alpha2; 50 | 51 | Vec3 p = gaussian_product_center(alpha1, a, alpha2, b); 52 | double rab2 = dist2(a,b); 53 | double rcp2 = dist2(c,p); 54 | 55 | std::vector ax = A_array(l1,l2,p.getx()-a.getx(),p.getx()-b.getx(),p.getx()-c.getx(),gamma); 56 | std::vector ay = A_array(m1,m2,p.gety()-a.gety(),p.gety()-b.gety(),p.gety()-c.gety(),gamma); 57 | std::vector az = A_array(n1,n2,p.getz()-a.getz(),p.getz()-b.getz(),p.getz()-c.getz(),gamma); 58 | 59 | double sum = 0.0; 60 | 61 | for(int i=0; i<=l1+l2;i++) { 62 | for(int j=0; j<=m1+m2;j++) { 63 | for(int k=0; k<=n1+n2;k++) { 64 | sum += ax[i] * ay[j] * az[k] * Fgamma(i+j+k,rcp2*gamma); 65 | } 66 | } 67 | } 68 | 69 | return -norm1 * norm2 * 2 * pi / gamma * exp(-alpha1*alpha2*rab2/gamma) * sum; 70 | } 71 | 72 | std::vector A_array(const int l1, const int l2, const double pa, const double pb, const double cp, const double g) { 73 | int imax = l1 + l2 + 1; 74 | std::vector arrA(imax, 0); 75 | 76 | for(int i=0; i 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "config.h" 33 | #include "molecule.h" 34 | #include "clock.h" 35 | #include "matrix.h" 36 | #include "canorg.h" 37 | #include "kinetic.h" 38 | #include "overlap.h" 39 | #include "nuclear.h" 40 | #include "repulsion.h" 41 | #include "eigsym.h" 42 | #include "output.h" 43 | 44 | class HF{ 45 | private: 46 | Molecule mol; 47 | unsigned int nrorbs; 48 | unsigned int nrat; 49 | unsigned int nrelec; 50 | unsigned int cntstep; 51 | unsigned int bss; 52 | Clock clock; 53 | std::vector orblist; 54 | std::vector orbitals; 55 | Hmatrix H; /* hamiltonian matrix */ 56 | Smatrix S; /* overlap matrix */ 57 | Tmatrix T; /* kinetic matrix */ 58 | Pmatrix P; /* density matrix */ 59 | Pmatrix Pnew; /* density matrix */ 60 | Gmatrix G; /* P + TE matrix */ 61 | Fmatrix F; /* Fock matrix */ 62 | Fmatrix Fp; /* Fock matrix */ 63 | Xmatrix X; /* X matrix */ 64 | Xmatrix Xp; /* X matrix */ 65 | Cmatrix C; /* Coefficient matrix */ 66 | Ccmatrix Cc; /* Cprime matrix */ 67 | std::vector V; /* set of nuclear attraction matrices */ 68 | std::vector TE; /* set of double electron integrals */ 69 | std::vector energies; /* set of energies of each iterative step */ 70 | std::vector itertimes; /* set of iteration times */ 71 | std::vector molorben; /* energy of molecular orbitals */ 72 | double energy; /* current energy in the iterative loop */ 73 | double nucl_repul; /* nuclear repulsion energy */ 74 | double alpha; /* damping parameter for the iterative SCF cycles */ 75 | Output out; 76 | 77 | public: 78 | bool debug; /* set debug to either true or false */ 79 | HF(); /* default constructor */ 80 | void molecule(const Molecule &moll); 81 | void listorbs() const; 82 | void run(); 83 | 84 | inline double get_energy() const { 85 | return this->energy; 86 | } 87 | 88 | /* iterative step functions */ 89 | private: 90 | void step(); 91 | void setup(); 92 | unsigned int iterate(); 93 | 94 | /* energy functions */ 95 | double calcen(); 96 | double calcnuclrepul(); 97 | 98 | /* special output functions for debugging purposes */ 99 | public: 100 | void printS() const; 101 | void printX() const; 102 | void printT() const; 103 | void printG() const; 104 | void printF() const; 105 | void printFp() const; 106 | void printH() const; 107 | void printV() const; 108 | void printTE() const; 109 | void molorbs() const; 110 | }; 111 | 112 | #endif //_HF_H 113 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | When contributing to this repository, please first discuss the change you wish to make via issue, 4 | email, or any other method with the owners of this repository before making a change. 5 | 6 | Please note we have a code of conduct, please follow it in all your interactions with the project. 7 | 8 | ## Pull Request Process 9 | 10 | 1. Ensure any install or build dependencies are removed before the end of the layer when doing a 11 | build. 12 | 2. Update the README.md with details of changes to the interface, this includes new environment 13 | variables, exposed ports, useful file locations and container parameters. 14 | 3. Increase the version numbers in any examples files and the README.md to the new version that this 15 | Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/). 16 | 4. You may merge the Pull Request in once you have the sign-off of two other developers, or if you 17 | do not have permission to do that, you may request the second reviewer to merge it for you. 18 | 19 | ## Code of Conduct 20 | 21 | ### Our Pledge 22 | 23 | In the interest of fostering an open and welcoming environment, we as 24 | contributors and maintainers pledge to making participation in our project and 25 | our community a harassment-free experience for everyone, regardless of age, body 26 | size, disability, ethnicity, gender identity and expression, level of experience, 27 | nationality, personal appearance, race, religion, or sexual identity and 28 | orientation. 29 | 30 | ### Our Standards 31 | 32 | Examples of behavior that contributes to creating a positive environment 33 | include: 34 | 35 | * Using welcoming and inclusive language 36 | * Being respectful of differing viewpoints and experiences 37 | * Gracefully accepting constructive criticism 38 | * Focusing on what is best for the community 39 | * Showing empathy towards other community members 40 | 41 | Examples of unacceptable behavior by participants include: 42 | 43 | * The use of sexualized language or imagery and unwelcome sexual attention or 44 | advances 45 | * Trolling, insulting/derogatory comments, and personal or political attacks 46 | * Public or private harassment 47 | * Publishing others' private information, such as a physical or electronic 48 | address, without explicit permission 49 | * Other conduct which could reasonably be considered inappropriate in a 50 | professional setting 51 | 52 | ### Our Responsibilities 53 | 54 | Project maintainers are responsible for clarifying the standards of acceptable 55 | behavior and are expected to take appropriate and fair corrective action in 56 | response to any instances of unacceptable behavior. 57 | 58 | Project maintainers have the right and responsibility to remove, edit, or 59 | reject comments, commits, code, wiki edits, issues, and other contributions 60 | that are not aligned to this Code of Conduct, or to ban temporarily or 61 | permanently any contributor for other behaviors that they deem inappropriate, 62 | threatening, offensive, or harmful. 63 | 64 | ### Scope 65 | 66 | This Code of Conduct applies both within project spaces and in public spaces 67 | when an individual is representing the project or its community. Examples of 68 | representing a project or community include using an official project e-mail 69 | address, posting via an official social media account, or acting as an appointed 70 | representative at an online or offline event. Representation of a project may be 71 | further defined and clarified by project maintainers. 72 | 73 | ### Enforcement 74 | 75 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 76 | reported by contacting the project team at [INSERT EMAIL ADDRESS]. All 77 | complaints will be reviewed and investigated and will result in a response that 78 | is deemed necessary and appropriate to the circumstances. The project team is 79 | obligated to maintain confidentiality with regard to the reporter of an incident. 80 | Further details of specific enforcement policies may be posted separately. 81 | 82 | Project maintainers who do not follow or enforce the Code of Conduct in good 83 | faith may face temporary or permanent repercussions as determined by other 84 | members of the project's leadership. 85 | 86 | ### Attribution 87 | 88 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 89 | available at [http://contributor-covenant.org/version/1/4][version] 90 | 91 | [homepage]: http://contributor-covenant.org 92 | [version]: http://contributor-covenant.org/version/1/4/ 93 | -------------------------------------------------------------------------------- /src/molecule.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * molecule.cpp -- This file is part of HFCXX. * 3 | * * 4 | * Copyright (C) 2012, Ivo Filot * 5 | * * 6 | * HFCXX is free software: * 7 | * you can redistribute it and/or modify it under the terms of the * 8 | * GNU General Public License as published by the Free Software * 9 | * Foundation, either version 3 of the License, or (at your option) * 10 | * any later version. * 11 | * * 12 | * HFCXX is distributed in the hope that it will be useful, * 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | * See the GNU General Public License for more details. * 16 | * * 17 | * You should have received a copy of the GNU General Public License * 18 | * along with this program. If not, see http://www.gnu.org/licenses/. * 19 | * * 20 | **************************************************************************/ 21 | 22 | #include "molecule.h" 23 | 24 | /* default constructor */ 25 | Molecule::Molecule() { 26 | nrat = 0; 27 | } 28 | 29 | void Molecule::addAtom(const Atom &at) { 30 | atoms.push_back(at); 31 | nrat++; 32 | } 33 | 34 | void Molecule::addAtom(const std::string symbolin, const double xx, const double yy, const double zz) { 35 | Atom at(symbolin, xx, yy, zz, basis); 36 | atoms.push_back(at); 37 | nrat++; 38 | } 39 | 40 | void Molecule::addAtom(const unsigned int Zz, const double xx, const double yy, const double zz) { 41 | Atom at(Zz, xx, yy, zz, basis); 42 | atoms.push_back(at); 43 | nrat++; 44 | } 45 | 46 | std::ostream & operator << (std::ostream &os, const Molecule &rhs) { 47 | for(unsigned int i=0; i lines; 65 | std::vector pieces; 66 | fp.readFile(lines); 67 | std::string line, dat, units; 68 | unsigned int pos, nrat; 69 | double un; 70 | 71 | /* grab basisset from first line 1 */ 72 | line = strtrim(lines[0]); 73 | pos = strpos(line,"="); 74 | dat = substr(line,pos+1); 75 | basisset = strtrim(dat); 76 | basis.setType(basisset); 77 | //std::cout << basisset << std::endl; 78 | 79 | /* grab charge from line 2 */ 80 | line = strtrim(lines[1]); 81 | pos = strpos(line,"="); 82 | dat = substr(line,pos+1); 83 | charge = atoi(strtrim(dat).c_str() ); 84 | //std::cout << charge << std::endl; 85 | 86 | /* grab number of atoms from line 3 */ 87 | line = strtrim(lines[2]); 88 | pos = strpos(line,"="); 89 | dat = substr(line,pos+1); 90 | nrat = atoi(strtrim(dat).c_str() ); 91 | //std::cout << nrat << std::endl; 92 | 93 | /* grab length unit from first line 4 */ 94 | line = strtrim(lines[3]); 95 | pos = strpos(line,"="); 96 | dat = substr(line,pos+1); 97 | units = strtrim(dat); 98 | if(units.compare("bohr")==0) { 99 | un = 1; 100 | } 101 | if(units.compare("angstrom")==0) { 102 | un = 1.0 / 0.52917721092; 103 | } 104 | //std::cout << units << std::endl; 105 | 106 | double x, y, z; 107 | std::string element; 108 | for(unsigned int i=0; i explode( const string &delimiter, const string &str) 112 | { 113 | vector arr; 114 | 115 | int strleng = str.length(); 116 | int delleng = delimiter.length(); 117 | if (delleng==0) 118 | return arr;//no change 119 | 120 | int i=0; 121 | int k=0; 122 | while( i symbols; 60 | 61 | symbols.push_back("H"); 62 | symbols.push_back("He"); 63 | symbols.push_back("Li"); 64 | symbols.push_back("Be"); 65 | symbols.push_back("B"); 66 | symbols.push_back("C"); 67 | symbols.push_back("N"); 68 | symbols.push_back("O"); 69 | symbols.push_back("F"); 70 | symbols.push_back("Ne"); 71 | 72 | return symbols[Z-1]; 73 | } 74 | 75 | const double Atom::x() const { 76 | return r.getx(); 77 | } 78 | 79 | const double Atom::y() const { 80 | return r.gety(); 81 | } 82 | 83 | const double Atom::z() const { 84 | return r.getz(); 85 | } 86 | 87 | const Vec3 Atom::gr() const { 88 | return r; 89 | } 90 | 91 | unsigned int Atom::e2z(const std::string &symbol) const { 92 | if(symbol.compare("H") == 0) { 93 | return 1; 94 | } 95 | if(symbol.compare("He") == 0) { 96 | return 2; 97 | } 98 | if(symbol.compare("Li") == 0) { 99 | return 3; 100 | } 101 | if(symbol.compare("Be") == 0) { 102 | return 4; 103 | } 104 | if(symbol.compare("B") == 0) { 105 | return 5; 106 | } 107 | if(symbol.compare("C") == 0) { 108 | return 6; 109 | } 110 | if(symbol.compare("N") == 0) { 111 | return 7; 112 | } 113 | if(symbol.compare("O") == 0) { 114 | return 8; 115 | } 116 | if(symbol.compare("F") == 0) { 117 | return 9; 118 | } 119 | if(symbol.compare("Ne") == 0) { 120 | return 10; 121 | } 122 | 123 | return 0; 124 | } 125 | 126 | std::string Atom::z2e(const unsigned int &z) const { 127 | if(z==1) { 128 | return "H"; 129 | } 130 | if(z==2) { 131 | return "He"; 132 | } 133 | if(z==3) { 134 | return "Li"; 135 | } 136 | if(z==4) { 137 | return "Be"; 138 | } 139 | if(z==5) { 140 | return "B"; 141 | } 142 | if(z==6) { 143 | return "C"; 144 | } 145 | if(z==7) { 146 | return "N"; 147 | } 148 | if(z==8) { 149 | return "O"; 150 | } 151 | if(z==9) { 152 | return "F"; 153 | } 154 | if(z==10) { 155 | return "Ne"; 156 | } 157 | 158 | return "undefined"; 159 | } 160 | 161 | void Atom::addWavefunctions(Basis &basis){ 162 | 163 | if(Z==1 || Z==2) { 164 | basis.set("1s", Z,r); 165 | wavefunctions.push_back(CGF("1s", Z, r, basis.getGTOs() )); 166 | nrwav = 1; 167 | } 168 | if(Z==3 || Z==4) { 169 | basis.set("1s", Z,r); 170 | wavefunctions.push_back(CGF("1s", Z, r, basis.getGTOs() )); 171 | basis.set("2s", Z,r); 172 | wavefunctions.push_back(CGF("2s", Z, r, basis.getGTOs() )); 173 | nrwav = 2; 174 | } 175 | if(Z>=5 && Z<=10) { 176 | basis.set("1s", Z,r); 177 | wavefunctions.push_back(CGF("1s", Z, r, basis.getGTOs() )); 178 | basis.set("2s", Z,r); 179 | wavefunctions.push_back(CGF("2s", Z, r, basis.getGTOs() )); 180 | basis.set("2px", Z,r); 181 | wavefunctions.push_back(CGF("2px", Z, r, basis.getGTOs() )); 182 | basis.set("2py", Z,r); 183 | wavefunctions.push_back(CGF("2py", Z, r, basis.getGTOs() )); 184 | basis.set("2pz", Z,r); 185 | wavefunctions.push_back(CGF("2pz", Z, r, basis.getGTOs() )); 186 | nrwav = 5; 187 | } 188 | } 189 | 190 | const CGF& Atom::operator[](const unsigned int i) const { 191 | return wavefunctions[i]; 192 | } 193 | 194 | const unsigned int Atom::nrorbs() const { 195 | return nrwav; 196 | } 197 | 198 | const unsigned int Atom::nrelecs() const { 199 | return nrelec; 200 | } 201 | 202 | const unsigned int Atom::nucl_chg() const { 203 | return Z; 204 | } 205 | -------------------------------------------------------------------------------- /src/gamma.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * gamma.cpp -- This file is part of HFCXX. * 3 | * * 4 | * Copyright (C) 2012, Ivo Filot * 5 | * * 6 | * HFCXX is free software: * 7 | * you can redistribute it and/or modify it under the terms of the * 8 | * GNU General Public License as published by the Free Software * 9 | * Foundation, either version 3 of the License, or (at your option) * 10 | * any later version. * 11 | * * 12 | * HFCXX is distributed in the hope that it will be useful, * 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | * See the GNU General Public License for more details. * 16 | * * 17 | * You should have received a copy of the GNU General Public License * 18 | * along with this program. If not, see http://www.gnu.org/licenses/. * 19 | * * 20 | **************************************************************************/ 21 | 22 | /* 23 | * References: 24 | * [1] Numerical Recipes 25 | * William H. Press, Saul A. Teukolsky, William T., 26 | * Vetterling and Brian P. Flannery 27 | * 3rd edition page 261 28 | * ISBN-13: 978-0521880688 29 | * 30 | * The functions below have all been obtained using ref [1] 31 | */ 32 | 33 | #include "gamma.h" 34 | 35 | double Fgamma(const double m, double x) { 36 | double tiny = 0.00000001; 37 | x = std::max(std::abs(x),tiny); 38 | double val = gamm_inc(m+0.5,x); 39 | return 0.5 * pow(x,-m - 0.5) * val; 40 | } 41 | 42 | double gamm_inc(const double a, const double x) { 43 | double gammap = gammp(a,x); 44 | double gln = gammln(a); 45 | return exp(gln) * gammap; 46 | } 47 | 48 | double gammp(const double a, double x) { 49 | static const int ASWITCH = 100; 50 | 51 | if(x < 0.0 || a <= 0.0) { 52 | std::cout << "Bad value in Fgamma!"; 53 | return 0.0; 54 | } 55 | 56 | if(x == 0.0) { 57 | return 0.0; 58 | } else if(a >= ASWITCH) { 59 | return gammpapprox(a,x,1); /* use quadrature */ 60 | } else if(x < a + 1.0) { 61 | return gser(a,x); /* use the series expansion */ 62 | } else { 63 | return 1.0 - gcf(a,x); /* use the continued fraction expansion */ 64 | } 65 | } 66 | 67 | double gser(const double a, const double x) { 68 | double EPS = std::numeric_limits::epsilon(); 69 | 70 | double sum, del, ap; 71 | double gln = gammln(a); 72 | ap = a; 73 | del = sum = 1.0/a; 74 | for(;;) { 75 | ++ap; 76 | del *= x / ap; 77 | sum += del; 78 | if(fabs(del) < fabs(sum)*EPS) { 79 | return sum * exp(-x +a*log(x)-gln); 80 | } 81 | } 82 | } 83 | 84 | double gammln(const double xx) { 85 | int j; 86 | double x, tmp, y, ser; 87 | static const double cof[14]={57.1562356658629235,-59.5979603554754912, 88 | 14.1360979747417471,-0.491913816097620199,.339946499848118887e-4, 89 | .465236289270485756e-4,-.983744753048795646e-4,.158088703224912494e-3, 90 | -.210264441724104883e-3,.217439618115212643e-3,-.164318106536763890e-3, 91 | .844182239838527433e-4,-.261908384015814087e-4,.368991826595316234e-5}; 92 | if(xx <= 0) { 93 | std::cout << "Bad argument in gammln"; 94 | return 0.0; 95 | } 96 | 97 | y = x = xx; 98 | tmp = x+5.24218750000000000; 99 | tmp = (x+0.5)*log(tmp)-tmp; 100 | ser = 0.999999999999997092; 101 | for (j=0;j<14;j++) ser += cof[j]/++y; 102 | return tmp+log(2.5066282746310005*ser/x); 103 | } 104 | 105 | double gcf(const double a, const double x) { 106 | double EPS = std::numeric_limits::epsilon(); 107 | double FPMIN = std::numeric_limits::min() / EPS; 108 | 109 | int i; 110 | double an, b, c, d, del, h; 111 | double gln = gammln(a); 112 | b = x + 1.0 - a; 113 | c = 1.0 / FPMIN; 114 | d = 1.0 /b; 115 | h = d; 116 | for(i=1;;i++) { 117 | an = -i * (i-a); 118 | b += 2.0; 119 | d = an * d + b; 120 | if(fabs(d) < FPMIN) d = FPMIN; 121 | c = b + an /c; 122 | if(fabs(c) < FPMIN) c = FPMIN; 123 | d = 1.0 / d; 124 | del = d * c; 125 | h *= del; 126 | if(fabs(del - 1.0) <= EPS) break; 127 | } 128 | 129 | return exp(-x + a * log(x) - gln)*h; 130 | } 131 | 132 | double gammpapprox(double a, double x, int psig) { 133 | static const int ngau = 18; 134 | 135 | double y[18] = {0.0021695375159141994, 136 | 0.011413521097787704,0.027972308950302116,0.051727015600492421, 137 | 0.082502225484340941, 0.12007019910960293,0.16415283300752470, 138 | 0.21442376986779355, 0.27051082840644336, 0.33199876341447887, 139 | 0.39843234186401943, 0.46931971407375483, 0.54413605556657973, 140 | 0.62232745288031077, 0.70331500465597174, 0.78649910768313447, 141 | 0.87126389619061517, 0.95698180152629142}; 142 | 143 | double w[18] = {0.0055657196642445571, 144 | 0.012915947284065419,0.020181515297735382,0.027298621498568734, 145 | 0.034213810770299537,0.040875750923643261,0.047235083490265582, 146 | 0.053244713977759692,0.058860144245324798,0.064039797355015485, 147 | 0.068745323835736408,0.072941885005653087,0.076598410645870640, 148 | 0.079687828912071670,0.082187266704339706,0.084078218979661945, 149 | 0.085346685739338721,0.085983275670394821}; 150 | 151 | int j; 152 | double xu, t, sum, ans; 153 | double a1 = a - 1.0, lna1 = log(a1), sqrta1 = sqrt(a1); 154 | double gln = gammln(a); 155 | 156 | if(x > a1) xu = std::max(a1 + 11.5 * sqrta1, x + 6.0 * sqrta1); 157 | else xu = std::max(0., std::min(a1 - 7.5 * sqrta1, x - 5.0 * sqrta1)); 158 | sum = 0; 159 | 160 | for(j=0; j < ngau; j++) { 161 | t = x + (xu-x)*y[j]; 162 | sum += w[j] * exp(-(t-a1)+a1*(log(t)-lna1)); 163 | } 164 | 165 | ans = sum * (xu-x)*exp(a1*(lna1-1.)-gln); 166 | return (psig?(ans>0.0? 1.0-ans:-ans):(ans>=0.0? ans:1.0+ans)); 167 | } 168 | -------------------------------------------------------------------------------- /src/repulsion.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * repulsion.cpp -- This file is part of HFCXX. * 3 | * * 4 | * Copyright (C) 2012, Ivo Filot * 5 | * * 6 | * HFCXX is free software: * 7 | * you can redistribute it and/or modify it under the terms of the * 8 | * GNU General Public License as published by the Free Software * 9 | * Foundation, either version 3 of the License, or (at your option) * 10 | * any later version. * 11 | * * 12 | * HFCXX is distributed in the hope that it will be useful, * 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | * See the GNU General Public License for more details. * 16 | * * 17 | * You should have received a copy of the GNU General Public License * 18 | * along with this program. If not, see http://www.gnu.org/licenses/. * 19 | * * 20 | **************************************************************************/ 21 | 22 | #include "repulsion.h" 23 | 24 | double cgf_repulsion(const CGF &cgf1,const CGF &cgf2,const CGF &cgf3,const CGF &cgf4) { 25 | double sum = 0; 26 | 27 | int size1 = cgf1.gtos.size(); 28 | int size2 = cgf2.gtos.size(); 29 | int size3 = cgf3.gtos.size(); 30 | int size4 = cgf4.gtos.size(); 31 | 32 | #ifdef HAS_OPENMP 33 | #pragma omp parallel for collapse(4) reduction ( + : sum) 34 | #endif 35 | for(int i=0; i< size1; i++) { 36 | for(int j=0; j< size2; j++) { 37 | for(int k=0; k < size3; k++) { 38 | for(int l=0; l < size4; l++) { 39 | double pre = cgf1.gtos[i].c * cgf2.gtos[j].c * cgf3.gtos[k].c * cgf4.gtos[l].c; 40 | sum += pre * gto_repulsion(cgf1.gtos[i],cgf2.gtos[j],cgf3.gtos[k],cgf4.gtos[l]); 41 | } 42 | } 43 | } 44 | } 45 | 46 | return sum; 47 | } 48 | 49 | double gto_repulsion(const GTO >o1, const GTO >o2, const GTO >o3, const GTO >o4) { 50 | 51 | return coulomb_repulsion(gto1.r, gto1.norm, gto1.l, gto1.m, gto1.n, gto1.alpha, 52 | gto2.r, gto2.norm, gto2.l, gto2.m, gto2.n, gto2.alpha, 53 | gto3.r, gto3.norm, gto3.l, gto3.m, gto3.n, gto3.alpha, 54 | gto4.r, gto4.norm, gto4.l, gto4.m, gto4.n, gto4.alpha); 55 | } 56 | 57 | double coulomb_repulsion(const Vec3 &a, const double &norma, const int la, const int ma, const int na, const double &alphaa, 58 | const Vec3 &b, const double &normb, const int lb, const int mb, const int nb, const double &alphab, 59 | const Vec3 &c, const double &normc, const int lc, const int mc, const int nc, const double &alphac, 60 | const Vec3 &d, const double &normd, const int ld, const int md, const int nd, const double &alphad) { 61 | 62 | static const double pi = 3.14159265359; 63 | double rab2 = dist2(a,b); 64 | double rcd2 = dist2(c,d); 65 | 66 | Vec3 p = gaussian_product_center(alphaa, a, alphab, b); 67 | Vec3 q = gaussian_product_center(alphac, c, alphad, d); 68 | 69 | double rpq2 = dist2(p,q); 70 | 71 | double gamma1 = alphaa + alphab; 72 | double gamma2 = alphac + alphad; 73 | double delta = 0.25 * (1.0 / gamma1 + 1.0 / gamma2); 74 | 75 | std::vector bx = B_array(la, lb, lc, ld, p.getx(), a.getx(), b.getx(), q.getx(), c.getx(), d.getx(), gamma1, gamma2, delta); 76 | std::vector by = B_array(ma, mb, mc, md, p.gety(), a.gety(), b.gety(), q.gety(), c.gety(), d.gety(), gamma1, gamma2, delta); 77 | std::vector bz = B_array(na, nb, nc, nd, p.getz(), a.getz(), b.getz(), q.getz(), c.getz(), d.getz(), gamma1, gamma2, delta); 78 | 79 | double sum = 0.0; 80 | for(int i=0; i<=(la+lb+lc+ld); i++) { 81 | for(int j=0; j<=(ma+mb+mc+md); j++) { 82 | for(int k=0; k<=(na+nb+nc+nd); k++) { 83 | sum += bx[i]*by[j]*bz[k]*Fgamma(i+j+k,0.25*rpq2/delta); 84 | } 85 | } 86 | } 87 | 88 | return 2*pow(pi,2.5)/(gamma1*gamma2*sqrt(gamma1+gamma2))* 89 | exp(-alphaa*alphab*rab2/gamma1)* 90 | exp(-alphac*alphad*rcd2/gamma2)*sum*norma*normb*normc*normd; 91 | } 92 | 93 | std::vector B_array(const int l1,const int l2,const int l3,const int l4, 94 | const double &p, const double &a, const double &b, const double &q, const double &c, const double &d, 95 | const double g1, const double g2, const double delta) { 96 | 97 | int imax = l1 + l2 + l3 + l4 + 1; 98 | std::vector arrB(imax,0); 99 | 100 | for(int i1=0; i1 &molorben, const std::vector &orblist, const MatDoub &C, unsigned int nrelec) { 129 | std::stringstream str; 130 | unsigned int w = 33; 131 | 132 | unsigned int nrorbs = orblist.size(); 133 | str << std::setw(w) << std::right << "***********************" << std::endl; 134 | str << std::setw(w) << std::right << "* *" << std::endl; 135 | str << std::setw(w) << std::right << "* ORBITALS *" << std::endl; 136 | str << std::setw(w) << std::right << "* *" << std::endl; 137 | str << std::setw(w) << std::right << "***********************" << std::endl; 138 | str << std::endl; 139 | 140 | for(unsigned int i=0; i 26 | #include 27 | #include 28 | 29 | template 30 | class Matrix { 31 | private: 32 | int nn; //number of rows 33 | int mm; //number of columns 34 | T **v; //pointer to pointer of type T 35 | public: 36 | Matrix(); // Default constructor 37 | Matrix(int n, int m); // Construct m x n matrix with value zero 38 | Matrix(int n, int m, const T &a); // Construct m x n matrix with value a 39 | Matrix(int n, int m, const T *a); // Construct m x n array using array a 40 | Matrix(const Matrix &rhs); // Copy constructor 41 | 42 | Matrix & operator=(const Matrix &rhs); // Assignment operator 43 | 44 | typedef T value_type; // Make T available externally 45 | T* operator[](const int i); // Subscripting: pointer to row i 46 | const T* operator[](const int i) const; 47 | 48 | unsigned int nrows() const; // Get number of rows 49 | unsigned int ncols() const; // Get number of columns 50 | void resize(const int newn, const int newm); // resize (contents not preserved) 51 | void assign(const int newn, const int newm, const T &a); // resize and assign a constant value 52 | 53 | void rowswap(const int r1, const int r2); // swap two rows 54 | void columnswap(const int r1, const int r2); // swap two columns 55 | 56 | template 57 | friend std::ostream& operator <<(std::ostream &os,const Matrix &rhs); //output matrix 58 | 59 | ~Matrix(); // deconstructor 60 | }; 61 | 62 | /* TYPEDEFS */ 63 | 64 | typedef Matrix MatDoub; 65 | typedef Matrix Hmatrix; 66 | typedef Matrix Tmatrix; 67 | typedef Matrix Vmatrix; 68 | typedef Matrix Smatrix; 69 | typedef Matrix Xmatrix; 70 | typedef Matrix Fmatrix; 71 | typedef Matrix Pmatrix; 72 | typedef Matrix Gmatrix; 73 | typedef Matrix Ccmatrix; 74 | typedef Matrix Cmatrix; 75 | 76 | template 77 | Matrix::Matrix() : nn(0), mm(0), v(NULL) {} 78 | 79 | /* 80 | * alternative constructor, create m x n matrix object 81 | * 82 | * 1: initialize number of rows and columns to n and m respectively 83 | * 2: set v as an array of size n of pointers to type T 84 | * 3: calculate number of elements 85 | * 4: let v[0] (a pointer to type T) point to the first element of a new array with the size of the number of elements 86 | * 5: let each v[i] point to the address of v[i-1] incremented by the column size 87 | */ 88 | template 89 | Matrix::Matrix(int n, int m) : nn(n), mm(m), v(n>0 ? new T*[n] : NULL) 90 | { 91 | int i,nel=m*n; // set number of elements 92 | if (v) v[0] = nel>0 ? new T[nel] : NULL; 93 | for (i=1;i 100 | Matrix::Matrix(int n, int m, const T &a) : nn(n), mm(m), v(n>0 ? new T*[n] : NULL) 101 | { 102 | int i,j,nel=m*n; 103 | if (v) v[0] = nel>0 ? new T[nel] : NULL; 104 | for (i=1; i< n; i++) v[i] = v[i-1] + m; 105 | for (i=0; i< n; i++) for (j=0; j 112 | Matrix::Matrix(int n, int m, const T *a) : nn(n), mm(m), v(n>0 ? new T*[n] : NULL) 113 | { 114 | int i,j,nel=m*n; 115 | if (v) v[0] = nel>0 ? new T[nel] : NULL; 116 | for (i=1; i< n; i++) v[i] = v[i-1] + m; 117 | for (i=0; i< n; i++) for (j=0; j 124 | Matrix::Matrix(const Matrix &rhs) : nn(rhs.nn), mm(rhs.mm), v(nn>0 ? new T*[nn] : NULL) 125 | { 126 | int i,j,nel=mm*nn; 127 | if (v) v[0] = nel>0 ? new T[nel] : NULL; 128 | for (i=1; i< nn; i++) v[i] = v[i-1] + mm; 129 | for (i=0; i< nn; i++) for (j=0; j 136 | Matrix & Matrix::operator=(const Matrix &rhs) 137 | { 138 | if (this != &rhs) { 139 | int i,j,nel; 140 | if (nn != rhs.nn || mm != rhs.mm) { 141 | if (v != NULL) { 142 | delete[] (v[0]); 143 | delete[] (v); 144 | } 145 | nn=rhs.nn; 146 | mm=rhs.mm; 147 | v = nn>0 ? new T*[nn] : NULL; 148 | nel = mm*nn; 149 | if (v) v[0] = nel>0 ? new T[nel] : NULL; 150 | for (i=1; i< nn; i++) v[i] = v[i-1] + mm; 151 | } 152 | for (i=0; i< nn; i++) for (j=0; j 158 | T* Matrix::operator[](const int i) 159 | { 160 | #ifdef _CHECKBOUNDS_ 161 | if (i<0 || i>=nn) { 162 | std::cout << "Out of bounds in matrix " << __FILE__ << " line " << __LINE__ << std::endl; 163 | exit(1); 164 | } 165 | #endif 166 | return v[i]; 167 | } 168 | 169 | template 170 | const T* Matrix::operator[](const int i) const 171 | { 172 | #ifdef _CHECKBOUNDS_ 173 | if (i<0 || i>=nn) { 174 | std::cout << "Out of bounds in matrix " << __FILE__ << " line " << __LINE__ << std::endl; 175 | exit(1); 176 | } 177 | #endif 178 | return v[i]; 179 | } 180 | 181 | /* 182 | * return the number of rows 183 | */ 184 | template 185 | unsigned int Matrix::nrows() const 186 | { 187 | return nn; 188 | } 189 | 190 | /* 191 | * return the number of columns 192 | */ 193 | template 194 | unsigned int Matrix::ncols() const 195 | { 196 | return mm; 197 | } 198 | 199 | /* 200 | * resize the matrix 201 | */ 202 | template 203 | void Matrix::resize(const int newn, const int newm) 204 | { 205 | int i,nel; 206 | if (newn != nn || newm != mm) { 207 | if (v != NULL) { 208 | delete[] (v[0]); 209 | delete[] (v); 210 | } 211 | nn = newn; 212 | mm = newm; 213 | v = nn>0 ? new T*[nn] : NULL; 214 | nel = mm*nn; 215 | if (v) v[0] = nel>0 ? new T[nel] : NULL; 216 | for (i=1; i< nn; i++) v[i] = v[i-1] + mm; 217 | } 218 | } 219 | 220 | /* 221 | * assign a new value for each element in the array 222 | */ 223 | template 224 | void Matrix::assign(const int newn, const int newm, const T& a) 225 | { 226 | int i,j,nel; 227 | if (newn != nn || newm != mm) { 228 | if (v != NULL) { 229 | delete[] (v[0]); 230 | delete[] (v); 231 | } 232 | nn = newn; 233 | mm = newm; 234 | v = nn>0 ? new T*[nn] : NULL; 235 | nel = mm*nn; 236 | if (v) v[0] = nel>0 ? new T[nel] : NULL; 237 | for (i=1; i< nn; i++) v[i] = v[i-1] + mm; 238 | } 239 | for (i=0; i< nn; i++) for (j=0; j 243 | void Matrix::rowswap(const int r1, const int r2) { 244 | if(r1 < 0 || r2 < 0 || r1 >= nn || r2 >= nn) { 245 | std::cout << "Row size exceeded " << __FILE__ << " line " << __LINE__ << std::endl; 246 | exit(1); 247 | } 248 | for(int i=0; i 254 | void Matrix::columnswap(const int r1, const int r2) { 255 | if(r1 < 0 || r2 < 0 || r1 >= mm || r2 >= mm) { 256 | std::cout << "Column size exceeded " << __FILE__ << " line " << __LINE__ << std::endl; 257 | exit(1); 258 | } 259 | for(int i=0; i 265 | std::ostream& operator<<(std::ostream &os,const Matrix &rhs) { 266 | for(int i=0; i < rhs.nn; i++) { 267 | os << std::setw(10) << std::setiosflags(std::ios::right); 268 | os << std::setprecision(5) << std::setiosflags(std::ios::fixed); 269 | for(int j=0; j < rhs.mm; j++) { 270 | os << rhs[i][j] << "\t"; 271 | } 272 | os << std::endl; 273 | } 274 | return os; 275 | } 276 | 277 | /* 278 | * deconstructor 279 | */ 280 | template 281 | Matrix::~Matrix() 282 | { 283 | if (v != NULL) { 284 | delete[] (v[0]); 285 | delete[] (v); 286 | } 287 | } 288 | 289 | #endif // _MATRIX_H 290 | -------------------------------------------------------------------------------- /src/hf.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * hf.cpp -- This file is part of HFCXX. * 3 | * * 4 | * Copyright (C) 2012, Ivo Filot * 5 | * * 6 | * HFCXX is free software: * 7 | * you can redistribute it and/or modify it under the terms of the * 8 | * GNU General Public License as published by the Free Software * 9 | * Foundation, either version 3 of the License, or (at your option) * 10 | * any later version. * 11 | * * 12 | * HFCXX is distributed in the hope that it will be useful, * 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty * 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 15 | * See the GNU General Public License for more details. * 16 | * * 17 | * You should have received a copy of the GNU General Public License * 18 | * along with this program. If not, see http://www.gnu.org/licenses/. * 19 | * * 20 | **************************************************************************/ 21 | 22 | #include "hf.h" 23 | 24 | HF::HF(){ 25 | debug = false; 26 | alpha = 0.5; 27 | bss = 0; 28 | } /* default constructor */ 29 | 30 | void HF::molecule(const Molecule &moll) { 31 | mol = moll; 32 | nrelec = 0; 33 | energy = 0; 34 | cntstep = 0; 35 | 36 | unsigned int cnt = 0; /* counter for orbitals */ 37 | for(unsigned int i=0; i> te_jobs; 155 | for(unsigned int i=0; i 1e-9) { /* loop until convergence criterion is met */ 293 | /* start clock */ 294 | clock.tic(); 295 | 296 | iter++; 297 | step(); 298 | std::cout << std::setprecision(10); 299 | ediff = std::abs(energy - oldenergy); 300 | oldenergy = energy; 301 | energies.push_back(energy); 302 | 303 | /* save iteration time */ 304 | clock.toc(); 305 | passed = clock.passed(); 306 | itertimes.push_back(passed); 307 | 308 | /* output result to commandline */ 309 | if(debug) { 310 | std::cout << "Energy after iteration " << iter << ":\t " << energy << " Hartree\t" 311 | << " [ " << passed << " ms ] " << std::endl; 312 | } 313 | 314 | if(iter > 100) { 315 | std::cout << "Too may iteration steps.. terminating and outputting results." << std::endl; 316 | break; 317 | } 318 | } 319 | 320 | if(debug) { 321 | std::cout << "-------------------------------" << std::endl; 322 | std::cout << "End electronic convergence... " << std::endl; 323 | std::cout << "-------------------------------" << std::endl; 324 | } 325 | 326 | /* output resulting orbitals */ 327 | if(debug) { 328 | molorbs(); 329 | } 330 | 331 | return iter; 332 | } 333 | 334 | void HF::molorbs() const { 335 | std::cout << "-------------------------------" << std::endl; 336 | std::cout << " Molecular orbitals " << std::endl; 337 | std::cout << "-------------------------------" << std::endl; 338 | std::cout << std::endl; 339 | for(unsigned int i=0; i