Setting attributes#
This page documents view.set(...).
view.set(...) assigns new values to attributes of the molecular system.
This is a live operation: it mutates the system behind the view and refreshes the viewer so the change becomes visible.
set is a wrapper around MolSysMT’s set, so the attribute names and selection rules follow MolSysMT.
For more details and additional examples, see the MolSysMT tutorial: Set.
Elements and attribute names#
set operates on selected elements (atoms, groups, molecules, …). Here is a quick reminder of the most common element levels:
Element |
Meaning |
|---|---|
|
Atoms of the molecular system. |
|
First supra-atomic chemical level: amino acids, waters, ions, lipids, etc. |
|
A covalently connected set of atoms (a covalent component). |
|
A single molecular instance (one water molecule, one benzene molecule, etc.). |
|
An author-defined grouping that can vary across sources; it may represent anything from a polymer chain to a higher-level supra-molecular partition. |
|
Molecular nature/type. For example, you can have two entities (water and benzene) and six molecules (four waters and two benzenes). |
|
The whole molecular system. |
|
Covalent connectivity between atoms (may be absent or inferred depending on the input). |
For a quick reference of common attribute names (the keywords you pass as ...=value), see Getting attributes.
import molsysviewer as viewer
view = viewer.demo["181L"]
view.show()
Example: rename a group#
Here we rename a single group (by group_index) and then revert the change.
This is a simple example, but it shows the mental model: select what you want to modify, then set a new value.
We start by retrieving the current group name so we can safely restore it at the end.
old_name = view.get(element="group", selection="group_index==30", group_name=True)[0]
old_name
'HIS'
view.set(selection="group_index==30", group_name="HSD")
view.get(element="group", selection="group_index==30", group_name=True)
['HSD']
A second example: split chain names#
In MolSysMT/MolSysViewer, a “chain” is a topological level that may depend on how the input was authored.
In this demo, all chains start with the same chain name ("A"). We will assign the name "B" to every chain whose index is not 0.
This is a convenient way to quickly separate the main polymer chain from everything else in the metadata.
view.get(element="chain", chain_index=True, chain_id=True, chain_name=True, output_type="dictionary")
{'chain_index': [0, 1, 2, 3, 4, 5],
'chain_id': ['A', 'B', 'C', 'D', 'E', 'F'],
'chain_name': ['A', 'A', 'A', 'A', 'A', 'A']}
view.set(element="chain", selection="chain_index!=0", chain_name="B")
view.get(element="chain", chain_index=True, chain_id=True, chain_name=True, output_type="dictionary")
{'chain_index': [0, 1, 2, 3, 4, 5],
'chain_id': ['A', 'B', 'C', 'D', 'E', 'F'],
'chain_name': ['A', 'B', 'B', 'B', 'B', 'B']}