Skip to content

Commit

Permalink
Add a 'convert' option to wrap the atoms
Browse files Browse the repository at this point in the history
Ref #8
  • Loading branch information
Guillaume Fraux committed Sep 30, 2016
1 parent c5882ab commit b9953e3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/commands/Convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ format to use based on the files extension. The '--input-format' and
-c <cell>, --cell=<cell> alternative unit cell for the input. <cell>
should be formated using one of the
<a:b:c:α:β:γ> or <a:b:c> or <L> formats.
--wrap Rewrap the particles inside the unit cell
)";

static Convert::Options parse_options(int argc, const char* argv[]) {
Expand All @@ -41,6 +42,7 @@ static Convert::Options parse_options(int argc, const char* argv[]) {
options.infile = args["<input>"].asString();
options.outfile = args["<output>"].asString();
options.guess_bonds = args.at("--guess-bonds").asBool();
options.wrap = args.at("--wrap").asBool();

if (args["--input-format"]){
options.input_format = args["--input-format"].asString();
Expand Down Expand Up @@ -103,6 +105,15 @@ int Convert::run(int argc, const char* argv[]) {
frame.guess_topology();
}

if (options.wrap) {
auto positions = frame.positions();
auto cell = frame.cell();

for (auto position: positions) {
position = cell.wrap(position);
}
}

outfile.write(frame);
}

Expand Down
1 change: 1 addition & 0 deletions src/commands/Convert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Convert final: public Command {
chemfiles::UnitCell cell;
std::string topology;
bool guess_bonds;
bool wrap;
};

Convert() {}
Expand Down

0 comments on commit b9953e3

Please sign in to comment.