2.1.1. Sequential Input

 1import sys
 2
 3import CDPL.Pharm as Pharm
 4
 5
 6# function called for each read pharmacophore
 7def procPharmacophore(ph4: Pharm.Pharmacophore) -> None: 
 8    print('Read pharmacophore \'%s\' comprising %s features' % (Pharm.getName(ph4), str(ph4.numFeatures)))
 9
10def main() -> None:
11    if len(sys.argv) < 2:
12        sys.exit('Usage: %s <input pharm. file>' % sys.argv[0])
13
14    # create reader for input pharmacophores (format specified by file extension)
15    reader = Pharm.PharmacophoreReader(sys.argv[1]) 
16 
17    # create an instance of the default implementation of the Pharm.Pharmacophore interface
18    ph4 = Pharm.BasicPharmacophore()
19    
20    # read and process pharmacophores one after the other until the end of input has been reached
21    try:
22        while reader.read(ph4): 
23            try:
24                procPharmacophore(ph4)
25            except Exception as e:
26                sys.exit('Error: processing of pharmacophore failed: ' + str(e))
27                
28    except Exception as e: # handle exception raised in case of severe read errors
29        sys.exit('Error: reading pharmacophore failed: ' + str(e))
30
31    sys.exit(0)
32        
33if __name__ == '__main__':
34    main()

Download source file