ProteinRibbons
Repository source: ProteinRibbons
Description¶
This example reads Protein Data Bank files. The example expects a file in .pdb format.
Here src/Testing/Data/2j6g.pdb
is the sample file.
Other languages
See (Java)
Question
If you have a question about this example, please use the VTK Discourse Forum
Code¶
ProteinRibbons.cxx
#include <vtkActor.h>
#include <vtkCamera.h>
#include <vtkInteractorStyleSwitch.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkPDBReader.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkProteinRibbonFilter.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
int main(int argc, char* argv[])
{
if (argc < 2)
{
std::cout << "Usage: " << argv[0] << " file.pdb e.g. 2j6g.pdb" << std::endl;
return EXIT_FAILURE;
}
std::string fileName(argv[1]);
// read protein from pdb
vtkNew<vtkPDBReader> reader;
reader->SetFileName(fileName.c_str());
// setup ribbon filter
vtkNew<vtkProteinRibbonFilter> ribbonFilter;
ribbonFilter->SetInputConnection(reader->GetOutputPort());
// setup poly data mapper
vtkNew<vtkPolyDataMapper> polyDataMapper;
polyDataMapper->SetInputConnection(ribbonFilter->GetOutputPort());
// setup actor
vtkNew<vtkActor> actor;
actor->SetMapper(polyDataMapper);
actor->GetProperty()->SetDiffuse(.7);
actor->GetProperty()->SetSpecular(.5);
actor->GetProperty()->SetSpecularPower(80.0);
// setup render window
vtkNew<vtkRenderer> renderer;
vtkNew<vtkRenderWindow> renderWindow;
renderWindow->AddRenderer(renderer);
vtkNew<vtkRenderWindowInteractor> interactor;
interactor->SetRenderWindow(renderWindow);
vtkInteractorStyleSwitch* style =
dynamic_cast<vtkInteractorStyleSwitch*>(interactor->GetInteractorStyle());
style->SetCurrentStyleToTrackballCamera();
vtkNew<vtkNamedColors> colors;
renderer->AddActor(actor);
renderer->SetBackground(colors->GetColor3d("Silver").GetData());
renderWindow->SetSize(640, 480);
renderWindow->SetWindowName("ProteinRibbons");
renderWindow->Render();
renderer->ResetCamera();
renderer->GetActiveCamera()->Azimuth(45);
renderer->GetActiveCamera()->Elevation(45);
renderer->GetActiveCamera()->Zoom(1.7);
renderer->ResetCameraClippingRange();
renderWindow->Render();
// Finally render the scene
renderWindow->SetMultiSamples(0);
interactor->Initialize();
interactor->Start();
return EXIT_SUCCESS;
}
CMakeLists.txt¶
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
project(ProteinRibbons)
find_package(VTK COMPONENTS
CommonColor
CommonCore
DomainsChemistry
DomainsChemistryOpenGL2
IOChemistry
InteractionStyle
RenderingContextOpenGL2
RenderingCore
RenderingFreeType
RenderingGL2PSOpenGL2
RenderingOpenGL2
)
if (NOT VTK_FOUND)
message(FATAL_ERROR "ProteinRibbons: Unable to find the VTK build folder.")
endif()
# Prevent a "command line is too long" failure in Windows.
set(CMAKE_NINJA_FORCE_RESPONSE_FILE "ON" CACHE BOOL "Force Ninja to use response files.")
add_executable(ProteinRibbons MACOSX_BUNDLE ProteinRibbons.cxx )
target_link_libraries(ProteinRibbons PRIVATE ${VTK_LIBRARIES}
)
# vtk_module_autoinit is needed
vtk_module_autoinit(
TARGETS ProteinRibbons
MODULES ${VTK_LIBRARIES}
)
Download and Build ProteinRibbons¶
Click here to download ProteinRibbons and its CMakeLists.txt file. Once the tarball ProteinRibbons.tar has been downloaded and extracted,
cd ProteinRibbons/build
If VTK is installed:
cmake ..
If VTK is not installed but compiled on your system, you will need to specify the path to your VTK build:
cmake -DVTK_DIR:PATH=/home/me/vtk_build ..
Build the project:
make
and run it:
./ProteinRibbons
WINDOWS USERS
Be sure to add the VTK bin directory to your path. This will resolve the VTK dll's at run time.