22 #include "../core/ActionRegister.h"
23 #include "../core/ActionAtomistic.h"
24 #include "../core/ActionPilot.h"
25 #include "../core/PlumedMain.h"
26 #include "../core/Atoms.h"
27 #include "../tools/Exception.h"
91 PLUMED_REGISTER_ACTION(IMD,
"IMD")
94 keys.addFlag(
"WAIT",
false,
"");
95 keys.addFlag(
"NOWAIT",
true,
"");
96 keys.addFlag(
"WRAP",
false,
"");
97 keys.add(
"compulsory",
"HOST",
"");
98 keys.add(
"compulsory",
"PORT",
"");
99 keys.add(
"compulsory",
"FSCALE",
"1.0",
"");
118 std::vector<AtomNumber> index(
natoms);
119 for(
int i=0;i<
natoms;i++) index[i].setIndex(i);
121 coord.resize(natoms*3,
float(0.0));
122 forces.resize(natoms*3,0.0);
127 if(nowait)
wait=
false;
138 else log.
printf(
" not waiting for a connection\n");
140 else log.
printf(
" not wrapping atoms\n");
145 sock = vmdsock_create();
147 vmdsock_listen(
sock);
156 fprintf(stderr,
"Waiting for IMD connection on %s:%d...\n",
host.c_str(),
port);
158 if (vmdsock_selread(
sock,00) > 0) {
167 imd_recv_header(
clientsock, &length) != IMD_GO) {
193 if(type==IMD_MDCOMM){
194 int32* vmd_atoms =
new int32[length];
195 float* vmd_forces =
new float[3*length];
196 imd_recv_mdcomm(
clientsock, length, vmd_atoms, vmd_forces);
197 for(
int i=0;i<length;i++){
198 forces[3*vmd_atoms[i]+0]=vmd_forces[3*i+0];
199 forces[3*vmd_atoms[i]+1]=vmd_forces[3*i+1];
200 forces[3*vmd_atoms[i]+2]=vmd_forces[3*i+2];
203 delete [] vmd_forces;
207 }
else if(type==IMD_DISCONNECT){
215 }
else if(type==IMD_TRATE){
216 if(length<1) length=1;
218 log.
printf(
"IMD: setting transfer rate to %d\n",length);
222 }
else if(type==IMD_KILL){
244 else if(itype==3)
plumed.exit();
253 double scale=10.0*
plumed.getAtoms().getUnits().getLength();
255 for(
int i=0;i<
natoms;i++){
258 coord[3*i+0]=
static_cast<float>((pos[0]*scale));
259 coord[3*i+1]=
static_cast<float>((pos[1]*scale));
260 coord[3*i+2]=
static_cast<float>((pos[2]*scale));
270 const double scale=4.184/
plumed.getAtoms().getUnits().getEnergy()
273 for(
unsigned i=0;i<f.size();i++){
const Vector & getPosition(int) const
Get position of i-th atom.
void parseFlag(const std::string &key, bool &t)
Parse one keyword as boolean flag.
Log & log
Reference to the log stream.
std::vector< float > coord
This is used to create PLMD::Action objects that are run with some set frequency. ...
void calculate()
Calculate an Action.
Class implementing fixed size vectors of doubles.
IMD(const ActionOptions &)
void Bcast(T *, int, int)
void apply()
Apply an Action.
void checkRead()
Check if Action was properly read.
void parse(const std::string &key, T &t)
Parse one keyword as generic type.
This class holds the keywords and their documentation.
std::vector< double > forces
int Get_rank() const
Obtain the rank of the present process.
This class is used to bring the relevant information to the Action constructor.
Action used to create objects that access the positions of the atoms from the MD code.
int printf(const char *fmt,...)
Formatted output with explicit format - a la printf.
Base class for all the input Actions.
Vector pbcDistance(const Vector &, const Vector &) const
Compute the pbc distance between two positions.
static void registerKeywords(Keywords &keys)
void requestAtoms(const std::vector< AtomNumber > &a)
Request an array of atoms.
std::vector< Vector > & modifyForces()
Get a reference to forces array.