KpointCmd.h 2.88 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
// KpointCmd.h:
//
////////////////////////////////////////////////////////////////////////////////
Francois Gygi committed
18
// $Id: KpointCmd.h,v 1.3 2008-09-08 15:56:18 fgygi Exp $
Francois Gygi committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

#ifndef KPOINTCMD_H
#define KPOINTCMD_H

#include "UserInterface.h"
#include "D3vector.h"
#include "Sample.h"

class KpointCmd : public Cmd
{
  public:

  Sample *s;

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

35 36
  const char *name(void) const { return "kpoint"; }
  const char *help_msg(void) const
Francois Gygi committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
  {
    return
    "\n kpoint\n\n"
    " syntax:\n\n"
    "   kpoint add kx ky kz weight\n"
    "   kpoint delete kx ky kz \n"
    "   kpoint list\n\n";
  }

  int action(int argc, char **argv)
  {
    const bool onpe0 = s->ctxt_.onpe0();
    if ( argc < 2 )
    {
      if ( onpe0 )
        cout << help_msg();
      return 1;
    }
    string subcmd(argv[1]);
    if ( subcmd == "add" )
    {
      if ( argc != 6 )
      {
        if ( onpe0 )
          cout << help_msg();
        return 1;
      }
      double kx = atof(argv[2]);
      double ky = atof(argv[3]);
      double kz = atof(argv[4]);
      double w = atof(argv[5]);
      s->wf.add_kpoint(D3vector(kx,ky,kz),w);
    }
    else if ( subcmd == "delete" )
    {
      if ( argc != 5 )
      {
        if ( onpe0 )
          cout << help_msg();
        return 1;
      }
      double kx = atof(argv[2]);
      double ky = atof(argv[3]);
      double kz = atof(argv[4]);
      s->wf.del_kpoint(D3vector(kx,ky,kz));
    }
    else if ( subcmd == "list" )
    {
      if ( argc != 2 )
      {
        if ( onpe0 )
          cout << help_msg();
        return 1;
      }
      if ( onpe0 )
      {
        cout << " <-- kpoint list: reciprocal lattice coordinates" << endl;
        for ( int ikp = 0; ikp < s->wf.nkp(); ikp++ )
        {
          cout << " "
               << s->wf.kpoint(ikp) << "    " << s->wf.weight(ikp) << endl;
        }
        cout << "    kpoint list: cartesian coordinates" << endl;
        UnitCell u = s->wf.cell();
        for ( int ikp = 0; ikp < s->wf.nkp(); ikp++ )
        {
          D3vector kp = s->wf.kpoint(ikp);
          cout << " "
               << kp * u.b(0) << " " << kp * u.b(1) << " " << kp * u.b(2)
               << "    " << s->wf.weight(ikp) << endl;
        }
        cout << " -->" << endl;
      }
    }
    else
    {
      if ( onpe0 )
        cout << help_msg();
    }

    return 0;
  }
};
#endif