QMCPACK
FreeOrbitalBuilder.cpp
Go to the documentation of this file.
2 #include "LongRange/StructFact.h"
3 #include "LongRange/KContainer.h"
6 
7 namespace qmcplusplus
8 {
10  : SPOSetBuilder("PW", comm), targetPtcl(els)
11 {}
12 
13 std::unique_ptr<SPOSet> FreeOrbitalBuilder::createSPOSetFromXML(xmlNodePtr cur)
14 {
15  int norb = -1;
16  std::string spo_object_name;
17  PosType twist(0.0);
18  OhmmsAttributeSet attrib;
19  attrib.add(norb, "size");
20  attrib.add(twist, "twist");
21  attrib.add(spo_object_name, "name");
22  attrib.put(cur);
23 
24  if (norb < 0)
25  throw std::runtime_error("free orbital SPO set require the \"size\" input");
26 
27  auto lattice = targetPtcl.getLattice();
28 
29  PosType tvec = lattice.k_cart(twist);
30 #ifdef QMC_COMPLEX
31  const int npw = norb;
32  targetPtcl.setTwist(twist);
33  app_log() << "twist fraction = " << twist << std::endl;
34  app_log() << "twist cartesian = " << tvec << std::endl;
35 #else
36  const int npw = std::ceil((norb + 1.0) / 2);
37  if (2 * npw - 1 != norb)
38  {
39  std::ostringstream msg;
40  msg << "norb = " << norb << " npw = " << npw;
41  msg << " cannot be ran in real PWs (sin, cos)" << std::endl;
42  msg << "either use complex build or change the size of SPO set" << std::endl;
43  msg << "ideally, set size to a closed shell of PWs." << std::endl;
44  throw std::runtime_error(msg.str());
45  }
46  for (int ldim = 0; ldim < twist.size(); ldim++)
47  {
48  if (std::abs(twist[ldim]) > 1e-16)
49  throw std::runtime_error("no twist for real orbitals");
50  }
51 #endif
52 
53  // extract npw k-points from container
54  // kpts_cart is sorted by magnitude
55  std::vector<PosType> kpts(npw);
56  KContainer klists;
57  RealType kcut = lattice.LR_kc; // to-do: reduce kcut to >~ kf
58  klists.updateKLists(lattice, kcut, lattice.ndim, twist);
59 
60  // k0 is not in kpts_cart
61  kpts[0] = tvec;
62 #ifdef QMC_COMPLEX
63  for (int ik = 1; ik < npw; ik++)
64  {
65  kpts[ik] = klists.kpts_cart[ik - 1];
66  }
67 #else
68  const int nktot = klists.kpts.size();
69  std::vector<int> mkidx(npw, 0);
70  int ik = 1;
71  for (int jk = 0; jk < nktot; jk++)
72  {
73  // check if -k is already chosen
74  const int jmk = klists.minusk[jk];
75  if (in_list(jk, mkidx))
76  continue;
77  // if not, then add this kpoint
78  kpts[ik] = klists.kpts_cart[jk];
79  mkidx[ik] = jmk; // keep track of its minus
80  ik++;
81  if (ik >= npw)
82  break;
83  }
84 #endif
85  auto sposet = std::make_unique<FreeOrbital>(spo_object_name, kpts);
86  sposet->report(" ");
87  return sposet;
88 }
89 
90 bool FreeOrbitalBuilder::in_list(const int j, const std::vector<int> l)
91 {
92  for (int i = 0; i < l.size(); i++)
93  {
94  if (j == l[i])
95  return true;
96  }
97  return false;
98 }
99 
100 } // namespace qmcplusplus
FreeOrbitalBuilder(ParticleSet &els, Communicate *comm, xmlNodePtr cur)
std::vector< PosType > kpts_cart
K-vector in Cartesian coordinates.
Definition: KContainer.h:53
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
QTBase::RealType RealType
Definition: Configuration.h:58
MakeReturn< UnaryNode< FnFabs, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t abs(const Vector< T1, C1 > &l)
std::unique_ptr< SPOSet > createSPOSetFromXML(xmlNodePtr cur) override
create an sposet from xml (legacy)
std::ostream & app_log()
Definition: OutputManager.h:65
bool put(xmlNodePtr cur)
assign attributes to the set
Definition: AttributeSet.h:55
bool in_list(const int j, const std::vector< int > l)
Wrapping information on parallelism.
Definition: Communicate.h:68
CrystalLattice< OHMMS_PRECISION, OHMMS_DIM > lattice
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
base class for the real SPOSet builder
Definition: SPOSetBuilder.h:47
MakeReturn< UnaryNode< FnCeil, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t ceil(const Vector< T1, C1 > &l)
class to handle a set of attributes of an xmlNode
Definition: AttributeSet.h:24
void setTwist(const SingleParticlePos &t)
Definition: ParticleSet.h:481
Container for k-points.
Definition: KContainer.h:29
std::vector< int > minusk
Given a k index, return index to -k.
Definition: KContainer.h:59
const auto & getLattice() const
Definition: ParticleSet.h:251
void updateKLists(const ParticleLayout &lattice, RealType kc, unsigned ndim, const PosType &twist=PosType(), bool useSphere=true)
k points sorted by the |k| excluding |k|=0
Definition: KContainer.cpp:24
std::vector< TinyVector< int, DIM > > kpts
K-vector in reduced coordinates.
Definition: KContainer.h:50
void add(PDT &aparam, const std::string &aname, std::vector< PDT > candidate_values={}, TagStatus status=TagStatus::OPTIONAL)
add a new attribute
Definition: AttributeSet.h:42