| 1 | from chimerax.core.utils import string_to_attr
|
|---|
| 2 | attr_names = set()
|
|---|
| 3 | numeric_attr_names = set()
|
|---|
| 4 | for 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)
|
|---|
| 18 | session.logger.info("The following numeric ViewDockX attributes were registered: %s" % ", ".join(sorted(list(numeric_attr_names))))
|
|---|
| 19 | session.logger.info("The following non-numeric ViewDockX attributes were registered: %s" % ", ".join(sorted(list(attr_names - numeric_attr_names))))
|
|---|