Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set pos command #35

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/qb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ using namespace std;
#include <ui/LockCmd.h>
#include <ui/UnlockCmd.h>
#include <ui/SetVelCmd.h>
#include <ui/SetPosCmd.h>
#include <ui/ComputeMLWFCmd.h>
#include <ui/AngleCmd.h>
#include <ui/ConstraintCmd.h>
Expand Down Expand Up @@ -347,6 +348,7 @@ int main(int argc, char **argv, char **envp)
ui->addCmd(new LockCmd(s));
ui->addCmd(new UnlockCmd(s));
ui->addCmd(new SetVelCmd(s));
ui->addCmd(new SetPosCmd(s));
ui->addCmd(new ComputeMLWFCmd(s));
ui->addCmd(new ConstraintCmd(s));
ui->addCmd(new ShiftWFCmd(s));
Expand Down
1 change: 1 addition & 0 deletions src/qball/qbLink.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ using namespace std;
#include <ui/LockCmd.h>
#include <ui/UnlockCmd.h>
#include <ui/SetVelCmd.h>
#include <ui/SetPosCmd.h>
#include <ui/ComputeMLWFCmd.h>
#include <ui/AngleCmd.h>
#include <ui/ConstraintCmd.h>
Expand Down
1 change: 1 addition & 0 deletions src/ui/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ noinst_HEADERS = \
SavesysCmd.h \
SetCmd.h \
SetVelCmd.h \
SetPosCmd.h \
ShiftWFCmd.h \
SpeciesCmd.h \
StatusCmd.h \
Expand Down
122 changes: 122 additions & 0 deletions src/ui/SetPosCmd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2013, Lawrence Livermore National Security, LLC.
// qb@ll: Qbox at Lawrence Livermore
//
// This file is part of qb@ll.
//
// Produced at the Lawrence Livermore National Laboratory.
// Written by Erik Draeger ([email protected]) and Francois Gygi ([email protected]).
// Based on the Qbox code by Francois Gygi Copyright (c) 2008
// LLNL-CODE-635376. All rights reserved.
//
// qb@ll 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.
//
// This program 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, in the file COPYING in the
// root directory of this distribution or <http://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////////////
//
// SetVelCmd.h:
//
////////////////////////////////////////////////////////////////////////////////

#include <config.h>

#ifndef SETPOSCMD_H
#define SETPOSCMD_H

#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;

#include <ui/UserInterface.h>
#include <qball/Sample.h>
#include <qball/Species.h>
#include <qball/MMSpecies.h>
#include <qball/Atom.h>

class SetPosCmd : public Cmd {
public:

Sample *s;

SetPosCmd(Sample *sample) : s(sample) { };

char const*name(void) const { return "set_position"; }

char const*help_msg(void) const {
return
"\n lock\n\n"
" syntax: set_position [atom name] [x] [y] [z]\n\n"
" The set_position command sets the velocity for a given atom.\n\n";
}


int action(int argc, char **argv) {
string name;

string pos_unit_name = "bohr";
// string vel_unit_name = "atomicvelocity";

if ( argc != 5 && argc != 6) {
ui->error("<!-- use: set_position [atom name] [x] [y] [z] [units] -->");
return 1;
}

if (argc == 5) {
ui->warning("Units missing for the set_velocity command, assuming 'atomicvelocity'.");
} else {
pos_unit_name = string(argv[5]);
}

Unit pos_unit(Dimensions::length, pos_unit_name);
// Unit vel_unit(Dimensions::velocity, vel_unit_name);

if(!pos_unit.exists()) {
ui->error("Unknown position unit '" + pos_unit_name + "'.");
return 1;
}

name = argv[1];
double x = atof(argv[2]);
double y = atof(argv[3]);
double z = atof(argv[4]);
D3vector newpos(x,y,z);

newpos = pos_unit.to_atomic(newpos);

if (s->atoms.findAtom(name) ) {
Atom *a = s->atoms.findAtom(name);

a->set_position(newpos);
if ( ui->oncoutpe() )
cout << "<!-- Atom " << a->name() << " position set to " << newpos << " -->" << endl;
}
else if (s->atoms.findMMAtom(name) ) {
Atom *a = s->atoms.findMMAtom(name);

a->set_position(newpos);
if ( ui->oncoutpe() )
cout << "<!-- Atom " << a->name() << " position set to " << newpos << " -->" << endl;
}
else {
if ( ui->oncoutpe() )
cout << "<ERROR>SetPosCmd: " << name << " not found!</ERROR>" << endl;
return 1;
}
return 0;
}

};
#endif

// Local Variables:
// mode: c++
// End:
2 changes: 1 addition & 1 deletion src/ui/SetVelCmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class SetVelCmd : public Cmd {
Unit vel_unit(Dimensions::velocity, vel_unit_name);

if(!vel_unit.exists()) {
ui->error("Unknown energy unit '" + vel_unit_name + "'.");
ui->error("Unknown velocity unit '" + vel_unit_name + "'.");
return 1;
}

Expand Down