AtomCmd.h 2.64 KB
Newer Older
Francois Gygi committed
1 2
////////////////////////////////////////////////////////////////////////////////
//
Francois Gygi committed
3 4 5 6
// Copyright (c) 2008 The Regents of the University of California
//
// This file is part of Qbox
//
Francois Gygi committed
7 8
// Qbox is distributed under the terms of the GNU General Public License
// as published by the Free Software Foundation, either version 2 of
Francois Gygi committed
9 10 11 12 13 14
// the License, or (at your option) any later version.
// See the file COPYING in the root directory of this distribution
// or <http://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////////////
//
Francois Gygi committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
// AtomCmd.h:
//
////////////////////////////////////////////////////////////////////////////////

#ifndef ATOMCMD_H
#define ATOMCMD_H

#include <string>
#include <cstdlib>
#include <iostream>
#include "UserInterface.h"
#include "Sample.h"

class AtomCmd : public Cmd
{
  public:

  Sample *s;

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

36 37
  const char *name(void) const { return "atom"; }
  const char *help_msg(void) const
Francois Gygi committed
38
  {
39
    return
Francois Gygi committed
40 41 42 43
    "\n atom\n\n"
    " syntax: atom name species x y z [vx vy vz]\n\n"
    "   The atom command defines a new atom and adds it to the atom list.\n"
    "   The name can be any character string, the species must be the name\n"
Francois Gygi committed
44 45
    "   of a species previously defined using the species command.\n"
    "   The position of the atom is specified by x y and z in atomic units.\n"
Francois Gygi committed
46 47 48 49 50 51 52 53 54
    "   Optionally, the atom velocity can be specified by vx vy and vz.\n\n";
  }

  int action(int argc, char **argv)
  {
    string name;
    string species;
    D3vector position;
    D3vector velocity;
55

Francois Gygi committed
56 57 58 59 60 61 62
    // atom must be defined with either 3 or 6 arguments
    if ( argc != 6 && argc != 9 )
    {
      if ( ui->onpe0() )
        cout << " use: atom name species x y z [vx vy vz]" << endl;
      return 1;
    }
63

Francois Gygi committed
64 65 66 67 68 69 70 71 72 73 74
    name = argv[1];
    species = argv[2];
    position.x = atof(argv[3]);
    position.y = atof(argv[4]);
    position.z = atof(argv[5]);
    if ( argc == 9 )
    {
      velocity.x = atof(argv[6]);
      velocity.y = atof(argv[7]);
      velocity.z = atof(argv[8]);
    }
75

Francois Gygi committed
76
    Atom *a = new Atom(name,species,position,velocity);
77 78

    const int atoms_nel_before = s->atoms.nel();
Francois Gygi committed
79 80 81 82 83 84 85
    if ( !(s->atoms.addAtom( a ) ) )
    {
      if ( ui->onpe0() )
        cout << " AtomCmd: could not add atom " << name << endl;
      delete a;
      return 1;
    }
86
    const int atoms_nel_after = s->atoms.nel();
87
    const int delta_nel = atoms_nel_after - atoms_nel_before;
88
    const int wf_nel = s->wf.nel();
89

90
    s->wf.set_nel(wf_nel+delta_nel);
Francois Gygi committed
91
    s->wf.update_occ(0.0);
Francois Gygi committed
92 93
    if ( s->wfv != 0 )
    {
94
      s->wfv->set_nel(wf_nel+delta_nel);
Francois Gygi committed
95 96
      s->wfv->clear();
    }
97

Francois Gygi committed
98 99 100 101
    return 0;
  }
};
#endif