Differentiating Containers¶
Sims and Groups can be used to develop “fire-and-forget” analysis routines. Large numbers of Containers can be fed to an analysis code to give that code access to all trajectory and intermediate data, with individual Containers handled according to their characteristics. To make it possible to write code that tailors its approach according to the Container it encounters, we can use tags and categories.
Tags are individual strings that describe a Container. Using our Sim
marklar
as an example, we can add many tags at once
>>> from mdsynthesis import Sim
>>> s = Sim('marklar')
>>> s.tags.add('TIP4P', 'ADK', 'kinases', 'globular', 'equilibrium')
>>> s.tags
<Tags(['ADK', 'TIP4P', 'equilibrium', 'globular', 'kinases'])>
They can be iterated through as well
>>> for tag in s.tags:
>>> print tag
kinases
globular
ADK
TIP4P
equilibrium
Categories are key-value pairs of strings. They are particularly useful as
switches for analysis code. For example, if we are simulating two different
states of a protein (say, “open” and “closed”), we can make a category that
reflects this. In this case, we categorize marklar
as “open”
>>> s.categories['state'] = 'open'
>>> s.categories
<Categories({'state': 'open'})>
Perhaps we’ve written some analysis code that will take both “open” and “closed” simulation trajectories as input but needs to handle them differently. It can see what variety of Sim it is working with using
>>> s.categories['state']
'open'
Reference: Tags¶
The class mdsynthesis.core.aggregators.Tags
is the interface used
by Containers to access their tags. It is not intended to be used on its own,
but is shown here to give a detailed view of its methods.
-
class
mdsynthesis.core.aggregators.
Tags
(container, containerfile, logger)¶ Interface to tags.
-
add
(*tags)¶ Add any number of tags to the Container.
Tags are individual strings that serve to differentiate Containers from one another. Sometimes preferable to categories.
Arguments: - tags
Tags to add. Must be convertable to strings using the str() builtin. May also be a list of tags.
-
remove
(*tags, **kwargs)¶ Remove tags from Container.
Any number of tags can be given as arguments, and these will be deleted.
Arguments: - tags
Tags to delete.
Keywords: - all
When True, delete all tags [
False
]
-
Reference: Categories¶
The class mdsynthesis.core.aggregators.Categories
is the interface
used by Containers to access their categories. It is not intended to be used on
its own, but is shown here to give a detailed view of its methods.
-
class
mdsynthesis.core.aggregators.
Categories
(container, containerfile, logger)¶ Interface to categories.
-
add
(*categorydicts, **categories)¶ Add any number of categories to the Container.
Categories are key-value pairs of strings that serve to differentiate Containers from one another. Sometimes preferable to tags.
If a given category already exists (same key), the value given will replace the value for that category.
Keywords: - categorydict
dict of categories to add; keys used as keys, values used as values. Both keys and values must be convertible to strings using the str() builtin.
- categories
Categories to add. Keyword used as key, value used as value. Both must be convertible to strings using the str() builtin.
-
keys
()¶ Get category keys.
Returns: - keys
keys present among categories
-
remove
(*categories, **kwargs)¶ Remove categories from Container.
Any number of categories (keys) can be given as arguments, and these keys (with their values) will be deleted.
Arguments: - categories
Categories to delete.
Keywords: - all
When True, delete all categories [
False
]
-
values
()¶ Get category values.
Returns: - values
values present among categories
-