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 molecular graph
9def outputProperties(molgraph: Chem.MolecularGraph) -> None:
10 Chem.calcImplicitHydrogenCounts(molgraph, False) # calculate implicit hydrogen counts and set corresponding property for all atoms
11 Chem.perceiveHybridizationStates(molgraph, False) # perceive atom hybridization states and set corresponding property for all atoms
12 Chem.perceiveSSSR(molgraph, False) # perceive SSSR and store as Chem.MolecularGraph property
13 Chem.setRingFlags(molgraph, False) # perceive cycles and set corresponding atom and bond properties
14 Chem.setAromaticityFlags(molgraph, False) # perceive aromaticity and set corresponding atom and bond properties
15 Chem.calcTopologicalDistanceMatrix(molgraph, False) # calculate topological distance matrix and store as Chem.MolecularGraph property
16 # (required for effective polarizability calculations)
17 for atom in molgraph.atoms:
18 print('- Atom #%s' % str(molgraph.getAtomIndex(atom)))
19 print('\tHybrid polarizability: %s' % str(MolProp.getHybridPolarizability(atom, molgraph)))
20 print('\tEffective polarizability: %s' % str(MolProp.calcEffectivePolarizability(atom, molgraph)))
21
22def main() -> None:
23 if len(sys.argv) < 2:
24 sys.exit('Usage: %s <input mol. file>' % sys.argv[0])
25
26 # create reader for input molecules (format specified by file extension)
27 reader = Chem.MoleculeReader(sys.argv[1])
28
29 # create an instance of the default implementation of the Chem.Molecule interface
30 mol = Chem.BasicMolecule()
31
32 # read and process molecules one after the other until the end of input has been reached
33 try:
34 while reader.read(mol):
35 try:
36 outputProperties(mol)
37 except Exception as e:
38 sys.exit('Error: processing of molecule failed: ' + str(e))
39
40 except Exception as e: # handle exception raised in case of severe read errors
41 sys.exit('Error: reading molecule failed: ' + str(e))
42
43 sys.exit(0)
44
45if __name__ == '__main__':
46 main()