QMCPACK
XMLParticleIO.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
8 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
9 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
10 //
11 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
12 //////////////////////////////////////////////////////////////////////////////////////
13 
14 
15 #ifndef OHMMS_PARTICLE_INPUTOUTPUT_XML_UTILITY_H
16 #define OHMMS_PARTICLE_INPUTOUTPUT_XML_UTILITY_H
17 
20 #include "Particle/ParticleSet.h"
21 
22 namespace qmcplusplus
23 {
25 {
26  std::map<std::string, int> AttribTypeMap;
27  std::map<std::string, OhmmsObject*> AttribList;
28  ///** objects created by getXYZAttrib(aname) */
29  //std::vector<OhmmsObject*> AllocatedList;
30 
31 public:
33  {
34  //map[type-name] to enum
40  }
41 
42  /*
43  ~AttribListType()
44  {
45  for(int i=0; i<AllocatedList.size(); i++)
46  delete AllocatedList[i];
47  }
48  */
49 
50  /** add ParticleAttrib<AT>
51  * @tparam AT any element type, int, double, float ...
52  */
53  template<typename AT>
55  {
56  int oid = AttribList.size();
57  std::map<std::string, OhmmsObject*>::iterator it = AttribList.find(pa.objName());
58  if (it == AttribList.end())
59  {
60  AttribList[pa.objName()] = &pa;
61  pa.setID(oid);
62  }
63  else
64  {
65  oid = (*it).second->id();
66  }
67  return oid;
68  }
69 
70  ///return a type id: one of the enum values
71  inline int getAttribType(const std::string& tname) { return AttribTypeMap[tname]; }
72 
73  /** generic get function attribute function
74  * @param tname attribute type name
75  * @param oname attribute name
76  * @return pointer to the attribute
77  */
78  template<typename AT>
79  ParticleAttrib<AT>* getAttribute(const std::string& tname, const std::string& oname)
80  {
81  using attrib_type = ParticleAttrib<AT>;
82  const auto it = AttribList.find(oname);
83  if (it != AttribList.end())
84  {
85  OhmmsObject* o = (*it).second;
86  return dynamic_cast<attrib_type*>(o);
87  }
88  else
89  throw std::runtime_error("AttribListType::getAttribute Unknown attribute " + oname + "\n");
90  return nullptr;
91  }
92 };
93 
95 {
101 
104 
105  /** read the data of a particle attribute
106  *@param cur the xmlnode
107  *@param in_offset the location offset to read from XML element node body.
108  *@param copy_size the number of particle attributes to be read
109  *@param out_offset the current local count to which copy_size particle attributes are added.
110  */
111  void getPtclAttrib(xmlNodePtr cur, int in_offset, int copy_size, int out_offset);
112 
113  void checkGrouping(int nat, const std::vector<int>& nat_group) const;
114 
115 public:
116  /**constructor
117  *@param aptcl the particleset to be initialized
118  */
120 
121  bool readXML(xmlNodePtr cur);
122 
123  /** reset the properties of a particle set
124  */
125  bool reset(xmlNodePtr cur);
126 };
127 
129 {
135 
138  std::string FileRoot;
139  std::vector<std::string> SpeciesName;
140 
141 public:
143 
144  ~XMLSaveParticle() override;
145 
146  void reset(const char* fileroot, bool append = false) override;
147 
148  void report(int iter) override;
149 
150  void finalize() override {}
151 
152  bool put(xmlNodePtr cur) override;
153 
154  void get(std::ostream& os, int olevel) const;
155 
156  xmlNodePtr createNode(bool addlattice);
157 
158 private:
159 };
160 } // namespace qmcplusplus
161 
162 #endif
bool reset(xmlNodePtr cur)
reset the properties of a particle set
void checkGrouping(int nat, const std::vector< int > &nat_group) const
xmlNodePtr createNode(bool addlattice)
create particleset node
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
void reset(const char *fileroot, bool append=false) override
std::map< std::string, OhmmsObject * > AttribList
Definition: XMLParticleIO.h:27
abstract base class to record any properties
static std::string indextype_tag
the datatype tag for the index-type attribute
Definition: ParticleTags.h:55
void setID(int i)
overwrite ObjectID
Definition: OhmmsObject.h:54
static std::string postype_tag
the datatype tag for the pos-type attribute
Definition: ParticleTags.h:64
ParticleAttrib< Index_t > ParticleIndex
Definition: Configuration.h:90
Attaches a unit to a Vector for IO.
int getAttribType(const std::string &tname)
return a type id: one of the enum values
Definition: XMLParticleIO.h:71
std::vector< std::string > SpeciesName
ParticleAttrib< AT > * getAttribute(const std::string &tname, const std::string &oname)
generic get function attribute function
Definition: XMLParticleIO.h:79
Declaration of OhmmsElementBase and define xml-related macros.
An OhmmsElementBase with extra members to keep track the object/type.
Definition: OhmmsObject.h:43
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
ParticleAttrib< Tensor_t > ParticleTensor
Definition: Configuration.h:93
AttribListType()
objects created by getXYZAttrib(aname)
Definition: XMLParticleIO.h:32
static std::string tensortype_tag
the datatype tag for the tensor-type attribute
Definition: ParticleTags.h:73
Define the tags for the data types and attributes of particle classes.
Definition: ParticleTags.h:30
bool put(xmlNodePtr cur) override
bool readXML(xmlNodePtr cur)
process xmlnode <particleset/> which contains everything about the particle set to initialize ...
void getPtclAttrib(xmlNodePtr cur, int in_offset, int copy_size, int out_offset)
read the data of a particle attribute
void report(int iter) override
const std::string & objName() const
return the object name
Definition: OhmmsObject.h:69
static std::string stringtype_tag
the datatype tag for the string-type attribute
Definition: ParticleTags.h:61
XMLSaveParticle(Particle_t &pin)
ParticleAttrib< SingleParticlePos > ParticlePos
Definition: Configuration.h:92
XMLParticleParser(Particle_t &aptcl)
constructor
std::map< std::string, int > AttribTypeMap
Definition: XMLParticleIO.h:26
ParticleAttrib< Scalar_t > ParticleScalar
Definition: Configuration.h:91
static std::string scalartype_tag
the datatype tag for the scalar-type attribute
Definition: ParticleTags.h:58
int add(ParticleAttrib< AT > &pa)
add ParticleAttrib<AT>
Definition: XMLParticleIO.h:54