forked from plumed/plumed2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Keywords.cpp
580 lines (536 loc) · 24.2 KB
/
Keywords.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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
/* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Copyright (c) 2013 The plumed team
(see the PEOPLE file at the root of the distribution for a list of names)
See http://www.plumed-code.org for more information.
This file is part of plumed, version 2.0.
plumed is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
plumed 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with plumed. If not, see <http://www.gnu.org/licenses/>.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
#include "Keywords.h"
#include "Log.h"
#include "Tools.h"
#include <iostream>
namespace PLMD{
Keywords::KeyType::KeyType( const std::string& type ){
if( type=="compulsory" ){
style=compulsory;
} else if( type=="flag" ){
style=flag;
} else if( type=="optional" ){
style=optional;
} else if( type.find("atoms")!=std::string::npos || type.find("residues")!=std::string::npos ){
style=atoms;
} else if( type=="hidden" ){
style=hidden;
} else {
plumed_massert(false,"invalid keyword specifier " + type);
}
}
void Keywords::KeyType::setStyle( const std::string& type ){
if( type=="compulsory" ){
style=compulsory;
} else if( type=="flag" ){
style=flag;
} else if( type=="optional" ){
style=optional;
} else if( type.find("atoms")!=std::string::npos || type.find("residues")!=std::string::npos ){
style=atoms;
} else if( type=="hidden" ){
style=hidden;
} else {
plumed_massert(false,"invalid keyword specifier " + type);
}
}
void Keywords::add( const Keywords& newkeys ){
newkeys.copyData( keys, reserved_keys, types, allowmultiple, documentation, booldefs, numdefs, atomtags, cnames, ckey, cdocs );
}
void Keywords::copyData( std::vector<std::string>& kk, std::vector<std::string>& rk, std::map<std::string,KeyType>& tt, std::map<std::string,bool>& am,
std::map<std::string,std::string>& docs, std::map<std::string,bool>& bools, std::map<std::string,std::string>& nums,
std::map<std::string,std::string>& atags, std::vector<std::string>& cnam, std::map<std::string,std::string>& ck,
std::map<std::string,std::string>& cd ) const {
for(unsigned i=0;i<keys.size();++i){
std::string thiskey=keys[i];
for(unsigned j=0;j<kk.size();++j) plumed_massert( thiskey!=kk[j], "keyword " + thiskey + " is in twice" );
for(unsigned j=0;j<rk.size();++j) plumed_massert( thiskey!=rk[j], "keyword " + thiskey + " is in twice" );
kk.push_back( thiskey );
plumed_massert( types.count( thiskey ), "no type data on keyword " + thiskey + " to copy" );
tt.insert( std::pair<std::string,KeyType>( thiskey,types.find(thiskey)->second) );
if( (types.find(thiskey)->second).isAtomList() ) atags.insert( std::pair<std::string,std::string>( thiskey,atomtags.find(thiskey)->second) );
plumed_massert( allowmultiple.count( thiskey ), "no numbered data on keyword " + thiskey + " to copy" );
am.insert( std::pair<std::string,bool>(thiskey,allowmultiple.find(thiskey)->second) );
plumed_massert( documentation.count( thiskey ), "no documentation for keyword " + thiskey + " to copy" );
docs.insert( std::pair<std::string,std::string>(thiskey,documentation.find(thiskey)->second) );
if( booldefs.count( thiskey ) ) bools.insert( std::pair<std::string,bool>( thiskey,booldefs.find(thiskey)->second) );
if( numdefs.count( thiskey ) ) nums.insert( std::pair<std::string,std::string>( thiskey,numdefs.find(thiskey)->second) );
}
for(unsigned i=0;i<reserved_keys.size();++i){
std::string thiskey=reserved_keys[i];
for(unsigned j=0;j<kk.size();++j) plumed_massert( thiskey!=kk[j], "keyword " + thiskey + " is in twice" );
for(unsigned j=0;j<rk.size();++j) plumed_massert( thiskey!=rk[j], "keyword " + thiskey + " is in twice" );
rk.push_back( thiskey );
plumed_massert( types.count( thiskey ), "no type data on keyword " + thiskey + " to copy" );
tt.insert( std::pair<std::string,KeyType>( thiskey,types.find(thiskey)->second) );
if( (types.find(thiskey)->second).isAtomList() ) atags.insert( std::pair<std::string,std::string>( thiskey,atomtags.find(thiskey)->second) );
plumed_massert( allowmultiple.count( thiskey ), "no numbered data on keyword " + thiskey + " to copy" );
am.insert( std::pair<std::string,bool>(thiskey,allowmultiple.find(thiskey)->second) );
plumed_massert( documentation.count( thiskey ), "no documentation for keyword " + thiskey + " to copy" );
docs.insert( std::pair<std::string,std::string>(thiskey,documentation.find(thiskey)->second) );
if( booldefs.count( thiskey ) ) bools.insert( std::pair<std::string,bool>( thiskey,booldefs.find(thiskey)->second) );
if( numdefs.count( thiskey ) ) nums.insert( std::pair<std::string,std::string>( thiskey,numdefs.find(thiskey)->second) );
}
for(unsigned i=0;i<cnames.size();++i){
std::string thisnam=cnames[i];
for(unsigned j=0;j<cnam.size();++j) plumed_massert( thisnam!=cnam[j], "component " + thisnam + " is in twice" );
cnam.push_back( thisnam );
plumed_massert( ckey.count( thisnam ), "no keyword data on component " + thisnam + " to copy" );
ck.insert( std::pair<std::string,std::string>( thisnam, ckey.find(thisnam)->second) );
plumed_massert( cdocs.count( thisnam ), "no documentation on component " + thisnam + " to copy" );
cd.insert( std::pair<std::string,std::string>( thisnam, cdocs.find(thisnam)->second) );
}
}
void Keywords::reserve( const std::string & t, const std::string & k, const std::string & d, const bool isvessel ){
plumed_assert( !exists(k) && !reserved(k) );
std::string fd, lowkey=k;
std::transform(lowkey.begin(),lowkey.end(),lowkey.begin(),tolower);
if( t=="numbered" ){
if(isvessel){
fd = d + " The final value can be referenced using <em>label</em>." + lowkey +
". You can use multiple instances of this keyword i.e. " +
k +"1, " + k + "2, " + k + "3... The corresponding values are then "
"referenced using <em>label</em>."+ lowkey +"-1, <em>label</em>." + lowkey +
"-2, <em>label</em>." + lowkey + "-3...";
} else {
fd = d + " You can use multiple instances of this keyword i.e. " + k +"1, " + k + "2, " + k + "3...";
}
allowmultiple.insert( std::pair<std::string,bool>(k,true) );
types.insert( std::pair<std::string,KeyType>(k,KeyType("optional")) );
} else {
if(isvessel){
fd = d + " The final value can be referenced using <em>label</em>." + lowkey + ".";
} else {
fd = d;
}
allowmultiple.insert( std::pair<std::string,bool>(k,false) );
types.insert( std::pair<std::string,KeyType>(k,KeyType(t)) );
if( (types.find(k)->second).isAtomList() ) atomtags.insert( std::pair<std::string,std::string>(k,t) );
}
documentation.insert( std::pair<std::string,std::string>(k,fd) );
reserved_keys.push_back(k);
}
void Keywords::reserveFlag( const std::string & k, const bool def, const std::string & d, const bool isvessel ){
plumed_assert( !exists(k) && !reserved(k) );
std::string defstr;
if( def ) { defstr="( default=on ) "; } else { defstr="( default=off ) "; }
types.insert( std::pair<std::string,KeyType>(k,KeyType("flag")) );
std::string fd,lowkey=k; std::transform(lowkey.begin(),lowkey.end(),lowkey.begin(),tolower);
if(isvessel) fd=defstr + d + " The final value can be referenced using <em>label</em>." + lowkey;
else fd=defstr + d;
documentation.insert( std::pair<std::string,std::string>(k,fd) );
allowmultiple.insert( std::pair<std::string,bool>(k,false) );
booldefs.insert( std::pair<std::string,bool>(k,def) );
reserved_keys.push_back(k);
}
void Keywords::use( const std::string & k ){
plumed_massert( reserved(k), "the " + k + " keyword is not reserved");
for(unsigned i=0;i<reserved_keys.size();++i){
if(reserved_keys[i]==k) keys.push_back( reserved_keys[i] );
}
}
void Keywords::reset_style( const std::string & k, const std::string & style ){
plumed_assert( exists(k) || reserved(k) );
(types.find(k)->second).setStyle(style);
if( (types.find(k)->second).isAtomList() ) atomtags.insert( std::pair<std::string,std::string>(k,style) );
}
void Keywords::add( const std::string & t, const std::string & k, const std::string & d ){
plumed_assert( !exists(k) && t!="flag" && !reserved(k) );
std::string fd;
if( t=="numbered" ){
fd=d + " You can use multiple instances of this keyword i.e. " + k +"1, " + k + "2, " + k + "3...";
allowmultiple.insert( std::pair<std::string,bool>(k,true) );
types.insert( std::pair<std::string,KeyType>(k, KeyType("optional")) );
} else {
fd=d;
allowmultiple.insert( std::pair<std::string,bool>(k,false) );
types.insert( std::pair<std::string,KeyType>(k,KeyType(t)) );
if( (types.find(k)->second).isAtomList() ) atomtags.insert( std::pair<std::string,std::string>(k,t) );
}
documentation.insert( std::pair<std::string,std::string>(k,fd) );
keys.push_back(k);
}
void Keywords::add( const std::string & t, const std::string & k, const std::string & def, const std::string & d ){
plumed_assert( !exists(k) && !reserved(k) && t=="compulsory" ); // An optional keyword can't have a default
types.insert( std::pair<std::string,KeyType>(k, KeyType(t)) );
documentation.insert( std::pair<std::string,std::string>(k,"( default=" + def + " ) " + d) );
allowmultiple.insert( std::pair<std::string,bool>(k,false) );
numdefs.insert( std::pair<std::string,std::string>(k,def) );
keys.push_back(k);
}
void Keywords::addFlag( const std::string & k, const bool def, const std::string & d ){
plumed_massert( !exists(k) && !reserved(k), "keyword " + k + " has already been registered");
std::string defstr;
if( def ) { defstr="( default=on ) "; } else { defstr="( default=off ) "; }
types.insert( std::pair<std::string,KeyType>(k,KeyType("flag")) );
documentation.insert( std::pair<std::string,std::string>(k,defstr + d) );
allowmultiple.insert( std::pair<std::string,bool>(k,false) );
booldefs.insert( std::pair<std::string,bool>(k,def) );
keys.push_back(k);
}
void Keywords::remove( const std::string & k ){
bool found=false; unsigned j=0;
while(true){
for(j=0;j<keys.size();j++) if(keys[j]==k)break;
if(j<keys.size()){
keys.erase(keys.begin()+j);
found=true;
} else break;
}
plumed_massert(found,"You are trying to forbid " + k + " a keyword that isn't there"); // You have tried to forbid a keyword that isn't there
}
bool Keywords::numbered( const std::string & k ) const {
if( style( k,"atoms") ) return true;
plumed_massert( allowmultiple.count(k), "Did not find keyword " + k );
return allowmultiple.find(k)->second;
}
bool Keywords::style( const std::string & k, const std::string & t ) const {
plumed_massert( types.count(k), "Did not find keyword " + k );
if( (types.find(k)->second).toString()==t ) return true;
return false;
}
unsigned Keywords::size() const {
return keys.size();
}
std::string Keywords::getKeyword( const unsigned i ) const {
plumed_assert( i<size() );
return keys[i];
}
bool Keywords::exists( const std::string & k ) const {
for(unsigned i=0;i<keys.size();++i){
if( keys[i]==k ) return true;
}
return false;
}
bool Keywords::reserved( const std::string & k ) const {
for(unsigned i=0;i<reserved_keys.size();++i){
if( reserved_keys[i]==k ) return true;
}
return false;
}
void Keywords::print_template(const std::string& actionname, bool include_optional) const {
unsigned nkeys=0;
printf("%s",actionname.c_str());
for(unsigned i=0;i<keys.size();++i){
if ( (types.find(keys[i])->second).isAtomList() ) nkeys++;
}
if( nkeys>0 ){
std::string prevtag="start";
for(unsigned i=0;i<keys.size();++i){
if( (types.find(keys[i])->second).isAtomList() ){
plumed_massert( atomtags.count(keys[i]), "keyword " + keys[i] + " allegedly specifies atoms but no tag has been specified. Please email Gareth Tribello");
if( prevtag!="start" && prevtag!=atomtags.find(keys[i])->second ) break;
if( (atomtags.find(keys[i])->second).find("residues")!=std::string::npos) printf(" %s=<residue selection>", keys[i].c_str() );
else printf(" %s=<atom selection>", keys[i].c_str() );
prevtag=atomtags.find(keys[i])->second;
}
}
}
nkeys=0;
for(unsigned i=0;i<keys.size();++i){
if ( include_optional || \
(types.find(keys[i])->second).isCompulsory() ) nkeys++;
}
if( nkeys>0 ){
for(unsigned i=0;i<keys.size();++i){
if ( (types.find(keys[i])->second).isCompulsory() ){
std::string def;
if( getDefaultValue( keys[i], def) ){
printf(" %s=%s ", keys[i].c_str(), def.c_str() );
} else {
printf(" %s= ", keys[i].c_str() );
}
} else if (include_optional) {
// TG no defaults for optional keywords?
printf(" [%s]", keys[i].c_str() );
}
}
}
printf("\n");
}
void Keywords::print_html( const bool isaction ) const {
// This is the part that outputs the details of the components
if( cnames.size()>0 ){
if( ckey.find(cnames[0])->second=="default" ){
std::cout<<"\\par Description of components\n\n";
std::cout<<cstring<<"\n\n";
std::cout<<" <table align=center frame=void width=95%% cellpadding=5%%> \n";
printf("<tr> <td width=5%%> <b> Quantity </b> </td> <td> <b> Description </b> </td> </tr>\n");
for(unsigned i=0;i<cnames.size();++i){
plumed_assert( ckey.find(cnames[i])->second=="default" );
printf("<tr>\n");
printf("<td width=15%%> <b> %s </b></td>\n",cnames[i].c_str() );
printf("<td> %s </td>\n",(cdocs.find(cnames[i])->second).c_str() );
printf("</tr>\n");
}
std::cout<<"</table>\n\n";
} else {
unsigned nregs=0;
for(unsigned i=0;i<cnames.size();++i){
if( exists(ckey.find(cnames[i])->second) ) nregs++;
}
if( nregs>0 ){
std::cout<<"\\par Description of components\n\n";
std::cout<<cstring<<"\n\n";
std::cout<<" <table align=center frame=void width=60%% cellpadding=5%%> \n";
printf("<tr> <td width=5%%> <b> Quantity </b> </td> <td> <b> Keyword </b> </td> <td> <b> Description </b> </td> </tr>\n");
for(unsigned i=0;i<cnames.size();++i){
if( exists(ckey.find(cnames[i])->second) ){
printf("<tr>\n");
printf("<td width=5%%> <b> %s </b></td> <td width=10%%> <b> %s </b> </td> \n",
cnames[i].c_str(),(ckey.find(cnames[i])->second).c_str() );
printf("<td> %s </td>\n",(cdocs.find(cnames[i])->second).c_str() );
printf("</tr>\n");
}
}
std::cout<<"</table>\n\n";
}
}
}
unsigned nkeys=0;
for(unsigned i=0;i<keys.size();++i){
if ( (types.find(keys[i])->second).isAtomList() ) nkeys++;
}
if( nkeys>0 ){
if(isaction) std::cout<<"\\par The atoms involved can be specified using\n\n";
else std::cout<<"\\par The input trajectory is specified using one of the following\n\n";
std::cout<<" <table align=center frame=void width=95%% cellpadding=5%%> \n";
std::string prevtag="start";
for(unsigned i=0;i<keys.size();++i){
if ( (types.find(keys[i])->second).isAtomList() ){
plumed_massert( atomtags.count(keys[i]), "keyword " + keys[i] + " allegedly specifies atoms but no tag has been specified. Please email Gareth Tribello");
if( prevtag!="start" && prevtag!=atomtags.find(keys[i])->second && isaction ){
std::cout<<"</table>\n\n";
std::cout<<"\\par Or alternatively by using\n\n";
std::cout<<" <table align=center frame=void width=95%% cellpadding=5%%> \n";
}
print_html_item( keys[i] );
prevtag=atomtags.find(keys[i])->second;
}
}
std::cout<<"</table>\n\n";
}
nkeys=0;
for(unsigned i=0;i<keys.size();++i){
if ( (types.find(keys[i])->second).isCompulsory() ) nkeys++;
}
if( nkeys>0 ){
if(isaction) std::cout<< "\\par Compulsory keywords\n\n";
else std::cout<<"\\par The following must be present\n\n";
std::cout<<" <table align=center frame=void width=95%% cellpadding=5%%> \n";
for(unsigned i=0;i<keys.size();++i){
if ( (types.find(keys[i])->second).isCompulsory() ) print_html_item( keys[i] );
}
std::cout<<"</table>\n\n";
}
nkeys=0;
for(unsigned i=0;i<keys.size();++i){
if ( (types.find(keys[i])->second).isFlag() ) nkeys++;
}
if( nkeys>0 ){
if(isaction) std::cout<<"\\par Options\n\n";
else std::cout<<"\\par The following options are available\n\n";
std::cout<<" <table align=center frame=void width=95%% cellpadding=5%%> \n";
for(unsigned i=0;i<keys.size();++i){
if ( (types.find(keys[i])->second).isFlag() ) print_html_item( keys[i] );
}
std::cout<<"\n";
}
std::cout<<"</table>\n\n";
nkeys=0;
for(unsigned i=0;i<keys.size();++i){
if ( (types.find(keys[i])->second).isOptional() ) nkeys++;
}
if( nkeys>0 ){
std::cout<<" <table align=center frame=void width=95%% cellpadding=5%%> \n";
for(unsigned i=0;i<keys.size();++i){
if ( (types.find(keys[i])->second).isOptional() ) print_html_item( keys[i] );
}
std::cout<<"\n";
}
std::cout<<"</table>\n\n";
}
void Keywords::print( FILE* out ) const {
unsigned nkeys=0;
for(unsigned i=0;i<keys.size();++i){
if ( (types.find(keys[i])->second).isAtomList() ) nkeys++;
}
if( nkeys>0 ){
fprintf(out,"The input trajectory can be in any of the following formats: \n\n");
for(unsigned i=0;i<keys.size();++i){
if ( (types.find(keys[i])->second).isAtomList() ) printKeyword( keys[i], out );
}
}
nkeys=0;
for(unsigned i=0;i<keys.size();++i){
if ( (types.find(keys[i])->second).isCompulsory() ) nkeys++;
}
unsigned ncompulsory=nkeys;
if( nkeys>0 ){
fprintf(out,"\nThe following arguments are compulsory: \n\n");
for(unsigned i=0;i<keys.size();++i){
if ( (types.find(keys[i])->second).isCompulsory() ) printKeyword( keys[i], out ); //log.printKeyword( keys[i], documentation[i] );
}
}
nkeys=0;
for(unsigned i=0;i<keys.size();++i){
if ( (types.find(keys[i])->second).isFlag() ) nkeys++;
}
if( nkeys>0 ){
if(ncompulsory>0) fprintf( out,"\nIn addition you may use the following options: \n\n");
else fprintf( out,"\nThe following options are available\n\n");
for(unsigned i=0;i<keys.size();++i){
if ( (types.find(keys[i])->second).isFlag() ) printKeyword( keys[i], out ); //log.printKeyword( keys[i], documentation[i] );
}
}
nkeys=0;
for(unsigned i=0;i<keys.size();++i){
if ( (types.find(keys[i])->second).isOptional() ) nkeys++;
}
if( nkeys>0 ){
for(unsigned i=0;i<keys.size();++i){
if ( (types.find(keys[i])->second).isOptional() ) printKeyword( keys[i], out ); //log.printKeyword( keys[i], documentation[i] );
}
fprintf(out,"\n");
}
}
void Keywords::printKeyword( const std::string& key, FILE* out ) const {
bool killdot=( (documentation.find(key)->second).find("\\f$")!=std::string::npos ); // Check for latex
std::vector<std::string> w=Tools::getWords( documentation.find(key)->second );
fprintf(out,"%23s - ", key.c_str() );
unsigned nl=0; std::string blank=" ";
for(unsigned i=0;i<w.size();++i){
nl+=w[i].length() + 1;
if( nl>60 ){
fprintf(out,"\n%23s %s ", blank.c_str(), w[i].c_str() ); nl=0;
} else {
fprintf(out,"%s ", w[i].c_str() );
}
if( killdot && w[i].find(".")!=std::string::npos ) break; // If there is latex only write up to first dot
}
fprintf(out,"\n");
}
void Keywords::print( Log& log ) const {
unsigned nkeys=0;
for(unsigned i=0;i<keys.size();++i){
if ( (types.find(keys[i])->second).isAtomList() ) nkeys++;
}
if (nkeys>0 ){
log.printf( "The input for this keyword can be specified using one of the following \n\n");
for(unsigned i=0;i<keys.size();++i){
if ( (types.find(keys[i])->second).isAtomList() ) printKeyword( keys[i], log ); //log.printKeyword( keys[i], documentation[i] );
}
}
nkeys=0;
for(unsigned i=0;i<keys.size();++i){
if ( (types.find(keys[i])->second).isCompulsory() ) nkeys++;
}
if( nkeys>0 ){
log.printf( "\n The compulsory keywords for this action are: \n\n");
for(unsigned i=0;i<keys.size();++i){
if ( (types.find(keys[i])->second).isCompulsory() ) printKeyword( keys[i], log ); //log.printKeyword( keys[i], documentation[i] );
}
}
nkeys=0;
for(unsigned i=0;i<keys.size();++i){
if ( (types.find(keys[i])->second).isFlag() ) nkeys++;
}
if( nkeys>0 ){
log.printf( "\n The following options are available: \n\n");
for(unsigned i=0;i<keys.size();++i){
if ( (types.find(keys[i])->second).isFlag() ) printKeyword( keys[i], log ); //log.printKeyword( keys[i], documentation[i] );
}
log.printf("\n");
}
nkeys=0;
for(unsigned i=0;i<keys.size();++i){
if ( (types.find(keys[i])->second).isOptional() ) nkeys++;
}
if( nkeys>0 ){
for(unsigned i=0;i<keys.size();++i){
if ( (types.find(keys[i])->second).isOptional() ) printKeyword( keys[i], log ); //log.printKeyword( keys[i], documentation[i] );
}
log.printf("\n");
}
}
void Keywords::printKeyword( const std::string& key, Log& log ) const {
bool killdot=( (documentation.find(key)->second).find("\\f$")!=std::string::npos ); // Check for latex
std::vector<std::string> w=Tools::getWords( documentation.find(key)->second );
log.printf("%23s - ", key.c_str() );
unsigned nl=0; std::string blank=" ";
for(unsigned i=0;i<w.size();++i){
nl+=w[i].length() + 1;
if( nl>60 ){
log.printf("\n%23s %s ", blank.c_str(), w[i].c_str() ); nl=0;
} else {
log.printf("%s ", w[i].c_str() );
}
if( killdot && w[i].find(".")!=std::string::npos ) break; // If there is latex only write up to first dot
}
log.printf("\n");
}
void Keywords::print_html_item( const std::string& key ) const {
printf("<tr>\n");
printf("<td width=15%%> <b> %s </b></td>\n",key.c_str() );
printf("<td> %s </td>\n",(documentation.find(key)->second).c_str() );
printf("</tr>\n");
}
std::string Keywords::get( const unsigned k ) const {
plumed_assert( k<size() );
return keys[k];
}
bool Keywords::getLogicalDefault( std::string key, bool& def ) const {
if( booldefs.find(key)!=booldefs.end() ){
def=booldefs.find(key)->second;
return true;
} else {
return false;
}
}
bool Keywords::getDefaultValue( std::string key, std::string& def ) const {
plumed_assert( style(key,"compulsory") || style(key,"hidden") );
if( numdefs.find(key)!=numdefs.end() ){
def=numdefs.find(key)->second;
return true;
} else {
return false;
}
}
void Keywords::destroyData(){
keys.clear(); reserved_keys.clear(); types.clear();
allowmultiple.clear(); documentation.clear();
booldefs.clear(); numdefs.clear(); atomtags.clear();
ckey.clear(); cdocs.clear(); ckey.clear();
}
void Keywords::setComponentsIntroduction( const std::string& instr ){
cstring = instr;
}
void Keywords::addOutputComponent( const std::string& name, const std::string& key, const std::string& descr ){
plumed_assert( !outputComponentExists( name, false ) );
ckey.insert( std::pair<std::string,std::string>(name,key) );
cdocs.insert( std::pair<std::string,std::string>(name,descr) );
cnames.push_back(name);
}
bool Keywords::outputComponentExists( const std::string& name, const bool& custom ) const {
if( custom && cstring.find("customizable")!=std::string::npos ) return true;
for(unsigned i=0;i<cnames.size();++i){
if( name.find(cnames[i])!=std::string::npos ) return true;
}
return false;
}
}