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.calcImplicitHydrogenCounts(mol, False) # calculate implicit hydrogen counts and set corresponding property for all atoms
11 Chem.perceiveHybridizationStates(mol, False) # perceive atom hybridization states and set corresponding property for all atoms
12 Chem.perceiveSSSR(mol, False) # perceive smallest set of smallest rings and store as Chem.MolecularGraph property
13 Chem.setRingFlags(mol, False) # perceive cycles and set corresponding atom and bond properties
14 Chem.setAromaticityFlags(mol, False) # perceive aromaticity and set corresponding atom and bond properties
15 Chem.perceivePiElectronSystems(mol, False) # perceive pi electron systems and store info as Chem.MolecularGraph property
16 # (required for MHMO calculations)
17
18 # calculate sigma charges and electronegativities using the PEOE method and store values as atom properties
19 # (prerequisite for MHMO calculations)
20 MolProp.calcPEOEProperties(mol, False)
21
22 # calculate pi charges, electronegativities and other properties by a modified Hueckel MO method and store values as properties
23 MolProp.calcMHMOProperties(mol, False)
24
25 for atom in mol.atoms:
26 print('- Atom #%s' % str(atom.getIndex()))
27 print('\tSigma charge: %s' % str(MolProp.getPEOESigmaCharge(atom)))
28 print('\tPi charge: %s' % str(MolProp.getMHMOPiCharge(atom)))
29 print('\tTotal partial charge: %s' % str(MolProp.calcTotalPartialCharge(atom)))
30 print('\tLone-pair electronegativity: %s' % str(MolProp.calcLonePairElectronegativity(atom, mol)))
31 print('\tPi electronegativity: %s' % str(MolProp.calcPiElectronegativity(atom, mol)))
32 print('\tSigma electronegativity: %s' % str(MolProp.getPEOESigmaElectronegativity(atom)))
33 print('\tExerted inductive effect: %s' % str(MolProp.calcInductiveEffect(atom, mol)))
34 print('\tFree valence electron count: %s' % str(MolProp.calcFreeValenceElectronCount(atom, mol)))
35 print('\tValence electron count: %s' % str(MolProp.calcValenceElectronCount(atom)))
36
37def main() -> None:
38 if len(sys.argv) < 2:
39 sys.exit('Usage: %s <input mol. file>' % sys.argv[0])
40
41 # create reader for input molecules (format specified by file extension)
42 reader = Chem.MoleculeReader(sys.argv[1])
43
44 # create an instance of the default implementation of the Chem.Molecule interface
45 mol = Chem.BasicMolecule()
46
47 # read and process molecules one after the other until the end of input has been reached
48 try:
49 while reader.read(mol):
50 try:
51 outputProperties(mol)
52 except Exception as e:
53 sys.exit('Error: processing of molecule failed: ' + str(e))
54
55 except Exception as e: # handle exception raised in case of severe read errors
56 sys.exit('Error: reading molecule failed: ' + str(e))
57
58 sys.exit(0)
59
60if __name__ == '__main__':
61 main()