3.1.3. Classification 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    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    MolProp.perceiveHBondDonorAtomTypes(molgraph, False) # perceive H-bond donor atom types and set corresponding atom properties
 16    MolProp.perceiveHBondAcceptorAtomTypes(molgraph, False) # perceive H-bond acceptor atom types and set corresponding atom properties
 17
 18    hba_type_str = { MolProp.HBondAcceptorAtomType.UNDEF                   : 'UNDEF',
 19                     MolProp.HBondAcceptorAtomType.NONE                    : 'NONE',
 20                     MolProp.HBondAcceptorAtomType.O_H2O                   : 'O_H2O',
 21                     MolProp.HBondAcceptorAtomType.O_UREA                  : 'O_UREA',
 22                     MolProp.HBondAcceptorAtomType.O_BARBITURIC_ACID       : 'O_BARBITURIC_ACID',
 23                     MolProp.HBondAcceptorAtomType.O_URIC_ACID             : 'O_URIC_ACID',
 24                     MolProp.HBondAcceptorAtomType.O_ETHER                 : 'O_ETHER',
 25                     MolProp.HBondAcceptorAtomType.O_AMIDE                 : 'O_AMIDE',
 26                     MolProp.HBondAcceptorAtomType.O_N_OXIDE               : 'O_N_OXIDE',
 27                     MolProp.HBondAcceptorAtomType.O_ACID                  : 'O_ACID',
 28                     MolProp.HBondAcceptorAtomType.O_ESTER                 : 'O_ESTER',
 29                     MolProp.HBondAcceptorAtomType.O_SULFOXIDE             : 'O_SULFOXIDE',
 30                     MolProp.HBondAcceptorAtomType.O_NITRO                 : 'O_NITRO',
 31                     MolProp.HBondAcceptorAtomType.O_SELEN_OXIDE           : 'O_SELEN_OXIDE',
 32                     MolProp.HBondAcceptorAtomType.O_ALDEHYD               : 'O_ALDEHYD',
 33                     MolProp.HBondAcceptorAtomType.O_KETONE                : 'O_KETONE',
 34                     MolProp.HBondAcceptorAtomType.O_ALCOHOL               : 'O_ALCOHOL',
 35                     MolProp.HBondAcceptorAtomType.N_NH3                   : 'N_NH3',
 36                     MolProp.HBondAcceptorAtomType.N_DIAMINE               : 'N_DIAMINE',
 37                     MolProp.HBondAcceptorAtomType.N_MONO_DI_NITRO_ANILINE : 'N_MONO_DI_NITRO_ANILINE',
 38                     MolProp.HBondAcceptorAtomType.N_TRI_NITRO_ANILINE     : 'N_TRI_NITRO_ANILINE',
 39                     MolProp.HBondAcceptorAtomType.N_HALOGENO_ANILINE      : 'N_HALOGENO_ANILINE',
 40                     MolProp.HBondAcceptorAtomType.N_ANILINE               : 'N_ANILINE',
 41                     MolProp.HBondAcceptorAtomType.N_NITRILE               : 'N_NITRILE',
 42                     MolProp.HBondAcceptorAtomType.N_AZOLE                 : 'N_AZOLE',
 43                     MolProp.HBondAcceptorAtomType.N_AMINE                 : 'N_AMINE',
 44                     MolProp.HBondAcceptorAtomType.N_AMIDINE               : 'N_AMIDINE',
 45                     MolProp.HBondAcceptorAtomType.N_AZO                   : 'N_AZO',
 46                     MolProp.HBondAcceptorAtomType.N_AZINE                 : 'N_AZINE',
 47                     MolProp.HBondAcceptorAtomType.N_DIAZINE               : 'N_DIAZINE',
 48                     MolProp.HBondAcceptorAtomType.N_IMINE                 : 'N_IMINE',
 49                     MolProp.HBondAcceptorAtomType.S_SULFIDE               : 'S_SULFIDE',
 50                     MolProp.HBondAcceptorAtomType.S_THIOUREA              : 'S_THIOUREA',
 51                     MolProp.HBondAcceptorAtomType.P_MONO_DI_PHOSPHINE     : 'P_MONO_DI_PHOSPHINE',
 52                     MolProp.HBondAcceptorAtomType.P_TRI_PHOSPHINE         : 'P_TRI_PHOSPHINE' }
 53
 54    hbd_type_str = { MolProp.HBondDonorAtomType.UNDEF                       : 'UNDEF',
 55                     MolProp.HBondDonorAtomType.NONE                        : 'NONE',
 56                     MolProp.HBondDonorAtomType.I_HI                        : 'I_HI',
 57                     MolProp.HBondDonorAtomType.BR_HBR                      : 'BR_HBR',
 58                     MolProp.HBondDonorAtomType.CL_HCL                      : 'CL_HCL',
 59                     MolProp.HBondDonorAtomType.S_HSCN                      : 'S_HSCN',
 60                     MolProp.HBondDonorAtomType.F_HF                        : 'F_HF',
 61                     MolProp.HBondDonorAtomType.H_H2                        : 'H_H2',
 62                     MolProp.HBondDonorAtomType.C_HCN                       : 'C_HCN',
 63                     MolProp.HBondDonorAtomType.C_ETHINE                    : 'C_ETHINE',
 64                     MolProp.HBondDonorAtomType.N_HN3                       : 'N_HN3',
 65                     MolProp.HBondDonorAtomType.N_NH3                       : 'N_NH3',
 66                     MolProp.HBondDonorAtomType.N_NH4                       : 'N_NH4',
 67                     MolProp.HBondDonorAtomType.N_AMINE                     : 'N_AMINE',
 68                     MolProp.HBondDonorAtomType.N_AMINIUM                   : 'N_AMINIUM',
 69                     MolProp.HBondDonorAtomType.N_ANILINE                   : 'N_ANILINE',
 70                     MolProp.HBondDonorAtomType.N_MONO_DI_NITRO_ANILINE     : 'N_MONO_DI_NITRO_ANILINE',
 71                     MolProp.HBondDonorAtomType.N_TRI_NITRO_ANILINE         : 'N_TRI_NITRO_ANILINE',
 72                     MolProp.HBondDonorAtomType.N_PYRROLE                   : 'N_PYRROLE',
 73                     MolProp.HBondDonorAtomType.N_AMIDE                     : 'N_AMIDE',
 74                     MolProp.HBondDonorAtomType.N_IMINE                     : 'N_IMINE',
 75                     MolProp.HBondDonorAtomType.N_IMINIUM                   : 'N_IMINIUM',
 76                     MolProp.HBondDonorAtomType.S_H2S                       : 'S_H2S',
 77                     MolProp.HBondDonorAtomType.S_HS                        : 'S_HS',
 78                     MolProp.HBondDonorAtomType.S_THIOL                     : 'S_THIOL',
 79                     MolProp.HBondDonorAtomType.O_H3PO4                     : 'O_H3PO4',
 80                     MolProp.HBondDonorAtomType.O_H2CO3                     : 'O_H2CO3',
 81                     MolProp.HBondDonorAtomType.O_HCO3                      : 'O_HCO3',
 82                     MolProp.HBondDonorAtomType.O_H2O2                      : 'O_H2O2',
 83                     MolProp.HBondDonorAtomType.O_H2O                       : 'O_H2O',
 84                     MolProp.HBondDonorAtomType.O_CF3SO3H                   : 'O_CF3SO3H',
 85                     MolProp.HBondDonorAtomType.O_HCLO4                     : 'O_HCLO4',
 86                     MolProp.HBondDonorAtomType.O_H2SO4                     : 'O_H2SO4',
 87                     MolProp.HBondDonorAtomType.O_HNO3                      : 'O_HNO3',
 88                     MolProp.HBondDonorAtomType.O_HSO4                      : 'O_HSO4',
 89                     MolProp.HBondDonorAtomType.O_HNO2                      : 'O_HNO2',
 90                     MolProp.HBondDonorAtomType.O_NH2OH                     : 'O_NH2OH',
 91                     MolProp.HBondDonorAtomType.O_H2PO4                     : 'O_H2PO4',
 92                     MolProp.HBondDonorAtomType.O_H3BO3                     : 'O_H3BO3',
 93                     MolProp.HBondDonorAtomType.O_H4SIO4                    : 'O_H4SIO4',
 94                     MolProp.HBondDonorAtomType.O_HPO4                      : 'O_HPO4',
 95                     MolProp.HBondDonorAtomType.O_H2BO3                     : 'O_H2BO3',
 96                     MolProp.HBondDonorAtomType.O_HO                        : 'O_HO',
 97                     MolProp.HBondDonorAtomType.O_SULFONIC_ACID             : 'O_SULFONIC_ACID',
 98                     MolProp.HBondDonorAtomType.O_MONO_DI_NITRO_PHENOL      : 'O_MONO_DI_NITRO_PHENOL',
 99                     MolProp.HBondDonorAtomType.O_HALOGENO_ALCOHOL          : 'O_HALOGENO_ALCOHOL',
100                     MolProp.HBondDonorAtomType.O_ALCOHOL                   : 'O_ALCOHOL',
101                     MolProp.HBondDonorAtomType.O_TRI_NITRO_PHENOL          : 'O_TRI_NITRO_PHENOL',
102                     MolProp.HBondDonorAtomType.O_HALOGENO_PHENOL           : 'O_HALOGENO_PHENOL',
103                     MolProp.HBondDonorAtomType.O_PHENOL                    : 'O_PHENOL',
104                     MolProp.HBondDonorAtomType.O_CARBOXYLIC_ACID           : 'O_CARBOXYLIC_ACID',
105                     MolProp.HBondDonorAtomType.O_HALOGENO_CARBOXYCLIC_ACID : 'O_HALOGENO_CARBOXYCLIC_ACID',
106                     MolProp.HBondDonorAtomType.O_ENOL                      : 'O_ENOL',
107                     MolProp.HBondDonorAtomType.O_OXIME                     : 'O_OXIME',
108                     MolProp.HBondDonorAtomType.O_CL5_PHENOL                : 'O_CL5_PHENOL' }
109    
110    for atom in molgraph.atoms:
111        print('- Atom #%s' % str(molgraph.getAtomIndex(atom)))
112        print('\tIs std. hydrogen: %s' % str(MolProp.isOrdinaryHydrogen(atom, molgraph)))
113        print('\tIs heavy atom: %s' % str(MolProp.isHeavy(atom)))
114        print('\tIs unsaturated: %s' % str(MolProp.isUnsaturated(atom, molgraph)))
115        print('\tIs H-bond acceptor: %s' % str(MolProp.isHBondAcceptor(atom, molgraph)))
116        print('\tH-bond acceptor type: %s' % hba_type_str[MolProp.getHBondAcceptorType(atom)])
117        print('\tIs H-bond donor: %s' % str(MolProp.isHBondDonor(atom, molgraph)))
118        print('\tH-bond donor type: %s' % hbd_type_str[MolProp.getHBondDonorType(atom)])
119        print('\tIs carbonyl carbon: %s' % str(MolProp.isCarbonylLikeAtom(atom, molgraph, True, True)))
120        print('\tIs amide carbon: %s' % str(MolProp.isAmideCenterAtom(atom, molgraph, True, True)))
121        print('\tIs amide nitrogen: %s' % str(MolProp.isAmideNitrogen(atom, molgraph, True, True)))
122        print('\tIs invertible nitrogen: %s' % str(MolProp.isInvertibleNitrogen(atom, molgraph)))
123        print('\tIs planar nitrogen: %s' % str(MolProp.isPlanarNitrogen(atom, molgraph)))
124        
125def main() -> None:
126    if len(sys.argv) < 2:
127        sys.exit('Usage: %s <input mol. file>' % sys.argv[0])
128
129    # create reader for input molecules (format specified by file extension)
130    reader = Chem.MoleculeReader(sys.argv[1]) 
131  
132    # create an instance of the default implementation of the Chem.Molecule interface
133    mol = Chem.BasicMolecule()
134    
135    # read and process molecules one after the other until the end of input has been reached
136    try:
137        while reader.read(mol):
138            try:
139                outputProperties(mol)
140            except Exception as e:
141                sys.exit('Error: processing of molecule failed: ' + str(e))
142                
143    except Exception as e: # handle exception raised in case of severe read errors
144        sys.exit('Error: reading molecule failed: ' + str(e))
145
146    sys.exit(0)
147        
148if __name__ == '__main__':
149    main()

Download source file