pymopac
PyMOPAC: A Python interface for MOPAC calculations.
This package provides tools and utilities for working with MOPAC, a semi-empirical quantum chemistry program.
- class MopacInput(geometry, model: str = 'PM7', custom_header: str = '', comment: str = '#', path=False, addHs: bool = True, preopt: bool = True, verbose: bool = False, stream: bool = False, plot: bool = False, aux: bool = True)[source]
Bases:
BaseInputClass that sets up the input file for a MOPAC calculation.
- geometry:
pure xyz block
SMILES (str)
rdkit Mol
- model: str
all supported MOPAC keywords, e.g. AM1, PM6, …
- custom_header: str
custom string that is attached to other header keywords
- comment: str
second line in the input file
- path:
if False, a dir is created under /tmp/, else under the given str
- AddHs: bool
calls AddHs on the mol object
- preopt: bool
uses MMFF to optimize the mol structure
- verbose: bool
if True, prints additional class internal statements
- stream: bool
if True, streams the outfile to stdout
- plot: bool
if True, plots progress via matplotlib
- + run()
- runs MOPAC as a subprocess
- returns MopacOutput class
- + getInpFile()
- returns the MOPAC input as a string
- class MopacOutput(outfile: str, stdout=None, stderr=None, aux: str | None = None)[source]
Bases:
BaseOutputMain Output class, calls parsers and structures outputs
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.
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 self.auxDict
- get_mopac()[source]
Checks if the MOPAC binary is within the path. looks for approximate alternatives. E.g., finds run_mopac7 on ubuntu22, but older MOPAC versions might parse files differently, thus being incompatible with this wrapper
API Module
- class MopacProperties[source]
Bases:
StructureStores the calculated ground-state properties and job information.
- heat
Heat of formation (kcal/mol).
- Type:
float
- dipole
Dipole moment vector (Debye).
- Type:
float[3]
- charge
Pointer to atomic partial charges array (size natom).
- Type:
POINTER(c_double)
- coord_update
Pointer to updated coordinates array (size 3*natom_move).
- Type:
POINTER(c_double)
- coord_deriv
Pointer to heat gradients array (size 3*natom_move).
- Type:
POINTER(c_double)
- freq
Pointer to vibrational frequencies array (size 3*natom_move).
- Type:
POINTER(c_double)
- disp
Pointer to displacement vectors array (size 3*natom_move, 3*natom_move).
- Type:
POINTER(c_double)
- bond_index
Pointer to CSC format bond matrix indices array (size natom+1).
- Type:
POINTER(c_int)
- bond_atom
Pointer to bonded atoms list (size bond_index[natom]).
- Type:
POINTER(c_int)
- bond_order
Pointer to bond orders array (size bond_index[natom]).
- Type:
POINTER(c_double)
- lattice_update
Pointer to updated lattice vectors array (size 3*nlattice_move).
- Type:
POINTER(c_double)
- lattice_deriv
Pointer to lattice gradients array (size 3*nlattice_move).
- Type:
POINTER(c_double)
- stress
Stress tensor in Voigt form.
- Type:
float[6]
- nerror
Number of error messages.
- Type:
int
- error_msg
Pointer to error messages array (size nerror).
- Type:
POINTER(POINTER(c_char))
- bond_atom
Structure/Union member
- bond_index
Structure/Union member
- bond_order
Structure/Union member
- charge
Structure/Union member
- coord_deriv
Structure/Union member
- coord_update
Structure/Union member
- dipole
Structure/Union member
- disp
Structure/Union member
- error_msg
Structure/Union member
- freq
Structure/Union member
- heat
Structure/Union member
- lattice_deriv
Structure/Union member
- lattice_update
Structure/Union member
- nerror
Structure/Union member
- stress
Structure/Union member
- class MopacState[source]
Bases:
StructureRepresents an electronic state using standard molecular orbitals.
- mpack
Number of packed matrix elements.
- Type:
int
- uhf
Unrestricted HF flag (0 = restricted, 1 = unrestricted).
- Type:
int
- pa
Pointer to alpha density matrix array (size mpack).
- Type:
POINTER(c_double)
- pb
Pointer to beta density matrix array (size mpack, NULL if uhf=0).
- Type:
POINTER(c_double)
- mpack
Structure/Union member
- pa
Structure/Union member
- pb
Structure/Union member
- uhf
Structure/Union member
- class MopacSystem[source]
Bases:
StructureDefines the atomistic system and MOPAC job options.
- natom
Number of atoms in the system.
- Type:
int
- natom_move
Number of atoms allowed to move.
- Type:
int
- charge
Net charge of the system.
- Type:
int
- spin
Number of spin excitations.
- Type:
int
- model
Semiempirical model (PM7=0, PM6-D3H4=1, etc.).
- Type:
int
- epsilon
Dielectric constant for COSMO solvent.
- Type:
float
- atom
Pointer to atomic numbers array (size natom).
- Type:
POINTER(c_int)
- coord
Pointer to atomic coordinates array (size 3*natom).
- Type:
POINTER(c_double)
- nlattice
Number of lattice vectors.
- Type:
int
- nlattice_move
Number of moveable lattice vectors.
- Type:
int
- pressure
External hydrostatic pressure (GPa).
- Type:
float
- lattice
Pointer to lattice vectors array (size 3*nlattice).
- Type:
POINTER(c_double)
- tolerance
Relative numerical tolerance.
- Type:
float
- max_time
Time limit in seconds.
- Type:
int
- atom
Structure/Union member
- charge
Structure/Union member
- coord
Structure/Union member
- epsilon
Structure/Union member
- lattice
Structure/Union member
- max_time
Structure/Union member
- model
Structure/Union member
- natom
Structure/Union member
- natom_move
Structure/Union member
- nlattice
Structure/Union member
- nlattice_move
Structure/Union member
- pressure
Structure/Union member
- spin
Structure/Union member
- tolerance
Structure/Union member
- class MozymeState[source]
Bases:
StructureRepresents an electronic state using localized molecular orbitals.
- numat
Number of real atoms.
- Type:
int
- nbonds
Pointer to Lewis bonds per atom array (size numat).
- Type:
POINTER(c_int)
- ibonds
Pointer to Lewis-bonded atoms array (size 9*numat).
- Type:
POINTER(c_int)
- iorbs
Pointer to orbitals per atom array (size numat).
- Type:
POINTER(c_int)
- noccupied
Number of occupied molecular orbitals.
- Type:
int
- ncf
Pointer to atoms in occupied localized molecular orbitals (size noccupied).
- Type:
POINTER(c_int)
- nvirtual
Number of virtual molecular orbitals.
- Type:
int
- nce
Pointer to atoms in virtual localized molecular orbitals (size nvirtual).
- Type:
POINTER(c_int)
- icocc_dim
Size of icocc array.
- Type:
int
- icocc
Pointer to atom indices in occupied LMOs array (size icocc_dim).
- Type:
POINTER(c_int)
- icvir_dim
Size of icvir array.
- Type:
int
- icvir
Pointer to atom indices in virtual LMOs array (size icvir_dim).
- Type:
POINTER(c_int)
- cocc_dim
Size of cocc array.
- Type:
int
- cocc
Pointer to occupied LMO coefficients array (size cocc_dim).
- Type:
POINTER(c_double)
- cvir_dim
Size of cvir array.
- Type:
int
- cvir
Pointer to virtual LMO coefficients array (size cvir_dim).
- Type:
POINTER(c_double)
- cocc
Structure/Union member
- cocc_dim
Structure/Union member
- cvir
Structure/Union member
- cvir_dim
Structure/Union member
- ibonds
Structure/Union member
- icocc
Structure/Union member
- icocc_dim
Structure/Union member
- icvir
Structure/Union member
- icvir_dim
Structure/Union member
- iorbs
Structure/Union member
- nbonds
Structure/Union member
- nce
Structure/Union member
- ncf
Structure/Union member
- noccupied
Structure/Union member
- numat
Structure/Union member
- nvirtual
Structure/Union member
- calculate_frequencies(system: MopacSystem, state: MopacState | None = None, properties: MopacProperties | None = None)[source]
Perform MOPAC vibrational analysis
- calculate_mozyme_frequencies(system: MopacSystem, state: MozymeState | None = None, properties: MopacProperties | None = None)[source]
Perform MOZYME vibrational analysis
- calculate_mozyme_scf(system: MopacSystem, state: MozymeState | None = None, properties: MopacProperties | None = None)[source]
Perform MOZYME electronic ground state calculation
- calculate_scf(system: MopacSystem, state: MopacState | None = None, properties: MopacProperties | None = None)[source]
Perform MOPAC electronic ground state calculation
- mol_to_system(mol, charge=0, spin=0, model=0, preopt=True, add_Hs=True, optimize_geometry=True)[source]
Convert an RDKit molecule to a MOPAC system
- Parameters:
mol – RDKit molecule object
preopt – if the mol object should by pre-optimized via MMFF
assHs – if hydrogens should be substituted at empty spots
charge – Net molecular charge (default: 0)
spin – Number of unpaired electrons (default: 0)
model – Semiempirical model (default: 0/PM7)
optimize_geometry – Whether atoms can move in calculation (default: True)
- Returns:
MopacSystem object ready for calculation
- optimize_geometry(system: MopacSystem, state: MopacState | None = None, properties: MopacProperties | None = None)[source]
Perform MOPAC geometry optimization
- optimize_mozyme_geometry(system: MopacSystem, state: MozymeState | None = None, properties: MopacProperties | None = None)[source]
Perform MOZYME geometry optimization
- system_to_mol(system, sanitize=True, charge=0, cov_factor=1.3)[source]
Convert a MOPAC system to an RDKit molecule
- Parameters:
system – MopacSystem object
sanitize – Whether to sanitize the molecule (default: True)
charge – Molecular charge (default: 0)
cov_factor – Factor to multiply covalent radii (default: 1.3)
- Returns:
RDKit Mol object