3.1.1. Connectivity Properties

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

  • Num. connected std. hydrogens (incl. impl. H)

  • Num. connected carbon atoms

  • Num. connected heteroatoms

  • Num. connected halogens

  • Num. connected heavy atoms

  • Num. connected chain atoms (excl. impl. H)

  • Num. connected chain atoms (incl. impl. H)

  • Num. connected ring atoms

  • Num. connected aromatic atoms

  • Num. incident bonds (excl. impl. H)

  • Num. incident bonds (incl. impl. H)

  • Num. incident single bonds (excl. impl. H)

  • Num. incident single bonds (incl. impl. H)

  • Num. incident double bonds

  • Num. incident triple bonds

  • Num. incident chain bonds (excl. impl. H)

  • Num. incident chain bonds (incl. impl. H)

  • Num. incident ring bonds (incl. impl. H)

  • Num. incident aromatic bonds (incl. impl. H)

  • Num. incident heavy atom bonds (incl. impl. H)

  • Num. incident rotatable bonds (incl. impl. H)

  • Valence (excl. impl. H)

  • Valence (incl. impl. H)

  • Steric number

  • VSEPR coordination geometry

Synopsis

python print_atom_con_props.py

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

Download source file