IMP logo
IMP Manual  for IMP version 2.16.0
new_code.md
1 Writing new code {#new_code}
2 ================
3 
4 The easiest way to start writing new functions and classes is to
5 create a new module using the [make-module.py](\ref dev_tools_make_module)
6 script. This creates a new module in the `modules` directory. Alternatively,
7 you can simply use the `scratch` module.
8 
9 If, instead, you choose to add code to an existing module, you need to
10 consult with the maintainer of that module. Their GitHub username
11 can be found on the [module main page](../ref/namespaces.html).
12 
13 Either way, we highly recommend doing this in a [git clone](@ref devsetup),
14 as described earlier, then using [git](@ref faq_git) to keep track of
15 changes to your code.
16 
17 When designing the interface for your new code, you should
18 
19 - think about what exactly is the functionality you want to contribute. Is
20  it a single function, a single Restraint, a set of related classes
21  and functions?
22 
23 - search %IMP for similar functionality and, if there is any, adapt
24  the existing interface for your purposes. (It might make more sense to
25  modify the existing code in cooperation with its author.) For example,
26  the existing
27  IMP::atom::read_pdb() and IMP::atom::write_pdb() functions provide
28  templates that should be used for the design of any functions that
29  create particles from a file or write particles to a file. Since
31  IMP::display::Geometry all use methods like
33  endpoints of a segment, any new object which defines similar
34  point-based geometry should do likewise.
35 
36 - think about how other people are likely to use the code. For
37  example, not all molecular hierarchies have atoms as their leaves,
38  so make sure your code searches for arbitrary
39  IMP::core::XYZ particles rather than atoms if you only care
40  about the geometry.
41 
42 - look for easy ways of splitting the functionality into pieces. It
43  generally makes sense, for %example, to split selection of the
44  particles from the action taken on them, either by accepting a
45  IMP::Refiner, a IMP::SingletonContainer or just an arbitrary
46  IMP::ParticleIndexes object. Similarly, rather than writing a Restraint,
47  it may make more sense to write an IMP::PairScore or IMP::UnaryFunction;
48  an IMP::SingletonModifier may be more appropriate than an IMP::Constraint.
49 
50 You are encouraged to post to the
51 [imp-dev list](https://integrativemodeling.org/contact.html) to find help
52 answering these questions as it can be hard to grasp all the various
53 pieces of functionality already in the repository.
54 
55 See also the IMP::example module, which contains many examples of writing
56 new %IMP functionality in C++ or Python.
57 You may also want to read [the design example](\ref design_example) for
58 some suggestions on how to go about implementing your functionality
59 in %IMP.
const Vector3D & get_point(unsigned int i) const