Appending structures#

This page documents view.append_structures(...).

view.append_structures(...) appends additional structures to the current molecular system.

If your molecular system represents a trajectory, structures are often called “frames”. Appending structures is the most common way to extend a trajectory with an additional chunk.

append_structures is a live operation: it mutates the system behind the view and refreshes the viewer so the change is reflected in the browser.

For more details and additional examples, see the MolSysMT tutorial: Append structures.

Example: append a second structure#

In Adding elements, we combined two systems by increasing the number of atoms.

Here we do something different: we keep the same atoms and topology, but we add a second set of coordinates. The result is a molecular system with two structures.

A key requirement is that the system you append from represents the same topology. In this example, we guarantee that by appending from a translated copy of the same system.

import molsysviewer as viewer

view = viewer.demo["dialanine"]
view.get(element="system", n_structures=True)

1
view.show()

Now let’s add the second structure:

import molsysmt as msm

second_structure = msm.copy(view.molsys)
msm.structure.translate(second_structure, translation='[0.2, 0.0, 0.0] nm', in_place=True)

view.append_structures(second_structure)
view.get(element="system", n_structures=True)
2

If you open the viewer controls and move between structures, you should see the dialanine shift position between structure 0 and structure 1 like this: