3.1.5. Physicochemical Properties

The script print_atom_physchem_props.py demonstrates how to iterate over the atoms of molecules read from a specified input file and calculate the following physicochemical atom properties:

  • Hybrid polarizability

  • Effective polarizability

Synopsis

python print_atom_physchem_props.py <file>

Code

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

Download source file