Ticket #15362: vdx_attrs.py

File vdx_attrs.py, 891 bytes (added by Eric Pettersen, 17 months ago)

Added by email2trac

Line 
1from chimerax.core.utils import string_to_attr
2attr_names = set()
3numeric_attr_names = set()
4for m in session.models:
5 if hasattr(m, 'viewdockx_data'):
6 for k, v in m.viewdockx_data.items():
7 attr_name = string_to_attr(k, prefix='vdx_')
8 if attr_name not in attr_names:
9 if isinstance(v, (float, int)):
10 kw = { 'attr_type': type(v) }
11 numeric_attr_names.add(attr_name)
12 else:
13 kw = { 'attr_type': str }
14 from chimerax.atomic import Structure
15 Structure.register_attr(session, attr_name, "ViewDockX attribute script", **kw)
16 attr_names.add(attr_name)
17 setattr(m, attr_name, v)
18session.logger.info("The following numeric ViewDockX attributes were registered: %s" % ", ".join(sorted(list(numeric_attr_names))))
19session.logger.info("The following non-numeric ViewDockX attributes were registered: %s" % ", ".join(sorted(list(attr_names - numeric_attr_names))))