Adding elements#
This page documents view.add(...).
You will use view.add(...) when you want to combine two molecular systems into a single view.
In practice, that often means things like adding a small molecule to a protein system, or bringing two fragments together so you can inspect them side by side.
add is a live operation: it mutates the system behind the view (view.molsys) and refreshes the viewer so the change is reflected in the browser.
For more details and additional examples, see the MolSysMT tutorial: Add.
If you want to undo an add, reload the view (or re-create it from the original data).
If what you need is to append structures (for example, to grow a trajectory), see Appending structures.
Example: add another system#
Here we build a tiny “two-peptide” system by adding a translated copy of the same peptide.
This is a simple toy example, but it shows two practical points:
addtakes a MolSysMT-compatible molecular system object (here, we reuseview.molsys).It is usually worth translating/rotating the second system before adding it, to avoid overlap.
Because add merges two systems, the total number of atoms increases, and indices in the resulting system reflect the merged topology.
In this example we will:
Load a viewer with dialanine.
Create a second dialanine and translate it so it does not overlap.
Add the translated dialanine to the viewer and confirm the change with a simple system-level query.
import molsysviewer as viewer
view = viewer.demo["dialanine"]
view.get(n_peptides=True)
1
By default, view.get(...) queries the system element, so calls like view.get(n_peptides=True) are shorthand for “system-level” questions.
view.show()
Now we create a second dialanine and shift it in space.
Without the translation, the two copies would largely overlap after add, which makes the result harder to inspect.
import molsysmt as msm
second_dialanine = msm.copy(view.molsys)
msm.structure.translate(second_dialanine, translation='[2.0, 0.0, 0.0] nm', in_place=True)
Now we add the translated dialanine to the viewer:
view.add(second_dialanine)
view.get(n_peptides=True)
2
Your final view should look like this: