### Compile MOPAC Fortran API Example Source: https://github.com/openmopac/mopac/blob/main/examples/README.md Build the Fortran API example program. This command links the Fortran source file, wrapper files, and the MOPAC shared library. ```bash gfortran example.F90 ../include/mopac_wrapper.F90 ../include/mopac_wrapper_internal.F90 -I../include -L../lib -lmopac -o fortran_executable ``` -------------------------------- ### Compile MOPAC C API Example Source: https://github.com/openmopac/mopac/blob/main/examples/README.md Build the C API example program. This command links the C source file with the MOPAC header and shared library. ```bash gcc example.c -I../include -L../lib -lmopac -o c_executable ``` -------------------------------- ### Fortran MOPAC API Example Source: https://context7.com/openmopac/mopac/llms.txt Demonstrates SCF, relaxation, and vibrational calculations using the Fortran API. Ensure correct compilation flags and linking of MOPAC libraries. ```fortran ! Build: gfortran example.F90 ../include/mopac_wrapper.F90 \ ! ../include/mopac_wrapper_internal.F90 \ ! -I../include -L../lib -lmopac -o fortran_calc program mopac_api_example use mopac_api_f implicit none type(mopac_system_f) :: water type(mopac_state_f) :: state type(mopac_properties_f) :: output integer :: i water%natom = 3 allocate(water%atom(water%natom), water%coord(water%natom*3)) ! H water%atom(1) = 1; water%coord(1) = -0.02110d0; water%coord(2) = -0.00200d0; water%coord(3) = 0.0d0 ! O water%atom(2) = 8; water%coord(4) = 0.83450d0; water%coord(5) = 0.45190d0; water%coord(6) = 0.0d0 ! H water%atom(3) = 1; water%coord(7) = 1.47690d0; water%coord(8) = -0.27300d0; water%coord(9) = 0.0d0 ! SCF in vacuum call mopac_scf_f(water, state, output) write(*,*) "PM7 heat of water =", output%heat, "kcal/mol" ! => PM7 heat of water = -57.690302 kcal/mol ! SCF in COSMO solvent (water, eps=78.4) water%epsilon = 78.4d0 call mopac_scf_f(water, state, output) write(*,*) "PM7 heat in COSMO solvent =", output%heat, "kcal/mol" ! => PM7 heat in COSMO solvent = -65.218424 kcal/mol ! Geometry relaxation water%epsilon = 1.0d0 water%natom_move = 3 call mopac_relax_f(water, state, output) write(*,*) "Relaxed coordinates:" do i = 1, water%natom*3 write(*,*) i, ":", water%coord(i), "->", output%coord_update(i) water%coord(i) = output%coord_update(i) end do ! Vibrational calculation on relaxed geometry call mopac_vibe_f(water, state, output) write(*,*) "Vibrational modes:" do i = 1, water%natom_move*3 write(*,*) i, ":", output%freq(i), "1/cm" end do ! => Mode 7: 1395.08 Mode 8: 2810.21 Mode 9: 2856.56 end program mopac_api_example ``` -------------------------------- ### Install MOPAC using Conda Source: https://github.com/openmopac/mopac/blob/main/README.md Install the MOPAC package from the conda-forge channel. This is the recommended method for obtaining pre-built versions on Linux, Mac, and Windows. ```bash conda install -c conda-forge mopac ``` -------------------------------- ### Perform COSMO Implicit Solvation with MOPAC Source: https://context7.com/openmopac/mopac/llms.txt Enable the COSMO implicit solvation model using the 'EPS=' keyword followed by the dielectric constant. This cannot be used with periodic boundary conditions. The example shows water's dielectric constant (78.4). ```bash # example_cosmo.mop cat > example_cosmo.mop << 'EOF' 1SCF EPS=78.4 3 SCF calculation of water in COSMO solvent (dielectric constant of water = 78.4) H -0.02110 -0.00200 0.00000 O 0.83450 0.45190 0.00000 H 1.47690 -0.27300 0.00000 EOF mopac example_cosmo.mop # Output: # FINAL HEAT OF FORMATION = -65.218424 KCAL/MOL # (compared to -57.690 kcal/mol in vacuum — solvation stabilizes by ~7.5 kcal/mol) ``` -------------------------------- ### C API: `run_mopac_from_input` — File-Based API Call Source: https://context7.com/openmopac/mopac/llms.txt Executes a standard MOPAC calculation from an existing `.mop` input file via the API, keeping the MOPAC library in memory. Returns 0 on success and 1 on error. ```APIDOC ## C API: `run_mopac_from_input` — File-Based API Call ### Description Use `run_mopac_from_input` to execute a standard MOPAC calculation from an existing `.mop` input file via the API (equivalent to command-line) while keeping the MOPAC library resident in memory. Returns 0 on success, 1 on error. ### Function Signature `int run_mopac_from_input(const char *input_filename);` ### Parameters - `input_filename`: A string representing the path to the MOPAC input file (e.g., `"example_scf.mop"`). ### Return Value - `0`: Success. - `1`: Error during MOPAC execution. ### Example Usage ```c #include #include "mopac.h" int main(void) { // Run a MOPAC job from an existing input file int status = run_mopac_from_input("example_scf.mop"); if (status != 0) { printf("MOPAC encountered an error.\n"); return 1; } printf("MOPAC completed successfully.\n"); // Output written to example_scf.out and example_scf.arc as usual // Get the MOPAC version string char version[32]; get_mopac_version(version); printf("MOPAC version: %s\n", version); // e.g., "23.2.5" return 0; } ``` ``` -------------------------------- ### Run MOPAC Calculation from Input File Source: https://context7.com/openmopac/mopac/llms.txt Use `run_mopac_from_input` to execute a MOPAC calculation from a specified `.mop` input file, similar to command-line execution, while keeping the MOPAC library loaded. Returns 0 on success and 1 on error. ```c #include #include "mopac.h" int main(void) { // Run a MOPAC job from an existing input file int status = run_mopac_from_input("example_scf.mop"); if (status != 0) { printf("MOPAC encountered an error.\n"); return 1; } printf("MOPAC completed successfully.\n"); // Output written to example_scf.out and example_scf.arc as usual // Get the MOPAC version string char version[32]; get_mopac_version(version); printf("MOPAC version: %s\n", version); // e.g., "23.2.5" return 0; } ``` -------------------------------- ### Add Subdirectories Source: https://github.com/openmopac/mopac/blob/main/tests/CMakeLists.txt Includes build configurations from subdirectories for INDO development and keyword handling. ```cmake add_subdirectory(INDO-dev) ``` ```cmake add_subdirectory(keywords) ``` -------------------------------- ### Run MOPAC Calculation from Command Line Source: https://github.com/openmopac/mopac/blob/main/examples/README.md Execute a MOPAC calculation using an input file from the command line. Ensure the MOPAC executable is in your system's PATH. ```bash /path/to/mopac/executable example_name.mop ``` -------------------------------- ### Build MOPAC from Source using CMake Source: https://github.com/openmopac/mopac/blob/main/README.md Build MOPAC locally using its CMake build system. This process requires a Fortran compiler, BLAS/LAPACK, Python 3, and NumPy. Optional MDI support can be enabled with a CMake flag. ```bash mkdir build cd build cmake .. make ``` ```bash cmake -DMDI=ON .. make ``` -------------------------------- ### Add Source Files to Target in CMake Source: https://github.com/openmopac/mopac/blob/main/src/makpol/CMakeLists.txt Iterates through the defined source file list and adds each Fortran file to the 'mopac-makpol' build target using CMake. ```cmake foreach(idx IN LISTS src_list) target_sources(mopac-makpol PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/${idx}.F90) endforeach() ``` -------------------------------- ### Run Single-Point SCF Calculation with MOPAC Source: https://context7.com/openmopac/mopac/llms.txt Use the '1SCF' keyword for a single self-consistent field energy calculation. Input requires keywords, a title, and molecular geometry. Output is saved to .out and .arc files. ```bash # example_scf.mop cat > example_scf.mop << 'EOF' 1SCF 3 Self-consistent field calculation of a water molecule with PM7 H -0.02110 -0.00200 0.00000 O 0.83450 0.45190 0.00000 H 1.47690 -0.27300 0.00000 EOF mopac example_scf.mop # Key output (from example_scf.out): # FINAL HEAT OF FORMATION = -57.69030 KCAL/MOL = -241.37622 KJ/MOL # IONIZATION POTENTIAL = 12.030798 EV # HOMO LUMO ENERGIES (EV) = -12.031 3.977 # MOLECULAR POINT GROUP : C2v # WALL-CLOCK TIME = 0.012 SECONDS ``` -------------------------------- ### Define Source Files in CMake Source: https://github.com/openmopac/mopac/blob/main/src/makpol/CMakeLists.txt Defines a list of Fortran source files with the .F90 extension for the MOPAC project. ```cmake set(src_list cell common_atomtx common_ctvec common_elemts common_geosym common_jobnam common_keywrd common_sizes common_symult common_systm common_titles geout getpdb getsym gettxt haddon maklay makpol maksym mod_atomradii setcuc standard symtry ) ``` -------------------------------- ### COSMO Solvation with mopac_scf Source: https://context7.com/openmopac/mopac/llms.txt Enable COSMO implicit solvation by setting `epsilon` in `mopac_system` before calling `mopac_scf`. Remember to reset `epsilon` to 1.0 for vacuum calculations. COSMO is not compatible with periodic boundary conditions (`nlattice > 0`). ```c #include #include #include "mopac.h" int main(void) { struct mopac_system water; water.natom = 3; water.natom_move = 0; water.charge = 0; water.spin = 0; water.model = 0; water.nlattice = 0; water.nlattice_move = 0; water.pressure = 0.0; water.tolerance = 1.0; water.max_time = 3600; water.atom = (int*)malloc(3 * sizeof(int)); water.coord = (double*)malloc(9 * sizeof(double)); water.atom[0]=1; water.coord[0]=-0.02110; water.coord[1]=-0.00200; water.coord[2]=0.0; water.atom[1]=8; water.coord[3]= 0.83450; water.coord[4]= 0.45190; water.coord[5]=0.0; water.atom[2]=1; water.coord[6]= 1.47690; water.coord[7]=-0.27300; water.coord[8]=0.0; struct mopac_state state; struct mopac_properties vac_out, solv_out; state.mpack = 0; // Vacuum SCF water.epsilon = 1.0; mopac_scf(&water, &state, &vac_out); printf("Vacuum: heat = %lf kcal/mol\n", vac_out.heat); // -57.690302 // COSMO solvent (water, eps=78.4) water.epsilon = 78.4; mopac_scf(&water, &state, &solv_out); printf("Solvent: heat = %lf kcal/mol\n", solv_out.heat); // -65.218424 printf("Solvation energy = %lf kcal/mol\n", solv_out.heat - vac_out.heat); // ~-7.53 destroy_mopac_properties(&vac_out); destroy_mopac_properties(&solv_out); free(water.atom); free(water.coord); destroy_mopac_state(&state); return 0; } ``` -------------------------------- ### Define Reaction Source Files in CMake Source: https://github.com/openmopac/mopac/blob/main/src/reactions/CMakeLists.txt Defines a list of Fortran source files for the reactions module. These files are expected to have a .F90 extension. ```cmake set(src_list pathk react1 paths write_trajectory maps_C grid set_up_RAPID drc drcout prtdrc quadr picopt big_swap ) ``` -------------------------------- ### Perform SCF Calculation with mopac_scf Source: https://context7.com/openmopac/mopac/llms.txt Use this snippet to perform a diskless SCF calculation. Ensure memory allocated by `mopac_properties` is freed using `destroy_mopac_properties`. Build with `gcc example.c -I./include -L./lib -lmopac -o calc`. ```c #include #include #include "mopac.h" int main(void) { // Define water molecule struct mopac_system water; water.natom = 3; water.natom_move = 0; // fixed geometry for SCF only water.charge = 0; water.spin = 0; water.model = 0; // PM7 water.epsilon = 1.0; // vacuum (no solvent) water.nlattice = 0; water.nlattice_move = 0; water.pressure = 0.0; water.tolerance = 1.0; water.max_time = 3600; water.atom = (int*)malloc(3 * sizeof(int)); water.coord = (double*)malloc(9 * sizeof(double)); // H water.atom[0] = 1; water.coord[0] = -0.02110; water.coord[1] = -0.00200; water.coord[2] = 0.0; // O water.atom[1] = 8; water.coord[3] = 0.83450; water.coord[4] = 0.45190; water.coord[5] = 0.0; // H water.atom[2] = 1; water.coord[6] = 1.47690; water.coord[7] = -0.27300; water.coord[8] = 0.0; struct mopac_state state; struct mopac_properties output; state.mpack = 0; // fresh calculation (no prior state) mopac_scf(&water, &state, &output); if (output.nerror > 0) { for (int i = 0; i < output.nerror; i++) printf("ERROR: %s\n", output.error_msg[i]); return 1; } printf("PM7 heat of formation: %lf kcal/mol\n", output.heat); // Expected: PM7 heat of water = -57.690302 kcal/mol destroy_mopac_properties(&output); free(water.atom); free(water.coord); destroy_mopac_state(&state); return 0; } ``` -------------------------------- ### Run Vibrational Frequency Calculation with MOPAC Source: https://context7.com/openmopac/mopac/llms.txt Use the 'FORCE' keyword to perform a vibrational (normal mode) analysis. This should be run on a previously relaxed geometry for accurate results. Output includes vibrational frequencies in cm⁻¹ and zero-point energy. ```bash # example_vibe.mop — use relaxed geometry from prior optimization cat > example_vibe.mop << 'EOF' FORCE 3 Vibrational calculation of a relaxed water molecule with PM7 H -0.01662 0.00960388 0.00000000 O 0.83340 0.44586408 0.00000000 H 1.47682 -0.26055545 0.00000000 EOF mopac example_vibe.mop # Output includes: # Mode 7: 1395.08 1/cm (H-O-H bend) # Mode 8: 2810.21 1/cm (symmetric O-H stretch) # Mode 9: 2856.56 1/cm (asymmetric O-H stretch) ``` -------------------------------- ### Define Source Files for MOPAC Core Source: https://github.com/openmopac/mopac/blob/main/src/properties/CMakeLists.txt Defines a list of Fortran source files with the .F90 extension for the MOPAC core library. This list is used to manage the compilation of various property calculation modules. ```cmake set(src_list polar dimens mpcsyb thermo mullik bonds polar_C dipole static_polarizability CPE_Energy chrge ) ``` -------------------------------- ### C API: COSMO Solvation with `mopac_scf` Source: https://context7.com/openmopac/mopac/llms.txt Enables the COSMO implicit solvation model by setting the solvent dielectric constant in the `mopac_system` struct. This feature is incompatible with periodic boundary conditions. ```APIDOC ## C API: COSMO Solvation with `mopac_scf` ### Description Set `epsilon` to the solvent dielectric constant in `mopac_system` before calling any API function to enable the COSMO implicit solvation model. Switch back to `epsilon = 1.0` for vacuum calculations. COSMO is incompatible with periodic boundary conditions (`nlattice > 0`). ### Function Signature `void mopac_scf(struct mopac_system *sys, struct mopac_state *state, struct mopac_properties *output);` ### Parameters - `sys`: Pointer to `mopac_system` struct. Set `sys->epsilon` to the solvent dielectric constant (e.g., 78.4 for water) to enable COSMO. Set to `1.0` for vacuum. - `state`: Pointer to `mopac_state` struct for calculation state. - `output`: Pointer to `mopac_properties` struct to store results, including heat of formation. ### Example Usage ```c #include #include #include "mopac.h" int main(void) { struct mopac_system water; water.natom = 3; water.natom_move = 0; water.charge = 0; water.spin = 0; water.model = 0; water.nlattice = 0; water.nlattice_move = 0; water.pressure = 0.0; water.tolerance = 1.0; water.max_time = 3600; water.atom = (int*)malloc(3 * sizeof(int)); water.coord = (double*)malloc(9 * sizeof(double)); water.atom[0]=1; water.coord[0]=-0.02110; water.coord[1]=-0.00200; water.coord[2]=0.0; water.atom[1]=8; water.coord[3]= 0.83450; water.coord[4]= 0.45190; water.coord[5]=0.0; water.atom[2]=1; water.coord[6]= 1.47690; water.coord[7]=-0.27300; water.coord[8]=0.0; struct mopac_state state; struct mopac_properties vac_out, solv_out; state.mpack = 0; // Vacuum SCF water.epsilon = 1.0; mopac_scf(&water, &state, &vac_out); printf("Vacuum: heat = %lf kcal/mol\n", vac_out.heat); // -57.690302 // COSMO solvent (water, eps=78.4) water.epsilon = 78.4; mopac_scf(&water, &state, &solv_out); printf("Solvent: heat = %lf kcal/mol\n", solv_out.heat); // -65.218424 printf("Solvation energy = %lf kcal/mol\n", solv_out.heat - vac_out.heat); // ~-7.53 destroy_mopac_properties(&vac_out); destroy_mopac_properties(&solv_out); free(water.atom); free(water.coord); destroy_mopac_state(&state); return 0; } ``` ``` -------------------------------- ### Define Source Files List in CMake Source: https://github.com/openmopac/mopac/blob/main/src/chemistry/CMakeLists.txt Defines a list of Fortran source files using the set command. These files are essential components of the MOPAC build. ```cmake set(src_list findn1 atomrs atomradii_C names reseq lewis lyse geochk_bits_2 greek txtype add_hydrogen_atoms chklew nxtmer geochk_bits_1 chkion orient_water geochk ligand PDB3 ) ``` -------------------------------- ### mopac_scf — Single-Point Energy via Shared Library Source: https://context7.com/openmopac/mopac/llms.txt Performs a diskless SCF calculation by populating `mopac_system`, calling `mopac_scf`, and reading results from `mopac_properties`. Memory in `mopac_properties` is allocated by MOPAC and must be freed with `destroy_mopac_properties`. ```APIDOC ## mopac_scf — Single-Point Energy via Shared Library ### Description Performs a diskless SCF calculation by populating `mopac_system`, calling `mopac_scf`, and reading results from `mopac_properties`. Memory in `mopac_properties` is allocated by MOPAC and must be freed with `destroy_mopac_properties`. ### Build Command Example `gcc example.c -I./include -L./lib -lmopac -o calc` ### Function Signature `void mopac_scf(const struct mopac_system *system, struct mopac_state *state, struct mopac_properties *output);` ### Parameters #### `mopac_system` Structure - **natom** (int) - Number of atoms in the system. - **natom_move** (int) - Number of atoms that are free to move (0 for SCF only). - **charge** (int) - Total charge of the system. - **spin** (int) - Total spin multiplicity of the system. - **model** (int) - MOPAC calculation model (e.g., 0 for PM7). - **epsilon** (double) - Dielectric constant for solvent effects (1.0 for vacuum). - **nlattice** (int) - Number of lattice vectors (0 for molecular calculations). - **nlattice_move** (int) - Number of lattice vectors that are free to move. - **pressure** (double) - Pressure in atm for calculations involving pressure. - **tolerance** (double) - Convergence tolerance for SCF. - **max_time** (int) - Maximum calculation time in seconds. - **atom** (int*) - Array of atomic numbers for each atom. - **coord** (double*) - Array of atomic coordinates (x, y, z for each atom). #### `mopac_state` Structure - **mpack** (int) - Flag to indicate if a prior state is being used (0 for fresh calculation). #### `mopac_properties` Structure (Output) - **nerror** (int) - Number of errors encountered. - **error_msg** (char**) - Array of error messages. - **heat** (double) - Heat of formation in kcal/mol. - **coord_update** (double*) - Updated coordinates after optimization (used in `mopac_relax`). ### Usage Example ```c #include #include #include "mopac.h" int main(void) { // Define water molecule struct mopac_system water; water.natom = 3; water.natom_move = 0; // fixed geometry for SCF only water.charge = 0; water.spin = 0; water.model = 0; // PM7 water.epsilon = 1.0; // vacuum (no solvent) water.nlattice = 0; water.nlattice_move = 0; water.pressure = 0.0; water.tolerance = 1.0; water.max_time = 3600; water.atom = (int*)malloc(3 * sizeof(int)); water.coord = (double*)malloc(9 * sizeof(double)); // H water.atom[0] = 1; water.coord[0] = -0.02110; water.coord[1] = -0.00200; water.coord[2] = 0.0; // O water.atom[1] = 8; water.coord[3] = 0.83450; water.coord[4] = 0.45190; water.coord[5] = 0.0; // H water.atom[2] = 1; water.coord[6] = 1.47690; water.coord[7] = -0.27300; water.coord[8] = 0.0; struct mopac_state state; struct mopac_properties output; state.mpack = 0; // fresh calculation (no prior state) mopac_scf(&water, &state, &output); if (output.nerror > 0) { for (int i = 0; i < output.nerror; i++) printf("ERROR: %s\n", output.error_msg[i]); return 1; } printf("PM7 heat of formation: %%lf kcal/mol\n", output.heat); // Expected: PM7 heat of water = -57.690302 kcal/mol destroy_mopac_properties(&output); free(water.atom); free(water.coord); destroy_mopac_state(&state); return 0; } ``` ``` -------------------------------- ### Add MOPAC Test Cases Source: https://github.com/openmopac/mopac/blob/main/tests/CMakeLists.txt Adds various MOPAC test cases using the `add_mopac_test` macro, each with specific input files. ```cmake add_mopac_test(port "port.mop;port.parameters;try.txt;aa.txt;mol.in;SETUP") ``` ```cmake add_mopac_test(crambin "Crambin_1SCF.mop") ``` ```cmake add_mopac_test(mozyme "test_Lewis_for_Proteins.mop") ``` ```cmake add_mopac_test(xeno "Test_XENO.mop") ``` ```cmake add_mopac_test(hetero_group "Test_Hetero_group.mop") ``` ```cmake add_mopac_test(convert_edited_pdb "convert_an_edited_PDB_file.mop") ``` ```cmake add_mopac_test(convert_unedited_pdb "convert_an_un-edited_PDB_file.mop") ``` ```cmake add_mopac_test(ters_preserved "Check_that_TERs_are_preserved.mop;Check_TERs.pdb") ``` ```cmake add_mopac_test(compare_proteins "Compare_two_protein_structures.mop;Structure-1.txt;Structure-2.txt") ``` ```cmake add_mopac_test(pdb1cbn "PDB1CBN.ent") ``` ```cmake add_mopac_test(pdb1ejg "PDB1EJG.ent") ``` ```cmake add_mopac_test(add-h "ADD-H_Bacteriorhodopsin_1AP9.mop;Bacteriorhodopsin_1AP9.ent") ``` ```cmake add_mopac_test(add-h2 "ADD-H_Bacteriorhodopsin_1AT9.mop;Bacteriorhodopsin_1AT9.ent") ``` ```cmake add_mopac_test(add-h3 "Au_Add-H.mop") ``` ```cmake add_mopac_test(compare_add-h "Compare_ADD-H_1EJG_and_1CBN.mop") ``` ```cmake add_mopac_test(pdb_compare "Compare_PDB_1EJG_and_1CBN.mop") ``` ```cmake add_mopac_test(pdb_compare2 "Compare_PDB_Bacteriorhodopsin_1AP9_and_2AT9.mop;Bacteriorhodopsin_2AT9.ent") ``` ```cmake add_mopac_test(pdb_compare3 "Compare_PDB_Bacteriorhodopsin_1AP9_and_1C3W.mop;Bacteriorhodopsin_1C3W.ent") ``` ```cmake add_mopac_test(pdb_compare4 "Compare_PDB_Bacteriorhodopsin_1AP9_and_1BRX.mop;Bacteriorhodopsin_1BRX.ent") ``` ```cmake add_mopac_test(pdb_compare5 "Compare_PDB_Bacteriorhodopsin_1AP9_and_1BRR.mop;Bacteriorhodopsin_1BRR.ent") ``` ```cmake add_mopac_test(pdb_compare6 "Compare_PDB_Bacteriorhodopsin_1AP9_and_1AT9.mop") ``` ```cmake add_mopac_test(locate_ts "Locate_TS.mop;Cyclobutadiene_1.arc;Cyclobutadiene_2.arc") ``` ```cmake add_mopac_test(ionize "IONIZE.mop;Neutral.mop") ``` ```cmake add_mopac_test(salt "SALT.mop") ``` ```cmake add_mopac_test(salt2 "SALT_2.mop") ``` ```cmake add_mopac_test(residues "SITE_Individual_residues.mop") ``` ```cmake add_mopac_test(erratic-1 "erratic1.mop") ``` ```cmake add_mopac_test(erratic-2 "erratic2.mop") ``` ```cmake add_mopac_test(erratic-3 "erratic3.mop") ```