Skip to content
dstoeckel edited this page Jun 9, 2015 · 3 revisions

In the following we will create a small application that uses the VIEW library to display a protein from a PDBFile. In essence the required steps are:

  • Create the GUI
  • Load the protein
  • Apply normalization and reconstruct bonds
  • Display the protein.

To understand these steps, a little knowledge about the inner workings of the VIEW library is required. The main component in every VIEW application is the MainControl. It provides a central hub through which all other components interact. Instantiating a MainControl instance is usually one of the first things you want to do in a VIEW Application:

int main(int argc, char* argv[]) 
{
  // VIEW is based on the Qt toolkit and
  // needs a QApplication object to work
  // properly
  QApplication app(ac, av);

  // Instantiate a MainControl object
  BALL::VIEW::MainControl control;

  // Register the control so that other
  // components can access it.
  control.registerThis();

  // Initialize other components here

  // Show the main window 
  control.show();

  return app.exec();
}

We now can setup the second most important part of a VIEW application: the Scene. The Scene manages the rendering of molecules and is responsible for displaying them on screen.

  // Create a Scene object
  auto scene = new BALL::VIEW::Scene(&control);

  // Set the scene as the central widget of the MainControl.
  // The behaviour of this function is documented here:
  // http://doc.qt.io/qt-4.8/qmainwindow.html#setCentralWidget
  control.setCentralWidget(scene);

Now our application is ready to go and can be used to view molecules. For this purpose we create a representation, which takes a Molecule, Protein or any other BALL Composite and generates a model that we can view. We can create representations using the RepresentationManager object that is part of the MainControl.

  // Get the RepresentationManager
  auto& repManager = control.getRepresentationManager();

  // Create a blank representation that we can fill.
  auto* rep = repManager.createRepresentation();
 
  // Hook up a composite with our representation-
  rep->setComposite(system);

  // We want to create a cartoon model of the backbone that is coloured
  // according to the secondary structure elements.
  rep->setColorProcessor(new SecondaryStructureColorProcessor());
  rep->setModelProcessor(new AddCartoonModel());
 
  // Tell the MainControl to display the representation.
  control.update(*rep);
 
  // Centre the camera on the representation we just
  // created.
  repManager.focusRepresentation(*rep);

You can find the full code for this application in the following gist.

Clone this wiki locally