forked from wcatykid/Graph-Based-Molecular-Synthesis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Options.cpp
270 lines (243 loc) · 6.93 KB
/
Options.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/*
* This file is part of esynth.
*
* esynth is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* esynth is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with esynth. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string>
#include <vector>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <sys/stat.h>
#include "Options.h"
#include "Constants.h"
double Options::TANIMOTO = 0.95;
std::string Options::shmPath = "/run/shm";
std::string Options::writerPath = "./";
bool Options::THREADED = false;
bool Options::SERIAL = true;
bool Options::OPENBABEL = true;
bool Options::SMI_ONLY = false;
bool Options::USE_LIPINSKI = false;
unsigned Options::OBGEN_THREAD_POOL_SIZE = 15;
//unsigned Options::SMI_LEVEL_BOUND = 3;
unsigned Options::PROBABILITY_PRUNE_LEVEL_START = 5;
std::string Options::OUTPUT_DIR_SUFFIX = "";
Options::Options(int argCount, char** vals) : argc(argCount), argv(vals)
{
// Default values
outFile = "molecules.sdf";
outFileSMI = "molecules.smi";
validationFile = "";
Options::TANIMOTO = 0.95;
Options::THREADED = false;
}
bool Options::acquireEnvironmentVariable(const std::string& variable,
const std::string& suffix, std::string& value)
{
//
// Acquire the environment variablei value
//
char* path = getenv(variable.c_str());
if (!path)
{
std::cerr << variable << " environment variable not specified."
<< std::endl;
value = "";
return false;
}
else
{
std::cerr << variable << " environmental path: " << path << std::endl;
}
// Create the path of the actual file.
std::string filePath = path;
if (filePath[filePath.size() - 1] != '/') filePath += '/';
// Assign to the return variable.
value = filePath;
filePath += suffix;
// Check that such a file exists.
struct stat buffer;
if (stat (filePath.c_str(), &buffer) != 0)
{
std::cerr << "Specified path: " << filePath << " does not exist." << std::endl;
value = "";
return false;
}
return true;
}
bool Options::AnalyzeEnvironment()
{
bool returnVal = acquireEnvironmentVariable("COMPLIANT_WRITER", COMPLIANT_EXE, Options::writerPath);
returnVal = acquireEnvironmentVariable("SHM_PATH", "", Options::shmPath) && returnVal;
return returnVal;
}
bool Options::parseCommandLine()
{
for (int i = 1; i < argc; i++)
{
if (argv[i][0] == '-')
{
if (!handleOption(i)) return false;
}
else
{
inFiles.push_back(argv[i]);
}
}
return true;
}
//
// Deal with the actual options specified on the command-line.
//
bool Options::handleOption(int& index)
{
if (strcmp(argv[index], "-o") == 0)
{
outFile = argv[++index];
return true;
}
if (strcmp(argv[index], "-v") == 0)
{
VALIDATE = true;
validationFile = argv[++index];
return true;
}
if (strncmp(argv[index], "-tc", 3) == 0)
{
// not directly following; e.g. -tc 0.95
if (strcmp(argv[index], "-tc") == 0)
{
Options::TANIMOTO = atof(argv[++index]);
}
// -tc followed by a double value; e.g. -tc0.95
else
{
Options::TANIMOTO = atof(&argv[index][3]);
}
return true;
}
if (strncmp(argv[index], "-mw", 3) == 0)
{
if (strcmp(argv[index], "-mw") == 0)
MOLWT_UPPERBOUND = atof(argv[++index]);
else
MOLWT_UPPERBOUND = atof(&argv[index][3]);
return true;
}
if (strncmp(argv[index], "-hd", 3) == 0)
{
if (strcmp(argv[index], "-hd") == 0)
HBD_UPPERBOUND = atof(argv[++index]);
else
HBD_UPPERBOUND = atof(&argv[index][3]);
return true;
}
if (strncmp(argv[index], "-ha", 3) == 0)
{
if (strcmp(argv[index], "-ha") == 0)
HBA1_UPPERBOUND = atof(argv[++index]);
else
HBA1_UPPERBOUND = atof(&argv[index][3]);
return true;
}
if (strncmp(argv[index], "-lp", 3) == 0)
{
if (strcmp(argv[index], "-lp") == 0)
LOGP_UPPERBOUND = atof(argv[++index]);
else
LOGP_UPPERBOUND = atof(&argv[index][3]);
return true;
}
if (strncmp(argv[index], "-hl", 3) == 0)
{
if (strcmp(argv[index], "-hl") == 0)
HIERARCHICAL_LEVEL_BOUND = atoi(argv[++index]);
else
HIERARCHICAL_LEVEL_BOUND = atoi(&argv[index][3]);
return true;
}
/*
if (strncmp(argv[index], "-smi-level", 10) == 0)
{
if (strcmp(argv[index], "-smi-level") == 0)
SMI_LEVEL_BOUND = atoi(argv[++index]);
else
SMI_LEVEL_BOUND = atoi(&argv[index][10]);
return true;
}
*/
if (strncmp(argv[index], "-prob-level", 11) == 0)
{
if (strcmp(argv[index], "-prob-level") == 0)
PROBABILITY_PRUNE_LEVEL_START = atoi(argv[++index]);
else
PROBABILITY_PRUNE_LEVEL_START = atoi(&argv[index][11]);
return true;
}
if (strncmp(argv[index], "-smi-only", 9) == 0)
{
Options::SMI_ONLY = true;
return true;
}
if (strncmp(argv[index], "-serial", 7) == 0)
{
Options::THREADED = false;
Options::SERIAL = true;
return true;
}
if (strncmp(argv[index], "-threaded", 9) == 0)
{
Options::THREADED = true;
Options::SERIAL = false;
return true;
}
if (strncmp(argv[index], "-nopen", 6) == 0)
{
Options::OPENBABEL = false;
return true;
}
if (strncmp(argv[index], "-pool", 5) == 0)
{
if (strcmp(argv[index], "-mw") == 0)
OBGEN_THREAD_POOL_SIZE = atoi(argv[++index]);
else
OBGEN_THREAD_POOL_SIZE = atoi(&argv[index][5]);
return true;
}
if (strncmp(argv[index], "-odir", 5) == 0)
{
if (strcmp(argv[index], "-odir") == 0)
OUTPUT_DIR_SUFFIX = argv[++index];
return true;
}
if (strncmp(argv[index], "-lip", 4) == 0)
{
if (strcmp(argv[index], "-lip") == 0)
USE_LIPINSKI = true;
return true;
}
/*
//
// Check for an error: last command-line argument is an option (with no subsequent file)
//
if (index + 1 >= argc)
{
std::cerr << "Specified option " << argv[index]
<< " not followed by the option value." << std::endl;
return false;
}
*/
return false;
}