forked from Pymol-Scripts/Pymol-script-repo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
save_settings.py
53 lines (43 loc) · 1.69 KB
/
save_settings.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
'''
http://pymolwiki.org/index.php/save_settings
(c) 2011 Thomas Holder, MPI for Developmental Biology
License: BSD-2-Clause
'''
from __future__ import print_function
from pymol import cmd, CmdException
def save_settings(filename='~/.pymolrc-settings.py', quiet=1):
'''
DESCRIPTION
Dumps all settings with non-default values to ~/.pymolrc-settings.py
Feature Request: Save settings for later use - ID: 1009951
https://sourceforge.net/tracker/?func=detail&aid=1009951&group_id=4546&atid=354546
'''
from pymol.setting import get_name_list
quiet = int(quiet)
if not filename.endswith('.py'):
print('Warning: filename should end with ".py"')
# temporatily load default settings and remember them
cmd.reinitialize('store_defaults')
cmd.reinitialize('original_settings')
original = [(name, cmd.get(name)) for name in get_name_list()]
cmd.reinitialize('settings')
# dump to file
filename = cmd.exp_path(filename)
f = open(filename, 'w')
print('# AUTOGENERATED FILE', file=f)
print('from pymol import cmd, invocation', file=f)
print('if invocation.options.show_splash:', end=' ', file=f) # no newline
print(' print("Loading settings from", ' + repr(filename) + ')', file=f)
count = 0
for name, o_value in original:
value = cmd.get(name)
if value != o_value:
print('cmd.set("%s", %s)' % (name, repr(value)), file=f)
if not quiet:
print('set %s, %s ;# default: %s' % (name, value, o_value))
count += 1
f.close()
if not quiet:
print('Dumped %d settings to %s' % (count, filename))
cmd.extend('save_settings', save_settings)
# vi:expandtab:smarttab