1import sys
2
3import CDPL.Chem as Chem
4import CDPL.ForceField as ForceField
5
6
7# calculates and outputs the MMFF94 charges of the atoms of the provided molecular graph
8def calcAndOutputCharges(mol: Chem.Molecule) -> None:
9 Chem.calcImplicitHydrogenCounts(mol, False) # calculate implicit hydrogen counts and set corresponding property for all atoms
10 Chem.makeHydrogenComplete(mol) # make all implicit hydrogens explicit
11 Chem.perceiveHybridizationStates(mol, False) # perceive atom hybridization states and set corresponding property for all atoms
12 Chem.perceiveSSSR(mol, False) # perceive smallest set of smallest rings and store as Chem.MolecularGraph property
13 Chem.setRingFlags(mol, False) # perceive cycles and set corresponding atom and bond properties
14 Chem.setAromaticityFlags(mol, False) # perceive aromaticity and set corresponding atom and bond properties
15
16 ForceField.perceiveMMFF94AromaticRings(mol, False) # perceive aromatic rings according to the MMFF94 aroamticity model and store data as Chem.MolecularGraph property
17 ForceField.assignMMFF94AtomTypes(mol, False, False) # perceive MMFF94 atom types (tolerant mode) set corresponding property for all atoms
18 ForceField.assignMMFF94BondTypeIndices(mol, False, False) # perceive MMFF94 bond types (tolerant mode) set corresponding property for all bonds
19 ForceField.calcMMFF94AtomCharges(mol, False, False) # calculate MMFF94 atom charges (tolerant mode) set corresponding property for all atoms
20
21 print('- MMFF94 partial charges')
22
23 for atom in mol.atoms:
24 print('Atom #%s: %s' % (str(atom.getIndex()), str(ForceField.getMMFF94Charge(atom))))
25
26def main() -> None:
27 if len(sys.argv) < 2:
28 sys.exit('Usage: %s <input mol. file>' % sys.argv[0])
29
30 # create reader for input molecules (format specified by file extension)
31 reader = Chem.MoleculeReader(sys.argv[1])
32
33 # create an instance of the default implementation of the Chem.Molecule interface
34 mol = Chem.BasicMolecule()
35
36 # read and process molecules one after the other until the end of input has been reached
37 try:
38 while reader.read(mol):
39 try:
40 calcAndOutputCharges(mol)
41 except Exception as e:
42 sys.exit('Error: processing of molecule failed: ' + str(e))
43
44 except Exception as e: # handle exception raised in case of severe read errors
45 sys.exit('Error: reading molecule failed: ' + str(e))
46
47 sys.exit(0)
48
49if __name__ == '__main__':
50 main()