Skip to main content

a python wrapper to interact with the semiempirical quantum chemistry program MOPAC

Project description

pyMOPAC

initial test build with basic functionality

wraps MOPAC to conveniently interact with the program from within python scripts

Dependencies

  • MOPAC in $PATH (some search is done for slightly different names, but older versions might not parse)

Optional (skip via pip --no-dependencies, supports Input from pure XYZ data and runs without plotting)

  • rdkit

  • numpy

  • matplotlib

Installation

  • via pip

pip install pymopac

  • directly from github (nightly)
git clone Acetylsalicylsaeure/pymopac
cd pymopac
pip install .

Usage

At the core, this module implements two classes, MopacInput and MopacOutput. These represent the MOPAC .mop input and .out output files, respectively. MopacInput takes a molecular geometry in various supported formats like SMILES or rdkit Mol. Furthermore, various keywords are accepted that define the MOPAC Header. The input file can be sent to MOPAC via the .run() method, which returns a MopacOutput object.

This Object Class parses the .out file and aims to dynamically extract calculation results.

Minimal working example:

import pymopac


infile = pymopac.MopacInput("CC")
outfile = infile.run()
print(outfile.result)

Getting calculated properties

import pymopac


outfile = pymopac.MopacInput("c1ccccc1").run()
print(outfile.keys())
print(outfile["IONIZATION_POTENTIAL"])

working with Mol objects

The module internally represents the molecule via rdkit Mol objects. They can serve both as inputs and can be accessed as outputs after having their geometry optimized with MOPAC

from rdkit import Chem
from rdkit.Chem import AllChem
import pymopac


mmff_mol = Chem.MolFromSmiles("c1ccc1")
mmff_mol = AllChem.AddHs(mmff_mol)
AllChem.EmbedMolecule(mmff_mol)
AllChem.MMFFOptimizeMolecule(mmff_mol)

outfile = pymopac.MopacInput(mmff_mol).run()
mopac_mol = outfile.toMol()

print(AllChem.GetBestRMS(mmff_mol, mopac_mol))

Run feedback

3 different keywords are implemented, which offer feedback to a MOPAC run

  • verbose=True prints internal messages from the python module to stdout

  • stream=True streams the MOPAC .out file to stdout

  • plot=True uses matplotlib to plot the progress in gradient and heat of formation

Parsers

Custom parsers can be written, inherinting from input.BaseParser. Every Output class has a list at self.parser which, custom parsers can simply be added. If a parser has been added after Output initialization, parsing can be redone using Output.parseAll()

By convention, custom parsers are able to set attributes on the Ouput class by having the Output passed as an argument at parse time.

AUX Parser

A parser working on the MOPAC AUX file is called when a .aux file is passed, as is standard when creating the output via the MopacInput.run() method. Using this, all properties can be parsed in an unsupervised manner. Results of this can be found under Output.auxDict.

Tests

done for Ubuntu 24 LTS and Fedora 40,

Python 3.9-12

Roadmap

  • add parsing for further keywords
  • add accuracy tests
  • implement performance overhead benchmark

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymopac-1.0.tar.gz (58.8 kB view details)

Uploaded Source

Built Distribution

pymopac-1.0-py3-none-any.whl (36.0 kB view details)

Uploaded Python 3

File details

Details for the file pymopac-1.0.tar.gz.

File metadata

  • Download URL: pymopac-1.0.tar.gz
  • Upload date:
  • Size: 58.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for pymopac-1.0.tar.gz
Algorithm Hash digest
SHA256 a4646f7453240f8830b055c0aae93d2e6d9e2598f2dc7b05829373bc896c79ce
MD5 3db304787be5064be373bec09a9589ef
BLAKE2b-256 742b5d0b278e6486611341b0c436f6dd5f89acc50676d1becefa3b6435e68c4f

See more details on using hashes here.

File details

Details for the file pymopac-1.0-py3-none-any.whl.

File metadata

  • Download URL: pymopac-1.0-py3-none-any.whl
  • Upload date:
  • Size: 36.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for pymopac-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4187163bca506cfdea04b6024d20431cfed5a7a73b83be049c4dcf9c82f79c19
MD5 5397c64c7195da12c74b1e38baa84936
BLAKE2b-256 d24abd7bce366f05a811d251c57db6e25bc37d68a04ac27a80415cb88bf39ef2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page