Skip to content

Commit 1a28498

Browse files
committed
adding some documentation
1 parent 6e1f1e3 commit 1a28498

2 files changed

Lines changed: 155 additions & 122 deletions

File tree

src/cltools/Benchmark.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ void Benchmark::registerKeywords( Keywords& keys ) {
381381
keys.add("compulsory","--atom-distribution","line|wiggle 0.5","the kind of possible atomic displacement at each step");
382382
// Maybe "--atom-distribution" can be more clear when calling --help if we use reset_style to "atoms"
383383
keys.add("optional","--dump-trajectory","dump the trajectory to this file");
384+
keys.addFlag("--ad-help",false,"print a small help text for the atom distributions");
384385
keys.addFlag("--domain-decomposition",false,"simulate domain decomposition, implies --shuffle");
385386
keys.addFlag("--shuffled",false,"reshuffle atoms");
386387
TrajectoryParser::registerKeywords(keys);
@@ -414,6 +415,41 @@ int Benchmark::main(FILE* in, FILE*out,Communicator& pc) {
414415
} else {
415416
log.link(log_dev_null.get());
416417
}
418+
419+
bool printADHelp=false;
420+
parseFlag("--ad-help",printADHelp);
421+
if (printADHelp) {
422+
log << "Documentation for the atomic distributions:\n";
423+
log << "\nThese are the basic atomic distributions:\n";
424+
auto distrs = AtomDistribution::getDistributionDocumentation();
425+
for(const auto& d:distrs) {
426+
log.printf("%8s - %s\n\n",d.id.c_str(),d.doc.c_str());
427+
}
428+
auto modifiers = AtomDistribution::getDecoratorsDocumentation();
429+
430+
log << "\nThese are the modifiers that can be applied to any atomic distributions:\n";
431+
for(const auto& d:modifiers) {
432+
log.printf("%8s - %s\n\n",d.id.c_str(),d.doc.c_str());
433+
}
434+
log << R"==(
435+
To use these distributions in the benchmark you can simple the cli option --atom-distribution
436+
like:
437+
--atom-distribution="sc", with no extra modifiers
438+
--atom-distribution="line|wiggle 0.5", use the pipe for modify the base distribution
439+
--atom-distribution="ifcc|scale 2.3|reply 2 1 1", do not add spaces before or after the pipes
440+
441+
As an extra tool you can append more modificators with --modify-trajectory,
442+
it is not necessary since you can use --atom-distribution, but can be applied
443+
to a trajectory read from a file, for example "box" can be used for adding
444+
the pbcs to certain file parsers.
445+
Remember that --modify-trajectory accepts only modifiers, with the
446+
same syntax of --atom-distribution
447+
--modify-trajectory="box 5 5 5"
448+
--modify-trajectory="box 0 1 1 1 1 0 1 0 1|reply 4 2 6"
449+
)==";
450+
return 0;
451+
}
452+
417453
log.setLinePrefix("BENCH: ");
418454
log <<"Welcome to PLUMED benchmark\n";
419455
std::vector<Kernel> kernels;

src/tools/AtomDistribution.cpp

Lines changed: 119 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -434,91 +434,90 @@ class repliedTrajectory: public AtomDistribution {
434434
public:
435435
static constexpr auto id="reply";
436436
static constexpr auto doc=R"=(replicate the box by the given in all the directions:
437-
usage (must be used with 3 paramenters):
438-
reply x y z
439-
)=";
437+
usage:
438+
reply x y z)=";
440439

441440
static std::unique_ptr<AtomDistribution> decorate(std::unique_ptr<AtomDistribution>&& d,
442-
std::string_view cmd) {
443-
unpackedLine lines;
444-
Tools::getWordsSimple(lines,cmd);
445-
unsigned repeatX;
446-
unsigned repeatY;
447-
unsigned repeatZ;
448-
plumed_assert(lines.size() ==4) << id << " supports exacly three inputs: x y z";
449-
450-
Tools::convert(std::string(lines[1]),repeatX);
451-
Tools::convert(std::string(lines[2]),repeatY);
452-
Tools::convert(std::string(lines[3]),repeatZ);
453-
return std::make_unique<repliedTrajectory>(std::move(d),
454-
repeatX,
455-
repeatY,
456-
repeatZ);
457-
}
441+
std::string_view cmd) {
442+
unpackedLine lines;
443+
Tools::getWordsSimple(lines,cmd);
444+
unsigned repeatX;
445+
unsigned repeatY;
446+
unsigned repeatZ;
447+
plumed_assert(lines.size() ==4) << id << " supports exacly three inputs: x y z";
448+
449+
Tools::convert(std::string(lines[1]),repeatX);
450+
Tools::convert(std::string(lines[2]),repeatY);
451+
Tools::convert(std::string(lines[3]),repeatZ);
452+
return std::make_unique<repliedTrajectory>(std::move(d),
453+
repeatX,
454+
repeatY,
455+
repeatZ);
456+
}
458457

459458
repliedTrajectory(std::unique_ptr<AtomDistribution>&& d,
460459
const unsigned repeatX,
461460
const unsigned repeatY,
462461
const unsigned repeatZ) :
463-
distribution(std::move(d)),
464-
rX(repeatX),
465-
rY(repeatY),
466-
rZ(repeatZ)
467-
{}
462+
distribution(std::move(d)),
463+
rX(repeatX),
464+
rY(repeatY),
465+
rZ(repeatZ)
466+
{}
468467

469468
///Generates the inner trajectory of `(nat)/(rX*rY*rZ)`, where `nat` is the dimension of the vector view, then it replicate the atoms in the various directions
470469
void frame(View<Vector> posToUpdate,
471470
View<double,9> box,
472471
unsigned step,
473472
Random& rng) override {
474-
plumed_assert((posToUpdate.size() % (rX*rY*rZ)==0));
475-
const auto nat = posToUpdate.size()/(rX*rY*rZ);
476-
auto coordinates=posToUpdate.subview(0,nat);
477-
distribution->frame(coordinates,box,step,rng);
478-
479-
// repetitions
480-
auto p = posToUpdate.begin()+nat;
481-
482-
assert((rX*rY*rZ)*nat == posToUpdate.size());
483-
484-
Vector boxX(box[0],box[1],box[2]);
485-
Vector boxY(box[3],box[4],box[5]);
486-
Vector boxZ(box[6],box[7],box[8]);
487-
for (unsigned x=0; x<rX; ++x) {
488-
for (unsigned y=0; y<rY; ++y) {
489-
for (unsigned z=0; z<rZ; ++z) {
490-
if(x==0&&y==0&&z==0) {
491-
continue;
492-
}
493-
for (unsigned i=0; i<nat; ++i) {
494-
*p=coordinates[i]
495-
+ x * boxX
496-
+ y * boxY
497-
+ z * boxZ;
498-
++p;
473+
plumed_assert((posToUpdate.size() % (rX*rY*rZ)==0));
474+
const auto nat = posToUpdate.size()/(rX*rY*rZ);
475+
auto coordinates=posToUpdate.subview(0,nat);
476+
distribution->frame(coordinates,box,step,rng);
477+
478+
// repetitions
479+
auto p = posToUpdate.begin()+nat;
480+
481+
assert((rX*rY*rZ)*nat == posToUpdate.size());
482+
483+
Vector boxX(box[0],box[1],box[2]);
484+
Vector boxY(box[3],box[4],box[5]);
485+
Vector boxZ(box[6],box[7],box[8]);
486+
for (unsigned x=0; x<rX; ++x) {
487+
for (unsigned y=0; y<rY; ++y) {
488+
for (unsigned z=0; z<rZ; ++z) {
489+
if(x==0&&y==0&&z==0) {
490+
continue;
491+
}
492+
for (unsigned i=0; i<nat; ++i) {
493+
*p=coordinates[i]
494+
+ x * boxX
495+
+ y * boxY
496+
+ z * boxZ;
497+
++p;
498+
}
499499
}
500500
}
501501
}
502-
}
503-
box[0]*=rX;
504-
box[1]*=rX;
505-
box[2]*=rX;
502+
box[0]*=rX;
503+
box[1]*=rX;
504+
box[2]*=rX;
506505

507-
box[3]*=rY;
508-
box[4]*=rY;
509-
box[5]*=rY;
506+
box[3]*=rY;
507+
box[4]*=rY;
508+
box[5]*=rY;
510509

511-
box[6]*=rZ;
512-
box[7]*=rZ;
513-
box[8]*=rZ;
514-
}
510+
box[6]*=rZ;
511+
box[7]*=rZ;
512+
box[8]*=rZ;
513+
}
515514

516515
///See the documentation the AtomDistribution
517516
bool overrideNat(unsigned& natoms) override {
518-
distribution->overrideNat(natoms);
519-
natoms *= (rX*rY*rZ);
520-
return true;
521-
}
517+
distribution->overrideNat(natoms);
518+
natoms *= (rX*rY*rZ);
519+
return true;
520+
}
522521
};
523522

524523
///a decorator for scaling the atomic positions
@@ -529,48 +528,47 @@ class scaledTrajectory: public AtomDistribution {
529528
static constexpr auto id="scale";
530529
static constexpr auto doc=R"=(scales the atoms by a certain amount
531530
usage:
532-
scale (optional: mults=2.0)
533-
)=";
531+
scale (optional: mults=2.0))=";
534532

535533
static std::unique_ptr<AtomDistribution> decorate(std::unique_ptr<AtomDistribution>&& d,
536-
std::string_view cmd) {
537-
unpackedLine lines;
538-
Tools::getWordsSimple(lines,cmd);
539-
plumed_assert(lines.size() <=2) << id << " supports maximum one input";
540-
if (lines.size()==2) {
541-
double mult=2.0;
542-
Tools::convert(std::string(lines[1]), mult);
543-
return std::make_unique<scaledTrajectory>(std::move(d),mult);
544-
}
534+
std::string_view cmd) {
535+
unpackedLine lines;
536+
Tools::getWordsSimple(lines,cmd);
537+
plumed_assert(lines.size() <=2) << id << " supports maximum one input";
538+
if (lines.size()==2) {
539+
double mult=2.0;
540+
Tools::convert(std::string(lines[1]), mult);
541+
return std::make_unique<scaledTrajectory>(std::move(d),mult);
542+
}
545543

546-
//the default value is specified in the header
547-
return std::make_unique<scaledTrajectory>(std::move(d));
548-
}
544+
//the default value is specified in the header
545+
return std::make_unique<scaledTrajectory>(std::move(d));
546+
}
549547

550548
scaledTrajectory(std::unique_ptr<AtomDistribution>&& d,
551-
double mult=2.0):
552-
distribution(std::move(d)),
553-
multiplier(mult)
554-
{}
549+
double mult=2.0):
550+
distribution(std::move(d)),
551+
multiplier(mult)
552+
{}
555553

556554
void frame(View<Vector> posToUpdate,
557555
View<double,9> box,
558556
unsigned step,
559557
Random& rng) override {
560-
distribution->frame(posToUpdate,box,step,rng);
558+
distribution->frame(posToUpdate,box,step,rng);
561559

562-
for (auto& p:posToUpdate) {
563-
p*=multiplier;
564-
}
560+
for (auto& p:posToUpdate) {
561+
p*=multiplier;
562+
}
565563

566-
for (auto& b:box) {
567-
b*=multiplier;
564+
for (auto& b:box) {
565+
b*=multiplier;
566+
}
568567
}
569-
}
570568

571-
bool overrideNat(unsigned& natoms) override {
572-
return distribution->overrideNat(natoms);
573-
}
569+
bool overrideNat(unsigned& natoms) override {
570+
return distribution->overrideNat(natoms);
571+
}
574572
};
575573

576574

@@ -581,45 +579,44 @@ class wiggleTrajectory: public AtomDistribution {
581579
double radius;
582580
public:
583581
static constexpr auto id="wiggle";
584-
static constexpr auto doc=R"=(displaces all the atoms by a certain amunt
582+
static constexpr auto doc=R"=(displaces all the atoms by a certain amount
585583
usage:
586-
wiggle (optional: sphere radius=0.1)
587-
)=";
584+
wiggle (optional: sphere radius=0.1))=";
588585
static std::unique_ptr<AtomDistribution> decorate(
589-
std::unique_ptr<AtomDistribution>&& d,
586+
std::unique_ptr<AtomDistribution>&& d,
590587
std::string_view cmd) {
591-
unpackedLine lines;
592-
Tools::getWordsSimple(lines,cmd);
593-
plumed_assert(lines.size() <=2) << id << " supports maximum one input";
594-
if (lines.size()==2) {
595-
double displacement=0.1;
596-
Tools::convert(std::string(lines[1]), displacement);
597-
return std::make_unique<wiggleTrajectory>(std::move(d),displacement);
598-
}
599-
//the default value is specified in the header
600-
return std::make_unique<wiggleTrajectory>(std::move(d));
601-
}
588+
unpackedLine lines;
589+
Tools::getWordsSimple(lines,cmd);
590+
plumed_assert(lines.size() <=2) << id << " supports maximum one input";
591+
if (lines.size()==2) {
592+
double displacement=0.1;
593+
Tools::convert(std::string(lines[1]), displacement);
594+
return std::make_unique<wiggleTrajectory>(std::move(d),displacement);
595+
}
596+
//the default value is specified in the header
597+
return std::make_unique<wiggleTrajectory>(std::move(d));
598+
}
602599

603600
wiggleTrajectory(std::unique_ptr<AtomDistribution>&& d,
604-
double amount=0.1) :
605-
distribution(std::move(d)),
606-
radius(amount)
607-
{}
601+
double amount=0.1) :
602+
distribution(std::move(d)),
603+
radius(amount)
604+
{}
608605

609606
void frame(View<Vector> posToUpdate,
610607
View<double,9> box,
611608
unsigned step,
612609
Random& rng) override {
613-
distribution->frame(posToUpdate,box,step,rng);
610+
distribution->frame(posToUpdate,box,step,rng);
614611

615-
UniformSphericalVector usv(radius);
616-
for (auto& v: posToUpdate) {
617-
v+= usv(rng);
612+
UniformSphericalVector usv(radius);
613+
for (auto& v: posToUpdate) {
614+
v+= usv(rng);
615+
}
618616
}
619-
}
620617
bool overrideNat(unsigned& natoms) override {
621-
return distribution->overrideNat(natoms);
622-
}
618+
return distribution->overrideNat(natoms);
619+
}
623620
};
624621

625622

@@ -632,9 +629,9 @@ class forceBoxTrajectory: public AtomDistribution {
632629
static constexpr auto id="box";
633630
static constexpr auto doc=R"=(Forces a box on the atom distribution
634631
usage:
635-
"box xx yy zz"
636-
or
637-
"box xx xy xy yx yy yz zx zy zz")=";
632+
box xx yy zz
633+
or
634+
box xx xy xy yx yy yz zx zy zz)=";
638635

639636
static std::unique_ptr<AtomDistribution> decorate(
640637
std::unique_ptr<AtomDistribution>&& d,
@@ -705,7 +702,7 @@ class fixedTrajectory: public AtomDistribution {
705702
static constexpr auto id="fix";
706703
static constexpr auto doc=R"=(Fixes the trajectory for stride steps, or forever if stride is 0
707704
usage:
708-
"fix stride(optional)")=";
705+
fix (optional stride=0))=";
709706

710707
static std::unique_ptr<AtomDistribution> decorate(
711708
std::unique_ptr<AtomDistribution>&& d,

0 commit comments

Comments
 (0)