-
Notifications
You must be signed in to change notification settings - Fork 4
/
rewriteDepositories.py
56 lines (36 loc) · 1.6 KB
/
rewriteDepositories.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python
# encoding: utf-8
import os
from rmgpy import settings
from rmgpy.data.kinetics import KineticsDatabase, saveEntry
###############################################################################
def main():
db = KineticsDatabase()
db.loadFamilies(os.path.join(settings['database.directory'],
'kinetics/families'))
for family in db.families.values():
for depository in family.depositories:
if 'NIST' in depository.name:
entries = depository.entries.values()
entries.sort(key=lambda entry: sum([1 for r in entry.item.reactants for a in r.atoms if a.isNonHydrogen()]))
print 'Rewriting {0}...'.format(depository.name),
rewrite(entries, depository.name)
print 'done.'
###############################################################################
def rewrite(entries, name):
file = os.path.join(settings['database.directory'], 'kinetics/families',
'{0}.py'.format(name))
open(file, 'w').write('#!/usr/bin/env python\n'
'# encoding: utf-8\n\n'
'name = "{0}"\n'.format(name) +
'shortDesc = u""\n'
'longDesc = u"""\n\n"""\n'
'recommended = False\n\n')
index = 0
for entry in entries:
index += 1
entry.index = index
saveEntry(open(file, 'a'), entry)
###############################################################################
if __name__ == '__main__':
main()