AtomCmd.h 2.69 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
// AtomCmd.h:
//
////////////////////////////////////////////////////////////////////////////////
Francois Gygi committed
18
// $Id: AtomCmd.h,v 1.11 2009-08-14 17:06:43 fgygi Exp $
Francois Gygi committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

#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) {};

37 38
  const char *name(void) const { return "atom"; }
  const char *help_msg(void) const
Francois Gygi committed
39
  {
40
    return
Francois Gygi committed
41 42 43 44
    "\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
45 46
    "   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
47 48 49 50 51 52 53 54 55
    "   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;
56

Francois Gygi committed
57 58 59 60 61 62 63
    // 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;
    }
64

Francois Gygi committed
65 66 67 68 69 70 71 72 73 74 75
    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]);
    }
76

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

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

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

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