3.1.4. Partial Charges And Other Electronic Properties
The script print_atom_elec_props.py demonstrates how to iterate over the atoms of molecules read from a specified input file and calculate the following electronic atom properties:
Sigma charge
Pi charge
Total partial charge
Lone-pair electronegativity
Pi electronegativity
Sigma electronegativity
Exerted inductive effect
Free valence electron count
Valence electron count
Synopsis
python print_atom_elec_props.py <file>
Code
1import sys
2import os
3
4import CDPL.Chem as Chem
5import CDPL.MolProp as MolProp
6
7
8# outputs the corresponding properties of each atom of the provided molecule
9def outputProperties(mol: Chem.Molecule) -> None:
10 Chem.calcBasicProperties(mol, False) # calculate basic molecular properties (if not yet done)
11 Chem.perceivePiElectronSystems(mol, False) # perceive pi electron systems and store info as Chem.MolecularGraph property
12 # (required for MHMO calculations)
13
14 # calculate sigma charges and electronegativities using the PEOE method and store values as atom properties
15 # (prerequisite for MHMO calculations)
16 MolProp.calcPEOEProperties(mol, False)
17
18 # calculate pi charges, electronegativities and other properties by a modified Hueckel MO method and store values as properties
19 MolProp.calcMHMOProperties(mol, False)
20
21 for atom in mol.atoms:
22 print('- Atom #%s' % str(atom.getIndex()))
23 print('\tSigma charge: %s' % str(MolProp.getPEOESigmaCharge(atom)))
24 print('\tPi charge: %s' % str(MolProp.getMHMOPiCharge(atom)))
25 print('\tTotal partial charge: %s' % str(MolProp.calcTotalPartialCharge(atom)))
26 print('\tLone-pair electronegativity: %s' % str(MolProp.calcLonePairElectronegativity(atom, mol)))
27 print('\tPi electronegativity: %s' % str(MolProp.calcPiElectronegativity(atom, mol)))
28 print('\tSigma electronegativity: %s' % str(MolProp.getPEOESigmaElectronegativity(atom)))
29 print('\tExerted inductive effect: %s' % str(MolProp.calcInductiveEffect(atom, mol)))
30 print('\tFree valence electron count: %s' % str(MolProp.calcFreeValenceElectronCount(atom, mol)))
31 print('\tValence electron count: %s' % str(MolProp.calcValenceElectronCount(atom)))
32
33def main() -> None:
34 if len(sys.argv) < 2:
35 sys.exit('Usage: %s <input mol. file>' % sys.argv[0])
36
37 # create reader for input molecules (format specified by file extension)
38 reader = Chem.MoleculeReader(sys.argv[1])
39
40 # create an instance of the default implementation of the Chem.Molecule interface
41 mol = Chem.BasicMolecule()
42
43 # read and process molecules one after the other until the end of input has been reached
44 try:
45 while reader.read(mol):
46 try:
47 outputProperties(mol)
48 except Exception as e:
49 sys.exit('Error: processing of molecule failed: ' + str(e))
50
51 except Exception as e: # handle exception raised in case of severe read errors
52 sys.exit('Error: reading molecule failed: ' + str(e))
53
54 sys.exit(0)
55
56if __name__ == '__main__':
57 main()