Save all files inside a group to either one file or a list of files.
Assumes the groups were generated using 'expand'
Parameters:
-
group
(str
, default:
'all'
)
–
name of the group to save
-
one_file
(bool
, default:
True
)
–
Saves each protein in the group to one file, if False, then saves all members individually
-
out_dir
(str
, default:
getcwd()
)
–
The directory location to save the files to
Returns:
Source code in symdesign/visualization/SymmetryMates.py
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76 | def save_group(group: str = 'all', one_file: bool = True, out_dir: str = os.getcwd()) -> None:
"""Save all files inside a group to either one file or a list of files.
Assumes the groups were generated using 'expand'
Args:
group: name of the group to save
one_file: Saves each protein in the group to one file, if False, then saves all members individually
out_dir: The directory location to save the files to
Returns:
None
"""
if group == 'all':
# remove appended symmetry mate number '_#' from the group instances and take the set of structures
expanded_group = set('_'.join(name.split('_')[:-1]) for name in cmd.get_names('group_objects', enabled_only=1))
groups = [f'{group}_expanded' for group in expanded_group]
elif cmd.get_type(group) == 'object:group':
groups = [group]
else:
print('Error: please provide a group name to save.')
return None
if one_file:
for group in groups:
cmd.save(os.path.join(out_dir, f'{group}.pdb'), group)
else:
for group in groups:
stored.models = set()
cmd.iterate(group, 'stored.models.add(model)')
for model in stored.models:
cmd.save(os.path.join(out_dir, f'{model}.pdb'), model)
|