RxDock 0.1.0
A fast, versatile, and open-source program for docking ligands to proteins and nucleic acids
Loading...
Searching...
No Matches
Command.h
1/***********************************************************************
2 * The rDock program was developed from 1998 - 2006 by the software team
3 * at RiboTargets (subsequently Vernalis (R&D) Ltd).
4 * In 2006, the software was licensed to the University of York for
5 * maintenance and distribution.
6 * In 2012, Vernalis and the University of York agreed to release the
7 * program as Open Source software.
8 * This version is licensed under GNU-LGPL version 3.0 with support from
9 * the University of Barcelona.
10 * http://rdock.sourceforge.net/
11 ***********************************************************************/
12
13// Command Class. Command represents a function or input variable of the CGP
14
15#ifndef _RBT_COMMAND_H_
16#define _RBT_COMMAND_H_
17
18#include "rxdock/geneticprogram/GPTypes.h"
19
20#include <cmath>
21
22namespace rxdock {
23
24class Command {
25public:
26 virtual ReturnType Execute() = 0;
27 virtual int GetNArgs() = 0;
28 virtual std::string GetName() = 0;
29 virtual void SetArg(int i, ReturnType f) = 0; // { *(Arg[i]) = f;};
30 virtual void SetNameArg(int i, std::string &n) = 0; // { NameArg[i] = n;};
31 static void Clear() { ntabs = 0; }
32
34 // Destructor
36 virtual ~Command() {}
37 static int ntabs;
38 static bool inside;
39
40protected:
42 // Constructors
44 Command() {} // Default constructor disabled
45 std::string tabs(int n) {
46 std::string st = "";
47 for (int i = 0; i < n; i++)
48 st += " ";
49 return st;
50 }
51
52private:
53 // friend std::ostream& operator<<(std::ostream& s, const Command &p);
54};
55
56// Useful typedefs
57typedef SmartPtr<Command> CommandPtr; // Smart pointer
58typedef std::vector<CommandPtr> CommandList; // Vector of smart pointers
59typedef CommandList::iterator CommandListIter;
60typedef CommandList::const_iterator CommandListConstIter;
61class AddCommand : public Command {
62public:
63 int GetNArgs() { return 2; }
64 std::string GetName() { return ("(" + NameArg[0] + "+ " + NameArg[1] + ")"); }
65 AddCommand() {} //{Arg = ReturnType(2);}
66 void SetArg(int i, ReturnType f) { Arg[i] = f; }
67 void SetNameArg(int i, std::string &n) { NameArg[i] = n; }
68 ReturnType Execute() { return Arg[0] + Arg[1]; }
69
70private:
71 ReturnType Arg[2];
72 std::string NameArg[2];
73};
74
75class SubCommand : public Command {
76public:
77 int GetNArgs() { return 2; }
78 std::string GetName() { return ("(" + NameArg[0] + "- " + NameArg[1] + ")"); }
79 void SetArg(int i, ReturnType f) { Arg[i] = f; }
80 void SetNameArg(int i, std::string &n) { NameArg[i] = n; }
81 SubCommand() {}
82 ReturnType Execute() { return Arg[0] - Arg[1]; }
83
84private:
85 ReturnType Arg[2];
86 std::string NameArg[2];
87};
88
89class MulCommand : public Command {
90public:
91 int GetNArgs() { return 2; }
92 std::string GetName() { return ("(" + NameArg[0] + "* " + NameArg[1] + ")"); }
93 void SetArg(int i, ReturnType f) { Arg[i] = f; }
94 void SetNameArg(int i, std::string &n) { NameArg[i] = n; }
95 MulCommand() {}
96 ReturnType Execute() { return Arg[0] * Arg[1]; }
97
98private:
99 ReturnType Arg[2];
100 std::string NameArg[2];
101};
102
103class DivCommand : public Command {
104public:
105 int GetNArgs() { return 2; }
106 std::string GetName() {
107 return ("(" + NameArg[0] + "div " + NameArg[1] + ")");
108 }
109 DivCommand() {}
110 void SetArg(int i, ReturnType f) { Arg[i] = f; }
111 void SetNameArg(int i, std::string &n) { NameArg[i] = n; }
112 ReturnType Execute() {
113 if (std::fabs(Arg[1]) < 0.000001)
114 return Arg[0];
115 return Arg[0] / Arg[1];
116 }
117
118private:
119 ReturnType Arg[2];
120 std::string NameArg[2];
121};
122
123class IfCommand : public Command {
124public:
125 int GetNArgs() { return 3; }
126 std::string GetName() {
127 // return ("\niff(" + NameArg[0] + "," + NameArg[1] + "," +
128 // NameArg[2] + ")");};
129 if (inside)
130 return ("iff(" + NameArg[0] + " , " + NameArg[1] + " , " + NameArg[2] +
131 ")");
132 return ("\n" + tabs(ntabs - 1) + "if " + NameArg[0] + "> 0 then\n" +
133 tabs(ntabs) + NameArg[1] + "\n" + tabs(ntabs - 1) + "else \n" +
134 tabs(ntabs) + NameArg[2] + "\n" + tabs(ntabs - 1) + "end\n");
135 }
136 IfCommand() {}
137 void SetArg(int i, ReturnType f) { Arg[i] = f; }
138 void SetNameArg(int i, std::string &n) { NameArg[i] = n; }
139 ReturnType Execute() {
140 if (Arg[0] > 0.0)
141 return Arg[1];
142 return Arg[2];
143 }
144
145private:
146 ReturnType Arg[3];
147 std::string NameArg[3];
148};
149
150class LogCommand : public Command {
151public:
152 int GetNArgs() { return 1; }
153 std::string GetName() { return ("log(" + NameArg[0] + ")"); }
154 LogCommand() {}
155 void SetArg(int i, ReturnType f) { Arg[i] = f; }
156 void SetNameArg(int i, std::string &n) { NameArg[i] = n; }
157 ReturnType Execute() {
158 if (std::fabs(Arg[0]) < 0.000001)
159 return 0;
160 return (std::log(std::fabs(Arg[0])));
161 }
162
163private:
164 ReturnType Arg[1];
165 std::string NameArg[1];
166};
167
168class ExpCommand : public Command {
169public:
170 int GetNArgs() { return 1; }
171 std::string GetName() { return ("exp(" + NameArg[0] + ")"); }
172 ExpCommand() {}
173 void SetArg(int i, ReturnType f) { Arg[i] = f; }
174 void SetNameArg(int i, std::string &n) { NameArg[i] = n; }
175 ReturnType Execute() {
176 if (Arg[0] > 200)
177 return std::exp(200);
178 if (Arg[0] < -200)
179 return 0;
180 return std::exp(Arg[0]);
181 }
182
183private:
184 ReturnType Arg[2];
185 std::string NameArg[2];
186};
187
188} // namespace rxdock
189
190#endif //_Command_H_
Definition Command.h:61
Definition Command.h:24
Definition Command.h:103
Definition Command.h:168
Definition Command.h:123
Definition Command.h:150
Definition Command.h:89
Definition SmartPointer.h:48
Definition Command.h:75