Skip to content

Commit

Permalink
Merge pull request #218 from openmopac/bindc-api
Browse files Browse the repository at this point in the history
C binding of API
  • Loading branch information
godotalgorithm authored Nov 9, 2024
2 parents 14e9d2e + cd0d325 commit d5a01db
Show file tree
Hide file tree
Showing 21 changed files with 1,942 additions and 450 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,20 @@ jobs:
- name: Configure MOPAC with CMake
run: |
cmake -B build \
-DCMAKE_BUILD_TYPE=Debug \
-DTHREADS_KEYWORD=OFF \
-DSTATIC_BUILD=ON
- name: Build MOPAC with Make
run: |
cmake --build build -- -j$NUM_CORES
# - name: Run Valgrind on MOPAC API tester
# run: |
# sudo apt update && sudo apt install -y valgrind
# cd build/tests
# valgrind -s --track-origins=yes --leak-check=yes ./mopac-api-test

- name: Test MOPAC with CTest
run: |
cd build
Expand Down Expand Up @@ -92,13 +99,20 @@ jobs:
- name: Configure MOPAC with CMake
run: |
cmake -B build \
-DCMAKE_BUILD_TYPE=Debug \
-DTHREADS_KEYWORD=OFF \
-DENABLE_COVERAGE=ON
- name: Build MOPAC with Make
run: |
cmake --build build -- -j$NUM_CORES
# - name: Run Valgrind on MOPAC API tester
# run: |
# sudo apt update && sudo apt install -y valgrind
# cd build/tests
# valgrind -s --track-origins=yes --leak-check=yes ./mopac-api-test

- name: Test MOPAC with CTest
run: |
cd build
Expand Down
16 changes: 12 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ if(BUILD_BZ)
endif()
endif()

# Use malloc in API w/ Intel Fortran compiler because it can't deallocate Fortran-allocated memory passed through a C interface
if(CMAKE_Fortran_COMPILER_ID STREQUAL "Intel")
target_compile_definitions(mopac-core PRIVATE MOPAC_API_MALLOC)
endif()

# MOPAC shared library ABI compatibility version
set_target_properties(mopac-core PROPERTIES SOVERSION 2)

Expand All @@ -151,6 +156,7 @@ if(APPLE)
target_compile_definitions(mopac-core PRIVATE MOPAC_OS="MacOS")
elseif(WIN32)
target_compile_definitions(mopac-core PRIVATE MOPAC_OS="Windows")
target_compile_definitions(mopac-core PRIVATE WIN32)
elseif(UNIX)
target_compile_definitions(mopac-core PRIVATE MOPAC_OS="Linux")
endif()
Expand Down Expand Up @@ -262,12 +268,10 @@ if(TESTS)
endif()
message(FATAL_ERROR "Python3 and Numpy are required for MOPAC testing (testing can be disabled with -DTESTS=OFF)")
endif()
enable_testing()
add_executable(mopac-api-test)
target_link_libraries(mopac-api-test mopac-core)
if (STATIC_BUILD)
target_link_options(mopac-api-test PUBLIC "-static")
endif()
enable_testing()
add_subdirectory(include)
add_subdirectory(tests)
endif()

Expand Down Expand Up @@ -320,6 +324,10 @@ install(FILES "${CMAKE_SOURCE_DIR}/.github/mopac.ico" DESTINATION "." COMPONENT
install(FILES "${CMAKE_SOURCE_DIR}/CITATION.cff"
"${CMAKE_SOURCE_DIR}/COPYING"
"${CMAKE_SOURCE_DIR}/COPYING.lesser" DESTINATION "." COMPONENT redist EXCLUDE_FROM_ALL)
install(FILES "${CMAKE_SOURCE_DIR}/include/mopac_api.h" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT redist EXCLUDE_FROM_ALL)
install(FILES "${CMAKE_SOURCE_DIR}/include/mopac_api_internal.F90" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT redist EXCLUDE_FROM_ALL)
install(FILES "${CMAKE_SOURCE_DIR}/include/mopac_api_f.F90" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT redist EXCLUDE_FROM_ALL)
install(FILES "${CMAKE_SOURCE_DIR}/include/LICENSE" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT redist EXCLUDE_FROM_ALL)

# Install the executables and library
install(TARGETS mopac RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT main)
Expand Down
18 changes: 18 additions & 0 deletions include/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Molecular Orbital PACkage (MOPAC)
# Copyright (C) 2021, Virginia Polytechnic Institute and State University
#
# MOPAC is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# MOPAC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

target_sources(mopac-api-test PRIVATE mopac_api_f.F90)
target_sources(mopac-api-test PRIVATE mopac_api_internal.F90)
21 changes: 21 additions & 0 deletions include/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021, Virginia Polytechnic Institute and State University

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
176 changes: 176 additions & 0 deletions include/mopac_api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/* Molecular Orbital PACkage (MOPAC)
* Copyright (C) 2021, Virginia Polytechnic Institute and State University
*/

/* Diskless/stateless Application Programming Interface (API) to core MOPAC operations */
#ifndef MOPAC_API_H
#define MOPAC_API_H

/* data that defines the atomistic system and MOPAC job options */
struct mopac_system {
/* number of atoms */
int natom;
/* number of atoms that are allowed to move (first natom_move atoms in array) */
int natom_move;
/* net charge */
int charge;
/* number of spin excitations, floor[(number of alpha electrons)/2 - (number of beta electrons)/2] */
int spin;
/* semiempirical model: PM7 = 0, PM6-D3H4 = 1, PM6-ORG = 2, PM6 = 3, AM1 = 4, RM1 = 5 */
int model;
/* dielectric constant for COSMO implicit solvent, must be 1 (no solvent) for nlattice > 0 */
double epsilon;
/* atomic number of each atom */
int *atom; /* [natom] */
/* (x,y,z) coordinates of each atom (Angstroms) */
double *coord; /* [3*natom] */
/* number of lattice vectors / translation vectors / periodic dimensions */
int nlattice;
/* number of lattice vectors that are allowed to move (first nlattice_move vectors in array) */
int nlattice_move;
/* external hydrostatic pressure (Gigapascals) */
double pressure;
/* (x,y,z) coordinates of each lattice vectors (Angstroms) */
double *lattice; /* [3*nlattice] */
/* relative numerical tolerances (equivalent to GNORM and RELSCF keyword values) */
double tolerance;
/* time limit for a MOPAC calculation (seconds) */
int max_time;
};

/* calculated ground-state properties of an atomistic system and MOPAC job info */
struct mopac_properties {
/* heat of formation (kcal/mol) */
double heat;
/* dipole moment vector (Debye) */
double dipole[3];
/* atomic partial charges */
double *charge; /* [natom] */
/* (x,y,z) coordinates of each moveable atom (Angstroms) */
double *coord_update; /* [3*natom_move] */
/* (x,y,z) heat gradients for each moveable atom (kcal/mol/Angstrom) */
double *coord_deriv; /* [3*natom_move] */
/* vibrational frequencies of normal modes (1/cm) */
double *freq; /* [3*natom_move], NULL if unavailable */
/* (x,y,z) displacement vectors of normal modes */
double *disp; /* [3*natom_move,3*natom_move], NULL if unavailable */
/* bond-order matrix in compressed sparse column (CSC) matrix format (0-based indexing)
* with insignificant bond orders (<0.01) truncated
* diagonal matrix entries are atomic valencies */
/* > first index of each atom in CSC bond-order matrix */
int *bond_index; /* [natom+1] */
/* > list of atoms bonded to each atom in CSC format */
int *bond_atom; /* [bond_index[natom]] */
/* > bond order of atoms bonded to each atom in CSC format */
double *bond_order; /* [bond_index[natom]] */
/* (x,y,z) coordinates of each moveable lattice vectors (Angstroms) */
double *lattice_update; /* [3*nlattice_move] */
/* (x,y,z) heat gradients for each moveable lattice vector (kcal/mol/Angstrom) */
double *lattice_deriv; /* [3*nlattice_move] */
/* stress tensor (Gigapascals) in Voigt form (xx, yy, zz, yz, xz, xy) */
double stress[6]; /* 0 if unavailable */
/* number of MOPAC error messages (negative value indicates that allocation of error_msg failed) */
int nerror;
/* text of MOPAC error messages */
char **error_msg; /* [nerror][*] */
};

/* data that describes the electronic state using standard molecular orbitals */
struct mopac_state {
/* MOPAC data format is adapted from molkst_C and Common_arrays_C modules */
/* > number of matrix elements in packed lower triangle matrix format */
int mpack; /* 0 if state is unavailable */
/* > flag for unrestricted Hartree-Fock ground state (0 == restricted, 1 == unrestricted) */
int uhf;
/* > alpha density matrix */
double *pa; /* [mpack] */
/* > beta density matrix */
double *pb; /* [mpack], NULL if uhf == 0 */
};

/* data that describes the electronic state using localized molecular orbitals */
struct mozyme_state {
/* MOZYME data format is adapted from molkst_C, Common_arrays_C, and MOZYME_C modules */
/* > number of real atoms */
int numat; /* 0 if state is unavailable */
/* > number of Lewis bonds per real atom */
int *nbonds; /* [numat] */
/* > list of Lewis-bonded real atoms for each real atom */
int *ibonds; /* [9,numat] */
/* > number of orbitals per real atom */
int *iorbs; /* [numat] */
/* > number of occupied molecular orbitals */
int noccupied;
/* > number of atoms in each occupied LMO */
int *ncf; /* [noccupied] */
/* > number of virtual molecular orbitals */
int nvirtual;
/* > number of atoms in each virtual LMO */
int *nce; /* [nvirtual] */
/* > size of array icocc */
int icocc_dim;
/* > index of each real atom in the occupied LMOs */
int *icocc; /* [iccoc_dim] */
/* > size of array icvir */
int icvir_dim;
/* > index of each real atom in the virtual LMOs */
int *icvir; /* [icvir_dim] */
/* > size of array cocc */
int cocc_dim;
/* > atomic orbital coefficients of the occupied LMOs */
double *cocc; /* [cocc_dim] */
/* > size of array cvir */
int cvir_dim;
/* > atomic orbital coefficients of the virtual LMOs */
double *cvir; /* [cvir_dim] */
};

/* MOPAC electronic ground state calculation */
void mopac_scf(struct mopac_system *system,
struct mopac_state *state,
struct mopac_properties *properties);

/* MOPAC geometry relaxation */
void mopac_relax(struct mopac_system *system,
struct mopac_state *state,
struct mopac_properties *properties);

/* MOPAC vibrational calculation */
void mopac_vibe(struct mopac_system *system,
struct mopac_state *state,
struct mopac_properties *properties);

/* MOZYME electronic ground state calculation */
void mozyme_scf(struct mopac_system *system,
struct mozyme_state *state,
struct mopac_properties *properties);

/* MOZYME geometry relaxation */
void mozyme_relax(struct mopac_system *system,
struct mozyme_state *state,
struct mopac_properties *properties);

/* MOZYME vibrational calculation */
void mozyme_vibe(struct mopac_system *system,
struct mozyme_state *state,
struct mopac_properties *properties);

/* allocate memory for mopac_state */
void create_mopac_state(struct mopac_state *state);

/* allocate memory for mozyme_state */
void create_mozyme_state(struct mozyme_state *state);

/* deallocate memory in mopac_properties */
void destroy_mopac_properties(struct mopac_properties *properties);

/* deallocate memory in mopac_state */
void destroy_mopac_state(struct mopac_state *state);

/* deallocate memory in mozyme_state */
void destroy_mozyme_state(struct mozyme_state *state);

/* run MOPAC conventionally from an input file */
int run_mopac_from_input(char *path_to_file);

#endif
Loading

0 comments on commit d5a01db

Please sign in to comment.