3.1.2. Chemical element properties

 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    for atom in molgraph.atoms:
11        print('- Atom #%s' % str(molgraph.getAtomIndex(atom)))
12        print('\tAtomic weight: %s' % str(MolProp.getAtomicWeight(atom)))
13        print('\tPTE IUPAC group: %s' % str(MolProp.getIUPACGroup(atom)))
14        print('\tPTE period: %s' % str(MolProp.getPeriod(atom)))
15        print('\tVdW radius: %s' % str(MolProp.getVdWRadius(atom)))
16        print('\tCovalent radius (bond order=1): %s' % str(MolProp.getCovalentRadius(atom, 1)))
17        print('\tCovalent radius (bond order=2): %s' % str(MolProp.getCovalentRadius(atom, 2)))
18        print('\tCovalent radius (bond order=3): %s' % str(MolProp.getCovalentRadius(atom, 3)))
19        print('\tAllred Rochow electronegativity: %s' % str(MolProp.getAllredRochowElectronegativity(atom)))
20        print('\tElement name: %s' % MolProp.getElementName(atom))
21        print('\tValence electron count: %s' % str(MolProp.getElementValenceElectronCount(atom)))
22        print('\tAtom type specifies chemical element: %s' % str(MolProp.isChemicalElement(atom)))
23        print('\tIs main group element: %s' % str(MolProp.isMainGroupElement(atom)))
24        print('\tIs metal: %s' % str(MolProp.isMetal(atom)))
25        print('\tIs transition metal: %s' % str(MolProp.isTransitionMetal(atom)))
26        print('\tIs non-metal: %s' % str(MolProp.isNonMetal(atom)))
27        print('\tIs semi-metal: %s' % str(MolProp.isSemiMetal(atom)))
28        print('\tIs halogen: %s' % str(MolProp.isHalogen(atom)))
29        print('\tIs noble gas: %s' % str(MolProp.isNobleGas(atom)))
30
31def main() -> None:
32    if len(sys.argv) < 2:
33        sys.exit('Usage: %s <input mol. file>' % sys.argv[0])
34
35    # create reader for input molecules (format specified by file extension)
36    reader = Chem.MoleculeReader(sys.argv[1]) 
37  
38    # create an instance of the default implementation of the Chem.Molecule interface
39    mol = Chem.BasicMolecule()
40    
41    # read and process molecules one after the other until the end of input has been reached
42    try:
43        while reader.read(mol):
44            try:
45                outputProperties(mol)
46            except Exception as e:
47                sys.exit('Error: processing of molecule failed: ' + str(e))
48                
49    except Exception as e: # handle exception raised in case of severe read errors
50        sys.exit('Error: reading molecule failed: ' + str(e))
51
52    sys.exit(0)
53        
54if __name__ == '__main__':
55    main()

Download source file