Skip to content
This repository was archived by the owner on Aug 16, 2022. It is now read-only.

Commit bef7c08

Browse files
committed
Format code & refactor
1 parent f7c9de7 commit bef7c08

File tree

1 file changed

+28
-21
lines changed

1 file changed

+28
-21
lines changed

utils/entry.py

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828

2929
starttime = time.time()
30-
Tilde = API()
30+
work = API()
3131

3232
parser = argparse.ArgumentParser(
3333
prog="[this_script]",
@@ -43,7 +43,7 @@
4343
parser.add_argument("-v", dest="convergence", action="store", help="print calculation convergence", type=bool, metavar="", nargs='?', const=True, default=False)
4444
parser.add_argument("-f", dest="freqs", action="store", help="print phonons", type=bool, metavar="", nargs='?', const=True, default=False)
4545
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()))
4747
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)
4848
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)
4949
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,11 +58,14 @@
5858

5959
# -a option
6060
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
6365

6466
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)
6669

6770
# path(s)
6871
if args.path or args.targetlist:
@@ -80,20 +83,20 @@
8083

8184
# -x option
8285
elif args.service:
83-
sys.exit("Items in DB: %s" % Tilde.count(session))
86+
sys.exit("Items in DB: %s" % work.count(session))
8487

8588
for target in target_source:
8689

8790
if not os.path.exists(target):
8891
print('Target does not exist: ' + target)
8992
continue
9093

91-
tasks = Tilde.savvyize(target, recursive=args.recursive, stemma=True)
94+
tasks = work.savvyize(target, recursive=args.recursive, stemma=True)
9295

9396
for task in tasks:
9497

9598
detected = False
96-
for calc, error in Tilde.parse(task):
99+
for calc, error in work.parse(task):
97100
output_lines, add_msg = '', ''
98101

99102
if error:
@@ -102,7 +105,7 @@
102105
logging.info("%s %s" % (task, error))
103106
continue
104107

105-
calc, error = Tilde.classify(calc, args.symprec)
108+
calc, error = work.classify(calc, args.symprec)
106109
if error:
107110
print(task, error)
108111
logging.info("%s %s" % (task, error))
@@ -115,22 +118,22 @@
115118
if args.info:
116119
found_topics = []
117120
skip_topics = ['location', 'elements', 'nelem', 'natom', 'spg']
118-
for n, entity in enumerate(Tilde.hierarchy):
121+
for n, entity in enumerate(work.hierarchy):
119122
if entity['cid'] > 1999 or entity['source'] in skip_topics: continue # apps hierarchy
120123

121124
if entity['multiple']:
122125
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'] ]]
124127
)
125128
except KeyError: pass
126129
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)] )
128131
except KeyError: pass
129132

130133
j, out = 0, ''
131134
for t in found_topics:
132135
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"
134137
j+=1
135138
output_lines += out[:-1] + "\n"
136139

@@ -160,7 +163,7 @@
160163
try: calc.structures[ args.cif ]
161164
except IndexError: output_lines += "Warning! Structure "+args.cif+" not found!" + "\n"
162165
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
164167
comment = calc.info['formula'] + " extracted from " + task + " (structure N " + str(N) + ")"
165168
cif_file = os.path.realpath(os.path.abspath(DATA_DIR + os.sep + os.path.basename(task))) + '_' + str(args.cif) + '.cif'
166169
if write_cif(cif_file, calc.structures[ args.cif ], comment):
@@ -171,10 +174,10 @@
171174
# -m option
172175
if args.module:
173176
if args.module == True:
174-
calc = Tilde.postprocess(calc, dry_run=True)
177+
calc = work.postprocess(calc, dry_run=True)
175178
output_lines += "Modules to be invoked: " + str([i for i in calc.apps]) + "\n"
176179
else:
177-
calc = Tilde.postprocess(calc, args.module)
180+
calc = work.postprocess(calc, args.module)
178181
if args.module not in calc.apps:
179182
output_lines += "Module \"" + args.module + "\" is not suitable for this case (outside the scope defined in module manifest)!" + "\n"
180183
else:
@@ -198,22 +201,26 @@
198201

199202
# -a option
200203
if args.add:
201-
checksum, error = Tilde.save(calc, session)
204+
checksum, error = work.save(calc, session)
202205
if error:
203206
print(task, error)
204207
logging.info("%s %s" % (task, error))
205208
continue
206209
header_line += ' added'
207210
detected = True
208211

209-
if len(output_lines): output_lines = "\n" + output_lines
212+
if len(output_lines):
213+
output_lines = "\n" + output_lines
214+
210215
print(header_line + add_msg + output_lines)
211216

212217
if detected:
213218
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
215220

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()
218225

219226
print("Done in %1.2f sc" % (time.time() - starttime))

0 commit comments

Comments
 (0)