|
14 | 14 |
|
15 | 15 | ######################################################################### |
16 | 16 |
|
17 | | -import sys |
18 | | -import os |
19 | 17 | import argparse |
20 | | -import entry_property_calculator |
| 18 | +import sys |
| 19 | + |
21 | 20 | from ccdc import io |
22 | 21 |
|
23 | | -if __name__ == '__main__': |
| 22 | +import entry_property_calculator |
24 | 23 |
|
25 | | - parser = argparse.ArgumentParser( description=__doc__, |
26 | | - formatter_class=argparse.RawDescriptionHelpFormatter ) |
| 24 | +if __name__ == '__main__': |
27 | 25 |
|
| 26 | + parser = argparse.ArgumentParser(description=__doc__, |
| 27 | + formatter_class=argparse.RawDescriptionHelpFormatter) |
28 | 28 |
|
29 | | - parser.add_argument( '-r','--refcode_file', help='input file containing the list of refcodes', default = None ) |
30 | | - parser.add_argument( '-d','--database_file', help='input file containing the list of refcodes', default = None ) |
31 | | - parser.add_argument( '-c','--control_file', help='configuration file containing the desired properties\n\n %s' % (entry_property_calculator.helptext()) ) |
32 | | - parser.add_argument( '-v','--get_values', action="store_true", help='calculate and print descriptor values where possible rather than filter\n\n %s' % (entry_property_calculator.helptext()) ) |
33 | | - parser.add_argument( '-o','--output_file', default = None, help='output CSV file for results\n\n %s' % (entry_property_calculator.helptext()) ) |
| 29 | + parser.add_argument('-r', '--refcode_file', help='input file containing the list of refcodes', default=None) |
| 30 | + parser.add_argument('-d', '--database_file', help='input file containing the list of refcodes', default=None) |
| 31 | + parser.add_argument('-c', '--control_file', help='configuration file containing the desired properties\n\n %s' % ( |
| 32 | + entry_property_calculator.helptext())) |
| 33 | + parser.add_argument('-v', '--get_values', action="store_true", |
| 34 | + help='calculate and print descriptor values where possible rather than filter\n\n %s' % ( |
| 35 | + entry_property_calculator.helptext())) |
| 36 | + parser.add_argument('-o', '--output_file', default=None, |
| 37 | + help='output CSV file for results\n\n %s' % (entry_property_calculator.helptext())) |
34 | 38 |
|
35 | 39 | args = parser.parse_args() |
36 | 40 |
|
|
43 | 47 | if args.output_file != None: |
44 | 48 | outfile = open(args.output_file, 'wb') |
45 | 49 |
|
46 | | - filterer = entry_property_calculator.parse_control_file(open(control_file,"r").readlines()) |
| 50 | + filterer = entry_property_calculator.parse_control_file(open(control_file, "r").readlines()) |
47 | 51 |
|
48 | 52 | reader = None |
49 | 53 | if refcode_file: |
|
55 | 59 |
|
56 | 60 | if args.get_values: |
57 | 61 | import csv |
58 | | - csvwriter = None |
| 62 | + |
| 63 | + csvwriter = None |
59 | 64 | for entry in reader: |
60 | 65 | values = filterer.values(entry) |
61 | 66 | if csvwriter == None: |
62 | | - fieldnames=["identifier"] + values.keys() |
| 67 | + fieldnames = ["identifier"] + values.keys() |
63 | 68 | csvwriter = csv.DictWriter(outfile, fieldnames=fieldnames) |
64 | 69 | csvwriter.writeheader() |
65 | 70 | values["identifier"] = entry.identifier |
|
0 commit comments