1import sys
2
3import CDPL.Chem as Chem
4
5
6# function called for each read molecule
7def procMolecule(mol: Chem.Molecule) -> None:
8 print('Processing molecule with {!s} atoms and {!s} bonds'.format(mol.numAtoms, mol.numBonds))
9
10def main() -> None:
11 if len(sys.argv) < 2:
12 sys.exit('Usage: %s <input mol. file>' % sys.argv[0])
13
14 # create reader for input molecules (format specified by file extension)
15 reader = Chem.MoleculeReader(sys.argv[1])
16
17 # create an instance of the default implementation of the Chem.Molecule interface
18 mol = Chem.BasicMolecule()
19
20 # read and process molecules one after the other until the end of input has been reached
21 try:
22 while reader.read(mol):
23 try:
24 procMolecule(mol)
25 except Exception as e:
26 sys.exit('Error: processing of molecule failed: ' + str(e))
27
28 except Exception as e: # handle exception raised in case of severe read errors
29 sys.exit('Error: reading molecule failed: ' + str(e))
30
31 sys.exit(0)
32
33if __name__ == '__main__':
34 main()