How To Write An Interaction

From OxDNA
Jump to navigation Jump to search

The oxDNA program is written in such a way to be easily modifiable to perform research in previously unplanned research directions. One of the most common ways of doing so is to write a new interaction, to simulate a different DNA/RNA model or to simulate something else entirely, including patchy particles.

This section (currently a stub) is going to explain briefly what is needed to write such an interaction.

Files to create

  1. Interaction Header - this is the header file of your interaction. Contains the C++ header of the interaction, and should be saved in the directory src/Interactions with extension .h. The faster way to write it is probably to copy the one of an existing interaction that is somewhat similar to the interaction you want to write and modify it until you're happy with it. The name of the file should be as close as the one of the class defining the interaction, with the extension .h common to all header files. Therefore, if your interaction defines the class MyInteraction, the file could be called MyInteraction.h.
  2. Interaction Source - this is the source file of your interaction. Like the header, it should be saved in the src/Interactions directory, but it should have extension .cpp. Again, the best way to write one is to look at the .cpp file of an interaction similar to the one you are going to write and modify it as needed. The name should be the same as the header file, with the only difference that the extension should be .cpp instead of .h.

Files to modify

Here and in the following we are assuming that your interaction defines a class MyInteraction, and is saved in the files MyInteraction.h and MyInteraction.cpp. Your interaction will of course have a more informative name, so make sure to modify the following files accordingly.

  1. src/CMakeLists.txt - this files contains information on how to compile oxDNA, i.e. which files to use to produce the oxDNA executable and how to do it. The files containing the interactions are listed in the block that starts with SET(interactions_SOURCES . Add a line containing MyInteraction.cpp to the list, so that the source file will be included in the build. The header file will be included by the source file (provided it contains the appropriate #include directive).
  1. src/Interactions/InteractionFactory.cpp Now your file will be compiled, but it's still disjoint from the rest of the program. In order to make sure that the oxDNA program can use your interaction, you must modify the InteractionFactory.cpp file to use your interaction.
    1. Add the header file #include "MyInteraction.h" together with the other interaction header files, at the beginning of the file.
    2. In the function make_interaction there's a long list of statements that create a different type of interaction depending on the value of the interaction_type string in the oxDNA input file. Add your own interaction there, making sure not to mask any previously defined interactions. The syntax of the code of block might change, but currently it's just a bunch of lines like

      else if(inter_type.compare("DNA_nomesh") == 0) return new DNAInteraction_nomesh<number>();
      else if(inter_type.compare("DNA2_nomesh") == 0) return new DNA2Interaction_nomesh<number>();
      else if(inter_type.compare("LJ") == 0) return new LJInteraction<number>();
      else if(inter_type.compare("DNA_relax") == 0) return new DNAInteraction_relax<number>();
      else if(inter_type.compare("RNA") == 0) return new RNAInteraction<number>();


      so you would just add the line

      else if(inter_type.compare("my_interaction") == 0) return new MyInteraction<number>();

      somewhere over there.