First, use the SAMSON Element generator to create a new SAMSON Element containing one app class. We refer to the SAMSON Element generator tutorial for a reminder on how to generate a new SAMSON Element.
Launch SAMSON and invoke the SAMSON Element generator. Select a folder where you want to generate a SAMSON Element.
SEAtomShakerAppGUI: the main GUI, which implements the user interface of the app.
Each class has its own pair of hpp (header) and cpp (code) files. The SEAtomShakerAppGUI class also goes with the ui file for GUI.
Let's now programm the App.
Note how the apps are sorted alphabetically.
The default interface contains a label with a developer tip. Delete the label and add a QPushButton.
We’re done with this interface for now. We can save it and quit the interface editor.
Here, first, we collect all atoms in the active document, and store pointers to them in a node indexer nodeIndexer. The SBNode::IsType(SBNode::Atom) is a predicate (i.e. an object that contains a function returning true or false when it is applied to a node). When passed to the getNodes function, it ensures that only atoms are added to the node indexer.
We set the status message in SAMSON saying how many atoms were found.
All nodes in the document derive (directly or indirectly) from the SBNode class. The node indexer stores pointers to nodes, and the type of the node variable is thus SBNode*. In order to use functionalities of atoms (such as the getPosition and setPosition function), we need to cast node to a pointer to a SBAtom object.
All physical quantities (lengths, energies, etc.) are strongly typed in SAMSON: they are not mere floating-point values, but have associated units. We thus need to specify the unit of the displacement, for that we use SBQuantity::angstrom.
The unit mechanism integrated in SAMSON ensures that developers from different backgrounds may work with units relevant to them, while ensuring physical correctness and preserving integration between SAMSON Elements of various origins. For a test, try to replace angstrom(1.0) by e.g. electronVolt(1.0), and the code will not compile, whereas picometer(100.0) will compile and give the same result as angstrom(1.0). Please, refer to the Units for more information.
This spin box will define the maximum shaking distance in angstrom for each atom.
Here, we send the maximum distance from the GUI to the shakeAtoms function of the app class.
Note that here we are using SBQuantity::length and in the GUI class we are sending SBQuantity::angstrom. This is possible thanks to SAMSON's units.
Here, we change atoms' positions by a user defined maximum distance multiplied by a random number in the interval (-0.5, 0.5).
Now, users can specify the maximum shaking distance.