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