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 smallest set of smallest rings 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
16 vsepr_geom_str = { MolProp.CoordinationGeometry.UNDEF : 'UNDEF',
17 MolProp.CoordinationGeometry.NONE : 'NONE',
18 MolProp.CoordinationGeometry.LINEAR : 'LINEAR',
19 MolProp.CoordinationGeometry.TRIGONAL_PLANAR : 'TRIGONAL_PLANAR',
20 MolProp.CoordinationGeometry.TETRAHEDRAL : 'TETRAHEDRAL',
21 MolProp.CoordinationGeometry.TRIGONAL_BIPYRAMIDAL : 'TRIGONAL_BIPYRAMIDAL',
22 MolProp.CoordinationGeometry.OCTAHEDRAL : 'OCTAHEDRAL',
23 MolProp.CoordinationGeometry.PENTAGONAL_BIPYRAMIDAL : 'PENTAGONAL_BIPYRAMIDAL',
24 MolProp.CoordinationGeometry.SQUARE_ANTIPRISMATIC : 'SQUARE_ANTIPRISMATIC',
25 MolProp.CoordinationGeometry.BENT : 'BENT',
26 MolProp.CoordinationGeometry.TRIGONAL_PYRAMIDAL : 'TRIGONAL_PYRAMIDAL',
27 MolProp.CoordinationGeometry.SQUARE_PLANAR : 'SQUARE_PLANAR',
28 MolProp.CoordinationGeometry.SQUARE_PYRAMIDAL : 'SQUARE_PYRAMIDAL',
29 MolProp.CoordinationGeometry.T_SHAPED : 'T_SHAPED',
30 MolProp.CoordinationGeometry.SEESAW : 'SEESAW',
31 MolProp.CoordinationGeometry.PENTAGONAL_PYRAMIDAL : 'PENTAGONAL_PYRAMIDAL',
32 MolProp.CoordinationGeometry.PENTAGONAL_PLANAR : 'PENTAGONAL_PLANAR' }
33
34 for atom in molgraph.atoms:
35 print('- Atom #%s' % str(molgraph.getAtomIndex(atom)))
36 print('\tNum. connected std. hydrogens (incl. impl. H): %s' % str(MolProp.getOrdinaryHydrogenCount(atom, molgraph)))
37 print('\tNum. connected carbon atoms: %s' % str(MolProp.getExplicitAtomCount(atom, molgraph, Chem.AtomType.C)))
38 print('\tNum. connected heteroatoms: %s' % str(MolProp.getExplicitAtomCount(atom, molgraph, Chem.AtomType.HET, False)))
39 print('\tNum. connected halogens: %s' % str(MolProp.getExplicitAtomCount(atom, molgraph, Chem.AtomType.X, False)))
40 print('\tNum. connected heavy atoms: %s' % str(MolProp.getHeavyAtomCount(atom, molgraph)))
41 print('\tNum. connected chain atoms (excl. impl. H): %s' % str(MolProp.getExplicitChainAtomCount(atom, molgraph)))
42 print('\tNum. connected chain atoms (incl. impl. H): %s' % str(MolProp.getChainAtomCount(atom, molgraph)))
43 print('\tNum. connected ring atoms: %s' % str(MolProp.getRingAtomCount(atom, molgraph)))
44 print('\tNum. connected aromatic atoms: %s' % str(MolProp.getAromaticAtomCount(atom, molgraph)))
45 print('\tNum. incident bonds (excl. impl. H): %s' % str(MolProp.getExplicitBondCount(atom, molgraph)))
46 print('\tNum. incident bonds (incl. impl. H): %s' % str(MolProp.getBondCount(atom, molgraph)))
47 print('\tNum. incident single bonds (excl. impl. H): %s' % str(MolProp.getExplicitBondCount(atom, molgraph, 1)))
48 print('\tNum. incident single bonds (incl. impl. H): %s' % str(MolProp.getBondCount(atom, molgraph, 1)))
49 print('\tNum. incident double bonds: %s' % str(MolProp.getBondCount(atom, molgraph, 2)))
50 print('\tNum. incident triple bonds: %s' % str(MolProp.getBondCount(atom, molgraph, 3)))
51 print('\tNum. incident chain bonds (excl. impl. H): %s' % str(MolProp.getExplicitChainBondCount(atom, molgraph)))
52 print('\tNum. incident chain bonds (incl. impl. H): %s' % str(MolProp.getChainBondCount(atom, molgraph)))
53 print('\tNum. incident ring bonds (incl. impl. H): %s' % str(MolProp.getRingBondCount(atom, molgraph)))
54 print('\tNum. incident aromatic bonds (incl. impl. H): %s' % str(MolProp.getAromaticBondCount(atom, molgraph)))
55 print('\tNum. incident heavy atom bonds (incl. impl. H): %s' % str(MolProp.getHeavyBondCount(atom, molgraph)))
56 print('\tNum. incident rotatable bonds (incl. impl. H): %s' % str(MolProp.getRotatableBondCount(atom, molgraph, False, False)))
57 print('\tValence (excl. impl. H): %s' % str(MolProp.calcExplicitValence(atom, molgraph)))
58 print('\tValence (incl. impl. H): %s' % str(MolProp.calcValence(atom, molgraph)))
59 print('\tSteric number: %s' % str(MolProp.calcStericNumber(atom, molgraph)))
60 print('\tVSEPR coordination geometry: %s' % vsepr_geom_str[MolProp.getVSEPRCoordinationGeometry(atom, molgraph)])
61
62def main() -> None:
63 if len(sys.argv) < 2:
64 sys.exit('Usage: %s <input mol. file>' % sys.argv[0])
65
66 # create reader for input molecules (format specified by file extension)
67 reader = Chem.MoleculeReader(sys.argv[1])
68
69 # create an instance of the default implementation of the Chem.Molecule interface
70 mol = Chem.BasicMolecule()
71
72 # read and process molecules one after the other until the end of input has been reached
73 try:
74 while reader.read(mol):
75 try:
76 outputProperties(mol)
77 except Exception as e:
78 sys.exit('Error: processing of molecule failed: ' + str(e))
79
80 except Exception as e: # handle exception raised in case of severe read errors
81 sys.exit('Error: reading molecule failed: ' + str(e))
82
83 sys.exit(0)
84
85if __name__ == '__main__':
86 main()