1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2008 The Regents of the University of California
4 //
5 // This file is part of Qbox
6 //
7 // Qbox is distributed under the terms of the GNU General Public License
8 // as published by the Free Software Foundation, either version 2 of
9 // the License, or (at your option) any later version.
10 // See the file COPYING in the root directory of this distribution
11 // or <http://www.gnu.org/licenses/>.
12 //
13 ////////////////////////////////////////////////////////////////////////////////
14 //
15 // RunCmd.cpp
16 //
17 ////////////////////////////////////////////////////////////////////////////////
18 
19 #include "RunCmd.h"
20 #include<iostream>
21 using namespace std;
22 #include "BOSampleStepper.h"
23 #include "CPSampleStepper.h"
24 
25 #include<ctime>
26 #include<cassert>
27 
action(int argc,char ** argv)28 int RunCmd::action(int argc, char **argv)
29 {
30   if ( argc < 2 || argc > 5)
31   {
32     if ( ui->onpe0() )
33     {
34       cout << " use: run [-atomic_density] niter" << endl;
35       cout << "      run [-atomic_density] niter nitscf" << endl;
36       cout << "      run [-atomic_density] niter nitscf nite" << endl;
37     }
38     return 1;
39   }
40 
41   if ( s->wf.nst() == 0 )
42   {
43     if ( ui->onpe0() )
44       cout << " RunCmd: no states, cannot run" << endl;
45     return 1;
46   }
47   if ( s->wf.ecut() == 0.0 )
48   {
49     if ( ui->onpe0() )
50       cout << " RunCmd: ecut = 0.0, cannot run" << endl;
51     return 1;
52   }
53   if ( s->wf.cell().volume() == 0.0 )
54   {
55     if ( ui->onpe0() )
56       cout << " RunCmd: volume = 0.0, cannot run" << endl;
57     return 1;
58   }
59 
60   SampleStepper* stepper;
61 
62   int iarg = 1;
63   bool atomic_density = false;
64   if ( !strcmp(argv[iarg],"-atomic_density") )
65   {
66     atomic_density = true;
67     iarg++;
68     argc--;
69   }
70 
71   int niter = atoi(argv[iarg]);
72   int nite = 0;
73   int nitscf = 1;
74   if ( argc == 3 )
75   {
76     // run niter nitscf
77     nitscf = atoi(argv[iarg+1]);
78   }
79   else if ( argc == 4 )
80   {
81     // run niter nitscf nite
82     nitscf = atoi(argv[iarg+1]);
83     nite = atoi(argv[iarg+2]);
84   }
85 
86   s->extforces.setup(s->atoms);
87 
88   if ( s->ctrl.wf_dyn == "MD" )
89     stepper = new CPSampleStepper(*s);
90   else
91     stepper = new BOSampleStepper(*s,nitscf,nite);
92 
93   assert(stepper!=0);
94   stepper->set_iter_cmd(s->ctrl.iter_cmd);
95   stepper->set_iter_cmd_period(s->ctrl.iter_cmd_period);
96 
97   if ( atomic_density )
98     stepper->initialize_density();
99 
100   s->wf.info(cout,"wavefunction");
101   stepper->step(niter);
102 
103   // Delete wave function velocity if not using atoms_dyn = MD
104   if ( s->ctrl.atoms_dyn != "MD" )
105   {
106     if ( s->wfv != 0 )
107       delete s->wfv;
108     s->wfv = 0;
109   }
110 
111   delete stepper;
112 
113   return 0;
114 }
115