QMCPACK
SpeciesSet Class Reference

Custom container for set of attributes for a set of species. More...

+ Collaboration diagram for SpeciesSet:

Public Types

using Scalar_t = double
 
using SpeciesAttrib_t = std::vector< Scalar_t >
 
using AttribList_t = std::vector< SpeciesAttrib_t >
 

Public Member Functions

int size () const
 return the number of species More...
 
int getTotalNum () const
 return the number of species More...
 
void setTotalNum (const unsigned n)
 set the number of species More...
 
int numAttributes () const
 return the number of attributes in our list More...
 
int addSpecies (const std::string &aname)
 When a name species does not exist, add a new species. More...
 
int addAttribute (const std::string &aname)
 for a new attribute, allocate the data, !More often used to get the index of a species More...
 
int getAttribute (const std::string &aname) const
 When a name species does not exist, return attribute.size() More...
 
bool hasAttribute (const std::string &aname) const
 Check for attribute presence This replaces code that gets numAttributes then tries to addAttribute for a particular name and compares the numAttributes and index of the new Attribute. More...
 
double operator() (int i, int j) const
 
double & operator() (int i, int j)
 assignment operator More...
 
void create (unsigned m)
 
int findSpecies (const std::string &name) const
 if the input species is not found, add a new species More...
 
int findAttribute (const std::string &name) const
 almost all code ignores this and just uses addAttribute for the same purpose. More...
 
int findIndex (const std::string &name, const std::vector< std::string > &alist) const
 
const std::string & getSpeciesName (int index) const
 

Public Attributes

unsigned TotalNum = 0
 The number of species. More...
 
std::vector< std::string > speciesName
 Species name list. More...
 
std::vector< std::string > attribName
 attribute name list More...
 
AttribList_t d_attrib
 List of species attributes. More...
 

Detailed Description

Custom container for set of attributes for a set of species.

A confusingly equivalent of std::map<std::string, <std::map<std::string, Scalar>> implemented as two sets of key vectors and a single vector of Scalars. It leaks its implementation details i.e. the indexing to the vectors. Reduces readability and increases semantic load. Looks like premature optimization.

Todo:
prove this helps overall performance, if not remove it. Else document it and it's use

Definition at line 33 of file SpeciesSet.h.

Member Typedef Documentation

◆ AttribList_t

using AttribList_t = std::vector<SpeciesAttrib_t>

Definition at line 38 of file SpeciesSet.h.

◆ Scalar_t

using Scalar_t = double

Definition at line 36 of file SpeciesSet.h.

◆ SpeciesAttrib_t

using SpeciesAttrib_t = std::vector<Scalar_t>

Definition at line 37 of file SpeciesSet.h.

Member Function Documentation

◆ addAttribute()

int addAttribute ( const std::string &  aname)

for a new attribute, allocate the data, !More often used to get the index of a species

Parameters
anamea unique name of an attribute
Returns
the index of a new attribute

Definition at line 45 of file SpeciesSet.cpp.

References SpeciesSet::attribName, SpeciesSet::d_attrib, qmcplusplus::n, and SpeciesSet::TotalNum.

Referenced by RadialJastrowBuilder::buildComponent(), qmcplusplus::create_C_pbc_particlesets(), qmcplusplus::createElectronParticleSet(), QMCGaussianParserBase::createElectronSet(), ParticleSet::createSK(), qmcplusplus::doSOECPotentialTest(), qmcplusplus::generateCuspInfo(), ForceChiesaPBCAA::initBreakup(), StressPBC::initBreakup(), CoulombPBCAB::initBreakup(), QMCGaussianParserBase::QMCGaussianParserBase(), ParticleSet::resetGroups(), EnergyDensityEstimator::set_ptcl(), QMCUpdateBase::setDefaults(), qmcplusplus::setSpeciesProperty(), qmcplusplus::setup_He_wavefunction(), qmcplusplus::test_cartesian_ao(), qmcplusplus::TEST_CASE(), qmcplusplus::test_CoulombPBCAA_3p(), qmcplusplus::test_diamond_2x1x1_xml_input(), qmcplusplus::test_dirac_ao(), qmcplusplus::test_hcpBe_rotation(), qmcplusplus::test_He(), qmcplusplus::test_He_mw(), qmcplusplus::test_He_sto3g_xml_input(), qmcplusplus::test_J1_spline(), qmcplusplus::test_LCAO_DiamondC_2x1x1_cplx(), qmcplusplus::test_LCAO_DiamondC_2x1x1_real(), qmcplusplus::test_lcao_spinor(), qmcplusplus::test_lcao_spinor_excited(), qmcplusplus::test_lcao_spinor_ion_derivs(), qmcplusplus::test_LiH_msd(), qmcplusplus::test_LiH_msd_xml_input(), qmcplusplus::test_LiH_msd_xml_input_with_positron(), qmcplusplus::test_Ne(), qmcplusplus::testElecCase(), and qmcplusplus::testTrialWaveFunction_diamondC_2x1x1().

46 {
47  int i = 0;
48  while (i < attribName.size())
49  {
50  if (attribName[i] == aname)
51  return i;
52  i++;
53  }
54  attribName.push_back(aname);
55  int n = d_attrib.size();
56  d_attrib.push_back(SpeciesAttrib_t(TotalNum));
57  return n;
58 }
std::vector< std::string > attribName
attribute name list
Definition: SpeciesSet.h:47
AttribList_t d_attrib
List of species attributes.
Definition: SpeciesSet.h:50
std::vector< Scalar_t > SpeciesAttrib_t
Definition: SpeciesSet.h:37
unsigned TotalNum
The number of species.
Definition: SpeciesSet.h:41

◆ addSpecies()

int addSpecies ( const std::string &  aname)

When a name species does not exist, add a new species.

Parameters
anameUnique name of the species be added.
Returns
the index of the species

Definition at line 33 of file SpeciesSet.cpp.

References SpeciesSet::create(), SpeciesSet::findSpecies(), SpeciesSet::speciesName, and SpeciesSet::TotalNum.

Referenced by qmcplusplus::create_C_pbc_particlesets(), qmcplusplus::createElectronParticleSet(), QMCGaussianParserBase::createElectronSet(), qmcplusplus::doSOECPotentialTest(), qmcplusplus::get_two_species_particleset(), qmcplusplus::setup_He_wavefunction(), qmcplusplus::test_cartesian_ao(), qmcplusplus::TEST_CASE(), qmcplusplus::test_CoulombPBCAA_3p(), qmcplusplus::test_diamond_2x1x1_xml_input(), qmcplusplus::test_dirac_ao(), qmcplusplus::test_hcpBe_rotation(), qmcplusplus::test_He(), qmcplusplus::test_He_mw(), qmcplusplus::test_He_sto3g_xml_input(), qmcplusplus::test_J1_spline(), qmcplusplus::test_J3_polynomial3D(), qmcplusplus::test_LCAO_DiamondC_2x1x1_cplx(), qmcplusplus::test_LCAO_DiamondC_2x1x1_real(), qmcplusplus::test_lcao_spinor(), qmcplusplus::test_lcao_spinor_excited(), qmcplusplus::test_lcao_spinor_ion_derivs(), qmcplusplus::test_LiH_msd(), qmcplusplus::test_LiH_msd_xml_input(), qmcplusplus::test_LiH_msd_xml_input_with_positron(), qmcplusplus::test_Ne(), qmcplusplus::testElecCase(), and qmcplusplus::testTrialWaveFunction_diamondC_2x1x1().

34 {
35  int i = findSpecies(aname); // check if the name is registered
36  if (i == TotalNum)
37  // if not found, add a new species
38  {
39  create(1);
40  speciesName[i] = aname;
41  }
42  return i; // return an index for a species
43 }
void create(unsigned m)
Definition: SpeciesSet.cpp:20
std::vector< std::string > speciesName
Species name list.
Definition: SpeciesSet.h:44
int findSpecies(const std::string &name) const
if the input species is not found, add a new species
Definition: SpeciesSet.h:114
unsigned TotalNum
The number of species.
Definition: SpeciesSet.h:41

◆ create()

void create ( unsigned  m)
Parameters
mthe number of species to be added

Definition at line 20 of file SpeciesSet.cpp.

References SpeciesSet::d_attrib, qmcplusplus::Units::distance::m, SpeciesSet::speciesName, and SpeciesSet::TotalNum.

Referenced by SpeciesSet::addSpecies().

21 {
22  if (m > 0)
23  {
24  speciesName.insert(speciesName.end(), m, std::string("none"));
25  for (auto& d : d_attrib)
26  {
27  d.insert(d.end(), m, 0);
28  }
29  TotalNum += m;
30  }
31 }
AttribList_t d_attrib
List of species attributes.
Definition: SpeciesSet.h:50
std::vector< std::string > speciesName
Species name list.
Definition: SpeciesSet.h:44
unsigned TotalNum
The number of species.
Definition: SpeciesSet.h:41

◆ findAttribute()

int findAttribute ( const std::string &  name) const
inline

almost all code ignores this and just uses addAttribute for the same purpose.

Definition at line 128 of file SpeciesSet.h.

References SpeciesSet::attribName, and SpeciesSet::findIndex().

Referenced by SpinDensityNew::getSpeciesSize(), and EinsplineSetBuilder::ReadOrbitalInfo_ESHDF().

128 { return findIndex(name, attribName); }
int findIndex(const std::string &name, const std::vector< std::string > &alist) const
Definition: SpeciesSet.h:130
std::vector< std::string > attribName
attribute name list
Definition: SpeciesSet.h:47

◆ findIndex()

int findIndex ( const std::string &  name,
const std::vector< std::string > &  alist 
) const
inline

Definition at line 130 of file SpeciesSet.h.

Referenced by SpeciesSet::findAttribute().

131  {
132  int i = 0;
133  while (i < alist.size())
134  {
135  if (alist[i] == name)
136  return i;
137  i++;
138  }
139  return -1;
140  }

◆ findSpecies()

int findSpecies ( const std::string &  name) const
inline

if the input species is not found, add a new species

Parameters
namea name of species
Returns
an ID for the species with name.

Definition at line 114 of file SpeciesSet.h.

References SpeciesSet::speciesName.

Referenced by BackflowBuilder::addOneBody(), SpeciesSet::addSpecies(), LCAOrbitalBuilder::createBasisSet(), LCAOrbitalBuilder::createBasisSetH5(), RadialJastrowBuilder::createJ1(), LatticeDeviationEstimator::LatticeDeviationEstimator(), SlaterDetBuilder::putDeterminant(), eeI_JastrowBuilder::putkids(), and ECPotentialBuilder::useXmlFormat().

115  {
116  int i = 0;
117  while (i < speciesName.size())
118  {
119  if (speciesName[i] == name)
120  return i;
121  i++;
122  }
123  return i;
124  }
std::vector< std::string > speciesName
Species name list.
Definition: SpeciesSet.h:44

◆ getAttribute()

int getAttribute ( const std::string &  aname) const

When a name species does not exist, return attribute.size()

Parameters
anameUnique name of the species to be looked up.
Returns
the index of the species

Definition at line 60 of file SpeciesSet.cpp.

References SpeciesSet::attribName.

Referenced by StressPBC::evalConsts_AA(), StressPBC::evaluateLR_AA(), OneBodyDensityMatrices::OneBodyDensityMatrices(), and SpeciesKineticEnergy::SpeciesKineticEnergy().

61 {
62  for (int i = 0; i < attribName.size(); i++)
63  {
64  if (attribName[i] == aname)
65  return i;
66  }
67  return attribName.size();
68 }
std::vector< std::string > attribName
attribute name list
Definition: SpeciesSet.h:47

◆ getSpeciesName()

const std::string& getSpeciesName ( int  index) const
inline

Definition at line 142 of file SpeciesSet.h.

References SpeciesSet::speciesName.

Referenced by XMLParticleParser::checkGrouping().

142 { return speciesName[index]; }
std::vector< std::string > speciesName
Species name list.
Definition: SpeciesSet.h:44

◆ getTotalNum()

◆ hasAttribute()

bool hasAttribute ( const std::string &  aname) const

Check for attribute presence This replaces code that gets numAttributes then tries to addAttribute for a particular name and compares the numAttributes and index of the new Attribute.

Parameters
anameUnique name of the species to be looked up.
Returns
is an attribute of that name present

Definition at line 70 of file SpeciesSet.cpp.

References SpeciesSet::attribName.

Referenced by OneBodyDensityMatrices::OneBodyDensityMatrices().

71 {
72  return std::find(attribName.begin(), attribName.end(), aname) != attribName.end();
73 }
std::vector< std::string > attribName
attribute name list
Definition: SpeciesSet.h:47

◆ numAttributes()

int numAttributes ( ) const
inline

return the number of attributes in our list

Definition at line 59 of file SpeciesSet.h.

References SpeciesSet::d_attrib.

Referenced by ParticleSet::createSK(), DensityMatrices1B::initialize(), and ParticleSet::resetGroups().

59 { return d_attrib.size(); }
AttribList_t d_attrib
List of species attributes.
Definition: SpeciesSet.h:50

◆ operator()() [1/2]

double operator() ( int  i,
int  j 
) const
inline
Parameters
iattribute index
jspecies index
Returns
the value of i-th attribute for the j-th species

Definition at line 94 of file SpeciesSet.h.

References SpeciesSet::d_attrib.

94 { return d_attrib[i][j]; }
AttribList_t d_attrib
List of species attributes.
Definition: SpeciesSet.h:50

◆ operator()() [2/2]

double& operator() ( int  i,
int  j 
)
inline

assignment operator

Parameters
iattribute index
jspecies index
Returns
the value of i-th attribute for the j-th species

Definition at line 102 of file SpeciesSet.h.

References SpeciesSet::d_attrib.

102 { return d_attrib[i][j]; }
AttribList_t d_attrib
List of species attributes.
Definition: SpeciesSet.h:50

◆ setTotalNum()

void setTotalNum ( const unsigned  n)
inline

set the number of species

Definition at line 57 of file SpeciesSet.h.

References qmcplusplus::n, and SpeciesSet::TotalNum.

57 { TotalNum = n; }
unsigned TotalNum
The number of species.
Definition: SpeciesSet.h:41

◆ size()

Member Data Documentation

◆ attribName

std::vector<std::string> attribName

◆ d_attrib

AttribList_t d_attrib

List of species attributes.

Definition at line 50 of file SpeciesSet.h.

Referenced by SpeciesSet::addAttribute(), SpeciesSet::create(), SpeciesSet::numAttributes(), and SpeciesSet::operator()().

◆ speciesName

◆ TotalNum


The documentation for this class was generated from the following files: