3.1.5. Physicochemical Properties

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

Download source file