Skip to content

Writing a new tool without python

Tod Romo edited this page Oct 21, 2022 · 3 revisions

Developing LOOS tools in python is pretty straightforward -- you import the loos library, and start writing. However, there's a little more involved in writing a C++ tool, since it has to get compiled and linked against the loos library. Although in principle you can manage all of that for yourself, we've tried to make the process a bit easier with Packages/User.

The first question you should ask yourself is, is C++ necessary, or would a python script be sufficient? C++ is noticeably faster, but it's also more difficult to develop and adapt the code, and often runtime performance isn't all that important. However, if we assume you're planning to write a standalone tool in C++, Packages/User is most likely where you'll want to work.

First, there are a number of example programs in that Package that will give you a good idea of what LOOS code should look like. There are 4 examples, covering the 4 basic use cases for LOOS

  1. simple_model_calc.cpp is a skeleton of a program that would calculate a property of a single structure
  2. simple_model_transform.cpp lays out what a program that alters a single structure would look like
  3. traj_calc.cpp sketches calculating a property for each frame from a trajectory
  4. traj_transform.cpp shows what executing a geometric transformation on a trajectory would look like.

Each of these programs is a skeleton that sets up to do a particular task -- read command-line options, initialize the system, prepare to write output, etc -- but doesn't actually do anything useful. These programs could make good starting points for many analyses (there are analogous python scripts in Packages/PyLOOS.

Second, working in Packages/User makes it very easy to handle building and linking your tool. Suppose you've written mycoolanalysis.cpp; to make it part of the build simply requires editing Packages/User/CMakeLists.txt. Specifically, you'd need to add a line to the set statement that defines the list of LOOS user tools,

set(LOOS_USER_TOOLS
    model_calc
    simple_model_calc
    simple_model_transform
    traj_calc
    traj_transform
)

to instead be

set(LOOS_USER_TOOLS
    model_calc
    simple_model_calc
    simple_model_transform
    traj_calc
    traj_transform
    mycoolanalysis
)

Then, re-run your build using cmake. See instructions in the INSTALL file.