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