|
27 | 27 |
|
28 | 28 |
|
29 | 29 | starttime = time.time() |
30 | | -Tilde = API() |
| 30 | +work = API() |
31 | 31 |
|
32 | 32 | parser = argparse.ArgumentParser( |
33 | 33 | prog="[this_script]", |
|
43 | 43 | parser.add_argument("-v", dest="convergence", action="store", help="print calculation convergence", type=bool, metavar="", nargs='?', const=True, default=False) |
44 | 44 | parser.add_argument("-f", dest="freqs", action="store", help="print phonons", type=bool, metavar="", nargs='?', const=True, default=False) |
45 | 45 | parser.add_argument("-i", dest="info", action="store", help="print tags", type=bool, metavar="", nargs='?', const=True, default=False) |
46 | | -parser.add_argument("-m", dest="module", action="store", help="invoke a module from the list", nargs='?', const=True, default=False, choices=list(Tilde.Apps.keys())) |
| 46 | +parser.add_argument("-m", dest="module", action="store", help="invoke a module from the list", nargs='?', const=True, default=False, choices=list(work.Apps.keys())) |
47 | 47 | parser.add_argument("-s", dest="structures", action="store", help="print the final lattice and the final atomic structure", type=bool, metavar="", nargs='?', const=True, default=False) |
48 | 48 | parser.add_argument("-c", dest="cif", action="store", help="save i-th CIF structure in \"data\" folder", type=int, metavar="i", nargs='?', const=-1, default=False) |
49 | 49 | parser.add_argument("-x", dest="service", action="store", help="print total number of items (use to create schema)", type=bool, metavar="", nargs='?', const=True, default=False) |
|
58 | 58 |
|
59 | 59 | # -a option |
60 | 60 | if args.add or args.service: |
61 | | - if settings['db']['engine'] == 'sqlite': user_choice = args.add |
62 | | - elif settings['db']['engine'] == 'postgresql': user_choice = None |
| 61 | + if settings['db']['engine'] == 'sqlite': |
| 62 | + user_choice = args.add |
| 63 | + elif settings['db']['engine'] == 'postgresql': |
| 64 | + user_choice = None |
63 | 65 |
|
64 | 66 | session = connect_database(settings, named=user_choice) |
65 | | - if user_choice: print("The database selected:", user_choice) |
| 67 | + if user_choice: |
| 68 | + print("The database selected:", user_choice) |
66 | 69 |
|
67 | 70 | # path(s) |
68 | 71 | if args.path or args.targetlist: |
|
80 | 83 |
|
81 | 84 | # -x option |
82 | 85 | elif args.service: |
83 | | - sys.exit("Items in DB: %s" % Tilde.count(session)) |
| 86 | + sys.exit("Items in DB: %s" % work.count(session)) |
84 | 87 |
|
85 | 88 | for target in target_source: |
86 | 89 |
|
87 | 90 | if not os.path.exists(target): |
88 | 91 | print('Target does not exist: ' + target) |
89 | 92 | continue |
90 | 93 |
|
91 | | - tasks = Tilde.savvyize(target, recursive=args.recursive, stemma=True) |
| 94 | + tasks = work.savvyize(target, recursive=args.recursive, stemma=True) |
92 | 95 |
|
93 | 96 | for task in tasks: |
94 | 97 |
|
95 | 98 | detected = False |
96 | | - for calc, error in Tilde.parse(task): |
| 99 | + for calc, error in work.parse(task): |
97 | 100 | output_lines, add_msg = '', '' |
98 | 101 |
|
99 | 102 | if error: |
|
102 | 105 | logging.info("%s %s" % (task, error)) |
103 | 106 | continue |
104 | 107 |
|
105 | | - calc, error = Tilde.classify(calc, args.symprec) |
| 108 | + calc, error = work.classify(calc, args.symprec) |
106 | 109 | if error: |
107 | 110 | print(task, error) |
108 | 111 | logging.info("%s %s" % (task, error)) |
|
115 | 118 | if args.info: |
116 | 119 | found_topics = [] |
117 | 120 | skip_topics = ['location', 'elements', 'nelem', 'natom', 'spg'] |
118 | | - for n, entity in enumerate(Tilde.hierarchy): |
| 121 | + for n, entity in enumerate(work.hierarchy): |
119 | 122 | if entity['cid'] > 1999 or entity['source'] in skip_topics: continue # apps hierarchy |
120 | 123 |
|
121 | 124 | if entity['multiple']: |
122 | 125 | try: found_topics.append( |
123 | | - [ entity['category'] ] + [num2name(x, entity, Tilde.hierarchy_values) for x in calc.info[ entity['source'] ]] |
| 126 | + [entity['category']] + [num2name(x, entity, work.hierarchy_values) for x in calc.info[ entity['source'] ]] |
124 | 127 | ) |
125 | 128 | except KeyError: pass |
126 | 129 | else: |
127 | | - try: found_topics.append( [ entity['category'], num2name(calc.info.get(entity['source']), entity, Tilde.hierarchy_values) ] ) |
| 130 | + try: found_topics.append( [entity['category'], num2name(calc.info.get(entity['source']), entity, work.hierarchy_values)] ) |
128 | 131 | except KeyError: pass |
129 | 132 |
|
130 | 133 | j, out = 0, '' |
131 | 134 | for t in found_topics: |
132 | 135 | out += "\t" + t[0] + ': ' + ', '.join(map(str, t[1:])) |
133 | | - out += "\t" if not j%2 else "\n" |
| 136 | + out += "\t" if not j % 2 else "\n" |
134 | 137 | j+=1 |
135 | 138 | output_lines += out[:-1] + "\n" |
136 | 139 |
|
|
160 | 163 | try: calc.structures[ args.cif ] |
161 | 164 | except IndexError: output_lines += "Warning! Structure "+args.cif+" not found!" + "\n" |
162 | 165 | else: |
163 | | - N = args.cif if args.cif>0 else len(calc.structures) + 1 + args.cif |
| 166 | + N = args.cif if args.cif > 0 else len(calc.structures) + 1 + args.cif |
164 | 167 | comment = calc.info['formula'] + " extracted from " + task + " (structure N " + str(N) + ")" |
165 | 168 | cif_file = os.path.realpath(os.path.abspath(DATA_DIR + os.sep + os.path.basename(task))) + '_' + str(args.cif) + '.cif' |
166 | 169 | if write_cif(cif_file, calc.structures[ args.cif ], comment): |
|
171 | 174 | # -m option |
172 | 175 | if args.module: |
173 | 176 | if args.module == True: |
174 | | - calc = Tilde.postprocess(calc, dry_run=True) |
| 177 | + calc = work.postprocess(calc, dry_run=True) |
175 | 178 | output_lines += "Modules to be invoked: " + str([i for i in calc.apps]) + "\n" |
176 | 179 | else: |
177 | | - calc = Tilde.postprocess(calc, args.module) |
| 180 | + calc = work.postprocess(calc, args.module) |
178 | 181 | if args.module not in calc.apps: |
179 | 182 | output_lines += "Module \"" + args.module + "\" is not suitable for this case (outside the scope defined in module manifest)!" + "\n" |
180 | 183 | else: |
|
198 | 201 |
|
199 | 202 | # -a option |
200 | 203 | if args.add: |
201 | | - checksum, error = Tilde.save(calc, session) |
| 204 | + checksum, error = work.save(calc, session) |
202 | 205 | if error: |
203 | 206 | print(task, error) |
204 | 207 | logging.info("%s %s" % (task, error)) |
205 | 208 | continue |
206 | 209 | header_line += ' added' |
207 | 210 | detected = True |
208 | 211 |
|
209 | | - if len(output_lines): output_lines = "\n" + output_lines |
| 212 | + if len(output_lines): |
| 213 | + output_lines = "\n" + output_lines |
| 214 | + |
210 | 215 | print(header_line + add_msg + output_lines) |
211 | 216 |
|
212 | 217 | if detected: |
213 | 218 | logging.info(task + " successfully processed") |
214 | | - # NB: from here the calc instance is not functional anymore! |
| 219 | + # NB: from here the calc instance is not accessible anymore |
215 | 220 |
|
216 | | -if session: session.close() |
217 | | -if args.targetlist: target_source.close() |
| 221 | +if session: |
| 222 | + session.close() |
| 223 | +if args.targetlist: |
| 224 | + target_source.close() |
218 | 225 |
|
219 | 226 | print("Done in %1.2f sc" % (time.time() - starttime)) |
0 commit comments